CMS 3D CMS Logo

EcalTimeMapDigitizer.cc
Go to the documentation of this file.
2 
7 
8 //#include "FWCore/ServiceRegistry/interface/Service.h"
9 //#include "FWCore/Utilities/interface/RandomNumberGenerator.h"
10 //#include "CLHEP/Random/RandPoissonQ.h"
11 //#include "CLHEP/Random/RandGaussQ.h"
12 
15 
17 
18 #include "CLHEP/Units/GlobalPhysicalConstants.h"
19 #include "CLHEP/Units/GlobalSystemOfUnits.h"
20 
21 #include <iostream>
22 
23 //#define ecal_time_debug 1
24 
25 const float EcalTimeMapDigitizer::MIN_ENERGY_THRESHOLD=5e-5; //50 KeV threshold to consider a valid hit in the timing detector
26 
28  m_subDet(myDet),
29  m_geometry(0)
30 {
31 // edm::Service<edm::RandomNumberGenerator> rng ;
32 // if ( !rng.isAvailable() )
33 // {
34 // throw cms::Exception("Configuration")
35 // << "EcalTimeMapDigitizer requires the RandomNumberGeneratorService\n"
36 // "which is not present in the configuration file. You must add the service\n"
37 // "in the configuration file or remove the modules that require it.";
38 // }
39 // m_RandPoisson = new CLHEP::RandPoissonQ( rng->getEngine() ) ;
40 // m_RandGauss = new CLHEP::RandGaussQ( rng->getEngine() ) ;
41 
42  unsigned int size=0;
43  DetId detId(0);
44 
45  //Initialize the map
46  if (myDet==EcalBarrel)
47  {
49  detId=EBDetId::detIdFromDenseIndex( 0 ) ;
50  }
51  else if (myDet==EcalEndcap)
52  {
54  detId=EEDetId::detIdFromDenseIndex( 0 ) ;
55  }
56  else
57  edm::LogError("TimeDigiError") << "[EcalTimeMapDigitizer]::ERROR::This subdetector " << myDet << " is not implemented";
58 
59 
60  assert(m_maxBunch-m_minBunch+1<=10);
61  assert(m_minBunch<=0);
62 
63  m_vSam.reserve( size ) ;
64 
65  for( unsigned int i ( 0 ) ; i != size ; ++i )
66  {
67  // m_vSam.emplace_back(CaloGenericDetId( detId.det(), detId.subdetId(), i ) ,
68  // m_maxBunch-m_minBunch+1, abs(m_minBunch) );
69  m_vSam.emplace_back(TimeSamples(CaloGenericDetId( detId.det(), detId.subdetId(), i )));
70  }
71 
72 
73  edm::LogInfo("TimeDigiInfo") << "[EcalTimeDigitizer]::Subdetector " << m_subDet << "::Reserved size for time digis " << m_vSam.size();
74 
75 #ifdef ecal_time_debug
76  std::cout << "[EcalTimeDigitizer]::Subdetector " << m_subDet << "::Reserved size for time digis " << m_vSam.size() << std::endl;
77 #endif
78 
79 }
80 
82 {
83 }
84 
85 void
86 EcalTimeMapDigitizer::add(const std::vector<PCaloHit> & hits, int bunchCrossing) {
87  if(bunchCrossing>=m_minBunch && bunchCrossing<=m_maxBunch ) {
88 
89  for(std::vector<PCaloHit>::const_iterator it = hits.begin(), itEnd = hits.end(); it != itEnd; ++it) {
90  //here goes the map logic
91 
92  if (edm::isNotFinite( (*it).time() ) )
93  continue;
94 
95  //Just consider only the hits belonging to the specified time layer
96  if ((*it).depth()!=100+m_timeLayerId) //modified layerId start from 100
97  continue;
98 
99  if ((*it).energy()<MIN_ENERGY_THRESHOLD) //apply a minimal cut on the hit energy
100  continue;
101 
102  const DetId detId ( (*it).id() ) ;
103 
104  double time = (*it).time();
105 
106  //time of flight is not corrected here for the vertex position
107  const double jitter ( time - timeOfFlight( detId, m_timeLayerId ) ) ;
108 
109  TimeSamples& result ( *findSignal( detId ) ) ;
110 
111  //here fill the result for the given bunch crossing
112  result.average_time[bunchCrossing-m_minBunch]+=jitter*(*it).energy();
113  result.tot_energy[bunchCrossing-m_minBunch]+=(*it).energy();
114  result.nhits[bunchCrossing-m_minBunch]++;
115 
116 #ifdef ecal_time_debug
117  std::cout << (*it).id() << "\t" << (*it).depth() << "\t" << jitter << "\t" << (*it).energy() << "\t" << result.average_time[bunchCrossing-m_minBunch] << "\t" << result.nhits[bunchCrossing-m_minBunch] << "\t" << timeOfFlight( detId, m_timeLayerId ) << std::endl;
118 #endif
119  }
120  }
121 }
122 
123 
126 {
127  const unsigned int di ( CaloGenericDetId( detId ).denseIndex() ) ;
128  TimeSamples* result ( vSamAll( di ) ) ;
129  if( result->zero() ) m_index.push_back( di ) ;
130  return result ;
131 }
132 
133 
134 
135 void
137 {
138  m_geometry = geometry ;
139 }
140 
141 
142 void
143 EcalTimeMapDigitizer::blankOutUsedSamples() // blank out previously used elements
144 {
145  const unsigned int size ( m_index.size() ) ;
146 
147 
148  for( unsigned int i ( 0 ) ; i != size ; ++i )
149  {
150 #ifdef ecal_time_debug
151  std::cout << "Zeroing " << m_index[i] << std::endl;
152 #endif
153  vSamAll( m_index[i] )->setZero() ;
154  }
155 
156  m_index.erase( m_index.begin() , // done and make ready to start over
157  m_index.end() ) ;
158 }
159 
160 
161 void
163 {
164  //Getting the size from the actual hits
165  const unsigned int size ( m_index.size() ) ;
166 
167  //Here just averaging the MC truth
168  for( unsigned int i ( 0 ) ; i != size ; ++i )
169  {
170 #ifdef ecal_time_debug
171  std::cout << "Averaging " << m_index[i] << std::endl;
172 #endif
174 #ifdef ecal_time_debug
175  for ( unsigned int j ( 0 ) ; j != vSamAll( m_index[i] )->time_average_capacity; ++j )
176  std::cout << j << "\t" << vSamAll( m_index[i] )->average_time[j] << "\t" << vSamAll( m_index[i] )->nhits[j] << "\t" << vSamAll( m_index[i] )->tot_energy[j] << std::endl;
177 #endif
178  }
179 
180  //Noise can be added here
181 
182 }
183 
184 void
186 {
187 #ifdef ecal_time_debug
188  std::cout << "[EcalTimeMapDigitizer]::Zeroing the used samples" << std::endl;
189 #endif
191 }
192 
193 
194 void
196 {
197 #ifdef ecal_time_debug
198  std::cout << "[EcalTimeMapDigitizer]::Finalizing hits and fill output collection" << std::endl;
199 #endif
200 
201  //Do the time averages and add noise if simulated
202  finalizeHits();
203 
204  //Until we do now simulated noise we can get the size from the index vector
205  const unsigned int ssize ( m_index.size() ) ;
206 
207  output.reserve( ssize ) ;
208 
209  for( unsigned int i ( 0 ) ; i != ssize ; ++i )
210  {
211 
212  #ifdef ecal_time_debug
213  std::cout << "----- in digi loop " << i << std::endl;
214  #endif
215 
216  output.push_back( Digi(vSamAll( m_index[i] )->id) );
217 
218  unsigned int nTimeHits=0;
219  float timeHits[vSamAll( m_index[i] )->time_average_capacity];
220  unsigned int timeBX[vSamAll( m_index[i] )->time_average_capacity];
221 
222  for ( unsigned int j ( 0 ) ; j != vSamAll( m_index[i] )->time_average_capacity; ++j ) //here sampling on the OOTPU
223  {
224  if (vSamAll( m_index[i] )->nhits[j]>0)
225  {
226  timeHits[nTimeHits]= vSamAll( m_index[i] )->average_time[j];
227  timeBX[nTimeHits++]= m_minBunch+j;
228  }
229  }
230 
231  output.back().setSize(nTimeHits);
232 
233  for (unsigned int j ( 0 ) ; j != nTimeHits; ++j ) //filling the !zero hits
234  {
235  output.back().setSample(j,timeHits[j]);
236  if (timeBX[j]==0)
237  {
238 #ifdef ecal_time_debug
239  std::cout << "setting interesting sample " << j << std::endl;
240 #endif
241  output.back().setSampleOfInterest(j);
242  }
243  }
244 
245  #ifdef ecal_time_debug
246  std::cout << "digi " << output.back().id().rawId() << "\t" << output.back().size();
247  if (output.back().sampleOfInterest()>0)
248  std::cout << "\tBX0 time " << output.back().sample(output.back().sampleOfInterest()) << std::endl;
249  else
250  std::cout << "\tNo in time hits" << std::endl;
251  #endif
252  }
253 #ifdef ecal_time_debug
254  std::cout << "[EcalTimeMapDigitizer]::Output collection size " << output.size() << std::endl;
255 #endif
256 
257 }
258 
259 
260 double
261 EcalTimeMapDigitizer::timeOfFlight( const DetId& detId , int layer) const
262 {
263  //not using the layer yet
264  const CaloCellGeometry* cellGeometry ( m_geometry->getGeometry( detId ) ) ;
265  assert( 0 != cellGeometry ) ;
266  GlobalPoint layerPos = (dynamic_cast<const TruncatedPyramid*>(cellGeometry))->getPosition( double(layer)+0.5 ); //depth in mm in the middle of the layer position
267  return layerPos.mag()*cm/c_light ;
268 }
269 
270 
271 unsigned int
273 {
274  return m_vSam.size() ;
275 }
276 
277 unsigned int
279 {
280  return m_vSam.size() ;
281 }
282 
284 EcalTimeMapDigitizer::operator[]( unsigned int i ) const
285 {
286  return &m_vSam[ i ] ;
287 }
288 
291 {
292  return &m_vSam[ i ] ;
293 }
294 
297 {
298  return &m_vSam[ i ] ;
299 }
300 
303 {
304  return &m_vSam[ i ] ;
305 }
306 
308 EcalTimeMapDigitizer::vSamAll( unsigned int i ) const
309 {
310  return &m_vSam[ i ] ;
311 }
312 
313 int
315 {
316  return m_minBunch ;
317 }
318 
319 int
321 {
322  return m_maxBunch ;
323 }
324 
327 {
328  return m_index ;
329 }
330 
333 {
334  return m_index ;
335 }
336 
337 // const EcalTimeMapDigitizer::TimeSamples*
338 // EcalTimeMapDigitizer::findDetId( const DetId& detId ) const
339 // {
340 // const unsigned int di ( CaloGenericDetId( detId ).denseIndex() ) ;
341 // return vSamAll( di ) ;
342 // }
static EEDetId detIdFromDenseIndex(uint32_t din)
Definition: EEDetId.h:220
size
Write out results.
unsigned int samplesSizeAll() const
void run(EcalTimeDigiCollection &output)
static const int m_maxBunch
const CaloSubdetectorGeometry * m_geometry
void push_back(T const &t)
const TimeSamples * operator[](unsigned int i) const
unsigned int nhits[time_average_capacity]
std::vector< TimeSamples > m_vSam
void setGeometry(const CaloSubdetectorGeometry *geometry)
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
static EBDetId detIdFromDenseIndex(uint32_t di)
Definition: EBDetId.h:111
unsigned int samplesSize() const
T mag() const
Definition: PV3DBase.h:67
bool isNotFinite(T x)
Definition: isFinite.h:10
TimeSamples * vSamAll(unsigned int i)
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
static const unsigned short time_average_capacity
Definition: DetId.h:18
static const int m_minBunch
TimeSamples * findSignal(const DetId &detId)
double timeOfFlight(const DetId &detId, int layer) const
A base class to handle the particular shape of Ecal Xtals. Taken from ORCA Calorimetry Code...
void add(const std::vector< PCaloHit > &hits, int bunchCrossing)
ESHandle< TrackerGeometry > geometry
EcalTimeMapDigitizer(EcalSubdetector myDet)
size_type size() const
float average_time[time_average_capacity]
void reserve(size_type n)
float tot_energy[time_average_capacity]
std::vector< unsigned int > VecInd
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
EcalSubdetector
static const float MIN_ENERGY_THRESHOLD
TimeSamples * vSam(unsigned int i)
const_reference back() const