Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PhotonJet.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PhotonJet.C
1 //general fun4all and subsysreco includes
3 #include <g4main/PHG4Hit.h>
4 #include <g4main/PHG4Particle.h>
7 #include <phool/getClass.h>
8 
9 //calorimeter includes
10 #include <calobase/RawCluster.h>
11 #include <calobase/RawClusterContainer.h>
12 #include <calobase/RawClusterUtility.h>
13 #include <calobase/RawTower.h>
14 #include <calobase/RawTowerContainer.h>
15 #include <calobase/RawTowerGeom.h>
16 #include <calobase/RawTowerGeomContainer.h>
17 #include <calotrigger/CaloTriggerInfo.h>
18 
19 #include <g4jets/Jet.h>
20 #include <g4jets/JetMap.h>
21 #include <g4vertex/GlobalVertex.h>
22 #include <g4vertex/GlobalVertexMap.h>
25 #include <trackbase_historic/SvtxVertex.h>
26 #include <trackbase_historic/SvtxVertexMap.h>
27 
28 //evaluation includes
30 #include <g4eval/JetEvalStack.h>
31 #include <g4eval/SvtxEvalStack.h>
32 
33 //hepmc includes
34 #include <HepMC/GenEvent.h>
35 #include <HepMC/GenVertex.h>
38 
39 //general c++ includes
40 #include <TLorentzVector.h>
41 #include <cassert>
42 #include <iostream>
43 #include <sstream>
44 
45 #include "PhotonJet.h"
46 
47 using namespace std;
48 
50  : SubsysReco("PHOTONJET")
51 {
52  //just set all global values to -999 from the start so that they have a spot in memory
54 
55  outfilename = name;
56 
57  //initialize public member values
58 
59  //default don't use isocone algorithm
60  use_isocone = 0;
61 
62  //default do not use tracked jets (or tracks)
64 
65  //default use 0.3 jet cone
66  jet_cone_size = 3;
67 
68  //default set beginning number of events to 0
69  //this can be changed with one of the public functions if e.g. you want individual event number IDs for multiple MC blocks of events
70  nevents = 0;
71 
72  //default to barrel sPHENIX acceptance
73  etalow = -1;
74  etahigh = 1;
75 
76  //default jetminptcut
77  minjetpt = 5.;
78 
79  //default mincluscut
80  mincluspt = 0.5;
81 
82  //default minimum direct photon p_T
83  mindp_pt = 10;
84 
85  //default to use the trigger emulator
86  usetrigger = 1;
87 
88  //default to using position corrected emcal clusters
89  use_pos_cor_cemc = 1;
90 
91  //default to not AA and not using embedded background subtraction
92  is_AA = 0;
93 }
94 
96 {
97  if (Verbosity() > 1)
98  {
99  cout << "COLLECTING PHOTON-JET PAIRS FOR THE FOLLOWING: " << endl;
100  cout << "GATHERING JETS: " << jet_cone_size << endl;
101  cout << "GATHERING IN ETA: [" << etalow
102  << "," << etahigh << "]" << endl;
103  cout << "EVALUATING TRACKED JETS: " << eval_tracked_jets << endl;
104  cout << "USING ISOLATION CONE: " << use_isocone << endl;
105  }
106 
107  //create output photonjet tfile which contains output TTrees
108  file = new TFile(outfilename.c_str(), "RECREATE");
109 
110  //create some basic histograms
111  ntruthconstituents_h = new TH1F("ntruthconstituents", "", 200, 0, 200);
112  percent_photon_h = new TH1F("percent_photon_h",
113  ";E_{photon}/E_{jet}; Counts", 200, 0, 2);
114  histo = new TH1F("histo", "histo", 100, -3, 3);
115 
116  //create basic tree
117  tree = new TTree("tree", "a tree");
118  tree->Branch("nevents", &nevents, "nevents/I");
119 
120  //main trees are set in this fxn - branch addresses are defined to global data types
122 
123  return 0;
124 }
125 
127 {
128  // event number tracker,
129  if (nevents % 10 == 0)
130  cout << "at event number " << nevents << endl;
131 
132  //get the requested size jets
133  ostringstream truthjetsize;
134  ostringstream recojetsize;
135  ostringstream trackjetsize;
136 
137  //these are the node names for Truth, Calorimeter tower, and tracked jets
138  truthjetsize.str("");
139  truthjetsize << "AntiKt_Truth_r";
140  recojetsize.str("");
141  recojetsize << "AntiKt_Tower_r";
142  trackjetsize.str("");
143  trackjetsize << "AntiKt_Track_r";
144 
145  if (jet_cone_size == 2)
146  {
147  truthjetsize << "02";
148  recojetsize << "02";
149  trackjetsize << "02";
150  }
151  else if (jet_cone_size == 3)
152  {
153  truthjetsize << "03";
154  recojetsize << "03";
155  trackjetsize << "03";
156  }
157  else if (jet_cone_size == 4)
158  {
159  truthjetsize << "04";
160  recojetsize << "04";
161  trackjetsize << "04";
162  }
163  else if (jet_cone_size == 5)
164  {
165  truthjetsize << "05";
166  recojetsize << "05";
167  trackjetsize << "05";
168  }
169  else if (jet_cone_size == 6)
170  {
171  truthjetsize << "06";
172  recojetsize << "06";
173  trackjetsize << "06";
174  }
175 
176  else if (jet_cone_size == 7)
177  {
178  truthjetsize << "07";
179  recojetsize << "07";
180  trackjetsize << "07";
181  }
182  //if its some other number just set it to 0.4
183 
184  else
185  {
186  truthjetsize << "04";
187  recojetsize << "04";
188  }
189 
190  if (Verbosity() > 1)
191  {
192  cout << "Gathering RECO Jets: " << recojetsize.str().c_str() << endl;
193  cout << "Gathering TRUTH Jets: " << truthjetsize.str().c_str() << endl;
194  }
195 
196  //get the nodes from the NodeTree
197 
198  //JetMap nodes
199  JetMap *truth_jets =
200  findNode::getClass<JetMap>(topnode, truthjetsize.str().c_str());
201 
202  JetMap *reco_jets = 0;
203  if (!is_AA)
204  {
205  reco_jets = findNode::getClass<JetMap>(topnode, recojetsize.str().c_str());
206  }
207 
208  JetMap *tracked_jets =
209  findNode::getClass<JetMap>(topnode, trackjetsize.str().c_str());
210 
211  //G4 truth particle node
212  PHG4TruthInfoContainer *truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topnode, "G4TruthInfo");
213 
214  //EMCal raw tower cluster node
216  if (!use_pos_cor_cemc)
217  clusters = findNode::getClass<RawClusterContainer>(topnode, "CLUSTER_CEMC");
218 
219  //EMCal position calibrated cluster node
220  if (use_pos_cor_cemc)
221  clusters = findNode::getClass<RawClusterContainer>(topnode, "CLUSTER_POS_COR_CEMC");
222 
223  //SVTX tracks node
224  SvtxTrackMap *trackmap = findNode::getClass<SvtxTrackMap>(topnode, "SvtxTrackMap");
225 
226  //trigger emulator
227  CaloTriggerInfo *trigger = findNode::getClass<CaloTriggerInfo>(topnode, "CaloTriggerInfo");
228 
229  PHG4TruthInfoContainer::Range range = truthinfo->GetPrimaryParticleRange();
230 
231  //for truth track matching
232  SvtxEvalStack *svtxevalstack = new SvtxEvalStack(topnode);
233  svtxevalstack->next_event(topnode);
234 
235  if (is_AA)
236  {
237  recojetsize << "_Sub1";
238  reco_jets =
239  findNode::getClass<JetMap>(topnode, recojetsize.str().c_str());
240  }
241 
242  //for truth jet matching
243  JetEvalStack *_jetevalstack = 0;
244  if (!is_AA)
245  _jetevalstack =
246  new JetEvalStack(topnode, recojetsize.str().c_str(),
247  truthjetsize.str().c_str());
248  //the jet eval stack doesn't work for AA - so this is useless
249  //in that case the code is setup to match reco and truth jets based on
250  //their difference in deltaphi and deltaeta
251  else
252  _jetevalstack = new JetEvalStack(topnode,
253  "AntiKt_Tower_r04_Sub1",
254  "AntiKt_Truth_r04");
255 
256  GlobalVertexMap *vertexmap = findNode::getClass<GlobalVertexMap>(topnode, "GlobalVertexMap");
257  if (!vertexmap)
258  {
259  cout << "PhotonJet::process_event - Fatal Error - GlobalVertexMap node is missing. Please turn on the do_global flag in the main macro in order to reconstruct the global vertex." << endl;
260  assert(vertexmap); // force quit
261 
262  return 0;
263  }
264 
265  if (vertexmap->empty())
266  {
267  cout << "PhotonJet::process_event - Fatal Error - GlobalVertexMap node is empty. Please turn on the do_global flag in the main macro in order to reconstruct the global vertex." << endl;
268  return 0;
269  }
270 
271  GlobalVertex *vtx = vertexmap->begin()->second;
272  if (vtx == nullptr) return 0;
273 
274 
275  RawTowerContainer *_cemctowers = findNode::getClass<RawTowerContainer>(topnode,"TOWER_CALIB_CEMC");
276  RawTowerContainer *_hcalintowers = findNode::getClass<RawTowerContainer>(topnode,"TOWER_CALIB_HCALIN");
277  RawTowerContainer *_hcalouttowers = findNode::getClass<RawTowerContainer>(topnode,"TOWER_CALIB_HCALOUT");
278  RawTowerGeomContainer *_cemctowergeom = findNode::getClass<RawTowerGeomContainer>(topnode,"TOWERGEOM_CEMC");
279  RawTowerGeomContainer *_hcalintowergeom = findNode::getClass<RawTowerGeomContainer>(topnode,"TOWERGEOM_HCALIN");
280  RawTowerGeomContainer *_hcalouttowergeom = findNode::getClass<RawTowerGeomContainer>(topnode,"TOWERGEOM_HCALOUT");
281 
282 
283 
284 
285 
286 
287 
288 
289 
290  //Make sure all nodes for analysis are here. If one isn't in the NodeTree, bail
291  if (!trigger && usetrigger)
292  {
293  cout << "NO TRIGGER EMULATOR, BAILING" << endl;
294  return 0;
295  }
296  if (!tracked_jets && eval_tracked_jets)
297  {
298  cout << "no tracked jets, bailing" << endl;
299  return 0;
300  }
301  if (!truth_jets)
302  {
303  cout << "no truth jets" << endl;
304  return 0;
305  }
306  if (!reco_jets)
307  {
308  cout << "no reco jets" << endl;
309  return 0;
310  }
311  if (!truthinfo)
312  {
313  cout << "no truth track info" << endl;
314  return 0;
315  }
316  if (!clusters)
317  {
318  cout << "no cluster info" << endl;
319  return 0;
320  }
321  if (!trackmap && eval_tracked_jets)
322  {
323  cout << "no track map" << endl;
324  return 0;
325  }
326  if (!_jetevalstack)
327  {
328  cout << "no good truth jets" << endl;
329  return 0;
330  }
331 
332  //For jet and track truth/reco matching
333  JetRecoEval *recoeval = _jetevalstack->get_reco_eval();
334  SvtxTrackEval *trackeval = svtxevalstack->get_track_eval();
335  JetTruthEval *trutheval = _jetevalstack->get_truth_eval();
336 
337 
338 
339  //now we have all the nodes, so collect the data from the various nodes
340 
341  /***********************************************
342 
343  GET ALL THE HEPMC EVENT LEVEL TRUTH PARTICLES
344 
345  ************************************************/
346 
347  PHHepMCGenEventMap *hepmceventmap = findNode::getClass<PHHepMCGenEventMap>(topnode, "PHHepMCGenEventMap");
348 
349  if (!hepmceventmap)
350  {
351  cout << "hepmc event map node is missing, BAILING" << endl;
352  //return 0;
353  }
354 
355  if (Verbosity() > 1)
356  {
357  cout << "Getting HEPMC truth particles " << endl;
358  }
359 
360  //you can iterate over the number of events in a hepmc event
361  //for pile up events where you have multiple hard scatterings per bunch crossing
362  for (PHHepMCGenEventMap::ConstIter iterr = hepmceventmap->begin();
363  iterr != hepmceventmap->end();
364  ++iterr)
365  {
366  PHHepMCGenEvent *hepmcevent = iterr->second;
367 
368  if (hepmcevent)
369  {
370  //get the event characteristics, inherited from HepMC classes
371  HepMC::GenEvent *truthevent = hepmcevent->getEvent();
372  if (!truthevent)
373  {
374  cout << PHWHERE << "no evt pointer under phhepmvgeneventmap found " << endl;
375  return 0;
376  }
377 
378  //get the interacting protons
379  if (truthevent->valid_beam_particles())
380  {
381  HepMC::GenParticle *part1 = truthevent->beam_particles().first;
382 
383  //beam energy
384  beam_energy = fabs(part1->momentum().pz());
385  }
386 
387  //Parton info
388  HepMC::PdfInfo *pdfinfo = truthevent->pdf_info();
389 
390  partid1 = pdfinfo->id1();
391  partid2 = pdfinfo->id2();
392  x1 = pdfinfo->x1();
393  x2 = pdfinfo->x2();
394 
395  //are there multiple partonic intercations in a p+p event
396  mpi = truthevent->mpi();
397 
399 
400  //Get the PYTHIA signal process id identifying the 2-to-2 hard process
401  process_id = truthevent->signal_process_id();
402 
403  //loop over all the truth particles and get their information
404  for (HepMC::GenEvent::particle_const_iterator iter = truthevent->particles_begin();
405  iter != truthevent->particles_end();
406  ++iter)
407  {
408  //get each pythia particle characteristics
409  truthenergy = (*iter)->momentum().e();
410  truthpid = (*iter)->pdg_id();
411 
412  trutheta = (*iter)->momentum().pseudoRapidity();
413  truthphi = (*iter)->momentum().phi();
414  truthpx = (*iter)->momentum().px();
415  truthpy = (*iter)->momentum().py();
416  truthpz = (*iter)->momentum().pz();
417  truthpt = sqrt(truthpx * truthpx + truthpy * truthpy);
418 
419  //fill the truth tree
420  truthtree->Fill();
422  }
423  }
424  }
425 
426  //these are global variables, i.e. the highest pt cluster in an event
427  cluseventenergy = 0;
428  cluseventphi = 0;
429  cluseventpt = 0;
430  cluseventeta = 0;
431  float lastenergy = 0;
432 
433  if (Verbosity() > 1)
434  {
435  cout << "get G4 stable truth particles" << endl;
436  }
437 
438  //loop over the G4 truth (stable) particles
439  for (PHG4TruthInfoContainer::ConstIterator iter = range.first;
440  iter != range.second;
441  ++iter)
442  {
443  //get this particle
444  PHG4Particle *truth = iter->second;
445 
446  //get this particles momentum, etc.
447  truthpx = truth->get_px();
448  truthpy = truth->get_py();
449  truthpz = truth->get_pz();
450  truthp = sqrt(truthpx * truthpx + truthpy * truthpy + truthpz * truthpz);
451  truthenergy = truth->get_e();
452 
453  TLorentzVector vec;
454  vec.SetPxPyPzE(truthpx, truthpy, truthpz, truthenergy);
455 
456  truthpt = sqrt(truthpx * truthpx + truthpy * truthpy);
457 
458  truthphi = vec.Phi();
459 
460  trutheta = TMath::ATanH(truthpz / truthenergy);
461  //check for nans
462  if (trutheta != trutheta)
463  trutheta = -9999;
464  truthpid = truth->get_pid();
465 
466  //find the highest energy photon in the event in the eta range
467  if (truthpid == 22 && truthenergy > lastenergy
468  && trutheta > etalow && trutheta < etahigh)
469  {
470  lastenergy = truthenergy;
475  }
476  //fill the g4 truth tree
477  truth_g4particles->Fill();
478  }
479 
480  /***************************************
481 
482  TRUTH JETS
483 
484  ***************************************/
485  if (Verbosity() > 1)
486  {
487  cout << "get the truth jets" << endl;
488  }
489 
490  //loop over the truth jets
491  float hardest_jet = 0;
492  // If not truth jet is found that satisfies the requirements,
493  // then the jet 4 vector will be (0,0,0,0)
494  hardest_jetpt = 0;
495  hardest_jetenergy = 0;
496  hardest_jeteta = 0;
497  hardest_jetphi = 0;
498  for (JetMap::Iter iter = truth_jets->begin();
499  iter != truth_jets->end();
500  ++iter)
501  {
502  Jet *jet = iter->second;
503 
504  truthjetpt = jet->get_pt();
505 
506  //only collect truthjets above the minjetpt cut
507  if (truthjetpt < minjetpt)
508  continue;
509 
510  truthjeteta = jet->get_eta();
511 
512  //make the width extra just to be safe and collect truth jets
513  //that might be e.g. half in the sphenix acceptance
514  if (truthjeteta < (etalow - 1) || truthjeteta > (etahigh + 1))
515  continue;
516 
517  truthjetpx = jet->get_px();
518  truthjetpy = jet->get_py();
519  truthjetpz = jet->get_pz();
520  truthjetphi = jet->get_phi();
521  truthjetmass = jet->get_mass();
522  truthjetp = jet->get_p();
523  truthjetenergy = jet->get_e();
524 
525  //check that the jet isn't just a high pt photon
526 
527  //get the truth constituents of the jet
528  std::set<PHG4Particle *> truthjetcomp =
529  trutheval->all_truth_particles(jet);
530  ntruthconstituents = 0;
531  float truthjetenergysum = 0;
532  float truthjethighestphoton = 0;
533  //loop over the constituents of the truth jet
534  for (std::set<PHG4Particle *>::iterator iter2 = truthjetcomp.begin();
535  iter2 != truthjetcomp.end();
536  ++iter2)
537  {
538  //get the particle of the truthjet
539  PHG4Particle *truthpart = *iter2;
540  if (!truthpart)
541  {
542  cout << "no truth particles in the jet??" << endl;
543  break;
544  }
545 
547 
548  int constpid = truthpart->get_pid();
549  float conste = truthpart->get_e();
550 
551  truthjetenergysum += conste;
552 
553  if (constpid == 22)
554  {
555  if (conste > truthjethighestphoton)
556  truthjethighestphoton = conste;
557  }
558  }
560 
561  //we want jets that are real jets, not just an e.g. isolated photon
562  //require that the number of constituents in the jet be larger than 3
563  float percent_photon = truthjethighestphoton / truthjetenergy;
564  percent_photon_h->Fill(percent_photon);
565 
566  //if there is a high energy photon that is 80% of the jets energy, skip it
567  //it is likely the near-side direct photon
568  if (percent_photon > 0.8)
569  {
570  continue;
571  }
572 
573  //we also want jets to have at least 3 constituents
574  if (ntruthconstituents < 3)
575  continue;
576 
577  //identify the highest pt jet in the event
578  if (truthjetpt > hardest_jet)
579  {
580  hardest_jet = truthjetpt;
585  }
586 
587  //fill the truthjet tree
588  truthjettree->Fill();
589  }
590 
591  //fill the event tree with e.g. x1,x2 partonic momentum fractions,
592  //process id, highest energy photon, etc.
593  event_tree->Fill();
594 
595  if (Verbosity() > 1)
596  {
597  cout << "get trigger emulator info" << endl;
598  }
599  /***********************************************
600 
601  TRIGGER EMULATOR INFO
602 
603  ************************************************/
604  if (usetrigger)
605  {
606  //get the 4x4 trigger tile info
607  E_4x4 = trigger->get_best_EMCal_4x4_E();
608  phi_4x4 = trigger->get_best_EMCal_4x4_phi();
609  eta_4x4 = trigger->get_best_EMCal_4x4_eta();
610 
611  //get the 2x2 trigger tile info
612  E_2x2 = trigger->get_best_EMCal_2x2_E();
613  phi_2x2 = trigger->get_best_EMCal_2x2_phi();
614  eta_2x2 = trigger->get_best_EMCal_2x2_eta();
615  }
616 
617  /***********************************************
618 
619  GET THE EMCAL CLUSTERS
620 
621  ************************************************/
622  if (Verbosity() > 1)
623  {
624  cout << "Get EMCal Cluster" << endl;
625  }
626 
627  RawClusterContainer::ConstRange begin_end = clusters->getClusters();
629 
630  //loop over the emcal clusters
631  for (clusiter = begin_end.first;
632  clusiter != begin_end.second;
633  ++clusiter)
634  {
635  //get this cluster
636  RawCluster *cluster = clusiter->second;
637 
638  //get cluster characteristics
639  //this helper class determines the photon characteristics
640  //depending on the vertex position
641  //this is important for e.g. eta determination and E_T determination
642  CLHEP::Hep3Vector vertex(vtx->get_x(), vtx->get_y(), vtx->get_z());
643  CLHEP::Hep3Vector E_vec_cluster = RawClusterUtility::GetECoreVec(*cluster, vertex);
644  clus_energy = E_vec_cluster.mag();
645  clus_eta = E_vec_cluster.pseudoRapidity();
646  clus_theta = E_vec_cluster.getTheta();
647  clus_pt = E_vec_cluster.perp();
648  clus_phi = E_vec_cluster.getPhi();
649 
650  if (clus_pt < mincluspt)
651  continue;
652 
653  if (clus_eta < etalow)
654  continue;
655  if (clus_eta > etahigh)
656  continue;
657 
658  TLorentzVector *clus = new TLorentzVector();
659  clus->SetPtEtaPhiE(clus_pt, clus_eta, clus_phi, clus_energy);
660 
661  float dumarray[4];
662  clus->GetXYZT(dumarray);
663  clus_x = dumarray[0];
664  clus_y = dumarray[1];
665  clus_z = dumarray[2];
666  clus_t = dumarray[3];
667 
668  clus_px = clus_pt * TMath::Cos(clus_phi);
669  clus_py = clus_pt * TMath::Sin(clus_phi);
671 
672  //fill the cluster tree with all emcal clusters
673  cluster_tree->Fill();
674 
675  //now determine the direct photon
676  //only interested in high pt photons to be isolated i.e. direct photons
677  if (clus_pt < mindp_pt)
678  continue;
679  //require that the entire isolation cone fall within sPHENIX acceptance
680  if (fabs(clus_eta) > (1.0 - isoconeradius) && use_isocone)
681  continue;
682 
683  if (use_isocone)
684  {
685  //get the energy sum in the cone surrounding the photon
686  float energysum = ConeSum(cluster, clusters, trackmap, isoconeradius, vtx);
687 
688  //check if energy sum is less than 10% of isolated photon energy
689  bool conecut = energysum > 0.1 * clus_energy;
690  if (conecut)
691  continue;
692  }
693 
694  //find the associated truth high pT photon with this reconstructed photon
695  for (PHG4TruthInfoContainer::ConstIterator iter = range.first;
696  iter != range.second;
697  ++iter)
698  {
699  //get this truth particle
700  PHG4Particle *truth = iter->second;
701 
702  clustruthpid = truth->get_pid();
703 
704  //check that it is a photon, i.e. pid==22
705  if (clustruthpid == 22)
706  {
707  clustruthpx = truth->get_px();
708  clustruthpy = truth->get_py();
709  clustruthpz = truth->get_pz();
710  clustruthenergy = truth->get_e();
712  if (clustruthpt < mindp_pt)
713  continue;
714 
715  TLorentzVector vec;
716  vec.SetPxPyPzE(clustruthpx, clustruthpy, clustruthpz, clustruthenergy);
717  clustruthphi = vec.Phi();
718 
719  clustrutheta = TMath::ATanH(clustruthpz / clustruthenergy);
720  //check for nans
721  if (clustrutheta != clustrutheta)
722  clustrutheta = -9999;
723 
724  //check that the truth photon has similar eta/phi to reco photon
725  //the clustering has a resolution of about 0.005 rads so this is sufficient
726  if (fabs(clustruthphi - clus_phi) > 0.02 || fabs(clustrutheta - clus_eta) > 0.02)
727  continue;
728 
729  //once the photon is found and the values are set
730  //just break out of the loop
731  break;
732  }
733  }
734  //fill isolated clusters tree, i.e. all isolated clusters regardless
735  //of if an away-side jet is found also
736  isolated_clusters->Fill();
737 
738  //get back to back reconstructed hadrons/jets for photon-jet processes
739  //two different functions for Au+Au vs p+p due to the way truth jet matching
740  //is performed between the two systems
741  if (!is_AA)
742  GetRecoHadronsAndJets(cluster, trackmap,
743  reco_jets, tracked_jets,
744  recoeval, trackeval,
745  truthinfo,
746  trutheval,
747  truth_jets,
748  vtx);
749 
750  if (is_AA)
751  GetRecoHadronsAndJetsAA(cluster,
752  trackmap,
753  reco_jets,
754  truthinfo,
755  truth_jets,
756  vtx);
757  }
758 
759  /***********************************************
760 
761  GET THE SVTX TRACKS
762 
763  ************************************************/
764  if (eval_tracked_jets)
765  {
766  if (Verbosity() > 1)
767  {
768  cout << "Get the Tracks" << endl;
769  }
770  for (SvtxTrackMap::Iter iter = trackmap->begin();
771  iter != trackmap->end();
772  ++iter)
773  {
774  SvtxTrack *track = iter->second;
775 
776  //get reco info
777  tr_px = track->get_px();
778  tr_py = track->get_py();
779  tr_pz = track->get_pz();
780  tr_p = sqrt(tr_px * tr_px + tr_py * tr_py + tr_pz * tr_pz);
781 
782  tr_pt = sqrt(tr_px * tr_px + tr_py * tr_py);
783 
784  if (tr_pt < 0.5)
785  continue;
786 
787  tr_phi = track->get_phi();
788  tr_eta = track->get_eta();
789 
790  if (tr_eta < etalow || tr_eta > etahigh)
791  continue;
792 
793  charge = track->get_charge();
794  chisq = track->get_chisq();
795  ndf = track->get_ndf();
796  dca = track->get_dca();
797  tr_x = track->get_x();
798  tr_y = track->get_y();
799  tr_z = track->get_z();
800 
801  //get truth track info
802  PHG4Particle *truthtrack = trackeval->max_truth_particle_by_nclusters(track);
803  truth_is_primary = truthinfo->is_primary(truthtrack);
804 
805  truthtrackpx = truthtrack->get_px();
806  truthtrackpy = truthtrack->get_py();
807  truthtrackpz = truthtrack->get_pz();
809 
810  truthtracke = truthtrack->get_e();
811 
812  TLorentzVector *Truthtrack = new TLorentzVector();
813  Truthtrack->SetPxPyPzE(truthtrackpx, truthtrackpy, truthtrackpz, truthtracke);
814 
815  truthtrackpt = Truthtrack->Pt();
816  truthtrackphi = Truthtrack->Phi();
817  truthtracketa = Truthtrack->Eta();
818  truthtrackpid = truthtrack->get_pid();
819 
820  tracktree->Fill();
821  }
822  }
823 
824  /***************************************
825 
826  RECONSTRUCTED JETS
827 
828  ***************************************/
829  if (Verbosity() > 1)
830  {
831  cout << "Get all Reco Jets" << endl;
832  }
833 
834  for (JetMap::Iter iter = reco_jets->begin();
835  iter != reco_jets->end();
836  ++iter)
837  {
838  Jet *jet = iter->second;
839  Jet *truthjet = recoeval->max_truth_jet_by_energy(jet);
840  recojetpt = jet->get_pt();
841  if (recojetpt < minjetpt)
842  continue;
843 
844  recojeteta = jet->get_eta();
845 
846  //reco jet eta better not be outside of the sPHENIX acceptance....
847  if (recojeteta < (etalow - 1) || recojeteta > (etahigh + 1))
848  continue;
849 
850  //get reco jet characteristics
851  recojetid = jet->get_id();
852  recojetpx = jet->get_px();
853  recojetpy = jet->get_py();
854  recojetpz = jet->get_pz();
855  recojetphi = jet->get_phi();
856  recojetmass = jet->get_mass();
857  recojetp = jet->get_p();
858  recojetenergy = jet->get_e();
859 
860  //if truthjet exists, then it is p+p and we can use the stackeval
861  //for truthjet matching
862  if (truthjet)
863  {
864  truthjetid = truthjet->get_id();
865  truthjetp = truthjet->get_p();
866  truthjetphi = truthjet->get_phi();
867  truthjeteta = truthjet->get_eta();
868  truthjetpt = truthjet->get_pt();
869  truthjetenergy = truthjet->get_e();
870  truthjetpx = truthjet->get_px();
871  truthjetpy = truthjet->get_py();
872  truthjetpz = truthjet->get_pz();
873  truthjetmass = truthjet->get_mass();
874 
875  //check that the jet isn't just a photon or something like this
876  //needs at least 2 constituents and that 80% of jet isn't from one photon
877  std::set<PHG4Particle *> truthjetcomp =
878  trutheval->all_truth_particles(truthjet);
879  ntruthconstituents = 0;
880  float truthjetenergysum = 0;
881  float truthjethighestphoton = 0;
882  for (std::set<PHG4Particle *>::iterator iter2 = truthjetcomp.begin();
883  iter2 != truthjetcomp.end();
884  ++iter2)
885  {
886  PHG4Particle *truthpart = *iter2;
887  if (!truthpart)
888  {
889  cout << "no truth particles in the jet??" << endl;
890  break;
891  }
893 
894  int constpid = truthpart->get_pid();
895  float conste = truthpart->get_e();
896 
897  truthjetenergysum += conste;
898 
899  if (constpid == 22)
900  {
901  if (conste > truthjethighestphoton)
902  truthjethighestphoton = conste;
903  }
904  }
905 
906  //if the highest energy photon in the jet is 80% of the jets energy
907  //its probably an isolated photon and so we want to not include it in the tree
908  float percent_photon = truthjethighestphoton / truthjetenergy;
909  if (percent_photon > 0.8)
910  {
911  continue;
912  }
913  if (!is_AA && ntruthconstituents < 3)
914  continue;
915  }
916 
917  //if truthjet was null then we just match the reco-truth jets by
918  //their distance in dphi deta space
919  else
920  {
921  if (Verbosity() > 1)
922  {
923  cout << "matching by distance jet" << endl;
924  }
925 
926  truthjetid = 0;
927  truthjetp = 0;
928  truthjetphi = 0;
929  truthjeteta = 0;
930  truthjetpt = 0;
931  truthjetenergy = 0;
932  truthjetpx = 0;
933  truthjetpy = 0;
934  truthjetpz = 0;
935 
936  //if the jetevalstack can't find a good truth jet
937  //try to match reco jet with closest truth jet
938  float closestjet = 9999;
939  for (JetMap::Iter iter3 = truth_jets->begin();
940  iter3 != truth_jets->end();
941  ++iter3)
942  {
943  Jet *jet = iter3->second;
944 
945  float thisjetpt = jet->get_pt();
946  if (thisjetpt < minjetpt)
947  continue;
948 
949  float thisjeteta = jet->get_eta();
950  float thisjetphi = jet->get_phi();
951 
952  float dphi = recojetphi - thisjetphi;
953  if (dphi > 3. * pi / 2.)
954  dphi -= pi * 2.;
955  if (dphi < -1. * pi / 2.)
956  dphi += pi * 2.;
957 
958  float deta = recojeteta - thisjeteta;
959 
960  dR = sqrt(pow(dphi, 2.) + pow(deta, 2.));
961 
962  if (dR < reco_jets->get_par() && dR < closestjet)
963  {
964  truthjetid = -9999; //indicates matched with distance, not jetevalstack
965  truthjetp = jet->get_p();
966  truthjetphi = jet->get_phi();
967  truthjeteta = jet->get_eta();
968  truthjetpt = jet->get_pt();
969  truthjetenergy = jet->get_e();
970  truthjetpx = jet->get_px();
971  truthjetpy = jet->get_py();
972  truthjetpz = jet->get_pz();
973  truthjetmass = jet->get_mass();
974  }
975 
976  if (dR < closestjet)
977  {
978  closestjet = dR;
979  }
980  }
981  }
982 
983  //get the reco jet constituents and calculate the dphi deta
984  //from the jet axis. Added to understand the truth jet - reco jet
985  //azimuthal offset
986 
987 
988 
989  for(Jet::ConstIter constiter = jet->begin_comp();
990  constiter != jet->end_comp();
991  ++constiter)
992  {
993  Jet::SRC source = constiter->first;
994  unsigned int index = constiter->second;
995 
996  RawTower *thetower = 0;
997  if(source == Jet::CEMC_TOWER)
998  {
999  thetower = _cemctowers->getTower(index);
1000  }
1001  else if(source == Jet::HCALIN_TOWER)
1002  {
1003  thetower = _hcalintowers->getTower(index);
1004  }
1005  else if(source == Jet::HCALOUT_TOWER)
1006  {
1007  thetower = _hcalouttowers->getTower(index);
1008  }
1009 
1010  assert(thetower);
1011 
1012  int tower_phi_bin = thetower->get_binphi();
1013  int tower_eta_bin = thetower->get_bineta();
1014 
1015  double constphi = -9999;
1016  double consteta = -9999;
1017  if(source == Jet::CEMC_TOWER)
1018  {
1019  constphi = _cemctowergeom->get_phicenter(tower_phi_bin);
1020  consteta = _cemctowergeom->get_etacenter(tower_eta_bin);
1021  }
1022  else if(source == Jet::HCALIN_TOWER)
1023  {
1024  constphi = _hcalintowergeom->get_phicenter(tower_phi_bin);
1025  consteta = _hcalintowergeom->get_etacenter(tower_eta_bin);
1026  }
1027  else if(source == Jet::HCALOUT_TOWER)
1028  {
1029  constphi = _hcalouttowergeom->get_phicenter(tower_phi_bin);
1030  consteta = _hcalouttowergeom->get_etacenter(tower_eta_bin);
1031  }
1032  float checkdphi = truthjetphi - constphi;
1033  if(checkdphi < -1 * TMath::Pi() / 2.)
1034  checkdphi += 2. * TMath::Pi();
1035  if(checkdphi > 3. * TMath::Pi() / 2.)
1036  checkdphi -= 2. * TMath::Pi();
1037 
1038  constituent_dphis.push_back(checkdphi);
1039  constituent_detas.push_back(truthjeteta - consteta);
1040 
1041  }
1042 
1043  recojettree->Fill();
1044 
1045  constituent_dphis.resize(0);
1046  constituent_detas.resize(0);
1047 
1048  }
1049 
1050  if (Verbosity() > 1)
1051  {
1052  cout << "finished event" << endl;
1053  }
1054 
1055  nevents++;
1056  tree->Fill();
1057  return 0;
1058 }
1059 
1061 {
1062  std::cout << " DONE PROCESSING PHOTONJET PACKAGE" << endl;
1063 
1064  file->Write();
1065  file->Close();
1066  return 0;
1067 }
1070  JetMap *recojets,
1071  PHG4TruthInfoContainer *alltruth,
1072  JetMap *truthjets,
1073  GlobalVertex *vtx)
1074 {
1075  CLHEP::Hep3Vector vertex(vtx->get_x(), vtx->get_y(), vtx->get_z());
1076  CLHEP::Hep3Vector E_vec_cluster = RawClusterUtility::GetECoreVec(*trig, vertex);
1077 
1078  float trig_phi = E_vec_cluster.getPhi();
1079  float trig_eta = E_vec_cluster.pseudoRapidity();
1080 
1082 
1083  //find the matching truth photon to the reco photon
1084  //for the values in the photon-jet tree
1085  for (PHG4TruthInfoContainer::ConstIterator iter = range.first;
1086  iter != range.second;
1087  ++iter)
1088  {
1089  PHG4Particle *truth = iter->second;
1090 
1091  clustruthpid = truth->get_pid();
1092  if (clustruthpid == 22)
1093  {
1094  clustruthpx = truth->get_px();
1095  clustruthpy = truth->get_py();
1096  clustruthpz = truth->get_pz();
1097  clustruthenergy = truth->get_e();
1099  if (clustruthpt < mincluspt)
1100  continue;
1101 
1102  TLorentzVector vec;
1103  vec.SetPxPyPzE(clustruthpx, clustruthpy, clustruthpz, clustruthenergy);
1104  clustruthphi = vec.Phi();
1105 
1106  clustrutheta = TMath::ATanH(clustruthpz / clustruthenergy);
1107  //check for nans
1108  if (clustrutheta != clustrutheta)
1109  clustrutheta = -9999;
1110 
1111  if (fabs(clustruthphi - trig_phi) > 0.02 || fabs(clustrutheta - trig_eta) > 0.02)
1112  continue;
1113 
1114  //once the values are set, we've found the truth photon so just break out of this loop
1115  break;
1116  }
1117  }
1118 
1119  //find the away-side jets from the direct photon
1120  for (JetMap::Iter iter = recojets->begin();
1121  iter != recojets->end();
1122  ++iter)
1123  {
1124  Jet *jet = iter->second;
1125 
1126  _recojetpt = jet->get_pt();
1127  if (_recojetpt < minjetpt)
1128  continue;
1129 
1130  _recojeteta = jet->get_eta();
1131  if (_recojeteta < etalow || _recojeteta > etahigh)
1132  continue;
1133 
1134  _recojetpx = jet->get_px();
1135  _recojetpy = jet->get_py();
1136  _recojetpz = jet->get_pz();
1137  _recojetphi = jet->get_phi();
1138  _recojetmass = jet->get_mass();
1139  _recojetp = jet->get_p();
1140  _recojetenergy = jet->get_e();
1141  _recojetid = jet->get_id();
1142 
1143  _truthjetid = 0;
1144  _truthjetp = 0;
1145  _truthjetphi = 0;
1146  _truthjeteta = 0;
1147  _truthjetpt = 0;
1148  _truthjetenergy = 0;
1149  _truthjetpx = 0;
1150  _truthjetpy = 0;
1151  _truthjetpz = 0;
1152 
1153  //try to match reco jet with closest truth jet
1154  //this is A+A so we know the jet eval stack doesn't work
1155  //so just match the truth-reco jet pair by distance
1156  float closestjet = 9999;
1157  for (JetMap::Iter iter = truthjets->begin(); iter != truthjets->end(); ++iter)
1158  {
1159  Jet *truthjet = iter->second;
1160 
1161  float thisjetpt = truthjet->get_pt();
1162  if (thisjetpt < minjetpt)
1163  continue;
1164 
1165  float thisjeteta = truthjet->get_eta();
1166  float thisjetphi = truthjet->get_phi();
1167 
1168  float dphi = recojetphi - thisjetphi;
1169  if (dphi > 3. * pi / 2.)
1170  dphi -= pi * 2.;
1171  if (dphi < -1. * pi / 2.)
1172  dphi += pi * 2.;
1173 
1174  float deta = recojeteta - thisjeteta;
1175 
1176  float dR = sqrt(pow(dphi, 2.) + pow(deta, 2.));
1177 
1178  if (dR < recojets->get_par() && dR < closestjet)
1179  {
1180  _truthjetid = -9999; //indicates matched with distance, not evalstack
1181  _truthjetp = truthjet->get_p();
1182  _truthjetphi = truthjet->get_phi();
1183  _truthjeteta = truthjet->get_eta();
1184  _truthjetpt = truthjet->get_pt();
1185  _truthjetenergy = truthjet->get_e();
1186  _truthjetpx = truthjet->get_px();
1187  _truthjetpy = truthjet->get_py();
1188  _truthjetpz = truthjet->get_pz();
1189  _truthjetmass = truthjet->get_mass();
1190  }
1191 
1192  if (dR < closestjet)
1193  closestjet = dR;
1194  }
1195 
1196  jetdphi = trig_phi - _recojetphi;
1197  if (jetdphi < pi2)
1198  jetdphi += 2. * pi;
1199  if (jetdphi > threepi2)
1200  jetdphi -= 2. * pi;
1201 
1202  if (fabs(jetdphi) < 0.05)
1203  //don't care about matching the reco photon with itself
1204  continue;
1205 
1206  jetdeta = trig_eta - _recojeteta;
1207  jetpout = _recojetpt * TMath::Sin(jetdphi);
1208 
1209  isophot_jet_tree->Fill();
1210  }
1211 }
1214  JetMap *jets,
1215  JetMap *trackedjets,
1216  JetRecoEval *recoeval,
1217  SvtxTrackEval *trackeval,
1218  PHG4TruthInfoContainer *alltruth,
1219  JetTruthEval *trutheval,
1220  JetMap *truthjets,
1221  GlobalVertex *vtx)
1222 {
1223  CLHEP::Hep3Vector vertex(vtx->get_x(), vtx->get_y(), vtx->get_z());
1224  CLHEP::Hep3Vector E_vec_cluster = RawClusterUtility::GetECoreVec(*trig, vertex);
1225 
1226  float trig_phi = E_vec_cluster.getPhi();
1227  float trig_eta = E_vec_cluster.pseudoRapidity();
1228 
1230 
1231  //Match the reco photon with the truth photon
1232  for (PHG4TruthInfoContainer::ConstIterator iter = range.first;
1233  iter != range.second;
1234  ++iter)
1235  {
1236  PHG4Particle *truth = iter->second;
1237 
1238  clustruthpid = truth->get_pid();
1239  if (clustruthpid == 22)
1240  {
1241  clustruthpx = truth->get_px();
1242  clustruthpy = truth->get_py();
1243  clustruthpz = truth->get_pz();
1244  clustruthenergy = truth->get_e();
1246  if (clustruthpt < mincluspt)
1247  continue;
1248 
1249  TLorentzVector vec;
1250  vec.SetPxPyPzE(clustruthpx, clustruthpy, clustruthpz, clustruthenergy);
1251  clustruthphi = vec.Phi();
1252 
1253  clustrutheta = TMath::ATanH(clustruthpz / clustruthenergy);
1254  //check for nans
1255  if (clustrutheta != clustrutheta)
1256  clustrutheta = -9999;
1257 
1258  if (fabs(clustruthphi - trig_phi) > 0.02 || fabs(clustrutheta - trig_eta) > 0.02)
1259  continue;
1260 
1261  //once the values are set, we've found the truth photon so just break out of this loop
1262  break;
1263  }
1264  }
1265 
1266  if (eval_tracked_jets)
1267  {
1268  if (Verbosity() > 1)
1269  {
1270  cout << "evaluating tracked hadrons opposite the direct photon" << endl;
1271  }
1272  for (SvtxTrackMap::Iter iter = tracks->begin();
1273  iter != tracks->end();
1274  ++iter)
1275  {
1276  SvtxTrack *track = iter->second;
1277 
1278  _tr_px = track->get_px();
1279  _tr_py = track->get_py();
1280  _tr_pz = track->get_pz();
1281  _tr_pt = sqrt(_tr_px * _tr_px + _tr_py * _tr_py);
1282  if (_tr_pt < 0.5)
1283  continue;
1284 
1285  _tr_p = sqrt(_tr_px * _tr_px + _tr_py * _tr_py + _tr_pz * _tr_pz);
1286  _tr_phi = track->get_phi();
1287  _tr_eta = track->get_eta();
1288  _charge = track->get_charge();
1289  _chisq = track->get_chisq();
1290  //can find appropriate values to cut on for these later
1291  _ndf = track->get_ndf();
1292  _dca = track->get_dca();
1293 
1294  _tr_x = track->get_x();
1295  _tr_y = track->get_y();
1296  _tr_z = track->get_z();
1297 
1298  haddphi = trig_phi - _tr_phi;
1299  if (haddphi < pi2)
1300  haddphi += 2. * pi;
1301  if (haddphi > threepi2)
1302  haddphi -= 2. * pi;
1303 
1304  //get the truth track info
1305  PHG4Particle *truthtrack = trackeval->max_truth_particle_by_nclusters(track);
1306  _truth_is_primary = alltruth->is_primary(truthtrack);
1307 
1308  _truthtrackpx = truthtrack->get_px();
1309  _truthtrackpy = truthtrack->get_py();
1310  _truthtrackpz = truthtrack->get_pz();
1312 
1313  _truthtracke = truthtrack->get_e();
1314  TLorentzVector *Truthtrack = new TLorentzVector();
1315  Truthtrack->SetPxPyPzE(truthtrackpx, truthtrackpy, truthtrackpz, truthtracke);
1316  _truthtrackpt = Truthtrack->Pt();
1317  _truthtrackphi = Truthtrack->Phi();
1318  _truthtracketa = Truthtrack->Eta();
1319  _truthtrackpid = truthtrack->get_pid();
1320 
1321  haddeta = trig_eta - _tr_eta;
1322 
1323  hadpout = _tr_pt * TMath::Sin(haddphi);
1324 
1325  isophot_had_tree->Fill();
1326  }
1327 
1328  //now collect the away-sidet tracked jets from the direct photon
1329  for (JetMap::Iter iter = trackedjets->begin();
1330  iter != trackedjets->end();
1331  ++iter)
1332  {
1333  Jet *jet = iter->second;
1334  Jet *truthjet = recoeval->max_truth_jet_by_energy(jet);
1335 
1336  _trecojetpt = jet->get_pt();
1337 
1338  if (_trecojetpt < minjetpt)
1339  continue;
1340 
1341  _trecojeteta = jet->get_eta();
1342  if (fabs(_trecojeteta) > 1.)
1343  continue;
1344 
1345  _trecojetpx = jet->get_px();
1346  _trecojetpy = jet->get_py();
1347  _trecojetpz = jet->get_pz();
1348  _trecojetphi = jet->get_phi();
1349  _trecojetmass = jet->get_mass();
1350  _trecojetp = jet->get_p();
1351  _trecojetenergy = jet->get_e();
1352  _trecojetid = jet->get_id();
1353 
1354  if (truthjet)
1355  {
1356  _ttruthjetid = truthjet->get_id();
1357  _ttruthjetp = truthjet->get_p();
1358  _ttruthjetphi = truthjet->get_phi();
1359  _ttruthjeteta = truthjet->get_eta();
1360  _ttruthjetpt = truthjet->get_pt();
1361  _ttruthjetenergy = truthjet->get_e();
1362  _ttruthjetpx = truthjet->get_px();
1363  _ttruthjetpy = truthjet->get_py();
1364  _ttruthjetpz = truthjet->get_pz();
1365  }
1366  //for some reason jeteval stack doesn't have matched jets, just set them to -999
1367  else
1368  {
1369  _ttruthjetid = -9999;
1370  _ttruthjetp = -9999;
1371  _ttruthjetphi = -9999;
1372  _ttruthjeteta = -9999;
1373  _ttruthjetpt = -9999;
1374  _ttruthjetenergy = -9999;
1375  _ttruthjetpx = -9999;
1376  _ttruthjetpy = -9999;
1377  _ttruthjetpz = -9999;
1378  }
1379 
1380  tjetdphi = trig_phi - _trecojetphi;
1381  if (tjetdphi < pi2)
1382  tjetdphi += 2. * pi;
1383  if (tjetdphi > threepi2)
1384  tjetdphi -= 2. * pi;
1385 
1386  if (fabs(tjetdphi) < 0.05)
1387  //just pairedthe photon with itself instead of with a jet, so skip it
1388  continue;
1389 
1390  tjetdeta = trig_eta - _trecojeteta;
1391  tjetpout = _trecojetpt * TMath::Sin(jetdphi);
1392 
1393  isophot_trackjet_tree->Fill();
1394  }
1395  }
1396 
1397  //now collect awayside cluster jets
1398 
1399  for (JetMap::Iter iter = jets->begin();
1400  iter != jets->end();
1401  ++iter)
1402  {
1403  Jet *jet = iter->second;
1404  Jet *truthjet = recoeval->max_truth_jet_by_energy(jet);
1405 
1406  _recojetpt = jet->get_pt();
1407  if (_recojetpt < minjetpt)
1408  continue;
1409 
1410  _recojeteta = jet->get_eta();
1411  if (_recojeteta < etalow || _recojeteta > etahigh)
1412  continue;
1413 
1414  _recojetpx = jet->get_px();
1415  _recojetpy = jet->get_py();
1416  _recojetpz = jet->get_pz();
1417  _recojetphi = jet->get_phi();
1418  _recojetmass = jet->get_mass();
1419  _recojetp = jet->get_p();
1420  _recojetenergy = jet->get_e();
1421  _recojetid = jet->get_id();
1422  int pair_ntruthconstituents = 0;
1423  if (truthjet)
1424  {
1425  _truthjetid = truthjet->get_id();
1426  _truthjetp = truthjet->get_p();
1427  _truthjetphi = truthjet->get_phi();
1428  _truthjeteta = truthjet->get_eta();
1429  _truthjetpt = truthjet->get_pt();
1430  _truthjetenergy = truthjet->get_e();
1431  _truthjetpx = truthjet->get_px();
1432  _truthjetpy = truthjet->get_py();
1433  _truthjetpz = truthjet->get_pz();
1434  _truthjetmass = truthjet->get_mass();
1435 
1436  //check that the jet isn't just a photon or something like this
1437  //needs at least 2 constituents and that 90% of jet isn't from one photon
1438  std::set<PHG4Particle *> truthjetcomp =
1439  trutheval->all_truth_particles(truthjet);
1440 
1441  float truthjetenergysum = 0;
1442  float truthjethighestphoton = 0;
1443  for (std::set<PHG4Particle *>::iterator iter2 = truthjetcomp.begin();
1444  iter2 != truthjetcomp.end();
1445  ++iter2)
1446  {
1447  PHG4Particle *truthpart = *iter2;
1448  if (!truthpart)
1449  {
1450  cout << "no truth particles in the jet??" << endl;
1451  break;
1452  }
1453  pair_ntruthconstituents++;
1454 
1455  int constpid = truthpart->get_pid();
1456  float conste = truthpart->get_e();
1457 
1458  truthjetenergysum += conste;
1459 
1460  if (constpid == 22)
1461  {
1462  if (conste > truthjethighestphoton)
1463  truthjethighestphoton = conste;
1464  }
1465  }
1466  }
1467 
1468  else
1469  {
1470  _truthjetid = 0;
1471  _truthjetp = 0;
1472  _truthjetphi = 0;
1473  _truthjeteta = 0;
1474  _truthjetpt = 0;
1475  _truthjetenergy = 0;
1476  _truthjetpx = 0;
1477  _truthjetpy = 0;
1478  _truthjetpz = 0;
1479 
1480  //if the jetevalstack can't find a good truth jet
1481  //try to match reco jet with closest truth jet
1482  float closestjet = 9999;
1483  for (JetMap::Iter iter = truthjets->begin(); iter != truthjets->end(); ++iter)
1484  {
1485  Jet *trutherjet = iter->second;
1486 
1487  float thisjetpt = trutherjet->get_pt();
1488  if (thisjetpt < minjetpt)
1489  continue;
1490 
1491  float thisjeteta = trutherjet->get_eta();
1492  float thisjetphi = trutherjet->get_phi();
1493 
1494  float dphi = recojetphi - thisjetphi;
1495  if (dphi > 3. * pi / 2.)
1496  dphi -= pi * 2.;
1497  if (dphi < -1. * pi / 2.)
1498  dphi += pi * 2.;
1499 
1500  float deta = recojeteta - thisjeteta;
1501 
1502  float dR = sqrt(pow(dphi, 2.) + pow(deta, 2.));
1503 
1504  if (dR < jets->get_par() && dR < closestjet)
1505  {
1506  _truthjetid = -9999; //indicates matched with distance, not evalstack
1507  _truthjetp = trutherjet->get_p();
1508  _truthjetphi = trutherjet->get_phi();
1509  _truthjeteta = trutherjet->get_eta();
1510  _truthjetpt = trutherjet->get_pt();
1511  _truthjetenergy = trutherjet->get_e();
1512  _truthjetpx = trutherjet->get_px();
1513  _truthjetpy = trutherjet->get_py();
1514  _truthjetpz = trutherjet->get_pz();
1515  _truthjetmass = trutherjet->get_mass();
1516  }
1517 
1518  if (dR < closestjet)
1519  closestjet = dR;
1520  }
1521  }
1522 
1523  //make sure the jet has at least 3 constiutents
1524  if (!is_AA && pair_ntruthconstituents < 3)
1525  continue;
1526 
1527  jetdphi = trig_phi - _recojetphi;
1528  if (jetdphi < pi2)
1529  jetdphi += 2. * pi;
1530  if (jetdphi > threepi2)
1531  jetdphi -= 2. * pi;
1532 
1533  //just pairedthe photon with itself instead of with a jet, so skip it
1534  if (fabs(jetdphi) < 0.05)
1535  continue;
1536 
1537  jetdeta = trig_eta - _recojeteta;
1538  jetpout = _recojetpt * TMath::Sin(jetdphi);
1539 
1540  isophot_jet_tree->Fill();
1541  }
1542 }
1543 
1545  RawClusterContainer *cluster_container,
1546  SvtxTrackMap *trackmap,
1547  float coneradius,
1548  GlobalVertex *vtx)
1549 {
1550  float energyptsum = 0;
1551 
1552  CLHEP::Hep3Vector vertex(vtx->get_x(), vtx->get_y(), vtx->get_z());
1553  CLHEP::Hep3Vector E_vec_cluster = RawClusterUtility::GetECoreVec(*cluster, vertex);
1554 
1555  RawClusterContainer::ConstRange begin_end = cluster_container->getClusters();
1557 
1558  for (clusiter = begin_end.first;
1559  clusiter != begin_end.second;
1560  ++clusiter)
1561  {
1562  RawCluster *conecluster = clusiter->second;
1563 
1564  //check to make sure that the candidate isolated photon isn't being counted in the energy sum
1565  if (conecluster->get_energy() == cluster->get_energy())
1566  if (conecluster->get_phi() == cluster->get_phi())
1567  if (conecluster->get_z() == cluster->get_z())
1568  continue;
1569 
1570  CLHEP::Hep3Vector E_vec_conecluster = RawClusterUtility::GetECoreVec(*conecluster, vertex);
1571 
1572  float cone_pt = E_vec_conecluster.perp();
1573 
1574  if (cone_pt < 0.2)
1575  continue;
1576 
1577  float cone_e = conecluster->get_energy();
1578  float cone_eta = E_vec_conecluster.pseudoRapidity();
1579  float cone_phi = E_vec_conecluster.getPhi();
1580 
1581  float dphi = cluster->get_phi() - cone_phi;
1582  if (dphi < -1 * pi)
1583  dphi += 2. * pi;
1584  if (dphi > pi)
1585  dphi -= 2. * pi;
1586 
1587  float deta = E_vec_cluster.pseudoRapidity() - cone_eta;
1588 
1589  float radius = sqrt(dphi * dphi + deta * deta);
1590 
1591  if (radius < coneradius)
1592  {
1593  energyptsum += cone_e;
1594  }
1595  }
1596 
1597  for (SvtxTrackMap::Iter iter = trackmap->begin(); iter != trackmap->end(); ++iter)
1598  {
1599  SvtxTrack *track = iter->second;
1600 
1601  float trackpx = track->get_px();
1602  float trackpy = track->get_py();
1603  float trackpt = sqrt(trackpx * trackpx + trackpy * trackpy);
1604  if (trackpt < 0.2)
1605  continue;
1606  float trackphi = track->get_phi();
1607  float tracketa = track->get_eta();
1608  float dphi = E_vec_cluster.getPhi() - trackphi;
1609  float deta = E_vec_cluster.pseudoRapidity() - tracketa;
1610  float radius = sqrt(dphi * dphi + deta * deta);
1611 
1612  if (radius < coneradius)
1613  {
1614  energyptsum += trackpt;
1615  }
1616  }
1617 
1618  return energyptsum;
1619 }
1620 
1622 {
1623  cluster_tree = new TTree("clustertree", "A tree with EMCal cluster information");
1624  cluster_tree->Branch("clus_energy", &clus_energy, "clus_energy/F");
1625  cluster_tree->Branch("clus_eta", &clus_eta, "clus_eta/F");
1626  cluster_tree->Branch("clus_phi", &clus_phi, "clus_phi/F");
1627  cluster_tree->Branch("clus_pt", &clus_pt, "clus_pt/F");
1628  cluster_tree->Branch("clus_theta", &clus_theta, "clus_theta/F");
1629  cluster_tree->Branch("clus_x", &clus_x, "clus_x/F");
1630  cluster_tree->Branch("clus_y", &clus_y, "clus_y/F");
1631  cluster_tree->Branch("clus_z", &clus_z, "clus_z/F");
1632  cluster_tree->Branch("clus_t", &clus_t, "clus_t/F");
1633  cluster_tree->Branch("clus_px", &clus_px, "clus_px/F");
1634  cluster_tree->Branch("clus_py", &clus_py, "clus_py/F");
1635  cluster_tree->Branch("clus_pz", &clus_pz, "clus_pz/F");
1636  cluster_tree->Branch("nevents", &nevents, "nevents/I");
1637  cluster_tree->Branch("process_id", &process_id, "process_id/I");
1638  cluster_tree->Branch("x1", &x1, "x1/F");
1639  cluster_tree->Branch("x2", &x2, "x2/F");
1640  cluster_tree->Branch("partid1", &partid1, "partid1/I");
1641  cluster_tree->Branch("partid2", &partid2, "partid2/I");
1642  cluster_tree->Branch("E_4x4", &E_4x4, "E_4x4/F");
1643  cluster_tree->Branch("phi_4x4", &phi_4x4, "phi_4x4/F");
1644  cluster_tree->Branch("eta_4x4", &eta_4x4, "eta_4x4/F");
1645  cluster_tree->Branch("E_2x2", &E_2x2, "E_2x2/F");
1646  cluster_tree->Branch("phi_2x2", &phi_2x2, "phi_2x2/F");
1647  cluster_tree->Branch("eta_2x2", &eta_2x2, "eta_2x2/F");
1648 
1649  isolated_clusters = new TTree("isolated_clusters", "a tree with isolated EMCal clusters");
1650  isolated_clusters->Branch("clus_energy", &clus_energy, "clus_energy/F");
1651  isolated_clusters->Branch("clus_eta", &clus_eta, "clus_eta/F");
1652  isolated_clusters->Branch("clus_phi", &clus_phi, "clus_phi/F");
1653  isolated_clusters->Branch("clus_pt", &clus_pt, "clus_pt/F");
1654  isolated_clusters->Branch("clus_theta", &clus_theta, "clus_theta/F");
1655  isolated_clusters->Branch("clus_x", &clus_x, "clus_x/F");
1656  isolated_clusters->Branch("clus_y", &clus_y, "clus_y/F");
1657  isolated_clusters->Branch("clus_z", &clus_z, "clus_z/F");
1658  isolated_clusters->Branch("clus_t", &clus_t, "clus_t/F");
1659  isolated_clusters->Branch("clus_px", &clus_px, "clus_px/F");
1660  isolated_clusters->Branch("clus_py", &clus_py, "clus_py/F");
1661  isolated_clusters->Branch("clus_pz", &clus_pz, "clus_pz/F");
1662  isolated_clusters->Branch("nevents", &nevents, "nenvents/I");
1663  isolated_clusters->Branch("clustruthenergy", &clustruthenergy, "clustruthenergy/F");
1664  isolated_clusters->Branch("clustruthpt", &clustruthpt, "clustruthpt/F");
1665  isolated_clusters->Branch("clustruthphi", &clustruthphi, "clustruthphi/F");
1666  isolated_clusters->Branch("clustrutheta", &clustrutheta, "clustrutheta/F");
1667  isolated_clusters->Branch("clustruthpx", &clustruthpx, "clustruthpx/F");
1668  isolated_clusters->Branch("clustruthpy", &clustruthpy, "clustruthpy/F");
1669  isolated_clusters->Branch("clustruthpz", &clustruthpz, "clustruthpz/F");
1670  isolated_clusters->Branch("process_id", &process_id, "process_id/I");
1671  isolated_clusters->Branch("x1", &x1, "x1/F");
1672  isolated_clusters->Branch("x2", &x2, "x2/F");
1673  isolated_clusters->Branch("partid1", &partid1, "partid1/I");
1674  isolated_clusters->Branch("partid2", &partid2, "partid2/I");
1675  isolated_clusters->Branch("E_4x4", &E_4x4, "E_4x4/F");
1676  isolated_clusters->Branch("phi_4x4", &phi_4x4, "phi_4x4/F");
1677  isolated_clusters->Branch("eta_4x4", &eta_4x4, "eta_4x4/F");
1678  isolated_clusters->Branch("E_2x2", &E_2x2, "E_2x2/F");
1679  isolated_clusters->Branch("phi_2x2", &phi_2x2, "phi_2x2/F");
1680  isolated_clusters->Branch("eta_2x2", &eta_2x2, "eta_2x2/F");
1681 
1682  tracktree = new TTree("tracktree", "a tree with svtx tracks");
1683  tracktree->Branch("tr_px", &tr_px, "tr_px/F");
1684  tracktree->Branch("tr_py", &tr_py, "tr_py/F");
1685  tracktree->Branch("tr_pz", &tr_pz, "tr_pz/F");
1686  tracktree->Branch("tr_pt", &tr_pt, "tr_pt/F");
1687  tracktree->Branch("tr_phi", &tr_phi, "tr_phi/F");
1688  tracktree->Branch("tr_eta", &tr_eta, "tr_eta/F");
1689  tracktree->Branch("charge", &charge, "charge/I");
1690  tracktree->Branch("chisq", &chisq, "chisq/F");
1691  tracktree->Branch("ndf", &ndf, "ndf/I");
1692  tracktree->Branch("dca", &dca, "dca/F");
1693  tracktree->Branch("tr_x", &tr_x, "tr_x/F");
1694  tracktree->Branch("tr_y", &tr_y, "tr_y/F");
1695  tracktree->Branch("tr_z", &tr_z, "tr_z/F");
1696  tracktree->Branch("nevents", &nevents, "nevents/i");
1697 
1698  tracktree->Branch("truthtrackpx", &truthtrackpx, "truthtrackpx/F");
1699  tracktree->Branch("truthtrackpy", &truthtrackpy, "truthtrackpy/F");
1700  tracktree->Branch("truthtrackpz", &truthtrackpz, "truthtrackpz/F");
1701  tracktree->Branch("truthtrackp", &truthtrackp, "truthtrackp/F");
1702  tracktree->Branch("truthtracke", &truthtracke, "truthtracke/F");
1703  tracktree->Branch("truthtrackpt", &truthtrackpt, "truthtrackpt/F");
1704  tracktree->Branch("truthtrackphi", &truthtrackphi, "truthtrackphi/F");
1705  tracktree->Branch("truthtracketa", &truthtracketa, "truthtracketa/F");
1706  tracktree->Branch("truthtrackpid", &truthtrackpid, "truthtrackpid/I");
1707  tracktree->Branch("truth_is_primary", &truth_is_primary, "truth_is_primary/B");
1708  tracktree->Branch("process_id", &process_id, "process_id/I");
1709  tracktree->Branch("x1", &x1, "x1/F");
1710  tracktree->Branch("x2", &x2, "x2/F");
1711  tracktree->Branch("partid1", &partid1, "partid1/I");
1712  tracktree->Branch("partid2", &partid2, "partid2/I");
1713 
1714  truthjettree = new TTree("truthjettree", "a tree with truth jets");
1715  truthjettree->Branch("ntruthconstituents", &ntruthconstituents, "ntruthconstituents/I");
1716  truthjettree->Branch("truthjetpt", &truthjetpt, "truthjetpt/F");
1717  truthjettree->Branch("truthjetpx", &truthjetpx, "truthjetpx/F");
1718  truthjettree->Branch("truthjetpy", &truthjetpy, "truthjetpy/F");
1719  truthjettree->Branch("truthjetpz", &truthjetpz, "truthjetpz/F");
1720  truthjettree->Branch("truthjetphi", &truthjetphi, "truthjetphi/F");
1721  truthjettree->Branch("truthjeteta", &truthjeteta, "truthjeteta/F");
1722  truthjettree->Branch("truthjetmass", &truthjetmass, "truthjetmass/F");
1723  truthjettree->Branch("truthjetp", &truthjetp, "truthjetp/F");
1724  truthjettree->Branch("truthjetenergy", &truthjetenergy, "truthjetenergy/F");
1725  truthjettree->Branch("nevents", &nevents, "nevents/I");
1726  truthjettree->Branch("process_id", &process_id, "process_id/I");
1727  truthjettree->Branch("x1", &x1, "x1/F");
1728  truthjettree->Branch("x2", &x2, "x2/F");
1729  truthjettree->Branch("partid1", &partid1, "partid1/I");
1730  truthjettree->Branch("partid2", &partid2, "partid2/I");
1731  truthjettree->Branch("E_4x4", &E_4x4, "E_4x4/F");
1732  truthjettree->Branch("phi_4x4", &phi_4x4, "phi_4x4/F");
1733  truthjettree->Branch("eta_4x4", &eta_4x4, "eta_4x4/F");
1734  truthjettree->Branch("E_2x2", &E_2x2, "E_2x2/F");
1735  truthjettree->Branch("phi_2x2", &phi_2x2, "phi_2x2/F");
1736  truthjettree->Branch("eta_2x2", &eta_2x2, "eta_2x2/F");
1737 
1738  recojettree = new TTree("recojettree", "a tree with reco jets");
1739  recojettree->Branch("dR", &dR, "dR/F");
1740  recojettree->Branch("recojetpt", &recojetpt, "recojetpt/F");
1741  recojettree->Branch("recojetpx", &recojetpx, "recojetpx/F");
1742  recojettree->Branch("recojetpy", &recojetpy, "recojetpy/F");
1743  recojettree->Branch("recojetpz", &recojetpz, "recojetpz/F");
1744  recojettree->Branch("recojetphi", &recojetphi, "recojetphi/F");
1745  recojettree->Branch("recojeteta", &recojeteta, "recojeteta/F");
1746  recojettree->Branch("recojetmass", &recojetmass, "recojetmass/F");
1747  recojettree->Branch("recojetp", &recojetp, "recojetp/F");
1748  recojettree->Branch("recojetenergy", &recojetenergy, "recojetenergy/F");
1749  recojettree->Branch("nevents", &nevents, "nevents/I");
1750  recojettree->Branch("recojetid", &recojetid, "recojetid/F");
1751  recojettree->Branch("truthjetid", &truthjetid, "truthjetid/F");
1752  recojettree->Branch("truthjetp", &truthjetp, "truthjetp/F");
1753  recojettree->Branch("truthjetphi", &truthjetphi, "truthjetphi/F");
1754  recojettree->Branch("truthjeteta", &truthjeteta, "truthjeteta/F");
1755  recojettree->Branch("truthjetpt", &truthjetpt, "truthjetpt/F");
1756  recojettree->Branch("truthjetenergy", &truthjetenergy, "truthjetenergy/F");
1757  recojettree->Branch("truthjetpx", &truthjetpx, "truthjetpx/F");
1758  recojettree->Branch("truthjetpy", &truthjetpy, "truthjetpy/F");
1759  recojettree->Branch("truthjetpz", &truthjetpz, "truthjetpz/F");
1760  recojettree->Branch("process_id", &process_id, "process_id/I");
1761  recojettree->Branch("truthjetmass", &truthjetmass, "truthjetmass/F");
1762  recojettree->Branch("x1", &x1, "x1/F");
1763  recojettree->Branch("x2", &x2, "x2/F");
1764  recojettree->Branch("partid1", &partid1, "partid1/I");
1765  recojettree->Branch("partid2", &partid2, "partid2/I");
1766  recojettree->Branch("E_4x4", &E_4x4, "E_4x4/F");
1767  recojettree->Branch("phi_4x4", &phi_4x4, "phi_4x4/F");
1768  recojettree->Branch("eta_4x4", &eta_4x4, "eta_4x4/F");
1769  recojettree->Branch("E_2x2", &E_2x2, "E_2x2/F");
1770  recojettree->Branch("phi_2x2", &phi_2x2, "phi_2x2/F");
1771  recojettree->Branch("eta_2x2", &eta_2x2, "eta_2x2/F");
1772  recojettree->Branch("constituent_dphis","std::vector<float>",&constituent_dphis);
1773  recojettree->Branch("constituent_detas","std::vector<float>",&constituent_detas);
1774 
1775 
1776  isophot_jet_tree = new TTree("isophoton-jets",
1777  "a tree with correlated isolated photons and jets");
1778  isophot_jet_tree->Branch("clus_energy", &clus_energy, "clus_energy/F");
1779  isophot_jet_tree->Branch("clus_eta", &clus_eta, "clus_eta/F");
1780  isophot_jet_tree->Branch("clus_phi", &clus_phi, "clus_phi/F");
1781  isophot_jet_tree->Branch("clus_pt", &clus_pt, "clus_pt/F");
1782  isophot_jet_tree->Branch("clus_theta", &clus_theta, "clus_theta/F");
1783  isophot_jet_tree->Branch("clus_x", &clus_x, "clus_x/F");
1784  isophot_jet_tree->Branch("clus_y", &clus_y, "clus_y/F");
1785  isophot_jet_tree->Branch("clus_z", &clus_z, "clus_z/F");
1786  isophot_jet_tree->Branch("clus_t", &clus_t, "clus_t/F");
1787  isophot_jet_tree->Branch("clus_px", &clus_px, "clus_px/F");
1788  isophot_jet_tree->Branch("clus_py", &clus_py, "clus_py/F");
1789  isophot_jet_tree->Branch("clus_pz", &clus_pz, "clus_pz/F");
1790  isophot_jet_tree->Branch("clustruthenergy", &clustruthenergy, "clustruthenergy/F");
1791  isophot_jet_tree->Branch("clustruthpt", &clustruthpt, "clustruthpt/F");
1792  isophot_jet_tree->Branch("clustruthphi", &clustruthphi, "clustruthphi/F");
1793  isophot_jet_tree->Branch("clustrutheta", &clustrutheta, "clustrutheta/F");
1794  isophot_jet_tree->Branch("clustruthpx", &clustruthpx, "clustruthpx/F");
1795  isophot_jet_tree->Branch("clustruthpy", &clustruthpy, "clustruthpy/F");
1796  isophot_jet_tree->Branch("clustruthpz", &clustruthpz, "clustruthpz/F");
1797  isophot_jet_tree->Branch("_recojetpt", &_recojetpt, "_recojetpt/F");
1798  isophot_jet_tree->Branch("_recojetpx", &_recojetpx, "_recojetpx/F");
1799  isophot_jet_tree->Branch("_recojetpy", &_recojetpy, "_recojetpy/F");
1800  isophot_jet_tree->Branch("_recojetpz", &_recojetpz, "_recojetpz/F");
1801  isophot_jet_tree->Branch("_recojetphi", &_recojetphi, "_recojetphi/F");
1802  isophot_jet_tree->Branch("_recojeteta", &_recojeteta, "_recojeteta/F");
1803  isophot_jet_tree->Branch("_recojetmass", &_recojetmass, "_recojetmass/F");
1804  isophot_jet_tree->Branch("_recojetp", &_recojetp, "_recojetp/F");
1805  isophot_jet_tree->Branch("_recojetenergy", &_recojetenergy, "_recojetenergy/F");
1806  isophot_jet_tree->Branch("jetdphi", &jetdphi, "jetdphi/F");
1807  isophot_jet_tree->Branch("jetdeta", &jetdeta, "jetdeta/F");
1808  isophot_jet_tree->Branch("jetpout", &jetpout, "jetpout/F");
1809  isophot_jet_tree->Branch("nevents", &nevents, "nevents/I");
1810  isophot_jet_tree->Branch("_recojetid", &_recojetid, "_recojetid/F");
1811  isophot_jet_tree->Branch("_truthjetid", &_truthjetid, "_truthjetid/F");
1812  isophot_jet_tree->Branch("_truthjetp", &_truthjetp, "_truthjetp/F");
1813  isophot_jet_tree->Branch("_truthjetphi", &_truthjetphi, "_truthjetphi/F");
1814  isophot_jet_tree->Branch("_truthjeteta", &_truthjeteta, "_truthjeteta/F");
1815  isophot_jet_tree->Branch("_truthjetpt", &_truthjetpt, "_truthjetpt/F");
1816  isophot_jet_tree->Branch("_truthjetenergy", &_truthjetenergy, "_truthjetenergy/F");
1817  isophot_jet_tree->Branch("_truthjetpx", &_truthjetpx, "_truthjetpx/F");
1818  isophot_jet_tree->Branch("_truthjetpy", &_truthjetpy, "_truthjetpy/F");
1819  isophot_jet_tree->Branch("_truthjetpz", &_truthjetpz, "_truthjetpz/F");
1820  isophot_jet_tree->Branch("process_id", &process_id, "process_id/I");
1821  isophot_jet_tree->Branch("x1", &x1, "x1/F");
1822  isophot_jet_tree->Branch("x2", &x2, "x2/F");
1823  isophot_jet_tree->Branch("partid1", &partid1, "partid1/I");
1824  isophot_jet_tree->Branch("partid2", &partid2, "partid2/I");
1825  isophot_jet_tree->Branch("E_4x4", &E_4x4, "E_4x4/F");
1826  isophot_jet_tree->Branch("phi_4x4", &phi_4x4, "phi_4x4/F");
1827  isophot_jet_tree->Branch("eta_4x4", &eta_4x4, "eta_4x4/F");
1828  isophot_jet_tree->Branch("E_2x2", &E_2x2, "E_2x2/F");
1829  isophot_jet_tree->Branch("phi_2x2", &phi_2x2, "phi_2x2/F");
1830  isophot_jet_tree->Branch("eta_2x2", &eta_2x2, "eta_2x2/F");
1831 
1832  isophot_trackjet_tree = new TTree("isophoton-trackjets",
1833  "a tree with correlated isolated photons and track jets");
1834  isophot_trackjet_tree->Branch("clus_energy", &clus_energy, "clus_energy/F");
1835  isophot_trackjet_tree->Branch("clus_eta", &clus_eta, "clus_eta/F");
1836  isophot_trackjet_tree->Branch("clus_phi", &clus_phi, "clus_phi/F");
1837  isophot_trackjet_tree->Branch("clus_pt", &clus_pt, "clus_pt/F");
1838  isophot_trackjet_tree->Branch("clus_theta", &clus_theta, "clus_theta/F");
1839  isophot_trackjet_tree->Branch("clus_x", &clus_x, "clus_x/F");
1840  isophot_trackjet_tree->Branch("clus_y", &clus_y, "clus_y/F");
1841  isophot_trackjet_tree->Branch("clus_z", &clus_z, "clus_z/F");
1842  isophot_trackjet_tree->Branch("clus_t", &clus_t, "clus_t/F");
1843  isophot_trackjet_tree->Branch("clus_px", &clus_px, "clus_px/F");
1844  isophot_trackjet_tree->Branch("clus_py", &clus_py, "clus_py/F");
1845  isophot_trackjet_tree->Branch("clus_pz", &clus_pz, "clus_pz/F");
1846  isophot_trackjet_tree->Branch("clustruthenergy", &clustruthenergy, "clustruthenergy/F");
1847  isophot_trackjet_tree->Branch("clustruthpt", &clustruthpt, "clustruthpt/F");
1848  isophot_trackjet_tree->Branch("clustruthphi", &clustruthphi, "clustruthphi/F");
1849  isophot_trackjet_tree->Branch("clustrutheta", &clustrutheta, "clustrutheta/F");
1850  isophot_trackjet_tree->Branch("clustruthpx", &clustruthpx, "clustruthpx/F");
1851  isophot_trackjet_tree->Branch("clustruthpy", &clustruthpy, "clustruthpy/F");
1852  isophot_trackjet_tree->Branch("clustruthpz", &clustruthpz, "clustruthpz/F");
1853  isophot_trackjet_tree->Branch("_trecojetpt", &_trecojetpt, "_trecojetpt/F");
1854  isophot_trackjet_tree->Branch("_trecojetpx", &_trecojetpx, "_trecojetpx/F");
1855  isophot_trackjet_tree->Branch("_trecojetpy", &_trecojetpy, "_trecojetpy/F");
1856  isophot_trackjet_tree->Branch("_trecojetpz", &_trecojetpz, "_trecojetpz/F");
1857  isophot_trackjet_tree->Branch("_trecojetphi", &_trecojetphi, "_trecojetphi/F");
1858  isophot_trackjet_tree->Branch("_trecojeteta", &_trecojeteta, "_trecojeteta/F");
1859  isophot_trackjet_tree->Branch("_trecojetmass", &_trecojetmass, "_trecojetmass/F");
1860  isophot_trackjet_tree->Branch("_trecojetp", &_trecojetp, "_trecojetp/F");
1861  isophot_trackjet_tree->Branch("_trecojetenergy", &_trecojetenergy, "_trecojetenergy/F");
1862  isophot_trackjet_tree->Branch("tjetdphi", &tjetdphi, "tjetdphi/F");
1863  isophot_trackjet_tree->Branch("tjetdeta", &tjetdeta, "tjetdeta/F");
1864  isophot_trackjet_tree->Branch("tjetpout", &tjetpout, "tjetpout/F");
1865  isophot_trackjet_tree->Branch("nevents", &nevents, "nevents/I");
1866  isophot_trackjet_tree->Branch("_trecojetid", &_trecojetid, "_trecojetid/F");
1867  isophot_trackjet_tree->Branch("_ttruthjetid", &_ttruthjetid, "_ttruthjetid/F");
1868  isophot_trackjet_tree->Branch("_ttruthjetp", &_ttruthjetp, "_ttruthjetp/F");
1869  isophot_trackjet_tree->Branch("_ttruthjetphi", &_ttruthjetphi, "_ttruthjetphi/F");
1870  isophot_trackjet_tree->Branch("_ttruthjeteta", &_ttruthjeteta, "_ttruthjeteta/F");
1871  isophot_trackjet_tree->Branch("_ttruthjetpt", &_ttruthjetpt, "_ttruthjetpt/F");
1872  isophot_trackjet_tree->Branch("_ttruthjetenergy", &_ttruthjetenergy, "_ttruthjetenergy/F");
1873  isophot_trackjet_tree->Branch("_ttruthjetpx", &_ttruthjetpx, "_ttruthjetpx/F");
1874  isophot_trackjet_tree->Branch("_ttruthjetpy", &_ttruthjetpy, "_ttruthjetpy/F");
1875  isophot_trackjet_tree->Branch("_ttruthjetpz", &_ttruthjetpz, "_ttruthjetpz/F");
1876  isophot_trackjet_tree->Branch("process_id", &process_id, "process_id/I");
1877  isophot_trackjet_tree->Branch("x1", &x1, "x1/F");
1878  isophot_trackjet_tree->Branch("x2", &x2, "x2/F");
1879  isophot_trackjet_tree->Branch("partid1", &partid1, "partid1/I");
1880  isophot_trackjet_tree->Branch("partid2", &partid2, "partid2/I");
1881  isophot_trackjet_tree->Branch("E_4x4", &E_4x4, "E_4x4/F");
1882  isophot_trackjet_tree->Branch("phi_4x4", &phi_4x4, "phi_4x4/F");
1883  isophot_trackjet_tree->Branch("eta_4x4", &eta_4x4, "eta_4x4/F");
1884  isophot_trackjet_tree->Branch("E_2x2", &E_2x2, "E_2x2/F");
1885  isophot_trackjet_tree->Branch("phi_2x2", &phi_2x2, "phi_2x2/F");
1886  isophot_trackjet_tree->Branch("eta_2x2", &eta_2x2, "eta_2x2/F");
1887 
1888  isophot_had_tree = new TTree("isophoton-hads", "a tree with correlated isolated photons and hadrons");
1889  isophot_had_tree->Branch("clus_energy", &clus_energy, "clus_energy/F");
1890  isophot_had_tree->Branch("clus_eta", &clus_eta, "clus_eta/F");
1891  isophot_had_tree->Branch("clus_phi", &clus_phi, "clus_phi/F");
1892  isophot_had_tree->Branch("clus_pt", &clus_pt, "clus_pt/F");
1893  isophot_had_tree->Branch("clus_theta", &clus_theta, "clus_theta/F");
1894  isophot_had_tree->Branch("clus_x", &clus_x, "clus_x/F");
1895  isophot_had_tree->Branch("clus_y", &clus_y, "clus_y/F");
1896  isophot_had_tree->Branch("clus_z", &clus_z, "clus_z/F");
1897  isophot_had_tree->Branch("clus_t", &clus_t, "clus_t/F");
1898  isophot_had_tree->Branch("clus_px", &clus_px, "clus_px/F");
1899  isophot_had_tree->Branch("clus_py", &clus_py, "clus_py/F");
1900  isophot_had_tree->Branch("clus_pz", &clus_pz, "clus_pz/F");
1901  isophot_had_tree->Branch("clustruthenergy", &clustruthenergy, "clustruthenergy/F");
1902  isophot_had_tree->Branch("clustruthpt", &clustruthpt, "clustruthpt/F");
1903  isophot_had_tree->Branch("clustruthphi", &clustruthphi, "clustruthphi/F");
1904  isophot_had_tree->Branch("clustrutheta", &clustrutheta, "clustrutheta/F");
1905  isophot_had_tree->Branch("clustruthpx", &clustruthpx, "clustruthpx/F");
1906  isophot_had_tree->Branch("clustruthpy", &clustruthpy, "clustruthpy/F");
1907  isophot_had_tree->Branch("clustruthpz", &clustruthpz, "clustruthpz/F");
1908 
1909  isophot_had_tree->Branch("_tr_px", &_tr_px, "_tr_px/F");
1910  isophot_had_tree->Branch("_tr_py", &_tr_py, "_tr_py/F");
1911  isophot_had_tree->Branch("_tr_pz", &_tr_pz, "_tr_pz/F");
1912  isophot_had_tree->Branch("_tr_pt", &_tr_pt, "_tr_pt/F");
1913  isophot_had_tree->Branch("_tr_phi", &_tr_phi, "_tr_phi/F");
1914  isophot_had_tree->Branch("_tr_eta", &_tr_eta, "_tr_eta/F");
1915  isophot_had_tree->Branch("_charge", &_charge, "_charge/I");
1916  isophot_had_tree->Branch("_chisq", &_chisq, "_chisq/F");
1917  isophot_had_tree->Branch("_ndf", &_ndf, "_ndf/I");
1918  isophot_had_tree->Branch("_dca", &_dca, "_dca/F");
1919  isophot_had_tree->Branch("_tr_x", &_tr_x, "_tr_x/F");
1920  isophot_had_tree->Branch("_tr_y", &_tr_y, "_tr_y/F");
1921  isophot_had_tree->Branch("_tr_z", &_tr_z, "_tr_z/F");
1922  isophot_had_tree->Branch("haddphi", &haddphi, "haddphi/F");
1923  isophot_had_tree->Branch("hadpout", &hadpout, "hadpout/F");
1924  isophot_had_tree->Branch("haddeta", &haddeta, "haddeta/F");
1925  isophot_had_tree->Branch("nevents", &nevents, "nevents/I");
1926  isophot_had_tree->Branch("_truthtrackpx", &_truthtrackpx, "_truthtrackpx/F");
1927  isophot_had_tree->Branch("_truthtrackpy", &_truthtrackpy, "_truthtrackpy/F");
1928  isophot_had_tree->Branch("_truthtrackpz", &_truthtrackpz, "_truthtrackpz/F");
1929  isophot_had_tree->Branch("_truthtrackp", &_truthtrackp, "_truthtrackp/F");
1930  isophot_had_tree->Branch("_truthtracke", &_truthtracke, "_truthtracke/F");
1931  isophot_had_tree->Branch("_truthtrackpt", &_truthtrackpt, "_truthtrackpt/F");
1932  isophot_had_tree->Branch("_truthtrackphi", &_truthtrackphi, "_truthtrackphi/F");
1933  isophot_had_tree->Branch("_truthtracketa", &_truthtracketa, "_truthtracketa/F");
1934  isophot_had_tree->Branch("_truthtrackpid", &_truthtrackpid, "_truthtrackpid/I");
1935  isophot_had_tree->Branch("_truth_is_primary", &_truth_is_primary, "_truth_is_primary/B");
1936  isophot_had_tree->Branch("process_id", &process_id, "process_id/I");
1937  isophot_had_tree->Branch("x1", &x1, "x1/F");
1938  isophot_had_tree->Branch("x2", &x2, "x2/F");
1939  isophot_had_tree->Branch("partid1", &partid1, "partid1/I");
1940  isophot_had_tree->Branch("partid2", &partid2, "partid2/I");
1941  isophot_had_tree->Branch("E_4x4", &E_4x4, "E_4x4/F");
1942  isophot_had_tree->Branch("phi_4x4", &phi_4x4, "phi_4x4/F");
1943  isophot_had_tree->Branch("eta_4x4", &eta_4x4, "eta_4x4/F");
1944  isophot_had_tree->Branch("E_2x2", &E_2x2, "E_2x2/F");
1945  isophot_had_tree->Branch("phi_2x2", &phi_2x2, "phi_2x2/F");
1946  isophot_had_tree->Branch("eta_2x2", &eta_2x2, "eta_2x2/F");
1947 
1948  truth_g4particles = new TTree("truthtree_g4", "a tree with all truth g4 particles");
1949  truth_g4particles->Branch("truthpx", &truthpx, "truthpx/F");
1950  truth_g4particles->Branch("truthpy", &truthpy, "truthpy/F");
1951  truth_g4particles->Branch("truthpz", &truthpz, "truthpz/F");
1952  truth_g4particles->Branch("truthp", &truthp, "truthp/F");
1953  truth_g4particles->Branch("truthenergy", &truthenergy, "truthenergy/F");
1954  truth_g4particles->Branch("truthphi", &truthphi, "truthphi/F");
1955  truth_g4particles->Branch("trutheta", &trutheta, "trutheta/F");
1956  truth_g4particles->Branch("truthpt", &truthpt, "truthpt/F");
1957  truth_g4particles->Branch("truthpid", &truthpid, "truthpid/I");
1958  truth_g4particles->Branch("nevents", &nevents, "nevents/I");
1959  truth_g4particles->Branch("process_id", &process_id, "process_id/I");
1960  truth_g4particles->Branch("x1", &x1, "x1/F");
1961  truth_g4particles->Branch("x2", &x2, "x2/F");
1962  truth_g4particles->Branch("partid1", &partid1, "partid1/I");
1963  truth_g4particles->Branch("partid2", &partid2, "partid2/I");
1964  truth_g4particles->Branch("E_4x4", &E_4x4, "E_4x4/F");
1965  truth_g4particles->Branch("phi_4x4", &phi_4x4, "phi_4x4/F");
1966  truth_g4particles->Branch("eta_4x4", &eta_4x4, "eta_4x4/F");
1967  truth_g4particles->Branch("E_2x2", &E_2x2, "E_2x2/F");
1968  truth_g4particles->Branch("phi_2x2", &phi_2x2, "phi_2x2/F");
1969  truth_g4particles->Branch("eta_2x2", &eta_2x2, "eta_2x2/F");
1970 
1971  truthtree = new TTree("truthtree", "a tree with all truth pythia particles");
1972  truthtree->Branch("truthpx", &truthpx, "truthpx/F");
1973  truthtree->Branch("truthpy", &truthpy, "truthpy/F");
1974  truthtree->Branch("truthpz", &truthpz, "truthpz/F");
1975  truthtree->Branch("truthp", &truthp, "truthp/F");
1976  truthtree->Branch("truthenergy", &truthenergy, "truthenergy/F");
1977  truthtree->Branch("truthphi", &truthphi, "truthphi/F");
1978  truthtree->Branch("trutheta", &trutheta, "trutheta/F");
1979  truthtree->Branch("truthpt", &truthpt, "truthpt/F");
1980  truthtree->Branch("truthpid", &truthpid, "truthpid/I");
1981  truthtree->Branch("nevents", &nevents, "nevents/I");
1982  truthtree->Branch("numparticlesinevent", &numparticlesinevent, "numparticlesinevent/I");
1983  truthtree->Branch("process_id", &process_id, "process_id/I");
1984  truthtree->Branch("x1", &x1, "x1/F");
1985  truthtree->Branch("x2", &x2, "x2/F");
1986  truthtree->Branch("partid1", &partid1, "partid1/I");
1987  truthtree->Branch("partid2", &partid2, "partid2/I");
1988 
1989  event_tree = new TTree("eventtree", "A tree with 2 to 2 event info");
1990  event_tree->Branch("mpi", &mpi, "mpi/F");
1991  event_tree->Branch("x1", &x1, "x1/F");
1992  event_tree->Branch("x2", &x2, "x2/F");
1993  event_tree->Branch("partid1", &partid1, "partid1/I");
1994  event_tree->Branch("partid2", &partid2, "partid2/I");
1995  event_tree->Branch("process_id", &process_id, "process_id/I");
1996  event_tree->Branch("nevents", &nevents, "nevents/I");
1997  event_tree->Branch("cluseventenergy", &cluseventenergy, "cluseventenergy/F");
1998  event_tree->Branch("cluseventeta", &cluseventeta, "cluseventeta/F");
1999  event_tree->Branch("cluseventpt", &cluseventpt, "cluseventpt/F");
2000  event_tree->Branch("cluseventphi", &cluseventphi, "cluseventphi/F");
2001  event_tree->Branch("hardest_jetpt", &hardest_jetpt, "hardest_jetpt/F");
2002  event_tree->Branch("hardest_jetphi", &hardest_jetphi, "hardest_jetphi/F");
2003  event_tree->Branch("hardest_jeteta", &hardest_jeteta, "hardest_jeteta/F");
2004  event_tree->Branch("hardest_jetenergy", &hardest_jetenergy, "hardest_jetenergy/F");
2005  event_tree->Branch("E_4x4", &E_4x4, "E_4x4/F");
2006  event_tree->Branch("phi_4x4", &phi_4x4, "phi_4x4/F");
2007  event_tree->Branch("eta_4x4", &eta_4x4, "eta_4x4/F");
2008  event_tree->Branch("E_2x2", &E_2x2, "E_2x2/F");
2009  event_tree->Branch("phi_2x2", &phi_2x2, "phi_2x2/F");
2010  event_tree->Branch("eta_2x2", &eta_2x2, "eta_2x2/F");
2011 }
2012 
2014 {
2015  E_4x4 = 0;
2016  phi_4x4 = 0;
2017  eta_4x4 = 0;
2018  E_2x2 = 0;
2019  phi_2x2 = 0;
2020  eta_2x2 = 0;
2021 
2022  event_tree = 0;
2023  tree = 0;
2024  cluster_tree = 0;
2025  truth_g4particles = 0;
2026  truthtree = 0;
2027  isolated_clusters = 0;
2028  tracktree = 0;
2029  truthjettree = 0;
2030  recojettree = 0;
2031  isophot_jet_tree = 0;
2033  isophot_had_tree = 0;
2034 
2035  histo = 0;
2036  dR = 0;
2037  percent_photon_h = 0;
2038  _truthjetmass = -999;
2039  clus_energy = -999;
2040  clus_eta = -999;
2041  clus_phi = -999;
2042  clus_pt = -999;
2043  clus_px = -999;
2044  clus_py = -999;
2045  clus_pz = -999;
2046  clus_theta = -999;
2047  clus_x = -999;
2048  clus_y = -999;
2049  clus_z = -999;
2050  clus_t = -999;
2051 
2052  tr_px = -999;
2053  tr_py = -999;
2054  tr_pz = -999;
2055  tr_p = -999;
2056  tr_pt = -999;
2057  tr_phi = -999;
2058  tr_eta = -999;
2059  charge = -999;
2060  chisq = -999;
2061  ndf = -999;
2062  dca = -999;
2063  tr_x = -999;
2064  tr_y = -999;
2065  tr_z = -999;
2066  truthtrackpx = -999;
2067  truthtrackpy = -999;
2068  truthtrackpz = -999;
2069  truthtrackp = -999;
2070  truthtracke = -999;
2071  truthtrackpt = -999;
2072  truthtrackphi = -999;
2073  truthtracketa = -999;
2074  truthtrackpid = -999;
2075  truth_is_primary = false;
2076 
2077  truthjetpt = -999;
2078  truthjetpx = -999;
2079  truthjetpy = -999;
2080  truthjetpz = -999;
2081  truthjetphi = -999;
2082  truthjeteta = -999;
2083  truthjetmass = -999;
2084  truthjetp = -999;
2085  truthjetenergy = -999;
2086  recojetpt = -999;
2087  recojetpx = -999;
2088  recojetpy = -999;
2089  recojetpz = -999;
2090  recojetphi = -999;
2091  recojeteta = -999;
2092  recojetmass = -999;
2093  recojetp = -999;
2094  recojetenergy = -999;
2095  recojetid = -999;
2096  truthjetid = -999;
2097 
2098  _recojetid = -999;
2099  _recojetpt = -999;
2100  _recojetpx = -999;
2101  _recojetpy = -999;
2102  _recojetpz = -999;
2103  _recojetphi = -999;
2104  _recojeteta = -999;
2105  _recojetmass = -999;
2106  _recojetp = -999;
2107  _recojetenergy = -999;
2108  jetdphi = -999;
2109  jetpout = -999;
2110  jetdeta = -999;
2111  _truthjetid = -999;
2112  _truthjetpt = -999;
2113  _truthjetpx = -999;
2114  _truthjetpy = -999;
2115  _truthjetpz = -999;
2116  _truthjetphi = -999;
2117  _truthjeteta = -999;
2118  _truthjetmass = -999;
2119  _truthjetp = -999;
2120  _truthjetenergy = -999;
2121 
2122  _trecojetid = -999;
2123  _trecojetpt = -999;
2124  _trecojetpx = -999;
2125  _trecojetpy = -999;
2126  _trecojetpz = -999;
2127  _trecojetphi = -999;
2128  _trecojeteta = -999;
2129  _trecojetmass = -999;
2130  _trecojetp = -999;
2131  _trecojetenergy = -999;
2132  tjetdphi = -999;
2133  tjetpout = -999;
2134  tjetdeta = -999;
2135  _ttruthjetid = -999;
2136  _ttruthjetpt = -999;
2137  _ttruthjetpx = -999;
2138  _ttruthjetpy = -999;
2139  _ttruthjetpz = -999;
2140  _ttruthjetphi = -999;
2141  _ttruthjeteta = -999;
2142  _ttruthjetmass = -999;
2143  _ttruthjetp = -999;
2144  _ttruthjetenergy = -999;
2145 
2146  _tr_px = -999;
2147  _tr_py = -999;
2148  _tr_pz = -999;
2149  _tr_p = -999;
2150  _tr_pt = -999;
2151  _tr_phi = -999;
2152  _tr_eta = -999;
2153  _charge = -999;
2154  _chisq = -999;
2155  _ndf = -999;
2156  _dca = -999;
2157  _tr_x = -999;
2158  _tr_y = -999;
2159  _tr_z = -999;
2160  haddphi = -999;
2161  hadpout = -999;
2162  haddeta = -999;
2163  _truth_is_primary = false;
2164  _truthtrackpx = -999;
2165  _truthtrackpy = -999;
2166  _truthtrackpz = -999;
2167  _truthtrackp = -999;
2168  _truthtracke = -999;
2169  _truthtrackpt = -999;
2170  _truthtrackphi = -999;
2171  _truthtracketa = -999;
2172  _truthtrackpid = -999;
2173 
2174  truthpx = -999;
2175  truthpy = -999;
2176  truthpz = -999;
2177  truthp = -999;
2178  truthphi = -999;
2179  trutheta = -999;
2180  truthpt = -999;
2181  truthenergy = -999;
2182  truthpid = -999;
2183  numparticlesinevent = -999;
2184  process_id = -999;
2185 
2186  clustruthpx = -999;
2187  clustruthpy = -999;
2188  clustruthpz = -999;
2189  clustruthenergy = -999;
2190  clustruthpt = -999;
2191  clustruthphi = -999;
2192  clustrutheta = -999;
2193  clustruthpid = -999;
2194 
2195  beam_energy = 0;
2196  x1 = 0;
2197  x2 = 0;
2198  partid1 = 0;
2199  partid2 = 0;
2200 
2201  hardest_jetpt = 0;
2202  hardest_jetphi = 0;
2203  hardest_jeteta = 0;
2204  hardest_jetenergy = 0;
2205 }