CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes
PreMixingSiStripWorker Class Reference
Inheritance diagram for PreMixingSiStripWorker:
PreMixingWorker

Classes

class  StrictWeakOrdering
 
class  StrictWeakRawOrdering
 

Public Member Functions

void addPileups (PileUpEventPrincipal const &pep, edm::EventSetup const &es) override
 
void addSignals (edm::Event const &e, edm::EventSetup const &es) override
 
void initializeEvent (edm::Event const &e, edm::EventSetup const &c) override
 
 PreMixingSiStripWorker (const edm::ParameterSet &ps, edm::ProducerBase &producer, edm::ConsumesCollector &&iC)
 
void put (edm::Event &e, edm::EventSetup const &iSetup, std::vector< PileupSummaryInfo > const &ps, int bs) override
 
 ~PreMixingSiStripWorker () override=default
 
- Public Member Functions inherited from PreMixingWorker
virtual void beginLuminosityBlock (edm::LuminosityBlock const &iLumi, edm::EventSetup const &iSetup)
 
virtual void beginRun (edm::Run const &iRun, edm::EventSetup const &iSetup)
 
virtual void endRun ()
 
virtual void finalizeBunchCrossing (edm::Event &iEvent, edm::EventSetup const &iSetup, int bunchCrossing)
 
virtual void initializeBunchCrossing (edm::Event const &iEvent, edm::EventSetup const &iSetup, int bunchCrossing)
 
 PreMixingWorker ()=default
 
virtual ~PreMixingWorker ()=default
 

Private Types

typedef float Amplitude
 
typedef std::multimap< uint32_t, std::bitset< 6 > > APVMap
 
typedef SiDigitalConverter::DigitalVecType DigitalVecType
 
typedef std::vector< SiStripDigiOneDetectorMap
 
typedef std::vector< RawDigiOneDetectorRawMap
 
typedef std::pair< uint16_t, AmplitudeRawDigi
 
typedef std::map< uint32_t, OneDetectorMapSiGlobalIndex
 
typedef std::map< uint32_t, OneDetectorRawMapSiGlobalRawIndex
 
typedef std::map< uint32_t, SignalMapTypesignalMaps
 
typedef std::map< int, AmplitudeSignalMapType
 

Private Member Functions

void DMinitializeDetUnit (StripGeomDetUnit const *det, const edm::EventSetup &iSetup)
 
const SignalMapTypegetSignal (uint32_t detID) const
 

Private Attributes

std::map< unsigned int, std::vector< bool > > allBadChannels
 
std::map< unsigned int, std::vector< bool > > allHIPChannels
 
bool APVSaturationFromHIP_
 
std::map< unsigned int, size_t > firstChannelsWithSignal
 
std::string gainLabel
 
std::string geometryType
 
std::map< unsigned int, size_t > lastChannelsWithSignal
 
edm::ESHandle< TrackerGeometrypDD
 
bool peakMode
 
signalMaps signals_
 
SiGlobalIndex SiHitStorage_
 
bool SingleStripNoise
 
SiGlobalRawIndex SiRawDigis_
 
edm::InputTag SistripAPVLabelSig_
 
std::string SistripAPVListDM_
 
edm::InputTag SiStripAPVPileInputTag_
 
std::string SiStripDigiCollectionDM_
 
edm::InputTag SistripLabelSig_
 
edm::InputTag SiStripPileInputTag_
 
APVMap theAffectedAPVmap_
 
double theElectronPerADC
 
int theFedAlgo
 
std::unique_ptr< SiTrivialDigitalConvertertheSiDigitalConverter
 
std::unique_ptr< SiGaussianTailNoiseAddertheSiNoiseAdder
 
std::unique_ptr< SiStripFedZeroSuppressiontheSiZeroSuppress
 
double theThreshold
 

Detailed Description

Definition at line 42 of file PreMixingSiStripWorker.cc.

Member Typedef Documentation

typedef float PreMixingSiStripWorker::Amplitude
private

Definition at line 67 of file PreMixingSiStripWorker.cc.

typedef std::multimap<uint32_t, std::bitset<6> > PreMixingSiStripWorker::APVMap
private

Definition at line 94 of file PreMixingSiStripWorker.cc.

Definition at line 74 of file PreMixingSiStripWorker.cc.

Definition at line 69 of file PreMixingSiStripWorker.cc.

typedef std::vector<RawDigi> PreMixingSiStripWorker::OneDetectorRawMap
private

Definition at line 70 of file PreMixingSiStripWorker.cc.

typedef std::pair<uint16_t, Amplitude> PreMixingSiStripWorker::RawDigi
private

Definition at line 68 of file PreMixingSiStripWorker.cc.

typedef std::map<uint32_t, OneDetectorMap> PreMixingSiStripWorker::SiGlobalIndex
private

Definition at line 71 of file PreMixingSiStripWorker.cc.

typedef std::map<uint32_t, OneDetectorRawMap> PreMixingSiStripWorker::SiGlobalRawIndex
private

Definition at line 72 of file PreMixingSiStripWorker.cc.

typedef std::map<uint32_t, SignalMapType> PreMixingSiStripWorker::signalMaps
private

Definition at line 81 of file PreMixingSiStripWorker.cc.

typedef std::map<int, Amplitude> PreMixingSiStripWorker::SignalMapType
private

Definition at line 80 of file PreMixingSiStripWorker.cc.

Constructor & Destructor Documentation

PreMixingSiStripWorker::PreMixingSiStripWorker ( const edm::ParameterSet ps,
edm::ProducerBase producer,
edm::ConsumesCollector &&  iC 
)

Definition at line 136 of file PreMixingSiStripWorker.cc.

References APVSaturationFromHIP_, Exception, edm::ParameterSet::getParameter(), edm::Service< T >::isAvailable(), edm::ProductRegistryHelper::produces(), SiHitStorage_, SistripAPVLabelSig_, SistripAPVListDM_, SiStripAPVPileInputTag_, SiStripDigiCollectionDM_, SistripLabelSig_, SiStripPileInputTag_, AlCaHLTBitMon_QueryRunRegistry::string, theSiNoiseAdder, and theThreshold.

139  : gainLabel(ps.getParameter<std::string>("Gain")),
140  SingleStripNoise(ps.getParameter<bool>("SingleStripNoise")),
141  peakMode(ps.getParameter<bool>("APVpeakmode")),
142  theThreshold(ps.getParameter<double>("NoiseSigmaThreshold")),
143  theElectronPerADC(ps.getParameter<double>(peakMode ? "electronPerAdcPeak" : "electronPerAdcDec")),
144  APVSaturationFromHIP_(ps.getParameter<bool>("APVSaturationFromHIP")),
145  theFedAlgo(ps.getParameter<int>("FedAlgorithm_PM")),
146  geometryType(ps.getParameter<std::string>("GeometryType")),
149 
150 {
151  // declare the products to produce
152 
153  SistripLabelSig_ = ps.getParameter<edm::InputTag>("SistripLabelSig");
154  SiStripPileInputTag_ = ps.getParameter<edm::InputTag>("SiStripPileInputTag");
155 
156  SiStripDigiCollectionDM_ = ps.getParameter<std::string>("SiStripDigiCollectionDM");
157  SistripAPVListDM_ = ps.getParameter<std::string>("SiStripAPVListDM");
158 
160 
161  if (APVSaturationFromHIP_) {
162  SistripAPVLabelSig_ = ps.getParameter<edm::InputTag>("SistripAPVLabelSig");
163  SiStripAPVPileInputTag_ = ps.getParameter<edm::InputTag>("SistripAPVPileInputTag");
164  iC.consumes<std::vector<std::pair<int, std::bitset<6>>>>(SistripAPVLabelSig_);
165  }
167  // clear local storage for this event
168  SiHitStorage_.clear();
169 
171  if (!rng.isAvailable()) {
172  throw cms::Exception("Psiguration") << "SiStripDigitizer requires the RandomNumberGeneratorService\n"
173  "which is not present in the psiguration file. You must add the service\n"
174  "in the configuration file or remove the modules that require it.";
175  }
176 
178 }
BranchAliasSetterT< ProductType > produces()
declare what type of product will make and with which optional label
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
std::unique_ptr< SiTrivialDigitalConverter > theSiDigitalConverter
std::unique_ptr< SiGaussianTailNoiseAdder > theSiNoiseAdder
bool isAvailable() const
Definition: Service.h:40
std::unique_ptr< SiStripFedZeroSuppression > theSiZeroSuppress
PreMixingSiStripWorker::~PreMixingSiStripWorker ( )
overridedefault

Member Function Documentation

void PreMixingSiStripWorker::addPileups ( PileUpEventPrincipal const &  pep,
edm::EventSetup const &  es 
)
overridevirtual

Implements PreMixingWorker.

Definition at line 261 of file PreMixingSiStripWorker.cc.

References APVSaturationFromHIP_, begin, PileUpEventPrincipal::bunchCrossing(), end, mps_splice::entry, PileUpEventPrincipal::getByLabel(), edm::EventPrincipal::id(), input, edm::HandleBase::isValid(), LogDebug, PileUpEventPrincipal::principal(), SiHitStorage_, SiStripAPVPileInputTag_, SiStripPileInputTag_, and theAffectedAPVmap_.

261  {
262  LogDebug("PreMixingSiStripWorker") << "\n===============> adding pileups from event " << pep.principal().id()
263  << " for bunchcrossing " << pep.bunchCrossing();
264 
265  // fill in maps of hits; same code as addSignals, except now applied to the pileup events
266 
268  pep.getByLabel(SiStripPileInputTag_, inputHandle);
269 
270  if (inputHandle.isValid()) {
271  const auto& input = *inputHandle;
272 
273  OneDetectorMap LocalMap;
274 
275  //loop on all detsets (detectorIDs) inside the input collection
277  for (; DSViter != input.end(); DSViter++) {
278 #ifdef DEBUG
279  LogDebug("PreMixingSiStripWorker") << "Pileups: Processing DetID " << DSViter->id;
280 #endif
281 
282  // find correct local map (or new one) for this detector ID
283 
284  SiGlobalIndex::const_iterator itest;
285 
286  itest = SiHitStorage_.find(DSViter->id);
287 
288  if (itest != SiHitStorage_.end()) { // this detID already has hits, add to existing map
289 
290  LocalMap = itest->second;
291 
292  // fill in local map with extra channels
293  LocalMap.insert(LocalMap.end(), (DSViter->data).begin(), (DSViter->data).end());
294  std::stable_sort(LocalMap.begin(), LocalMap.end(), PreMixingSiStripWorker::StrictWeakOrdering());
295  SiHitStorage_[DSViter->id] = LocalMap;
296 
297  } else { // fill local storage with this information, put in global collection
298 
299  LocalMap.clear();
300  LocalMap.reserve((DSViter->data).size());
301  LocalMap.insert(LocalMap.end(), (DSViter->data).begin(), (DSViter->data).end());
302 
303  SiHitStorage_.insert(SiGlobalIndex::value_type(DSViter->id, LocalMap));
304  }
305  }
306 
307  if (APVSaturationFromHIP_) {
309  pep.getByLabel(SiStripAPVPileInputTag_, inputAPVHandle);
310 
311  if (inputAPVHandle.isValid()) {
312  const auto& APVinput = inputAPVHandle;
313 
314  std::vector<std::pair<int, std::bitset<6>>>::const_iterator entry = APVinput->begin();
315  for (; entry != APVinput->end(); entry++) {
316  theAffectedAPVmap_.insert(APVMap::value_type(entry->first, entry->second));
317  }
318  }
319  }
320  }
321 }
#define LogDebug(id)
static std::string const input
Definition: EdmProvDump.cc:48
std::vector< SiStripDigi > OneDetectorMap
#define end
Definition: vmac.h:39
bool isValid() const
Definition: HandleBase.h:74
#define begin
Definition: vmac.h:32
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:104
void PreMixingSiStripWorker::addSignals ( edm::Event const &  e,
edm::EventSetup const &  es 
)
overridevirtual

Implements PreMixingWorker.

Definition at line 223 of file PreMixingSiStripWorker.cc.

References begin, end, edm::Event::getByLabel(), input, LogDebug, edm::DetSetVector< T >::reserve(), SiHitStorage_, and SistripLabelSig_.

223  {
224  // fill in maps of hits
225 
227 
228  if (e.getByLabel(SistripLabelSig_, input)) {
229  OneDetectorMap LocalMap;
230 
231  //loop on all detsets (detectorIDs) inside the input collection
232  edm::DetSetVector<SiStripDigi>::const_iterator DSViter = input->begin();
233  for (; DSViter != input->end(); DSViter++) {
234 #ifdef DEBUG
235  LogDebug("PreMixingSiStripWorker") << "Processing DetID " << DSViter->id;
236 #endif
237 
238  LocalMap.clear();
239  LocalMap.reserve((DSViter->data).size());
240  LocalMap.insert(LocalMap.end(), (DSViter->data).begin(), (DSViter->data).end());
241 
242  SiHitStorage_.insert(SiGlobalIndex::value_type(DSViter->id, LocalMap));
243  }
244  }
245 
246  // keep here for future reference. In current implementation, HIP killing is done once in PU file
247  /* if(APVSaturationFromHIP_) {
248  edm::Handle<std::vector<std::pair<int,std::bitset<6>> > > APVinput;
249 
250  if( e.getByLabel(SistripAPVLabelSig_,APVinput) ) {
251 
252  std::vector<std::pair<int,std::bitset<6>> >::const_iterator entry = APVinput->begin();
253  for( ; entry != APVinput->end(); entry++) {
254  theAffectedAPVmap_.insert(APVMap::value_type(entry->first, entry->second));
255  }
256  }
257  } */
258 
259 } // end of addSiStripSignals
#define LogDebug(id)
void reserve(size_t s)
Definition: DetSetVector.h:150
static std::string const input
Definition: EdmProvDump.cc:48
std::vector< SiStripDigi > OneDetectorMap
#define end
Definition: vmac.h:39
#define begin
Definition: vmac.h:32
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:104
void PreMixingSiStripWorker::DMinitializeDetUnit ( StripGeomDetUnit const *  det,
const edm::EventSetup iSetup 
)
private

Definition at line 198 of file PreMixingSiStripWorker.cc.

References allBadChannels, allHIPChannels, SiStripBadStrip::decode(), firstChannelsWithSignal, SiStripBadStrip::data::firstStrip, GeomDet::geographicalId(), edm::EventSetup::get(), SiStripBadStrip::getRange(), lastChannelsWithSignal, SiStripBadStrip::data::range, DetId::rawId(), StripGeomDetUnit::specificTopology(), and digitizers_cfi::strip.

Referenced by initializeEvent().

198  {
199  edm::ESHandle<SiStripBadStrip> deadChannelHandle;
200  iSetup.get<SiStripBadChannelRcd>().get(deadChannelHandle);
201 
202  unsigned int detId = det->geographicalId().rawId();
203  int numStrips = (det->specificTopology()).nstrips();
204 
205  SiStripBadStrip::Range detBadStripRange = deadChannelHandle->getRange(detId);
206  //storing the bad strip of the the module. the module is not removed but just signal put to 0
207  std::vector<bool>& badChannels = allBadChannels[detId];
208  std::vector<bool>& hipChannels = allHIPChannels[detId];
209  badChannels.clear();
210  badChannels.insert(badChannels.begin(), numStrips, false);
211  hipChannels.clear();
212  hipChannels.insert(hipChannels.begin(), numStrips, false);
213 
214  for (SiStripBadStrip::ContainerIterator it = detBadStripRange.first; it != detBadStripRange.second; ++it) {
215  SiStripBadStrip::data fs = deadChannelHandle->decode(*it);
216  for (int strip = fs.firstStrip; strip < fs.firstStrip + fs.range; ++strip)
217  badChannels[strip] = true;
218  }
219  firstChannelsWithSignal[detId] = numStrips;
220  lastChannelsWithSignal[detId] = 0;
221 }
unsigned short range
std::map< unsigned int, std::vector< bool > > allBadChannels
std::map< unsigned int, std::vector< bool > > allHIPChannels
std::map< unsigned int, size_t > lastChannelsWithSignal
std::vector< unsigned int >::const_iterator ContainerIterator
unsigned short firstStrip
const Range getRange(const uint32_t detID) const
std::pair< ContainerIterator, ContainerIterator > Range
T get() const
Definition: EventSetup.h:71
std::map< unsigned int, size_t > firstChannelsWithSignal
data decode(const unsigned int &value) const
const SignalMapType* PreMixingSiStripWorker::getSignal ( uint32_t  detID) const
inlineprivate

Definition at line 83 of file PreMixingSiStripWorker.cc.

References signals_.

Referenced by put().

83  {
84  auto where = signals_.find(detID);
85  if (where == signals_.end()) {
86  return nullptr;
87  }
88  return &where->second;
89  }
void PreMixingSiStripWorker::initializeEvent ( edm::Event const &  e,
edm::EventSetup const &  c 
)
overridevirtual

Implements PreMixingWorker.

Definition at line 180 of file PreMixingSiStripWorker.cc.

References TrackerGeometry::detUnits(), DMinitializeDetUnit(), geometryType, edm::EventSetup::get(), pDD, DetId::subdetId(), StripSubdetector::TEC, StripSubdetector::TIB, StripSubdetector::TID, and StripSubdetector::TOB.

180  {
181  // initialize individual detectors so we can copy real digitization code:
182 
183  iSetup.get<TrackerDigiGeometryRecord>().get(geometryType, pDD);
184 
185  for (auto iu = pDD->detUnits().begin(); iu != pDD->detUnits().end(); ++iu) {
186  unsigned int detId = (*iu)->geographicalId().rawId();
187  DetId idet = DetId(detId);
188  unsigned int isub = idet.subdetId();
189  if ((isub == StripSubdetector::TIB) || (isub == StripSubdetector::TID) || (isub == StripSubdetector::TOB) ||
190  (isub == StripSubdetector::TEC)) {
191  auto stripdet = dynamic_cast<StripGeomDetUnit const*>((*iu));
192  assert(stripdet != nullptr);
193  DMinitializeDetUnit(stripdet, iSetup);
194  }
195  }
196 }
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
edm::ESHandle< TrackerGeometry > pDD
void DMinitializeDetUnit(StripGeomDetUnit const *det, const edm::EventSetup &iSetup)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
Definition: DetId.h:18
void PreMixingSiStripWorker::put ( edm::Event e,
edm::EventSetup const &  iSetup,
std::vector< PileupSummaryInfo > const &  ps,
int  bs 
)
overridevirtual

Implements PreMixingWorker.

Definition at line 323 of file PreMixingSiStripWorker.cc.

References allBadChannels, APVSaturationFromHIP_, edm::DetSet< T >::data, DEFINE_PREMIXING_WORKER, TrackerGeometry::detUnits(), SiPixelPhase1TrackClustersV_cfi::e3, objects.autophobj::float, gainLabel, GeomDet::geographicalId(), edm::EventSetup::get(), edm::RandomNumberGenerator::getEngine(), SiStripNoises::getNoise(), SiStripNoises::getRange(), SiStripGain::getRange(), getSignal(), SiStripGain::getStripGain(), createfilelist::int, eostools::move(), pDD, edm::Event::put(), DetId::rawId(), signals_, SiHitStorage_, SingleStripNoise, SiRawDigis_, SiStripDigiCollectionDM_, StripGeomDetUnit::specificTopology(), edm::Event::streamID(), digitizers_cfi::strip, groupFilesInBlocks::temp, theAffectedAPVmap_, theElectronPerADC, theSiDigitalConverter, theSiNoiseAdder, and theSiZeroSuppress.

326  {
327  // set up machinery to do proper noise adding:
328  edm::ESHandle<SiStripGain> gainHandle;
329  edm::ESHandle<SiStripNoises> noiseHandle;
330  edm::ESHandle<SiStripThreshold> thresholdHandle;
331  edm::ESHandle<SiStripPedestals> pedestalHandle;
332  edm::ESHandle<SiStripBadStrip> deadChannelHandle;
333  iSetup.get<SiStripGainSimRcd>().get(gainLabel, gainHandle);
334  iSetup.get<SiStripNoisesRcd>().get(noiseHandle);
335  iSetup.get<SiStripThresholdRcd>().get(thresholdHandle);
336  iSetup.get<SiStripPedestalsRcd>().get(pedestalHandle);
337 
339  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
340 
341  std::map<int, std::bitset<6>> DeadAPVList;
342  DeadAPVList.clear();
343 
344  // First, have to convert all ADC counts to raw pulse heights so that values can be added properly
345  // In PreMixing, pulse heights are saved with ADC = sqrt(9.0*PulseHeight) - have to undo.
346 
347  // This is done here because it's the only place we have access to EventSetup
348  // Simultaneously, merge lists of hit channels in each DetId.
349  // Signal Digis are in the list first, have to merge lists of hit strips on the fly,
350  // add signals on duplicates later
351 
352  OneDetectorRawMap LocalRawMap;
353 
354  // Now, loop over hits and add them to the map in the proper sorted order
355  // Note: We are assuming that the hits from the Signal events have been created in
356  // "PreMix" mode, rather than in the standard ADC conversion routines. If not, this
357  // doesn't work at all.
358 
359  // At the moment, both Signal and Reconstituted PU hits have the same compression algorithm.
360  // If this were different, and one needed gains, the conversion back to pulse height can only
361  // be done in this routine. So, yes, there is an extra loop over hits here in the current code,
362  // because, in principle, one could convert to pulse height during the read/store phase.
363 
364  for (SiGlobalIndex::const_iterator IDet = SiHitStorage_.begin(); IDet != SiHitStorage_.end(); IDet++) {
365  uint32_t detID = IDet->first;
366 
367  OneDetectorMap LocalMap = IDet->second;
368 
369  //loop over hit strips for this DetId, do conversion to pulse height, store.
370 
371  LocalRawMap.clear();
372 
373  OneDetectorMap::const_iterator iLocal = LocalMap.begin();
374  for (; iLocal != LocalMap.end(); ++iLocal) {
375  uint16_t currentStrip = iLocal->strip();
376  float signal = float(iLocal->adc());
377  if (iLocal->adc() == 1022)
378  signal = 1500.; // average values for overflows
379  if (iLocal->adc() == 1023)
380  signal = 3000.;
381 
382  //convert signals back to raw counts
383 
384  float ReSignal = signal * signal / 9.0; // The PreMixing conversion is adc = sqrt(9.0*pulseHeight)
385 
386  RawDigi NewRawDigi = std::make_pair(currentStrip, ReSignal);
387 
388  LocalRawMap.push_back(NewRawDigi);
389  }
390 
391  // save information for this detiD into global map
392  SiRawDigis_.insert(SiGlobalRawIndex::value_type(detID, LocalRawMap));
393  }
394 
395  // If we are killing APVs, merge list of dead ones before we digitize
396 
397  int NumberOfBxBetweenHIPandEvent = 1e3;
398 
399  if (APVSaturationFromHIP_) {
400  // calculate affected BX parameter
401 
402  bool HasAtleastOneAffectedAPV = false;
403  while (!HasAtleastOneAffectedAPV) {
404  for (int bx = floor(300.0 / 25.0); bx > 0; bx--) { //Reminder: make these numbers not hard coded!!
405  float temp = CLHEP::RandFlat::shoot(engine) < 0.5 ? 1 : 0;
406  if (temp == 1 && bx < NumberOfBxBetweenHIPandEvent) {
407  NumberOfBxBetweenHIPandEvent = bx;
408  HasAtleastOneAffectedAPV = true;
409  }
410  }
411  }
412 
413  APVMap::const_iterator iAPVchk;
414  uint32_t formerID = 0;
415  uint32_t currentID;
416  std::bitset<6> NewAPVBits;
417 
418  for (APVMap::const_iterator iAPV = theAffectedAPVmap_.begin(); iAPV != theAffectedAPVmap_.end(); ++iAPV) {
419  currentID = iAPV->first;
420 
421  if (currentID == formerID) { // we have to OR these
422  for (int ibit = 0; ibit < 6; ++ibit) {
423  NewAPVBits[ibit] = NewAPVBits[ibit] || (iAPV->second)[ibit];
424  }
425  } else {
426  DeadAPVList[currentID] = NewAPVBits;
427  //save pointers for next iteration
428  formerID = currentID;
429  NewAPVBits = iAPV->second;
430  }
431 
432  iAPVchk = iAPV;
433  if ((++iAPVchk) == theAffectedAPVmap_.end()) { //make sure not to lose the last one
434  DeadAPVList[currentID] = NewAPVBits;
435  }
436  }
437  }
438  //
439 
440  // Ok, done with merging raw signals and APVs - now add signals on duplicate strips
441 
442  // collection of Digis to put in the event
443  std::vector<edm::DetSet<SiStripDigi>> vSiStripDigi;
444 
445  // loop through our collection of detectors, merging hits and making a new list of "signal" digis
446 
447  // clear some temporary storage for later digitization:
448 
449  signals_.clear();
450 
451  // big loop over Detector IDs:
452  for (SiGlobalRawIndex::const_iterator IDet = SiRawDigis_.begin(); IDet != SiRawDigis_.end(); IDet++) {
453  uint32_t detID = IDet->first;
454 
455  SignalMapType Signals;
456  Signals.clear();
457 
458  OneDetectorRawMap LocalMap = IDet->second;
459 
460  //counter variables
461  int formerStrip = -1;
462  int currentStrip;
463  float ADCSum = 0;
464 
465  //loop over hit strips for this DetId, add duplicates
466 
467  OneDetectorRawMap::const_iterator iLocalchk;
468  OneDetectorRawMap::const_iterator iLocal = LocalMap.begin();
469  for (; iLocal != LocalMap.end(); ++iLocal) {
470  currentStrip = iLocal->first; // strip is first element
471 
472  if (currentStrip == formerStrip) { // we have to add these digis together
473 
474  ADCSum += iLocal->second; // raw pulse height is second element.
475  } else {
476  if (formerStrip != -1) {
477  Signals.insert(std::make_pair(formerStrip, ADCSum));
478  }
479  // save pointers for next iteration
480  formerStrip = currentStrip;
481  ADCSum = iLocal->second; // lone ADC
482  }
483 
484  iLocalchk = iLocal;
485  if ((++iLocalchk) == LocalMap.end()) { //make sure not to lose the last one
486  Signals.insert(std::make_pair(formerStrip, ADCSum));
487  }
488  }
489  // save merged map:
490  signals_.insert(std::make_pair(detID, Signals));
491  }
492 
493  //Now, do noise, zero suppression, take into account bad channels, etc.
494  // This section stolen from SiStripDigitizerAlgorithm
495  // must loop over all detIds in the tracker to get all of the noise added properly.
496  for (const auto& iu : pDD->detUnits()) {
497  const StripGeomDetUnit* sgd = dynamic_cast<const StripGeomDetUnit*>(iu);
498  if (sgd != nullptr) {
499  uint32_t detID = sgd->geographicalId().rawId();
500 
501  edm::DetSet<SiStripDigi> SSD(detID); // Make empty collection with this detector ID
502 
503  int numStrips = (sgd->specificTopology()).nstrips();
504 
505  // see if there is some signal on this detector
506 
507  const SignalMapType* theSignal(getSignal(detID));
508 
509  std::vector<float> detAmpl(numStrips, 0.);
510  if (theSignal) {
511  for (const auto& amp : *theSignal) {
512  detAmpl[amp.first] = amp.second;
513  }
514  }
515 
516  //removing signal from the dead (and HIP effected) strips
517  std::vector<bool>& badChannels = allBadChannels[detID];
518 
519  for (int strip = 0; strip < numStrips; ++strip) {
520  if (badChannels[strip])
521  detAmpl[strip] = 0.;
522  }
523 
524  if (APVSaturationFromHIP_) {
525  std::bitset<6>& bs = DeadAPVList[detID];
526 
527  if (bs.any()) {
528  // Here below is the scaling function which describes the evolution of the baseline (i.e. how the charge is suppressed).
529  // This must be replaced as soon as we have a proper modeling of the baseline evolution from VR runs
530  float Shift =
531  1 - NumberOfBxBetweenHIPandEvent / floor(300.0 / 25.0); //Reminder: make these numbers not hardcoded!!
532  float randomX = CLHEP::RandFlat::shoot(engine);
533  float scalingValue = (randomX - Shift) * 10.0 / 7.0 - 3.0 / 7.0;
534 
535  for (int strip = 0; strip < numStrips; ++strip) {
536  if (!badChannels[strip] && bs[strip / 128] == 1) {
537  detAmpl[strip] *= scalingValue > 0 ? scalingValue : 0.0;
538  }
539  }
540  }
541  }
542 
543  SiStripNoises::Range detNoiseRange = noiseHandle->getRange(detID);
544  SiStripApvGain::Range detGainRange = gainHandle->getRange(detID);
545 
546  // Gain conversion is already done during signal adding
547  //convert our signals back to raw counts so that we can add noise properly:
548 
549  /*
550  if(theSignal) {
551  for(unsigned int iv = 0; iv!=detAmpl.size(); iv++) {
552  float signal = detAmpl[iv];
553  if(signal > 0) {
554  float gainValue = gainHandle->getStripGain(iv, detGainRange);
555  signal *= theElectronPerADC/gainValue;
556  detAmpl[iv] = signal;
557  }
558  }
559  }
560  */
561 
562  //SiStripPedestals::Range detPedestalRange = pedestalHandle->getRange(detID);
563 
564  // -----------------------------------------------------------
565 
566  size_t firstChannelWithSignal = 0;
567  size_t lastChannelWithSignal = numStrips;
568 
569  if (SingleStripNoise) {
570  std::vector<float> noiseRMSv;
571  noiseRMSv.clear();
572  noiseRMSv.insert(noiseRMSv.begin(), numStrips, 0.);
573  for (int strip = 0; strip < numStrips; ++strip) {
574  if (!badChannels[strip]) {
575  float gainValue = gainHandle->getStripGain(strip, detGainRange);
576  noiseRMSv[strip] = (noiseHandle->getNoise(strip, detNoiseRange)) * theElectronPerADC / gainValue;
577  }
578  }
579  theSiNoiseAdder->addNoiseVR(detAmpl, noiseRMSv, engine);
580  } else {
581  int RefStrip = int(numStrips / 2.);
582  while (RefStrip < numStrips &&
583  badChannels[RefStrip]) { //if the refstrip is bad, I move up to when I don't find it
584  RefStrip++;
585  }
586  if (RefStrip < numStrips) {
587  float RefgainValue = gainHandle->getStripGain(RefStrip, detGainRange);
588  float RefnoiseRMS = noiseHandle->getNoise(RefStrip, detNoiseRange) * theElectronPerADC / RefgainValue;
589 
590  theSiNoiseAdder->addNoise(
591  detAmpl, firstChannelWithSignal, lastChannelWithSignal, numStrips, RefnoiseRMS, engine);
592  }
593  }
594 
595  DigitalVecType digis;
596  theSiZeroSuppress->suppress(
597  theSiDigitalConverter->convert(detAmpl, gainHandle, detID), digis, detID, noiseHandle, thresholdHandle);
598 
599  SSD.data = digis;
600 
601  // stick this into the global vector of detector info
602  vSiStripDigi.push_back(SSD);
603 
604  } // end of loop over one detector
605 
606  } // end of big loop over all detector IDs
607 
608  // put the collection of digis in the event
609  edm::LogInfo("PreMixingSiStripWorker") << "total # Merged strips: " << vSiStripDigi.size();
610 
611  // make new digi collection
612 
613  std::unique_ptr<edm::DetSetVector<SiStripDigi>> MySiStripDigis(new edm::DetSetVector<SiStripDigi>(vSiStripDigi));
614 
615  // put collection
616 
617  e.put(std::move(MySiStripDigis), SiStripDigiCollectionDM_);
618 
619  // clear local storage for this event
620  SiHitStorage_.clear();
621  SiRawDigis_.clear();
622  signals_.clear();
623 }
std::map< unsigned int, std::vector< bool > > allBadChannels
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
std::unique_ptr< SiTrivialDigitalConverter > theSiDigitalConverter
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
edm::ESHandle< TrackerGeometry > pDD
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
static float getNoise(uint16_t strip, const Range &range)
Definition: SiStripNoises.h:74
static float getStripGain(const uint16_t &strip, const SiStripApvGain::Range &range)
Definition: SiStripGain.h:73
std::vector< SiStripDigi > OneDetectorMap
const SignalMapType * getSignal(uint32_t detID) const
std::unique_ptr< SiGaussianTailNoiseAdder > theSiNoiseAdder
std::pair< ContainerIterator, ContainerIterator > Range
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:79
std::unique_ptr< SiStripFedZeroSuppression > theSiZeroSuppress
std::pair< uint16_t, Amplitude > RawDigi
const Range getRange(const uint32_t detID) const
StreamID streamID() const
Definition: Event.h:95
std::vector< RawDigi > OneDetectorRawMap
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:50
def move(src, dest)
Definition: eostools.py:511
std::map< int, Amplitude > SignalMapType
const SiStripApvGain::Range getRange(uint32_t detID) const
Definition: SiStripGain.h:71
SiDigitalConverter::DigitalVecType DigitalVecType

Member Data Documentation

std::map<unsigned int, std::vector<bool> > PreMixingSiStripWorker::allBadChannels
private

Definition at line 116 of file PreMixingSiStripWorker.cc.

Referenced by DMinitializeDetUnit(), and put().

std::map<unsigned int, std::vector<bool> > PreMixingSiStripWorker::allHIPChannels
private

Definition at line 118 of file PreMixingSiStripWorker.cc.

Referenced by DMinitializeDetUnit().

bool PreMixingSiStripWorker::APVSaturationFromHIP_
private

Definition at line 105 of file PreMixingSiStripWorker.cc.

Referenced by addPileups(), PreMixingSiStripWorker(), and put().

std::map<unsigned int, size_t> PreMixingSiStripWorker::firstChannelsWithSignal
private

Definition at line 120 of file PreMixingSiStripWorker.cc.

Referenced by DMinitializeDetUnit().

std::string PreMixingSiStripWorker::gainLabel
private

Definition at line 100 of file PreMixingSiStripWorker.cc.

Referenced by put().

std::string PreMixingSiStripWorker::geometryType
private

Definition at line 107 of file PreMixingSiStripWorker.cc.

Referenced by initializeEvent().

std::map<unsigned int, size_t> PreMixingSiStripWorker::lastChannelsWithSignal
private

Definition at line 121 of file PreMixingSiStripWorker.cc.

Referenced by DMinitializeDetUnit().

edm::ESHandle<TrackerGeometry> PreMixingSiStripWorker::pDD
private

Definition at line 113 of file PreMixingSiStripWorker.cc.

Referenced by initializeEvent(), and put().

bool PreMixingSiStripWorker::peakMode
private

Definition at line 102 of file PreMixingSiStripWorker.cc.

signalMaps PreMixingSiStripWorker::signals_
private

Definition at line 91 of file PreMixingSiStripWorker.cc.

Referenced by getSignal(), and put().

SiGlobalIndex PreMixingSiStripWorker::SiHitStorage_
private

Definition at line 76 of file PreMixingSiStripWorker.cc.

Referenced by addPileups(), addSignals(), PreMixingSiStripWorker(), and put().

bool PreMixingSiStripWorker::SingleStripNoise
private

Definition at line 101 of file PreMixingSiStripWorker.cc.

Referenced by put().

SiGlobalRawIndex PreMixingSiStripWorker::SiRawDigis_
private

Definition at line 77 of file PreMixingSiStripWorker.cc.

Referenced by put().

edm::InputTag PreMixingSiStripWorker::SistripAPVLabelSig_
private

Definition at line 61 of file PreMixingSiStripWorker.cc.

Referenced by PreMixingSiStripWorker().

std::string PreMixingSiStripWorker::SistripAPVListDM_
private

Definition at line 63 of file PreMixingSiStripWorker.cc.

Referenced by PreMixingSiStripWorker().

edm::InputTag PreMixingSiStripWorker::SiStripAPVPileInputTag_
private

Definition at line 62 of file PreMixingSiStripWorker.cc.

Referenced by addPileups(), and PreMixingSiStripWorker().

std::string PreMixingSiStripWorker::SiStripDigiCollectionDM_
private

Definition at line 59 of file PreMixingSiStripWorker.cc.

Referenced by PreMixingSiStripWorker(), and put().

edm::InputTag PreMixingSiStripWorker::SistripLabelSig_
private

Definition at line 57 of file PreMixingSiStripWorker.cc.

Referenced by addSignals(), and PreMixingSiStripWorker().

edm::InputTag PreMixingSiStripWorker::SiStripPileInputTag_
private

Definition at line 58 of file PreMixingSiStripWorker.cc.

Referenced by addPileups(), and PreMixingSiStripWorker().

APVMap PreMixingSiStripWorker::theAffectedAPVmap_
private

Definition at line 96 of file PreMixingSiStripWorker.cc.

Referenced by addPileups(), and put().

double PreMixingSiStripWorker::theElectronPerADC
private

Definition at line 104 of file PreMixingSiStripWorker.cc.

Referenced by put().

int PreMixingSiStripWorker::theFedAlgo
private

Definition at line 106 of file PreMixingSiStripWorker.cc.

std::unique_ptr<SiTrivialDigitalConverter> PreMixingSiStripWorker::theSiDigitalConverter
private

Definition at line 111 of file PreMixingSiStripWorker.cc.

Referenced by put().

std::unique_ptr<SiGaussianTailNoiseAdder> PreMixingSiStripWorker::theSiNoiseAdder
private

Definition at line 109 of file PreMixingSiStripWorker.cc.

Referenced by PreMixingSiStripWorker(), and put().

std::unique_ptr<SiStripFedZeroSuppression> PreMixingSiStripWorker::theSiZeroSuppress
private

Definition at line 110 of file PreMixingSiStripWorker.cc.

Referenced by put().

double PreMixingSiStripWorker::theThreshold
private

Definition at line 103 of file PreMixingSiStripWorker.cc.

Referenced by PreMixingSiStripWorker().