All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
SimpleFCalDigi.cc
Go to the documentation of this file.
1 #include "SimpleFCalDigi.h"
2 #include <EVENT/LCCollection.h>
3 #include <EVENT/SimCalorimeterHit.h>
4 #include <IMPL/CalorimeterHitImpl.h>
5 #include <IMPL/LCCollectionVec.h>
6 #include <IMPL/LCFlagImpl.h>
7 #include <IMPL/LCRelationImpl.h>
8 #include <EVENT/LCParameters.h>
9 #include <UTIL/CellIDDecoder.h>
10 #include <iostream>
11 #include <string>
12 #include <math.h>
13 #include <marlin/Global.h>
14 #include <gear/GEAR.h>
15 #include <gear/CalorimeterParameters.h>
16 #include <gear/GearParameters.h>
17 #include <gear/LayerLayout.h>
18 #include "CalorimeterHitType.h"
19 
20 using namespace std;
21 using namespace lcio ;
22 using namespace marlin ;
23 
24 
26 
27 
28 SimpleFCalDigi::SimpleFCalDigi() : Processor("SimpleFCalDigi") {
29 
30  _description = "Performs simple digitization of SimCalorimeter hits in forward calorimeters ..." ;
31 
32  std::vector<std::string> fcalCollections;
33 
34  fcalCollections.push_back(std::string("LcalCollection"));
35 
36  registerInputCollections( LCIO::SIMCALORIMETERHIT,
37  "FCALCollections" ,
38  "Fcal Collection Names" ,
40  fcalCollections);
41 
42  registerOutputCollection( LCIO::CALORIMETERHIT,
43  "FCALOutputCollection" ,
44  "Fcal Collection of real Hits" ,
46  std::string("FCAL")) ;
47 
48  registerOutputCollection( LCIO::LCRELATION,
49  "RelationOutputCollection" ,
50  "CaloHit Relation Collection" ,
52  std::string("RelationFcalHit")) ;
53 
54  registerProcessorParameter("FcalThreshold" ,
55  "Threshold for Fcal Hits in GeV" ,
57  (float)0.0);
58 
59  registerProcessorParameter("CalibrFCAL" ,
60  "Calibration coefficients for FCAL" ,
62  (float)31.);
63 
64  registerProcessorParameter("CellIDLayerString" ,
65  "name of the part of the cellID that holds the layer" ,
67  std::string("K-1")
68  );
69 
70  registerProcessorParameter("FixLCalHits" ,
71  "Fix the hit positions in LCal using the cellID (for DBD simulated samples)" ,
72  _fixLCalHits ,
73  bool(false)
74  );
75 
76  registerProcessorParameter("CaloType" ,
77  "type of calorimeter: em, had, muon" ,
78  _caloType ,
79  std::string("had")
80  );
81 
82  registerProcessorParameter("CaloID" ,
83  "ID of calorimeter: lcal, fcal, bcal",
84  _caloID ,
85  std::string("fcal")
86  );
87 
88  registerProcessorParameter("CaloLayout" ,
89  "subdetector layout: barrel, endcap, plug, ring",
90  _caloLayout ,
91  std::string("endcap")
92  );
93 
94  registerProcessorParameter("DefaultEncoding" ,
95  "string defining cell encoding" ,
97  std::string("M:3,S-1:3,I:9,J:9,K-1:6")
98  );
99 
100 }
101 
103 
104  _nRun = -1;
105  _nEvt = 0;
106 
107  //fg: need to set default encoding in for reading old files...
108  //CellIDDecoder<SimCalorimeterHit>::setDefaultEncoding("M:3,S-1:3,I:9,J:9,K-1:6") ;
109  CellIDDecoder<SimCalorimeterHit>::setDefaultEncoding(_defaultEncoding.c_str()) ;
110  if ( ! _caloID.compare("lcal") && // true if it is false ...
111  _fixLCalHits ) {
112  // parametrs for fixing wrong cellID to xyz coding in LCal Mokka
113 
114  const gear::CalorimeterParameters& lcalparam = Global::GEAR->getLcalParameters();
115 
116  xing_angle = lcalparam.getDoubleVal("beam_crossing_angle"); // 1.400000000e+01 ; beam_crossing_angle (mrad)
117  zMin = lcalparam.getExtent()[2] ; // 2.506900000e+03 ; inner_z
118  dZ = lcalparam.getLayerLayout().getThickness(0) ; // 4.290000000e+00 ; thickness
119  rMin = lcalparam.getExtent()[0] ; // 8.402209443e+01 ; inner_r
120  cellDimR = lcalparam.getLayerLayout().getCellSize0(0); // 1.718404774e+00 ; cellSize0
121  cellDimPhi = lcalparam.getLayerLayout().getCellSize1(0); // 1.308996939e-01 ; cellSize1
122  WThickness = lcalparam.getLayerLayout().getAbsorberThickness(0); // 3.500000000e+00 ; absorberThickness
123  }
124 
125 }
126 
127 
128 void SimpleFCalDigi::processRunHeader( LCRunHeader* /*run*/) {
129  _nRun++ ;
130  _nEvt = 0;
131 }
132 
133 void SimpleFCalDigi::processEvent( LCEvent * evt ) {
134 
135 
136  LCCollectionVec *lcalcol = new LCCollectionVec(LCIO::CALORIMETERHIT);
137  LCCollectionVec *relcol = new LCCollectionVec(LCIO::LCRELATION);
138 
139  LCFlagImpl flag;
140 
141  flag.setBit(LCIO::CHBIT_LONG);
142  flag.setBit(LCIO::CHBIT_ID1);
143 
144  lcalcol->setFlag(flag.getFlag());
145 
146  //
147  // * Reading Collections of FCAL Simulated Hits *
148  //
149  string initString;
150  for (unsigned int i(0); i < _fcalCollections.size(); ++i) {
151  try{
152  LCCollection * col = evt->getCollection( _fcalCollections[i].c_str() ) ;
153  initString = col->getParameters().getStringVal(LCIO::CellIDEncoding);
154  int numElements = col->getNumberOfElements();
155  CellIDDecoder<SimCalorimeterHit> idDecoder( col );
156  for (int j(0); j < numElements; ++j) {
157  SimCalorimeterHit * hit = dynamic_cast<SimCalorimeterHit*>( col->getElementAt( j ) ) ;
158  float energy = hit->getEnergy();
159 
160  if (energy > _thresholdFcal) {
161  CalorimeterHitImpl * calhit = new CalorimeterHitImpl();
162  int cellid = hit->getCellID0();
163  int cellid1 = hit->getCellID1();
164  float calibr_coeff(1.);
165  calibr_coeff = _calibrCoeffFcal;
166  calhit->setCellID0(cellid);
167  calhit->setCellID1(cellid1);
168  calhit->setEnergy(calibr_coeff*energy);
169  float pos[3];
170  if ( ! _caloID.compare("lcal") && // true if it is false ...
171  _fixLCalHits ) {
172  // fix for wrong cellID to xyz coding in LCal Mokka
173 
174  int i = idDecoder(hit)[ "I" ] ;
175  int j = idDecoder(hit)[ "J" ] ;
176  int k = idDecoder(hit)[ "K" ] ;
177  int s = idDecoder(hit)[ "S-1" ] ;
178 
179  float z_from_cell = ( zMin + (k-1) * dZ + (dZ- WThickness)/2.0 ) - 0.11 ; // 0.11 is a guess on the sensorthikness
180  float r_from_cell = i*cellDimR + cellDimR/2.0 + rMin;
181  int oddeven = ((k+1)%2) ;
182  float phi_from_cell = j*cellDimPhi + cellDimPhi/2.0 - oddeven*cellDimPhi/2.0;
183 
184  float angle= -(xing_angle*1.0e-3 / 2.0)* (2 * ( s - 0.5 ) ) - ( s - 1 )*3.14159 ;
185  float rotated_z_from_cell= z_from_cell*cos( angle) + r_from_cell*cos(phi_from_cell)*sin( angle);
186  float rotated_x_from_cell= - z_from_cell*sin( angle) + r_from_cell*cos(phi_from_cell)*cos( angle);
187 
188  pos[0] = rotated_x_from_cell ;
189  pos[1] = r_from_cell*sin(phi_from_cell) ;
190  pos[2]=rotated_z_from_cell;
191 
192  streamlog_out( DEBUG3 ) << "i,j,k,s : " << i << " " << j << " " << k << " " << s << " " << oddeven << std::endl;
193  streamlog_out( DEBUG3 ) << "xyzr input : " << hit->getPosition()[0] << " " << hit->getPosition()[1] << " " << hit->getPosition()[2] << " " <<
194  sqrt(hit->getPosition()[0]*hit->getPosition()[0]+hit->getPosition()[1]*hit->getPosition()[1]) << std::endl;
195  streamlog_out( DEBUG3 ) << "xyzr with r and z fr cellID rotated : " << pos[0] << " " << pos[1] << " " << pos[2] << " " <<
196  sqrt(pos[0]*pos[0]+pos[1]*pos[1]) << std::endl;
197  streamlog_out( DEBUG2 ) << " hit and diffs " << hit->getPosition()[0] << " " << hit->getPosition()[1] << " " << hit->getPosition()[2] << " "
198  << hit->getPosition()[0]-pos[0] << " " << hit->getPosition()[1]-pos[1] << " " << hit->getPosition()[2]-pos[2] <<std::endl;
199  streamlog_out( DEBUG3 ) << std::endl;
200 
201 
202  } else {
203  pos[0] = hit->getPosition()[0];
204  pos[1] = hit->getPosition()[1];
205  pos[2] = hit->getPosition()[2];
206  }
207  calhit->setPosition(pos);
208 
209  calhit->setType( CHT ( caloTypeFromString(_caloType), caloIDFromString(_caloID), layoutFromString(_caloLayout.c_str()), idDecoder(hit)[ _cellIDLayerString ] ) );
210 
211  calhit->setRawHit(hit);
212  lcalcol->addElement(calhit);
213  LCRelationImpl *rel = new LCRelationImpl(calhit,hit,1.);
214  relcol->addElement( rel );
215  }
216 
217  }
218  }
219  catch(DataNotAvailableException &e){
220  }
221  }
222  lcalcol->parameters().setValue(LCIO::CellIDEncoding,initString);
223  evt->addCollection(lcalcol,_outputFcalCollection.c_str());
224  evt->addCollection(relcol,_outputRelCollection.c_str());
225 
226 
227  _nEvt++;
228 
229 }
230 
231 
232 void SimpleFCalDigi::check( LCEvent * /*evt*/ ) { }
233 
std::string _caloLayout
SimpleFCalDigi aSimpleFCalDigi
std::string _caloID
std::string _cellIDLayerString
std::string _outputRelCollection
static const float k
virtual void end()
std::string _caloType
std::string _defaultEncoding
virtual void check(LCEvent *evt)
virtual void init()
static const float s
virtual void processEvent(LCEvent *evt)
static const float e
std::string _outputFcalCollection
std::vector< LCCollection * > LCCollectionVec
Definition: SiStripClus.h:55
virtual void processRunHeader(LCRunHeader *run)
std::vector< std::string > _fcalCollections
float _calibrCoeffFcal