CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EgammaHLTRechitInRegionsProducer.cc
Go to the documentation of this file.
1 // C/C++ headers
2 #include <iostream>
3 #include <vector>
4 #include <memory>
5 
6 // Framework
15 
16 // Reconstruction Classes
21 //#include "DataFormats/EgammaReco/interface/BasicCluster.h"
22 //#include "DataFormats/EgammaReco/interface/SuperCluster.h"
23 //#include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
28 
29 // Geometry
37 
38 // Level 1 Trigger
43 
44 // EgammaCoreTools
45 //#include "RecoEcal/EgammaCoreTools/interface/PositionCalc.h"
47 
48 // Class header file
50 
51 //#include "DataFormats/Math/interface/deltaR.h"
52 
53 
55 
56  useUncalib_ = ps.getParameter<bool>("useUncalib");
57  //hitproducer_ = ps.getParameter<edm::InputTag>("ecalhitproducer");
58 
59  l1TagIsolated_ = ps.getParameter< edm::InputTag > ("l1TagIsolated");
60  l1TagNonIsolated_ = ps.getParameter< edm::InputTag > ("l1TagNonIsolated");
61  doIsolated_ = ps.getParameter<bool>("doIsolated");
62 
63  l1LowerThr_ = ps.getParameter<double> ("l1LowerThr");
64  l1UpperThr_ = ps.getParameter<double> ("l1UpperThr");
65  l1LowerThrIgnoreIsolation_ = ps.getParameter<double> ("l1LowerThrIgnoreIsolation");
66 
67  regionEtaMargin_ = ps.getParameter<double>("regionEtaMargin");
68  regionPhiMargin_ = ps.getParameter<double>("regionPhiMargin");
69 
70  //const std::vector<std::string> flagnames = ps.getParameter<std::vector<std::string> >("RecHitFlagToBeExcluded");
71  //const std::vector<int> flagsexcl = StringToEnumValue<EcalRecHit::Flags>(flagnames);
72 
73  //const std::vector<std::string> severitynames = ps.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcluded");
74  //const std::vector<int> severitiesexcl = StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynames);
75 
76  hitLabels = ps.getParameter<std::vector<edm::InputTag>>("ecalhitLabels");
77  productLabels = ps.getParameter<std::vector<std::string>>("productLabels");
78 
79  if (useUncalib_) {
80  for (unsigned int i=0; i<hitLabels.size(); i++) {
81  uncalibHitTokens.push_back(consumes<EcalUncalibratedRecHitCollection>(hitLabels[i]));
82  produces<EcalUncalibratedRecHitCollection>(productLabels[i]);
83  }
84  } else {
85  for (unsigned int i=0; i<hitLabels.size(); i++) {
86  hitTokens.push_back(consumes<EcalRecHitCollection>(hitLabels[i]));
87  produces<EcalRecHitCollection> (productLabels[i]);
88  }
89  }
90 }
91 
92 
94 {}
95 
98  std::vector<std::string> productTags;
99  productTags.push_back("EcalRegionalRecHitsEB");
100  productTags.push_back("EcalRegionalRecHitsEE");
101  desc.add<std::vector<std::string>>("productLabels", productTags);
102  std::vector<edm::InputTag> inputTags;
103  inputTags.push_back(edm::InputTag("hltEcalRegionalEgammaRecHit:EcalRecHitsEB"));
104  inputTags.push_back(edm::InputTag("hltEcalRegionalEgammaRecHit:EcalRecHitsEE"));
105  inputTags.push_back(edm::InputTag("hltESRegionalEgammaRecHit:EcalRecHitsES"));
106  desc.add<std::vector<edm::InputTag>>("ecalhitLabels", inputTags);
107  //desc.add<edm::InputTag>("ecalhitproducer", edm::InputTag("ecalRecHit"));
108  desc.add<edm::InputTag>("l1TagIsolated", edm::InputTag("l1extraParticles","Isolated"));
109  desc.add<edm::InputTag>("l1TagNonIsolated", edm::InputTag("l1extraParticles","NonIsolated"));
110  desc.add<bool>("useUncalib", true);
111  desc.add<bool>("doIsolated", true);
112  desc.add<double>("l1LowerThr", 5.0);
113  desc.add<double>("l1UpperThr", 999.);
114  desc.add<double>("l1LowerThrIgnoreIsolation", 0.0);
115  desc.add<double>("regionEtaMargin", 0.14);
116  desc.add<double>("regionPhiMargin", 0.4);
117  //desc.add<std::vector<std::string> >("RecHitFlagToBeExcluded", std::vector<std::string>());
118  //desc.add<std::vector<std::string> >("RecHitSeverityToBeExcluded", std::vector<std::string>());
119  descriptions.add(("hltEgammaHLTRechitInRegionsProducer"), desc);
120 }
121 
123 
124  // get the collection geometry:
125  edm::ESHandle<CaloGeometry> geoHandle;
126  es.get<CaloGeometryRecord>().get(geoHandle);
127  const CaloGeometry& geometry = *geoHandle;
128  const CaloSubdetectorGeometry *geometry_p;
129  std::auto_ptr<const CaloSubdetectorTopology> topology;
130 
131  //Get the L1 EM Particle Collection
132  //Get the L1 EM Particle Collection
134  if(doIsolated_)
135  evt.getByLabel(l1TagIsolated_, emIsolColl);
136 
137  //Get the L1 EM Particle Collection
139  evt.getByLabel(l1TagNonIsolated_, emNonIsolColl);
140 
141  // Get the CaloGeometry
142  edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
143  es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
144 
145  std::vector<EcalEtaPhiRegion> regions;
146  if(doIsolated_) {
147  for( l1extra::L1EmParticleCollection::const_iterator emItr = emIsolColl->begin(); emItr != emIsolColl->end() ;++emItr ) {
148  if ((emItr->et() > l1LowerThr_) and (emItr->et() < l1UpperThr_)) {
149 
150  // Access the GCT hardware object corresponding to the L1Extra EM object.
151  int etaIndex = emItr->gctEmCand()->etaIndex();
152  int phiIndex = emItr->gctEmCand()->phiIndex();
153 
154  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
155  double etaLow = l1CaloGeom->etaBinLowEdge(etaIndex);
156  double etaHigh = l1CaloGeom->etaBinHighEdge(etaIndex);
157  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
158  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
159 
160  etaLow -= regionEtaMargin_;
161  etaHigh += regionEtaMargin_;
162  phiLow -= regionPhiMargin_;
163  phiHigh += regionPhiMargin_;
164 
165  regions.push_back(EcalEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
166  }
167  }
168  }
169 
171  for( l1extra::L1EmParticleCollection::const_iterator emItr = emNonIsolColl->begin(); emItr != emNonIsolColl->end() ;++emItr ) {
172 
173  if(doIsolated_ and (emItr->et() < l1LowerThrIgnoreIsolation_))
174  continue;
175 
176  if ((emItr->et() > l1LowerThr_) and (emItr->et() < l1UpperThr_)) {
177 
178  // Access the GCT hardware object corresponding to the L1Extra EM object.
179  int etaIndex = emItr->gctEmCand()->etaIndex();
180  int phiIndex = emItr->gctEmCand()->phiIndex();
181 
182  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
183  double etaLow = l1CaloGeom->etaBinLowEdge(etaIndex);
184  double etaHigh = l1CaloGeom->etaBinHighEdge(etaIndex);
185  double phiLow = l1CaloGeom->emJetPhiBinLowEdge(phiIndex);
186  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge(phiIndex);
187 
188  etaLow -= regionEtaMargin_;
189  etaHigh += regionEtaMargin_;
190  phiLow -= regionPhiMargin_;
191  phiHigh += regionPhiMargin_;
192 
193  regions.push_back(EcalEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
194  }
195  }
196  }
197  if (useUncalib_) {
199  for (unsigned int i=0; i<hitLabels.size(); i++) {
200  std::auto_ptr<EcalUncalibratedRecHitCollection> uhits(new EcalUncalibratedRecHitCollection);
201 
202  evt.getByToken(uncalibHitTokens[i], urhcH[i]);
203  if (!(urhcH[i].isValid())) {
204  edm::LogError("ProductNotFound")<< "could not get a handle on the EcalRecHitCollection! (" << hitLabels[i].encode() << ")" << std::endl;
205  return;
206  }
207  const EcalUncalibratedRecHitCollection* uncalibRecHits = urhcH[i].product();
208 
209  if (uncalibRecHits->size() == 0)
210  continue;
211 
212  if ((*uncalibRecHits)[0].id().subdetId() == EcalBarrel) {
213  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
214  topology.reset(new EcalBarrelTopology(geoHandle));
215  } else if ((*uncalibRecHits)[0].id().subdetId() == EcalEndcap) {
216  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
217  topology.reset(new EcalEndcapTopology(geoHandle));
218  } else if ((*uncalibRecHits)[0].id().subdetId() == EcalPreshower) {
219  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
220  topology.reset(new EcalPreshowerTopology (geoHandle));
221  } else throw(std::runtime_error("\n\nProducer encountered invalied ecalhitcollection type.\n\n"));
222 
223  if(regions.size() != 0) {
225 
226  for (it = uncalibRecHits->begin(); it != uncalibRecHits->end(); it++){
227  const CaloCellGeometry *this_cell = (*geometry_p).getGeometry(it->id());
228  GlobalPoint position = this_cell->getPosition();
229 
230  std::vector<EcalEtaPhiRegion>::const_iterator region;
231  for (region=regions.begin(); region!=regions.end(); region++) {
232  if (region->inRegion(position))
233  uhits->push_back(*it);
234  }
235  }
236  }
237 
238  evt.put(uhits, productLabels[i]);
239  }
240  } else {
242 
243  for (unsigned int i=0; i<hitLabels.size(); i++) {
244  std::auto_ptr<EcalRecHitCollection> hits(new EcalRecHitCollection);
245 
246  evt.getByToken(hitTokens[i], rhcH[i]);
247  if (!(rhcH[i].isValid())) {
248  edm::LogError("ProductNotFound")<< "could not get a handle on the EcalRecHitCollection! (" << hitLabels[i].encode() << ")" << std::endl;
249  return;
250  }
251  const EcalRecHitCollection* recHits = rhcH[i].product();
252 
253  if (recHits->size() == 0)
254  continue;
255 
256  if ((*recHits)[0].id().subdetId() == EcalBarrel) {
257  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
258  topology.reset(new EcalBarrelTopology(geoHandle));
259  } else if ((*recHits)[0].id().subdetId() == EcalEndcap) {
260  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
261  topology.reset(new EcalEndcapTopology(geoHandle));
262  } else if ((*recHits)[0].id().subdetId() == EcalPreshower) {
263  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
264  topology.reset(new EcalPreshowerTopology (geoHandle));
265  } else throw(std::runtime_error("\n\nProducer encountered invalied ecalhitcollection type.\n\n"));
266 
267  if(regions.size() != 0) {
269  for (it = recHits->begin(); it != recHits->end(); it++){
270  const CaloCellGeometry *this_cell = (*geometry_p).getGeometry(it->id());
271  GlobalPoint position = this_cell->getPosition();
272 
273  std::vector<EcalEtaPhiRegion>::const_iterator region;
274  for (region=regions.begin(); region!=regions.end(); region++) {
275  if (region->inRegion(position))
276  hits->push_back(*it);
277  }
278  }
279  }
280 
281  evt.put(hits, productLabels[i]);
282  }
283  }
284 }
285 
T getParameter(std::string const &) const
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:43
std::vector< edm::EDGetTokenT< EcalUncalibratedRecHitCollection > > uncalibHitTokens
int i
Definition: DBlmapReader.cc:9
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
CaloTopology const * topology(0)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
std::vector< EcalUncalibratedRecHit >::const_iterator const_iterator
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
virtual void produce(edm::Event &, const edm::EventSetup &)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
std::vector< edm::EDGetTokenT< EcalRecHitCollection > > hitTokens
const_iterator end() const
EgammaHLTRechitInRegionsProducer(const edm::ParameterSet &ps)
const T & get() const
Definition: EventSetup.h:55
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
T const * product() const
Definition: Handle.h:81
ESHandle< TrackerGeometry > geometry
size_type size() const
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
const_iterator begin() const