BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
NavigationTestAlg.cxx
Go to the documentation of this file.
2
4
5#include <cmath>
6#include "GaudiKernel/MsgStream.h"
7#include "GaudiKernel/SmartDataPtr.h"
8//#include "PartPropSvc/PartPropSvc.h"
9
10// Monte-Carlo data
11#include "McTruth/McParticle.h"
12#include "McTruth/MdcMcHit.h"
13
14// MDC reconstructed data
17
18// EMC reconstructed data
20
21#include "TH1F.h"
22#include "TH2F.h"
23#include "TFile.h"
24
25using namespace std;
26using namespace Event;
27
28
29DECLARE_COMPONENT(NavigationTestAlg)
30NavigationTestAlg::NavigationTestAlg(const std::string& name, ISvcLocator* pSvcLocator) : Algorithm(name, pSvcLocator)
31{
32 declareProperty("OutputFileName", m_fout="histo.root");
33}
34
35// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
36
38 MsgStream log(msgSvc(), name());
39
40 log << MSG::INFO << " Creating histograms" << endreq;
41
42 // create histograms
43 m_histo.push_back(new TH1F("deltap","#delta p, true momentum - rec momentum, MeV/c",600,-100,500)); //0
44
45 m_histo.push_back(new TH1F("n_parents","Number of parents for reconstructed track",20,0,20)); // 1
46 m_histo.push_back(new TH1F("n_tracks","Number of tracks for one MC particle",20,0,20)); // 2
47
48 m_histo.push_back(new TH1F("hit_parent","Number of parent MC hits for reconstructed hit",20,-10,10)); // 3
49 m_histo.push_back(new TH1F("hit_track","Number of reconstructed hits for MC hit",20,-10,10)); // 4
50
51 m_histo.push_back(new TH1F("true_p","true momentum, MeV/c",1500,0,1500)); // 5
52 m_histo.push_back(new TH1F("rec_p","reconstructed momentum, MeV/c",1500,0,1500)); // 6
53
54 m_histo.push_back(new TH1F("n_emcparents","# of parents for reconstructed shower",20,0,20)); // 7
55 m_histo.push_back(new TH1F("n_showers","# of showers for one true particle",20,0,20)); // 8
56
57 m_histo.push_back(new TH1F("pdg_miss","Pdg of particles with # trk==0 and #showers > 0",6000,-3000,3000)); //9
58
59 m_histo.push_back(new TH1F("dE_true","True energy - shower energy",40,-2000,2000)); //10
60 m_histo.push_back(new TH1F("dE_rec","shower energy - sqrt(Prec**2+m_true**2)",40,-2000,2000)); //11
61
62 m_histo.push_back(new TH1F("E_true","True energy, MeV",100,0,1000)); //12
63 m_histo.push_back(new TH1F("E_rec","Rec energy, MeV",100,0,1000)); //13
64
65 m_histo2.push_back(new TH2F("deltap_p","#delta p/p vs. p, MeV",100,0,1000,20,0,2));
66
67 return StatusCode::SUCCESS;
68}
69
70// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
71
73 MsgStream log(msgSvc(), name());
74
75 // Get EventNavigator from the TDS
76 SmartDataPtr<EventNavigator> navigator (eventSvc(),"/Event/Navigator");
77 if( ! navigator )
78 {
79 log << MSG::ERROR << " Unable to retrieve EventNavigator" << endreq;
80 return StatusCode::FAILURE;
81 }
82
83 log << MSG::INFO << "EventNavigator object" << endreq;
84 navigator->Print();
85
86
87 // ======== Analyse Monte-Carlo information using navigator
88 log << MSG::INFO << "=======================================================================" << endreq;
89 log << MSG::INFO << "MC Particles ===============================================================" << endreq;
90
91 // Get McParticle collection
92 SmartDataPtr<McParticleCol> mcParticles(eventSvc(),"/Event/MC/McParticleCol");
93 if( ! mcParticles )
94 {
95 log << MSG::ERROR << " Unable to retrieve McParticleCol" << endreq;
96 return StatusCode::FAILURE;
97 }
98
99 // For each McParticle
100 for( McParticleCol::iterator it = mcParticles->begin(); it != mcParticles->end(); it++ )
101 {
102 // get charge of McParticles
103 int pdg_code = (*it)->particleProperty();
104
105 // get true momentum value
106 double true_mom = (*it)->initialFourMomentum().vect().mag();
107
108 // fill true momentum
109 m_histo[5]->Fill(true_mom);
110
111 log<<MSG::INFO<<"Retrieved McParticle # "<<(*it)->trackIndex()
112 << " PDG " << pdg_code << " of true momentum "
113 << true_mom <<" GeV/c " <<endreq;
114
115 // get list of reconstructed tracks, which correspond to this particle, using EventNavigator
116 RecMdcTrackVector tracks = navigator->getMdcTracks(*it);
117 RecMdcKalTrackVector ktracks = navigator->getMdcKalTracks(*it);
118
119 // fill the distribution of number of rec. tracks corresponding to single particle
120 m_histo[2]->Fill(tracks.size());
121
122 log << MSG::INFO << " Found " << tracks.size() << " tracks and " << ktracks.size() << " Kalman tracks" << endreq;
123
124 // for each track
125 for(unsigned int i=0; i<ktracks.size(); i++)
126 {
127 // Hep3Vector p = momentum(tracks[i]);
128 double momentum = ktracks[i]->p();
129
130 log << MSG::INFO << "\t Track # " << i
131 << " id = " << ktracks[i]->trackId()
132 << " Pid " << ktracks[i]->getPidType()
133 << " Ptot " << momentum << " GeV/c" << endreq;
134
135 // fill difference of true momentum and rec momentum for the _same_ track
136 m_histo[0]->Fill(true_mom-momentum);
137
138 // fill delta_p/p wrt p for the _same_ track
139 m_histo2[0]->Fill(true_mom, fabs(true_mom-momentum)/true_mom);
140 }
141
142 // get list of reconstructed showers, which correspond to this particle, using EventNavigator
143 RecEmcShowerVector showers = navigator->getEmcRecShowers(*it);
144
145 m_histo[8]->Fill(showers.size());
146
147 log << MSG::INFO << " Found " << showers.size() << " showers" << endreq;
148
149 for(unsigned int i=0; i<showers.size(); i++)
150 {
151 double true_energy = (*it)->initialFourMomentum().e();
152 double rec_energy = showers[i]->energy()*1000; // MeV
153
154 log << MSG::INFO << "\t Shower # " << i
155 << " Id = " << showers[i]->getShowerId().get_value()
156 << " E = " << showers[i]->energy()*1000 << " MeV " << endreq;
157
158 m_histo[12]->Fill(true_energy);
159 m_histo[13]->Fill(rec_energy);
160 }
161 }
162
163 log << MSG::INFO << "MDC Tracks ==============================================================" << endreq;
164 // ======== Analyse reconstructed track information using navigator
165
166 SmartDataPtr<RecMdcKalTrackCol> mdcKalTracks(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
167 if( ! mdcKalTracks )
168 {
169 log << MSG::ERROR << " Unable to retrieve MdcKalTrackCol" << endreq;
170 return StatusCode::SUCCESS;
171 }
172
173 for( RecMdcKalTrackCol::iterator it = mdcKalTracks->begin(); it != mdcKalTracks->end(); it++ )
174 {
175 McParticleVector particles = navigator->getMcParticles(*it);
176
177 log << MSG::INFO << "Retrieved " << particles.size() << " McParticles for for MdcKalTrack # "
178 << (*it)->trackId() << " of reconstructed momentum " << (*it)->p() << " GeV/c (PID="
179 << (*it)->getPidType() << ")" << endreq;
180
181 // fill rec momentum
182 m_histo[6]->Fill((*it)->p());
183
184 // fill the distribution of number of parent particles corresponding to this track
185 m_histo[1]->Fill(particles.size());
186
187 // for each parent particle
188 for(unsigned int i=0; i<particles.size(); i++)
189 {
190 int pdg_code = particles[i]->particleProperty();
191
192 // get true momentum value
193 double true_mom = particles[i]->initialFourMomentum().vect().mag();
194
195 // get relevance
196 int relevance = navigator->getMcParticleRelevance(*it, particles[i]);
197
198 // dump particle names, momenta and their relevance
199 log << MSG::INFO << "\t" << pdg_code << " momentum "
200 << true_mom << " relevance " << relevance << endreq;
201 }
202 }
203
204 // ======== Analyse reconstructed shower information using navigator
205 log << MSG::INFO << "EMC Showers ==============================================================" << endreq;
206 SmartDataPtr<RecEmcShowerCol> emcShowers(eventSvc(),"/Event/Recon/RecEmcShowerCol");
207 if( ! emcShowers )
208 {
209 log << MSG::ERROR << " Unable to retrieve EmcRecShowerCol" << endreq;
210 return StatusCode::SUCCESS;
211 }
212
213 int ij = 0;
214 for( RecEmcShowerCol::iterator it = emcShowers->begin(); it != emcShowers->end(); it++ )
215 {
216 McParticleVector particles = navigator->getMcParticles(*it);
217 log << MSG::INFO << "Retrieved McParticles for EmcShower # " << ij++
218 << " Id " << (*it)->getShowerId().get_value()
219 << " Energy = " << (*it)->energy() << endreq;
220
221 for(unsigned int i=0; i<particles.size(); i++)
222 {
223 int pdg_code = particles[i]->particleProperty();
224
225 // get true energy
226 double true_e = particles[i]->initialFourMomentum().e();
227
228 // get relevance
229 int relevance = navigator->getMcParticleRelevance(*it, particles[i]);
230
231 log << "\t Particle " << i << " PDG " << pdg_code << " E=" << true_e
232 << " Relevance " << relevance << endreq;
233 }
234
235 // fill the distribution of number of parent particles corresponding to this track
236 m_histo[7]->Fill(particles.size());
237 }
238
239 log << MSG::INFO << "=======================================================================" << endreq;
240
241 return StatusCode::SUCCESS;
242}
243
244// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
245
247
248 // Save histograms to ROOT file
249 TFile of(m_fout.c_str(),"RECREATE");
250 of.cd();
251 for(vector<TH1F*>::iterator it=m_histo.begin(); it!=m_histo.end(); it++)
252 (*it)->Write();
253 for(vector<TH2F*>::iterator it=m_histo2.begin(); it!=m_histo2.end(); it++)
254 (*it)->Write();
255 of.Close();
256
257 return StatusCode::SUCCESS;
258}
**********INTEGER nmxhep !maximum number of particles DOUBLE PRECISION vhep INTEGER jdahep COMMON hepevt $ !serial number $ !number of particles $ !status code $ !particle ident KF $ !parent particles $ !childreen particles $ !four momentum
std::vector< const RecMdcTrack * > RecMdcTrackVector
std::vector< const Event::McParticle * > McParticleVector
std::vector< const RecMdcKalTrack * > RecMdcKalTrackVector
std::vector< const RecEmcShower * > RecEmcShowerVector
IMessageSvc * msgSvc()
Definition Event.h:21