CMS 3D CMS Logo

PreMixingSiStripWorker.cc
Go to the documentation of this file.
12 
15 
16 //Data Formats
21 
30 
36 
37 #include "CLHEP/Random/RandFlat.h"
38 
41 
42 #include <map>
43 #include <memory>
44 
46 public:
48  ~PreMixingSiStripWorker() override = default;
49 
50  void initializeEvent(edm::Event const& e, edm::EventSetup const& c) override;
51  void addSignals(edm::Event const& e, edm::EventSetup const& es) override;
52  void addPileups(PileUpEventPrincipal const& pep, edm::EventSetup const& es) override;
53  void put(edm::Event& e, edm::EventSetup const& iSetup, std::vector<PileupSummaryInfo> const& ps, int bs) override;
54 
55 private:
56  void DMinitializeDetUnit(StripGeomDetUnit const* det, const edm::EventSetup& iSetup);
57 
58  // data specifiers
59 
60  edm::InputTag SistripLabelSig_; // name given to collection of SiStrip digis
61  edm::InputTag SiStripPileInputTag_; // InputTag for pileup strips
62  std::string SiStripDigiCollectionDM_; // secondary name to be given to new SiStrip digis
63 
64  edm::InputTag SistripAPVLabelSig_; // where to find vector of dead APVs
67 
68  //
69 
70  typedef float Amplitude;
71  typedef std::pair<uint16_t, Amplitude> RawDigi; // Replacement for SiStripDigi with pulse height instead of integer ADC
72  typedef std::vector<SiStripDigi> OneDetectorMap; // maps by strip ID for later combination - can have duplicate strips
73  typedef std::vector<RawDigi> OneDetectorRawMap; // maps by strip ID for later combination - can have duplicate strips
74  typedef std::map<uint32_t, OneDetectorMap> SiGlobalIndex; // map to all data for each detector ID
75  typedef std::map<uint32_t, OneDetectorRawMap> SiGlobalRawIndex; // map to all data for each detector ID
76 
78 
81 
82  // variables for temporary storage of mixed hits:
83  typedef std::map<int, Amplitude> SignalMapType;
84  typedef std::map<uint32_t, SignalMapType> signalMaps;
85 
86  const SignalMapType* getSignal(uint32_t detID) const {
87  auto where = signals_.find(detID);
88  if (where == signals_.end()) {
89  return nullptr;
90  }
91  return &where->second;
92  }
93 
95 
96  // to keep track of dead APVs from HIP interactions
97  typedef std::multimap<uint32_t, std::bitset<6>> APVMap;
98 
100 
101  // for noise adding:
102 
105  bool peakMode;
106  double theThreshold;
111 
112  std::unique_ptr<SiGaussianTailNoiseAdder> theSiNoiseAdder;
113  std::unique_ptr<SiStripFedZeroSuppression> theSiZeroSuppress;
114  std::unique_ptr<SiTrivialDigitalConverter> theSiDigitalConverter;
115 
117 
118  // bad channels for each detector ID
119  std::map<unsigned int, std::vector<bool>> allBadChannels;
120  // channels killed by HIP interactions for each detector ID
121  std::map<unsigned int, std::vector<bool>> allHIPChannels;
122  // first and last channel wit signal for each detector ID
123  std::map<unsigned int, size_t> firstChannelsWithSignal;
124  std::map<unsigned int, size_t> lastChannelsWithSignal;
125 
127  const double fracOfEventsToSimAPV_;
128  const double apv_maxResponse_;
129  const double apv_rate_;
130  const double apv_mVPerQ_;
131  const double apv_fCPerElectron_;
132 
133  //----------------------------
134 
136  public:
137  bool operator()(SiStripDigi i, SiStripDigi j) const { return i.strip() < j.strip(); }
138  };
139 
141  public:
142  bool operator()(RawDigi i, RawDigi j) const { return i.first < j.first; }
143  };
144 };
145 
147  edm::ProducesCollector producesCollector,
149  : gainLabel(ps.getParameter<std::string>("Gain")),
150  SingleStripNoise(ps.getParameter<bool>("SingleStripNoise")),
151  peakMode(ps.getParameter<bool>("APVpeakmode")),
152  theThreshold(ps.getParameter<double>("NoiseSigmaThreshold")),
153  theElectronPerADC(ps.getParameter<double>(peakMode ? "electronPerAdcPeak" : "electronPerAdcDec")),
154  APVSaturationFromHIP_(ps.getParameter<bool>("APVSaturationFromHIP")),
155  theFedAlgo(ps.getParameter<int>("FedAlgorithm_PM")),
156  geometryType(ps.getParameter<std::string>("GeometryType")),
157  theSiZeroSuppress(new SiStripFedZeroSuppression(theFedAlgo)),
158  theSiDigitalConverter(new SiTrivialDigitalConverter(theElectronPerADC, false)), // no premixing
159  includeAPVSimulation_(ps.getParameter<bool>("includeAPVSimulation")),
160  fracOfEventsToSimAPV_(ps.getParameter<double>("fracOfEventsToSimAPV")),
161  apv_maxResponse_(ps.getParameter<double>("apv_maxResponse")),
162  apv_rate_(ps.getParameter<double>("apv_rate")),
163  apv_mVPerQ_(ps.getParameter<double>("apv_mVPerQ")),
164  apv_fCPerElectron_(ps.getParameter<double>("apvfCPerElectron"))
165 
166 {
167  // declare the products to produce
168 
169  SistripLabelSig_ = ps.getParameter<edm::InputTag>("SistripLabelSig");
170  SiStripPileInputTag_ = ps.getParameter<edm::InputTag>("SiStripPileInputTag");
171 
172  SiStripDigiCollectionDM_ = ps.getParameter<std::string>("SiStripDigiCollectionDM");
173  SistripAPVListDM_ = ps.getParameter<std::string>("SiStripAPVListDM");
174 
176  producesCollector.produces<bool>(SiStripDigiCollectionDM_ + "SimulatedAPVDynamicGain");
177 
178  if (APVSaturationFromHIP_) {
179  SistripAPVLabelSig_ = ps.getParameter<edm::InputTag>("SistripAPVLabelSig");
180  SiStripAPVPileInputTag_ = ps.getParameter<edm::InputTag>("SistripAPVPileInputTag");
181  iC.consumes<std::vector<std::pair<int, std::bitset<6>>>>(SistripAPVLabelSig_);
182  }
184  // clear local storage for this event
185  SiHitStorage_.clear();
186 
188  if (!rng.isAvailable()) {
189  throw cms::Exception("Psiguration") << "SiStripDigitizer requires the RandomNumberGeneratorService\n"
190  "which is not present in the psiguration file. You must add the service\n"
191  "in the configuration file or remove the modules that require it.";
192  }
193 
194  theSiNoiseAdder = std::make_unique<SiGaussianTailNoiseAdder>(theThreshold);
195 }
196 
198  // initialize individual detectors so we can copy real digitization code:
199 
201 
202  for (auto iu = pDD->detUnits().begin(); iu != pDD->detUnits().end(); ++iu) {
203  unsigned int detId = (*iu)->geographicalId().rawId();
204  DetId idet = DetId(detId);
205  unsigned int isub = idet.subdetId();
206  if ((isub == StripSubdetector::TIB) || (isub == StripSubdetector::TID) || (isub == StripSubdetector::TOB) ||
207  (isub == StripSubdetector::TEC)) {
208  auto stripdet = dynamic_cast<StripGeomDetUnit const*>((*iu));
209  assert(stripdet != nullptr);
210  DMinitializeDetUnit(stripdet, iSetup);
211  }
212  }
213 }
214 
216  edm::ESHandle<SiStripBadStrip> deadChannelHandle;
217  iSetup.get<SiStripBadChannelRcd>().get(deadChannelHandle);
218 
219  unsigned int detId = det->geographicalId().rawId();
220  int numStrips = (det->specificTopology()).nstrips();
221 
222  SiStripBadStrip::Range detBadStripRange = deadChannelHandle->getRange(detId);
223  //storing the bad strip of the the module. the module is not removed but just signal put to 0
224  std::vector<bool>& badChannels = allBadChannels[detId];
225  std::vector<bool>& hipChannels = allHIPChannels[detId];
226  badChannels.clear();
227  badChannels.insert(badChannels.begin(), numStrips, false);
228  hipChannels.clear();
229  hipChannels.insert(hipChannels.begin(), numStrips, false);
230 
231  for (SiStripBadStrip::ContainerIterator it = detBadStripRange.first; it != detBadStripRange.second; ++it) {
232  SiStripBadStrip::data fs = deadChannelHandle->decode(*it);
233  for (int strip = fs.firstStrip; strip < fs.firstStrip + fs.range; ++strip)
234  badChannels[strip] = true;
235  }
236  firstChannelsWithSignal[detId] = numStrips;
237  lastChannelsWithSignal[detId] = 0;
238 }
239 
241  // fill in maps of hits
242 
244 
245  if (e.getByLabel(SistripLabelSig_, input)) {
246  OneDetectorMap LocalMap;
247 
248  //loop on all detsets (detectorIDs) inside the input collection
250  for (; DSViter != input->end(); DSViter++) {
251 #ifdef DEBUG
252  LogDebug("PreMixingSiStripWorker") << "Processing DetID " << DSViter->id;
253 #endif
254 
255  LocalMap.clear();
256  LocalMap.reserve((DSViter->data).size());
257  LocalMap.insert(LocalMap.end(), (DSViter->data).begin(), (DSViter->data).end());
258 
259  SiHitStorage_.insert(SiGlobalIndex::value_type(DSViter->id, LocalMap));
260  }
261  }
262 
263  // keep here for future reference. In current implementation, HIP killing is done once in PU file
264  /* if(APVSaturationFromHIP_) {
265  edm::Handle<std::vector<std::pair<int,std::bitset<6>> > > APVinput;
266 
267  if( e.getByLabel(SistripAPVLabelSig_,APVinput) ) {
268 
269  std::vector<std::pair<int,std::bitset<6>> >::const_iterator entry = APVinput->begin();
270  for( ; entry != APVinput->end(); entry++) {
271  theAffectedAPVmap_.insert(APVMap::value_type(entry->first, entry->second));
272  }
273  }
274  } */
275 
276 } // end of addSiStripSignals
277 
279  LogDebug("PreMixingSiStripWorker") << "\n===============> adding pileups from event " << pep.principal().id()
280  << " for bunchcrossing " << pep.bunchCrossing();
281 
282  // fill in maps of hits; same code as addSignals, except now applied to the pileup events
283 
285  pep.getByLabel(SiStripPileInputTag_, inputHandle);
286 
287  if (inputHandle.isValid()) {
288  const auto& input = *inputHandle;
289 
290  OneDetectorMap LocalMap;
291 
292  //loop on all detsets (detectorIDs) inside the input collection
294  for (; DSViter != input.end(); DSViter++) {
295 #ifdef DEBUG
296  LogDebug("PreMixingSiStripWorker") << "Pileups: Processing DetID " << DSViter->id;
297 #endif
298 
299  // find correct local map (or new one) for this detector ID
300 
301  SiGlobalIndex::const_iterator itest;
302 
303  itest = SiHitStorage_.find(DSViter->id);
304 
305  if (itest != SiHitStorage_.end()) { // this detID already has hits, add to existing map
306 
307  LocalMap = itest->second;
308 
309  // fill in local map with extra channels
310  LocalMap.insert(LocalMap.end(), (DSViter->data).begin(), (DSViter->data).end());
311  std::stable_sort(LocalMap.begin(), LocalMap.end(), PreMixingSiStripWorker::StrictWeakOrdering());
312  SiHitStorage_[DSViter->id] = LocalMap;
313 
314  } else { // fill local storage with this information, put in global collection
315 
316  LocalMap.clear();
317  LocalMap.reserve((DSViter->data).size());
318  LocalMap.insert(LocalMap.end(), (DSViter->data).begin(), (DSViter->data).end());
319 
320  SiHitStorage_.insert(SiGlobalIndex::value_type(DSViter->id, LocalMap));
321  }
322  }
323 
324  if (APVSaturationFromHIP_) {
326  pep.getByLabel(SiStripAPVPileInputTag_, inputAPVHandle);
327 
328  if (inputAPVHandle.isValid()) {
329  const auto& APVinput = inputAPVHandle;
330 
331  std::vector<std::pair<int, std::bitset<6>>>::const_iterator entry = APVinput->begin();
332  for (; entry != APVinput->end(); entry++) {
333  theAffectedAPVmap_.insert(APVMap::value_type(entry->first, entry->second));
334  }
335  }
336  }
337  }
338 }
339 
341  edm::EventSetup const& iSetup,
342  std::vector<PileupSummaryInfo> const& ps,
343  int bs) {
344  // set up machinery to do proper noise adding:
345  edm::ESHandle<SiStripGain> gainHandle;
346  edm::ESHandle<SiStripNoises> noiseHandle;
347  edm::ESHandle<SiStripThreshold> thresholdHandle;
348  edm::ESHandle<SiStripPedestals> pedestalHandle;
349  edm::ESHandle<SiStripBadStrip> deadChannelHandle;
350  edm::ESHandle<SiStripApvSimulationParameters> apvSimulationParametersHandle;
352  iSetup.get<SiStripGainSimRcd>().get(gainLabel, gainHandle);
353  iSetup.get<SiStripNoisesRcd>().get(noiseHandle);
354  iSetup.get<SiStripThresholdRcd>().get(thresholdHandle);
355  iSetup.get<SiStripPedestalsRcd>().get(pedestalHandle);
356 
358  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
359 
360  const bool simulateAPVInThisEvent = includeAPVSimulation_ && (CLHEP::RandFlat::shoot(engine) < fracOfEventsToSimAPV_);
361  float nTruePU = 0.; // = ps.getTrueNumInteractions();
362  if (simulateAPVInThisEvent) {
363  iSetup.get<TrackerTopologyRcd>().get(tTopo);
364  iSetup.get<SiStripApvSimulationParametersRcd>().get(apvSimulationParametersHandle);
365  const auto it = std::find_if(
366  std::begin(ps), std::end(ps), [](const PileupSummaryInfo& bxps) { return bxps.getBunchCrossing() == 0; });
367  if (it != std::begin(ps)) {
368  nTruePU = it->getTrueNumInteractions();
369  } else {
370  edm::LogWarning("PreMixingSiStripWorker") << "Could not find PileupSummaryInfo for current bunch crossing";
371  nTruePU = std::begin(ps)->getTrueNumInteractions();
372  }
373  }
374 
375  std::map<int, std::bitset<6>> DeadAPVList;
376  DeadAPVList.clear();
377 
378  // First, have to convert all ADC counts to raw pulse heights so that values can be added properly
379  // In PreMixing, pulse heights are saved with ADC = sqrt(9.0*PulseHeight) - have to undo.
380 
381  // This is done here because it's the only place we have access to EventSetup
382  // Simultaneously, merge lists of hit channels in each DetId.
383  // Signal Digis are in the list first, have to merge lists of hit strips on the fly,
384  // add signals on duplicates later
385 
386  OneDetectorRawMap LocalRawMap;
387 
388  // Now, loop over hits and add them to the map in the proper sorted order
389  // Note: We are assuming that the hits from the Signal events have been created in
390  // "PreMix" mode, rather than in the standard ADC conversion routines. If not, this
391  // doesn't work at all.
392 
393  // At the moment, both Signal and Reconstituted PU hits have the same compression algorithm.
394  // If this were different, and one needed gains, the conversion back to pulse height can only
395  // be done in this routine. So, yes, there is an extra loop over hits here in the current code,
396  // because, in principle, one could convert to pulse height during the read/store phase.
397 
398  for (SiGlobalIndex::const_iterator IDet = SiHitStorage_.begin(); IDet != SiHitStorage_.end(); IDet++) {
399  uint32_t detID = IDet->first;
400 
401  OneDetectorMap LocalMap = IDet->second;
402 
403  //loop over hit strips for this DetId, do conversion to pulse height, store.
404 
405  LocalRawMap.clear();
406 
407  OneDetectorMap::const_iterator iLocal = LocalMap.begin();
408  for (; iLocal != LocalMap.end(); ++iLocal) {
409  uint16_t currentStrip = iLocal->strip();
410  float signal = float(iLocal->adc());
411  if (iLocal->adc() == 1022)
412  signal = 1500.; // average values for overflows
413  if (iLocal->adc() == 1023)
414  signal = 3000.;
415 
416  //convert signals back to raw counts
417 
418  float ReSignal = signal * signal / 9.0; // The PreMixing conversion is adc = sqrt(9.0*pulseHeight)
419 
420  RawDigi NewRawDigi = std::make_pair(currentStrip, ReSignal);
421 
422  LocalRawMap.push_back(NewRawDigi);
423  }
424 
425  // save information for this detiD into global map
426  SiRawDigis_.insert(SiGlobalRawIndex::value_type(detID, LocalRawMap));
427  }
428 
429  // If we are killing APVs, merge list of dead ones before we digitize
430 
431  int NumberOfBxBetweenHIPandEvent = 1e3;
432 
433  if (APVSaturationFromHIP_) {
434  // calculate affected BX parameter
435 
436  bool HasAtleastOneAffectedAPV = false;
437  while (!HasAtleastOneAffectedAPV) {
438  for (int bx = floor(300.0 / 25.0); bx > 0; bx--) { //Reminder: make these numbers not hard coded!!
439  float temp = CLHEP::RandFlat::shoot(engine) < 0.5 ? 1 : 0;
440  if (temp == 1 && bx < NumberOfBxBetweenHIPandEvent) {
441  NumberOfBxBetweenHIPandEvent = bx;
442  HasAtleastOneAffectedAPV = true;
443  }
444  }
445  }
446 
447  APVMap::const_iterator iAPVchk;
448  uint32_t formerID = 0;
449  uint32_t currentID;
450  std::bitset<6> NewAPVBits;
451 
452  for (APVMap::const_iterator iAPV = theAffectedAPVmap_.begin(); iAPV != theAffectedAPVmap_.end(); ++iAPV) {
453  currentID = iAPV->first;
454 
455  if (currentID == formerID) { // we have to OR these
456  for (int ibit = 0; ibit < 6; ++ibit) {
457  NewAPVBits[ibit] = NewAPVBits[ibit] || (iAPV->second)[ibit];
458  }
459  } else {
460  DeadAPVList[currentID] = NewAPVBits;
461  //save pointers for next iteration
462  formerID = currentID;
463  NewAPVBits = iAPV->second;
464  }
465 
466  iAPVchk = iAPV;
467  if ((++iAPVchk) == theAffectedAPVmap_.end()) { //make sure not to lose the last one
468  DeadAPVList[currentID] = NewAPVBits;
469  }
470  }
471  }
472  //
473 
474  // Ok, done with merging raw signals and APVs - now add signals on duplicate strips
475 
476  // collection of Digis to put in the event
477  std::vector<edm::DetSet<SiStripDigi>> vSiStripDigi;
478 
479  // loop through our collection of detectors, merging hits and making a new list of "signal" digis
480 
481  // clear some temporary storage for later digitization:
482 
483  signals_.clear();
484 
485  // big loop over Detector IDs:
486  for (SiGlobalRawIndex::const_iterator IDet = SiRawDigis_.begin(); IDet != SiRawDigis_.end(); IDet++) {
487  uint32_t detID = IDet->first;
488 
489  SignalMapType Signals;
490  Signals.clear();
491 
492  OneDetectorRawMap LocalMap = IDet->second;
493 
494  //counter variables
495  int formerStrip = -1;
496  int currentStrip;
497  float ADCSum = 0;
498 
499  //loop over hit strips for this DetId, add duplicates
500 
501  OneDetectorRawMap::const_iterator iLocalchk;
502  OneDetectorRawMap::const_iterator iLocal = LocalMap.begin();
503  for (; iLocal != LocalMap.end(); ++iLocal) {
504  currentStrip = iLocal->first; // strip is first element
505 
506  if (currentStrip == formerStrip) { // we have to add these digis together
507 
508  ADCSum += iLocal->second; // raw pulse height is second element.
509  } else {
510  if (formerStrip != -1) {
511  Signals.insert(std::make_pair(formerStrip, ADCSum));
512  }
513  // save pointers for next iteration
514  formerStrip = currentStrip;
515  ADCSum = iLocal->second; // lone ADC
516  }
517 
518  iLocalchk = iLocal;
519  if ((++iLocalchk) == LocalMap.end()) { //make sure not to lose the last one
520  Signals.insert(std::make_pair(formerStrip, ADCSum));
521  }
522  }
523  // save merged map:
524  signals_.insert(std::make_pair(detID, Signals));
525  }
526 
527  //Now, do noise, zero suppression, take into account bad channels, etc.
528  // This section stolen from SiStripDigitizerAlgorithm
529  // must loop over all detIds in the tracker to get all of the noise added properly.
530  for (const auto& iu : pDD->detUnits()) {
531  const StripGeomDetUnit* sgd = dynamic_cast<const StripGeomDetUnit*>(iu);
532  if (sgd != nullptr) {
533  uint32_t detID = sgd->geographicalId().rawId();
534 
535  edm::DetSet<SiStripDigi> SSD(detID); // Make empty collection with this detector ID
536 
537  int numStrips = (sgd->specificTopology()).nstrips();
538 
539  // see if there is some signal on this detector
540 
541  const SignalMapType* theSignal(getSignal(detID));
542 
543  std::vector<float> detAmpl(numStrips, 0.);
544  if (theSignal) {
545  for (const auto& amp : *theSignal) {
546  detAmpl[amp.first] = amp.second;
547  }
548  }
549 
550  //removing signal from the dead (and HIP effected) strips
551  std::vector<bool>& badChannels = allBadChannels[detID];
552 
553  for (int strip = 0; strip < numStrips; ++strip) {
554  if (badChannels[strip])
555  detAmpl[strip] = 0.;
556  }
557 
558  if (simulateAPVInThisEvent) {
559  // Get index in apv baseline distributions corresponding to z of detSet and PU
560  const StripTopology* topol = dynamic_cast<const StripTopology*>(&(sgd->specificTopology()));
561  LocalPoint localPos = topol->localPosition(0);
562  GlobalPoint globalPos = sgd->surface().toGlobal(Local3DPoint(localPos.x(), localPos.y(), localPos.z()));
563  float detSet_z = fabs(globalPos.z());
564  float detSet_r = globalPos.perp();
565 
566  const uint32_t SubDet = DetId(detID).subdetId();
567  // Simulate APV response for each strip
568  for (int strip = 0; strip < numStrips; ++strip) {
569  if (detAmpl[strip] > 0) {
570  // Convert charge from electrons to fC
571  double stripCharge = detAmpl[strip] * apv_fCPerElectron_;
572 
573  // Get APV baseline
574  double baselineV = 0;
576  baselineV = apvSimulationParametersHandle->sampleTIB(tTopo->tibLayer(detID), detSet_z, nTruePU, engine);
577  } else if (SubDet == SiStripSubdetector::TOB) {
578  baselineV = apvSimulationParametersHandle->sampleTOB(tTopo->tobLayer(detID), detSet_z, nTruePU, engine);
579  } else if (SubDet == SiStripSubdetector::TID) {
580  baselineV = apvSimulationParametersHandle->sampleTID(tTopo->tidWheel(detID), detSet_r, nTruePU, engine);
581  } else if (SubDet == SiStripSubdetector::TEC) {
582  baselineV = apvSimulationParametersHandle->sampleTEC(tTopo->tecWheel(detID), detSet_r, nTruePU, engine);
583  }
584  // Fitted parameters from G Hall/M Raymond
585  double maxResponse = apv_maxResponse_;
586  double rate = apv_rate_;
587 
588  double outputChargeInADC = 0;
589  if (baselineV < apv_maxResponse_) {
590  // Convert V0 into baseline charge
591  double baselineQ = -1.0 * rate * log(2 * maxResponse / (baselineV + maxResponse) - 1);
592 
593  // Add charge deposited in this BX
594  double newStripCharge = baselineQ + stripCharge;
595 
596  // Apply APV response
597  double signalV = 2 * maxResponse / (1 + exp(-1.0 * newStripCharge / rate)) - maxResponse;
598  double gain = signalV - baselineV;
599 
600  // Convert gain (mV) to charge (assuming linear region of APV) and then to electrons
601  double outputCharge = gain / apv_mVPerQ_;
602  outputChargeInADC = outputCharge / apv_fCPerElectron_;
603  }
604 
605  // Output charge back to original container
606  detAmpl[strip] = outputChargeInADC;
607  }
608  }
609  }
610 
611  if (APVSaturationFromHIP_) {
612  std::bitset<6>& bs = DeadAPVList[detID];
613 
614  if (bs.any()) {
615  // Here below is the scaling function which describes the evolution of the baseline (i.e. how the charge is suppressed).
616  // This must be replaced as soon as we have a proper modeling of the baseline evolution from VR runs
617  float Shift =
618  1 - NumberOfBxBetweenHIPandEvent / floor(300.0 / 25.0); //Reminder: make these numbers not hardcoded!!
619  float randomX = CLHEP::RandFlat::shoot(engine);
620  float scalingValue = (randomX - Shift) * 10.0 / 7.0 - 3.0 / 7.0;
621 
622  for (int strip = 0; strip < numStrips; ++strip) {
623  if (!badChannels[strip] && bs[strip / 128] == 1) {
624  detAmpl[strip] *= scalingValue > 0 ? scalingValue : 0.0;
625  }
626  }
627  }
628  }
629 
630  SiStripNoises::Range detNoiseRange = noiseHandle->getRange(detID);
631  SiStripApvGain::Range detGainRange = gainHandle->getRange(detID);
632 
633  // Gain conversion is already done during signal adding
634  //convert our signals back to raw counts so that we can add noise properly:
635 
636  /*
637  if(theSignal) {
638  for(unsigned int iv = 0; iv!=detAmpl.size(); iv++) {
639  float signal = detAmpl[iv];
640  if(signal > 0) {
641  float gainValue = gainHandle->getStripGain(iv, detGainRange);
642  signal *= theElectronPerADC/gainValue;
643  detAmpl[iv] = signal;
644  }
645  }
646  }
647  */
648 
649  //SiStripPedestals::Range detPedestalRange = pedestalHandle->getRange(detID);
650 
651  // -----------------------------------------------------------
652 
653  size_t firstChannelWithSignal = 0;
654  size_t lastChannelWithSignal = numStrips;
655 
656  if (SingleStripNoise) {
657  std::vector<float> noiseRMSv;
658  noiseRMSv.clear();
659  noiseRMSv.insert(noiseRMSv.begin(), numStrips, 0.);
660  for (int strip = 0; strip < numStrips; ++strip) {
661  if (!badChannels[strip]) {
662  float gainValue = gainHandle->getStripGain(strip, detGainRange);
663  noiseRMSv[strip] = (noiseHandle->getNoise(strip, detNoiseRange)) * theElectronPerADC / gainValue;
664  }
665  }
666  theSiNoiseAdder->addNoiseVR(detAmpl, noiseRMSv, engine);
667  } else {
668  int RefStrip = int(numStrips / 2.);
669  while (RefStrip < numStrips &&
670  badChannels[RefStrip]) { //if the refstrip is bad, I move up to when I don't find it
671  RefStrip++;
672  }
673  if (RefStrip < numStrips) {
674  float RefgainValue = gainHandle->getStripGain(RefStrip, detGainRange);
675  float RefnoiseRMS = noiseHandle->getNoise(RefStrip, detNoiseRange) * theElectronPerADC / RefgainValue;
676 
677  theSiNoiseAdder->addNoise(
678  detAmpl, firstChannelWithSignal, lastChannelWithSignal, numStrips, RefnoiseRMS, engine);
679  }
680  }
681 
682  DigitalVecType digis;
683  theSiZeroSuppress->suppress(
684  theSiDigitalConverter->convert(detAmpl, gainHandle, detID), digis, detID, noiseHandle, thresholdHandle);
685 
686  SSD.data = digis;
687 
688  // stick this into the global vector of detector info
689  vSiStripDigi.push_back(SSD);
690 
691  } // end of loop over one detector
692 
693  } // end of big loop over all detector IDs
694 
695  // put the collection of digis in the event
696  edm::LogInfo("PreMixingSiStripWorker") << "total # Merged strips: " << vSiStripDigi.size();
697 
698  // make new digi collection
699 
700  std::unique_ptr<edm::DetSetVector<SiStripDigi>> MySiStripDigis(new edm::DetSetVector<SiStripDigi>(vSiStripDigi));
701 
702  // put collection
703 
704  e.put(std::move(MySiStripDigis), SiStripDigiCollectionDM_);
705  e.put(std::make_unique<bool>(simulateAPVInThisEvent), SiStripDigiCollectionDM_ + "SimulatedAPVDynamicGain");
706 
707  // clear local storage for this event
708  SiHitStorage_.clear();
709  SiRawDigis_.clear();
710  signals_.clear();
711 }
712 
edm::DetSetVector< SiStripDigi >
SiStripDependentRecords.h
edm::RandomNumberGenerator::getEngine
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
Handle.h
PileupSummaryInfo.h
PreMixingSiStripWorker::theSiNoiseAdder
std::unique_ptr< SiGaussianTailNoiseAdder > theSiNoiseAdder
Definition: PreMixingSiStripWorker.cc:112
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
input
static const std::string input
Definition: EdmProvDump.cc:48
StripGeomDetUnit.h
MessageLogger.h
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
funct::false
false
Definition: Factorize.h:29
SiStripBadStrip::getRange
const Range getRange(const uint32_t detID) const
Definition: SiStripBadStrip.cc:27
TrackerGeometry.h
PreMixingSiStripWorker::theAffectedAPVmap_
APVMap theAffectedAPVmap_
Definition: PreMixingSiStripWorker.cc:99
PreMixingSiStripWorker::SiStripDigiCollectionDM_
std::string SiStripDigiCollectionDM_
Definition: PreMixingSiStripWorker.cc:62
PreMixingSiStripWorker::RawDigi
std::pair< uint16_t, Amplitude > RawDigi
Definition: PreMixingSiStripWorker.cc:71
SiStripBadChannelRcd
Definition: SiStripCondDataRecords.h:14
PreMixingSiStripWorker::SiStripAPVPileInputTag_
edm::InputTag SiStripAPVPileInputTag_
Definition: PreMixingSiStripWorker.cc:65
SiStripGain.h
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
edm::DetSet< SiStripDigi >
PreMixingSiStripWorker::theSiZeroSuppress
std::unique_ptr< SiStripFedZeroSuppression > theSiZeroSuppress
Definition: PreMixingSiStripWorker.cc:113
PreMixingSiStripWorker::getSignal
const SignalMapType * getSignal(uint32_t detID) const
Definition: PreMixingSiStripWorker.cc:86
StripTopology::localPosition
virtual LocalPoint localPosition(float strip) const =0
RandomNumberGenerator.h
PreMixingSiStripWorker::OneDetectorRawMap
std::vector< RawDigi > OneDetectorRawMap
Definition: PreMixingSiStripWorker.cc:73
mps_splice.entry
entry
Definition: mps_splice.py:68
PreMixingSiStripWorker::theElectronPerADC
double theElectronPerADC
Definition: PreMixingSiStripWorker.cc:107
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
SiStripBadStrip::decode
data decode(const unsigned int &value) const
Definition: SiStripBadStrip.h:78
GeomDetType.h
PreMixingSiStripWorker::apv_rate_
const double apv_rate_
Definition: PreMixingSiStripWorker.cc:129
edm::DetSetVector::reserve
void reserve(size_t s)
Definition: DetSetVector.h:147
cms::cuda::assert
assert(be >=bs)
PreMixingSiStripWorker::includeAPVSimulation_
bool includeAPVSimulation_
Definition: PreMixingSiStripWorker.cc:126
PileUpEventPrincipal::bunchCrossing
int bunchCrossing() const
Definition: PileUpEventPrincipal.h:30
PileUpEventPrincipal
Definition: PileUpEventPrincipal.h:19
PreMixingSiStripWorker::StrictWeakOrdering
Definition: PreMixingSiStripWorker.cc:135
SiStripNoises.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
StripTopology.h
SiStripApvSimulationParametersRcd
Definition: SiStripCondDataRecords.h:58
PreMixingSiStripWorker::SistripAPVLabelSig_
edm::InputTag SistripAPVLabelSig_
Definition: PreMixingSiStripWorker.cc:64
SiStripBadStrip.h
SiStripNoises::getRange
const Range getRange(const uint32_t detID) const
Definition: SiStripNoises.cc:34
PreMixingSiStripWorker::theFedAlgo
int theFedAlgo
Definition: PreMixingSiStripWorker.cc:109
PreMixingSiStripWorker::StrictWeakRawOrdering::operator()
bool operator()(RawDigi i, RawDigi j) const
Definition: PreMixingSiStripWorker.cc:142
RPCpg::rate
double rate(double x)
Definition: Constants.cc:3
SiStripSubdetector::TEC
Definition: SiStripEnums.h:5
edm::Handle
Definition: AssociativeIterator.h:50
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
PreMixingSiStripWorker::apv_fCPerElectron_
const double apv_fCPerElectron_
Definition: PreMixingSiStripWorker.cc:131
edm::EventPrincipal::id
EventID const & id() const
Definition: EventPrincipal.h:92
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
SiStripPedestalsRcd
Definition: SiStripCondDataRecords.h:43
SiStripApvSimulationParameters::sampleTID
float sampleTID(layerid wheel, float r, float pu, CLHEP::HepRandomEngine *engine) const
Definition: SiStripApvSimulationParameters.h:57
PreMixingSiStripWorker::addSignals
void addSignals(edm::Event const &e, edm::EventSetup const &es) override
Definition: PreMixingSiStripWorker.cc:240
SiStripNoisesRcd
Definition: SiStripCondDataRecords.h:40
ProducesCollector.h
PreMixingSiStripWorker::OneDetectorMap
std::vector< SiStripDigi > OneDetectorMap
Definition: PreMixingSiStripWorker.cc:72
TrackerTopology::tidWheel
unsigned int tidWheel(const DetId &id) const
Definition: TrackerTopology.h:201
SiStripGain::getStripGain
static float getStripGain(const uint16_t &strip, const SiStripApvGain::Range &range)
Definition: SiStripGain.h:73
PreMixingSiStripWorker
Definition: PreMixingSiStripWorker.cc:45
SiStripSubdetector::TOB
Definition: SiStripEnums.h:5
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
PreMixingSiStripWorker::initializeEvent
void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override
Definition: PreMixingSiStripWorker.cc:197
DetId
Definition: DetId.h:17
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
cms::cuda::bs
bs
Definition: HistoContainer.h:127
PreMixingSiStripWorker::put
void put(edm::Event &e, edm::EventSetup const &iSetup, std::vector< PileupSummaryInfo > const &ps, int bs) override
Definition: PreMixingSiStripWorker.cc:340
SiStripBadStrip::Range
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripBadStrip.h:53
PreMixingSiStripWorker::SiGlobalIndex
std::map< uint32_t, OneDetectorMap > SiGlobalIndex
Definition: PreMixingSiStripWorker.cc:74
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
PreMixingSiStripWorker::~PreMixingSiStripWorker
~PreMixingSiStripWorker() override=default
SiStripFedZeroSuppression.h
PreMixingSiStripWorker::PreMixingSiStripWorker
PreMixingSiStripWorker(const edm::ParameterSet &ps, edm::ProducesCollector, edm::ConsumesCollector &&iC)
Definition: PreMixingSiStripWorker.cc:146
TrackerGeometry::detUnits
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
Definition: TrackerGeometry.h:61
PreMixingWorker.h
ntupleEnum.SubDet
SubDet
Definition: ntupleEnum.py:15
Service.h
PreMixingSiStripWorker::SingleStripNoise
bool SingleStripNoise
Definition: PreMixingSiStripWorker.cc:104
SiStripNoises::Range
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:47
SiStripGain::getRange
const SiStripApvGain::Range getRange(uint32_t detID) const
Definition: SiStripGain.h:71
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
SiStripDigi.h
SiStripFedZeroSuppression
Definition: SiStripFedZeroSuppression.h:16
mps_fire.end
end
Definition: mps_fire.py:242
Surface::toGlobal
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
PileUpEventPrincipal::principal
edm::EventPrincipal const & principal()
Definition: PileUpEventPrincipal.h:24
edm::ESHandle< TrackerGeometry >
PileUpEventPrincipal.h
PreMixingSiStripWorker::apv_mVPerQ_
const double apv_mVPerQ_
Definition: PreMixingSiStripWorker.cc:130
StripSubdetector::TIB
static constexpr auto TIB
Definition: StripSubdetector.h:16
PreMixingSiStripWorker::StrictWeakRawOrdering
Definition: PreMixingSiStripWorker.cc:140
PreMixingSiStripWorker::theSiDigitalConverter
std::unique_ptr< SiTrivialDigitalConverter > theSiDigitalConverter
Definition: PreMixingSiStripWorker.cc:114
Point3DBase< float, LocalTag >
SiStripThreshold.h
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
SiStripThresholdRcd
Definition: SiStripCondDataRecords.h:50
SiStripApvSimulationParameters::sampleTIB
float sampleTIB(layerid layer, float z, float pu, CLHEP::HepRandomEngine *engine) const
Definition: SiStripApvSimulationParameters.h:51
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PreMixingSiStripWorker::fracOfEventsToSimAPV_
const double fracOfEventsToSimAPV_
Definition: PreMixingSiStripWorker.cc:127
SiDigitalConverter::DigitalVecType
std::vector< SiStripDigi > DigitalVecType
Definition: SiDigitalConverter.h:14
GeomDet::geographicalId
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
PreMixingSiStripWorker::DigitalVecType
SiDigitalConverter::DigitalVecType DigitalVecType
Definition: PreMixingSiStripWorker.cc:77
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
PreMixingSiStripWorker::theThreshold
double theThreshold
Definition: PreMixingSiStripWorker.cc:106
PreMixingSiStripWorker::signalMaps
std::map< uint32_t, SignalMapType > signalMaps
Definition: PreMixingSiStripWorker.cc:84
edm::DetSetVector::const_iterator
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
PreMixingSiStripWorker::addPileups
void addPileups(PileUpEventPrincipal const &pep, edm::EventSetup const &es) override
Definition: PreMixingSiStripWorker.cc:278
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
edm::Service< edm::RandomNumberGenerator >
createfilelist.int
int
Definition: createfilelist.py:10
SiStripBadStrip::data::firstStrip
unsigned short firstStrip
Definition: SiStripBadStrip.h:33
edm::ProducesCollector::produces
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
Definition: ProducesCollector.h:52
PileupSummaryInfo::getBunchCrossing
const int getBunchCrossing() const
Definition: PileupSummaryInfo.h:73
PreMixingSiStripWorker::APVMap
std::multimap< uint32_t, std::bitset< 6 > > APVMap
Definition: PreMixingSiStripWorker.cc:97
edm::EventSetup
Definition: EventSetup.h:58
PreMixingSiStripWorker::firstChannelsWithSignal
std::map< unsigned int, size_t > firstChannelsWithSignal
Definition: PreMixingSiStripWorker.cc:123
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
PreMixingSiStripWorker::apv_maxResponse_
const double apv_maxResponse_
Definition: PreMixingSiStripWorker.cc:128
DetSetVector.h
get
#define get
PreMixingSiStripWorker::Amplitude
float Amplitude
Definition: PreMixingSiStripWorker.cc:70
PreMixingSiStripWorker::allHIPChannels
std::map< unsigned int, std::vector< bool > > allHIPChannels
Definition: PreMixingSiStripWorker.cc:121
SiStripSubdetector::TIB
Definition: SiStripEnums.h:5
PreMixingSiStripWorker::SiHitStorage_
SiGlobalIndex SiHitStorage_
Definition: PreMixingSiStripWorker.cc:79
PedestalClient_cfi.gain
gain
Definition: PedestalClient_cfi.py:37
SiPixelPhase1Clusters_cfi.e3
e3
Definition: SiPixelPhase1Clusters_cfi.py:9
SiStripSimParameters_cfi.SingleStripNoise
SingleStripNoise
Definition: SiStripSimParameters_cfi.py:105
PreMixingWorkerFactory.h
PreMixingSiStripWorker::signals_
signalMaps signals_
Definition: PreMixingSiStripWorker.cc:94
GeomDet.h
TrackerTopology::tobLayer
unsigned int tobLayer(const DetId &id) const
Definition: TrackerTopology.h:147
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
edm::ProducesCollector
Definition: ProducesCollector.h:43
StripSubdetector::TEC
static constexpr auto TEC
Definition: StripSubdetector.h:19
PreMixingSiStripWorker::StrictWeakOrdering::operator()
bool operator()(SiStripDigi i, SiStripDigi j) const
Definition: PreMixingSiStripWorker.cc:137
PreMixingSiStripWorker::allBadChannels
std::map< unsigned int, std::vector< bool > > allBadChannels
Definition: PreMixingSiStripWorker.cc:119
PreMixingSiStripWorker::geometryType
std::string geometryType
Definition: PreMixingSiStripWorker.cc:110
PreMixingSiStripWorker::SignalMapType
std::map< int, Amplitude > SignalMapType
Definition: PreMixingSiStripWorker.cc:83
SiStripApvGain::Range
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripApvGain.h:28
PreMixingSiStripWorker::lastChannelsWithSignal
std::map< unsigned int, size_t > lastChannelsWithSignal
Definition: PreMixingSiStripWorker.cc:124
PreMixingSiStripWorker::peakMode
bool peakMode
Definition: PreMixingSiStripWorker.cc:105
SiTrivialDigitalConverter
Definition: SiTrivialDigitalConverter.h:8
Exception
Definition: hltDiff.cc:245
PreMixingSiStripWorker::APVSaturationFromHIP_
bool APVSaturationFromHIP_
Definition: PreMixingSiStripWorker.cc:108
DEFINE_PREMIXING_WORKER
#define DEFINE_PREMIXING_WORKER(TYPE)
Definition: PreMixingWorkerFactory.h:16
StripSubdetector::TOB
static constexpr auto TOB
Definition: StripSubdetector.h:18
SiStripPedestals.h
SiStripApvSimulationParameters.h
edm::DetSet::data
collection_type data
Definition: DetSet.h:80
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
PreMixingWorker
Definition: PreMixingWorker.h:14
SiStripBadStrip::data::range
unsigned short range
Definition: SiStripBadStrip.h:34
StripGeomDetUnit::specificTopology
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
Definition: StripGeomDetUnit.cc:17
SiStripDigi
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
Definition: SiStripDigi.h:12
SiStripGainSimRcd
Definition: SiStripDependentRecords.h:32
DetSet.h
ConsumesCollector.h
SiStripApvSimulationParameters::sampleTEC
float sampleTEC(layerid wheel, float r, float pu, CLHEP::HepRandomEngine *engine) const
Definition: SiStripApvSimulationParameters.h:60
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
PreMixingSiStripWorker::gainLabel
std::string gainLabel
Definition: PreMixingSiStripWorker.cc:103
ParameterSet.h
PreMixingSiStripWorker::SiStripPileInputTag_
edm::InputTag SiStripPileInputTag_
Definition: PreMixingSiStripWorker.cc:61
SiGaussianTailNoiseAdder.h
PileUpEventPrincipal::getByLabel
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
Definition: PileUpEventPrincipal.h:33
PreMixingSiStripWorker::SiGlobalRawIndex
std::map< uint32_t, OneDetectorRawMap > SiGlobalRawIndex
Definition: PreMixingSiStripWorker.cc:75
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
SiStripApvSimulationParameters::sampleTOB
float sampleTOB(layerid layer, float z, float pu, CLHEP::HepRandomEngine *engine) const
Definition: SiStripApvSimulationParameters.h:54
SiStripNoises::getNoise
static float getNoise(uint16_t strip, const Range &range)
Definition: SiStripNoises.h:73
PreMixingSiStripWorker::SistripAPVListDM_
std::string SistripAPVListDM_
Definition: PreMixingSiStripWorker.cc:66
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
PreMixingSiStripWorker::pDD
edm::ESHandle< TrackerGeometry > pDD
Definition: PreMixingSiStripWorker.cc:116
PreMixingSiStripWorker::SiRawDigis_
SiGlobalRawIndex SiRawDigis_
Definition: PreMixingSiStripWorker.cc:80
edm::Event
Definition: Event.h:73
PreMixingSiStripWorker::SistripLabelSig_
edm::InputTag SistripLabelSig_
Definition: PreMixingSiStripWorker.cc:60
TrackerTopology::tecWheel
unsigned int tecWheel(const DetId &id) const
Definition: TrackerTopology.h:198
SiTrivialDigitalConverter.h
StripTopology
Definition: StripTopology.h:11
StripSubdetector.h
PreMixingSiStripWorker::DMinitializeDetUnit
void DMinitializeDetUnit(StripGeomDetUnit const *det, const edm::EventSetup &iSetup)
Definition: PreMixingSiStripWorker.cc:215
PV3DBase::perp
T perp() const
Definition: PV3DBase.h:69
edm::InputTag
Definition: InputTag.h:15
SiStripBadStrip::ContainerIterator
std::vector< unsigned int >::const_iterator ContainerIterator
Definition: SiStripBadStrip.h:52
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
StripSubdetector::TID
static constexpr auto TID
Definition: StripSubdetector.h:17
PileupSummaryInfo
Definition: PileupSummaryInfo.h:22
SiStripSubdetector::TID
Definition: SiStripEnums.h:5
Local3DPoint
Point3DBase< float, LocalTag > Local3DPoint
Definition: LocalPoint.h:9
SiStripBadStrip::data
Definition: SiStripBadStrip.h:32
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
StripGeomDetUnit
Definition: StripGeomDetUnit.h:15
TrackerTopology::tibLayer
unsigned int tibLayer(const DetId &id) const
Definition: TrackerTopology.h:150