20 #include "CLHEP/Random/RandFlat.h" 31 DataMixingSiStripMCDigiWorker::DataMixingSiStripMCDigiWorker() { }
36 label_(ps.getParameter<
std::
string>(
"Label")),
37 gainLabel(ps.getParameter<
std::
string>(
"Gain")),
39 peakMode(ps.getParameter<bool>(
"APVpeakmode")),
40 theThreshold(ps.getParameter<double>(
"NoiseSigmaThreshold")),
41 theElectronPerADC(ps.getParameter<double>( peakMode ?
"electronPerAdcPeak" :
"electronPerAdcDec" )),
42 APVSaturationFromHIP_(ps.getParameter<bool>(
"APVSaturationFromHIP")),
43 theFedAlgo(ps.getParameter<
int>(
"FedAlgorithm_PM")),
44 geometryType(ps.getParameter<
std::
string>(
"GeometryType")),
74 <<
"SiStripDigitizer requires the RandomNumberGeneratorService\n" 75 "which is not present in the psiguration file. You must add the service\n" 76 "in the configuration file or remove the modules that require it.";
97 unsigned int detId = (*iu)->geographicalId().rawId();
106 assert(stripdet != 0);
126 badChannels.insert(badChannels.begin(), numStrips,
false);
128 hipChannels.insert(hipChannels.begin(), numStrips,
false);
149 for (; DSViter!=input->end();DSViter++){
152 LogDebug(
"DataMixingSiStripMCDigiWorker") <<
"Processing DetID " << DSViter->id;
156 LocalMap.
reserve((DSViter->data).size());
157 LocalMap.insert(LocalMap.end(),(DSViter->data).
begin(),(DSViter->data).
end());
183 LogDebug(
"DataMixingSiStripMCDigiWorker") <<
"\n===============> adding pileups from event "<<ep->
id()<<
" for bunchcrossing "<<bcr;
187 std::shared_ptr<Wrapper<edm::DetSetVector<SiStripDigi> >
const> inputPTR =
202 for (; DSViter!=input->
end();DSViter++){
205 LogDebug(
"DataMixingSiStripMCDigiWorker") <<
"Pileups: Processing DetID " << DSViter->id;
210 SiGlobalIndex::const_iterator itest;
216 LocalMap = itest->second;
227 LocalMap.
reserve((DSViter->data).size());
235 std::shared_ptr<Wrapper<std::vector<std::pair<int,std::bitset<6>> > >
const> inputAPVPTR =
240 const std::vector<std::pair<int,std::bitset<6>> > *APVinput =
const_cast< std::vector<std::pair<int,std::bitset<6>
> > * >(inputAPVPTR->product());
242 std::vector<std::pair<int,std::bitset<6>> >::const_iterator
entry = APVinput->begin();
243 for( ; entry != APVinput->end(); entry++) {
269 std::map< int,std::bitset<6>> DeadAPVList;
293 for(SiGlobalIndex::const_iterator IDet =
SiHitStorage_.begin();
296 uint32_t detID = IDet->first;
304 OneDetectorMap::const_iterator iLocal = LocalMap.begin();
305 for(;iLocal != LocalMap.end(); ++iLocal) {
307 uint16_t currentStrip = iLocal->strip();
308 float signal =
float(iLocal->adc());
309 if(iLocal->adc() == 1022) signal = 1500.;
310 if(iLocal->adc() == 1023) signal = 3000.;
314 float ReSignal = signal*signal/9.0;
316 RawDigi NewRawDigi = std::make_pair(currentStrip,ReSignal);
318 LocalRawMap.push_back(NewRawDigi);
328 int NumberOfBxBetweenHIPandEvent=1e3;
334 bool HasAtleastOneAffectedAPV=
false;
335 while(!HasAtleastOneAffectedAPV){
336 for(
int bx=floor(300.0/25.0);bx>0;bx--){
337 float temp=CLHEP::RandFlat::shoot(engine)<0.5?1:0;
338 if(temp==1 && bx<NumberOfBxBetweenHIPandEvent){
339 NumberOfBxBetweenHIPandEvent=bx;
340 HasAtleastOneAffectedAPV=
true;
345 APVMap::const_iterator iAPVchk;
346 uint32_t formerID = 0;
348 std::bitset<6> NewAPVBits;
353 currentID = iAPV->first;
355 if (currentID == formerID) {
356 for(
int ibit=0; ibit<6; ++ibit){
357 NewAPVBits[ibit] = NewAPVBits[ibit]||(iAPV->second)[ibit];
361 DeadAPVList[currentID]=NewAPVBits;
363 formerID = currentID;
364 NewAPVBits = iAPV->second;
369 DeadAPVList[currentID]=NewAPVBits;
379 std::vector< edm::DetSet<SiStripDigi> > vSiStripDigi;
388 for(SiGlobalRawIndex::const_iterator IDet =
SiRawDigis_.begin();
391 uint32_t detID = IDet->first;
399 int formerStrip = -1;
405 OneDetectorRawMap::const_iterator iLocalchk;
406 OneDetectorRawMap::const_iterator iLocal = LocalMap.begin();
407 for(;iLocal != LocalMap.end(); ++iLocal) {
409 currentStrip = iLocal->first;
411 if (currentStrip == formerStrip) {
413 ADCSum+=iLocal->second ;
417 Signals.insert( std::make_pair(formerStrip, ADCSum));
420 formerStrip = currentStrip;
421 ADCSum = iLocal->second;
425 if((++iLocalchk) == LocalMap.end()) {
426 Signals.insert( std::make_pair(formerStrip, ADCSum));
430 signals_.insert( std::make_pair( detID, Signals));
436 for(TrackingGeometry::DetUnitContainer::const_iterator iu =
pDD->
detUnits().begin(); iu !=
pDD->
detUnits().end(); iu ++){
451 std::vector<float> detAmpl(numStrips, 0.);
453 for(
const auto& amp : *theSignal) {
454 detAmpl[amp.first] = amp.second;
466 std::bitset<6> & bs=DeadAPVList[detID];
471 float Shift=1-NumberOfBxBetweenHIPandEvent/floor(300.0/25.0);
472 float randomX=CLHEP::RandFlat::shoot(engine);
473 float scalingValue=(randomX-Shift)*10.0/7.0-3.0/7.0;
477 detAmpl[
strip] *=scalingValue>0?scalingValue:0.0;
506 size_t firstChannelWithSignal = 0;
507 size_t lastChannelWithSignal = numStrips;
511 std::vector<float> noiseRMSv;
513 noiseRMSv.insert(noiseRMSv.begin(),numStrips,0.);
515 if(!badChannels[
strip]){
516 float gainValue = gainHandle->
getStripGain(strip, detGainRange);
523 int RefStrip =
int(numStrips/2.);
524 while(RefStrip<numStrips&&badChannels[RefStrip]){
527 if(RefStrip<numStrips){
528 float RefgainValue = gainHandle->
getStripGain(RefStrip, detGainRange);
531 theSiNoiseAdder->addNoise(detAmpl,firstChannelWithSignal,lastChannelWithSignal,numStrips,RefnoiseRMS, engine);
548 vSiStripDigi.push_back(SSD);
555 LogInfo(
"DataMixingSiStripMCDigiWorker") <<
"total # Merged strips: " << vSiStripDigi.size() ;
T getParameter(std::string const &) const
void addSiStripSignals(const edm::Event &e)
std::map< unsigned int, size_t > firstChannelsWithSignal
std::map< unsigned int, std::vector< bool > > allHIPChannels
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
edm::InputTag SiStripPileInputTag_
std::map< int, Amplitude > SignalMapType
std::vector< RawDigi > OneDetectorRawMap
std::vector< unsigned int >::const_iterator ContainerIterator
edm::ESHandle< TrackerGeometry > pDD
SiGlobalIndex SiHitStorage_
std::pair< uint16_t, Amplitude > RawDigi
EventID const & id() const
virtual void initializeEvent(const edm::Event &e, edm::EventSetup const &iSetup)
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.
edm::InputTag SistripLabelSig_
virtual ~DataMixingSiStripMCDigiWorker()
static std::string const input
SiDigitalConverter::DigitalVecType DigitalVecType
uint32_t rawId() const
get the raw id
static float getNoise(uint16_t strip, const Range &range)
Container::value_type value_type
static float getStripGain(const uint16_t &strip, const SiStripApvGain::Range &range)
void addSiStripPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId, ModuleCallingContext const *)
std::pair< ContainerIterator, ContainerIterator > Range
void DMinitializeDetUnit(StripGeomDetUnit const *det, const edm::EventSetup &iSetup)
DetId geographicalId() const
The label of this GeomDet.
APVMap theAffectedAPVmap_
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
std::unique_ptr< SiGaussianTailNoiseAdder > theSiNoiseAdder
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
iterator end()
Return the off-the-end iterator.
std::string SistripAPVListDM_
unsigned short firstStrip
const SignalMapType * getSignal(uint32_t detID) const
edm::InputTag SistripAPVLabelSig_
edm::InputTag SiStripAPVPileInputTag_
void insert(detset const &s)
Insert the given DetSet.
bool APVSaturationFromHIP_
std::map< unsigned int, std::vector< bool > > allBadChannels
const Range getRange(const uint32_t detID) const
const Range getRange(const uint32_t detID) const
std::pair< ContainerIterator, ContainerIterator > Range
std::unique_ptr< SiTrivialDigitalConverter > theSiDigitalConverter
StreamID streamID() const
std::unique_ptr< SiStripFedZeroSuppression > theSiZeroSuppress
iterator begin()
Return an iterator to the first DetSet.
std::map< unsigned int, size_t > lastChannelsWithSignal
std::pair< ContainerIterator, ContainerIterator > Range
void putSiStrip(edm::Event &e, edm::EventSetup const &iSetup)
collection_type::const_iterator const_iterator
SiGlobalRawIndex SiRawDigis_
const DetUnitContainer & detUnits() const override
Returm a vector of all GeomDetUnit.
data decode(const unsigned int &value) const
std::string SiStripDigiCollectionDM_
std::vector< SiStripDigi > OneDetectorMap
const SiStripApvGain::Range getRange(uint32_t detID) const