All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
SimpleCaloDigi.cc
Go to the documentation of this file.
1 #include "SimpleCaloDigi.h"
2 #include <EVENT/LCCollection.h>
3 #include <EVENT/SimCalorimeterHit.h>
4 #include <IMPL/CalorimeterHitImpl.h>
5 #include <IMPL/LCCollectionVec.h>
6 #include <IMPL/LCFlagImpl.h>
7 #include <IMPL/LCRelationImpl.h>
8 #include <EVENT/LCParameters.h>
9 #include <UTIL/CellIDDecoder.h>
10 #include <iostream>
11 // #include <string>
12 // #include <algorithm>
13 
14 #include "CalorimeterHitType.h"
15 
16 
17 using namespace std;
18 using namespace lcio ;
19 using namespace marlin ;
20 
21 
23 
24 
25 
26 SimpleCaloDigi::SimpleCaloDigi() : Processor("SimpleCaloDigi") {
27 
28  _description = "Performs simple digitization of sim calo hits..." ;
29 
30  std::vector<std::string> ecalCollections;
31 
32  ecalCollections.push_back(std::string("ecal02_EcalBarrel"));
33  ecalCollections.push_back(std::string("ecal02_EcalEndcap"));
34 
35  registerInputCollections( LCIO::SIMCALORIMETERHIT,
36  "ECALCollections" ,
37  "ECAL Collection Names" ,
39  ecalCollections);
40 
41  std::vector<std::string> hcalCollections;
42 
43  hcalCollections.push_back(std::string("hcalFeScintillator_HcalBarrelEnd"));
44  hcalCollections.push_back(std::string("hcalFeScintillator_HcalBarrelReg"));
45  hcalCollections.push_back(std::string("hcalFeScintillator_HcalEndCaps"));
46 
47  registerInputCollections( LCIO::SIMCALORIMETERHIT,
48  "HCALCollections" ,
49  "HCAL Collection Names" ,
51  hcalCollections);
52 
53  registerOutputCollection( LCIO::CALORIMETERHIT,
54  "ECALOutputCollection" ,
55  "ECAL Collection of real Hits" ,
57  std::string("ECAL")) ;
58 
59  registerOutputCollection( LCIO::CALORIMETERHIT,
60  "HCALOutputCollection" ,
61  "HCAL Collection of real Hits" ,
63  std::string("HCAL")) ;
64 
65 
66  registerOutputCollection( LCIO::LCRELATION,
67  "RelationOutputCollection" ,
68  "CaloHit Relation Collection" ,
70  std::string("RelationCaloHit")) ;
71 
72  registerProcessorParameter("ECALThreshold" ,
73  "Threshold for ECAL Hits in GeV" ,
75  (float)1.0e-4);
76 
77  registerProcessorParameter("HCALThreshold" ,
78  "Threshold for HCAL Hits in GeV" ,
80  (float)4.0e-4);
81 
82 
83  std::vector<int> ecalLayers;
84  ecalLayers.push_back(30);
85  ecalLayers.push_back(100);
86 
87 
88  registerProcessorParameter("ECALLayers" ,
89  "Index of ECal Layers" ,
91  ecalLayers);
92 
93 
94 
95  std::vector<int> hcalLayers;
96  hcalLayers.push_back(100);
97 
98  registerProcessorParameter("HCALLayers" ,
99  "Index of HCal Layers" ,
100  _hcalLayers,
101  hcalLayers);
102 
103 
104  std::vector<float> calibrEcal;
105  calibrEcal.push_back(31.3);
106  calibrEcal.push_back(83.0);
107 
108 
109  registerProcessorParameter("CalibrECAL" ,
110  "Calibration coefficients for ECAL" ,
112  calibrEcal);
113 
114 
115  std::vector<float> calibrHcal;
116  calibrHcal.push_back(27.3);
117 
118  registerProcessorParameter("CalibrHCAL" ,
119  "Calibration coefficients for HCAL" ,
121  calibrHcal);
122 
123 
124  registerProcessorParameter("IfDigitalEcal" ,
125  "Digital Ecal" ,
126  _digitalEcal ,
127  0);
128 
129 
130  registerProcessorParameter("IfDigitalHcal" ,
131  "Digital Hcal" ,
132  _digitalHcal ,
133  0);
134 
135 
136 }
137 
139 
140  _nRun = -1;
141  _nEvt = 0;
142 
143  //fg: need to set default encoding in for reading old files...
144  CellIDDecoder<SimCalorimeterHit>::setDefaultEncoding("M:3,S-1:3,I:9,J:9,K-1:6") ;
145 
146 }
147 
148 
149 void SimpleCaloDigi::processRunHeader( LCRunHeader* /*run*/) {
150  _nRun++ ;
151  _nEvt = 0;
152 }
153 
154 void SimpleCaloDigi::processEvent( LCEvent * evt ) {
155 
156 
157  LCCollectionVec *ecalcol = new LCCollectionVec(LCIO::CALORIMETERHIT);
158  LCCollectionVec *hcalcol = new LCCollectionVec(LCIO::CALORIMETERHIT);
159 
160  LCCollectionVec *relcol = new LCCollectionVec(LCIO::LCRELATION);
161 
162  LCFlagImpl flag;
163 
164  flag.setBit(LCIO::CHBIT_LONG);
165 
166  ecalcol->setFlag(flag.getFlag());
167  hcalcol->setFlag(flag.getFlag());
168 
169 
170  //
171  // * Reading Collections of ECAL Simulated Hits *
172  //
173  string initString;
174  for (unsigned int i(0); i < _ecalCollections.size(); ++i) {
175 
176  std::string colName = _ecalCollections[i] ;
177 
178  //fg: need to establish the subdetetcor part here
179  // use collection name as cellID does not seem to have that information
180  CHT::Layout caloLayout = layoutFromString( colName ) ;
181 
182  try{
183  LCCollection * col = evt->getCollection( _ecalCollections[i].c_str() ) ;
184  initString = col->getParameters().getStringVal(LCIO::CellIDEncoding);
185  int numElements = col->getNumberOfElements();
186  CellIDDecoder<SimCalorimeterHit> idDecoder( col );
187  for (int j(0); j < numElements; ++j) {
188  SimCalorimeterHit * hit = dynamic_cast<SimCalorimeterHit*>( col->getElementAt( j ) ) ;
189  float energy = hit->getEnergy();
190 
191  if (energy > _thresholdEcal) {
192  CalorimeterHitImpl * calhit = new CalorimeterHitImpl();
193  int cellid = hit->getCellID0();
194  int cellid1 = hit->getCellID1();
195  float calibr_coeff(1.);
196  int layer = idDecoder(hit)["K-1"];
197  for (unsigned int k(0); k < _ecalLayers.size(); ++k) {
198  int min,max;
199  if (k == 0)
200  min = 0;
201  else
202  min = _ecalLayers[k-1];
203  max = _ecalLayers[k];
204  if (layer >= min && layer < max) {
205  calibr_coeff = _calibrCoeffEcal[k];
206  break;
207  }
208  }
209  calhit->setCellID0(cellid);
210  calhit->setCellID1(cellid1);
211  if (_digitalEcal) {
212  calhit->setEnergy(calibr_coeff);
213  }
214  else {
215  calhit->setEnergy(calibr_coeff*energy);
216  }
217  calhit->setPosition(hit->getPosition());
218 
219  calhit->setType( CHT( CHT::em, CHT::ecal, caloLayout , layer ) );
220 
221  calhit->setRawHit(hit);
222  ecalcol->addElement(calhit);
223  LCRelationImpl *rel = new LCRelationImpl(calhit,hit,1.);
224  relcol->addElement( rel );
225  }
226 
227  }
228  }
229  catch(DataNotAvailableException &e){
230  }
231  }
232  ecalcol->parameters().setValue(LCIO::CellIDEncoding,initString);
233  evt->addCollection(ecalcol,_outputEcalCollection.c_str());
234 
235 
236  //
237  // * Reading HCAL Collections of Simulated Hits *
238  //
239 
240  for (unsigned int i(0); i < _hcalCollections.size(); ++i) {
241 
242  std::string colName = _hcalCollections[i] ;
243 
244  //fg: need to establish the subdetetcor part here
245  // use collection name as cellID does not seem to have that information
246  CHT::Layout caloLayout = layoutFromString( colName ) ;
247 
248 
249  try{
250  LCCollection * col = evt->getCollection( _hcalCollections[i].c_str() ) ;
251  initString = col->getParameters().getStringVal(LCIO::CellIDEncoding);
252  int numElements = col->getNumberOfElements();
253  CellIDDecoder<SimCalorimeterHit> idDecoder(col);
254  for (int j(0); j < numElements; ++j) {
255  SimCalorimeterHit * hit = dynamic_cast<SimCalorimeterHit*>( col->getElementAt( j ) ) ;
256  float energy = hit->getEnergy();
257 
258 
259  if (energy > _thresholdHcal) {
260  CalorimeterHitImpl * calhit = new CalorimeterHitImpl();
261  int cellid = hit->getCellID0();
262  int cellid1 = hit->getCellID1();
263  float calibr_coeff(1.);
264  int layer =idDecoder(hit)["K-1"];
265  for (unsigned int k(0); k < _hcalLayers.size(); ++k) {
266  int min,max;
267  if (k == 0)
268  min = 0;
269  else
270  min = _hcalLayers[k-1];
271  max = _hcalLayers[k];
272  if (layer >= min && layer < max) {
273  calibr_coeff = _calibrCoeffHcal[k];
274  break;
275  }
276  }
277  calhit->setCellID0(cellid);
278  calhit->setCellID1(cellid1);
279  if (_digitalHcal) {
280  calhit->setEnergy(calibr_coeff);
281  }
282  else {
283  calhit->setEnergy(calibr_coeff*energy);
284  }
285  calhit->setPosition(hit->getPosition());
286 
287  calhit->setType( CHT( CHT::had, CHT::hcal , caloLayout , layer ) );
288 
289  calhit->setRawHit(hit);
290  hcalcol->addElement(calhit);
291  LCRelationImpl *rel = new LCRelationImpl(calhit,hit,1.0);
292  relcol->addElement( rel );
293  }
294 
295  }
296  }
297  catch(DataNotAvailableException &e){
298  }
299  }
300  hcalcol->parameters().setValue(LCIO::CellIDEncoding,initString);
301  evt->addCollection(hcalcol,_outputHcalCollection.c_str());
302  evt->addCollection(relcol,_outputRelCollection.c_str());
303 
304  _nEvt++;
305 
306 }
307 
308 
309 void SimpleCaloDigi::check( LCEvent * /*evt*/ ) { }
310 
std::string _outputEcalCollection
virtual void init()
virtual void check(LCEvent *evt)
std::vector< std::string > _ecalCollections
static const float k
virtual void processEvent(LCEvent *evt)
std::vector< int > _hcalLayers
SimpleCaloDigi aSimpleCaloDigi
std::vector< int > _ecalLayers
std::string _outputRelCollection
std::string _outputHcalCollection
std::vector< std::string > _hcalCollections
virtual void processRunHeader(LCRunHeader *run)
virtual void end()
static const float e
std::vector< LCCollection * > LCCollectionVec
Definition: SiStripClus.h:55
std::vector< float > _calibrCoeffHcal
std::vector< float > _calibrCoeffEcal