CMS 3D CMS Logo

CaloHitResponse.cc
Go to the documentation of this file.
14 
15 #include "CLHEP/Random/RandPoissonQ.h"
16 #include "CLHEP/Units/GlobalPhysicalConstants.h"
17 #include "CLHEP/Units/GlobalSystemOfUnits.h"
18 
19 #include<iostream>
20 
22  const CaloVShape * shape)
23 : theAnalogSignalMap(),
24  theParameterMap(parametersMap),
25  theShapes(nullptr),
26  theShape(shape),
27  theHitCorrection(nullptr),
28  thePECorrection(nullptr),
29  theHitFilter(nullptr),
30  theGeometry(nullptr),
31  theMinBunch(-10),
32  theMaxBunch(10),
33  thePhaseShift_(1.),
34  storePrecise(false),
35  ignoreTime(false) {}
36 
38  const CaloShapes * shapes)
40  theParameterMap(parametersMap),
41  theShapes(shapes),
47  theMinBunch(-10),
48  theMaxBunch(10),
49  thePhaseShift_(1.),
51  ignoreTime(false) {}
52 
54 }
55 
59 }
60 
61 void CaloHitResponse::run(const MixCollection<PCaloHit> & hits, CLHEP::HepRandomEngine* engine) {
62 
63  for(MixCollection<PCaloHit>::MixItr hitItr = hits.begin();
64  hitItr != hits.end(); ++hitItr) {
65  if(withinBunchRange(hitItr.bunch())) {
66  add(*hitItr, engine);
67  } // loop over hits
68  }
69 }
70 
71 void CaloHitResponse::add( const PCaloHit& hit, CLHEP::HepRandomEngine* engine ) {
72  // check the hit time makes sense
73  if ( edm::isNotFinite(hit.time()) ) { return; }
74 
75  // maybe it's not from this subdetector
76  if(theHitFilter == nullptr || theHitFilter->accepts(hit)) {
77  LogDebug("CaloHitResponse") << hit;
78  CaloSamples signal( makeAnalogSignal( hit, engine ) ) ;
79  bool keep ( keepBlank() ) ; // here we check for blank signal if not keeping them
80  if( !keep )
81  {
82  const unsigned int size ( signal.size() ) ;
83  if( 0 != size )
84  {
85  for( unsigned int i ( 0 ) ; i != size ; ++i )
86  {
87  keep = keep || signal[i] > 1.e-7 ;
88  }
89  }
90  }
91 
92  if( keep ) add(signal);
93  }
94 }
95 
96 
97 void CaloHitResponse::add(const CaloSamples & signal)
98 {
99  DetId id(signal.id());
100  CaloSamples * oldSignal = findSignal(id);
101  if (oldSignal == nullptr) {
102  theAnalogSignalMap[id] = signal;
103 
104  } else {
105  (*oldSignal) += signal;
106  }
107 }
108 
109 
110 CaloSamples CaloHitResponse::makeAnalogSignal(const PCaloHit & hit, CLHEP::HepRandomEngine* engine) const {
111 
112  DetId detId(hit.id());
114  double signal = analogSignalAmplitude(detId, hit.energy(), parameters, engine);
115 
116  double time = hit.time();
117  double tof = timeOfFlight(detId);
118  if(ignoreTime) time = tof;
119  if(theHitCorrection != nullptr) {
120  time += theHitCorrection->delay(hit, engine);
121  }
122  double jitter = time - tof;
123 
124  const CaloVShape * shape = theShape;
125  if(!shape) {
126  shape = theShapes->shape(detId,storePrecise);
127  }
128  // assume bins count from zero, go for center of bin
129  const double tzero = ( shape->timeToRise()
130  + parameters.timePhase()
131  - jitter
132  - BUNCHSPACE*( parameters.binOfMaximum()
133  - thePhaseShift_ ) ) ;
134  double binTime = tzero;
135 
137 
138  if(storePrecise){
139  result.resetPrecise();
140  int sampleBin(0);
141  //use 1ns binning for precise sample
142  for(int bin = 0; bin < result.size()*BUNCHSPACE; bin++) {
143  sampleBin = bin/BUNCHSPACE;
144  double pulseBit = (*shape)(binTime)* signal;
145  result[sampleBin] += pulseBit;
146  result.preciseAtMod(bin) += pulseBit;
147  binTime += 1.0;
148  }
149  }
150  else {
151  for(int bin = 0; bin < result.size(); bin++) {
152  result[bin] += (*shape)(binTime)* signal;
153  binTime += BUNCHSPACE;
154  }
155  }
156  return result;
157 }
158 
159 double CaloHitResponse::analogSignalAmplitude(const DetId & detId, float energy, const CaloSimParameters & parameters, CLHEP::HepRandomEngine* engine) const {
160 
161  // OK, the "energy" in the hit could be a real energy, deposited energy,
162  // or pe count. This factor converts to photoelectrons
163  //GMA Smeared in photon production it self
164  double npe = energy * parameters.simHitToPhotoelectrons(detId);
165  // do we need to doPoisson statistics for the photoelectrons?
166  if(parameters.doPhotostatistics()) {
167  npe = CLHEP::RandPoissonQ::shoot(engine,npe);
168  }
169  if(thePECorrection) npe = thePECorrection->correctPE(detId, npe, engine);
170  return npe;
171 }
172 
173 
175  CaloSamples * result = nullptr;
176  AnalogSignalMap::iterator signalItr = theAnalogSignalMap.find(detId);
177  if(signalItr == theAnalogSignalMap.end()) {
178  result = nullptr;
179  } else {
180  result = &(signalItr->second);
181  }
182  return result;
183 }
184 
185 
188  int preciseSize(storePrecise ? parameters.readoutFrameSize()*BUNCHSPACE : 0);
189  CaloSamples result(detId, parameters.readoutFrameSize(),preciseSize);
190  result.setPresamples(parameters.binOfMaximum()-1);
191  if(storePrecise) result.setPrecise(result.presamples()*BUNCHSPACE,1.0);
192  return result;
193 }
194 
195 
196 double CaloHitResponse::timeOfFlight(const DetId & detId) const {
197  // not going to assume there's one of these per subdetector.
198  // Take the whole CaloGeometry and find the right subdet
199  double result = 0.;
200  if(theGeometry == nullptr) {
201  edm::LogWarning("CaloHitResponse") << "No Calo Geometry set, so no time of flight correction";
202  }
203  else {
204  const CaloCellGeometry* cellGeometry = theGeometry->getSubdetectorGeometry(detId)->getGeometry(detId);
205  if(cellGeometry == nullptr) {
206  edm::LogWarning("CaloHitResponse") << "No Calo cell found for ID"
207  << detId.rawId() << " so no time-of-flight subtraction will be done";
208  }
209  else {
210  double distance = cellGeometry->getPosition().mag();
211  result = distance * cm / c_light; // Units of c_light: mm/ns
212  }
213  }
214  return result;
215 }
216 
217 
#define LogDebug(id)
size
Write out results.
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:45
CaloSamples makeBlankSignal(const DetId &detId) const
creates an empty signal for this DetId
double time() const
Definition: PCaloHit.h:36
virtual ~CaloHitResponse()
doesn&#39;t delete the pointers passed in
virtual const CaloVShape * shape(const DetId &detId, bool precise=false) const
Definition: CaloShapes.h:15
bool withinBunchRange(int bunchCrossing) const
check if crossing is within bunch range:
virtual const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
double energy() const
Definition: PCaloHit.h:29
bool doPhotostatistics() const
whether or not to apply Poisson statistics to photoelectrons
virtual bool keepBlank() const
virtual double delay(const PCaloHit &hit, CLHEP::HepRandomEngine *) const =0
Electronic response of the preamp.
Definition: CaloVShape.h:11
void resetPrecise()
Definition: CaloSamples.cc:27
CaloHitResponse(const CaloVSimParameterMap *parameterMap, const CaloVShape *shape)
#define nullptr
virtual void run(const MixCollection< PCaloHit > &hits, CLHEP::HepRandomEngine *)
Complete cell digitization.
Main class for Parameters in different subdetectors.
const CaloGeometry * theGeometry
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
const CaloVPECorrection * thePECorrection
const int keep
virtual bool accepts(const PCaloHit &hit) const =0
virtual double timeToRise() const =0
T mag() const
Definition: PV3DBase.h:67
bool isNotFinite(T x)
Definition: isFinite.h:10
virtual CaloSamples makeAnalogSignal(const PCaloHit &inputHit, CLHEP::HepRandomEngine *) const
creates the signal corresponding to this hit
virtual const CaloSimParameters & simParameters(const DetId &id) const =0
double simHitToPhotoelectrons() const
iterator end() const
unsigned int id() const
Definition: PCaloHit.h:43
double timeOfFlight(const DetId &detId) const
int readoutFrameSize() const
for now, the LinearFrames and trhe digis will be one-to-one.
const CaloVHitCorrection * theHitCorrection
bin
set the eta bin as selection string.
AnalogSignalMap theAnalogSignalMap
Definition: DetId.h:18
double analogSignalAmplitude(const DetId &id, float energy, const CaloSimParameters &parameters, CLHEP::HepRandomEngine *) const
const CaloShapes * theShapes
const CaloVSimParameterMap * theParameterMap
int size() const
get the size
Definition: CaloSamples.h:24
virtual double correctPE(const DetId &detId, double npe, CLHEP::HepRandomEngine *) const =0
void setBunchRange(int minBunch, int maxBunch)
tells it which pileup bunches to do
CaloSamples * findSignal(const DetId &detId)
users can look for the signal for a given cell
float & preciseAtMod(int i)
mutable function to access precise samples
Definition: CaloSamples.h:31
virtual void add(const PCaloHit &hit, CLHEP::HepRandomEngine *)
process a single SimHit
static const double tzero[3]
const CaloVHitFilter * theHitFilter
const CaloVShape * theShape
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21
iterator begin() const
int binOfMaximum() const