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