CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalSiPMHitResponse.cc
Go to the documentation of this file.
13 
14 #include <math.h>
15 
17  const CaloShapes * shapes) :
18  CaloHitResponse(parameterMap, shapes), theSiPM(), theRecoveryTime(250.),
19  TIMEMULT(1), Y11RANGE(80.), Y11MAX(0.04), Y11TIMETORISE(16.65),
20  theRndFlat(0) {
21  theSiPM = new HcalSiPM(2500);
22 }
23 
25  if (theSiPM)
26  delete theSiPM;
27  delete theRndFlat;
28 }
29 
31  precisionTimedPhotons.clear();
32 }
33 
35 
36  photonTimeMap::iterator channelPhotons;
37  for (channelPhotons = precisionTimedPhotons.begin();
38  channelPhotons != precisionTimedPhotons.end();
39  ++channelPhotons) {
40  CaloSamples signal(makeSiPMSignal(channelPhotons->first,
41  channelPhotons->second));
42  bool keep( keepBlank() );
43  if (!keep) {
44  const unsigned int size ( signal.size() ) ;
45  if( 0 != size ) {
46  for( unsigned int i ( 0 ) ; i != size ; ++i ) {
47  keep = keep || signal[i] > 1.e-7 ;
48  }
49  }
50  }
51 
52  LogDebug("HcalSiPMHitResponse") << HcalDetId(signal.id()) << ' ' << signal;
53  if (keep) add(signal);
54  }
55 }
56 
58  DetId id(signal.id());
59  CaloSamples * oldSignal = findSignal(id);
60  if (oldSignal == 0) {
61  theAnalogSignalMap[id] = signal;
62  } else {
63  (*oldSignal) += signal;
64  }
65 }
66 
68  if (!edm::isNotFinite(hit.time()) &&
69  ((theHitFilter == 0) || (theHitFilter->accepts(hit)))) {
70  HcalDetId id(hit.id());
71  const HcalSimParameters& pars = dynamic_cast<const HcalSimParameters&>(theParameterMap->simParameters(id));
72  double signal(analogSignalAmplitude(id, hit.energy(), pars));
73  unsigned int photons(signal + 0.5);
74  double time( hit.time() );
75 
76  if (photons > 0)
77  if (precisionTimedPhotons.find(id)==precisionTimedPhotons.end()) {
78  precisionTimedPhotons.insert(
79  std::pair<DetId, photonTimeHist >(id,
81  pars.readoutFrameSize(), 0)
82  )
83  );
84  }
85 
86  LogDebug("HcalSiPMHitResponse") << id;
87  LogDebug("HcalSiPMHitResponse") << " fCtoGeV: " << pars.fCtoGeV(id)
88  << " samplingFactor: " << pars.samplingFactor(id)
89  << " photoelectronsToAnalog: " << pars.photoelectronsToAnalog(id)
90  << " simHitToPhotoelectrons: " << pars.simHitToPhotoelectrons(id);
91  LogDebug("HcalSiPMHitResponse") << " energy: " << hit.energy()
92  << " photons: " << photons
93  << " time: " << time;
94  if (theHitCorrection != 0)
95  time += theHitCorrection->delay(hit);
96  LogDebug("HcalSiPMHitResponse") << " corrected time: " << time;
97  LogDebug("HcalSiPMHitResponse") << " timePhase: " << pars.timePhase()
98  << " tof: " << timeOfFlight(id)
99  << " binOfMaximum: " << pars.binOfMaximum()
100  << " phaseShift: " << thePhaseShift_;
101  double tzero(Y11TIMETORISE + pars.timePhase() -
102  (hit.time() - timeOfFlight(id)) -
103  BUNCHSPACE*( pars.binOfMaximum() - thePhaseShift_));
104  LogDebug("HcalSiPMHitResponse") << " tzero: " << tzero;
105  tzero += BUNCHSPACE*pars.binOfMaximum() + 72.31;
106  LogDebug("HcalSiPMHitResponse") << " corrected tzero: " << tzero << '\n';
107  double t_pe(0.);
108  int t_bin(0);
109  for (unsigned int pe(0); pe<photons; ++pe) {
110  t_pe = generatePhotonTime();
111  t_bin = int((t_pe + tzero)/(theTDCParams.deltaT()/TIMEMULT) + 0.5);
112  LogDebug("HcalSiPMHitResponse") << "t_pe: " << t_pe << " t_pe + tzero: " << (t_pe+tzero)
113  << " t_bin: " << t_bin << '\n';
114  if ((t_bin >= 0) &&
115  (static_cast<unsigned int>(t_bin) < precisionTimedPhotons[id].size()))
116  precisionTimedPhotons[id][t_bin] += 1;
117  }
118  }
119 }
120 
122  typedef std::multiset <const PCaloHit *, PCaloHitCompareTimes> SortedHitSet;
123 
124  std::map< DetId, SortedHitSet > sortedhits;
125  for (MixCollection<PCaloHit>::MixItr hitItr = hits.begin();
126  hitItr != hits.end(); ++hitItr) {
127  if (!((hitItr.bunch() < theMinBunch) || (hitItr.bunch() > theMaxBunch)) &&
128  !(edm::isNotFinite(hitItr->time())) &&
129  ((theHitFilter == 0) || (theHitFilter->accepts(*hitItr)))) {
130  DetId id(hitItr->id());
131  if (sortedhits.find(id)==sortedhits.end())
132  sortedhits.insert(std::pair<DetId, SortedHitSet>(id, SortedHitSet()));
133  sortedhits[id].insert(&(*hitItr));
134  }
135  }
136  int pixelIntegral, oldIntegral;
137  HcalSiPMRecovery pixelHistory(theRecoveryTime);
138  for (std::map<DetId, SortedHitSet>::iterator i = sortedhits.begin();
139  i!=sortedhits.end(); ++i) {
140  pixelHistory.clearHistory();
141  for (SortedHitSet::iterator itr = i->second.begin();
142  itr != i->second.end(); ++itr) {
143  const PCaloHit& hit = **itr;
144  pixelIntegral = pixelHistory.getIntegral(hit.time());
145  oldIntegral = pixelIntegral;
146  CaloSamples signal(makeSiPMSignal(i->first, hit, pixelIntegral));
147  pixelHistory.addToHistory(hit.time(), pixelIntegral-oldIntegral);
148  add(signal);
149  }
150  }
151 }
152 
153 
154 void HcalSiPMHitResponse::setRandomEngine(CLHEP::HepRandomEngine & engine)
155 {
156  theSiPM->initRandomEngine(engine);
158  theRndFlat = new CLHEP::RandFlat(engine);
159 }
160 
163  int preciseSize(parameters.readoutFrameSize()*theTDCParams.nbins());
164  CaloSamples result(detId, parameters.readoutFrameSize(), preciseSize);
165  result.setPresamples(parameters.binOfMaximum()-1);
166  result.setPrecise(result.presamples()*theTDCParams.nbins(),
167  theTDCParams.deltaT());
168  return result;
169 }
170 
172  const PCaloHit & inHit,
173  int & integral ) const {
174 
175  PCaloHit hit = inHit;
176  if (theHitCorrection != 0) {
177  hit.setTime(hit.time() + theHitCorrection->delay(hit));
178  }
179 
180  const HcalSimParameters& pars = dynamic_cast<const HcalSimParameters&>(theParameterMap->simParameters(id));
181  theSiPM->setNCells(pars.pixels());
182 
183  double signal = analogSignalAmplitude(id, hit.energy(), pars);
184  int photons = static_cast<int>(signal + 0.5);
185  int pixels = theSiPM->hitCells(photons, integral);
186  integral += pixels;
187  signal = double(pixels);
188 
190 
191  if(pixels > 0)
192  {
193  const CaloVShape * shape = theShapes->shape(id);
194  double jitter = hit.time() - timeOfFlight(id);
195 
196  const double tzero = pars.timePhase() - jitter -
198  double binTime = tzero;
199 
200  for (int bin = 0; bin < result.size(); bin++) {
201  result[bin] += (*shape)(binTime)*signal;
202  binTime += BUNCHSPACE;
203  }
204  }
205 
206  return result;
207 }
208 
210  photonTimeHist const& photons) const {
211  const HcalSimParameters& pars = dynamic_cast<const HcalSimParameters&>(theParameterMap->simParameters(id));
212  theSiPM->setNCells(pars.pixels());
213  theSiPM->setTau(5.);
214  //use to make signal
215  CaloSamples signal( makeBlankSignal(id) );
216  double const dt(theTDCParams.deltaT()/TIMEMULT);
217  double const invdt(1./theTDCParams.deltaT());
218  int sampleBin(0), preciseBin(0);
219  signal.resetPrecise();
220  unsigned int pe(0);
221  double hitPixels(0.), elapsedTime(0.);
222  unsigned int sumPE(0);
223  double sumHits(0.);
224  // std::cout << HcalDetId(id) << '\n';
225  for (unsigned int pt(0); pt < photons.size(); ++pt) {
226  pe = photons[pt];
227  sumPE += pe;
228  preciseBin = pt/TIMEMULT;
229  sampleBin = preciseBin/theTDCParams.nbins();
230  if (pe > 0) {
231  hitPixels = theSiPM->hitCells(pe, 0., elapsedTime);
232  signal[sampleBin] += hitPixels;
233  sumHits += hitPixels;
234  // std::cout << " elapsedTime: " << elapsedTime
235  // << " sampleBin: " << sampleBin
236  // << " preciseBin: " << preciseBin
237  // << " pe: " << pe
238  // << " hitPixels: " << hitPixels
239  // << '\n';
240  hitPixels *= invdt;
241  signal.preciseAtMod(preciseBin) += 0.6*hitPixels;
242  if (preciseBin > 0)
243  signal.preciseAtMod(preciseBin-1) += 0.2*hitPixels;
244  if (preciseBin < signal.preciseSize() -1)
245  signal.preciseAtMod(preciseBin+1) += 0.2*hitPixels;
246  }
247  // signal.preciseAtMod(preciseBin) += sumHits;
248  elapsedTime += dt;
249  }
250 
251  // differentiatePreciseSamples(signal, 1.);
252 
253  // std::cout << "sum pe: " << sumPE
254  // << " sum sipm pixels: " << sumHits
255  // << std::endl;
256 
257  return signal;
258 }
259 
261  double diffNorm) const {
262  static double const invdt(1./samples.preciseDeltaT());
263  // double dy(0.);
264  for (int i(0); i < samples.preciseSize(); ++i) {
265  // dy = samples.preciseAt(i+1) - samples.preciseAt(i);
266  samples.preciseAtMod(i) *= invdt*diffNorm;
267  }
268 }
269 
271  double result(0.);
272  while (true) {
273  result = theRndFlat->fire(Y11RANGE);
274  if (theRndFlat->fire(Y11MAX) < Y11TimePDF(result))
275  return result;
276  }
277 }
278 
280  return exp(-0.0635-0.1518*t)*pow(t, 2.528)/2485.9;
281 }
#define LogDebug(id)
float dt
Definition: AMPTWrapper.h:126
int i
Definition: DBlmapReader.cc:9
dictionary parameters
Definition: Parameters.py:2
virtual void initializeHits()
Initialize hits.
float deltaT() const
A general implementation for the response of a SiPM.
Definition: HcalSiPM.h:20
double time() const
Definition: PCaloHit.h:34
double energy() const
Definition: PCaloHit.h:29
virtual bool keepBlank() const
Electronic response of the preamp.
Definition: CaloVShape.h:11
std::multiset< PCaloHit, PCaloHitCompareTimes > SortedHitSet
static double Y11TimePDF(double t)
void resetPrecise()
Definition: CaloSamples.cc:25
int preciseSize() const
get the size
Definition: CaloSamples.h:64
Main class for Parameters in different subdetectors.
CLHEP::RandFlat * theRndFlat
virtual double delay(const PCaloHit &hit) const =0
iterator end()
double timePhase() const
the adjustment you need to apply to get the signal where you want it
const int keep
bool isNotFinite(T x)
Definition: isFinite.h:10
int getIntegral(double time)
Creates electronics signals from hits.
virtual void differentiatePreciseSamples(CaloSamples &samples, double diffNorm=1.0) const
void setNCells(int nCells)
Definition: HcalSiPM.cc:136
tuple result
Definition: query.py:137
void setTau(double tau)
Definition: HcalSiPM.h:42
virtual const CaloSimParameters & simParameters(const DetId &id) const =0
virtual bool accepts(const PCaloHit &hit) const =0
void initRandomEngine(CLHEP::HepRandomEngine &engine)
Definition: HcalSiPM.cc:159
unsigned int id() const
Definition: PCaloHit.h:41
double timeOfFlight(const DetId &detId) const
float preciseDeltaT() const
Definition: CaloSamples.h:66
double generatePhotonTime() const
double analogSignalAmplitude(const DetId &id, float energy, const CaloSimParameters &parameters) const
int readoutFrameSize() const
for now, the LinearFrames and trhe digis will be one-to-one.
const CaloVHitCorrection * theHitCorrection
Integral< F, X >::type integral(const F &f)
Definition: Integral.h:69
HcalTDCParameters theTDCParams
AnalogSignalMap theAnalogSignalMap
Definition: DetId.h:20
iterator begin()
std::vector< unsigned int > photonTimeHist
virtual CaloSamples makeBlankSignal(const DetId &detId) const
const CaloShapes * theShapes
virtual void setRandomEngine(CLHEP::HepRandomEngine &engine)
const CaloVSimParameterMap * theParameterMap
int size() const
get the size
Definition: CaloSamples.h:26
HcalSiPMHitResponse(const CaloVSimParameterMap *parameterMap, const CaloShapes *shapes)
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:33
virtual int hitCells(unsigned int photons, unsigned int integral=0) const
Definition: HcalSiPM.cc:24
void setTime(float t)
Definition: PCaloHit.h:55
virtual void run(MixCollection< PCaloHit > &hits)
Complete cell digitization.
virtual void finalizeHits()
Finalize hits.
static const double tzero[3]
virtual void add(const PCaloHit &hit)
process a single SimHit
const CaloVHitFilter * theHitFilter
virtual void setRandomEngine(CLHEP::HepRandomEngine &engine)
DetId id() const
get the (generic) id
Definition: CaloSamples.h:23
photonTimeMap precisionTimedPhotons
void addToHistory(double time, int pixels)
int binOfMaximum() const
tuple size
Write out results.
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
virtual const CaloVShape * shape(const DetId &detId) const
Definition: CaloShapes.h:15
virtual CaloSamples makeSiPMSignal(const DetId &id, const PCaloHit &hit, int &integral) const