CMS 3D CMS Logo

HLTEcalResonanceFilter.cc
Go to the documentation of this file.
4 
5 using namespace std;
6 using namespace edm;
7 
8 
10 {
11  barrelHits_ = iConfig.getParameter< edm::InputTag > ("barrelHits");
12  barrelClusters_ = iConfig.getParameter< edm::InputTag > ("barrelClusters");
13  barrelHitsToken_ = consumes<EBRecHitCollection>(barrelHits_);
14  barrelClustersToken_ = consumes<reco::BasicClusterCollection>(barrelClusters_);
15 
16  endcapHits_ = iConfig.getParameter< edm::InputTag > ("endcapHits");
17  endcapClusters_ = iConfig.getParameter< edm::InputTag > ("endcapClusters");
18  endcapHitsToken_ = consumes<EERecHitCollection>(endcapHits_);
19  endcapClustersToken_ = consumes<reco::BasicClusterCollection>(endcapClusters_);
20 
21  doSelBarrel_ = iConfig.getParameter<bool>("doSelBarrel");
22  if(doSelBarrel_){
23  edm::ParameterSet barrelSelection = iConfig.getParameter<edm::ParameterSet>( "barrelSelection" );
24 
26  selePtGamma_ = barrelSelection.getParameter<double> ("selePtGamma");
27  selePtPair_ = barrelSelection.getParameter<double> ("selePtPair");
28  seleS4S9Gamma_ = barrelSelection.getParameter<double> ("seleS4S9Gamma");
29  seleS9S25Gamma_ = barrelSelection.getParameter<double> ("seleS9S25Gamma");
30  seleMinvMaxBarrel_ = barrelSelection.getParameter<double> ("seleMinvMaxBarrel");
31  seleMinvMinBarrel_ = barrelSelection.getParameter<double> ("seleMinvMinBarrel");
32  ptMinForIsolation_ = barrelSelection.getParameter<double> ("ptMinForIsolation");
33  removePi0CandidatesForEta_ = barrelSelection.getParameter<bool>("removePi0CandidatesForEta");
34  if(removePi0CandidatesForEta_){
35  massLowPi0Cand_ = barrelSelection.getParameter<double>("massLowPi0Cand");
36  massHighPi0Cand_ = barrelSelection.getParameter<double>("massHighPi0Cand");
37  }
38  seleIso_ = barrelSelection.getParameter<double> ("seleIso");
39  ptMinForIsolation_ = barrelSelection.getParameter<double> ("ptMinForIsolation");
40  seleBeltDR_ = barrelSelection.getParameter<double> ("seleBeltDR");
41  seleBeltDeta_ = barrelSelection.getParameter<double> ("seleBeltDeta");
42 
43  store5x5RecHitEB_ = barrelSelection.getParameter<bool> ("store5x5RecHitEB");
44  BarrelHits_ = barrelSelection.getParameter<string > ("barrelHitCollection");
45 
46  produces< EBRecHitCollection >(BarrelHits_);
47 
48  }
49 
50 
51  doSelEndcap_ = iConfig.getParameter<bool>("doSelEndcap");
52  if(doSelEndcap_){
53  edm::ParameterSet endcapSelection = iConfig.getParameter<edm::ParameterSet>( "endcapSelection" );
54 
56  seleMinvMaxEndCap_ = endcapSelection.getParameter<double> ("seleMinvMaxEndCap");
57  seleMinvMinEndCap_ = endcapSelection.getParameter<double> ("seleMinvMinEndCap");
58 
59  region1_EndCap_ = endcapSelection.getParameter<double> ("region1_EndCap");
60  selePtGammaEndCap_region1_ = endcapSelection.getParameter<double> ("selePtGammaEndCap_region1");
61  selePtPairEndCap_region1_ = endcapSelection.getParameter<double> ("selePtPairEndCap_region1");
62 
63  region2_EndCap_ = endcapSelection.getParameter<double> ("region2_EndCap");
64  selePtGammaEndCap_region2_ = endcapSelection.getParameter<double> ("selePtGammaEndCap_region2");
65  selePtPairEndCap_region2_ = endcapSelection.getParameter<double> ("selePtPairEndCap_region2");
66 
67  selePtGammaEndCap_region3_ = endcapSelection.getParameter<double> ("selePtGammaEndCap_region3");
68  selePtPairEndCap_region3_ = endcapSelection.getParameter<double> ("selePtPairEndCap_region3");
69  selePtPairMaxEndCap_region3_ = endcapSelection.getParameter<double> ("selePtPairMaxEndCap_region3");
70 
71 
72  seleS4S9GammaEndCap_ = endcapSelection.getParameter<double> ("seleS4S9GammaEndCap");
73  seleS9S25GammaEndCap_ = endcapSelection.getParameter<double> ("seleS9S25GammaEndCap");
74  ptMinForIsolationEndCap_ = endcapSelection.getParameter<double> ("ptMinForIsolationEndCap");
75  seleBeltDREndCap_ = endcapSelection.getParameter<double> ("seleBeltDREndCap");
76  seleBeltDetaEndCap_ = endcapSelection.getParameter<double> ("seleBeltDetaEndCap");
77  seleIsoEndCap_ = endcapSelection.getParameter<double> ("seleIsoEndCap");
78 
79  store5x5RecHitEE_ = endcapSelection.getParameter<bool> ("store5x5RecHitEE");
80  EndcapHits_ = endcapSelection.getParameter<string > ("endcapHitCollection");
81  produces< EERecHitCollection >(EndcapHits_);
82 
83 
84  }
85 
86 
87  useRecoFlag_ = iConfig.getParameter<bool>("useRecoFlag");
88  flagLevelRecHitsToUse_ = iConfig.getParameter<int>("flagLevelRecHitsToUse");
89 
90  useDBStatus_ = iConfig.getParameter<bool>("useDBStatus");
91  statusLevelRecHitsToUse_ = iConfig.getParameter<int>("statusLevelRecHitsToUse");
92 
93 
94  preshHitProducer_ = iConfig.getParameter<edm::InputTag>("preshRecHitProducer");
95  preshHitsToken_ = consumes<EBRecHitCollection>(preshHitProducer_);
96 
98  storeRecHitES_ = iConfig.getParameter<bool>("storeRecHitES");
99  if(storeRecHitES_){
100 
101  edm::ParameterSet preshowerSelection = iConfig.getParameter<edm::ParameterSet>( "preshowerSelection" );
102 
103  // maximum number of matched ES clusters (in each ES layer) to each BC
104  preshNclust_ = preshowerSelection.getParameter<int>("preshNclust");
105  // min energy of ES clusters
106  preshClustECut = preshowerSelection.getParameter<double>("preshClusterEnergyCut");
107  // algo params
108  float preshStripECut = preshowerSelection.getParameter<double>("preshStripEnergyCut");
109  int preshSeededNst = preshowerSelection.getParameter<int>("preshSeededNstrip");
110  // calibration parameters:
111  calib_planeX_ = preshowerSelection.getParameter<double>("preshCalibPlaneX");
112  calib_planeY_ = preshowerSelection.getParameter<double>("preshCalibPlaneY");
113  gamma_ = preshowerSelection.getParameter<double>("preshCalibGamma");
114  mip_ = preshowerSelection.getParameter<double>("preshCalibMIP");
115 
116  // ES algo constructor:
117  presh_algo_ = new PreshowerClusterAlgo(preshStripECut,preshClustECut,preshSeededNst);
118 
119  ESHits_ = preshowerSelection.getParameter< std::string > ("ESCollection");
120  produces< ESRecHitCollection >(ESHits_);
121  }
122 
123  debug_ = iConfig.getParameter<int> ("debugLevel");
124 
125 }
126 
127 
129 {
130  if(storeRecHitES_){
131  delete presh_algo_;
132  }
133 }
134 
135 
136 void
139  desc.add<edm::InputTag>("barrelHits",edm::InputTag("hltEcalRegionalPi0EtaRecHit","EcalRecHitsEB"));
140  desc.add<edm::InputTag>("endcapHits",edm::InputTag("hltEcalRegionalPi0EtaRecHit","EcalRecHitsEE"));
141  desc.add<edm::InputTag>("preshRecHitProducer",edm::InputTag("hltEcalRegionalPi0EtaRecHit","EcalRecHitsES"));
142  desc.add<edm::InputTag>("barrelClusters",edm::InputTag("hltSimple3x3Clusters","Simple3x3ClustersBarrel"));
143  desc.add<edm::InputTag>("endcapClusters",edm::InputTag("hltSimple3x3Clusters","Simple3x3ClustersEndcap"));
144  desc.add<bool>("useRecoFlag",false);
145  desc.add<int>("flagLevelRecHitsToUse",1);
146  desc.add<bool>("useDBStatus",true);
147  desc.add<int>("statusLevelRecHitsToUse",1);
148 
149  desc.add<bool>("doSelBarrel",true);
150  edm::ParameterSetDescription barrelSelection;
151  barrelSelection.add<double>("selePtGamma",1.);
152  barrelSelection.add<double>("selePtPair",2.);
153  barrelSelection.add<double>("seleMinvMaxBarrel",0.22);
154  barrelSelection.add<double>("seleMinvMinBarrel",0.06);
155  barrelSelection.add<bool>("removePi0CandidatesForEta",false);
156  barrelSelection.add<double>("massLowPi0Cand",0.104);
157  barrelSelection.add<double>("massHighPi0Cand",0.163);
158  barrelSelection.add<double>("seleS4S9Gamma",0.83);
159  barrelSelection.add<double>("seleS9S25Gamma",0.);
160  barrelSelection.add<double>("ptMinForIsolation",1.0);
161  barrelSelection.add<double>("seleIso",0.5);
162  barrelSelection.add<double>("seleBeltDR",0.2);
163  barrelSelection.add<double>("seleBeltDeta",0.05);
164  barrelSelection.add<bool>("store5x5RecHitEB",false);
165  barrelSelection.add<std::string>("barrelHitCollection","pi0EcalRecHitsEB");
166  desc.add<edm::ParameterSetDescription>("barrelSelection",barrelSelection);
167 
168  desc.add<bool>("doSelEndcap",true);
169  edm::ParameterSetDescription endcapSelection;
170  endcapSelection.add<double>("seleMinvMaxEndCap",0.3);
171  endcapSelection.add<double>("seleMinvMinEndCap",0.05);
172  endcapSelection.add<double>("region1_EndCap",2.0);
173  endcapSelection.add<double>("selePtGammaEndCap_region1",0.8);
174  endcapSelection.add<double>("selePtPairEndCap_region1",3.0);
175  endcapSelection.add<double>("region2_EndCap",2.5);
176  endcapSelection.add<double>("selePtGammaEndCap_region2",0.5);
177  endcapSelection.add<double>("selePtPairEndCap_region2",2.0);
178  endcapSelection.add<double>("selePtGammaEndCap_region3",0.3);
179  endcapSelection.add<double>("selePtPairEndCap_region3",1.2);
180  endcapSelection.add<double>("selePtPairMaxEndCap_region3",2.5);
181  endcapSelection.add<double>("seleS4S9GammaEndCap",0.9);
182  endcapSelection.add<double>("seleS9S25GammaEndCap",0.);
183  endcapSelection.add<double>("ptMinForIsolationEndCap",0.5);
184  endcapSelection.add<double>("seleIsoEndCap",0.5);
185  endcapSelection.add<double>("seleBeltDREndCap",0.2);
186  endcapSelection.add<double>("seleBeltDetaEndCap",0.05);
187  endcapSelection.add<bool>("store5x5RecHitEE",false);
188  endcapSelection.add<std::string>("endcapHitCollection","pi0EcalRecHitsEE");
189  desc.add<edm::ParameterSetDescription>("endcapSelection",endcapSelection);
190 
191  desc.add<bool>("storeRecHitES",true);
192  edm::ParameterSetDescription preshowerSelection;
193  preshowerSelection.add<std::string>("ESCollection","pi0EcalRecHitsES");
194  preshowerSelection.add<int>("preshNclust",4);
195  preshowerSelection.add<double>("preshClusterEnergyCut",0.0);
196  preshowerSelection.add<double>("preshStripEnergyCut",0.0);
197  preshowerSelection.add<int>("preshSeededNstrip",15);
198  preshowerSelection.add<double>("preshCalibPlaneX",1.0);
199  preshowerSelection.add<double>("preshCalibPlaneY",0.7);
200  preshowerSelection.add<double>("preshCalibGamma",0.024);
201  preshowerSelection.add<double>("preshCalibMIP",9.0E-5);
202  preshowerSelection.add<std::string>("debugLevelES",""); // *** This is not needed and shoul be better removed !
203  desc.add<edm::ParameterSetDescription>("preshowerSelection",preshowerSelection);
204 
205  desc.add<int>("debugLevel",0);
206  descriptions.add("hltEcalResonanceFilter",desc);
207 }
208 
209 // ------------ method called to produce the data ------------
210 bool
212 {
213 
214  //Create empty output collections
215  std::unique_ptr< EBRecHitCollection > selEBRecHitCollection( new EBRecHitCollection );
216  //Create empty output collections
217  std::unique_ptr< EERecHitCollection > selEERecHitCollection( new EERecHitCollection );
218 
219 
221  vector<DetId> selectedEBDetIds;
222  vector<DetId> selectedEEDetIds;
223 
224 
225  edm::ESHandle<CaloTopology> pTopology;
226  iSetup.get<CaloTopologyRecord>().get(pTopology);
227  const CaloSubdetectorTopology *topology_eb = pTopology->getSubdetectorTopology(DetId::Ecal,EcalBarrel);
228  const CaloSubdetectorTopology *topology_ee = pTopology->getSubdetectorTopology(DetId::Ecal,EcalEndcap);
229 
230 
231  edm::ESHandle<CaloGeometry> geoHandle;
232  iSetup.get<CaloGeometryRecord>().get(geoHandle);
234  std::unique_ptr<CaloSubdetectorTopology> topology_es;
235  if (geometry_es) {
236  topology_es = std::make_unique<EcalPreshowerTopology>();
237  }else{
238  storeRecHitES_ = false;
239  }
240 
241 
244  if ( useDBStatus_ ) iSetup.get<EcalChannelStatusRcd>().get(csHandle);
245  const EcalChannelStatus &channelStatus = *csHandle;
246 
248 
249  Handle<EBRecHitCollection> barrelRecHitsHandle;
250 
251  iEvent.getByToken(barrelHitsToken_,barrelRecHitsHandle);
252  if (!barrelRecHitsHandle.isValid()) {
253  LogDebug("") << "AlCaEcalResonanceProducer: Error! can't get product barrel hits!" << std::endl;
254  }
255 
256  const EcalRecHitCollection *hitCollection_eb = barrelRecHitsHandle.product();
257 
258 
259  Handle<reco::BasicClusterCollection> barrelClustersHandle;
260  iEvent.getByToken(barrelClustersToken_,barrelClustersHandle);
261  if (!barrelClustersHandle.isValid()) {
262  LogDebug("") << "AlCaEcalResonanceProducer: Error! can't get product barrel clusters!" << std::endl;
263  }
264  const reco::BasicClusterCollection *clusterCollection_eb = barrelClustersHandle.product();
265  if(debug_>=1) LogDebug("")<<" barrel_input_size: run "<<iEvent.id().run()<<" event "<<iEvent.id().event()<<" nhitEB: "<<hitCollection_eb->size()<<" nCluster: "<< clusterCollection_eb->size() <<endl;
266 
267 
268  if(doSelBarrel_){
269 
270  map<int, vector<EcalRecHit> > RecHits5x5_clus;
271  vector<int> indIsoClus;
272  vector<int> indCandClus;
273  vector<int> indClusSelected;
274 
275  doSelection( EcalBarrel,clusterCollection_eb, hitCollection_eb, channelStatus,topology_eb,
276  RecHits5x5_clus,
277  indCandClus,indIsoClus, indClusSelected);
278 
279 
281  for(int ind : indClusSelected){
282  auto it_bc3 = clusterCollection_eb->begin() + ind;
283  const std::vector< std::pair<DetId, float> > &vid = it_bc3->hitsAndFractions();
284  for (auto const & idItr : vid){
285  auto hit = hitCollection_eb->find(idItr.first);
286  if( hit == hitCollection_eb->end()) continue; //this should not happen.
287  selEBRecHitCollection->push_back(*hit);
288  selectedEBDetIds.push_back(idItr.first);
289  }
290  }
291 
292 
293  if( store5x5RecHitEB_ ){
295  for(int ind : indCandClus){
296  vector<EcalRecHit> v5x5 = RecHits5x5_clus[ind];
297  for(auto & n : v5x5){
298  DetId ed = n.id();
299  auto itdet = find(selectedEBDetIds.begin(),selectedEBDetIds.end(),ed);
300  if( itdet == selectedEBDetIds.end()){
301  selectedEBDetIds.push_back(ed);
302  selEBRecHitCollection->push_back(n);
303  }
304  }
305  }
306 
307 
309  for(int ind : indIsoClus){
310  auto it = find(indCandClus.begin(),indCandClus.end(), ind);
311  if( it != indCandClus.end()) continue;
312 
313  auto it_bc3 = clusterCollection_eb->begin() + ind;
314  DetId seedId = it_bc3->seed();
315  std::vector<DetId> clus_v5x5 = topology_eb->getWindow(seedId,5,5);
316  for( std::vector<DetId>::const_iterator idItr = clus_v5x5.begin(); idItr != clus_v5x5.end(); idItr++){
317  DetId ed = *idItr;
318  auto rit = hitCollection_eb->find( ed );
319  if ( rit == hitCollection_eb->end() ) continue;
320  if( ! checkStatusOfEcalRecHit(channelStatus, *rit) ) continue;
321  auto itdet = find(selectedEBDetIds.begin(),selectedEBDetIds.end(),ed);
322  if( itdet == selectedEBDetIds.end()){
323  selectedEBDetIds.push_back(ed);
324  selEBRecHitCollection->push_back(*rit);
325  }
326  }
327  }
328  }
329 
330 
331  }// end of selection for eta/pi0->gg in the barrel
332 
333  int eb_collsize = selEBRecHitCollection->size();
334 
335  if(debug_>=1) LogDebug("")<<" barrel_output_size_run "<<iEvent.id().run()<<" event "<<iEvent.id().event()<<" nEBSaved "<<selEBRecHitCollection->size()<<std::endl;
337 
338 
339 
340  //===============Start of Endcap =================/////
342  Handle<ESRecHitCollection> esRecHitsHandle;
343  iEvent.getByToken(preshHitsToken_,esRecHitsHandle);
344  if( !esRecHitsHandle.isValid()){
345  LogDebug("") << "AlCaEcalResonanceProducer: Error! can't get product esRecHit!" << std::endl;
346  }
347  const EcalRecHitCollection* hitCollection_es = esRecHitsHandle.product();
348  // make a map of rechits:
349  m_esrechit_map.clear();
351  for (iter = esRecHitsHandle->begin(); iter != esRecHitsHandle->end(); iter++) {
352  //Make the map of DetID, EcalRecHit pairs
353  m_esrechit_map.insert(std::make_pair(iter->id(), *iter));
354  }
355  // The set of used DetID's for a given event:
356  m_used_strips.clear();
357  std::unique_ptr<ESRecHitCollection> selESRecHitCollection(new ESRecHitCollection );
358 
359  Handle<EERecHitCollection> endcapRecHitsHandle;
360  iEvent.getByToken(endcapHitsToken_,endcapRecHitsHandle);
361  if (!endcapRecHitsHandle.isValid()) {
362  LogDebug("") << "AlCaEcalResonanceProducer: Error! can't get product endcap hits!" << std::endl;
363  }
364  const EcalRecHitCollection *hitCollection_ee = endcapRecHitsHandle.product();
365  Handle<reco::BasicClusterCollection> endcapClustersHandle;
366  iEvent.getByToken(endcapClustersToken_,endcapClustersHandle);
367  if (!endcapClustersHandle.isValid()) {
368  LogDebug("") << "AlCaEcalResonanceProducer: Error! can't get product endcap clusters!" << std::endl;
369  }
370  const reco::BasicClusterCollection *clusterCollection_ee = endcapClustersHandle.product();
371  if(debug_>=1) LogDebug("")<<" endcap_input_size: run "<<iEvent.id().run()<<" event "<<iEvent.id().event()<<" nhitEE: "<<hitCollection_ee->size()<<" nhitES: "<<hitCollection_es->size()<<" nCluster: "<< clusterCollection_ee->size() <<endl;
372 
373 
374  if(doSelEndcap_){
375 
376  map<int, vector<EcalRecHit> > RecHits5x5_clus;
377  vector<int> indIsoClus;
378  vector<int> indCandClus;
379  vector<int> indClusSelected;
380 
381  doSelection( EcalEndcap,clusterCollection_ee, hitCollection_ee, channelStatus,topology_ee,
382  RecHits5x5_clus,
383  indCandClus,indIsoClus, indClusSelected);
384 
386  for(int ind : indClusSelected){
387  auto it_bc3 = clusterCollection_ee->begin() + ind;
388  const std::vector< std::pair<DetId, float> > &vid = it_bc3->hitsAndFractions();
389  for (auto const & idItr : vid){
390  auto hit = hitCollection_ee->find(idItr.first);
391  if( hit == hitCollection_ee->end()) continue; //this should not happen.
392  selEERecHitCollection->push_back(*hit);
393  selectedEEDetIds.push_back(idItr.first);
394  }
396  if(storeRecHitES_){
397  std::set<DetId> used_strips_before = m_used_strips;
398  makeClusterES(it_bc3->x(),it_bc3->y(),it_bc3->z(),geometry_es,topology_es.get());
399  auto ites = m_used_strips.begin();
400  for(; ites != m_used_strips.end(); ++ ites ){
401  ESDetId d1 = ESDetId(*ites);
402  auto ites2 = find(used_strips_before.begin(),used_strips_before.end(),d1);
403  if( (ites2 == used_strips_before.end())){
404  auto itmap = m_esrechit_map.find(d1);
405  selESRecHitCollection->push_back(itmap->second);
406  }
407  }
408  }
409  }
410 
411 
412  if( store5x5RecHitEE_ ){
414  for(int ind : indCandClus){
415  vector<EcalRecHit> v5x5 = RecHits5x5_clus[ind];
416  for(auto & n : v5x5){
417  DetId ed = n.id();
418  auto itdet = find(selectedEEDetIds.begin(),selectedEEDetIds.end(),ed);
419  if( itdet == selectedEEDetIds.end()){
420  selectedEEDetIds.push_back(ed);
421  selEERecHitCollection->push_back(n);
422  }
423  }
424  }
425 
426 
428  for(int ind : indIsoClus){
429  auto it = find(indCandClus.begin(),indCandClus.end(), ind);
430  if( it != indCandClus.end()) continue;
431 
432  auto it_bc3 = clusterCollection_ee->begin() + ind;
433  DetId seedId = it_bc3->seed();
434  std::vector<DetId> clus_v5x5 = topology_ee->getWindow(seedId,5,5);
435  for( std::vector<DetId>::const_iterator idItr = clus_v5x5.begin(); idItr != clus_v5x5.end(); idItr++){
436  DetId ed = *idItr;
437  auto rit = hitCollection_ee->find( ed );
438  if ( rit == hitCollection_ee->end() ) continue;
439  if( ! checkStatusOfEcalRecHit(channelStatus, *rit) ) continue;
440  auto itdet = find(selectedEEDetIds.begin(),selectedEEDetIds.end(),ed);
441  if( itdet == selectedEEDetIds.end()){
442  selectedEEDetIds.push_back(ed);
443  selEERecHitCollection->push_back(*rit);
444  }
445  }
446  }
447  }
448 
449  }// end of selection for eta/pi0->gg in the endcap
450 
451 
452 
454 
455  if(debug_>=1) LogDebug("")<<" endcap_output_size run "<<iEvent.id().run()<<"_"<<iEvent.id().event()<<" nEESaved "<<selEERecHitCollection->size()<<" nESSaved: " << selESRecHitCollection->size() <<endl;
456 
457 
458  //Put selected information in the event
459  int ee_collsize = selEERecHitCollection->size();
460 
461  if( eb_collsize < 2 && ee_collsize <2) return false;
462 
464  if(doSelBarrel_){
465  iEvent.put(std::move(selEBRecHitCollection), BarrelHits_);
466  }
467  if(doSelEndcap_){
468  iEvent.put(std::move(selEERecHitCollection), EndcapHits_);
469  if(storeRecHitES_){
470  iEvent.put(std::move(selESRecHitCollection), ESHits_);
471  }
472  }
473 
474  return true;
475 
476 
477 }
478 
479 
480 
483  const EcalChannelStatus &channelStatus,
484  const CaloSubdetectorTopology *topology_p,
485  map<int, vector<EcalRecHit> > &RecHits5x5_clus,
486  vector<int> &indCandClus,
487  vector<int> &indIsoClus,
488  vector<int> &indClusSelected
489  ){
490 
491 
492  vector<int> indClusPi0Candidates;
493  if( detector ==EcalBarrel && removePi0CandidatesForEta_){
494  for( auto it_bc = clusterCollection->begin(); it_bc != clusterCollection->end();it_bc++){
495  for( auto it_bc2 = it_bc + 1 ; it_bc2 != clusterCollection->end();it_bc2++){
496  float m_pair,pt_pair,eta_pair, phi_pair;
497  calcPaircluster(*it_bc,*it_bc2, m_pair, pt_pair,eta_pair,phi_pair);
498  if(m_pair > massLowPi0Cand_ && m_pair < massHighPi0Cand_){
499  int indtmp[2]={ int( it_bc - clusterCollection->begin()), int( it_bc2 - clusterCollection->begin())};
500  for(int & k : indtmp){
501  auto it = find(indClusPi0Candidates.begin(),indClusPi0Candidates.end(),k);
502  if( it == indClusPi0Candidates.end()) indClusPi0Candidates.push_back(k);
503  }
504  }
505  }
506  }//end of loop over finding pi0's clusters
507  }
508 
509 
510 
511 
512 
513  double m_minCut = seleMinvMinBarrel_;
514  double m_maxCut = seleMinvMaxBarrel_;
515  double ptminforIso = ptMinForIsolation_;
516  double isoCut = seleIso_;
517  double isoBeltdrCut = seleBeltDR_ ;
518  double isoBeltdetaCut = seleBeltDeta_;
519  double s4s9Cut = seleS4S9Gamma_;
520  double s9s25Cut = seleS9S25Gamma_;
521  bool store5x5 = store5x5RecHitEB_;
522 
523  if( detector ==EcalEndcap){
524  m_minCut = seleMinvMinEndCap_;
525  m_maxCut = seleMinvMaxEndCap_;
526  ptminforIso = ptMinForIsolationEndCap_;
527  isoCut = seleIsoEndCap_;
528  isoBeltdrCut = seleBeltDREndCap_;
529  isoBeltdetaCut = seleBeltDetaEndCap_;
530  s4s9Cut = seleS4S9GammaEndCap_;
531  s9s25Cut = seleS9S25GammaEndCap_ ;
532  store5x5 = store5x5RecHitEE_;
533 
534  }
535 
536 
537 
538 
539  map<int,bool> passShowerShape_clus; //if this cluster passed showershape cut, so no need to compute the quantity again for each loop
540 
541  for( auto it_bc = clusterCollection->begin(); it_bc != clusterCollection->end();it_bc++){
542 
543  if( detector ==EcalBarrel && removePi0CandidatesForEta_){
544  auto it = find(indClusPi0Candidates.begin(),indClusPi0Candidates.end(),int(it_bc - clusterCollection->begin()) );
545  if( it != indClusPi0Candidates.end()) continue;
546  }
547 
548  float en1 = it_bc->energy();
549  float theta1 = 2. * atan(exp(-it_bc->position().eta()));
550  float pt1 = en1*sin(theta1);
551 
552  int ind1 = int( it_bc - clusterCollection->begin() );
553  auto itmap = passShowerShape_clus.find(ind1);
554  if( itmap != passShowerShape_clus.end()){
555  if( itmap->second == false){
556  continue;
557  }
558  }
559 
560  for( auto it_bc2 = it_bc + 1 ; it_bc2 != clusterCollection->end();it_bc2++){
561  if( detector ==EcalBarrel && removePi0CandidatesForEta_){
562  auto it = find(indClusPi0Candidates.begin(),indClusPi0Candidates.end(),int(it_bc2 - clusterCollection->begin()) );
563  if( it != indClusPi0Candidates.end()) continue;
564  }
565  float en2 = it_bc2 ->energy();
566  float theta2 = 2. * atan(exp(-it_bc2->position().eta()));
567  float pt2 = en2*sin(theta2);
568 
569  int ind2 = int( it_bc2 - clusterCollection->begin() );
570  auto itmap = passShowerShape_clus.find(ind2);
571  if( itmap != passShowerShape_clus.end()){
572  if( itmap->second == false){
573  continue;
574  }
575  }
576 
577  float m_pair,pt_pair,eta_pair, phi_pair;
578  calcPaircluster(*it_bc,*it_bc2, m_pair, pt_pair,eta_pair,phi_pair);
580  float ptmin = pt1< pt2 ? pt1:pt2;
581  if( detector ==EcalBarrel ){
582  if( ptmin < selePtGamma_ ) continue;
583  if (pt_pair < selePtPair_ )continue;
584  }else{
585  float etapair = fabs(eta_pair);
586  if(etapair <= region1_EndCap_){
587  if(ptmin < selePtGammaEndCap_region1_ || pt_pair < selePtPairEndCap_region1_) continue;
588  }else if( etapair <= region2_EndCap_){
589  if(ptmin < selePtGammaEndCap_region2_ || pt_pair < selePtPairEndCap_region2_) continue;
590  }else{
591  if(ptmin < selePtGammaEndCap_region3_ || pt_pair < selePtPairEndCap_region3_) continue;
592  if(pt_pair > selePtPairMaxEndCap_region3_ ) continue;
593  }
594  }
595 
596 
597 
599  if( m_pair < m_minCut || m_pair > m_maxCut) continue;
600 
601 
602 
603 
605  vector<int> IsoClus;
606  IsoClus.push_back(ind1); //first two are good clusters
607  IsoClus.push_back(ind2);
608 
609  float Iso = 0;
610  for( auto it_bc3 = clusterCollection->begin(); it_bc3 != clusterCollection->end();it_bc3++){
611  if( it_bc3->seed() == it_bc->seed() || it_bc3->seed() == it_bc2->seed()) continue;
612  float drcl = GetDeltaR(eta_pair,it_bc3->eta(),phi_pair,it_bc3->phi());
613  float dretacl = fabs( eta_pair - it_bc3->eta());
614  if( drcl > isoBeltdrCut || dretacl > isoBeltdetaCut ) continue;
615  float pt3 = it_bc3->energy()*sin(it_bc3->position().theta()) ;
616  if( pt3 < ptminforIso) continue;
617  Iso += pt3;
618  int ind3 = int(it_bc3 - clusterCollection->begin());
619  IsoClus.push_back( ind3);
620  }
622  if(Iso/pt_pair > isoCut) continue;
623 
624 
625  bool failShowerShape = false;
626  for(int n=0; n<2; n++){
627  int ind = IsoClus[n];
628  auto it_bc3 = clusterCollection->begin() + ind;
629  auto itmap = passShowerShape_clus.find(ind);
630  if( itmap != passShowerShape_clus.end()){
631  if( itmap->second == false){
632  failShowerShape = true;
633  n=2; //exit the loop
634  }
635  }else{
636  vector<EcalRecHit> RecHitsCluster_5x5;
637  float res[3];
638  calcShowerShape(*it_bc3, channelStatus,hitCollection, topology_p,store5x5, RecHitsCluster_5x5, res);
639  float s4s9 = res[1] >0 ? res[0]/ res[1] : -1;
640  float s9s25 = res[2] >0 ? res[1] / res[2] : -1;
641  bool passed = s4s9 > s4s9Cut && s9s25 > s9s25Cut;
642  passShowerShape_clus.insert(pair<int, bool>(ind,passed));
643  if( !passed ){
644  failShowerShape = true;
645  n=2; //exit the loop
646  }else{
647  RecHits5x5_clus.insert(pair<int, vector<EcalRecHit> >(ind,RecHitsCluster_5x5) );
648  }
649  }
650  }
651 
652  if( failShowerShape == true) continue; //if any of the two clusters fail shower shape
653 
654 
656  for(unsigned int iii=0 ; iii<IsoClus.size() ; iii++){
657  int ind = IsoClus[iii];
658 
659  if( iii < 2){
660  auto it = find(indCandClus.begin(),indCandClus.end(), ind);
661  if( it == indCandClus.end()) indCandClus.push_back(ind);
662  else continue;
663  }else{
664  auto it = find(indIsoClus.begin(),indIsoClus.end(), ind); //iso cluster
665  if( it == indIsoClus.end()) indIsoClus.push_back(ind);
666  else continue;
667  }
668 
669  auto it = find(indClusSelected.begin(),indClusSelected.end(),ind);
670  if( it != indClusSelected.end()) continue;
671  indClusSelected.push_back(ind);
672  }
673 
674  }
675  }
676 
677 
678 
679 
680 }
681 
682 
683 
684 
685 
686 
687 
688 void HLTEcalResonanceFilter::convxtalid(Int_t &nphi,Int_t &neta)
689 {
690  // Barrel only
691  // Output nphi 0...359; neta 0...84; nside=+1 (for eta>0), or 0 (for eta<0).
692  // neta will be [-85,-1] , or [0,84], the minus sign indicates the z<0 side.
693 
694  if(neta > 0) neta -= 1;
695  if(nphi > 359) nphi=nphi-360;
696 
697  // final check
698  if(nphi >359 || nphi <0 || neta< -85 || neta > 84)
699  {
700  LogError("") <<" unexpected fatal error in HLTEcalResonanceFilter::convxtalid "<< nphi << " " << neta << " " <<std::endl;
701  }
702 } //end of convxtalid
703 
704 
705 
706 
707 int HLTEcalResonanceFilter::diff_neta_s(Int_t neta1, Int_t neta2){
708  Int_t mdiff;
709  mdiff=(neta1-neta2);
710  return mdiff;
711 }
712 
713 // Calculate the distance in xtals taking into account the periodicity of the Barrel
714 int HLTEcalResonanceFilter::diff_nphi_s(Int_t nphi1,Int_t nphi2) {
715  Int_t mdiff;
716  if(std::abs(nphi1-nphi2) < (360-std::abs(nphi1-nphi2))) {
717  mdiff=nphi1-nphi2;
718  }
719  else {
720  mdiff=360-std::abs(nphi1-nphi2);
721  if(nphi1>nphi2) mdiff=-mdiff;
722  }
723  return mdiff;
724 }
725 
726 
727 void HLTEcalResonanceFilter::calcShowerShape(const reco::BasicCluster &bc, const EcalChannelStatus &channelStatus, const EcalRecHitCollection *recHits, const CaloSubdetectorTopology *topology_p, bool calc5x5, vector<EcalRecHit> &rechit5x5, float res[]){
728 
729 
730  const std::vector< std::pair<DetId, float> > &vid = bc.hitsAndFractions();
731 
732 
733  float e2x2[4]={0};
734  float e3x3 =0 ;
735  float e5x5 =0;
736  int seedx ;
737  int seedy;
738  DetId seedId = bc.seed();
739 
740  bool InBarrel = true;
741  if( seedId.subdetId() == EcalBarrel){
742  EBDetId ebd = EBDetId(seedId);
743  seedx = ebd.ieta();
744  seedy = ebd.iphi();
745  convxtalid(seedy,seedx);
746  }else{
747  InBarrel = false;
748  EEDetId eed = EEDetId(seedId);
749  seedx = eed.ix();
750  seedy = eed.iy();
751  }
752  int x,y, dx, dy;
753 
754 
755 
756  if( calc5x5 ){
757  rechit5x5.clear();
758  std::vector<DetId> clus_v5x5;
759  clus_v5x5 = topology_p->getWindow(seedId,5,5);
760 
761  for( std::vector<DetId>::const_iterator idItr = clus_v5x5.begin(); idItr != clus_v5x5.end(); idItr++){
762  DetId ed = *idItr;
763  if( InBarrel == true){
764  EBDetId ebd = EBDetId(ed);
765  x = ebd.ieta();
766  y = ebd.iphi();
767  convxtalid(y,x);
768  dx = diff_neta_s(x,seedx);
769  dy = diff_nphi_s(y,seedy);
770  }else{
771  EEDetId eed = EEDetId(ed);
772  x = eed.ix();
773  y = eed.iy();
774  dx = x-seedx;
775  dy = y-seedy;
776  }
777  auto rit = recHits->find( ed );
778  if ( rit == recHits->end() ) continue;
779  if( ! checkStatusOfEcalRecHit(channelStatus, *rit) ) continue;
780 
781  float energy = (*rit).energy();
782  e5x5 += energy;
783 
784  auto idItrF = std::find( vid.begin(),vid.end(), std::make_pair(ed,1.0f));
785  if( idItrF == vid.end()){
786  rechit5x5.push_back(*rit);
787  }else{
788  if(std::abs(dx)<=1 && std::abs(dy)<=1) {
789  if(dx <= 0 && dy <=0) e2x2[0] += energy;
790  if(dx >= 0 && dy <=0) e2x2[1] += energy;
791  if(dx <= 0 && dy >=0) e2x2[2] += energy;
792  if(dx >= 0 && dy >=0) e2x2[3] += energy;
793  e3x3 += energy;
794  }
795  }
796  }
797 
798 
799  }else{
800 
801  for (auto const & idItr : vid){
802  DetId ed = idItr.first;
803  if( InBarrel == true){
804  EBDetId ebd = EBDetId(ed);
805  x = ebd.ieta();
806  y = ebd.iphi();
807  convxtalid(y,x);
808  dx = diff_neta_s(x,seedx);
809  dy = diff_nphi_s(y,seedy);
810  }else{
811  EEDetId eed = EEDetId(ed);
812  x = eed.ix();
813  y = eed.iy();
814  dx = x-seedx;
815  dy = y-seedy;
816  }
817  auto rit = recHits->find( ed );
818  if ( rit == recHits->end() ) {
819  continue;
820  }
821 
822  float energy = (*rit).energy();
823  if(std::abs(dx)<=1 && std::abs(dy)<=1){
824  if(dx <= 0 && dy <=0) e2x2[0] += energy;
825  if(dx >= 0 && dy <=0) e2x2[1] += energy;
826  if(dx <= 0 && dy >=0) e2x2[2] += energy;
827  if(dx >= 0 && dy >=0) e2x2[3] += energy;
828  e3x3 += energy;
829  }
830 
831  }
832  e5x5 = e3x3;
833  }
834 
835 
836 
838  res[0] = *max_element( e2x2,e2x2+4);
839  res[1] = e3x3;
840  res[2] = e5x5;
841 
842 
843 }
844 
845 
846 
847 
848 void HLTEcalResonanceFilter::calcPaircluster(const reco::BasicCluster &bc1, const reco::BasicCluster &bc2,float &m_pair,float &pt_pair,float &eta_pair, float &phi_pair){
849 
850 
851  float theta1 = 2. * atan(exp(-bc1.eta()));
852  float en1 = bc1.energy();
853  float pt1 = en1 * sin(theta1);
854  TLorentzVector v1( pt1 *cos(bc1.phi()),pt1 * sin(bc1.phi()),en1*cos(theta1),en1);
855 
856  float theta2 = 2. * atan(exp(-bc2.eta()));
857  float en2 = bc2.energy();
858  float pt2 = en2 * sin(theta2);
859  TLorentzVector v2( pt2 *cos(bc2.phi()),pt2 * sin(bc2.phi()),en2*cos(theta2),en2);
860 
861  TLorentzVector v = v1 + v2;
862 
863  m_pair = v.M();
864  pt_pair = v.Pt();
865  eta_pair = v.Eta();
866  phi_pair = v.Phi();
867 
868 
869 }
870 
871 
872 
873 
874 
876 
877  if(useRecoFlag_ ){
878  int flag = rh.recoFlag();
879  if( flagLevelRecHitsToUse_ ==0){
880  if( flag != 0) return false;
881  }
882  else if( flagLevelRecHitsToUse_ ==1){
883  if( flag !=0 && flag != 4 ) return false;
884  }
885  else if( flagLevelRecHitsToUse_ ==2){
886  if( flag !=0 && flag != 4 && flag != 6 && flag != 7) return false;
887  }
888  }
889  if ( useDBStatus_){
890  int status = int(channelStatus[rh.id().rawId()].getStatusCode());
891  if ( status > statusLevelRecHitsToUse_ ) return false;
892  }
893 
894  return true;
895 }
896 
897 
898 float HLTEcalResonanceFilter::DeltaPhi(float phi1, float phi2){
899 
900  float diff = fabs(phi2 - phi1);
901 
902  while (diff >acos(-1)) diff -= 2*acos(-1);
903  while (diff <= -acos(-1)) diff += 2*acos(-1);
904 
905  return diff;
906 
907 }
908 
909 
910 float HLTEcalResonanceFilter::GetDeltaR(float eta1, float eta2, float phi1, float phi2){
911 
912  return sqrt( (eta1-eta2)*(eta1-eta2)
913  + DeltaPhi(phi1, phi2)*DeltaPhi(phi1, phi2) );
914 
915 }
916 
917 
918 void HLTEcalResonanceFilter::makeClusterES(float x, float y, float z, const CaloSubdetectorGeometry* geometry_es,
919  const CaloSubdetectorTopology* topology_es
920  ){
921 
922 
924  const GlobalPoint point(x,y,z);
925  DetId tmp1 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_es))->getClosestCellInPlane(point, 1);
926  DetId tmp2 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_es))->getClosestCellInPlane(point, 2);
927  ESDetId strip1 = (tmp1 == DetId(0)) ? ESDetId(0) : ESDetId(tmp1);
928  ESDetId strip2 = (tmp2 == DetId(0)) ? ESDetId(0) : ESDetId(tmp2);
929 
930  // Get ES clusters (found by the PreshSeeded algorithm) associated with a given EE cluster.
931  for (int i2=0; i2<preshNclust_; i2++) {
932  reco::PreshowerCluster cl1 = presh_algo_->makeOneCluster(strip1,&m_used_strips,&m_esrechit_map,geometry_es,topology_es);
933  reco::PreshowerCluster cl2 = presh_algo_->makeOneCluster(strip2,&m_used_strips,&m_esrechit_map,geometry_es,topology_es);
934  } // end of cycle over ES clusters
935 
936 }
937 
938 // declare this class as a framework plugin
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:39
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:49
EventNumber_t event() const
Definition: EventID.h:41
void doSelection(int detector, const reco::BasicClusterCollection *clusterCollection, const EcalRecHitCollection *hitCollection, const EcalChannelStatus &channelStatus, const CaloSubdetectorTopology *topology_p, std::map< int, std::vector< EcalRecHit > > &RecHits5x5_clus, std::vector< int > &indCandClus, std::vector< int > &indIsoClus, std::vector< int > &indClusSelected)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
int ix() const
Definition: EEDetId.h:77
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
bool filter(edm::Event &, const edm::EventSetup &) override
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
std::vector< EcalRecHit >::const_iterator const_iterator
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
Definition: Electron.h:6
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
static float DeltaPhi(float phi1, float phi2)
bool checkStatusOfEcalRecHit(const EcalChannelStatus &channelStatus, const EcalRecHit &rh)
void makeClusterES(float x, float y, float z, const CaloSubdetectorGeometry *iSubGeom, const CaloSubdetectorTopology *topology_p)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
T sqrt(T t)
Definition: SSEVec.h:18
void calcPaircluster(const reco::BasicCluster &bc1, const reco::BasicCluster &bc2, float &mpair, float &ptpair, float &etapair, float &phipair)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
HLTEcalResonanceFilter(const edm::ParameterSet &)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
int iy() const
Definition: EEDetId.h:83
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
static float GetDeltaR(float eta1, float eta2, float phi1, float phi2)
int k[5][pyjets_maxn]
const_iterator end() const
Definition: DetId.h:18
virtual std::vector< DetId > getWindow(const DetId &id, const int &northSouthSize, const int &eastWestSize) const
DetId id() const
get the id
Definition: EcalRecHit.h:77
T const * product() const
Definition: Handle.h:74
Flags recoFlag() const
DEPRECATED provided for temporary backward compatibility.
Definition: EcalRecHit.h:207
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const CaloSubdetectorTopology * getSubdetectorTopology(const DetId &id) const
access the subdetector Topology for the given subdetector directly
Definition: CaloTopology.cc:20
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
double ptmin
Definition: HydjetWrapper.h:90
edm::EventID id() const
Definition: EventBase.h:59
iterator find(key_type k)
HLT enums.
size_type size() const
T get() const
Definition: EventSetup.h:71
void calcShowerShape(const reco::BasicCluster &bc, const EcalChannelStatus &channelStatus, const EcalRecHitCollection *recHits, const CaloSubdetectorTopology *topology_p, bool calc5x5, std::vector< EcalRecHit > &rechit5x5, float res[])
def move(src, dest)
Definition: eostools.py:511
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
const_iterator begin() const