CMS 3D CMS Logo

SSDigitizerAlgorithm.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <cmath>
3 
5 
9 
10 // Geometry
14 
15 using namespace edm;
16 
19  : Phase2TrackerDigitizerAlgorithm(conf.getParameter<ParameterSet>("AlgorithmCommon"),
20  conf.getParameter<ParameterSet>("SSDigitizerAlgorithm")),
21  hitDetectionMode_(conf.getParameter<ParameterSet>("SSDigitizerAlgorithm").getParameter<int>("HitDetectionMode")),
22  pulseShapeParameters_(conf.getParameter<ParameterSet>("SSDigitizerAlgorithm")
23  .getParameter<std::vector<double> >("PulseShapeParameters")),
24  deadTime_(conf.getParameter<ParameterSet>("SSDigitizerAlgorithm").getParameter<double>("CBCDeadTime")) {
25  pixelFlag_ = false;
26  LogDebug("SSDigitizerAlgorithm ") << "SSDigitizerAlgorithm constructed "
27  << "Configuration parameters:"
28  << "Threshold/Gain = "
29  << "threshold in electron Endcap = " << theThresholdInE_Endcap_
30  << "threshold in electron Barrel = " << theThresholdInE_Barrel_ << " "
31  << theElectronPerADC_ << " " << theAdcFullScale_ << " The delta cut-off is set to "
32  << tMax_ << " pix-inefficiency " << addPixelInefficiency_;
34 }
35 SSDigitizerAlgorithm::~SSDigitizerAlgorithm() { LogDebug("SSDigitizerAlgorithm") << "SSDigitizerAlgorithm deleted"; }
36 void SSDigitizerAlgorithm::accumulateSimHits(std::vector<PSimHit>::const_iterator inputBegin,
37  std::vector<PSimHit>::const_iterator inputEnd,
38  const size_t inputBeginGlobalIndex,
39  const uint32_t tofBin,
40  const Phase2TrackerGeomDetUnit* pixdet,
41  const GlobalVector& bfield) {
42  // produce SignalPoint's for all SimHit's in detector
43  // Loop over hits
44  uint32_t detId = pixdet->geographicalId().rawId();
45  size_t simHitGlobalIndex = inputBeginGlobalIndex; // This needs to be stored to create the digi-sim link later
46 
47  // find the relevant hits
48  std::vector<PSimHit> matchedSimHits;
49  std::copy_if(inputBegin, inputEnd, std::back_inserter(matchedSimHits), [detId](auto const& hit) -> bool {
50  return hit.detUnitId() == detId;
51  });
52  // loop over a much reduced set of SimHits
53  for (auto const& hit : matchedSimHits) {
54  LogDebug("SSDigitizerAlgorithm") << hit.particleType() << " " << hit.pabs() << " " << hit.energyLoss() << " "
55  << hit.tof() << " " << hit.trackId() << " " << hit.processType() << " "
56  << hit.detUnitId() << hit.entryPoint() << " " << hit.exitPoint();
57 
58  std::vector<DigitizerUtility::EnergyDepositUnit> ionization_points;
59  std::vector<DigitizerUtility::SignalPoint> collection_points;
60 
61  double signalScale = 1.0;
62  // fill collection_points for this SimHit, indpendent of topology
63  if (select_hit(hit, (pixdet->surface().toGlobal(hit.localPosition()).mag() * c_inv), signalScale)) {
64  primary_ionization(hit, ionization_points); // fills ionization_points
65 
66  // transforms ionization_points -> collection_points
67  drift(hit, pixdet, bfield, ionization_points, collection_points);
68 
69  // compute induced signal on readout elements and add to _signal
70  // hit needed only for SimHit<-->Digi link
71  induce_signal(hit, simHitGlobalIndex, tofBin, pixdet, collection_points);
72  }
73  ++simHitGlobalIndex;
74  }
75 }
76 //
77 // -- Select the Hit for Digitization
78 //
79 bool SSDigitizerAlgorithm::select_hit(const PSimHit& hit, double tCorr, double& sigScale) {
80  bool result = false;
82  result = select_hit_sampledMode(hit, tCorr, sigScale);
84  result = select_hit_latchedMode(hit, tCorr, sigScale);
85  else {
86  double toa = hit.tof() - tCorr;
87  result = (toa > theTofLowerCut_ && toa < theTofUpperCut_);
88  }
89  return result;
90 }
91 //
92 // -- Select Hits in Sampled Mode
93 //
94 bool SSDigitizerAlgorithm::select_hit_sampledMode(const PSimHit& hit, double tCorr, double& sigScale) {
95  double toa = hit.tof() - tCorr;
96  double sampling_time = bx_time;
97 
98  DetId det_id = DetId(hit.detUnitId());
99  float theThresholdInE =
101 
102  sigScale = getSignalScale(sampling_time - toa);
103  return (sigScale * hit.energyLoss() / GeVperElectron_ > theThresholdInE);
104 }
105 //
106 // -- Select Hits in Hit Detection Mode
107 //
108 bool SSDigitizerAlgorithm::select_hit_latchedMode(const PSimHit& hit, double tCorr, double& sigScale) {
109  float toa = hit.tof() - tCorr;
110  toa -= hit.eventId().bunchCrossing() * bx_time;
111 
112  float sampling_time = (-1) * (hit.eventId().bunchCrossing() + 1) * bx_time;
113 
114  DetId det_id = DetId(hit.detUnitId());
115  float theThresholdInE =
117 
118  bool lastPulse = true;
119  bool aboveThr = false;
120  for (float i = deadTime_; i <= bx_time; i++) {
121  sigScale = getSignalScale(sampling_time - toa + i);
122 
123  aboveThr = (sigScale * hit.energyLoss() / GeVperElectron_ > theThresholdInE);
124  if (!lastPulse && aboveThr)
125  return true;
126 
127  lastPulse = aboveThr;
128  }
129  return false;
130 }
131 
132 double SSDigitizerAlgorithm::nFactorial(int n) { return std::tgamma(n + 1); }
134  return std::pow(-1, (double)i) * nFactorial(N) * nFactorial(N + 2) /
135  (nFactorial(N - i) * nFactorial(N + 2 - i) * nFactorial(i));
136 }
138  constexpr size_t max_par = 6;
139  if (pulseShapeParameters_.size() < max_par)
140  return -1;
141  double xOffset = pulseShapeParameters_[0];
142  double tau = pulseShapeParameters_[1];
143  double r = pulseShapeParameters_[2];
144  double theta = pulseShapeParameters_[3];
145  int nTerms = static_cast<int>(pulseShapeParameters_[4]);
146 
147  double fN = 0;
148  double xx = x - xOffset;
149  if (xx < 0)
150  return 0;
151 
152  for (int i = 0; i < nTerms; i++) {
153  double angularTerm = 0;
154  double temporalTerm = 0;
155  double rTerm = std::pow(r, i) / (std::pow(tau, 2. * i) * nFactorial(i + 2));
156  for (int j = 0; j <= i; j++) {
157  angularTerm += std::pow(std::cos(theta), (double)(i - j)) * std::pow(std::sin(theta), (double)j);
158  temporalTerm += aScalingConstant(i, j) * std::pow(xx, (double)(i - j)) * std::pow(tau, (double)j);
159  }
160  double fi = rTerm * angularTerm * temporalTerm;
161 
162  fN += fi;
163  }
164  return fN;
165 }
167  double xOffset = pulseShapeParameters_[0];
168  double tau = pulseShapeParameters_[1];
169  double maxCharge = pulseShapeParameters_[5];
170 
171  double xx = x - xOffset;
172  return maxCharge * (std::exp(-xx / tau) * std::pow(xx / tau, 2.) * cbc3PulsePolarExpansion(x));
173 }
175  for (size_t i = 0; i < interpolationPoints; i++) {
176  float val = i / interpolationStep;
177 
178  pulseShapeVec_.push_back(signalShape(val));
179  }
180 }
182  double res = 0.0;
183  int len = pulseShapeVec_.size();
184 
185  if (xval < 0.0 || xval * interpolationStep >= len)
186  return res;
187 
188  unsigned int lower = std::floor(xval) * interpolationStep;
189  unsigned int upper = std::ceil(xval) * interpolationStep;
190  for (size_t i = lower + 1; i < upper * interpolationStep; i++) {
191  float val = i * 0.1;
192  if (val > xval) {
193  res = pulseShapeVec_[i - 1];
194  break;
195  }
196  }
197  return res;
198 }
199 //
200 // -- Compare Signal with Threshold
201 //
203  float charge,
204  float thr) {
205  return (charge >= thr);
206 }
Vector3DBase
Definition: Vector3DBase.h:8
SSDigitizerAlgorithm::storeSignalShape
void storeSignalShape()
Definition: SSDigitizerAlgorithm.cc:174
Phase2TrackerDigitizerAlgorithm::theThresholdInE_Barrel_
const float theThresholdInE_Barrel_
Definition: Phase2TrackerDigitizerAlgorithm.h:141
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
SSDigitizerAlgorithm::SSDigitizerAlgorithm
SSDigitizerAlgorithm(const edm::ParameterSet &conf)
Definition: SSDigitizerAlgorithm.cc:18
Phase2TrackerDigitizerAlgorithm::theTofUpperCut_
const float theTofUpperCut_
Definition: Phase2TrackerDigitizerAlgorithm.h:150
metsig::tau
Definition: SignAlgoResolutions.h:49
SSDigitizerAlgorithm::interpolationStep
static constexpr int interpolationStep
Definition: SSDigitizerAlgorithm.h:41
SSDigitizerAlgorithm::pulseShapeVec_
std::vector< double > pulseShapeVec_
Definition: SSDigitizerAlgorithm.h:36
edm
HLT enums.
Definition: AlignableModifier.h:19
SSDigitizerAlgorithm::getSignalScale
double getSignalScale(double xval)
Definition: SSDigitizerAlgorithm.cc:181
SSDigitizerAlgorithm::interpolationPoints
static constexpr size_t interpolationPoints
Definition: SSDigitizerAlgorithm.h:40
SSDigitizerAlgorithm::bx_time
static constexpr float bx_time
Definition: SSDigitizerAlgorithm.h:39
SSDigitizerAlgorithm::~SSDigitizerAlgorithm
~SSDigitizerAlgorithm() override
Definition: SSDigitizerAlgorithm.cc:35
DDAxes::x
SSDigitizerAlgorithm::nFactorial
double nFactorial(int n)
Definition: SSDigitizerAlgorithm.cc:132
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Phase2TrackerDigitizerAlgorithm::theTofLowerCut_
const float theTofLowerCut_
Definition: Phase2TrackerDigitizerAlgorithm.h:149
DetId
Definition: DetId.h:17
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
Phase2TrackerDigitizerAlgorithm::primary_ionization
void primary_ionization(const PSimHit &hit, std::vector< DigitizerUtility::EnergyDepositUnit > &ionization_points) const
Definition: Phase2TrackerDigitizerAlgorithm.cc:183
SSDigitizerAlgorithm::cbc3PulsePolarExpansion
double cbc3PulsePolarExpansion(double x)
Definition: SSDigitizerAlgorithm.cc:137
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
reco::ceil
constexpr int32_t ceil(float num)
Definition: constexpr_cmath.h:7
Phase2TrackerDigitizerAlgorithm::theAdcFullScale_
const int theAdcFullScale_
Definition: Phase2TrackerDigitizerAlgorithm.h:135
SSDigitizerAlgorithm::accumulateSimHits
void accumulateSimHits(const std::vector< PSimHit >::const_iterator inputBegin, const std::vector< PSimHit >::const_iterator inputEnd, const size_t inputBeginGlobalIndex, const uint32_t tofBin, const Phase2TrackerGeomDetUnit *pixdet, const GlobalVector &bfield) override
Definition: SSDigitizerAlgorithm.cc:36
SSDigitizerAlgorithm::LatchedMode
Definition: SSDigitizerAlgorithm.h:25
Service.h
PixelGeomDetUnit
Definition: PixelGeomDetUnit.h:15
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
vertices_cff.x
x
Definition: vertices_cff.py:29
Surface::toGlobal
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
SSDigitizerAlgorithm::signalShape
double signalShape(double x)
Definition: SSDigitizerAlgorithm.cc:166
Phase2TrackerDigitizerAlgorithm::induce_signal
void induce_signal(const PSimHit &hit, const size_t hitIndex, const uint32_t tofBin, const Phase2TrackerGeomDetUnit *pixdet, const std::vector< DigitizerUtility::SignalPoint > &collection_points)
Definition: Phase2TrackerDigitizerAlgorithm.cc:389
SSDigitizerAlgorithm::pulseShapeParameters_
std::vector< double > pulseShapeParameters_
Definition: SSDigitizerAlgorithm.h:37
N
#define N
Definition: blowfish.cc:9
theta
Geom::Theta< T > theta() const
Definition: Basic3DVectorLD.h:150
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
hcaldqm::quantity::fN
Definition: ValueQuantity.h:11
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
SSDigitizerAlgorithm::select_hit_sampledMode
bool select_hit_sampledMode(const PSimHit &hit, double tCorr, double &sigScale)
Definition: SSDigitizerAlgorithm.cc:94
GeomDet::geographicalId
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
TrackerDigiGeometryRecord.h
SSDigitizerAlgorithm.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
Phase2TrackerDigitizerAlgorithm
Definition: Phase2TrackerDigitizerAlgorithm.h:58
Phase2TrackerDigitizerAlgorithm::pixelFlag_
bool pixelFlag_
Definition: Phase2TrackerDigitizerAlgorithm.h:241
Phase2TrackerDigitizerAlgorithm::tMax_
const double tMax_
Definition: Phase2TrackerDigitizerAlgorithm.h:173
edm::get
T const & get(Event const &event, InputTag const &tag) noexcept(false)
Definition: Event.h:669
createfilelist.int
int
Definition: createfilelist.py:10
phase1PixelTopology::xOffset
constexpr int16_t xOffset
Definition: phase1PixelTopology.h:18
SSDigitizerAlgorithm::deadTime_
float deadTime_
Definition: SSDigitizerAlgorithm.h:38
Phase2TrackerDigitizerAlgorithm::theElectronPerADC_
const float theElectronPerADC_
Definition: Phase2TrackerDigitizerAlgorithm.h:134
edm::EventSetup
Definition: EventSetup.h:57
Phase2TrackerDigitizerAlgorithm::GeVperElectron_
const float GeVperElectron_
Definition: Phase2TrackerDigitizerAlgorithm.h:120
SSDigitizerAlgorithm::aScalingConstant
double aScalingConstant(int N, int i)
Definition: SSDigitizerAlgorithm.cc:133
res
Definition: Electron.h:6
Phase2TrackerDigitizerAlgorithm::theThresholdInE_Endcap_
const float theThresholdInE_Endcap_
Definition: Phase2TrackerDigitizerAlgorithm.h:140
alignCSCRings.r
r
Definition: alignCSCRings.py:93
DigitizerUtility::SimHitInfo
Definition: DigitizerUtility.h:14
mag
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Definition: Basic3DVectorLD.h:127
heppy_batch.val
val
Definition: heppy_batch.py:351
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
c_inv
constexpr double c_inv
Definition: Phase2TrackerDigitizerAlgorithm.h:56
SSDigitizerAlgorithm::select_hit
bool select_hit(const PSimHit &hit, double tCorr, double &sigScale) override
Definition: SSDigitizerAlgorithm.cc:79
SSDigitizerAlgorithm::init
void init(const edm::EventSetup &es) override
Definition: SSDigitizerAlgorithm.cc:17
SSDigitizerAlgorithm::hitDetectionMode_
int hitDetectionMode_
Definition: SSDigitizerAlgorithm.h:35
SSDigitizerAlgorithm::isAboveThreshold
bool isAboveThreshold(const DigitizerUtility::SimHitInfo *hitInfo, float charge, float thr) override
Definition: SSDigitizerAlgorithm.cc:202
SSDigitizerAlgorithm::SampledMode
Definition: SSDigitizerAlgorithm.h:25
PixelGeomDetUnit.h
StripSubdetector::TOB
static constexpr auto TOB
Definition: StripSubdetector.h:18
pileupCalc.upper
upper
Definition: pileupCalc.py:214
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
mps_fire.result
result
Definition: mps_fire.py:303
Phase2TrackerDigitizerAlgorithm::drift
void drift(const PSimHit &hit, const Phase2TrackerGeomDetUnit *pixdet, const GlobalVector &bfield, const std::vector< DigitizerUtility::EnergyDepositUnit > &ionization_points, std::vector< DigitizerUtility::SignalPoint > &collection_points) const
Definition: Phase2TrackerDigitizerAlgorithm.cc:293
ParameterSet.h
PSimHit
Definition: PSimHit.h:15
Phase2TrackerDigitizerAlgorithm::addPixelInefficiency_
const bool addPixelInefficiency_
Definition: Phase2TrackerDigitizerAlgorithm.h:160
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
StripSubdetector.h
geometryCSVtoXML.xx
xx
Definition: geometryCSVtoXML.py:19
hit
Definition: SiStripHitEffFromCalibTree.cc:88
SSDigitizerAlgorithm::select_hit_latchedMode
bool select_hit_latchedMode(const PSimHit &hit, double tCorr, double &sigScale)
Definition: SSDigitizerAlgorithm.cc:108