3 #include <UTIL/LCRelationNavigator.h>
4 #include <EVENT/MCParticle.h>
5 #include <EVENT/SimCalorimeterHit.h>
6 #include <EVENT/CalorimeterHit.h>
7 #include <IMPL/LCRelationImpl.h>
8 #include <IMPL/LCFlagImpl.h>
17 _description =
"This processor links calorimeter hits to MC particles" ;
19 std::vector<std::string> inputCollections = {} ;
20 registerInputCollections( LCIO::CALORIMETERHIT ,
21 "inputHitCollections" ,
22 "Sim Calorimeter Hit Collections" ,
26 std::vector<std::string> inputRelCollections = {} ;
27 registerInputCollections( LCIO::LCCOLLECTION ,
28 "inputRelationCollections" ,
29 "Collections of generic objects containing additional step informations" ,
31 inputRelCollections) ;
34 std::vector<std::string> outputRelCollections = {} ;
35 registerProcessorParameter(
"outputRelationCollections",
36 "output hit relation Collection Names" ,
38 outputRelCollections ) ;
56 LCCollection* inputCol = evt->getCollection( inputColName.c_str() ) ;
57 LCCollection* inputRelCol = evt->getCollection( inputRelColName.c_str() ) ;
61 evt->addCollection(outputRelCol , outputRelColName.c_str()) ;
63 catch(DataNotAvailableException& )
72 flag.setBit(LCIO::CHBIT_LONG);
76 outputRelCol->setFlag( flag.getFlag() ) ;
78 LCRelationNavigator navi(inputRelCol) ;
80 int nHitsInCol = inputCol->getNumberOfElements() ;
82 for (
int i = 0 ; i < nHitsInCol ; ++i )
84 CalorimeterHit* hit =
dynamic_cast<CalorimeterHit*
>( inputCol->getElementAt(i) ) ;
86 if ( navi.getRelatedToObjects( hit ).size() > 0 )
88 SimCalorimeterHit* simHit =
dynamic_cast<SimCalorimeterHit*
>( navi.getRelatedToObjects(hit)[0] ) ;
90 std::map<MCParticle* , unsigned int> linkMap ;
91 unsigned int total = 0U ;
92 for (
int j = 0 ; j < simHit->getNMCContributions() ; ++j )
94 MCParticle* particle = simHit->getParticleCont(j) ;
95 linkMap[particle] ++ ;
99 for (
const auto& it : linkMap )
100 outputRelCol->addElement(
new LCRelationImpl(it.first , hit , 1.f*it.second/total ) ) ;
105 streamlog_out ( WARNING ) <<
"could not find relation to sim calo hit !" << std::endl ;
109 return outputRelCol ;
SimDigitalLinkToParticles aSimDigitalLinkToParticles
std::vector< std::string > _outputRelCollections
std::vector< std::string > _inputCollections
SimDigitalLinkToParticles()
virtual void processEvent(LCEvent *evt)
std::vector< LCCollection * > LCCollectionVec
LCCollectionVec * processCollection(LCCollection *inputCol, LCCollection *inputRelCol)
std::vector< std::string > _inputRelCollections