MakeMEUPerDiblock.C
Go to the documentation of this file.
1 #include "CalibAnaPlot.h"
2 #include "CalibAnaTypes.h"
3 #include "TexBuilder.h"
4 #include <iomanip>
5 #include <numeric>
6 
7 class MEUPerDiblock : public CalibAnaPlot{
8 
9  public:
10 
12  // vvv CalibAnaPlot implimentations
13  void SchedulePlots();
14  void ScheduleAllDataPlots();
15  void ScheduleSamples();
16  void ScheduleHitVars();
17  void FillHitPlots();
18  // ^^^ CalibAnaPlot implimentations
19  void DoAna();
20  //void DriftTex(std::string plotdir);
21 
22 
23 
24  private:
25  std::vector< std::string > fEpochList;
27  std::map< int, std::map < int, bool > > fBadFeb;//[plane][module]
28 };
29 
30 
32 : CalibAnaPlot(outpath, group)
33 {
34 }
35 
36 void MakeMEUPerDiblock(std::string outpath, std::string group, unsigned int cap = 0, unsigned int stride = 0)
37 {
38  //group WOULD BE fd_mp5 FOR EXAMPLE.
39  MEUPerDiblock meuperdiblock(outpath, group);
40  meuperdiblock.Initialize();
41  if(cap) meuperdiblock.SetTreeLoopCap (cap);
42  if(stride)meuperdiblock.SetTreeLoopStride(stride);
43 
44  meuperdiblock.DoAna();
45 
46 }
47 
48 //^~^~^~~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
50 {
51  //WRITE YOUR ANALYSIS CODE HERE!
52 
53  std::vector<std::string> allsamples;
54  for( auto& samp : fSamples ){
55  allsamples.push_back(samp.first);
56  ProcessTrees(samp.first);
57  }
58 
59  fTex = new TexBuilder( fOutPath+"/MEUPerDiblock.tex",
60  "Drift by Diblock",
61  "Tyler Alion, Alexander Booth, Yibing Zhang",
62  "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 Diblock.");
63 
64  std::string plotdir = "fd_all_samples";
65 
66  std::vector< std::string > views = {"x", "y"};
67  std::vector< std::string > yaxes = {"pecm", "pecorrcm"};
68  std::vector< std::string > drawplots;
69  for(auto& view : views){
70  for(auto& yax : yaxes){
71  drawplots.push_back(yax+"_diblock_"+view);
72  }
73  }
74 
75  Draw(plotdir,
76  allsamples, // numerator samples
77  "fd_mc_p3", // denom sample: data over all time
78  "", // denom plot: mean for whole view-module group
79  drawplots, // plots to make in numerator samples
80  "" ); // don't draw ratio for now
81 
82  //DriftTex(plotdir);
83 
84  delete fTex;
85 }
86 
87 //^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
88 /*
89 void MEUPerDiblock::DriftTex(std::string plotdir)
90 {
91  fTex->SectionNoNum("By View and Cell Group");
92  fTex->AddFigureRow({plotdir+"/legend"}, {""}, {""});
93  fTex->AddFigureRow({plotdir+"/pecm_time_x_0-31", plotdir+"/pecm_time_y_0-31" }, {"", ""}, {"", ""});
94  fTex->AddFigureRow({plotdir+"/pecm_time_x_32-63", plotdir+"/pecm_time_y_32-63"}, {"", ""}, {"", ""});
95  fTex->AddFigureRow({plotdir+"/pecm_time_x_64-95", plotdir+"/pecm_time_y_64-95"}, {"", ""}, {"", ""});
96  fTex->NewPage();
97  fTex->AddFigureRow({plotdir+"/legend"}, {""}, {""});
98  fTex->AddFigureRow({plotdir+"/pecorrcm_time_x_0-31", plotdir+"/pecorrcm_time_y_0-31" }, {"", ""}, {"", ""});
99  fTex->AddFigureRow({plotdir+"/pecorrcm_time_x_32-63", plotdir+"/pecorrcm_time_y_32-63"}, {"", ""}, {"", ""});
100  fTex->AddFigureRow({plotdir+"/pecorrcm_time_x_64-95", plotdir+"/pecorrcm_time_y_64-95"}, {"", ""}, {"", ""});
101  fTex->NewPage();
102 
103  fTex->SectionNoNum("MEU with FEB Cut");
104  fTex->AddFigureRow({plotdir+"/legend"}, {""}, {""});
105  fTex->AddFigureRow({plotdir+"/pecm_time_x_0-31_febcut", plotdir+"/pecm_time_y_0-31_febcut" }, {"", ""}, {"", ""});
106  fTex->AddFigureRow({plotdir+"/pecm_time_x_32-63_febcut", plotdir+"/pecm_time_y_32-63_febcut"}, {"", ""}, {"", ""});
107  fTex->AddFigureRow({plotdir+"/pecm_time_x_64-95_febcut", plotdir+"/pecm_time_y_64-95_febcut"}, {"", ""}, {"", ""});
108  fTex->NewPage();
109  fTex->AddFigureRow({plotdir+"/legend"}, {""}, {""});
110  fTex->AddFigureRow({plotdir+"/pecorrcm_time_x_0-31_febcut", plotdir+"/pecorrcm_time_y_0-31_febcut" }, {"", ""}, {"", ""});
111  fTex->AddFigureRow({plotdir+"/pecorrcm_time_x_32-63_febcut", plotdir+"/pecorrcm_time_y_32-63_febcut"}, {"", ""}, {"", ""});
112  fTex->AddFigureRow({plotdir+"/pecorrcm_time_x_64-95_febcut", plotdir+"/pecorrcm_time_y_64-95_febcut"}, {"", ""}, {"", ""});
113  fTex->NewPage();
114 
115 
116  unsigned int nPlanes = fDet->NPlanes();
117  for(unsigned int p = 0; p < nPlanes; p++)
118  {
119  fTex->SectionNoNum(Form("Plane %i", p));
120  std::string pstr = (p % 2 == 0 ? "y_" : "x_") + std::to_string(p);
121  fTex->AddFigureRow({plotdir+"/legend"}, {""}, {""});
122  fTex->AddFigureRow({plotdir+"/pecm_time_"+pstr+"_0-31", plotdir+"/pecorrcm_time_"+pstr+"_0-31" }, {"", ""}, {"", ""});
123  fTex->AddFigureRow({plotdir+"/pecm_time_"+pstr+"_32-63", plotdir+"/pecorrcm_time_"+pstr+"_32-63"}, {"", ""}, {"", ""});
124  fTex->AddFigureRow({plotdir+"/pecm_time_"+pstr+"_64-95", plotdir+"/pecorrcm_time_"+pstr+"_64-95"}, {"", ""}, {"", ""});
125  if(p!=nPlanes-1) fTex->NewPage();
126  }
127 }*/
128 
129 //^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
131 {
132  // The filled branches are protected members of
133  // CalibAnaPlot, so can be used here
134 
135  bool abscal_hit = ( w > -100 && w < 100 &&
136  path > 0. &&
137  pecorr > 0. && pecorr/path < 100. &&
138  pe > 0. &&
139  cmFromEnd > 100 && cmFromEnd < 200 );
140  if( !abscal_hit ) return;
141  //if( plane > 191) return;
142 
143  std::string vstr = "";
144  if(view==0){ vstr="x"; }
145  if(view==1){ vstr="y"; }
146 
147 
148  float pecm = pe/path;
149  float pecorrcm = pecorr/path;
150 
151  fPlots["pecm_diblock_"+vstr] ->Fill(diblock, pecm);
152  fPlots["pecorrcm_diblock_"+vstr]->Fill(diblock, pecorrcm);
153 }
154 
155 //^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
157 {
158  fHitVars="w, view, plane, cell, pe, pecorr, path, evt_time, cmFromEnd, diblock,";
159 }
160 
161 //^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
163 {
164  unsigned int nDiblocks = fDet->NDiblocks();
165 
166  std::vector< PlotAxis > xaxes = {
167  {"diblock", "Diblock Number", (int)nDiblocks, 0., (float)nDiblocks}
168  };
169 
170  std::vector< ContentAxis > yaxes = {
171  {"pecm", "PE/cm"},
172  {"pecorrcm", "PECorr/cm"},
173  };
174 
175  std::vector< std::string > views = {"x", "y"};
176  std::string vstr = "";
177  for( auto& v : views){
178  if(v=="x") vstr = "X";
179  if(v=="y") vstr = "Y";
180  for(auto& xax : xaxes){
181  for(auto& yax : yaxes){
182  std::string name = yax.label +"_"+ xax.label +"_"+ v;
183  std::cout << "Schedule: " << name << std::endl;
184 
185  fPlots[name] = new TProfile(name.c_str(), (vstr+" View;" + xax.title +";"+ yax.title).c_str(),
186  xax.nbins, xax.min, xax.max);
187  } // yaxes
188  } // xaxes
189  }
190 } // SchedulePlots
191 
192 //^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
194 {
195  return;
196 }
197 
198 //^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
200 {
201  std::vector< std::string > epoch_list = {
202  "3b", "5a"};
203  /*
204  "2a", "2b","2c","2d","2e",
205  "3b","3c","3d","3e",
206  "4a", "4b.1", "4b.2", "4c", // split 4b up manually
207  "5a","5b",
208  "6a","6b",
209  "7a","7b","7c","7d",
210  "8b" };
211  */
212 
213  fEpochList = epoch_list;
214 
215  for( auto& ep : epoch_list ){
216  if(fDet->IsND()){
217  if(ep=="4b.1" || ep=="4b.2")
218  fSamples["nd_data_ep"+ep]="/nova/ana/users/talion/miniprod5/pcliststop_miniprod5.b/nd_data_epoch4b/calibana/merged.root";
219  else
220  fSamples["nd_data_ep"+ep]="/nova/ana/users/talion/miniprod5/pcliststop_miniprod5.b/nd_data_epoch"+ep+"/calibana/merged.root";
221  if(!fSamples.count("nd_mc")){
222  //fSamples["nd_mc"]="/nova/ana/users/abooth/miniprod5.b/nd_mc/merged.root";
223  }
224  }
225  else if(fDet->IsFD()){
226  fSamples["fd_data_ep"+ep]="/nova/ana/users/talion/miniprod5_calibana/fd_data_epoch"+ep+"/merged.root";
227  if(!fSamples.count("fd_mc_p3")){
228  //fSamples["fd_mc_p2"]="/nova/ana/users/talion/miniprod5_calibana/fd_mc_lowgain/merged.p2.root";
229  fSamples["fd_mc_p3"]="/nova/ana/users/talion/miniprod5_calibana/fd_mc_highgain/merged.p3.root";
230  //fSamples["fd_mc_p5"]="/nova/ana/users/talion/miniprod5_calibana/fd_mc_highgain/merged.p5.root";
231  }
232  }
233  }
234 
235 }
236 
const XML_Char * name
Definition: expat.h:151
std::vector< std::string > fEpochList
std::map< std::string, TH1 * > fPlots
Definition: CalibAnaPlot.h:57
void MakeMEUPerDiblock(std::string outpath, std::string group, unsigned int cap=0, unsigned int stride=0)
std::string fOutPath
Definition: CalibAnaPlot.h:62
bool IsFD()
Definition: Detector.h:21
void Initialize()
Definition: CalibAnaPlot.h:138
std::string fHitVars
Definition: CalibAnaPlot.h:67
std::map< int, std::map< int, bool > > fBadFeb
void ProcessTrees(std::string sample)
Definition: CalibAnaPlot.h:329
TexBuilder * fTex
MEUPerDiblock(std::string outpath, std::string group)
void SetTreeLoopStride(unsigned int stride)
Definition: CalibAnaPlot.h:32
OStream cout
Definition: OStream.cxx:6
bool IsND()
Definition: Detector.h:20
void Draw(std::string pdfdir, std::vector< Plot > plots, Plot denom_plot, std::string ratio_title="")
Definition: CalibAnaPlot.h:168
void ScheduleAllDataPlots()
unsigned int NDiblocks()
Definition: Detector.h:14
std::map< std::string, std::string > fSamples
Definition: CalibAnaPlot.h:59
Detector * fDet
Definition: CalibAnaPlot.h:68
enum BeamMode string