CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DataMixingMuonWorker.cc
Go to the documentation of this file.
1 // File: DataMixingMuonWorker.cc
2 // Description: see DataMixingMuonWorker.h
3 // Author: Mike Hildreth, University of Notre Dame
4 //
5 //--------------------------------------------
6 
9 #include <map>
10 #include <memory>
11 //
12 //
13 #include "DataMixingMuonWorker.h"
14 
15 using namespace std;
16 
17 namespace edm {
18 
19  // Virtual constructor
20 
21  DataMixingMuonWorker::DataMixingMuonWorker() {}
22 
23  // Constructor
24  DataMixingMuonWorker::DataMixingMuonWorker(const edm::ParameterSet &ps, edm::ConsumesCollector &&iC)
25  : label_(ps.getParameter<std::string>("Label"))
26 
27  {
28  // get the subdetector names
29  // this->getSubdetectorNames(); //something like this may be useful to
30  // check what we are supposed to do...
31 
32  // Declare the products to produce
33 
34  DTDigiTagSig_ = ps.getParameter<edm::InputTag>("DTDigiTagSig");
35  RPCDigiTagSig_ = ps.getParameter<edm::InputTag>("RPCDigiTagSig");
36 
37  CSCstripdigi_collectionSig_ = ps.getParameter<edm::InputTag>("CSCstripdigiCollectionSig");
38  CSCwiredigi_collectionSig_ = ps.getParameter<edm::InputTag>("CSCwiredigiCollectionSig");
39  CSCCompdigi_collectionSig_ = ps.getParameter<edm::InputTag>("CSCCompdigiCollectionSig");
40 
46 
47  DTPileInputTag_ = ps.getParameter<edm::InputTag>("DTPileInputTag");
48  RPCPileInputTag_ = ps.getParameter<edm::InputTag>("RPCPileInputTag");
49  CSCWirePileInputTag_ = ps.getParameter<edm::InputTag>("CSCWirePileInputTag");
50  CSCStripPileInputTag_ = ps.getParameter<edm::InputTag>("CSCStripPileInputTag");
51  CSCCompPileInputTag_ = ps.getParameter<edm::InputTag>("CSCCompPileInputTag");
52 
58 
59  // outputs:
60 
61  DTDigiCollectionDM_ = ps.getParameter<std::string>("DTDigiCollectionDM");
62  RPCDigiCollectionDM_ = ps.getParameter<std::string>("RPCDigiCollectionDM");
63  CSCStripDigiCollectionDM_ = ps.getParameter<std::string>("CSCStripDigiCollectionDM");
64  CSCWireDigiCollectionDM_ = ps.getParameter<std::string>("CSCWireDigiCollectionDM");
65  CSCComparatorDigiCollectionDM_ = ps.getParameter<std::string>("CSCComparatorDigiCollectionDM");
66  }
67 
68  // Virtual destructor needed.
70 
72  // fill in maps of hits
73 
74  LogDebug("DataMixingMuonWorker") << "===============> adding MC signals for " << e.id();
75 
76  // DT
77  //
78 
80  Handle<DTDigiCollection> pDTdigis;
81 
82  // Get the digis from the event
83  if (e.getByToken(DTDigiToken_, pDTdigis)) {
84  // LogInfo("DataMixingMuonWorker") << "total # DT Digis: " <<
85  // DTdigis->size();
86 
87  // Loop over digis, copying them to our own local storage
88  const DTDigiCollection *DTdigis = pDTdigis.product();
90  for (DLayerIt = DTdigis->begin(); DLayerIt != DTdigis->end(); ++DLayerIt) {
91  // The layerId
92  const DTLayerId &layerId = (*DLayerIt).first;
93 
94  // Get the iterators over the digis associated with this LayerId
95  const DTDigiCollection::Range &range = (*DLayerIt).second;
96 
97  OurDTDigis_->put(range, layerId);
98  }
99  }
100  // RPC
101  //
102 
104 
105  // Get the digis from the event
106  Handle<RPCDigiCollection> pRPCdigis;
107 
108  if (e.getByToken(RPCDigiToken_, pRPCdigis)) {
109  // Loop over digis, copying them to our own local storage
110 
111  const RPCDigiCollection *RPCdigis = pRPCdigis.product();
113  for (RLayerIt = RPCdigis->begin(); RLayerIt != RPCdigis->end(); ++RLayerIt) {
114  // The layerId
115  const RPCDetId &layerId = (*RLayerIt).first;
116 
117  // Get the iterators over the digis associated with this LayerId
118  const RPCDigiCollection::Range &range = (*RLayerIt).second;
119 
120  OurRPCDigis_->put(range, layerId);
121  }
122  }
123  // CSCStrip
124  //
125 
127 
128  // Get the digis from the event
129  Handle<CSCStripDigiCollection> pCSCStripdigis;
130 
131  if (e.getByToken(CSCStripDigiToken_, pCSCStripdigis)) {
132  // if(pCSCStripdigis.isValid() ) { std::cout << "Signal: have CSCStripDigis"
133  // << std::endl;} else { std::cout << "Signal: NO CSCStripDigis" <<
134  // std::endl;}
135 
136  // Loop over digis, copying them to our own local storage
137 
138  const CSCStripDigiCollection *CSCStripdigis = pCSCStripdigis.product();
140  for (CSLayerIt = CSCStripdigis->begin(); CSLayerIt != CSCStripdigis->end(); ++CSLayerIt) {
141  // The layerId
142  const CSCDetId &layerId = (*CSLayerIt).first;
143 
144  // Get the iterators over the digis associated with this LayerId
145  const CSCStripDigiCollection::Range &range = (*CSLayerIt).second;
146 
147  // std::cout << " Signal CSC layer " << (*CSLayerIt).first << std::endl;
148 
149  // for(CSCStripDigiCollection::const_iterator dtdigi=range.first;
150  // dtdigi!=range.second; dtdigi++){
151  // std::cout << "Digi " << (*dtdigi) << std::endl;
152  //}
153 
154  OurCSCStripDigis_->put(range, layerId);
155  }
156  }
157  // CSCWire
158  //
159 
161 
162  // Get the digis from the event
163  Handle<CSCWireDigiCollection> pCSCWiredigis;
164 
165  if (e.getByToken(CSCWireDigiToken_, pCSCWiredigis)) {
166  // if(pCSCWiredigis.isValid() ) { std::cout << "Signal: have CSCWireDigis"
167  // << std::endl;} else { std::cout << "Signal: NO CSCWireDigis" <<
168  // std::endl;}
169 
170  // Loop over digis, copying them to our own local storage
171 
172  const CSCWireDigiCollection *CSCWiredigis = pCSCWiredigis.product();
174  for (CWLayerIt = CSCWiredigis->begin(); CWLayerIt != CSCWiredigis->end(); ++CWLayerIt) {
175  // The layerId
176  const CSCDetId &layerId = (*CWLayerIt).first;
177 
178  // Get the iterators over the digis associated with this LayerId
179  const CSCWireDigiCollection::Range &range = (*CWLayerIt).second;
180 
181  OurCSCWireDigis_->put(range, layerId);
182  }
183  }
184 
185  // CSCComparators
186  //
187 
189 
190  // Get the digis from the event
191  Handle<CSCComparatorDigiCollection> pCSCComparatordigis;
192 
193  // std::cout << "CSCComp label: " << CSCDigiTagSig_.label() << " " <<
194  // CSCCompdigi_collectionSig_.label() << std::endl;
195 
196  if (e.getByToken(CSCCompDigiToken_, pCSCComparatordigis)) {
197  // if(pCSCComparatordigis.isValid() ) { std::cout << "Signal: have
198  // CSCComparatorDigis" << std::endl;} else { std::cout << "Signal: NO
199  // CSCComparatorDigis" << std::endl;}
200 
201  // Loop over digis, copying them to our own local storage
202 
203  const CSCComparatorDigiCollection *CSCComparatordigis = pCSCComparatordigis.product();
205  for (CWLayerIt = CSCComparatordigis->begin(); CWLayerIt != CSCComparatordigis->end(); ++CWLayerIt) {
206  // The layerId
207  const CSCDetId &layerId = (*CWLayerIt).first;
208 
209  // Get the iterators over the digis associated with this LayerId
210  const CSCComparatorDigiCollection::Range &range = (*CWLayerIt).second;
211 
212  OurCSCComparatorDigis_->put(range, layerId);
213  }
214  }
215 
216  } // end of addMuonSignals
217 
219  const EventPrincipal *ep,
220  unsigned int eventNr,
221  ModuleCallingContext const *mcc) {
222  LogDebug("DataMixingMuonWorker") << "\n===============> adding pileups from event " << ep->id()
223  << " for bunchcrossing " << bcr;
224 
225  // fill in maps of hits; same code as addSignals, except now applied to the
226  // pileup events
227 
228  // DT
229  //
230  // Get the digis from the event
231 
232  std::shared_ptr<Wrapper<DTDigiCollection> const> DTDigisPTR =
233  getProductByTag<DTDigiCollection>(*ep, DTPileInputTag_, mcc);
234 
235  if (DTDigisPTR) {
236  const DTDigiCollection *DTDigis = const_cast<DTDigiCollection *>(DTDigisPTR->product());
237 
239  for (DTLayerIt = DTDigis->begin(); DTLayerIt != DTDigis->end(); ++DTLayerIt) {
240  // The layerId
241  const DTLayerId &layerId = (*DTLayerIt).first;
242 
243  // Get the iterators over the Digis associated with this LayerId
244  const DTDigiCollection::Range &range = (*DTLayerIt).second;
245 
246  OurDTDigis_->put(range, layerId);
247  }
248  }
249  // RPC
250  //
251 
252  // Get the digis from the event
253 
254  std::shared_ptr<Wrapper<RPCDigiCollection> const> RPCDigisPTR =
255  getProductByTag<RPCDigiCollection>(*ep, RPCPileInputTag_, mcc);
256 
257  if (RPCDigisPTR) {
258  const RPCDigiCollection *RPCDigis = const_cast<RPCDigiCollection *>(RPCDigisPTR->product());
259 
261  for (RPCLayerIt = RPCDigis->begin(); RPCLayerIt != RPCDigis->end(); ++RPCLayerIt) {
262  // The layerId
263  const RPCDetId &layerId = (*RPCLayerIt).first;
264 
265  // Get the iterators over the digis associated with this LayerId
266  const RPCDigiCollection::Range &range = (*RPCLayerIt).second;
267 
268  OurRPCDigis_->put(range, layerId);
269  }
270  }
271 
272  // CSCStrip
273  //
274 
275  // Get the digis from the event
276 
277  std::shared_ptr<Wrapper<CSCStripDigiCollection> const> CSCStripDigisPTR =
278  getProductByTag<CSCStripDigiCollection>(*ep, CSCStripPileInputTag_, mcc);
279 
280  if (CSCStripDigisPTR) {
281  const CSCStripDigiCollection *CSCStripDigis = const_cast<CSCStripDigiCollection *>(CSCStripDigisPTR->product());
282 
284  for (CSCStripLayerIt = CSCStripDigis->begin(); CSCStripLayerIt != CSCStripDigis->end(); ++CSCStripLayerIt) {
285  // The layerId
286  const CSCDetId &layerId = (*CSCStripLayerIt).first;
287 
288  // Get the iterators over the digis associated with this LayerId
289  const CSCStripDigiCollection::Range &range = (*CSCStripLayerIt).second;
290 
291  // std::cout << " Pileup CSC layer " << (*CSCStripLayerIt).first <<
292  // std::endl;
293 
294  // for(CSCStripDigiCollection::const_iterator dtdigi=range.first;
295  // dtdigi!=range.second; dtdigi++){
296  // std::cout << "Digi " << (*dtdigi) << std::endl;
297  // }
298 
299  OurCSCStripDigis_->put(range, layerId);
300  }
301  }
302 
303  // CSCWire
304  //
305 
306  // Get the digis from the event
307 
308  std::shared_ptr<Wrapper<CSCWireDigiCollection> const> CSCWireDigisPTR =
309  getProductByTag<CSCWireDigiCollection>(*ep, CSCWirePileInputTag_, mcc);
310 
311  if (CSCWireDigisPTR) {
312  const CSCWireDigiCollection *CSCWireDigis = const_cast<CSCWireDigiCollection *>(CSCWireDigisPTR->product());
313 
315  for (CSCWireLayerIt = CSCWireDigis->begin(); CSCWireLayerIt != CSCWireDigis->end(); ++CSCWireLayerIt) {
316  // The layerId
317  const CSCDetId &layerId = (*CSCWireLayerIt).first;
318 
319  // Get the iterators over the digis associated with this LayerId
320  const CSCWireDigiCollection::Range &range = (*CSCWireLayerIt).second;
321 
322  OurCSCWireDigis_->put(range, layerId);
323  }
324  }
325 
326  // CSCComparators
327  //
328 
329  // Get the digis from the event
330 
331  std::shared_ptr<Wrapper<CSCComparatorDigiCollection> const> CSCComparatorDigisPTR =
332  getProductByTag<CSCComparatorDigiCollection>(*ep, CSCCompPileInputTag_, mcc);
333 
334  if (CSCComparatorDigisPTR) {
335  const CSCComparatorDigiCollection *CSCComparatorDigis =
336  const_cast<CSCComparatorDigiCollection *>(CSCComparatorDigisPTR->product());
337 
339  for (CSCComparatorLayerIt = CSCComparatorDigis->begin(); CSCComparatorLayerIt != CSCComparatorDigis->end();
340  ++CSCComparatorLayerIt) {
341  // The layerId
342  const CSCDetId &layerId = (*CSCComparatorLayerIt).first;
343 
344  // Get the iterators over the digis associated with this LayerId
345  const CSCComparatorDigiCollection::Range &range = (*CSCComparatorLayerIt).second;
346 
347  OurCSCComparatorDigis_->put(range, layerId);
348  }
349  }
350  }
351 
353  // collections of digis to put in the event
354  std::unique_ptr<DTDigiCollection> DTDigiMerge(new DTDigiCollection);
355  std::unique_ptr<RPCDigiCollection> RPCDigiMerge(new RPCDigiCollection);
356  std::unique_ptr<CSCStripDigiCollection> CSCStripDigiMerge(new CSCStripDigiCollection);
357  std::unique_ptr<CSCWireDigiCollection> CSCWireDigiMerge(new CSCWireDigiCollection);
358  std::unique_ptr<CSCComparatorDigiCollection> CSCComparatorDigiMerge(new CSCComparatorDigiCollection);
359 
360  // Loop over DT digis, copying them from our own local storage
361 
363  for (DLayerIt = OurDTDigis_->begin(); DLayerIt != OurDTDigis_->end(); ++DLayerIt) {
364  // The layerId
365  const DTLayerId &layerId = (*DLayerIt).first;
366 
367  // Get the iterators over the digis associated with this LayerId
368  const DTDigiCollection::Range &range = (*DLayerIt).second;
369 
370  DTDigiMerge->put(range, layerId);
371  }
372 
373  // Loop over RPC digis, copying them from our own local storage
374 
376  for (RLayerIt = OurRPCDigis_->begin(); RLayerIt != OurRPCDigis_->end(); ++RLayerIt) {
377  // The layerId
378  const RPCDetId &layerId = (*RLayerIt).first;
379 
380  // Get the iterators over the digis associated with this LayerId
381  const RPCDigiCollection::Range &range = (*RLayerIt).second;
382 
383  RPCDigiMerge->put(range, layerId);
384  }
385  // Loop over CSCStrip digis, copying them from our own local storage
386 
388  for (CSLayerIt = OurCSCStripDigis_->begin(); CSLayerIt != OurCSCStripDigis_->end(); ++CSLayerIt) {
389  // The layerId
390  const CSCDetId &layerId = (*CSLayerIt).first;
391 
392  // Get the iterators over the digis associated with this LayerId
393  const CSCStripDigiCollection::Range &range = (*CSLayerIt).second;
394 
395  std::vector<CSCStripDigi> NewDigiList;
396 
397  std::vector<int> StripList;
398  std::vector<CSCStripDigiCollection::const_iterator> StripPointer;
399 
400  for (CSCStripDigiCollection::const_iterator dtdigi = range.first; dtdigi != range.second; ++dtdigi) {
401  // std::cout << "Digi " << (*dtdigi).getStrip() << std::endl;
402  StripList.push_back((*dtdigi).getStrip());
403  StripPointer.push_back(dtdigi);
404  }
405 
406  int PrevStrip = -1;
407  std::vector<int> DuplicateList;
408 
409  std::vector<CSCStripDigiCollection::const_iterator>::const_iterator StripPtr = StripPointer.begin();
410 
411  for (std::vector<int>::const_iterator istrip = StripList.begin(); istrip != StripList.end(); ++istrip) {
412  const int CurrentStrip = *(istrip);
413 
414  if (CurrentStrip > PrevStrip) {
415  PrevStrip = CurrentStrip;
416 
417  int dupl_count;
418  dupl_count = std::count(StripList.begin(), StripList.end(), CurrentStrip);
419  if (dupl_count > 1) {
420  std::vector<int>::const_iterator duplicate = istrip;
421  ++duplicate;
422  std::vector<CSCStripDigiCollection::const_iterator>::const_iterator DuplPointer = StripPtr;
423  ++DuplPointer;
424  for (; duplicate != StripList.end(); ++duplicate) {
425  if ((*duplicate) == CurrentStrip) {
426  // std::cout << " Duplicate of current " <<
427  // CurrentStrip << " found at " << (duplicate - StripList.begin())
428  //<< std::endl;
429 
430  DuplicateList.push_back(CurrentStrip);
431 
432  std::vector<int> pileup_adc = (**DuplPointer).getADCCounts();
433  std::vector<int> signal_adc = (**StripPtr).getADCCounts();
434 
435  std::vector<int>::const_iterator minplace;
436 
437  minplace = std::min_element(pileup_adc.begin(), pileup_adc.end());
438 
439  int minvalue = (*minplace);
440 
441  std::vector<int> new_adc;
442 
443  std::vector<int>::const_iterator newsig = signal_adc.begin();
444 
445  for (std::vector<int>::const_iterator ibin = pileup_adc.begin(); ibin != pileup_adc.end(); ++ibin) {
446  new_adc.push_back((*newsig) + (*ibin) - minvalue);
447 
448  ++newsig;
449  }
450 
451  CSCStripDigi newDigi(CurrentStrip, new_adc);
452  NewDigiList.push_back(newDigi);
453  }
454  ++DuplPointer;
455  }
456  } else {
457  NewDigiList.push_back(**StripPtr);
458  }
459  } // if strips monotonically increasing... Haven't hit duplicates yet
460  else { // reached end of signal digis, or there was no overlap
461  PrevStrip = 1000; // now into pileup signals, stop looking forward for
462  // duplicates
463 
464  // check if this digi was in the duplicate list
465  int check;
466  check = std::count(DuplicateList.begin(), DuplicateList.end(), CurrentStrip);
467  if (check == 0)
468  NewDigiList.push_back(**StripPtr);
469  }
470  ++StripPtr;
471  }
472 
473  CSCStripDigiCollection::Range stripRange(NewDigiList.begin(), NewDigiList.end());
474 
475  CSCStripDigiMerge->put(stripRange, layerId);
476  }
477  // Loop over CSCStrip digis, copying them from our own local storage
478 
480  for (CWLayerIt = OurCSCWireDigis_->begin(); CWLayerIt != OurCSCWireDigis_->end(); ++CWLayerIt) {
481  // The layerId
482  const CSCDetId &layerId = (*CWLayerIt).first;
483 
484  // Get the iterators over the digis associated with this LayerId
485  const CSCWireDigiCollection::Range &range = (*CWLayerIt).second;
486 
487  CSCWireDigiMerge->put(range, layerId);
488  }
489 
490  // Loop over CSCComparator digis, copying them from our own local storage
491 
493  for (CCLayerIt = OurCSCComparatorDigis_->begin(); CCLayerIt != OurCSCComparatorDigis_->end(); ++CCLayerIt) {
494  // The layerId
495  const CSCDetId &layerId = (*CCLayerIt).first;
496 
497  // Get the iterators over the digis associated with this LayerId
498  const CSCComparatorDigiCollection::Range &range = (*CCLayerIt).second;
499 
500  CSCComparatorDigiMerge->put(range, layerId);
501  }
502 
503  // put the collection of recunstructed hits in the event
504  // LogDebug("DataMixingMuonWorker") << "total # DT Merged Digis: " <<
505  // DTDigiMerge->size() ; LogDebug("DataMixingMuonWorker") << "total # RPC
506  // Merged Digis: " << RPCDigiMerge->size() ;
507  // LogDebug("DataMixingMuonWorker") << "total # CSCStrip Merged Digis: " <<
508  // CSCStripDigiMerge->size() ; LogDebug("DataMixingMuonWorker") << "total #
509  // CSCWire Merged Digis: " << CSCWireDigiMerge->size() ;
510 
511  e.put(std::move(DTDigiMerge));
512  e.put(std::move(RPCDigiMerge));
513  e.put(std::move(CSCStripDigiMerge), CSCStripDigiCollectionDM_);
514  e.put(std::move(CSCWireDigiMerge), CSCWireDigiCollectionDM_);
515  e.put(std::move(CSCComparatorDigiMerge), CSCComparatorDigiCollectionDM_);
516 
517  // clear local storage for this event
518  delete OurDTDigis_;
519  delete OurRPCDigis_;
520  delete OurCSCStripDigis_;
521  delete OurCSCWireDigis_;
522  delete OurCSCComparatorDigis_;
523  }
524 
525 } // namespace edm
void addMuonSignals(const edm::Event &e)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
void addMuonPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId, ModuleCallingContext const *)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
EventID const & id() const
edm::InputTag CSCwiredigi_collectionSig_
MuonDigiCollection< CSCDetId, CSCStripDigi > CSCStripDigiCollection
edm::EDGetTokenT< RPCDigiCollection > RPCDigiPToken_
edm::EDGetTokenT< CSCStripDigiCollection > CSCStripDigiPToken_
CSCStripDigiCollection * OurCSCStripDigis_
MuonDigiCollection< CSCDetId, CSCComparatorDigi > CSCComparatorDigiCollection
const uint16_t range(const Frame &aFrame)
MuonDigiCollection< RPCDetId, RPCDigi > RPCDigiCollection
def move
Definition: eostools.py:511
edm::EDGetTokenT< DTDigiCollection > DTDigiPToken_
edm::EDGetTokenT< RPCDigiCollection > RPCDigiToken_
edm::EDGetTokenT< DTDigiCollection > DTDigiToken_
RPCDigiCollection * OurRPCDigis_
CSCWireDigiCollection * OurCSCWireDigis_
MuonDigiCollection< CSCDetId, CSCWireDigi > CSCWireDigiCollection
edm::EDGetTokenT< CSCStripDigiCollection > CSCStripDigiToken_
edm::EDGetTokenT< CSCComparatorDigiCollection > CSCCompDigiToken_
T const * product() const
Definition: Handle.h:70
edm::EDGetTokenT< CSCWireDigiCollection > CSCWireDigiToken_
std::pair< const_iterator, const_iterator > Range
CSCComparatorDigiCollection * OurCSCComparatorDigis_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< DigiType >::const_iterator const_iterator
static void check(T const &p, std::string const &id, SelectedProducts const &iProducts, bool iVerbose)
edm::EventID id() const
Definition: EventBase.h:59
MuonDigiCollection< DTLayerId, DTDigi > DTDigiCollection
edm::InputTag CSCCompdigi_collectionSig_
edm::EDGetTokenT< CSCComparatorDigiCollection > CSCCompDigiPToken_
edm::EDGetTokenT< CSCWireDigiCollection > CSCWireDigiPToken_
edm::InputTag CSCstripdigi_collectionSig_
#define LogDebug(id)