CMS 3D CMS Logo

EcalRecHitsMerger.cc
Go to the documentation of this file.
1 
2 //#include <FWCore/Framework/interface/Handle.h>
8 
11 
13 
14 
15 using namespace edm;
16 using namespace std;
17 
18 
20 
21  debug_ = pset.getUntrackedParameter<bool>("debug");
22 
23  EgammaSourceEB_ = pset.getUntrackedParameter<edm::InputTag>("EgammaSource_EB");
24  MuonsSourceEB_ = pset.getUntrackedParameter<edm::InputTag>("MuonsSource_EB");
25  TausSourceEB_ = pset.getUntrackedParameter<edm::InputTag>("TausSource_EB");
26  JetsSourceEB_ = pset.getUntrackedParameter<edm::InputTag>("JetsSource_EB");
27  RestSourceEB_ = pset.getUntrackedParameter<edm::InputTag>("RestSource_EB");
28  Pi0SourceEB_ = pset.getUntrackedParameter<edm::InputTag>("Pi0Source_EB",edm::InputTag("dummyPi0"));
29 
30  EgammaSourceEE_ = pset.getUntrackedParameter<edm::InputTag>("EgammaSource_EE");
31  MuonsSourceEE_ = pset.getUntrackedParameter<edm::InputTag>("MuonsSource_EE");
32  TausSourceEE_ = pset.getUntrackedParameter<edm::InputTag>("TausSource_EE");
33  JetsSourceEE_ = pset.getUntrackedParameter<edm::InputTag>("JetsSource_EE");
34  RestSourceEE_ = pset.getUntrackedParameter<edm::InputTag>("RestSource_EE");
35  Pi0SourceEE_ = pset.getUntrackedParameter<edm::InputTag>("Pi0Source_EE",edm::InputTag("dummyPi0"));
36 
37  OutputLabelEB_ = pset.getUntrackedParameter<std::string>("OutputLabel_EB");
38  OutputLabelEE_ = pset.getUntrackedParameter<std::string>("OutputLabel_EE");
39 
40  InputRecHitEB_ = pset.getUntrackedParameter<std::string>("EcalRecHitCollectionEB");
41  InputRecHitEE_ = pset.getUntrackedParameter<std::string>("EcalRecHitCollectionEE");
42 
43  produces<EcalRecHitCollection>(OutputLabelEB_);
44  produces<EcalRecHitCollection>(OutputLabelEE_);
45 
46 }
47 
48 
49 
51 }
52 
54 
56  desc.add<bool>("debug", false);
57  desc.add<edm::InputTag>("EgammaSource_EB", edm::InputTag("ecalRegionalEgammaRecHitTmp","EcalRecHitsEB"));
58  desc.add<edm::InputTag>("MuonsSource_EB", edm::InputTag("ecalRegionalMuonsRecHitTmp","EcalRecHitsEB"));
59  desc.add<edm::InputTag>("TausSource_EB", edm::InputTag("ecalRegionalTausRecHitTmp","EcalRecHitsEB"));
60  desc.add<edm::InputTag>("JetsSource_EB", edm::InputTag("ecalRegionalJetsRecHitTmp","EcalRecHitsEB"));
61  desc.add<edm::InputTag>("RestSource_EB", edm::InputTag("ecalRegionalRestRecHitTmp","EcalRecHitsEB"));
62  desc.add<edm::InputTag>("Pi0Source_EB", edm::InputTag("dummyPi0"));
63  desc.add<edm::InputTag>("EgammaSource_EE", edm::InputTag("ecalRegionalEgammaRecHitTmp","EcalRecHitsEE"));
64  desc.add<edm::InputTag>("MuonsSource_EE", edm::InputTag("ecalRegionalMuonsRecHitTmp","EcalRecHitsEE"));
65  desc.add<edm::InputTag>("TausSource_EE", edm::InputTag("ecalRegionalTausRecHitTmp","EcalRecHitsEE"));
66  desc.add<edm::InputTag>("JetsSource_EE", edm::InputTag("ecalRegionalJetsRecHitTmp","EcalRecHitsEE"));
67  desc.add<edm::InputTag>("RestSource_EE", edm::InputTag("ecalRegionalRestRecHitTmp","EcalRecHitsEE"));
68  desc.add<edm::InputTag>("Pi0Source_EE", edm::InputTag("dummyPi0"));
69  desc.add<std::string>("OutputLabel_EB", "EcalRecHitsEB");
70  desc.add<std::string>("OutputLabel_EE", "EcalRecHitsEE");
71  desc.add<std::string>("EcalRecHitCollectionEB", "EcalRecHitsEB");
72  desc.add<std::string>("EcalRecHitCollectionEE", "EcalRecHitsEE");
73  descriptions.add("hltEcalRecHitsMerger", desc);
74 }
75 
77 }
78 
80 }
81 
83 
84  if (debug_) std::cout << " EcalRecHitMerger : Run " << e.id().run() << " Event " << e.id().event() << std::endl;
85 
86  std::vector< edm::Handle<EcalRecHitCollection> > EcalRecHits_done;
87  e.getManyByType(EcalRecHits_done);
88 
89  auto EBMergedRecHits = std::make_unique<EcalRecHitCollection>();
90  auto EEMergedRecHits = std::make_unique<EcalRecHitCollection>();
91 
92  unsigned int nColl = EcalRecHits_done.size();
93 
94  int nEB = 0;
95  int nEE = 0;
96 
97 
98  for (unsigned int i=0; i < nColl; i++) {
99 
100  std::string instance = EcalRecHits_done[i].provenance()->productInstanceName();
101  std::string module_label = EcalRecHits_done[i].provenance()->moduleLabel();
102 
103  if ( module_label != EgammaSourceEB_.label() &&
104  module_label != MuonsSourceEB_.label() &&
105  module_label != JetsSourceEB_.label() &&
106  module_label != TausSourceEB_.label() &&
107  module_label != RestSourceEB_.label() &&
108  module_label != Pi0SourceEB_.label() ) continue;
109 
110  if (instance == InputRecHitEB_) {
111  nEB += EcalRecHits_done[i] -> size();
112  }
113  else if (instance == InputRecHitEE_) {
114  nEE += EcalRecHits_done[i] -> size();
115  }
116 
117  }
118 
119  EBMergedRecHits -> reserve(nEB);
120  EEMergedRecHits -> reserve(nEE);
121  if (debug_) std::cout << " Number of EB Rechits to merge = " << nEB << std::endl;
122  if (debug_) std::cout << " Number of EE Rechits to merge = " << nEE << std::endl;
123 
124  for (unsigned int i=0; i < nColl; i++) {
125  std::string instance = EcalRecHits_done[i].provenance()->productInstanceName();
126 
127  std::string module_label = EcalRecHits_done[i].provenance()->moduleLabel();
128  if ( module_label != EgammaSourceEB_.label() &&
129  module_label != MuonsSourceEB_.label() &&
130  module_label != JetsSourceEB_.label() &&
131  module_label != TausSourceEB_.label() &&
132  module_label != RestSourceEB_.label() &&
133  module_label != Pi0SourceEB_.label() ) continue;
134 
135  if (instance == InputRecHitEB_) {
136  for (EcalRecHitCollection::const_iterator it=EcalRecHits_done[i]->begin(); it !=EcalRecHits_done[i]->end(); it++) {
137  EBMergedRecHits -> push_back(*it);
138  }
139  }
140  else if (instance == InputRecHitEE_) {
141  for (EcalRecHitCollection::const_iterator it=EcalRecHits_done[i]->begin(); it !=EcalRecHits_done[i]->end(); it++) {
142  EEMergedRecHits -> push_back(*it);
143  }
144  }
145 
146  }
147 
148 
149  // std::cout << " avant le put " << std::endl;
150  e.put(std::move(EBMergedRecHits),OutputLabelEB_);
151  e.put(std::move(EEMergedRecHits),OutputLabelEE_);
152  // std::cout << " apres le put " << std::endl;
153 
154 }
155 
RunNumber_t run() const
Definition: EventID.h:39
size
Write out results.
EventNumber_t event() const
Definition: EventID.h:41
~EcalRecHitsMerger() override
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static PFTauRenderPlugin instance
EcalRecHitsMerger(const edm::ParameterSet &pset)
std::vector< EcalRecHit >::const_iterator const_iterator
void getManyByType(std::vector< Handle< PROD >> &results) const
Definition: Event.h:508
void produce(edm::StreamID sid, edm::Event &e, const edm::EventSetup &c) const override
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void beginJob(void) override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EventID id() const
Definition: EventBase.h:59
#define begin
Definition: vmac.h:32
HLT enums.
void endJob(void) override
def move(src, dest)
Definition: eostools.py:511