CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
13 
14 // Reconstruction Classes
25 
26 // Geometry
34 
35 
36 // Level 1 Trigger
41 
42 // EgammaCoreTools
45 
46 // Class header file
48 
49 
51 {
52 
53 
54  basicclusterCollection_ = ps.getParameter<std::string>("basicclusterCollection");
55  superclusterCollection_ = ps.getParameter<std::string>("superclusterCollection");
56  hitproducer_ = ps.getParameter<edm::InputTag>("ecalhitproducer");
57  hitcollection_ =ps.getParameter<std::string>("ecalhitcollection");
58 
59 
60 
61  // L1 matching parameters
62  l1TagIsolated_ = ps.getParameter< edm::InputTag > ("l1TagIsolated");
63  l1TagNonIsolated_ = ps.getParameter< edm::InputTag > ("l1TagNonIsolated");
64 
65  doIsolated_ = ps.getParameter<bool>("doIsolated");
66 
67  l1LowerThr_ = ps.getParameter<double> ("l1LowerThr");
68  l1UpperThr_ = ps.getParameter<double> ("l1UpperThr");
69  l1LowerThrIgnoreIsolation_ = ps.getParameter<double> ("l1LowerThrIgnoreIsolation");
70 
71  regionEtaMargin_ = ps.getParameter<double>("regionEtaMargin");
72  regionPhiMargin_ = ps.getParameter<double>("regionPhiMargin");
73 
74  // Parameters for the position calculation:
75  posCalculator_ = PositionCalc( ps.getParameter<edm::ParameterSet>("posCalcParameters") );
76 
77  const std::vector<std::string> flagnames =
78  ps.getParameter<std::vector<std::string> >("RecHitFlagToBeExcluded");
79 
80  const std::vector<int> flagsexcl=
81  StringToEnumValue<EcalRecHit::Flags>(flagnames);
82 
83  const std::vector<std::string> severitynames =
84  ps.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcluded");
85 
86  const std::vector<int> severitiesexcl=
87  StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynames);
88 
89 
90  hybrid_p = new HybridClusterAlgo(ps.getParameter<double>("HybridBarrelSeedThr"),
91  ps.getParameter<int>("step"),
92  ps.getParameter<double>("ethresh"),
93  ps.getParameter<double>("eseed"),
94  ps.getParameter<double>("xi"),
95  ps.getParameter<bool>("useEtForXi"),
96  ps.getParameter<double>("ewing"),
97  flagsexcl,
98  posCalculator_,
99  ps.getParameter<bool>("dynamicEThresh"),
100  ps.getParameter<double>("eThreshA"),
101  ps.getParameter<double>("eThreshB"),
102  severitiesexcl,
103  ps.getParameter<bool>("excludeFlagged")
104  );
105 
106  bool dynamicPhiRoad = ps.getParameter<bool>("dynamicPhiRoad");
107  if (dynamicPhiRoad) {
108  edm::ParameterSet bremRecoveryPset = ps.getParameter<edm::ParameterSet>("bremRecoveryPset");
109  hybrid_p->setDynamicPhiRoad(bremRecoveryPset);
110  }
111 
112 
113  produces< reco::BasicClusterCollection >(basicclusterCollection_);
114  produces< reco::SuperClusterCollection >(superclusterCollection_);
115  nEvt_ = 0;
116 }
117 
118 
120 {
121  delete hybrid_p;
122 }
123 
124 
126 {
127  // get the hit collection from the event:
129  // evt.getByType(rhcHandle);
130  evt.getByLabel(hitproducer_.label(), hitcollection_, rhcHandle);
131  if (!(rhcHandle.isValid()))
132  {
133  edm::LogError("ProductNotFound")<< "could not get a handle on the EcalRecHitCollection!" << std::endl;
134  return;
135  }
136  const EcalRecHitCollection *hit_collection = rhcHandle.product();
137 
138  // get the collection geometry:
139  edm::ESHandle<CaloGeometry> geoHandle;
140  es.get<CaloGeometryRecord>().get(geoHandle);
141  const CaloGeometry& geometry = *geoHandle;
142  const CaloSubdetectorGeometry *geometry_p;
143  std::auto_ptr<const CaloSubdetectorTopology> topology;
144 
145  //edm::ESHandle<EcalChannelStatus> chStatus;
146  //es.get<EcalChannelStatusRcd>().get(chStatus);
147  //const EcalChannelStatus* theEcalChStatus = chStatus.product();
148 
150  es.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
151  const EcalSeverityLevelAlgo* sevLevel = sevlv.product();
152 
153  if(hitcollection_ == "EcalRecHitsEB") {
154  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
155  topology.reset(new EcalBarrelTopology(geoHandle));
156  } else if(hitcollection_ == "EcalRecHitsEE") {
157  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
158  topology.reset(new EcalEndcapTopology(geoHandle));
159  } else if(hitcollection_ == "EcalRecHitsPS") {
160  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
161  topology.reset(new EcalPreshowerTopology (geoHandle));
162  } else throw(std::runtime_error("\n\nHybrid Cluster Producer encountered invalied ecalhitcollection type.\n\n"));
163 
164  //Get the L1 EM Particle Collection
165  //Get the L1 EM Particle Collection
167  if(doIsolated_)
168  evt.getByLabel(l1TagIsolated_, emIsolColl);
169  //Get the L1 EM Particle Collection
171  evt.getByLabel(l1TagNonIsolated_, emNonIsolColl);
172 
173  // Get the CaloGeometry
174  edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
175  es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
176 
177  std::vector<EcalEtaPhiRegion> regions;
178 
179  if(doIsolated_) {
180  for( l1extra::L1EmParticleCollection::const_iterator emItr = emIsolColl->begin(); emItr != emIsolColl->end() ;++emItr ){
181 
182  if (emItr->et() > l1LowerThr_ && emItr->et() < l1UpperThr_
183  //&&
185 ) {
186 
187  //bool isolated = emItr->gctEmCand()->isolated();
188  //if ((l1Isolated_ &&isolated) || (!l1Isolated_ &&!isolated)) {
189 
190  // Access the GCT hardware object corresponding to the L1Extra EM object.
191  int etaIndex = emItr->gctEmCand()->etaIndex() ;
192  int phiIndex = emItr->gctEmCand()->phiIndex() ;
193  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
194  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
195  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
196  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
197  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
198 
199  int isbarl=0;
200  //Part of the region is in the barel if either the upper or lower
201  //edge of the region is within the barrel
202  if(((float)(etaLow)>-1.479 && (float)(etaLow)<1.479) ||
203  ((float)(etaHigh)>-1.479 && (float)(etaHigh)<1.479)) isbarl=1;
204 
205 
206  etaLow -= regionEtaMargin_;
207  etaHigh += regionEtaMargin_;
208  phiLow -= regionPhiMargin_;
209  phiHigh += regionPhiMargin_;
210 
211  if (etaHigh>1.479) etaHigh=1.479;
212  if (etaLow<-1.479) etaLow=-1.479;
213 
214  if(isbarl) regions.push_back(EcalEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
215 
216  }
217  }
218  }
219 
221  for( l1extra::L1EmParticleCollection::const_iterator emItr = emNonIsolColl->begin(); emItr != emNonIsolColl->end() ;++emItr ){
222 
223  if(doIsolated_&&emItr->et()<l1LowerThrIgnoreIsolation_) continue;
224 
225  if (emItr->et() > l1LowerThr_ && emItr->et() < l1UpperThr_
226  //&&
228 ) {
229 
230  //bool isolated = emItr->gctEmCand()->isolated();
231  //if ((l1Isolated_ &&isolated) || (!l1Isolated_ &&!isolated)) {
232 
233  // Access the GCT hardware object corresponding to the L1Extra EM object.
234  int etaIndex = emItr->gctEmCand()->etaIndex() ;
235  int phiIndex = emItr->gctEmCand()->phiIndex() ;
236  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
237  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
238  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
239  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
240  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
241 
242  int isbarl=0;
243  //Part of the region is in the barel if either the upper or lower
244  //edge of the region is within the barrel
245  if(((float)(etaLow)>-1.479 && (float)(etaLow)<1.479) ||
246  ((float)(etaHigh)>-1.479 && (float)(etaHigh)<1.479)) isbarl=1;
247 
248 
249  etaLow -= regionEtaMargin_;
250  etaHigh += regionEtaMargin_;
251  phiLow -= regionPhiMargin_;
252  phiHigh += regionPhiMargin_;
253 
254  if (etaHigh>1.479) etaHigh=1.479;
255  if (etaLow<-1.479) etaLow=-1.479;
256 
257  if(isbarl) regions.push_back(EcalEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
258 
259  }
260  }
261  }
262 
263  // make the Basic clusters!
264  reco::BasicClusterCollection basicClusters;
265  hybrid_p->makeClusters(hit_collection, geometry_p, basicClusters, sevLevel, true, regions);
266 
267  // create an auto_ptr to a BasicClusterCollection, copy the clusters into it and put in the Event:
268  std::auto_ptr< reco::BasicClusterCollection > basicclusters_p(new reco::BasicClusterCollection);
269  basicclusters_p->assign(basicClusters.begin(), basicClusters.end());
270  edm::OrphanHandle<reco::BasicClusterCollection> bccHandle = evt.put(basicclusters_p,
272  //Basic clusters now in the event.
273 
274  //Weird though it is, get the BasicClusters back out of the event. We need the
275  //edm::Ref to these guys to make our superclusters for Hybrid.
276 // edm::Handle<reco::BasicClusterCollection> bccHandle;
277  // evt.getByLabel("clusterproducer",basicclusterCollection_, bccHandle);
278  if (!(bccHandle.isValid())) {
279  return;
280  }
281  reco::BasicClusterCollection clusterCollection = *bccHandle;
282 
283  reco::CaloClusterPtrVector clusterRefVector;
284  for (unsigned int i = 0; i < clusterCollection.size(); i++){
285  clusterRefVector.push_back(reco::CaloClusterPtr(bccHandle, i));
286  }
287 
288  reco::SuperClusterCollection superClusters = hybrid_p->makeSuperClusters(clusterRefVector);
289 
290  std::auto_ptr< reco::SuperClusterCollection > superclusters_p(new reco::SuperClusterCollection);
291  superclusters_p->assign(superClusters.begin(), superClusters.end());
292  evt.put(superclusters_p, superclusterCollection_);
293 
294 
295  nEvt_++;
296 }
297 
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
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:137
virtual void produce(edm::Event &, const edm::EventSetup &)
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
reco::SuperClusterCollection makeSuperClusters(const reco::CaloClusterPtrVector &)
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
T const * product() const
Definition: Handle.h:74
std::string const & label() const
Definition: InputTag.h:25
ESHandle< TrackerGeometry > geometry
EgammaHLTHybridClusterProducer(const edm::ParameterSet &ps)
void makeClusters(const EcalRecHitCollection *, const CaloSubdetectorGeometry *geometry, reco::BasicClusterCollection &basicClusters, const EcalSeverityLevelAlgo *sevLv, bool regional=false, const std::vector< EcalEtaPhiRegion > &regions=std::vector< EcalEtaPhiRegion >())