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  nEvt_ = 0;
82 }
83 
85  delete Multi5x5_p;
86 }
87 
89 
91  desc.add<bool>(("doBarrel"), false);
92  desc.add<bool>(("doEndcaps"), true);
93  desc.add<bool>(("doIsolated"), true);
94  desc.add<std::string>("VerbosityLevel" ,"ERROR");
95 
96  edm::ParameterSetDescription posCalcPSET;
97  posCalcPSET.add<double>("T0_barl", 7.4);
98  posCalcPSET.add<double>("T0_endc", 3.1);
99  posCalcPSET.add<double>("T0_endcPresh", 1.2);
100  posCalcPSET.add<double>("W0", 4.2);
101  posCalcPSET.add<double>("X0", 0.89);
102  posCalcPSET.add<bool>("LogWeighted", true);
103  desc.add<edm::ParameterSetDescription>("posCalcParameters", posCalcPSET);
104 
105  desc.add<edm::InputTag>(("barrelHitProducer"), edm::InputTag("hltEcalRegionalEgammaRecHit", "EcalRecHitsEB"));
106  desc.add<edm::InputTag>(("endcapHitProducer"), edm::InputTag("hltEcalRegionalEgammaRecHit", "EcalRecHitsEE"));
107  desc.add<std::string>(("barrelClusterCollection"), "notused");
108  desc.add<std::string>(("endcapClusterCollection"), "multi5x5EndcapBasicClusters");
109  desc.add<double>(("Multi5x5BarrelSeedThr"), 0.5);
110  desc.add<double>(("Multi5x5EndcapSeedThr"), 0.5);
111  desc.add<edm::InputTag>(("l1TagIsolated"), edm::InputTag("hltL1extraParticles","Isolated"));
112  desc.add<edm::InputTag>(("l1TagNonIsolated"), edm::InputTag("hltL1extraParticles","NonIsolated"));
113  desc.add<double>(("l1LowerThr"), 5.0);
114  desc.add<double>(("l1UpperThr"), 9999.);
115  desc.add<double>(("l1LowerThrIgnoreIsolation"), 999.0);
116  desc.add<double>(("regionEtaMargin"), 0.3);
117  desc.add<double>(("regionPhiMargin"), 0.4);
118 
119  desc.add<std::vector<std::string> >(("RecHitFlagToBeExcluded"), std::vector<std::string>());
120  descriptions.add(("hltEgammaHLTMulti5x5ClusterProducer"), desc);
121 }
122 
124 
125  //Get the L1 EM Particle Collection
127  if(doIsolated_)
128  evt.getByToken(l1TagIsolated_, emIsolColl);
129 
130  //Get the L1 EM Particle Collection
132  evt.getByToken(l1TagNonIsolated_, emNonIsolColl);
133 
134  // Get the CaloGeometry
135  edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
136  es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
137 
138  std::vector<RectangularEtaPhiRegion> barrelRegions;
139  std::vector<RectangularEtaPhiRegion> endcapRegions;
140 
141  if(doIsolated_) {
142  for( l1extra::L1EmParticleCollection::const_iterator emItr = emIsolColl->begin(); emItr != emIsolColl->end() ;++emItr ){
143 
144  if (emItr->et() > l1LowerThr_ && emItr->et() < l1UpperThr_) {
145 
146  // Access the GCT hardware object corresponding to the L1Extra EM object.
147  int etaIndex = emItr->gctEmCand()->etaIndex() ;
148 
149 
150  int phiIndex = emItr->gctEmCand()->phiIndex() ;
151  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
152  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
153  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
154  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
155  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
156 
157  //Attention isForward does not work
158  int isforw=0;
159  int isbarl=0;
160  if((float)(etaHigh)>1.479 || (float)(etaLow)<-1.479) isforw=1;
161  if(((float)(etaLow)>-1.479 && (float)(etaLow)<1.479) ||
162  ((float)(etaHigh)>-1.479 && (float)(etaHigh)<1.479)) isbarl=1;
163 
164  //std::cout<<"Multi5x5 etaindex "<<etaIndex<<" low hig : "<<etaLow<<" "<<etaHigh<<" phi low hig" <<phiLow<<" " << phiHigh<<" isforw "<<emItr->gctEmCand()->regionId().isForward()<<" isforwnew" <<isforw<< std::endl;
165 
166  etaLow -= regionEtaMargin_;
167  etaHigh += regionEtaMargin_;
168  phiLow -= regionPhiMargin_;
169  phiHigh += regionPhiMargin_;
170 
171  //if (emItr->gctEmCand()->regionId().isForward()) {
172  if (isforw) {
173  if (etaHigh>-1.479 && etaHigh<1.479) etaHigh=-1.479;
174  if ( etaLow>-1.479 && etaLow<1.479) etaLow=1.479;
175  RectangularEtaPhiRegion region(etaLow,etaHigh,phiLow,phiHigh);
176  endcapRegions.push_back(region);
177  }
178  if (isbarl) {
179  if (etaHigh>1.479) etaHigh=1.479;
180  if (etaLow<-1.479) etaLow=-1.479;
181  RectangularEtaPhiRegion region(etaLow,etaHigh,phiLow,phiHigh);
182  barrelRegions.push_back(region);
183  }
184  RectangularEtaPhiRegion region(etaLow,etaHigh,phiLow,phiHigh);
185 
186  }
187  }
188  }
189 
190 
192  for( l1extra::L1EmParticleCollection::const_iterator emItr = emNonIsolColl->begin(); emItr != emNonIsolColl->end() ;++emItr ){
193 
194  if(doIsolated_&&emItr->et()<l1LowerThrIgnoreIsolation_) continue;
195 
196  if (emItr->et() > l1LowerThr_ && emItr->et() < l1UpperThr_) {
197 
198  // Access the GCT hardware object corresponding to the L1Extra EM object.
199  int etaIndex = emItr->gctEmCand()->etaIndex() ;
200 
201 
202  int phiIndex = emItr->gctEmCand()->phiIndex() ;
203  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
204  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
205  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
206  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
207  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
208 
209 
210  int isforw=0;
211  int isbarl=0;
212  if((float)(etaHigh)>1.479 || (float)(etaLow)<-1.479) isforw=1;
213  if(((float)(etaLow)>-1.479 && (float)(etaLow)<1.479) ||
214  ((float)(etaHigh)>-1.479 && (float)(etaHigh)<1.479)) isbarl=1;
215 
216  //std::cout<<"Multi5x5 etaindex "<<etaIndex<<" low hig : "<<etaLow<<" "<<etaHigh<<" phi low hig" <<phiLow<<" " << phiHigh<<" isforw "<<emItr->gctEmCand()->regionId().isForward()<<" isforwnew" <<isforw<< std::endl;
217 
218  etaLow -= regionEtaMargin_;
219  etaHigh += regionEtaMargin_;
220  phiLow -= regionPhiMargin_;
221  phiHigh += regionPhiMargin_;
222 
223  //if (emItr->gctEmCand()->regionId().isForward()) {
224  if (isforw) {
225  if (etaHigh>-1.479 && etaHigh<1.479) etaHigh=-1.479;
226  if ( etaLow>-1.479 && etaLow<1.479) etaLow=1.479;
227  RectangularEtaPhiRegion region(etaLow,etaHigh,phiLow,phiHigh);
228  endcapRegions.push_back(region);
229  }
230  if (isbarl) {
231  if (etaHigh>1.479) etaHigh=1.479;
232  if (etaLow<-1.479) etaLow=-1.479;
233  RectangularEtaPhiRegion region(etaLow,etaHigh,phiLow,phiHigh);
234  barrelRegions.push_back(region);
235  }
236 
237  }
238  }
239  }
240 
241 
242  if (doEndcaps_) {
244  }
245  if (doBarrel_) {
247  }
248  nEvt_++;
249 }
250 
251 
254 
256  evt.getByToken(hitToken, rhcHandle);
257 
258  if (!(rhcHandle.isValid()))
259  {
260  std::cout << "could not get a handle on the EcalRecHitCollection!" << std::endl;
261  edm::LogError("EgammaHLTMulti5x5ClusterProducerError") << "Error! can't get the product ";
262  return nullptr;
263  }
264  return rhcHandle.product();
265 }
266 
267 
270  const std::string& clusterCollection,
271  const std::vector<RectangularEtaPhiRegion>& regions,
273 
274  // get the hit collection from the event:
275  const EcalRecHitCollection *hitCollection_p = getCollection(evt, hitToken);
276 
277  // get the geometry and topology from the event setup:
278  edm::ESHandle<CaloGeometry> geoHandle;
279  es.get<CaloGeometryRecord>().get(geoHandle);
280 
281  const CaloSubdetectorGeometry *geometry_p;
282  CaloSubdetectorTopology *topology_p;
283 
284  if (detector == reco::CaloID::DET_ECAL_BARREL)
285  {
286  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
287  topology_p = new EcalBarrelTopology(geoHandle);
288  }
289  else
290  {
291  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
292  topology_p = new EcalEndcapTopology(geoHandle);
293  }
294 
295 
296  const CaloSubdetectorGeometry *geometryES_p;
297  geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
298 
299  // Run the clusterization algorithm:
301  clusters = Multi5x5_p->makeClusters(hitCollection_p, geometry_p, topology_p, geometryES_p, detector, true, regions);
302 
303  // create an unique_ptr to a BasicClusterCollection, copy the barrel clusters into it and put in the Event:
304  auto clusters_p = std::make_unique<reco::BasicClusterCollection>();
305  clusters_p->assign(clusters.begin(), clusters.end());
307  if (detector == reco::CaloID::DET_ECAL_BARREL)
308  bccHandle = evt.put(std::move(clusters_p), barrelClusterCollection_);
309  else
310  bccHandle = evt.put(std::move(clusters_p), endcapClusterCollection_);
311 
312  delete topology_p;
313 }
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: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
double etaBinLowEdge(unsigned int etaIndex, bool central=true) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
edm::EDGetTokenT< l1extra::L1EmParticleCollection > l1TagNonIsolated_
void clusterizeECALPart(edm::Event &evt, const edm::EventSetup &es, edm::EDGetTokenT< EcalRecHitCollection > &hitToken, const std::string &clusterCollection, const std::vector< RectangularEtaPhiRegion > &regions, const reco::CaloID::Detectors detector)
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
const EcalRecHitCollection * getCollection(edm::Event &evt, edm::EDGetTokenT< EcalRecHitCollection > &hitToken)
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
const T & get() const
Definition: EventSetup.h:59
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
void produce(edm::Event &, const edm::EventSetup &) override
double emJetPhiBinLowEdge(unsigned int phiIndex) const
def move(src, dest)
Definition: eostools.py:510
double emJetPhiBinHighEdge(unsigned int phiIndex) const
EgammaHLTMulti5x5ClusterProducer(const edm::ParameterSet &ps)
edm::EDGetTokenT< l1extra::L1EmParticleCollection > l1TagIsolated_