FennecPlot.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Make validation page
3 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5  std::string user_dir, std::string user_name, std::string fileProfile, std::string fileHisto1D, std::string fileHisto2D){
6  // NOTE: Validation program seems to not like the tab special character, so using two spaces for a tab in the yaml instead
7  std::cout << "Making .yaml file to make Validation webpage." << std::endl;
8 
9  std::string validation_name = "cal_val_"+calibName;
10 
11  std::string dataName = detector+"_data_period"+period;
12  std::string dataFile = getOutputName(detector,period,sample,outputName,false,user_dir);
13 
14  std::string mcName;
15  std::string mcFile;
16  if( detector.find("fd")!=std::string::npos && detector.find("2")!=std::string::npos ){
17  mcName = detector+"_mc_gain100";
18  mcFile = getOutputName(detector,"mc_gain100",sample,outputName,false,user_dir);
19  }
20  if( detector.find("fd")!=std::string::npos && detector.find("2")==std::string::npos ){
21  mcName = detector+"_mc_gain140";
22  mcFile = getOutputName(detector,"mc_gain140",sample,outputName,false,user_dir);
23  }
24  if( detector.find("nd")!=std::string::npos ){
25  mcName = detector+"_mc";
26  mcFile = getOutputName(detector,"mc",sample,outputName,false,user_dir);
27  }
28 
29  std::string output_dir = "/nusoft/app/web/htdoc/nova/users/"+user_name+"/calibcheckout";
30 
31  std::string output_name = user_dir+"Output/Validation/"+validation_name+"_"+detector+"_period"+period+".yaml";
32 
33  std::ofstream yamlOut( output_name.c_str(), std::ofstream::out );
34  yamlOut << "{" << std::endl;
35  yamlOut << " " << "\"validation_name\": \"" << validation_name << "\"," << std::endl;
36  yamlOut << std::endl;
37  yamlOut << " " << "\"histogram_topdirs\": {" << std::endl;
38  yamlOut << " " << " " << "\"" << dataName << "\": \"" << dataFile << "\"," << std::endl;
39  yamlOut << " " << " " << "\"" << mcName << "\": \"" << mcFile << "\"," << std::endl;
40  yamlOut << " " << "}," << std::endl;
41  yamlOut << std::endl;
42  yamlOut << " " << "\"output_dir\": \"" << output_dir << "\"," << std::endl;
43  yamlOut << std::endl;
44  yamlOut << " " << "ratio_denom: \"" << mcName << "\"," << std::endl;
45  yamlOut << std::endl;
46  yamlOut << " " << "\"plot_accept_filters\": {" << std::endl;
47  //////////////////////////////////////////////////////
48  // Now put in the histogram names from the text files
49  for( auto const& iName : histo1DVector ){
50  yamlOut << " " << " " << "\"" << iName << "\"," << std::endl;
51  }
52  for( auto const& iName : histo2DVector ){
53  yamlOut << " " << " " << "\"" << iName << "\"," << std::endl;
54  }
55  for( auto const& iName : profileVector ){
56  yamlOut << " " << " " << "\"" << iName << "\"," << std::endl;
57  }
58  // If passed text files for additional plots, then add those
59  if( fileProfile.length()>0 ){
60  std::string readLineProfile;
61  std::ifstream inFileProfile(fileProfile,std::ifstream::in);
62  while( inFileProfile.good() ){
63  std::getline(inFileProfile,readLineProfile);
64  if( readLineProfile.empty() ) continue;
65  yamlOut << " " << " " << "\"" << readLineProfile << "\"," << std::endl;
66  }
67  }
68  if( fileHisto1D.length()>0 ){
69  std::string readLineHisto1D;
70  std::ifstream inFileHisto1D(fileHisto1D,std::ifstream::in);
71  while( inFileHisto1D.good() ){
72  std::getline(inFileHisto1D,readLineHisto1D);
73  if( readLineHisto1D.empty() ) continue;
74  yamlOut << " " << " " << "\"" << readLineHisto1D << "\"," << std::endl;
75  }
76  }
77  if( fileHisto2D.length()>0 ){
78  std::string readLineHisto2D;
79  std::ifstream inFileHisto2D(fileHisto2D,std::ifstream::in);
80  while( inFileHisto2D.good() ){
81  std::getline(inFileHisto2D,readLineHisto2D);
82  if( readLineHisto2D.empty() ) continue;
83  yamlOut << " " << " " << "\"" << readLineHisto2D << "\"," << std::endl;
84  }
85  }
86  //////////////////////////////////////////////////////
87  yamlOut << " " << "}," << std::endl;
88  yamlOut << "}" << std::endl;
89 
90  return;
91 }
92 
93 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
94 // Make comparison plots for periods
95 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
96 void InvestigatePeriods(std::vector<TFile*> myFiles, std::vector<std::string> thePeriods, std::string calibName, std::string user_dir,
97  std::string fileProfile, std::string fileHisto1D){
98  std::cout << "Running InvestigatePeriods with " << myFiles.size() << " files." << std::endl;
99 
101  std::vector<std::string> myHistosS;
102  std::vector<std::string> myProfsS;
103 
104  if( myFiles.size()<2 ){
105  std::cout << "... Asking to do ratios, but not 2+ files. Moving on ..." << std::endl;
106  return;
107  }
108  if( myFiles.size()!=thePeriods.size() ){
109  std::cout << "... Asking to do ratios, but myFiles size != thePeriods size. Moving on ..." << std::endl;
110  return;
111  }
112 
113  for( unsigned int iPeriod=0; iPeriod<myFiles.size(); ++iPeriod){
114  if( !myFiles[iPeriod]->IsOpen() ){
115  std::cout << "File for " << thePeriods[iPeriod] << " is closed and shouldn't be... Quitting." << std::endl;
116  return;
117  }
118  }
119 
120  // Get the names of histograms to look up
121  for( auto const& iName : histo1DVector ){
122  myHistosS.push_back(iName);
123  }
124  for( auto const& iName : profileVector ){
125  myProfsS.push_back(iName);
126  }
127 
128  // If passed text files for additional plots, then add those
129  if( fileProfile.length()>0 ){
130  std::string readLineProfile;
131  std::ifstream inFileProfile(fileProfile,std::ifstream::in);
132  while( inFileProfile.good() ){
133  std::getline(inFileProfile,readLineProfile);
134  if( readLineProfile.empty() ) continue;
135  myProfsS.push_back(readLineProfile);
136  }
137  }
138  if( fileHisto1D.length()>0 ){
139  std::string readLineHisto1D;
140  std::ifstream inFileHisto1D(fileHisto1D,std::ifstream::in);
141  while( inFileHisto1D.good() ){
142  std::getline(inFileHisto1D,readLineHisto1D);
143  if( readLineHisto1D.empty() ) continue;
144  myHistosS.push_back(readLineHisto1D);
145  }
146  }
147 
148  std::cout << "hists " << myHistosS.size() << std::endl;
149  std::cout << "profs " << myProfsS.size() << std::endl;
150 
151  // Set up elements
152  std::vector< std::vector<TH1D*> > myHistos; myHistos.resize( myHistosS.size() );
153  std::vector< std::vector<TProfile*> > myProfs; myProfs.resize( myProfsS.size() );
154  std::vector< TCanvas* > myCanvasH; myCanvasH.resize( myHistosS.size() );
155  std::vector< TCanvas* > myCanvasP; myCanvasP.resize( myProfsS.size() );
156  std::vector< TLegend* > myLegendH; myLegendH.resize( myHistosS.size() );
157  std::vector< TLegend* > myLegendP; myLegendP.resize( myProfsS.size() );
158 
159  for( unsigned int iPlot=0; iPlot<myHistosS.size(); ++iPlot ){
160  myHistos[iPlot].resize(myFiles.size());
161  }
162 
163  for( unsigned int iPlot=0; iPlot<myProfsS.size(); ++iPlot ){
164  myProfs[iPlot].resize(myFiles.size());
165  }
166 
167  for( unsigned int iPlot=0; iPlot<myProfsS.size(); ++iPlot ){
168  if( myProfsS[iPlot].find("true")!=std::string::npos ) continue; // skip truth plots which are in the MC
169  for( unsigned int iPeriod=0; iPeriod<myFiles.size(); ++iPeriod ){
170  myFiles[iPeriod]->cd();
171  myProfs[iPlot][iPeriod] = (TProfile*)myFiles[iPeriod]->Get(myProfsS[iPlot].c_str());
172  myProfs[iPlot][iPeriod]->SetName( TString::Format("%s_%u",myProfs[iPlot][iPeriod]->GetName(),iPeriod) );
173  }
174  makeRatioPlot( myCanvasP[iPlot], myLegendP[iPlot], myProfs[iPlot], myProfsS[iPlot], thePeriods, calibName, user_dir );
175  }
176 
177  for( unsigned int iPlot=0; iPlot<myHistosS.size(); ++iPlot ){
178  if( myHistosS[iPlot].find("true")!=std::string::npos ) continue; // skip truth plots which are in the MC
179  for( unsigned int iPeriod=0; iPeriod<myFiles.size(); ++iPeriod ){
180  myFiles[iPeriod]->cd();
181  myHistos[iPlot][iPeriod] = (TH1D*)myFiles[iPeriod]->Get(myHistosS[iPlot].c_str());
182  myHistos[iPlot][iPeriod]->SetName( TString::Format("%s_%u",myHistos[iPlot][iPeriod]->GetName(),iPeriod) );
183  // Scale y-axis to be fraction of hits
184  double myInt = myHistos[iPlot][iPeriod]->Integral();
185  myHistos[iPlot][iPeriod]->Scale(1./myInt);
186  myHistos[iPlot][iPeriod]->GetYaxis()->SetTitle("Fraction of hits");
187  }
188  makeRatioPlot( myCanvasH[iPlot], myLegendH[iPlot], myHistos[iPlot], myHistosS[iPlot], thePeriods, calibName, user_dir );
189  }
190 
191  ///// NEW 2D plots over time
192  // These plots will put the time axis in date mode, using method as in the event counting macros
193  // NOTE: Because of the way that the time fills at the moment, it may fill some hours off (UTC vs Central US Time)
194  // Need to check into this...
195  gSystem->Setenv("TZ","UTC");
196  gStyle->SetTimeOffset(0);
197  std::string taxis_labels = "%b '%y";
198 
199  // Define plots
200  TH2D *th2d_resp_time_flatW_xview = new TH2D("th2d_resp_time_flatW_xview_combined","Response [PECorr/cm] vs Time of Event;Time;Response",
201  6312,1388600000,1704100000,1000,0,500);
202  TH2D *th2d_pecm_time_flatW_xview = new TH2D("th2d_pecm_time_flatW_xview_combined","Uncorrected Response [PE/cm] vs Time of Event;Time;Response",
203  6312,1388600000,1704100000,1000,0,500);
204  TH2D *th2d_pe_time_flatW_xview = new TH2D("th2d_pe_time_flatW_xview_combined","Uncorrected PE vs Time of Event;Time;Response",
205  6312,1388600000,1704100000,1000,0,500);
206  TH2D *th2d_resp_time_flatW_yview = new TH2D("th2d_resp_time_flatW_yview_combined","Response [PECorr/cm] vs Time of Event;Time;Response",
207  6312,1388600000,1704100000,1000,0,500);
208  TH2D *th2d_pecm_time_flatW_yview = new TH2D("th2d_pecm_time_flatW_yview_combined","Uncorrected Response [PE/cm] vs Time of Event;Time;Response",
209  6312,1388600000,1704100000,1000,0,500);
210  TH2D *th2d_pe_time_flatW_yview = new TH2D("th2d_pe_time_flatW_yview_combined","Uncorrected PE vs Time of Event;Time;Response",
211  6312,1388600000,1704100000,1000,0,500);
212  // Load from file
213  for( unsigned int iPeriod=0; iPeriod<myFiles.size(); ++iPeriod ){
214  myFiles[iPeriod]->cd();
215  TH2D *th2d_resp_time_flatW_xview_pd = (TH2D*)myFiles[iPeriod]->Get("th2d_resp_time_flatW_xview");
216  th2d_resp_time_flatW_xview->Add(th2d_resp_time_flatW_xview_pd);
217  TH2D *th2d_pecm_time_flatW_xview_pd = (TH2D*)myFiles[iPeriod]->Get("th2d_pecm_time_flatW_xview");
218  th2d_pecm_time_flatW_xview->Add(th2d_pecm_time_flatW_xview_pd);
219  TH2D *th2d_pe_time_flatW_xview_pd = (TH2D*)myFiles[iPeriod]->Get("th2d_pe_time_flatW_xview");
220  th2d_pe_time_flatW_xview->Add(th2d_pe_time_flatW_xview_pd);
221  TH2D *th2d_resp_time_flatW_yview_pd = (TH2D*)myFiles[iPeriod]->Get("th2d_resp_time_flatW_yview");
222  th2d_resp_time_flatW_yview->Add(th2d_resp_time_flatW_yview_pd);
223  TH2D *th2d_pecm_time_flatW_yview_pd = (TH2D*)myFiles[iPeriod]->Get("th2d_pecm_time_flatW_yview");
224  th2d_pecm_time_flatW_yview->Add(th2d_pecm_time_flatW_yview_pd);
225  TH2D *th2d_pe_time_flatW_yview_pd = (TH2D*)myFiles[iPeriod]->Get("th2d_pe_time_flatW_yview");
226  th2d_pe_time_flatW_yview->Add(th2d_pe_time_flatW_yview_pd);
227  th2d_resp_time_flatW_xview_pd->~TH2D();
228  th2d_pecm_time_flatW_xview_pd->~TH2D();
229  th2d_pe_time_flatW_xview_pd->~TH2D();
230  th2d_resp_time_flatW_yview_pd->~TH2D();
231  th2d_pecm_time_flatW_yview_pd->~TH2D();
232  th2d_pe_time_flatW_yview_pd->~TH2D();
233  }
234  // Write them out now
235  double minX(0.), maxX(0.), maxY(0.);
236 
237  // X View
238  TCanvas *c1x = new TCanvas();
239  th2d_resp_time_flatW_xview->SetStats(0);
240  minX = th2d_resp_time_flatW_xview->GetXaxis()->GetBinCenter(th2d_resp_time_flatW_xview->FindFirstBinAbove(0.,1)-1);
241  maxX = th2d_resp_time_flatW_xview->GetXaxis()->GetBinCenter(th2d_resp_time_flatW_xview->FindLastBinAbove(0.,1)-1);
242  maxY = th2d_resp_time_flatW_xview->GetYaxis()->GetBinCenter(th2d_resp_time_flatW_xview->FindLastBinAbove(0.,2)-1);
243  th2d_resp_time_flatW_xview->GetXaxis()->SetRangeUser(minX,maxX);
244  th2d_resp_time_flatW_xview->GetYaxis()->SetRangeUser(0.,maxY);
245  th2d_resp_time_flatW_xview->GetXaxis()->SetTimeDisplay(1);
246  th2d_resp_time_flatW_xview->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
247  th2d_resp_time_flatW_xview->GetXaxis()->CenterTitle();
248  th2d_resp_time_flatW_xview->GetYaxis()->CenterTitle();
249  th2d_resp_time_flatW_xview->Draw("COLZ");
250  c1x->Print(TString::Format("%sOutput/Plots-ByPeriod/Plot_%s_th2d_resp_time_flatW_xview.pdf",user_dir.c_str(),calibName.c_str()));
251  TCanvas *c1xprof = new TCanvas();
252  TProfile *th2d_resp_time_flatW_xview_prof = (TProfile*)th2d_resp_time_flatW_xview->ProfileX();
253  th2d_resp_time_flatW_xview_prof->SetName("th2d_resp_time_flatW_xview_prof");
254  minX = th2d_resp_time_flatW_xview_prof->GetXaxis()->GetBinCenter(th2d_resp_time_flatW_xview_prof->FindFirstBinAbove(0.,1)-1);
255  maxX = th2d_resp_time_flatW_xview_prof->GetXaxis()->GetBinCenter(th2d_resp_time_flatW_xview_prof->FindLastBinAbove(0.,1)-1);
256  th2d_resp_time_flatW_xview_prof->GetXaxis()->SetRangeUser(minX,maxX);
257  th2d_resp_time_flatW_xview_prof->SetStats(0);
258  th2d_resp_time_flatW_xview_prof->Draw("");
259  c1xprof->Print(TString::Format("%sOutput/Plots-ByPeriod/Plot_%s_th2d_resp_time_flatW_xview_prof_UNZOOM.pdf",user_dir.c_str(),calibName.c_str()));
260  th2d_resp_time_flatW_xview_prof->GetYaxis()->SetRangeUser(39.,41.); // there are really low bin(s)... not sure why? maybe only few hits...
261  th2d_resp_time_flatW_xview_prof->GetXaxis()->SetTimeDisplay(1);
262  th2d_resp_time_flatW_xview_prof->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
263  th2d_resp_time_flatW_xview_prof->GetXaxis()->CenterTitle();
264  th2d_resp_time_flatW_xview_prof->GetYaxis()->CenterTitle();
265  gPad->Update();
266  c1xprof->Print(TString::Format("%sOutput/Plots-ByPeriod/Plot_%s_th2d_resp_time_flatW_xview_prof.pdf",user_dir.c_str(),calibName.c_str()));
267 
268  TCanvas *c2x = new TCanvas();
269  th2d_pecm_time_flatW_xview->SetStats(0);
270  minX = th2d_pecm_time_flatW_xview->GetXaxis()->GetBinCenter(th2d_pecm_time_flatW_xview->FindFirstBinAbove(0.,1)-1);
271  maxX = th2d_pecm_time_flatW_xview->GetXaxis()->GetBinCenter(th2d_pecm_time_flatW_xview->FindLastBinAbove(0.,1)-1);
272  maxY = th2d_pecm_time_flatW_xview->GetYaxis()->GetBinCenter(th2d_pecm_time_flatW_xview->FindLastBinAbove(0.,2)-1);
273  th2d_pecm_time_flatW_xview->GetXaxis()->SetRangeUser(minX,maxX);
274  th2d_pecm_time_flatW_xview->GetYaxis()->SetRangeUser(0.,maxY);
275  th2d_pecm_time_flatW_xview->GetXaxis()->SetTimeDisplay(1);
276  th2d_pecm_time_flatW_xview->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
277  th2d_pecm_time_flatW_xview->GetXaxis()->CenterTitle();
278  th2d_pecm_time_flatW_xview->GetYaxis()->CenterTitle();
279  th2d_pecm_time_flatW_xview->Draw("COLZ");
280  c2x->Print(TString::Format("%sOutput/Plots-ByPeriod/Plot_%s_th2d_pecm_time_flatW_xview.pdf",user_dir.c_str(),calibName.c_str()));
281  TCanvas *c2xprof = new TCanvas();
282  TProfile *th2d_pecm_time_flatW_xview_prof = (TProfile*)th2d_pecm_time_flatW_xview->ProfileX();
283  th2d_pecm_time_flatW_xview_prof->SetName("th2d_pecm_time_flatW_xview_prof");
284  minX = th2d_pecm_time_flatW_xview_prof->GetXaxis()->GetBinCenter(th2d_pecm_time_flatW_xview_prof->FindFirstBinAbove(0.,1)-1);
285  maxX = th2d_pecm_time_flatW_xview_prof->GetXaxis()->GetBinCenter(th2d_pecm_time_flatW_xview_prof->FindLastBinAbove(0.,1)-1);
286  th2d_pecm_time_flatW_xview_prof->GetXaxis()->SetRangeUser(minX,maxX);
287  th2d_pecm_time_flatW_xview_prof->SetStats(0);
288  th2d_pecm_time_flatW_xview_prof->Draw("");
289  c2xprof->Print(TString::Format("%sOutput/Plots-ByPeriod/Plot_%s_th2d_pecm_time_flatW_xview_prof_UNZOOM.pdf",user_dir.c_str(),calibName.c_str()));
290  th2d_pecm_time_flatW_xview_prof->GetYaxis()->SetRangeUser(26.,28.); // there are really low bin(s)... not sure why? maybe only few hits...
291  th2d_pecm_time_flatW_xview_prof->GetXaxis()->SetTimeDisplay(1);
292  th2d_pecm_time_flatW_xview_prof->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
293  th2d_pecm_time_flatW_xview_prof->GetXaxis()->CenterTitle();
294  th2d_pecm_time_flatW_xview_prof->GetYaxis()->CenterTitle();
295  gPad->Update();
296  c2xprof->Print(TString::Format("%sOutput/Plots-ByPeriod/Plot_%s_th2d_pecm_time_flatW_xview_prof.pdf",user_dir.c_str(),calibName.c_str()));
297 
298  TCanvas *c3x = new TCanvas();
299  th2d_pe_time_flatW_xview->SetStats(0);
300  minX = th2d_pe_time_flatW_xview->GetXaxis()->GetBinCenter(th2d_pe_time_flatW_xview->FindFirstBinAbove(0.,1)-1);
301  maxX = th2d_pe_time_flatW_xview->GetXaxis()->GetBinCenter(th2d_pe_time_flatW_xview->FindLastBinAbove(0.,1)-1);
302  maxY = th2d_pe_time_flatW_xview->GetYaxis()->GetBinCenter(th2d_pe_time_flatW_xview->FindLastBinAbove(0.,2)-1);
303  th2d_pe_time_flatW_xview->GetXaxis()->SetRangeUser(minX,maxX);
304  th2d_pe_time_flatW_xview->GetYaxis()->SetRangeUser(0.,maxY);
305  th2d_pe_time_flatW_xview->GetXaxis()->SetTimeDisplay(1);
306  th2d_pe_time_flatW_xview->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
307  th2d_pe_time_flatW_xview->GetXaxis()->CenterTitle();
308  th2d_pe_time_flatW_xview->GetYaxis()->CenterTitle();
309  th2d_pe_time_flatW_xview->Draw("COLZ");
310  c3x->Print(TString::Format("%sOutput/Plots-ByPeriod/Plot_%s_th2d_pe_time_flatW_xview.pdf",user_dir.c_str(),calibName.c_str()));
311  TCanvas *c3xprof = new TCanvas();
312  TProfile *th2d_pe_time_flatW_xview_prof = (TProfile*)th2d_pe_time_flatW_xview->ProfileX();
313  th2d_pe_time_flatW_xview_prof->SetName("th2d_pe_time_flatW_xview_prof");
314  minX = th2d_pe_time_flatW_xview_prof->GetXaxis()->GetBinCenter(th2d_pe_time_flatW_xview_prof->FindFirstBinAbove(0.,1)-1);
315  maxX = th2d_pe_time_flatW_xview_prof->GetXaxis()->GetBinCenter(th2d_pe_time_flatW_xview_prof->FindLastBinAbove(0.,1)-1);
316  th2d_pe_time_flatW_xview_prof->GetXaxis()->SetRangeUser(minX,maxX);
317  th2d_pe_time_flatW_xview_prof->SetStats(0);
318  th2d_pe_time_flatW_xview_prof->Draw("");
319  c3xprof->Print(TString::Format("%sOutput/Plots-ByPeriod/Plot_%s_th2d_pe_time_flatW_xview_prof_UNZOOM.pdf",user_dir.c_str(),calibName.c_str()));
320  th2d_pe_time_flatW_xview_prof->GetYaxis()->SetRangeUser(152.,162.); // there are really low bin(s)... not sure why? maybe only few hits...
321  th2d_pe_time_flatW_xview_prof->GetXaxis()->SetTimeDisplay(1);
322  th2d_pe_time_flatW_xview_prof->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
323  th2d_pe_time_flatW_xview_prof->GetXaxis()->CenterTitle();
324  th2d_pe_time_flatW_xview_prof->GetYaxis()->CenterTitle();
325  gPad->Update();
326  c3xprof->Print(TString::Format("%sOutput/Plots-ByPeriod/Plot_%s_th2d_pe_time_flatW_xview_prof.pdf",user_dir.c_str(),calibName.c_str()));
327 
328  // Y View
329  TCanvas *c1y = new TCanvas();
330  th2d_resp_time_flatW_yview->SetStats(0);
331  minX = th2d_resp_time_flatW_yview->GetXaxis()->GetBinCenter(th2d_resp_time_flatW_yview->FindFirstBinAbove(0.,1)-1);
332  maxX = th2d_resp_time_flatW_yview->GetXaxis()->GetBinCenter(th2d_resp_time_flatW_yview->FindLastBinAbove(0.,1)-1);
333  maxY = th2d_resp_time_flatW_yview->GetYaxis()->GetBinCenter(th2d_resp_time_flatW_yview->FindLastBinAbove(0.,2)-1);
334  th2d_resp_time_flatW_yview->GetXaxis()->SetRangeUser(minX,maxX);
335  th2d_resp_time_flatW_yview->GetYaxis()->SetRangeUser(0.,maxY);
336  th2d_resp_time_flatW_yview->GetXaxis()->SetTimeDisplay(1);
337  th2d_resp_time_flatW_yview->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
338  th2d_resp_time_flatW_yview->GetXaxis()->CenterTitle();
339  th2d_resp_time_flatW_yview->GetYaxis()->CenterTitle();
340  th2d_resp_time_flatW_yview->Draw("COLZ");
341  c1y->Print(TString::Format("%sOutput/Plots-ByPeriod/Plot_%s_th2d_resp_time_flatW_yview.pdf",user_dir.c_str(),calibName.c_str()));
342  TCanvas *c1yprof = new TCanvas();
343  TProfile *th2d_resp_time_flatW_yview_prof = (TProfile*)th2d_resp_time_flatW_yview->ProfileX();
344  th2d_resp_time_flatW_yview_prof->SetName("th2d_resp_time_flatW_yview_prof");
345  minX = th2d_resp_time_flatW_yview_prof->GetXaxis()->GetBinCenter(th2d_resp_time_flatW_yview_prof->FindFirstBinAbove(0.,1)-1);
346  maxX = th2d_resp_time_flatW_yview_prof->GetXaxis()->GetBinCenter(th2d_resp_time_flatW_yview_prof->FindLastBinAbove(0.,1)-1);
347  th2d_resp_time_flatW_yview_prof->GetXaxis()->SetRangeUser(minX,maxX);
348  th2d_resp_time_flatW_yview_prof->Draw("");
349  th2d_resp_time_flatW_yview_prof->SetStats(0);
350  c1yprof->Print(TString::Format("%sOutput/Plots-ByPeriod/Plot_%s_th2d_resp_time_flatW_yview_prof_UNZOOM.pdf",user_dir.c_str(),calibName.c_str()));
351  th2d_resp_time_flatW_yview_prof->GetYaxis()->SetRangeUser(39.,41.); // there are really low bin(s)... not sure why? maybe only few hits...
352  th2d_resp_time_flatW_yview_prof->GetXaxis()->SetTimeDisplay(1);
353  th2d_resp_time_flatW_yview_prof->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
354  th2d_resp_time_flatW_yview_prof->GetXaxis()->CenterTitle();
355  th2d_resp_time_flatW_yview_prof->GetYaxis()->CenterTitle();
356  gPad->Update();
357  c1yprof->Print(TString::Format("%sOutput/Plots-ByPeriod/Plot_%s_th2d_resp_time_flatW_yview_prof.pdf",user_dir.c_str(),calibName.c_str()));
358 
359  TCanvas *c2y = new TCanvas();
360  th2d_pecm_time_flatW_yview->SetStats(0);
361  minX = th2d_pecm_time_flatW_yview->GetXaxis()->GetBinCenter(th2d_pecm_time_flatW_yview->FindFirstBinAbove(0.,1)-1);
362  maxX = th2d_pecm_time_flatW_yview->GetXaxis()->GetBinCenter(th2d_pecm_time_flatW_yview->FindLastBinAbove(0.,1)-1);
363  maxY = th2d_pecm_time_flatW_yview->GetYaxis()->GetBinCenter(th2d_pecm_time_flatW_yview->FindLastBinAbove(0.,2)-1);
364  th2d_pecm_time_flatW_yview->GetXaxis()->SetRangeUser(minX,maxX);
365  th2d_pecm_time_flatW_yview->GetYaxis()->SetRangeUser(0.,maxY);
366  th2d_pecm_time_flatW_yview->GetXaxis()->SetTimeDisplay(1);
367  th2d_pecm_time_flatW_yview->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
368  th2d_pecm_time_flatW_yview->GetXaxis()->CenterTitle();
369  th2d_pecm_time_flatW_yview->GetYaxis()->CenterTitle();
370  th2d_pecm_time_flatW_yview->Draw("COLZ");
371  c2y->Print(TString::Format("%sOutput/Plots-ByPeriod/Plot_%s_th2d_pecm_time_flatW_yview.pdf",user_dir.c_str(),calibName.c_str()));
372  TCanvas *c2yprof = new TCanvas();
373  TProfile *th2d_pecm_time_flatW_yview_prof = (TProfile*)th2d_pecm_time_flatW_yview->ProfileX();
374  th2d_pecm_time_flatW_yview_prof->SetName("th2d_pecm_time_flatW_yview_prof");
375  minX = th2d_pecm_time_flatW_yview_prof->GetXaxis()->GetBinCenter(th2d_pecm_time_flatW_yview_prof->FindFirstBinAbove(0.,1)-1);
376  maxX = th2d_pecm_time_flatW_yview_prof->GetXaxis()->GetBinCenter(th2d_pecm_time_flatW_yview_prof->FindLastBinAbove(0.,1)-1);
377  th2d_pecm_time_flatW_yview_prof->GetXaxis()->SetRangeUser(minX,maxX);
378  th2d_pecm_time_flatW_yview_prof->SetStats(0);
379  th2d_pecm_time_flatW_yview_prof->Draw("");
380  c2yprof->Print(TString::Format("%sOutput/Plots-ByPeriod/Plot_%s_th2d_pecm_time_flatW_yview_prof_UNZOOM.pdf",user_dir.c_str(),calibName.c_str()));
381  th2d_pecm_time_flatW_yview_prof->GetYaxis()->SetRangeUser(20.5,22.5); // there are really low bin(s)... not sure why? maybe only few hits...
382  th2d_pecm_time_flatW_yview_prof->GetXaxis()->SetTimeDisplay(1);
383  th2d_pecm_time_flatW_yview_prof->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
384  th2d_pecm_time_flatW_yview_prof->GetXaxis()->CenterTitle();
385  th2d_pecm_time_flatW_yview_prof->GetYaxis()->CenterTitle();
386  gPad->Update();
387  c2yprof->Print(TString::Format("%sOutput/Plots-ByPeriod/Plot_%s_th2d_pecm_time_flatW_yview_prof.pdf",user_dir.c_str(),calibName.c_str()));
388 
389  TCanvas *c3y = new TCanvas();
390  th2d_pe_time_flatW_yview->SetStats(0);
391  minX = th2d_pe_time_flatW_yview->GetXaxis()->GetBinCenter(th2d_pe_time_flatW_yview->FindFirstBinAbove(0.,1)-1);
392  maxX = th2d_pe_time_flatW_yview->GetXaxis()->GetBinCenter(th2d_pe_time_flatW_yview->FindLastBinAbove(0.,1)-1);
393  maxY = th2d_pe_time_flatW_yview->GetYaxis()->GetBinCenter(th2d_pe_time_flatW_yview->FindLastBinAbove(0.,2)-1);
394  th2d_pe_time_flatW_yview->GetXaxis()->SetRangeUser(minX,maxX);
395  th2d_pe_time_flatW_yview->GetYaxis()->SetRangeUser(0.,maxY);
396  th2d_pe_time_flatW_yview->GetXaxis()->SetTimeDisplay(1);
397  th2d_pe_time_flatW_yview->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
398  th2d_pe_time_flatW_yview->GetXaxis()->CenterTitle();
399  th2d_pe_time_flatW_yview->GetYaxis()->CenterTitle();
400  th2d_pe_time_flatW_yview->Draw("COLZ");
401  c3y->Print(TString::Format("%sOutput/Plots-ByPeriod/Plot_%s_th2d_pe_time_flatW_yview.pdf",user_dir.c_str(),calibName.c_str()));
402  TCanvas *c3yprof = new TCanvas();
403  TProfile *th2d_pe_time_flatW_yview_prof = (TProfile*)th2d_pe_time_flatW_yview->ProfileX();
404  th2d_pe_time_flatW_yview_prof->SetName("th2d_pe_time_flatW_yview_prof");
405  minX = th2d_pe_time_flatW_yview_prof->GetXaxis()->GetBinCenter(th2d_pe_time_flatW_yview_prof->FindFirstBinAbove(0.,1)-1);
406  maxX = th2d_pe_time_flatW_yview_prof->GetXaxis()->GetBinCenter(th2d_pe_time_flatW_yview_prof->FindLastBinAbove(0.,1)-1);
407  th2d_pe_time_flatW_yview_prof->GetXaxis()->SetRangeUser(minX,maxX);
408  th2d_pe_time_flatW_yview_prof->SetStats(0);
409  th2d_pe_time_flatW_yview_prof->Draw("");
410  c3yprof->Print(TString::Format("%sOutput/Plots-ByPeriod/Plot_%s_th2d_pe_time_flatW_yview_prof_UNZOOM.pdf",user_dir.c_str(),calibName.c_str()));
411  th2d_pe_time_flatW_yview_prof->GetYaxis()->SetRangeUser(88.,93.); // there are really low bin(s)... not sure why? maybe only few hits...
412  th2d_pe_time_flatW_yview_prof->GetXaxis()->SetTimeDisplay(1);
413  th2d_pe_time_flatW_yview_prof->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
414  th2d_pe_time_flatW_yview_prof->GetXaxis()->CenterTitle();
415  th2d_pe_time_flatW_yview_prof->GetYaxis()->CenterTitle();
416  gPad->Update();
417  c3yprof->Print(TString::Format("%sOutput/Plots-ByPeriod/Plot_%s_th2d_pe_time_flatW_yview_prof.pdf",user_dir.c_str(),calibName.c_str()));
418 }
419 
420 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
421 // MakeTimeSeries (and fits!)
422 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
423 void MakeTimeSeries( std::string detector, bool byDB, unsigned int nDB, std::string calibName, std::string user_dir,
424  TProfile *prof_resp_time_flatW_xview, TProfile *prof_resp_time_flatW_yview,
425  TProfile *prof_pecm_time_flatW_xview, TProfile *prof_pecm_time_flatW_yview,
426  TProfile *prof_pe_time_flatW_xview, TProfile *prof_pe_time_flatW_yview,
427  TProfile *prof_resp_time_flatW_comboview, TProfile *prof_pecm_time_flatW_comboview, TProfile *prof_pe_time_flatW_comboview,
428  TProfile *prof_resp_time_flatW_xview_loW, TProfile *prof_resp_time_flatW_xview_mdW, TProfile *prof_resp_time_flatW_xview_hiW,
429  TProfile *prof_pecm_time_flatW_xview_loW, TProfile *prof_pecm_time_flatW_xview_mdW, TProfile *prof_pecm_time_flatW_xview_hiW,
430  TProfile *prof_resp_time_flatW_yview_loW, TProfile *prof_resp_time_flatW_yview_mdW, TProfile *prof_resp_time_flatW_yview_hiW,
431  TProfile *prof_pecm_time_flatW_yview_loW, TProfile *prof_pecm_time_flatW_yview_mdW, TProfile *prof_pecm_time_flatW_yview_hiW,
432  TProfile *prof_resp_time_flatW_xview_noSwap, TProfile *prof_pecm_time_flatW_xview_noSwap,
433  TProfile *prof_resp_time_flatW_yview_noSwap, TProfile *prof_pecm_time_flatW_yview_noSwap,
434  TProfile *prof_pecm_time_flatW_xview_db[14], TProfile *prof_pecm_time_flatW_yview_db[14], bool useNoSwap ){
435 
436  // Set up the cuts to use to draw the plots nicely
437  // These are the ND versions, change at FD
438  long t_lo = 1410000000;
439  long t_lo_fit = 1444000000;
440  long t_hi = 1555000000;
441  long t_hi_fit = 1555000000;
442  double y_resp_lo = 39;
443  double y_resp_hi = 45;
444  double y_pecm_lo = 42;
445  double y_pecm_hi = 48;
446  double y_pe_lo = 175;
447  double y_pe_hi = 220;
448 
449  double x_resp_lo = 39;
450  double x_resp_hi = 45;
451  double x_pecm_lo = 44;
452  double x_pecm_hi = 53;
453  double x_pe_lo = 240;
454  double x_pe_hi = 280;
455 
456  double pecm_db_fit_x_lo = 39; // for ND just picking wide region
457  double pecm_db_fit_x_hi = 56; // region since likely won't do
458  double pecm_db_fit_y_lo = 39; // as much by diblock here
459  double pecm_db_fit_y_hi = 56; //
460 
461  double c_resp_lo = 39;
462  double c_resp_hi = 45;
463  double c_pecm_lo = 42;
464  double c_pecm_hi = 53;
465  double c_pe_lo = 175;
466  double c_pe_hi = 280;
467  if( detector.find("fd")!=std::string::npos ){
468  t_lo = 1444000000;
469  t_hi = 1524000000;
470  t_lo_fit = t_lo;
471  t_hi_fit = t_hi;
472  y_resp_lo = 38;
473  y_resp_hi = 41;
474  y_pecm_lo = 20;
475  y_pecm_hi = 23;
476  y_pe_lo = 87;
477  y_pe_hi = 92;
478 
479  x_resp_lo = 39;
480  x_resp_hi = 42;
481  x_pecm_lo = 26;
482  x_pecm_hi = 28;
483  x_pe_lo = 150;
484  x_pe_hi = 160;
485 
486  c_resp_lo = 39;
487  c_resp_hi = 41;
488  c_pecm_lo = 21;
489  c_pecm_hi = 24;
490  c_pe_lo = 95;
491  c_pe_hi = 110;
492 
493  pecm_db_fit_x_lo= 23;
494  pecm_db_fit_x_hi= 32;
495  pecm_db_fit_y_lo= 18.5;
496  pecm_db_fit_y_hi= 25.5;
497  }
498 
499  // Do the fitting to PE and print those canvases
500  std::cout << "fitting plots" << std::endl;
501  TF1 *funcX = new TF1("funcX",TString::Format("[0]*(x-%ld)+[1]",t_lo_fit),t_lo_fit,t_hi_fit);
502  funcX->SetParameter(0,60.);
503  funcX->SetParameter(0,-0.05);
504 
505  TCanvas *canv_fit_pecm_time_flatW_xview = new TCanvas();
506  prof_pecm_time_flatW_xview->GetXaxis()->SetRangeUser(t_lo_fit,t_hi_fit);
507  prof_pecm_time_flatW_xview->GetYaxis()->SetRangeUser(x_pecm_lo,x_pecm_hi);
508  prof_pecm_time_flatW_xview->Fit(funcX,"QN");
509  prof_pecm_time_flatW_xview->Draw("");
510  funcX->Draw("same");
511 
512  TPaveText *tptX = new TPaveText(0.55,0.6,0.85,0.85,"NDC NB");
513  tptX->SetFillStyle(0);
514  tptX->AddText( TString::Format("y = %e*(x-%ld) + %f",funcX->GetParameter(0),t_lo_fit,funcX->GetParameter(1)) );
515  tptX->AddText( TString::Format("Chi2 = %f",funcX->GetChisquare()) );
516  tptX->AddText( TString::Format("NDOF = %d",funcX->GetNDF()) );
517  canv_fit_pecm_time_flatW_xview->cd();
518  tptX->Draw();
519 
520  canv_fit_pecm_time_flatW_xview->Print( TString::Format("%sOutput/Plots-ByPeriod/TimeFit-%s_%s_pecm_time_flatW_xview.pdf",user_dir.c_str(),detector.c_str(),calibName.c_str()) );
521 
522  TF1 *funcY = new TF1("funcY",TString::Format("[0]*(x-%ld)+[1]",t_lo_fit),t_lo_fit,t_hi_fit);
523  funcY->SetParameter(0,60.);
524  funcY->SetParameter(0,-0.05);
525 
526  TCanvas *canv_fit_pecm_time_flatW_yview = new TCanvas();
527  prof_pecm_time_flatW_yview->GetXaxis()->SetRangeUser(t_lo_fit,t_hi_fit);
528  prof_pecm_time_flatW_yview->GetYaxis()->SetRangeUser(y_pecm_lo,y_pecm_hi);
529  prof_pecm_time_flatW_yview->Fit(funcY,"QN");
530  prof_pecm_time_flatW_yview->Draw("");
531  funcY->Draw("same");
532 
533  TPaveText *tptY = new TPaveText(0.55,0.6,0.85,0.85,"NDC NB");
534  tptY->SetFillStyle(0);
535  tptY->AddText( TString::Format("y = %e*(x-%ld) + %f",funcY->GetParameter(0),t_lo_fit,funcY->GetParameter(1)) );
536  tptY->AddText( TString::Format("Chi2 = %f",funcY->GetChisquare()) );
537  tptY->AddText( TString::Format("NDOF = %d",funcY->GetNDF()) );
538  canv_fit_pecm_time_flatW_yview->cd();
539  tptY->Draw();
540 
541  canv_fit_pecm_time_flatW_yview->Print( TString::Format("%sOutput/Plots-ByPeriod/TimeFit-%s_%s_pecm_time_flatW_yview.pdf",user_dir.c_str(),detector.c_str(),calibName.c_str()) );
542 
543  std::cout << "FITS " << detector << " (PE/cm/year):" << std::endl;
544  std::cout << "x = " << 31536000.*funcX->GetParameter(0) << " +/- " << 31536000.*funcX->GetParError(0) << " -- chi2/dof = " << funcX->GetChisquare() << "/" << funcX->GetNDF() << std::endl;
545  std::cout << "y = " << 31536000.*funcY->GetParameter(0) << " +/- " << 31536000.*funcY->GetParError(0) << " -- chi2/dof = " << funcY->GetChisquare() << "/" << funcY->GetNDF() << std::endl;
546 
547  // Diblock-specific fits
548  TF1 *funcX_DB[14];
549  TF1 *funcY_DB[14];
550  TCanvas *canv_fit_pecm_time_flatW_xview_DB[14];
551  TCanvas *canv_fit_pecm_time_flatW_yview_DB[14];
552  TPaveText *tptX_DB[14];
553  TPaveText *tptY_DB[14];
554  if( byDB ){
555  std::cout << "diblock-by-diblock fits" << std::endl;
556  for( unsigned int iDB=0; iDB<nDB; ++iDB ){
557  funcX_DB[iDB] = new TF1(TString::Format("funcX_DB%i",iDB),TString::Format("[0]*(x-%ld)+[1]",t_lo_fit),t_lo_fit,t_hi_fit);
558  funcX_DB[iDB]->SetParameter(0,60.);
559  funcX_DB[iDB]->SetParameter(0,-0.05);
560 
561  canv_fit_pecm_time_flatW_xview_DB[iDB] = new TCanvas();
562  prof_pecm_time_flatW_xview_db[iDB]->GetXaxis()->SetRangeUser(t_lo_fit,t_hi_fit);
563  prof_pecm_time_flatW_xview_db[iDB]->GetYaxis()->SetRangeUser(pecm_db_fit_x_lo,pecm_db_fit_x_hi);
564  prof_pecm_time_flatW_xview_db[iDB]->Fit(funcX_DB[iDB],"QN");
565  prof_pecm_time_flatW_xview_db[iDB]->Draw("");
566  funcX_DB[iDB]->Draw("same");
567 
568  // Put the pave text at bottom left if "y-intercept" is closer to top of plot than bottom
569  if( pecm_db_fit_x_hi-funcX_DB[iDB]->GetParameter(1) <= funcX_DB[iDB]->GetParameter(1)-pecm_db_fit_x_lo )
570  tptX_DB[iDB] = new TPaveText(0.15,0.15,0.45,0.4,"NDC NB");
571  else tptX_DB[iDB] = new TPaveText(0.55,0.6,0.85,0.85,"NDC NB");
572  tptX_DB[iDB]->SetFillStyle(0);
573  tptX_DB[iDB]->AddText( TString::Format("y = %e*(x-%ld) + %f",funcX_DB[iDB]->GetParameter(0),t_lo_fit,funcX_DB[iDB]->GetParameter(1)) );
574  tptX_DB[iDB]->AddText( TString::Format("Chi2 = %f",funcX_DB[iDB]->GetChisquare()) );
575  tptX_DB[iDB]->AddText( TString::Format("NDOF = %d",funcX_DB[iDB]->GetNDF()) );
576  canv_fit_pecm_time_flatW_xview_DB[iDB]->cd();
577  tptX_DB[iDB]->Draw();
578 
579  canv_fit_pecm_time_flatW_xview_DB[iDB]->Print( TString::Format("%sOutput/Plots-ByPeriod/TimeFit-%s_%s_pecm_time_flatW_xview_db%i.pdf",user_dir.c_str(),detector.c_str(),calibName.c_str(),iDB) );
580 
581  funcY_DB[iDB] = new TF1(TString::Format("funcY_DB%i",iDB),TString::Format("[0]*(x-%ld)+[1]",t_lo_fit),t_lo_fit,t_hi_fit);
582  funcY_DB[iDB]->SetParameter(0,60.);
583  funcY_DB[iDB]->SetParameter(0,-0.05);
584 
585  canv_fit_pecm_time_flatW_yview_DB[iDB] = new TCanvas();
586  prof_pecm_time_flatW_yview_db[iDB]->GetXaxis()->SetRangeUser(t_lo_fit,t_hi_fit);
587  prof_pecm_time_flatW_yview_db[iDB]->GetYaxis()->SetRangeUser(pecm_db_fit_y_lo,pecm_db_fit_y_hi);
588  prof_pecm_time_flatW_yview_db[iDB]->Fit(funcY_DB[iDB],"QN");
589  prof_pecm_time_flatW_yview_db[iDB]->Draw("");
590  funcY_DB[iDB]->Draw("same");
591 
592  if( pecm_db_fit_y_hi-funcY_DB[iDB]->GetParameter(1) <= funcY_DB[iDB]->GetParameter(1)-pecm_db_fit_y_lo )
593  tptY_DB[iDB] = new TPaveText(0.15,0.15,0.45,0.4,"NDC NB");
594  else tptY_DB[iDB] = new TPaveText(0.55,0.6,0.85,0.85,"NDC NB");
595  tptY_DB[iDB]->SetFillStyle(0);
596  tptY_DB[iDB]->AddText( TString::Format("y = %e*(x-%ld) + %f",funcY_DB[iDB]->GetParameter(0),t_lo_fit,funcY_DB[iDB]->GetParameter(1)) );
597  tptY_DB[iDB]->AddText( TString::Format("Chi2 = %f",funcY_DB[iDB]->GetChisquare()) );
598  tptY_DB[iDB]->AddText( TString::Format("NDOF = %d",funcY_DB[iDB]->GetNDF()) );
599  canv_fit_pecm_time_flatW_yview_DB[iDB]->cd();
600  tptY_DB[iDB]->Draw();
601 
602  canv_fit_pecm_time_flatW_yview_DB[iDB]->Print( TString::Format("%sOutput/Plots-ByPeriod/TimeFit-%s_%s_pecm_time_flatW_yview_db%i.pdf",user_dir.c_str(),detector.c_str(),calibName.c_str(),iDB) );
603  }
604  }
605 
606  if( byDB ){
607  std::cout << "FITS " << detector << ", diblocks (PE/cm/year):" << std::endl;
608  for( unsigned int iDB=0; iDB<nDB; ++iDB ){
609  std::cout << "DB " << iDB+1 << std::endl;
610  std::cout << " x = " << 31536000.*funcX_DB[iDB]->GetParameter(0) << " +/- " << 31536000.*funcX_DB[iDB]->GetParError(0)
611  << " -- chi2/dof = " << funcX_DB[iDB]->GetChisquare() << "/" << funcX_DB[iDB]->GetNDF() << std::endl;
612  std::cout << " y = " << 31536000.*funcY_DB[iDB]->GetParameter(0) << " +/- " << 31536000.*funcY_DB[iDB]->GetParError(0)
613  << " -- chi2/dof = " << funcY_DB[iDB]->GetChisquare() << "/" << funcY_DB[iDB]->GetNDF() << std::endl;
614  }
615  }
616 
617  // Draw with time axis
618  // Make time axis as in Event Counting macros for nue/numu ana
619  std::cout << "time axis plots" << std::endl;
620  gSystem->Setenv("TZ","UTC");
621  gStyle->SetTimeOffset(0);
622  std::string taxis_labels = "%b '%y";
623 
624  TCanvas *canv_resp_time_flatW_xview = new TCanvas();
625  prof_resp_time_flatW_xview->GetXaxis()->SetRangeUser(t_lo,t_hi);
626  prof_resp_time_flatW_xview->GetYaxis()->SetRangeUser(x_resp_lo,x_resp_hi);
627  prof_resp_time_flatW_xview->GetXaxis()->SetTimeDisplay(1);
628  prof_resp_time_flatW_xview->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
629  prof_resp_time_flatW_xview->Draw("");
630  canv_resp_time_flatW_xview->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_resp_time_flatW_xview->GetName()) );
631 
632  TCanvas *canv_pecm_time_flatW_xview = new TCanvas();
633  prof_pecm_time_flatW_xview->GetXaxis()->SetRangeUser(t_lo,t_hi);
634  prof_pecm_time_flatW_xview->GetYaxis()->SetRangeUser(x_pecm_lo,x_pecm_hi);
635  prof_pecm_time_flatW_xview->GetXaxis()->SetTimeDisplay(1);
636  prof_pecm_time_flatW_xview->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
637  prof_pecm_time_flatW_xview->Draw("");
638  canv_pecm_time_flatW_xview->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_pecm_time_flatW_xview->GetName()) );
639 
640  TCanvas *canv_pe_time_flatW_xview = new TCanvas();
641  prof_pe_time_flatW_xview->GetXaxis()->SetRangeUser(t_lo,t_hi);
642  prof_pe_time_flatW_xview->GetYaxis()->SetRangeUser(x_pe_lo,x_pe_hi);
643  prof_pe_time_flatW_xview->GetXaxis()->SetTimeDisplay(1);
644  prof_pe_time_flatW_xview->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
645  prof_pe_time_flatW_xview->Draw("");
646  canv_pe_time_flatW_xview->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_pe_time_flatW_xview->GetName()) );
647 
648  TCanvas *canv_resp_time_flatW_yview = new TCanvas();
649  prof_resp_time_flatW_yview->GetXaxis()->SetRangeUser(t_lo,t_hi);
650  prof_resp_time_flatW_yview->GetYaxis()->SetRangeUser(y_resp_lo,y_resp_hi);
651  prof_resp_time_flatW_yview->GetXaxis()->SetTimeDisplay(1);
652  prof_resp_time_flatW_yview->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
653  prof_resp_time_flatW_yview->Draw("");
654  canv_resp_time_flatW_yview->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_resp_time_flatW_yview->GetName()) );
655 
656  TCanvas *canv_pecm_time_flatW_yview = new TCanvas();
657  prof_pecm_time_flatW_yview->GetXaxis()->SetRangeUser(t_lo,t_hi);
658  prof_pecm_time_flatW_yview->GetYaxis()->SetRangeUser(y_pecm_lo,y_pecm_hi);
659  prof_pecm_time_flatW_yview->GetXaxis()->SetTimeDisplay(1);
660  prof_pecm_time_flatW_yview->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
661  prof_pecm_time_flatW_yview->Draw("");
662  canv_pecm_time_flatW_yview->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_pecm_time_flatW_yview->GetName()) );
663 
664  TCanvas *canv_pe_time_flatW_yview = new TCanvas();
665  prof_pe_time_flatW_yview->GetXaxis()->SetRangeUser(t_lo,t_hi);
666  prof_pe_time_flatW_yview->GetYaxis()->SetRangeUser(y_pe_lo,y_pe_hi);
667  prof_pe_time_flatW_yview->GetXaxis()->SetTimeDisplay(1);
668  prof_pe_time_flatW_yview->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
669  prof_pe_time_flatW_yview->Draw("");
670  canv_pe_time_flatW_yview->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_pe_time_flatW_yview->GetName()) );
671 
672  TCanvas *canv_resp_time_flatW_comboview = new TCanvas();
673  prof_resp_time_flatW_comboview->GetXaxis()->SetRangeUser(t_lo,t_hi);
674  prof_resp_time_flatW_comboview->GetYaxis()->SetRangeUser(c_resp_lo,c_resp_hi);
675  prof_resp_time_flatW_comboview->GetXaxis()->SetTimeDisplay(1);
676  prof_resp_time_flatW_comboview->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
677  prof_resp_time_flatW_comboview->Draw("");
678  canv_resp_time_flatW_comboview->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_resp_time_flatW_comboview->GetName()) );
679 
680  TCanvas *canv_pecm_time_flatW_comboview = new TCanvas();
681  prof_pecm_time_flatW_comboview->GetXaxis()->SetRangeUser(t_lo,t_hi);
682  prof_pecm_time_flatW_comboview->GetYaxis()->SetRangeUser(c_pecm_lo,c_pecm_hi);
683  prof_pecm_time_flatW_comboview->GetXaxis()->SetTimeDisplay(1);
684  prof_pecm_time_flatW_comboview->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
685  prof_pecm_time_flatW_comboview->Draw("");
686  canv_pecm_time_flatW_comboview->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_pecm_time_flatW_comboview->GetName()) );
687 
688  TCanvas *canv_pe_time_flatW_comboview = new TCanvas();
689  prof_pe_time_flatW_comboview->GetXaxis()->SetRangeUser(t_lo,t_hi);
690  prof_pe_time_flatW_comboview->GetYaxis()->SetRangeUser(c_pe_lo,c_pe_hi);
691  prof_pe_time_flatW_comboview->GetXaxis()->SetTimeDisplay(1);
692  prof_pe_time_flatW_comboview->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
693  prof_pe_time_flatW_comboview->Draw("");
694  canv_pe_time_flatW_comboview->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_pe_time_flatW_comboview->GetName()) );
695 
696  // W breakdowns
697  TCanvas *canv_resp_time_flatW_xview_loW = new TCanvas();
698  prof_resp_time_flatW_xview_loW->GetXaxis()->SetRangeUser(t_lo,t_hi);
699  prof_resp_time_flatW_xview_loW->GetYaxis()->SetRangeUser(0.92*prof_resp_time_flatW_xview_loW->GetMaximum(),1.08*prof_resp_time_flatW_xview_loW->GetMaximum());
700  prof_resp_time_flatW_xview_loW->GetXaxis()->SetTimeDisplay(1);
701  prof_resp_time_flatW_xview_loW->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
702  prof_resp_time_flatW_xview_loW->Draw("");
703  // hits
704  TPaveText *tpRXLo = new TPaveText(0.7,0.7,0.86,0.86,"NB NDC");
705  tpRXLo->SetFillStyle(0);
706  tpRXLo->AddText( TString::Format("Hits: %3.1f%%",100.0*prof_resp_time_flatW_xview_loW->GetEntries()/prof_resp_time_flatW_xview->GetEntries()) );
707  canv_resp_time_flatW_xview_loW->cd();
708  tpRXLo->Draw();
709  canv_resp_time_flatW_xview_loW->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_resp_time_flatW_xview_loW->GetName()) );
710 
711  TCanvas *canv_pecm_time_flatW_xview_loW = new TCanvas();
712  prof_pecm_time_flatW_xview_loW->GetXaxis()->SetRangeUser(t_lo,t_hi);
713  prof_pecm_time_flatW_xview_loW->GetYaxis()->SetRangeUser(0.92*prof_pecm_time_flatW_xview_loW->GetMaximum(),1.08*prof_pecm_time_flatW_xview_loW->GetMaximum());
714  prof_pecm_time_flatW_xview_loW->GetXaxis()->SetTimeDisplay(1);
715  prof_pecm_time_flatW_xview_loW->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
716  prof_pecm_time_flatW_xview_loW->Draw("");
717  // hits
718  TPaveText *tpPXLo = new TPaveText(0.7,0.7,0.86,0.86,"NB NDC");
719  tpPXLo->SetFillStyle(0);
720  tpPXLo->AddText( TString::Format("Hits: %3.1f%%",100.0*prof_pecm_time_flatW_xview_loW->GetEntries()/prof_pecm_time_flatW_xview->GetEntries()) );
721  canv_pecm_time_flatW_xview_loW->cd();
722  tpPXLo->Draw();
723  canv_pecm_time_flatW_xview_loW->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_pecm_time_flatW_xview_loW->GetName()) );
724 
725  TCanvas *canv_resp_time_flatW_yview_loW = new TCanvas();
726  prof_resp_time_flatW_yview_loW->GetXaxis()->SetRangeUser(t_lo,t_hi);
727  prof_resp_time_flatW_yview_loW->GetYaxis()->SetRangeUser(0.92*prof_resp_time_flatW_yview_loW->GetMaximum(),1.08*prof_resp_time_flatW_yview_loW->GetMaximum());
728  prof_resp_time_flatW_yview_loW->GetXaxis()->SetTimeDisplay(1);
729  prof_resp_time_flatW_yview_loW->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
730  prof_resp_time_flatW_yview_loW->Draw("");
731  // hits
732  TPaveText *tpRYLo = new TPaveText(0.7,0.7,0.86,0.86,"NB NDC");
733  tpRYLo->SetFillStyle(0);
734  tpRYLo->AddText( TString::Format("Hits: %3.1f%%",100.0*prof_resp_time_flatW_yview_loW->GetEntries()/prof_resp_time_flatW_yview->GetEntries()) );
735  canv_resp_time_flatW_yview_loW->cd();
736  tpRYLo->Draw();
737  canv_resp_time_flatW_yview_loW->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_resp_time_flatW_yview_loW->GetName()) );
738 
739  TCanvas *canv_pecm_time_flatW_yview_loW = new TCanvas();
740  prof_pecm_time_flatW_yview_loW->GetXaxis()->SetRangeUser(t_lo,t_hi);
741  prof_pecm_time_flatW_yview_loW->GetYaxis()->SetRangeUser(0.92*prof_pecm_time_flatW_yview_loW->GetMaximum(),1.08*prof_pecm_time_flatW_yview_loW->GetMaximum());
742  prof_pecm_time_flatW_yview_loW->GetXaxis()->SetTimeDisplay(1);
743  prof_pecm_time_flatW_yview_loW->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
744  prof_pecm_time_flatW_yview_loW->Draw("");
745  // hits
746  TPaveText *tpPYLo = new TPaveText(0.7,0.7,0.86,0.86,"NB NDC");
747  tpPYLo->SetFillStyle(0);
748  tpPYLo->AddText( TString::Format("Hits: %3.1f%%",100.0*prof_pecm_time_flatW_yview_loW->GetEntries()/prof_pecm_time_flatW_yview->GetEntries()) );
749  canv_pecm_time_flatW_yview_loW->cd();
750  tpPYLo->Draw();
751  canv_pecm_time_flatW_yview_loW->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_pecm_time_flatW_yview_loW->GetName()) );
752 
753  TCanvas *canv_resp_time_flatW_xview_mdW = new TCanvas();
754  prof_resp_time_flatW_xview_mdW->GetXaxis()->SetRangeUser(t_lo,t_hi);
755  prof_resp_time_flatW_xview_mdW->GetYaxis()->SetRangeUser(0.92*prof_resp_time_flatW_xview_mdW->GetMaximum(),1.08*prof_resp_time_flatW_xview_mdW->GetMaximum());
756  prof_resp_time_flatW_xview_mdW->GetXaxis()->SetTimeDisplay(1);
757  prof_resp_time_flatW_xview_mdW->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
758  prof_resp_time_flatW_xview_mdW->Draw("");
759  // hits
760  TPaveText *tpRXMd = new TPaveText(0.7,0.7,0.86,0.86,"NB NDC");
761  tpRXMd->SetFillStyle(0);
762  tpRXMd->AddText( TString::Format("Hits: %3.1f%%",100.0*prof_resp_time_flatW_xview_mdW->GetEntries()/prof_resp_time_flatW_xview->GetEntries()) );
763  canv_resp_time_flatW_xview_mdW->cd();
764  tpRXMd->Draw();
765  canv_resp_time_flatW_xview_mdW->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_resp_time_flatW_xview_mdW->GetName()) );
766 
767  TCanvas *canv_pecm_time_flatW_xview_mdW = new TCanvas();
768  prof_pecm_time_flatW_xview_mdW->GetXaxis()->SetRangeUser(t_lo,t_hi);
769  prof_pecm_time_flatW_xview_mdW->GetYaxis()->SetRangeUser(0.92*prof_pecm_time_flatW_xview_mdW->GetMaximum(),1.08*prof_pecm_time_flatW_xview_mdW->GetMaximum());
770  prof_pecm_time_flatW_xview_mdW->GetXaxis()->SetTimeDisplay(1);
771  prof_pecm_time_flatW_xview_mdW->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
772  prof_pecm_time_flatW_xview_mdW->Draw("");
773  // hits
774  TPaveText *tpPXMd = new TPaveText(0.7,0.7,0.86,0.86,"NB NDC");
775  tpPXMd->SetFillStyle(0);
776  tpPXMd->AddText( TString::Format("Hits: %3.1f%%",100.0*prof_pecm_time_flatW_xview_mdW->GetEntries()/prof_pecm_time_flatW_xview->GetEntries()) );
777  canv_pecm_time_flatW_xview_mdW->cd();
778  tpPXMd->Draw();
779  canv_pecm_time_flatW_xview_mdW->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_pecm_time_flatW_xview_mdW->GetName()) );
780 
781  TCanvas *canv_resp_time_flatW_yview_mdW = new TCanvas();
782  prof_resp_time_flatW_yview_mdW->GetXaxis()->SetRangeUser(t_lo,t_hi);
783  prof_resp_time_flatW_yview_mdW->GetYaxis()->SetRangeUser(0.92*prof_resp_time_flatW_yview_mdW->GetMaximum(),1.08*prof_resp_time_flatW_yview_mdW->GetMaximum());
784  prof_resp_time_flatW_yview_mdW->GetXaxis()->SetTimeDisplay(1);
785  prof_resp_time_flatW_yview_mdW->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
786  prof_resp_time_flatW_yview_mdW->Draw("");
787  // hits
788  TPaveText *tpRYMd = new TPaveText(0.7,0.7,0.86,0.86,"NB NDC");
789  tpRYMd->SetFillStyle(0);
790  tpRYMd->AddText( TString::Format("Hits: %3.1f%%",100.0*prof_resp_time_flatW_yview_mdW->GetEntries()/prof_resp_time_flatW_yview->GetEntries()) );
791  canv_resp_time_flatW_yview_mdW->cd();
792  tpRYMd->Draw();
793  canv_resp_time_flatW_yview_mdW->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_resp_time_flatW_yview_mdW->GetName()) );
794 
795  TCanvas *canv_pecm_time_flatW_yview_mdW = new TCanvas();
796  prof_pecm_time_flatW_yview_mdW->GetXaxis()->SetRangeUser(t_lo,t_hi);
797  prof_pecm_time_flatW_yview_mdW->GetYaxis()->SetRangeUser(0.92*prof_pecm_time_flatW_yview_mdW->GetMaximum(),1.08*prof_pecm_time_flatW_yview_mdW->GetMaximum());
798  prof_pecm_time_flatW_yview_mdW->GetXaxis()->SetTimeDisplay(1);
799  prof_pecm_time_flatW_yview_mdW->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
800  prof_pecm_time_flatW_yview_mdW->Draw("");
801  // hits
802  TPaveText *tpPYMd = new TPaveText(0.7,0.7,0.86,0.86,"NB NDC");
803  tpPYMd->SetFillStyle(0);
804  tpPYMd->AddText( TString::Format("Hits: %3.1f%%",100.0*prof_pecm_time_flatW_yview_mdW->GetEntries()/prof_pecm_time_flatW_yview->GetEntries()) );
805  canv_pecm_time_flatW_yview_mdW->cd();
806  tpPYMd->Draw();
807  canv_pecm_time_flatW_yview_mdW->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_pecm_time_flatW_yview_mdW->GetName()) );
808 
809  TCanvas *canv_resp_time_flatW_xview_hiW = new TCanvas();
810  prof_resp_time_flatW_xview_hiW->GetXaxis()->SetRangeUser(t_lo,t_hi);
811  prof_resp_time_flatW_xview_hiW->GetYaxis()->SetRangeUser(0.92*prof_resp_time_flatW_xview_hiW->GetMaximum(),1.08*prof_resp_time_flatW_xview_hiW->GetMaximum());
812  prof_resp_time_flatW_xview_hiW->GetXaxis()->SetTimeDisplay(1);
813  prof_resp_time_flatW_xview_hiW->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
814  prof_resp_time_flatW_xview_hiW->Draw("");
815  // hits
816  TPaveText *tpRXHi = new TPaveText(0.7,0.7,0.86,0.86,"NB NDC");
817  tpRXHi->SetFillStyle(0);
818  tpRXHi->AddText( TString::Format("Hits: %3.1f%%",100.0*prof_resp_time_flatW_xview_hiW->GetEntries()/prof_resp_time_flatW_xview->GetEntries()) );
819  canv_resp_time_flatW_xview_hiW->cd();
820  tpRXHi->Draw();
821  canv_resp_time_flatW_xview_hiW->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_resp_time_flatW_xview_hiW->GetName()) );
822 
823  TCanvas *canv_pecm_time_flatW_xview_hiW = new TCanvas();
824  prof_pecm_time_flatW_xview_hiW->GetXaxis()->SetRangeUser(t_lo,t_hi);
825  prof_pecm_time_flatW_xview_hiW->GetYaxis()->SetRangeUser(0.92*prof_pecm_time_flatW_xview_hiW->GetMaximum(),1.08*prof_pecm_time_flatW_xview_hiW->GetMaximum());
826  prof_pecm_time_flatW_xview_hiW->GetXaxis()->SetTimeDisplay(1);
827  prof_pecm_time_flatW_xview_hiW->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
828  prof_pecm_time_flatW_xview_hiW->Draw("");
829  // hits
830  TPaveText *tpPXHi = new TPaveText(0.7,0.7,0.86,0.86,"NB NDC");
831  tpPXHi->SetFillStyle(0);
832  tpPXHi->AddText( TString::Format("Hits: %3.1f%%",100.0*prof_pecm_time_flatW_xview_hiW->GetEntries()/prof_pecm_time_flatW_xview->GetEntries()) );
833  canv_pecm_time_flatW_xview_hiW->cd();
834  tpPXHi->Draw();
835  canv_pecm_time_flatW_xview_hiW->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_pecm_time_flatW_xview_hiW->GetName()) );
836 
837  TCanvas *canv_resp_time_flatW_yview_hiW = new TCanvas();
838  prof_resp_time_flatW_yview_hiW->GetXaxis()->SetRangeUser(t_lo,t_hi);
839  prof_resp_time_flatW_yview_hiW->GetYaxis()->SetRangeUser(0.92*prof_resp_time_flatW_yview_hiW->GetMaximum(),1.08*prof_resp_time_flatW_yview_hiW->GetMaximum());
840  prof_resp_time_flatW_yview_hiW->GetXaxis()->SetTimeDisplay(1);
841  prof_resp_time_flatW_yview_hiW->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
842  prof_resp_time_flatW_yview_hiW->Draw("");
843  // hits
844  TPaveText *tpRYHi = new TPaveText(0.7,0.7,0.86,0.86,"NB NDC");
845  tpRYHi->SetFillStyle(0);
846  tpRYHi->AddText( TString::Format("Hits: %3.1f%%",100.0*prof_resp_time_flatW_yview_hiW->GetEntries()/prof_resp_time_flatW_yview->GetEntries()) );
847  canv_resp_time_flatW_yview_hiW->cd();
848  tpRYHi->Draw();
849  canv_resp_time_flatW_yview_hiW->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_resp_time_flatW_yview_hiW->GetName()) );
850 
851  TCanvas *canv_pecm_time_flatW_yview_hiW = new TCanvas();
852  prof_pecm_time_flatW_yview_hiW->GetXaxis()->SetRangeUser(t_lo,t_hi);
853  prof_pecm_time_flatW_yview_hiW->GetYaxis()->SetRangeUser(0.92*prof_pecm_time_flatW_yview_hiW->GetMaximum(),1.08*prof_pecm_time_flatW_yview_hiW->GetMaximum());
854  prof_pecm_time_flatW_yview_hiW->GetXaxis()->SetTimeDisplay(1);
855  prof_pecm_time_flatW_yview_hiW->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
856  prof_pecm_time_flatW_yview_hiW->Draw("");
857  // hits
858  TPaveText *tpPYHi = new TPaveText(0.7,0.7,0.86,0.86,"NB NDC");
859  tpPYHi->SetFillStyle(0);
860  tpPYHi->AddText( TString::Format("Hits: %3.1f%%",100.0*prof_pecm_time_flatW_yview_hiW->GetEntries()/prof_pecm_time_flatW_yview->GetEntries()) );
861  canv_pecm_time_flatW_yview_hiW->cd();
862  tpPYHi->Draw();
863  canv_pecm_time_flatW_yview_hiW->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_pecm_time_flatW_yview_hiW->GetName()) );
864 
865  // NoSwap breakdowns
866  if( useNoSwap ){
867  TCanvas *canv_resp_time_flatW_xview_noSwap = new TCanvas();
868  prof_resp_time_flatW_xview_noSwap->GetXaxis()->SetRangeUser(t_lo,t_hi);
869  prof_resp_time_flatW_xview_noSwap->GetYaxis()->SetRangeUser(x_resp_lo,x_resp_hi);
870  prof_resp_time_flatW_xview_noSwap->GetXaxis()->SetTimeDisplay(1);
871  prof_resp_time_flatW_xview_noSwap->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
872  prof_resp_time_flatW_xview_noSwap->Draw("");
873  // hits
874  TPaveText *tpRXNoS = new TPaveText(0.7,0.7,0.86,0.86,"NB NDC");
875  tpRXNoS->SetFillStyle(0);
876  tpRXNoS->AddText( TString::Format("Hits: %3.1f%%",100.0*prof_resp_time_flatW_xview_noSwap->GetEntries()/prof_resp_time_flatW_xview->GetEntries()) );
877  canv_resp_time_flatW_xview_noSwap->cd();
878  tpRXNoS->Draw();
879  canv_resp_time_flatW_xview_noSwap->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_resp_time_flatW_xview_noSwap->GetName()) );
880 
881  TCanvas *canv_pecm_time_flatW_xview_noSwap = new TCanvas();
882  prof_pecm_time_flatW_xview_noSwap->GetXaxis()->SetRangeUser(t_lo,t_hi);
883  prof_pecm_time_flatW_xview_noSwap->GetYaxis()->SetRangeUser(x_pecm_lo,x_pecm_hi);
884  prof_pecm_time_flatW_xview_noSwap->GetXaxis()->SetTimeDisplay(1);
885  prof_pecm_time_flatW_xview_noSwap->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
886  prof_pecm_time_flatW_xview_noSwap->Draw("");
887  // hits
888  TPaveText *tpPXNoS = new TPaveText(0.7,0.7,0.86,0.86,"NB NDC");
889  tpPXNoS->SetFillStyle(0);
890  tpPXNoS->AddText( TString::Format("Hits: %3.1f%%",100.0*prof_pecm_time_flatW_xview_noSwap->GetEntries()/prof_pecm_time_flatW_xview->GetEntries()) );
891  canv_pecm_time_flatW_xview_noSwap->cd();
892  tpPXNoS->Draw();
893  canv_pecm_time_flatW_xview_noSwap->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_pecm_time_flatW_xview_noSwap->GetName()) );
894 
895  TCanvas *canv_resp_time_flatW_yview_noSwap = new TCanvas();
896  prof_resp_time_flatW_yview_noSwap->GetXaxis()->SetRangeUser(t_lo,t_hi);
897  prof_resp_time_flatW_yview_noSwap->GetYaxis()->SetRangeUser(y_resp_lo,y_resp_hi);
898  prof_resp_time_flatW_yview_noSwap->GetXaxis()->SetTimeDisplay(1);
899  prof_resp_time_flatW_yview_noSwap->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
900  prof_resp_time_flatW_yview_noSwap->Draw("");
901  // hits
902  TPaveText *tpRYNoS = new TPaveText(0.7,0.7,0.86,0.86,"NB NDC");
903  tpRYNoS->SetFillStyle(0);
904  tpRYNoS->AddText( TString::Format("Hits: %3.1f%%",100.0*prof_resp_time_flatW_yview_noSwap->GetEntries()/prof_resp_time_flatW_yview->GetEntries()) );
905  canv_resp_time_flatW_yview_noSwap->cd();
906  tpRYNoS->Draw();
907  canv_resp_time_flatW_yview_noSwap->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_resp_time_flatW_yview_noSwap->GetName()) );
908 
909  TCanvas *canv_pecm_time_flatW_yview_noSwap = new TCanvas();
910  prof_pecm_time_flatW_yview_noSwap->GetXaxis()->SetRangeUser(t_lo,t_hi);
911  prof_pecm_time_flatW_yview_noSwap->GetYaxis()->SetRangeUser(y_pecm_lo,y_pecm_hi);
912  prof_pecm_time_flatW_yview_noSwap->GetXaxis()->SetTimeDisplay(1);
913  prof_pecm_time_flatW_yview_noSwap->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
914  prof_pecm_time_flatW_yview_noSwap->Draw("");
915  // hits
916  TPaveText *tpPYNoS = new TPaveText(0.7,0.7,0.86,0.86,"NB NDC");
917  tpPYNoS->SetFillStyle(0);
918  tpPYNoS->AddText( TString::Format("Hits: %3.1f%%",100.0*prof_pecm_time_flatW_yview_noSwap->GetEntries()/prof_pecm_time_flatW_yview->GetEntries()) );
919  canv_pecm_time_flatW_yview_noSwap->cd();
920  tpPYNoS->Draw();
921  canv_pecm_time_flatW_yview_noSwap->Print( TString::Format("%sOutput/Plots-ByPeriod/PlotTime-%s_%s.pdf",user_dir.c_str(),detector.c_str(),prof_pecm_time_flatW_yview_noSwap->GetName()) );
922  }
923 
924  return;
925 }
926 
927 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
928 // Make plots by reading in the csv file(s) for a particular run
929 // TODO: this function doesn't actually work properly at the moment. It's not run from the .cxx right now...
930 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
931 void PlotCSV( TFile* inFileData, std::string detector, std::string sample, std::string period, std::string outputName,
932  bool byDB, int runsPerDiv, std::string calibMethod, std::string user_dir ){
933  // Determine number of run divisions. 0 means calibrate monolithically.
934  long timeDiv=0;
935  long loRun(0),hiRun(0);
936  int fileRunsPerDiv(0);
937  TH1D *metadataPlot;
938  inFileData->GetObject("metadataPlot",metadataPlot);
939  if( metadataPlot ){
940  fileRunsPerDiv = metadataPlot->GetBinContent(2);
941  timeDiv = metadataPlot->GetBinContent(5);
942  loRun = metadataPlot->GetBinContent(3);
943  hiRun = metadataPlot->GetBinContent(4);
944  }
945 
946  if( fileRunsPerDiv!=runsPerDiv ){
947  std::cout << "WARNING!!!!!"
948  << "\n\t runsPerDiv requested (" << runsPerDiv << ") doesn't match what file produced with (" << fileRunsPerDiv << ") ..."
949  << "\n\t Defaulting to calibrate full file at once (runsPerDiv=0)..." << std::endl;
950  runsPerDiv=0;
951  timeDiv=0;
952  }
953 
954  unsigned int nChan = 14;
955  if( detector.find("fd")!=std::string::npos ) nChan = 14;
956  else if( detector.find("nd")!=std::string::npos ) nChan = 4;
957 
958  std::vector<int> vecRunLo; // Lowest run number in this section
959  std::vector<int> vecRunHi; // Highest run number in this section
960  std::vector< std::vector<double> > vecMEU; // PECorr/cm
961  vecMEU.resize( nChan );
962  std::vector< std::vector<double> > vecdEdx; // MeV/cm converted from GeV/cm
963  vecdEdx.resize( nChan );
964  std::vector< std::vector<double> > vecEScale; // PECorr/MeV
965  vecEScale.resize( nChan );
966 
967  for( int iTime=0; iTime<=timeDiv; ++iTime ){
968  if( runsPerDiv>0 && iTime==timeDiv ) break; // include iTime==0 when that's the only one, otherwise break when iTime==timeDiv
969  std::string csvName;
970  if(timeDiv==0 && metadataPlot) csvName = getOutputName(detector,period,sample,outputName,true,user_dir)+"_"+calibMethod+"_r"+std::to_string(loRun)+"-r"+std::to_string(hiRun)+".csv";
971  else if(timeDiv==0 && !metadataPlot) return; // only works on new version of CSVs
972  else csvName = getOutputName(detector,period,sample,outputName,true,user_dir)+
973  "_"+calibMethod+
974  "_r"+std::to_string(loRun+(iTime*runsPerDiv))+
975  "-r"+std::to_string(loRun+((iTime+1)*runsPerDiv)-1>hiRun ? hiRun : loRun+((iTime+1)*runsPerDiv)-1)+".csv";
976  // Read in the csv file and process it
977  std::ifstream csv( csvName.c_str(), std::ifstream::in );
978  std::string csvIn;
979  bool wroteRuns = false;
980  while( csv.good() ){
981  if( !wroteRuns ){
982  int theLoRun = loRun+(iTime*runsPerDiv);
983  int theHiRun = loRun+((iTime+1)*runsPerDiv)-1>hiRun ? hiRun : loRun+((iTime+1)*runsPerDiv)-1;
984  vecRunLo.push_back( theLoRun );
985  vecRunHi.push_back( theHiRun );
986  wroteRuns = true;
987  }
988  std::getline(csv,csvIn);
989  if( csvIn.empty() || csvIn.find("#")!=std::string::npos ) continue;
990  unsigned int comma1 = csvIn.find(",");
991  unsigned int comma2 = csvIn.find(",",comma1+1);
992  unsigned int comma3 = csvIn.find(",",comma2+1);
993  unsigned int comma4 = csvIn.find(",",comma3+1);
994  std::string strMEU = csvIn.substr(0,comma1);
995  std::string strdEdx = csvIn.substr(comma2+1,comma3-comma2);
996  std::string strDB = csvIn.substr(comma4+1,csvIn.length()-comma4);
997  int theDB = std::stoi(strDB);
998  vecMEU[theDB-1].push_back(std::stod(strMEU));
999  vecdEdx[theDB-1].push_back(std::stod(strdEdx)*1000.);
1000  vecEScale[theDB-1].push_back( std::stod(strMEU)/(std::stod(strdEdx)*1000.) );
1001  }
1002  }
1003 
1004  // Check sizes of vectors to make sure they agree
1005  /*
1006  if( vecRunLo.size()!=vecRunHi.size() || vecRunLo.size()!=vecMEU[0].size() || (byDB && vecRunLo.size()!=vecEScale[nChan-1].size()) ){
1007  std::cout << "Problem loading values... the sizes do not agree." << std::endl;
1008  std::cout << "vecRunLo.size() = " << vecRunLo.size() << std::endl;
1009  std::cout << "vecRunHi.size() = " << vecRunHi.size() << std::endl;
1010  std::cout << "vecMEU[0].size() = " << vecMEU[0].size() << std::endl;
1011  if( byDB ) std::cout << "vecESCale[nChan-1].size() = " << vecEScale[nChan-1].size() << std::endl;
1012  std::cout << "Returning..." << std::endl;
1013  return;
1014  }
1015  */
1016 
1017  // Now make plots of the three quantities
1018  const int nRunGroups = vecRunLo.size();
1019  double theBins[nRunGroups+1];
1020 
1021  std::cout << vecRunLo[0] << std::endl;
1022  theBins[0] = vecRunLo[0];
1023  for( int iRunGroup=0; iRunGroup<=nRunGroups; ++iRunGroup ){
1024  if( runsPerDiv>0 && iRunGroup==nRunGroups ) break; // include iTime==0 when that's the only one, otherwise break when iTime==timeDiv
1025  std::cout << vecRunHi[iRunGroup] << std::endl;
1026  theBins[iRunGroup+1] = vecRunHi[iRunGroup];
1027  }
1028 
1029  std::vector<TH1D*> histMEU;
1030  histMEU.resize(nChan);
1031  std::vector<TH1D*> histdEdx;
1032  histdEdx.resize(nChan);
1033  std::vector<TH1D*> histEScale;
1034  histEScale.resize(nChan);
1035 
1036  for( unsigned int iChan=0; iChan<nChan; ++iChan ){
1037  histMEU[iChan] = new TH1D( TString::Format("histMEU_%s_%u",calibMethod.c_str(),iChan+1), TString::Format(";%s Run Number;MEU [PECorr/cm]",detector.c_str()), nRunGroups, theBins );
1038  histdEdx[iChan] = new TH1D( TString::Format("histdEdx_%s_%u",calibMethod.c_str(),iChan+1), TString::Format(";%s Run Number;dE/dx [MeV/cm]",detector.c_str()), nRunGroups, theBins );
1039  histEScale[iChan] = new TH1D( TString::Format("histEScale_%s_%u",calibMethod.c_str(),iChan+1), TString::Format(";%s Run Number;Energy Scale [PECorr/MeV]",detector.c_str()), nRunGroups, theBins );
1040  }
1041 
1042  for( int iRunGroup=0; iRunGroup<nRunGroups+1; ++iRunGroup ){
1043  for( unsigned int iChan=0; iChan<nChan; ++iChan ){
1044  histMEU[iChan]->SetBinContent(iRunGroup+1,vecMEU[iChan][iRunGroup]);
1045  histdEdx[iChan]->SetBinContent(iRunGroup+1,vecdEdx[iChan][iRunGroup]);
1046  histEScale[iChan]->SetBinContent(iRunGroup+1,vecEScale[iChan][iRunGroup]);
1047  }
1048  }
1049 
1050  TCanvas *cMEU = new TCanvas();
1051  TLegend *lMEU = new TLegend(0.65,0.6,0.87,0.87);
1052 
1053  for( unsigned int iChan=0; iChan<nChan; ++iChan ){
1054  histMEU[iChan]->SetStats(0);
1055  histMEU[iChan]->SetLineColor(fColorWheel[iChan]);
1056  if( iChan==0 ) histMEU[iChan]->Draw("");
1057  else histMEU[iChan]->Draw("SAME");
1058  lMEU->AddEntry(histMEU[iChan]->GetName(),TString::Format("db %i",iChan+1),"l");
1059  }
1060 
1061  cMEU->Print(TString::Format("%sOutput/histMEU_%s_%s_pd%s.pdf",user_dir.c_str(),calibMethod.c_str(),byDB ? "byDB" : "monolithic",period.c_str()));
1062 
1063  TCanvas *cdEdx = new TCanvas();
1064  TLegend *ldEdx = new TLegend(0.65,0.6,0.87,0.87);
1065 
1066  for( unsigned int iChan=0; iChan<nChan; ++iChan ){
1067  histdEdx[iChan]->SetStats(0);
1068  histdEdx[iChan]->SetLineColor(fColorWheel[iChan]);
1069  if( iChan==0 ) histdEdx[iChan]->Draw("");
1070  else histdEdx[iChan]->Draw("SAME");
1071  ldEdx->AddEntry(histdEdx[iChan]->GetName(),TString::Format("db %i",iChan+1),"l");
1072  }
1073 
1074  cdEdx->Print(TString::Format("%sOutput/histdEdx_%s_%s_pd%s.pdf",user_dir.c_str(),calibMethod.c_str(),byDB ? "byDB" : "monolithic",period.c_str()));
1075 
1076 
1077  TCanvas *cEScale = new TCanvas();
1078  TLegend *lEScale = new TLegend(0.65,0.6,0.87,0.87);
1079 
1080  for( unsigned int iChan=0; iChan<nChan; ++iChan ){
1081  histEScale[iChan]->SetStats(0);
1082  histEScale[iChan]->SetLineColor(fColorWheel[iChan]);
1083  if( iChan==0 ) histEScale[iChan]->Draw("");
1084  else histEScale[iChan]->Draw("SAME");
1085  lEScale->AddEntry(histEScale[iChan]->GetName(),TString::Format("db %i",iChan+1),"l");
1086  }
1087 
1088  cEScale->Print(TString::Format("%sOutput/histEScale_%s_%s_pd%s.pdf",user_dir.c_str(),calibMethod.c_str(),byDB ? "byDB" : "monolithic",period.c_str()));
1089 
1090  return;
1091 }
1092 
1093 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1094 // Draw plots for a given data set (some overlap with validation web page and the above for all periods)
1095 // Mostly keeps stuff that wasn't commented out and made it to final version and then updated for new stuff.
1096 // Original version: "draw.C"
1097 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1098 void DrawPlots(TFile *inputFile, std::string det, std::string thisSample, std::string calibName, bool isMC, std::string my_dir){
1099  std::string outputDir = my_dir+"Output/Plots/"+calibName+"_"+thisSample;
1100 
1101  float meu_min, meu_max, pecm_min, pecm_max, true_min, true_max;
1102  float pe_x_min, pe_x_max, pe_y_min, pe_y_max;
1103  float dx_x_min, dx_x_max, dx_y_min, dx_y_max;
1104  float pecorrpe_min, pecorrpe_max;
1105  float pecorrmev_pe_min, pecorrmev_pe_max;
1106  float pecorrmev_w_min, pecorrmev_w_max;
1107  if(det=="nd"){
1108  meu_min = 30; meu_max = 55;
1109  pecm_min = 15; pecm_max = 70;
1110  true_min = 1.5; true_max = 2;
1111  pe_x_min = 0; pe_x_max = 400; // 50, 400
1112  pe_y_min = 0; pe_y_max = 400; // 40, 300
1113  dx_x_min = 3.3; dx_x_max = 6.5;
1114  dx_y_min = 3.5; dx_y_max = 5;
1115  pecorrpe_min=0; pecorrpe_max=2.;
1116  pecorrmev_pe_min=5; pecorrmev_pe_max=30;
1117  pecorrmev_w_min=15; pecorrmev_w_max=30;
1118  }
1119  if(det=="fd"){
1120  meu_min = 34; meu_max = 55;
1121  pecm_min = 0; pecm_max = 60;
1122  true_min = 1.5; true_max = 2;
1123  pe_x_min = 0; pe_x_max = 400; // 0, 300
1124  pe_y_min = 0; pe_y_max = 400; // 0, 200
1125  dx_x_min = 3.5; dx_x_max = 6.5;
1126  dx_y_min = 3.5; dx_y_max = 5;
1127  pecorrpe_min=-0.5; pecorrpe_max=7.5;
1128  pecorrmev_pe_min=10; pecorrmev_pe_max=30;
1129  pecorrmev_w_min=15; pecorrmev_w_max=30;
1130  }
1131 
1132  overlayFBplotsH("th1d_nhits_resp_xview-fbsplit",inputFile,outputDir);
1133  overlayFBplotsH("th1d_nhits_resp_yview-fbsplit",inputFile,outputDir);
1134  overlayFBplotsH("th1d_nhits_pecm_xview-fbsplit",inputFile,outputDir);
1135  overlayFBplotsH("th1d_nhits_pecm_yview-fbsplit",inputFile,outputDir);
1136  overlayFBplotsH("th1d_nhits_pe_xview-fbsplit",inputFile,outputDir);
1137  overlayFBplotsH("th1d_nhits_pe_yview-fbsplit",inputFile,outputDir);
1138  overlayFBplotsH("th1d_nhits_w_xview-fbsplit",inputFile,outputDir);
1139  overlayFBplotsH("th1d_nhits_w_yview-fbsplit",inputFile,outputDir);
1140  if(isMC){
1141  overlayFBplotsH("th1d_nhits_truededx_xview-fbsplit",inputFile,outputDir);
1142  overlayFBplotsH("th1d_nhits_truededx_yview-fbsplit",inputFile,outputDir);
1143  }
1144 
1145  // vs W
1146  overlayFBplots("tprof_resp_w_xview-fbsplit",inputFile,outputDir, 30, meu_max);
1147  overlayFBplots("tprof_resp_w_yview-fbsplit",inputFile,outputDir, 30, meu_max);
1148  overlayFBplots("tprof_pe_w_xview-fbsplit",inputFile,outputDir, pe_x_min,pe_x_max);
1149  overlayFBplots("tprof_pe_w_yview-fbsplit",inputFile,outputDir, pe_y_min,pe_y_max);
1150  overlayFBplots("tprof_pecm_w_xview-fbsplit",inputFile,outputDir, pecm_min,pecm_max);
1151  overlayFBplots("tprof_pecm_w_yview-fbsplit",inputFile,outputDir, pecm_min,pecm_max);
1152  overlayFBplots("tprof_pecm_w_xview-fbsplit",inputFile,outputDir, pecm_min,pecm_max);
1153  overlayFBplots("tprof_pecm_w_yview-fbsplit",inputFile,outputDir, pecm_min,pecm_max);
1154  overlayFBplots("tprof_dx_w_xview-fbsplit",inputFile,outputDir, dx_x_min,dx_x_max);
1155  overlayFBplots("tprof_dx_w_yview-fbsplit",inputFile,outputDir, dx_y_min,dx_y_max);
1156  overlayFBplots("tprof_pecorrpe_w_xview-fbsplit",inputFile,outputDir, pecorrpe_min,pecorrpe_max);
1157  overlayFBplots("tprof_pecorrpe_w_yview-fbsplit",inputFile,outputDir, pecorrpe_min,pecorrpe_max);
1158  overlayFBplots("tprof_resp_w_edgecells-xview-fbsplit",inputFile,outputDir, meu_min, meu_max);
1159  overlayFBplots("tprof_resp_w_edgecells-yview-fbsplit",inputFile,outputDir, meu_min, meu_max);
1160  if(isMC){
1161  overlayFBplots("tprof_truededx_w_xview-fbsplit",inputFile,outputDir, true_min,true_max);
1162  overlayFBplots("tprof_truededx_w_yview-fbsplit",inputFile,outputDir, true_min,true_max);
1163  overlayFBplots("tprof_pecorrmev_w_xview-fbsplit",inputFile,outputDir, pecorrmev_w_min,pecorrmev_w_max);
1164  overlayFBplots("tprof_pecorrmev_w_yview-fbsplit",inputFile,outputDir, pecorrmev_w_min,pecorrmev_w_max);
1165  }
1166 
1167 
1168  // vs PE
1169  overlayFBplots("tprof_resp_pe_xview-fbsplit",inputFile,outputDir, meu_min,meu_max);
1170  overlayFBplots("tprof_resp_pe_yview-fbsplit",inputFile,outputDir, meu_min,meu_max);
1171  overlayFBplots("tprof_pecorr_pe_xview-fbsplit",inputFile,outputDir, meu_min*3,meu_max*5);
1172  overlayFBplots("tprof_pecorr_pe_yview-fbsplit",inputFile,outputDir, meu_min*3,meu_max*5);
1173  overlayFBplots("tprof_pecorrpe_pe_xview-fbsplit",inputFile,outputDir, pecorrpe_min,pecorrpe_max);
1174  overlayFBplots("tprof_pecorrpe_pe_yview-fbsplit",inputFile,outputDir, pecorrpe_min,pecorrpe_max);
1175  if(isMC){
1176  overlayFBplots("tprof_pecorrmev_pe_xview-fbsplit",inputFile,outputDir, pecorrmev_pe_min,pecorrmev_pe_max);
1177  overlayFBplots("tprof_pecorrmev_pe_yview-fbsplit",inputFile,outputDir, pecorrmev_pe_min,pecorrmev_pe_max);
1178  overlayFBplots("tprof_pecorrmev_dE_xview-fbsplit",inputFile,outputDir, pecorrmev_w_min,pecorrmev_w_max);
1179  overlayFBplots("tprof_pecorrmev_dE_yview-fbsplit",inputFile,outputDir, pecorrmev_w_min,pecorrmev_w_max);
1180  }
1181 
1182 
1183  // NEED TO FIX BELOW HERE
1184  // NOTE: I think... I did? Check...
1185 
1186 
1187  TCanvas *c = new TCanvas("c","c");
1188  c->cd();
1189 
1190  // loop through all plots and print them
1191  TKey *key;
1192  TIter next(inputFile->GetListOfKeys());
1193  while ((key = (TKey*)next())) {
1194  TClass *cl = gROOT->GetClass(key->GetClassName());
1195  TH1 *th1 = (TH1*)key->ReadObj();
1196  std::string name = th1->GetName();
1197 
1198  if(name.find("-w.")!=std::string::npos) continue; // TODO: I think we don't make this any more... Check!
1199  if(name.find("-fbsplit")!=std::string::npos) continue;
1200  if(name.find("_range")!=std::string::npos) continue; // NOTE: for at least now skipping the various run range plots (if existing)
1201  if(name.find("_db")!=std::string::npos) continue; // NOTE: for at least now skipping the various by diblock plots (if existing)
1202  if(name.find("metadataPlot")!=std::string::npos) continue;
1203 
1204  // NOTE: this is commented out because unused...
1205  //bool xview = name.find("xview")!=std::string::npos;
1206  //bool yview = name.find("yview")!=std::string::npos;
1207 
1208  if (cl->InheritsFrom("TH2")){
1209  TH2 *h2 = (TH2*)key->ReadObj();
1210  gStyle->SetPalette(53);
1211  h2->Draw("colz");
1212  h2->SetStats(0);
1213  c->Print(Form("%s_%s.pdf",outputDir.c_str(),name.c_str()));
1214  }
1215  } // draw profiles and distributions seperately
1216 
1217  TProfile2D *tp2d_x, *tp2d_y, *tp2d;
1218 
1219  inputFile->GetObject("tprof2_pecm_cell-plane_xview",tp2d_x);
1220  inputFile->GetObject("tprof2_pecm_cell-plane_yview",tp2d_y);
1221  inputFile->GetObject("tprof2_pecm_cell-plane",tp2d);
1222  tp2d_x->SetTitle("Mean PE/cm (X View)");
1223  tp2d_x->SetStats(0);
1224  tp2d_y->SetTitle("Mean PE/cm (Y View)");
1225  tp2d_y->SetStats(0);
1226  gStyle -> SetPalette(53);
1227  tp2d_x->SetMinimum(0);
1228  tp2d_x->SetMaximum(100);
1229  tp2d_y->SetMinimum(0);
1230  tp2d_y->SetMaximum(100);
1231  tp2d_x->Draw("colz");
1232  c->Print(Form("%s_tprof2_pecm_cell-plane_xview.pdf",outputDir.c_str()));
1233  tp2d_y->Draw("colz");
1234  c->Print(Form("%s_tprof2_pecm_cell-plane_yview.pdf",outputDir.c_str()));
1235 
1236  tp2d->SetStats(0);
1237  //tp2d->SetMinimum(0.2*30);
1238  //tp2d->SetMaximum(1.8*30);
1239  tp2d->Draw("colz");
1240  c->Print(Form("%s_tprof2_pecm_cell-plane.pdf",outputDir.c_str()));
1241 
1242  int nbinsx = tp2d->GetXaxis()->GetNbins();
1243  int nbinsy = tp2d->GetYaxis()->GetNbins();
1244  int numCells = nbinsx*nbinsy;
1245  double avg=0.;
1246  for(int x=1; x<nbinsx; x++){
1247  for(int y=1; y<nbinsy; y++){
1248  avg += tp2d->GetBinContent(x,y)/numCells;
1249  }
1250  }
1251  tp2d->Scale(1/avg);
1252  tp2d->SetMinimum(0);
1253  tp2d->SetMaximum(2);
1254  tp2d->Draw("colz");
1255  c->Print(Form("%s_tprof2_pecmnorm_cell-plane.pdf",outputDir.c_str()));
1256 
1257 
1258  TCanvas *sq = new TCanvas("c","c",500,500);
1259  sq->cd();
1260  TProfile2D *profMEUreco_cell_w_x, *profMEUreco_w_cell_y;
1261  inputFile->GetObject("tprof2_resp_w-cell_xview",profMEUreco_cell_w_x);
1262  inputFile->GetObject("tprof2_resp_cell-w_yview",profMEUreco_w_cell_y);
1263  profMEUreco_cell_w_x->SetStats(0);
1264  profMEUreco_w_cell_y->SetStats(0);
1265  profMEUreco_cell_w_x->SetMinimum(36);
1266  profMEUreco_w_cell_y->SetMinimum(36);
1267  profMEUreco_cell_w_x->SetMaximum(44);
1268  gStyle -> SetPalette(53);
1269  profMEUreco_w_cell_y->SetMaximum(44);
1270  profMEUreco_cell_w_x->Draw("colz");
1271  //sq->Print(Form("%s/profMEUreco_cell_w_x_%s.pdf",sample.c_str(),plotname_suffix.c_str()));
1272  profMEUreco_w_cell_y->Draw("colz");
1273  //sq->Print(Form("%s/profMEUreco_w_cell_y_%s.pdf",sample.c_str(),plotname_suffix.c_str()));
1274 
1275  TH2D *stats_cell_w_x, *stats_w_cell_y;
1276  inputFile->GetObject("th2d_nhits_cell-w_xview",stats_cell_w_x);
1277  inputFile->GetObject("th2d_nhits_w-cell_yview",stats_w_cell_y);
1278  stats_cell_w_x->SetStats(0);
1279  stats_w_cell_y->SetStats(0);
1280  stats_cell_w_x->SetMinimum(0);
1281  stats_w_cell_y->SetMinimum(0);
1282  //stats_cell_w_x->SetMaximum(70);
1283  //stats_w_cell_y->SetMaximum(70);
1284  stats_cell_w_x->Draw("colz");
1285  sq->Print(Form("%s_th2d_nhits_cell-w_xview.pdf",outputDir.c_str()));
1286  stats_w_cell_y->Draw("colz");
1287  sq->Print(Form("%s_th2d_nhits_w-cell_yview.pdf",outputDir.c_str()));
1288 }
1289 
1290 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1291 // Draw data/MC plots for a given data set (some overlap with validation web page)
1292 // Mostly keeps stuff that wasn't commented out and made it to final version and then updated for new stuff.
1293 // Original version: "data_mc.C"
1294 // Only do 1 file at a time...
1295 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1296 void DrawDataMC( TFile *inputFile, TFile *mcFile, std::string det, std::string thisSample, std::string period,
1297  std::string mcName, std::string calibName, std::string my_dir, bool proton){
1298  std::string outputDir = my_dir+"Output/Plots-DataMC/"+calibName+"_"+thisSample;
1299 
1300  // NOTE: this is commented out because unused...
1301  //TCanvas *c = new TCanvas("c","data_vs_mc");
1302 
1303  // loop through all plots and print them
1304  TKey *key;
1305  TIter next(inputFile->GetListOfKeys());
1306  while ((key = (TKey*)next())) {
1307  TClass *cl = gROOT->GetClass(key->GetClassName());
1308  TH1 *th1 = (TH1*)key->ReadObj();
1309  std::string name = th1->GetName();
1310 
1311  if (cl->InheritsFrom("TH2")) continue;
1312 
1313  // NOTE: this is commented out because unused...
1314  //bool xview = name.find("xview")!=std::string::npos;
1315  //bool yview = name.find("yview")!=std::string::npos;
1316  //bool cell = name.find("cell")!=std::string::npos;
1317  //bool cell = name.find("plane")!=std::string::npos; //NOTE: This should probably be called plane...
1318  //bool fb = name.find("-fb")!=std::string::npos;
1319 
1320  // NOTE: new skip fiber brightness plots, diblock plots, metadata plot, and "true" plots
1321  // The ones named starting with "db" were intentionally not named according to convention to not get it into the Validation code
1322  if( name.find("-fb")!=std::string::npos || name.find("-db")!=std::string::npos || name.substr(0,2).compare("db")==0 ) continue;
1323  if( name.find("metadata")!=std::string::npos ) continue;
1324  if( name.find("true")!=std::string::npos ) continue;
1325 
1326  float ymin(0.), ymax(600.);
1327  if(det=="nd"){
1328  if(name.find("tprof_pecorrpe_")!=std::string::npos){ ymin=0.4; ymax=1.6; }
1329  if(name.find("tprof_pecorr_")!=std::string::npos){ ymin=0; ymax=600; }
1330  if(name.find("tprof_pe_")!=std::string::npos){ ymin=100; ymax=600; }
1331  if(name.find("tprof_pecm_")!=std::string::npos){ ymin=0; ymax=80; }
1332  if(name.find("tprof_resp_")!=std::string::npos){ ymin=0; ymax=80; }
1333  if(name.find("tprof_dx_")!=std::string::npos){ ymin=3; ymax=20; }
1334  if(name.find("tprof_recodedx_")!=std::string::npos){ ymin=1.4; ymax=2.4; }
1335 
1336  if(proton){
1337  if(name.find("tprof_pecorr_")!=std::string::npos){ ymin=0; ymax=1300; }
1338  if(name.find("tprof_pe_")!=std::string::npos){ ymin=200; ymax=1300; }
1339  if(name.find("tprof_resp_")!=std::string::npos){ ymin=0; ymax=150; }
1340  if(name.find("tprof_pecm_")!=std::string::npos){ ymin=0; ymax=150; }
1341  if(name.find("tprof_recodedx_")!=std::string::npos){ ymin=0; ymax=7; }
1342  }
1343  }
1344  if(det=="fd"){
1345  if(name.find("tprof_pecorrpe_")!=std::string::npos){ ymin=0.4; ymax=1.6; }
1346  if(name.find("tprof_pecorr_")!=std::string::npos){ ymin=0; ymax=600; }
1347  if(name.find("tprof_pe_")!=std::string::npos){ ymin=100; ymax=600; }
1348  if(name.find("tprof_pecm_")!=std::string::npos){ ymin=0; ymax=80; }
1349  if(name.find("tprof_resp_")!=std::string::npos){ ymin=30; ymax=55; }
1350  if(name.find("tprof_dx_")!=std::string::npos){ ymin=3; ymax=20; }
1351  if(name.find("tprof_recodedx_")!=std::string::npos){ ymin=0; ymax=7; }
1352  }
1353 
1354  if ( cl->InheritsFrom("TProfile") )
1355  data_over_mc_profile( name, inputFile, mcFile, calibName, outputDir, det, period, mcName, ymin, ymax);
1356  }
1357 }
const XML_Char * name
Definition: expat.h:151
TFile * inputFile
Definition: PlotXSec.C:134
const std::vector< std::string > profileVector
Definition: FennecFnc.h:3
void overlayFBplots(std::string name, TFile *temp, std::string outputDir, float ymin, float ymax, float meu=-1.)
Definition: FennecFnc.h:393
string output_name
Pickle.
double stod(const std::string &val)
const std::vector< std::string > histo2DVector
Definition: FennecFnc.h:37
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
double maxY
Definition: plot_hist.C:10
Double_t ymax
Definition: plot.C:25
std::string GetName(int i)
void MakeValidation(std::string calibName, std::string detector, std::string period, std::string sample, std::string outputName, std::string user_dir, std::string user_name, std::string fileProfile, std::string fileHisto1D, std::string fileHisto2D)
Definition: FennecPlot.h:4
void MakeTimeSeries(std::string detector, bool byDB, unsigned int nDB, std::string calibName, std::string user_dir, TProfile *prof_resp_time_flatW_xview, TProfile *prof_resp_time_flatW_yview, TProfile *prof_pecm_time_flatW_xview, TProfile *prof_pecm_time_flatW_yview, TProfile *prof_pe_time_flatW_xview, TProfile *prof_pe_time_flatW_yview, TProfile *prof_resp_time_flatW_comboview, TProfile *prof_pecm_time_flatW_comboview, TProfile *prof_pe_time_flatW_comboview, TProfile *prof_resp_time_flatW_xview_loW, TProfile *prof_resp_time_flatW_xview_mdW, TProfile *prof_resp_time_flatW_xview_hiW, TProfile *prof_pecm_time_flatW_xview_loW, TProfile *prof_pecm_time_flatW_xview_mdW, TProfile *prof_pecm_time_flatW_xview_hiW, TProfile *prof_resp_time_flatW_yview_loW, TProfile *prof_resp_time_flatW_yview_mdW, TProfile *prof_resp_time_flatW_yview_hiW, TProfile *prof_pecm_time_flatW_yview_loW, TProfile *prof_pecm_time_flatW_yview_mdW, TProfile *prof_pecm_time_flatW_yview_hiW, TProfile *prof_resp_time_flatW_xview_noSwap, TProfile *prof_pecm_time_flatW_xview_noSwap, TProfile *prof_resp_time_flatW_yview_noSwap, TProfile *prof_pecm_time_flatW_yview_noSwap, TProfile *prof_pecm_time_flatW_xview_db[14], TProfile *prof_pecm_time_flatW_yview_db[14], bool useNoSwap)
Definition: FennecPlot.h:423
const std::vector< int > fColorWheel
Definition: FennecFnc.h:109
OStream cout
Definition: OStream.cxx:6
TH1F * h2
Definition: plot.C:45
void PlotCSV(TFile *inFileData, std::string detector, std::string sample, std::string period, std::string outputName, bool byDB, int runsPerDiv, std::string calibMethod, std::string user_dir)
Definition: FennecPlot.h:931
void data_over_mc_profile(std::string plotname, TFile *data_f, TFile *mc_f, std::string calibName, std::string outputDir, std::string det, std::string data_name, std::string mc_name, float ymin=0, float ymax=0, float rat_min=0.8, float rat_max=1.2)
Definition: FennecFnc.h:534
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
gStyle SetPalette(1)
ifstream in
Definition: comparison.C:7
std::string getOutputName(std::string detector, std::string period, std::string sample, std::string outName, bool appendRoot, std::string user_dir)
Function to determine output file name.
Definition: FennecFnc.h:221
Int_t nbinsx
Definition: plot.C:23
const std::vector< std::string > histo1DVector
Definition: FennecFnc.h:21
Double_t ymin
Definition: plot.C:24
std::string dataName
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
void overlayFBplotsH(std::string name, TFile *temp, std::string outputDir)
Definition: FennecFnc.h:453
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
void DrawPlots(TFile *inputFile, std::string det, std::string thisSample, std::string calibName, bool isMC, std::string my_dir)
Definition: FennecPlot.h:1098
void makeRatioPlot(TCanvas *tC, TLegend *tL, std::vector< TProfile * > hVec, std::string hName, std::vector< std::string > hPlotNames, std::string calibName, std::string user_dir)
Definition: FennecFnc.h:745
void next()
Definition: show_event.C:84
void DrawDataMC(TFile *inputFile, TFile *mcFile, std::string det, std::string thisSample, std::string period, std::string mcName, std::string calibName, std::string my_dir, bool proton)
Definition: FennecPlot.h:1296
void InvestigatePeriods(std::vector< TFile * > myFiles, std::vector< std::string > thePeriods, std::string calibName, std::string user_dir, std::string fileProfile, std::string fileHisto1D)
Definition: FennecPlot.h:96