All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
MokkaCaloDigi.cc
Go to the documentation of this file.
1 #include "MokkaCaloDigi.h"
2 #include <iostream>
3 #include <cmath>
4 #include <vector>
5 #ifdef MARLIN_USE_AIDA
6 #include <marlin/AIDAProcessor.h>
7 #include <AIDA/IHistogramFactory.h>
8 #include <AIDA/ICloud1D.h>
9 //#include <AIDA/IHistogram1D.h>
10 #endif
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>
16 #include <lcio.h>
17 #include <iterator>
18 #define SHIFT_M 0
19 #define SHIFT_S 3
20 #define SHIFT_I 6
21 #define SHIFT_J 15
22 #define SHIFT_K 24
23 #define SHIFT_2 30
24 #define SHIFT_1 31
25 
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
33 
34 using namespace lcio ;
35 using namespace marlin ;
36 using namespace std;
37 using namespace IMPL;
38 
39 #include <marlin/Global.h>
40 #include <gear/GEAR.h>
41 #include <gear/CalorimeterParameters.h>
42 #include <gear/LayerLayout.h>
43 
45 
46 MokkaCaloDigi::MokkaCaloDigi() : Processor("MokkaCaloDigi") {
47 
48  // modify processor description
49  _description = "Mokka digitizer..." ;
50 
51  // register steering parameters: name, description, class-variable, default value
52 
53  std::vector<std::string> ecalCollections;
54  ecalCollections.push_back(std::string("SEcal01_EcalEndcap"));
55  ecalCollections.push_back(std::string("SEcal01_EcalBarrel"));
56 
57  registerInputCollections( LCIO::SIMCALORIMETERHIT,
58  "ECALCollections" ,
59  "ECAL Collection Names" ,
61  ecalCollections);
62 
63 
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"));
68 
69  registerInputCollections( LCIO::SIMCALORIMETERHIT,
70  "HCALCollections" ,
71  "HCAL Collection Names" ,
73  hcalCollections);
74 
75 
76  registerOutputCollection( LCIO::CALORIMETERHIT,
77  "NewECALCollName" ,
78  "name for the new collection of ECAL hits" ,
80  std::string("ECAL")) ;
81 
82 
83  registerOutputCollection( LCIO::CALORIMETERHIT,
84  "NewHCALCollName" ,
85  "name for the new collection of HCAL hits" ,
87  std::string("HCAL"));
88 
89 
90  registerOutputCollection( LCIO::LCRELATION,
91  "RelationCollName" ,
92  "name for collection of relations between CalorimeterHits and SimCalorimeterHits",
94  std::string("RelationCaloHit"));
95 
96 
97  registerProcessorParameter("ECALThreshold" ,
98  "Threshold for ECAL Hits in GeV" ,
100  (float)1.0e-4);
101 
102  registerProcessorParameter("HCALThreshold" ,
103  "Threshold for HCAL Hits in GeV" ,
105  (float)4.0e-4);
106 
107  std::vector<int> ecalLayers;
108  ecalLayers.push_back(30);
109  ecalLayers.push_back(100);
110  registerProcessorParameter("ECALLayers" ,
111  "Index of ECal Layers" ,
112  _ecalLayers,
113  ecalLayers);
114 
115  std::vector<int> hcalLayers;
116  hcalLayers.push_back(100);
117  registerProcessorParameter("HCALLayers" ,
118  "Index of HCal Layers" ,
119  _hcalLayers,
120  hcalLayers);
121 
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" ,
128  calibrEcal);
129 
130  std::vector<float> calibrHcal;
131  calibrHcal.push_back(27.3);
132  registerProcessorParameter("CalibrHCAL" ,
133  "Calibration coefficients for HCAL" ,
135  calibrHcal);
136 
137  registerProcessorParameter("IfDigitalEcal" ,
138  "Digital Ecal" ,
139  _digitalEcal ,
140  0);
141 
142  registerProcessorParameter("IfDigitalHcal" ,
143  "Digital Hcal" ,
144  _digitalHcal ,
145  0);
146 }
147 
148 
150 
151  printParameters() ;
152 
153  const gear::CalorimeterParameters& pHcalBarrel = Global::GEAR->getHcalBarrelParameters();
154  const gear::CalorimeterParameters& pHcalEndcap = Global::GEAR->getHcalEndcapParameters();
155 
156  _nRun = -1 ;
157  _nEvt = 0 ;
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"));
160  _lateralPlateThickness = float(pHcalBarrel.getDoubleVal("Hcal_lateral_structure_thickness"));
161  _modulesGap = float(pHcalBarrel.getDoubleVal("Hcal_modules_gap"));
162  float staves_gap = float(pHcalBarrel.getDoubleVal("Hcal_stave_gaps"));
163  _innerHcalRadius = float(pHcalBarrel.getExtent()[0]);
164  float top_end_dim_z;
165  _numberOfHcalLayers = int(pHcalBarrel.getLayerLayout().getNLayers());
166  _hcalLayerThickness = float(pHcalBarrel.getLayerLayout().getThickness(0));
167  _hcalAbsorberThickness = float(pHcalBarrel.getLayerLayout().getAbsorberThickness(0));
168  _hcalSensitiveThickness = _hcalLayerThickness - _hcalAbsorberThickness;
169  float back_plate_thickness = float(pHcalBarrel.getDoubleVal("Hcal_back_plate_thickness"));
170  if(end_module_type == 1 ) {
171  _regularBarrelModuleLength = 2*tpc_ecal_hcalbarrel_halfz/5.-1.;
172  top_end_dim_z = 1180.0;
173  }
174  else {
175  // the 140 and the proportions comes from Tesla TDR
176  float total_z_size = 140 +
177  2 * tpc_ecal_hcalbarrel_halfz;
178  _regularBarrelModuleLength = total_z_size / 5. * 1080./1120.;
179  top_end_dim_z =
180  (total_z_size - 3 * _regularBarrelModuleLength)/2;
181  }
182 
184  _virtualCellSizeX = float(pHcalBarrel.getDoubleVal("Hcal_virtual_cell_size"));
186  float Pi = acos(-1.0);
187  float total_dim_y = _numberOfHcalLayers*_hcalLayerThickness+back_plate_thickness;
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;
194  float y_dim2_for_z = (top_end_dim_z-_regularBarrelModuleLength)*tan(Pi*39.28/180.);
195  _cellScaleX = int((float(pHcalBarrel.getLayerLayout().getCellSize0(0)+0.01))/_virtualCellSizeX);
196  _cellScaleZ = int((float(pHcalBarrel.getLayerLayout().getCellSize1(0)+0.01))/_virtualCellSizeX);
198  _newCellSizeZ = _virtualCellSizeZ * _cellScaleZ;
203 
204  for (int i = 0; i < _numberOfHcalLayers; i++) {
205  float x_width = 0;
206  float z_width = 0;
207  int id = i + 1;
208  float z = id*_hcalLayerThickness;
209  if (z < y_dim1_for_x) {
210  float x = bottom_dim_x + 2*(id*_hcalAbsorberThickness+(id-1)*_hcalSensitiveThickness)*tan(Pi/8.);
211  x_width = int(x/_virtualCellSizeX)*_virtualCellSizeX;
212  }
213  else {
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;
216  x_width = int(x/_virtualCellSizeX)*_virtualCellSizeX;
217  }
218 
219  if (z < y_dim1_for_z) {
220  z_width = _regularBarrelChamberLength;
221  }
222 
223  if (z >= y_dim1_for_z && z < (y_dim1_for_z+y_dim2_for_z)) {
224  float z =
225  _regularBarrelModuleLength-2*_lateralPlateThickness+(id*_hcalAbsorberThickness+(id-1)*_hcalSensitiveThickness-y_dim1_for_z)*(top_end_dim_z-_regularBarrelModuleLength)/y_dim2_for_z;
226  z_width = int(z/_virtualCellSizeZ)*_virtualCellSizeZ;
227  }
228 
229  if (z >= (y_dim1_for_z+y_dim2_for_z) ) {
230  float z = top_end_dim_z - 2*_lateralPlateThickness;
231  z_width = int(z/_virtualCellSizeZ)*_virtualCellSizeZ;
232  }
233 
234 
235  _endBarrelChamberLength[i] = z_width;
236  _barrelLateralWidth[i] = x_width;
237  int imax = int(x_width/_newCellSizeX);
238  float offset = imax * _newCellSizeX;
239  _barrelOffsetMaxX[i] = offset + 0.5*(x_width-offset);
240  imax = int(z_width/_newCellSizeZ);
241  offset = imax * _newCellSizeZ;
242  _endBarrelOffsetMaxZ[i] = offset + 0.5*(z_width-offset);
243 
244  }
245 
247  float offset = imax * _newCellSizeZ;
249 
250  _nModules = 7;
251  _nStaves = 8;
252  _deltaPhi = 2.*Pi/8.;
253 
254  float half_endcap_hole = float(pHcalEndcap.getExtent()[0]);
255  _startIEndcap = int ((half_endcap_hole+0.00001) / _virtualCellSizeX);
256  _startJEndcap = int ((half_endcap_hole+0.00001) / _virtualCellSizeZ);
257  _startXEndcap = _startIEndcap * _virtualCellSizeX ;
259 
260 }
261 
262 void MokkaCaloDigi::processRunHeader( LCRunHeader* /*run*/) {
263 
264  _nRun++ ;
265 }
266 
267 void MokkaCaloDigi::processEvent( LCEvent * evt ) {
268 
269  // set flag to store more information in the output file
270  LCFlagImpl flag;
271  flag.setBit(LCIO::CHBIT_LONG);
272 
273  //
274  // * Reading Collections of HCAL Simulated Hits *
275  //
276  _calorimeterHitVec.clear();
277  int numberOfZones = _nModules*_nStaves*_numberOfHcalLayers;
278  _calorimeterHitVec.resize(numberOfZones);
279  _relationCollection = new LCCollectionVec(LCIO::LCRELATION);
280 
281  float simEnergy = 0;
282 
283  for (unsigned int i=0; i < _hcalCollections.size(); ++i) {
284  try {
285  LCCollection * col = evt->getCollection( _hcalCollections[i].c_str() ) ;
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();
291  int Module=(cellid & MASK_M) >> SHIFT_M; // reed module number on it depends further calculation
292  int Stave =(cellid & MASK_S) >> SHIFT_S; // stave
293  int Layer =(cellid & MASK_K) >> SHIFT_K; // layer
294  MyHit * newHit = NULL;
295  if (Module == 0 || Module == 6) {
296  newHit = ProcessHitInEndcap( hit );
297  }
298  else {
299  newHit = ProcessHitInBarrel( hit );
300  }
301  if (newHit != NULL) {
302  newHit->hit->setType(2);
303  int sector = Layer + _numberOfHcalLayers*Stave + _numberOfHcalLayers*_nStaves*Module;
304  _calorimeterHitVec[sector].push_back( newHit );
305  }
306 
307  }
308 
309  }
310  catch(DataNotAvailableException &e){ }
311  }
312 
313  float digitizedEnergy = 0.;
314  LCCollectionVec * hcalcol = new LCCollectionVec(LCIO::CALORIMETERHIT);
315  hcalcol->setFlag(flag.getFlag());
316  for (int i=0; i<numberOfZones; ++i) {
317  int nHits = int(_calorimeterHitVec[i].size());
318  for (int iHit=0; iHit<nHits; ++iHit) {
319  MyHit * myh = _calorimeterHitVec[i][iHit];
320  CalorimeterHitImpl * calhit = myh->hit;
321 
322  float energy = calhit->getEnergy();
323  digitizedEnergy += energy;
324  if (energy > _thresholdHcal) {
325  int Cellid = calhit->getCellID0();
326  float calibr_coeff(1.);
327  int layer = Cellid >> 24;
328  for (unsigned int k(0); k < _hcalLayers.size(); ++k) {
329  int min,max;
330  if (k == 0)
331  min = 0;
332  else
333  min = _hcalLayers[k-1];
334  max = _hcalLayers[k];
335  if (layer >= min && layer < max) {
336  calibr_coeff = _calibrCoeffHcal[k];
337  break;
338  }
339  }
340  if (_digitalHcal) {
341  calhit->setEnergy(calibr_coeff);
342  }
343  else {
344  calhit->setEnergy(calibr_coeff*energy);
345  }
346  int nSimHit = myh->simHits.size();
347  float x = calhit->getPosition()[0];
348  float y = calhit->getPosition()[1];
349  float z = calhit->getPosition()[2];
350 
351  for (int iS = 0; iS < nSimHit; ++iS) {
352  float weight = 1.0;
353  SimCalorimeterHit * simHit = myh->simHits[iS];
354  LCRelationImpl * rel = new LCRelationImpl(calhit, simHit , weight);
355  _relationCollection->addElement(rel);
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)+
360  (y-y1)*(y-y1)+
361  (z-z1)*(z-z1));
362  float cutX = 0.5*(_newCellSizeX-_virtualCellSizeX) ;
363  float cutZ = 0.5*(_newCellSizeZ-_virtualCellSizeZ) ;
364 
365  float cut = sqrt(cutX*cutX+cutZ*cutZ) + 0.01;
366  if (dist > cut) {
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;
371  }
372  }
373  hcalcol->addElement( calhit );
374  }
375  else{
376  // std::cout << " >>>>>>>> deleting spurious Calohit ! " << std::endl ;
377  //fg: fix memory leak - if energy below threshold the hit is never added to the collection,
378  // thus we have to delete it !
379  delete calhit ;
380  }
381 
382  delete myh;
383  }
384  }
385 
386  // std::cout << "Initial energy = " << simEnergy
387 // << " compared to digi energy =" << digitizedEnergy << std::endl;
388 
389  //
390  // * Reading Collections of ECAL Simulated Hits *
391  //
392 
393  LCCollectionVec * ecalcol = new LCCollectionVec(LCIO::CALORIMETERHIT);
394  ecalcol->setFlag(flag.getFlag());
395 
396  for (unsigned int i(0); i < _ecalCollections.size(); ++i) {
397  try{
398  LCCollection * col = evt->getCollection( _ecalCollections[i].c_str() ) ;
399  int numElements = col->getNumberOfElements();
400 
401  for (int j(0); j < numElements; ++j) {
402  SimCalorimeterHit * hit = dynamic_cast<SimCalorimeterHit*>( col->getElementAt( j ) ) ;
403 
404 
405  float energy = hit->getEnergy();
406  if (energy > _thresholdEcal) {
407  CalorimeterHitImpl * calhit = new CalorimeterHitImpl();
408  int Cellid = hit->getCellID0();
409  float calibr_coeff(1.);
410  int layer = Cellid >> 24;
411  int type = 0;
412  for (unsigned int k(0); k < _ecalLayers.size(); ++k) {
413  int min,max;
414  if (k == 0)
415  min = 0;
416  else
417  min = _ecalLayers[k-1];
418  max = _ecalLayers[k];
419  if (layer >= min && layer < max) {
420  calibr_coeff = _calibrCoeffEcal[k];
421  type = k;
422  break;
423  }
424  }
425  calhit->setCellID0(Cellid);
426  if (_digitalEcal) {
427  calhit->setEnergy(calibr_coeff);
428  }
429  else {
430  calhit->setEnergy(calibr_coeff*energy);
431  }
432  calhit->setType(type);
433  calhit->setPosition(hit->getPosition());
434  ecalcol->addElement(calhit);
435  float weight = 1.0;
436  LCRelationImpl * rel = new LCRelationImpl(calhit,hit,weight);
437  _relationCollection->addElement( rel );
438  }
439  }
440  }
441  catch(DataNotAvailableException &e){
442  }
443  }
444 
445  evt->addCollection(ecalcol, _newCollNameECAL.c_str());
446  evt->addCollection(hcalcol, _newCollNameHCAL.c_str());
447  evt->addCollection(_relationCollection,_relationCollName.c_str());
448  _nEvt ++ ;
449 
450 } // end of event processor
451 
452 MyHit * MokkaCaloDigi::ProcessHitInBarrel( SimCalorimeterHit * hit ) {
453 
454  MyHit * newMyHit = NULL;
455 
456  int cellid = hit->getCellID0();
457  float pos[3];
458  for (int i=0;i<3;++i)
459  pos[i] = hit->getPosition()[i];
460  int Module=(cellid & MASK_M) >> SHIFT_M; // reed module number on it depends further calculation
461  int Stave=(cellid & MASK_S) >> SHIFT_S; // stave
462  int Layer=(cellid & MASK_K) >> SHIFT_K; // layer
463  //int J=(cellid & MASK_J) >> SHIFT_J; // J
464  int I=(cellid & MASK_I) >> SHIFT_I; // I
465 
466  float zBegin = 0.;
467  float chamberLength = 0.;
468  float offsetMaxZ;
469 
470  // calculation of the lower z coordinate of the sensitive part of barrel module
471  if (Module == 1) {
473  }
474  if (Module == 2) {
476  }
477  if (Module == 3) {
478  zBegin = -0.5*_regularBarrelChamberLength;
479  }
480  if (Module == 4) {
482  }
483  if (Module == 5) {
485  }
486  if (Module == 1 || Module == 5) {
487  chamberLength = _endBarrelChamberLength[Layer];
488  offsetMaxZ = _endBarrelOffsetMaxZ[Layer];
489  }
490  else {
491  chamberLength = _regularBarrelChamberLength;
492  offsetMaxZ = _regularBarrelOffsetMaxZ;
493  }
494 
495 
496  float xBegin = -0.5*_barrelLateralWidth[Layer];
497  int Inew = I / _cellScaleX;
498  int Jnew = int((pos[2] - zBegin)/ _newCellSizeZ);
499  float offsetI = (Inew+0.5) * _newCellSizeX ;
500  float offsetJ = (Jnew+0.5) * _newCellSizeZ ;
501 
502  int cellidNew=((Module<<SHIFT_M)&MASK_M)
503  | ((Stave<<SHIFT_S)&MASK_S)
504  | ((Jnew<<SHIFT_J)&MASK_J)
505  | ((Layer<<SHIFT_K)&MASK_K)
506  | ((Inew<<SHIFT_I)&MASK_I);
507 
508  int sector = Layer + _numberOfHcalLayers*Stave + _numberOfHcalLayers*_nStaves*Module;
509 
510  int iExist = 0;
511 
512  int SIZE = int(_calorimeterHitVec[sector].size());
513  for (int i=0; i<SIZE; ++i) {
514  MyHit * myh = _calorimeterHitVec[sector][i];
515  CalorimeterHitImpl * hitImpl = myh->hit;
516  int cellidImpl = hitImpl->getCellID0();
517  if (cellidNew == cellidImpl) {
518  iExist = 1;
519  float energy = hitImpl->getEnergy() + hit->getEnergy();
520  hitImpl->setEnergy( energy );
521  myh->simHits.push_back( hit );
522  break;
523  }
524  }
525 
526  if (iExist == 0) {
527  CalorimeterHitImpl * newHit = new CalorimeterHitImpl();
528  newHit->setCellID0(cellidNew);
529  newHit->setEnergy(hit->getEnergy());
530  float newPos[3];
531  newPos[1] = pos[1];
532  if (Stave > 0) {
533  float Radius = sqrt(pos[0]*pos[0]+pos[1]*pos[1]);
534  float Phi = atan2(pos[1],pos[0]);
535  Phi = Phi - Stave*_deltaPhi;
536  newPos[1] = Radius*sin(Phi);
537  }
538  newPos[0] = xBegin + offsetI ;
539  newPos[2] = zBegin + offsetJ ;
540  if (Stave > 0) {
541  float Radius = sqrt(newPos[0]*newPos[0]+newPos[1]*newPos[1]);
542  float Phi = atan2(newPos[1],newPos[0]);
543  Phi = Phi + Stave*_deltaPhi;
544  newPos[0] = Radius*cos(Phi);
545  newPos[1] = Radius*sin(Phi);
546  }
547  newHit->setPosition( newPos );
548  newMyHit = new MyHit();
549  newMyHit->hit = newHit;
550  newMyHit->simHits.push_back( hit );
551 
552 // float dist = sqrt((pos[0]-newPos[0])*(pos[0]-newPos[0])+
553 // (pos[1]-newPos[1])*(pos[1]-newPos[1])+
554 // (pos[2]-newPos[2])*(pos[2]-newPos[2]));
555 // if (dist > 0.01) {
556 // std::cout << "Layer width = " << _barrelLateralWidth[Layer] << std::endl;
557 // std::cout << I << " " << Inew << std::endl;
558 // float Radius = sqrt(pos[0]*pos[0]+pos[1]*pos[1]);
559 // float Phi = atan2(pos[1],pos[0]);
560 // Phi = Phi - Stave*_deltaPhi;
561 // float xpos = Radius*cos(Phi);
562 // float xpos1 = xBegin + offsetI ;
563 // std::cout << xpos << " " << xpos1 << std::endl;
564 // std::cout << pos[0] << " " << pos[1] << " " << pos[2] << std::endl;
565 // std::cout << newPos[0] << " " << newPos[1] << " " << newPos[2] << " " << std::endl;
566 // }
567 
568  }
569 
570 
571  return newMyHit ;
572 
573 }
574 
575 MyHit * MokkaCaloDigi::ProcessHitInEndcap(SimCalorimeterHit * hit) {
576 
577  MyHit * newMyHit = NULL;
578 
579  int cellid = hit->getCellID0();
580  float pos[3];
581  for (int i=0;i<3;++i)
582  pos[i] = hit->getPosition()[i];
583  int Module=(cellid & MASK_M) >> SHIFT_M; // reed module number on it depends further calculation
584  int Stave=(cellid & MASK_S) >> SHIFT_S; // stave
585  int Layer=(cellid & MASK_K) >> SHIFT_K; // layer
586  int J=(cellid & MASK_J) >> SHIFT_J; // J
587  int I=(cellid & MASK_I) >> SHIFT_I; // I
588 
589  int Inew = I / _cellScaleX;
590  int Jnew = J / _cellScaleZ;
591 
592  int cellidNew=((Module<<SHIFT_M)&MASK_M)
593  | ((Stave<<SHIFT_S)&MASK_S)
594  | ((Jnew<<SHIFT_J)&MASK_J)
595  | ((Layer<<SHIFT_K)&MASK_K)
596  | ((Inew<<SHIFT_I)&MASK_I);
597 
598  int sector = Layer + _numberOfHcalLayers*Stave + _numberOfHcalLayers*_nStaves*Module;
599 
600  int iExist = 0;
601 
602  int SIZE = int(_calorimeterHitVec[sector].size());
603  for (int i=0; i<SIZE; ++i) {
604  MyHit * myh = _calorimeterHitVec[sector][i];
605  CalorimeterHitImpl * hitImpl = myh->hit;
606  int cellidImpl = hitImpl->getCellID0();
607  if (cellidNew == cellidImpl) {
608  iExist = 1;
609  float energy = hitImpl->getEnergy() + hit->getEnergy();
610  hitImpl->setEnergy( energy );
611  myh->simHits.push_back( hit );
612  break;
613  }
614  }
615 
616  if (iExist == 0) {
617  CalorimeterHitImpl * newHit = new CalorimeterHitImpl();
618  newHit->setCellID0(cellidNew);
619  newHit->setEnergy(hit->getEnergy());
620  float newPos[3];
621  float offsetX = (Inew + 0.5)*_newCellSizeX;
622  float offsetZ = (Jnew + 0.5)*_newCellSizeZ;
623  if (Module == 0) {
624  if (Stave == 0) {
625  newPos[0] = - offsetZ;
626  newPos[1] = offsetX;
627  }
628  else if (Stave == 1) {
629  newPos[0] = -offsetX;
630  newPos[1] = -offsetZ;
631  }
632  else if (Stave == 2) {
633  newPos[0] = offsetZ;
634  newPos[1] = -offsetX;
635  }
636  else if (Stave == 3) {
637  newPos[0] = offsetX;
638  newPos[1] = offsetZ;
639  }
640  }
641  else {
642  if (Stave == 0) {
643  newPos[0] = offsetZ;
644  newPos[1] = offsetX;
645  }
646  else if (Stave == 1) {
647  newPos[0] = offsetX;
648  newPos[1] = -offsetZ;
649  }
650  else if (Stave == 2) {
651  newPos[0] = -offsetZ;
652  newPos[1] = -offsetX;
653  }
654  else if (Stave == 3) {
655  newPos[0] = -offsetX;
656  newPos[1] = offsetZ;
657  }
658  }
659  newPos[2] = pos[2] ;
660  newHit->setPosition( newPos );
661  newMyHit = new MyHit();
662  newMyHit->hit = newHit;
663  newMyHit->simHits.push_back( hit );
664  }
665  return newMyHit;
666 }
667 
668 
669 void MokkaCaloDigi::check( LCEvent * /*evt*/ ) {
670  // nothing to check here - could be used to fill checkplots in reconstruction processor
671 }
672 
673 
675 
676  std::cout << "MokkaCaloDigi::end() " << name()
677  << " processed " << _nEvt << " events in " << _nRun << " runs "
678  << std::endl ;
679 
680 }
681 
std::vector< std::string > _hcalCollections
std::string _relationCollName
float _regularBarrelModuleLength
float * _barrelOffsetMaxX
float _thresholdHcal
float _innerHcalRadius
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
float _hcalLayerThickness
virtual void end()
Called after data processing for clean up.
std::string _newCollNameHCAL
float _virtualCellSizeX
static const float k
#define MASK_J
virtual void check(LCEvent *evt)
float _hcalSensitiveThickness
std::vector< float > _calibrCoeffHcal
std::vector< float > _calibrCoeffEcal
std::vector< std::vector< MyHit * > > _calorimeterHitVec
float _lateralPlateThickness
#define MASK_M
float * _barrelLateralWidth
MokkaCaloDigi aMokkaCaloDigi
std::string _newCollNameECAL
static const float e
MyHit * ProcessHitInEndcap(SimCalorimeterHit *hit)
std::vector< int > _hcalLayers
CalorimeterHitImpl * hit
Definition: MokkaCaloDigi.h:74
std::vector< int > _ecalLayers
LCCollectionVec * _relationCollection
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
float _hcalAbsorberThickness
std::vector< LCCollection * > LCCollectionVec
Definition: SiStripClus.h:55
std::vector< SimCalorimeterHit * > simHits
Definition: MokkaCaloDigi.h:75
#define MASK_I
#define SHIFT_J
#define SHIFT_S
#define SHIFT_M
#define SHIFT_K
MyHit * ProcessHitInBarrel(SimCalorimeterHit *hit)
float _regularBarrelChamberLength
float _regularBarrelOffsetMaxZ
virtual void init()
Called at the begin of the job before anything is read.
#define MASK_K
float _virtualCellSizeZ
float _thresholdEcal
#define MASK_S
float * _endBarrelChamberLength
float * _endBarrelOffsetMaxZ
#define SHIFT_I
std::vector< std::string > _ecalCollections