Class Reference for E1039 Core & Analysis Software
AnaModule.cxx
Go to the documentation of this file.
1 #include <iomanip>
2 #include <TFile.h>
3 #include <TTree.h>
4 
6 #include <phool/getClass.h>
10 
11 
12 #include "AnaModule.h"
13 
14 AnaModule::AnaModule(const std::string& name): SubsysReco(name), legacyContainer(true)
15 {}
16 
18 {
19  delete pos1;
20  delete pos2;
21  delete pos3;
22  delete posvtx;
23  delete mom1;
24  delete mom2;
25  delete mom3;
26  delete momvtx;
27  delete rec_mom1;
28  delete rec_momvtx;
29  delete rec_posvtx;
30  delete rec_momtgt;
31  delete rec_postgt;
32 
33  delete pmom;
34  delete nmom;
35  delete rec_pmom;
36  delete rec_nmom;
37  delete rec_ppos;
38  delete rec_npos;
39  delete rec_vtx;
40  delete vtx;
41 }
42 
43 int AnaModule::Init(PHCompositeNode* topNode)
44 {
45  pos1 = new TVector3();
46  pos2 = new TVector3();
47  pos3 = new TVector3();
48  posvtx = new TVector3();
49  mom1 = new TVector3();
50  mom2 = new TVector3();
51  mom3 = new TVector3();
52  momvtx = new TVector3();
53  rec_mom1 = new TVector3();
54  rec_momvtx = new TVector3();
55  rec_posvtx = new TVector3();
56  rec_momtgt = new TVector3();
57  rec_postgt = new TVector3();
58 
59  vtx = new TVector3();
60  pmom = new TVector3();
61  nmom = new TVector3();
62  rec_pmom = new TVector3();
63  rec_nmom = new TVector3();
64  rec_ppos = new TVector3();
65  rec_npos = new TVector3();
66  rec_vtx = new TVector3();
67 
69 }
70 
72 {
73  int ret = GetNodes(topNode);
74  if(ret != Fun4AllReturnCodes::EVENT_OK) return ret;
75 
76  eventID = 0;
77  MakeTree();
79 }
80 
82 {
83  int nTracks = trackVector->size();
84  int nRecTracks = legacyContainer ? recEvent->getNTracks() : recTrackVector->size();
85  for(int i = 0; i < nTracks; ++i)
86  {
87  SQTrack* track = trackVector->at(i);
88  charge = track->get_charge();
89  *pos1 = track->get_pos_st1();
90  *mom1 = track->get_mom_st1().Vect();
91  *pos3 = track->get_pos_st3();
92  *mom3 = track->get_mom_st3().Vect();
93  *posvtx = track->get_pos_vtx();
94  *momvtx = track->get_mom_vtx().Vect();
95 
96  int recid = track->get_rec_track_id();
97  if(recid >= 0 && recid < nRecTracks)
98  {
99  SRecTrack* recTrack = legacyContainer ? &(recEvent->getTrack(recid)) : dynamic_cast<SRecTrack*>(recTrackVector->at(recid));
100  *rec_mom1 = recTrack->getMomentumVecSt1();
101  *rec_momvtx = recTrack->getVertexMom();
102  *rec_posvtx = recTrack->getVertexPos();
103  *rec_momtgt = recTrack->getTargetMom();
104  *rec_postgt = recTrack->getTargetPos();
105  }
106  else
107  {
108  rec_mom1->SetXYZ(-999., -999., -999.);
109  rec_momvtx->SetXYZ(999., -999., -999.);
110  rec_posvtx->SetXYZ(999., -999., -999.);
111  }
112 
113  saveTree1->Fill();
114  }
115 
116  int nDimuons = dimuonVector->size();
117  int nRecDimuons = legacyContainer ? recEvent->getNDimuons() : (recDimuonVector ? recDimuonVector->size() : -1);
118  for(int i = 0; i < nDimuons; ++i)
119  {
120  SQDimuon* dimuon = dimuonVector->at(i);
121  mass = dimuon->get_mom().M();
122  *vtx = dimuon->get_pos();
123  *pmom = dimuon->get_mom_pos().Vect();
124  *nmom = dimuon->get_mom_neg().Vect();
125 
126  int recid = dimuon->get_rec_dimuon_id();
127  if(recid >= 0 && recid < nRecDimuons)
128  {
129  SRecDimuon* recDimuon = legacyContainer ? &(recEvent->getDimuon(recid)) : dynamic_cast<SRecDimuon*>(recDimuonVector->at(recid));
130  rec_mass = recDimuon->mass;
131  *rec_pmom = recDimuon->p_pos.Vect();
132  *rec_nmom = recDimuon->p_neg.Vect();
133  *rec_ppos = recDimuon->vtx_pos;
134  *rec_npos = recDimuon->vtx_neg;
135  *rec_vtx = recDimuon->vtx;
136  }
137  else
138  {
139  rec_mass = -100.;
140  }
141 
142  saveTree2->Fill();
143  }
144 
145  ++eventID;
147 }
148 
149 int AnaModule::End(PHCompositeNode* topNode)
150 {
151  saveFile->cd();
152  saveTree1->Write();
153  saveTree2->Write();
154  saveFile->Close();
155 
157 }
158 
159 int AnaModule::GetNodes(PHCompositeNode* topNode)
160 {
161  hitVector = findNode::getClass<SQHitVector>(topNode, "SQHitVector");
162  trackVector = findNode::getClass<SQTrackVector>(topNode, "SQTruthTrackVector");
163  dimuonVector = findNode::getClass<SQDimuonVector>(topNode, "SQTruthDimuonVector");
164  if(!hitVector || !trackVector || !dimuonVector)
165  {
167  }
168 
169  if(legacyContainer)
170  {
171  recEvent = findNode::getClass<SRecEvent>(topNode, "SRecEvent");
172  if(!recEvent)
173  {
174  recEvent = nullptr;
176  }
177  }
178  else
179  {
180  recTrackVector = findNode::getClass<SQTrackVector>(topNode, "SQRecTrackVector");
181  recDimuonVector = findNode::getClass<SQDimuonVector>(topNode, "SQRecDimuonVector");
182  if(!recTrackVector)
183  {
185  }
186  }
187 
189 }
190 
191 void AnaModule::MakeTree()
192 {
193  saveFile = new TFile(saveName, "RECREATE");
194 
195  saveTree1 = new TTree("trk", "Track Tree Created by AnaModule");
196  saveTree1->Branch("eventID", &eventID, "eventID/I");
197  saveTree1->Branch("charge", &charge, "charge/I");
198  saveTree1->Branch("pos1", &pos1, 256000, 99);
199  saveTree1->Branch("pos2", &pos2, 256000, 99);
200  saveTree1->Branch("pos3", &pos3, 256000, 99);
201  saveTree1->Branch("posvtx", &posvtx, 256000, 99);
202  saveTree1->Branch("mom1", &mom1, 256000, 99);
203  saveTree1->Branch("mom2", &mom2, 256000, 99);
204  saveTree1->Branch("mom3", &mom3, 256000, 99);
205  saveTree1->Branch("momvtx", &momvtx, 256000, 99);
206  saveTree1->Branch("rec_mom1", &rec_mom1, 256000, 99);
207  saveTree1->Branch("rec_momvtx", &rec_momvtx, 256000, 99);
208  saveTree1->Branch("rec_posvtx", &rec_posvtx, 256000, 99);
209  saveTree1->Branch("rec_momtgt", &rec_momtgt, 256000, 99);
210  saveTree1->Branch("rec_postgt", &rec_postgt, 256000, 99);
211 
212  saveTree2 = new TTree("dim", "Dimuon Tree Created by AnaModule");
213  saveTree2->Branch("eventID", &eventID, "eventID/I");
214  saveTree2->Branch("mass", &mass, "mass/D");
215  saveTree2->Branch("rec_mass", &rec_mass, "rec_mass/D");
216  saveTree2->Branch("vtx", &vtx, 256000, 99);
217  saveTree2->Branch("pmom", &pmom, 256000, 99);
218  saveTree2->Branch("nmom", &nmom, 256000, 99);
219  saveTree2->Branch("rec_pmom", &rec_pmom, 256000, 99);
220  saveTree2->Branch("rec_nmom", &rec_nmom, 256000, 99);
221  saveTree2->Branch("rec_ppos", &rec_ppos, 256000, 99);
222  saveTree2->Branch("rec_npos", &rec_npos, 256000, 99);
223  saveTree2->Branch("rec_vtx", &rec_vtx, 256000, 99);
224 }
AnaModule()
Definition: AnaModule.h:15
int End(PHCompositeNode *topNode)
Called at the end of all processing.
Definition: AnaModule.cxx:70
int Init(PHCompositeNode *topNode)
Definition: AnaModule.cxx:20
int InitRun(PHCompositeNode *topNode)
Definition: AnaModule.cxx:25
int process_event(PHCompositeNode *topNode)
Definition: AnaModule.cxx:35
virtual ~AnaModule()
Definition: AnaModule.cxx:17
virtual const SQDimuon * at(const size_t id) const =0
virtual size_t size() const =0
An SQ interface class to hold one true or reconstructed dimuon.
Definition: SQDimuon.h:8
virtual TLorentzVector get_mom_neg() const =0
Return the momentum of the negative track at vertex.
virtual TLorentzVector get_mom_pos() const =0
Return the momentum of the positive track at vertex.
virtual int get_rec_dimuon_id() const =0
Return the dimuon ID of associated reconstructed dimuon. Valid only if this object holds truth dimuon...
virtual TLorentzVector get_mom() const =0
Return the dimuon momentum at vertex.
virtual TVector3 get_pos() const =0
Return the dimuon position at vertex.
virtual const SQTrack * at(const size_t id) const =0
virtual size_t size() const =0
An SQ interface class to hold one true or reconstructed track.
Definition: SQTrack.h:8
virtual TVector3 get_pos_vtx() const =0
Return the track position at vertex.
virtual int get_charge() const =0
Return the charge, i.e. +1 or -1.
virtual int get_rec_track_id() const =0
Return the track ID of associated reconstructed track. Valid only if this object holds truth track in...
virtual TLorentzVector get_mom_vtx() const =0
Return the track momentum at vertex.
virtual TLorentzVector get_mom_st1() const =0
Return the track momentum at Station 1.
virtual TVector3 get_pos_st3() const =0
Return the track position at Station 3.
virtual TVector3 get_pos_st1() const =0
Return the track position at Station 1.
virtual TLorentzVector get_mom_st3() const =0
Return the track momentum at Station 3.
TVector3 vtx
3-vector vertex position
Definition: SRecEvent.h:379
TLorentzVector p_neg
Definition: SRecEvent.h:366
TLorentzVector p_pos
4-momentum of the muon tracks after vertex fit
Definition: SRecEvent.h:365
Double_t mass
Kinematic variables.
Definition: SRecEvent.h:390
TVector3 vtx_neg
Definition: SRecEvent.h:381
TVector3 vtx_pos
Definition: SRecEvent.h:380
SRecDimuon & getDimuon(Int_t i)
Definition: SRecEvent.h:463
Int_t getNTracks()
Get tracks.
Definition: SRecEvent.h:455
SRecTrack & getTrack(Int_t i)
Definition: SRecEvent.h:456
Int_t getNDimuons()
Get dimuons.
Definition: SRecEvent.h:462
TVector3 getTargetPos()
Definition: SRecEvent.h:188
TVector3 getVertexPos()
Definition: SRecEvent.h:196
TVector3 getMomentumVecSt1() const
Definition: SRecEvent.h:129
TVector3 getVertexMom()
Definition: SRecEvent.h:197
TVector3 getTargetMom()
Definition: SRecEvent.h:193