4 #include <EVENT/LCCollection.h>
5 #include <EVENT/SimCalorimeterHit.h>
6 #include <IMPL/CalorimeterHitImpl.h>
7 #include <IMPL/LCCollectionVec.h>
8 #include <IMPL/LCFlagImpl.h>
9 #include <IMPL/LCRelationImpl.h>
10 #include <marlin/Global.h>
11 #include <gear/GEAR.h>
12 #include <gear/GearParameters.h>
13 #include <gear/CalorimeterParameters.h>
14 #include <gear/LayerLayout.h>
15 #include <EVENT/LCParameters.h>
16 #include <UTIL/CellIDDecoder.h>
22 using namespace lcio ;
23 using namespace marlin ;
28 const float pi = acos(-1.0);
36 _description =
"Performs simple digitization of sim calo hits..." ;
38 std::vector<std::string> ecalCollections;
40 ecalCollections.push_back(std::string(
"EcalBarrelCollection"));
41 ecalCollections.push_back(std::string(
"EcalEndcapCollection"));
42 ecalCollections.push_back(std::string(
"EcalRingCollection"));
44 registerInputCollections( LCIO::SIMCALORIMETERHIT,
46 "ECAL Collection Names" ,
50 std::vector<std::string> hcalCollections;
52 hcalCollections.push_back(std::string(
"HcalBarrelRegCollection"));
53 hcalCollections.push_back(std::string(
"HcalEndcapRingsCollection"));
54 hcalCollections.push_back(std::string(
"HcalEndcapsCollection"));
56 registerInputCollections( LCIO::SIMCALORIMETERHIT,
58 "HCAL Collection Names" ,
62 registerOutputCollection( LCIO::CALORIMETERHIT,
63 "ECALOutputCollection" ,
64 "ECAL Collection of real Hits" ,
66 std::string(
"ECAL")) ;
68 registerOutputCollection( LCIO::CALORIMETERHIT,
69 "HCALOutputCollection" ,
70 "HCAL Collection of real Hits" ,
72 std::string(
"HCAL")) ;
75 registerOutputCollection( LCIO::LCRELATION,
76 "RelationOutputCollection" ,
77 "CaloHit Relation Collection" ,
79 std::string(
"RelationCaloHit")) ;
81 registerProcessorParameter(
"ECALThreshold" ,
82 "Threshold for ECAL Hits in GeV" ,
86 registerProcessorParameter(
"HCALThreshold" ,
87 "Threshold for HCAL Hits in GeV" ,
92 std::vector<int> ecalLayers;
93 ecalLayers.push_back(20);
94 ecalLayers.push_back(100);
97 registerProcessorParameter(
"ECALLayers" ,
98 "Index of ECal Layers" ,
104 std::vector<int> hcalLayers;
105 hcalLayers.push_back(100);
107 registerProcessorParameter(
"HCALLayers" ,
108 "Index of HCal Layers" ,
113 std::vector<float> calibrEcal;
114 calibrEcal.push_back(40.91);
115 calibrEcal.push_back(81.81);
118 registerProcessorParameter(
"CalibrECAL" ,
119 "Calibration coefficients for ECAL" ,
124 std::vector<float> calibrHcal;
125 calibrHcal.push_back(34.8);
127 registerProcessorParameter(
"CalibrHCAL" ,
128 "Calibration coefficients for HCAL" ,
133 registerProcessorParameter(
"IfDigitalEcal" ,
139 registerProcessorParameter(
"IfDigitalHcal" ,
144 registerProcessorParameter(
"ECALGapCorrection" ,
145 "Correct for ECAL gaps" ,
149 registerProcessorParameter(
"ECAlEndcapCorrectionFactor" ,
150 "Energy correction for endcap" ,
154 registerProcessorParameter(
"ECALGapCorrectionFactor" ,
155 "Factor applied to gap correction" ,
159 registerProcessorParameter(
"ECALModuleGapCorrectionFactor" ,
160 "Factor applied to module gap correction" ,
173 CellIDDecoder<SimCalorimeterHit>::setDefaultEncoding(
"M:3,S-1:3,I:9,J:9,K-1:6") ;
184 const gear::CalorimeterParameters& pEcalBarrel = Global::GEAR->getEcalBarrelParameters();
185 const gear::CalorimeterParameters& pEcalEndcap = Global::GEAR->getEcalEndcapParameters();
188 const gear::LayerLayout& ecalBarrelLayout = pEcalBarrel.getLayerLayout();
189 const gear::LayerLayout& ecalEndcapLayout = pEcalEndcap.getLayerLayout();
194 int symmetry = pEcalBarrel.getSymmetryOrder();
201 float nFoldSymmetry =
static_cast<float>(symmetry);
202 float phi0 = pEcalBarrel.getPhi0();
203 for(
int i=0;i<symmetry;++i){
204 float phi = phi0 + i*
twopi/nFoldSymmetry;
210 for(
int i=0;i<ecalBarrelLayout.getNLayers();++i){
215 for(
int i=0;i<ecalEndcapLayout.getNLayers();++i){
231 flag.setBit(LCIO::CHBIT_LONG);
232 ecalcol->setFlag(flag.getFlag());
233 hcalcol->setFlag(flag.getFlag());
252 initString = col->getParameters().getStringVal(LCIO::CellIDEncoding);
253 int numElements = col->getNumberOfElements();
254 CellIDDecoder<SimCalorimeterHit> idDecoder( col );
255 for (
int j(0); j < numElements; ++j) {
256 SimCalorimeterHit * hit =
dynamic_cast<SimCalorimeterHit*
>( col->getElementAt( j ) ) ;
257 float energy = hit->getEnergy();
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 int stave = idDecoder(hit)[
"S-1"];
266 int module= idDecoder(hit)[
"M"];
282 if (layer >= min && layer < max) {
289 calhit->setEnergy(calibr_coeff);
295 calhit->setEnergy(calibr_coeff*energy);
298 calhit->setPosition(hit->getPosition());
299 calhit->setType((
int)0);
300 calhit->setRawHit(hit);
301 calhit->setCellID0(cellid);
302 calhit->setCellID1(cellid1);
303 ecalcol->addElement(calhit);
305 LCRelationImpl *rel =
new LCRelationImpl(calhit,hit,1.);
306 relcol->addElement( rel );
311 catch(DataNotAvailableException &
e){
320 ecalcol->parameters().setValue(LCIO::CellIDEncoding,initString);
330 initString = col->getParameters().getStringVal(LCIO::CellIDEncoding);
331 int numElements = col->getNumberOfElements();
332 CellIDDecoder<SimCalorimeterHit> idDecoder(col);
333 for (
int j(0); j < numElements; ++j) {
334 SimCalorimeterHit * hit =
dynamic_cast<SimCalorimeterHit*
>( col->getElementAt( j ) ) ;
335 float energy = hit->getEnergy();
340 CalorimeterHitImpl * calhit =
new CalorimeterHitImpl();
341 int cellid = hit->getCellID0();
342 int cellid1 = hit->getCellID1();
343 float calibr_coeff(1.);
344 int layer =idDecoder(hit)[
"K-1"];
352 if (layer >= min && layer < max) {
357 calhit->setCellID0(cellid);
358 calhit->setCellID1(cellid1);
360 calhit->setEnergy(calibr_coeff);
363 calhit->setEnergy(calibr_coeff*energy);
365 calhit->setPosition(hit->getPosition());
366 calhit->setType(
int(1));
367 calhit->setRawHit(hit);
368 hcalcol->addElement(calhit);
369 LCRelationImpl *rel =
new LCRelationImpl(calhit,hit,1.0);
370 relcol->addElement( rel );
375 catch(DataNotAvailableException &
e){
380 hcalcol->parameters().setValue(LCIO::CellIDEncoding,initString);
411 float xi = hiti->getPosition()[0];
412 float yi = hiti->getPosition()[1];
413 float zi = hiti->getPosition()[2];
418 float xj = hitj->getPosition()[0];
419 float yj = hitj->getPosition()[1];
420 float zj = hitj->getPosition()[2];
421 float dz = fabs(zi-zj);
445 if( dz > zmin && dz < zmax && dt < tminm )zgap =
true;
446 if( dz < zminm && dt > tmin && dt < tmax )tgap =
true;
447 if( dz > zmin && dz < zmax && dt > tmin && dt < tmax )ztgap=
true;
449 if(modulei!=modulej){
457 if(zgap||tgap||ztgap||mgap){
464 float ei = hiti->getEnergy()*ecor;
465 float ej = hitj->getEnergy()*ecor;
472 float dx = fabs(xi-xj);
473 float dy = fabs(yi-yj);
485 if(dx > xmin && dx < xmax && dy < yminm )xgap =
true;
486 if(dx < xminm && dy > ymin && dy < ymax )ygap =
true;
487 if(dx > xmin && dx < xmax && dy > ymin && dy < ymax )xygap=
true;
489 if(xgap||ygap||xygap){
496 hiti->setEnergy( hiti->getEnergy()*ecor );
497 hitj->setEnergy( hitj->getEnergy()*ecor );
std::vector< std::string > _ecalCollections
float _ecalModuleGapCorrectionFactor
float _ecalEndcapCorrectionFactor
float _ecalGapCorrectionFactor
std::vector< float > _calibrCoeffHcal
std::vector< int > _hcalLayers
virtual void fillECALGaps()
float _barrelPixelSizeT[MAX_LAYERS]
std::string _outputHcalCollection
virtual void check(LCEvent *evt)
std::vector< float > _calibrCoeffEcal
std::vector< int > _calHitsByStaveLayerModule[MAX_STAVES][MAX_LAYERS]
float _barrelPixelSizeZ[MAX_LAYERS]
std::vector< int > _ecalLayers
std::vector< std::string > _hcalCollections
float _endcapPixelSizeY[MAX_LAYERS]
std::vector< LCCollection * > LCCollectionVec
std::string _outputRelCollection
std::vector< CalorimeterHitImpl * > _calHitsByStaveLayer[MAX_STAVES][MAX_LAYERS]
virtual void processRunHeader(LCRunHeader *run)
std::string _outputEcalCollection
float _barrelStaveDir[MAX_STAVES][2]
virtual void processEvent(LCEvent *evt)
float _endcapPixelSizeX[MAX_LAYERS]