test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DataMixingEMWorker.cc
Go to the documentation of this file.
1 // File: DataMixingEMWorker.cc
2 // Description: see DataMixingEMWorker.h
3 // Author: Mike Hildreth, University of Notre Dame
4 //
5 //--------------------------------------------
6 
7 #include <map>
8 #include <memory>
16 //
17 //
18 #include "DataMixingEMWorker.h"
19 
20 
21 using namespace std;
22 
23 namespace edm
24 {
25 
26  // Virtual constructor
27 
28  DataMixingEMWorker::DataMixingEMWorker() { }
29 
30  // Constructor
31  DataMixingEMWorker::DataMixingEMWorker(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, retrieve
40 
41  EBProducerSig_ = ps.getParameter<edm::InputTag>("EBProducerSig");
42  EEProducerSig_ = ps.getParameter<edm::InputTag>("EEProducerSig");
43  ESProducerSig_ = ps.getParameter<edm::InputTag>("ESProducerSig");
44 
48 
49 
50  EBrechitCollectionSig_ = ps.getParameter<edm::InputTag>("EBrechitCollectionSig");
51  EErechitCollectionSig_ = ps.getParameter<edm::InputTag>("EErechitCollectionSig");
52  ESrechitCollectionSig_ = ps.getParameter<edm::InputTag>("ESrechitCollectionSig");
53 
54  EBPileRecHitInputTag_ = ps.getParameter<edm::InputTag>("EBPileRecHitInputTag");
55  EEPileRecHitInputTag_ = ps.getParameter<edm::InputTag>("EEPileRecHitInputTag");
56  ESPileRecHitInputTag_ = ps.getParameter<edm::InputTag>("ESPileRecHitInputTag");
57 
61 
62 
63  EBRecHitCollectionDM_ = ps.getParameter<std::string>("EBRecHitCollectionDM");
64  EERecHitCollectionDM_ = ps.getParameter<std::string>("EERecHitCollectionDM");
65  ESRecHitCollectionDM_ = ps.getParameter<std::string>("ESRecHitCollectionDM");
66 
67  }
68 
69 
70  // Virtual destructor needed.
72  }
73 
75  // fill in maps of hits
76 
77  LogInfo("DataMixingEMWorker")<<"===============> adding MC signals for "<<e.id();
78 
79  // EB first
80 
82 
83  const EBRecHitCollection* EBRecHits = 0;
84 
85  if(e.getByToken(EBRecHitToken_, pEBRecHits) ){
86  EBRecHits = pEBRecHits.product(); // get a ptr to the product
87  LogDebug("DataMixingEMWorker") << "total # EB rechits: " << EBRecHits->size();
88  }
89 
90 
91  if (EBRecHits)
92  {
93  // loop over rechits, storing them in a map so we can add pileup later
94  for(EBRecHitCollection::const_iterator it = EBRecHits->begin();
95  it != EBRecHits->end(); ++it) {
96 
97  EBRecHitStorage_.insert(EBRecHitMap::value_type( ( it->id() ), *it ));
98 
99  LogDebug("DataMixingEMWorker") << "processed EBRecHit with rawId: "
100  << it->id().rawId() << "\n"
101  << " rechit energy: " << it->energy();
102 
103  }
104  }
105 
106  // EE next
107 
108  Handle< EERecHitCollection > pEERecHits;
109 
110  const EERecHitCollection* EERecHits = 0;
111 
112 
113  if(e.getByToken(EERecHitToken_, pEERecHits) ){
114  EERecHits = pEERecHits.product(); // get a ptr to the product
115  LogDebug("DataMixingEMWorker") << "total # EE rechits: " << EERecHits->size();
116  }
117 
118 
119  if (EERecHits)
120  {
121  // loop over rechits, storing them in a map so we can add pileup later
122  for(EERecHitCollection::const_iterator it = EERecHits->begin();
123  it != EERecHits->end(); ++it) {
124 
125  EERecHitStorage_.insert(EERecHitMap::value_type( ( it->id() ), *it ));
126 #ifdef DEBUG
127  LogDebug("DataMixingEMWorker") << "processed EERecHit with rawId: "
128  << it->id().rawId() << "\n"
129  << " rechit energy: " << it->energy();
130 #endif
131 
132  }
133  }
134  // ES next
135 
136  Handle< ESRecHitCollection > pESRecHits;
137 
138  const ESRecHitCollection* ESRecHits = 0;
139 
140 
141  if(e.getByToken( ESRecHitToken_, pESRecHits) ){
142  ESRecHits = pESRecHits.product(); // get a ptr to the product
143 #ifdef DEBUG
144  LogDebug("DataMixingEMWorker") << "total # ES rechits: " << ESRecHits->size();
145 #endif
146  }
147 
148 
149  if (ESRecHits)
150  {
151  // loop over rechits, storing them in a map so we can add pileup later
152  for(ESRecHitCollection::const_iterator it = ESRecHits->begin();
153  it != ESRecHits->end(); ++it) {
154 
155  ESRecHitStorage_.insert(ESRecHitMap::value_type( ( it->id() ), *it ));
156 
157 #ifdef DEBUG
158  LogDebug("DataMixingEMWorker") << "processed ESRecHit with rawId: "
159  << it->id().rawId() << "\n"
160  << " rechit energy: " << it->energy();
161 #endif
162 
163  }
164  }
165 
166  } // end of addEMSignals
167 
168  void DataMixingEMWorker::addEMPileups(const int bcr, const EventPrincipal *ep, unsigned int eventNr,
169  ModuleCallingContext const* mcc) {
170 
171  LogInfo("DataMixingEMWorker") <<"\n===============> adding pileups from event "<<ep->id()<<" for bunchcrossing "<<bcr;
172 
173  // fill in maps of hits; same code as addSignals, except now applied to the pileup events
174 
175  // EB first
176 
177  std::shared_ptr<Wrapper<EBRecHitCollection> const> EBRecHitsPTR =
178  getProductByTag<EBRecHitCollection>(*ep, EBPileRecHitInputTag_, mcc);
179 
180  if(EBRecHitsPTR ) {
181 
182  const EBRecHitCollection* EBRecHits = const_cast< EBRecHitCollection * >(EBRecHitsPTR->product());
183 
184  LogDebug("DataMixingEMWorker") << "total # EB rechits: " << EBRecHits->size();
185 
186  // loop over digis, adding these to the existing maps
187  for(EBRecHitCollection::const_iterator it = EBRecHits->begin();
188  it != EBRecHits->end(); ++it) {
189 
190  EBRecHitStorage_.insert(EBRecHitMap::value_type( (it->id()), *it ));
191 
192 #ifdef DEBUG
193  LogDebug("DataMixingEMWorker") << "processed EBRecHit with rawId: "
194  << it->id().rawId() << "\n"
195  << " rechit energy: " << it->energy();
196 #endif
197  }
198  }
199 
200  // EE Next
201 
202  std::shared_ptr<Wrapper<EERecHitCollection> const> EERecHitsPTR =
203  getProductByTag<EERecHitCollection>(*ep, EEPileRecHitInputTag_, mcc);
204 
205  if(EERecHitsPTR ) {
206 
207  const EERecHitCollection* EERecHits = const_cast< EERecHitCollection * >(EERecHitsPTR->product());
208 
209  LogDebug("DataMixingEMWorker") << "total # EE rechits: " << EERecHits->size();
210 
211  // loop over digis, adding these to the existing maps
212  for(EERecHitCollection::const_iterator it = EERecHits->begin();
213  it != EERecHits->end(); ++it) {
214 
215  EERecHitStorage_.insert(EERecHitMap::value_type( (it->id()), *it ));
216 
217 #ifdef DEBUG
218  LogDebug("DataMixingEMWorker") << "processed EERecHit with rawId: "
219  << it->id().rawId() << "\n"
220  << " rechit energy: " << it->energy();
221 #endif
222  }
223  }
224 
225  // ES Next
226 
227  std::shared_ptr<Wrapper<ESRecHitCollection> const> ESRecHitsPTR =
228  getProductByTag<ESRecHitCollection>(*ep, ESPileRecHitInputTag_, mcc);
229 
230  if(ESRecHitsPTR ) {
231 
232  const ESRecHitCollection* ESRecHits = const_cast< ESRecHitCollection * >(ESRecHitsPTR->product());
233 
234  LogDebug("DataMixingEMWorker") << "total # ES rechits: " << ESRecHits->size();
235 
236  // loop over digis, adding these to the existing maps
237  for(ESRecHitCollection::const_iterator it = ESRecHits->begin();
238  it != ESRecHits->end(); ++it) {
239 
240  ESRecHitStorage_.insert(ESRecHitMap::value_type( (it->id()), *it ));
241 
242 #ifdef DEBUG
243  LogDebug("DataMixingEMWorker") << "processed ESRecHit with rawId: "
244  << it->id().rawId() << "\n"
245  << " rechit energy: " << it->energy();
246 #endif
247  }
248  }
249 
250 
251  }
252 
254 
255  // collection of rechits to put in the event
256  std::auto_ptr< EBRecHitCollection > EBrechits( new EBRecHitCollection );
257  std::auto_ptr< EERecHitCollection > EErechits( new EERecHitCollection );
258  std::auto_ptr< ESRecHitCollection > ESrechits( new ESRecHitCollection );
259 
260  // loop over the maps we have, re-making individual hits or digis if necessary.
261  DetId formerID = 0;
262  DetId currentID;
263  float ESum = 0.;
264  float EBTime = 0.;
265 
266  // EB first...
267 
268  EBRecHitMap::const_iterator iEBchk;
269 
270  for(EBRecHitMap::const_iterator iEB = EBRecHitStorage_.begin();
271  iEB != EBRecHitStorage_.end(); ++iEB) {
272 
273  currentID = iEB->first;
274 
275  if (currentID == formerID) { // we have to add these rechits together
276 
277  ESum+=(iEB->second).energy();
278  }
279  else {
280  if(formerID>0) {
281  // cutoff for ESum?
282  EcalRecHit aHit(formerID, ESum, EBTime);
283  EBrechits->push_back( aHit );
284  }
285  //save pointers for next iteration
286  formerID = currentID;
287  ESum = (iEB->second).energy();
288  EBTime = (iEB->second).time(); // take time of first hit in sequence - is this ok?
289  }
290 
291  iEBchk = iEB;
292  if((++iEBchk) == EBRecHitStorage_.end()) { //make sure not to lose the last one
293  EcalRecHit aHit(formerID, ESum, EBTime);
294  EBrechits->push_back( aHit );
295  }
296  }
297 
298  // EE next...
299 
300  // loop over the maps we have, re-making individual hits or digis if necessary.
301  formerID = 0;
302  ESum = 0.;
303  float EETime = 0.;
304 
305  EERecHitMap::const_iterator iEEchk;
306 
307  for(EERecHitMap::const_iterator iEE = EERecHitStorage_.begin();
308  iEE != EERecHitStorage_.end(); ++iEE) {
309 
310  currentID = iEE->first;
311 
312  if (currentID == formerID) { // we have to add these rechits together
313 
314  ESum+=(iEE->second).energy();
315  }
316  else {
317  if(formerID>0) {
318  // cutoff for ESum?
319  EcalRecHit aHit(formerID, ESum, EETime);
320  EErechits->push_back( aHit );
321  }
322  //save pointers for next iteration
323  formerID = currentID;
324  ESum = (iEE->second).energy();
325  EETime = (iEE->second).time(); // take time of first hit in sequence - is this ok?
326  }
327 
328  iEEchk = iEE;
329  if((++iEEchk) == EERecHitStorage_.end()) { //make sure not to lose the last one
330  EcalRecHit aHit(formerID, ESum, EETime);
331  EErechits->push_back( aHit );
332  }
333  }
334 
335  // ES next...
336 
337  // loop over the maps we have, re-making individual hits or digis if necessary.
338  formerID = 0;
339  ESum = 0.;
340  float ESTime = 0.;
341 
342  ESRecHitMap::const_iterator iESchk;
343 
344  for(ESRecHitMap::const_iterator iES = ESRecHitStorage_.begin();
345  iES != ESRecHitStorage_.end(); ++iES) {
346 
347  currentID = iES->first;
348 
349  if (currentID == formerID) { // we have to add these rechits together
350 
351  ESum+=(iES->second).energy();
352  }
353  else {
354  if(formerID>0) {
355  // cutoff for ESum?
356  EcalRecHit aHit(formerID, ESum, ESTime);
357  ESrechits->push_back( aHit );
358  }
359  //save pointers for next iteration
360  formerID = currentID;
361  ESum = (iES->second).energy();
362  ESTime = (iES->second).time(); // take time of first hit in sequence - is this ok?
363  }
364 
365  iESchk = iES;
366  if((++iESchk) == ESRecHitStorage_.end()) { //make sure not to lose the last one
367  EcalRecHit aHit(formerID, ESum, ESTime);
368  ESrechits->push_back( aHit );
369  }
370  }
371 
372  // done merging
373 
374  // put the collection of reconstructed hits in the event
375  LogInfo("DataMixingEMWorker") << "total # EB Merged rechits: " << EBrechits->size() ;
376  LogInfo("DataMixingEMWorker") << "total # EE Merged rechits: " << EErechits->size() ;
377  LogInfo("DataMixingEMWorker") << "total # ES Merged rechits: " << ESrechits->size() ;
378 
379  e.put( EBrechits, EBRecHitCollectionDM_ );
380  e.put( EErechits, EERecHitCollectionDM_ );
381  e.put( ESrechits, ESRecHitCollectionDM_ );
382 
383  // clear local storage after this event
384 
385  EBRecHitStorage_.clear();
386  EERecHitStorage_.clear();
387  ESRecHitStorage_.clear();
388 
389  }
390 
391 } //edm
392 
393 // LocalWords: ESProducerSig
#define LogDebug(id)
T getParameter(std::string const &) const
void putEM(edm::Event &e)
void addEMSignals(const edm::Event &e)
edm::EDGetTokenT< EERecHitCollection > EEPileRecHitToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
EventID const & id() const
std::vector< EcalRecHit >::const_iterator const_iterator
edm::InputTag EBrechitCollectionSig_
edm::InputTag ESPileRecHitInputTag_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
edm::EDGetTokenT< EERecHitCollection > EERecHitToken_
edm::InputTag EErechitCollectionSig_
edm::EDGetTokenT< EBRecHitCollection > EBRecHitToken_
edm::EDGetTokenT< ESRecHitCollection > ESPileRecHitToken_
const_iterator end() const
Definition: DetId.h:18
edm::EDGetTokenT< ESRecHitCollection > ESRecHitToken_
edm::InputTag ESrechitCollectionSig_
T const * product() const
Definition: Handle.h:81
void addEMPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId, ModuleCallingContext const *)
edm::InputTag EBPileRecHitInputTag_
edm::InputTag EEPileRecHitInputTag_
edm::EventID id() const
Definition: EventBase.h:59
size_type size() const
edm::EDGetTokenT< EBRecHitCollection > EBPileRecHitToken_
const_iterator begin() const