Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SEnergyCorrelator.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SEnergyCorrelator.h
1 // ----------------------------------------------------------------------------
2 // 'SEnergyCorrelator.h'
3 // Derek Anderson
4 // 01.20.2023
5 //
6 // A module to implement Peter Komiske's EEC library
7 // in the sPHENIX software stack for the Cold QCD
8 // Energy-Energy Correlator analysis.
9 // ----------------------------------------------------------------------------
10 
11 #ifndef SENERGYCORRELATOR_H
12 #define SENERGYCORRELATOR_H
13 
14 // standard c includes
15 #include <cmath>
16 #include <string>
17 #include <vector>
18 #include <cassert>
19 #include <sstream>
20 #include <cstdlib>
21 #include <utility>
22 // root includes
23 #include <TH1.h>
24 #include <TH2.h>
25 #include <TROOT.h>
26 #include <TFile.h>
27 #include <TMath.h>
28 #include <TChain.h>
29 #include <TString.h>
30 #include <TDirectory.h>
31 #include <Math/Vector4D.h>
32 // f4a include
33 #include <fun4all/SubsysReco.h>
36 // phool includes
37 #include <phool/phool.h>
38 #include <phool/getClass.h>
39 #include <phool/PHIODataNode.h>
40 #include <phool/PHNodeIterator.h>
41 #include <phool/PHCompositeNode.h>
42 // fastjet includes
43 #include <fastjet/PseudoJet.hh>
44 // eec include
45 #include "/sphenix/user/danderson/eec/EnergyEnergyCorrelators/eec/include/EECLongestSide.hh"
46 
47 using namespace std;
48 using namespace fastjet;
49 
50 
51 
52 namespace SColdQcdCorrelatorAnalysis {
53 
54  // SEnergyCorrelator definition ---------------------------------------------
55 
56  class SEnergyCorrelator : public SubsysReco {
57 
58  public:
59 
60  // ctor/dtor
61  SEnergyCorrelator(const string &name = "SEnergyCorrelator", const bool isComplex = false, const bool doDebug = false, const bool inBatch = false);
62  ~SEnergyCorrelator() override;
63 
64  // F4A methods
65  int Init(PHCompositeNode*) override;
66  int process_event(PHCompositeNode*) override;
67  int End(PHCompositeNode*) override;
68 
69  // standalone-only methods
70  void Init();
71  void Analyze();
72  void End();
73 
74  // setters (inline)
75  void SetVerbosity(const int verb) {m_verbosity = verb;}
76  void SetInputNode(const string &iNodeName) {m_inNodeName = iNodeName;}
77  void SetOutputFile(const string &oFileName) {m_outFileName = oFileName;}
78  void SetDoSecondCstLoop(const bool loop) {m_doSecondCstLoop = loop;}
79  void SetInputFiles(const vector<string> &vecInFileNames) {m_inFileNames = vecInFileNames;}
80 
81  // setters (*.io.h)
82  void SetInputTree(const string &iTreeName, const bool isTruthTree = false, const bool isEmbedTree = false);
83  void SetJetParameters(const vector<pair<double, double>> &pTjetBins, const pair<double, double> etaJetRange);
84  void SetConstituentParameters(const pair<double, double> momCstRange, const pair<double, double> drCstRange, const bool applyCstCuts = false);
85  void SetCorrelatorParameters(const uint32_t nPointCorr, const uint64_t nBinsDr, const pair<double, double> drBinRange);
86  void SetSubEventsToUse(const uint16_t subEvtOpt = 0, const vector<int> vecSubEvtsToUse = {});
87 
88  // system getters
89  int GetVerbosity() {return m_verbosity;}
90  bool GetInDebugMode() {return m_inDebugMode;}
91  bool GetInBatchMode() {return m_inBatchMode;}
92  bool GetInComplexMode() {return m_inComplexMode;}
93  bool GetInStandaloneMode() {return m_inStandaloneMode;}
94  bool GetIsInputTreeTruth() {return m_isInputTreeTruth;}
95  bool GetIsInputTreeEmbed() {return m_isInputTreeEmbed;}
96  bool GetApplyCstCuts() {return m_applyCstCuts;}
97  bool GetSelectSubEvts() {return m_selectSubEvts;}
98  bool GetDoSecondCstLoop() {return m_doSecondCstLoop;}
99  string GetModuleName() {return m_moduleName;}
100  string GetInputNodeName() {return m_inNodeName;}
101  string GetInputTreeName() {return m_inTreeName;}
102  string GetOutputFileName() {return m_outFileName;}
103  uint16_t GetSubEvtOpt() {return m_subEvtOpt;}
104  vector<string> GetInputFileNames() {return m_inFileNames;}
105 
106  // correlator getters
107  double GetMinDrBin() {return m_drBinRange.first;}
108  double GetMaxDrBin() {return m_drBinRange.second;}
109  double GetMinJetPt() {return m_ptJetRange.first;}
110  double GetMaxJetPt() {return m_ptJetRange.second;}
111  double GetMinJetEta() {return m_etaJetRange.first;}
112  double GetMaxJetEta() {return m_etaJetRange.second;}
113  double GetMinCstMom() {return m_momCstRange.first;}
114  double GetMaxCstMom() {return m_momCstRange.second;}
115  double GetMinCstDr() {return m_drCstRange.first;}
116  double GetMaxCstDr() {return m_drCstRange.second;}
117  size_t GetNBinsJetPt() {return m_nBinsJetPt;}
118  uint32_t GetNPointCorr() {return m_nPointCorr;}
119  uint64_t GetNBinsDr() {return m_nBinsDr;}
120 
121  private:
122 
123  // constants
124  enum CONST {
125  NPARTONS = 2
126  };
127 
128  // io methods (*.io.h)
129  void GrabInputNode();
130  void OpenInputFiles();
131  void OpenOutputFile();
132  void SaveOutput();
133  void CloseOutputFile();
134 
135  // system methods (*.sys.h)
136  void InitializeMembers();
137  void InitializeHists();
138  void InitializeCorrs();
139  void InitializeTree();
140  void PrintMessage(const uint32_t code, const uint64_t nEvts = 0, const uint64_t event = 0);
141  void PrintDebug(const uint32_t code);
142  void PrintError(const uint32_t code, const size_t nDrBinEdges = 0, const size_t iDrBin = 0, const string sInFileName = "");
143  bool CheckCriticalParameters();
144  int64_t LoadTree(const uint64_t entry);
145  int64_t GetEntry(const uint64_t entry);
146 
147  // analysis methods (*.ana.h)
148  void DoCorrelatorCalculation();
149  void ExtractHistsFromCorr();
150  bool ApplyJetCuts(const double ptJet, const double etaJet);
151  bool ApplyCstCuts(const double momCst, const double drCst);
152  bool CheckIfSubEvtGood(const int embedID);
153  uint32_t GetJetPtBin(const double ptJet);
154 
155  // io members
156  TFile* m_outFile = NULL;
157  TFile* m_inFile = NULL;
158  TChain* m_inChain = NULL;
159 
160  // output histograms
161  vector<TH1D*> m_outHistVarDrAxis;
162  vector<TH1D*> m_outHistErrDrAxis;
163  vector<TH1D*> m_outHistVarLnDrAxis;
164  vector<TH1D*> m_outHistErrLnDrAxis;
165 
166  // for weird cst check
181 
182  // system members
183  int m_fCurrent = 0;
184  int m_verbosity = 0;
185  bool m_inDebugMode = false;
186  bool m_inBatchMode = false;
187  bool m_inComplexMode = false;
188  bool m_inStandaloneMode = false;
189  bool m_isInputTreeTruth = false;
190  bool m_isInputTreeEmbed = false;
191  bool m_applyCstCuts = false;
192  bool m_selectSubEvts = false;
193  bool m_doSecondCstLoop = false;
194  string m_moduleName = "";
195  string m_inNodeName = "";
196  string m_inTreeName = "";
197  string m_outFileName = "";
198  uint16_t m_subEvtOpt = 0;
199 
200  // vector of input files (standalone mode only)
201  vector<string> m_inFileNames;
202 
203  // jet, cst, correlator parameters
204  uint32_t m_nPointCorr = 0;
205  uint64_t m_nBinsDr = 0;
206  size_t m_nBinsJetPt = 0;
207  pair<double, double> m_drBinRange = {-999., -999.};
208  pair<double, double> m_ptJetRange = {-999., -999.};
209  pair<double, double> m_etaJetRange = {-999., -999.};
210  pair<double, double> m_momCstRange = {-999., -999.};
211  pair<double, double> m_drCstRange = {-999., -999.};
212  vector<pair<double, double>> m_ptJetBins;
213  vector<PseudoJet> m_jetCstVector;
214  vector<int> m_subEvtsToUse;
215 
216  // correlators
217  vector<contrib::eec::EECLongestSide<contrib::eec::hist::axis::log>*> m_eecLongSide;
218 
219  // input truth tree address members
220  int m_evtNumChrgPars = -999;
221  int m_partonID[CONST::NPARTONS] = {-999, -999};
222  double m_partonMomX[CONST::NPARTONS] = {-999., -999.};
223  double m_partonMomY[CONST::NPARTONS] = {-999., -999.};
224  double m_partonMomZ[CONST::NPARTONS] = {-999., -999.};
225  double m_evtSumPar = -999.;
226  vector<vector<int>>* m_cstID = NULL;
227  vector<vector<int>>* m_cstEmbedID = NULL;
228  // input reco. tree address members
229  int m_evtNumTrks = -999;
230  double m_evtSumECal = -999.;
231  double m_evtSumHCal = -999.;
232  vector<vector<int>>* m_cstMatchID = NULL;
233 
234  // generic input tree address members
235  int m_evtNumJets = -999;
236  double m_evtVtxX = -999.;
237  double m_evtVtxY = -999.;
238  double m_evtVtxZ = -999.;
239  vector<unsigned long>* m_jetNumCst = NULL;
240  vector<unsigned int>* m_jetID = NULL;
241  vector<unsigned int>* m_jetTruthID = NULL;
242  vector<double>* m_jetEnergy = NULL;
243  vector<double>* m_jetPt = NULL;
244  vector<double>* m_jetEta = NULL;
245  vector<double>* m_jetPhi = NULL;
246  vector<double>* m_jetArea = NULL;
247  vector<vector<double>>* m_cstZ = NULL;
248  vector<vector<double>>* m_cstDr = NULL;
249  vector<vector<double>>* m_cstEnergy = NULL;
250  vector<vector<double>>* m_cstPt = NULL;
251  vector<vector<double>>* m_cstEta = NULL;
252  vector<vector<double>>* m_cstPhi = NULL;
253 
254  // input truth tree branch members
255  TBranch* m_brPartonID[CONST::NPARTONS] = {NULL, NULL};
256  TBranch* m_brPartonMomX[CONST::NPARTONS] = {NULL, NULL};
257  TBranch* m_brPartonMomY[CONST::NPARTONS] = {NULL, NULL};
258  TBranch* m_brPartonMomZ[CONST::NPARTONS] = {NULL, NULL};
259  TBranch* m_brEvtSumPar = NULL;
260  TBranch* m_brCstID = NULL;
261  TBranch* m_brCstEmbedID = NULL;
262  // input reco. tree branch members
263  TBranch* m_brEvtNumTrks = NULL;
264  TBranch* m_brEvtSumECal = NULL;
265  TBranch* m_brEvtSumHCal = NULL;
266  TBranch* m_brCstMatchID = NULL;
267 
268  // generic input tree branch members
269  TBranch* m_brEvtNumJets = NULL;
270  TBranch* m_brEvtVtxX = NULL;
271  TBranch* m_brEvtVtxY = NULL;
272  TBranch* m_brEvtVtxZ = NULL;
273  TBranch* m_brJetNumCst = NULL;
274  TBranch* m_brJetID = NULL;
275  TBranch* m_brJetEnergy = NULL;
276  TBranch* m_brJetPt = NULL;
277  TBranch* m_brJetEta = NULL;
278  TBranch* m_brJetPhi = NULL;
279  TBranch* m_brJetArea = NULL;
280  TBranch* m_brCstZ = NULL;
281  TBranch* m_brCstDr = NULL;
282  TBranch* m_brCstPt = NULL;
283  TBranch* m_brCstEnergy = NULL;
284  TBranch* m_brCstEta = NULL;
285  TBranch* m_brCstPhi = NULL;
286 
287  };
288 
289 } // end SColdQcdCorrelatorAnalysis namespace
290 
291 #endif
292 
293 // end ------------------------------------------------------------------------