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