Skip to content

Commit

Permalink
Wrap globals in a namespace so that both scripts can be run in the sa…
Browse files Browse the repository at this point in the history
…me namespace.
  • Loading branch information
sdobbs committed Dec 9, 2015
1 parent 7bc50d4 commit 4de9bc3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Script to extract time-walk constants for the BCAL

//Leave this global so the accesors don't need the pointer as an argument
TFile *thisFile;
namespace ExtractTimeOffsetsAndCEff {
//Leave this global so the accesors don't need the pointer as an argument
TFile *thisFile;

// Accessor functions to grab histograms from our file
// (Makes things easy with the HistogramTools fills)
TH1I * Get1DHistogram(const char * plugin, const char * directoryName, const char * name, bool print = true){
// Accessor functions to grab histograms from our file
// (Makes things easy with the HistogramTools fills)
TH1I * Get1DHistogram(const char * plugin, const char * directoryName, const char * name, bool print = true){
TH1I * histogram;
TString fullName = TString(plugin) + "/" + TString(directoryName) + "/" + TString(name);
thisFile->GetObject(fullName, histogram);
Expand All @@ -14,9 +15,9 @@ TH1I * Get1DHistogram(const char * plugin, const char * directoryName, const cha
return NULL;
}
return histogram;
}
}

TH2I * Get2DHistogram(const char * plugin, const char * directoryName, const char * name){
TH2I * Get2DHistogram(const char * plugin, const char * directoryName, const char * name){
TH2I * histogram;
TString fullName = TString(plugin) + "/" + TString(directoryName) + "/" + TString(name);
histogram = thisFile->GetObject(fullName, histogram);
Expand All @@ -25,19 +26,20 @@ TH2I * Get2DHistogram(const char * plugin, const char * directoryName, const cha
return NULL;
}
return histogram;
}
}

// Do the extraction of the actual constants
void ExtractTimeOffsetsAndCEff(int run = 2931, TString filename = "hd_root.root"){

// Open our input and output file
thisFile = TFile::Open(filename);
ExtractTimeOffsetsAndCEff::thisFile = TFile::Open(filename);
TFile *outputFile = TFile::Open("BCALTimeOffsetAndCEff_Results.root", "RECREATE");
outputFile->mkdir("Fits");
outputFile->mkdir("ResultOverview");

// Check to make sure it is open
if (thisFile == 0) {
if (ExtractTimeOffsetsAndCEff::thisFile == 0) {
cout << "Unable to open file " << fileName.Data() << "...Exiting" << endl;
return;
}
Expand Down Expand Up @@ -118,7 +120,7 @@ void ExtractTimeOffsetsAndCEff(int run = 2931, TString filename = "hd_root.root"
TH1D * selectedBCALOffset = new TH1D("selectedBCALOffset", "Selected Global BCAL Offset; CCDB Index; Offset [ns]", 768, 0.5, 768 + 0.5);
TH1I * BCALOffsetDistribution = new TH1I("BCALOffsetDistribution", "Global BCAL Offset; Global Offset [ns]; Entries", 100, -10, 10);

thisHist = Get2DHistogram("BCAL_Global_Offsets", "Target Time", "Target Time Minus RF Time Vs. Cell Number");
thisHist = ExtractTimeOffsetsAndCEff::Get2DHistogram("BCAL_Global_Offsets", "Target Time", "Target Time Minus RF Time Vs. Cell Number");
if(thisHist != NULL){
int nBinsX = thisHist->GetNbinsX();
int nBinsY = thisHist->GetNbinsY();
Expand Down Expand Up @@ -164,7 +166,7 @@ void ExtractTimeOffsetsAndCEff(int run = 2931, TString filename = "hd_root.root"

// These histograms are created on the fly in the plugin, so there is a chance that they do not exist, in which case the pointer will be NULL

TH2I *h_offsets = Get2DHistogram ("BCAL_TDC_Offsets", "Z Position", name);
TH2I *h_offsets = ExtractTimeOffsetsAndCEff::Get2DHistogram ("BCAL_TDC_Offsets", "Z Position", name);

// Use FitSlicesY routine to extract the mean of each x bin
TObjArray ySlices;
Expand Down Expand Up @@ -202,7 +204,7 @@ void ExtractTimeOffsetsAndCEff(int run = 2931, TString filename = "hd_root.root"
channel_global_offset_File.close();
tdiff_u_d_File.close();
outputFile->Write();
thisFile->Close();
ExtractTimeOffsetsAndCEff::thisFile->Close();
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Script to extract time-walk constants for the BCAL

//Leave this global so the accesors don't need the pointer as an argument
TFile *thisFile;

namespace ExtractTimeWalk {
TFile *thisFile;

// Accessor functions to grab histograms from our file
// (Makes things easy with the HistogramTools fills)
TH1I * Get1DHistogram(const char * plugin, const char * directoryName, const char * name, bool print = true){
TH1I * Get1DHistogram(const char * plugin, const char * directoryName, const char * name, bool print = true){
TH1I * histogram;
TString fullName = TString(plugin) + "/" + TString(directoryName) + "/" + TString(name);
thisFile->GetObject(fullName, histogram);
Expand All @@ -14,9 +16,9 @@ TH1I * Get1DHistogram(const char * plugin, const char * directoryName, const cha
return NULL;
}
return histogram;
}
}

TH2I * Get2DHistogram(const char * plugin, const char * directoryName, const char * name){
TH2I * Get2DHistogram(const char * plugin, const char * directoryName, const char * name){
TH2I * histogram;
TString fullName = TString(plugin) + "/" + TString(directoryName) + "/" + TString(name);
histogram = thisFile->GetObject(fullName, histogram);
Expand All @@ -25,19 +27,20 @@ TH2I * Get2DHistogram(const char * plugin, const char * directoryName, const cha
return NULL;
}
return histogram;
}
}

// Do the extraction of the actual constants
void ExtractTimeWalk(TString filename = "hd_root.root"){

// Open our input and output file
thisFile = TFile::Open(filename);
ExtractTimeWalk::thisFile = TFile::Open(filename);
TFile *outputFile = TFile::Open("BCALTimewalk_Results.root", "RECREATE");
outputFile->mkdir("Upstream");
outputFile->mkdir("Downstream");

// Check to make sure it is open
if (thisFile == 0) {
if (ExtractTimeWalk::thisFile == 0) {
cout << "Unable to open file " << fileName.Data() << "...Exiting" << endl;
return;
}
Expand Down Expand Up @@ -79,10 +82,10 @@ void ExtractTimeWalk(TString filename = "hd_root.root"){
// For each M/L/S we have Upstream and downstream, lets grab them
// These histograms are created on the fly in the plugin, so there is a chance that they do not exist, in which case the pointer will be NULL

TH2I *h_UpstreamTW_E = Get2DHistogram ("BCAL_TDC_Timing", "BCAL_Upstream_Timewalk_NoCorrection_E", name);
TH2I *h_UpstreamTW_PP = Get2DHistogram ("BCAL_TDC_Timing", "BCAL_Upstream_Timewalk_NoCorrection_PP", name);
TH2I *h_DownstreamTW_E = Get2DHistogram ("BCAL_TDC_Timing", "BCAL_Downstream_Timewalk_NoCorrection_E", name);
TH2I *h_DownstreamTW_PP = Get2DHistogram ("BCAL_TDC_Timing", "BCAL_Downstream_Timewalk_NoCorrection_PP", name);
TH2I *h_UpstreamTW_E = ExtractTimeWalk::Get2DHistogram ("BCAL_TDC_Timing", "BCAL_Upstream_Timewalk_NoCorrection_E", name);
TH2I *h_UpstreamTW_PP = ExtractTimeWalk::Get2DHistogram ("BCAL_TDC_Timing", "BCAL_Upstream_Timewalk_NoCorrection_PP", name);
TH2I *h_DownstreamTW_E = ExtractTimeWalk::Get2DHistogram ("BCAL_TDC_Timing", "BCAL_Downstream_Timewalk_NoCorrection_E", name);
TH2I *h_DownstreamTW_PP = ExtractTimeWalk::Get2DHistogram ("BCAL_TDC_Timing", "BCAL_Downstream_Timewalk_NoCorrection_PP", name);

// Use FitSlicesY routine to extract the mean of each x bin
TObjArray ySlicesUpstream;
Expand Down Expand Up @@ -142,7 +145,7 @@ void ExtractTimeWalk(TString filename = "hd_root.root"){
}
textFile.close();
outputFile->Write();
thisFile->Close();
ExtractTimeWalk::thisFile->Close();
return;
}

Expand Down

0 comments on commit 4de9bc3

Please sign in to comment.