Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
jetHistogrammer.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file jetHistogrammer.cc
1 //____________________________________________________________________________..
2 // This module is intended to look at truth level and pseudo jet level jets
3 // and measure the spectrum from min bias pythia. The output will be used
4 // to determine the point of 100% efficiency between two independent data sets
5 // e.g. the 10 and 30GeV triggered data sets
6 //____________________________________________________________________________..
7 
8 #include "jetHistogrammer.h"
9 
11 #include <fun4all/PHTFileServer.h>
12 
13 //fast jet stuff
14 #include <fastjet/ClusterSequence.hh>
15 #include <fastjet/JetDefinition.hh>
16 #include <fastjet/PseudoJet.hh>
17 
18 //jet stuff
19 #include <g4jets/JetMap.h>
20 
21 #include <algorithm>
22 #include <cmath>
23 #include <cstdlib>
24 #include <iostream>
25 #include <memory>
26 #include <utility>
27 #include <vector>
28 
29 #include <phool/PHCompositeNode.h>
30 #include <phool/getClass.h>
31 
32 
35 #pragma GCC diagnostic push
36 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
37 #include <HepMC/GenEvent.h>
38 #include <HepMC/GenParticle.h>
39 #include <HepMC/GenVertex.h>
40 #include <HepMC/IteratorRange.h>
41 #include <HepMC/SimpleVector.h>
42 #include <HepMC/GenParticle.h>
43 #pragma GCC diagnostic pop
44 
45 //____________________________________________________________________________..
47  SubsysReco(name),
48  m_outputFilename(fileout)
49 {
50  std::cout << "jetHistogrammer::jetHistogrammer(const std::string &name) Calling ctor" << std::endl;
51 }
52 
53 //____________________________________________________________________________..
55 {
56 
57  for(int i = 0; i < nEtaBins; i++)ptGJet[i] = 0;
58  ptPJet = 0;
59  std::cout << "jetHistogrammer::~jetHistogrammer() Calling dtor" << std::endl;
60 }
61 
62 //____________________________________________________________________________..
64 {
65 
66  std::cout << "jetHistogrammer::Init(PHCompositeNode *topNode) Initializing" << std::endl;
67 
68 
69  int nBins = 100;
70  Float_t bins[nBins+1];
71  for(int i = 0; i < nBins+1; i++) bins[i] = 80./nBins*i;
72 
73  for(int i = 0; i < nEtaBins; i++) ptGJet[i] = new TH1F(Form("geantJets_%dEta",i),"jets reco'd in GEANT world",nBins,bins);
74  //0.7,1.5,inclusive
75 
76  ptPJet = new TH1F("pythiaJets","jets reco'd in pythia world",nBins,bins);
77 
78 
79 
81 }
82 
83 //____________________________________________________________________________..
85 {
86  std::cout << "jetHistogrammer::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << std::endl;
88 }
89 
90 //____________________________________________________________________________..
92 {
93 
94  JetMap* jetsMC = findNode::getClass<JetMap>(topNode, "AntiKt_Truth_r04");
95  if(!jetsMC)
96  {
97  std::cout << "jetHistogrammer::process_event Cannot find truth node!" << std::endl;
98  exit(-1);
99  }
100 
101  PHHepMCGenEventMap *genEventMap = findNode::getClass<PHHepMCGenEventMap>(topNode, "PHHepMCGenEventMap");
102  if(!genEventMap)
103  {
104  std::cout << "jetHistogrammer::process_event Cannot find genEventMap!" << std::endl;
105  exit(-1);
106  }
107 
108  PHHepMCGenEvent *genEvent = genEventMap -> get(1);
109  if(!genEvent)
110  {
111  std::cout << "jetHistogrammer::process_event Cannot find genEvent!" << std::endl;
112  exit(-1);
113  }
114 
115  HepMC::GenEvent *theEvent = genEvent -> getEvent();
116 
117 
118  float maxJetPt = 0;
119  float maxEta = -1;
120  for(JetMap::Iter iter = jetsMC -> begin(); iter != jetsMC -> end(); ++iter)
121  {
122  Jet *truthjet = iter -> second;
123 
124  if(truthjet -> get_pt() > maxJetPt)
125  {
126  maxJetPt = truthjet -> get_pt();
127  maxEta = truthjet -> get_eta();
128  }
129  }
130 
131 
132  if(getEtaBin(maxEta) != -1)
133  {
134  ptGJet[3] -> Fill(maxJetPt);
135  for(int i = (int)getEtaBin(maxEta); i < nEtaBins - 1; i++) ptGJet[i] -> Fill(maxJetPt);
136  }
137  else
138  {
139  ptGJet[3] -> Fill(maxJetPt);
140  }
141 
142  std::vector<fastjet::PseudoJet> pseudojets;
143  unsigned int i = 0;
144  for(HepMC::GenEvent::particle_const_iterator p = theEvent -> particles_begin(); p != theEvent -> particles_end(); ++p)
145  {
146  if(!(*p) -> status()) continue; //only stable particles
147 
148  // remove some particles (muons, taus, neutrinos)...
149  // 12 == nu_e
150  // 13 == muons
151  // 14 == nu_mu
152  // 15 == taus
153  // 16 == nu_tau
154  if (abs((*p) -> pdg_id() >= 12) && abs((*p) -> pdg_id() <= 16)) continue;
155 
156  // remove acceptance... _etamin,_etamax
157  if (((*p) -> momentum().px() == 0.0) && ((*p) -> momentum().py() == 0.0)) continue; // avoid pt=0
158 
159  if (abs((*p) -> momentum().pseudoRapidity()) > 1.5) continue;
160 
161  fastjet::PseudoJet pseudojet((*p)->momentum().px(),
162  (*p)->momentum().py(),
163  (*p)->momentum().pz(),
164  (*p)->momentum().e());
165  pseudojet.set_user_index(i);
166  pseudojets.push_back(pseudojet);
167  i++;
168  }
169  //call fastjet
170  fastjet::JetDefinition *jetDef = new fastjet::JetDefinition(fastjet::antikt_algorithm, 0.4, fastjet::E_scheme, fastjet::Best);
171  fastjet::ClusterSequence jetFinder(pseudojets, *jetDef);
172  std::vector<fastjet::PseudoJet> fastjets = jetFinder.inclusive_jets();
173  delete jetDef;
174 
175  maxJetPt = 0;
176  for(unsigned int ijet = 0; ijet < fastjets.size(); ++ijet)
177  {
178  const double pt = sqrt(fastjets[ijet].px() * fastjets[ijet].px() + fastjets[ijet].py() * fastjets[ijet].py());
179  if(pt > maxJetPt) maxJetPt = pt;
180 
181  }
182  ptPJet -> Fill(maxJetPt);
183 
184 
186 }
187 
188 //____________________________________________________________________________..
190 {
192 }
193 
194 //____________________________________________________________________________..
196 {
197  std::cout << "jetHistogrammer::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl;
199 }
200 
201 //____________________________________________________________________________..
203 {
204 
205  std::cout << "jetHistogrammer opening output file: " << m_outputFilename << std::endl;
207  for(int i = 0; i < nEtaBins; i++)ptGJet[i] -> Write();
208  ptPJet -> Write();
209 
210  std::cout << "jetHistogrammer::End(PHCompositeNode *topNode) This is the End..." << std::endl;
212 }
213 
214 //____________________________________________________________________________..
216 {
217  std::cout << "jetHistogrammer::Reset(PHCompositeNode *topNode) being Reset" << std::endl;
219 }
220 
221 //____________________________________________________________________________..
222 void jetHistogrammer::Print(const std::string &what) const
223 {
224  std::cout << "jetHistogrammer::Print(const std::string &what) const Printing info for " << what << std::endl;
225 }
226 //____________________________________________________________________________..
228 {
229  int etaBin = -1;
230  for(int i = 0; i < nEtaBins-1; i++)
231  {
232  if(sqrt(pow(eta,2)) >= etaBins[i] && sqrt(pow(eta,2)) < etaBins[i+1]) etaBin = i;
233  }
234  return etaBin;
235 
236 }