Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JetUnderlyingEvent.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file JetUnderlyingEvent.cc
1 //____________________________________________________________________________..
2 //
3 // This is a template for a Fun4All SubsysReco module with all methods from the
4 // $OFFLINE_MAIN/include/fun4all/SubsysReco.h baseclass
5 // You do not have to implement all of them, you can just remove unused methods
6 // here and in JetUnderlyingEvent.h.
7 //
8 // JetUnderlyingEvent(const std::string &name = "JetUnderlyingEvent")
9 // everything is keyed to JetUnderlyingEvent, duplicate names do work but it makes
10 // e.g. finding culprits in logs difficult or getting a pointer to the module
11 // from the command line
12 //
13 // JetUnderlyingEvent::~JetUnderlyingEvent()
14 // this is called when the Fun4AllServer is deleted at the end of running. Be
15 // mindful what you delete - you do loose ownership of object you put on the node tree
16 //
17 // int JetUnderlyingEvent::Init(PHCompositeNode *topNode)
18 // This method is called when the module is registered with the Fun4AllServer. You
19 // can create historgrams here or put objects on the node tree but be aware that
20 // modules which haven't been registered yet did not put antyhing on the node tree
21 //
22 // int JetUnderlyingEvent::InitRun(PHCompositeNode *topNode)
23 // This method is called when the first event is read (or generated). At
24 // this point the run number is known (which is mainly interesting for raw data
25 // processing). Also all objects are on the node tree in case your module's action
26 // depends on what else is around. Last chance to put nodes under the DST Node
27 // We mix events during readback if branches are added after the first event
28 //
29 // int JetUnderlyingEvent::process_event(PHCompositeNode *topNode)
30 // called for every event. Return codes trigger actions, you find them in
31 // $OFFLINE_MAIN/include/fun4all/Fun4AllReturnCodes.h
32 // everything is good:
33 // return Fun4AllReturnCodes::EVENT_OK
34 // abort event reconstruction, clear everything and process next event:
35 // return Fun4AllReturnCodes::ABORT_EVENT;
36 // proceed but do not save this event in output (needs output manager setting):
37 // return Fun4AllReturnCodes::DISCARD_EVENT;
38 // abort processing:
39 // return Fun4AllReturnCodes::ABORT_RUN
40 // all other integers will lead to an error and abort of processing
41 //
42 // int JetUnderlyingEvent::ResetEvent(PHCompositeNode *topNode)
43 // If you have internal data structures (arrays, stl containers) which needs clearing
44 // after each event, this is the place to do that. The nodes under the DST node are cleared
45 // by the framework
46 //
47 // int JetUnderlyingEvent::EndRun(const int runnumber)
48 // This method is called at the end of a run when an event from a new run is
49 // encountered. Useful when analyzing multiple runs (raw data). Also called at
50 // the end of processing (before the End() method)
51 //
52 // int JetUnderlyingEvent::End(PHCompositeNode *topNode)
53 // This is called at the end of processing. It needs to be called by the macro
54 // by Fun4AllServer::End(), so do not forget this in your macro
55 //
56 // int JetUnderlyingEvent::Reset(PHCompositeNode *topNode)
57 // not really used - it is called before the dtor is called
58 //
59 // void JetUnderlyingEvent::Print(const std::string &what) const
60 // Called from the command line - useful to print information when you need it
61 //
62 //____________________________________________________________________________..
63 
64 #include "JetUnderlyingEvent.h"
65 
66 #include <TH3.h>
68 
69 #include <phool/PHCompositeNode.h>
70 
72 #include <fun4all/PHTFileServer.h>
73 
74 #include <phool/PHCompositeNode.h>
75 #include <phool/getClass.h>
76 
77 #include <g4jets/JetMap.h>
78 #include <g4jets/Jetv1.h>
79 
81 #include <TFile.h>
82 #include <TH3F.h>
83 #include <TH2.h>
84 #include <TH2F.h>
85 #include <TString.h>
86 
87 #include <calobase/RawTower.h>
88 #include <calobase/RawTowerContainer.h>
89 #include <calobase/RawTowerGeom.h>
90 #include <calobase/RawTowerGeomContainer.h>
91 
93 
94 
95 
96 
97 //____________________________________________________________________________..
99  SubsysReco(name)
100  , m_outputFileName(outputfilename)
101 {
102  std::cout << "JetUnderlyingEvent::JetUnderlyingEvent(const std::string &name) Calling ctor" << std::endl;
103 }
104 
105 //____________________________________________________________________________..
107 {
108  std::cout << "JetUnderlyingEvent::~JetUnderlyingEvent() Calling dtor" << std::endl;
109 }
110 
111 //____________________________________________________________________________..
113 {
114  std::cout << "JetUnderlyingEvent::Init(PHCompositeNode *topNode) Initializing" << std::endl;
116  std::cout << "JetUnderlyingEvent::Init - Output to " << m_outputFileName << std::endl;
117 
118  // Histograms
119 
120  hsubtractedE = new TH3F("HsubtractedE", "", 100, 0.0, 100, 100, 0, 100, 10, 0, 100);
121  hsubtractedE->GetXaxis()->SetTitle("E_{T} [GeV]");
122  hsubtractedE->GetYaxis()->SetTitle("Subtracted E_{T} [GeV]");
123  hsubtractedE->GetZaxis()->SetTitle("Centrality");
125 }
126 
127 //____________________________________________________________________________..
129 {
130  std::cout << "JetUnderlyingEvent::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << std::endl;
132 }
133 
134 //____________________________________________________________________________..
136 {
137  // interface to reco jets
138  JetMap* jets = findNode::getClass<JetMap>(topNode, "AntiKt_Tower_r04_Sub1");
139  if (!jets){
140  std::cout
141  << "MyJetAnalysis::process_event - Error can not find DST Reco JetMap node "
142  << std::endl;
143  exit(-1);
144  }
145 
146 
147  //calorimeter towers
148  RawTowerContainer *towersEM3 = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_CEMC_RETOWER");
149  RawTowerContainer *towersIH3 = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_HCALIN");
150  RawTowerContainer *towersOH3 = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_HCALOUT");
151  RawTowerGeomContainer *tower_geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALIN");
152  RawTowerGeomContainer *tower_geomOH = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALOUT");
153  if(!towersEM3 || !towersIH3 || !towersOH3){
154  std::cout
155  <<"MyJetAnalysis::process_event - Error can not find raw tower node "
156  << std::endl;
157  exit(-1);
158  }
159 
160  if(!tower_geom || !tower_geomOH){
161  std::cout
162  <<"MyJetAnalysis::process_event - Error can not find raw tower geometry "
163  << std::endl;
164  exit(-1);
165  }
166 
167  //centrality
168 
169  CentralityInfo* cent_node = findNode::getClass<CentralityInfo>(topNode, "CentralityInfo");
170  if (!cent_node)
171  {
172  std::cout
173  << "MyJetAnalysis::process_event - Error can not find centrality node "
174  << std::endl;
175  exit(-1);
176  }
177 
178  int m_centrality = cent_node->get_centile(CentralityInfo::PROP::mbd_NS);
179 
180  //underlying event
181  TowerBackground *background = findNode::getClass<TowerBackground>(topNode, "TowerBackground_Sub2");
182  if(!background){
183  std::cout<<"Can't get background. Exiting"<<std::endl;
185  }
186 
187 
188  //get reco jets
189  float background_v2 = 0;
190  float background_Psi2 = 0;
191 
192  {
193  background_v2 = background->get_v2();
194  background_Psi2 = background->get_Psi2();
195  }
196  for (JetMap::Iter iter = jets->begin(); iter != jets->end(); ++iter)
197  {
198 
199  Jet* jet = iter->second;
200 
201 
202 
203  Jet* unsubjet = new Jetv1();
204  float totalPx = 0;
205  float totalPy = 0;
206  float totalPz = 0;
207  float totalE = 0;
208  int nconst = 0;
209 
210  for (Jet::ConstIter comp = jet->begin_comp(); comp != jet->end_comp(); ++comp)
211  {
212  RawTower *tower;
213  nconst++;
214 
215  if ((*comp).first == 15)
216  {
217  tower = towersIH3->getTower((*comp).second);
218  if(!tower || !tower_geom){
219  continue;
220  }
221  float UE = background->get_UE(1).at(tower->get_bineta());
222  float tower_phi = tower_geom->get_tower_geometry(tower->get_key())->get_phi();
223  float tower_eta = tower_geom->get_tower_geometry(tower->get_key())->get_eta();
224  UE = UE * (1 + 2 * background_v2 * cos(2 * (tower_phi - background_Psi2)));
225  totalE += tower->get_energy() + UE;
226  double pt = tower->get_energy() / cosh(tower_eta);
227  totalPx += pt * cos(tower_phi);
228  totalPy += pt * sin(tower_phi);
229  totalPz += pt * sinh(tower_eta);
230  }
231  else if ((*comp).first == 16)
232  {
233  tower = towersOH3->getTower((*comp).second);
234  if(!tower || !tower_geomOH)
235  {
236  continue;
237  }
238 
239  float UE = background->get_UE(2).at(tower->get_bineta());
240  float tower_phi = tower_geomOH->get_tower_geometry(tower->get_key())->get_phi();
241  float tower_eta = tower_geomOH->get_tower_geometry(tower->get_key())->get_eta();
242  UE = UE * (1 + 2 * background_v2 * cos(2 * (tower_phi - background_Psi2)));
243  totalE +=tower->get_energy() + UE;
244  double pt = tower->get_energy() / cosh(tower_eta);
245  totalPx += pt * cos(tower_phi);
246  totalPy += pt * sin(tower_phi);
247  totalPz += pt * sinh(tower_eta);
248  }
249  else if ((*comp).first == 14)
250  {
251  tower = towersEM3->getTower((*comp).second);
252  if(!tower || !tower_geom)
253  {
254  continue;
255  }
256  float UE = background->get_UE(0).at(tower->get_bineta());
257  float tower_phi = tower_geom->get_tower_geometry(tower->get_key())->get_phi();
258  float tower_eta = tower_geom->get_tower_geometry(tower->get_key())->get_eta();
259  UE = UE * (1 + 2 * background_v2 * cos(2 * (tower_phi - background_Psi2)));
260  totalE +=tower->get_energy() + UE;
261  double pt = tower->get_energy() / cosh(tower_eta);
262  totalPx += pt * cos(tower_phi);
263  totalPy += pt * sin(tower_phi);
264  totalPz += pt * sinh(tower_eta);
265  }
266  }
267 
268  //get unsubtracted jet
269  unsubjet->set_px(totalPx);
270  unsubjet->set_py(totalPy);
271  unsubjet->set_pz(totalPz);
272  unsubjet->set_e(totalE);
273 
274  // fill histograms
276  hsubtractedE->Fill(jet->get_pt(),unsubjet->get_pt() - jet->get_pt(),m_centrality);
277 
278 
279  }
280 
281 
282 
283 
285 }
286 
287 //____________________________________________________________________________..
289  {
291  }
292 
293 //____________________________________________________________________________..
295  {
296  std::cout << "JetUnderlyingEvent::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl;
298  }
299 
300 //____________________________________________________________________________..
302 {
303  std::cout << "JetValidation::End - Output to " << m_outputFileName << std::endl;
305 
306  TH2 *Centrality;
307  for(int i = 0; i < hsubtractedE ->GetNbinsZ(); i++)
308  {
309  hsubtractedE -> GetZaxis()->SetRange(i+1,i+1);
310  Centrality = (TH2*) hsubtractedE -> Project3D("yx");
311  Centrality -> Write(Form("hsubtractedE%1.0f",hsubtractedE->GetZaxis()->GetBinLowEdge(i+1)));
312  }
313 
315 }
316 
317 //____________________________________________________________________________..
319  {
320  std::cout << "JetUnderlyingEvent::Reset(PHCompositeNode *topNode) being Reset" << std::endl;
322  }
323 
324 //____________________________________________________________________________..
325  void JetUnderlyingEvent::Print(const std::string &what) const
326  {
327  std::cout << "JetUnderlyingEvent::Print(const std::string &what) const Printing info for " << what << std::endl;
328  }