LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
CalorPad.cxx
Go to the documentation of this file.
1 
12 
13 #include "TFile.h"
14 #include "TGraph.h"
15 #include "TH1F.h"
16 #include "TPad.h"
17 
20 #include "cetlib/search_path.h"
31 
32 namespace {
33  // Utility function to make uniform error messages.
34  void writeErrMsg(const char* fcn, cet::exception const& e)
35  {
36  mf::LogWarning("CalorPad") << "CalorPad::" << fcn << " failed with message:\n" << e;
37  }
38 }
39 
40 evd::CalorPad::CalorPad(const char* name,
41  const char* title,
42  double x1,
43  double y1,
44  double x2,
45  double y2,
46  int curvetype)
47  : DrawingPad(name, title, x1, y1, x2, y2), fcurvetype(curvetype)
48 {
49 
50  // Set up pad.
51  this->Pad()->cd();
52  this->Pad()->SetBit(kCannotPick);
53  this->Pad()->SetBit(TPad::kCannotMove);
54  this->Pad()->SetFillColor(kWhite);
55  this->Pad()->SetLeftMargin(0.10);
56  this->Pad()->SetRightMargin(0.025);
57  this->Pad()->SetTopMargin(0.025);
58  this->Pad()->SetBottomMargin(0.10);
59  this->Pad()->Draw();
60 
61  dedx_range_pro = 0;
62  dedx_range_ka = 0;
63  dedx_range_pi = 0;
64  dedx_range_mu = 0;
65  ke_range_pro = 0;
66  ke_range_ka = 0;
67  ke_range_pi = 0;
68  ke_range_mu = 0;
69 
70  fView = new evdb::View2D();
71 }
72 
73 //......................................................................
74 // Destructor.
76 {
77  if (dedx_range_pro) {
78  delete dedx_range_pro;
79  dedx_range_pro = 0;
80  }
81  if (dedx_range_ka) {
82  delete dedx_range_ka;
83  dedx_range_ka = 0;
84  }
85  if (dedx_range_pi) {
86  delete dedx_range_pi;
87  dedx_range_pi = 0;
88  }
89  if (dedx_range_mu) {
90  delete dedx_range_mu;
91  dedx_range_mu = 0;
92  }
93  if (ke_range_pro) {
94  delete ke_range_pro;
95  ke_range_pro = 0;
96  }
97  if (ke_range_ka) {
98  delete ke_range_ka;
99  ke_range_ka = 0;
100  }
101  if (ke_range_pi) {
102  delete ke_range_pi;
103  ke_range_pi = 0;
104  }
105  if (ke_range_mu) {
106  delete ke_range_mu;
107  ke_range_mu = 0;
108  }
109  if (fView) {
110  delete fView;
111  fView = 0;
112  }
113 }
114 
115 //......................................................................
116 // Draw selected objects.
117 
118 void evd::CalorPad::Draw(const char* /*opt*/)
119 {
120 
121  this->Pad()->cd();
122 
123  //Remove all previous objects from Pad's primitive list
124  this->Pad()->Clear();
125 
126  //Remove all previous TPolyMarkers, TLatexs, etc... from list of such objects
127  fView->Clear();
128 
129  //Draw coordinate axis and also GEANT based dE/dx vs. Range, or KE vs. Range, curves.
130  DrawRefCurves();
131 
132  // grab the event from the singleton
134 
135  // Insert graphic objects into fView collection.
136  if (evt) {
137  try {
138  if (fcurvetype == 1)
139  AnalysisBaseDraw()->DrawDeDx(*evt, fView);
140  else if (fcurvetype == 0)
142  else if (fcurvetype == 2)
144  }
145  catch (cet::exception const& e) {
146  if (fcurvetype == 1)
147  writeErrMsg("Draw->DrawDeDx", e);
148  else if (fcurvetype == 0)
149  writeErrMsg("Draw->DrawKineticEnergy", e);
150  else if (fcurvetype == 2)
151  writeErrMsg("Draw->CalorShower", e);
152  }
153  }
154 
155  // Draw objects on pad.
156  fView->Draw();
157  fPad->Modified();
158  fPad->Update();
159 }
160 
161 //......................................................................
162 // Draw truth curves
163 
165 {
166 
167  if (dedx_range_pro) {
168  delete dedx_range_pro;
169  dedx_range_pro = 0;
170  }
171  if (dedx_range_ka) {
172  delete dedx_range_ka;
173  dedx_range_ka = 0;
174  }
175  if (dedx_range_pi) {
176  delete dedx_range_pi;
177  dedx_range_pi = 0;
178  }
179  if (dedx_range_mu) {
180  delete dedx_range_mu;
181  dedx_range_mu = 0;
182  }
183  if (ke_range_pro) {
184  delete ke_range_pro;
185  ke_range_pro = 0;
186  }
187  if (ke_range_ka) {
188  delete ke_range_ka;
189  ke_range_ka = 0;
190  }
191  if (ke_range_pi) {
192  delete ke_range_pi;
193  ke_range_pi = 0;
194  }
195  if (ke_range_mu) {
196  delete ke_range_mu;
197  ke_range_mu = 0;
198  }
199 
200  double ymax;
201  if (fcurvetype == 1)
202  ymax = 50.0;
203  else
204  ymax = 200.0;
205  TH1F* h = this->Pad()->DrawFrame(0.0, 0.0, 25.0, ymax);
206  h->GetXaxis()->SetLabelSize(0.04);
207  h->GetXaxis()->SetTitleSize(0.04);
208  h->GetXaxis()->CenterTitle();
209  h->GetYaxis()->SetLabelSize(0.04);
210  h->GetYaxis()->SetTitleSize(0.04);
211  h->GetYaxis()->CenterTitle();
212 
213  if (fcurvetype == 1) {
214  h->GetXaxis()->SetTitle("Residual Range (cm)");
215  h->GetYaxis()->SetTitle("dE/dx (MeV/cm)");
216  }
217  else {
218  h->GetXaxis()->SetTitle("Total Range (cm)");
219  h->GetYaxis()->SetTitle("T (MeV)");
220  }
221 
223 
224  cet::search_path sp("FW_SEARCH_PATH");
225  if (!sp.find_file(anaOpt->fCalorTemplateFileName + ".root", fROOTfile))
226  throw cet::exception("Chi2ParticleID")
227  << "cannot find the root template file: \n"
228  << anaOpt->fCalorTemplateFileName << "\n bail ungracefully.\n";
229 
230  TFile* file = TFile::Open(fROOTfile.c_str());
231  if (fcurvetype == 1) {
232  dedx_range_pro = (TGraph*)file->Get("dedx_range_pro");
233  dedx_range_ka = (TGraph*)file->Get("dedx_range_ka");
234  dedx_range_pi = (TGraph*)file->Get("dedx_range_pi");
235  dedx_range_mu = (TGraph*)file->Get("dedx_range_mu");
236 
237  dedx_range_pro->SetMarkerStyle(7);
238  dedx_range_ka->SetMarkerStyle(7);
239  dedx_range_pi->SetMarkerStyle(7);
240  dedx_range_mu->SetMarkerStyle(7);
241 
242  dedx_range_pro->SetMarkerColor(kBlack);
243  dedx_range_ka->SetMarkerColor(kGray + 2);
244  dedx_range_pi->SetMarkerColor(kGray + 1);
245  dedx_range_mu->SetMarkerColor(kGray);
246 
247  dedx_range_mu->Draw("P,same");
248  dedx_range_pi->Draw("P,same");
249  dedx_range_ka->Draw("P,same");
250  dedx_range_pro->Draw("P,same");
251  }
252  else {
253  ke_range_pro = (TGraph*)file->Get("kinen_range_pro");
254  ke_range_ka = (TGraph*)file->Get("kinen_range_ka");
255  ke_range_pi = (TGraph*)file->Get("kinen_range_pi");
256  ke_range_mu = (TGraph*)file->Get("kinen_range_mu");
257 
258  ke_range_pro->SetMarkerStyle(7);
259  ke_range_ka->SetMarkerStyle(7);
260  ke_range_pi->SetMarkerStyle(7);
261  ke_range_mu->SetMarkerStyle(7);
262 
263  ke_range_pro->SetMarkerColor(kBlack);
264  ke_range_ka->SetMarkerColor(kGray + 2);
265  ke_range_pi->SetMarkerColor(kGray + 1);
266  ke_range_mu->SetMarkerColor(kGray);
267 
268  ke_range_mu->Draw("P,same");
269  ke_range_pi->Draw("P,same");
270  ke_range_ka->Draw("P,same");
271  ke_range_pro->Draw("P,same");
272  }
273  file->Close();
274 }
275 
AnalysisBaseDrawer * AnalysisBaseDraw()
Definition: DrawingPad.cxx:143
void DrawDeDx(const art::Event &evt, evdb::View2D *view)
void DrawRefCurves()
Definition: CalorPad.cxx:164
Class to aid in the rendering of AnalysisBase objects.
const art::Event * GetEvent() const
Definition: EventHolder.cxx:45
int fcurvetype
Definition: CalorPad.h:50
void Draw(const char *opt=0)
Definition: CalorPad.cxx:118
Float_t y1[n_points_granero]
Definition: compare.C:5
TGraph * ke_range_pi
pion template
Definition: CalorPad.h:48
Float_t x1[n_points_granero]
Definition: compare.C:5
evdb::View2D * fView
Collection of graphics objects to render; text labels.
Definition: CalorPad.h:52
TGraph * dedx_range_pi
pion template
Definition: CalorPad.h:43
A collection of drawable 2-D objects.
void Clear()
Definition: View2D.cxx:109
Singleton to hold the current art::Event for the event display.
Float_t y2[n_points_geant4]
Definition: compare.C:26
std::string fROOTfile
Definition: CalorPad.h:40
std::string fCalorTemplateFileName
files that have calorimetry template curves
void Draw()
Definition: View2D.cxx:89
static EventHolder * Instance()
Definition: EventHolder.cxx:15
Drawing pad showing calorimetric particle ID information.
CalorPad(const char *name, const char *title, double x1, double y1, double x2, double y2, int curvetype)
Definition: CalorPad.cxx:40
Base class for event display drawing pads.
Definition: DrawingPad.h:27
TPad * Pad()
Definition: DrawingPad.h:31
TGraph * ke_range_ka
kaon template
Definition: CalorPad.h:47
TGraph * ke_range_pro
proton template
Definition: CalorPad.h:46
TFile * file
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
TPad * fPad
The ROOT graphics pad.
Definition: DrawingPad.h:45
TCEvent evt
Definition: DataStructs.cxx:8
TGraph * dedx_range_ka
kaon template
Definition: CalorPad.h:42
void CalorShower(const art::Event &evt, evdb::View2D *view)
Float_t x2[n_points_geant4]
Definition: compare.C:26
Float_t e
Definition: plot.C:35
TGraph * ke_range_mu
muon template
Definition: CalorPad.h:49
TGraph * dedx_range_mu
muon template
Definition: CalorPad.h:44
void DrawKineticEnergy(const art::Event &evt, evdb::View2D *view)
TGraph * dedx_range_pro
proton template
Definition: CalorPad.h:41
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33