test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Pi0FixedMassWindowCalibration.cc
Go to the documentation of this file.
2 
3 // System include files
4 
5 // Framework
6 
7 
8 // Conditions database
9 
12 
13 // Reconstruction Classes
16 // Geometry
23 
24 // EgammaCoreTools
27 
28 //const double Pi0Calibration::PDGPi0Mass = 0.1349766;
29 
30 using namespace std;
31 
32 //_____________________________________________________________________________
33 
35  theMaxLoops( iConfig.getUntrackedParameter<unsigned int>("maxLoops",0) ),
36  ecalHitsProducer_( iConfig.getParameter< std::string > ("ecalRecHitsProducer") ),
37  barrelHits_( iConfig.getParameter< std::string > ("barrelHitCollection") )
38 {
39 
40  std::cout << "[Pi0FixedMassWindowCalibration] Constructor "<<std::endl;
41  // The verbosity level
42  std::string verbosityString = iConfig.getParameter<std::string>("VerbosityLevel");
43  if (verbosityString == "DEBUG") verbosity = IslandClusterAlgo::pDEBUG;
44  else if (verbosityString == "WARNING") verbosity = IslandClusterAlgo::pWARNING;
45  else if (verbosityString == "INFO") verbosity = IslandClusterAlgo::pINFO;
47 
48  // The names of the produced cluster collections
49  barrelClusterCollection_ = iConfig.getParameter<std::string>("barrelClusterCollection");
50 
51  // Island algorithm parameters
52  double barrelSeedThreshold = iConfig.getParameter<double>("IslandBarrelSeedThr");
53  double endcapSeedThreshold = iConfig.getParameter<double>("IslandEndcapSeedThr");
54 
55 
56  // Selection algorithm parameters
57  selePi0PtGammaOneMin_ = iConfig.getParameter<double>("selePi0PtGammaOneMin");
58  selePi0PtGammaTwoMin_ = iConfig.getParameter<double>("selePi0PtGammaTwoMin");
59 
60  selePi0DRBelt_ = iConfig.getParameter<double>("selePi0DRBelt");
61  selePi0DetaBelt_ = iConfig.getParameter<double>("selePi0DetaBelt");
62 
63  selePi0PtPi0Min_ = iConfig.getParameter<double>("selePi0PtPi0Min");
64 
65  selePi0S4S9GammaOneMin_ = iConfig.getParameter<double>("selePi0S4S9GammaOneMin");
66  selePi0S4S9GammaTwoMin_ = iConfig.getParameter<double>("selePi0S4S9GammaTwoMin");
67  selePi0S9S25GammaOneMin_ = iConfig.getParameter<double>("selePi0S9S25GammaOneMin");
68  selePi0S9S25GammaTwoMin_ = iConfig.getParameter<double>("selePi0S9S25GammaTwoMin");
69 
70  selePi0EtBeltIsoRatioMax_ = iConfig.getParameter<double>("selePi0EtBeltIsoRatioMax");
71 
72  selePi0MinvMeanFixed_ = iConfig.getParameter<double>("selePi0MinvMeanFixed");
73  selePi0MinvSigmaFixed_ = iConfig.getParameter<double>("selePi0MinvSigmaFixed");
74 
75 
76 
77 
78  // Parameters for the position calculation:
80  iConfig.getParameter<edm::ParameterSet>("posCalcParameters");
81  posCalculator_ = PositionCalc(posCalcParameters);
82  shapeAlgo_ = ClusterShapeAlgo(posCalcParameters);
83  clustershapecollectionEB_ = iConfig.getParameter<std::string>("clustershapecollectionEB");
84 
85  //AssociationMap
86  barrelClusterShapeAssociation_ = iConfig.getParameter<std::string>("barrelShapeAssociation");
87 
88  island_p = new IslandClusterAlgo(barrelSeedThreshold, endcapSeedThreshold, posCalculator_,verbosity);
89 
90  theParameterSet=iConfig;
91 
92 
93 }
94 
95 
96 //_____________________________________________________________________________
97 // Close files, etc.
98 
100 {
101 
102 }
103 
104 //_____________________________________________________________________________
105 // Initialize algorithm
106 
108 {
109 
110  //std::cout << "[Pi0FixedMassWindowCalibration] beginOfJob "<<std::endl;
111 
112  isfirstcall_=true;
113 
114 
115 
116 }
117 
118 
120 {
121 
122  std::cout << "[Pi0FixedMassWindowCalibration] endOfJob"<<endl;
123 
124  // Write new calibration constants
125 
126  Pi0CalibXMLwriter barrelWriter(EcalBarrel,99);
127 
128  std::vector<DetId>::const_iterator barrelIt=barrelCells.begin();
129  for (; barrelIt!=barrelCells.end(); barrelIt++) {
130  EBDetId eb(*barrelIt);
131  int ieta = eb.ieta();
132  int iphi = eb.iphi();
133  int sign = eb.zside()>0 ? 1 : 0;
134  barrelWriter.writeLine(eb,newCalibs_barl[abs(ieta)-1][iphi-1][sign]);
135  }
136 
137 }
138 
139 //_____________________________________________________________________________
140 // Called at beginning of loop
142 {
143 
144  for (int sign=0; sign<2; sign++) {
145  for (int ieta=0; ieta<85; ieta++) {
146  for (int iphi=0; iphi<360; iphi++) {
147  wxtals[ieta][iphi][sign]=0.;
148  mwxtals[ieta][iphi][sign]=0.;
149  }
150  }
151  }
152  std::cout << "[Pi0FixedMassWindowCalibration] Starting loop number " << iLoop<<std::endl;
153 
154 }
155 
156 
157 //_____________________________________________________________________________
158 // Called at end of loop
159 
162 {
163  std::cout << "[Pi0FixedMassWindowCalibration] Ending loop " << iLoop<<std::endl;
164 
165  for (int sign=0; sign<2; sign++) {
166  for (int ieta=0; ieta<85; ieta++) {
167  for (int iphi=0; iphi<360; iphi++) {
168 
169  if (wxtals[ieta][iphi][sign] == 0 )
170  {
171  newCalibs_barl[ieta][iphi][sign]=oldCalibs_barl[ieta][iphi][sign];
172  } else {
173  newCalibs_barl[ieta][iphi][sign]=oldCalibs_barl[ieta][iphi][sign]*(mwxtals[ieta][iphi][sign]/wxtals[ieta][iphi][sign]);
174  }
175  cout<< " New calibration constant: ieta iphi sign - old,mwxtals,wxtals,new: "<<ieta<<" "<<iphi<<" "<<sign<<" - "<<oldCalibs_barl[ieta][iphi][sign]<<" "<<mwxtals[ieta][iphi][sign]<<" "<<wxtals[ieta][iphi][sign]<<" "<<newCalibs_barl[ieta][iphi][sign]<<endl;
176 
177  }
178  }
179  }
180 
181  Pi0CalibXMLwriter barrelWriter(EcalBarrel,iLoop+1);
182 
183  std::vector<DetId>::const_iterator barrelIt=barrelCells.begin();
184  for (; barrelIt!=barrelCells.end(); barrelIt++) {
185  EBDetId eb(*barrelIt);
186  int ieta = eb.ieta();
187  int iphi = eb.iphi();
188  int sign = eb.zside()>0 ? 1 : 0;
189  barrelWriter.writeLine(eb,newCalibs_barl[abs(ieta)-1][iphi-1][sign]);
190  if (iphi==1) {
191  std::cout << "Calib constant for barrel crystal "
192  << " (" << ieta << "," << iphi << ") changed from "
193  << oldCalibs_barl[abs(ieta)-1][iphi-1][sign] << " to "
194  << newCalibs_barl[abs(ieta)-1][iphi-1][sign] << std::endl;
195  }
196  }
197 
198  // replace old calibration constants with new one
199 
200  for (int sign=0; sign<2; sign++) {
201  for (int ieta=0; ieta<85; ieta++) {
202  for (int iphi=0; iphi<360; iphi++) {
203  oldCalibs_barl[ieta][iphi][sign]=newCalibs_barl[ieta][iphi][sign];
204  newCalibs_barl[ieta][iphi][sign]=0;
205  }
206  }
207  }
208 
209 
210  if ( iLoop == theMaxLoops-1 || iLoop >= theMaxLoops ) return kStop;
211  else return kContinue;
212 }
213 
214 //_____________________________________________________________________________
215 // Called at each event
216 
219  const edm::EventSetup& setup )
220 {
221  using namespace edm;
222  using namespace std;
223 
224  // this chunk used to belong to beginJob(isetup). Moved here
225  // with the beginJob without arguments migration
226 
227  if (isfirstcall_){
228  // initialize arrays
229 
230  for (int sign=0; sign<2; sign++) {
231  for (int ieta=0; ieta<85; ieta++) {
232  for (int iphi=0; iphi<360; iphi++) {
233  oldCalibs_barl[ieta][iphi][sign]=0.;
234  newCalibs_barl[ieta][iphi][sign]=0.;
235  wxtals[ieta][iphi][sign]=0.;
236  mwxtals[ieta][iphi][sign]=0.;
237  }
238  }
239  }
240 
241  // get initial constants out of DB
242 
245 
246  try {
247  setup.get<EcalIntercalibConstantsRcd>().get(pIcal);
248  std::cout << "Taken EcalIntercalibConstants" << std::endl;
249  imap = pIcal.product()->getMap();
250  std::cout << "imap.size() = " << imap.size() << std::endl;
251  } catch ( std::exception& ex ) {
252  std::cerr << "Error! can't get EcalIntercalibConstants " << std::endl;
253  }
254 
255  // get the ecal geometry:
256  edm::ESHandle<CaloGeometry> geoHandle;
257  setup.get<CaloGeometryRecord>().get(geoHandle);
258  const CaloGeometry& geometry = *geoHandle;
259  //const CaloSubdetectorGeometry *barrelGeometry = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
260 
261  // loop over all barrel crystals
263  std::vector<DetId>::const_iterator barrelIt;
264  for (barrelIt=barrelCells.begin(); barrelIt!=barrelCells.end(); barrelIt++) {
265  EBDetId eb(*barrelIt);
266 
267  // get the initial calibration constants
269  if ( itcalib == imap.end() ) {
270  // FIXME -- throw error
271  }
272  EcalIntercalibConstant calib = (*itcalib);
273  int sign = eb.zside()>0 ? 1 : 0;
274  oldCalibs_barl[abs(eb.ieta())-1][eb.iphi()-1][sign] = calib;
275  if (eb.iphi()==1) std::cout << "Read old constant for crystal "
276  << " (" << eb.ieta() << "," << eb.iphi()
277  << ") : " << calib << std::endl;
278 
279 
280 
281  }
282  isfirstcall_=false;
283  }
284 
285 
286 
287  nevent++;
288 
289  if ((nevent<100 && nevent%10==0)
290  ||(nevent<1000 && nevent%100==0)
291  ||(nevent<10000 && nevent%100==0)
292  ||(nevent<100000 && nevent%1000==0)
293  ||(nevent<10000000 && nevent%1000==0))
294  std::cout << "[Pi0FixedMassWindowCalibration] Events processed: "<<nevent<<std::endl;
295 
296  recHitsEB_map = new std::map<DetId, EcalRecHit>();
297 
299 
300  int nRecHitsEB=0;
301  Handle<EcalRecHitCollection> pEcalRecHitBarrelCollection;
302  event.getByLabel(ecalHitsProducer_, barrelHits_, pEcalRecHitBarrelCollection);
303  const EcalRecHitCollection* ecalRecHitBarrelCollection = pEcalRecHitBarrelCollection.product();
304  cout << " ECAL Barrel RecHits # "<< ecalRecHitBarrelCollection->size() <<endl;
306  //cout << " ECAL Barrel RecHit #,E,time,det,subdetid: "<<nRecHitsEB<<" "<<aRecHitEB->energy()<<" "<<aRecHitEB->time()<<" "<<aRecHitEB->detid().det()<<" "<<aRecHitEB->detid().subdetId()<<endl;
307 
308 
309  EBDetId ebrhdetid = aRecHitEB->detid();
310  //cout << " EBDETID: z,ieta,iphi "<<ebrhdetid.zside()<<" "<<ebrhdetid.ieta()<<" "<<ebrhdetid.iphi()<<endl;
311  //cout << " EBDETID: tower_ieta,tower_iphi "<<ebrhdetid.tower_ieta()<<" "<<ebrhdetid.tower_iphi()<<endl;
312  //cout << " EBDETID: iSM, ic "<<ebrhdetid.ism()<<" "<<ebrhdetid.ic()<<endl;
313 
314  int sign = ebrhdetid.zside()>0 ? 1 : 0;
315  EcalRecHit aHit(aRecHitEB->id(),aRecHitEB->energy()*oldCalibs_barl[abs(ebrhdetid.ieta())-1][ebrhdetid.iphi()-1][sign],aRecHitEB->time());
316  recalibEcalRecHitCollection->push_back(aHit);
317 
318  nRecHitsEB++;
319 
320  }
321 
322  // cout<<" Recalib size: "<<recalibEcalRecHitCollection->size()<<endl;
323  int irecalib=0;
324  for(EcalRecHitCollection::const_iterator aRecHitEB = recalibEcalRecHitCollection->begin(); aRecHitEB != recalibEcalRecHitCollection->end(); aRecHitEB++) {
325  //cout << " [recalibrated] ECAL Barrel RecHit #,E,time,det,subdetid: "<<irecalib<<" "<<aRecHitEB->energy()<<" "<<aRecHitEB->time()<<" "<<aRecHitEB->detid().det()<<" "<<aRecHitEB->detid().subdetId()<<endl;
326 
327  // EBDetId ebrhdetid = aRecHitEB->detid();
328  //cout << " [recalibrated] EBDETID: z,ieta,iphi "<<ebrhdetid.zside()<<" "<<ebrhdetid.ieta()<<" "<<ebrhdetid.iphi()<<endl;
329  //cout << " [recalibrated] EBDETID: tower_ieta,tower_iphi "<<ebrhdetid.tower_ieta()<<" "<<ebrhdetid.tower_iphi()<<endl;
330  //cout << " [recalibrated] EBDETID: iSM, ic "<<ebrhdetid.ism()<<" "<<ebrhdetid.ic()<<endl;
331 
332  std::pair<DetId, EcalRecHit> map_entry(aRecHitEB->id(), *aRecHitEB);
333  recHitsEB_map->insert(map_entry);
334 
335 
336  irecalib++;
337 
338  }
339 
340 
341  // get the geometry and topology from the event setup:
342  edm::ESHandle<CaloGeometry> geoHandle;
343  setup.get<CaloGeometryRecord>().get(geoHandle);
344 
345  const CaloSubdetectorGeometry *geometry_p;
346  CaloSubdetectorTopology *topology_p;
347 
348  std::string clustershapetag;
349  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
350  topology_p = new EcalBarrelTopology(geoHandle);
351 
352  const CaloSubdetectorGeometry *geometryES_p;
353  geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
354 
355  /*
356  reco::BasicClusterCollection clusters;
357  clusters = island_p->makeClusters(ecalRecHitBarrelCollection,geometry_p,topology_p,geometryES_p,IslandClusterAlgo::barrel);
358 
359  //Create associated ClusterShape objects.
360  std::vector <reco::ClusterShape> ClusVec;
361  for (int erg=0;erg<int(clusters.size());++erg){
362  reco::ClusterShape TestShape = shapeAlgo_.Calculate(clusters[erg],ecalRecHitBarrelCollection,geometry_p,topology_p);
363  ClusVec.push_back(TestShape);
364  }
365 
366  //Put clustershapes in event, but retain a Handle on them.
367  std::auto_ptr<reco::ClusterShapeCollection> clustersshapes_p(new reco::ClusterShapeCollection);
368  clustersshapes_p->assign(ClusVec.begin(), ClusVec.end());
369 
370  cout<<"[Pi0Calibration] Basic Cluster collection size: "<<clusters.size()<<endl;
371  cout<<"[Pi0Calibration] Basic Cluster Shape Collection size: "<<clustersshapes_p->size()<<endl;
372 
373  int iClus=0;
374  for(reco::BasicClusterCollection::const_iterator aClus = clusters.begin(); aClus != clusters.end(); aClus++) {
375  cout<<" CLUSTER : #,NHits,e,et,eta,phi,e2x2,e3x3,e5x5: "<<iClus<<" "<<aClus->getHitsByDetId().size()<<" "<<aClus->energy()<<" "<<aClus->energy()*sin(aClus->position().theta())<<" "<<aClus->position().eta()<<" "<<aClus->position().phi()<<" "<<(*clustersshapes_p)[iClus].e2x2()<<" "<<(*clustersshapes_p)[iClus].e3x3()<<" "<<(*clustersshapes_p)[iClus].e5x5()<<endl;
376  iClus++;
377  }
378  */
379 
380  // recalibrated clusters
381  reco::BasicClusterCollection clusters_recalib;
382  clusters_recalib = island_p->makeClusters(recalibEcalRecHitCollection,geometry_p,topology_p,geometryES_p,IslandClusterAlgo::barrel);
383 
384  //Create associated ClusterShape objects.
385  std::vector <reco::ClusterShape> ClusVec_recalib;
386  for (int erg=0;erg<int(clusters_recalib.size());++erg){
387  reco::ClusterShape TestShape_recalib = shapeAlgo_.Calculate(clusters_recalib[erg],recalibEcalRecHitCollection,geometry_p,topology_p);
388  ClusVec_recalib.push_back(TestShape_recalib);
389  }
390 
391  //Put clustershapes in event, but retain a Handle on them.
392  std::auto_ptr<reco::ClusterShapeCollection> clustersshapes_p_recalib(new reco::ClusterShapeCollection);
393  clustersshapes_p_recalib->assign(ClusVec_recalib.begin(), ClusVec_recalib.end());
394 
395  cout<<"[Pi0FixedMassWindowCalibration][recalibration] Basic Cluster collection size: "<<clusters_recalib.size()<<endl;
396  cout<<"[Pi0FixedMassWindowCalibration][recalibration] Basic Cluster Shape Collection size: "<<clustersshapes_p_recalib->size()<<endl;
397 
398 
399  // pizero selection
400 
401  // Get ECAL Barrel Island Basic Clusters collection
402  // ECAL Barrel Island Basic Clusters
403  static const int MAXBCEB = 200;
404  static const int MAXBCEBRH = 200;
405  int nIslandBCEB;
406  float eIslandBCEB[MAXBCEB];
407  float etIslandBCEB[MAXBCEB];
408  float etaIslandBCEB[MAXBCEB];
409  float phiIslandBCEB[MAXBCEB];
410  float e2x2IslandBCEB[MAXBCEB];
411  float e3x3IslandBCEB[MAXBCEB];
412  float e5x5IslandBCEB[MAXBCEB];
413  // indexes to the RecHits assiciated with
414  // ECAL Barrel Island Basic Clusters
415  int nIslandBCEBRecHits[MAXBCEB];
416  // int indexIslandBCEBRecHits[MAXBCEB][MAXBCEBRH];
417  int ietaIslandBCEBRecHits[MAXBCEB][MAXBCEBRH];
418  int iphiIslandBCEBRecHits[MAXBCEB][MAXBCEBRH];
419  int zsideIslandBCEBRecHits[MAXBCEB][MAXBCEBRH];
420  float eIslandBCEBRecHits[MAXBCEB][MAXBCEBRH];
421 
422  nIslandBCEB=0;
423  for(int i=0; i<MAXBCEB; i++){
424  eIslandBCEB[i] = 0;
425  etIslandBCEB[i] = 0;
426  etaIslandBCEB[i] = 0;
427  phiIslandBCEB[i] = 0;
428  e2x2IslandBCEB[i] = 0;
429  e3x3IslandBCEB[i] = 0;
430  e5x5IslandBCEB[i] = 0;
431  nIslandBCEBRecHits[i] = 0;
432  for(int j=0;j<MAXBCEBRH;j++){
433  // indexIslandBCEBRecHits[i][j] = 0;
434  ietaIslandBCEBRecHits[i][j] = 0;
435  iphiIslandBCEBRecHits[i][j] = 0;
436  zsideIslandBCEBRecHits[i][j] = 0;
437  eIslandBCEBRecHits[i][j] = 0;
438  }
439  }
440 
441 
442  int iClus_recalib=0;
443  for(reco::BasicClusterCollection::const_iterator aClus = clusters_recalib.begin(); aClus != clusters_recalib.end(); aClus++) {
444  cout<<" CLUSTER [recalibration] : #,NHits,e,et,eta,phi,e2x2,e3x3,e5x5: "<<iClus_recalib<<" "<<aClus->size()<<" "<<aClus->energy()<<" "<<aClus->energy()*sin(aClus->position().theta())<<" "<<aClus->position().eta()<<" "<<aClus->position().phi()<<" "<<(*clustersshapes_p_recalib)[iClus_recalib].e2x2()<<" "<<(*clustersshapes_p_recalib)[iClus_recalib].e3x3()<<" "<<(*clustersshapes_p_recalib)[iClus_recalib].e5x5()<<endl;
445 
446  eIslandBCEB[nIslandBCEB] = aClus->energy();
447  etIslandBCEB[nIslandBCEB] = aClus->energy()*sin(aClus->position().theta());
448  etaIslandBCEB[nIslandBCEB] = aClus->position().eta();
449  phiIslandBCEB[nIslandBCEB] = aClus->position().phi();
450 
451  e2x2IslandBCEB[nIslandBCEB] = (*clustersshapes_p_recalib)[nIslandBCEB].e2x2();
452  e3x3IslandBCEB[nIslandBCEB] = (*clustersshapes_p_recalib)[nIslandBCEB].e3x3();
453  e5x5IslandBCEB[nIslandBCEB] = (*clustersshapes_p_recalib)[nIslandBCEB].e5x5();
454 
455  nIslandBCEBRecHits[nIslandBCEB] = aClus->size();
456 
457  std::vector<std::pair< DetId,float> > hits = aClus->hitsAndFractions();
458  std::vector<std::pair< DetId,float> >::iterator hit;
459  std::map<DetId, EcalRecHit>::iterator aHit;
460 
461  int irhcount=0;
462  for(hit = hits.begin(); hit != hits.end(); hit++)
463  {
464  // need to get hit by DetID in order to get energy
465  aHit = recHitsEB_map->find((*hit).first);
466  //cout << " RecHit #: "<<irhcount<<" from Basic Cluster with Energy: "<<aHit->second.energy()<<endl;
467 
468  EBDetId sel_rh = aHit->second.detid();
469  //cout << " RecHit: z,ieta,iphi "<<sel_rh.zside()<<" "<<sel_rh.ieta()<<" "<<sel_rh.iphi()<<endl;
470  //cout << " RecHit: tower_ieta,tower_iphi "<<sel_rh.tower_ieta()<<" "<<sel_rh.tower_iphi()<<endl;
471  //cout << " RecHit: iSM, ic "<<sel_rh.ism()<<" "<<sel_rh.ic()<<endl;
472 
473  ietaIslandBCEBRecHits[nIslandBCEB][irhcount] = sel_rh.ieta();
474  iphiIslandBCEBRecHits[nIslandBCEB][irhcount] = sel_rh.iphi();
475  zsideIslandBCEBRecHits[nIslandBCEB][irhcount] = sel_rh.zside();
476  eIslandBCEBRecHits[nIslandBCEB][irhcount] = aHit->second.energy();
477 
478  irhcount++;
479  }
480  nIslandBCEB++;
481  iClus_recalib++;
482 
483 
484  }
485 
486  // Selection, based on ECAL Barrel Basic Clusters
487 
488  if (nIslandBCEB > 1)
489  {
490  for(int i=0 ; i<nIslandBCEB ; i++)
491  {
492  for(int j=i+1 ; j<nIslandBCEB ; j++)
493  {
494 
495  if( etIslandBCEB[i]>selePi0PtGammaOneMin_ && etIslandBCEB[j]>selePi0PtGammaOneMin_)
496  {
497 
498  float theta_0 = 2. * atan(exp(-etaIslandBCEB[i]));
499  float theta_1 = 2. * atan(exp(-etaIslandBCEB[j]));
500 
501  float p0x = eIslandBCEB[i] * sin(theta_0) * cos(phiIslandBCEB[i]);
502  float p1x = eIslandBCEB[j] * sin(theta_1) * cos(phiIslandBCEB[j]);
503 
504  float p0y = eIslandBCEB[i] * sin(theta_0) * sin(phiIslandBCEB[i]);
505  float p1y = eIslandBCEB[j] * sin(theta_1) * sin(phiIslandBCEB[j]);
506 
507  float p0z = eIslandBCEB[i] * cos(theta_0);
508  float p1z = eIslandBCEB[j] * cos(theta_1);
509 
510  float pi0_px = p0x + p1x;
511  float pi0_py = p0y + p1y;
512  float pi0_pz = p0z + p1z;
513 
514  float pi0_ptot = sqrt (pi0_px*pi0_px + pi0_py*pi0_py + pi0_pz*pi0_pz);
515 
516  float pi0_theta = acos(pi0_pz/pi0_ptot);
517  float pi0_eta = -log(tan(pi0_theta/2));
518  float pi0_phi = atan(pi0_py/pi0_px);
519  //cout << " pi0_theta, pi0_eta, pi0_phi "<<pi0_theta<<" "<<pi0_eta<<" "<<pi0_phi<<endl;
520 
521  // belt isolation
522 
523  float et_belt=0;
524  for(Int_t k=0 ; k<nIslandBCEB ; k++)
525  {
526  if( (k != i) && (k != j) )
527  {
528  float dr_pi0_k = sqrt( (etaIslandBCEB[k]-pi0_eta)*(etaIslandBCEB[k]-pi0_eta) + (phiIslandBCEB[k]-pi0_phi)*(phiIslandBCEB[k]-pi0_phi) );
529  float deta_pi0_k = fabs(etaIslandBCEB[k]-pi0_eta);
530  if ( (dr_pi0_k<selePi0DRBelt_) && (deta_pi0_k<selePi0DetaBelt_) ) et_belt = et_belt + etIslandBCEB[k];
531  }
532  }
533 
534 
535  float pt_pi0 = sqrt( (p0x+p1x)*(p0x+p1x) + (p0y+p1y)*(p0y+p1y));
536  //float dr_pi0 = sqrt ( (etaIslandBCEB[i]-etaIslandBCEB[j])*(etaIslandBCEB[i]-etaIslandBCEB[j]) + (phiIslandBCEB[i]-phiIslandBCEB[j])*(phiIslandBCEB[i]-phiIslandBCEB[j]) );
537 
538  //cout <<" pi0 pt,dr: "<<pt_pi0<<" "<<dr_pi0<<endl;
539  if (pt_pi0 > selePi0PtPi0Min_)
540  {
541  float m_inv = sqrt ( (eIslandBCEB[i] + eIslandBCEB[j])*(eIslandBCEB[i] + eIslandBCEB[j]) - (p0x+p1x)*(p0x+p1x) - (p0y+p1y)*(p0y+p1y) - (p0z+p1z)*(p0z+p1z) );
542  cout <<" pi0 (pt>2.5 GeV) m_inv = "<<m_inv<<endl;
543 
544  float s4s9_1 = e2x2IslandBCEB[i]/e3x3IslandBCEB[i];
545  float s4s9_2 = e2x2IslandBCEB[j]/e3x3IslandBCEB[j];
546 
547  float s9s25_1 = e3x3IslandBCEB[i]/e5x5IslandBCEB[i];
548  float s9s25_2 = e3x3IslandBCEB[j]/e5x5IslandBCEB[j];
549 
550  //float s9Esc_1 = e3x3IslandBCEB[i]/eIslandBCEB[i];
551  //float s9Esc_2 = e3x3IslandBCEB[j]/eIslandBCEB[j];
552 
554  {
555  //good pizero candidate
557  {
558  //fill wxtals and mwxtals weights
559  cout<<" Pi0 Good candidate : minv = "<<m_inv<<endl;
560  for(int kk=0 ; kk<nIslandBCEBRecHits[i] ; kk++)
561  {
562  int ieta_xtal = ietaIslandBCEBRecHits[i][kk];
563  int iphi_xtal = iphiIslandBCEBRecHits[i][kk];
564  int sign = zsideIslandBCEBRecHits[i][kk]>0 ? 1 : 0;
565  wxtals[abs(ieta_xtal)-1][iphi_xtal-1][sign] = wxtals[abs(ieta_xtal)-1][iphi_xtal-1][sign] + eIslandBCEBRecHits[i][kk]/e3x3IslandBCEB[i];
566  mwxtals[abs(ieta_xtal)-1][iphi_xtal-1][sign] = mwxtals[abs(ieta_xtal)-1][iphi_xtal-1][sign] + (selePi0MinvMeanFixed_/m_inv)*(selePi0MinvMeanFixed_/m_inv)*(eIslandBCEBRecHits[i][kk]/e3x3IslandBCEB[i]);
567  cout<< "[Pi0FixedMassWindowCalibration] eta, phi, sign, e, e3x3, wxtals and mwxtals: "<<ieta_xtal<<" "<<iphi_xtal<<" "<<sign<<" "<<eIslandBCEBRecHits[i][kk]<<" "<<e3x3IslandBCEB[i]<<" "<<wxtals[abs(ieta_xtal)-1][iphi_xtal-1][sign]<<" "<<mwxtals[abs(ieta_xtal)-1][iphi_xtal-1][sign]<<endl;
568  }
569 
570  for(int kk=0 ; kk<nIslandBCEBRecHits[j] ; kk++)
571  {
572  int ieta_xtal = ietaIslandBCEBRecHits[j][kk];
573  int iphi_xtal = iphiIslandBCEBRecHits[j][kk];
574  int sign = zsideIslandBCEBRecHits[j][kk]>0 ? 1 : 0;
575  wxtals[abs(ieta_xtal)-1][iphi_xtal-1][sign] = wxtals[abs(ieta_xtal)-1][iphi_xtal-1][sign] + eIslandBCEBRecHits[j][kk]/e3x3IslandBCEB[j];
576  mwxtals[abs(ieta_xtal)-1][iphi_xtal-1][sign] = mwxtals[abs(ieta_xtal)-1][iphi_xtal-1][sign] + (selePi0MinvMeanFixed_/m_inv)*(selePi0MinvMeanFixed_/m_inv)*(eIslandBCEBRecHits[j][kk]/e3x3IslandBCEB[j]);
577  cout<< "[Pi0FixedMassWindowCalibration] eta, phi, sign, e, e3x3, wxtals and mwxtals: "<<ieta_xtal<<" "<<iphi_xtal<<" "<<sign<<" "<<eIslandBCEBRecHits[j][kk]<<" "<<e3x3IslandBCEB[j]<<" "<<wxtals[abs(ieta_xtal)-1][iphi_xtal-1][sign]<<" "<<mwxtals[abs(ieta_xtal)-1][iphi_xtal-1][sign]<<endl;
578  }
579 
580  }
581  }
582  }
583  }
584 
585 
586  } // End of the "j" loop over BCEB
587  } // End of the "i" loop over BCEB
588 
589 
590  } else {
591  cout<< " Not enough ECAL Barrel Basic Clusters: "<<nIslandBCEB<<endl;
592  }
593 
594 
595 
596 
597 
598 
599  return kContinue;
600 }
601 
602 // ----------------------------------------------------------------------------
virtual void beginOfJob()
Called at beginning of job.
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
virtual void startingNewLoop(unsigned int iLoop)
Called at beginning of loop.
void writeLine(EBDetId const &, float)
double sign(double x)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::vector< EcalRecHit >::const_iterator const_iterator
std::vector< ClusterShape > ClusterShapeCollection
collection of ClusterShape objects
IslandClusterAlgo::VerbosityLevel verbosity
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
virtual Status duringLoop(const edm::Event &, const edm::EventSetup &)
Called at each event.
reco::ClusterShape Calculate(const reco::BasicCluster &passedCluster, const EcalRecHitCollection *hits, const CaloSubdetectorGeometry *geometry, const CaloSubdetectorTopology *topology)
MVATrainerComputer * calib
Definition: MVATrainer.cc:64
virtual Status endOfLoop(const edm::EventSetup &, unsigned int iLoop)
Called at end of loop.
T sqrt(T t)
Definition: SSEVec.h:18
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::vector< reco::BasicCluster > makeClusters(const EcalRecHitCollection *hits, const CaloSubdetectorGeometry *geometry, const CaloSubdetectorTopology *topology_p, const CaloSubdetectorGeometry *geometryES_p, EcalPart ecalPart, bool regional=false, const std::vector< EcalEtaPhiRegion > &regions=std::vector< EcalEtaPhiRegion >())
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
const EcalRecHitCollection * ecalRecHitBarrelCollection
const_iterator end() const
virtual void endOfJob()
Called at end of job.
const T & get() const
Definition: EventSetup.h:56
std::vector< Item >::const_iterator const_iterator
T const * product() const
Definition: ESHandle.h:86
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:90
ESHandle< TrackerGeometry > geometry
size_type size() const
const_iterator find(uint32_t rawId) const
tuple cout
Definition: gather_cfg.py:145
const_iterator end() const
std::map< DetId, EcalRecHit > * recHitsEB_map
Pi0FixedMassWindowCalibration(const edm::ParameterSet &iConfig)
Constructor.
const EcalRecHitCollection * recalibEcalRecHitCollection
const_iterator begin() const
int zside() const
get the z-side of the crystal (1/-1)
Definition: EBDetId.h:47
float EcalIntercalibConstant