All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
G2CD.cc
Go to the documentation of this file.
1 #include <G2CD.hh>
2 #include <EVENT/LCCollection.h>
3 #include <EVENT/MCParticle.h>
4 #include <EVENT/SimCalorimeterHit.h>
5 #include <EVENT/CalorimeterHit.h>
6 #include <EVENT/LCFloatVec.h>
7 #include <EVENT/LCParameters.h>
8 #include <IMPL/CalorimeterHitImpl.h>
9 #include <IMPL/LCCollectionVec.h>
10 #include <IMPL/LCFlagImpl.h>
11 #include <IMPL/LCRelationImpl.h>
12 #include "UTIL/CellIDDecoder.h"
13 
14 #include <limits.h>
15 #include <string>
16 #include <iostream>
17 #include <cmath>
18 #include <stdexcept>
19 #include <sstream>
20 
21 #include <TFile.h>
22 #include <TTree.h>
23 #include <Rtypes.h>
24 #include <TMath.h>
25 #include <TF1.h>
26 #include <TMath.h>
27 #include <TRandom.h>
28 #include <TVector3.h>
29 
30 using namespace std;
31 using namespace lcio ;
32 using namespace marlin ;
33 
34 const float pi = acos(-1.0);
35 
36 struct DigiHit {
39  float digihitCharge;
42  float PosX;
43  float PosY;
44  float PosZ;
46  float ChargeShare;
47  SimCalorimeterHit * LeadSimCaloHit;
48 } ;
49 
50 std::map <int, std::pair<float, float> >WeightVector;
51 
52 float ChanceOfKink = 0.1;
53 float KinkHitChargeBoost = 2.2;
54 
57  : Processor("G2CD"),
58  _output(0)
59 {
60  _description = "Gaseous Calorimeter Digitizer: take 1mm Simulated Hits as input";
61 
62  std::vector<std::string> ecalCollections;
63  ecalCollections.push_back(std::string("EcalBarrelSiliconCollection"));
64  ecalCollections.push_back(std::string("EcalEndcapSiliconCollection"));
65  ecalCollections.push_back(std::string("EcalEndcapRingCollection"));
66  registerInputCollections( LCIO::SIMCALORIMETERHIT,
67  "ECALCollections" ,
68  "Input ECAL Hits Collection Names" ,
70  ecalCollections);
71 
72  std::vector<std::string> outputEcalCollections;
73  outputEcalCollections.push_back(std::string("ECALBarrel"));
74  outputEcalCollections.push_back(std::string("ECALEndcap"));
75  outputEcalCollections.push_back(std::string("ECALOther"));
76  registerProcessorParameter("DigiECALCollection" ,
77  "Name of Digitized ECAL Hit Collections" ,
79  outputEcalCollections);
80 
81  std::vector<float> calibrEcal;
82  calibrEcal.push_back(40.91);
83  calibrEcal.push_back(81.81);
84  registerProcessorParameter("CalibrECAL" ,
85  "Calibration coefficients for ECAL" ,
87  calibrEcal);
88 
89  registerProcessorParameter("NumThinEcalLayer" ,
90  "Num of thiner Ecal layers" ,
92  20);
93 
94  registerProcessorParameter("ECALThreshold" ,
95  "Threshold for ECAL Hits in GeV" ,
97  (float)5.0e-5);
98 
99  std::vector<std::string> hcalCollections;
100  hcalCollections.push_back(std::string("HcalBarrelRegCollection"));
101  hcalCollections.push_back(std::string("HcalEndcapsCollection"));
102  hcalCollections.push_back(std::string("HcalEndcapRingsCollection"));
103  registerInputCollections( LCIO::SIMCALORIMETERHIT,
104  "HCALCollections" ,
105  "HCAL Collection Names" ,
107  hcalCollections);
108 
109  std::vector<std::string> outputHcalCollections;
110  outputHcalCollections.push_back(std::string("HCALBarrel"));
111  outputHcalCollections.push_back(std::string("HCALEndcap"));
112  outputHcalCollections.push_back(std::string("HCALOther"));
113  registerProcessorParameter("DigiHCALCollection" ,
114  "Name of Digitized HCAL Hit Collections" ,
116  outputHcalCollections);
117 
118  std::vector<float> ChargeSpatialDistri;
119  ChargeSpatialDistri.push_back(0.1);
120  ChargeSpatialDistri.push_back(0.2);
121  ChargeSpatialDistri.push_back(0.4);
122  ChargeSpatialDistri.push_back(0.2);
123  ChargeSpatialDistri.push_back(0.1);
124  registerProcessorParameter("ChargeSpatialDistribution" ,
125  "Spactial Distribution of MIP charge X*Y;" ,
127  ChargeSpatialDistri);
128 
129  std::vector<int> ShowerPositionShiftID;
130  ShowerPositionShiftID.push_back(0);
131  ShowerPositionShiftID.push_back(0);
132  ShowerPositionShiftID.push_back(0);
133  registerProcessorParameter("PositionShiftID" ,
134  "Global Position Shift For Overlay" ,
136  ShowerPositionShiftID);
137 
138  registerProcessorParameter( "DigiCellSize" ,
139  "Size of Digitized Cell (in mm)" ,
140  _DigiCellSize ,
141  10);
142 
143  registerProcessorParameter( "UsingDefaultDetector",
144  "Flag Parameter Setting (0 ~ self definition, 1 ~ MircoMegas, 2 ~ GRPC_PS, 3 ~ GRPC_SPS)",
146  0);
147 
148  registerProcessorParameter( "PolyaParaA" ,
149  "Polya: x^A*exp(-b*x) + c" ,
150  _PolyaParaA ,
151  float(0.7));
152 
153  registerProcessorParameter( "PolyaParaB" ,
154  "Polya: x^a*exp(-B*x) + c" ,
155  _PolyaParaB ,
156  float(0.045));
157 
158  registerProcessorParameter( "PolyaParaC" ,
159  "Polya: x^a*exp(-b*x) + C" ,
160  _PolyaParaC,
161  float(0.03) );
162 
163  registerProcessorParameter( "ChanceOfKink" ,
164  "Chance of one boundary hit to create a multiple hit with boosted charge" ,
166  float(0.0) );
167 
168  registerProcessorParameter( "KinkHitChargeBoost" ,
169  "Scale factor of Charge on boosted multiple hits" ,
171  float(1.0) );
172 
173 }
174 
175 void G2CD::init() {
176 
177  printParameters();
178 
179  if( _outputHcalCollections.size() < _hcalCollections.size() )
180  {
181  cout<<"WARNING! Output Collections Array Smaller than Input"<<endl;
182  exit(1);
183  }
184  else if( _ChargeSpatialDistri.size() % 2 == 0 )
185  {
186  cout<<"WARNING! Better Organize Charge Spatial distribution array in odd integer length"<<endl;
187  exit(2);
188  }
189 
190  if(_UsingDefaultDetector < 0 || _UsingDefaultDetector > 4)
191  {
192  cout<<"Parameter Flag Wrong. Need to be 0 (selfdefine), 1 (MircoMegas), 2 (GRPC_PS) or 3 (GRPC_SPS)"<<endl;
193  exit(0);
194  }
195  else if(_UsingDefaultDetector == 1) //MircoMegas Small Chamber, 2008 PS TB
196  {
197  _PolyaParaA = 0.7;
198  _PolyaParaB = 0.045;
199  _PolyaParaC = 0.03;
200  _ChargeSpatialDistri.clear();
201  _ChargeSpatialDistri.push_back(0.1);
202  _ChargeSpatialDistri.push_back(8.0);
203  _ChargeSpatialDistri.push_back(0.1);
204  ChanceOfKink = 0.095;
205  KinkHitChargeBoost = 2.2;
206  }
207  else if(_UsingDefaultDetector == 2) //GRPC Cubic Meter, 2011 PS TB
208  {
209  _PolyaParaA = 4.0;
210  _PolyaParaB = 4.5;
211  _PolyaParaC = 0.0;
212  _ChargeSpatialDistri.clear();
213  _ChargeSpatialDistri.push_back(0.1);
214  _ChargeSpatialDistri.push_back(0.1);
215  _ChargeSpatialDistri.push_back(0.1);
216  _ChargeSpatialDistri.push_back(0.1);
217  _ChargeSpatialDistri.push_back(0.1);
218  _ChargeSpatialDistri.push_back(0.1);
219  _ChargeSpatialDistri.push_back(0.1);
220  ChanceOfKink = 0.0;
221  KinkHitChargeBoost = 1.0;
222  }
223  else if(_UsingDefaultDetector == 3) //GRPC Bubic Meter, 2012 May SPS TB
224  {
225  _PolyaParaA = 1.1;
226  _PolyaParaB = 1.0;
227  _PolyaParaC = 0.0;
228  _ChargeSpatialDistri.clear();
229  _ChargeSpatialDistri.push_back(0.1);
230  _ChargeSpatialDistri.push_back(0.2);
231  _ChargeSpatialDistri.push_back(0.3);
232  _ChargeSpatialDistri.push_back(0.6);
233  _ChargeSpatialDistri.push_back(0.6);
234  _ChargeSpatialDistri.push_back(0.6);
235  _ChargeSpatialDistri.push_back(0.3);
236  _ChargeSpatialDistri.push_back(0.2);
237  _ChargeSpatialDistri.push_back(0.1);
238  ChanceOfKink = 0.0;
239  KinkHitChargeBoost = 1.0;
240  }
241  else
242  {
245  }
246 
247  float PolyaDomain = 100;
248  if(_PolyaParaB )
249  {
250  PolyaDomain = 20*_PolyaParaA/_PolyaParaB;
251  }
252  _QPolya = new TF1("QPolya", "x^[0]*exp(-1*x*[1]) + [2]", 0, PolyaDomain);
253  _QPolya->SetParameters(_PolyaParaA, _PolyaParaB, _PolyaParaC);
254 
255  cout<<"Parameters After Para Review: "<<ChanceOfKink<<", "<<KinkHitChargeBoost <<", "<<_DigiCellSize<<endl;
256  printParameters();
257 
258  int SizeCSD = _ChargeSpatialDistri.size();
259  int CoverAreaLength = int((SizeCSD - 1)/2);
260  if(CoverAreaLength > _DigiCellSize - 1)
261  {
262  cout<<"WARNING! CoverAreaLength is too large comparing to the Digitized Cell Size: to have maximally 4 multiple hit, CoverAreaLength must <= _DigiCellSize - 1"<<endl;
263  exit(0);
264  }
265  int tmpIndex = 0;
266  float NormalWeightFactor = 0;
267  //fg: variable length array is not ISO C++: float NormalWeight[SizeCSD];
268  std::vector<float> NormalWeight(SizeCSD);
269  int IndexA = 0;
270  int IndexB = 0; //Used to denote charge distributions...
271  float WeightA = 0;
272  float WeightB = 0;
273 
274  for( int i0 = 0; i0 < SizeCSD; i0++ )
275  {
276  NormalWeightFactor += _ChargeSpatialDistri[i0];
277  }
278 
279  for( int i1 = 0; i1 < SizeCSD; i1++ )
280  {
281  NormalWeight[i1] = _ChargeSpatialDistri[i1]/NormalWeightFactor;
282  }
283 
284  int SignX(0);
285  int SignY(0);
286  pair<float, float> WMatrix; //if Vec(A) != Vec(B)
287 
288  for(int i2 = 0; i2 < _DigiCellSize; i2++)
289  {
290  for(int j2 = 0; j2 < _DigiCellSize; j2++)
291  {
292  tmpIndex = _DigiCellSize*i2 + j2;
293  IndexA = 0;
294  IndexB = 0;
295  WeightA = 0;
296  WeightB = 0;
297 
298  if( i2 < CoverAreaLength )
299  {
300  IndexA = CoverAreaLength - i2;
301  SignX = -1;
302  }
303  else if( i2 > _DigiCellSize - CoverAreaLength - 1)
304  {
305  IndexA = CoverAreaLength + i2 - _DigiCellSize + 1;
306  SignX = 1;
307  }
308 
309  if( j2 < CoverAreaLength )
310  {
311  IndexB = CoverAreaLength - j2;
312  SignY = -1;
313  }
314  else if( j2 > _DigiCellSize - CoverAreaLength - 1)
315  {
316  IndexB = CoverAreaLength + j2 - _DigiCellSize + 1;
317  SignY = 1;
318  }
319 
320  for(int i3 = 0; i3 < CoverAreaLength; i3 ++)
321  {
322  if(i3 < IndexA) WeightA += NormalWeight[i3];
323  if(i3 < IndexB) WeightB += NormalWeight[i3];
324  }
325 
326  WMatrix.first = SignX*WeightA;
327  WMatrix.second = SignY*WeightB;
328  WeightVector[tmpIndex] = WMatrix;
329 
330  cout<<WMatrix.first<<"/"<<WMatrix.second<<", ";
331  }
332  cout<<endl;
333  }
334 }
335 
336 void G2CD::processEvent( LCEvent * evtP )
337 {
338  if (evtP)
339  {
340  try{
341 
342  _eventNr = evtP->getEventNumber();
343  if(_eventNr % 100 == 0) cout<<"eventNr: "<<_eventNr<<endl;
344 
345  float HitEn = 0;
346  float DigiHitEn = 0;
347  int LayerNum = 0;
348  TVector3 HitPos;
349  int tmpM, tmpS, tmpI, tmpJ, tmpK;
350  int CurrI = 0;
351  int CurrJ = 0;
352  int DHIndexI = 0;
353  int DHIndexJ = 0;
354  float DHChargeWeight = 0;
355  int DHCellID0 = 0;
356  float RndCharge = 0;
357  int SingleMCPPID = 0;
358  float SingleMCPPEn = 0;
359  float RefPosX = 0;
360  float RefPosY = 0;
361  float RefPosZ = 0;
362  float DeltaPosI = 0;
363  float DeltaPosJ = 0;
364  std::vector<float> CurrWeightVec;
365  float WeiI = 0;
366  float WeiJ = 0;
367  int DeltaI = 0;
368  int DeltaJ = 0;
369  int MapI = 0;
370  int MapJ = 0;
371  int MapIndex = 0;
372 
373  LCCollectionVec *relcol = new LCCollectionVec(LCIO::LCRELATION);
374  LCFlagImpl linkflag;
375  linkflag.setBit(LCIO::CHBIT_LONG);
376  relcol->setFlag(linkflag.getFlag());
377 
378  LCCollection * MCPCol = evtP->getCollection("MCParticle");
379  for ( int s0(0); s0 < MCPCol->getNumberOfElements(); s0++)
380  {
381  MCParticle * a_MCP = dynamic_cast<MCParticle*> (MCPCol->getElementAt(s0));
382  if( a_MCP->getParents().size() == 0 )
383  {
384  SingleMCPPID = a_MCP->getPDG();
385  SingleMCPPEn = a_MCP->getEnergy();
386  break;
387  }
388  }
389 
390  LCFlagImpl flag;
391  flag.setBit(LCIO::CHBIT_LONG); //To set position & ID1
392  flag.setBit(LCIO::CHBIT_ID1);
393  flag.setBit(LCIO::RCHBIT_ENERGY_ERROR); //In order to use an additional FLOAT
394 
395  for (unsigned int k0 = 0; k0 < _ecalCollections.size(); ++k0)
396  {
397  try{
398  LCCollection *Ecalcol = evtP->getCollection( _ecalCollections[k0].c_str() ) ;
399  CellIDDecoder<SimCalorimeterHit> idDecoder( Ecalcol );
400  int NumEcalhit = Ecalcol->getNumberOfElements();
401  LCCollectionVec *ecalcol = new LCCollectionVec(LCIO::CALORIMETERHIT);
402  ecalcol->setFlag(flag.getFlag());
403  string EcalinitString = Ecalcol->getParameters().getStringVal(LCIO::CellIDEncoding);
404  ecalcol->parameters().setValue(LCIO::CellIDEncoding, EcalinitString);
405 
406  for(int k1 = 0; k1 < NumEcalhit; k1++)
407  {
408  SimCalorimeterHit * SimEcalhit = dynamic_cast<SimCalorimeterHit*>( Ecalcol->getElementAt( k1 ) ) ;
409  HitEn = SimEcalhit->getEnergy();
410  LayerNum = idDecoder(SimEcalhit)["K-1"];
411  if(LayerNum < _NEcalThinLayer)
412  DigiHitEn = HitEn * _calibCoeffEcal[0];
413  else
414  DigiHitEn = HitEn * _calibCoeffEcal[1];
415  if(HitEn > _thresholdEcal)
416  {
417  CalorimeterHitImpl * DigiEcalhit = new CalorimeterHitImpl();
418  DigiEcalhit->setPosition(SimEcalhit->getPosition());
419  DigiEcalhit->setCellID0(SimEcalhit->getCellID0());
420  DigiEcalhit->setCellID1(SimEcalhit->getCellID1());
421  DigiEcalhit->setEnergy(DigiHitEn);
422  ecalcol->addElement(DigiEcalhit);
423  LCRelationImpl *rel = new LCRelationImpl(DigiEcalhit, SimEcalhit, 1.0); //only keep the leading contribution
424  relcol->addElement(rel);
425  }
426  }
427 
428  evtP->addCollection(ecalcol,_outputEcalCollections[k0].c_str());
429 
430  }catch(lcio::DataNotAvailableException& zero) { }
431  }
432 
433 
434  for (unsigned int i(0); i < _hcalCollections.size(); ++i)
435  { //strictly follow barrel, endcap, ring order
436 
437  std::map <int, DigiHit> IDtoDigiHit;
438  IDtoDigiHit.clear();
439  std::map <int, TVector3> IDtoPos;
440  IDtoPos.clear();
441 
442  try{
443  LCCollection * col = evtP->getCollection( _hcalCollections[i].c_str() ) ;
444 
445  int numOrihits = col->getNumberOfElements();
446  CellIDDecoder<SimCalorimeterHit> idDecoder(col);
447  LCCollectionVec *hcalcol = new LCCollectionVec(LCIO::CALORIMETERHIT);
448  string initString = "M:3,S-1:3,I:9,J:9,K-1:6"; //Need to verify
449  hcalcol->parameters().setValue(LCIO::CellIDEncoding, initString);
450  hcalcol->setFlag(flag.getFlag());
451 
452  for (int j(0); j < numOrihits; ++j) {
453  SimCalorimeterHit * hit = dynamic_cast<SimCalorimeterHit*>( col->getElementAt( j ) ) ;
454  HitEn = hit->getEnergy();
455 
456  tmpM = idDecoder(hit)["M"];
457  tmpS = idDecoder(hit)["S-1"];
458  tmpI = idDecoder(hit)["I"];
459  tmpJ = idDecoder(hit)["J"];
460  tmpK = idDecoder(hit)["K-1"];
461 
462  RefPosX = hit->getPosition()[0];
463  RefPosY = hit->getPosition()[1];
464  RefPosZ = hit->getPosition()[2];
465 
466  CurrI = tmpI/_DigiCellSize;
467  CurrJ = tmpJ/_DigiCellSize;
468  MapI = tmpI % _DigiCellSize;
469  MapJ = tmpJ % _DigiCellSize;
470  MapIndex = MapI * _DigiCellSize + MapJ;
471  WeiI = WeightVector[MapIndex].first;
472  WeiJ = WeightVector[MapIndex].second;
473 
474  DeltaPosI = (float(_DigiCellSize) - 1.0)/2 - MapI;
475  DeltaPosJ = (float(_DigiCellSize) - 1.0)/2 - MapJ;
476 
477  // cout<<"DeltaI "<<DeltaPosI<<", "<<DeltaPosJ<<endl;
478 
479  DeltaI = 0;
480  DeltaJ = 0;
481 
482  if(fabs(WeiI) > 1E-9)
483  {
484  DeltaI = ((WeiI > 0) ? 1: -1);
485  }
486  if(fabs(WeiJ) > 1E-9)
487  {
488  DeltaJ = ((WeiJ > 0) ? 1: -1);
489  }
490 
491  // cout<<"Weight... "<<WeiI<<"\t"<<DeltaI<<"\t"<<WeiJ<<"\t"<<DeltaJ<<endl;
492 
493  RndCharge = _QPolya->GetRandom();
494 
495  CurrWeightVec.clear();
496  CurrWeightVec.push_back((1 - fabs(WeiI))*(1 - fabs(WeiJ)));
497  if(DeltaI && !DeltaJ)
498  {
499  CurrWeightVec.push_back(fabs(WeiI));
500  }
501  else if(DeltaJ && !DeltaI)
502  {
503  CurrWeightVec.push_back(fabs(WeiJ));
504  }
505  else if(DeltaI && DeltaJ)
506  {
507  CurrWeightVec.push_back(fabs(WeiI) * (1 - fabs(WeiJ)));
508  CurrWeightVec.push_back(fabs(WeiJ) * (1 - fabs(WeiI)));
509  CurrWeightVec.push_back(fabs(WeiJ*WeiI));
510  }
511 
512  for(int i0 = 0; i0 < int(CurrWeightVec.size()); i0++)
513  {
514  if(i0 == 0)
515  {
516  DHIndexI = CurrI;
517  DHIndexJ = CurrJ;
518  }
519  else if(i0 == 1)
520  {
521  if(DeltaI)
522  {
523  DHIndexI = CurrI + DeltaI;
524  DHIndexJ = CurrJ;
525  }
526  if(DeltaJ)
527  {
528  DHIndexI = CurrI;
529  DHIndexJ = CurrJ + DeltaJ;
530  }
531  }
532  else if(i0 == 2)
533  {
534  DHIndexI = CurrI + DeltaI;
535  DHIndexJ = CurrJ;
536  }
537  else if(i0 == 3)
538  {
539  DHIndexI = CurrI + DeltaI;
540  DHIndexJ = CurrJ + DeltaJ;
541  }
542 
543  DHChargeWeight = CurrWeightVec[i0];
544  DHCellID0 = (i<<30) + (tmpK<<24) + (DHIndexJ<<15) + (DHIndexI<<6) + (tmpS << 3) + tmpM;
545 
546  if( IDtoDigiHit.find(DHCellID0) == IDtoDigiHit.end() && IDtoPos.find(DHCellID0) == IDtoPos.end() )
547  {
548  IDtoDigiHit[DHCellID0].digihitCellID0 = DHCellID0;
549  IDtoDigiHit[DHCellID0].digihitCharge = RndCharge * DHChargeWeight;
550  IDtoDigiHit[DHCellID0].digihitEnergyDepo = HitEn * DHChargeWeight; //Assumption...
551  IDtoDigiHit[DHCellID0].digihitNum1mmCell = 1;
552  IDtoDigiHit[DHCellID0].LeadChargeDepo = RndCharge * DHChargeWeight;
553  IDtoDigiHit[DHCellID0].LeadSimCaloHit = hit;
554  IDtoDigiHit[DHCellID0].ChargeShare = DHChargeWeight;
555 
556  if(i == 0) //Barrel
557  {
558  IDtoDigiHit[DHCellID0].PosX = RefPosX + (DeltaPosI + int(DHIndexI - CurrI)*_DigiCellSize) * cos(tmpS*pi/4.0) + _ShowerPositionShiftID[0]*_DigiCellSize; //(mm in unit)
559  IDtoDigiHit[DHCellID0].PosY = RefPosY + (DeltaPosI + int(DHIndexI - CurrI)*_DigiCellSize)* sin(tmpS*pi/4.0) + _ShowerPositionShiftID[1]*_DigiCellSize;
560  IDtoDigiHit[DHCellID0].PosZ = RefPosZ + DeltaPosJ + int(DHIndexJ - CurrJ)*_DigiCellSize + _ShowerPositionShiftID[2]*_DigiCellSize; //Rotation is needed, based on S;
561  }
562  else //endcap or ring;
563  {
564  IDtoDigiHit[DHCellID0].PosX = RefPosX + DeltaPosI + (DHIndexI - CurrI)*_DigiCellSize + _ShowerPositionShiftID[0]*_DigiCellSize; //(mm in unit)
565  IDtoDigiHit[DHCellID0].PosY = RefPosY + DeltaPosJ + (DHIndexJ - CurrJ)*_DigiCellSize + _ShowerPositionShiftID[1]*_DigiCellSize;
566  IDtoDigiHit[DHCellID0].PosZ = RefPosZ;
567  }
568 
569  HitPos.SetXYZ(IDtoDigiHit[DHCellID0].PosX, IDtoDigiHit[DHCellID0].PosY, IDtoDigiHit[DHCellID0].PosZ);
570 
571  IDtoPos[DHCellID0] = HitPos;
572  }
573  else
574  {
575  IDtoDigiHit[DHCellID0].digihitCharge += RndCharge * DHChargeWeight;
576  IDtoDigiHit[DHCellID0].digihitEnergyDepo += HitEn * DHChargeWeight;
577  IDtoDigiHit[DHCellID0].digihitNum1mmCell ++;
578  if(RndCharge * DHChargeWeight > IDtoDigiHit[DHCellID0].LeadChargeDepo)
579  {
580  IDtoDigiHit[DHCellID0].LeadChargeDepo = RndCharge * DHChargeWeight;
581  IDtoDigiHit[DHCellID0].LeadSimCaloHit = hit;
582  IDtoDigiHit[DHCellID0].ChargeShare = DHChargeWeight;
583  }
584 
585  if(IDtoDigiHit[DHCellID0].PosX != IDtoPos[DHCellID0].X() )
586  cout<<"Position Changed.........."<<endl;
587  }
588 
589  //cout<<"Com "<<IDtoPos.size()<<"\t"<<IDtoDigiHit.size()<<endl;
590  }
591  }
592 
593  float DigiHitPos[3];
594 
595  for(std::map <int, DigiHit>::iterator ff = IDtoDigiHit.begin(); ff!=IDtoDigiHit.end(); ff++)
596  {
597  CalorimeterHitImpl * calhit = new CalorimeterHitImpl();
598  LCRelationImpl *rel = new LCRelationImpl(calhit, ff->second.LeadSimCaloHit, ff->second.ChargeShare); //only keep the leading contribution
599  relcol->addElement(rel);
600 
601  calhit->setCellID0( ff->first );
602  calhit->setEnergy(ff->second.digihitCharge); //Charge
603  calhit->setCellID1(SingleMCPPID); //Use ID1 & Energy Error to denote the MCP info...
604  calhit->setEnergyError(SingleMCPPEn);
605  /*
606  DigiHitPos[0] = ff->second.PosX;
607  DigiHitPos[1] = ff->second.PosY;
608  DigiHitPos[2] = ff->second.PosZ;
609  */
610  DigiHitPos[0] = IDtoPos[ff->first].X();
611  DigiHitPos[1] = IDtoPos[ff->first].Y();
612  DigiHitPos[2] = IDtoPos[ff->first].Z();
613 
614  calhit->setPosition(DigiHitPos);
615  hcalcol->addElement(calhit);
616  }
617 
618  evtP->addCollection(hcalcol,_outputHcalCollections[i].c_str());
619  IDtoDigiHit.clear();
620  }
621  catch (lcio::DataNotAvailableException& zero) { }
622  }
623 
624  evtP->addCollection(relcol, "CaloToSimuCaloLink");
625  }
626  catch (lcio::DataNotAvailableException& zero) { }
627  }
628 }
629 
630 void G2CD::end()
631 {
632  std::cout<<"General Gas Digitizer FINISHED"<<std::endl;
633 }
float _ChanceOfKink
Definition: G2CD.hh:66
Definition: G2CD.hh:29
std::vector< int > _ShowerPositionShiftID
Definition: G2CD.hh:59
int _NEcalThinLayer
Definition: G2CD.hh:61
float ChanceOfKink
Definition: G2CD.cc:52
const float pi
Definition: G2CD.cc:34
int digihitCellID1
Definition: G2CD.cc:38
std::vector< float > _calibCoeffEcal
Definition: G2CD.hh:58
TF1 * _QPolya
Definition: G2CD.hh:69
std::vector< std::string > _ecalCollections
Definition: G2CD.hh:54
float LeadChargeDepo
Definition: G2CD.cc:45
float _PolyaParaC
Definition: G2CD.hh:65
void init()
Definition: G2CD.cc:175
void processEvent(LCEvent *evtP)
Definition: G2CD.cc:336
std::map< int, std::pair< float, float > > WeightVector
Definition: G2CD.cc:50
float _thresholdEcal
Definition: G2CD.hh:60
float PosZ
Definition: G2CD.cc:44
float _KinkHitChargeBoost
Definition: G2CD.hh:66
float ChargeShare
Definition: G2CD.cc:46
G2CD aG2CD
Definition: G2CD.cc:55
Definition: G2CD.cc:36
std::vector< float > _ChargeSpatialDistri
Definition: G2CD.hh:56
std::vector< std::string > _hcalCollections
Definition: G2CD.hh:52
float digihitEnergyDepo
Definition: G2CD.cc:40
float _PolyaParaB
Definition: G2CD.hh:65
std::vector< std::string > _outputHcalCollections
Definition: G2CD.hh:53
int digihitNum1mmCell
Definition: G2CD.cc:41
void end()
Definition: G2CD.cc:630
float digihitCharge
Definition: G2CD.cc:39
int digihitCellID0
Definition: G2CD.cc:37
int _eventNr
Definition: G2CD.hh:72
static const float e
float KinkHitChargeBoost
Definition: G2CD.cc:53
int _UsingDefaultDetector
Definition: G2CD.hh:64
std::vector< LCCollection * > LCCollectionVec
Definition: SiStripClus.h:55
float _PolyaParaA
Definition: G2CD.hh:65
float PosY
Definition: G2CD.cc:43
G2CD()
Definition: G2CD.cc:56
std::vector< std::string > _outputEcalCollections
Definition: G2CD.hh:55
SimCalorimeterHit * LeadSimCaloHit
Definition: G2CD.cc:47
int _DigiCellSize
Definition: G2CD.hh:63
float PosX
Definition: G2CD.cc:42