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>
20 #include "CalorimeterHitType.h"
23 using namespace lcio ;
24 using namespace marlin ;
29 const float pi = acos(-1.0);
36 _description =
"Performs simple digitization of sim calo hits..." ;
38 std::vector<std::string> ecalCollections;
39 ecalCollections.push_back(std::string(
"EcalBarrelCollection"));
40 ecalCollections.push_back(std::string(
"EcalEndcapCollection"));
41 ecalCollections.push_back(std::string(
"EcalRingCollection"));
42 registerInputCollections( LCIO::SIMCALORIMETERHIT,
44 "ECAL Collection Names" ,
48 std::vector<std::string> hcalCollections;
49 hcalCollections.push_back(std::string(
"HcalBarrelRegCollection"));
50 hcalCollections.push_back(std::string(
"HcalEndcapRingsCollection"));
51 hcalCollections.push_back(std::string(
"HcalEndcapsCollection"));
52 registerInputCollections( LCIO::SIMCALORIMETERHIT,
54 "HCAL Collection Names" ,
65 registerOutputCollection( LCIO::CALORIMETERHIT,
66 "ECALOutputCollection0" ,
67 "ECAL Collection of real Hits" ,
69 std::string(
"ECALBarrel") );
72 registerOutputCollection( LCIO::CALORIMETERHIT,
73 "ECALOutputCollection1" ,
74 "ECAL Collection of real Hits" ,
76 std::string(
"ECALEndcap") );
78 registerOutputCollection( LCIO::CALORIMETERHIT,
79 "ECALOutputCollection2" ,
80 "ECAL Collection of real Hits" ,
82 std::string(
"ECALOther") ) ;
84 registerOutputCollection( LCIO::CALORIMETERHIT,
85 "HCALOutputCollection0" ,
86 "HCAL Collection of real Hits" ,
88 std::string(
"HCALBarrel") );
90 registerOutputCollection( LCIO::CALORIMETERHIT,
91 "HCALOutputCollection1" ,
92 "HCAL Collection of real Hits" ,
94 std::string(
"HCALEndcap") );
96 registerOutputCollection( LCIO::CALORIMETERHIT,
97 "HCALOutputCollection2" ,
98 "HCAL Collection of real Hits" ,
100 std::string(
"HCALOther") ) ;
102 registerOutputCollection( LCIO::LCRELATION,
103 "RelationOutputCollection" ,
104 "CaloHit Relation Collection" ,
106 std::string(
"RelationCaloHit")) ;
108 registerProcessorParameter(
"ECALThreshold" ,
109 "Threshold for ECAL Hits in GeV" ,
115 std::vector<float> hcalThresholds;
116 hcalThresholds.push_back(0.00004);
117 registerProcessorParameter(
"HCALThreshold" ,
118 "Threshold for HCAL Hits in GeV" ,
123 std::vector<int> ecalLayers;
124 ecalLayers.push_back(20);
125 ecalLayers.push_back(100);
128 registerProcessorParameter(
"ECALLayers" ,
129 "Index of ECal Layers" ,
135 std::vector<int> hcalLayers;
136 hcalLayers.push_back(100);
138 registerProcessorParameter(
"HCALLayers" ,
139 "Index of HCal Layers" ,
144 std::vector<float> calibrEcal;
145 calibrEcal.push_back(40.91);
146 calibrEcal.push_back(81.81);
149 registerProcessorParameter(
"CalibrECAL" ,
150 "Calibration coefficients for ECAL" ,
155 std::vector<float> calibrHcal;
156 calibrHcal.push_back(34.8);
158 registerProcessorParameter(
"CalibrHCAL" ,
159 "Calibration coefficients for HCAL" ,
164 registerProcessorParameter(
"IfDigitalEcal" ,
170 registerProcessorParameter(
"IfDigitalHcal" ,
175 registerProcessorParameter(
"ECALGapCorrection" ,
176 "Correct for ECAL gaps" ,
180 registerProcessorParameter(
"ECALEndcapCorrectionFactor" ,
181 "Energy correction for ECAL endcap" ,
185 registerProcessorParameter(
"HCALEndcapCorrectionFactor" ,
186 "Energy correction for HCAL endcap" ,
190 registerProcessorParameter(
"ECALGapCorrectionFactor" ,
191 "Factor applied to gap correction" ,
195 registerProcessorParameter(
"ECALModuleGapCorrectionFactor" ,
196 "Factor applied to module gap correction" ,
202 registerProcessorParameter(
"CellIDLayerString" ,
203 "name of the part of the cellID that holds the layer" ,
208 registerProcessorParameter(
"CellIDModuleString" ,
209 "name of the part of the cellID that holds the module" ,
213 registerProcessorParameter(
"CellIDStaveString" ,
214 "name of the part of the cellID that holds the stave" ,
228 CellIDDecoder<SimCalorimeterHit>::setDefaultEncoding(
"M:3,S-1:3,I:9,J:9,K-1:6") ;
231 const gear::CalorimeterParameters& pEcalBarrel = Global::GEAR->getEcalBarrelParameters();
232 const gear::CalorimeterParameters& pEcalEndcap = Global::GEAR->getEcalEndcapParameters();
235 const gear::LayerLayout& ecalBarrelLayout = pEcalBarrel.getLayerLayout();
236 const gear::LayerLayout& ecalEndcapLayout = pEcalEndcap.getLayerLayout();
241 int symmetry = pEcalBarrel.getSymmetryOrder();
248 float nFoldSymmetry =
static_cast<float>(symmetry);
249 float phi0 = pEcalBarrel.getPhi0();
250 for(
int i=0;i<symmetry;++i){
251 float phi = phi0 + i*
twopi/nFoldSymmetry;
257 for(
int i=0;i<ecalBarrelLayout.getNLayers();++i){
262 for(
int i=0;i<ecalEndcapLayout.getNLayers();++i){
285 flag.setBit(LCIO::CHBIT_LONG);
296 CHT::Layout caloLayout = layoutFromString( colName ) ;
300 string initString = col->getParameters().getStringVal(LCIO::CellIDEncoding);
302 CellIDDecoder<SimCalorimeterHit> idDecoder( col );
306 ecalcol->setFlag(flag.getFlag());
323 int numElements = col->getNumberOfElements();
324 for (
int j(0); j < numElements; ++j) {
325 SimCalorimeterHit * hit =
dynamic_cast<SimCalorimeterHit*
>( col->getElementAt( j ) ) ;
333 float energy = hit->getEnergy();
335 streamlog_out( DEBUG0 ) <<
" Hit energy " << energy <<
" in cellID : " << idDecoder( hit ).valueString() << std::endl;
339 CalorimeterHitImpl * calhit =
new CalorimeterHitImpl();
340 int cellid = hit->getCellID0();
341 int cellid1 = hit->getCellID1();
342 float calibr_coeff(1.);
343 int layer = idDecoder(hit)[ layerIndex ];
344 int stave = idDecoder(hit)[ staveIndex ];
345 int module= idDecoder(hit)[ moduleIndex ];
361 if (layer >= min && layer < max) {
368 calhit->setEnergy(calibr_coeff);
374 calhit->setEnergy(calibr_coeff*energy);
377 calhit->setPosition(hit->getPosition());
379 calhit->setType( CHT( CHT::em, CHT::ecal, caloLayout , layer ) );
381 calhit->setRawHit(hit);
382 calhit->setCellID0(cellid);
383 calhit->setCellID1(cellid1);
384 ecalcol->addElement(calhit);
386 LCRelationImpl *rel =
new LCRelationImpl(calhit,hit,1.);
387 relcol->addElement( rel );
393 ecalcol->parameters().setValue(LCIO::CellIDEncoding,initString);
396 catch(DataNotAvailableException &
e){
409 CHT::Layout caloLayout = layoutFromString( colName ) ;
415 string initString = col->getParameters().getStringVal(LCIO::CellIDEncoding);
416 int numElements = col->getNumberOfElements();
417 CellIDDecoder<SimCalorimeterHit> idDecoder(col);
419 hcalcol->setFlag(flag.getFlag());
420 for (
int j(0); j < numElements; ++j) {
422 SimCalorimeterHit * hit =
dynamic_cast<SimCalorimeterHit*
>( col->getElementAt( j ) ) ;
425 float energy = hit->getEnergy();
427 streamlog_out( DEBUG0 ) <<
" Hit energy " << energy <<
" in cellID : " << idDecoder( hit ).valueString() << std::endl;
430 CalorimeterHitImpl * calhit =
new CalorimeterHitImpl();
431 int cellid = hit->getCellID0();
432 int cellid1 = hit->getCellID1();
433 float calibr_coeff(1.);
435 int layer =idDecoder(hit)[ layerIndex ];
442 for(
unsigned int ithresh=1;ithresh<
_thresholdHcal.size();ithresh++){
447 streamlog_out(ERROR) <<
" Semi-digital level " << ilevel <<
" greater than number of HCAL Calibration Constants (" <<
_calibrCoeffHcal.size() <<
")" << std::endl;
459 if (layer >= min && layer < max) {
466 calhit->setCellID0(cellid);
467 calhit->setCellID1(cellid1);
469 calhit->setEnergy(calibr_coeff);
472 calhit->setEnergy(calibr_coeff*energy);
477 calhit->setPosition(hit->getPosition());
479 calhit->setType( CHT( CHT::had, CHT::hcal , caloLayout , layer ) );
482 calhit->setRawHit(hit);
483 hcalcol->addElement(calhit);
484 LCRelationImpl *rel =
new LCRelationImpl(calhit,hit,1.0);
485 relcol->addElement( rel );
490 hcalcol->parameters().setValue(LCIO::CellIDEncoding,initString);
493 catch(DataNotAvailableException &
e){
526 float xi = hiti->getPosition()[0];
527 float yi = hiti->getPosition()[1];
528 float zi = hiti->getPosition()[2];
533 float xj = hitj->getPosition()[0];
534 float yj = hitj->getPosition()[1];
535 float zj = hitj->getPosition()[2];
536 float dz = fabs(zi-zj);
560 if( dz > zmin && dz < zmax && dt < tminm )zgap =
true;
561 if( dz < zminm && dt > tmin && dt < tmax )tgap =
true;
562 if( dz > zmin && dz < zmax && dt > tmin && dt < tmax )ztgap=
true;
564 if(modulei!=modulej){
572 if(zgap||tgap||ztgap||mgap){
579 float ei = hiti->getEnergy()*ecor;
580 float ej = hitj->getEnergy()*ecor;
587 float dx = fabs(xi-xj);
588 float dy = fabs(yi-yj);
595 float pixsizex, pixsizey;
604 float xmin = 1.0*pixsizex+
slop;
605 float xminm = 1.0*pixsizex-
slop;
606 float xmax = 2.0*pixsizex-
slop;
607 float ymin = 1.0*pixsizey+
slop;
608 float yminm = 1.0*pixsizey-
slop;
609 float ymax = 2.0*pixsizey-
slop;
611 if(dx > xmin && dx < xmax && dy < yminm )xgap =
true;
612 if(dx < xminm && dy > ymin && dy < ymax )ygap =
true;
613 if(dx > xmin && dx < xmax && dy > ymin && dy < ymax )xygap=
true;
615 if(xgap||ygap||xygap){
617 streamlog_out( DEBUG0 ) <<
"NewLDCCaloDigi found endcap gap, adjusting energy! " << xgap <<
" " << ygap <<
" " << xygap <<
" , " << il << endl;
618 streamlog_out( DEBUG0 ) <<
"stave " << is <<
" layer " << il << endl;
619 streamlog_out( DEBUG0 ) <<
" dx, dy " << dx<<
" " << dy <<
" , sizes = " << pixsizex <<
" " << pixsizey << endl;
620 streamlog_out( DEBUG0 ) <<
" xmin... " << xmin <<
" " << xminm <<
" " << xmax <<
" ymin... " << ymin <<
" " << yminm <<
" " << ymax << endl;
625 if(xgap)ecor = 1.+f*(dx - pixsizex)/2./pixsizex;
626 if(ygap)ecor = 1.+f*(dy - pixsizey)/2./pixsizey;
627 if(xygap)ecor= 1.+f*(dx - pixsizex)*(dy - pixsizey)/4./pixsizex/pixsizey;
629 streamlog_out( DEBUG0 ) <<
"correction factor = " << ecor << endl;
631 hiti->setEnergy( hiti->getEnergy()*ecor );
632 hitj->setEnergy( hitj->getEnergy()*ecor );
float _barrelStaveDir[MAX_STAVES][2]
float _barrelPixelSizeT[MAX_LAYERS]
float _ecalEndcapCorrectionFactor
std::string _cellIDStaveString
float _hcalEndcapCorrectionFactor
virtual void processRunHeader(LCRunHeader *run)
std::vector< std::string > _outputEcalCollections
std::vector< int > _ecalLayers
std::vector< CalorimeterHitImpl * > _calHitsByStaveLayer[MAX_STAVES][MAX_LAYERS]
float _endcapPixelSizeY[MAX_LAYERS]
virtual void processEvent(LCEvent *evt)
std::string _cellIDModuleString
float _ecalModuleGapCorrectionFactor
std::vector< int > _hcalLayers
float _endcapPixelSizeX[MAX_LAYERS]
virtual void fillECALGaps()
std::vector< int > _calHitsByStaveLayerModule[MAX_STAVES][MAX_LAYERS]
std::string _cellIDLayerString
std::vector< LCCollection * > LCCollectionVec
virtual void check(LCEvent *evt)
float _ecalGapCorrectionFactor
std::vector< std::string > _ecalCollections
std::vector< float > _calibrCoeffHcal
NewLDCCaloDigi aNewLDCCaloDigi
std::vector< std::string > _hcalCollections
float _barrelPixelSizeZ[MAX_LAYERS]
std::string _outputRelCollection
std::vector< float > _calibrCoeffEcal
std::vector< std::string > _outputHcalCollections
std::vector< float > _thresholdHcal