CMS 3D CMS Logo

HcalTimeSlewSim.cc
Go to the documentation of this file.
10 
11 #include "CLHEP/Random/RandGaussQ.h"
12 
14  : theParameterMap(parameterMap), minFCToDelay_(minFCToDelay) {}
15 
16 // not quite adequate to 25ns high-PU regime
18  double totalCharge = 0.;
19  for (int i = 0; i < 4; ++i) {
20  int bin = i + samples.presamples();
21  if (bin < samples.size()) {
22  totalCharge += samples[bin];
23  }
24  }
25  return totalCharge;
26 }
27 
29  CLHEP::HepRandomEngine* engine,
30  const HcalTimeSlew* hcalTimeSlew_delay) const {
31  // HO goes slow, HF shouldn't be used at all
32  //ZDC not used for the moment
33 
34  DetId detId(cs.id());
35  if (detId.det() == DetId::Calo && detId.subdetId() == HcalZDCDetId::SubdetectorId)
36  return;
37  HcalDetId hcalDetId(detId);
38 
39  if (hcalDetId.subdet() == HcalBarrel || hcalDetId.subdet() == HcalEndcap || hcalDetId.subdet() == HcalOuter) {
40  HcalTimeSlew::BiasSetting biasSetting =
42 
43  // double totalCharge = charge(cs); // old TS...
44 
45  int maxbin = cs.size();
46  CaloSamples data(detId, maxbin); // for a temporary copy
47  data = cs;
48 
49  // smearing
50  int soi = cs.presamples();
51  double eps = 1.e-6;
52  double scale_factor = 0.6;
53  double scale = cs[soi] / scale_factor;
54  double smearns = 0.;
55  double cut = minFCToDelay_; //5. fC (above mean) for signal to be delayed
56 
58  if (params.doTimeSmear()) {
59  double rms = params.timeSmearRMS(scale);
60  smearns = CLHEP::RandGaussQ::shoot(engine) * rms;
61  LogDebug("HcalTimeSlewSim") << "TimeSmear charge " << scale << " rms " << rms << " smearns " << smearns;
62  }
63 
64  // cycle over TS', it - current TS index
65  for (int it = 0; it < maxbin - 1;) {
66  double datai = cs[it];
67  int nts = 0;
68  double tshift = smearns;
69  double totalCharge = datai / scale_factor;
70 
71  // until we get more precise/reliable QIE8 simulation...
72  if (totalCharge <= 0.)
73  totalCharge = eps; // protecion against negaive v.
74  tshift += hcalTimeSlew_delay->delay(totalCharge, biasSetting);
75  if (tshift <= 0.)
76  tshift = eps;
77 
78  if (cut > -999.) { //preserve compatibility
79  if ((datai > cut) && (it == 0 || (datai > cs[it - 1]))) {
80  // number of TS affected by current move depends on the signal shape:
81  // rising or peaking
82  nts = 2; // rising
83  if (datai > cs[it + 1])
84  nts = 3; // peaking
85 
86  // 1 or 2 TS to move from here,
87  // 2d or 3d TS gets leftovers to preserve the sum
88  for (int j = it; j < it + nts && j < maxbin; ++j) {
89  // snippet borrowed from CaloSamples::offsetTime(offset)
90  // CalibFormats/CaloObjects/src/CaloSamples.cc
91  double t = j * 25. - tshift;
92  int firstbin = floor(t / 25.);
93  double f = t / 25. - firstbin;
94  int nextbin = firstbin + 1;
95  double v1 = (firstbin < 0 || firstbin >= maxbin) ? 0. : cs[firstbin];
96  double v2 = (nextbin < 0 || nextbin >= maxbin) ? 0. : cs[nextbin];
97 
98  // Keeping the overal sum intact
99  if (nts == 2) {
100  if (j == it)
101  data[j] = v2 * f;
102  else
103  data[j] = v1 * (1. - f) + v2;
104  } else { // nts = 3
105  if (j == it)
106  data[j] = v2 * f;
107  if (j == it + 1)
108  data[j] = v1 * (1. - f) + v2 * f;
109  if (j == it + nts - 1)
110  data[j] = v1 * (1. - f) + v2;
111  }
112 
113  } // end of local move of TS', now update...
114  cs = data;
115 
116  } // end of rising edge or peak finding
117  } else {
118  double t = it * 25. - tshift;
119  int firstbin = floor(t / 25.);
120  double f = t / 25. - firstbin;
121  int nextbin = firstbin + 1;
122  double v2 = (nextbin < 0 || nextbin >= maxbin) ? 0. : data[nextbin];
123  data[it] = v2 * f;
124  data[it + 1] += (v2 - data[it]);
125  cs = data;
126  }
127 
128  if (nts < 3)
129  it++;
130  else
131  it += 2;
132  }
133 
134  // final update of the shifted TS array
135  cs = data;
136  }
137 }
HcalTimeSlewSim(const CaloVSimParameterMap *parameterMap, double minFCToDelay)
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
double charge(const CaloSamples &samples) const
float delay(float fC, BiasSetting bias=Medium) const
Returns the amount (ns) by which a pulse of the given number of fC will be delayed by the timeslew ef...
Definition: HcalTimeSlew.cc:20
virtual const CaloSimParameters & simParameters(const DetId &id) const =0
double f[11][100]
const CaloVSimParameterMap * theParameterMap
Definition: DetId.h:17
static const int SubdetectorId
Definition: HcalZDCDetId.h:25
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
void delay(CaloSamples &samples, CLHEP::HepRandomEngine *, const HcalTimeSlew *hcalTimeSlew_delay) const
#define LogDebug(id)