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