Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SimpleTrackingAnalysis.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SimpleTrackingAnalysis.C
2 
3 #include <phool/getClass.h>
6 
8 //#include <g4hough/PHG4HoughTransform.h> // CAUSES ERRORS DUE TO VertexFinder.h FAILING TO FIND <Eigen/LU>
9 
10 
12 #include <g4main/PHG4Particle.h>
13 #include <g4main/PHG4VtxPoint.h>
14 
15 #include <g4hough/SvtxVertexMap.h>
16 #include <g4hough/SvtxVertex.h>
17 #include <g4hough/SvtxTrackMap.h>
18 #include <g4hough/SvtxTrack.h>
19 
20 #include <g4eval/SvtxEvalStack.h>
21 #include <g4eval/SvtxTrackEval.h>
22 #include <g4eval/SvtxVertexEval.h>
23 #include <g4eval/SvtxTruthEval.h>
24 
25 // --- common to all calorimeters
26 #include <calobase/RawTowerGeomContainer.h>
27 #include <calobase/RawTowerContainer.h>
28 #include <calobase/RawTower.h>
29 #include <calobase/RawCluster.h>
30 #include <calobase/RawClusterContainer.h>
31 #include <g4eval/CaloEvalStack.h>
34 
35 #include <TH1D.h>
36 #include <TH2D.h>
37 #include <TProfile2D.h>
38 
39 #include <iostream>
40 //#include <cassert>
41 
42 using namespace std;
43 
44 
45 
47 {
48  cout << "SimpleTrackingAnalysis class constructor called " << endl;
49  nevents = 0;
50  nerrors = 0;
51  nwarnings = 0;
52  nlayers = 7;
53  verbosity = 0;
54  magneticfield = 1.4; // default is 1.5 but Mike's tracking stuff is using 1.4 for now...
55  //docalocuts = false;
56 }
57 
58 
59 
61 {
62 
63  // --------------------------------------------------------------------------------
64  // --- This is the class initialization method
65  // --- Get a pointer to the Fun4All server to register histograms
66  // --- Histograms are declared in class header file
67  // --- Histograms are instantiated here and then registered with the Fun4All server
68  // --------------------------------------------------------------------------------
69 
70  cout << "SimpleTrackingAnalysis::Init called" << endl;
71 
72  // --- get instance of
74 
75 
76 
77  // --- special stuff...
78 
79 
80 
81 
82  // --- additional tracking histograms for studying quality
83 
84  _recopt_quality = new TH2D("recopt_quality", "", 20,0.0,10.0, 100,0.0,5.0);
85  _recopt_quality_tracks_all = new TH2D("recopt_quality_tracks_all", "", 20,0.0,10.0, 100,0.0,5.0);
86  _recopt_quality_tracks_recoWithin4Percent = new TH2D("recopt_quality_tracks_recoWithin4Percent", "", 20,0.0,10.0, 100,0.0,5.0);
87  _truept_quality_particles_recoWithin4Percent = new TH2D("truept_quality_particles_recoWithin4Percent", "", 20,0.0,10.0, 100,0.0,5.0);
88 
93 
94 
95 
96  // --- histograms over true pt, used for finding efficiencies
97 
98  _truept_dca = new TH2D("truept_dca", "", 20,0.0,10.0, 200,-0.1,0.1);
99  _truept_dptoverpt = new TH2D("truept_dptoverpt", "", 40,0.0,40.0, 200,-0.5,0.5);
100  _truept_particles_leavingAllHits = new TH1D("truept_particles_leavingAllHits", "", 20,0.0,10.0);
101  _truept_particles_recoWithExactHits = new TH1D("truept_particles_recoWithExactHits", "", 20,0.0,10.0);
102  _truept_particles_recoWithin1Hit = new TH1D("truept_particles_recoWithin1Hit", "", 20,0.0,10.0);
103  _truept_particles_recoWithin2Hits = new TH1D("truept_particles_recoWithin2Hits", "", 20,0.0,10.0);
104  _truept_particles_recoWithin3Percent = new TH1D("truept_particles_recoWithin3Percent", "", 20,0.0,10.0);
105  _truept_particles_recoWithin4Percent = new TH1D("truept_particles_recoWithin4Percent", "", 20,0.0,10.0);
106  _truept_particles_recoWithin5Percent = new TH1D("truept_particles_recoWithin5Percent", "", 20,0.0,10.0);
107 
117 
118 
119 
120  // --- (mostly) the same set of histograms over reconstructed pt, used for studying purity
121 
122  _recopt_tracks_all = new TH1D("recopt_tracks_all", "", 20,0.0,10.0);
123  _recopt_tracks_recoWithExactHits = new TH1D("recopt_tracks_recoWithExactHits", "", 20,0.0,10.0);
124  _recopt_tracks_recoWithin1Hit = new TH1D("recopt_tracks_recoWithin1Hit", "", 20,0.0,10.0);
125  _recopt_tracks_recoWithin2Hits = new TH1D("recopt_tracks_recoWithin2Hits", "", 20,0.0,10.0);
126  _recopt_tracks_recoWithin3Percent = new TH1D("recopt_tracks_recoWithin3Percent", "", 20,0.0,10.0);
127  _recopt_tracks_recoWithin4Percent = new TH1D("recopt_tracks_recoWithin4Percent", "", 20,0.0,10.0);
128  _recopt_tracks_recoWithin5Percent = new TH1D("recopt_tracks_recoWithin5Percent", "", 20,0.0,10.0);
129 
137 
138 
139 
140  // --- purity study with calorimeter cuts
141 
142  th2d_recopt_tracks_withcalocuts_all = new TH2D(Form("th2d_recopt_tracks_withcalocuts_all"), "", 80,0.0,40.0, 20,0.0,2.0);
143  th2d_recopt_tracks_withcalocuts_recoWithExactHits = new TH2D(Form("th2d_recopt_tracks_withcalocuts_recoWithExactHits"), "", 80,0.0,40.0, 20,0.0,2.0);
144  th2d_recopt_tracks_withcalocuts_recoWithin1Hit = new TH2D(Form("th2d_recopt_tracks_withcalocuts_recoWithin1Hit"), "", 80,0.0,40.0, 20,0.0,2.0);
145  th2d_recopt_tracks_withcalocuts_recoWithin2Hits = new TH2D(Form("th2d_recopt_tracks_withcalocuts_recoWithin2Hits"), "", 80,0.0,40.0, 20,0.0,2.0);
146  th2d_recopt_tracks_withcalocuts_recoWithin3Percent = new TH2D(Form("th2d_recopt_tracks_withcalocuts_recoWithin3Percent"), "", 80,0.0,40.0, 20,0.0,2.0);
147  th2d_recopt_tracks_withcalocuts_recoWithin4Percent = new TH2D(Form("th2d_recopt_tracks_withcalocuts_recoWithin4Percent"), "", 80,0.0,40.0, 20,0.0,2.0);
148  th2d_recopt_tracks_withcalocuts_recoWithin5Percent = new TH2D(Form("th2d_recopt_tracks_withcalocuts_recoWithin5Percent"), "", 80,0.0,40.0, 20,0.0,2.0);
149  th2d_recopt_tracks_withcalocuts_recoWithin1Sigma = new TH2D(Form("th2d_recopt_tracks_withcalocuts_recoWithin1Sigma"), "", 80,0.0,40.0, 20,0.0,2.0);
150  th2d_recopt_tracks_withcalocuts_recoWithin2Sigma = new TH2D(Form("th2d_recopt_tracks_withcalocuts_recoWithin2Sigma"), "", 80,0.0,40.0, 20,0.0,2.0);
151  th2d_recopt_tracks_withcalocuts_recoWithin3Sigma = new TH2D(Form("th2d_recopt_tracks_withcalocuts_recoWithin3Sigma"), "", 80,0.0,40.0, 20,0.0,2.0);
152 
163 
164 
165 
166  // --- efficiency study with calorimter cuts
167 
168  th2d_truept_particles_withcalocuts_leavingAllHits = new TH2D(Form("th2d_truept_particles_withcalocuts_leavingAllHits"), "", 80,0.0,40.0, 20,0.0,2.0);
169  th2d_truept_particles_withcalocuts_recoWithExactHits = new TH2D(Form("th2d_truept_particles_withcalocuts_recoWithExactHits"), "", 80,0.0,40.0, 20,0.0,2.0);
170  th2d_truept_particles_withcalocuts_recoWithin1Hit = new TH2D(Form("th2d_truept_particles_withcalocuts_recoWithin1Hit"), "", 80,0.0,40.0, 20,0.0,2.0);
171  th2d_truept_particles_withcalocuts_recoWithin2Hits = new TH2D(Form("th2d_truept_particles_withcalocuts_recoWithin2Hits"), "", 80,0.0,40.0, 20,0.0,2.0);
172  th2d_truept_particles_withcalocuts_recoWithin3Percent = new TH2D(Form("th2d_truept_particles_withcalocuts_recoWithin3Percent"), "", 80,0.0,40.0, 20,0.0,2.0);
173  th2d_truept_particles_withcalocuts_recoWithin4Percent = new TH2D(Form("th2d_truept_particles_withcalocuts_recoWithin4Percent"), "", 80,0.0,40.0, 20,0.0,2.0);
174  th2d_truept_particles_withcalocuts_recoWithin5Percent = new TH2D(Form("th2d_truept_particles_withcalocuts_recoWithin5Percent"), "", 80,0.0,40.0, 20,0.0,2.0);
175  th2d_truept_particles_withcalocuts_recoWithin1Sigma = new TH2D(Form("th2d_truept_particles_withcalocuts_recoWithin1Sigma"), "", 80,0.0,40.0, 20,0.0,2.0);
176  th2d_truept_particles_withcalocuts_recoWithin2Sigma = new TH2D(Form("th2d_truept_particles_withcalocuts_recoWithin2Sigma"), "", 80,0.0,40.0, 20,0.0,2.0);
177  th2d_truept_particles_withcalocuts_recoWithin3Sigma = new TH2D(Form("th2d_truept_particles_withcalocuts_recoWithin3Sigma"), "", 80,0.0,40.0, 20,0.0,2.0);
178 
189 
190 
191 
192  // --- new additional (eventual replacement?) histograms for purity study
193 
194  th2d_reco_calo_nhits8 = new TH2D("th2d_reco_calo_nhits8", "", 80,0.0,40.0, 20,0.0,2.0);
195  th2d_reco_calo_nhits7 = new TH2D("th2d_reco_calo_nhits7", "", 80,0.0,40.0, 20,0.0,2.0);
196  th2d_reco_calo_nhits6 = new TH2D("th2d_reco_calo_nhits6", "", 80,0.0,40.0, 20,0.0,2.0);
197  th2d_reco_calo_nhits5 = new TH2D("th2d_reco_calo_nhits5", "", 80,0.0,40.0, 20,0.0,2.0);
198  th2d_reco_calo_nhits4 = new TH2D("th2d_reco_calo_nhits4", "", 80,0.0,40.0, 20,0.0,2.0);
199  th2d_reco_calo_nhits3 = new TH2D("th2d_reco_calo_nhits3", "", 80,0.0,40.0, 20,0.0,2.0);
200  th2d_reco_calo_nhits2 = new TH2D("th2d_reco_calo_nhits2", "", 80,0.0,40.0, 20,0.0,2.0);
201  th2d_reco_calo_nhits1 = new TH2D("th2d_reco_calo_nhits1", "", 80,0.0,40.0, 20,0.0,2.0);
202 
203  th2d_reco_calo_pt1sigma = new TH2D("th2d_reco_calo_pt1sigma", "", 80,0.0,40.0, 20,0.0,2.0);
204  th2d_reco_calo_pt2sigma = new TH2D("th2d_reco_calo_pt2sigma", "", 80,0.0,40.0, 20,0.0,2.0);
205  th2d_reco_calo_pt3sigma = new TH2D("th2d_reco_calo_pt3sigma", "", 80,0.0,40.0, 20,0.0,2.0);
206  th2d_reco_calo_pt4sigma = new TH2D("th2d_reco_calo_pt4sigma", "", 80,0.0,40.0, 20,0.0,2.0);
207  th2d_reco_calo_pt5sigma = new TH2D("th2d_reco_calo_pt5sigma", "", 80,0.0,40.0, 20,0.0,2.0);
208  th2d_reco_calo_pt6sigma = new TH2D("th2d_reco_calo_pt6sigma", "", 80,0.0,40.0, 20,0.0,2.0);
209 
210 
211 
212  // --- new additional (eventual replacement?) histograms for purity study
213 
214  th2d_true_calo_nhits8 = new TH2D("th2d_true_calo_nhits8", "", 80,0.0,40.0, 20,0.0,2.0);
215  th2d_true_calo_nhits7 = new TH2D("th2d_true_calo_nhits7", "", 80,0.0,40.0, 20,0.0,2.0);
216  th2d_true_calo_nhits6 = new TH2D("th2d_true_calo_nhits6", "", 80,0.0,40.0, 20,0.0,2.0);
217  th2d_true_calo_nhits5 = new TH2D("th2d_true_calo_nhits5", "", 80,0.0,40.0, 20,0.0,2.0);
218  th2d_true_calo_nhits4 = new TH2D("th2d_true_calo_nhits4", "", 80,0.0,40.0, 20,0.0,2.0);
219  th2d_true_calo_nhits3 = new TH2D("th2d_true_calo_nhits3", "", 80,0.0,40.0, 20,0.0,2.0);
220  th2d_true_calo_nhits2 = new TH2D("th2d_true_calo_nhits2", "", 80,0.0,40.0, 20,0.0,2.0);
221  th2d_true_calo_nhits1 = new TH2D("th2d_true_calo_nhits1", "", 80,0.0,40.0, 20,0.0,2.0);
222 
223  th2d_true_calo_pt1sigma = new TH2D("th2d_true_calo_pt1sigma", "", 80,0.0,40.0, 20,0.0,2.0);
224  th2d_true_calo_pt2sigma = new TH2D("th2d_true_calo_pt2sigma", "", 80,0.0,40.0, 20,0.0,2.0);
225  th2d_true_calo_pt3sigma = new TH2D("th2d_true_calo_pt3sigma", "", 80,0.0,40.0, 20,0.0,2.0);
226  th2d_true_calo_pt4sigma = new TH2D("th2d_true_calo_pt4sigma", "", 80,0.0,40.0, 20,0.0,2.0);
227  th2d_true_calo_pt5sigma = new TH2D("th2d_true_calo_pt5sigma", "", 80,0.0,40.0, 20,0.0,2.0);
228  th2d_true_calo_pt6sigma = new TH2D("th2d_true_calo_pt6sigma", "", 80,0.0,40.0, 20,0.0,2.0);
229 
230 
231 
232  // --- vertex residual histograms
233 
234  _dx_vertex = new TH1D("dx_vertex", "dx_vertex", 200,-0.03,0.03);
235  _dy_vertex = new TH1D("dy_vertex", "dy_vertex", 200,-0.03,0.03);
236  _dz_vertex = new TH1D("dz_vertex", "dz_vertex", 200,-0.03,0.03);
240 
241  hmult = new TH1D("hmult","",5000,-0.5,4999.5);
242  hmult_vertex = new TH1D("hmult_vertex","",5000,-0.5,4999.5);
243  se->registerHisto(hmult);
245 
246 
247  return 0;
248 
249 }
250 
251 
252 
254 {
255 
256  // --- This is the class process_event method
257  // --- This is where the bulk of the analysis is done
258  // --- Here we get the various data nodes we need to do the analysis
259  // --- Then we use variables (accessed through class methods) to perform calculations
260 
261  if ( verbosity > -1 )
262  {
263  cout << endl;
264  cout << "------------------------------------------------------------------------------------" << endl;
265  cout << "Now processing event number " << nevents << endl; // would be good to add verbosity switch
266  }
267 
268  ++nevents; // You may as youtself, why ++nevents (pre-increment) rather
269  // than nevents++ (post-increment)? The short answer is performance.
270  // For simple types it probably doesn't matter, but it can really help
271  // for complex types (like the iterators below).
272 
273 
274  // --- Truth level information
275  PHG4TruthInfoContainer* truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,"G4TruthInfo");
276  if ( !truthinfo )
277  {
278  cerr << PHWHERE << " ERROR: Can't find G4TruthInfo" << endl;
279  exit(-1);
280  }
281 
282  // --- SvtxTrackMap
283  SvtxTrackMap* trackmap = findNode::getClass<SvtxTrackMap>(topNode,"SvtxTrackMap");
284  if ( !trackmap )
285  {
286  cerr << PHWHERE << " ERROR: Can't find SvtxTrackMap" << endl;
287  exit(-1);
288  }
289 
290  // --- SvtxVertexMap
291  SvtxVertexMap* vertexmap = findNode::getClass<SvtxVertexMap>(topNode,"SvtxVertexMap");
292  if ( !vertexmap )
293  {
294  cerr << PHWHERE << " ERROR: Can't find SvtxVertexMap" << endl;
295  exit(-1);
296  }
297 
298 
299 
300  // --- Create SVTX eval stack
301  SvtxEvalStack svtxevalstack(topNode);
302  // --- Get evaluator objects from the eval stack
303  SvtxVertexEval* vertexeval = svtxevalstack.get_vertex_eval();
304  SvtxTrackEval* trackeval = svtxevalstack.get_track_eval();
305  SvtxTruthEval* trutheval = svtxevalstack.get_truth_eval();
306 
307 
308 
309  if ( verbosity > 0 ) cout << "Now going to loop over truth partcles..." << endl; // need verbosity switch
310 
311  // --- Loop over all truth particles
313  for ( PHG4TruthInfoContainer::ConstIterator iter = range.first; iter != range.second; ++iter )
314  {
315  PHG4Particle* g4particle = iter->second; // You may ask yourself, why second?
316  // In C++ the iterator is a map, which has two members
317  // first is the key (analogous the index of an arry),
318  // second is the value (analogous to the value stored for the array index)
319  int particleID = g4particle->get_pid();
320 
321  if ( trutheval->get_embed(g4particle) <= 0 && fabs(particleID) == 11 && verbosity > 0 )
322  {
323  cout << "NON EMBEDDED ELECTRON!!! WHEE!!! " << particleID << " " << iter->first << endl;
324  }
325 
326  if ( trutheval->get_embed(g4particle) <= 0 ) continue; // only look at embedded particles // no good for hits files
327  bool iselectron = fabs(particleID) == 11;
328  bool ispion = fabs(particleID) == 211;
329  if ( verbosity > 0 ) cout << "embedded particle ID is " << particleID << " ispion " << ispion << " iselectron " << iselectron << " " << iter->first << endl;
330 
331  set<PHG4Hit*> g4hits = trutheval->all_truth_hits(g4particle);
332  float ng4hits = g4hits.size();
333 
334  float truept = sqrt(pow(g4particle->get_px(),2)+pow(g4particle->get_py(),2));
335  float true_energy = g4particle->get_e();
336 
337  // --- Get the reconsructed SvtxTrack based on the best candidate from the truth info
338  SvtxTrack* track = trackeval->best_track_from(g4particle);
339  if (!track) continue;
340  float recopt = track->get_pt();
341  float recop = track->get_p();
342 
343  if ( verbosity > 0 )
344  {
345  cout << "truept is " << truept << endl;
346  cout << "recopt is " << recopt << endl;
347  cout << "true energy is " << true_energy << endl;
348  }
349 
350  // --- energy variables directly from the track object
351  float emc_energy_track = track->get_cal_energy_3x3(SvtxTrack::CEMC);
352  float hci_energy_track = track->get_cal_energy_3x3(SvtxTrack::HCALIN);
353  float hco_energy_track = track->get_cal_energy_3x3(SvtxTrack::HCALOUT);
354 
355  if ( verbosity > 0 )
356  {
357  cout << "emc_energy_track is " << emc_energy_track << endl;
358  cout << "hci_energy_track is " << hci_energy_track << endl;
359  cout << "hco_energy_track is " << hco_energy_track << endl;
360  }
361 
362  // -------------------------------------------------------------------------------------
363  // --- IMPORTANT NOTE: according to Jin, dphi and deta will not work correctly in HIJING
364 
365  float emc_dphi_track = track->get_cal_dphi(SvtxTrack::CEMC);
366  float hci_dphi_track = track->get_cal_dphi(SvtxTrack::HCALIN);
367  float hco_dphi_track = track->get_cal_dphi(SvtxTrack::HCALOUT);
368 
369  float emc_deta_track = track->get_cal_deta(SvtxTrack::CEMC);
370  float hci_deta_track = track->get_cal_deta(SvtxTrack::HCALIN);
371  float hco_deta_track = track->get_cal_deta(SvtxTrack::HCALOUT);
372 
373  float assoc_dphi = 0.1; // adjust as needed, consider class set method
374  float assoc_deta = 0.1; // adjust as needed, consider class set method
375  bool good_emc_assoc = fabs(emc_dphi_track) < assoc_dphi && fabs(emc_deta_track) < assoc_deta;
376  bool good_hci_assoc = fabs(hci_dphi_track) < assoc_dphi && fabs(hci_deta_track) < assoc_deta;
377  bool good_hco_assoc = fabs(hco_dphi_track) < assoc_dphi && fabs(hco_deta_track) < assoc_deta;
378 
379  // ------------------------------------------------------------------------------------------
380 
381 
382  float hct_energy_track = 0;
383  if ( hci_energy_track >= 0 ) hct_energy_track += hci_energy_track;
384  if ( hco_energy_track >= 0 ) hct_energy_track += hco_energy_track;
385 
386  float total_energy_dumb = 0;
387  if ( emc_energy_track >= 0 ) total_energy_dumb += emc_energy_track;
388  if ( hci_energy_track >= 0 ) total_energy_dumb += hci_energy_track;
389  if ( hco_energy_track >= 0 ) total_energy_dumb += hco_energy_track;
390 
391  float total_energy_smart = 0;
392  if ( good_emc_assoc ) total_energy_smart += emc_energy_track;
393  if ( good_hci_assoc ) total_energy_smart += hci_energy_track;
394  if ( good_hco_assoc ) total_energy_smart += hco_energy_track;
395 
396 
397 
398  // ----------------------------------------------------------------------
399  // ----------------------------------------------------------------------
400  // ----------------------------------------------------------------------
401 
402  //cout << "starting the main part of the truth analysis" << endl;
403 
404  // examine truth particles that leave all (7 or 8 depending on design) detector hits
405  if ( ng4hits == nlayers )
406  {
407  _truept_particles_leavingAllHits->Fill(truept);
408 
409  unsigned int nfromtruth = trackeval->get_nclusters_contribution(track,g4particle);
410 
411  unsigned int ndiff = abs((int)nfromtruth-(int)nlayers);
412  if ( ndiff <= 2 ) _truept_particles_recoWithin2Hits->Fill(truept);
413  if ( ndiff <= 1 ) _truept_particles_recoWithin1Hit->Fill(truept);
414  if ( ndiff == 0 ) _truept_particles_recoWithExactHits->Fill(truept);
415 
416  float diff = fabs(recopt-truept)/truept;
417  if ( diff < 0.05 ) _truept_particles_recoWithin5Percent->Fill(truept);
418  if ( diff < 0.04 )
419  {
422  }
423  if ( diff < 0.03 ) _truept_particles_recoWithin3Percent->Fill(truept);
424 
425  double good_energy = total_energy_dumb - 3.14;
426 
427 
428  double eoverp = good_energy/recop;
429  double sigmapt = 0.011 + 0.0008*recopt;
431  if ( ndiff <= 2 ) th2d_truept_particles_withcalocuts_recoWithin2Hits->Fill(truept,eoverp);
432  if ( ndiff <= 1 ) th2d_truept_particles_withcalocuts_recoWithin1Hit->Fill(truept,eoverp);
433  if ( ndiff == 0 ) th2d_truept_particles_withcalocuts_recoWithExactHits->Fill(truept,eoverp);
434  if ( diff < 0.05 ) th2d_truept_particles_withcalocuts_recoWithin5Percent->Fill(truept,eoverp);
435  if ( diff < 0.04 ) th2d_truept_particles_withcalocuts_recoWithin4Percent->Fill(truept,eoverp);
436  if ( diff < 0.03 ) th2d_truept_particles_withcalocuts_recoWithin3Percent->Fill(truept,eoverp);
437  if ( diff < 1.0*sigmapt ) th2d_truept_particles_withcalocuts_recoWithin1Sigma->Fill(recopt,eoverp);
438  if ( diff < 2.0*sigmapt ) th2d_truept_particles_withcalocuts_recoWithin2Sigma->Fill(recopt,eoverp);
439  if ( diff < 3.0*sigmapt ) th2d_truept_particles_withcalocuts_recoWithin3Sigma->Fill(recopt,eoverp);
440 
441 
442  } // end of requirement of ng4hits == nlayers
443 
444  } // end of loop over truth particles
445 
446 
447 
448  // loop over all reco particles
449  int ntracks = 0;
450  for ( SvtxTrackMap::Iter iter = trackmap->begin(); iter != trackmap->end(); ++iter )
451  {
452 
453  // --- Get the StxTrack object (from the iterator)
454  SvtxTrack* track = iter->second;
455  float recopt = track->get_pt();
456  float recop = track->get_p();
457 
458  // --- Get the truth particle from the evaluator
459  PHG4Particle* g4particle = trackeval->max_truth_particle_by_nclusters(track);
460  float truept = sqrt(pow(g4particle->get_px(),2)+pow(g4particle->get_py(),2));
461  int particleID = g4particle->get_pid();
462  if ( verbosity > 5 ) cout << "particle ID is " << particleID << endl;
463  bool iselectron = fabs(particleID) == 11;
464  bool ispion = fabs(particleID) == 211;
465 
466  // ---------------------
467  // --- calorimeter stuff
468  // ---------------------
469 
470  // --- get the energy values directly from the track
471  float emc_energy_track = track->get_cal_energy_3x3(SvtxTrack::CEMC);
472  float hci_energy_track = track->get_cal_energy_3x3(SvtxTrack::HCALIN);
473  float hco_energy_track = track->get_cal_energy_3x3(SvtxTrack::HCALOUT);
474 
475  float total_energy = 0;
476  if ( emc_energy_track > 0 ) total_energy += emc_energy_track;
477  if ( hci_energy_track > 0 ) total_energy += hci_energy_track;
478  if ( hco_energy_track > 0 ) total_energy += hco_energy_track;
479 
480  if ( verbosity > 2 ) cout << "total calo energy is " << total_energy << endl;
481 
482  if (trutheval->get_embed(g4particle) > 0)
483  {
484  // embedded results (quality or performance measures)
485  _truept_dptoverpt->Fill(truept,(recopt-truept)/truept);
486  _truept_dca->Fill(truept,track->get_dca2d());
487  _recopt_quality->Fill(recopt,track->get_quality());
488  if ( verbosity > 0 ) cout << "embedded particle ID is " << particleID << " ispion " << ispion << " iselectron " << iselectron << endl;
489  // ---
490  } // end if (embedded results)
491  else
492  {
493  // electron and pion (hadron) id
494 
495  // non-embedded results (purity measures)
496  _recopt_tracks_all->Fill(recopt);
497  _recopt_quality_tracks_all->Fill(recopt,track->get_quality());
498 
499  unsigned int nfromtruth = trackeval->get_nclusters_contribution(track,g4particle);
500 
501  unsigned int ndiff = abs((int)nfromtruth-(int)nlayers);
502  if ( ndiff <= 2 ) _recopt_tracks_recoWithin2Hits->Fill(recopt);
503  if ( ndiff <= 1 ) _recopt_tracks_recoWithin1Hit->Fill(recopt);
504  if ( ndiff == 0 ) _recopt_tracks_recoWithExactHits->Fill(recopt);
505 
506  float diff = fabs(recopt-truept)/truept;
507  if ( diff < 0.05 ) _recopt_tracks_recoWithin5Percent->Fill(recopt);
508  if ( diff < 0.04 )
509  {
510  _recopt_tracks_recoWithin4Percent->Fill(recopt);
512  }
513  if ( diff < 0.03 ) _recopt_tracks_recoWithin3Percent->Fill(recopt);
514 
515 
516  // --------------------------------------
517  // --- same but now with calorimeter cuts
518  // --------------------------------------
519 
520  double good_energy = total_energy - 3.14;
521 
522  double eoverp = good_energy/recop;
523  double sigmapt = 0.011 + 0.0008*recopt;
524  th2d_recopt_tracks_withcalocuts_all->Fill(recopt,eoverp);
525  if ( ndiff <= 2 ) th2d_recopt_tracks_withcalocuts_recoWithin2Hits->Fill(recopt,eoverp);
526  if ( ndiff <= 1 ) th2d_recopt_tracks_withcalocuts_recoWithin1Hit->Fill(recopt,eoverp);
527  if ( ndiff == 0 ) th2d_recopt_tracks_withcalocuts_recoWithExactHits->Fill(recopt,eoverp);
528  if ( diff < 0.05 ) th2d_recopt_tracks_withcalocuts_recoWithin5Percent->Fill(recopt,eoverp);
529  if ( diff < 0.04 ) th2d_recopt_tracks_withcalocuts_recoWithin4Percent->Fill(recopt,eoverp);
530  if ( diff < 0.03 ) th2d_recopt_tracks_withcalocuts_recoWithin3Percent->Fill(recopt,eoverp);
531  if ( diff < 1.0*sigmapt ) th2d_recopt_tracks_withcalocuts_recoWithin1Sigma->Fill(recopt,eoverp);
532  if ( diff < 2.0*sigmapt ) th2d_recopt_tracks_withcalocuts_recoWithin2Sigma->Fill(recopt,eoverp);
533  if ( diff < 3.0*sigmapt ) th2d_recopt_tracks_withcalocuts_recoWithin3Sigma->Fill(recopt,eoverp);
534 
535  // --- done with reco tracks
536 
537  } // else (non-embedded results)
538 
539  ++ntracks;
540  } // loop over reco tracks
541 
542 
543  hmult->Fill(ntracks);
544 
545  // --- Get the leading vertex
546  SvtxVertex* maxvertex = NULL;
547  unsigned int maxtracks = 0;
548  for ( SvtxVertexMap::Iter iter = vertexmap->begin(); iter != vertexmap->end(); ++iter )
549  {
550  SvtxVertex* vertex = iter->second;
551  if ( vertex->size_tracks() > maxtracks )
552  {
553  maxvertex = vertex;
554  maxtracks = vertex->size_tracks();
555  }
556  }
557  if ( !maxvertex )
558  {
559  cerr << PHWHERE << " ERROR: cannot get reconstructed vertex (event number " << nevents << ")" << endl;
560  ++nerrors;
562  }
563 
564  // --- Get the coordinates for the vertex from the evaluator
565  PHG4VtxPoint* point = vertexeval->max_truth_point_by_ntracks(maxvertex);
566  if ( !point )
567  {
568  cerr << PHWHERE << " ERROR: cannot get truth vertex (event number " << nevents << ")" << endl;
569  ++nerrors;
571  }
572  _dx_vertex->Fill(maxvertex->get_x() - point->get_x());
573  _dy_vertex->Fill(maxvertex->get_y() - point->get_y());
574  _dz_vertex->Fill(maxvertex->get_z() - point->get_z());
575 
576  hmult_vertex->Fill(ntracks);
577 
578 
579 
581 
582 }
583 
584 
585 
587 {
588  cout << "End called, " << nevents << " events processed with " << nerrors << " errors and " << nwarnings << " warnings." << endl;
589  return 0;
590 }
591