CMS 3D CMS Logo

HLTRegionalEcalResonanceFilter.cc
Go to the documentation of this file.
4 
5 #include "DataFormats/Math/interface/Vector3D.h" // to use math::XYZVector
6 #include "DataFormats/Math/interface/deltaPhi.h" // use already existing deltaPhi function to return deltaPhi in [-pi, pi]
7 
8 using namespace std;
9 using namespace edm;
10 
12 {
13  barrelHits_ = iConfig.getParameter< edm::InputTag > ("barrelHits");
14  barrelClusters_ = iConfig.getParameter< edm::InputTag > ("barrelClusters");
15  barrelHitsToken_ = consumes<EBRecHitCollection>(barrelHits_);
16  barrelClustersToken_ = consumes<reco::BasicClusterCollection>(barrelClusters_);
17 
18  endcapHits_ = iConfig.getParameter< edm::InputTag > ("endcapHits");
19  endcapClusters_ = iConfig.getParameter< edm::InputTag > ("endcapClusters");
20  endcapHitsToken_ = consumes<EERecHitCollection>(endcapHits_);
21  endcapClustersToken_ = consumes<reco::BasicClusterCollection>(endcapClusters_);
22 
23  doSelBarrel_ = iConfig.getParameter<bool>("doSelBarrel");
24 
25  if(doSelBarrel_){
26  edm::ParameterSet barrelSelection = iConfig.getParameter<edm::ParameterSet>( "barrelSelection" );
27 
29  // EB region 1
30  region1_Barrel_ = barrelSelection.getParameter<double> ("region1_Barrel"); //eta dividing between region 1 and region 2
31  selePtGammaBarrel_region1_ = barrelSelection.getParameter<double> ("selePtGammaBarrel_region1");
32  selePtPairBarrel_region1_ = barrelSelection.getParameter<double> ("selePtPairBarrel_region1");
33  seleS4S9GammaBarrel_region1_ = barrelSelection.getParameter<double> ("seleS4S9GammaBarrel_region1");
34  seleIsoBarrel_region1_ = barrelSelection.getParameter<double> ("seleIsoBarrel_region1");
35  seleNxtalBarrel_region1_ = barrelSelection.getParameter<uint32_t> ("seleNxtalBarrel_region1");
36 
37  // EB region 2
38  selePtGammaBarrel_region2_ = barrelSelection.getParameter<double> ("selePtGammaBarrel_region2");
39  selePtPairBarrel_region2_ = barrelSelection.getParameter<double> ("selePtPairBarrel_region2");
40  seleS4S9GammaBarrel_region2_ = barrelSelection.getParameter<double> ("seleS4S9GammaBarrel_region2");
41  seleIsoBarrel_region2_ = barrelSelection.getParameter<double> ("seleIsoBarrel_region2");
42  seleNxtalBarrel_region2_ = barrelSelection.getParameter<uint32_t> ("seleNxtalBarrel_region2");
43 
44  // other
45  seleS9S25Gamma_ = barrelSelection.getParameter<double> ("seleS9S25Gamma");
46 
47  //mass window
48  seleMinvMaxBarrel_ = barrelSelection.getParameter<double> ("seleMinvMaxBarrel");
49  seleMinvMinBarrel_ = barrelSelection.getParameter<double> ("seleMinvMinBarrel");
50 
51  // remove pi0 candidates for eta dataset
52  removePi0CandidatesForEta_ = barrelSelection.getParameter<bool>("removePi0CandidatesForEta");
53  if(removePi0CandidatesForEta_){
54  massLowPi0Cand_ = barrelSelection.getParameter<double>("massLowPi0Cand");
55  massHighPi0Cand_ = barrelSelection.getParameter<double>("massHighPi0Cand");
56  }
57 
58  // EB Isolation configuration
59  ptMinForIsolation_ = barrelSelection.getParameter<double> ("ptMinForIsolation");
60  seleBeltDR_ = barrelSelection.getParameter<double> ("seleBeltDR");
61  seleBeltDeta_ = barrelSelection.getParameter<double> ("seleBeltDeta");
62 
63  // EB storage and collection
64  store5x5RecHitEB_ = barrelSelection.getParameter<bool> ("store5x5RecHitEB");
65  BarrelHits_ = barrelSelection.getParameter<string> ("barrelHitCollection");
66 
67  // selePtGamma_ = barrelSelection.getParameter<double> ("selePtGamma"); // old non-region filter
68  // selePtPair_ = barrelSelection.getParameter<double> ("selePtPair"); // old non-region filter
69  // seleS4S9Gamma_ = barrelSelection.getParameter<double> ("seleS4S9Gamma"); //old non-region filter
70  // seleIso_ = barrelSelection.getParameter<double> ("seleIso"); // old non-region filter
71 
72  produces<EBRecHitCollection>(BarrelHits_);
73  }
74 
75 
76  doSelEndcap_ = iConfig.getParameter<bool>("doSelEndcap");
77  if(doSelEndcap_){
78  edm::ParameterSet endcapSelection = iConfig.getParameter<edm::ParameterSet>( "endcapSelection" );
79 
81  seleMinvMaxEndCap_ = endcapSelection.getParameter<double> ("seleMinvMaxEndCap");
82  seleMinvMinEndCap_ = endcapSelection.getParameter<double> ("seleMinvMinEndCap");
83 
84  // EE region 1
85  region1_EndCap_ = endcapSelection.getParameter<double> ("region1_EndCap"); //eta dividing between region 1 and region 2
86  selePtGammaEndCap_region1_ = endcapSelection.getParameter<double> ("selePtGammaEndCap_region1");
87  selePtPairEndCap_region1_ = endcapSelection.getParameter<double> ("selePtPairEndCap_region1");
88  seleS4S9GammaEndCap_region1_ = endcapSelection.getParameter<double> ("seleS4S9GammaEndCap_region1");
89  seleIsoEndCap_region1_ = endcapSelection.getParameter<double> ("seleIsoEndCap_region1");
90  seleNxtalEndCap_region1_ = endcapSelection.getParameter<uint32_t> ("seleNxtalEndCap_region1");
91 
92  // EE region 2
93  region2_EndCap_ = endcapSelection.getParameter<double> ("region2_EndCap"); //eta dividing between region 2 and region 3
94  selePtGammaEndCap_region2_ = endcapSelection.getParameter<double> ("selePtGammaEndCap_region2");
95  selePtPairEndCap_region2_ = endcapSelection.getParameter<double> ("selePtPairEndCap_region2");
96  seleS4S9GammaEndCap_region2_ = endcapSelection.getParameter<double> ("seleS4S9GammaEndCap_region2");
97  seleIsoEndCap_region2_ = endcapSelection.getParameter<double> ("seleIsoEndCap_region2");
98  seleNxtalEndCap_region2_ = endcapSelection.getParameter<uint32_t> ("seleNxtalEndCap_region2");
99 
100  // EE region 3 (available but not yet used)
101  selePtGammaEndCap_region3_ = endcapSelection.getParameter<double> ("selePtGammaEndCap_region3");
102  selePtPairEndCap_region3_ = endcapSelection.getParameter<double> ("selePtPairEndCap_region3");
103  selePtPairMaxEndCap_region3_ = endcapSelection.getParameter<double> ("selePtPairMaxEndCap_region3");
104  seleS4S9GammaEndCap_region3_ = endcapSelection.getParameter<double> ("seleS4S9GammaEndCap_region3");
105  seleIsoEndCap_region3_ = endcapSelection.getParameter<double> ("seleIsoEndCap_region3");
106  seleNxtalEndCap_region3_ = endcapSelection.getParameter<uint32_t> ("seleNxtalEndCap_region3");
107 
108  seleS9S25GammaEndCap_ = endcapSelection.getParameter<double> ("seleS9S25GammaEndCap");
109 
110  // isolation belt and size configuration
111  ptMinForIsolationEndCap_ = endcapSelection.getParameter<double> ("ptMinForIsolationEndCap");
112  seleBeltDREndCap_ = endcapSelection.getParameter<double> ("seleBeltDREndCap");
113  seleBeltDetaEndCap_ = endcapSelection.getParameter<double> ("seleBeltDetaEndCap");
114 
115  // EE storage and collections
116  store5x5RecHitEE_ = endcapSelection.getParameter<bool> ("store5x5RecHitEE");
117  EndcapHits_ = endcapSelection.getParameter<string > ("endcapHitCollection");
118 
119  //seleS4S9GammaEndCap_ = endcapSelection.getParameter<double> ("seleS4S9GammaEndCap"); // old non-region filter
120  //seleIsoEndCap_ = endcapSelection.getParameter<double> ("seleIsoEndCap"); // old non-region filter
121 
122  produces< EERecHitCollection >(EndcapHits_);
123 
124  }
125 
126  useRecoFlag_ = iConfig.getParameter<bool>("useRecoFlag");
127  flagLevelRecHitsToUse_ = iConfig.getParameter<int>("flagLevelRecHitsToUse");
128 
129  useDBStatus_ = iConfig.getParameter<bool>("useDBStatus");
130  statusLevelRecHitsToUse_ = iConfig.getParameter<int>("statusLevelRecHitsToUse");
131 
132 
133  preshHitProducer_ = iConfig.getParameter<edm::InputTag>("preshRecHitProducer");
134  preshHitsToken_ = consumes<EBRecHitCollection>(preshHitProducer_);
135 
137  storeRecHitES_ = iConfig.getParameter<bool>("storeRecHitES");
138  if(storeRecHitES_){
139 
140  edm::ParameterSet preshowerSelection = iConfig.getParameter<edm::ParameterSet>( "preshowerSelection" );
141 
142  // maximum number of matched ES clusters (in each ES layer) to each BC
143  preshNclust_ = preshowerSelection.getParameter<int>("preshNclust");
144  // min energy of ES clusters
145  preshClustECut = preshowerSelection.getParameter<double>("preshClusterEnergyCut");
146  // algo params
147  float preshStripECut = preshowerSelection.getParameter<double>("preshStripEnergyCut");
148  int preshSeededNst = preshowerSelection.getParameter<int>("preshSeededNstrip");
149  // calibration parameters:
150  calib_planeX_ = preshowerSelection.getParameter<double>("preshCalibPlaneX");
151  calib_planeY_ = preshowerSelection.getParameter<double>("preshCalibPlaneY");
152  gamma_ = preshowerSelection.getParameter<double>("preshCalibGamma");
153  mip_ = preshowerSelection.getParameter<double>("preshCalibMIP");
154 
155  // ES algo constructor:
156  presh_algo_ = new PreshowerClusterAlgo(preshStripECut,preshClustECut,preshSeededNst);
157 
158  ESHits_ = preshowerSelection.getParameter< std::string > ("ESCollection");
159  produces< ESRecHitCollection >(ESHits_);
160  }
161 
162  debug_ = iConfig.getParameter<int> ("debugLevel");
163 
164 }
165 
166 
168 {
169  if(storeRecHitES_){
170  delete presh_algo_;
171  }
172 }
173 
174 
175 void
178  desc.add<edm::InputTag>("barrelHits",edm::InputTag("hltEcalRegionalPi0EtaRecHit","EcalRecHitsEB"));
179  desc.add<edm::InputTag>("endcapHits",edm::InputTag("hltEcalRegionalPi0EtaRecHit","EcalRecHitsEE"));
180  desc.add<edm::InputTag>("preshRecHitProducer",edm::InputTag("hltEcalRegionalPi0EtaRecHit","EcalRecHitsES"));
181  desc.add<edm::InputTag>("barrelClusters",edm::InputTag("hltSimple3x3Clusters","Simple3x3ClustersBarrel"));
182  desc.add<edm::InputTag>("endcapClusters",edm::InputTag("hltSimple3x3Clusters","Simple3x3ClustersEndcap"));
183  desc.add<bool>("useRecoFlag",false);
184  desc.add<int>("flagLevelRecHitsToUse",1);
185  desc.add<bool>("useDBStatus",true);
186  desc.add<int>("statusLevelRecHitsToUse",1);
187 
188  //----------------------BARREL CONFIGURATION-----------------
189  desc.add<bool>("doSelBarrel",true);
190  edm::ParameterSetDescription barrelSelection;
191 
192  //EB region 1
193  barrelSelection.add<double>("region1_Barrel", 1.0); //separator between barrel region 1 and region 2
194  barrelSelection.add<double>("selePtGammaBarrel_region1", 1.0);
195  barrelSelection.add<double>("selePtPairBarrel_region1", 2.0);
196  barrelSelection.add<double>("seleIsoBarrel_region1", 0.5);
197  barrelSelection.add<uint32_t>("seleNxtalBarrel_region1", 6);
198  barrelSelection.add<double>("seleS4S9GammaBarrel_region1", 0.83);
199 
200  //EB region 2
201  barrelSelection.add<double>("selePtGammaBarrel_region2", 1.0);
202  barrelSelection.add<double>("selePtPairBarrel_region2", 2.0);
203  barrelSelection.add<double>("seleIsoBarrel_region2", 0.5);
204  barrelSelection.add<uint32_t>("seleNxtalBarrel_region2", 6);
205  barrelSelection.add<double>("seleS4S9GammaBarrel_region2", 0.83);
206 
207  //EB Isolation configuration
208  barrelSelection.add<double>("ptMinForIsolation", 1.0);
209  barrelSelection.add<double>("seleBeltDR", 0.2);
210  barrelSelection.add<double>("seleBeltDeta", 0.05);
211 
212  //other parameters
213  barrelSelection.add<double>("seleMinvMaxBarrel", 0.22);
214  barrelSelection.add<double>("seleMinvMinBarrel", 0.06);
215  barrelSelection.add<bool>("removePi0CandidatesForEta",false);
216  barrelSelection.add<double>("massLowPi0Cand", 0.104);
217  barrelSelection.add<double>("massHighPi0Cand", 0.163);
218  barrelSelection.add<double>("seleS9S25Gamma", 0.);
219 
220  //collections and storage
221  barrelSelection.add<bool>("store5x5RecHitEB",false);
222  barrelSelection.add<std::string>("barrelHitCollection","pi0EcalRecHitsEB");
223  desc.add<edm::ParameterSetDescription>("barrelSelection", barrelSelection);
224 
225  //barrelSelection.add<double>("selePtGamma",1.); //old non-region
226  //barrelSelection.add<double>("selePtPair",2.); //old non-regional
227  //barrelSelection.add<double>("seleIso",0.5); //old non-regional
228  //barrelSelection.add<double>("seleS4S9Gamma",0.83); //old non-regional
229 
230 
231  //----------------------ENDCAP CONFIGURATION-----------------
232 
233  desc.add<bool>("doSelEndcap",true);
234  edm::ParameterSetDescription endcapSelection;
235  // Mass Cuts
236  endcapSelection.add<double>("seleMinvMaxEndCap", 0.3);
237  endcapSelection.add<double>("seleMinvMinEndCap", 0.05);
238 
239  // EE region 1
240  endcapSelection.add<double>("region1_EndCap", 2.0); // eta division between endcap region 1 and 2
241  endcapSelection.add<double>("selePtGammaEndCap_region1", 0.8);
242  endcapSelection.add<double>("selePtPairEndCap_region1", 3.0);
243  endcapSelection.add<double>("seleS4S9GammaEndCap_region1", 0.9);
244  endcapSelection.add<double>("seleIsoEndCap_region1", 0.5);
245  endcapSelection.add<uint32_t>("seleNxtalEndCap_region1", 6);
246 
247  // EE region 2
248  endcapSelection.add<double>("region2_EndCap", 2.5); // eta division between endcap region 2 and 3
249  endcapSelection.add<double>("selePtGammaEndCap_region2", 0.5);
250  endcapSelection.add<double>("selePtPairEndCap_region2", 2.0);
251  endcapSelection.add<double>("seleS4S9GammaEndCap_region2", 0.9);
252  endcapSelection.add<double>("seleIsoEndCap_region2", 0.5);
253  endcapSelection.add<uint32_t>("seleNxtalEndCap_region2", 6);
254 
255  // EE region 3
256  endcapSelection.add<double>("selePtGammaEndCap_region3", 0.3);
257  endcapSelection.add<double>("selePtPairEndCap_region3", 1.2);
258  endcapSelection.add<double>("selePtPairMaxEndCap_region3", 2.5);
259  endcapSelection.add<double>("seleS4S9GammaEndCap_region3", 0.9);
260  endcapSelection.add<double>("seleIsoEndCap_region3", 0.5);
261  endcapSelection.add<uint32_t>("seleNxtalEndCap_region3", 6);
262 
263  // other
264  endcapSelection.add<double>("seleS9S25GammaEndCap", 0.);
265 
266  // isolation configuration for endcap
267  endcapSelection.add<double>("ptMinForIsolationEndCap", 0.5);
268  endcapSelection.add<double>("seleBeltDREndCap", 0.2);
269  endcapSelection.add<double>("seleBeltDetaEndCap", 0.05);
270 
271  // collections and storage
272  endcapSelection.add<bool>("store5x5RecHitEE", false);
273  endcapSelection.add<std::string>("endcapHitCollection", "pi0EcalRecHitsEE");
274  desc.add<edm::ParameterSetDescription>("endcapSelection", endcapSelection);
275 
276  //endcapSelection.add<double>("seleS4S9GammaEndCap",0.9); //old non-region filter
277 
278  //-----------------------------------------------------------
279 
280  desc.add<bool>("storeRecHitES",true);
281  edm::ParameterSetDescription preshowerSelection;
282  preshowerSelection.add<std::string>("ESCollection","pi0EcalRecHitsES");
283  preshowerSelection.add<int>("preshNclust",4);
284  preshowerSelection.add<double>("preshClusterEnergyCut",0.0);
285  preshowerSelection.add<double>("preshStripEnergyCut",0.0);
286  preshowerSelection.add<int>("preshSeededNstrip",15);
287  preshowerSelection.add<double>("preshCalibPlaneX",1.0);
288  preshowerSelection.add<double>("preshCalibPlaneY",0.7);
289  preshowerSelection.add<double>("preshCalibGamma",0.024);
290  preshowerSelection.add<double>("preshCalibMIP",9.0E-5);
291  preshowerSelection.add<std::string>("debugLevelES",""); // *** This is not needed and shoul be better removed !
292  desc.add<edm::ParameterSetDescription>("preshowerSelection",preshowerSelection);
293 
294  desc.add<int>("debugLevel",0);
295  descriptions.add("hltRegionalEcalResonanceFilter",desc);
296 }
297 
298 // ------------ method called to produce the data ------------
300 {
301  //Create empty output collections
302  std::unique_ptr< EBRecHitCollection > selEBRecHitCollection( new EBRecHitCollection );
303  //Create empty output collections
304  std::unique_ptr< EERecHitCollection > selEERecHitCollection( new EERecHitCollection );
305 
306 
308  vector<DetId> selectedEBDetIds;
309  vector<DetId> selectedEEDetIds;
310 
311 
312  edm::ESHandle<CaloTopology> pTopology;
313  iSetup.get<CaloTopologyRecord>().get(pTopology);
314  const CaloSubdetectorTopology *topology_eb = pTopology->getSubdetectorTopology(DetId::Ecal,EcalBarrel);
315  const CaloSubdetectorTopology *topology_ee = pTopology->getSubdetectorTopology(DetId::Ecal,EcalEndcap);
316 
317 
318  edm::ESHandle<CaloGeometry> geoHandle;
319  iSetup.get<CaloGeometryRecord>().get(geoHandle);
321  std::unique_ptr<CaloSubdetectorTopology> topology_es;
322  if (geometry_es) {
323  topology_es = std::make_unique<EcalPreshowerTopology>();
324  }else{
325  storeRecHitES_ = false;
326  }
327 
328 
331  if ( useDBStatus_ ) iSetup.get<EcalChannelStatusRcd>().get(csHandle);
332  const EcalChannelStatus &channelStatus = *csHandle;
333 
335 
336  Handle<EBRecHitCollection> barrelRecHitsHandle;
337 
338  iEvent.getByToken(barrelHitsToken_,barrelRecHitsHandle);
339  if (!barrelRecHitsHandle.isValid()) {
340  LogError("AlCaEcalResonanceProducer") << "AlCaEcalResonanceProducer: Error! can't get product barrel hits!";
341  }
342 
343  const EcalRecHitCollection *hitCollection_eb = barrelRecHitsHandle.product();
344 
345 
346  Handle<reco::BasicClusterCollection> barrelClustersHandle;
347  iEvent.getByToken(barrelClustersToken_,barrelClustersHandle);
348  if (!barrelClustersHandle.isValid()) {
349  LogError("AlCaEcalResonanceProducer") << "AlCaEcalResonanceProducer: Error! can't get product barrel clusters!";
350  }
351  const reco::BasicClusterCollection *clusterCollection_eb = barrelClustersHandle.product();
352  if(debug_>=1)
353  LogDebug("AlCaEcalResonanceProducer") <<" barrel_input_size: run "<<iEvent.id().run()<<" event "<<iEvent.id().event()<<" nhitEB: "<<hitCollection_eb->size()<<" nCluster: "<< clusterCollection_eb->size();
354 
355 
356  if(doSelBarrel_){
357 
358  map<int, vector<EcalRecHit> > RecHits5x5_clus;
359  vector<int> indIsoClus;
360  vector<int> indCandClus;
361  vector<int> indClusSelected;
362 
363  doSelection( EcalBarrel,clusterCollection_eb, hitCollection_eb, channelStatus,topology_eb,
364  RecHits5x5_clus,
365  indCandClus,indIsoClus, indClusSelected);
366 
367 
369  for(int ind : indClusSelected){
370  auto it_bc3 = clusterCollection_eb->begin() + ind;
371  const std::vector< std::pair<DetId, float> > &vid = it_bc3->hitsAndFractions();
372  for (auto const & idItr : vid){
373  auto hit = hitCollection_eb->find(idItr.first);
374  if( hit == hitCollection_eb->end()) continue; //this should not happen.
375  selEBRecHitCollection->push_back(*hit);
376  selectedEBDetIds.push_back(idItr.first);
377  }
378  }
379 
380 
381  if( store5x5RecHitEB_ ){
383  for(int ind : indCandClus){
384  vector<EcalRecHit> v5x5 = RecHits5x5_clus[ind];
385  for(auto & n : v5x5){
386  DetId ed = n.id();
387  auto itdet = find(selectedEBDetIds.begin(),selectedEBDetIds.end(),ed);
388  if( itdet == selectedEBDetIds.end()){
389  selectedEBDetIds.push_back(ed);
390  selEBRecHitCollection->push_back(n);
391  }
392  }
393  }
394 
395 
397  for(int ind : indIsoClus){
398  auto it = find(indCandClus.begin(),indCandClus.end(), ind);
399  if( it != indCandClus.end()) continue;
400 
401  auto it_bc3 = clusterCollection_eb->begin() + ind;
402  DetId seedId = it_bc3->seed();
403  std::vector<DetId> clus_v5x5 = topology_eb->getWindow(seedId,5,5);
404  for( std::vector<DetId>::const_iterator idItr = clus_v5x5.begin(); idItr != clus_v5x5.end(); idItr++){
405  DetId ed = *idItr;
406  auto rit = hitCollection_eb->find( ed );
407  if ( rit == hitCollection_eb->end() ) continue;
408  if( ! checkStatusOfEcalRecHit(channelStatus, *rit) ) continue;
409  auto itdet = find(selectedEBDetIds.begin(),selectedEBDetIds.end(),ed);
410  if( itdet == selectedEBDetIds.end()){
411  selectedEBDetIds.push_back(ed);
412  selEBRecHitCollection->push_back(*rit);
413  }
414  }
415  }
416  }
417 
418 
419  }// end of selection for eta/pi0->gg in the barrel
420 
421  int eb_collsize = selEBRecHitCollection->size();
422 
423  if(debug_>=1)
424  LogDebug("AlCaEcalResonanceProducer") <<" barrel_output_size_run "<<iEvent.id().run()<<" event "<<iEvent.id().event()<<" nEBSaved "<<selEBRecHitCollection->size();
426 
427 
428 
429  //===============Start of Endcap =================/////
431  Handle<ESRecHitCollection> esRecHitsHandle;
432  iEvent.getByToken(preshHitsToken_,esRecHitsHandle);
433  if( !esRecHitsHandle.isValid()){
434  LogError("AlCaEcalResonanceProducer") << "AlCaEcalResonanceProducer: Error! can't get product esRecHit!";
435  }
436  const EcalRecHitCollection* hitCollection_es = esRecHitsHandle.product();
437  // make a map of rechits:
438  m_esrechit_map.clear();
440  for (iter = esRecHitsHandle->begin(); iter != esRecHitsHandle->end(); iter++) {
441  //Make the map of DetID, EcalRecHit pairs
442  m_esrechit_map.insert(std::make_pair(iter->id(), *iter));
443  }
444  // The set of used DetID's for a given event:
445  m_used_strips.clear();
446  std::unique_ptr<ESRecHitCollection> selESRecHitCollection(new ESRecHitCollection );
447 
448  Handle<EERecHitCollection> endcapRecHitsHandle;
449  iEvent.getByToken(endcapHitsToken_,endcapRecHitsHandle);
450  if (!endcapRecHitsHandle.isValid()) {
451  LogError("AlCaEcalResonanceProducer") << "AlCaEcalResonanceProducer: Error! can't get product endcap hits!";
452  }
453  const EcalRecHitCollection *hitCollection_ee = endcapRecHitsHandle.product();
454  Handle<reco::BasicClusterCollection> endcapClustersHandle;
455  iEvent.getByToken(endcapClustersToken_,endcapClustersHandle);
456  if (!endcapClustersHandle.isValid()) {
457  LogError("AlCaEcalResonanceProducer") << "AlCaEcalResonanceProducer: Error! can't get product endcap clusters!";
458  }
459  const reco::BasicClusterCollection *clusterCollection_ee = endcapClustersHandle.product();
460  if(debug_>=1)
461  LogDebug("AlCaEcalResonanceProducer") <<" endcap_input_size: run "<<iEvent.id().run()<<" event "<<iEvent.id().event()<<" nhitEE: "<<hitCollection_ee->size()<<" nhitES: "<<hitCollection_es->size()<<" nCluster: "<< clusterCollection_ee->size();
462 
463 
464  if(doSelEndcap_){
465 
466  map<int, vector<EcalRecHit> > RecHits5x5_clus;
467  vector<int> indIsoClus;
468  vector<int> indCandClus;
469  vector<int> indClusSelected;
470 
471  doSelection( EcalEndcap,clusterCollection_ee, hitCollection_ee, channelStatus,topology_ee,
472  RecHits5x5_clus,
473  indCandClus,indIsoClus, indClusSelected);
474 
476  for(int ind : indClusSelected){
477  auto it_bc3 = clusterCollection_ee->begin() + ind;
478  const std::vector< std::pair<DetId, float> > &vid = it_bc3->hitsAndFractions();
479  for (auto const & idItr : vid){
480  auto hit = hitCollection_ee->find(idItr.first);
481  if( hit == hitCollection_ee->end()) continue; //this should not happen.
482  selEERecHitCollection->push_back(*hit);
483  selectedEEDetIds.push_back(idItr.first);
484  }
486  if(storeRecHitES_){
487  std::set<DetId> used_strips_before = m_used_strips;
488  makeClusterES(it_bc3->x(),it_bc3->y(),it_bc3->z(),geometry_es,topology_es.get());
489  auto ites = m_used_strips.begin();
490  for(; ites != m_used_strips.end(); ++ ites ){
491  ESDetId d1 = ESDetId(*ites);
492  auto ites2 = find(used_strips_before.begin(),used_strips_before.end(),d1);
493  if( (ites2 == used_strips_before.end())){
494  auto itmap = m_esrechit_map.find(d1);
495  selESRecHitCollection->push_back(itmap->second);
496  }
497  }
498  }
499  }
500 
501 
502  if( store5x5RecHitEE_ ){
504  for(int ind : indCandClus){
505  vector<EcalRecHit> v5x5 = RecHits5x5_clus[ind];
506  for(auto & n : v5x5){
507  DetId ed = n.id();
508  auto itdet = find(selectedEEDetIds.begin(),selectedEEDetIds.end(),ed);
509  if( itdet == selectedEEDetIds.end()){
510  selectedEEDetIds.push_back(ed);
511  selEERecHitCollection->push_back(n);
512  }
513  }
514  }
515 
516 
518  for(int ind : indIsoClus){
519  auto it = find(indCandClus.begin(),indCandClus.end(), ind);
520  if( it != indCandClus.end()) continue;
521 
522  auto it_bc3 = clusterCollection_ee->begin() + ind;
523  DetId seedId = it_bc3->seed();
524  std::vector<DetId> clus_v5x5 = topology_ee->getWindow(seedId,5,5);
525  for( std::vector<DetId>::const_iterator idItr = clus_v5x5.begin(); idItr != clus_v5x5.end(); idItr++){
526  DetId ed = *idItr;
527  auto rit = hitCollection_ee->find( ed );
528  if ( rit == hitCollection_ee->end() ) continue;
529  if( ! checkStatusOfEcalRecHit(channelStatus, *rit) ) continue;
530  auto itdet = find(selectedEEDetIds.begin(),selectedEEDetIds.end(),ed);
531  if( itdet == selectedEEDetIds.end()){
532  selectedEEDetIds.push_back(ed);
533  selEERecHitCollection->push_back(*rit);
534  }
535  }
536  }
537  }
538 
539  }// end of selection for eta/pi0->gg in the endcap
540 
541 
542 
544 
545  if(debug_>=1)
546  LogDebug("AlCaEcalResonanceProducer") <<" endcap_output_size run "<<iEvent.id().run()<<"_"<<iEvent.id().event()<<" nEESaved "<<selEERecHitCollection->size()<<" nESSaved: " << selESRecHitCollection->size();
547 
548 
549  //Put selected information in the event
550  int ee_collsize = selEERecHitCollection->size();
551 
552  if( eb_collsize < 2 && ee_collsize <2)
553  return false;
554 
556  if(doSelBarrel_){
557  iEvent.put(std::move(selEBRecHitCollection), BarrelHits_);
558  }
559  if(doSelEndcap_){
560  iEvent.put(std::move(selEERecHitCollection), EndcapHits_);
561  if(storeRecHitES_){
562  iEvent.put(std::move(selESRecHitCollection), ESHits_);
563  }
564  }
565 
566  return true;
567 
568 
569 }
570 
571 
572 
575  const EcalChannelStatus &channelStatus,
576  const CaloSubdetectorTopology *topology_p,
577  map<int, vector<EcalRecHit> > &RecHits5x5_clus,
578  vector<int> &indCandClus,
579  vector<int> &indIsoClus,
580  vector<int> &indClusSelected
581  ){
582 
583 
584  vector<int> indClusPi0Candidates;
585  if( detector ==EcalBarrel && removePi0CandidatesForEta_){
586  for( auto it_bc = clusterCollection->begin(); it_bc != clusterCollection->end();it_bc++){
587  for( auto it_bc2 = it_bc + 1 ; it_bc2 != clusterCollection->end();it_bc2++){
588  float m_pair,pt_pair,eta_pair, phi_pair;
589  calcPaircluster(*it_bc,*it_bc2, m_pair, pt_pair,eta_pair,phi_pair);
590  if(m_pair > massLowPi0Cand_ && m_pair < massHighPi0Cand_){
591  int indtmp[2]={ int( it_bc - clusterCollection->begin()), int( it_bc2 - clusterCollection->begin())};
592  for(int & k : indtmp){
593  auto it = find(indClusPi0Candidates.begin(),indClusPi0Candidates.end(),k);
594  if( it == indClusPi0Candidates.end()) indClusPi0Candidates.push_back(k);
595  }
596  }
597  }
598  }//end of loop over finding pi0's clusters
599  }
600 
601  //mass cut
602  double m_minCut = seleMinvMinBarrel_;
603  double m_maxCut = seleMinvMaxBarrel_;
604 
605  //isolation
606  double ptminforIso = ptMinForIsolation_;
607  double isoBeltdrCut = seleBeltDR_ ;
608  double isoBeltdetaCut = seleBeltDeta_;
609 
610  //other
611  double s9s25Cut = seleS9S25Gamma_;
612  bool store5x5 = store5x5RecHitEB_;
613 
614  //double isoCut = seleIso_; //old non-region filter
615  //double s4s9Cut = seleS4S9Gamma_; // old non-region filter
616 
617  if( detector == EcalEndcap){
618  //mass cuts
619  m_minCut = seleMinvMinEndCap_;
620  m_maxCut = seleMinvMaxEndCap_;
621 
622  //isolation
623  ptminforIso = ptMinForIsolationEndCap_;
624  isoBeltdrCut = seleBeltDREndCap_;
625  isoBeltdetaCut = seleBeltDetaEndCap_;
626 
627  //other
628  s9s25Cut = seleS9S25GammaEndCap_ ;
629  store5x5 = store5x5RecHitEE_;
630 
631  //isoCut = seleIsoEndCap_; // old non-region filter
632  //s4s9Cut = seleS4S9GammaEndCap_; //old non-region filter
633  }
634 
635  map<int,bool> passShowerShape_clus; //if this cluster passed showershape cut, so no need to compute the quantity again for each loop
636 
637  for( auto it_bc = clusterCollection->begin(); it_bc != clusterCollection->end();it_bc++){
638 
639  if( detector == EcalBarrel && removePi0CandidatesForEta_){
640  auto it = find(indClusPi0Candidates.begin(),indClusPi0Candidates.end(),int(it_bc - clusterCollection->begin()) );
641  if( it != indClusPi0Candidates.end()) continue;
642  }
643 
644  float en1 = it_bc->energy();
645  math::XYZVector v1(it_bc->position()); // set vector as cluster position
646  v1 *= (en1 / v1.R()); // rescale vector's magnitude to the energy in order to get momentum vector (assuming massless particles)
647  float pt1 = v1.Rho(); // Rho is equivalent to Pt when using XYZVector
648 
649  int ind1 = int( it_bc - clusterCollection->begin() );
650  auto itmap = passShowerShape_clus.find(ind1);
651  if( itmap != passShowerShape_clus.end()){
652  if( itmap->second == false){
653  continue;
654  }
655  }
656 
657  for( auto it_bc2 = it_bc + 1 ; it_bc2 != clusterCollection->end();it_bc2++){
658  if( detector ==EcalBarrel && removePi0CandidatesForEta_){
659  auto it = find(indClusPi0Candidates.begin(),indClusPi0Candidates.end(),int(it_bc2 - clusterCollection->begin()) );
660  if( it != indClusPi0Candidates.end()) continue;
661  }
662 
663  float en2 = it_bc2 ->energy();
664  math::XYZVector v2(it_bc2->position()); // set vector as cluster position
665  v2 *= (en2 / v2.R()); // rescale vector's magnitude to the energy in order to get momentum vector (assuming massless particles)
666  float pt2 = v2.Rho(); // Rho is equivalent to Pt when using XYZVector
667 
668  int ind2 = int( it_bc2 - clusterCollection->begin() );
669  auto itmap = passShowerShape_clus.find(ind2);
670  if( itmap != passShowerShape_clus.end()){
671  if( itmap->second == false){
672  continue;
673  }
674  }
675 
676  float m_pair,pt_pair,eta_pair, phi_pair;
677  calcPaircluster(*it_bc,*it_bc2, m_pair, pt_pair,eta_pair,phi_pair);
678 
680  float ptmin = pt1< pt2 ? pt1:pt2;
681  float etapair = fabs(eta_pair);
682 
683  //-------------------------------------
684  // Region Based Kinematic Cuts: pt of the diphoton system and pt of each photon
685  //-------------------------------------
686  if( detector ==EcalBarrel ){ // BARREL
687  //EB region 1
688  if(etapair <= region1_Barrel_){ //EB region 1
689  if(ptmin < selePtGammaBarrel_region1_ || pt_pair < selePtPairBarrel_region1_) continue;
690  }
691  //EB region 2
692  else{
693  if(ptmin < selePtGammaBarrel_region2_ || pt_pair < selePtPairBarrel_region2_) continue;
694  }
695  }
696  else{ // ENDCAP
697  //EE region 1
698  if(etapair <= region1_EndCap_){
699  if(ptmin < selePtGammaEndCap_region1_ || pt_pair < selePtPairEndCap_region1_) continue;
700  }
701  //EE region 2
702  else if( etapair <= region2_EndCap_){
703  if(ptmin < selePtGammaEndCap_region2_ || pt_pair < selePtPairEndCap_region2_) continue;
704  }
705  //EE region 3
706  else{
707  if(ptmin < selePtGammaEndCap_region3_ || pt_pair < selePtPairEndCap_region3_) continue;
708  if(pt_pair > selePtPairMaxEndCap_region3_ ) continue; // there is also a possible maximum pt for the very forward region
709  }
710  }
711 
713  if( m_pair < m_minCut || m_pair > m_maxCut) continue;
714 
716  vector<int> IsoClus;
717  IsoClus.push_back(ind1); //first two are good clusters
718  IsoClus.push_back(ind2);
719 
720  float Iso = 0;
721  for( auto it_bc3 = clusterCollection->begin(); it_bc3 != clusterCollection->end();it_bc3++){
722  if( it_bc3->seed() == it_bc->seed() || it_bc3->seed() == it_bc2->seed()) continue;
723  float drcl = std::hypot(eta_pair - it_bc3->eta(), deltaPhi(phi_pair, it_bc3->phi()));
724  float dretacl = fabs( eta_pair - it_bc3->eta());
725  if( drcl > isoBeltdrCut || dretacl > isoBeltdetaCut ) continue;
726  float pt3 = it_bc3->energy()*sin(it_bc3->position().theta()) ;
727  if( pt3 < ptminforIso) continue;
728  Iso += pt3;
729  int ind3 = int(it_bc3 - clusterCollection->begin());
730  IsoClus.push_back( ind3);
731  }
732 
733  //-------------------------------------
734  // Region Based Nxtal Cut: Nxtal of the clusters
735  //-------------------------------------
736 
737  uint32_t Nxtal_pho1 = it_bc->size();
738  uint32_t Nxtal_pho2 = it_bc2->size();
739 
740  // BARREL
741  if( detector == EcalBarrel ){
742  //EB region 1
743  if(etapair <= region1_Barrel_){ //EB region 1
744  if(Nxtal_pho1 < seleNxtalBarrel_region1_ || Nxtal_pho2 < seleNxtalBarrel_region1_) continue;
745  }
746  //EB region 2
747  else{
748  if(Nxtal_pho1 < seleNxtalBarrel_region2_ || Nxtal_pho2 < seleNxtalBarrel_region2_) continue;
749  }
750  }
751  // ENDCAP
752  else{
753  //EE region 1
754  if(etapair <= region1_EndCap_){
755  if(Nxtal_pho1 < seleNxtalEndCap_region1_ || Nxtal_pho2 < seleNxtalEndCap_region1_) continue;
756  }
757  //EE region 2
758  else if( etapair <= region2_EndCap_){
759  if(Nxtal_pho1 < seleNxtalEndCap_region2_ || Nxtal_pho2 < seleNxtalEndCap_region2_) continue;
760  }
761  //EE region 3
762  else{
763  if(Nxtal_pho1 < seleNxtalEndCap_region3_ || Nxtal_pho2 < seleNxtalEndCap_region3_) continue;
764  }
765  }
766 
767  //-------------------------------------
768  // Region Based Isolation Cut: pt of the diphoton system and pt of each photon
769  //-------------------------------------
770  float iso_val = Iso/pt_pair;
771  // BARREL
772  if( detector == EcalBarrel ){
773  //EB region 1
774  if(etapair <= region1_Barrel_){ //EB region 1
775  if(iso_val > seleIsoBarrel_region1_ ) continue;
776  }
777  //EB region 2
778  else{
779  if(iso_val > seleIsoBarrel_region2_ ) continue;
780  }
781  }
782  // ENDCAP
783  else{
784  //EE region 1
785  if(etapair <= region1_EndCap_){
786  if(iso_val > seleIsoEndCap_region1_ ) continue;
787  }
788  //EE region 2
789  else if( etapair <= region2_EndCap_){
790  if(iso_val > seleIsoEndCap_region2_ ) continue;
791  }
792  //EE region 3
793  else{
794  if(iso_val > seleIsoEndCap_region3_ ) continue;
795  }
796  }
797  //-------------------------------------
798  //if(Iso/pt_pair > isoCut) continue; //old non-regional cut
799 
800 
801  //-------------------------------------
802  // Region based ShowerShape Cut: S4S9 Cut with possible S9S25 configuration
803  //-------------------------------------
804 
805  bool failShowerShape = false;
806  for(int n=0; n<2; n++){
807  int ind = IsoClus[n];
808  auto it_bc3 = clusterCollection->begin() + ind;
809  auto itmap = passShowerShape_clus.find(ind);
810 
811  if( itmap != passShowerShape_clus.end()){ // if we havent reached the end
812  if( itmap->second == false){
813  failShowerShape = true;
814  n=2; //exit the loop
815  }
816  }
817  else{
818  vector<EcalRecHit> RecHitsCluster_5x5;
819  float res[3];
820 
821  //build the shower shape variables
822  calcShowerShape(*it_bc3, channelStatus,hitCollection, topology_p,store5x5, RecHitsCluster_5x5, res);
823  float s4s9 = res[1] >0 ? res[0]/ res[1] : -1;
824  float s9s25 = res[2] >0 ? res[1] / res[2] : -1;
825 
826  bool passed = false;
827 
828  // BARREL
829  if( detector == EcalBarrel ){
830  //EB region 1
831  if(etapair <= region1_Barrel_){
832  passed = s4s9 > seleS4S9GammaBarrel_region1_;
833  }
834  //EB region 2
835  else{
836  passed = s4s9 > seleS4S9GammaBarrel_region2_;
837  }
838  }
839  // ENDCAP
840  else{
841  //EE region 1
842  if( etapair <= region1_EndCap_){
843  passed = s4s9 > seleS4S9GammaEndCap_region1_;
844  }
845  //EE region 2
846  else if( etapair <= region2_EndCap_){
847  passed = s4s9 > seleS4S9GammaEndCap_region2_;
848  }
849  //EE region 3
850  else{
851  passed = s4s9 > seleS4S9GammaEndCap_region3_;
852  }
853  }
854 
855  //apply the S9S25 cut as well
856  passed = passed && (s9s25 > s9s25Cut);
857  passShowerShape_clus.insert(pair<int, bool>(ind, passed));
858 
859  if( !passed ){
860  failShowerShape = true;
861  n=2; //exit the loop
862  }
863  else{
864  RecHits5x5_clus.insert(pair<int, vector<EcalRecHit> >(ind,RecHitsCluster_5x5) );
865  }
866  }
867  }
868 
869  if( failShowerShape == true) continue; //if any of the two clusters fail shower shape
870 
871 
873  for(unsigned int iii=0 ; iii<IsoClus.size() ; iii++){
874  int ind = IsoClus[iii];
875 
876  if( iii < 2){
877  auto it = find(indCandClus.begin(),indCandClus.end(), ind);
878  if( it == indCandClus.end()) indCandClus.push_back(ind);
879  else continue;
880  }
881  else{
882  auto it = find(indIsoClus.begin(),indIsoClus.end(), ind); //iso cluster
883  if( it == indIsoClus.end()) indIsoClus.push_back(ind);
884  else continue;
885  }
886 
887  auto it = find(indClusSelected.begin(),indClusSelected.end(),ind);
888  if( it != indClusSelected.end()) continue;
889  indClusSelected.push_back(ind);
890  }
891  }
892  }
893 }
894 
895 
896 
897 
898 
899 
900 
901 void HLTRegionalEcalResonanceFilter::convxtalid(Int_t &nphi,Int_t &neta)
902 {
903  // Barrel only
904  // Output nphi 0...359; neta 0...84; nside=+1 (for eta>0), or 0 (for eta<0).
905  // neta will be [-85,-1] , or [0,84], the minus sign indicates the z<0 side.
906 
907  if(neta > 0) neta -= 1;
908  if(nphi > 359) nphi=nphi-360;
909 
910  // final check
911  if(nphi >359 || nphi <0 || neta< -85 || neta > 84)
912  {
913  LogError("") <<" unexpected fatal error in HLTEcalResonanceFilter::convxtalid "<< nphi << " " << neta << " " <<std::endl;
914  }
915 } //end of convxtalid
916 
917 
918 
919 
920 int HLTRegionalEcalResonanceFilter::diff_neta_s(Int_t neta1, Int_t neta2){
921  Int_t mdiff;
922  mdiff=(neta1-neta2);
923  return mdiff;
924 }
925 
926 // Calculate the distance in xtals taking into account the periodicity of the Barrel
927 int HLTRegionalEcalResonanceFilter::diff_nphi_s(Int_t nphi1,Int_t nphi2) {
928  Int_t mdiff;
929  if(std::abs(nphi1-nphi2) < (360-std::abs(nphi1-nphi2))) {
930  mdiff=nphi1-nphi2;
931  }
932  else {
933  mdiff=360-std::abs(nphi1-nphi2);
934  if(nphi1>nphi2) mdiff=-mdiff;
935  }
936  return mdiff;
937 }
938 
939 
940 void HLTRegionalEcalResonanceFilter::calcShowerShape(const reco::BasicCluster &bc, const EcalChannelStatus &channelStatus, const EcalRecHitCollection *recHits, const CaloSubdetectorTopology *topology_p, bool calc5x5, vector<EcalRecHit> &rechit5x5, float res[]){
941 
942 
943  const std::vector< std::pair<DetId, float> > &vid = bc.hitsAndFractions();
944 
945 
946  float e2x2[4]={0};
947  float e3x3 =0 ;
948  float e5x5 =0;
949  int seedx ;
950  int seedy;
951  DetId seedId = bc.seed();
952 
953  bool InBarrel = true;
954  if( seedId.subdetId() == EcalBarrel){
955  EBDetId ebd = EBDetId(seedId);
956  seedx = ebd.ieta();
957  seedy = ebd.iphi();
958  convxtalid(seedy,seedx);
959  }else{
960  InBarrel = false;
961  EEDetId eed = EEDetId(seedId);
962  seedx = eed.ix();
963  seedy = eed.iy();
964  }
965  int x,y, dx, dy;
966 
967 
968 
969  if( calc5x5 ){
970  rechit5x5.clear();
971  std::vector<DetId> clus_v5x5;
972  clus_v5x5 = topology_p->getWindow(seedId,5,5);
973 
974  for( std::vector<DetId>::const_iterator idItr = clus_v5x5.begin(); idItr != clus_v5x5.end(); idItr++){
975  DetId ed = *idItr;
976  if( InBarrel == true){
977  EBDetId ebd = EBDetId(ed);
978  x = ebd.ieta();
979  y = ebd.iphi();
980  convxtalid(y,x);
981  dx = diff_neta_s(x,seedx);
982  dy = diff_nphi_s(y,seedy);
983  }else{
984  EEDetId eed = EEDetId(ed);
985  x = eed.ix();
986  y = eed.iy();
987  dx = x-seedx;
988  dy = y-seedy;
989  }
990  auto rit = recHits->find( ed );
991  if ( rit == recHits->end() ) continue;
992  if( ! checkStatusOfEcalRecHit(channelStatus, *rit) ) continue;
993 
994  float energy = (*rit).energy();
995  e5x5 += energy;
996 
997  auto idItrF = std::find( vid.begin(),vid.end(), std::make_pair(ed,1.0f));
998  if( idItrF == vid.end()){
999  rechit5x5.push_back(*rit);
1000  }else{
1001  if(std::abs(dx)<=1 && std::abs(dy)<=1) {
1002  if(dx <= 0 && dy <=0) e2x2[0] += energy;
1003  if(dx >= 0 && dy <=0) e2x2[1] += energy;
1004  if(dx <= 0 && dy >=0) e2x2[2] += energy;
1005  if(dx >= 0 && dy >=0) e2x2[3] += energy;
1006  e3x3 += energy;
1007  }
1008  }
1009  }
1010 
1011 
1012  }else{
1013 
1014  for (auto const & idItr : vid){
1015  DetId ed = idItr.first;
1016  if( InBarrel == true){
1017  EBDetId ebd = EBDetId(ed);
1018  x = ebd.ieta();
1019  y = ebd.iphi();
1020  convxtalid(y,x);
1021  dx = diff_neta_s(x,seedx);
1022  dy = diff_nphi_s(y,seedy);
1023  }else{
1024  EEDetId eed = EEDetId(ed);
1025  x = eed.ix();
1026  y = eed.iy();
1027  dx = x-seedx;
1028  dy = y-seedy;
1029  }
1030  auto rit = recHits->find( ed );
1031  if ( rit == recHits->end() ) {
1032  continue;
1033  }
1034 
1035  float energy = (*rit).energy();
1036  if(std::abs(dx)<=1 && std::abs(dy)<=1){
1037  if(dx <= 0 && dy <=0) e2x2[0] += energy;
1038  if(dx >= 0 && dy <=0) e2x2[1] += energy;
1039  if(dx <= 0 && dy >=0) e2x2[2] += energy;
1040  if(dx >= 0 && dy >=0) e2x2[3] += energy;
1041  e3x3 += energy;
1042  }
1043 
1044  }
1045  e5x5 = e3x3;
1046  }
1047 
1048 
1049 
1051  res[0] = *max_element( e2x2,e2x2+4);
1052  res[1] = e3x3;
1053  res[2] = e5x5;
1054 
1055 
1056 }
1057 
1058 
1059 
1060 
1061 void HLTRegionalEcalResonanceFilter::calcPaircluster(const reco::BasicCluster &bc1, const reco::BasicCluster &bc2,float &m_pair,float &pt_pair,float &eta_pair, float &phi_pair){
1062 
1063  // use XYZVector instead of TLorentzVector to make things faster (and initialize with cartesian coordinates).
1064  // We are interested in the momentum vector: however, we start from cartesian coordinates to get the vector direction,
1065  // then we set the vector's magnitude to obtain momentum coordinates. The magnitude we set is equal to the particle's energy.
1066  // We can do this because, assuming massless particles (or negligible mass), the magnitude of the momentum vector is given by the energy.
1067 
1068  math::XYZVector v1(bc1.position());
1069  float en1 = bc1.energy();
1070  float scaleFactor = en1 / v1.R(); // XYZVector::R() returns sqrt(Mag2()), where Mag2()= fx*fx + fy*fy + fz*fz
1071  // here I'm assuming that the vector initial magnitude is always different from 0 (the cluster must be somewhere in the detector, so the distance is greater than 0)
1072  v1 *= scaleFactor;
1073 
1074  // vsum would be v1 + v2, but instead of declaring both v2 and vsum, just declare vsum, initialize as if it is v2 and then sum v1.
1075  math::XYZVector vsum(bc2.position());
1076  // define energy sum initializing it to energy2, so that we can use it before summing energy1
1077  float energysum = bc2.energy();
1078  scaleFactor = energysum / vsum.R();
1079  vsum *= scaleFactor;
1080 
1081  vsum += v1;
1082  // now sum the energy of the second basic cluster to get total energy
1083  energysum += en1;
1084 
1085  // finally, assign values
1086  m_pair = sqrt( energysum * energysum - vsum.Mag2()); // M_pi0 = sqrt(E_pi0^2 - |p_pi0|^2)
1087  pt_pair = vsum.Rho(); // Rho method is the equivalent of Pt: returns sqrt( fx*fx + fy*fy )
1088  eta_pair = vsum.Eta();
1089  phi_pair = vsum.Phi();
1090 
1091 
1092 }
1093 
1094 
1095 
1096 
1097 
1099 
1100  if(useRecoFlag_ ){
1101  int flag = rh.recoFlag();
1102  if( flagLevelRecHitsToUse_ ==0){
1103  if( flag != 0) return false;
1104  }
1105  else if( flagLevelRecHitsToUse_ ==1){
1106  if( flag !=0 && flag != 4 ) return false;
1107  }
1108  else if( flagLevelRecHitsToUse_ ==2){
1109  if( flag !=0 && flag != 4 && flag != 6 && flag != 7) return false;
1110  }
1111  }
1112  if ( useDBStatus_){
1113  int status = int(channelStatus[rh.id().rawId()].getStatusCode());
1114  if ( status > statusLevelRecHitsToUse_ ) return false;
1115  }
1116 
1117  return true;
1118 }
1119 
1120 
1121 void HLTRegionalEcalResonanceFilter::makeClusterES(float x, float y, float z,const CaloSubdetectorGeometry* geometry_es,
1122  const CaloSubdetectorTopology* topology_es
1123  ){
1124 
1125 
1127  const GlobalPoint point(x,y,z);
1128  DetId tmp1 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_es))->getClosestCellInPlane(point, 1);
1129  DetId tmp2 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_es))->getClosestCellInPlane(point, 2);
1130  ESDetId strip1 = (tmp1 == DetId(0)) ? ESDetId(0) : ESDetId(tmp1);
1131  ESDetId strip2 = (tmp2 == DetId(0)) ? ESDetId(0) : ESDetId(tmp2);
1132 
1133  // Get ES clusters (found by the PreshSeeded algorithm) associated with a given EE cluster.
1134  for (int i2=0; i2<preshNclust_; i2++) {
1135  reco::PreshowerCluster cl1 = presh_algo_->makeOneCluster(strip1,&m_used_strips,&m_esrechit_map,geometry_es,topology_es);
1136  reco::PreshowerCluster cl2 = presh_algo_->makeOneCluster(strip2,&m_used_strips,&m_esrechit_map,geometry_es,topology_es);
1137  } // end of cycle over ES clusters
1138 
1139 }
1140 
1141 // 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
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
int ix() const
Definition: EEDetId.h:77
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
bool checkStatusOfEcalRecHit(const EcalChannelStatus &channelStatus, const EcalRecHit &rh)
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 makeClusterES(float x, float y, float z, const CaloSubdetectorGeometry *iSubGeom, const CaloSubdetectorTopology *topology_p)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
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)
Definition: Electron.h:6
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
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)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
int iy() const
Definition: EEDetId.h:83
void calcShowerShape(const reco::BasicCluster &bc, const EcalChannelStatus &channelStatus, const EcalRecHitCollection *recHits, const CaloSubdetectorTopology *topology_p, bool calc5x5, std::vector< EcalRecHit > &rechit5x5, float res[])
HLTRegionalEcalResonanceFilter(const edm::ParameterSet &)
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
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
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
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
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