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