CMS 3D CMS Logo

EgammaHLTHybridClusterProducer.cc
Go to the documentation of this file.
1 // C/C++ headers
2 #include <iostream>
3 #include <vector>
4 #include <memory>
5 
6 // Framework
10 
13 
14 // Reconstruction Classes
25 
26 // Geometry
34 
35 // Level 1 Trigger
38 
39 // EgammaCoreTools
41 
42 // Class header file
44 
45 
47 
48  basicclusterCollection_ = ps.getParameter<std::string>("basicclusterCollection");
49  superclusterCollection_ = ps.getParameter<std::string>("superclusterCollection");
50  hitcollection_ = ps.getParameter<edm::InputTag>("ecalhitcollection");
51  hittoken_ = consumes<EcalRecHitCollection>(hitcollection_);
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 
57  doIsolated_ = ps.getParameter<bool>("doIsolated");
58 
59  l1LowerThr_ = ps.getParameter<double> ("l1LowerThr");
60  l1UpperThr_ = ps.getParameter<double> ("l1UpperThr");
61  l1LowerThrIgnoreIsolation_ = ps.getParameter<double> ("l1LowerThrIgnoreIsolation");
62 
63  regionEtaMargin_ = ps.getParameter<double>("regionEtaMargin");
64  regionPhiMargin_ = ps.getParameter<double>("regionPhiMargin");
65 
66  // Parameters for the position calculation:
67  posCalculator_ = PositionCalc( ps.getParameter<edm::ParameterSet>("posCalcParameters") );
68 
69  const std::vector<std::string> flagnames =
70  ps.getParameter<std::vector<std::string> >("RecHitFlagToBeExcluded");
71 
72  const std::vector<int> flagsexcl=
73  StringToEnumValue<EcalRecHit::Flags>(flagnames);
74 
75  const std::vector<std::string> severitynames =
76  ps.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcluded");
77 
78  const std::vector<int> severitiesexcl=
79  StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynames);
80 
81 
82  hybrid_p = new HybridClusterAlgo(ps.getParameter<double>("HybridBarrelSeedThr"),
83  ps.getParameter<int>("step"),
84  ps.getParameter<double>("ethresh"),
85  ps.getParameter<double>("eseed"),
86  ps.getParameter<double>("xi"),
87  ps.getParameter<bool>("useEtForXi"),
88  ps.getParameter<double>("ewing"),
89  flagsexcl,
90  posCalculator_,
91  ps.getParameter<bool>("dynamicEThresh"),
92  ps.getParameter<double>("eThreshA"),
93  ps.getParameter<double>("eThreshB"),
94  severitiesexcl,
95  ps.getParameter<bool>("excludeFlagged")
96  );
97 
98  bool dynamicPhiRoad = ps.getParameter<bool>("dynamicPhiRoad");
99  if (dynamicPhiRoad) {
101  hybrid_p->setDynamicPhiRoad(bremRecoveryPset);
102  }
103 
104  produces< reco::BasicClusterCollection >(basicclusterCollection_);
105  produces< reco::SuperClusterCollection >(superclusterCollection_);
106  nEvt_ = 0;
107 }
108 
109 
111 {
112  delete hybrid_p;
113 }
114 
116 
118  desc.add<std::string>("debugLevel" , "INFO");
119  desc.add<std::string>("basicclusterCollection", "");
120  desc.add<std::string>("superclusterCollection", "");
121  desc.add<edm::InputTag>("ecalhitcollection", edm::InputTag("ecalRecHit","EcalRecHitsEB"));
122  desc.add<edm::InputTag>("l1TagIsolated", edm::InputTag("l1extraParticles","Isolated"));
123  desc.add<edm::InputTag>("l1TagNonIsolated", edm::InputTag("l1extraParticles","NonIsolated"));
124  desc.add<bool>("doIsolated", true);
125  desc.add<double>("l1LowerThr", 0);
126  desc.add<double>("l1UpperThr", 9999.0);
127  desc.add<double>("l1LowerThrIgnoreIsolation", 999.0);
128  desc.add<double>("regionEtaMargin", 0.14);
129  desc.add<double>("regionPhiMargin", 0.4);
130 
131  edm::ParameterSetDescription posCalcPSET;
132  posCalcPSET.add<double>("T0_barl", 7.4);
133  posCalcPSET.add<double>("T0_endc", 3.1);
134  posCalcPSET.add<double>("T0_endcPresh", 1.2);
135  posCalcPSET.add<double>("W0", 4.2);
136  posCalcPSET.add<double>("X0", 0.89);
137  posCalcPSET.add<bool>("LogWeighted", true);
138  desc.add<edm::ParameterSetDescription>("posCalcParameters", posCalcPSET);
139 
140  desc.add<std::vector<std::string>>("RecHitFlagToBeExcluded", std::vector<std::string>());
141  desc.add<std::vector<std::string> >("RecHitSeverityToBeExcluded", std::vector<std::string>());
142  desc.add<double>("severityRecHitThreshold", 4.0);
143  desc.add<double>("HybridBarrelSeedThr", 1.0);
144  desc.add<int>("step", 10);
145  desc.add<double>("ethresh", 0.1);
146  desc.add<double>("eseed", 0.35);
147  desc.add<double>("xi", 0);
148  desc.add<bool>("useEtForXi", true);
149  desc.add<double>("ewing", 1.0);
150  desc.add<bool>("dynamicEThresh", false);
151  desc.add<double>("eThreshA", 0.003);
152  desc.add<double>("eThreshB", 0.1);
153  desc.add<bool>("excludeFlagged", false);
154  desc.add<bool>("dynamicPhiRoad", false);
155  //desc.add<edm::ParameterSet>("bremRecoveryPset", edm::ParameterSet());
156 
157  descriptions.add("hltEgammaHLTHybridClusterProducer", desc);
158 }
159 
160 
162 {
163  // get the hit collection from the event:
165  evt.getByToken(hittoken_, rhcHandle);
166 
167  if (!(rhcHandle.isValid()))
168  {
169  edm::LogError("ProductNotFound")<< "could not get a handle on the EcalRecHitCollection!" << std::endl;
170  return;
171  }
172  const EcalRecHitCollection *hit_collection = rhcHandle.product();
173 
174  // get the collection geometry:
175  edm::ESHandle<CaloGeometry> geoHandle;
176  es.get<CaloGeometryRecord>().get(geoHandle);
177  const CaloGeometry& geometry = *geoHandle;
178  const CaloSubdetectorGeometry *geometry_p;
179  std::unique_ptr<const CaloSubdetectorTopology> topology;
180 
181  //edm::ESHandle<EcalChannelStatus> chStatus;
182  //es.get<EcalChannelStatusRcd>().get(chStatus);
183  //const EcalChannelStatus* theEcalChStatus = chStatus.product();
184 
186  es.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
187  const EcalSeverityLevelAlgo* sevLevel = sevlv.product();
188 
189  if(hitcollection_.instance() == "EcalRecHitsEB") {
190  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
191  topology.reset(new EcalBarrelTopology(geoHandle));
192  } else if(hitcollection_.instance() == "EcalRecHitsEE") {
193  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
194  topology.reset(new EcalEndcapTopology(geoHandle));
195  } else if(hitcollection_.instance() == "EcalRecHitsPS") {
196  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
197  topology.reset(new EcalPreshowerTopology (geoHandle));
198  } else throw(std::runtime_error("\n\nHybrid Cluster Producer encountered invalied ecalhitcollection type.\n\n"));
199 
200  //Get the L1 EM Particle Collection
201  //Get the L1 EM Particle Collection
203  if(doIsolated_)
204  evt.getByToken(l1TagIsolated_, emIsolColl);
205 
206  //Get the L1 EM Particle Collection
208  evt.getByToken(l1TagNonIsolated_, emNonIsolColl);
209 
210  // Get the CaloGeometry
211  edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
212  es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
213 
214  std::vector<RectangularEtaPhiRegion> regions;
215 
216  if(doIsolated_) {
217  for( l1extra::L1EmParticleCollection::const_iterator emItr = emIsolColl->begin(); emItr != emIsolColl->end() ;++emItr ){
218 
219  if (emItr->et() > l1LowerThr_ && emItr->et() < l1UpperThr_) {
220 
221  // Access the GCT hardware object corresponding to the L1Extra EM object.
222  int etaIndex = emItr->gctEmCand()->etaIndex() ;
223  int phiIndex = emItr->gctEmCand()->phiIndex() ;
224  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
225  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
226  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
227  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
228  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
229 
230  int isbarl=0;
231  //Part of the region is in the barel if either the upper or lower
232  //edge of the region is within the barrel
233  if(((float)(etaLow)>-1.479 && (float)(etaLow)<1.479) ||
234  ((float)(etaHigh)>-1.479 && (float)(etaHigh)<1.479)) isbarl=1;
235 
236 
237  etaLow -= regionEtaMargin_;
238  etaHigh += regionEtaMargin_;
239  phiLow -= regionPhiMargin_;
240  phiHigh += regionPhiMargin_;
241 
242  if (etaHigh>1.479) etaHigh=1.479;
243  if (etaLow<-1.479) etaLow=-1.479;
244 
245  if(isbarl) regions.push_back(RectangularEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
246 
247  }
248  }
249  }
250 
252  for( l1extra::L1EmParticleCollection::const_iterator emItr = emNonIsolColl->begin(); emItr != emNonIsolColl->end() ;++emItr ){
253 
254  if(doIsolated_&&emItr->et()<l1LowerThrIgnoreIsolation_) continue;
255 
256  if (emItr->et() > l1LowerThr_ && emItr->et() < l1UpperThr_) {
257 
258  // Access the GCT hardware object corresponding to the L1Extra EM object.
259  int etaIndex = emItr->gctEmCand()->etaIndex() ;
260  int phiIndex = emItr->gctEmCand()->phiIndex() ;
261  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
262  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
263  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
264  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
265  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
266 
267  int isbarl=0;
268  //Part of the region is in the barel if either the upper or lower
269  //edge of the region is within the barrel
270  if(((float)(etaLow)>-1.479 && (float)(etaLow)<1.479) ||
271  ((float)(etaHigh)>-1.479 && (float)(etaHigh)<1.479)) isbarl=1;
272 
273 
274  etaLow -= regionEtaMargin_;
275  etaHigh += regionEtaMargin_;
276  phiLow -= regionPhiMargin_;
277  phiHigh += regionPhiMargin_;
278 
279  if (etaHigh>1.479) etaHigh=1.479;
280  if (etaLow<-1.479) etaLow=-1.479;
281 
282  if(isbarl) regions.push_back(RectangularEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
283 
284  }
285  }
286  }
287 
288  // make the Basic clusters!
289  reco::BasicClusterCollection basicClusters;
290  hybrid_p->makeClusters(hit_collection, geometry_p, basicClusters, sevLevel, true, regions);
291 
292  // create an unique_ptr to a BasicClusterCollection, copy the clusters into it and put in the Event:
293  auto basicclusters_p = std::make_unique<reco::BasicClusterCollection>();
294  basicclusters_p->assign(basicClusters.begin(), basicClusters.end());
295  edm::OrphanHandle<reco::BasicClusterCollection> bccHandle = evt.put(std::move(basicclusters_p),
297  if (!(bccHandle.isValid())) {
298  return;
299  }
300  reco::BasicClusterCollection clusterCollection = *bccHandle;
301 
302  reco::CaloClusterPtrVector clusterRefVector;
303  for (unsigned int i = 0; i < clusterCollection.size(); i++){
304  clusterRefVector.push_back(reco::CaloClusterPtr(bccHandle, i));
305  }
306 
307  reco::SuperClusterCollection superClusters = hybrid_p->makeSuperClusters(clusterRefVector);
308 
309  auto superclusters_p = std::make_unique<reco::SuperClusterCollection>();
310  superclusters_p->assign(superClusters.begin(), superClusters.end());
311  evt.put(std::move(superclusters_p), superclusterCollection_);
312 
313 
314  nEvt_++;
315 }
316 
317 
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
edm::EDGetTokenT< l1extra::L1EmParticleCollection > l1TagIsolated_
double etaBinHighEdge(unsigned int etaIndex, bool central=true) const
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
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:140
void produce(edm::Event &, const edm::EventSetup &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
reco::SuperClusterCollection makeSuperClusters(const reco::CaloClusterPtrVector &)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
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
edm::EDGetTokenT< l1extra::L1EmParticleCollection > l1TagNonIsolated_
double emJetPhiBinLowEdge(unsigned int phiIndex) const
void makeClusters(const EcalRecHitCollection *, const CaloSubdetectorGeometry *geometry, reco::BasicClusterCollection &basicClusters, const EcalSeverityLevelAlgo *sevLv, bool regional=false, const std::vector< RectangularEtaPhiRegion > &regions=std::vector< RectangularEtaPhiRegion >())
T const * product() const
Definition: ESHandle.h:86
std::string const & instance() const
Definition: InputTag.h:37
EgammaHLTHybridClusterProducer(const edm::ParameterSet &ps)
def move(src, dest)
Definition: eostools.py:510
edm::EDGetTokenT< EcalRecHitCollection > hittoken_
double emJetPhiBinHighEdge(unsigned int phiIndex) const