Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TreeMakerCopyAndMakeJets.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TreeMakerCopyAndMakeJets.C
1 #include <TreeMaker.h>
2 
3 #include <phool/getClass.h>
5 
6 // --- calorimeter towers
7 #include <calobase/RawTower.h>
8 #include <calobase/RawTowerContainer.h>
9 #include <calobase/RawTowerGeom.h>
10 #include <calobase/RawTowerGeomContainer.h>
11 
12 // --- jet specific stuff
13 #include <g4jets/Jet.h>
14 #include <g4jets/JetMap.h>
15 #include <g4jets/JetV1.h>
16 #include <g4jets/JetMapV1.h>
17 
18 using std::cout;
19 using std::endl;
20 
21 
22 
24 {
25 
26  // -----------------------------------------------------------------------------------------------------
27  // ---
28  // -----------------------------------------------------------------------------------------------------
29 
30  // --- calorimeter tower containers
31  RawTowerContainer* towersEM3 = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_CEMC");
32  RawTowerContainer* towersIH3 = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_HCALIN");
33  RawTowerContainer* towersOH3 = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_HCALOUT");
34 
35  // --- calorimeter geometry objects
36  RawTowerGeomContainer* geomEM = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_CEMC");
37  RawTowerGeomContainer* geomIH = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALIN");
38  RawTowerGeomContainer* geomOH = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALOUT");
39 
40  // --- jet objects
41  JetMap* old_jets = findNode::getClass<JetMap>(topNode,"AntiKt_Tower_r02");
42  JetMap* new_jets = findNode::getClass<JetMap>(topNode,"AntiKt_Tower_Mod_r02"); // this node is created in createnode
43  if ( verbosity > 0 )
44  {
45  cout << "Regular jet node: " << old_jets << endl;
46  cout << "Modified jet node: " << new_jets << endl;
47  }
48  if ( !old_jets || ! new_jets )
49  {
50  cout << "One or more invalid pointers, exiting event" << endl;
51  return 0;
52  }
53 
54  // --- print sizes of old and new objects for diagnostic purposes
55  if ( verbosity > 0 )
56  {
57  cout << "process_event: entering with # original jets = " << old_jets->size() << endl;
58  cout << "process_event: entering with # new jets = " << new_jets->size() << endl;
59  }
60 
61  // --- iterate over jets
62  int ijet = 0;
63  for ( JetMap::Iter iter = old_jets->begin(); iter != old_jets->end(); ++iter )
64  {
65  // --- get information from this jet (an element of the jet container)
66  Jet* this_jet = iter->second;
67  float this_e = this_jet->get_e();
68  float this_pt = this_jet->get_pt();
69  float this_phi = this_jet->get_phi();
70  float this_eta = this_jet->get_eta();
71  // --- create a new jet object
72  Jet *new_jet = new JetV1();
73  float new_total_px = 0;
74  float new_total_py = 0;
75  float new_total_pz = 0;
76  float new_total_e = 0;
77  if ( verbosity > 3 && this_pt > 5 )
78  {
79  cout << "process_event: unsubtracted jet with e / pt / eta / phi = "
80  << this_e << " / " << this_pt << " / " << this_eta << " / " << this_phi << endl;
81  }
82  // --- now loop over individual constituents of this jet
83  for ( Jet::ConstIter comp = this_jet->begin_comp(); comp != this_jet->end_comp(); ++comp )
84  {
85  // --- (*.comp).first is the layer:
86  // --- 0 = void
87  // --- 1 = particle
88  // --- 2 = track
89  // --- 3 = emcal tower
90  // --- 4 = emcal cluster
91  // --- 5 = ihcal tower
92  // --- 6 = ihcal cluster
93  // --- 7 = ohcal tower
94  // --- 8 = ohcal cluster
95  // --- 9 = femc tower
96  // --- 10 = femc cluster
97  // --- 11 = fhcal tower
98  // --- 12 = fhcal cluster
99  // --- 13 = emcal retower (combined towers to match ihcal geometry)
100  // --- 14 = subtracted emcal tower
101  // --- 15 = subtracted ihcal tower
102  // --- 16 = subtracted ohcal tower
103  RawTower *tower = 0;
104  RawTowerGeom *tower_geom = 0;
105  double comp_e = 0;
106  double comp_eta = 0;
107  double comp_phi = 0;
108  int comp_ieta = 0;
109  int comp_iphi = 0;
110  //double comp_background = 0;
111  // --- layer 5 is inner hcal towers
112  if ( (*comp).first == 5 )
113  {
114  tower = towersIH3->getTower( (*comp).second );
115  tower_geom = geomIH->get_tower_geometry(tower->get_key());
116  comp_ieta = geomIH->get_etabin( tower_geom->get_eta() );
117  comp_iphi = geomIH->get_phibin( tower_geom->get_phi() );
118  }
119  // --- layer 7 is outer hcal towers
120  else if ( (*comp).first == 7 )
121  {
122  tower = towersOH3->getTower( (*comp).second );
123  tower_geom = geomOH->get_tower_geometry(tower->get_key());
124  comp_ieta = geomOH->get_etabin( tower_geom->get_eta() );
125  comp_iphi = geomOH->get_phibin( tower_geom->get_phi() );
126  }
127  // --- layer 3 is EMCal towers
128  // --- layer 13 is re-towered emcal, which uses IHCal geom... not using for now
129  else if ( (*comp).first == 3 )
130  {
131  tower = towersEM3->getTower( (*comp).second );
132  tower_geom = geomEM->get_tower_geometry(tower->get_key());
133  comp_ieta = geomEM->get_etabin( tower_geom->get_eta() );
134  comp_iphi = geomEM->get_phibin( tower_geom->get_phi() );
135  }
136 
137  // --- if tower and tower_geom exist, get energy from there
138  if ( tower && tower_geom )
139  {
140  comp_e = tower->get_energy();
141  comp_eta = tower_geom->get_eta();
142  comp_phi = tower_geom->get_phi();
143  }
144 
145  // --- if very high verbosity, print lots of stuff to screen
146  if ( verbosity > 4 && this_jet->get_pt() > 5 )
147  {
148  cout << "process_event: --> constituent in layer " << (*comp).first
149  << ", has unsub E = " << comp_e << ", is at ieta #" << comp_ieta
150  << " and iphi # = " << comp_iphi << endl;
151  }
152 
153  // --- update constituent energy based on some algorithm to be developed
154  double comp_new_e = comp_e;
155 
156  // --- define new kinematics for constituent
157  double comp_px = comp_new_e / cosh( comp_eta ) * cos( comp_phi );
158  double comp_py = comp_new_e / cosh( comp_eta ) * sin( comp_phi );
159  double comp_pz = comp_new_e * tanh( comp_eta );
160 
161  // --- add up the total for the new jet based on the modified constituents
162  new_total_px += comp_px;
163  new_total_py += comp_py;
164  new_total_pz += comp_pz;
165  new_total_e += comp_new_e;
166  } // end of loop over jet constituents
167 
168  // --- set the properties for the new jet
169  new_jet->set_px( new_total_px );
170  new_jet->set_py( new_total_py );
171  new_jet->set_pz( new_total_pz );
172  new_jet->set_e( new_total_e );
173  new_jet->set_id(ijet);
174 
175  // --- put the jet into a new container class
176  new_jets->insert( new_jet );
177 
178  if (verbosity > 1 && this_pt > 5)
179  {
180  cout << "process_event: old jet #" << ijet << ", old px / py / pz / e = "
181  << this_jet->get_px() << " / " << this_jet->get_py() << " / "
182  << this_jet->get_pz() << " / " << this_jet->get_e() << endl;
183  cout << "process_event: new jet #" << ijet << ", new px / py / pz / e = "
184  << new_jet->get_px() << " / " << new_jet->get_py() << " / "
185  << new_jet->get_pz() << " / " << new_jet->get_e() << endl;
186  }
187 
188  ijet++; // increment jet counter
189 
190  } // end of loop over jet maps (list of jets)
191 
192  if ( verbosity > 0 )
193  {
194  cout << "process_event: exiting with # original jets = " << old_jets->size() << endl;
195  cout << "process_event: exiting with # new jets = " << new_jets->size() << endl;
196  }
197 
198  return 0;
199 
200 }