BOSS 7.0.3
BESIII Offline Software System
Loading...
Searching...
No Matches
BesNavigatorInit.cxx
Go to the documentation of this file.
1#include "GaudiKernel/MsgStream.h"
2#include "GaudiKernel/SmartDataPtr.h"
3
4#include "EventNavigator/EventNavigator.h"
5#include "EventNavigator/BesNavigatorInit.h"
6
7// Monte-Carlo data
8#include "McTruth/McParticle.h"
9#include "McTruth/EmcMcHit.h"
10#include "McTruth/MdcMcHit.h"
11#include "McTruth/MucMcHit.h"
12#include "McTruth/TofMcHit.h"
13
14// MDC reconstructed data
15#include "MdcRecEvent/RecMdcTrack.h"
16#include "MdcRecEvent/RecMdcKalTrack.h"
17#include "MdcRecEvent/RecMdcHit.h"
18
19// EMC reconstructed data
20#include "EmcRecEventModel/RecEmcShower.h"
21
22// TOF reconstructed data
23#include "TofRecEvent/RecTofTrack.h"
24#include "TofRecEvent/RecBTofHit.h"
25#include "TofRecEvent/RecETofHit.h"
26
27// MUC reconstructed data
28#include "MucRecEvent/RecMucTrack.h"
29#include "MucRecEvent/MucRecHit.h"
30
31// Digi information
32#include "EmcRecEventModel/RecEmcDigit.h"
33#include "MdcRawEvent/MdcDigi.h"
34
35using namespace std;
36using namespace EventModel;
37using namespace Event;
38
39/////////////////////////////////////////////////////////////////////////////
40
41BesNavigatorInit::BesNavigatorInit(const std::string& name, ISvcLocator* pSvcLocator) : Algorithm(name, pSvcLocator){
42 // Subdetector flags
43 declareProperty("FillMdcInfo", b_fillMdc=true);
44 declareProperty("FillTofInfo", b_fillTof=true);
45 declareProperty("FillEmcInfo", b_fillEmc=true);
46 declareProperty("FillMucInfo", b_fillMuc=true);
47 declareProperty("MdcCut", m_mdcCut=7);
48 declareProperty("PrepareHitMaps", b_fillHitMaps = false);
49 state = SIMU;
50}
51
52// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
53
55 return StatusCode::SUCCESS;
56}
57
58// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
59
61 MsgStream log(msgSvc(), name());
62
63 state = SIMU;
64
65 SmartDataPtr<EventNavigator> nav(eventSvc(),"/Event/Navigator");
66 if( ! nav )
67 {
68 log << MSG::DEBUG << "Create EventNavigator" << endreq;
69 m_navigator = new EventNavigator;
70 m_navigator->setMdcCut(m_mdcCut);
71 }
72 else
73 {
74 log << MSG::DEBUG << "Found EventNavigator (read from DST)" << endreq;
75 m_navigator = nav;
76 state = RECO;
77 if( log.level() < 3 )
78 m_navigator->Print();
79 }
80
81 SmartDataPtr<McParticleCol> mcParticles(eventSvc(),"/Event/MC/McParticleCol");
82 if( ! mcParticles )
83 {
84 log << MSG::ERROR << "Unable to retrieve McParticleCol" << endreq;
85 return StatusCode::FAILURE;
86 }
87 else
88 log << MSG::DEBUG << "McParticleCol retrieved of size "<< mcParticles->size() << endreq;
89
90 for(McParticleCol::const_iterator it = mcParticles->begin(); it != mcParticles->end(); it++)
91 {
92 m_navigator->addIdLink( (*it)->trackIndex(), *it );
93 }
94
95 // store MDC relations
96 if( b_fillMdc )
98
99 // store EMC relations
100 if( b_fillEmc )
101 fillEmcInfo();
102
103 // store TOF relations
104 if( b_fillTof )
105 fillTofInfo();
106
107 // store MUC relations
108 if( b_fillMuc )
109 fillMucInfo();
110
111 // Register EventNavigator to Gaudi TDS
112 if (state == SIMU)
113 {
114 StatusCode sc = eventSvc()->registerObject("/Event/Navigator",m_navigator);
115 if (sc != StatusCode::SUCCESS)
116 {
117 log << MSG::ERROR << "Could not register EventNavigator" << endreq;
118 return StatusCode::FAILURE;
119 }
120 else
121 log << MSG::INFO << "EventNavigator registered successfully in TDS" << endreq;
122 }
123
124 if( log.level() < 3 )
125 {
126 log << MSG::DEBUG << "Write EventNavigator" << endreq;
127 m_navigator->Print();
128 }
129
130 return StatusCode::SUCCESS;
131}
132
133// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
134
136 return StatusCode::SUCCESS;
137}
138
140{
141 MsgStream log(msgSvc(), name());
142
143 //****** Process hits ******
144 // If simulated hits are there, fill index map (read from DST if no hits in TDS)
145 SmartDataPtr<MdcMcHitCol> mdcMcHits(eventSvc(),"/Event/MC/MdcMcHitCol");
146 if( mdcMcHits )
147 {
148 log << MSG::DEBUG << "MdcMcHitsCol retrieved of size "<< mdcMcHits->size() << endreq;
149
150 if (mdcMcHits->size() != 0)
151 m_navigator->getMcMdcMcHitsIdx().clear();
152
153 for(MdcMcHitCol::const_iterator it = mdcMcHits->begin(); it != mdcMcHits->end(); it++)
154 {
155 // fill relation MdcHit id <-> McParticle
156 m_navigator->getMcMdcMcHitsIdx().insert( pair<int,int>((*it)->identify().get_value(), (*it)->getTrackIndex()));
157
158 // m_navigator->addIdLink( (*it)->identify().get_value(), *it );
159 }
160 }
161 else
162 {
163 log << MSG::DEBUG << "Unable to retrieve MdcMcHitCol" << endreq;
164 }
165
166 // If reconstructed hits are there, fill index map (read from DST if no hits in TDS)
167 SmartDataPtr<RecMdcHitCol> mdcRecHits(eventSvc(),"/Event/Recon/RecMdcHitCol");
168 if( mdcRecHits )
169 {
170 log << MSG::DEBUG << "MdcRecHitCol retrieved of size "<< mdcRecHits->size() << endreq;
171
172 if (mdcRecHits->size() != 0)
173 m_navigator->getMcMdcTracksIdx().clear();
174
175 IndexMap& mchits = m_navigator->getMcMdcMcHitsIdx();
176 for(RecMdcHitCol::iterator it=mdcRecHits->begin(); it!=mdcRecHits->end(); it++)
177 {
178 int mdcId = ((*it)->getMdcId()).get_value();
179 // m_navigator->addIdLink( mdcId, *it);
180
181 const pair<IndexMap::const_iterator, IndexMap::const_iterator> range = mchits.equal_range(mdcId);
182 for(IndexMap::const_iterator jt = range.first; jt != range.second; jt++)
183 {
184 m_navigator->getMcMdcTracksIdx().insert( pair<int,int>((*jt).second, (*it)->getTrkId()));
185 }
186 }
187 }
188 else
189 log << MSG::DEBUG << "Unable to retrieve RecMdcHitCol" << endreq;
190
191
192 // ****** Get MDC top level objects from TDS ******
193 // MDC Reconstructed Tracks
194 SmartDataPtr<RecMdcTrackCol> mdcTracks(eventSvc(),"/Event/Recon/RecMdcTrackCol");
195 if( mdcTracks )
196 {
197 log << MSG::DEBUG << "MdcTrackCol retrieved of size "<< mdcTracks->size() << endreq;
198 for(RecMdcTrackCol::const_iterator it = mdcTracks->begin(); it != mdcTracks->end(); it++)
199 m_navigator->addIdLink( (*it)->trackId(), *it );
200 }
201 else
202 {
203 log << MSG::DEBUG << "Unable to retrieve RecMdcTrackCol" << endreq;
204 }
205
206 // MDC Kalman Tracks
207 SmartDataPtr<RecMdcKalTrackCol> mdcKalTracks(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
208 if( mdcKalTracks )
209 {
210 log << MSG::DEBUG << "MdcKalTrackCol retrieved of size "<< mdcKalTracks->size() << endreq;
211 for(RecMdcKalTrackCol::const_iterator it = mdcKalTracks->begin(); it != mdcKalTracks->end(); it++)
212 m_navigator->addIdLink( (*it)->trackId(), *it );
213 }
214 else
215 {
216 log << MSG::DEBUG << "Unable to retrieve RecMdcTrackCol" << endreq;
217 }
218
219 //****** Make main relations between top level objects ***
220 IndexMap::const_iterator i;
221 IndexMap& index = m_navigator->getMcMdcTracksIdx();
222 for(i = index.begin(); i != index.end(); i++)
223 {
224 // i.first = McParticle id; i.second = MdcTrack id
225 const McParticle* mcParticle = m_navigator->getMcParticle((*i).first);
226
227 if (mcParticle == 0)
228 continue;
229
230 const RecMdcTrack* mdcTrack = m_navigator->getMdcTrack((*i).second);
231
232 if( mdcTrack != 0 )
233 {
234 m_navigator->addLink(mcParticle, mdcTrack);
235 m_navigator->addLink(mdcTrack, mcParticle);
236 }
237
238 const RecMdcKalTrack* mdcKalTrack = m_navigator->getMdcKalTrack((*i).second); // same trkid
239 if( mdcKalTrack != 0 )
240 {
241 m_navigator->addLink(mcParticle, mdcKalTrack);
242 m_navigator->addLink(mdcKalTrack, mcParticle);
243 }
244 }
245}
246
247
249{
250 MsgStream log(msgSvc(), name());
251
252 //****** Process hits ******
253 // If simulated hits are there, fill index map (read from DST if no hits in TDS)
254 SmartDataPtr<EmcMcHitCol> emcMcHits(eventSvc(),"/Event/MC/EmcMcHitCol");
255 if( emcMcHits )
256 {
257 log << MSG::DEBUG << "EmcMcHitsCol retrieved of size "<< emcMcHits->size() << endreq;
258
259 if (emcMcHits->size() != 0)
260 m_navigator->getMcEmcMcHitsIdx().clear();
261
262 for(EmcMcHitCol::const_iterator it = emcMcHits->begin(); it != emcMcHits->end(); it++)
263 {
264 //first put Id of crystal, which particle hits initially
265 int crystalId = (*it)->identify().get_value();
266 int McParticleID = 0;
267 if(crystalId != 0) // not gamma converted in TOF
268 {
269 McParticleID = (*it)->getTrackIndex();
270 m_navigator->getMcEmcMcHitsIdx().insert( pair<int,int>(crystalId, McParticleID));
271 // m_navigator->addIdLink( crystalId, *it );
272 }
273
274 //then add all other crystals touched by shower
275 const map<Identifier,double>& hitmap = (*it)->getHitMap();
276 map<Identifier,double>::const_iterator jt;
277 for (jt=hitmap.begin(); jt!=hitmap.end(); jt++)
278 {
279 int crystalId = (*jt).first.get_value();
280
281 if(McParticleID !=0 ) // not gamma converted in TOF
282 {
283 m_navigator->getMcEmcMcHitsIdx().insert( pair<int,int>(crystalId, McParticleID)); // CrystalId, McParticleID
284 }
285 //m_navigator->addIdLink( (*jt).first.get_value(), *it );
286 }
287 }
288 }
289 else
290 {
291 log << MSG::DEBUG << "Unable to retrieve EmcMcHitCol" << endreq;
292 }
293
294 // ****** Get EMC top level objects from TDS ******
295 // EMC Reconstructed Showers
296 SmartDataPtr<RecEmcShowerCol> emcRecShowers(eventSvc(),"/Event/Recon/RecEmcShowerCol");
297 if( emcRecShowers )
298 {
299 log << MSG::DEBUG << "RecEmcShowerCol retrieved of size "<< emcRecShowers->size() << endreq;
300
301 IndexMap& mchits = m_navigator->getMcEmcMcHitsIdx();
302
303 for(RecEmcShowerCol::const_iterator it = emcRecShowers->begin();
304 it != emcRecShowers->end();
305 it++)
306 {
307 int showerId = (*it)->getShowerId().get_value();
308 m_navigator->addIdLink( showerId, *it );
309
310 // calculate relations only during reco and store them to DST.
311 // EmcMcHit tables are removed then.
312 if(! mchits.empty())
313 {
314 const RecEmcFractionMap& fractionMap = (*it)->getFractionMap();
315 for(RecEmcFractionMap::const_iterator jt = fractionMap.begin();
316 jt != fractionMap.end();
317 jt++)
318 {
319 int crystalId = (*jt).first.get_value();
320 const pair<IndexMap::const_iterator, IndexMap::const_iterator> range = mchits.equal_range(crystalId); // McParticles which hit given crystal
321
322 for(IndexMap::const_iterator kt = range.first; kt != range.second; kt++)
323 {
324 m_navigator->getMcEmcRecShowersIdx().insert( pair<int,int>((*kt).second, showerId)); // McParticle id <-> RecShower ShowerId
325 }
326 }
327 }
328 }
329 }
330 else
331 {
332 log << MSG::DEBUG << "Unable to retrieve RecEmcShowerCol" << endreq;
333 }
334
335
336 //****** Make main relations between top level objects ***
337 IndexMap::const_iterator i;
338 IndexMap& index = m_navigator->getMcEmcRecShowersIdx();
339 for(i = index.begin(); i != index.end(); i++)
340 {
341 // i.first = McParticle id; i.second = MdcTrack id
342 const McParticle* mcParticle = m_navigator->getMcParticle((*i).first);
343
344 if (mcParticle == 0)
345 continue;
346
347 const RecEmcShowerVector& emcShowers = m_navigator->getEmcRecShowers((*i).second);
348
349 if( ! emcShowers.empty() )
350 {
351 RecEmcShowerVector::const_iterator j;
352 for(j=emcShowers.begin(); j!=emcShowers.end(); j++)
353 {
354 m_navigator->addLink(mcParticle, *j);
355 m_navigator->addLink(*j, mcParticle);
356 }
357 }
358 }
359}
360
362{
363}
364
366{
367}
map< RecEmcID, RecEmcFraction, less< RecEmcID > > RecEmcFractionMap
std::vector< const RecEmcShower * > RecEmcShowerVector
StatusCode execute()
BesNavigatorInit(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode initialize()
void addLink(const Event::McParticle *key, const RecMdcTrack *value)
RecEmcShowerVector getEmcRecShowers(int id)