CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalRecHitsMerger.cc
Go to the documentation of this file.
1 
2 //#include <FWCore/Framework/interface/Handle.h>
6 
9 
11 
12 
13 using namespace edm;
14 using namespace std;
15 
16 
18 
19  debug_ = pset.getUntrackedParameter<bool>("debug");
20 
21  EgammaSourceEB_ = pset.getUntrackedParameter<edm::InputTag>("EgammaSource_EB");
22  MuonsSourceEB_ = pset.getUntrackedParameter<edm::InputTag>("MuonsSource_EB");
23  TausSourceEB_ = pset.getUntrackedParameter<edm::InputTag>("TausSource_EB");
24  JetsSourceEB_ = pset.getUntrackedParameter<edm::InputTag>("JetsSource_EB");
25  RestSourceEB_ = pset.getUntrackedParameter<edm::InputTag>("RestSource_EB");
26  Pi0SourceEB_ = pset.getUntrackedParameter<edm::InputTag>("Pi0Source_EB",edm::InputTag("dummyPi0"));
27 
28  EgammaSourceEE_ = pset.getUntrackedParameter<edm::InputTag>("EgammaSource_EE");
29  MuonsSourceEE_ = pset.getUntrackedParameter<edm::InputTag>("MuonsSource_EE");
30  TausSourceEE_ = pset.getUntrackedParameter<edm::InputTag>("TausSource_EE");
31  JetsSourceEE_ = pset.getUntrackedParameter<edm::InputTag>("JetsSource_EE");
32  RestSourceEE_ = pset.getUntrackedParameter<edm::InputTag>("RestSource_EE");
33  Pi0SourceEE_ = pset.getUntrackedParameter<edm::InputTag>("Pi0Source_EE",edm::InputTag("dummyPi0"));
34 
35  OutputLabelEB_ = pset.getUntrackedParameter<std::string>("OutputLabel_EB");
36  OutputLabelEE_ = pset.getUntrackedParameter<std::string>("OutputLabel_EE");
37 
38  InputRecHitEB_ = pset.getUntrackedParameter<std::string>("EcalRecHitCollectionEB");
39  InputRecHitEE_ = pset.getUntrackedParameter<std::string>("EcalRecHitCollectionEE");
40 
41  produces<EcalRecHitCollection>(OutputLabelEB_);
42  produces<EcalRecHitCollection>(OutputLabelEE_);
43 
44 }
45 
46 
47 
49 }
50 
51 
53 }
54 
56 }
57 
59 
60  if (debug_) std::cout << " EcalRecHitMerger : Run " << e.id().run() << " Event " << e.id().event() << std::endl;
61 
62  std::vector< edm::Handle<EcalRecHitCollection> > EcalRecHits_done;
63  e.getManyByType(EcalRecHits_done);
64 
65  std::auto_ptr<EcalRecHitCollection> EBMergedRecHits(new EcalRecHitCollection);
66  std::auto_ptr<EcalRecHitCollection> EEMergedRecHits(new EcalRecHitCollection);
67 
68  unsigned int nColl = EcalRecHits_done.size();
69 
70  int nEB = 0;
71  int nEE = 0;
72 
73 
74  for (unsigned int i=0; i < nColl; i++) {
75 
76  std::string instance = EcalRecHits_done[i].provenance()->productInstanceName();
77  std::string module_label = EcalRecHits_done[i].provenance()->moduleLabel();
78 
79  if ( module_label != EgammaSourceEB_.label() &&
80  module_label != MuonsSourceEB_.label() &&
81  module_label != JetsSourceEB_.label() &&
82  module_label != TausSourceEB_.label() &&
83  module_label != RestSourceEB_.label() &&
84  module_label != Pi0SourceEB_.label() ) continue;
85 
86  if (instance == InputRecHitEB_) {
87  nEB += EcalRecHits_done[i] -> size();
88  }
89  else if (instance == InputRecHitEE_) {
90  nEE += EcalRecHits_done[i] -> size();
91  }
92 
93  }
94 
95  EBMergedRecHits -> reserve(nEB);
96  EEMergedRecHits -> reserve(nEE);
97  if (debug_) std::cout << " Number of EB Rechits to merge = " << nEB << std::endl;
98  if (debug_) std::cout << " Number of EE Rechits to merge = " << nEE << std::endl;
99 
100  for (unsigned int i=0; i < nColl; i++) {
101  std::string instance = EcalRecHits_done[i].provenance()->productInstanceName();
102 
103  std::string module_label = EcalRecHits_done[i].provenance()->moduleLabel();
104  if ( module_label != EgammaSourceEB_.label() &&
105  module_label != MuonsSourceEB_.label() &&
106  module_label != JetsSourceEB_.label() &&
107  module_label != TausSourceEB_.label() &&
108  module_label != RestSourceEB_.label() &&
109  module_label != Pi0SourceEB_.label() ) continue;
110 
111  if (instance == InputRecHitEB_) {
112  for (EcalRecHitCollection::const_iterator it=EcalRecHits_done[i]->begin(); it !=EcalRecHits_done[i]->end(); it++) {
113  EBMergedRecHits -> push_back(*it);
114  }
115  }
116  else if (instance == InputRecHitEE_) {
117  for (EcalRecHitCollection::const_iterator it=EcalRecHits_done[i]->begin(); it !=EcalRecHits_done[i]->end(); it++) {
118  EEMergedRecHits -> push_back(*it);
119  }
120  }
121 
122  }
123 
124 
125  // std::cout << " avant le put " << std::endl;
126  e.put(EBMergedRecHits,OutputLabelEB_);
127  e.put(EEMergedRecHits,OutputLabelEE_);
128  // std::cout << " apres le put " << std::endl;
129 
130 }
131 
RunNumber_t run() const
Definition: EventID.h:42
void getManyByType(std::vector< Handle< PROD > > &results) const
Definition: Event.h:408
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
static PFTauRenderPlugin instance
EcalRecHitsMerger(const edm::ParameterSet &pset)
std::vector< EcalRecHit >::const_iterator const_iterator
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
virtual ~EcalRecHitsMerger()
edm::EventID id() const
Definition: EventBase.h:56
#define begin
Definition: vmac.h:31
tuple cout
Definition: gather_cfg.py:121
tuple size
Write out results.
void produce(edm::Event &e, const edm::EventSetup &c)