CMS 3D CMS Logo

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