Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HFTriggerMVA.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HFTriggerMVA.h
1 #ifndef HFTRIGGERMVA_H
2 #define HFTRIGGERMVA_H
3 
4 //sPHENIX stuff
6 #include <fun4all/SubsysReco.h>
7 #include <phool/getClass.h>
8 #include <trackbase/TrkrDefs.h>
9 #include <trackbase/TrkrHitSet.h>
13 #include <trackbase_historic/SvtxVertex.h>
14 #include <trackbase_historic/SvtxVertexMap.h>
15 
16 #include <g4eval/SvtxEvalStack.h>
17 #include <g4eval/SvtxTrackEval.h>
18 
19 //ROOT stuff
20 #include <TMVA/Reader.h>
21 #include <TMVA/Tools.h>
22 
23 #include <Eigen/Core>
24 #include <Eigen/Dense>
25 
26 #include <algorithm>
27 #include <cfloat>
28 #include <cmath>
29 #include <iostream>
30 #include <map>
31 #include <numeric>
32 #include <string>
33 
34 typedef Eigen::Matrix<float, 6, 1> Track;
35 typedef Eigen::Matrix<float, 3, 1> Vertex;
36 typedef Eigen::Matrix<float, 3, 1> TrackX;
37 typedef Eigen::Matrix<float, 3, 1> TrackP;
38 typedef Eigen::Matrix<float, 3, 1> DCA;
39 
40 class SvtxTrack;
41 class SvtxTrackMap;
42 class SvtxVertexMap;
43 class SvtxVertex;
44 
45 class HFTriggerMVA : public SubsysReco
46 {
47  public:
48  HFTriggerMVA();
49 
50  explicit HFTriggerMVA(const std::string &name);
51 
52  virtual ~HFTriggerMVA(){}
53 
54  int Init(PHCompositeNode *topNode);
55 
56  int process_event(PHCompositeNode *topNode);
57 
58  int End(PHCompositeNode *topNode);
59 
60  bool runTrigger(PHCompositeNode *topNode);
61 
62  bool runCutsTrigger(float mean_hits, float emcal_energy, float IP, float IP_xy, float DCA);
63 
64  bool runMVATrigger(TMVA::Reader* reader, std::string method, std::vector<float> inputValues, float cut);
65 
66  void calculateMultiplicity(PHCompositeNode *topNode, float& meanMultiplicity, float& asymmetryMultiplicity);
67 
68  float getMaxEMCalEnergy(PHCompositeNode *topNode);
69 
70  void getIPVariables(Track track1, Track track2, Vertex vertex, float& minIP, float& minIP_xy, float& maxIP, float& maxIP_xy, float& DCA);
71 
73 
74  std::vector<Vertex> makeAllPrimaryVertices(PHCompositeNode *topNode);
75 
77 
78  std::vector<Track> makeAllTracks(PHCompositeNode *topNode);
79 
80  int decomposeTrack(Track track, TrackX& trackPosition, TrackP& trackMomentum);
81 
83 
85 
86  float calcualteTrackTrackDCA(Track trackOne, Track trackTwo);
87 
88  std::tuple<TMVA::Reader*, std::vector<Float_t>> initMVA(std::vector<std::string> variableList, std::string method, std::string mvaFile);
89 
90  void printRunRecord();
91 
92  void printTrigger();
93 
94  //User configuration
95  void requireCutsTrigger(bool useTrigger) { m_useCutsTrigger = useTrigger; }
96  void requireMVAwCaloTrigger(bool useTrigger) { m_useMVAwCaloTrigger = useTrigger; }
97 
98  void setMeanMult(float value) { meanMult = value; }
99  void setAsymmMult(float value) { asymmMult = value; }
107 
108  protected:
111 
112  private:
113 
114  float meanMult = 12;
115  float asymmMult = 0.1;
116  float trackVertex3DDCA = 0.05;
117  float trackVertex2DDCA = 0.05;
118  float trackTrackDCA = 0.05;
119  float minEMCalEnergy = 0.5;
120  float MVA_wCaloResponse = -0.05;
121  float MVA_woutCaloResponse = -0.05;
123 
124  bool m_useCutsTrigger = false;
125  bool m_useCutswoutTrigger = false;
126  bool m_useMVAwCaloTrigger = false;
129 
133  SvtxTrack *m_dst_track = nullptr;
134 
135  //Counters
136  int m_events = 0;
137  int m_no_trigger = 0;
138  int m_counter = 0;
151 
152  //MVA stuff
153  std::string path = "/sphenix/u/cdean/software/analysis/HF-Particle/HFTrigger/weights/";
154 
156 
157  std::vector<std::string> varListwCalo = {"min(track_1_IP,track_2_IP)",
158  "min(abs(track_1_IP_xy),abs(track_2_IP_xy))",
159  "max(track_1_IP,track_2_IP)",
160  "max(abs(track_1_IP_xy),abs(track_2_IP_xy))",
161  "max(track_1_EMCAL_energy_cluster,track_2_EMCAL_energy_cluster)",
162  "track_1_track_2_DCA",
163  "INTT_meanHits"};
164 
165  std::vector<std::string> varListwoutCalo = {"min(track_1_IP,track_2_IP)",
166  "min(abs(track_1_IP_xy),abs(track_2_IP_xy))",
167  "max(track_1_IP,track_2_IP)",
168  "max(abs(track_1_IP_xy),abs(track_2_IP_xy))",
169  "track_1_track_2_DCA",
170  "INTT_meanHits"};
171 
172  std::vector<std::string> varListwoutCaloAndMinTrack = {"max(track_1_IP,track_2_IP)",
173  "max(abs(track_1_IP_xy),abs(track_2_IP_xy))",
174  "track_1_track_2_DCA",
175  "INTT_meanHits"};
176 
179 };
180 
181 #endif //HFTRIGGERMVA_H