5 namespace ExtractTimeWalkNS {
10 TH1I *
Get1DHistogram(
const char * plugin,
const char * directoryName,
const char * name,
bool print =
true){
12 TString fullName = TString(plugin) +
"/" + TString(directoryName) +
"/" + TString(name);
13 thisFile->GetObject(fullName, histogram);
15 if (print) cout <<
"Unable to find histogram " << fullName.Data() << endl;
21 TH2I *
Get2DHistogram(
const char * plugin,
const char * directoryName,
const char * name){
23 TString fullName = TString(plugin) +
"/" + TString(directoryName) +
"/" + TString(name);
24 thisFile->GetObject(fullName, histogram);
26 cout <<
"Unable to find histogram " << fullName.Data() << endl;
38 TFile *outputFile = TFile::Open(
"BCALTimewalk_Results.root",
"RECREATE");
39 outputFile->mkdir(
"Upstream");
40 outputFile->mkdir(
"Downstream");
44 cout <<
"Unable to open file " <<
filename.Data() <<
"...Exiting" << endl;
51 textFile.open(
"TimewalkBCAL.txt");
58 double a_thresh = 14.0;
60 sprintf(formula,
"[0]+[1]/TMath::Power(x/%f,[2])", a_thresh);
61 TF1 *
f1 =
new TF1(
"f1", formula , 15, 400);
62 f1->SetParLimits(2, 0.25, 1.5);
65 TH1I *h1_c0 =
new TH1I(
"h1_c0",
"Distribution of parameter c_{0}", 100, -10, 10);
66 TH1I *h1_c1 =
new TH1I(
"h1_c1",
"Distribution of parameter c_{1}", 100, 0, 20);
67 TH1I *h1_c2 =
new TH1I(
"h1_c2",
"Distribution of parameter c_{2}", 100, 0.0, 1.5);
68 TH2I *h2_c0_c1 =
new TH2I(
"h2_c0_c1",
"c_{1} Vs. c_{0}; c_{0}; c_{1}", 100, -10, 10, 100, 0, 20);
69 TH2I *h2_c0_c2 =
new TH2I(
"h2_c0_c2",
"c_{2} Vs. c_{0}; c_{0}; c_{2}", 100, -10, 10, 100, 0.0, 1.5);
70 TH2I *h2_c1_c2 =
new TH2I(
"h2_c1_c2",
"c_{2} Vs. c_{1}; c_{1}; c_{2}", 100, 0.0, 20, 100, 0.0, 1.5);
73 for (
unsigned int iModule = 1; iModule <=48; iModule++){
74 for (
unsigned int iLayer = 1; iLayer <= 3; iLayer++){
75 for (
unsigned int iSector = 1; iSector <= 4; iSector++){
79 sprintf(name,
"Module %.2i Layer %.2i Sector %.2i", iModule, iLayer, iSector);
91 TObjArray ySlicesUpstream;
92 TObjArray ySlicesDownstream;
94 outputFile->cd(
"Upstream");
95 if (h_UpstreamTW_PP != NULL) {
96 h_UpstreamTW_PP->FitSlicesY(0, 0, -1, 0,
"QNR", &ySlicesUpstream);
97 TH1D *meanHist = (TH1D *) ySlicesUpstream.At(1);
98 TH1D *meanHistClone = (TH1D *) meanHist->Clone();
99 f1->SetParameters(0, 5, 0.7);
100 TFitResultPtr fr = meanHistClone->Fit(f1,
"SRQ");
101 Int_t fitStatus = fr;
103 double c0 = fr->Parameter(0);
104 double c1 = fr->Parameter(1);
105 double c2 = fr->Parameter(2);
106 h1_c0->Fill(c0); h1_c1->Fill(c1); h1_c2->Fill(c2);
107 h2_c0_c1->Fill(c0,c1); h2_c0_c2->Fill(c0,c2); h2_c1_c2->Fill(c1,c2);
108 textFile << iModule <<
" " << iLayer <<
" " << iSector <<
" 0 " << c0 <<
" " << c1 <<
" " << c2 <<
" " << a_thresh << endl;
111 cout <<
"WARNING: Fit Status "<< fitStatus <<
" for Upstream " << name << endl;
112 textFile << iModule <<
" " << iLayer <<
" " << iSector <<
" 0 0.0 0.0 0.0 1.0" << endl;
116 textFile << iModule <<
" " << iLayer <<
" " << iSector <<
" 0 0.0 0.0 0.0 1.0" << endl;
119 outputFile->cd(
"Downstream");
120 if (h_DownstreamTW_PP != NULL) {
121 h_DownstreamTW_PP->FitSlicesY(0, 0, -1, 0,
"QNR", &ySlicesDownstream);
122 TH1D *meanHist = (TH1D *) ySlicesDownstream.At(1);
123 TH1D *meanHistClone = (TH1D *) meanHist->Clone();
124 f1->SetParameters(0, 5, 0.7);
125 TFitResultPtr fr = meanHistClone->Fit(f1,
"SRQ");
126 Int_t fitStatus = fr;
128 double c0 = fr->Parameter(0);
129 double c1 = fr->Parameter(1);
130 double c2 = fr->Parameter(2);
131 h1_c0->Fill(c0); h1_c1->Fill(c1); h1_c2->Fill(c2);
132 h2_c0_c1->Fill(c0,c1); h2_c0_c2->Fill(c0,c2); h2_c1_c2->Fill(c1,c2);
133 textFile << iModule <<
" " << iLayer <<
" " << iSector <<
" 1 " << c0 <<
" " << c1 <<
" " << c2 <<
" " << a_thresh << endl;
136 cout <<
"WARNING: Fit Status "<< fitStatus <<
" for Downstream " << name << endl;
137 textFile << iModule <<
" " << iLayer <<
" " << iSector <<
" 1 0.0 0.0 0.0 1.0" << endl;
141 textFile << iModule <<
" " << iLayer <<
" " << iSector <<
" 1 0.0 0.0 0.0 1.0" << endl;
sprintf(text,"Post KinFit Cut")