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
20 //#include "DataFormats/EgammaReco/interface/BasicCluster.h"
21 //#include "DataFormats/EgammaReco/interface/SuperCluster.h"
22 //#include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
27 
28 // Geometry
36 
37 
38 // Level 1 Trigger
43 
44 // EgammaCoreTools
45 //#include "RecoEcal/EgammaCoreTools/interface/PositionCalc.h"
47 
48 // Class header file
50 
51 
53 
54  hitproducer_ = ps.getParameter<edm::InputTag>("ecalhitproducer");
55 
56  l1TagIsolated_ = ps.getParameter< edm::InputTag > ("l1TagIsolated");
57  l1TagNonIsolated_ = ps.getParameter< edm::InputTag > ("l1TagNonIsolated");
58  doIsolated_ = ps.getParameter<bool>("doIsolated");
59 
60  l1LowerThr_ = ps.getParameter<double> ("l1LowerThr");
61  l1UpperThr_ = ps.getParameter<double> ("l1UpperThr");
62  l1LowerThrIgnoreIsolation_ = ps.getParameter<double> ("l1LowerThrIgnoreIsolation");
63 
64  regionEtaMargin_ = ps.getParameter<double>("regionEtaMargin");
65  regionPhiMargin_ = ps.getParameter<double>("regionPhiMargin");
66 
67  const std::vector<std::string> flagnames = ps.getParameter<std::vector<std::string> >("RecHitFlagToBeExcluded");
68  const std::vector<int> flagsexcl = StringToEnumValue<EcalRecHit::Flags>(flagnames);
69 
70  const std::vector<std::string> severitynames = ps.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcluded");
71  const std::vector<int> severitiesexcl = StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynames);
72 
73  hitLabels = ps.getParameter<std::vector<edm::InputTag>>("ecalhitLabels");
74  for (unsigned int i=0; i<hitLabels.size(); i++)
75  hitTokens.push_back(consumes<EcalRecHitCollection>(hitLabels[i]));
76 
77  produces<EcalRecHitCollection> ("EcalRegionalRecHitsEB");
78  produces<EcalRecHitCollection> ("EcalRegionalRecHitsEE");
79  produces<EcalRecHitCollection> ("EcalRegionalRecHitsES");
80 
81  nEvt_ = 0;
82 }
83 
84 
86 {}
87 
90  std::vector<edm::InputTag> inputTags;
91  inputTags.push_back(edm::InputTag("hltEcalRegionalEgammaRecHit:EcalRecHitsEB"));
92  inputTags.push_back(edm::InputTag("hltEcalRegionalEgammaRecHit:EcalRecHitsEE"));
93  inputTags.push_back(edm::InputTag("hltESRegionalEgammaRecHit:EcalRecHitsES"));
94  desc.add<std::vector<edm::InputTag>>("ecalhitLabels", inputTags);
95  desc.add<edm::InputTag>("ecalhitproducer", edm::InputTag("ecalRecHit"));
96  desc.add<edm::InputTag>("l1TagIsolated", edm::InputTag("l1extraParticles","Isolated"));
97  desc.add<edm::InputTag>("l1TagNonIsolated", edm::InputTag("l1extraParticles","NonIsolated"));
98  desc.add<bool>("doIsolated", true);
99  desc.add<double>("l1LowerThr", 5.0);
100  desc.add<double>("l1UpperThr", 999.);
101  desc.add<double>("l1LowerThrIgnoreIsolation", 0.0);
102  desc.add<double>("regionEtaMargin", 0.14);
103  desc.add<double>("regionPhiMargin", 0.4);
104  desc.add<std::vector<std::string> >("RecHitFlagToBeExcluded", std::vector<std::string>());
105  desc.add<std::vector<std::string> >("RecHitSeverityToBeExcluded", std::vector<std::string>());
106  descriptions.add(("hltEgammaHLTRechitInRegionsProducer"), desc);
107 }
108 
110 
111  std::auto_ptr<EcalRecHitCollection> hitsEB(new EcalRecHitCollection);
112  std::auto_ptr<EcalRecHitCollection> hitsEE(new EcalRecHitCollection);
113  std::auto_ptr<EcalRecHitCollection> hitsES(new EcalRecHitCollection);
114 
116 
117  for (unsigned int i=0; i<hitLabels.size(); i++) {
118  evt.getByToken(hitTokens[i], rhcH[i]);
119  if (!(rhcH[i].isValid())) {
120  edm::LogError("ProductNotFound")<< "could not get a handle on the EcalRecHitCollection! (" << hitLabels[i].encode() << ")" << std::endl;
121  return;
122  }
123  }
124 
125  // get the collection geometry:
126  edm::ESHandle<CaloGeometry> geoHandle;
127  es.get<CaloGeometryRecord>().get(geoHandle);
128  const CaloGeometry& geometry = *geoHandle;
129  const CaloSubdetectorGeometry *geometry_p;
130  std::auto_ptr<const CaloSubdetectorTopology> topology;
131 
132  //edm::ESHandle<EcalSeverityLevelAlgo> sevlv;
133  //es.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
134  //const EcalSeverityLevelAlgo* sevLevel = sevlv.product();
135 
136  //Get the L1 EM Particle Collection
137  //Get the L1 EM Particle Collection
139  if(doIsolated_)
140  evt.getByLabel(l1TagIsolated_, emIsolColl);
141 
142  //Get the L1 EM Particle Collection
144  evt.getByLabel(l1TagNonIsolated_, emNonIsolColl);
145 
146  // Get the CaloGeometry
147  edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
148  es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
149 
150  std::vector<EcalEtaPhiRegion> regions;
151 
152  if(doIsolated_) {
153  for( l1extra::L1EmParticleCollection::const_iterator emItr = emIsolColl->begin(); emItr != emIsolColl->end() ;++emItr ) {
154  if ((emItr->et() > l1LowerThr_) and (emItr->et() < l1UpperThr_)) {
155 
156  // Access the GCT hardware object corresponding to the L1Extra EM object.
157  int etaIndex = emItr->gctEmCand()->etaIndex();
158  int phiIndex = emItr->gctEmCand()->phiIndex();
159 
160  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
161  double etaLow = l1CaloGeom->etaBinLowEdge(etaIndex);
162  double etaHigh = l1CaloGeom->etaBinHighEdge(etaIndex);
163  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
164  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
165 
166  etaLow -= regionEtaMargin_;
167  etaHigh += regionEtaMargin_;
168  phiLow -= regionPhiMargin_;
169  phiHigh += regionPhiMargin_;
170 
171  regions.push_back(EcalEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
172  }
173  }
174  }
175 
177  for( l1extra::L1EmParticleCollection::const_iterator emItr = emNonIsolColl->begin(); emItr != emNonIsolColl->end() ;++emItr ) {
178 
179  if(doIsolated_ and (emItr->et() < l1LowerThrIgnoreIsolation_))
180  continue;
181 
182  if ((emItr->et() > l1LowerThr_) and (emItr->et() < l1UpperThr_)) {
183 
184  // Access the GCT hardware object corresponding to the L1Extra EM object.
185  int etaIndex = emItr->gctEmCand()->etaIndex();
186  int phiIndex = emItr->gctEmCand()->phiIndex();
187 
188  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
189  double etaLow = l1CaloGeom->etaBinLowEdge(etaIndex);
190  double etaHigh = l1CaloGeom->etaBinHighEdge(etaIndex);
191  double phiLow = l1CaloGeom->emJetPhiBinLowEdge(phiIndex);
192  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge(phiIndex);
193 
194  etaLow -= regionEtaMargin_;
195  etaHigh += regionEtaMargin_;
196  phiLow -= regionPhiMargin_;
197  phiHigh += regionPhiMargin_;
198 
199  regions.push_back(EcalEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
200  }
201  }
202  }
203 
204  for (unsigned int i=0; i<hitLabels.size(); i++) {
205  const EcalRecHitCollection *recHits = rhcH[i].product();
206  if(hitLabels[i].encode() == "hltEcalRegionalEgammaRecHit:EcalRecHitsEB") {
207  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
208  topology.reset(new EcalBarrelTopology(geoHandle));
209  } else if(hitLabels[i].encode() == "hltEcalRegionalEgammaRecHit:EcalRecHitsEE") {
210  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
211  topology.reset(new EcalEndcapTopology(geoHandle));
212  } else if(hitLabels[i].encode() == "hltESRegionalEgammaRecHit:EcalRecHitsES") {
213  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
214  topology.reset(new EcalPreshowerTopology (geoHandle));
215  } else throw(std::runtime_error("\n\nProducer encountered invalied ecalhitcollection type.\n\n"));
216 
217  if(regions.size() != 0) {
219 
220  for (it = recHits->begin(); it != recHits->end(); it++){
221  //Make the vector of seeds that we're going to use.
222  //One of the few places position is used, needed for ET calculation.
223  const CaloCellGeometry *this_cell = (*geometry_p).getGeometry(it->id());
224  GlobalPoint position = this_cell->getPosition();
225 
226  std::vector<EcalEtaPhiRegion>::const_iterator region;
227  for (region=regions.begin(); region!=regions.end(); region++) {
228  //std::cout << region->etaLow() << " " << region->etaHigh() << " " << region->phiLow() << " " << region->phiHigh() << std::endl;
229  //std::cout << i << " - " << position.eta() << " " << position.phi() << std::endl;
230  if (region->inRegion(position)) {
231  if (i == 0)
232  hitsEB->push_back(*it);
233  if (i == 1)
234  hitsEE->push_back(*it);
235  if (i == 2)
236  hitsES->push_back(*it);
237  }
238  }
239  }
240  }
241  }
242 
243  //std::cout << hitsEB->size() << " " << hitsEE->size() << " " << hitsES->size() << std::endl;
244  evt.put(hitsEB, "EcalRegionalRecHitsEB");
245  evt.put(hitsEE, "EcalRegionalRecHitsEE");
246  evt.put(hitsES, "EcalRegionalRecHitsES");
247 
248  nEvt_++;
249 }
250 
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
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
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
std::vector< EcalRecHit >::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
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
const_iterator begin() const