Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
analysis.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file analysis.cc
1 #include "analysis.h"
2 #include <fun4all/SubsysReco.h> // for SubsysReco
3 
5 #include <TFile.h>
6 #include <TH1F.h>
8 
10 #include <g4jets/JetMap.h>
11 #include <fun4all/Fun4AllServer.h>
12 #include <fun4all/PHTFileServer.h>
13 #include <g4main/PHG4VtxPoint.h>
14 #include <TTree.h>
15 #include <phool/PHCompositeNode.h>
16 
17 #include <phool/PHCompositeNode.h>
18 #include <phool/PHIODataNode.h> // for PHIODataNode
19 #include <phool/PHNode.h> // for PHNode
20 #include <phool/PHNodeIterator.h> // for PHNodeIterator
21 #include <phool/PHObject.h> // for PHObject
22 #include <phool/getClass.h>
23 
24 #include <iostream>
25 #include <sstream>
26 #include <string>
27 #include <phool/phool.h> // for PHWHERE
28 
29 #include <g4main/PHG4Particle.h>
31 
32 //____________________________________________________________________________..
34  SubsysReco(name)
35 {
36  std::cout << "analysis::analysis(const std::string &name) Calling ctor" << std::endl;
37 }
38 
39 //____________________________________________________________________________..
41 {
42  std::cout << "analysis::~analysis() Calling dtor" << std::endl;
43 }
44 //____________________________________________________________________________..
45 
47 {
48  //-------------------------------------------------------------
49  //print the list of nodes available in memory
50  //-------------------------------------------------------------
51  topNode->print();
53 }
54 
56 {
58  Fun4AllHistoManager *hm = se->getHistoManager("analysis_HISTOS");
59 
60  if (not hm)
61  {
62  std:: cout
63  << "analysis::get_HistoManager - Making Fun4AllHistoManager analysis_HISTOS"
64  << std::endl;
65  hm = new Fun4AllHistoManager("analysis_HISTOS");
66  se->registerHistoManager(hm);
67  }
68  assert(hm);
69  return hm;
70 }
71 
72 //____________________________________________________________________________..
74 {
75  std::cout << "analysis::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << std::endl;
76 
77  //-------------------------------
78  //Create the output file
79  //-------------------------------
80  PHTFileServer::get().open(m_outfilename.c_str(), "RECREATE");
81 
82 
84  assert(hm);
85 
86  //------------------------------------------------------------------------------------------------
87  // create the output tree where jets will be stored and register it to
88  // the histogram manager
89  //------------------------------------------------------------------------------------------------
90 
91  TTree* tree= new TTree("tree","tree");
92  tree->Print();
93  tree->Branch("tjet_pt",&m_tjet_pt);
94  tree->Branch("tjet_phi",&m_tjet_phi);
95  tree->Branch("tjet_eta",&m_tjet_eta);
96  tree->Branch("rjet_pt",&m_rjet_pt);
97  tree->Branch("rjet_phi",&m_rjet_phi);
98  tree->Branch("rjet_eta",&m_rjet_eta);
99 
100  hm->registerHisto(tree);
101 
103 }
104 
105 //____________________________________________________________________________..
107 {
108  double pi = TMath::Pi();
109 
110  //-----------------------------------------------------------------------------------------------------------------
111  // load in the containers which hold the truth and reconstructed jet information
112  //-----------------------------------------------------------------------------------------------------------------
113 
114  JetMap* tjets = findNode::getClass<JetMap>(topNode, "AntiKt_Truth_r04");
115  if (!tjets)
116  {
117  std::cout
118  << "MyJetAnalysis::process_event - Error can not find DST JetMap node "
119  << std::endl;
120  exit(-1);
121  }
122 
123 
124  JetMap* rjets = findNode::getClass<JetMap>(topNode, "AntiKt_Tower_r04");
125  if (!rjets)
126  {
127  std::cout
128  << "MyJetAnalysis::process_event - Error can not find DST JetMap node "
129  << std::endl;
130  exit(-1);
131  }
132 
133  //-------------------------------------------------------------
134  //Call the histogram manager in order to
135  //pull the tree into the perview of the event
136  //-------------------------------------------------------------
137 
139  assert(hm);
140  //---------------------------------------------------
141  // loop over all truth jets in the event
142  //---------------------------------------------------
143  for (JetMap::Iter iter = tjets->begin(); iter != tjets->end(); ++iter)
144  {
145  Jet* tjet = iter->second;
146  assert(tjet);
147  float tjet_phi = tjet->get_phi();
148  float tjet_eta = tjet->get_eta();
149  float tjet_pt = tjet->get_pt();
150  float drmin = 0.3;
151  float matched_pt = -999;
152  float matched_eta = -999;
153  float matched_phi = -999;
154  //---------------------------------------------------------------------------------------------------
155  //loop over reconstructed jets and match each truth jet to the closest
156  //reconstructed jet
157  //----------------------------------------------------------------------------------------------------
158  for (JetMap::Iter riter = rjets->begin(); riter != rjets->end(); ++riter)
159  {
160  Jet* rjet = riter->second;
161  float rjet_phi = rjet->get_phi();
162  float rjet_eta = rjet->get_eta();
163  float rjet_pt = rjet->get_pt();
164 
165  float deta = fabs(rjet_eta - tjet_eta);
166  float dphi = fabs(rjet_phi - tjet_phi);
167  if (dphi > pi)
168  {
169  dphi = 2*pi-dphi;
170  }
171 
172  float dr = TMath::Sqrt(dphi*dphi + deta*deta);
173  if (dr < drmin)//truth-reco jet matching
174  {
175  matched_pt = rjet_pt;
176  matched_eta = rjet_eta;
177  matched_phi = rjet_phi;
178  drmin = dr;
179  }
180  }
181  //-------------------------------------------------------------------------
182  //append the truth and matched reconstructed jet
183  // to the end of the corresponding vectors
184  //-------------------------------------------------------------------------
185  if (tjet_pt > 0)
186  {
187  m_tjet_pt.push_back(tjet_pt);
188  m_tjet_phi.push_back(tjet_phi);
189  m_tjet_eta.push_back(tjet_eta);
190  m_rjet_pt.push_back(matched_pt);
191  m_rjet_phi.push_back(matched_phi);
192  m_rjet_eta.push_back(matched_eta);
193  m_dr.push_back(drmin);
194 
195 
196 
197  }
198  }
199 
200  //----------------------------------------------------------
201  //Record the vectors of jet kinematic info
202  //to the ttree.
203  //----------------------------------------------------------
204 
205  TTree *tree = dynamic_cast<TTree *>(hm->getHisto("tree"));
206  assert(tree);
207  tree->Fill();
208 
209 
211 }
212 
213 //____________________________________________________________________________..
215 {
216  //-----------------------------------------------------
217  //Clear every vector inbetween events
218  // this is CRITICAL!! Otherwise you will
219  // have runaway behaviors
220  //------------------------------------------------------
221  m_tjet_pt.clear();
222  m_tjet_phi.clear();
223  m_tjet_eta.clear();
224 
225  m_rjet_pt.clear();
226  m_rjet_phi.clear();
227  m_rjet_eta.clear();
228  m_dr.clear();
230 }
231 
232 //____________________________________________________________________________..
234 {
235  std::cout << "analysis::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl;
237 }
238 
239 //____________________________________________________________________________..
241 {
242  std::cout << "analysis::End(PHCompositeNode *topNode) This is the End..." << std::endl;
243  //----------------------------------------------------------------------
244  //Enter the created output file and write the ttree
245  //----------------------------------------------------------------------
246 
248 
250  assert(hm);
251 
252  for (unsigned int i = 0; i < hm->nHistos(); i++)
253  hm->getHisto(i)->Write();
254 
255 
257 }
258 
259 //____________________________________________________________________________..
261 {
262  std::cout << "analysis::Reset(PHCompositeNode *topNode) being Reset" << std::endl;
264 }
265 
266 //____________________________________________________________________________..
267 void analysis::Print(const std::string &what) const
268 {
269  std::cout << "analysis::Print(const std::string &what) const Printing info for " << what << std::endl;
270 }