Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CopyAndSubtractJets.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CopyAndSubtractJets.cc
1 #include "CopyAndSubtractJets.h"
2 
3 #include "TowerBackground.h"
4 
5 #include <calobase/RawTower.h>
6 #include <calobase/RawTowerContainer.h>
7 #include <calobase/RawTowerGeom.h>
8 #include <calobase/RawTowerGeomContainer.h>
9 
10 #include <calobase/TowerInfo.h>
11 #include <calobase/TowerInfoContainer.h>
12 
13 
14 #include <jetbase/Jet.h>
15 #include <jetbase/JetContainer.h>
16 #include <jetbase/JetContainerv1.h>
17 #include <jetbase/Jetv2.h>
18 
20 #include <fun4all/SubsysReco.h>
21 
22 #include <phool/PHCompositeNode.h>
23 #include <phool/PHIODataNode.h>
24 #include <phool/PHNode.h>
25 #include <phool/PHNodeIterator.h>
26 #include <phool/PHObject.h>
27 #include <phool/getClass.h>
28 #include <phool/phool.h>
29 
30 // standard includes
31 #include <cmath>
32 #include <iostream>
33 #include <map>
34 #include <vector>
35 #include <utility>
36 
38  : SubsysReco(name)
39  , _use_flow_modulation(false)
40 {
41 }
42 
44 {
45  CreateNode(topNode);
46 
48 }
49 
51 {
52  if (Verbosity() > 0)
53  std::cout << "CopyAndSubtractJets::process_event: entering, with _use_flow_modulation = " << _use_flow_modulation << std::endl;
54 
55  // pull out needed calo tower info
56  RawTowerContainer *towersEM3 = nullptr;
57  RawTowerContainer *towersIH3 = nullptr;
58  RawTowerContainer *towersOH3 = nullptr;
59  TowerInfoContainer *towerinfosEM3 = nullptr;
60  TowerInfoContainer *towerinfosIH3 = nullptr;
61  TowerInfoContainer *towerinfosOH3 = nullptr;
62  if (m_use_towerinfo)
63  {
64  towerinfosEM3 = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_CEMC_RETOWER");
65  towerinfosIH3 = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_HCALIN");
66  towerinfosOH3 = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_HCALOUT");
67  }
68  else
69  {
70  towersEM3 = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_CEMC_RETOWER");
71  towersIH3 = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_HCALIN");
72  towersOH3 = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_HCALOUT");
73  }
74 
75 
76  RawTowerGeomContainer *geomIH = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALIN");
77  RawTowerGeomContainer *geomOH = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALOUT");
78 
79  // pull out jets and background
80  JetContainer *unsub_jets;
81  JetContainer *sub_jets;
82  TowerBackground *background;
83  if (m_use_towerinfo)
84  {
85  unsub_jets = findNode::getClass<JetContainer>(topNode, "AntiKt_TowerInfo_HIRecoSeedsRaw_r02");
86  sub_jets = findNode::getClass<JetContainer>(topNode, "AntiKt_TowerInfo_HIRecoSeedsSub_r02");
87  background = findNode::getClass<TowerBackground>(topNode, "TowerInfoBackground_Sub1");
88  }
89  else
90  {
91  unsub_jets = findNode::getClass<JetContainer>(topNode, "AntiKt_Tower_HIRecoSeedsRaw_r02");
92  sub_jets = findNode::getClass<JetContainer>(topNode, "AntiKt_Tower_HIRecoSeedsSub_r02");
93  background = findNode::getClass<TowerBackground>(topNode, "TowerBackground_Sub1");
94  }
95  std::vector<float> background_UE_0 = background->get_UE(0);
96  std::vector<float> background_UE_1 = background->get_UE(1);
97  std::vector<float> background_UE_2 = background->get_UE(2);
98 
99  float background_v2 = background->get_v2();
100  float background_Psi2 = background->get_Psi2();
101 
102  if (Verbosity() > 0)
103  {
104  std::cout << "CopyAndSubtractJets::process_event: entering with # unsubtracted jets = " << unsub_jets->size() << std::endl;
105  std::cout << "CopyAndSubtractJets::process_event: entering with # subtracted jets = " << sub_jets->size() << std::endl;
106  }
107 
108  // iterate over old jets
109  int ijet = 0;
110  for (auto this_jet : *unsub_jets)
111  {
112  float this_pt = this_jet->get_pt();
113  float this_phi = this_jet->get_phi();
114  float this_eta = this_jet->get_eta();
115 
116  float new_total_px = 0;
117  float new_total_py = 0;
118  float new_total_pz = 0;
119  float new_total_e = 0;
120 
121  //if (this_jet->get_pt() < 5) continue;
122 
123  if (Verbosity() > 1 && this_jet->get_pt() > 5)
124  std::cout << "CopyAndSubtractJets::process_event: unsubtracted jet with pt / eta / phi = " << this_pt << " / " << this_eta << " / " << this_phi << std::endl;
125 
126  for (const auto& comp : this_jet->get_comp_vec())
127  {
128  RawTower *tower = 0;
129  RawTowerGeom *tower_geom = 0;
130  TowerInfo* towerinfo = 0;
131 
132  double comp_e = 0;
133  double comp_eta = 0;
134  double comp_phi = 0;
135 
136  int comp_ieta = 0;
137 
138  double comp_background = 0;
139 
140  if (m_use_towerinfo)
141  {
142  if (comp.first == 5|| comp.first == 26)
143  {
144  towerinfo = towerinfosIH3->get_tower_at_channel(comp.second);
145  unsigned int towerkey = towerinfosIH3->encode_key(comp.second);
146  comp_ieta = towerinfosIH3->getTowerEtaBin(towerkey);
147  int comp_iphi = towerinfosIH3->getTowerPhiBin(towerkey);
149 
150  tower_geom = geomIH->get_tower_geometry(key);
151  comp_background = background_UE_1.at(comp_ieta);
152  }
153  else if (comp.first == 7 || comp.first == 27)
154  {
155  towerinfo = towerinfosOH3->get_tower_at_channel(comp.second);
156  unsigned int towerkey = towerinfosOH3->encode_key(comp.second);
157  comp_ieta = towerinfosOH3->getTowerEtaBin(towerkey);
158  int comp_iphi = towerinfosOH3->getTowerPhiBin(towerkey);
160  tower_geom = geomOH->get_tower_geometry(key);
161  comp_background = background_UE_2.at(comp_ieta);
162  }
163  else if (comp.first == 13 || comp.first == 28)
164  {
165  towerinfo = towerinfosEM3->get_tower_at_channel(comp.second);
166  unsigned int towerkey = towerinfosEM3->encode_key(comp.second);
167  comp_ieta = towerinfosEM3->getTowerEtaBin(towerkey);
168  int comp_iphi = towerinfosEM3->getTowerPhiBin(towerkey);
170 
171  tower_geom = geomIH->get_tower_geometry(key);
172  comp_background = background_UE_0.at(comp_ieta);
173  }
174  if (towerinfo)
175  {
176  comp_e = towerinfo->get_energy();
177  }
178  }
179  else
180  {
181  if (comp.first == 5)
182  {
183  tower = towersIH3->getTower(comp.second);
184  tower_geom = geomIH->get_tower_geometry(tower->get_key());
185 
186  comp_ieta = geomIH->get_etabin(tower_geom->get_eta());
187  comp_background = background_UE_1.at(comp_ieta);
188  }
189  else if (comp.first == 7)
190  {
191  tower = towersOH3->getTower(comp.second);
192  tower_geom = geomOH->get_tower_geometry(tower->get_key());
193 
194  comp_ieta = geomOH->get_etabin(tower_geom->get_eta());
195  comp_background = background_UE_2.at(comp_ieta);
196  }
197  else if (comp.first == 13)
198  {
199  tower = towersEM3->getTower(comp.second);
200  tower_geom = geomIH->get_tower_geometry(tower->get_key());
201 
202  comp_ieta = geomIH->get_etabin(tower_geom->get_eta());
203  comp_background = background_UE_0.at(comp_ieta);
204  }
205  if (tower)
206  {
207  comp_e = tower->get_energy();
208  }
209  }
210 
211  if (tower_geom)
212  {
213  comp_eta = tower_geom->get_eta();
214  comp_phi = tower_geom->get_phi();
215  }
216 
217  if (Verbosity() > 4 && this_jet->get_pt() > 5)
218  {
219  std::cout << "CopyAndSubtractJets::process_event: --> constituent in layer " << comp.first << ", has unsub E = " << comp_e << ", is at ieta #" << comp_ieta << ", and has UE = " << comp_background << std::endl;
220  }
221 
222  // flow modulate background if turned on
224  {
225  comp_background = comp_background * (1 + 2 * background_v2 * cos(2 * (comp_phi - background_Psi2)));
226  if (Verbosity() > 4 && this_jet->get_pt() > 5)
227  std::cout << "CopyAndSubtractJets::process_event: --> --> flow mod, at phi = " << comp_phi << ", v2 and Psi2 are = " << background_v2 << " , " << background_Psi2 << ", UE after modulation = " << comp_background << std::endl;
228  }
229 
230  // update constituent energy based on the background
231  double comp_sub_e = comp_e - comp_background;
232 
233  // now define new kinematics
234 
235  double comp_px = comp_sub_e / cosh(comp_eta) * cos(comp_phi);
236  double comp_py = comp_sub_e / cosh(comp_eta) * sin(comp_phi);
237  double comp_pz = comp_sub_e * tanh(comp_eta);
238 
239  new_total_px += comp_px;
240  new_total_py += comp_py;
241  new_total_pz += comp_pz;
242  new_total_e += comp_sub_e;
243  }
244 
245  auto new_jet = sub_jets->add_jet(); // returns a new Jet_v2
246 
247 
248  new_jet->set_px(new_total_px);
249  new_jet->set_py(new_total_py);
250  new_jet->set_pz(new_total_pz);
251  new_jet->set_e(new_total_e);
252  new_jet->set_id(ijet);
253 
254  if (Verbosity() > 1 && this_pt > 5)
255  {
256  std::cout << "CopyAndSubtractJets::process_event: old jet #" << ijet << ", old px / py / pz / e = " << this_jet->get_px() << " / " << this_jet->get_py() << " / " << this_jet->get_pz() << " / " << this_jet->get_e() << std::endl;
257  std::cout << "CopyAndSubtractJets::process_event: new jet #" << ijet << ", new px / py / pz / e = " << new_jet->get_px() << " / " << new_jet->get_py() << " / " << new_jet->get_pz() << " / " << new_jet->get_e() << std::endl;
258  }
259 
260  ijet++;
261  }
262 
263 
264 
265 
266 
267  if (Verbosity() > 0)
268  {
269  std::cout << "CopyAndSubtractJets::process_event: exiting with # subtracted jets = " << sub_jets->size() << std::endl;
270  }
271 
273 }
274 
276 {
278 }
279 
281 {
282  PHNodeIterator iter(topNode);
283 
284  // Looking for the DST node
285  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
286  if (!dstNode)
287  {
288  std::cout << PHWHERE << "DST Node missing, doing nothing." << std::endl;
290  }
291 
292  // Looking for the ANTIKT node
293  PHCompositeNode *antiktNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "ANTIKT"));
294  if (!antiktNode)
295  {
296  std::cout << PHWHERE << "ANTIKT node not found, doing nothing." << std::endl;
297  }
298 
299  // Looking for the TOWER node
300  PHCompositeNode *towerNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "TOWER"));
301  if (!towerNode)
302  {
303  std::cout << PHWHERE << "TOWER node not found, doing nothing." << std::endl;
304  }
305 
306  // store the new jet collection
307  JetContainer *test_jets ;
308  if (m_use_towerinfo)
309  {
310  test_jets = findNode::getClass<JetContainer>(topNode, "AntiKt_TowerInfo_HIRecoSeedsSub_r02");
311  }
312  else
313  {
314  test_jets = findNode::getClass<JetContainer>(topNode, "AntiKt_Tower_HIRecoSeedsSub_r02");
315  }
316  if (!test_jets)
317  {
318  JetContainer *sub_jets = new JetContainerv1();
319  PHIODataNode<PHObject> *subjetNode ;
320  if (m_use_towerinfo)
321  {
322  if (Verbosity() > 0) std::cout << "CopyAndSubtractJets::CreateNode : creating AntiKt_TowerInfo_HIRecoSeedsSub_r02 node " << std::endl;
323  subjetNode = new PHIODataNode<PHObject>(sub_jets, "AntiKt_TowerInfo_HIRecoSeedsSub_r02", "PHObject");
324 
325  }
326  else
327  {
328  if (Verbosity() > 0) std::cout << "CopyAndSubtractJets::CreateNode : creating AntiKt_Tower_HIRecoSeedsSub_r02 node " << std::endl;
329  subjetNode = new PHIODataNode<PHObject>(sub_jets, "AntiKt_Tower_HIRecoSeedsSub_r02", "PHObject");
330  }
331  towerNode->addNode(subjetNode);
332  }
333  else
334  {
335  std::cout << "CopyAndSubtractJets::CreateNode : AntiKt_Tower_HIRecoSeedsSub_r02 already exists! " << std::endl;
336  }
337 
339 }