CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EgammaHLTMulti5x5ClusterProducer.cc
Go to the documentation of this file.
1 // C/C++ headers
2 #include <iostream>
3 #include <vector>
4 #include <memory>
5 
6 // Framework
14 
15 // Reconstruction Classes
21 
22 // Geometry
29 
30 // Level 1 Trigger
35 
36 // EgammaCoreTools
39 
40 // Class header file
42 
44 {
45 
46  doBarrel_ = ps.getParameter<bool>("doBarrel");
47  doEndcaps_ = ps.getParameter<bool>("doEndcaps");
48  doIsolated_ = ps.getParameter<bool>("doIsolated");
49 
50  // Parameters to identify the hit collections
51  barrelHitProducer_ = ps.getParameter<edm::InputTag>("barrelHitProducer");
52  endcapHitProducer_ = ps.getParameter<edm::InputTag>("endcapHitProducer");
53  barrelHitCollection_ = ps.getParameter<std::string>("barrelHitCollection");
54  endcapHitCollection_ = ps.getParameter<std::string>("endcapHitCollection");
55 
56  // The names of the produced cluster collections
57  barrelClusterCollection_ = ps.getParameter<std::string>("barrelClusterCollection");
58  endcapClusterCollection_ = ps.getParameter<std::string>("endcapClusterCollection");
59 
60  // Multi5x5 algorithm parameters
61  double barrelSeedThreshold = ps.getParameter<double>("Multi5x5BarrelSeedThr");
62  double endcapSeedThreshold = ps.getParameter<double>("Multi5x5EndcapSeedThr");
63 
64  // L1 matching parameters
65  l1TagIsolated_ = ps.getParameter< edm::InputTag > ("l1TagIsolated");
66  l1TagNonIsolated_ = ps.getParameter< edm::InputTag > ("l1TagNonIsolated");
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  // exclude recHit flags from seeding
81  std::vector<int> v_chstatus = StringToEnumValue<EcalRecHit::Flags>(flagnames);
82 
83 
84  // Produces a collection of barrel and a collection of endcap clusters
85 
86  produces< reco::BasicClusterCollection >(endcapClusterCollection_);
87  produces< reco::BasicClusterCollection >(barrelClusterCollection_);
88 
89  Multi5x5_p = new Multi5x5ClusterAlgo(barrelSeedThreshold, endcapSeedThreshold, v_chstatus, posCalculator_);
90 
91  /*
92  shapeAlgo_ = ClusterShapeAlgo(providedParameters);//new
93 
94 
95  clustershapecollectionEB_ = ps.getParameter<std::string>("clustershapecollectionEB");
96  clustershapecollectionEE_ = ps.getParameter<std::string>("clustershapecollectionEE");
97 
98  //AssociationMap
99  barrelClusterShapeAssociation_ = ps.getParameter<std::string>("barrelShapeAssociation");
100  endcapClusterShapeAssociation_ = ps.getParameter<std::string>("endcapShapeAssociation");
101 
102  // Produces a collection of barrel and a collection of endcap clusters
103 
104  produces< reco::ClusterShapeCollection>(clustershapecollectionEE_);//new
105  //produces< reco::BasicClusterCollection >(endcapClusterCollection_);
106  produces< reco::ClusterShapeCollection>(clustershapecollectionEB_);//new
107  // produces< reco::BasicClusterCollection >(barrelClusterCollection_);
108  produces< reco::BasicClusterShapeAssociationCollection >(barrelClusterShapeAssociation_);//new
109  produces< reco::BasicClusterShapeAssociationCollection >(endcapClusterShapeAssociation_);//new
110 
111  */
112 
113  nEvt_ = 0;
114 }
115 
116 
118 {
119  delete Multi5x5_p;
120 }
121 
122 
124 {
125  //Get the L1 EM Particle Collection
127  if(doIsolated_)
128  evt.getByLabel(l1TagIsolated_, emIsolColl);
129  //Get the L1 EM Particle Collection
131  evt.getByLabel(l1TagNonIsolated_, emNonIsolColl);
132  // Get the CaloGeometry
133  edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
134  es.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
135 
136  std::vector<EcalEtaPhiRegion> barrelRegions;
137  std::vector<EcalEtaPhiRegion> endcapRegions;
138 
139  if(doIsolated_) {
140  for( l1extra::L1EmParticleCollection::const_iterator emItr = emIsolColl->begin(); emItr != emIsolColl->end() ;++emItr ){
141 
142  if (emItr->et() > l1LowerThr_ && emItr->et() < l1UpperThr_) {
143 
144  // Access the GCT hardware object corresponding to the L1Extra EM object.
145  int etaIndex = emItr->gctEmCand()->etaIndex() ;
146 
147 
148  int phiIndex = emItr->gctEmCand()->phiIndex() ;
149  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
150  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
151  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
152  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
153  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
154 
155  //Attention isForward does not work
156  int isforw=0;
157  int isbarl=0;
158  if((float)(etaHigh)>1.479 || (float)(etaLow)<-1.479) isforw=1;
159  if(((float)(etaLow)>-1.479 && (float)(etaLow)<1.479) ||
160  ((float)(etaHigh)>-1.479 && (float)(etaHigh)<1.479)) isbarl=1;
161 
162  //std::cout<<"Multi5x5 etaindex "<<etaIndex<<" low hig : "<<etaLow<<" "<<etaHigh<<" phi low hig" <<phiLow<<" " << phiHigh<<" isforw "<<emItr->gctEmCand()->regionId().isForward()<<" isforwnew" <<isforw<< std::endl;
163 
164  etaLow -= regionEtaMargin_;
165  etaHigh += regionEtaMargin_;
166  phiLow -= regionPhiMargin_;
167  phiHigh += regionPhiMargin_;
168 
169  //if (emItr->gctEmCand()->regionId().isForward()) {
170  if (isforw) {
171  if (etaHigh>-1.479 && etaHigh<1.479) etaHigh=-1.479;
172  if ( etaLow>-1.479 && etaLow<1.479) etaLow=1.479;
173  EcalEtaPhiRegion region(etaLow,etaHigh,phiLow,phiHigh);
174  endcapRegions.push_back(region);
175  }
176  if (isbarl) {
177  if (etaHigh>1.479) etaHigh=1.479;
178  if (etaLow<-1.479) etaLow=-1.479;
179  EcalEtaPhiRegion region(etaLow,etaHigh,phiLow,phiHigh);
180  barrelRegions.push_back(region);
181  }
182  EcalEtaPhiRegion region(etaLow,etaHigh,phiLow,phiHigh);
183 
184  }
185  }
186  }
187 
188 
190  for( l1extra::L1EmParticleCollection::const_iterator emItr = emNonIsolColl->begin(); emItr != emNonIsolColl->end() ;++emItr ){
191 
192  if(doIsolated_&&emItr->et()<l1LowerThrIgnoreIsolation_) continue;
193 
194  if (emItr->et() > l1LowerThr_ && emItr->et() < l1UpperThr_) {
195 
196  // Access the GCT hardware object corresponding to the L1Extra EM object.
197  int etaIndex = emItr->gctEmCand()->etaIndex() ;
198 
199 
200  int phiIndex = emItr->gctEmCand()->phiIndex() ;
201  // Use the L1CaloGeometry to find the eta, phi bin boundaries.
202  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
203  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
204  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
205  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
206 
207 
208  int isforw=0;
209  int isbarl=0;
210  if((float)(etaHigh)>1.479 || (float)(etaLow)<-1.479) isforw=1;
211  if(((float)(etaLow)>-1.479 && (float)(etaLow)<1.479) ||
212  ((float)(etaHigh)>-1.479 && (float)(etaHigh)<1.479)) isbarl=1;
213 
214  //std::cout<<"Multi5x5 etaindex "<<etaIndex<<" low hig : "<<etaLow<<" "<<etaHigh<<" phi low hig" <<phiLow<<" " << phiHigh<<" isforw "<<emItr->gctEmCand()->regionId().isForward()<<" isforwnew" <<isforw<< std::endl;
215 
216  etaLow -= regionEtaMargin_;
217  etaHigh += regionEtaMargin_;
218  phiLow -= regionPhiMargin_;
219  phiHigh += regionPhiMargin_;
220 
221  //if (emItr->gctEmCand()->regionId().isForward()) {
222  if (isforw) {
223  if (etaHigh>-1.479 && etaHigh<1.479) etaHigh=-1.479;
224  if ( etaLow>-1.479 && etaLow<1.479) etaLow=1.479;
225  EcalEtaPhiRegion region(etaLow,etaHigh,phiLow,phiHigh);
226  endcapRegions.push_back(region);
227  }
228  if (isbarl) {
229  if (etaHigh>1.479) etaHigh=1.479;
230  if (etaLow<-1.479) etaLow=-1.479;
231  EcalEtaPhiRegion region(etaLow,etaHigh,phiLow,phiHigh);
232  barrelRegions.push_back(region);
233  }
234 
235  }
236  }
237  }
238 
239 
240  if (doEndcaps_
241  //&&endcapRegions.size()!=0
242  ) {
243 
245  }
246  if (doBarrel_
247  //&& barrelRegions.size()!=0
248  ) {
250 
251  }
252  nEvt_++;
253 }
254 
255 
257  const std::string& hitProducer_,
258  const std::string& hitCollection_)
259 {
261 
262  evt.getByLabel(hitProducer_, hitCollection_, rhcHandle);
263  if (!(rhcHandle.isValid()))
264  {
265  std::cout << "could not get a handle on the EcalRecHitCollection!" << std::endl;
266  edm::LogError("EgammaHLTMulti5x5ClusterProducerError") << "Error! can't get the product " << hitCollection_.c_str() ;
267  return 0;
268  }
269  return rhcHandle.product();
270 }
271 
272 
274  const std::string& hitProducer,
275  const std::string& hitCollection,
276  const std::string& clusterCollection,
277  const std::vector<EcalEtaPhiRegion>& regions,
278  const reco::CaloID::Detectors detector)
279 {
280 
281  // get the hit collection from the event:
282  const EcalRecHitCollection *hitCollection_p = getCollection(evt, hitProducer, hitCollection);
283 
284  // get the geometry and topology from the event setup:
285  edm::ESHandle<CaloGeometry> geoHandle;
286  es.get<CaloGeometryRecord>().get(geoHandle);
287 
288  const CaloSubdetectorGeometry *geometry_p;
289  CaloSubdetectorTopology *topology_p;
290 
291  if (detector == reco::CaloID::DET_ECAL_BARREL)
292  {
293  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
294  topology_p = new EcalBarrelTopology(geoHandle);
295  }
296  else
297  {
298  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
299  topology_p = new EcalEndcapTopology(geoHandle);
300  }
301 
302 
303  const CaloSubdetectorGeometry *geometryES_p;
304  geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
305 
306  // Run the clusterization algorithm:
308  clusters = Multi5x5_p->makeClusters(hitCollection_p, geometry_p, topology_p, geometryES_p, detector, true, regions);
309 
310  // create an auto_ptr to a BasicClusterCollection, copy the barrel clusters into it and put in the Event:
311  std::auto_ptr< reco::BasicClusterCollection > clusters_p(new reco::BasicClusterCollection);
312  clusters_p->assign(clusters.begin(), clusters.end());
314  if (detector == reco::CaloID::DET_ECAL_BARREL)
315  bccHandle = evt.put(clusters_p, barrelClusterCollection_);
316  else
317  bccHandle = evt.put(clusters_p, endcapClusterCollection_);
318 
319  delete topology_p;
320 }
T getParameter(std::string const &) const
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< EcalEtaPhiRegion > &regions=std::vector< EcalEtaPhiRegion >())
const EcalRecHitCollection * getCollection(edm::Event &evt, const std::string &hitProducer_, const std::string &hitCollection_)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
virtual void produce(edm::Event &, const edm::EventSetup &)
void clusterizeECALPart(edm::Event &evt, const edm::EventSetup &es, const std::string &hitProducer, const std::string &hitCollection, const std::string &clusterCollection, const std::vector< EcalEtaPhiRegion > &regions, const reco::CaloID::Detectors detector)
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
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
tuple cout
Definition: gather_cfg.py:121
EgammaHLTMulti5x5ClusterProducer(const edm::ParameterSet &ps)