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
12 
13 // Reconstruction Classes
24 
25 // Geometry
33 
34 
35 // Level 1 Trigger
40 
41 // EgammaCoreTools
44 
45 // Class header file
47 
48 
50 {
51 
52  // The debug level
53  std::string debugString = ps.getParameter<std::string>("debugLevel");
54  if (debugString == "DEBUG") debugL = HybridClusterAlgo::pDEBUG;
55  else if (debugString == "INFO") debugL = HybridClusterAlgo::pINFO;
57 
58  basicclusterCollection_ = ps.getParameter<std::string>("basicclusterCollection");
59  superclusterCollection_ = ps.getParameter<std::string>("superclusterCollection");
60  hitproducer_ = ps.getParameter<edm::InputTag>("ecalhitproducer");
61  hitcollection_ =ps.getParameter<std::string>("ecalhitcollection");
62 
63 
64 
65  // L1 matching parameters
66  l1TagIsolated_ = ps.getParameter< edm::InputTag > ("l1TagIsolated");
67  l1TagNonIsolated_ = ps.getParameter< edm::InputTag > ("l1TagNonIsolated");
68 
69  doIsolated_ = ps.getParameter<bool>("doIsolated");
70 
71  l1LowerThr_ = ps.getParameter<double> ("l1LowerThr");
72  l1UpperThr_ = ps.getParameter<double> ("l1UpperThr");
73  l1LowerThrIgnoreIsolation_ = ps.getParameter<double> ("l1LowerThrIgnoreIsolation");
74 
75  regionEtaMargin_ = ps.getParameter<double>("regionEtaMargin");
76  regionPhiMargin_ = ps.getParameter<double>("regionPhiMargin");
77 
78  // Parameters for the position calculation:
79  posCalculator_ = PositionCalc( ps.getParameter<edm::ParameterSet>("posCalcParameters") );
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>("ewing"),
87  ps.getParameter<std::vector<int> >("RecHitFlagToBeExcluded"),
88  posCalculator_,
89  debugL,
90  ps.getParameter<bool>("dynamicEThresh"),
91  ps.getParameter<double>("eThreshA"),
92  ps.getParameter<double>("eThreshB"),
93  ps.getParameter<std::vector<int> >("RecHitSeverityToBeExcluded"),
94  //ps.getParameter<double>("severityRecHitThreshold"),
95  //ps.getParameter<int>("severitySpikeId"),
96  //ps.getParameter<double>("severitySpikeThreshold"),
97  ps.getParameter<bool>("excludeFlagged")
98  );
99 
100  bool dynamicPhiRoad = ps.getParameter<bool>("dynamicPhiRoad");
101  if (dynamicPhiRoad) {
102  edm::ParameterSet bremRecoveryPset = ps.getParameter<edm::ParameterSet>("bremRecoveryPset");
103  hybrid_p->setDynamicPhiRoad(bremRecoveryPset);
104  }
105 
106 
107  produces< reco::BasicClusterCollection >(basicclusterCollection_);
108  produces< reco::SuperClusterCollection >(superclusterCollection_);
109  nEvt_ = 0;
110 }
111 
112 
114 {
115  delete hybrid_p;
116 }
117 
118 
120 {
121  // get the hit collection from the event:
123  // evt.getByType(rhcHandle);
124  evt.getByLabel(hitproducer_.label(), hitcollection_, rhcHandle);
125  if (!(rhcHandle.isValid()))
126  {
128  std::cout << "could not get a handle on the EcalRecHitCollection!" << std::endl;
129  return;
130  }
131  const EcalRecHitCollection *hit_collection = rhcHandle.product();
132 
133  // get the collection geometry:
134  edm::ESHandle<CaloGeometry> geoHandle;
135  es.get<CaloGeometryRecord>().get(geoHandle);
136  const CaloGeometry& geometry = *geoHandle;
137  const CaloSubdetectorGeometry *geometry_p;
138  std::auto_ptr<const CaloSubdetectorTopology> topology;
139 
140  //edm::ESHandle<EcalChannelStatus> chStatus;
141  //es.get<EcalChannelStatusRcd>().get(chStatus);
142  //const EcalChannelStatus* theEcalChStatus = chStatus.product();
143 
145  es.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
146  const EcalSeverityLevelAlgo* sevLevel = sevlv.product();
147  //if (debugL == HybridClusterAlgo::pDEBUG)
148  //std::cout << "\n\n\n" << hitcollection_ << "\n\n" << std::endl;
149 
150  if(hitcollection_ == "EcalRecHitsEB") {
151  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
152  topology.reset(new EcalBarrelTopology(geoHandle));
153  } else if(hitcollection_ == "EcalRecHitsEE") {
154  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
155  topology.reset(new EcalEndcapTopology(geoHandle));
156  } else if(hitcollection_ == "EcalRecHitsPS") {
157  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
158  topology.reset(new EcalPreshowerTopology (geoHandle));
159  } else throw(std::runtime_error("\n\nHybrid Cluster Producer encountered invalied ecalhitcollection type.\n\n"));
160 
161  //Get the L1 EM Particle Collection
162  //Get the L1 EM Particle Collection
164  if(doIsolated_)
165  evt.getByLabel(l1TagIsolated_, emIsolColl);
166  //Get the L1 EM Particle Collection
168  evt.getByLabel(l1TagNonIsolated_, emNonIsolColl);
169 
170  // Get the CaloGeometry
171  edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
172  es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
173 
174  std::vector<EcalEtaPhiRegion> regions;
175 
176  if(doIsolated_) {
177  for( l1extra::L1EmParticleCollection::const_iterator emItr = emIsolColl->begin(); emItr != emIsolColl->end() ;++emItr ){
178 
179  if (emItr->et() > l1LowerThr_ && emItr->et() < l1UpperThr_
180  //&&
182 ) {
183 
184  //bool isolated = emItr->gctEmCand()->isolated();
185  //if ((l1Isolated_ &&isolated) || (!l1Isolated_ &&!isolated)) {
186 
187  // Access the GCT hardware object corresponding to the L1Extra EM object.
188  int etaIndex = emItr->gctEmCand()->etaIndex() ;
189  int phiIndex = emItr->gctEmCand()->phiIndex() ;
190  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
191  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
192  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
193  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
194  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
195 
196  int isbarl=0;
197  //Part of the region is in the barel if either the upper or lower
198  //edge of the region is within the barrel
199  if(((float)(etaLow)>-1.479 && (float)(etaLow)<1.479) ||
200  ((float)(etaHigh)>-1.479 && (float)(etaHigh)<1.479)) isbarl=1;
201 
202  //std::cout<<"Hybrid etaindex "<<etaIndex<<" low hig : "<<etaLow<<" "<<etaHigh<<" phi low hig" <<phiLow<<" " << phiHigh<<" isforw "<<emItr->gctEmCand()->regionId().isForward()<<" isforwnew" <<isforw<< std::endl;
203 
204  etaLow -= regionEtaMargin_;
205  etaHigh += regionEtaMargin_;
206  phiLow -= regionPhiMargin_;
207  phiHigh += regionPhiMargin_;
208 
209  if (etaHigh>1.479) etaHigh=1.479;
210  if (etaLow<-1.479) etaLow=-1.479;
211 
212  if(isbarl) regions.push_back(EcalEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
213 
214  }
215  }
216  }
217 
219  for( l1extra::L1EmParticleCollection::const_iterator emItr = emNonIsolColl->begin(); emItr != emNonIsolColl->end() ;++emItr ){
220 
221  if(doIsolated_&&emItr->et()<l1LowerThrIgnoreIsolation_) continue;
222 
223  if (emItr->et() > l1LowerThr_ && emItr->et() < l1UpperThr_
224  //&&
226 ) {
227 
228  //bool isolated = emItr->gctEmCand()->isolated();
229  //if ((l1Isolated_ &&isolated) || (!l1Isolated_ &&!isolated)) {
230 
231  // Access the GCT hardware object corresponding to the L1Extra EM object.
232  int etaIndex = emItr->gctEmCand()->etaIndex() ;
233  int phiIndex = emItr->gctEmCand()->phiIndex() ;
234  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
235  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
236  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
237  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
238  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
239 
240  int isbarl=0;
241  //Part of the region is in the barel if either the upper or lower
242  //edge of the region is within the barrel
243  if(((float)(etaLow)>-1.479 && (float)(etaLow)<1.479) ||
244  ((float)(etaHigh)>-1.479 && (float)(etaHigh)<1.479)) isbarl=1;
245 
246  //std::cout<<"Hybrid etaindex "<<etaIndex<<" low hig : "<<etaLow<<" "<<etaHigh<<" phi low hig" <<phiLow<<" " << phiHigh<<" isforw "<<emItr->gctEmCand()->regionId().isForward()<<" isforwnew" <<isforw<< std::endl;
247 
248  etaLow -= regionEtaMargin_;
249  etaHigh += regionEtaMargin_;
250  phiLow -= regionPhiMargin_;
251  phiHigh += regionPhiMargin_;
252 
253  if (etaHigh>1.479) etaHigh=1.479;
254  if (etaLow<-1.479) etaLow=-1.479;
255 
256  if(isbarl) regions.push_back(EcalEtaPhiRegion(etaLow,etaHigh,phiLow,phiHigh));
257 
258  }
259  }
260  }
261 
262  // make the Basic clusters!
263  reco::BasicClusterCollection basicClusters;
264  hybrid_p->makeClusters(hit_collection, geometry_p, basicClusters, sevLevel, true, regions);
265  //if (debugL == HybridClusterAlgo::pDEBUG)
266  //std::cout << "Hybrid Finished clustering - BasicClusterCollection returned to producer..." << std::endl;
267 
268  // create an auto_ptr to a BasicClusterCollection, copy the clusters into it and put in the Event:
269  std::auto_ptr< reco::BasicClusterCollection > basicclusters_p(new reco::BasicClusterCollection);
270  basicclusters_p->assign(basicClusters.begin(), basicClusters.end());
271  edm::OrphanHandle<reco::BasicClusterCollection> bccHandle = evt.put(basicclusters_p,
273  //Basic clusters now in the event.
274  //if (debugL == HybridClusterAlgo::pDEBUG)
275  //std::cout << "Basic Clusters now put into event." << std::endl;
276 
277  //Weird though it is, get the BasicClusters back out of the event. We need the
278  //edm::Ref to these guys to make our superclusters for Hybrid.
279 // edm::Handle<reco::BasicClusterCollection> bccHandle;
280  // evt.getByLabel("clusterproducer",basicclusterCollection_, bccHandle);
281  if (!(bccHandle.isValid())) {
282  //if (debugL <= HybridClusterAlgo::pINFO)
283  //std::cout << "could not get a handle on the BasicClusterCollection!" << std::endl;
284  return;
285  }
286  reco::BasicClusterCollection clusterCollection = *bccHandle;
287  //if (debugL == HybridClusterAlgo::pDEBUG)
288  //std::cout << "Got the BasicClusterCollection" << std::endl;
289 
290  reco::CaloClusterPtrVector clusterRefVector;
291  for (unsigned int i = 0; i < clusterCollection.size(); i++){
292  clusterRefVector.push_back(reco::CaloClusterPtr(bccHandle, i));
293  }
294 
295  reco::SuperClusterCollection superClusters = hybrid_p->makeSuperClusters(clusterRefVector);
296  //if (debugL == HybridClusterAlgo::pDEBUG)
297  //std::cout << "Found: " << superClusters.size() << " superclusters." << std::endl;
298 
299  std::auto_ptr< reco::SuperClusterCollection > superclusters_p(new reco::SuperClusterCollection);
300  superclusters_p->assign(superClusters.begin(), superClusters.end());
301  evt.put(superclusters_p, superclusterCollection_);
302 
303  //if (debugL == HybridClusterAlgo::pDEBUG)
304  //std::cout << "Hybrid Clusters (Basic/Super) added to the Event! :-)" << std::endl;
305 
306  nEvt_++;
307 }
308 
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:84
reco::SuperClusterCollection makeSuperClusters(const reco::CaloClusterPtrVector &)
bool isValid() const
Definition: HandleBase.h:76
void setDynamicPhiRoad(const edm::ParameterSet &bremRecoveryPset)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
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
tuple cout
Definition: gather_cfg.py:41
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 >())