CMS 3D CMS Logo

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 // Class header file
40 
41 template<typename T1>
43  useUncalib_ (ps.getParameter<bool>("useUncalib")),
44  doIsolated_ (ps.getParameter<bool>("doIsolated")),
45  l1TokenIsolated_ (doIsolated_ ? consumes<T1Collection>(ps.getParameter<edm::InputTag>("l1TagIsolated")) : edm::EDGetTokenT<T1Collection>()),
46  l1TokenNonIsolated_(consumes<T1Collection>(ps.getParameter<edm::InputTag>("l1TagNonIsolated"))),
47  l1LowerThr_ (ps.getParameter<double> ("l1LowerThr")),
48  l1UpperThr_ (ps.getParameter<double> ("l1UpperThr")),
49  l1LowerThrIgnoreIsolation_(ps.getParameter<double> ("l1LowerThrIgnoreIsolation")),
50  regionEtaMargin_(ps.getParameter<double>("regionEtaMargin")),
51  regionPhiMargin_(ps.getParameter<double>("regionPhiMargin")),
52  hitLabels (ps.getParameter<std::vector<edm::InputTag>>("ecalhitLabels")),
53  productLabels(ps.getParameter<std::vector<std::string>>("productLabels")) {
54 
55  if (useUncalib_) {
56  for (unsigned int i=0; i<hitLabels.size(); i++) {
57  uncalibHitTokens.push_back(consumes<EcalUncalibratedRecHitCollection>(hitLabels[i]));
58  produces<EcalUncalibratedRecHitCollection>(productLabels[i]);
59  }
60  } else {
61  for (unsigned int i=0; i<hitLabels.size(); i++) {
62  hitTokens.push_back(consumes<EcalRecHitCollection>(hitLabels[i]));
63  produces<EcalRecHitCollection> (productLabels[i]);
64  }
65  }
66 }
67 
68 template<typename T1>
70 {}
71 
72 template<typename T1>
75  std::vector<std::string> productTags;
76  productTags.push_back("EcalRegionalRecHitsEB");
77  productTags.push_back("EcalRegionalRecHitsEE");
78  desc.add<std::vector<std::string>>("productLabels", productTags);
79  std::vector<edm::InputTag> inputTags;
80  inputTags.push_back(edm::InputTag("hltEcalRegionalEgammaRecHit:EcalRecHitsEB"));
81  inputTags.push_back(edm::InputTag("hltEcalRegionalEgammaRecHit:EcalRecHitsEE"));
82  inputTags.push_back(edm::InputTag("hltESRegionalEgammaRecHit:EcalRecHitsES"));
83  desc.add<std::vector<edm::InputTag>>("ecalhitLabels", inputTags);
84  desc.add<edm::InputTag>("l1TagIsolated", edm::InputTag("l1extraParticles","Isolated"));
85  desc.add<edm::InputTag>("l1TagNonIsolated", edm::InputTag("l1extraParticles","NonIsolated"));
86  desc.add<bool>("useUncalib", true);
87  desc.add<bool>("doIsolated", true);
88  desc.add<double>("l1LowerThr", 5.0);
89  desc.add<double>("l1UpperThr", 999.);
90  desc.add<double>("l1LowerThrIgnoreIsolation", 0.0);
91  desc.add<double>("regionEtaMargin", 0.14);
92  desc.add<double>("regionPhiMargin", 0.4);
94 }
95 
96 template<typename T1>
98 
99  // get the collection geometry:
100  edm::ESHandle<CaloGeometry> geoHandle;
101  es.get<CaloGeometryRecord>().get(geoHandle);
102  const CaloGeometry& geometry = *geoHandle;
103  const CaloSubdetectorGeometry *geometry_p;
104  std::unique_ptr<const CaloSubdetectorTopology> topology;
105 
106  //Get the L1 EM Particle Collection
107  edm::Handle< T1Collection > emIsolColl ;
108  if(doIsolated_) {
109  evt.getByToken(l1TokenIsolated_, emIsolColl);
110  }
111 
112  //Get the L1 EM Particle Collection
113  edm::Handle< T1Collection > emNonIsolColl ;
114  evt.getByToken(l1TokenNonIsolated_, emNonIsolColl);
115 
116  // Get the CaloGeometry
117  edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
118  es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
119 
120  std::vector<RectangularEtaPhiRegion> regions;
121  if(doIsolated_) getEtaPhiRegions(&regions, *emIsolColl, *l1CaloGeom, true);
122 
123  if(!doIsolated_ or (l1LowerThrIgnoreIsolation_ < 64)) getEtaPhiRegions(&regions, *emNonIsolColl, *l1CaloGeom, false);
124 
125 
126  if (useUncalib_) {
127 
129  for (unsigned int i=0; i<hitLabels.size(); i++) {
130  auto uhits = std::make_unique<EcalUncalibratedRecHitCollection>();
131 
132  evt.getByToken(uncalibHitTokens[i], urhcH[i]);
133  if (!(urhcH[i].isValid())) {
134  edm::LogError("ProductNotFound")<< "could not get a handle on the EcalRecHitCollection! (" << hitLabels[i].encode() << ")" << std::endl;
135  return;
136  }
137  const EcalUncalibratedRecHitCollection* uncalibRecHits = urhcH[i].product();
138 
139  if (!uncalibRecHits->empty()) {
140  if ((*uncalibRecHits)[0].id().subdetId() == EcalBarrel) {
141  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
142  topology = std::make_unique<EcalBarrelTopology>(geoHandle);
143  } else if ((*uncalibRecHits)[0].id().subdetId() == EcalEndcap) {
144  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
145  topology = std::make_unique<EcalEndcapTopology>(geoHandle);
146  } else if ((*uncalibRecHits)[0].id().subdetId() == EcalPreshower) {
147  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
148  topology = std::make_unique<EcalPreshowerTopology>(geoHandle);
149  } else throw(std::runtime_error("\n\nProducer encountered invalied ecalhitcollection type.\n\n"));
150 
151  if(!regions.empty()) {
153 
154  for (it = uncalibRecHits->begin(); it != uncalibRecHits->end(); it++){
155  auto this_cell = geometry_p->getGeometry(it->id());
156 
157  std::vector<RectangularEtaPhiRegion>::const_iterator region;
158  for (region=regions.begin(); region!=regions.end(); region++) {
159  if (region->inRegion(this_cell->etaPos(),this_cell->phiPos())) {
160  uhits->push_back(*it);
161  break;
162  }
163  }
164  }
165  }
166  }
167  evt.put(std::move(uhits), productLabels[i]);
168 
169  }
170 
171  } else {
172 
174  for (unsigned int i=0; i<hitLabels.size(); i++) {
175  auto hits = std::make_unique<EcalRecHitCollection>();
176 
177  evt.getByToken(hitTokens[i], rhcH[i]);
178  if (!(rhcH[i].isValid())) {
179  edm::LogError("ProductNotFound")<< "could not get a handle on the EcalRecHitCollection! (" << hitLabels[i].encode() << ")" << std::endl;
180  return;
181  }
182  const EcalRecHitCollection* recHits = rhcH[i].product();
183 
184  if (!recHits->empty()) {
185  if ((*recHits)[0].id().subdetId() == EcalBarrel) {
186  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
187  topology = std::make_unique<EcalBarrelTopology>(geoHandle);
188  } else if ((*recHits)[0].id().subdetId() == EcalEndcap) {
189  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
190  topology = std::make_unique<EcalEndcapTopology>(geoHandle);
191  } else if ((*recHits)[0].id().subdetId() == EcalPreshower) {
192  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
193  topology = std::make_unique<EcalPreshowerTopology>(geoHandle);
194  } else throw(std::runtime_error("\n\nProducer encountered invalied ecalhitcollection type.\n\n"));
195 
196  if(!regions.empty()) {
198  for (it = recHits->begin(); it != recHits->end(); it++){
199  auto this_cell = geometry_p->getGeometry(it->id());
200 
201  std::vector<RectangularEtaPhiRegion>::const_iterator region;
202  for (region=regions.begin(); region!=regions.end(); region++) {
203  if (region->inRegion(this_cell->etaPos(),this_cell->phiPos())) {
204  hits->push_back(*it);
205  break;
206  }
207  }
208  }
209  }
210  }
211  evt.put(std::move(hits), productLabels[i]);
212 
213  }
214  }
215 }
216 
217 template<>
218 void HLTRechitInRegionsProducer<l1extra::L1EmParticle>::getEtaPhiRegions(std::vector<RectangularEtaPhiRegion> * theRegions, T1Collection theCandidateCollection, const L1CaloGeometry& l1CaloGeom, bool isolatedCase){
219  for (unsigned int candItr = 0 ; candItr < theCandidateCollection.size(); candItr++){
220  l1extra::L1EmParticle emItr = theCandidateCollection.at(candItr);
221 
222  if (!isolatedCase){
223  if(doIsolated_ and (emItr.et() < l1LowerThrIgnoreIsolation_)) continue;
224  }
225 
226  if ((emItr.et() > l1LowerThr_) and (emItr.et() < l1UpperThr_)) {
227 
228  // Access the GCT hardware object corresponding to the L1Extra EM object.
229  int etaIndex = emItr.gctEmCand()->etaIndex();
230  int phiIndex = emItr.gctEmCand()->phiIndex();
231 
232  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
233  double etaLow = l1CaloGeom.etaBinLowEdge(etaIndex);
234  double etaHigh = l1CaloGeom.etaBinHighEdge(etaIndex);
235  double phiLow = l1CaloGeom.emJetPhiBinLowEdge( phiIndex ) ;
236  double phiHigh = l1CaloGeom.emJetPhiBinHighEdge( phiIndex ) ;
237 
238  etaLow -= regionEtaMargin_;
239  etaHigh += regionEtaMargin_;
240  phiLow -= regionPhiMargin_;
241  phiHigh += regionPhiMargin_;
242 
243 
244 
245  theRegions->push_back(RectangularEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
246  }
247  }
248 }
249 
250 template<typename T1>
251 void HLTRechitInRegionsProducer<T1>::getEtaPhiRegions(std::vector<RectangularEtaPhiRegion> * theRegions, T1Collection theCandidateCollection, const L1CaloGeometry& l1CaloGeom, bool isolatedCase){
252  for (unsigned int candItr = 0 ; candItr < theCandidateCollection.size(); candItr++){
253  T1 emItr = theCandidateCollection.at(candItr);
254  if ((emItr.et() > l1LowerThr_) and (emItr.et() < l1UpperThr_)) {
255 
256  double etaLow = emItr.eta() - regionEtaMargin_;
257  double etaHigh = emItr.eta() + regionEtaMargin_;
258  double phiLow = emItr.phi() - regionPhiMargin_;
259  double phiHigh = emItr.phi() + regionPhiMargin_;
260 
261  theRegions->push_back(RectangularEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
262  }
263  }
264 }
265 
268 
271 
HLTRechitInRegionsProducer(const edm::ParameterSet &ps)
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:44
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
double etaBinHighEdge(unsigned int etaIndex, bool central=true) const
HLTRechitInRegionsProducer< reco::RecoChargedCandidate > MuonHLTRechitInRegionsProducer
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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:519
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
const edm::EDGetTokenT< T1Collection > l1TokenIsolated_
std::string defaultModuleLabel()
std::vector< edm::EDGetTokenT< EcalRecHitCollection > > hitTokens
unsigned phiIndex() const override
get phi index (0-17)
Definition: L1GctEmCand.h:70
unsigned etaIndex() const override
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
double et() const final
transverse energy
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::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
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
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
const T & get() const
Definition: EventSetup.h:59
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void getEtaPhiRegions(std::vector< RectangularEtaPhiRegion > *, T1Collection, const L1CaloGeometry &, bool)
HLT enums.
const edm::EDGetTokenT< T1Collection > l1TokenNonIsolated_
double emJetPhiBinLowEdge(unsigned int phiIndex) const
def move(src, dest)
Definition: eostools.py:510
const_iterator begin() const
std::vector< edm::EDGetTokenT< EcalUncalibratedRecHitCollection > > uncalibHitTokens
double emJetPhiBinHighEdge(unsigned int phiIndex) const