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 
56  edm::EDGetTokenT<edm::DetSetVector<PixelDigi> > PixelDigiToken_ ; // Token to retrieve information
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> OneDetectorMap; // maps by pixel ID for later combination - can have duplicate pixels
71  typedef std::map<uint32_t, OneDetectorMap> SiGlobalIndex; // map to all data for each detector ID
72 
73  SiGlobalIndex SiHitStorage_;
74 
76 
77  bool firstInitializeEvent_ = true;
78  bool firstFinalizeEvent_ = true;
79 };
80 
81 // Constructor
83  digitizer_(ps),
84  geometryType_(ps.getParameter<std::string>("PixGeometryType"))
85 {
86  // declare the products to produce
87 
88  pixeldigi_collectionSig_ = ps.getParameter<edm::InputTag>("pixeldigiCollectionSig");
89  pixeldigi_collectionPile_ = ps.getParameter<edm::InputTag>("pixeldigiCollectionPile");
90  PixelDigiCollectionDM_ = ps.getParameter<std::string>("PixelDigiCollectionDM");
91 
94 
96 
97  // clear local storage for this event
98  SiHitStorage_.clear();
99 }
100 
101 // Need an event initialization
102 
106  digitizer_.init(iSetup);
107  firstInitializeEvent_ = false;
108  }
110 }
111 
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 
123  //loop on all detsets (detectorIDs) inside the input collection
124  edm::DetSetVector<PixelDigi>::const_iterator DSViter=input->begin();
125  for (; DSViter!=input->end();DSViter++){
126 
127 #ifdef DEBUG
128  LogDebug("PreMixingSiPixelWorker") << "Processing DetID " << DSViter->id;
129 #endif
130 
131  uint32_t detID = DSViter->id;
135 
136  OneDetectorMap LocalMap;
137 
138  for (icopy=begin; icopy!=end; icopy++) {
139  LocalMap.insert(OneDetectorMap::value_type( (icopy->channel()), *icopy ));
140  }
141 
142  SiHitStorage_.insert( SiGlobalIndex::value_type( detID, LocalMap ) );
143  }
144 
145  }
146 } // end of addSiPixelSignals
147 
148 
149 
151 
152  LogDebug("PreMixingSiPixelWorker") <<"\n===============> adding pileups from event "<<pep.principal().id()<<" for bunchcrossing "<<pep.bunchCrossing();
153 
154  // fill in maps of hits; same code as addSignals, except now applied to the pileup events
155 
157  pep.getByLabel(pixeldigi_collectionPile_, inputHandle);
158 
159  if(inputHandle.isValid()) {
160  const auto& input = *inputHandle;
161 
162  //loop on all detsets (detectorIDs) inside the input collection
164  for (; DSViter!=input.end();DSViter++){
165 
166 #ifdef DEBUG
167  LogDebug("PreMixingSiPixelWorker") << "Pileups: Processing DetID " << DSViter->id;
168 #endif
169 
170  uint32_t detID = DSViter->id;
174 
175  // find correct local map (or new one) for this detector ID
176 
177  SiGlobalIndex::const_iterator itest;
178 
179  itest = SiHitStorage_.find(detID);
180 
181  if(itest!=SiHitStorage_.end()) { // this detID already has hits, add to existing map
182 
183  OneDetectorMap LocalMap = itest->second;
184 
185  // fill in local map with extra channels
186  for (icopy=begin; icopy!=end; icopy++) {
187  LocalMap.insert(OneDetectorMap::value_type( (icopy->channel()), *icopy ));
188  }
189 
190  SiHitStorage_[detID]=LocalMap;
191 
192  }
193  else{ // fill local storage with this information, put in global collection
194 
195  OneDetectorMap LocalMap;
196 
197  for (icopy=begin; icopy!=end; icopy++) {
198  LocalMap.insert(OneDetectorMap::value_type( (icopy->channel()), *icopy ));
199  }
200 
201  SiHitStorage_.insert( SiGlobalIndex::value_type( detID, LocalMap ) );
202  }
203 
204  }
205  }
206 }
207 
208 
209 
210 void PreMixingSiPixelWorker::put(edm::Event &e, edm::EventSetup const& iSetup, std::vector<PileupSummaryInfo> const& ps, int bs) {
211 
212  // collection of Digis to put in the event
213 
214  std::vector< edm::DetSet<PixelDigi> > vPixelDigi;
215 
216  // loop through our collection of detectors, merging hits and putting new ones in the output
217  signalMaps signal;
218 
219  // big loop over Detector IDs:
220 
221  for(SiGlobalIndex::const_iterator IDet = SiHitStorage_.begin();
222  IDet != SiHitStorage_.end(); IDet++) {
223 
224  uint32_t detID = IDet->first;
225 
226  OneDetectorMap LocalMap = IDet->second;
227 
228  signal_map_type Signals;
229  Signals.clear();
230 
231  //counter variables
232  int formerPixel = -1;
233  int currentPixel;
234  int ADCSum = 0;
235 
236 
237  OneDetectorMap::const_iterator iLocalchk;
238 
239  for(OneDetectorMap::const_iterator iLocal = LocalMap.begin();
240  iLocal != LocalMap.end(); ++iLocal) {
241 
242  currentPixel = iLocal->first;
243 
244  if (currentPixel == formerPixel) { // we have to add these digis together
245  ADCSum+=(iLocal->second).adc();
246  }
247  else{
248  if(formerPixel!=-1){ // ADC info stolen from SiStrips...
249  if (ADCSum > 511) ADCSum = 255;
250  else if (ADCSum > 253 && ADCSum < 512) ADCSum = 254;
251 
252  Signals.insert( std::make_pair(formerPixel, ADCSum));
253  }
254  // save pointers for next iteration
255  formerPixel = currentPixel;
256  ADCSum = (iLocal->second).adc();
257  }
258 
259  iLocalchk = iLocal;
260  if((++iLocalchk) == LocalMap.end()) { //make sure not to lose the last one
261  if (ADCSum > 511) ADCSum = 255;
262  else if (ADCSum > 253 && ADCSum < 512) ADCSum = 254;
263  Signals.insert( std::make_pair(formerPixel, ADCSum));
264  }
265 
266  }// end of loop over one detector
267 
268  // stick this into the global vector of detector info
269  signal.insert( std::make_pair( detID, Signals));
270 
271  } // end of big loop over all detector IDs
272 
273  // put the collection of digis in the event
274  edm::LogInfo("PreMixingSiPixelWorker") << "total # Merged Pixels: " << signal.size() ;
275 
276 
277  std::vector<edm::DetSet<PixelDigi> > theDigiVector;
278 
279  // Load inefficiency constants (1st pass), set pileup information.
280  if(firstFinalizeEvent_) {
281  digitizer_.init_DynIneffDB(iSetup, bs);
282  firstFinalizeEvent_ = false;
283  }
284 
287 
289  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
290 
292  iSetup.get<TrackerTopologyRcd>().get(tTopoHand);
293  const TrackerTopology *tTopo=tTopoHand.product();
294 
295  for(const auto& iu : pDD->detUnits()) {
296  if(iu->type().isTrackerPixel()) {
297  edm::DetSet<PixelDigi> collector(iu->geographicalId().rawId());
298  edm::DetSet<PixelDigiSimLink> linkcollector(iu->geographicalId().rawId()); // ignored as DigiSimLinks are combined separately
299 
300  digitizer_.digitize(dynamic_cast<const PixelGeomDetUnit *>(iu),
301  collector.data,
302  linkcollector.data,
303  tTopo,
304  engine);
305  if(!collector.data.empty()) {
306  theDigiVector.push_back(std::move(collector));
307  }
308  }
309  }
310 
311  e.put(std::make_unique<edm::DetSetVector<PixelDigi> >(theDigiVector), PixelDigiCollectionDM_);
312 
313  // clear local storage for this event
314  SiHitStorage_.clear();
315 }
316 
int adc(sample_type sample)
get the ADC sample (12 bits)
#define LogDebug(id)
BranchAliasSetterT< ProductType > produces()
declare what type of product will make and with which optional label
void init(const edm::EventSetup &es)
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
void init_DynIneffDB(const edm::EventSetup &, const unsigned int &)
void put(edm::Event &e, edm::EventSetup const &iSetup, std::vector< PileupSummaryInfo > const &ps, int bs) override
std::multimap< int, PixelDigi > OneDetectorMap
edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > PixelDigiPToken_
void addPileups(PileUpEventPrincipal const &, edm::EventSetup const &es) override
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
EventID const & id() const
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
static std::string const input
Definition: EdmProvDump.cc:44
edm::EventPrincipal const & principal()
~PreMixingSiPixelWorker() override=default
edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > PixelDigiToken_
SiPixelDigitizerAlgorithm digitizer_
void digitize(const PixelGeomDetUnit *pixdet, std::vector< PixelDigi > &digis, std::vector< PixelDigiSimLink > &simlinks, const TrackerTopology *tTopo, CLHEP::HepRandomEngine *)
#define end
Definition: vmac.h:39
bool isValid() const
Definition: HandleBase.h:74
void addSignals(edm::Event const &e, edm::EventSetup const &es) override
void setSimAccumulator(const std::map< uint32_t, std::map< int, int > > &signalMap)
void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override
void calculateInstlumiFactor(PileupMixingContent *puInfo)
std::map< uint32_t, signal_map_type > signalMaps
edm::EventID id() const
Definition: EventBase.h:60
#define begin
Definition: vmac.h:32
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
T get() const
Definition: EventSetup.h:63
edm::ESHandle< TrackerGeometry > pDD
StreamID streamID() const
Definition: Event.h:96
std::map< int, Amplitude, std::less< int > > signal_map_type
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:104
#define DEFINE_PREMIXING_WORKER(TYPE)
T const * product() const
Definition: ESHandle.h:86
PreMixingSiPixelWorker(const edm::ParameterSet &ps, edm::ProducerBase &producer, edm::ConsumesCollector &&iC)
def move(src, dest)
Definition: eostools.py:510
std::map< uint32_t, OneDetectorMap > SiGlobalIndex