All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
RealisticCaloReco.cc
Go to the documentation of this file.
1 #include "RealisticCaloReco.h"
2 
3 #include <marlin/Global.h>
4 
5 #include <EVENT/LCCollection.h>
6 
7 #include <IMPL/LCCollectionVec.h>
8 #include <IMPL/CalorimeterHitImpl.h>
9 #include <IMPL/LCRelationImpl.h>
10 
11 #include <UTIL/LCRelationNavigator.h>
12 
13 #include "CalorimeterHitType.h"
14 
15 #include <EVENT/LCParameters.h>
16 #include <EVENT/SimCalorimeterHit.h>
17 
18 #include <iostream>
19 #include <string>
20 #include <algorithm>
21 #include <assert.h>
22 #include <cmath>
23 
24 #define RELATIONFROMTYPESTR "FromType"
25 #define RELATIONTOTYPESTR "ToType"
26 
27 using namespace std;
28 using namespace lcio ;
29 using namespace marlin ;
30 
31 RealisticCaloReco::RealisticCaloReco() : Processor("RealisticCaloReco") {
32 
33  _description = "Performs simple reconstruction of calo hits..." ;
34 
35  std::vector < std::string > inputHitCollections;
36  registerInputCollections( LCIO::CALORIMETERHIT,
37  "inputHitCollections",
38  "input hit collection names",
40  inputHitCollections);
41 
42  std::vector < std::string > inputRelCollections;
43  registerInputCollections( LCIO::LCRELATION,
44  "inputRelationCollections",
45  "input relation collection names (digi<->sim), one per inputHitCollection",
47  inputRelCollections);
48 
49  // output collection names
50  std::vector < std::string > outputHitCollections;
51  registerProcessorParameter( "outputHitCollections",
52  "output hit collection names",
54  outputHitCollections);
55 
56  std::vector < std::string > outputRelCollections;
57  registerProcessorParameter( "outputRelationCollections",
58  "output hit collection names",
60  outputRelCollections);
61 
62  std::vector<int> calLayers;
63  registerProcessorParameter("calibration_layergroups" ,
64  "grouping of calo layers" ,
65  _calLayers,
66  calLayers);
67 
68  std::vector<float> calibrCoeff;
69  registerProcessorParameter("calibration_factorsMipGev" ,
70  "Calibration coefficients (MIP->shower GeV) of layers groups" ,
72  calibrCoeff);
73 
74  registerProcessorParameter("CellIDLayerString" ,
75  "name of the part of the cellID that holds the layer" ,
77  std::string("K-1")
78  );
79 
80 
81 }
82 
84  printParameters();
85  _idDecoder=NULL;
86 
87  // if no output collection names specified, set some default based on the input collection names
88  if ( _outputHitCollections.size()==0 ) {
89  for (size_t i=0; i<_inputHitCollections.size(); i++) {
90  _outputHitCollections.push_back( _inputHitCollections[i] + "Reco" );
91  }
92  }
93  if ( _outputRelCollections.size()==0 ) {
94  for (size_t i=0; i<_inputHitCollections.size(); i++) {
95  _outputRelCollections.push_back( _inputHitCollections[i] + "DigiRelation" );
96  }
97  }
98 
99  // should be one input relation collection per input hit collection
100  assert( _inputRelCollections.size() == _inputHitCollections.size() );
101 
102  // check that number of input and output collections names are the same
103  assert ( _outputHitCollections.size() == _inputHitCollections.size() );
104  assert ( _outputRelCollections.size() == _inputHitCollections.size() );
105 
106  assert ( _calibrCoeff.size()>0 );
107  assert ( _calibrCoeff.size() == _calLayers.size() );
108 
109  _flag.setBit(LCIO::CHBIT_LONG);
110  _flag.setBit(LCIO::RCHBIT_TIME); //store timing on output hits.
111 
112  _flag_rel.setBit(LCIO::LCREL_WEIGHTED); // for the hit relations
113 
114 }
115 
116 
117 void RealisticCaloReco::processRunHeader( LCRunHeader* /*run*/) {
118 }
119 
120 void RealisticCaloReco::processEvent( LCEvent * evt ) {
121 
122  // * Reading Collections of digitised calorimeter Hits *
123 
124  for (unsigned int i(0); i < _inputHitCollections.size(); ++i) {
125  std::string colName = _inputHitCollections[i] ;
126  std::string relName = _inputRelCollections[i] ;
127  streamlog_out ( DEBUG ) << "looking for hit, relation collection: " << colName << " " << relName << endl;
128 
129  try{
130  LCCollection * col = evt->getCollection( colName.c_str() ) ;
131  string initString = col->getParameters().getStringVal(LCIO::CellIDEncoding);
132 
133  LCCollection * inrelcol = evt->getCollection( relName.c_str() ) ;
134  LCRelationNavigator navi(inrelcol);
135 
136  if ( _idDecoder ) delete _idDecoder;
137  _idDecoder = new CellIDDecoder<CalorimeterHit> ( col );
138 
139  // create new collection
140  LCCollectionVec *newcol = new LCCollectionVec(LCIO::CALORIMETERHIT);
141  newcol->setFlag(_flag.getFlag());
142 
143  // relation from reconstructed to sim hits
144  LCCollectionVec *relcol = new LCCollectionVec(LCIO::LCRELATION);
145  relcol->setFlag(_flag_rel.getFlag());
146  relcol->parameters().setValue( RELATIONFROMTYPESTR , LCIO::CALORIMETERHIT ) ;
147  relcol->parameters().setValue( RELATIONTOTYPESTR , LCIO::SIMCALORIMETERHIT ) ;
148 
149  int numElements = col->getNumberOfElements();
150  streamlog_out ( DEBUG ) << colName << " number of elements = " << numElements << endl;
151 
152  for (int j(0); j < numElements; ++j) {
153  CalorimeterHit * hit = dynamic_cast<CalorimeterHit*>( col->getElementAt( j ) ) ;
154 
155  int cellid0 = hit->getCellID0();
156  int cellid1 = hit->getCellID1();
157 
158  CalorimeterHitImpl * calhit = new CalorimeterHitImpl(); // make new hit
159 
160  float energy = reconstructEnergy( hit ); // overloaded method, technology dependent
161 
162  calhit->setCellID0(cellid0);
163  calhit->setCellID1(cellid1);
164  calhit->setEnergy(energy);
165  calhit->setRawHit( hit->getRawHit() );
166  calhit->setTime( hit->getTime() );
167  calhit->setPosition( hit->getPosition() );
168  calhit->setType( hit->getType() );
169 
170  newcol->addElement( calhit );
171 
172  // get the simcalohit corresponding to this digitised hit
173  if ( navi.getRelatedToObjects( hit ) .size() > 0 ) {
174  SimCalorimeterHit* simhit = (SimCalorimeterHit*) navi.getRelatedToObjects(hit)[0]; // assume the first one (should be only one)
175  // make a relation, add to collection - keep relations from reco to sim hits
176  relcol->addElement( new LCRelationImpl(calhit,simhit,1.0) );
177  } else {
178  streamlog_out ( WARNING ) << "could not find relation to sim calo hit!" << endl;
179  }
180 
181  }
182 
183  // add collection to event
184  newcol->parameters().setValue(LCIO::CellIDEncoding,initString);
185 
186  evt->addCollection(newcol,_outputHitCollections[i].c_str());
187  evt->addCollection(relcol, _outputRelCollections[i].c_str());
188  }
189  catch(DataNotAvailableException &e){
190  streamlog_out(DEBUG) << "could not find input ECAL collection " << colName << std::endl;
191  }
192  }
193  return;
194 }
195 
196 float RealisticCaloReco::getLayerCalib( int ilayer ) {
197  float calib_coeff = 0;
198  // retrieve calibration constants
199  // Fixed the following logic (DJeans, June 2016)
200  int min(0),max(0);
201  for (unsigned int k(0); k < _calLayers.size(); ++k) {
202  if ( k > 0 ) min+=_calLayers[k-1];
203  max+=_calLayers[k];
204  if (ilayer >= min && ilayer < max) {
205  calib_coeff = _calibrCoeff[k];
206  break;
207  }
208  }
209  assert( calib_coeff>0 );
210  return calib_coeff;
211 }
212 
213 void RealisticCaloReco::check( LCEvent * /*evt*/ ) { }
214 
216 
virtual float reconstructEnergy(const CalorimeterHit *hit)=0
virtual void check(LCEvent *evt)
static const float k
virtual void processEvent(LCEvent *evt)
std::vector< float > _calibrCoeff
std::vector< std::string > _outputHitCollections
std::vector< std::string > _outputRelCollections
std::vector< std::string > _inputHitCollections
float getLayerCalib(int ilayer)
#define RELATIONFROMTYPESTR
static const float e
#define RELATIONTOTYPESTR
std::string _cellIDLayerString
std::vector< LCCollection * > LCCollectionVec
Definition: SiStripClus.h:55
std::vector< std::string > _inputRelCollections
virtual void init()
virtual void processRunHeader(LCRunHeader *run)
CellIDDecoder< CalorimeterHit > * _idDecoder
std::vector< int > _calLayers