Skip to content

Commit

Permalink
Merge pull request #139 from JeffersonLab/sdobbs_calib_challenge
Browse files Browse the repository at this point in the history
Sdobbs calib challenge
  • Loading branch information
Nathan A. Sparks committed Dec 9, 2015
2 parents 7bc50d4 + d1d3e79 commit 8a68615
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 25 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
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ jerror_t JEventProcessor_BCAL_TDC_Timing::erun(void)
jerror_t JEventProcessor_BCAL_TDC_Timing::fini(void)
{
// Called before program exit after event processing is finished.
SortDirectories(); // Sort the histogram directories by name
//SortDirectories(); // Sort the histogram directories by name
return NOERROR;
}

2 changes: 1 addition & 1 deletion src/plugins/Calibration/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import sbms
Import('*')

# update this when plugins are added
subdirs = ['BCAL_attenlength_gainratio','BCAL_gainmatrix','BCAL_TDC_Timing','HLDetectorTiming','TAGH_timewalk','CDC_TimeToDistance','PS_timing','PSC_TW','PS_E_calib']
subdirs = ['BCAL_attenlength_gainratio','BCAL_gainmatrix','BCAL_TDC_Timing','HLDetectorTiming','TAGH_timewalk','CDC_TimeToDistance','PS_timing','PSC_TW','PS_E_calib','st_tw_corr_auto']
SConscript(dirs=subdirs, exports='env osname', duplicate=0)

0 comments on commit 8a68615

Please sign in to comment.