6 #include <marlin/AIDAProcessor.h>
7 #include <AIDA/IHistogramFactory.h>
8 #include <AIDA/ICloud1D.h>
11 #include <EVENT/LCCollection.h>
12 #include <EVENT/CalorimeterHit.h>
13 #include <EVENT/SimCalorimeterHit.h>
14 #include <IMPL/LCRelationImpl.h>
15 #include <IMPL/LCFlagImpl.h>
26 #define MASK_M (unsigned int) 0x00000007
27 #define MASK_S (unsigned int) 0x00000038
28 #define MASK_I (unsigned int) 0x00007FC0
29 #define MASK_J (unsigned int) 0x00FF8000
30 #define MASK_K (unsigned int) 0x3F000000
31 #define MASK_2 (unsigned int) 0x40000000
32 #define MASK_1 (unsigned int) 0x80000000
34 using namespace lcio ;
35 using namespace marlin ;
39 #include <marlin/Global.h>
40 #include <gear/GEAR.h>
41 #include <gear/CalorimeterParameters.h>
42 #include <gear/LayerLayout.h>
49 _description =
"Mokka digitizer..." ;
53 std::vector<std::string> ecalCollections;
54 ecalCollections.push_back(std::string(
"SEcal01_EcalEndcap"));
55 ecalCollections.push_back(std::string(
"SEcal01_EcalBarrel"));
57 registerInputCollections( LCIO::SIMCALORIMETERHIT,
59 "ECAL Collection Names" ,
64 std::vector<std::string> hcalCollections;
65 hcalCollections.push_back(std::string(
"SHcal01_HcalBarrelEnd"));
66 hcalCollections.push_back(std::string(
"SHcal01_HcalBarrelReg"));
67 hcalCollections.push_back(std::string(
"SHcal01_HcalEndCaps"));
69 registerInputCollections( LCIO::SIMCALORIMETERHIT,
71 "HCAL Collection Names" ,
76 registerOutputCollection( LCIO::CALORIMETERHIT,
78 "name for the new collection of ECAL hits" ,
80 std::string(
"ECAL")) ;
83 registerOutputCollection( LCIO::CALORIMETERHIT,
85 "name for the new collection of HCAL hits" ,
90 registerOutputCollection( LCIO::LCRELATION,
92 "name for collection of relations between CalorimeterHits and SimCalorimeterHits",
94 std::string(
"RelationCaloHit"));
97 registerProcessorParameter(
"ECALThreshold" ,
98 "Threshold for ECAL Hits in GeV" ,
102 registerProcessorParameter(
"HCALThreshold" ,
103 "Threshold for HCAL Hits in GeV" ,
107 std::vector<int> ecalLayers;
108 ecalLayers.push_back(30);
109 ecalLayers.push_back(100);
110 registerProcessorParameter(
"ECALLayers" ,
111 "Index of ECal Layers" ,
115 std::vector<int> hcalLayers;
116 hcalLayers.push_back(100);
117 registerProcessorParameter(
"HCALLayers" ,
118 "Index of HCal Layers" ,
122 std::vector<float> calibrEcal;
123 calibrEcal.push_back(31.3);
124 calibrEcal.push_back(83.0);
125 registerProcessorParameter(
"CalibrECAL" ,
126 "Calibration coefficients for ECAL" ,
130 std::vector<float> calibrHcal;
131 calibrHcal.push_back(27.3);
132 registerProcessorParameter(
"CalibrHCAL" ,
133 "Calibration coefficients for HCAL" ,
137 registerProcessorParameter(
"IfDigitalEcal" ,
142 registerProcessorParameter(
"IfDigitalHcal" ,
153 const gear::CalorimeterParameters& pHcalBarrel = Global::GEAR->getHcalBarrelParameters();
154 const gear::CalorimeterParameters& pHcalEndcap = Global::GEAR->getHcalEndcapParameters();
158 int end_module_type = pHcalBarrel.getIntVal(
"Hcal_barrel_end_module_type");
159 float tpc_ecal_hcalbarrel_halfz = float(pHcalBarrel.getDoubleVal(
"TPC_Ecal_Hcal_barrel_halfZ"));
161 _modulesGap = float(pHcalBarrel.getDoubleVal(
"Hcal_modules_gap"));
162 float staves_gap = float(pHcalBarrel.getDoubleVal(
"Hcal_stave_gaps"));
169 float back_plate_thickness = float(pHcalBarrel.getDoubleVal(
"Hcal_back_plate_thickness"));
170 if(end_module_type == 1 ) {
172 top_end_dim_z = 1180.0;
176 float total_z_size = 140 +
177 2 * tpc_ecal_hcalbarrel_halfz;
186 float Pi = acos(-1.0);
188 float module_radius = _innerHcalRadius + total_dim_y ;
189 float y_dim2_for_x = module_radius - module_radius*cos(Pi/8.);
190 float y_dim1_for_x = total_dim_y - y_dim2_for_x;
191 float bottom_dim_x = 2.*_innerHcalRadius*tan(Pi/8.)-staves_gap;
192 float middle_dim_x = bottom_dim_x + 2*y_dim1_for_x*tan(Pi/8.);
193 float y_dim1_for_z = 134.8;
209 if (z < y_dim1_for_x) {
210 float x = bottom_dim_x + 2*(
id*_hcalAbsorberThickness+(
id-1)*_hcalSensitiveThickness)*tan(Pi/8.);
214 float x = middle_dim_x -2.*(
id*_hcalAbsorberThickness+(
id-1)*_hcalSensitiveThickness - y_dim1_for_x)/tan(Pi/8.)
215 - 2*_hcalSensitiveThickness/tan(Pi/8.) -2*back_plate_thickness;
219 if (z < y_dim1_for_z) {
223 if (z >= y_dim1_for_z && z < (y_dim1_for_z+y_dim2_for_z)) {
229 if (z >= (y_dim1_for_z+y_dim2_for_z) ) {
254 float half_endcap_hole = float(pHcalEndcap.getExtent()[0]);
256 _startJEndcap = int ((half_endcap_hole+0.00001) / _virtualCellSizeZ);
271 flag.setBit(LCIO::CHBIT_LONG);
286 int numElements = col->getNumberOfElements();
287 for (
int j(0); j < numElements; ++j) {
288 SimCalorimeterHit * hit =
dynamic_cast<SimCalorimeterHit*
>( col->getElementAt( j ) ) ;
289 simEnergy += hit->getEnergy();
290 int cellid = hit->getCellID0();
294 MyHit * newHit = NULL;
295 if (Module == 0 || Module == 6) {
301 if (newHit != NULL) {
302 newHit->
hit->setType(2);
303 int sector = Layer + _numberOfHcalLayers*Stave + _numberOfHcalLayers*
_nStaves*Module;
310 catch(DataNotAvailableException &
e){ }
313 float digitizedEnergy = 0.;
315 hcalcol->setFlag(flag.getFlag());
316 for (
int i=0; i<numberOfZones; ++i) {
318 for (
int iHit=0; iHit<nHits; ++iHit) {
320 CalorimeterHitImpl * calhit = myh->
hit;
322 float energy = calhit->getEnergy();
323 digitizedEnergy += energy;
325 int Cellid = calhit->getCellID0();
326 float calibr_coeff(1.);
327 int layer = Cellid >> 24;
335 if (layer >= min && layer < max) {
341 calhit->setEnergy(calibr_coeff);
344 calhit->setEnergy(calibr_coeff*energy);
346 int nSimHit = myh->
simHits.size();
347 float x = calhit->getPosition()[0];
348 float y = calhit->getPosition()[1];
349 float z = calhit->getPosition()[2];
351 for (
int iS = 0; iS < nSimHit; ++iS) {
353 SimCalorimeterHit * simHit = myh->
simHits[iS];
354 LCRelationImpl * rel =
new LCRelationImpl(calhit, simHit , weight);
356 float x1 = simHit->getPosition()[0];
357 float y1 = simHit->getPosition()[1];
358 float z1 = simHit->getPosition()[2];
359 float dist = sqrt((x-x1)*(x-x1)+
365 float cut = sqrt(cutX*cutX+cutZ*cutZ) + 0.01;
367 std::cout <<
"WARNING ==> " << std::endl;
368 std::cout <<
"Distance = " << dist <<
" > " << cut << std::endl;
369 std::cout << x <<
" " << y <<
" " << z << std::endl;
370 std::cout << x1 <<
" " << y1 <<
" " << z1 << std::endl;
373 hcalcol->addElement( calhit );
394 ecalcol->setFlag(flag.getFlag());
399 int numElements = col->getNumberOfElements();
401 for (
int j(0); j < numElements; ++j) {
402 SimCalorimeterHit * hit =
dynamic_cast<SimCalorimeterHit*
>( col->getElementAt( j ) ) ;
405 float energy = hit->getEnergy();
407 CalorimeterHitImpl * calhit =
new CalorimeterHitImpl();
408 int Cellid = hit->getCellID0();
409 float calibr_coeff(1.);
410 int layer = Cellid >> 24;
419 if (layer >= min && layer < max) {
425 calhit->setCellID0(Cellid);
427 calhit->setEnergy(calibr_coeff);
430 calhit->setEnergy(calibr_coeff*energy);
432 calhit->setType(type);
433 calhit->setPosition(hit->getPosition());
434 ecalcol->addElement(calhit);
436 LCRelationImpl * rel =
new LCRelationImpl(calhit,hit,weight);
441 catch(DataNotAvailableException &
e){
454 MyHit * newMyHit = NULL;
456 int cellid = hit->getCellID0();
458 for (
int i=0;i<3;++i)
459 pos[i] = hit->getPosition()[i];
467 float chamberLength = 0.;
486 if (Module == 1 || Module == 5) {
513 for (
int i=0; i<SIZE; ++i) {
515 CalorimeterHitImpl * hitImpl = myh->
hit;
516 int cellidImpl = hitImpl->getCellID0();
517 if (cellidNew == cellidImpl) {
519 float energy = hitImpl->getEnergy() + hit->getEnergy();
520 hitImpl->setEnergy( energy );
527 CalorimeterHitImpl * newHit =
new CalorimeterHitImpl();
528 newHit->setCellID0(cellidNew);
529 newHit->setEnergy(hit->getEnergy());
533 float Radius = sqrt(pos[0]*pos[0]+pos[1]*pos[1]);
534 float Phi = atan2(pos[1],pos[0]);
536 newPos[1] = Radius*sin(Phi);
538 newPos[0] = xBegin + offsetI ;
539 newPos[2] = zBegin + offsetJ ;
541 float Radius = sqrt(newPos[0]*newPos[0]+newPos[1]*newPos[1]);
542 float Phi = atan2(newPos[1],newPos[0]);
544 newPos[0] = Radius*cos(Phi);
545 newPos[1] = Radius*sin(Phi);
547 newHit->setPosition( newPos );
548 newMyHit =
new MyHit();
549 newMyHit->
hit = newHit;
550 newMyHit->
simHits.push_back( hit );
577 MyHit * newMyHit = NULL;
579 int cellid = hit->getCellID0();
581 for (
int i=0;i<3;++i)
582 pos[i] = hit->getPosition()[i];
603 for (
int i=0; i<SIZE; ++i) {
605 CalorimeterHitImpl * hitImpl = myh->
hit;
606 int cellidImpl = hitImpl->getCellID0();
607 if (cellidNew == cellidImpl) {
609 float energy = hitImpl->getEnergy() + hit->getEnergy();
610 hitImpl->setEnergy( energy );
617 CalorimeterHitImpl * newHit =
new CalorimeterHitImpl();
618 newHit->setCellID0(cellidNew);
619 newHit->setEnergy(hit->getEnergy());
625 newPos[0] = - offsetZ;
628 else if (Stave == 1) {
629 newPos[0] = -offsetX;
630 newPos[1] = -offsetZ;
632 else if (Stave == 2) {
634 newPos[1] = -offsetX;
636 else if (Stave == 3) {
646 else if (Stave == 1) {
648 newPos[1] = -offsetZ;
650 else if (Stave == 2) {
651 newPos[0] = -offsetZ;
652 newPos[1] = -offsetX;
654 else if (Stave == 3) {
655 newPos[0] = -offsetX;
660 newHit->setPosition( newPos );
661 newMyHit =
new MyHit();
662 newMyHit->
hit = newHit;
663 newMyHit->
simHits.push_back( hit );
676 std::cout <<
"MokkaCaloDigi::end() " << name()
677 <<
" processed " <<
_nEvt <<
" events in " <<
_nRun <<
" runs "
std::vector< std::string > _hcalCollections
std::string _relationCollName
float _regularBarrelModuleLength
float * _barrelOffsetMaxX
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
float _hcalLayerThickness
virtual void end()
Called after data processing for clean up.
std::string _newCollNameHCAL
virtual void check(LCEvent *evt)
float _hcalSensitiveThickness
std::vector< float > _calibrCoeffHcal
std::vector< float > _calibrCoeffEcal
std::vector< std::vector< MyHit * > > _calorimeterHitVec
float _lateralPlateThickness
float * _barrelLateralWidth
MokkaCaloDigi aMokkaCaloDigi
std::string _newCollNameECAL
MyHit * ProcessHitInEndcap(SimCalorimeterHit *hit)
std::vector< int > _hcalLayers
std::vector< int > _ecalLayers
LCCollectionVec * _relationCollection
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
float _hcalAbsorberThickness
std::vector< LCCollection * > LCCollectionVec
std::vector< SimCalorimeterHit * > simHits
MyHit * ProcessHitInBarrel(SimCalorimeterHit *hit)
float _regularBarrelChamberLength
float _regularBarrelOffsetMaxZ
virtual void init()
Called at the begin of the job before anything is read.
float * _endBarrelChamberLength
float * _endBarrelOffsetMaxZ
std::vector< std::string > _ecalCollections