EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QAExample.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file QAExample.cc
1 #include "QAExample.h"
2 
3 #include <qa_modules/QAHistManagerDef.h>
4 
5 #include <g4main/PHG4Particle.h>
7 
10 #include <fun4all/SubsysReco.h>
11 
12 #include <phool/getClass.h>
13 
14 #include <TH1.h>
15 #include <TH2.h>
16 
17 #include <array>
18 #include <cassert>
19 #include <cmath>
20 #include <iostream>
21 #include <map> // for map
22 #include <utility> // for pair
23 
24 using namespace std;
25 
26 QAExample::QAExample(const std::string &name)
27  : SubsysReco(name)
28 {
29 }
30 
32 {
34 }
35 
37 {
39  assert(hm);
40 
41  // reco pT / gen pT histogram
42  TH1 *h(nullptr);
43 
44  h = new TH1F(TString(get_histo_prefix()) + "pT",
45  "pT", 500, 0, 20);
46  hm->registerHisto(h);
47 
48  h = new TH2F(TString(get_histo_prefix()) + "pTpz",
49  "pT vs pz", 200, 0, 50, 500, 0, 20);
50  // QAHistManagerDef::useLogBins(h->GetXaxis());
51  hm->registerHisto(h);
52 
54 }
55 
57 {
58  if (Verbosity() > 2)
59  cout << "QAExample::process_event() entered" << endl;
60 
61  // load relevant nodes from NodeTree
62  load_nodes(topNode);
63 
64  // histogram manager
66  assert(hm);
67 
68  // reco pT / gen pT histogram
69  TH1 *pT = dynamic_cast<TH1 *>(hm->getHisto(get_histo_prefix() + "pT"));
70  assert(pT);
71 
72  // reco pT / gen pT histogram
73  TH2 *pTpz = dynamic_cast<TH2 *>(hm->getHisto(get_histo_prefix() + "pTpz"));
74  assert(pTpz);
75 
76  // fill histograms that need truth information
77  if (!m_truthContainer)
78  {
79  cout << "QAExample::process_event - fatal error - missing m_truthContainer! ";
81  }
82 
84  for (PHG4TruthInfoContainer::ConstIterator iter = range.first; iter != range.second; ++iter)
85  {
86  // get the truth particle information
87  PHG4Particle *g4particle = iter->second;
88 
89  if (Verbosity())
90  {
91  cout << "QAExample::process_event - processing ";
92  g4particle->identify();
93  }
94 
95  double gpx = g4particle->get_px();
96  double gpy = g4particle->get_py();
97  double pt = sqrt(gpx * gpx + gpy * gpy);
98  double gpz = g4particle->get_pz();
99  pT->Fill(pt);
100  pTpz->Fill(pt, gpz);
101  }
103 }
104 
106 {
107  m_truthContainer = findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");
108  if (!m_truthContainer)
109  {
110  cout << "QAExample::load_nodes - Fatal Error - "
111  << "unable to find DST node "
112  << "G4TruthInfo" << endl;
113  assert(m_truthContainer);
114  }
115 
117 }
118 
119 string
121 {
122  return string("h_") + Name() + string("_");
123 }