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