Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Pi0MassAnalysis.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Pi0MassAnalysis.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 Pi0MassAnalysis.h.
7 //
8 // Pi0MassAnalysis(const std::string &name = "Pi0MassAnalysis")
9 // everything is keyed to Pi0MassAnalysis, 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 // Pi0MassAnalysis::~Pi0MassAnalysis()
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 Pi0MassAnalysis::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 Pi0MassAnalysis::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 Pi0MassAnalysis::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 Pi0MassAnalysis::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 Pi0MassAnalysis::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 Pi0MassAnalysis::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 Pi0MassAnalysis::Reset(PHCompositeNode *topNode)
57 // not really used - it is called before the dtor is called
58 //
59 // void Pi0MassAnalysis::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 "Pi0MassAnalysis.h"
65 
66 #include <calobase/RawCluster.h>
67 #include <calobase/RawClusterContainer.h>
68 #include <calobase/RawClusterUtility.h>
69 
71 
74 
75 #include <phool/PHCompositeNode.h>
76 #include <phool/getClass.h>
77 
78 #include <boost/format.hpp>
79 
80 #include "TLorentzVector.h"
81 
82 //____________________________________________________________________________..
84  : SubsysReco(name)
85 {
86  std::cout << "Pi0MassAnalysis::Pi0MassAnalysis(const std::string &name) Calling ctor" << std::endl;
87  _foutname = name;
88 }
89 
90 //____________________________________________________________________________..
92 {
93  std::cout << "Pi0MassAnalysis::~Pi0MassAnalysis() Calling dtor" << std::endl;
94 }
95 
96 //____________________________________________________________________________..
98 {
99  std::cout << "Pi0MassAnalysis::Init(PHCompositeNode *topNode) Initializing" << std::endl;
100 
101  counter = 0;
102 
103  _f = new TFile(_foutname.c_str(), "RECREATE");
104 
105  _tree = new TTree("ttree", "");
106 
107  _tree->Branch("nclus", &nclus, "nclus/I");
108  _tree->Branch("cluster_energy", cluster_energy, "cluster_energy[nclus]/F");
109  _tree->Branch("cluster_eta", cluster_eta, "cluster_eta[nclus]/F");
110  _tree->Branch("cluster_phi", cluster_phi, "cluster_phi[nclus]/F");
111  _tree->Branch("cluster_prob", cluster_prob, "cluster_prob[nclus]/F");
112  _tree->Branch("cluster_chi2", cluster_chi2, "cluster_chi2[nclus]/F");
113 
114  _tree->Branch("npi0", &npi0, "npi0/I");
115  _tree->Branch("pi0cand_pt", pi0cand_pt, "pi0cand_pt[npi0]/F");
116  _tree->Branch("pi0cand_eta", pi0cand_eta, "pi0cand_eta[npi0]/F");
117  _tree->Branch("pi0cand_phi", pi0cand_phi, "pi0cand_phi[npi0]/F");
118  _tree->Branch("pi0cand_mass", pi0cand_mass, "pi0cand_mass[npi0]/F");
119 
120  pi0MassHist = new TH1F("pi0mass", ";m_{#gamma#gamma} [GeV];Entries", 50, 0.0, 0.3);
121 
122  for (int i = 0; i < 24; i++)
123  {
124  boost::format formatting("pi0mass %.1lf < eta < %.1lf");
125  std::string histName = (formatting % (-1.2 + i * 0.1) % (-1.1 + i * 0.1)).str();
126  pi0MassHistEtaDep[i] = new TH1F(histName.c_str(), ";m_{#gamma#gamma} [GeV];Entries", 50, 0.0, 0.3);
127  }
128 
130 }
131 
132 //____________________________________________________________________________..
134 {
135  std::cout << "Pi0MassAnalysis::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << std::endl;
137 }
138 
139 //____________________________________________________________________________..
141 {
142  nclus = 0;
143 
144  // Get Vertex
145  float vx = 0;
146  float vy = 0;
147  float vz = 0;
148  GlobalVertexMap *vertexmap = findNode::getClass<GlobalVertexMap>(topNode, "GlobalVertexMap");
149  if (vertexmap)
150  {
151  if (!vertexmap->empty())
152  {
153  GlobalVertex *vtx = (vertexmap->begin()->second);
154  vx = vtx->get_x();
155  vy = vtx->get_y();
156  vz = vtx->get_z();
157  }
158  }
159 
160  CLHEP::Hep3Vector vertex(vx, vy, vz);
161 
162  RawClusterContainer *clusterEM = findNode::getClass<RawClusterContainer>(topNode, "CLUSTER_CEMC");
163  if (clusterEM)
164  {
165  RawClusterContainer::Range begin_end = clusterEM->getClusters();
166  for (RawClusterContainer::Iterator iter = begin_end.first; iter != begin_end.second; ++iter)
167  {
168  RawCluster *clust = iter->second;
169 
170  if (clust->get_energy() > minClusterEnergy && clust->get_prob() > photonClusterProbability)
171  {
172  // CLHEP::Hep3Vector origin(0, 0, 0);
173  CLHEP::Hep3Vector cluster_vector = RawClusterUtility::GetECoreVec(*clust, vertex);
174 
175  cluster_energy[nclus] = clust->get_energy();
176  cluster_eta[nclus] = cluster_vector.pseudoRapidity();
177  cluster_phi[nclus] = clust->get_phi();
178  cluster_prob[nclus] = clust->get_prob();
179  cluster_chi2[nclus] = clust->get_chi2();
180 
181  nclus++;
182  }
183  }
184  }
185 
186  npi0 = 0;
187 
188  for (int i = 0; i < nclus; i++)
189  {
190  TLorentzVector v1;
191  v1.SetPtEtaPhiM(cluster_energy[i] / cosh(cluster_eta[i]), cluster_eta[i], cluster_phi[i], 0.0);
192  for (int j = i + 1; j < nclus; j++)
193  {
194  float alpha = fabs(cluster_energy[i] - cluster_energy[j]) / (cluster_energy[i] + cluster_energy[j]);
195 
196  if (alpha > 0.5)
197  continue;
198 
199  TLorentzVector v2;
200  v2.SetPtEtaPhiM(cluster_energy[j] / cosh(cluster_eta[j]), cluster_eta[j], cluster_phi[j], 0.0);
201 
202  if (v1.DeltaR(v2) > 0.8)
203  continue;
204 
205  TLorentzVector res;
206  res = v1 + v2;
207 
208  pi0cand_pt[npi0] = res.Pt();
209  pi0cand_eta[npi0] = res.Eta();
210  pi0cand_phi[npi0] = res.Phi();
211  pi0cand_mass[npi0] = res.M();
212  npi0++;
213 
214  pi0MassHist->Fill(res.M());
215 
216  int eta_index = floor((res.Eta() + 1.2) * 10);
217 
218  if (eta_index >= 0 && eta_index < 24)
219  {
220  pi0MassHistEtaDep[eta_index]->Fill(res.M());
221  }
222  }
223  }
224 
225  _tree->Fill();
226 
227  counter++;
228 
229  if (counter % 100 == 0)
230  std::cout << counter << " events are processed" << std::endl;
231 
233 }
234 
235 //____________________________________________________________________________..
237 {
239 }
240 
241 //____________________________________________________________________________..
243 {
244  std::cout << "Pi0MassAnalysis::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl;
246 }
247 
248 //____________________________________________________________________________..
250 {
251  std::cout << "Pi0MassAnalysis::End(PHCompositeNode *topNode) This is the End..." << std::endl;
252 
253  _f->Write();
254  _f->Close();
255 
257 }
258 
259 //____________________________________________________________________________..
261 {
262  std::cout << "Pi0MassAnalysis::Reset(PHCompositeNode *topNode) being Reset" << std::endl;
264 }
265 
266 //____________________________________________________________________________..
267 void Pi0MassAnalysis::Print(const std::string &what) const
268 {
269  std::cout << "Pi0MassAnalysis::Print(const std::string &what) const Printing info for " << what << std::endl;
270 }