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 68 of file PreMixingSiStripWorker.cc.

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

Definition at line 95 of file PreMixingSiStripWorker.cc.

Definition at line 75 of file PreMixingSiStripWorker.cc.

Definition at line 70 of file PreMixingSiStripWorker.cc.

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

Definition at line 71 of file PreMixingSiStripWorker.cc.

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

Definition at line 69 of file PreMixingSiStripWorker.cc.

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

Definition at line 72 of file PreMixingSiStripWorker.cc.

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

Definition at line 73 of file PreMixingSiStripWorker.cc.

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

Definition at line 82 of file PreMixingSiStripWorker.cc.

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

Definition at line 81 of file PreMixingSiStripWorker.cc.

Constructor & Destructor Documentation

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

Definition at line 138 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.

138  :
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")
173  << "SiStripDigitizer requires the RandomNumberGeneratorService\n"
174  "which is not present in the psiguration file. You must add the service\n"
175  "in the configuration file or remove the modules that require it.";
176  }
177 
179 }
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:46
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 271 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_.

271  {
272  LogDebug("PreMixingSiStripWorker") <<"\n===============> adding pileups from event "<<pep.principal().id()<<" for bunchcrossing "<<pep.bunchCrossing();
273 
274  // fill in maps of hits; same code as addSignals, except now applied to the pileup events
275 
277  pep.getByLabel(SiStripPileInputTag_, inputHandle);
278 
279  if(inputHandle.isValid()) {
280  const auto& input = *inputHandle;
281 
282  OneDetectorMap LocalMap;
283 
284  //loop on all detsets (detectorIDs) inside the input collection
286  for (; DSViter!=input.end();DSViter++){
287 
288 #ifdef DEBUG
289  LogDebug("PreMixingSiStripWorker") << "Pileups: Processing DetID " << DSViter->id;
290 #endif
291 
292  // find correct local map (or new one) for this detector ID
293 
294  SiGlobalIndex::const_iterator itest;
295 
296  itest = SiHitStorage_.find(DSViter->id);
297 
298  if(itest!=SiHitStorage_.end()) { // this detID already has hits, add to existing map
299 
300  LocalMap = itest->second;
301 
302  // fill in local map with extra channels
303  LocalMap.insert(LocalMap.end(),(DSViter->data).begin(),(DSViter->data).end());
304  std::stable_sort(LocalMap.begin(),LocalMap.end(),PreMixingSiStripWorker::StrictWeakOrdering());
305  SiHitStorage_[DSViter->id]=LocalMap;
306 
307  }
308  else{ // fill local storage with this information, put in global collection
309 
310  LocalMap.clear();
311  LocalMap.reserve((DSViter->data).size());
312  LocalMap.insert(LocalMap.end(),(DSViter->data).begin(),(DSViter->data).end());
313 
314  SiHitStorage_.insert( SiGlobalIndex::value_type( DSViter->id, LocalMap ) );
315  }
316  }
317 
320  pep.getByLabel(SiStripAPVPileInputTag_, inputAPVHandle);
321 
322  if(inputAPVHandle.isValid()) {
323 
324  const auto &APVinput = inputAPVHandle;
325 
326  std::vector<std::pair<int,std::bitset<6>> >::const_iterator entry = APVinput->begin();
327  for( ; entry != APVinput->end(); entry++) {
328  theAffectedAPVmap_.insert( APVMap::value_type(entry->first, entry->second ));
329  }
330  }
331  }
332  }
333 }
#define LogDebug(id)
static std::string const input
Definition: EdmProvDump.cc:44
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 229 of file PreMixingSiStripWorker.cc.

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

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

203  {
204 
205  edm::ESHandle<SiStripBadStrip> deadChannelHandle;
206  iSetup.get<SiStripBadChannelRcd>().get(deadChannelHandle);
207 
208  unsigned int detId = det->geographicalId().rawId();
209  int numStrips = (det->specificTopology()).nstrips();
210 
211  SiStripBadStrip::Range detBadStripRange = deadChannelHandle->getRange(detId);
212  //storing the bad strip of the the module. the module is not removed but just signal put to 0
213  std::vector<bool>& badChannels = allBadChannels[detId];
214  std::vector<bool>& hipChannels = allHIPChannels[detId];
215  badChannels.clear();
216  badChannels.insert(badChannels.begin(), numStrips, false);
217  hipChannels.clear();
218  hipChannels.insert(hipChannels.begin(), numStrips, false);
219 
220  for(SiStripBadStrip::ContainerIterator it = detBadStripRange.first; it != detBadStripRange.second; ++it) {
221  SiStripBadStrip::data fs = deadChannelHandle->decode(*it);
222  for(int strip = fs.firstStrip; strip < fs.firstStrip + fs.range; ++strip) badChannels[strip] = true;
223  }
224  firstChannelsWithSignal[detId] = numStrips;
225  lastChannelsWithSignal[detId]= 0;
226 }
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:63
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 84 of file PreMixingSiStripWorker.cc.

References signals_.

Referenced by put().

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

Implements PreMixingWorker.

Definition at line 181 of file PreMixingSiStripWorker.cc.

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

181  {
182  // initialize individual detectors so we can copy real digitization code:
183 
184  iSetup.get<TrackerDigiGeometryRecord>().get(geometryType,pDD);
185 
186  for(auto iu = pDD->detUnits().begin(); iu != pDD->detUnits().end(); ++iu) {
187  unsigned int detId = (*iu)->geographicalId().rawId();
188  DetId idet=DetId(detId);
189  unsigned int isub=idet.subdetId();
190  if((isub == StripSubdetector::TIB) ||
191  (isub == StripSubdetector::TID) ||
192  (isub == StripSubdetector::TOB) ||
193  (isub == StripSubdetector::TEC)) {
194 
195  auto stripdet = dynamic_cast<StripGeomDetUnit const*>((*iu));
196  assert(stripdet != nullptr);
197  DMinitializeDetUnit(stripdet, iSetup);
198  }
199  }
200 }
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 337 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.

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

Member Data Documentation

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

Definition at line 117 of file PreMixingSiStripWorker.cc.

Referenced by DMinitializeDetUnit(), and put().

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

Definition at line 119 of file PreMixingSiStripWorker.cc.

Referenced by DMinitializeDetUnit().

bool PreMixingSiStripWorker::APVSaturationFromHIP_
private

Definition at line 106 of file PreMixingSiStripWorker.cc.

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

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

Definition at line 121 of file PreMixingSiStripWorker.cc.

Referenced by DMinitializeDetUnit().

std::string PreMixingSiStripWorker::gainLabel
private

Definition at line 101 of file PreMixingSiStripWorker.cc.

Referenced by put().

std::string PreMixingSiStripWorker::geometryType
private

Definition at line 108 of file PreMixingSiStripWorker.cc.

Referenced by initializeEvent().

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

Definition at line 122 of file PreMixingSiStripWorker.cc.

Referenced by DMinitializeDetUnit().

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

Definition at line 114 of file PreMixingSiStripWorker.cc.

Referenced by initializeEvent(), and put().

bool PreMixingSiStripWorker::peakMode
private

Definition at line 103 of file PreMixingSiStripWorker.cc.

signalMaps PreMixingSiStripWorker::signals_
private

Definition at line 92 of file PreMixingSiStripWorker.cc.

Referenced by getSignal(), and put().

SiGlobalIndex PreMixingSiStripWorker::SiHitStorage_
private

Definition at line 77 of file PreMixingSiStripWorker.cc.

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

bool PreMixingSiStripWorker::SingleStripNoise
private

Definition at line 102 of file PreMixingSiStripWorker.cc.

Referenced by put().

SiGlobalRawIndex PreMixingSiStripWorker::SiRawDigis_
private

Definition at line 78 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 97 of file PreMixingSiStripWorker.cc.

Referenced by addPileups(), and put().

double PreMixingSiStripWorker::theElectronPerADC
private

Definition at line 105 of file PreMixingSiStripWorker.cc.

Referenced by put().

int PreMixingSiStripWorker::theFedAlgo
private

Definition at line 107 of file PreMixingSiStripWorker.cc.

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

Definition at line 112 of file PreMixingSiStripWorker.cc.

Referenced by put().

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

Definition at line 110 of file PreMixingSiStripWorker.cc.

Referenced by PreMixingSiStripWorker(), and put().

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

Definition at line 111 of file PreMixingSiStripWorker.cc.

Referenced by put().

double PreMixingSiStripWorker::theThreshold
private

Definition at line 104 of file PreMixingSiStripWorker.cc.

Referenced by PreMixingSiStripWorker().