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 <vector>
3 
4 // Framework
12 
13 // Reconstruction Classes
22 
23 // Geometry
31 
32 // Level 1 Trigger
37 
38 // EgammaCoreTools
40 
41 // Class header file
43 
44 template<typename T1>
46  useUncalib_ (ps.getParameter<bool>("useUncalib")),
47  doIsolated_ (ps.getParameter<bool>("doIsolated")),
48  l1TokenIsolated_ (doIsolated_ ? consumes<T1Collection>(ps.getParameter<edm::InputTag>("l1TagIsolated")) : edm::EDGetTokenT<T1Collection>()),
49  l1TokenNonIsolated_(consumes<T1Collection>(ps.getParameter<edm::InputTag>("l1TagNonIsolated"))),
50  l1LowerThr_ (ps.getParameter<double> ("l1LowerThr")),
51  l1UpperThr_ (ps.getParameter<double> ("l1UpperThr")),
52  l1LowerThrIgnoreIsolation_(ps.getParameter<double> ("l1LowerThrIgnoreIsolation")),
53  regionEtaMargin_(ps.getParameter<double>("regionEtaMargin")),
54  regionPhiMargin_(ps.getParameter<double>("regionPhiMargin")),
55  hitLabels (ps.getParameter<std::vector<edm::InputTag>>("ecalhitLabels")),
56  productLabels(ps.getParameter<std::vector<std::string>>("productLabels")) {
57 
58  if (useUncalib_) {
59  for (unsigned int i=0; i<hitLabels.size(); i++) {
60  uncalibHitTokens.push_back(consumes<EcalUncalibratedRecHitCollection>(hitLabels[i]));
61  produces<EcalUncalibratedRecHitCollection>(productLabels[i]);
62  }
63  } else {
64  for (unsigned int i=0; i<hitLabels.size(); i++) {
65  hitTokens.push_back(consumes<EcalRecHitCollection>(hitLabels[i]));
66  produces<EcalRecHitCollection> (productLabels[i]);
67  }
68  }
69 }
70 
71 template<typename T1>
73 {}
74 
75 template<typename T1>
78  std::vector<std::string> productTags;
79  productTags.push_back("EcalRegionalRecHitsEB");
80  productTags.push_back("EcalRegionalRecHitsEE");
81  desc.add<std::vector<std::string>>("productLabels", productTags);
82  std::vector<edm::InputTag> inputTags;
83  inputTags.push_back(edm::InputTag("hltEcalRegionalEgammaRecHit:EcalRecHitsEB"));
84  inputTags.push_back(edm::InputTag("hltEcalRegionalEgammaRecHit:EcalRecHitsEE"));
85  inputTags.push_back(edm::InputTag("hltESRegionalEgammaRecHit:EcalRecHitsES"));
86  desc.add<std::vector<edm::InputTag>>("ecalhitLabels", inputTags);
87  desc.add<edm::InputTag>("l1TagIsolated", edm::InputTag("l1extraParticles","Isolated"));
88  desc.add<edm::InputTag>("l1TagNonIsolated", edm::InputTag("l1extraParticles","NonIsolated"));
89  desc.add<bool>("useUncalib", true);
90  desc.add<bool>("doIsolated", true);
91  desc.add<double>("l1LowerThr", 5.0);
92  desc.add<double>("l1UpperThr", 999.);
93  desc.add<double>("l1LowerThrIgnoreIsolation", 0.0);
94  desc.add<double>("regionEtaMargin", 0.14);
95  desc.add<double>("regionPhiMargin", 0.4);
97 }
98 
99 template<typename T1>
101 
102  // get the collection geometry:
103  edm::ESHandle<CaloGeometry> geoHandle;
104  es.get<CaloGeometryRecord>().get(geoHandle);
105  const CaloGeometry& geometry = *geoHandle;
106  const CaloSubdetectorGeometry *geometry_p;
107  std::auto_ptr<const CaloSubdetectorTopology> topology;
108 
109  //Get the L1 EM Particle Collection
110  edm::Handle< T1Collection > emIsolColl ;
111  if(doIsolated_) {
112  evt.getByToken(l1TokenIsolated_, emIsolColl);
113  }
114 
115  //Get the L1 EM Particle Collection
116  edm::Handle< T1Collection > emNonIsolColl ;
117  evt.getByToken(l1TokenNonIsolated_, emNonIsolColl);
118 
119  // Get the CaloGeometry
120  edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
121  es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
122 
123  std::vector<EcalEtaPhiRegion> regions;
124  if(doIsolated_) getEtaPhiRegions(&regions, *emIsolColl, *l1CaloGeom, true);
125 
126  if(!doIsolated_ or (l1LowerThrIgnoreIsolation_ < 64)) getEtaPhiRegions(&regions, *emNonIsolColl, *l1CaloGeom, false);
127 
128 
129  if (useUncalib_) {
130 
132  for (unsigned int i=0; i<hitLabels.size(); i++) {
133  std::auto_ptr<EcalUncalibratedRecHitCollection> uhits(new EcalUncalibratedRecHitCollection);
134 
135  evt.getByToken(uncalibHitTokens[i], urhcH[i]);
136  if (!(urhcH[i].isValid())) {
137  edm::LogError("ProductNotFound")<< "could not get a handle on the EcalRecHitCollection! (" << hitLabels[i].encode() << ")" << std::endl;
138  return;
139  }
140  const EcalUncalibratedRecHitCollection* uncalibRecHits = urhcH[i].product();
141 
142  if (uncalibRecHits->size() > 0) {
143  if ((*uncalibRecHits)[0].id().subdetId() == EcalBarrel) {
144  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
145  topology.reset(new EcalBarrelTopology(geoHandle));
146  } else if ((*uncalibRecHits)[0].id().subdetId() == EcalEndcap) {
147  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
148  topology.reset(new EcalEndcapTopology(geoHandle));
149  } else if ((*uncalibRecHits)[0].id().subdetId() == EcalPreshower) {
150  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
151  topology.reset(new EcalPreshowerTopology (geoHandle));
152  } else throw(std::runtime_error("\n\nProducer encountered invalied ecalhitcollection type.\n\n"));
153 
154  if(regions.size() != 0) {
156 
157  for (it = uncalibRecHits->begin(); it != uncalibRecHits->end(); it++){
158  const CaloCellGeometry *this_cell = (*geometry_p).getGeometry(it->id());
159  GlobalPoint position = this_cell->getPosition();
160 
161  std::vector<EcalEtaPhiRegion>::const_iterator region;
162  for (region=regions.begin(); region!=regions.end(); region++) {
163  if (region->inRegion(position)) {
164  uhits->push_back(*it);
165  break;
166  }
167  }
168  }
169  }
170  }
171  evt.put(uhits, productLabels[i]);
172 
173  }
174 
175  } else {
176 
178  for (unsigned int i=0; i<hitLabels.size(); i++) {
179  std::auto_ptr<EcalRecHitCollection> hits(new EcalRecHitCollection);
180 
181  evt.getByToken(hitTokens[i], rhcH[i]);
182  if (!(rhcH[i].isValid())) {
183  edm::LogError("ProductNotFound")<< "could not get a handle on the EcalRecHitCollection! (" << hitLabels[i].encode() << ")" << std::endl;
184  return;
185  }
186  const EcalRecHitCollection* recHits = rhcH[i].product();
187 
188  if (recHits->size() > 0) {
189  if ((*recHits)[0].id().subdetId() == EcalBarrel) {
190  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
191  topology.reset(new EcalBarrelTopology(geoHandle));
192  } else if ((*recHits)[0].id().subdetId() == EcalEndcap) {
193  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
194  topology.reset(new EcalEndcapTopology(geoHandle));
195  } else if ((*recHits)[0].id().subdetId() == EcalPreshower) {
196  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
197  topology.reset(new EcalPreshowerTopology (geoHandle));
198  } else throw(std::runtime_error("\n\nProducer encountered invalied ecalhitcollection type.\n\n"));
199 
200  if(regions.size() != 0) {
202  for (it = recHits->begin(); it != recHits->end(); it++){
203  const CaloCellGeometry *this_cell = (*geometry_p).getGeometry(it->id());
204  GlobalPoint position = this_cell->getPosition();
205 
206  std::vector<EcalEtaPhiRegion>::const_iterator region;
207  for (region=regions.begin(); region!=regions.end(); region++) {
208  if (region->inRegion(position)) {
209  hits->push_back(*it);
210  break;
211  }
212  }
213  }
214  }
215  }
216  evt.put(hits, productLabels[i]);
217 
218  }
219  }
220 }
221 
222 template<>
223 void HLTRechitInRegionsProducer<l1extra::L1EmParticle>::getEtaPhiRegions(std::vector<EcalEtaPhiRegion> * theRegions, T1Collection theCandidateCollection, const L1CaloGeometry& l1CaloGeom, bool isolatedCase){
224  for (unsigned int candItr = 0 ; candItr < theCandidateCollection.size(); candItr++){
225  l1extra::L1EmParticle emItr = theCandidateCollection.at(candItr);
226 
227  if (!isolatedCase){
228  if(doIsolated_ and (emItr.et() < l1LowerThrIgnoreIsolation_)) continue;
229  }
230 
231  if ((emItr.et() > l1LowerThr_) and (emItr.et() < l1UpperThr_)) {
232 
233  // Access the GCT hardware object corresponding to the L1Extra EM object.
234  int etaIndex = emItr.gctEmCand()->etaIndex();
235  int phiIndex = emItr.gctEmCand()->phiIndex();
236 
237  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
238  double etaLow = l1CaloGeom.etaBinLowEdge(etaIndex);
239  double etaHigh = l1CaloGeom.etaBinHighEdge(etaIndex);
240  double phiLow = l1CaloGeom.emJetPhiBinLowEdge( phiIndex ) ;
241  double phiHigh = l1CaloGeom.emJetPhiBinHighEdge( phiIndex ) ;
242 
243  etaLow -= regionEtaMargin_;
244  etaHigh += regionEtaMargin_;
245  phiLow -= regionPhiMargin_;
246  phiHigh += regionPhiMargin_;
247 
248 
249 
250  theRegions->push_back(EcalEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
251  }
252  }
253 }
254 
255 template<typename T1>
256 void HLTRechitInRegionsProducer<T1>::getEtaPhiRegions(std::vector<EcalEtaPhiRegion> * theRegions, T1Collection theCandidateCollection, const L1CaloGeometry& l1CaloGeom, bool isolatedCase){
257  for (unsigned int candItr = 0 ; candItr < theCandidateCollection.size(); candItr++){
258  T1 emItr = theCandidateCollection.at(candItr);
259  if ((emItr.et() > l1LowerThr_) and (emItr.et() < l1UpperThr_)) {
260 
261  double etaLow = emItr.eta() - regionEtaMargin_;
262  double etaHigh = emItr.eta() + regionEtaMargin_;
263  double phiLow = emItr.phi() - regionPhiMargin_;
264  double phiHigh = emItr.phi() + regionPhiMargin_;
265 
266  theRegions->push_back(EcalEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
267  }
268  }
269 }
270 
273 
276 
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
std::string defaultModuleLabel()
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
CaloTopology const * topology(0)
double etaBinLowEdge(unsigned int etaIndex, bool central=true) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
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:121
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)
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:56
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
virtual double et() const final
transverse energy
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