MakeMEUPerFEB.C
Go to the documentation of this file.
1 
2 #include "CalibAnaPlot.h"
3 #include "CalibAnaTypes.h"
4 #include "TexBuilder.h"
5 #include <iomanip>
6 #include <numeric>
7 
8 class MEUPerFEB : public CalibAnaPlot{
9 
10  public:
11 
12  MEUPerFEB(std::string outpath);
13  // vvv CalibAnaPlot implimentations
14  void SchedulePlots();
15  void ScheduleAllDataPlots();
16  void ScheduleSamples();
17  void ScheduleHitVars();
18  void FillHitPlots();
19  // ^^^ CalibAnaPlot implimentations
20  void MakeTex();
21  void InitBadFeb();
22  bool BadFeb(int plane, int cell);
23  void DriftTex(std::string plotdir);
24 
25 
26 
27  private:
28  std::vector< std::string > fEpochList;
30  std::map< int, std::map < int, bool > > fBadFeb;//[plane][module]
31 };
32 
33 
35 : CalibAnaPlot(outpath)
36 {
37 }
38 
40  std::string sample,
41  bool justdraw=false,
42  unsigned int stride=0,
43  unsigned int limit=0)
44 {
45  MEUPerFEB meuperapd(outpath);
46  meuperapd.Initialize();
47  if(stride) meuperapd.SetTreeLoopStride(stride);
48  if(limit) meuperapd.SetTreeLoopLimit(limit);
49 
50  if(justdraw){
51  meuperapd.MakeTex();
52  } else {
53  if(sample=="all"){
54  for( auto& s : meuperapd.GetSamples() ){
55  meuperapd.ProcessTrees(s.first);
56  }
57  meuperapd.MakeTex();
58  } else {
59  meuperapd.ProcessTrees(sample);
60  }
61  }
62 }
63 
64 //^~^~^~~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
66 {
67  InitBadFeb();
68 
69  fTex = new TexBuilder( fOutPath+"/MEUPerCellGroupAndFEB.tex",
70  "Drift by FEB",
71  "Tyler Alion, Alexander Booth, Yibing Zhang",
72  "Miniproduction 5 Data vs. MC. Tricell hits from Stopping Cosmics populate all plots, with Absolute Calibration cuts applied. Showing PE/cm and PECorr/cm broken down by cell group and view then further by FEB.");
73 
74  std::string plotdir = "nd_all_samples";
75 
76  // There are 12 denominator plots
77  std::vector< std::string > views = {"x", "y"};
78  std::vector< std::string > mods = {"_0-31", "_32-63", "_64-95"};
79  std::vector< std::string > yaxes = {"pecm", "pecorrcm"};
80  for(auto& view : views){
81  size_t firstplane = 1;
82  if(view=="y") firstplane = 0;
83  for(auto& modstr : mods){
84  for(auto& yax : yaxes){
85 
86  std::vector< std::string > drawplots;
87  size_t np = fDet->NPlanes();
88  for(size_t p=firstplane; p<np; p+=2)
89  drawplots.push_back(yax+"_time_"+view+"_"+std::to_string(p)+modstr);
90  drawplots.push_back(yax+"_time_"+view+modstr);
91  drawplots.push_back(yax+"_time_"+view+modstr+"_febcut");
92 
93  Plot denom_plot(fOutPath+"/nd_all_data.root", // data over all time
94  yax+"_time_"+view+modstr+"_febcut", // mean for whole view-module group
95  "Mean: "+view+modstr);
96 
97  for(auto& plotname : drawplots){
98  std::vector< Plot > plotstack;
99  for(auto& samp : fSamples)
100  plotstack.push_back( Plot( fOutPath+"/"+samp.first+".root",
101  plotname,
102  LegendLabel(samp.first) ) );
103 
104  Draw( plotdir, plotstack, denom_plot, "" );
105  }
106  }
107  }
108  }
109 
110 
111 
112  DriftTex(plotdir);
113 
114  delete fTex;
115 }
116 
117 //^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
119 {
120  fTex->SectionNoNum("By View and Cell Group");
121  fTex->AddFigureRow({plotdir+"/legend"}, {""}, {""});
122  fTex->AddFigureRow({plotdir+"/pecm_time_x_0-31", plotdir+"/pecm_time_y_0-31" }, {"", ""}, {"", ""});
123  fTex->AddFigureRow({plotdir+"/pecm_time_x_32-63", plotdir+"/pecm_time_y_32-63"}, {"", ""}, {"", ""});
124  fTex->AddFigureRow({plotdir+"/pecm_time_x_64-95", plotdir+"/pecm_time_y_64-95"}, {"", ""}, {"", ""});
125  fTex->NewPage();
126  fTex->AddFigureRow({plotdir+"/legend"}, {""}, {""});
127  fTex->AddFigureRow({plotdir+"/pecorrcm_time_x_0-31", plotdir+"/pecorrcm_time_y_0-31" }, {"", ""}, {"", ""});
128  fTex->AddFigureRow({plotdir+"/pecorrcm_time_x_32-63", plotdir+"/pecorrcm_time_y_32-63"}, {"", ""}, {"", ""});
129  fTex->AddFigureRow({plotdir+"/pecorrcm_time_x_64-95", plotdir+"/pecorrcm_time_y_64-95"}, {"", ""}, {"", ""});
130  fTex->NewPage();
131 
132  fTex->SectionNoNum("MEU with FEB Cut");
133  fTex->AddFigureRow({plotdir+"/legend"}, {""}, {""});
134  fTex->AddFigureRow({plotdir+"/pecm_time_x_0-31_febcut", plotdir+"/pecm_time_y_0-31_febcut" }, {"", ""}, {"", ""});
135  fTex->AddFigureRow({plotdir+"/pecm_time_x_32-63_febcut", plotdir+"/pecm_time_y_32-63_febcut"}, {"", ""}, {"", ""});
136  fTex->AddFigureRow({plotdir+"/pecm_time_x_64-95_febcut", plotdir+"/pecm_time_y_64-95_febcut"}, {"", ""}, {"", ""});
137  fTex->NewPage();
138  fTex->AddFigureRow({plotdir+"/legend"}, {""}, {""});
139  fTex->AddFigureRow({plotdir+"/pecorrcm_time_x_0-31_febcut", plotdir+"/pecorrcm_time_y_0-31_febcut" }, {"", ""}, {"", ""});
140  fTex->AddFigureRow({plotdir+"/pecorrcm_time_x_32-63_febcut", plotdir+"/pecorrcm_time_y_32-63_febcut"}, {"", ""}, {"", ""});
141  fTex->AddFigureRow({plotdir+"/pecorrcm_time_x_64-95_febcut", plotdir+"/pecorrcm_time_y_64-95_febcut"}, {"", ""}, {"", ""});
142  fTex->NewPage();
143 
144 
145  unsigned int nPlanes = fDet->NPlanes();
146  for(unsigned int p = 0; p < nPlanes; p++)
147  {
148  fTex->SectionNoNum(Form("Plane %i", p));
149  std::string pstr = (p % 2 == 0 ? "y_" : "x_") + std::to_string(p);
150  fTex->AddFigureRow({plotdir+"/legend"}, {""}, {""});
151  fTex->AddFigureRow({plotdir+"/pecm_time_"+pstr+"_0-31", plotdir+"/pecorrcm_time_"+pstr+"_0-31" }, {"", ""}, {"", ""});
152  fTex->AddFigureRow({plotdir+"/pecm_time_"+pstr+"_32-63", plotdir+"/pecorrcm_time_"+pstr+"_32-63"}, {"", ""}, {"", ""});
153  fTex->AddFigureRow({plotdir+"/pecm_time_"+pstr+"_64-95", plotdir+"/pecorrcm_time_"+pstr+"_64-95"}, {"", ""}, {"", ""});
154  if(p!=nPlanes-1) fTex->NewPage();
155  }
156 }
157 
158 //^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
160 {
161  // The filled branches are protected members of
162  // CalibAnaPlot, so can be used here
163 
164  bool abscal_hit = ( w > -100 && w < 100 &&
165  path > 0. &&
166  pecorr > 0. && pecorr/path < 100. &&
167  pe > 0. &&
168  cmFromEnd > 100 && cmFromEnd < 200 );
169  if( !abscal_hit ) return;
170  if( plane > 191) return;
171 
172  std::string vstr, pstr;
173  if(view==0){ vstr="x"; }
174  if(view==1){ vstr="y"; }
175  pstr = std::to_string(plane);
176 
177  std::string end = vstr + "_" + pstr + "_";
178  std::string endGroup = vstr + "_";
179 
180  float pecm = pe/path;
181  float pecorrcm = pecorr/path;
182  if(cell <= 31){
183  end += "0-31";
184  endGroup += "0-31";
185  }
186  else if(cell > 31 && cell <= 63){
187  end += "32-63";
188  endGroup += "32-63";
189  }
190  else{
191  end += "64-95";
192  endGroup += "64-95";
193  }
194  fPlots["pecm_time_"+end] ->Fill(evt_time,pecm);
195  fPlots["pecorrcm_time_"+end]->Fill(evt_time,pecorrcm);
196  fPlots["pecm_time_"+endGroup] ->Fill(evt_time,pecm);
197  fPlots["pecorrcm_time_"+endGroup]->Fill(evt_time,pecorrcm);
198 
199  fAllDataPlots["pecm_time_"+endGroup] ->Fill(evt_time,pecm);
200  fAllDataPlots["pecorrcm_time_"+endGroup]->Fill(evt_time,pecorrcm);
201 
202  if( !BadFeb(plane,cell) ){
203  fPlots[ "pecm_time_"+endGroup+"_febcut" ]->Fill(evt_time,pecm);
204  fPlots[ "pecorrcm_time_"+endGroup+"_febcut" ]->Fill(evt_time,pecorrcm);
205  fAllDataPlots[ "pecm_time_"+endGroup+"_febcut" ]->Fill(evt_time,pecm);
206  fAllDataPlots[ "pecorrcm_time_"+endGroup+"_febcut" ]->Fill(evt_time,pecorrcm);
207  }
208 }
209 
210 //^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
212 {
213  // If no plane entry, it is _not_ a bad FEB
214  if( !fBadFeb.count(plane) ) return false;
215  // If there is a plane entry...
216  return fBadFeb[plane].count( fDet->CellToModule(cell) );
217 }
218 
219 //^~^~^~~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
221 {
222  // From a hand scan.
223 
224  // Eventually use algorith which compares Mean&RMS of time bin
225  // in a given FEB to it's view-module average
226 
227  // Y view
228  std::vector< int > planes = { 2, 10, 14, 16, 24, 38, 46, 50, 66, 82, 88, 90, 94, 114, 140, 150, 152, 184 };
229  for(auto& p : planes)
230  fBadFeb[p][1]=true;
231  planes = { 12, 20, 46, 110, 124, 130, 166 };
232  for(auto& p : planes)
233  fBadFeb[p][2]=true;
234 
235  // X view
236  planes = { 5, 63, 75, 77, 93, 95, 135, 149 };
237  for(auto& p : planes)
238  fBadFeb[p][1]=true;
239  planes = { 17, 31, 35, 69, 91, 95, 129, 175 };
240  for(auto& p : planes)
241  fBadFeb[p][2]=true;
242 
243 }
244 
245 //^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
247 {
248  fHitVars="w, view, plane, cell, pe, pecorr, path, evt_time, cmFromEnd,";
249 }
250 
251 //^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
253 {
254  int nPlanes = fDet->NPlanes();
255 
256  std::vector< PlotAxis > xaxes = {
257  {"time", "Unix Time (s)", 100, 14e8, 16e8}
258  };
259 
260  std::vector< ContentAxis > yaxes = {
261  {"pecm", "PE/cm"},
262  {"pecorrcm", "PECorr/cm"},
263  };
264 
265  std::vector< std::string > cells = {"0-31", "32-63", "64-95"};
266  std::vector<int> planes(nPlanes);
267  std::iota(planes.begin(), planes.end(), 0);
268  for(auto& p : planes){
269  std::string vstr = (p % 2 == 0 ? "Y" : "X");
270  std::string v = (p % 2 == 0 ? "y" : "x");
271  for(auto& c : cells){
272  for(auto& xax : xaxes){
273  for(auto& yax : yaxes){
274 
275  std::string name = yax.label +"_"+ xax.label +"_"+ v + "_" + std::to_string(p) + "_" + c;
276  //std::cout << "Schedule: " << name << std::endl;
277 
278  fPlots[name] = new TProfile( name.c_str(),
279  (vstr+" View, Plane "+std::to_string(p)+", Cells "+c+";" + xax.title +";"+ yax.title).c_str(),
280  xax.nbins, xax.min, xax.max );
281 
282  if(p < 2){
283  name = yax.label +"_"+ xax.label +"_"+ v + "_" + c;
284  fPlots[name] = new TProfile( name.c_str(),
285  (vstr+" View, Cells "+c+";" + xax.title +";"+ yax.title).c_str(),
286  xax.nbins, xax.min, xax.max );
287  name = name + "_febcut";
288  fPlots[name] = new TProfile( name.c_str(),
289  (vstr+" View, Cells "+c+" + FEB Cut;" + xax.title +";"+ yax.title).c_str(),
290  xax.nbins, xax.min, xax.max );
291  } // by module
292  } // yaxes
293  } // xaxes
294  } // cell groups
295  } // planes
296 } // SchedulePlots
297 
298 //^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
300 {
301 
302  std::vector< PlotAxis > xaxes = {
303  {"time", "Unix Time (s)", 100, 14e8, 16e8}
304  };
305 
306  std::vector< ContentAxis > yaxes = {
307  {"pecm", "PE/cm"},
308  {"pecorrcm", "PECorr/cm"},
309  };
310 
311  std::vector< std::string > cells = {"0-31", "32-63", "64-95"};
312  std::vector< std::string > views = {"x", "y"};
313  for(auto& v : views){
314  for(auto& c : cells){
315  for(auto& xax : xaxes){
316  for(auto& yax : yaxes){
317  std::string name = yax.label +"_"+ xax.label +"_"+v+"_" + c;
318  std::string vCap = (v=="x") ? "X" : "Y";
319  fAllDataPlots[name] = new TProfile( name.c_str(),
320  (vCap+" View, Cells "+c+";" + xax.title +";"+ yax.title).c_str(),
321  xax.nbins, xax.min, xax.max );
322  name = name + "_febcut";
323  fAllDataPlots[name] = new TProfile( name.c_str(),
324  (vCap+" View, Cells "+c+" + FEB Cut;" + xax.title +";"+ yax.title).c_str(),
325  xax.nbins, xax.min, xax.max );
326 
327  }
328  }
329  }
330  }
331 }
332 
333 //^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
335 {
336  std::vector< std::string > epoch_list = {
337  //"4c"};
338  "2a", "2b","2c","2d","2e",
339  "3b","3c","3d","3e",
340  "4a", "4b.1", "4b.2", "4c", // split 4b up manually
341  "5a","5b",
342  "6a","6b",
343  "7a","7b","7c","7d",
344  "8b" };
345 
346  fEpochList = epoch_list;
347 
348  for( auto& ep : epoch_list ){
349  if(ep=="4b.1" || ep=="4b.2")
350  fSamples["nd_data_ep"+ep]="/nova/ana/users/talion/miniprod5/pcliststop_miniprod5.b/nd_data_epoch4b/calibana/merged.root";
351  else
352  fSamples["nd_data_ep"+ep]="/nova/ana/users/talion/miniprod5/pcliststop_miniprod5.b/nd_data_epoch"+ep+"/calibana/merged.root";
353  }
354 
355  //fSamples["nd_mc"]="/nova/ana/users/abooth/miniprod5.b/nd_mc/merged.root";
356 }
357 
const XML_Char * name
Definition: expat.h:151
std::map< std::string, TH1 * > fPlots
Definition: CalibAnaPlot.h:57
std::map< std::string, std::string > GetSamples()
Definition: CalibAnaPlot.h:28
void NewPage()
Definition: TexBuilder.h:165
struct Plot Plot
Definition: DrawUtils.h:15
void FillHitPlots()
void ScheduleHitVars()
void ScheduleAllDataPlots()
unsigned int CellToModule(int cell)
Definition: Detector.h:75
void SchedulePlots()
std::string fOutPath
Definition: CalibAnaPlot.h:62
const char * p
Definition: xmltok.h:285
void InitBadFeb()
uint32_t evt_time
Definition: CalibAnaPlot.h:80
std::string LegendLabel(std::string key)
Definition: CalibAnaPlot.h:239
void MakeMEUPerFEB(std::string outpath, std::string sample, bool justdraw=false, unsigned int stride=0, unsigned int limit=0)
Definition: MakeMEUPerFEB.C:39
void Initialize()
Definition: CalibAnaPlot.h:138
void SetTreeLoopLimit(unsigned int limit)
Definition: CalibAnaPlot.h:31
std::vector< std::string > fEpochList
Definition: MakeMEUPerFEB.C:28
const XML_Char * s
Definition: expat.h:262
std::string fHitVars
Definition: CalibAnaPlot.h:67
====================================================================== ///
Definition: CutFlow_Data.C:28
MEUPerFEB(std::string outpath)
Definition: MakeMEUPerFEB.C:34
std::map< int, std::map< int, bool > > fBadFeb
Definition: MakeMEUPerFEB.C:30
void MakeTex()
Definition: MakeMEUPerFEB.C:65
void ProcessTrees(std::string sample)
Definition: CalibAnaPlot.h:329
void SectionNoNum(std::string secname)
Definition: TexBuilder.h:153
void SetTreeLoopStride(unsigned int stride)
Definition: CalibAnaPlot.h:32
void DriftTex(std::string plotdir)
TexBuilder * fTex
Definition: MakeMEUPerFEB.C:29
unsigned int NPlanes()
Definition: Detector.h:13
void ScheduleSamples()
void Draw(std::string pdfdir, std::vector< Plot > plots, Plot denom_plot, std::string ratio_title="")
Definition: CalibAnaPlot.h:168
bool BadFeb(int plane, int cell)
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
std::map< std::string, std::string > fSamples
Definition: CalibAnaPlot.h:59
void AddFigureRow(std::vector< std::string > figure, std::vector< std::string > caption, std::vector< std::string > label)
Definition: TexBuilder.h:98
Detector * fDet
Definition: CalibAnaPlot.h:68
enum BeamMode string