FennecFnc.h
Go to the documentation of this file.
1 // VARIABLES AND INFORMATION THAT MIGHT CHANGE FROM USER TO USER, TIME TO TIME, AND/OR CASE TO CASE.
2 // ADJUST THESE FOR YOUR NEEDS!
3 const std::vector<std::string> profileVector = {"tprof_pecm_w_xview",
4  "tprof_pecm_w_yview",
5  "tprof_resp_w_xview",
6  "tprof_resp_w_yview",
7  "tprof_pecm_fbbin_xview",
8  "tprof_pecm_fbbin_yview",
9  "tprof_resp_fbbin_xview",
10  "tprof_resp_fbbin_yview",
11  "tprof_dx_w_xview",
12  "tprof_dx_w_yview",
13  "tprof_pecm_plane_xview",
14  "tprof_pecm_plane_yview",
15  "tprof_resp_plane_xview",
16  "tprof_resp_plane_yview",
17  "tprof_resp_dx_xview",
18  "tprof_resp_dx_yview",
19  "tprof_dxres_truedx_xview",
20  "tprof_dxres_truedx_yview"};
21 const std::vector<std::string> histo1DVector = {"th1d_nhits_dx_xview",
22  "th1d_nhits_dx_yview",
23  "th1d_nhits_w_xview",
24  "th1d_nhits_w_yview",
25  "th1d_nhits_resp_xview",
26  "th1d_nhits_resp_yview",
27  "th1d_nhits_pecm_xview",
28  "th1d_nhits_pecm_yview",
29  "th1d_nhits_resp_flatW_xview",
30  "th1d_nhits_resp_flatW_yview",
31  "th1d_nhits_truededx_flatW_xview",
32  "th1d_nhits_truededx_flatW_yview",
33  "th1d_nhits_recodedx_flatW_xview",
34  "th1d_nhits_recodedx_flatW_yview",
35  "th1d_nhits_truedx_xview",
36  "th1d_nhits_truedx_yview"};
37 const std::vector<std::string> histo2DVector = {"th2d_uncalib_cell-plane",
38  "th2d_uncalib_cell-plane_xview",
39  "th2d_uncalib_cell-plane_yview"};
40 
41 // Far Detector Hardware Swaps (FEB and/or APD) since switching to gain 150. Can be used to include or exclude swapped components.
42 // Thanks to Louise and Tom Wieber for a list of FEB and APD swaps at the Far Detector
43 // I took the CSVs and grabbed block-plane-module coordinates from swaps since switching to gain 150 (12 Oct 2015)
44 // Then in Excel ordered and converted these to detector plane (0-895) and module (0-11).
45 std::vector< std::pair<int,int> > fdHardwareSwaps =
46  {{2,11},{6,9},{10,2},{11,3},{12,8},{15,8},{16,5},{17,5},{18,11},{23,9},{24,11},{26,3},{29,9},{29,11},{32,10},
47  {33,3},{33,8},{35,8},{39,9},{41,11},{42,4},{43,10},{49,8},{49,10},{51,4},{51,5},{52,10},{52,11},{53,3},{53,11},
48  {55,4},{57,0},{60,8},{60,10},{60,11},{63,10},{63,11},{64,1},{65,11},{66,5},{67,9},{68,2},{68,10},{70,6},{73,11},
49  {74,9},{76,2},{76,10},{78,2},{78,6},{80,2},{80,9},{81,9},{84,11},{87,11},{88,0},{88,4},{88,5},{88,8},{89,1},
50  {90,10},{91,5},{92,1},{92,6},{93,11},{94,3},{95,11},{96,3},{96,6},{96,7},{97,1},{98,11},{102,0},{104,4},{104,10},
51  {105,10},{105,11},{106,5},{109,6},{110,10},{111,0},{114,11},{115,8},{118,7},{120,4},{120,10},{122,10},{124,5},
52  {124,9},{125,1},{125,7},{125,9},{134,2},{144,2},{145,10},{148,11},{158,7},{167,2},{167,3},{168,5},{171,5},{177,8},
53  {182,2},{182,4},{182,5},{187,0},{194,6},{197,3},{197,10},{202,4},{204,10},{205,10},{213,8},{223,9},{225,0},{226,6},
54  {228,5},{229,5},{230,2},{230,10},{231,3},{232,5},{232,6},{234,5},{234,10},{235,5},{237,3},{243,3},{243,6},{243,7},
55  {245,0},{245,8},{247,6},{248,6},{251,6},{253,0},{253,7},{253,9},{254,1},{254,6},{255,11},{257,0},{259,7},{261,7},
56  {262,2},{263,2},{270,0},{271,4},{277,2},{277,3},{277,5},{281,5},{283,0},{283,3},{284,10},{287,3},{288,2},{291,0},
57  {291,3},{293,2},{296,2},{300,9},{301,0},{301,6},{304,2},{304,8},{305,4},{305,5},{305,11},{309,5},{310,1},{311,7},
58  {314,0},{316,4},{319,9},{320,2},{320,5},{326,6},{329,7},{329,11},{330,3},{330,4},{332,0},{334,2},{335,9},{335,10},
59  {336,7},{337,9},{337,10},{338,1},{338,5},{340,0},{340,2},{340,5},{341,3},{342,5},{344,6},{345,8},{345,10},{347,9},
60  {347,11},{349,4},{350,0},{351,8},{353,5},{354,4},{361,10},{362,3},{363,3},{366,9},{367,7},{369,7},{371,1},{372,5},
61  {375,6},{376,4},{379,10},{380,3},{380,4},{380,6},{380,10},{381,0},{381,4},{383,4},{383,9},{384,4},{387,2},{387,5},
62  {388,5},{390,0},{391,7},{392,4},{392,6},{392,8},{393,10},{394,1},{394,3},{394,5},{394,6},{394,11},{395,8},{396,0},
63  {396,3},{396,4},{397,2},{398,7},{399,3},{400,1},{400,4},{401,8},{402,4},{402,5},{403,6},{403,8},{407,4},{407,7},
64  {408,7},{417,8},{420,7},{421,8},{424,2},{431,8},{440,11},{441,8},{444,5},{444,10},{447,11},{449,0},{449,8},{451,5},
65  {451,7},{452,5},{453,1},{455,7},{457,3},{459,10},{461,3},{465,3},{466,5},{466,8},{467,3},{470,1},{471,6},{474,6},
66  {475,3},{476,0},{477,11},{479,11},{481,7},{481,11},{491,11},{494,11},{497,11},{499,7},{502,5},{506,9},{507,4},
67  {508,5},{509,1},{509,10},{510,6},{510,8},{512,0},{512,1},{513,10},{515,1},{520,0},{521,2},{521,10},{522,9},{523,9},
68  {536,1},{541,9},{542,5},{544,1},{544,8},{545,9},{547,0},{548,1},{554,0},{554,9},{556,1},{559,3},{564,1},{565,3},
69  {566,1},{566,4},{568,4},{570,4},{571,6},{573,1},{575,6},{579,9},{583,5},{583,6},{584,4},{585,10},{591,4},{593,1},
70  {594,9},{596,3},{596,11},{597,8},{598,5},{602,7},{605,8},{610,5},{616,6},{616,8},{624,10},{626,1},{627,9},{632,1},
71  {635,8},{636,1},{636,4},{639,11},{646,1},{647,3},{653,9},{655,2},{660,1},{665,0},{665,9},{670,4},{672,2},{673,7},
72  {675,2},{681,4},{683,8},{684,11},{686,9},{697,1},{699,6},{702,0},{702,10},{704,5},{705,1},{706,11},{709,0},{709,5},
73  {709,7},{710,2},{711,7},{714,5},{721,7},{721,11},{725,0},{725,1},{725,10},{726,2},{726,3},{727,6},{728,11},{730,0},
74  {731,5},{738,8},{739,7},{739,9},{742,9},{748,3},{749,0},{750,2},{750,4},{752,9},{754,11},{757,5},{757,10},{758,0},
75  {762,6},{764,3},{768,1},{769,4},{773,10},{778,10},{779,2},{780,5},{780,11},{784,8},{784,10},{791,3},{792,9},{793,5},
76  {795,6},{795,10},{797,3},{798,10},{799,3},{801,0},{803,1},{803,7},{803,8},{804,11},{805,4},{807,9},{808,1},{809,7},
77  {811,0},{811,11},{814,1},{814,5},{815,3},{815,6},{816,0},{817,3},{822,4},{823,2},{823,4},{824,7},{826,11},{827,5},
78  {827,6},{828,3},{831,3},{832,2},{832,10},{833,0},{834,1},{834,9},{835,9},{837,10},{838,3},{838,9},{841,6},{843,2},
79  {844,7},{844,10},{845,1},{848,2},{848,4},{854,6},{854,8},{856,8},{857,1},{858,2},{858,4},{859,0},{860,10},{862,0},
80  {865,2},{867,7},{870,0},{872,3},{874,5},{876,11},{877,10},{879,7},{881,6},{881,11},{882,0},{882,2},{891,4},{891,7},
81  {892,1},{892,10},{893,6},{893,8},{895,3},{895,11}}; // 0th index = detector plane, 1st index = module
82 
83 bool checkSwap(int plane, int mod){
84  // Returns true if channel has NOT been swapped during high gain FD running
85 
86  // In case need to debug, should be 499 swaps
87  // std::cout << fdHardwareSwaps.size() << std::endl;
88 
89  for( unsigned int iSwap=0; iSwap<fdHardwareSwaps.size(); ++iSwap ){
90  if( fdHardwareSwaps[iSwap].first > plane ) return true; // list is ordered
91  if( plane == fdHardwareSwaps[iSwap].first &&
92  mod == fdHardwareSwaps[iSwap].second )
93  return false; // this channel has been swapped
94  }
95 
96  return true; // shouldn't ever reach this point, but just in case
97 }
98 
99 // Cuts used to pick out hits for absolute calibration
100 bool cut_Track_Window(double x){
101  return (x<200) && (x>100);
102 }
103 
104 bool cut_PE(double pe){
105  return 0 < pe;
106 }
107 
108 // Some global variables
109 const std::vector<int> fColorWheel = {kBlack, kBlue+1, kRed, kMagenta, kGray+2, kGreen+2, kCyan, kGreen, kOrange+6, kViolet-3, kAzure+9, kMagenta-9, kYellow-3, kRed+1 };
110 
111 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
112 // File naming
113 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
114 /// Function to get the input file name
116  std::string fullPath;
117 
118  // If the sample input is a location on /nova/, choose that
119  if(sample.find("/nova/")!=std::string::npos || sample.find("/pnfs/")!=std::string::npos){
120  fullPath = sample;
121  return fullPath;
122  }
123 
124  // Table of currently produced files:
125  // Using Tyler's produced files for periods 2 through 5 (ana2017)
126  if( detector.find("fd")!=std::string::npos && period.find("mc_gain100")!=std::string::npos )
127  fullPath = "/nova/ana/users/talion/absana_fdmc_highstats/fd_mc_gain100/merged.root";
128  else if( detector.find("fd")!=std::string::npos && period.find("mc_gain140")!=std::string::npos )
129  fullPath = "/nova/ana/users/talion/absana_fdmc_highstats/fd_mc_gain140/merged.root";
130  else if( detector.find("fd")!=std::string::npos && period.find("2")!=std::string::npos )
131  fullPath = "/nova/ana/users/talion/absana_3A_v2light_real/fd_data_epoch2b/merged.root";
132  else if( detector.find("fd")!=std::string::npos && period.find("3")!=std::string::npos )
133  fullPath = "/nova/ana/users/talion/absana_3A_v2light_real/fd_data_epoch3b/merged.root";
134  else if( detector.find("fd")!=std::string::npos && period.find("4")!=std::string::npos )
135  fullPath = "/nova/ana/users/talion/absana_3A_v2light_real/fd_data_epoch4a/merged.root";
136  else if( detector.find("fd")!=std::string::npos && period.find("5")!=std::string::npos )
137  fullPath = "/nova/ana/users/talion/absana_3A_v2light_real/fd_data_epoch5a/merged.root";
138 
139  else if( detector.find("nd")!=std::string::npos && period.find("mc")!=std::string::npos )
140  fullPath = "/nova/ana/users/talion/absana_nofb/nd_mc/merged.root";
141  else if( detector.find("nd")!=std::string::npos && period.find("2")!=std::string::npos )
142  fullPath = "/nova/ana/users/talion/absana_nofb/nd_data_period2/merged.root";
143  else if( detector.find("nd")!=std::string::npos && period.find("3")!=std::string::npos )
144  fullPath = "/nova/ana/users/talion/absana_nofb/nd_data_period3/merged.root";
145  else if( detector.find("nd")!=std::string::npos && period.find("4")!=std::string::npos )
146  fullPath = "/nova/ana/users/talion/absana_nofb/nd_data_epoch4a/merged.root";
147  else if( detector.find("nd")!=std::string::npos && period.find("5")!=std::string::npos )
148  fullPath = "/nova/ana/users/talion/absana_nofb/nd_data_epoch5a/merged.root";
149 
150  // Using Bruce's produced files for periods 6 and 7 (ana2018)
151  else if( detector.find("fd")!=std::string::npos && period.find("6")!=std::string::npos )
152  fullPath = "/nova/ana/users/howard/absana_3A_v2light_real/fd_data_epoch6a/merged.root";
153  else if( detector.find("fd")!=std::string::npos && period.find("7a")!=std::string::npos )
154  fullPath = "/nova/ana/users/howard/absana_3A_v2light_real/fd_data_epoch7a_Ana2018/merged.root";
155  else if( detector.find("fd")!=std::string::npos && period.find("7b")!=std::string::npos )
156  fullPath = "/nova/ana/users/howard/absana_3A_v2light_real/fd_data_epoch7b_Ana2018/merged.root";
157  else if( detector.find("fd")!=std::string::npos && period.find("7")!=std::string::npos ){
158  std::cout << "WARNING!!!!!! "
159  << "\n\t You have asked for Period7. Period7 has separate files for 7a and 7b."
160  << "\n\t Choosing 7a by default. You can pick 7a or 7b by entering this for --pd" << std::endl;
161  fullPath = "/nova/ana/users/howard/absana_3A_v2light_real/fd_data_epoch7a_Ana2018/merged.root";
162  }
163 
164  else if( detector.find("nd")!=std::string::npos && period.find("6")!=std::string::npos )
165  fullPath = "/nova/ana/users/howard/absana_nofb/nd_data_epoch6a_Ana2018/merged.root";
166  else if( detector.find("nd")!=std::string::npos && period.find("7a")!=std::string::npos )
167  fullPath = "/nova/ana/users/howard/absana_nofb/nd_data_epoch7a_Ana2018/merged.root";
168  else if( detector.find("nd")!=std::string::npos && period.find("7b")!=std::string::npos )
169  fullPath = "/nova/ana/users/howard/absana_nofb/nd_data_epoch7b_Ana2018/merged.root";
170  else if( detector.find("nd")!=std::string::npos && period.find("7d")!=std::string::npos )
171  fullPath = "/nova/ana/users/yzhang/nd_data_period7d/merged.root";
172  else if( detector.find("nd")!=std::string::npos && period.find("7")!=std::string::npos ){
173  std::cout << "WARNING!!!!!! "
174  << "\n\t You have asked for Period7. Period7 has separate files for 7a, 7b, and 7d."
175  << "\n\t Choosing 7a by default. You can pick 7a, 7b, or 7c by entering this for --pd" << std::endl;
176  fullPath = "/nova/ana/users/howard/absana_nofb/nd_data_epoch7a_Ana2018/merged.root";
177  }
178  else if( detector.find("nd")!=std::string::npos && period.find("8")!=std::string::npos ){
179  fullPath = "/nova/ana/users/yzhang/nd_data_period8/merged.root"; // Preliminary 8b file
180  }
181 
182  if(fullPath.size()==0){
183  std::cout << "ERROR!!!!! "
184  << "\n\t You have a blank file path. This means the program doesn't know which calibration product to load!"
185  << "\n\t Exiting..." << std::endl;
186  exit(EXIT_FAILURE);
187  }
188 
189  return fullPath;
190 }
191 
192 /// Function to determine MC sample name
194  std::string theMCName;
195 
196  if( detector.find("nd")!=std::string::npos ){
197  theMCName = "mc";
198  return theMCName;
199  }
200  else if( detector.find("fd")!=std::string::npos && period.find("2")!=std::string::npos ){
201  theMCName = "mc_gain100";
202  return theMCName;
203  }
204  else if( detector.find("fd")!=std::string::npos ){
205  theMCName = "mc_gain140";
206  if( period.find("9999")!=std::string::npos ){
207  std::cout << "Note... You are using the default period 9999 which means"
208  << " the MC file may not match your expectation!!!"
209  << "\n\t You are loading the FD gain 140 MC..."
210  << "\n\t If this is in writing CSVs, it means the dE/dx and"
211  << "\n\t energy scale may not be what you expect, but the MEU"
212  << "\n\t in \"nominal\" mode comes from the data..." << std::endl;
213  }
214  return theMCName;
215  }
216 
217  return "";
218 }
219 
220 /// Function to determine output file name
222  std::string fullPath;
223  std::string specialName;
224 
225  // Files from Stefano are special
226  if( !appendRoot && sample.find("/nova/ana/users/sgermani")!=std::string::npos ){
227  if (sample.find("_MC_")!=std::string::npos) specialName="remid/nd_mc";
228  if (sample.find("_Cry_")!=std::string::npos) specialName="remid/fd_mc_gain100";
229  if (sample.find("_Data_")!=std::string::npos) specialName="remid/nd_data_period2";
230  if (sample.find("_CROverlay_")!=std::string::npos) specialName="remid/fd_data_epoch2b";
231 
232  fullPath = specialName+"/plot_abstree.root";
233  return fullPath;
234  }
235  else if( sample.length()>0 ){
236  // NOTE: For a CSV with custom input, use sample for the input and outName for the csv...
237  return sample;
238  }
239 
240  if( !appendRoot && outName.length()>0 ){
241  if( outName.find(".root")==std::string::npos ) return outName+".root";
242  else{
243  std::cout << "WARNING!!!!!! "
244  << "\n\t You are using a custom output file name that does NOT have .root - this is not allowed!"
245  << "\n\t Defaulting to custom_plot_abstree.root" << std::endl;
246  fullPath = "custom_plot_abstree.root";
247  return fullPath;
248  }
249  }
250  if( appendRoot && outName.length()>0 ){
251  if( outName.find(".csv")==std::string::npos ) return outName;
252  else{
253  std::cout << "WARNING!!!!!! "
254  << "\n\t You are using a custom output file name that DOES have .csv - this is not allowed!"
255  << "\n\t The extension is added later. Defaulting to custom_abscal" << std::endl;
256  fullPath = "custom_abscal";
257  return fullPath;
258  }
259  }
260 
261  fullPath+=user_dir;
262  fullPath+="Output/";
263 
264  // Determine name from detector and period
265  if( !appendRoot ){
266  if( detector.find("fd")!=std::string::npos && period.find("mc_gain100")!=std::string::npos )
267  fullPath += "fd_mc_gain100/plot_abstree.root";
268  else if( detector.find("fd")!=std::string::npos && period.find("mc_gain140")!=std::string::npos )
269  fullPath += "fd_mc_gain140/plot_abstree.root";
270  else if( detector.find("fd")!=std::string::npos && period.find("2")!=std::string::npos )
271  fullPath += "fd_data_epoch2b/plot_abstree.root";
272  else if( detector.find("fd")!=std::string::npos && period.find("3")!=std::string::npos )
273  fullPath += "fd_data_epoch3b/plot_abstree.root";
274  else if( detector.find("fd")!=std::string::npos && period.find("4")!=std::string::npos )
275  fullPath += "fd_data_epoch4a/plot_abstree.root";
276  else if( detector.find("fd")!=std::string::npos && period.find("5")!=std::string::npos )
277  fullPath += "fd_data_epoch5a/plot_abstree.root";
278  else if( detector.find("fd")!=std::string::npos && period.find("6")!=std::string::npos )
279  fullPath += "fd_data_epoch6a/plot_abstree.root";
280  else if( detector.find("fd")!=std::string::npos && period.find("7a")!=std::string::npos )
281  fullPath += "fd_data_epoch7a/plot_abstree.root";
282  else if( detector.find("fd")!=std::string::npos && period.find("7b")!=std::string::npos )
283  fullPath += "fd_data_epoch7b/plot_abstree.root";
284  else if( detector.find("fd")!=std::string::npos && period.find("7")!=std::string::npos ){
285  std::cout << "WARNING!!!!!! "
286  << "\n\t You have asked for Period7. Period7 has separate files for 7a and 7b."
287  << "\n\t Choosing 7a by default. You can pick 7a or 7b by entering this for --pd" << std::endl;
288  fullPath += "fd_data_epoch7a/plot_abstree.root";
289  }
290 
291  else if( detector.find("nd")!=std::string::npos && period.find("mc")!=std::string::npos )
292  fullPath += "nd_mc/plot_abstree.root";
293  else if( detector.find("nd")!=std::string::npos && period.find("2")!=std::string::npos )
294  fullPath += "nd_data_period2/plot_abstree.root";
295  else if( detector.find("nd")!=std::string::npos && period.find("3")!=std::string::npos )
296  fullPath += "nd_data_period3/plot_abstree.root";
297  else if( detector.find("nd")!=std::string::npos && period.find("4")!=std::string::npos )
298  fullPath += "nd_data_epoch4a/plot_abstree.root";
299  else if( detector.find("nd")!=std::string::npos && period.find("5")!=std::string::npos )
300  fullPath += "nd_data_epoch5a/plot_abstree.root";
301  else if( detector.find("nd")!=std::string::npos && period.find("6")!=std::string::npos )
302  fullPath += "nd_data_epoch6a/plot_abstree.root";
303  else if( detector.find("nd")!=std::string::npos && period.find("7a")!=std::string::npos )
304  fullPath += "nd_data_epoch7a/plot_abstree.root";
305  else if( detector.find("nd")!=std::string::npos && period.find("7b")!=std::string::npos )
306  fullPath += "nd_data_epoch7b/plot_abstree.root";
307  else if( detector.find("nd")!=std::string::npos && period.find("7d")!=std::string::npos )
308  fullPath += "nd_data_epoch7d/plot_abstree.root";
309  else if( detector.find("nd")!=std::string::npos && period.find("7")!=std::string::npos ){
310  std::cout << "WARNING!!!!!! "
311  << "\n\t You have asked for Period7. Period7 has separate files for 7a, 7b, and 7d."
312  << "\n\t Choosing 7a by default. You can pick 7a, 7b, or 7d by entering this for --pd" << std::endl;
313  fullPath += "nd_data_epoch7a/plot_abstree.root";
314  }
315  else if( detector.find("nd")!=std::string::npos && period.find("8")!=std::string::npos ){
316  fullPath += "nd_data_epoch8b/plot_abstree.root";
317  }
318  }
319  if( appendRoot ){
320  if( detector.find("fd")!=std::string::npos && period.find("mc_gain100")!=std::string::npos )
321  fullPath += "fd_mc_gain100_abscal";
322  else if( detector.find("fd")!=std::string::npos && period.find("mc_gain140")!=std::string::npos )
323  fullPath += "fd_mc_gain140_abscal";
324  else if( detector.find("fd")!=std::string::npos && period.find("2")!=std::string::npos )
325  fullPath += "fd_data_epoch2b_abscal";
326  else if( detector.find("fd")!=std::string::npos && period.find("3")!=std::string::npos )
327  fullPath += "fd_data_epoch3b_abscal";
328  else if( detector.find("fd")!=std::string::npos && period.find("4")!=std::string::npos )
329  fullPath += "fd_data_epoch4a_abscal";
330  else if( detector.find("fd")!=std::string::npos && period.find("5")!=std::string::npos )
331  fullPath += "fd_data_epoch5a_abscal";
332  else if( detector.find("fd")!=std::string::npos && period.find("6")!=std::string::npos )
333  fullPath += "fd_data_epoch6a_abscal";
334  else if( detector.find("fd")!=std::string::npos && period.find("7a")!=std::string::npos )
335  fullPath += "fd_data_epoch7a_abscal";
336  else if( detector.find("fd")!=std::string::npos && period.find("7b")!=std::string::npos )
337  fullPath += "fd_data_epoch7b_abscal";
338  else if( detector.find("fd")!=std::string::npos && period.find("7")!=std::string::npos ){
339  std::cout << "WARNING!!!!!! "
340  << "\n\t You have asked for Period7. Period7 has separate files for 7a and 7b."
341  << "\n\t Choosing 7a by default. You can pick 7a or 7b by entering this for --pd" << std::endl;
342  fullPath += "fd_data_epoch7a_abscal";
343  }
344 
345  else if( detector.find("nd")!=std::string::npos && period.find("mc")!=std::string::npos )
346  fullPath += "nd_mc_abscal";
347  else if( detector.find("nd")!=std::string::npos && period.find("2")!=std::string::npos )
348  fullPath += "nd_data_period2_abscal";
349  else if( detector.find("nd")!=std::string::npos && period.find("3")!=std::string::npos )
350  fullPath += "nd_data_period3_abscal";
351  else if( detector.find("nd")!=std::string::npos && period.find("4")!=std::string::npos )
352  fullPath += "nd_data_epoch4a_abscal";
353  else if( detector.find("nd")!=std::string::npos && period.find("5")!=std::string::npos )
354  fullPath += "nd_data_epoch5a_abscal";
355  else if( detector.find("nd")!=std::string::npos && period.find("6")!=std::string::npos )
356  fullPath += "nd_data_epoch6a_abscal";
357  else if( detector.find("nd")!=std::string::npos && period.find("7a")!=std::string::npos )
358  fullPath += "nd_data_epoch7a_abscal";
359  else if( detector.find("nd")!=std::string::npos && period.find("7b")!=std::string::npos )
360  fullPath += "nd_data_epoch7b_abscal";
361  else if( detector.find("nd")!=std::string::npos && period.find("7d")!=std::string::npos )
362  fullPath += "nd_data_epoch7d_abscal";
363  else if( detector.find("nd")!=std::string::npos && period.find("7")!=std::string::npos ){
364  std::cout << "WARNING!!!!!! "
365  << "\n\t You have asked for Period7. Period7 has separate files for 7a, 7b, and 7d."
366  << "\n\t Choosing 7a by default. You can pick 7a, 7b, or 7d by entering this for --pd" << std::endl;
367  fullPath += "nd_data_epoch7a_abscal";
368  }
369  else if( detector.find("nd")!=std::string::npos && period.find("8")!=std::string::npos ){
370  fullPath += "nd_data_epoch8b_abscal";
371  }
372  }
373 
374  if( !appendRoot && fullPath.length()==0 ){
375  std::cout << "WARNING!!!!!! "
376  << "\n\t You have an invalid file path..."
377  << "\n\t Defaulting to custom_plot_abstree.root" << std::endl;
378  fullPath="custom_plot_abstree.root";
379  }
380  if( appendRoot && fullPath.length()==0 ){
381  std::cout << "WARNING!!!!!! "
382  << "\n\t You have an invalid file path..."
383  << "\n\t Defaulting to custom_abscal" << std::endl;
384  fullPath="custom_abscal";
385  }
386  return fullPath;
387 }
388 
389 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
390 // Functions to put together plots (for a given period)
391 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
392 // FB overlay: Style One
394  float ymin, float ymax,
395  float meu=-1. ){
396  TCanvas *c2 = new TCanvas("c2","c2");
397 
398  unsigned int nFBbins = 10;
399  std::vector< TProfile* > plot;
400  plot.resize(nFBbins);
401 
402  TLegend *leg = new TLegend(0.45,0.12,0.9,0.2);
403  leg->SetHeader("Fibre Brightness Bin");
404  TLegendEntry *header = (TLegendEntry*)leg->GetListOfPrimitives()->First();
405  header->SetTextAlign(22);
406  leg->SetNColumns(5);
407 
408  Color_t col[10] = {kBlue+1,0,
409  kRed+1,0,
410  kGreen+1,0,
411  kMagenta+1,0,
412  kCyan+1,0};
413 
414  for(unsigned int b=0; b<nFBbins; b+=2){
415  temp->GetObject(Form("%s{fb%i}",name.c_str(),b),plot[b]);
416  if(!plot[b])
417  std::cout << "Could not find " << Form("%s{%i}",name.c_str(),b) << std::endl;
418 
419  if(meu>0.)
420  plot[b]->Scale(1/meu);
421  plot[b]->SetLineColor(col[b]);
422  plot[b]->SetMarkerColor(col[b]);
423  plot[b]->SetMarkerStyle(33);
424  plot[b]->SetStats(0);
425  TLegendEntry *le = leg->AddEntry(plot[b],Form("%i",b),"l");
426  le->SetTextColor(col[b]);
427  if(b==0){
428  plot[b]->SetMaximum(ymax);
429  plot[b]->SetMinimum(ymin);
430  plot[b]->SetTitle(Form("%s",plot[b]->GetTitle()));
431  plot[b]->Draw("");
432 
433  TLine *oneline = new TLine( plot[b]->GetXaxis()->GetXmin(), 1,
434  plot[b]->GetXaxis()->GetXmax(), 1);
435  oneline->SetLineStyle(2);
436  oneline->SetLineWidth(1);
437 
438  if(meu>0.)
439  oneline->Draw();
440  }
441  else {
442  plot[b]->Draw("same");
443  }
444  }
445 
446  leg->Draw();
447 
448  c2->Print(Form("%s_%s.pdf",outputDir.c_str(),name.c_str()));
449  c2->~TCanvas();
450 }
451 
452 // FB overlay: Style Two
454  TCanvas *c2 = new TCanvas("c2","c2");
455  c2->cd();
456 
457  unsigned int nFBbins = 10;
458  std::vector< TH1D* > plot;
459  plot.resize(nFBbins);
460  std::stringstream sMean, sRms, sErr;
461  std::stringstream le_text;
462 
463  bool meuPlot = (name.find("th1d_nhits_resp")!=std::string::npos) ||
464  (name.find("th1d_nhits_truededx")!=std::string::npos) ||
465  (name.find("th1d_nhits_pe")!=std::string::npos) ||
466  (name.find("th1d_nhits_pecm")!=std::string::npos);
467  bool areaNorm = true;
468 
469  TLegend *leg;
470 
471  if(meuPlot){
472  leg = new TLegend(0.5,0.45,0.95,0.85);
473  leg->SetHeader("Fibre Brightness Bin");
474  } else {
475  leg = new TLegend(0.15,0.5,0.25,0.85);
476  leg->SetHeader("FB Bin");
477  }
478 
479  TLegendEntry *header = (TLegendEntry*)leg->GetListOfPrimitives()->First();
480  header->SetTextAlign(22);
481  TLegendEntry *e = leg->AddEntry((TObject*)0,"dim","");
482  e->SetTextColor(kGray+2);
483  Color_t col[10] = {kBlue+1,0,
484  kRed+1,0,
485  kGreen+1,0,
486  kMagenta+1,0,
487  kCyan+1,0};
488 
489  for(unsigned int b=0; b<nFBbins; b+=2){
490  temp->GetObject(Form("%s{fb%i}",name.c_str(),b),plot[b]);
491  if(!plot[b])
492  std::cout << "Could not find " << Form("%s{%i}",name.c_str(),b) << std::endl;
493 
494  plot[b]->SetLineColor(col[b]);
495  plot[b]->SetMarkerColor(col[b]);
496  plot[b]->SetMarkerStyle(33);
497  plot[b]->SetStats(0);
498  if(areaNorm)
499  plot[b]->Scale(1/plot[b]->Integral());
500  sMean.str(""); sRms.str(""); sErr.str("");
501  sMean << std::setprecision(4) << plot[b]->GetMean(1);
502  sRms << std::setprecision(4) << plot[b]->GetRMS(1);
503  sErr << std::setprecision(4) << plot[b]->GetRMS(1)/std::sqrt(plot[b]->GetEntries());
504 
505  le_text.str("");
506  le_text << b << ": mu = " << sMean.str()
507  << ", rms = " << sRms.str()
508  << ", err = " << sErr.str();
509  if(meuPlot){
510  TLegendEntry *le = leg->AddEntry(plot[b],le_text.str().c_str(),"l");
511  le->SetTextColor(col[b]);
512  } else {
513  TLegendEntry *le = leg->AddEntry(plot[b],Form("%i",b),"l");
514  le->SetTextColor(col[b]);
515  }
516  if(b==0){
517  plot[b]->Draw("");
518  }
519  else {
520  plot[b]->Draw("same");
521  }
522  }
523  e = leg->AddEntry((TObject*)0,"bright","");
524  e->SetTextColor(kGray+2);
525  leg->Draw();
526 
527  c2->Print(Form("%s_%s.pdf",outputDir.c_str(),name.c_str()));
528  c2->~TCanvas();
529 }
530 
531 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
532 // Put plots together for Data/MC
533 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
534 void data_over_mc_profile( std::string plotname, TFile *data_f, TFile *mc_f,
535  std::string calibName, std::string outputDir,
536  std::string det, std::string data_name, std::string mc_name,
537  float ymin=0, float ymax=0,
538  float rat_min=0.8, float rat_max=1.2){
539 
540  std::string label="";
541  unsigned int slength = plotname.length();
542  if (plotname.find("fb")!=std::string::npos){
543  unsigned int bin = std::atoi(plotname.substr(slength-1,slength).c_str());
544  label = Form("FB %i",bin);
545  }
546  TLatex l(0.65, 0.75,label.c_str());
547  l.SetTextColor(17);
548  l.SetTextSize(0.15);
549  l.SetNDC(kTRUE);
550 
551  TProfile *data, *mc;
552  data_f->GetObject(plotname.c_str(),data);
553  data->SetName((std::string(data->GetName())+"_data").c_str()); // NOTE: Try to change the name to get rid of potential memory leaks
554  mc_f->GetObject(plotname.c_str(),mc);
555  mc->SetName((std::string(mc->GetName())+"_mc").c_str()); // NOTE: Try to change the name to get rid of potential memory leaks
556  if(!data)
557  std::cout << "Could not find data file's " << plotname << std::endl;
558  if(!mc){
559  std::cout << "Could not find mc file's " << plotname << std::endl; return; }
560 
561 
562  // how to avoid potential memory leak? no effect
563  //TProfile *d, *m;
564  //data->Copy(*d); mc->Copy(*m);
565  TH1D *data_proj = (TH1D*)data->ProjectionX("_px","B")->Clone();
566  TH1D *mc_proj = (TH1D*)mc->ProjectionX("_px","B")->Clone();
567  //TH1D *data_proj, *mc_proj;
568  //data->ProjectionX()->Copy(data_proj);
569  //mc->ProjectionX()->Copy(mc_proj)
570 
571  std::string title = "";
572  if(plotname.find("xview")!=std::string::npos) title = "X View";
573  if(plotname.find("yview")!=std::string::npos) title = "Y View";
574  mc_proj->SetTitle(title.c_str()); data_proj->SetTitle(title.c_str());
575  mc_proj->GetYaxis()->SetTitle("Arbitrary Unit");
576  data_proj->GetYaxis()->SetTitle("Arbitrary Unit");
577  mc_proj->Scale(1/mc_proj->Integral());
578  data_proj->Scale(1/data_proj->Integral());
579 
580  TCanvas *c = new TCanvas("c","data_over_mc",600,650);
581  float top = 0.7;
582  float bot = 1- top;
583  TPad *xpad = new TPad("xpad","xpad",0,bot,1,1);
584  TPad *xrat = new TPad("xrat","xrat",0,0,1,bot);
585  //TPad *xpad = new TPad("xpad","xpad",0,bot,0.5,1);
586  //TPad *xrat = new TPad("xrat","xrat",0,0,0.5,bot);
587  //TPad *ypad = new TPad("ypad","ypad",0.5,bot,1,1);
588  //TPad *yrat = new TPad("yrat","yrat",0.5,0,1,bot);
589  xpad->SetBottomMargin(0);
590  xpad->Draw();
591  xpad->cd();
592 
593  // shape up both TProfiles and TH1Ds
594  int data_col = kBlack;
595  int mc_col = kRed-3;
596  int mark = 22;
597  data->SetLineColor(data_col); data->SetMarkerColor(data_col);
598  data_proj->SetLineColor(data_col); data_proj->SetMarkerColor(data_col);
599  mc->SetLineColor(mc_col); mc->SetMarkerColor(mc_col);
600  mc_proj->SetLineColor(mc_col); mc_proj->SetMarkerColor(mc_col);
601  mc_proj->SetLineWidth(2);
602  mc->SetMarkerStyle(mark); data->SetMarkerStyle(mark);
603  mc_proj->SetMarkerStyle(mark); data_proj->SetMarkerStyle(mark);
604 
605  if(ymin==0 && ymax==0){
606  float maxprof = mc->GetMaximum();
607  float minprof = mc->GetMinimum();
608  if( maxprof < data->GetMaximum() ) maxprof = data->GetMaximum();
609  if( minprof > data->GetMinimum() ) minprof = data->GetMinimum();
610  float range = maxprof-minprof;
611  mc->SetMaximum(maxprof+range);
612  if(minprof>0.)
613  mc->SetMinimum(minprof-range);
614  else
615  mc->SetMinimum(0);
616  }
617  else {
618  mc->SetMinimum(ymin);
619  mc->SetMaximum(ymax);
620  }
621  float maxhist = mc_proj->GetMaximum();
622  if( maxhist < data_proj->GetMaximum() ) maxhist = data_proj->GetMaximum();
623  mc_proj->SetMaximum(1.1*maxhist);
624  mc_proj->SetMinimum(0);
625  data->SetStats(0); mc->SetStats(0);
626  data_proj->SetStats(0); mc_proj->SetStats(0);
627  mc->GetYaxis()->SetLabelSize( 0.02 / top );
628  mc->GetYaxis()->SetTitleSize( 0.025 / top );
629  mc->GetYaxis()->SetTitleOffset( 0.8 );
630  mc_proj->GetYaxis()->SetLabelSize( 0.02 / top );
631  mc_proj->GetYaxis()->SetTitleSize( 0.025 / top );
632  mc_proj->GetYaxis()->SetTitleOffset( 0.8 );
633 
634 
635  // draw the TProfiles first
636  mc->DrawCopy();
637  data->DrawCopy("same");
638  double leg_ymin = 0.75;
639  TLegend *leg = new TLegend(0.45-0.2,leg_ymin,0.45+0.2,0.9);
640  //TLegend *leg = new TLegend(0.7-0.2,0.1,0.7+0.2,0.35);
641  leg->AddEntry(data,Form("%s",data_name.c_str()),"lp");
642  leg->AddEntry(mc,Form("%s",mc_name.c_str()),"lp");
643  leg->Draw();
644  l.Draw();
645 
646  c->cd();
647  xrat->SetTopMargin(0);
648  xrat->SetBottomMargin(0.2);
649  xrat->Draw();
650  xrat->cd();
651  TProfile *ratio = new TProfile(*data);
652  TH1D *ratio_hist = new TH1D(*data_proj);
653  ratio->SetTitle("");
654  ratio->GetYaxis()->SetTitle("Data/MC");
655  ratio->SetMarkerColor(mc_col);
656  ratio->SetLineColor(mc_col);
657  ratio->SetLineWidth(2);
658  ratio->SetMarkerStyle(mark);
659  ratio_hist->SetTitle("");
660  ratio_hist->GetYaxis()->SetTitle("Data/MC");
661  ratio_hist->SetMarkerColor(mc_col);
662  ratio_hist->SetLineColor(mc_col);
663  ratio_hist->SetLineWidth(2);
664  ratio_hist->SetMarkerStyle(mark);
665 
666  ratio->GetXaxis()->SetLabelSize( 0.02 / bot );
667  ratio->GetYaxis()->SetLabelSize( 0.02 / bot );
668  ratio->GetXaxis()->SetTitleSize( 0.025 / bot );
669  ratio->GetYaxis()->SetTitleSize( 0.025 / bot );
670  ratio->GetYaxis()->SetTitleOffset( 0.45 );
671  ratio->GetYaxis()->SetNdivisions(505);
672  ratio_hist->GetXaxis()->SetLabelSize( 0.02 / bot );
673  ratio_hist->GetYaxis()->SetLabelSize( 0.02 / bot );
674  ratio_hist->GetXaxis()->SetTitleSize( 0.025 / bot );
675  ratio_hist->GetYaxis()->SetTitleSize( 0.025 / bot );
676  ratio_hist->GetYaxis()->SetTitleOffset( 0.45 );
677  ratio_hist->GetYaxis()->SetNdivisions(505);
678  /*
679  ratio->GetXaxis()->SetLabelFont(63); //font in pixels
680  ratio->GetXaxis()->SetLabelSize(16); //in pixels
681  ratio->GetYaxis()->SetLabelFont(63); //font in pixels
682  ratio->GetYaxis()->SetLabelSize(16); //in pixels
683  */
684  ratio->Divide(mc);
685  ratio->SetMinimum(rat_min);
686  ratio->SetMaximum(rat_max);
687  ratio->SetMarkerStyle(2);
688  ratio_hist->SetMarkerStyle(2);
689  TLine *oneline = new TLine( data->GetXaxis()->GetXmin(), 1,
690  data->GetXaxis()->GetXmax(), 1);
691  oneline->SetLineStyle(2);
692  ratio->Draw("hist");
693  oneline->Draw();
694  c->cd();
695 
696  // print tprofile ratio plot
697  c->Print(Form("%s_%s.pdf",outputDir.c_str(),plotname.c_str()));
698 
699  if(plotname.substr(0,6)!="tprof_")
700  std::cout << "TProfile not named within convention: " << plotname << std::endl;
701 
702  // peel off "tprof_" from plotname, then peel off name of whatever value was averaged
703  std::string projname = plotname.substr(6,plotname.length());
704  projname = projname.substr(projname.find("_"),projname.length());
705  // add proper prefix to name
706  projname = Form("th1d_nhits%s",projname.c_str());
707 
708  /*
709  float total_data_mc=0.;
710  for(int b=0; b<mc_proj->GetXaxis()->GetNbins(); b++){
711  total_data_mc += data_proj->GetBinContent(b) * ;
712  }
713  */
714 
715  // draw the TH1Ds
716  c->cd();
717  xpad->Draw();
718  xpad->cd();
719  mc_proj->DrawCopy();
720  data_proj->DrawCopy("same p");
721  TLegend *leg2 = new TLegend(0.45-0.2,leg_ymin,0.45+0.2,0.9);
722  //leg2 = new TLegend(0.75-0.17,leg_ymin,0.75+0.15,0.86);
723  leg2->AddEntry(data_proj,Form("%s",data_name.c_str()),"p");
724  leg2->AddEntry(mc_proj,Form("%s",mc_name.c_str()),"l");
725  leg2->Draw();
726  l.Draw();
727  c->cd();
728  xrat->Draw();
729  xrat->cd();
730  ratio_hist->Divide(mc_proj);
731  ratio_hist->SetMinimum(rat_min);
732  ratio_hist->SetMaximum(rat_max);
733  ratio_hist->Draw();
734  oneline->Draw();
735  c->cd();
736 
737  // print TH1Ds
738  c->Print(Form("%s_%s.pdf",outputDir.c_str(),plotname.c_str()));
739  c->~TCanvas();
740 }
741 
742 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
743 // Functions to put together plots (Ratio plots comparing periods)
744 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
745 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 ){
746  tC = new TCanvas();
747  tC->Divide(1,2);
748 
749  double blankmaxy(0.),blankmaxx(0.),blankminx(9.e9),blankminy(9.e9);
750  // NOTE: this is commented out because unused...
751  //nominaly(0.);
752  int binsx = hVec[0]->GetXaxis()->GetNbins();
753  double thisdx = hVec[0]->GetXaxis()->GetBinLowEdge(2)-hVec[0]->GetXaxis()->GetBinLowEdge(1);
754 
755  std::string histOvName = hVec[0]->GetTitle();
756  std::string histXName = hVec[0]->GetXaxis()->GetTitle();
757  std::string histYName = hVec[0]->GetYaxis()->GetTitle();
758 
759  // find min and max values
760  for( auto const& iHist : hVec ){
761  if( iHist->GetXaxis()->GetBinLowEdge(1) < blankminx ) blankminx = iHist->GetXaxis()->GetBinLowEdge(1);
762  if( 0.75*iHist->GetMinimum() < blankminy ) blankminy = 0.75*iHist->GetMinimum();
763  if( iHist->GetXaxis()->GetBinLowEdge(binsx)+thisdx > blankmaxx ) blankmaxx = iHist->GetXaxis()->GetBinLowEdge(binsx)+thisdx;
764  if( iHist->GetMaximum() > blankmaxy ) blankmaxy = iHist->GetMaximum();
765  }
766 
767  // Top plot
768  TPad *p1 = (TPad*)tC->cd(1);
769  p1->SetPad(0.01,0.3,0.99,0.99);
770  TH1D *blankHist = new TH1D( TString::Format("%s-blankAll",hName.c_str()), TString::Format("%s;%s;%s",histOvName.c_str(),histXName.c_str(),histYName.c_str()), binsx, blankminx, blankmaxx );
771  blankHist->SetStats(0);
772  blankHist->GetYaxis()->SetRangeUser(blankminy,1.3*blankmaxy);
773 
774  blankHist->GetXaxis()->CenterTitle();
775  blankHist->GetYaxis()->CenterTitle();
776 
777  blankHist->Draw("");
778 
779  tL = new TLegend(0.82,0.7,0.9,0.9);
780 
781  unsigned int intHist = 0;
782  for( auto const& iHist : hVec ){
783  iHist->SetLineWidth(2);
784  if( intHist<fColorWheel.size() ) iHist->SetLineColor( fColorWheel[intHist] );
785  else{
786  std::cout << "WARNING!!! Exceeded length of fColorWheel... defaulting to a color that may not be good." << std::endl;
787  iHist->SetLineColor( intHist );
788  }
789  iHist->SetStats(0);
790  iHist->Draw("same hist");
791  tL->AddEntry(iHist->GetName(),hPlotNames[intHist].c_str(),"l");
792  intHist+=1;
793  }
794 
795  tL->SetFillStyle(0);
796  tL->Draw();
797 
798  // Bottom plot
799  TPad *p2 = (TPad*)tC->cd(2);
800  p2->SetPad(0.01,0.01,0.99,0.365);
801  p2->SetTopMargin(0.);
802 
803  TH1D *blankHist2 = new TH1D( TString::Format("%s-blankRatio",hName.c_str()), TString::Format(";%s;Ratio",histXName.c_str()), binsx, blankminx, blankmaxx );
804  blankHist2->SetStats(0);
805  blankHist2->GetYaxis()->SetRangeUser(0.85,1.15);
806 
807  blankHist2->GetXaxis()->CenterTitle();
808  blankHist2->GetYaxis()->CenterTitle();
809  blankHist2->GetYaxis()->SetLabelSize(0.07);
810  blankHist2->GetXaxis()->SetLabelSize(0.07);
811  blankHist2->GetYaxis()->SetTitleSize(0.095);
812  blankHist2->GetYaxis()->SetTitleOffset(0.5);
813  blankHist2->GetXaxis()->SetTitleSize(0.075);
814  blankHist2->GetXaxis()->SetTitleOffset(0.6);
815 
816  TLine *unityLine = new TLine(blankminx,1.0,blankmaxx,1.0);
817  unityLine->SetLineColor(kBlack);
818  unityLine->SetLineStyle(7);
819 
820  double minrat(10.),maxrat(0.);
821  std::vector<TH1D*> hRatio;
822  for( unsigned int thisIntHist=1; thisIntHist<hVec.size(); ++thisIntHist ){
823  hRatio.push_back( new TH1D( TString::Format("%s-ratio-%s",hName.c_str(),hPlotNames[thisIntHist].c_str()), TString::Format(";%s;Ratio",histXName.c_str()), binsx, blankminx, blankmaxx ) );
824  hRatio[hRatio.size()-1]->Divide(hVec[thisIntHist],hVec[0]);
825  hRatio[hRatio.size()-1]->SetLineWidth(2);
826  if( thisIntHist<fColorWheel.size() ) hRatio[hRatio.size()-1]->SetLineColor( fColorWheel[thisIntHist] );
827  else{
828  std::cout << "WARNING!!! Exceeded length of fColorWheel... defaulting to a color that may not be good." << std::endl;
829  hRatio[hRatio.size()-1]->SetLineColor( thisIntHist );
830  }
831  if( hRatio[hRatio.size()-1]->GetMaximum() > maxrat ) maxrat = hRatio[hRatio.size()-1]->GetMaximum();
832  if( hRatio[hRatio.size()-1]->GetMinimum() < minrat ) minrat = hRatio[hRatio.size()-1]->GetMinimum();
833  }
834 
835  blankHist2->Draw("");
836  unityLine->Draw("same");
837 
838  for( auto const& iHist : hRatio ){
839  iHist->Draw("same");
840  }
841 
842  // Save
843  tC->Print(TString::Format("%sOutput/Plots-ByPeriod/Plot_%s_ComparePeriods-%s.pdf",user_dir.c_str(),calibName.c_str(),hName.c_str()));
844 }
845 
846 void makeRatioPlot( TCanvas *tC, TLegend *tL, std::vector<TH1D*> hVec, std::string hName, std::vector<std::string> hPlotNames, std::string calibName, std::string user_dir ){
847  tC = new TCanvas();
848  tC->Divide(1,2);
849 
850  double blankmaxy(0.),blankmaxx(0.),blankminx(9.e9),blankminy(9.e9);
851  int binsx = hVec[0]->GetXaxis()->GetNbins();
852  double thisdx = hVec[0]->GetXaxis()->GetBinLowEdge(2)-hVec[0]->GetXaxis()->GetBinLowEdge(1);
853 
854  std::string histOvName = hVec[0]->GetTitle();
855  std::string histXName = hVec[0]->GetXaxis()->GetTitle();
856  std::string histYName = hVec[0]->GetYaxis()->GetTitle();
857 
858  // find min and max values
859  for( auto const& iHist : hVec ){
860  if( iHist->GetXaxis()->GetBinLowEdge(1) < blankminx ) blankminx = iHist->GetXaxis()->GetBinLowEdge(1);
861  if( 0.75*iHist->GetMinimum() < blankminy ) blankminy = 0.75*iHist->GetMinimum();
862  if( iHist->GetXaxis()->GetBinLowEdge(binsx)+thisdx > blankmaxx ) blankmaxx = iHist->GetXaxis()->GetBinLowEdge(binsx)+thisdx;
863  if( iHist->GetMaximum() > blankmaxy ) blankmaxy = iHist->GetMaximum();
864  }
865 
866  // Top plot
867  TPad *p1 = (TPad*)tC->cd(1);
868  p1->SetPad(0.01,0.3,0.99,0.99);
869  TH1D *blankHist = new TH1D( TString::Format("%s-blankAll",hName.c_str()), TString::Format("%s;%s;%s",histOvName.c_str(),histXName.c_str(),histYName.c_str()), binsx, blankminx, blankmaxx );
870  blankHist->SetStats(0);
871  blankHist->GetYaxis()->SetRangeUser(blankminy,1.3*blankmaxy);
872 
873  blankHist->GetXaxis()->CenterTitle();
874  blankHist->GetYaxis()->CenterTitle();
875 
876  blankHist->Draw("");
877 
878  tL = new TLegend(0.82,0.7,0.9,0.9);
879 
880  unsigned int intHist = 0;
881  for( auto const& iHist : hVec ){
882  iHist->SetLineWidth(2);
883  if( intHist<fColorWheel.size() ) iHist->SetLineColor( fColorWheel[intHist] );
884  else{
885  std::cout << "WARNING!!! Exceeded length of fColorWheel... defaulting to a color that may not be good." << std::endl;
886  iHist->SetLineColor( intHist );
887  }
888  iHist->SetStats(0);
889  iHist->Draw("same hist");
890  tL->AddEntry(iHist->GetName(),hPlotNames[intHist].c_str(),"l");
891  intHist+=1;
892  }
893 
894  tL->SetFillStyle(0);
895  tL->Draw();
896 
897  // Bottom plot
898  TPad *p2 = (TPad*)tC->cd(2);
899  p2->SetPad(0.01,0.01,0.99,0.365);
900  p2->SetTopMargin(0.);
901 
902  TH1D *blankHist2 = new TH1D( TString::Format("%s-blankRatio",hName.c_str()), TString::Format(";%s;Ratio",histXName.c_str()), binsx, blankminx, blankmaxx );
903  blankHist2->SetStats(0);
904  blankHist2->GetYaxis()->SetRangeUser(0.85,1.15);
905 
906  blankHist2->GetXaxis()->CenterTitle();
907  blankHist2->GetYaxis()->CenterTitle();
908  blankHist2->GetYaxis()->SetLabelSize(0.07);
909  blankHist2->GetXaxis()->SetLabelSize(0.07);
910  blankHist2->GetYaxis()->SetTitleSize(0.095);
911  blankHist2->GetYaxis()->SetTitleOffset(0.5);
912  blankHist2->GetXaxis()->SetTitleSize(0.075);
913  blankHist2->GetXaxis()->SetTitleOffset(0.6);
914 
915  TLine *unityLine = new TLine(blankminx,1.0,blankmaxx,1.0);
916  unityLine->SetLineColor(kBlack);
917  unityLine->SetLineStyle(7);
918 
919  blankHist2->Draw("");
920  unityLine->Draw("same");
921 
922  double minrat(10.),maxrat(0.);
923  std::vector<TH1D*> hRatio;
924  for( unsigned int thisIntHist=1; thisIntHist<hVec.size(); ++thisIntHist ){
925  hRatio.push_back( new TH1D( TString::Format("%s-ratio-%s",hName.c_str(),hPlotNames[thisIntHist].c_str()), TString::Format(";%s;Ratio",histXName.c_str()), binsx, blankminx, blankmaxx ) );
926  hRatio[hRatio.size()-1]->Divide(hVec[thisIntHist],hVec[0]);
927  hRatio[hRatio.size()-1]->SetLineWidth(2);
928  if( thisIntHist<fColorWheel.size() ) hRatio[hRatio.size()-1]->SetLineColor( fColorWheel[thisIntHist] );
929  else{
930  std::cout << "WARNING!!! Exceeded length of fColorWheel... defaulting to a color that may not be good." << std::endl;
931  hRatio[hRatio.size()-1]->SetLineColor( thisIntHist );
932  }
933  if( hRatio[hRatio.size()-1]->GetMaximum() > maxrat ) maxrat = hRatio[hRatio.size()-1]->GetMaximum();
934  if( hRatio[hRatio.size()-1]->GetMinimum() < minrat ) minrat = hRatio[hRatio.size()-1]->GetMinimum();
935  }
936 
937  blankHist2->Draw("");
938  unityLine->Draw("same");
939 
940  for( auto const& iHist : hRatio ){
941  iHist->Draw("same");
942  }
943 
944  // Save
945  tC->Print(TString::Format("%sOutput/Plots-ByPeriod/Plot_%s_ComparePeriods-%s.pdf",user_dir.c_str(),calibName.c_str(),hName.c_str()));
946 }
const XML_Char * name
Definition: expat.h:151
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
std::vector< std::pair< int, int > > fdHardwareSwaps
Definition: FennecFnc.h:45
std::string getSample(std::string detector, std::string period, std::string sample)
Function to get the input file name.
Definition: FennecFnc.h:115
const std::vector< std::string > histo2DVector
Definition: FennecFnc.h:37
double Integral(const Spectrum &s, const double pot, int cvnregion)
T sqrt(T number)
Definition: d0nt_math.hpp:156
TH1 * ratio(TH1 *h1, TH1 *h2)
std::string getMCName(std::string detector, std::string period, std::string specialSample="")
Function to determine MC sample name.
Definition: FennecFnc.h:193
cout<< t1-> GetEntries()
Definition: plottest35.C:29
const char * label
const XML_Char const XML_Char * data
Definition: expat.h:268
Double_t ymax
Definition: plot.C:25
c2
Definition: demo5.py:33
Int_t col[ntarg]
Definition: Style.C:29
bool checkSwap(int plane, int mod)
Definition: FennecFnc.h:83
correl_xv GetXaxis() -> SetDecimals()
const std::vector< int > fColorWheel
Definition: FennecFnc.h:109
float bin[41]
Definition: plottest35.C:14
OStream cout
Definition: OStream.cxx:6
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
TChain * le
Definition: leana.C:12
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
exit(0)
const hit & b
Definition: hits.cxx:21
const std::vector< std::string > histo1DVector
Definition: FennecFnc.h:21
Double_t ymin
Definition: plot.C:24
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
Float_t e
Definition: plot.C:35
bool cut_Track_Window(double x)
Definition: FennecFnc.h:100
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
TGeoVolume * top
Definition: make_fe_box.C:9
void plot(std::string label, std::map< std::string, std::map< std::string, Spectrum * >> &plots, bool log)
bool cut_PE(double pe)
Definition: FennecFnc.h:104