All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
SimDigitalLinkToParticles.cc
Go to the documentation of this file.
2 
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>
9 
10 #include <cassert>
11 
13 
15  : Processor("SimDigitalLinkToParticles")
16 {
17  _description = "This processor links calorimeter hits to MC particles" ;
18 
19  std::vector<std::string> inputCollections = {} ;
20  registerInputCollections( LCIO::CALORIMETERHIT ,
21  "inputHitCollections" ,
22  "Sim Calorimeter Hit Collections" ,
24  inputCollections) ;
25 
26  std::vector<std::string> inputRelCollections = {} ;
27  registerInputCollections( LCIO::LCCOLLECTION ,
28  "inputRelationCollections" ,
29  "Collections of generic objects containing additional step informations" ,
31  inputRelCollections) ;
32 
33 
34  std::vector<std::string> outputRelCollections = {} ;
35  registerProcessorParameter( "outputRelationCollections",
36  "output hit relation Collection Names" ,
38  outputRelCollections ) ;
39 }
40 
42 {
43  assert ( _inputCollections.size() == _inputRelCollections.size() && _inputCollections.size() == _outputRelCollections.size() ) ;
44 }
45 
47 {
48  for (unsigned int i(0) ; i < _inputCollections.size() ; ++i)
49  {
50  try
51  {
52  std::string inputColName = _inputCollections.at(i) ;
53  std::string inputRelColName = _inputRelCollections.at(i) ;
54  std::string outputRelColName = _outputRelCollections.at(i) ;
55 
56  LCCollection* inputCol = evt->getCollection( inputColName.c_str() ) ;
57  LCCollection* inputRelCol = evt->getCollection( inputRelColName.c_str() ) ;
58 
59  LCCollectionVec* outputRelCol = processCollection(inputCol , inputRelCol) ;
60 
61  evt->addCollection(outputRelCol , outputRelColName.c_str()) ;
62  }
63  catch(DataNotAvailableException& )
64  {
65  }
66  }
67 }
68 
69 LCCollectionVec* SimDigitalLinkToParticles::processCollection(LCCollection* inputCol , LCCollection* inputRelCol)
70 {
71  LCFlagImpl flag ;
72  flag.setBit(LCIO::CHBIT_LONG);
73 
74 
75  LCCollectionVec* outputRelCol = new LCCollectionVec(LCIO::LCRELATION) ;
76  outputRelCol->setFlag( flag.getFlag() ) ;
77 
78  LCRelationNavigator navi(inputRelCol) ;
79 
80  int nHitsInCol = inputCol->getNumberOfElements() ;
81 
82  for ( int i = 0 ; i < nHitsInCol ; ++i )
83  {
84  CalorimeterHit* hit = dynamic_cast<CalorimeterHit*>( inputCol->getElementAt(i) ) ;
85 
86  if ( navi.getRelatedToObjects( hit ).size() > 0 )
87  {
88  SimCalorimeterHit* simHit = dynamic_cast<SimCalorimeterHit*>( navi.getRelatedToObjects(hit)[0] ) ;
89 
90  std::map<MCParticle* , unsigned int> linkMap ;
91  unsigned int total = 0U ;
92  for ( int j = 0 ; j < simHit->getNMCContributions() ; ++j )
93  {
94  MCParticle* particle = simHit->getParticleCont(j) ;
95  linkMap[particle] ++ ;
96  total ++ ;
97  }
98 
99  for ( const auto& it : linkMap )
100  outputRelCol->addElement( new LCRelationImpl(it.first , hit , 1.f*it.second/total ) ) ;
101 
102  }
103  else
104  {
105  streamlog_out ( WARNING ) << "could not find relation to sim calo hit !" << std::endl ;
106  }
107  }
108 
109  return outputRelCol ;
110 }
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
123 
124 
125 
126 
127 
128 
129 
130 
SimDigitalLinkToParticles aSimDigitalLinkToParticles
std::vector< std::string > _outputRelCollections
std::vector< std::string > _inputCollections
virtual void processEvent(LCEvent *evt)
std::vector< LCCollection * > LCCollectionVec
Definition: SiStripClus.h:55
LCCollectionVec * processCollection(LCCollection *inputCol, LCCollection *inputRelCol)
std::vector< std::string > _inputRelCollections