Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TracksInJets.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TracksInJets.cc
1 
2 #include "TracksInJets.h"
3 
5 
6 #include <g4jets/JetMap.h>
7 
9 
11 #include <fun4all/PHTFileServer.h>
12 
13 #include <phool/PHCompositeNode.h>
14 #include <phool/getClass.h>
15 
16 #include <TFile.h>
17 #include <TH3F.h>
18 #include <TH2F.h>
19 #include <TString.h>
20 #include <TVector3.h>
21 
22 #include <cassert>
23 
24 //____________________________________________________________________________..
25 TracksInJets::TracksInJets(const std::string& recojetname, const std::string& outputfilename):
26  SubsysReco("TracksInJets_" + recojetname)
27  , m_recoJetName(recojetname)
28  , m_trk_pt_cut(2)
29  , m_jetRadius(0.4)
30  , m_outputFileName(outputfilename)
31 {
32  std::cout << "TracksInJets::TracksInJets(const std::string &name) Calling ctor" << std::endl;
33 }
34 
35 //____________________________________________________________________________..
37 {
38  std::cout << "TracksInJets::~TracksInJets() Calling dtor" << std::endl;
39 }
40 
41 //____________________________________________________________________________..
43 {
44  std::cout << "TracksInJets::Init(PHCompositeNode *topNode) Initializing" << std::endl;
46  m_h_track_vs_calo_pt = new TH3F("m_h_track_vs_calo_pt","",100,0,100,500,0,100,10,0,100);
47  m_h_track_vs_calo_pt->GetXaxis()->SetTitle("Jet p_{T} [GeV]");
48  m_h_track_vs_calo_pt->GetYaxis()->SetTitle("Sum track p_{T} [GeV]");
50 }
51 
52 //____________________________________________________________________________..
54 {
55  std::cout << "TracksInJets::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << std::endl;
57 }
58 
59 //____________________________________________________________________________..
61 {
62  //std::cout << "TracksInJets::process_event(PHCompositeNode *topNode) Processing Event" << std::endl;
63 
64  //get reco jets
65  JetMap* jets = findNode::getClass<JetMap>(topNode, m_recoJetName);
66  if (!jets)
67  {
68  std::cout
69  << "TracksInJets::process_event - Error can not find DST Reco JetMap node "
70  << m_recoJetName << std::endl;
71  exit(-1);
72  }
73 
74  //get reco tracks
75  SvtxTrackMap* trackmap = findNode::getClass<SvtxTrackMap>(topNode, "SvtxTrackMap");
76  if (!trackmap)
77  {
78  trackmap = findNode::getClass<SvtxTrackMap>(topNode, "TrackMap");
79  if (!trackmap)
80  {
81  std::cout
82  << "TracksInJets::process_event - Error can not find DST trackmap node SvtxTrackMap" << std::endl;
83  exit(-1);
84  }
85  }
86 
87  //get event centrality
88  CentralityInfo* cent_node = findNode::getClass<CentralityInfo>(topNode, "CentralityInfo");
89  if (!cent_node)
90  {
91  std::cout
92  << "TracksInJets::process_event - Error can not find centrality node "
93  << std::endl;
94  exit(-1);
95  }
96  int cent = cent_node->get_centile(CentralityInfo::PROP::mbd_NS);
97 
98  //loop through jets
99  for (JetMap::Iter iter = jets->begin(); iter != jets->end(); ++iter)
100  {
101  Jet* jet = iter->second;
102  assert(jet);
103 
104  //sum up tracks in jet
105  TVector3 sumtrk(0, 0, 0);
106  for (SvtxTrackMap::Iter iter = trackmap->begin();
107  iter != trackmap->end();
108  ++iter)
109  {
110  SvtxTrack* track = iter->second;
111  float quality = track->get_quality();
112  auto silicon_seed = track->get_silicon_seed();
113  int nmvtxhits = 0;
114  if (silicon_seed)
115  {
116  nmvtxhits = silicon_seed->size_cluster_keys();
117  }
118  if(track->get_pt() < m_trk_pt_cut || quality > 6 || nmvtxhits < 4) //do some basic quality selections on tracks
119  {
120  continue;
121  }
122  TVector3 v(track->get_px(), track->get_py(), track->get_pz());
123  double dEta = v.Eta() - jet->get_eta();
124  double dPhi = v.Phi() - jet->get_phi();
125  while(dPhi > M_PI) dPhi -= 2*M_PI;
126  while(dPhi < -M_PI) dPhi += 2*M_PI;
127  double dR = sqrt(dEta * dEta + dPhi * dPhi);
128 
129  if(dR < m_jetRadius)
130  {
131  sumtrk += v;
132  }
133  }
135  m_h_track_vs_calo_pt->Fill(jet->get_pt(), sumtrk.Perp(), cent);
136  }
137 
139 }
140 
141 //____________________________________________________________________________..
143 {
144  //std::cout << "TracksInJets::ResetEvent(PHCompositeNode *topNode) Resetting internal structures, prepare for next event" << std::endl;
146 }
147 
148 //____________________________________________________________________________..
150 {
151  std::cout << "TracksInJets::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl;
153 }
154 
155 //____________________________________________________________________________..
157 {
158  std::cout << "TracksInJets::End(PHCompositeNode *topNode) This is the End..." << std::endl;
160 
161  TH2 *h_proj;
162  for(int i = 0; i < m_h_track_vs_calo_pt->GetNbinsZ(); i++)
163  {
164  m_h_track_vs_calo_pt->GetZaxis()->SetRange(i+1,i+1);
165  h_proj = (TH2*) m_h_track_vs_calo_pt->Project3D("yx");
166  h_proj->Write(Form("h_track_vs_calo_%1.0f",m_h_track_vs_calo_pt->GetZaxis()->GetBinLowEdge(i+1)));
167  }
168 
170 }
171 
172 //____________________________________________________________________________..
174 {
175  std::cout << "TracksInJets::Reset(PHCompositeNode *topNode) being Reset" << std::endl;
177 }
178 
179 //____________________________________________________________________________..
180 void TracksInJets::Print(const std::string &what) const
181 {
182  std::cout << "TracksInJets::Print(const std::string &what) const Printing info for " << what << std::endl;
183 }