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