test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTAlCa.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include <istream>
4 #include <fstream>
5 #include <iomanip>
6 #include <string>
7 #include <cmath>
8 #include <functional>
9 #include <stdlib.h>
10 #include <string.h>
11 
13 
15  evtCounter=0;
16 
17  //set parameter defaults
18  _Monte=false;
19  _Debug=false;
20 
22  first_ = true;
23 }
24 
25 /* Setup the analysis to put the branch-variables into the tree. */
26 void HLTAlCa::setup(const edm::ParameterSet& pSet, TTree* HltTree) {
27 
28  edm::ParameterSet myEmParams = pSet.getParameter<edm::ParameterSet>("RunParameters") ;
29  std::vector<std::string> parameterNames = myEmParams.getParameterNames() ;
30 
31  for ( std::vector<std::string>::iterator iParam = parameterNames.begin();
32  iParam != parameterNames.end(); iParam++ ){
33  if ( (*iParam) == "Monte" ) _Monte = myEmParams.getParameter<bool>( *iParam );
34  else if ( (*iParam) == "Debug" ) _Debug = myEmParams.getParameter<bool>( *iParam );
35  }
36 
37  // AlCa-specific parameters
38  clusSeedThr_ = pSet.getParameter<double> ("clusSeedThr");
39  clusSeedThrEndCap_ = pSet.getParameter<double> ("clusSeedThrEndCap");
40  clusEtaSize_ = pSet.getParameter<int> ("clusEtaSize");
41  clusPhiSize_ = pSet.getParameter<int> ("clusPhiSize");
42  seleXtalMinEnergy_ = pSet.getParameter<double> ("seleXtalMinEnergy");
43  RegionalMatch_ = pSet.getUntrackedParameter<bool>("RegionalMatch",true);
44  ptMinEMObj_ = pSet.getParameter<double>("ptMinEMObj");
45  EMregionEtaMargin_ = pSet.getParameter<double>("EMregionEtaMargin");
46  EMregionPhiMargin_ = pSet.getParameter<double>("EMregionPhiMargin");
47  Jets_ = pSet.getUntrackedParameter<bool>("Jets",false);
48  JETSdoCentral_ = pSet.getUntrackedParameter<bool>("JETSdoCentral",true);
49  JETSdoForward_ = pSet.getUntrackedParameter<bool>("JETSdoForward",true);
50  JETSdoTau_ = pSet.getUntrackedParameter<bool>("JETSdoTau",true);
51  JETSregionEtaMargin_ = pSet.getUntrackedParameter<double>("JETS_regionEtaMargin",1.0);
52  JETSregionPhiMargin_ = pSet.getUntrackedParameter<double>("JETS_regionPhiMargin",1.0);
53  Ptmin_jets_ = pSet.getUntrackedParameter<double>("Ptmin_jets",0.);
54 
55 
56  // Parameters for the position calculation:
58  pSet.getParameter<edm::ParameterSet>("posCalcParameters");
59  posCalculator_ = PositionCalc(posCalcParameters);
60 
61 
62  const int kMaxClus = 2000;
63  ptClusAll = new float[kMaxClus];
64  etaClusAll = new float[kMaxClus];
65  phiClusAll = new float[kMaxClus];
66  s4s9ClusAll = new float[kMaxClus];
67 
68  // AlCa-specific branches of the tree
69  HltTree->Branch("ohHighestEnergyEERecHit",&ohHighestEnergyEERecHit,"ohHighestEnergyEERecHit/F");
70  HltTree->Branch("ohHighestEnergyEBRecHit",&ohHighestEnergyEBRecHit,"ohHighestEnergyEBRecHit/F");
71  HltTree->Branch("ohHighestEnergyHBHERecHit",&ohHighestEnergyHBHERecHit,"ohHighestEnergyHBHERecHit/F");
72  HltTree->Branch("ohHighestEnergyHORecHit",&ohHighestEnergyHORecHit,"ohHighestEnergyHORecHit/F");
73  HltTree->Branch("ohHighestEnergyHFRecHit",&ohHighestEnergyHFRecHit,"ohHighestEnergyHFRecHit/F");
74  HltTree->Branch("Nalcapi0clusters",&Nalcapi0clusters,"Nalcapi0clusters/I");
75  HltTree->Branch("ohAlcapi0ptClusAll",ptClusAll,"ohAlcapi0ptClusAll[Nalcapi0clusters]/F");
76  HltTree->Branch("ohAlcapi0etaClusAll",etaClusAll,"ohAlcapi0etaClusAll[Nalcapi0clusters]/F");
77  HltTree->Branch("ohAlcapi0phiClusAll",phiClusAll,"ohAlcapi0phiClusAll[Nalcapi0clusters]/F");
78  HltTree->Branch("ohAlcapi0s4s9ClusAll",s4s9ClusAll,"ohAlcapi0s4s9ClusAll[Nalcapi0clusters]/F");
79 }
80 
81 /* **Analyze the event** */
83  const edm::Handle<EERecHitCollection> & eerechits,
84  const edm::Handle<HBHERecHitCollection> & hbherechits,
85  const edm::Handle<HORecHitCollection> & horechits,
86  const edm::Handle<HFRecHitCollection> & hfrechits,
87  const edm::Handle<EBRecHitCollection> & pi0ebrechits,
88  const edm::Handle<EERecHitCollection> & pi0eerechits,
94  const edm::ESHandle< EcalElectronicsMapping > & ecalmapping,
95  const edm::ESHandle<CaloGeometry> & geoHandle,
96  const edm::ESHandle<CaloTopology> & pTopology,
97  const edm::ESHandle<L1CaloGeometry> & l1CaloGeom,
98  TTree* HltTree) {
99 
100  // std::cout << " Beginning HLTAlCa " << std::endl;
101 
105  ohHighestEnergyHORecHit = -1.0;
106  ohHighestEnergyHFRecHit = -1.0;
107 
108  if (ebrechits.isValid()) {
109  EBRecHitCollection myebrechits;
110  myebrechits = * ebrechits;
111 
112  float ebrechitenergy = -1.0;
113 
114  typedef EBRecHitCollection::const_iterator ebrechititer;
115 
116  for (ebrechititer i=myebrechits.begin(); i!=myebrechits.end(); i++) {
117  ebrechitenergy = i->energy();
118  if(ebrechitenergy > ohHighestEnergyEBRecHit)
119  ohHighestEnergyEBRecHit = ebrechitenergy;
120  }
121  }
122 
123  if (eerechits.isValid()) {
124  EERecHitCollection myeerechits;
125  myeerechits = * eerechits;
126 
127  float eerechitenergy = -1.0;
128 
129  typedef EERecHitCollection::const_iterator eerechititer;
130 
131  for (eerechititer i=myeerechits.begin(); i!=myeerechits.end(); i++) {
132  eerechitenergy = i->energy();
133  if(eerechitenergy > ohHighestEnergyEERecHit)
134  ohHighestEnergyEERecHit = eerechitenergy;
135  }
136  }
137 
138  if (hbherechits.isValid()) {
139  HBHERecHitCollection myhbherechits;
140  myhbherechits = * hbherechits;
141 
142  float hbherechitenergy = -1.0;
143 
144  typedef HBHERecHitCollection::const_iterator hbherechititer;
145 
146  for (hbherechititer i=myhbherechits.begin(); i!=myhbherechits.end(); i++) {
147  hbherechitenergy = i->energy();
148  if(hbherechitenergy > ohHighestEnergyHBHERecHit)
149  ohHighestEnergyHBHERecHit = hbherechitenergy;
150  }
151  }
152 
153  if (horechits.isValid()) {
154  HORecHitCollection myhorechits;
155  myhorechits = * horechits;
156 
157  float horechitenergy = -1.0;
158 
159  typedef HORecHitCollection::const_iterator horechititer;
160 
161  for (horechititer i=myhorechits.begin(); i!=myhorechits.end(); i++) {
162  horechitenergy = i->energy();
163  if(horechitenergy > ohHighestEnergyHORecHit)
164  ohHighestEnergyHORecHit = horechitenergy;
165  }
166  }
167 
168  if (hfrechits.isValid()) {
169  HFRecHitCollection myhfrechits;
170  myhfrechits = * hfrechits;
171 
172  float hfrechitenergy = -1.0;
173 
174  typedef HFRecHitCollection::const_iterator hfrechititer;
175 
176  for (hfrechititer i=myhfrechits.begin(); i!=myhfrechits.end(); i++) {
177  hfrechitenergy = i->energy();
178  if(hfrechitenergy > ohHighestEnergyHFRecHit)
179  ohHighestEnergyHFRecHit = hfrechitenergy;
180  }
181  }
182 
184  // Start of AlCa pi0 trigger variables here
186 
187  if (first_) {
188 
189  const EcalElectronicsMapping* TheMapping_ = ecalmapping.product();
190  *TheMapping = *TheMapping_;
191  first_ = false;
192 
193  geometry_eb = geoHandle->getSubdetectorGeometry(DetId::Ecal,EcalBarrel);
194  geometry_ee = geoHandle->getSubdetectorGeometry(DetId::Ecal,EcalEndcap);
195  geometry_es = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
196 
197  topology_eb = pTopology->getSubdetectorTopology(DetId::Ecal,EcalBarrel);
198  topology_ee = pTopology->getSubdetectorTopology(DetId::Ecal,EcalEndcap);
199  }
200 
201  // End pi0 setup
202 
203  //first get all the FEDs around EM objects with PT > defined value.
204  FEDListUsed.clear();
205  std::vector<int>::iterator it;
206  if( RegionalMatch_){
207 
208  for( l1extra::L1EmParticleCollection::const_iterator emItr = l1EGIso->begin();
209  emItr != l1EGIso->end() ;++emItr ){
210 
211  float pt = emItr -> pt();
212 
213  if( pt< ptMinEMObj_ ) continue;
214 
215  int etaIndex = emItr->gctEmCand()->etaIndex() ;
216  int phiIndex = emItr->gctEmCand()->phiIndex() ;
217  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
218  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
219  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
220  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
221 
222  std::vector<int> feds = ListOfFEDS(etaLow, etaHigh, phiLow, phiHigh, EMregionEtaMargin_, EMregionPhiMargin_);
223  for (int n=0; n < (int)feds.size(); n++) {
224  int fed = feds[n];
225  it = find(FEDListUsed.begin(),FEDListUsed.end(),fed);
226  if( it == FEDListUsed.end()){
227  FEDListUsed.push_back(fed);
228  }
229  }
230  }
231 
232  for( l1extra::L1EmParticleCollection::const_iterator emItr = l1EGNonIso->begin();
233  emItr != l1EGNonIso->end() ;++emItr ){
234 
235  float pt = emItr -> pt();
236 
237  if( pt< ptMinEMObj_ ) continue;
238 
239  int etaIndex = emItr->gctEmCand()->etaIndex() ;
240  int phiIndex = emItr->gctEmCand()->phiIndex() ;
241  double etaLow = l1CaloGeom->etaBinLowEdge( etaIndex ) ;
242  double etaHigh = l1CaloGeom->etaBinHighEdge( etaIndex ) ;
243  double phiLow = l1CaloGeom->emJetPhiBinLowEdge( phiIndex ) ;
244  double phiHigh = l1CaloGeom->emJetPhiBinHighEdge( phiIndex ) ;
245 
246  std::vector<int> feds = ListOfFEDS(etaLow, etaHigh, phiLow, phiHigh, EMregionEtaMargin_, EMregionPhiMargin_);
247  for (int n=0; n < (int)feds.size(); n++) {
248  int fed = feds[n];
249  it = find(FEDListUsed.begin(),FEDListUsed.end(),fed);
250  if( it == FEDListUsed.end()){
251  FEDListUsed.push_back(fed);
252  }
253  }
254  }
255 
256  if( Jets_ ){
257 
258  double epsilon = 0.01;
259 
260  if (JETSdoCentral_) {
261 
262  for (l1extra::L1JetParticleCollection::const_iterator jetItr=l1extjetc->begin(); jetItr != l1extjetc->end(); jetItr++) {
263 
264  double pt = jetItr-> pt();
265  double eta = jetItr-> eta();
266  double phi = jetItr-> phi();
267 
268  if (pt < Ptmin_jets_ ) continue;
269 
270  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
271  for (int n=0; n < (int)feds.size(); n++) {
272  int fed = feds[n];
273  it = find(FEDListUsed.begin(),FEDListUsed.end(),fed);
274  if( it == FEDListUsed.end()){
275  FEDListUsed.push_back(fed);
276  }
277  }
278  }
279 
280  }
281 
282  if (JETSdoForward_) {
283 
284  for (l1extra::L1JetParticleCollection::const_iterator jetItr=l1extjetf->begin(); jetItr != l1extjetf->end(); jetItr++) {
285 
286  double pt = jetItr -> pt();
287  double eta = jetItr -> eta();
288  double phi = jetItr -> phi();
289 
290  if (pt < Ptmin_jets_ ) continue;
291 
292  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
293 
294  for (int n=0; n < (int)feds.size(); n++) {
295  int fed = feds[n];
296  it = find(FEDListUsed.begin(),FEDListUsed.end(),fed);
297  if( it == FEDListUsed.end()){
298  FEDListUsed.push_back(fed);
299  }
300  }
301 
302  }
303  }
304 
305  if (JETSdoTau_) {
306 
307  for (l1extra::L1JetParticleCollection::const_iterator jetItr=l1exttaujet->begin(); jetItr != l1exttaujet->end(); jetItr++) {
308 
309  double pt = jetItr -> pt();
310  double eta = jetItr -> eta();
311  double phi = jetItr -> phi();
312 
313  if (pt < Ptmin_jets_ ) continue;
314 
315  std::vector<int> feds = ListOfFEDS(eta, eta, phi-epsilon, phi+epsilon, JETSregionEtaMargin_, JETSregionPhiMargin_);
316  for (int n=0; n < (int)feds.size(); n++) {
317  int fed = feds[n];
318  it = find(FEDListUsed.begin(),FEDListUsed.end(),fed);
319  if( it == FEDListUsed.end()){
320  FEDListUsed.push_back(fed);
321  }
322  }
323 
324  }
325  }
326  }
327  }
328 
330  //separate into barrel and endcap to speed up when checking
331  FEDListUsedBarrel.clear();
332  FEDListUsedEndcap.clear();
333  for( int j=0; j< int(FEDListUsed.size());j++){
334  int fed = FEDListUsed[j];
335 
336  if( fed >= 10 && fed <= 45){
337  FEDListUsedBarrel.push_back(fed);
338  }else FEDListUsedEndcap.push_back(fed);
339  }
340 
341  //==============Start to process barrel part==================///
342 
343  if (pi0ebrechits.isValid()) {
344 
345  const EcalRecHitCollection *hitCollection_p = pi0ebrechits.product();
346 
347  std::vector<EcalRecHit> seeds;
348  seeds.clear();
349 
350  std::vector<EBDetId> usedXtals;
351  usedXtals.clear();
352 
353  detIdEBRecHits.clear();
354  EBRecHits.clear(); // EcalRecHit
355 
356  detIdEBRecHits.clear();
357  EBRecHits.clear(); // EcalRecHit
358 
361 
362  for (itb=pi0ebrechits->begin(); itb!=pi0ebrechits->end(); itb++) {
363  double energy = itb->energy();
364  if( energy < seleXtalMinEnergy_) continue;
365 
366  EBDetId det = itb->id();
367 
368  if (RegionalMatch_){
369  int fed = TheMapping->DCCid(det);
370  it = find(FEDListUsedBarrel.begin(),FEDListUsedBarrel.end(),fed);
371  if(it == FEDListUsedBarrel.end()) continue;
372  }
373 
374  detIdEBRecHits.push_back(det);
375  EBRecHits.push_back(*itb);
376 
377  if (energy > clusSeedThr_) seeds.push_back(*itb);
378  }
379 
380  int nClus;
381  std::vector<float> eClus;
382  std::vector<float> etClus;
383  std::vector<float> etaClus;
384  std::vector<float> phiClus;
385  std::vector<EBDetId> max_hit;
386  std::vector< std::vector<EcalRecHit> > RecHitsCluster;
387  std::vector<float> s4s9Clus;
388 
389  nClus=0;
390 
391  // Make own simple clusters (3x3, 5x5 or clusPhiSize_ x clusEtaSize_)
392  sort(seeds.begin(), seeds.end(), eecalRecHitLess());
393 
394  Nalcapi0clusters = 0;
395  nClusAll = 0;
396 
397  for (std::vector<EcalRecHit>::iterator itseed=seeds.begin(); itseed!=seeds.end(); itseed++) {
398  EBDetId seed_id = itseed->id();
399  std::vector<EBDetId>::const_iterator usedIds;
400 
401  bool seedAlreadyUsed=false;
402  for(usedIds=usedXtals.begin(); usedIds!=usedXtals.end(); usedIds++){
403  if(*usedIds==seed_id){
404  seedAlreadyUsed=true;
405  break;
406  }
407  }
408 
409  if(seedAlreadyUsed)continue;
410 
411  std::vector<DetId> clus_v = topology_eb->getWindow(seed_id,clusEtaSize_,clusPhiSize_);
412  std::vector< std::pair<DetId, float> > clus_used;
413 
414  std::vector<EcalRecHit> RecHitsInWindow;
415 
416  double simple_energy = 0;
417 
418  for (std::vector<DetId>::iterator det=clus_v.begin(); det!=clus_v.end(); det++) {
419  EBDetId EBdet = *det;
420 
421  bool HitAlreadyUsed=false;
422  for(usedIds=usedXtals.begin(); usedIds!=usedXtals.end(); usedIds++){
423  if(*usedIds==*det){
424  HitAlreadyUsed=true;
425  break;
426  }
427  }
428 
429  if(HitAlreadyUsed)continue;
430 
432  if (RegionalMatch_){
433  int fed = TheMapping->DCCid(EBdet);
434  it = find(FEDListUsedBarrel.begin(),FEDListUsedBarrel.end(),fed);
435  if(it == FEDListUsedBarrel.end()) continue;
436  }
437 
438 
439  std::vector<EBDetId>::iterator itdet = find( detIdEBRecHits.begin(),detIdEBRecHits.end(),EBdet);
440  if(itdet == detIdEBRecHits.end()) continue;
441 
442  int nn = int(itdet - detIdEBRecHits.begin());
443  usedXtals.push_back(*det);
444  RecHitsInWindow.push_back(EBRecHits[nn]);
445  clus_used.push_back( std::pair<DetId, float>(*det, 1) );
446  simple_energy = simple_energy + EBRecHits[nn].energy();
447  }
448 
449  math::XYZPoint clus_pos = posCalculator_.Calculate_Location(clus_used,hitCollection_p,geometry_eb,geometry_es);
450 
451  float theta_s = 2. * atan(exp(-clus_pos.eta()));
452  float p0x_s = simple_energy * sin(theta_s) * cos(clus_pos.phi());
453  float p0y_s = simple_energy * sin(theta_s) * sin(clus_pos.phi());
454  float et_s = sqrt( p0x_s*p0x_s + p0y_s*p0y_s);
455 
456  eClus.push_back(simple_energy);
457  etClus.push_back(et_s);
458  etaClus.push_back(clus_pos.eta());
459  phiClus.push_back(clus_pos.phi());
460  max_hit.push_back(seed_id);
461  RecHitsCluster.push_back(RecHitsInWindow);
462 
463  //Compute S4/S9 variable
464  //We are not sure to have 9 RecHits so need to check eta and phi:
465 
466  //check s4s9
467  float s4s9_tmp[4];
468  for(int i=0;i<4;i++)s4s9_tmp[i]= 0;
469 
470  int seed_ieta = seed_id.ieta();
471  int seed_iphi = seed_id.iphi();
472 
473  convxtalid( seed_iphi,seed_ieta);
474 
475  for(unsigned int j=0; j<RecHitsInWindow.size();j++){
476  EBDetId det = (EBDetId)RecHitsInWindow[j].id();
477 
478  int ieta = det.ieta();
479  int iphi = det.iphi();
480 
481  convxtalid(iphi,ieta);
482 
483  float en = RecHitsInWindow[j].energy();
484 
485  int dx = diff_neta_s(seed_ieta,ieta);
486  int dy = diff_nphi_s(seed_iphi,iphi);
487 
488  if(dx <= 0 && dy <=0) s4s9_tmp[0] += en;
489  if(dx >= 0 && dy <=0) s4s9_tmp[1] += en;
490  if(dx <= 0 && dy >=0) s4s9_tmp[2] += en;
491  if(dx >= 0 && dy >=0) s4s9_tmp[3] += en;
492  }
493 
494  float s4s9_max = *std::max_element( s4s9_tmp,s4s9_tmp+4)/simple_energy;
495  s4s9Clus.push_back(s4s9_max);
496 
497  if(nClusAll<MAXCLUS){
498  ptClusAll[nClusAll] = et_s;
499  etaClusAll[nClusAll] = clus_pos.eta();
500  phiClusAll[nClusAll] = clus_pos.phi();
501  s4s9ClusAll[nClusAll] = s4s9_max;
502  nClusAll++;
503  Nalcapi0clusters++;
504  }
505 
506  nClus++;
507  }
508  }
509 
510  //==============Start of Endcap ==================//
511 
512  if (pi0eerechits.isValid()) {
513 
514  const EcalRecHitCollection *hitCollection_e = pi0eerechits.product();
515 
516  detIdEERecHits.clear();
517  EERecHits.clear(); // EcalRecHit
518 
519  std::vector<EcalRecHit> seedsEndCap;
520  seedsEndCap.clear();
521 
522  std::vector<EEDetId> usedXtalsEndCap;
523  usedXtalsEndCap.clear();
524 
527  for (ite=pi0eerechits->begin(); ite!=pi0eerechits->end(); ite++) {
528  double energy = ite->energy();
529  if( energy < seleXtalMinEnergy_) continue;
530 
531  EEDetId det = ite->id();
532  if (RegionalMatch_){
534  int fed = elid.dccId();
535  it = find(FEDListUsedEndcap.begin(),FEDListUsedEndcap.end(),fed);
536  if(it == FEDListUsedEndcap.end()) continue;
537  }
538 
539  detIdEERecHits.push_back(det);
540  EERecHits.push_back(*ite);
541 
542 
543  if (energy > clusSeedThrEndCap_) seedsEndCap.push_back(*ite);
544 
545  }
546 
547  //Create empty output collections
548  std::auto_ptr< EERecHitCollection > pi0EERecHitCollection( new EERecHitCollection );
549 
550  int nClusEndCap;
551  std::vector<float> eClusEndCap;
552  std::vector<float> etClusEndCap;
553  std::vector<float> etaClusEndCap;
554  std::vector<float> phiClusEndCap;
555  std::vector< std::vector<EcalRecHit> > RecHitsClusterEndCap;
556  std::vector<float> s4s9ClusEndCap;
557  nClusEndCap=0;
558 
559  // Make own simple clusters (3x3, 5x5 or clusPhiSize_ x clusEtaSize_)
560  sort(seedsEndCap.begin(), seedsEndCap.end(), eecalRecHitLess());
561 
562  for (std::vector<EcalRecHit>::iterator itseed=seedsEndCap.begin(); itseed!=seedsEndCap.end(); itseed++) {
563  EEDetId seed_id = itseed->id();
564  std::vector<EEDetId>::const_iterator usedIds;
565 
566  bool seedAlreadyUsed=false;
567  for(usedIds=usedXtalsEndCap.begin(); usedIds!=usedXtalsEndCap.end(); usedIds++){
568  if(*usedIds==seed_id){
569  seedAlreadyUsed=true;
570  break;
571  }
572  }
573 
574  if(seedAlreadyUsed)continue;
575 
576  std::vector<DetId> clus_v = topology_ee->getWindow(seed_id,clusEtaSize_,clusPhiSize_);
577  std::vector< std::pair<DetId, float> > clus_used;
578 
579  std::vector<EcalRecHit> RecHitsInWindow;
580 
581  double simple_energy = 0;
582 
583  for (std::vector<DetId>::iterator det=clus_v.begin(); det!=clus_v.end(); det++) {
584  EEDetId EEdet = *det;
585 
586  bool HitAlreadyUsed=false;
587  for(usedIds=usedXtalsEndCap.begin(); usedIds!=usedXtalsEndCap.end(); usedIds++){
588  if(*usedIds==*det){
589  HitAlreadyUsed=true;
590  break;
591  }
592  }
593 
594  if(HitAlreadyUsed)continue;
595 
596  //once again. check FED of this det.
597  if (RegionalMatch_){
599  int fed = elid.dccId();
600  it = find(FEDListUsedEndcap.begin(),FEDListUsedEndcap.end(),fed);
601  if(it == FEDListUsedEndcap.end()) continue;
602  }
603 
604  std::vector<EEDetId>::iterator itdet = find( detIdEERecHits.begin(),detIdEERecHits.end(),EEdet);
605  if(itdet == detIdEERecHits.end()) continue;
606 
607  int nn = int(itdet - detIdEERecHits.begin());
608  usedXtalsEndCap.push_back(*det);
609  RecHitsInWindow.push_back(EERecHits[nn]);
610  clus_used.push_back( std::pair<DetId, float>(*det, 1) );
611  simple_energy = simple_energy + EERecHits[nn].energy();
612  }
613 
614  math::XYZPoint clus_pos = posCalculator_.Calculate_Location(clus_used,hitCollection_e,geometry_ee,geometry_es);
615 
616  float theta_s = 2. * atan(exp(-clus_pos.eta()));
617  float p0x_s = simple_energy * sin(theta_s) * cos(clus_pos.phi());
618  float p0y_s = simple_energy * sin(theta_s) * sin(clus_pos.phi());
619  float et_s = sqrt( p0x_s*p0x_s + p0y_s*p0y_s);
620 
621  eClusEndCap.push_back(simple_energy);
622  etClusEndCap.push_back(et_s);
623  etaClusEndCap.push_back(clus_pos.eta());
624  phiClusEndCap.push_back(clus_pos.phi());
625  RecHitsClusterEndCap.push_back(RecHitsInWindow);
626 
627  //Compute S4/S9 variable
628  //We are not sure to have 9 RecHits so need to check eta and phi:
629  float s4s9_tmp[4];
630  for(int i=0;i<4;i++) s4s9_tmp[i]= 0;
631 
632  int ixSeed = seed_id.ix();
633  int iySeed = seed_id.iy();
634  for(unsigned int j=0; j<RecHitsInWindow.size();j++){
635  EEDetId det_this = (EEDetId)RecHitsInWindow[j].id();
636  int dx = ixSeed - det_this.ix();
637  int dy = iySeed - det_this.iy();
638 
639  float en = RecHitsInWindow[j].energy();
640 
641  if(dx <= 0 && dy <=0) s4s9_tmp[0] += en;
642  if(dx >= 0 && dy <=0) s4s9_tmp[1] += en;
643  if(dx <= 0 && dy >=0) s4s9_tmp[2] += en;
644  if(dx >= 0 && dy >=0) s4s9_tmp[3] += en;
645  }
646 
647  float s4s9_max = *std::max_element( s4s9_tmp,s4s9_tmp+4)/simple_energy;
648  s4s9ClusEndCap.push_back(s4s9_max);
649 
650  if(nClusAll<MAXCLUS){
651  ptClusAll[nClusAll] = et_s;
652  etaClusAll[nClusAll] = clus_pos.eta();
653  phiClusAll[nClusAll] = clus_pos.phi();
654  s4s9ClusAll[nClusAll] = s4s9_max;
655  nClusAll++;
657  }
658 
659  nClusEndCap++;
660  }
661  }
662 
663  // If no barrel OR endcap rechits, set everything to 0
664  if(!(pi0eerechits.isValid()) && !(pi0ebrechits.isValid()))
665  Nalcapi0clusters = 0;
666 }
667 
668 
670 // Below here are helper functions for the pi0 variables
672 
673 
675 std::vector<int> HLTAlCa::ListOfFEDS(double etaLow, double etaHigh, double phiLow,
676  double phiHigh, double etamargin, double phimargin)
677 {
678 
679  std::vector<int> FEDs;
680 
681  if (phimargin > Geom::pi()) phimargin = Geom::pi() ;
682 
683  etaLow -= etamargin;
684  etaHigh += etamargin;
685  double phiMinus = phiLow - phimargin;
686  double phiPlus = phiHigh + phimargin;
687 
688  bool all = false;
689  double dd = fabs(phiPlus-phiMinus);
690 
691  if (dd > 2.*Geom::pi() ) all = true;
692 
693  while (phiPlus > Geom::pi()) { phiPlus -= 2.*Geom::pi() ; }
694  while (phiMinus < 0) { phiMinus += 2.*Geom::pi() ; }
695  if ( phiMinus > Geom::pi()) phiMinus -= 2.*Geom::pi() ;
696 
697  double dphi = phiPlus - phiMinus;
698  if (dphi < 0) dphi += 2.*Geom::pi() ;
699 
700  if (dphi > Geom::pi()) {
701  int fed_low1 = TheMapping->GetFED(etaLow,phiMinus*180./Geom::pi());
702  int fed_low2 = TheMapping->GetFED(etaLow,phiPlus*180./Geom::pi());
703 
704  if (fed_low1 == fed_low2) all = true;
705  int fed_hi1 = TheMapping->GetFED(etaHigh,phiMinus*180./Geom::pi());
706  int fed_hi2 = TheMapping->GetFED(etaHigh,phiPlus*180./Geom::pi());
707 
708  if (fed_hi1 == fed_hi2) all = true;
709  }
710 
711  if (all) {
712 
713  phiMinus = -20 * Geom::pi() / 180.; // -20 deg
714  phiPlus = -40 * Geom::pi() / 180.; // -20 deg
715  }
716 
717  const EcalEtaPhiRegion ecalregion(etaLow,etaHigh,phiMinus,phiPlus);
718 
719  FEDs = TheMapping->GetListofFEDs(ecalregion);
720 
721  return FEDs;
722 
723 }
724 
725 
727 int HLTAlCa::convertSmToFedNumbBarrel(int ieta, int smId){
728 
729  if( ieta<=-1) return smId - 9;
730  else return smId + 27;
731 
732 
733 }
734 
735 
736 void HLTAlCa::convxtalid(Int_t &nphi,Int_t &neta)
737 {
738  // Barrel only
739  // Output nphi 0...359; neta 0...84; nside=+1 (for eta>0), or 0 (for eta<0).
740  // neta will be [-85,-1] , or [0,84], the minus sign indicates the z<0 side.
741 
742  if(neta > 0) neta -= 1;
743  if(nphi > 359) nphi=nphi-360;
744 
745  // final check
746  if(nphi >359 || nphi <0 || neta< -85 || neta > 84)
747  {
748  std::cout <<" unexpected fatal error in HLTPi0::convxtalid "<< nphi << " " << neta << " " <<std::endl;
749  //exit(1);
750  }
751 } //end of convxtalid
752 
753 
754 
755 
756 int HLTAlCa::diff_neta_s(Int_t neta1, Int_t neta2){
757  Int_t mdiff;
758  mdiff=(neta1-neta2);
759  return mdiff;
760 }
761 
762 
763 // Calculate the distance in xtals taking into account the periodicity of the Barrel
764 int HLTAlCa::diff_nphi_s(Int_t nphi1,Int_t nphi2) {
765  Int_t mdiff;
766  if(std::abs(nphi1-nphi2) < (360-std::abs(nphi1-nphi2))) {
767  mdiff=nphi1-nphi2;
768  }
769  else {
770  mdiff=360-std::abs(nphi1-nphi2);
771  if(nphi1>nphi2) mdiff=-mdiff;
772  }
773  return mdiff;
774 }
775 
T getParameter(std::string const &) const
EcalElectronicsMapping * TheMapping
Definition: HLTAlCa.h:170
T getUntrackedParameter(std::string const &, T const &) const
float * phiClusAll
Definition: HLTAlCa.h:193
int i
Definition: DBlmapReader.cc:9
int GetFED(double eta, double phi) const
double ptMinEMObj_
Definition: HLTAlCa.h:154
bool _Debug
Definition: HLTAlCa.h:196
void setup(const edm::ParameterSet &pSet, TTree *tree)
Definition: HLTAlCa.cc:26
double JETSregionPhiMargin_
Definition: HLTAlCa.h:144
int ix() const
Definition: EEDetId.h:76
const CaloSubdetectorGeometry * geometry_es
Definition: HLTAlCa.h:174
std::vector< EEDetId > detIdEERecHits
Definition: HLTAlCa.h:128
bool _Monte
Definition: HLTAlCa.h:196
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
float ohHighestEnergyHFRecHit
Definition: HLTAlCa.h:190
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
bool JETSdoTau_
Definition: HLTAlCa.h:140
std::vector< EcalRecHit >::const_iterator const_iterator
double JETSregionEtaMargin_
Definition: HLTAlCa.h:143
static const int MAXCLUS
Definition: HLTAlCa.h:178
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
int Nalcapi0clusters
Definition: HLTAlCa.h:192
float * ptClusAll
Definition: HLTAlCa.h:193
int convertSmToFedNumbBarrel(int ieta, int smId)
Definition: HLTAlCa.cc:727
std::vector< EBDetId > detIdEBRecHits
Definition: HLTAlCa.h:126
std::vector< EcalRecHit > EBRecHits
Definition: HLTAlCa.h:127
int diff_nphi_s(Int_t nphi1, Int_t nphi2)
Definition: HLTAlCa.cc:764
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
int diff_neta_s(Int_t neta1, Int_t neta2)
Definition: HLTAlCa.cc:756
EcalElectronicsId getElectronicsId(const DetId &id) const
Get the electronics id for this det id.
double EMregionPhiMargin_
Definition: HLTAlCa.h:148
int clusPhiSize_
Definition: HLTAlCa.h:97
float * etaClusAll
Definition: HLTAlCa.h:193
double seleXtalMinEnergy_
Definition: HLTAlCa.h:104
double clusSeedThr_
Definition: HLTAlCa.h:95
float ohHighestEnergyHORecHit
Definition: HLTAlCa.h:190
T sqrt(T t)
Definition: SSEVec.h:18
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
const CaloSubdetectorTopology * topology_ee
Definition: HLTAlCa.h:176
const CaloSubdetectorGeometry * geometry_ee
Definition: HLTAlCa.h:173
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
std::vector< int > FEDListUsed
Definition: HLTAlCa.h:150
HLTAlCa()
Definition: HLTAlCa.cc:14
int iy() const
Definition: EEDetId.h:82
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
int evtCounter
Definition: HLTAlCa.h:198
std::vector< std::string > getParameterNames() const
bool JETSdoForward_
Definition: HLTAlCa.h:139
bool isValid() const
Definition: HandleBase.h:75
int dccId() const
get the DCC (Ecal Local DCC value not global one) id
void convxtalid(Int_t &nphi, Int_t &neta)
Definition: HLTAlCa.cc:736
const_iterator end() const
bool JETSdoCentral_
Definition: HLTAlCa.h:138
int clusEtaSize_
Definition: HLTAlCa.h:96
float ohHighestEnergyEERecHit
Definition: HLTAlCa.h:189
std::vector< EcalRecHit > EERecHits
Definition: HLTAlCa.h:129
float ohHighestEnergyEBRecHit
Definition: HLTAlCa.h:189
virtual std::vector< DetId > getWindow(const DetId &id, const int &northSouthSize, const int &eastWestSize) const
double EMregionEtaMargin_
Definition: HLTAlCa.h:147
PositionCalc posCalculator_
Definition: HLTAlCa.h:177
T const * product() const
Definition: Handle.h:81
bool first_
Definition: HLTAlCa.h:146
double Ptmin_jets_
Definition: HLTAlCa.h:141
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
T const * product() const
Definition: ESHandle.h:86
int DCCid(const EBDetId &id) const
returns the DCC of an EBDetId
std::vector< int > ListOfFEDS(double etaLow, double etaHigh, double phiLow, double phiHigh, double etamargin, double phimargin)
Definition: HLTAlCa.cc:675
double clusSeedThrEndCap_
Definition: HLTAlCa.h:98
const CaloSubdetectorTopology * topology_eb
Definition: HLTAlCa.h:175
bool Jets_
Definition: HLTAlCa.h:134
float * s4s9ClusAll
Definition: HLTAlCa.h:193
math::XYZPoint Calculate_Location(const HitsAndFractions &iDetIds, const edm::SortedCollection< HitType > *iRecHits, const CaloSubdetectorGeometry *iSubGeom, const CaloSubdetectorGeometry *iESGeom=0)
Definition: PositionCalc.h:68
std::vector< int > GetListofFEDs(const EcalEtaPhiRegion &region) const
tuple cout
Definition: gather_cfg.py:145
float ohHighestEnergyHBHERecHit
Definition: HLTAlCa.h:190
constexpr double pi()
Definition: Pi.h:31
int nClusAll
Definition: HLTAlCa.h:186
void analyze(const edm::Handle< EBRecHitCollection > &ebrechits, const edm::Handle< EERecHitCollection > &eerechits, const edm::Handle< HBHERecHitCollection > &hbherechits, const edm::Handle< HORecHitCollection > &horechits, const edm::Handle< HFRecHitCollection > &hfrechits, const edm::Handle< EBRecHitCollection > &pi0ebrechits, const edm::Handle< EERecHitCollection > &pi0eerechits, const edm::Handle< l1extra::L1EmParticleCollection > &l1extemi, const edm::Handle< l1extra::L1EmParticleCollection > &l1extemn, const edm::Handle< l1extra::L1JetParticleCollection > &l1extjetc, const edm::Handle< l1extra::L1JetParticleCollection > &l1extjetf, const edm::Handle< l1extra::L1JetParticleCollection > &l1exttaujet, const edm::ESHandle< EcalElectronicsMapping > &ecalmapping, const edm::ESHandle< CaloGeometry > &geoHandle, const edm::ESHandle< CaloTopology > &pTopology, const edm::ESHandle< L1CaloGeometry > &l1CaloGeom, TTree *tree)
Definition: HLTAlCa.cc:82
bool RegionalMatch_
Definition: HLTAlCa.h:153
std::vector< int > FEDListUsedBarrel
Definition: HLTAlCa.h:151
const_iterator begin() const
std::vector< int > FEDListUsedEndcap
Definition: HLTAlCa.h:152
const CaloSubdetectorGeometry * geometry_eb
Definition: HLTAlCa.h:172