00001 #include "GaudiKernel/MsgStream.h"
00002 #include "GaudiKernel/SmartDataPtr.h"
00003
00004 #include "EventNavigator/EventNavigator.h"
00005 #include "EventNavigator/BesNavigatorInit.h"
00006
00007
00008 #include "McTruth/McParticle.h"
00009 #include "McTruth/EmcMcHit.h"
00010 #include "McTruth/MdcMcHit.h"
00011 #include "McTruth/MucMcHit.h"
00012 #include "McTruth/TofMcHit.h"
00013
00014
00015 #include "MdcRecEvent/RecMdcTrack.h"
00016 #include "MdcRecEvent/RecMdcKalTrack.h"
00017 #include "MdcRecEvent/RecMdcHit.h"
00018
00019
00020 #include "EmcRecEventModel/RecEmcShower.h"
00021
00022
00023 #include "TofRecEvent/RecTofTrack.h"
00024 #include "TofRecEvent/RecBTofHit.h"
00025 #include "TofRecEvent/RecETofHit.h"
00026
00027
00028 #include "MucRecEvent/RecMucTrack.h"
00029 #include "MucRecEvent/MucRecHit.h"
00030
00031
00032 #include "EmcRecEventModel/RecEmcDigit.h"
00033 #include "MdcRawEvent/MdcDigi.h"
00034
00035 using namespace std;
00036 using namespace EventModel;
00037 using namespace Event;
00038
00040
00041 BesNavigatorInit::BesNavigatorInit(const std::string& name, ISvcLocator* pSvcLocator) : Algorithm(name, pSvcLocator){
00042
00043 declareProperty("FillMdcInfo", b_fillMdc=true);
00044 declareProperty("FillTofInfo", b_fillTof=true);
00045 declareProperty("FillEmcInfo", b_fillEmc=true);
00046 declareProperty("FillMucInfo", b_fillMuc=true);
00047 declareProperty("MdcCut", m_mdcCut=7);
00048 declareProperty("PrepareHitMaps", b_fillHitMaps = false);
00049 state = SIMU;
00050 }
00051
00052
00053
00054 StatusCode BesNavigatorInit::initialize(){
00055 return StatusCode::SUCCESS;
00056 }
00057
00058
00059
00060 StatusCode BesNavigatorInit::execute() {
00061 MsgStream log(msgSvc(), name());
00062
00063 state = SIMU;
00064
00065 SmartDataPtr<EventNavigator> nav(eventSvc(),"/Event/Navigator");
00066 if( ! nav )
00067 {
00068 log << MSG::DEBUG << "Create EventNavigator" << endreq;
00069 m_navigator = new EventNavigator;
00070 m_navigator->setMdcCut(m_mdcCut);
00071 }
00072 else
00073 {
00074 log << MSG::DEBUG << "Found EventNavigator (read from DST)" << endreq;
00075 m_navigator = nav;
00076 state = RECO;
00077 if( log.level() < 3 )
00078 m_navigator->Print();
00079 }
00080
00081 SmartDataPtr<McParticleCol> mcParticles(eventSvc(),"/Event/MC/McParticleCol");
00082 if( ! mcParticles )
00083 {
00084 log << MSG::ERROR << "Unable to retrieve McParticleCol" << endreq;
00085 return StatusCode::FAILURE;
00086 }
00087 else
00088 log << MSG::DEBUG << "McParticleCol retrieved of size "<< mcParticles->size() << endreq;
00089
00090 for(McParticleCol::const_iterator it = mcParticles->begin(); it != mcParticles->end(); it++)
00091 {
00092 m_navigator->addIdLink( (*it)->trackIndex(), *it );
00093 }
00094
00095
00096 if( b_fillMdc )
00097 fillMdcInfo();
00098
00099
00100 if( b_fillEmc )
00101 fillEmcInfo();
00102
00103
00104 if( b_fillTof )
00105 fillTofInfo();
00106
00107
00108 if( b_fillMuc )
00109 fillMucInfo();
00110
00111
00112 if (state == SIMU)
00113 {
00114 StatusCode sc = eventSvc()->registerObject("/Event/Navigator",m_navigator);
00115 if (sc != StatusCode::SUCCESS)
00116 {
00117 log << MSG::ERROR << "Could not register EventNavigator" << endreq;
00118 return StatusCode::FAILURE;
00119 }
00120 else
00121 log << MSG::INFO << "EventNavigator registered successfully in TDS" << endreq;
00122 }
00123
00124 if( log.level() < 3 )
00125 {
00126 log << MSG::DEBUG << "Write EventNavigator" << endreq;
00127 m_navigator->Print();
00128 }
00129
00130 return StatusCode::SUCCESS;
00131 }
00132
00133
00134
00135 StatusCode BesNavigatorInit::finalize() {
00136 return StatusCode::SUCCESS;
00137 }
00138
00139 void BesNavigatorInit::fillMdcInfo()
00140 {
00141 MsgStream log(msgSvc(), name());
00142
00143
00144
00145 SmartDataPtr<MdcMcHitCol> mdcMcHits(eventSvc(),"/Event/MC/MdcMcHitCol");
00146 if( mdcMcHits )
00147 {
00148 log << MSG::DEBUG << "MdcMcHitsCol retrieved of size "<< mdcMcHits->size() << endreq;
00149
00150 if (mdcMcHits->size() != 0)
00151 m_navigator->getMcMdcMcHitsIdx().clear();
00152
00153 for(MdcMcHitCol::const_iterator it = mdcMcHits->begin(); it != mdcMcHits->end(); it++)
00154 {
00155
00156 m_navigator->getMcMdcMcHitsIdx().insert( pair<int,int>((*it)->identify().get_value(), (*it)->getTrackIndex()));
00157
00158
00159 }
00160 }
00161 else
00162 {
00163 log << MSG::DEBUG << "Unable to retrieve MdcMcHitCol" << endreq;
00164 }
00165
00166
00167 SmartDataPtr<RecMdcHitCol> mdcRecHits(eventSvc(),"/Event/Recon/RecMdcHitCol");
00168 if( mdcRecHits )
00169 {
00170 log << MSG::DEBUG << "MdcRecHitCol retrieved of size "<< mdcRecHits->size() << endreq;
00171
00172 if (mdcRecHits->size() != 0)
00173 m_navigator->getMcMdcTracksIdx().clear();
00174
00175 IndexMap& mchits = m_navigator->getMcMdcMcHitsIdx();
00176 for(RecMdcHitCol::iterator it=mdcRecHits->begin(); it!=mdcRecHits->end(); it++)
00177 {
00178 int mdcId = ((*it)->getMdcId()).get_value();
00179
00180
00181 const pair<IndexMap::const_iterator, IndexMap::const_iterator> range = mchits.equal_range(mdcId);
00182 for(IndexMap::const_iterator jt = range.first; jt != range.second; jt++)
00183 {
00184 m_navigator->getMcMdcTracksIdx().insert( pair<int,int>((*jt).second, (*it)->getTrkId()));
00185 }
00186 }
00187 }
00188 else
00189 log << MSG::DEBUG << "Unable to retrieve RecMdcHitCol" << endreq;
00190
00191
00192
00193
00194 SmartDataPtr<RecMdcTrackCol> mdcTracks(eventSvc(),"/Event/Recon/RecMdcTrackCol");
00195 if( mdcTracks )
00196 {
00197 log << MSG::DEBUG << "MdcTrackCol retrieved of size "<< mdcTracks->size() << endreq;
00198 for(RecMdcTrackCol::const_iterator it = mdcTracks->begin(); it != mdcTracks->end(); it++)
00199 m_navigator->addIdLink( (*it)->trackId(), *it );
00200 }
00201 else
00202 {
00203 log << MSG::DEBUG << "Unable to retrieve RecMdcTrackCol" << endreq;
00204 }
00205
00206
00207 SmartDataPtr<RecMdcKalTrackCol> mdcKalTracks(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
00208 if( mdcKalTracks )
00209 {
00210 log << MSG::DEBUG << "MdcKalTrackCol retrieved of size "<< mdcKalTracks->size() << endreq;
00211 for(RecMdcKalTrackCol::const_iterator it = mdcKalTracks->begin(); it != mdcKalTracks->end(); it++)
00212 m_navigator->addIdLink( (*it)->trackId(), *it );
00213 }
00214 else
00215 {
00216 log << MSG::DEBUG << "Unable to retrieve RecMdcTrackCol" << endreq;
00217 }
00218
00219
00220 IndexMap::const_iterator i;
00221 IndexMap& index = m_navigator->getMcMdcTracksIdx();
00222 for(i = index.begin(); i != index.end(); i++)
00223 {
00224
00225 const McParticle* mcParticle = m_navigator->getMcParticle((*i).first);
00226
00227 if (mcParticle == 0)
00228 continue;
00229
00230 const RecMdcTrack* mdcTrack = m_navigator->getMdcTrack((*i).second);
00231
00232 if( mdcTrack != 0 )
00233 {
00234 m_navigator->addLink(mcParticle, mdcTrack);
00235 m_navigator->addLink(mdcTrack, mcParticle);
00236 }
00237
00238 const RecMdcKalTrack* mdcKalTrack = m_navigator->getMdcKalTrack((*i).second);
00239 if( mdcKalTrack != 0 )
00240 {
00241 m_navigator->addLink(mcParticle, mdcKalTrack);
00242 m_navigator->addLink(mdcKalTrack, mcParticle);
00243 }
00244 }
00245 }
00246
00247
00248 void BesNavigatorInit::fillEmcInfo()
00249 {
00250 MsgStream log(msgSvc(), name());
00251
00252
00253
00254 SmartDataPtr<EmcMcHitCol> emcMcHits(eventSvc(),"/Event/MC/EmcMcHitCol");
00255 if( emcMcHits )
00256 {
00257 log << MSG::DEBUG << "EmcMcHitsCol retrieved of size "<< emcMcHits->size() << endreq;
00258
00259 if (emcMcHits->size() != 0)
00260 m_navigator->getMcEmcMcHitsIdx().clear();
00261
00262 for(EmcMcHitCol::const_iterator it = emcMcHits->begin(); it != emcMcHits->end(); it++)
00263 {
00264
00265 int crystalId = (*it)->identify().get_value();
00266 int McParticleID = 0;
00267 if(crystalId != 0)
00268 {
00269 McParticleID = (*it)->getTrackIndex();
00270 m_navigator->getMcEmcMcHitsIdx().insert( pair<int,int>(crystalId, McParticleID));
00271
00272 }
00273
00274
00275 const map<Identifier,double>& hitmap = (*it)->getHitMap();
00276 map<Identifier,double>::const_iterator jt;
00277 for (jt=hitmap.begin(); jt!=hitmap.end(); jt++)
00278 {
00279 int crystalId = (*jt).first.get_value();
00280
00281 if(McParticleID !=0 )
00282 {
00283 m_navigator->getMcEmcMcHitsIdx().insert( pair<int,int>(crystalId, McParticleID));
00284 }
00285
00286 }
00287 }
00288 }
00289 else
00290 {
00291 log << MSG::DEBUG << "Unable to retrieve EmcMcHitCol" << endreq;
00292 }
00293
00294
00295
00296 SmartDataPtr<RecEmcShowerCol> emcRecShowers(eventSvc(),"/Event/Recon/RecEmcShowerCol");
00297 if( emcRecShowers )
00298 {
00299 log << MSG::DEBUG << "RecEmcShowerCol retrieved of size "<< emcRecShowers->size() << endreq;
00300
00301 IndexMap& mchits = m_navigator->getMcEmcMcHitsIdx();
00302
00303 for(RecEmcShowerCol::const_iterator it = emcRecShowers->begin();
00304 it != emcRecShowers->end();
00305 it++)
00306 {
00307 int showerId = (*it)->getShowerId().get_value();
00308 m_navigator->addIdLink( showerId, *it );
00309
00310
00311
00312 if(! mchits.empty())
00313 {
00314 const RecEmcFractionMap& fractionMap = (*it)->getFractionMap();
00315 for(RecEmcFractionMap::const_iterator jt = fractionMap.begin();
00316 jt != fractionMap.end();
00317 jt++)
00318 {
00319 int crystalId = (*jt).first.get_value();
00320 const pair<IndexMap::const_iterator, IndexMap::const_iterator> range = mchits.equal_range(crystalId);
00321
00322 for(IndexMap::const_iterator kt = range.first; kt != range.second; kt++)
00323 {
00324 m_navigator->getMcEmcRecShowersIdx().insert( pair<int,int>((*kt).second, showerId));
00325 }
00326 }
00327 }
00328 }
00329 }
00330 else
00331 {
00332 log << MSG::DEBUG << "Unable to retrieve RecEmcShowerCol" << endreq;
00333 }
00334
00335
00336
00337 IndexMap::const_iterator i;
00338 IndexMap& index = m_navigator->getMcEmcRecShowersIdx();
00339 for(i = index.begin(); i != index.end(); i++)
00340 {
00341
00342 const McParticle* mcParticle = m_navigator->getMcParticle((*i).first);
00343
00344 if (mcParticle == 0)
00345 continue;
00346
00347 const RecEmcShowerVector& emcShowers = m_navigator->getEmcRecShowers((*i).second);
00348
00349 if( ! emcShowers.empty() )
00350 {
00351 RecEmcShowerVector::const_iterator j;
00352 for(j=emcShowers.begin(); j!=emcShowers.end(); j++)
00353 {
00354 m_navigator->addLink(mcParticle, *j);
00355 m_navigator->addLink(*j, mcParticle);
00356 }
00357 }
00358 }
00359 }
00360
00361 void BesNavigatorInit::fillTofInfo()
00362 {
00363 }
00364
00365 void BesNavigatorInit::fillMucInfo()
00366 {
00367 }