CMS 3D CMS Logo

EgammaHLTMulti5x5ClusterProducer.cc
Go to the documentation of this file.
1 // C/C++ headers
2 #include <iostream>
3 #include <vector>
4 #include <memory>
5 
10 
11 // Reconstruction Classes
16 
17 // Geometry
24 
25 // Level 1 Trigger
30 
31 // EgammaCoreTools
33 
34 // Class header file
36 
38 
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  // Multi5x5 algorithm parameters
54  double barrelSeedThreshold = ps.getParameter<double>("Multi5x5BarrelSeedThr");
55  double endcapSeedThreshold = ps.getParameter<double>("Multi5x5EndcapSeedThr");
56 
57  // L1 matching parameters
58  l1TagIsolated_ = consumes<l1extra::L1EmParticleCollection>(ps.getParameter< edm::InputTag > ("l1TagIsolated"));
59  l1TagNonIsolated_ = consumes<l1extra::L1EmParticleCollection>(ps.getParameter< edm::InputTag > ("l1TagNonIsolated"));
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  // Parameters for the position calculation:
68  posCalculator_ = PositionCalc( ps.getParameter<edm::ParameterSet>("posCalcParameters") );
69 
70  const std::vector<std::string> flagnames =
71  ps.getParameter<std::vector<std::string> >("RecHitFlagToBeExcluded");
72 
73  // exclude recHit flags from seeding
74  std::vector<int> v_chstatus = StringToEnumValue<EcalRecHit::Flags>(flagnames);
75 
76  // Produces a collection of barrel and a collection of endcap clusters
77  produces< reco::BasicClusterCollection >(endcapClusterCollection_);
78  produces< reco::BasicClusterCollection >(barrelClusterCollection_);
79 
80  Multi5x5_p = new Multi5x5ClusterAlgo(barrelSeedThreshold, endcapSeedThreshold, v_chstatus, posCalculator_);
81 }
82 
84  delete Multi5x5_p;
85 }
86 
88 
90  desc.add<bool>(("doBarrel"), false);
91  desc.add<bool>(("doEndcaps"), true);
92  desc.add<bool>(("doIsolated"), true);
93  desc.add<std::string>("VerbosityLevel" ,"ERROR");
94 
95  edm::ParameterSetDescription posCalcPSET;
96  posCalcPSET.add<double>("T0_barl", 7.4);
97  posCalcPSET.add<double>("T0_endc", 3.1);
98  posCalcPSET.add<double>("T0_endcPresh", 1.2);
99  posCalcPSET.add<double>("W0", 4.2);
100  posCalcPSET.add<double>("X0", 0.89);
101  posCalcPSET.add<bool>("LogWeighted", true);
102  desc.add<edm::ParameterSetDescription>("posCalcParameters", posCalcPSET);
103 
104  desc.add<edm::InputTag>(("barrelHitProducer"), edm::InputTag("hltEcalRegionalEgammaRecHit", "EcalRecHitsEB"));
105  desc.add<edm::InputTag>(("endcapHitProducer"), edm::InputTag("hltEcalRegionalEgammaRecHit", "EcalRecHitsEE"));
106  desc.add<std::string>(("barrelClusterCollection"), "notused");
107  desc.add<std::string>(("endcapClusterCollection"), "multi5x5EndcapBasicClusters");
108  desc.add<double>(("Multi5x5BarrelSeedThr"), 0.5);
109  desc.add<double>(("Multi5x5EndcapSeedThr"), 0.5);
110  desc.add<edm::InputTag>(("l1TagIsolated"), edm::InputTag("hltL1extraParticles","Isolated"));
111  desc.add<edm::InputTag>(("l1TagNonIsolated"), edm::InputTag("hltL1extraParticles","NonIsolated"));
112  desc.add<double>(("l1LowerThr"), 5.0);
113  desc.add<double>(("l1UpperThr"), 9999.);
114  desc.add<double>(("l1LowerThrIgnoreIsolation"), 999.0);
115  desc.add<double>(("regionEtaMargin"), 0.3);
116  desc.add<double>(("regionPhiMargin"), 0.4);
117 
118  desc.add<std::vector<std::string> >(("RecHitFlagToBeExcluded"), std::vector<std::string>());
119  descriptions.add(("hltEgammaHLTMulti5x5ClusterProducer"), desc);
120 }
121 
123 
124  //Get the L1 EM Particle Collection
126  if(doIsolated_)
127  evt.getByToken(l1TagIsolated_, emIsolColl);
128 
129  //Get the L1 EM Particle Collection
131  evt.getByToken(l1TagNonIsolated_, emNonIsolColl);
132 
133  // Get the CaloGeometry
134  edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
135  es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
136 
137  std::vector<RectangularEtaPhiRegion> barrelRegions;
138  std::vector<RectangularEtaPhiRegion> endcapRegions;
139 
140  if(doIsolated_) {
141  for( l1extra::L1EmParticleCollection::const_iterator emItr = emIsolColl->begin(); emItr != emIsolColl->end() ;++emItr ){
142 
143  if (emItr->et() > l1LowerThr_ && emItr->et() < l1UpperThr_) {
144 
145  // Access the GCT hardware object corresponding to the L1Extra EM object.
146  int etaIndex = emItr->gctEmCand()->etaIndex() ;
147 
148 
149  int phiIndex = emItr->gctEmCand()->phiIndex() ;
150  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
151  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
152  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
153  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
154  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
155 
156  //Attention isForward does not work
157  int isforw=0;
158  int isbarl=0;
159  if((float)(etaHigh)>1.479 || (float)(etaLow)<-1.479) isforw=1;
160  if(((float)(etaLow)>-1.479 && (float)(etaLow)<1.479) ||
161  ((float)(etaHigh)>-1.479 && (float)(etaHigh)<1.479)) isbarl=1;
162 
163  //std::cout<<"Multi5x5 etaindex "<<etaIndex<<" low hig : "<<etaLow<<" "<<etaHigh<<" phi low hig" <<phiLow<<" " << phiHigh<<" isforw "<<emItr->gctEmCand()->regionId().isForward()<<" isforwnew" <<isforw<< std::endl;
164 
165  etaLow -= regionEtaMargin_;
166  etaHigh += regionEtaMargin_;
167  phiLow -= regionPhiMargin_;
168  phiHigh += regionPhiMargin_;
169 
170  //if (emItr->gctEmCand()->regionId().isForward()) {
171  if (isforw) {
172  if (etaHigh>-1.479 && etaHigh<1.479) etaHigh=-1.479;
173  if ( etaLow>-1.479 && etaLow<1.479) etaLow=1.479;
174  RectangularEtaPhiRegion region(etaLow,etaHigh,phiLow,phiHigh);
175  endcapRegions.push_back(region);
176  }
177  if (isbarl) {
178  if (etaHigh>1.479) etaHigh=1.479;
179  if (etaLow<-1.479) etaLow=-1.479;
180  RectangularEtaPhiRegion region(etaLow,etaHigh,phiLow,phiHigh);
181  barrelRegions.push_back(region);
182  }
183  RectangularEtaPhiRegion region(etaLow,etaHigh,phiLow,phiHigh);
184 
185  }
186  }
187  }
188 
189 
191  for( l1extra::L1EmParticleCollection::const_iterator emItr = emNonIsolColl->begin(); emItr != emNonIsolColl->end() ;++emItr ){
192 
193  if(doIsolated_&&emItr->et()<l1LowerThrIgnoreIsolation_) continue;
194 
195  if (emItr->et() > l1LowerThr_ && emItr->et() < l1UpperThr_) {
196 
197  // Access the GCT hardware object corresponding to the L1Extra EM object.
198  int etaIndex = emItr->gctEmCand()->etaIndex() ;
199 
200 
201  int phiIndex = emItr->gctEmCand()->phiIndex() ;
202  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
203  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
204  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
205  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
206  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
207 
208 
209  int isforw=0;
210  int isbarl=0;
211  if((float)(etaHigh)>1.479 || (float)(etaLow)<-1.479) isforw=1;
212  if(((float)(etaLow)>-1.479 && (float)(etaLow)<1.479) ||
213  ((float)(etaHigh)>-1.479 && (float)(etaHigh)<1.479)) isbarl=1;
214 
215  //std::cout<<"Multi5x5 etaindex "<<etaIndex<<" low hig : "<<etaLow<<" "<<etaHigh<<" phi low hig" <<phiLow<<" " << phiHigh<<" isforw "<<emItr->gctEmCand()->regionId().isForward()<<" isforwnew" <<isforw<< std::endl;
216 
217  etaLow -= regionEtaMargin_;
218  etaHigh += regionEtaMargin_;
219  phiLow -= regionPhiMargin_;
220  phiHigh += regionPhiMargin_;
221 
222  //if (emItr->gctEmCand()->regionId().isForward()) {
223  if (isforw) {
224  if (etaHigh>-1.479 && etaHigh<1.479) etaHigh=-1.479;
225  if ( etaLow>-1.479 && etaLow<1.479) etaLow=1.479;
226  RectangularEtaPhiRegion region(etaLow,etaHigh,phiLow,phiHigh);
227  endcapRegions.push_back(region);
228  }
229  if (isbarl) {
230  if (etaHigh>1.479) etaHigh=1.479;
231  if (etaLow<-1.479) etaLow=-1.479;
232  RectangularEtaPhiRegion region(etaLow,etaHigh,phiLow,phiHigh);
233  barrelRegions.push_back(region);
234  }
235 
236  }
237  }
238  }
239 
240 
241  if (doEndcaps_) {
243  }
244  if (doBarrel_) {
246  }
247 }
248 
249 
251  const edm::EDGetTokenT<EcalRecHitCollection>& hitToken) const {
252 
254  evt.getByToken(hitToken, rhcHandle);
255 
256  if (!(rhcHandle.isValid()))
257  {
258  std::cout << "could not get a handle on the EcalRecHitCollection!" << std::endl;
259  edm::LogError("EgammaHLTMulti5x5ClusterProducerError") << "Error! can't get the product ";
260  return nullptr;
261  }
262  return rhcHandle.product();
263 }
264 
265 
268  const std::string& clusterCollection,
269  const std::vector<RectangularEtaPhiRegion>& regions,
270  const reco::CaloID::Detectors detector) const {
271 
272  // get the hit collection from the event:
273  const EcalRecHitCollection *hitCollection_p = getCollection(evt, hitToken);
274 
275  // get the geometry and topology from the event setup:
276  edm::ESHandle<CaloGeometry> geoHandle;
277  es.get<CaloGeometryRecord>().get(geoHandle);
278 
279  const CaloSubdetectorGeometry *geometry_p;
280  CaloSubdetectorTopology *topology_p;
281 
282  if (detector == reco::CaloID::DET_ECAL_BARREL)
283  {
284  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
285  topology_p = new EcalBarrelTopology(geoHandle);
286  }
287  else
288  {
289  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
290  topology_p = new EcalEndcapTopology(geoHandle);
291  }
292 
293 
294  const CaloSubdetectorGeometry *geometryES_p;
295  geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
296 
297  // Run the clusterization algorithm:
299  clusters = Multi5x5_p->makeClusters(hitCollection_p, geometry_p, topology_p, geometryES_p, detector, true, regions);
300 
301  // create an unique_ptr to a BasicClusterCollection, copy the barrel clusters into it and put in the Event:
302  auto clusters_p = std::make_unique<reco::BasicClusterCollection>();
303  clusters_p->assign(clusters.begin(), clusters.end());
305  if (detector == reco::CaloID::DET_ECAL_BARREL)
306  bccHandle = evt.put(std::move(clusters_p), barrelClusterCollection_);
307  else
308  bccHandle = evt.put(std::move(clusters_p), endcapClusterCollection_);
309 
310  delete topology_p;
311 }
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:49
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
double etaBinHighEdge(unsigned int etaIndex, bool central=true) const
double etaBinLowEdge(unsigned int etaIndex, bool central=true) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
void clusterizeECALPart(edm::Event &evt, const edm::EventSetup &es, const edm::EDGetTokenT< EcalRecHitCollection > &hitToken, const std::string &clusterCollection, const std::vector< RectangularEtaPhiRegion > &regions, const reco::CaloID::Detectors detector) const
edm::EDGetTokenT< l1extra::L1EmParticleCollection > l1TagNonIsolated_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< EcalRecHitCollection > barrelHitToken_
edm::EDGetTokenT< EcalRecHitCollection > endcapHitToken_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
std::vector< reco::BasicCluster > makeClusters(const EcalRecHitCollection *hits, const CaloSubdetectorGeometry *geometry, const CaloSubdetectorTopology *topology_p, const CaloSubdetectorGeometry *geometryES_p, reco::CaloID::Detectors detector, 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
T get() const
Definition: EventSetup.h:62
void produce(edm::Event &, const edm::EventSetup &) override
const EcalRecHitCollection * getCollection(edm::Event &evt, const edm::EDGetTokenT< EcalRecHitCollection > &hitToken) const
double emJetPhiBinLowEdge(unsigned int phiIndex) const
def move(src, dest)
Definition: eostools.py:511
double emJetPhiBinHighEdge(unsigned int phiIndex) const
EgammaHLTMulti5x5ClusterProducer(const edm::ParameterSet &ps)
edm::EDGetTokenT< l1extra::L1EmParticleCollection > l1TagIsolated_