CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTRechitInRegionsProducer.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 
52 template<typename T1>
54  useUncalib_ (ps.getParameter<bool>("useUncalib")),
55  l1TagIsolated_ (ps.getParameter< edm::InputTag > ("l1TagIsolated")),
56  l1TagNonIsolated_(ps.getParameter< edm::InputTag > ("l1TagNonIsolated")),
57  doIsolated_ (ps.getParameter<bool>("doIsolated")),
58  l1LowerThr_ (ps.getParameter<double> ("l1LowerThr")),
59  l1UpperThr_ (ps.getParameter<double> ("l1UpperThr")),
60  l1LowerThrIgnoreIsolation_(ps.getParameter<double> ("l1LowerThrIgnoreIsolation")),
61  regionEtaMargin_(ps.getParameter<double>("regionEtaMargin")),
62  regionPhiMargin_(ps.getParameter<double>("regionPhiMargin")),
63  hitLabels (ps.getParameter<std::vector<edm::InputTag>>("ecalhitLabels")),
64  productLabels(ps.getParameter<std::vector<std::string>>("productLabels")) {
65  if (useUncalib_) {
66  for (unsigned int i=0; i<hitLabels.size(); i++) {
67  uncalibHitTokens.push_back(consumes<EcalUncalibratedRecHitCollection>(hitLabels[i]));
68  produces<EcalUncalibratedRecHitCollection>(productLabels[i]);
69  }
70  } else {
71  for (unsigned int i=0; i<hitLabels.size(); i++) {
72  hitTokens.push_back(consumes<EcalRecHitCollection>(hitLabels[i]));
73  produces<EcalRecHitCollection> (productLabels[i]);
74  }
75  }
76 }
77 
78 
79 
80 template<typename T1>
82 {}
83 
84 template<typename T1>
87  std::vector<std::string> productTags;
88  productTags.push_back("EcalRegionalRecHitsEB");
89  productTags.push_back("EcalRegionalRecHitsEE");
90  desc.add<std::vector<std::string>>("productLabels", productTags);
91  std::vector<edm::InputTag> inputTags;
92  inputTags.push_back(edm::InputTag("hltEcalRegionalEgammaRecHit:EcalRecHitsEB"));
93  inputTags.push_back(edm::InputTag("hltEcalRegionalEgammaRecHit:EcalRecHitsEE"));
94  inputTags.push_back(edm::InputTag("hltESRegionalEgammaRecHit:EcalRecHitsES"));
95  desc.add<std::vector<edm::InputTag>>("ecalhitLabels", inputTags);
96  //desc.add<edm::InputTag>("ecalhitproducer", edm::InputTag("ecalRecHit"));
97  desc.add<edm::InputTag>("l1TagIsolated", edm::InputTag("l1extraParticles","Isolated"));
98  desc.add<edm::InputTag>("l1TagNonIsolated", edm::InputTag("l1extraParticles","NonIsolated"));
99  desc.add<bool>("useUncalib", true);
100  desc.add<bool>("doIsolated", true);
101  desc.add<double>("l1LowerThr", 5.0);
102  desc.add<double>("l1UpperThr", 999.);
103  desc.add<double>("l1LowerThrIgnoreIsolation", 0.0);
104  desc.add<double>("regionEtaMargin", 0.14);
105  desc.add<double>("regionPhiMargin", 0.4);
106  descriptions.add(std::string("hlt")+std::string(typeid(HLTRechitInRegionsProducer<T1>).name()), desc);
107 }
108 
109 template<typename T1>
111 
112  // get the collection geometry:
113  edm::ESHandle<CaloGeometry> geoHandle;
114  es.get<CaloGeometryRecord>().get(geoHandle);
115  const CaloGeometry& geometry = *geoHandle;
116  const CaloSubdetectorGeometry *geometry_p;
117  std::auto_ptr<const CaloSubdetectorTopology> topology;
118 
119  //Get the L1 EM Particle Collection
120  edm::Handle< T1Collection > emIsolColl ;
121  if(doIsolated_)
122  evt.getByLabel(l1TagIsolated_, emIsolColl);
123 
124  //Get the L1 EM Particle Collection
125  edm::Handle< T1Collection > emNonIsolColl ;
126  evt.getByLabel(l1TagNonIsolated_, emNonIsolColl);
127 
128  // Get the CaloGeometry
129  edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
130  es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
131 
132  std::vector<EcalEtaPhiRegion> regions;
133  if(doIsolated_) getEtaPhiRegions(&regions, *emIsolColl, *l1CaloGeom, true);
134 
135  if(!doIsolated_ or (l1LowerThrIgnoreIsolation_ < 64)) getEtaPhiRegions(&regions, *emNonIsolColl, *l1CaloGeom, false);
136 
137 
138  if (useUncalib_) {
139 
141  for (unsigned int i=0; i<hitLabels.size(); i++) {
142  std::auto_ptr<EcalUncalibratedRecHitCollection> uhits(new EcalUncalibratedRecHitCollection);
143 
144  evt.getByToken(uncalibHitTokens[i], urhcH[i]);
145  if (!(urhcH[i].isValid())) {
146  edm::LogError("ProductNotFound")<< "could not get a handle on the EcalRecHitCollection! (" << hitLabels[i].encode() << ")" << std::endl;
147  return;
148  }
149  const EcalUncalibratedRecHitCollection* uncalibRecHits = urhcH[i].product();
150 
151  if (uncalibRecHits->size() > 0) {
152  if ((*uncalibRecHits)[0].id().subdetId() == EcalBarrel) {
153  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
154  topology.reset(new EcalBarrelTopology(geoHandle));
155  } else if ((*uncalibRecHits)[0].id().subdetId() == EcalEndcap) {
156  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
157  topology.reset(new EcalEndcapTopology(geoHandle));
158  } else if ((*uncalibRecHits)[0].id().subdetId() == EcalPreshower) {
159  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
160  topology.reset(new EcalPreshowerTopology (geoHandle));
161  } else throw(std::runtime_error("\n\nProducer encountered invalied ecalhitcollection type.\n\n"));
162 
163  if(regions.size() != 0) {
165 
166  for (it = uncalibRecHits->begin(); it != uncalibRecHits->end(); it++){
167  const CaloCellGeometry *this_cell = (*geometry_p).getGeometry(it->id());
168  GlobalPoint position = this_cell->getPosition();
169 
170  std::vector<EcalEtaPhiRegion>::const_iterator region;
171  for (region=regions.begin(); region!=regions.end(); region++) {
172  if (region->inRegion(position))
173  uhits->push_back(*it);
174  }
175  }
176  }
177  }
178  evt.put(uhits, productLabels[i]);
179 
180  }
181 
182  } else {
183 
185  for (unsigned int i=0; i<hitLabels.size(); i++) {
186  std::auto_ptr<EcalRecHitCollection> hits(new EcalRecHitCollection);
187 
188  evt.getByToken(hitTokens[i], rhcH[i]);
189  if (!(rhcH[i].isValid())) {
190  edm::LogError("ProductNotFound")<< "could not get a handle on the EcalRecHitCollection! (" << hitLabels[i].encode() << ")" << std::endl;
191  return;
192  }
193  const EcalRecHitCollection* recHits = rhcH[i].product();
194 
195  if (recHits->size() > 0) {
196  if ((*recHits)[0].id().subdetId() == EcalBarrel) {
197  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
198  topology.reset(new EcalBarrelTopology(geoHandle));
199  } else if ((*recHits)[0].id().subdetId() == EcalEndcap) {
200  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
201  topology.reset(new EcalEndcapTopology(geoHandle));
202  } else if ((*recHits)[0].id().subdetId() == EcalPreshower) {
203  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
204  topology.reset(new EcalPreshowerTopology (geoHandle));
205  } else throw(std::runtime_error("\n\nProducer encountered invalied ecalhitcollection type.\n\n"));
206 
207  if(regions.size() != 0) {
209  for (it = recHits->begin(); it != recHits->end(); it++){
210  const CaloCellGeometry *this_cell = (*geometry_p).getGeometry(it->id());
211  GlobalPoint position = this_cell->getPosition();
212 
213  std::vector<EcalEtaPhiRegion>::const_iterator region;
214  for (region=regions.begin(); region!=regions.end(); region++) {
215  if (region->inRegion(position))
216  hits->push_back(*it);
217  }
218  }
219  }
220  }
221  evt.put(hits, productLabels[i]);
222 
223  }
224  }
225 }
226 
227 template<>
228 void HLTRechitInRegionsProducer<l1extra::L1EmParticle>::getEtaPhiRegions(std::vector<EcalEtaPhiRegion> * theRegions, T1Collection theCandidateCollection, const L1CaloGeometry& l1CaloGeom, bool isolatedCase){
229  for (unsigned int candItr = 0 ; candItr < theCandidateCollection.size(); candItr++){
230  l1extra::L1EmParticle emItr = theCandidateCollection.at(candItr);
231 
232  if (!isolatedCase){
233  if(doIsolated_ and (emItr.et() < l1LowerThrIgnoreIsolation_)) continue;
234  }
235 
236  if ((emItr.et() > l1LowerThr_) and (emItr.et() < l1UpperThr_)) {
237 
238  // Access the GCT hardware object corresponding to the L1Extra EM object.
239  int etaIndex = emItr.gctEmCand()->etaIndex();
240  int phiIndex = emItr.gctEmCand()->phiIndex();
241 
242  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
243  double etaLow = l1CaloGeom.etaBinLowEdge(etaIndex);
244  double etaHigh = l1CaloGeom.etaBinHighEdge(etaIndex);
245  double phiLow = l1CaloGeom.emJetPhiBinLowEdge( phiIndex ) ;
246  double phiHigh = l1CaloGeom.emJetPhiBinHighEdge( phiIndex ) ;
247 
248  etaLow -= regionEtaMargin_;
249  etaHigh += regionEtaMargin_;
250  phiLow -= regionPhiMargin_;
251  phiHigh += regionPhiMargin_;
252 
253 
254 
255  theRegions->push_back(EcalEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
256  }
257  }
258 }
259 
260 template<typename T1>
261 void HLTRechitInRegionsProducer<T1>::getEtaPhiRegions(std::vector<EcalEtaPhiRegion> * theRegions, T1Collection theCandidateCollection, const L1CaloGeometry& l1CaloGeom, bool isolatedCase){
262  for (unsigned int candItr = 0 ; candItr < theCandidateCollection.size(); candItr++){
263  T1 emItr = theCandidateCollection.at(candItr);
264  if ((emItr.et() > l1LowerThr_) and (emItr.et() < l1UpperThr_)) {
265 
266  double etaLow = emItr.eta() - regionEtaMargin_;
267  double etaHigh = emItr.eta() + regionEtaMargin_;
268  double phiLow = emItr.phi() - regionPhiMargin_;
269  double phiHigh = emItr.phi() + regionPhiMargin_;
270 
271  theRegions->push_back(EcalEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
272  }
273  }
274 }
275 
278 
281 
HLTRechitInRegionsProducer(const edm::ParameterSet &ps)
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:43
int i
Definition: DBlmapReader.cc:9
double etaBinHighEdge(unsigned int etaIndex, bool central=true) const
HLTRechitInRegionsProducer< reco::RecoChargedCandidate > MuonHLTRechitInRegionsProducer
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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
const std::vector< edm::InputTag > hitLabels
virtual double et() const
transverse energy
CaloTopology const * topology(0)
double etaBinLowEdge(unsigned int etaIndex, bool central=true) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
HLTRechitInRegionsProducer< l1extra::L1EmParticle > EgammaHLTRechitInRegionsProducer
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const std::vector< std::string > productLabels
std::vector< EcalUncalibratedRecHit >::const_iterator const_iterator
const L1GctEmCand * gctEmCand() const
Definition: L1EmParticle.h:68
unsigned phiIndex() const
get phi index (0-17)
Definition: L1GctEmCand.h:70
std::vector< edm::EDGetTokenT< EcalRecHitCollection > > hitTokens
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
unsigned etaIndex() const
get eta index -6 to -0, +0 to +6 (bit 3 is sign, 1 for -ve Z, 0 for +ve Z)
Definition: L1GctEmCand.h:64
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:402
const_iterator end() const
void produce(edm::Event &, const edm::EventSetup &) override
T const * product() const
Definition: Handle.h:81
const T & get() const
Definition: EventSetup.h:55
void add(std::string const &label, ParameterSetDescription const &psetDescription)
ESHandle< TrackerGeometry > geometry
size_type size() const
static int position[264][3]
Definition: ReadPGInfo.cc:509
double emJetPhiBinLowEdge(unsigned int phiIndex) const
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
void getEtaPhiRegions(std::vector< EcalEtaPhiRegion > *, T1Collection, const L1CaloGeometry &, bool)
const_iterator begin() const
std::vector< edm::EDGetTokenT< EcalUncalibratedRecHitCollection > > uncalibHitTokens
double emJetPhiBinHighEdge(unsigned int phiIndex) const