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