CMS 3D CMS Logo

PreMixingSiPixelWorker.cc
Go to the documentation of this file.
11 
12 //Data Formats
18 
22 
30 
31 #include "CLHEP/Random/RandFlat.h"
32 
35 
37 
38 #include <map>
39 #include <memory>
40 
42 public:
44  ~PreMixingSiPixelWorker() override = default;
45 
46  void initializeEvent(edm::Event const& e, edm::EventSetup const& c) override;
47  void addSignals(edm::Event const& e, edm::EventSetup const& es) override;
48  void addPileups(PileUpEventPrincipal const&, edm::EventSetup const& es) override;
49  void put(edm::Event& e, edm::EventSetup const& iSetup, std::vector<PileupSummaryInfo> const& ps, int bs) override;
50 
51 private:
52  edm::InputTag pixeldigi_collectionSig_; // secondary name given to collection of SiPixel digis
53  edm::InputTag pixeldigi_collectionPile_; // secondary name given to collection of SiPixel digis
54  std::string PixelDigiCollectionDM_; // secondary name to be given to new SiPixel digis
55 
58 
60 
62 
63  //
64  // Internal typedefs
65 
66  typedef int Amplitude;
67  typedef std::map<int, Amplitude, std::less<int>> signal_map_type; // from Digi.Skel.
68  typedef std::map<uint32_t, signal_map_type> signalMaps;
69 
70  typedef std::multimap<int, PixelDigi>
71  OneDetectorMap; // maps by pixel ID for later combination - can have duplicate pixels
72  typedef std::map<uint32_t, OneDetectorMap> SiGlobalIndex; // map to all data for each detector ID
73 
75 
77 
78  bool firstInitializeEvent_ = true;
79  bool firstFinalizeEvent_ = true;
80 };
81 
82 // Constructor
84  edm::ProducesCollector producesCollector,
86  : digitizer_(ps), geometryType_(ps.getParameter<std::string>("PixGeometryType")) {
87  // declare the products to produce
88 
89  pixeldigi_collectionSig_ = ps.getParameter<edm::InputTag>("pixeldigiCollectionSig");
90  pixeldigi_collectionPile_ = ps.getParameter<edm::InputTag>("pixeldigiCollectionPile");
91  PixelDigiCollectionDM_ = ps.getParameter<std::string>("PixelDigiCollectionDM");
92 
95 
98 
99  // clear local storage for this event
100  SiHitStorage_.clear();
101 }
102 
103 // Need an event initialization
104 
107  if (firstInitializeEvent_) {
108  digitizer_.init(iSetup);
109  firstInitializeEvent_ = false;
110  }
112 }
113 
115  // fill in maps of hits
116 
117  LogDebug("PreMixingSiPixelWorker") << "===============> adding MC signals for " << e.id();
118 
120 
121  if (e.getByToken(PixelDigiToken_, input)) {
122  //loop on all detsets (detectorIDs) inside the input collection
124  for (; DSViter != input->end(); DSViter++) {
125 #ifdef DEBUG
126  LogDebug("PreMixingSiPixelWorker") << "Processing DetID " << DSViter->id;
127 #endif
128 
129  uint32_t detID = DSViter->id;
130  edm::DetSet<PixelDigi>::const_iterator begin = (DSViter->data).begin();
131  edm::DetSet<PixelDigi>::const_iterator end = (DSViter->data).end();
133 
134  OneDetectorMap LocalMap;
135 
136  for (icopy = begin; icopy != end; icopy++) {
137  LocalMap.insert(OneDetectorMap::value_type((icopy->channel()), *icopy));
138  }
139 
140  SiHitStorage_.insert(SiGlobalIndex::value_type(detID, LocalMap));
141  }
142  }
143 } // end of addSiPixelSignals
144 
146  LogDebug("PreMixingSiPixelWorker") << "\n===============> adding pileups from event " << pep.principal().id()
147  << " for bunchcrossing " << pep.bunchCrossing();
148 
149  // fill in maps of hits; same code as addSignals, except now applied to the pileup events
150 
152  pep.getByLabel(pixeldigi_collectionPile_, inputHandle);
153 
154  if (inputHandle.isValid()) {
155  const auto& input = *inputHandle;
156 
157  //loop on all detsets (detectorIDs) inside the input collection
159  for (; DSViter != input.end(); DSViter++) {
160 #ifdef DEBUG
161  LogDebug("PreMixingSiPixelWorker") << "Pileups: Processing DetID " << DSViter->id;
162 #endif
163 
164  uint32_t detID = DSViter->id;
165  edm::DetSet<PixelDigi>::const_iterator begin = (DSViter->data).begin();
166  edm::DetSet<PixelDigi>::const_iterator end = (DSViter->data).end();
168 
169  // find correct local map (or new one) for this detector ID
170 
171  SiGlobalIndex::const_iterator itest;
172 
173  itest = SiHitStorage_.find(detID);
174 
175  if (itest != SiHitStorage_.end()) { // this detID already has hits, add to existing map
176 
177  OneDetectorMap LocalMap = itest->second;
178 
179  // fill in local map with extra channels
180  for (icopy = begin; icopy != end; icopy++) {
181  LocalMap.insert(OneDetectorMap::value_type((icopy->channel()), *icopy));
182  }
183 
184  SiHitStorage_[detID] = LocalMap;
185 
186  } else { // fill local storage with this information, put in global collection
187 
188  OneDetectorMap LocalMap;
189 
190  for (icopy = begin; icopy != end; icopy++) {
191  LocalMap.insert(OneDetectorMap::value_type((icopy->channel()), *icopy));
192  }
193 
194  SiHitStorage_.insert(SiGlobalIndex::value_type(detID, LocalMap));
195  }
196  }
197  }
198 }
199 
201  edm::EventSetup const& iSetup,
202  std::vector<PileupSummaryInfo> const& ps,
203  int bs) {
204  // collection of Digis to put in the event
205 
206  std::vector<edm::DetSet<PixelDigi>> vPixelDigi;
207 
208  // loop through our collection of detectors, merging hits and putting new ones in the output
209  signalMaps signal;
210 
211  // big loop over Detector IDs:
212 
213  for (SiGlobalIndex::const_iterator IDet = SiHitStorage_.begin(); IDet != SiHitStorage_.end(); IDet++) {
214  uint32_t detID = IDet->first;
215 
216  OneDetectorMap LocalMap = IDet->second;
217 
218  signal_map_type Signals;
219  Signals.clear();
220 
221  //counter variables
222  int formerPixel = -1;
223  int currentPixel;
224  int ADCSum = 0;
225 
226  OneDetectorMap::const_iterator iLocalchk;
227 
228  for (OneDetectorMap::const_iterator iLocal = LocalMap.begin(); iLocal != LocalMap.end(); ++iLocal) {
229  currentPixel = iLocal->first;
230 
231  if (currentPixel == formerPixel) { // we have to add these digis together
232  ADCSum += (iLocal->second).adc();
233  } else {
234  if (formerPixel != -1) { // ADC info stolen from SiStrips...
235  if (ADCSum > 511)
236  ADCSum = 255;
237  else if (ADCSum > 253 && ADCSum < 512)
238  ADCSum = 254;
239 
240  Signals.insert(std::make_pair(formerPixel, ADCSum));
241  }
242  // save pointers for next iteration
243  formerPixel = currentPixel;
244  ADCSum = (iLocal->second).adc();
245  }
246 
247  iLocalchk = iLocal;
248  if ((++iLocalchk) == LocalMap.end()) { //make sure not to lose the last one
249  if (ADCSum > 511)
250  ADCSum = 255;
251  else if (ADCSum > 253 && ADCSum < 512)
252  ADCSum = 254;
253  Signals.insert(std::make_pair(formerPixel, ADCSum));
254  }
255 
256  } // end of loop over one detector
257 
258  // stick this into the global vector of detector info
259  signal.insert(std::make_pair(detID, Signals));
260 
261  } // end of big loop over all detector IDs
262 
263  // put the collection of digis in the event
264  edm::LogInfo("PreMixingSiPixelWorker") << "total # Merged Pixels: " << signal.size();
265 
266  std::vector<edm::DetSet<PixelDigi>> theDigiVector;
267 
268  // Load inefficiency constants (1st pass), set pileup information.
269  if (firstFinalizeEvent_) {
270  digitizer_.init_DynIneffDB(iSetup, bs);
271  firstFinalizeEvent_ = false;
272  }
273 
276 
278  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
279 
281  iSetup.get<TrackerTopologyRcd>().get(tTopoHand);
282  const TrackerTopology* tTopo = tTopoHand.product();
283 
285  std::unique_ptr<PixelFEDChannelCollection> PixelFEDChannelCollection_ = digitizer_.chooseScenario(ps, engine);
286  if (PixelFEDChannelCollection_ == nullptr) {
287  throw cms::Exception("NullPointerError") << "PixelFEDChannelCollection not set in chooseScenario function.\n";
288  }
289  e.put(std::move(PixelFEDChannelCollection_), PixelDigiCollectionDM_);
290  }
291 
292  for (const auto& iu : pDD->detUnits()) {
293  if (iu->type().isTrackerPixel()) {
294  edm::DetSet<PixelDigi> collector(iu->geographicalId().rawId());
295  edm::DetSet<PixelDigiSimLink> linkcollector(
296  iu->geographicalId().rawId()); // ignored as DigiSimLinks are combined separately
297 
298  digitizer_.digitize(dynamic_cast<const PixelGeomDetUnit*>(iu), collector.data, linkcollector.data, tTopo, engine);
299  if (!collector.data.empty()) {
300  theDigiVector.push_back(std::move(collector));
301  }
302  }
303  }
304 
305  e.put(std::make_unique<edm::DetSetVector<PixelDigi>>(theDigiVector), PixelDigiCollectionDM_);
306 
307  // clear local storage for this event
308  SiHitStorage_.clear();
309 }
310 
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
edm::DetSetVector
Definition: DetSetVector.h:61
PreMixingSiPixelWorker::digitizer_
SiPixelDigitizerAlgorithm digitizer_
Definition: PreMixingSiPixelWorker.cc:61
edm::RandomNumberGenerator::getEngine
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
Handle.h
PileupSummaryInfo.h
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
PreMixingSiPixelWorker::PreMixingSiPixelWorker
PreMixingSiPixelWorker(const edm::ParameterSet &ps, edm::ProducesCollector, edm::ConsumesCollector &&iC)
Definition: PreMixingSiPixelWorker.cc:83
TrackerGeometry.h
PixelTopology.h
ESHandle.h
SiPixelDigitizerAlgorithm::killBadFEDChannels
bool killBadFEDChannels() const
Definition: SiPixelDigitizerAlgorithm.cc:877
SiPixelDigitizerAlgorithm
Definition: SiPixelDigitizerAlgorithm.h:55
edm::DetSet
Definition: DetSet.h:23
edm::EDGetTokenT
Definition: EDGetToken.h:33
RandomNumberGenerator.h
TrackerTopology
Definition: TrackerTopology.h:16
PreMixingSiPixelWorker::~PreMixingSiPixelWorker
~PreMixingSiPixelWorker() override=default
PreMixingSiPixelWorker::geometryType_
const std::string geometryType_
Definition: PreMixingSiPixelWorker.cc:76
GeomDetType.h
PileUpEventPrincipal::bunchCrossing
int bunchCrossing() const
Definition: PileUpEventPrincipal.h:30
PileUpEventPrincipal
Definition: PileUpEventPrincipal.h:19
PixelDigi.h
PreMixingSiPixelWorker::signalMaps
std::map< uint32_t, signal_map_type > signalMaps
Definition: PreMixingSiPixelWorker.cc:68
PreMixingSiPixelWorker::Amplitude
int Amplitude
Definition: PreMixingSiPixelWorker.cc:66
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Handle
Definition: AssociativeIterator.h:50
edm::EventPrincipal::id
EventID const & id() const
Definition: EventPrincipal.h:92
ProducesCollector.h
ecalLiteDTU::adc
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
Definition: EcalLiteDTUSample.h:12
TrackerTopology.h
cms::cuda::bs
bs
Definition: HistoContainer.h:127
PreMixingSiPixelWorker::addSignals
void addSignals(edm::Event const &e, edm::EventSetup const &es) override
Definition: PreMixingSiPixelWorker.cc:114
PreMixingSiPixelWorker::pDD
edm::ESHandle< TrackerGeometry > pDD
Definition: PreMixingSiPixelWorker.cc:59
SiPixelDigitizerAlgorithm::init
void init(const edm::EventSetup &es)
Definition: SiPixelDigitizerAlgorithm.cc:116
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
TrackerGeometry::detUnits
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
Definition: TrackerGeometry.h:61
PreMixingWorker.h
Service.h
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
PreMixingSiPixelWorker::pixeldigi_collectionSig_
edm::InputTag pixeldigi_collectionSig_
Definition: PreMixingSiPixelWorker.cc:52
mps_fire.end
end
Definition: mps_fire.py:242
PileUpEventPrincipal::principal
edm::EventPrincipal const & principal()
Definition: PileUpEventPrincipal.h:24
edm::ESHandle< TrackerGeometry >
PileUpEventPrincipal.h
SiPixelDigitizerAlgorithm::chooseScenario
std::unique_ptr< PixelFEDChannelCollection > chooseScenario(PileupMixingContent *puInfo, CLHEP::HepRandomEngine *)
Definition: SiPixelDigitizerAlgorithm.cc:926
PixelGeomDetType.h
PreMixingSiPixelWorker::addPileups
void addPileups(PileUpEventPrincipal const &, edm::EventSetup const &es) override
Definition: PreMixingSiPixelWorker.cc:145
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PreMixingSiPixelWorker::initializeEvent
void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override
Definition: PreMixingSiPixelWorker.cc:105
TrackerDigiGeometryRecord.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
SiPixelDigitizerAlgorithm::calculateInstlumiFactor
void calculateInstlumiFactor(PileupMixingContent *puInfo)
Definition: SiPixelDigitizerAlgorithm.cc:814
Event.h
PreMixingSiPixelWorker::PixelDigiPToken_
edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > PixelDigiPToken_
Definition: PreMixingSiPixelWorker.cc:57
PreMixingSiPixelWorker::firstInitializeEvent_
bool firstInitializeEvent_
Definition: PreMixingSiPixelWorker.cc:78
edm::DetSetVector::const_iterator
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
edm::Service< edm::RandomNumberGenerator >
edm::ProducesCollector::produces
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
Definition: ProducesCollector.h:52
PreMixingSiPixelWorker::firstFinalizeEvent_
bool firstFinalizeEvent_
Definition: PreMixingSiPixelWorker.cc:79
edm::EventSetup
Definition: EventSetup.h:57
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
DetSetVector.h
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
get
#define get
PreMixingSiPixelWorker::PixelDigiToken_
edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > PixelDigiToken_
Definition: PreMixingSiPixelWorker.cc:56
PreMixingSiPixelWorker::signal_map_type
std::map< int, Amplitude, std::less< int > > signal_map_type
Definition: PreMixingSiPixelWorker.cc:67
PixelIndices.h
PreMixingWorkerFactory.h
GeomDet.h
edmNew::DetSetVector
Definition: DetSetNew.h:13
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::ProducesCollector
Definition: ProducesCollector.h:43
PreMixingSiPixelWorker::SiHitStorage_
SiGlobalIndex SiHitStorage_
Definition: PreMixingSiPixelWorker.cc:74
Exception
Definition: hltDiff.cc:246
DEFINE_PREMIXING_WORKER
#define DEFINE_PREMIXING_WORKER(TYPE)
Definition: PreMixingWorkerFactory.h:16
PixelGeomDetUnit.h
PreMixingSiPixelWorker::pixeldigi_collectionPile_
edm::InputTag pixeldigi_collectionPile_
Definition: PreMixingSiPixelWorker.cc:53
PreMixingSiPixelWorker::SiGlobalIndex
std::map< uint32_t, OneDetectorMap > SiGlobalIndex
Definition: PreMixingSiPixelWorker.cc:72
PreMixingSiPixelWorker::put
void put(edm::Event &e, edm::EventSetup const &iSetup, std::vector< PileupSummaryInfo > const &ps, int bs) override
Definition: PreMixingSiPixelWorker.cc:200
PreMixingSiPixelWorker::OneDetectorMap
std::multimap< int, PixelDigi > OneDetectorMap
Definition: PreMixingSiPixelWorker.cc:71
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
PreMixingWorker
Definition: PreMixingWorker.h:14
PreMixingSiPixelWorker::PixelDigiCollectionDM_
std::string PixelDigiCollectionDM_
Definition: PreMixingSiPixelWorker.cc:54
DetSet.h
ConsumesCollector.h
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
SiPixelDigitizerAlgorithm::setSimAccumulator
void setSimAccumulator(const std::map< uint32_t, std::map< int, int > > &signalMap)
Definition: SiPixelDigitizerAlgorithm.cc:971
ParameterSet.h
PileUpEventPrincipal::getByLabel
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
Definition: PileUpEventPrincipal.h:33
PreMixingSiPixelWorker
Definition: PreMixingSiPixelWorker.cc:41
SiPixelDigitizerAlgorithm.h
SiPixelDigitizerAlgorithm::digitize
void digitize(const PixelGeomDetUnit *pixdet, std::vector< PixelDigi > &digis, std::vector< PixelDigiSimLink > &simlinks, const TrackerTopology *tTopo, CLHEP::HepRandomEngine *)
Definition: SiPixelDigitizerAlgorithm.cc:982
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
SiPixelDigitizerAlgorithm::init_DynIneffDB
void init_DynIneffDB(const edm::EventSetup &, const unsigned int &)
Definition: SiPixelDigitizerAlgorithm.cc:587
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
SiPixelDigitizerAlgorithm::initializeEvent
void initializeEvent()
Definition: SiPixelDigitizerAlgorithm.h:63
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
edm::DetSet::const_iterator
collection_type::const_iterator const_iterator
Definition: DetSet.h:31