CMS 3D CMS Logo

EgammaHLTIslandClusterProducer.cc
Go to the documentation of this file.
1 // C/C++ headers
2 #include <iostream>
3 #include <vector>
4 #include <memory>
5 
6 // Framework
11 
12 // Reconstruction Classes
17 
18 // Geometry
25 
26 // Level 1 Trigger
29 
30 // EgammaCoreTools
32 
33 // Class header file
35 
37 
39  : doBarrel_ (ps.getParameter<bool>("doBarrel"))
40  , doEndcaps_ (ps.getParameter<bool>("doEndcaps"))
41  , doIsolated_ (ps.getParameter<bool>("doIsolated"))
42 
43  // Parameters to identify the hit collections
44  , barrelHitCollection_ (ps.getParameter<edm::InputTag>("barrelHitProducer"))
45  , endcapHitCollection_ (ps.getParameter<edm::InputTag>("endcapHitProducer"))
46  , barrelHitToken_ (consumes<EcalRecHitCollection>(barrelHitCollection_))
47  , endcapHitToken_ (consumes<EcalRecHitCollection>(endcapHitCollection_))
48 
49  // The names of the produced cluster collections
50  , barrelClusterCollection_ (ps.getParameter<std::string>("barrelClusterCollection"))
51  , endcapClusterCollection_ (ps.getParameter<std::string>("endcapClusterCollection"))
52 
53  // L1 matching parameters
54  , l1TagIsolated_ (consumes<l1extra::L1EmParticleCollection>(ps.getParameter< edm::InputTag > ("l1TagIsolated")))
55  , l1TagNonIsolated_ (consumes<l1extra::L1EmParticleCollection>(ps.getParameter< edm::InputTag > ("l1TagNonIsolated")))
56  , l1LowerThr_ (ps.getParameter<double> ("l1LowerThr"))
57  , l1UpperThr_ (ps.getParameter<double> ("l1UpperThr"))
58  , l1LowerThrIgnoreIsolation_ (ps.getParameter<double> ("l1LowerThrIgnoreIsolation"))
59 
60  , regionEtaMargin_ (ps.getParameter<double>("regionEtaMargin"))
61  , regionPhiMargin_ (ps.getParameter<double>("regionPhiMargin"))
62 
63  // Parameters for the position calculation:
64  , posCalculator_ (PositionCalc( ps.getParameter<edm::ParameterSet>("posCalcParameters") ))
65  // Island algorithm parameters
66  , verb_ (ps.getParameter<std::string>("VerbosityLevel"))
67  , island_p (new IslandClusterAlgo(ps.getParameter<double>("IslandBarrelSeedThr"),
68  ps.getParameter<double>("IslandEndcapSeedThr"),
69  posCalculator_,
70  StringToEnumValue<EcalRecHit::Flags>(ps.getParameter<std::vector<std::string> >("SeedRecHitFlagToBeExcludedEB")),
71  StringToEnumValue<EcalRecHit::Flags>(ps.getParameter<std::vector<std::string> >("SeedRecHitFlagToBeExcludedEE")),
72  StringToEnumValue<EcalRecHit::Flags>(ps.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEB")),
73  StringToEnumValue<EcalRecHit::Flags>(ps.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEE")),
74  verb_ == "DEBUG" ? IslandClusterAlgo::pDEBUG :
75  (verb_ == "WARNING" ? IslandClusterAlgo::pWARNING :
76  (verb_ == "INFO" ? IslandClusterAlgo::pINFO :
77  IslandClusterAlgo::pERROR)))
78  )
79 {
80  // Produces a collection of barrel and a collection of endcap clusters
81  produces< reco::BasicClusterCollection >(endcapClusterCollection_);
82  produces< reco::BasicClusterCollection >(barrelClusterCollection_);
83 }
84 
86  delete island_p;
87 }
88 
90 
92  desc.add<std::string>("VerbosityLevel", "ERROR");
93  desc.add<bool>("doBarrel", true);
94  desc.add<bool>("doEndcaps", true);
95  desc.add<bool>("doIsolated", true);
96  desc.add<edm::InputTag>("barrelHitProducer", edm::InputTag("islandEndcapBasicClusters", "EcalRecHitsEB"));
97  desc.add<edm::InputTag>("endcapHitProducer", edm::InputTag("islandEndcapBasicClusters", "EcalRecHitsEB"));
98  desc.add<std::string>("barrelClusterCollection", "islandBarrelBasicClusters");
99  desc.add<std::string>("endcapClusterCollection", "islandEndcapBasicClusters");
100  desc.add<double>("IslandBarrelSeedThr", 0.5);
101  desc.add<double>("IslandEndcapSeedThr", 0.18);
102  desc.add<edm::InputTag>("l1TagIsolated", edm::InputTag("l1extraParticles","Isolated"));
103  desc.add<edm::InputTag>("l1TagNonIsolated", edm::InputTag("l1extraParticles","NonIsolated"));
104  desc.add<double>("l1LowerThr", 0.0);
105  desc.add<double>("l1UpperThr", 9999.0);
106  desc.add<double>("l1LowerThrIgnoreIsolation", 9999.0);
107  desc.add<double>("regionEtaMargin", 0.3);
108  desc.add<double>("regionPhiMargin", 0.4);
109  //desc.add<edm::ParameterSet>("posCalcParameters"), edm::ParameterSet());
110  desc.add<std::vector<std::string>>("SeedRecHitFlagToBeExcludedEB", {});
111  desc.add<std::vector<std::string>>("SeedRecHitFlagToBeExcludedEE", {});
112  desc.add<std::vector<std::string>>("RecHitFlagToBeExcludedEB", {});
113  desc.add<std::vector<std::string>>("RecHitFlagToBeExcludedEE", {});
114  descriptions.add("hltEgammaHLTIslandClusterProducer", desc);
115 }
116 
118 
119  //Get the L1 EM Particle Collection
121  if(doIsolated_)
122  evt.getByToken(l1TagIsolated_, emIsolColl);
123 
124  //Get the L1 EM Particle Collection
126  evt.getByToken(l1TagNonIsolated_, emNonIsolColl);
127 
128  // Get the CaloGeometry
129  edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
130  es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
131 
132  std::vector<RectangularEtaPhiRegion> barrelRegions;
133  std::vector<RectangularEtaPhiRegion> endcapRegions;
134 
135  if(doIsolated_) {
136  for( l1extra::L1EmParticleCollection::const_iterator emItr = emIsolColl->begin(); emItr != emIsolColl->end() ;++emItr ){
137 
138  if (emItr->et() > l1LowerThr_ && emItr->et() < l1UpperThr_) {
139 
140  // Access the GCT hardware object corresponding to the L1Extra EM object.
141  int etaIndex = emItr->gctEmCand()->etaIndex() ;
142 
143  int phiIndex = emItr->gctEmCand()->phiIndex() ;
144  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
145  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
146  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
147  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
148  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
149 
150  //Attention isForward does not work
151  int isforw=0;
152  int isbarl=0;
153  if((float)(etaHigh)>1.479 || (float)(etaLow)<-1.479) isforw=1;
154  if(((float)(etaLow)>-1.479 && (float)(etaLow)<1.479) ||
155  ((float)(etaHigh)>-1.479 && (float)(etaHigh)<1.479)) isbarl=1;
156 
157  //std::cout<<"Island etaindex "<<etaIndex<<" low hig : "<<etaLow<<" "<<etaHigh<<" phi low hig" <<phiLow<<" " << phiHigh<<" isforw "<<emItr->gctEmCand()->regionId().isForward()<<" isforwnew" <<isforw<< std::endl;
158 
159  etaLow -= regionEtaMargin_;
160  etaHigh += regionEtaMargin_;
161  phiLow -= regionPhiMargin_;
162  phiHigh += regionPhiMargin_;
163 
164  //if (emItr->gctEmCand()->regionId().isForward()) {
165  if (isforw) {
166  if (etaHigh>-1.479 && etaHigh<1.479) etaHigh=-1.479;
167  if ( etaLow>-1.479 && etaLow<1.479) etaLow=1.479;
168  RectangularEtaPhiRegion region(etaLow,etaHigh,phiLow,phiHigh);
169  endcapRegions.push_back(region);
170  }
171  if (isbarl) {
172  if (etaHigh>1.479) etaHigh=1.479;
173  if (etaLow<-1.479) etaLow=-1.479;
174  RectangularEtaPhiRegion region(etaLow,etaHigh,phiLow,phiHigh);
175  barrelRegions.push_back(region);
176  }
177  RectangularEtaPhiRegion region(etaLow,etaHigh,phiLow,phiHigh);
178 
179  }
180  }
181  }
182 
183 
185  for( l1extra::L1EmParticleCollection::const_iterator emItr = emNonIsolColl->begin(); emItr != emNonIsolColl->end() ;++emItr ){
186 
187  if(doIsolated_&&emItr->et()<l1LowerThrIgnoreIsolation_) continue;
188 
189  if (emItr->et() > l1LowerThr_ && emItr->et() < l1UpperThr_) {
190 
191  // Access the GCT hardware object corresponding to the L1Extra EM object.
192  int etaIndex = emItr->gctEmCand()->etaIndex() ;
193 
194 
195  int phiIndex = emItr->gctEmCand()->phiIndex() ;
196  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
197  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
198  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
199  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
200  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
201 
202 
203  int isforw=0;
204  int isbarl=0;
205  if((float)(etaHigh)>1.479 || (float)(etaLow)<-1.479) isforw=1;
206  if(((float)(etaLow)>-1.479 && (float)(etaLow)<1.479) ||
207  ((float)(etaHigh)>-1.479 && (float)(etaHigh)<1.479)) isbarl=1;
208 
209  //std::cout<<"Island etaindex "<<etaIndex<<" low hig : "<<etaLow<<" "<<etaHigh<<" phi low hig" <<phiLow<<" " << phiHigh<<" isforw "<<emItr->gctEmCand()->regionId().isForward()<<" isforwnew" <<isforw<< std::endl;
210 
211  etaLow -= regionEtaMargin_;
212  etaHigh += regionEtaMargin_;
213  phiLow -= regionPhiMargin_;
214  phiHigh += regionPhiMargin_;
215 
216  //if (emItr->gctEmCand()->regionId().isForward()) {
217  if (isforw) {
218  if (etaHigh>-1.479 && etaHigh<1.479) etaHigh=-1.479;
219  if ( etaLow>-1.479 && etaLow<1.479) etaLow=1.479;
220  RectangularEtaPhiRegion region(etaLow,etaHigh,phiLow,phiHigh);
221  endcapRegions.push_back(region);
222  }
223  if (isbarl) {
224  if (etaHigh>1.479) etaHigh=1.479;
225  if (etaLow<-1.479) etaLow=-1.479;
226  RectangularEtaPhiRegion region(etaLow,etaHigh,phiLow,phiHigh);
227  barrelRegions.push_back(region);
228  }
229 
230  }
231  }
232  }
233 
234  if (doEndcaps_
235  //&&endcapRegions.size()!=0
236  ) {
237 
239  }
240  if (doBarrel_
241  //&& barrelRegions.size()!=0
242  ) {
244  }
245 }
246 
247 
250 const {
252  evt.getByToken(hitToken_, rhcHandle);
253  if (!(rhcHandle.isValid()))
254  {
255  std::cout << "could not get a handle on the EcalRecHitCollection!" << std::endl;
256  edm::LogError("EgammaHLTIslandClusterProducerError") << "Error! can't get the product ";
257  return nullptr;
258  }
259  return rhcHandle.product();
260 }
261 
262 
265  const std::string& clusterCollection,
266  const std::vector<RectangularEtaPhiRegion>& regions,
267  const IslandClusterAlgo::EcalPart& ecalPart)
268 const {
269  // get the hit collection from the event:
270  const EcalRecHitCollection *hitCollection_p = getCollection(evt, hitToken);
271 
272  // get the geometry and topology from the event setup:
273  edm::ESHandle<CaloGeometry> geoHandle;
274  es.get<CaloGeometryRecord>().get(geoHandle);
275 
276  const CaloSubdetectorGeometry *geometry_p;
277  CaloSubdetectorTopology *topology_p;
278 
279  if (ecalPart == IslandClusterAlgo::barrel)
280  {
281  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
282  topology_p = new EcalBarrelTopology(geoHandle);
283  }
284  else
285  {
286  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
287  topology_p = new EcalEndcapTopology(geoHandle);
288  }
289 
290  const CaloSubdetectorGeometry *geometryES_p;
291  geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
292 
293  // Run the clusterization algorithm:
295  clusters = island_p->makeClusters(hitCollection_p, geometry_p, topology_p, geometryES_p, ecalPart, true, regions);
296 
297  // create an unique_ptr to a BasicClusterCollection, copy the barrel clusters into it and put in the Event:
298  auto clusters_p = std::make_unique<reco::BasicClusterCollection>();
299  clusters_p->assign(clusters.begin(), clusters.end());
301  if (ecalPart == IslandClusterAlgo::barrel)
302  bccHandle = evt.put(std::move(clusters_p), barrelClusterCollection_);
303  else
304  bccHandle = evt.put(std::move(clusters_p), endcapClusterCollection_);
305 
306  delete topology_p;
307 }
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:49
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
void produce(edm::Event &, const edm::EventSetup &) override
double etaBinHighEdge(unsigned int etaIndex, bool central=true) const
void clusterizeECALPart(edm::Event &evt, const edm::EventSetup &es, const edm::EDGetTokenT< EcalRecHitCollection > &hitToken, const std::string &clusterCollection, const std::vector< RectangularEtaPhiRegion > &regions, const IslandClusterAlgo::EcalPart &ecalPart) const
double etaBinLowEdge(unsigned int etaIndex, bool central=true) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
const EcalRecHitCollection * getCollection(edm::Event &evt, const edm::EDGetTokenT< EcalRecHitCollection > &hitToken) const
const edm::EDGetTokenT< l1extra::L1EmParticleCollection > l1TagIsolated_
EgammaHLTIslandClusterProducer(const edm::ParameterSet &ps)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< reco::BasicCluster > makeClusters(const EcalRecHitCollection *hits, const CaloSubdetectorGeometry *geometry, const CaloSubdetectorTopology *topology_p, const CaloSubdetectorGeometry *geometryES_p, EcalPart ecalPart, bool regional=false, const std::vector< RectangularEtaPhiRegion > &regions=std::vector< RectangularEtaPhiRegion >())
T const * product() const
Definition: Handle.h:81
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
const edm::EDGetTokenT< EcalRecHitCollection > barrelHitToken_
int StringToEnumValue(std::string const &enumConstName)
HLT enums.
T get() const
Definition: EventSetup.h:62
const edm::EDGetTokenT< EcalRecHitCollection > endcapHitToken_
double emJetPhiBinLowEdge(unsigned int phiIndex) const
const edm::EDGetTokenT< l1extra::L1EmParticleCollection > l1TagNonIsolated_
def move(src, dest)
Definition: eostools.py:511
double emJetPhiBinHighEdge(unsigned int phiIndex) const