CMS 3D CMS Logo

Pi0FixedMassWindowCalibration.cc
Go to the documentation of this file.
2 
3 // System include files
4 
5 // Framework
6 
7 // Conditions database
8 
11 
12 // Reconstruction Classes
15 // Geometry
22 
23 // EgammaCoreTools
26 
28 
29 //const double Pi0Calibration::PDGPi0Mass = 0.1349766;
30 
31 using namespace std;
32 
33 //_____________________________________________________________________________
34 
36  theMaxLoops( iConfig.getUntrackedParameter<unsigned int>("maxLoops",0) ),
37  ecalHitsProducer_( iConfig.getParameter< std::string > ("ecalRecHitsProducer") ),
38  barrelHits_( iConfig.getParameter< std::string > ("barrelHitCollection") )
39 {
40 
41  std::cout << "[Pi0FixedMassWindowCalibration] Constructor "<<std::endl;
42  // The verbosity level
43  std::string verbosityString = iConfig.getParameter<std::string>("VerbosityLevel");
44  if (verbosityString == "DEBUG") verbosity = IslandClusterAlgo::pDEBUG;
45  else if (verbosityString == "WARNING") verbosity = IslandClusterAlgo::pWARNING;
46  else if (verbosityString == "INFO") verbosity = IslandClusterAlgo::pINFO;
48 
49  // The names of the produced cluster collections
50  barrelClusterCollection_ = iConfig.getParameter<std::string>("barrelClusterCollection");
51 
52  // Island algorithm parameters
53  double barrelSeedThreshold = iConfig.getParameter<double>("IslandBarrelSeedThr");
54  double endcapSeedThreshold = iConfig.getParameter<double>("IslandEndcapSeedThr");
55 
56 
57  // Selection algorithm parameters
58  selePi0PtGammaOneMin_ = iConfig.getParameter<double>("selePi0PtGammaOneMin");
59  selePi0PtGammaTwoMin_ = iConfig.getParameter<double>("selePi0PtGammaTwoMin");
60 
61  selePi0DRBelt_ = iConfig.getParameter<double>("selePi0DRBelt");
62  selePi0DetaBelt_ = iConfig.getParameter<double>("selePi0DetaBelt");
63 
64  selePi0PtPi0Min_ = iConfig.getParameter<double>("selePi0PtPi0Min");
65 
66  selePi0S4S9GammaOneMin_ = iConfig.getParameter<double>("selePi0S4S9GammaOneMin");
67  selePi0S4S9GammaTwoMin_ = iConfig.getParameter<double>("selePi0S4S9GammaTwoMin");
68  selePi0S9S25GammaOneMin_ = iConfig.getParameter<double>("selePi0S9S25GammaOneMin");
69  selePi0S9S25GammaTwoMin_ = iConfig.getParameter<double>("selePi0S9S25GammaTwoMin");
70 
71  selePi0EtBeltIsoRatioMax_ = iConfig.getParameter<double>("selePi0EtBeltIsoRatioMax");
72 
73  selePi0MinvMeanFixed_ = iConfig.getParameter<double>("selePi0MinvMeanFixed");
74  selePi0MinvSigmaFixed_ = iConfig.getParameter<double>("selePi0MinvSigmaFixed");
75 
76  // Parameters for the position calculation:
78  iConfig.getParameter<edm::ParameterSet>("posCalcParameters");
79  posCalculator_ = PositionCalc(posCalcParameters);
80  shapeAlgo_ = ClusterShapeAlgo(posCalcParameters);
81  clustershapecollectionEB_ = iConfig.getParameter<std::string>("clustershapecollectionEB");
82 
83  //AssociationMap
84  barrelClusterShapeAssociation_ = iConfig.getParameter<std::string>("barrelShapeAssociation");
85 
86  const std::vector<std::string> seedflagnamesEB = iConfig.getParameter<std::vector<std::string> >("SeedRecHitFlagToBeExcludedEB");
87  const std::vector<int> seedflagsexclEB = StringToEnumValue<EcalRecHit::Flags>(seedflagnamesEB);
88 
89  const std::vector<std::string> seedflagnamesEE = iConfig.getParameter<std::vector<std::string> >("SeedRecHitFlagToBeExcludedEE");
90  const std::vector<int> seedflagsexclEE = StringToEnumValue<EcalRecHit::Flags>(seedflagnamesEE);
91 
92  const std::vector<std::string> flagnamesEB = iConfig.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEB");
93  const std::vector<int> flagsexclEB = StringToEnumValue<EcalRecHit::Flags>(flagnamesEB);
94 
95  const std::vector<std::string> flagnamesEE = iConfig.getParameter<std::vector<std::string> >("RecHitFlagToBeExcludedEE");
96  const std::vector<int> flagsexclEE = StringToEnumValue<EcalRecHit::Flags>(flagnamesEE);
97 
98  island_p = new IslandClusterAlgo(barrelSeedThreshold, endcapSeedThreshold, posCalculator_, seedflagsexclEB, seedflagsexclEE, flagsexclEB, flagsexclEE, verbosity);
99 
100  theParameterSet=iConfig;
101 
102 
103 }
104 
105 
106 //_____________________________________________________________________________
107 // Close files, etc.
108 
110 {
111  delete island_p;
112 }
113 
115 
117 
118  desc.add<unsigned int>("maxLoops", 0);
119  desc.add<std::string>("ecalRecHitsProducer", "");
120  desc.add<std::string>("barrelHitCollection", "");
121 
122  desc.add<std::string>("VerbosityLevel", "");
123  desc.add<std::string>("barrelClusterCollection", "");
124 
125  desc.add<double>("IslandBarrelSeedThr", 0);
126  desc.add<double>("IslandEndcapSeedThr", 0);
127 
128  desc.add<double>("selePi0PtGammaOneMin", 0);
129  desc.add<double>("selePi0PtGammaTwoMin", 0);
130 
131  desc.add<double>("selePi0DRBelt", 0);
132  desc.add<double>("selePi0DetaBelt", 0);
133 
134  desc.add<double>("selePi0PtPi0Min", 0);
135 
136  desc.add<double>("selePi0S4S9GammaOneMin", 0);
137  desc.add<double>("selePi0S4S9GammaTwoMin", 0);
138  desc.add<double>("selePi0S9S25GammaOneMin", 0);
139  desc.add<double>("selePi0S9S25GammaTwoMin", 0);
140 
141  desc.add<double>("selePi0EtBeltIsoRatioMax", 0);
142 
143  desc.add<double>("selePi0MinvMeanFixed", 0);
144  desc.add<double>("selePi0MinvSigmaFixed", 0);
145 
147  posCalcParameters.add<bool>("LogWeighted", true);
148  posCalcParameters.add<double>("T0_barl", 7.4);
149  posCalcParameters.add<double>("T0_endc", 3.1);
150  posCalcParameters.add<double>("T0_endcPresh", 1.2);
151  posCalcParameters.add<double>("W0", 4.2);
152  posCalcParameters.add<double>("X0", 0.89);
153  desc.add<edm::ParameterSetDescription>("posCalcParameters", posCalcParameters);
154 
155  desc.add<std::string>("clustershapecollectionEB", "islandBarrelShape");
156  desc.add<std::string>("barrelShapeAssociation", "islandBarrelShapeAssoc");
157 
158  desc.add<std::vector<std::string>>("SeedRecHitFlagToBeExcludedEB", {});
159  desc.add<std::vector<std::string>>("SeedRecHitFlagToBeExcludedEE", {});
160  desc.add<std::vector<std::string>>("RecHitFlagToBeExcludedEB", {});
161  desc.add<std::vector<std::string>>("RecHitFlagToBeExcludedEE", {});
162 
163  descriptions.add("Pi0FixedMassWindowCalibration", desc);
164 }
165 
166 //_____________________________________________________________________________
167 // Initialize algorithm
168 
170 {
171 
172  //std::cout << "[Pi0FixedMassWindowCalibration] beginOfJob "<<std::endl;
173 
174  isfirstcall_=true;
175 
176 
177 
178 }
179 
180 
182 {
183 
184  std::cout << "[Pi0FixedMassWindowCalibration] endOfJob"<<endl;
185 
186  // Write new calibration constants
187 
188  Pi0CalibXMLwriter barrelWriter(EcalBarrel,99);
189 
190  std::vector<DetId>::const_iterator barrelIt=barrelCells.begin();
191  for (; barrelIt!=barrelCells.end(); barrelIt++) {
192  EBDetId eb(*barrelIt);
193  int ieta = eb.ieta();
194  int iphi = eb.iphi();
195  int sign = eb.zside()>0 ? 1 : 0;
196  barrelWriter.writeLine(eb,newCalibs_barl[abs(ieta)-1][iphi-1][sign]);
197  }
198 
199 }
200 
201 //_____________________________________________________________________________
202 // Called at beginning of loop
204 {
205 
206  for (int sign=0; sign<2; sign++) {
207  for (int ieta=0; ieta<85; ieta++) {
208  for (int iphi=0; iphi<360; iphi++) {
209  wxtals[ieta][iphi][sign]=0.;
210  mwxtals[ieta][iphi][sign]=0.;
211  }
212  }
213  }
214  std::cout << "[Pi0FixedMassWindowCalibration] Starting loop number " << iLoop<<std::endl;
215 
216 }
217 
218 
219 //_____________________________________________________________________________
220 // Called at end of loop
221 
224 {
225  std::cout << "[Pi0FixedMassWindowCalibration] Ending loop " << iLoop<<std::endl;
226 
227  for (int sign=0; sign<2; sign++) {
228  for (int ieta=0; ieta<85; ieta++) {
229  for (int iphi=0; iphi<360; iphi++) {
230 
231  if (wxtals[ieta][iphi][sign] == 0 )
232  {
233  newCalibs_barl[ieta][iphi][sign]=oldCalibs_barl[ieta][iphi][sign];
234  } else {
235  newCalibs_barl[ieta][iphi][sign]=oldCalibs_barl[ieta][iphi][sign]*(mwxtals[ieta][iphi][sign]/wxtals[ieta][iphi][sign]);
236  }
237  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;
238 
239  }
240  }
241  }
242 
243  Pi0CalibXMLwriter barrelWriter(EcalBarrel,iLoop+1);
244 
245  std::vector<DetId>::const_iterator barrelIt=barrelCells.begin();
246  for (; barrelIt!=barrelCells.end(); barrelIt++) {
247  EBDetId eb(*barrelIt);
248  int ieta = eb.ieta();
249  int iphi = eb.iphi();
250  int sign = eb.zside()>0 ? 1 : 0;
251  barrelWriter.writeLine(eb,newCalibs_barl[abs(ieta)-1][iphi-1][sign]);
252  if (iphi==1) {
253  std::cout << "Calib constant for barrel crystal "
254  << " (" << ieta << "," << iphi << ") changed from "
255  << oldCalibs_barl[abs(ieta)-1][iphi-1][sign] << " to "
256  << newCalibs_barl[abs(ieta)-1][iphi-1][sign] << std::endl;
257  }
258  }
259 
260  // replace old calibration constants with new one
261 
262  for (int sign=0; sign<2; sign++) {
263  for (int ieta=0; ieta<85; ieta++) {
264  for (int iphi=0; iphi<360; iphi++) {
265  oldCalibs_barl[ieta][iphi][sign]=newCalibs_barl[ieta][iphi][sign];
266  newCalibs_barl[ieta][iphi][sign]=0;
267  }
268  }
269  }
270 
271 
272  if ( iLoop == theMaxLoops-1 || iLoop >= theMaxLoops ) return kStop;
273  else return kContinue;
274 }
275 
276 //_____________________________________________________________________________
277 // Called at each event
278 
281  const edm::EventSetup& setup )
282 {
283  using namespace edm;
284  using namespace std;
285 
286  // this chunk used to belong to beginJob(isetup). Moved here
287  // with the beginJob without arguments migration
288 
289  if (isfirstcall_){
290  // initialize arrays
291 
292  for (int sign=0; sign<2; sign++) {
293  for (int ieta=0; ieta<85; ieta++) {
294  for (int iphi=0; iphi<360; iphi++) {
295  oldCalibs_barl[ieta][iphi][sign]=0.;
296  newCalibs_barl[ieta][iphi][sign]=0.;
297  wxtals[ieta][iphi][sign]=0.;
298  mwxtals[ieta][iphi][sign]=0.;
299  }
300  }
301  }
302 
303  // get initial constants out of DB
304 
307 
308  try {
309  setup.get<EcalIntercalibConstantsRcd>().get(pIcal);
310  std::cout << "Taken EcalIntercalibConstants" << std::endl;
311  imap = pIcal.product()->getMap();
312  std::cout << "imap.size() = " << imap.size() << std::endl;
313  } catch ( std::exception& ex ) {
314  std::cerr << "Error! can't get EcalIntercalibConstants " << std::endl;
315  }
316 
317  // get the ecal geometry:
318  edm::ESHandle<CaloGeometry> geoHandle;
319  setup.get<CaloGeometryRecord>().get(geoHandle);
320  const CaloGeometry& geometry = *geoHandle;
321  //const CaloSubdetectorGeometry *barrelGeometry = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
322 
323  // loop over all barrel crystals
325  std::vector<DetId>::const_iterator barrelIt;
326  for (barrelIt=barrelCells.begin(); barrelIt!=barrelCells.end(); barrelIt++) {
327  EBDetId eb(*barrelIt);
328 
329  // get the initial calibration constants
331  if ( itcalib == imap.end() ) {
332  // FIXME -- throw error
333  }
334  EcalIntercalibConstant calib = (*itcalib);
335  int sign = eb.zside()>0 ? 1 : 0;
336  oldCalibs_barl[abs(eb.ieta())-1][eb.iphi()-1][sign] = calib;
337  if (eb.iphi()==1) std::cout << "Read old constant for crystal "
338  << " (" << eb.ieta() << "," << eb.iphi()
339  << ") : " << calib << std::endl;
340 
341 
342 
343  }
344  isfirstcall_=false;
345  }
346 
347 
348 
349  nevent++;
350 
351  if ((nevent<100 && nevent%10==0)
352  ||(nevent<1000 && nevent%100==0)
353  ||(nevent<10000 && nevent%100==0)
354  ||(nevent<100000 && nevent%1000==0)
355  ||(nevent<10000000 && nevent%1000==0))
356  std::cout << "[Pi0FixedMassWindowCalibration] Events processed: "<<nevent<<std::endl;
357 
358  recHitsEB_map = new std::map<DetId, EcalRecHit>();
359 
361 
362  int nRecHitsEB=0;
363  Handle<EcalRecHitCollection> pEcalRecHitBarrelCollection;
364  event.getByLabel(ecalHitsProducer_, barrelHits_, pEcalRecHitBarrelCollection);
365  const EcalRecHitCollection* ecalRecHitBarrelCollection = pEcalRecHitBarrelCollection.product();
366  cout << " ECAL Barrel RecHits # "<< ecalRecHitBarrelCollection->size() <<endl;
367  for(EcalRecHitCollection::const_iterator aRecHitEB = ecalRecHitBarrelCollection->begin(); aRecHitEB != ecalRecHitBarrelCollection->end(); aRecHitEB++) {
368  //cout << " ECAL Barrel RecHit #,E,time,det,subdetid: "<<nRecHitsEB<<" "<<aRecHitEB->energy()<<" "<<aRecHitEB->time()<<" "<<aRecHitEB->detid().det()<<" "<<aRecHitEB->detid().subdetId()<<endl;
369 
370 
371  EBDetId ebrhdetid = aRecHitEB->detid();
372  //cout << " EBDETID: z,ieta,iphi "<<ebrhdetid.zside()<<" "<<ebrhdetid.ieta()<<" "<<ebrhdetid.iphi()<<endl;
373  //cout << " EBDETID: tower_ieta,tower_iphi "<<ebrhdetid.tower_ieta()<<" "<<ebrhdetid.tower_iphi()<<endl;
374  //cout << " EBDETID: iSM, ic "<<ebrhdetid.ism()<<" "<<ebrhdetid.ic()<<endl;
375 
376  int sign = ebrhdetid.zside()>0 ? 1 : 0;
377  EcalRecHit aHit(aRecHitEB->id(),aRecHitEB->energy()*oldCalibs_barl[abs(ebrhdetid.ieta())-1][ebrhdetid.iphi()-1][sign],aRecHitEB->time());
378  recalibEcalRecHitCollection->push_back(aHit);
379 
380  nRecHitsEB++;
381 
382  }
383 
384  // cout<<" Recalib size: "<<recalibEcalRecHitCollection->size()<<endl;
385  int irecalib=0;
386  for(EcalRecHitCollection::const_iterator aRecHitEB = recalibEcalRecHitCollection->begin(); aRecHitEB != recalibEcalRecHitCollection->end(); aRecHitEB++) {
387  //cout << " [recalibrated] ECAL Barrel RecHit #,E,time,det,subdetid: "<<irecalib<<" "<<aRecHitEB->energy()<<" "<<aRecHitEB->time()<<" "<<aRecHitEB->detid().det()<<" "<<aRecHitEB->detid().subdetId()<<endl;
388 
389  // EBDetId ebrhdetid = aRecHitEB->detid();
390  //cout << " [recalibrated] EBDETID: z,ieta,iphi "<<ebrhdetid.zside()<<" "<<ebrhdetid.ieta()<<" "<<ebrhdetid.iphi()<<endl;
391  //cout << " [recalibrated] EBDETID: tower_ieta,tower_iphi "<<ebrhdetid.tower_ieta()<<" "<<ebrhdetid.tower_iphi()<<endl;
392  //cout << " [recalibrated] EBDETID: iSM, ic "<<ebrhdetid.ism()<<" "<<ebrhdetid.ic()<<endl;
393 
394  std::pair<DetId, EcalRecHit> map_entry(aRecHitEB->id(), *aRecHitEB);
395  recHitsEB_map->insert(map_entry);
396 
397 
398  irecalib++;
399 
400  }
401 
402 
403  // get the geometry and topology from the event setup:
404  edm::ESHandle<CaloGeometry> geoHandle;
405  setup.get<CaloGeometryRecord>().get(geoHandle);
406 
407  const CaloSubdetectorGeometry *geometry_p;
408 
409  std::string clustershapetag;
410  geometry_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
411  EcalBarrelTopology topology{*geoHandle};
412 
413  const CaloSubdetectorGeometry *geometryES_p;
414  geometryES_p = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
415 
416  /*
417  reco::BasicClusterCollection clusters;
418  clusters = island_p->makeClusters(ecalRecHitBarrelCollection,geometry_p,&topology,geometryES_p,IslandClusterAlgo::barrel);
419 
420  //Create associated ClusterShape objects.
421  std::vector <reco::ClusterShape> ClusVec;
422  for (int erg=0;erg<int(clusters.size());++erg){
423  reco::ClusterShape TestShape = shapeAlgo_.Calculate(clusters[erg],ecalRecHitBarrelCollection,geometry_p,&topology);
424  ClusVec.push_back(TestShape);
425  }
426 
427  //Put clustershapes in event, but retain a Handle on them.
428  std::unique_ptr<reco::ClusterShapeCollection> clustersshapes_p(new reco::ClusterShapeCollection);
429  clustersshapes_p->assign(ClusVec.begin(), ClusVec.end());
430 
431  cout<<"[Pi0Calibration] Basic Cluster collection size: "<<clusters.size()<<endl;
432  cout<<"[Pi0Calibration] Basic Cluster Shape Collection size: "<<clustersshapes_p->size()<<endl;
433 
434  int iClus=0;
435  for(reco::BasicClusterCollection::const_iterator aClus = clusters.begin(); aClus != clusters.end(); aClus++) {
436  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;
437  iClus++;
438  }
439  */
440 
441  // recalibrated clusters
442  reco::BasicClusterCollection clusters_recalib;
443  clusters_recalib = island_p->makeClusters(recalibEcalRecHitCollection,geometry_p,&topology,geometryES_p,IslandClusterAlgo::barrel);
444 
445  //Create associated ClusterShape objects.
446  std::vector <reco::ClusterShape> ClusVec_recalib;
447  for (int erg=0;erg<int(clusters_recalib.size());++erg){
448  reco::ClusterShape TestShape_recalib = shapeAlgo_.Calculate(clusters_recalib[erg],recalibEcalRecHitCollection,geometry_p,&topology);
449  ClusVec_recalib.push_back(TestShape_recalib);
450  }
451 
452  //Put clustershapes in event, but retain a Handle on them.
453  std::unique_ptr<reco::ClusterShapeCollection> clustersshapes_p_recalib(new reco::ClusterShapeCollection);
454  clustersshapes_p_recalib->assign(ClusVec_recalib.begin(), ClusVec_recalib.end());
455 
456  cout<<"[Pi0FixedMassWindowCalibration][recalibration] Basic Cluster collection size: "<<clusters_recalib.size()<<endl;
457  cout<<"[Pi0FixedMassWindowCalibration][recalibration] Basic Cluster Shape Collection size: "<<clustersshapes_p_recalib->size()<<endl;
458 
459 
460  // pizero selection
461 
462  // Get ECAL Barrel Island Basic Clusters collection
463  // ECAL Barrel Island Basic Clusters
464  static const int MAXBCEB = 200;
465  static const int MAXBCEBRH = 200;
466  int nIslandBCEB;
467  float eIslandBCEB[MAXBCEB];
468  float etIslandBCEB[MAXBCEB];
469  float etaIslandBCEB[MAXBCEB];
470  float phiIslandBCEB[MAXBCEB];
471  float e2x2IslandBCEB[MAXBCEB];
472  float e3x3IslandBCEB[MAXBCEB];
473  float e5x5IslandBCEB[MAXBCEB];
474  // indexes to the RecHits assiciated with
475  // ECAL Barrel Island Basic Clusters
476  int nIslandBCEBRecHits[MAXBCEB];
477  // int indexIslandBCEBRecHits[MAXBCEB][MAXBCEBRH];
478  int ietaIslandBCEBRecHits[MAXBCEB][MAXBCEBRH];
479  int iphiIslandBCEBRecHits[MAXBCEB][MAXBCEBRH];
480  int zsideIslandBCEBRecHits[MAXBCEB][MAXBCEBRH];
481  float eIslandBCEBRecHits[MAXBCEB][MAXBCEBRH];
482 
483  nIslandBCEB=0;
484  for(int i=0; i<MAXBCEB; i++){
485  eIslandBCEB[i] = 0;
486  etIslandBCEB[i] = 0;
487  etaIslandBCEB[i] = 0;
488  phiIslandBCEB[i] = 0;
489  e2x2IslandBCEB[i] = 0;
490  e3x3IslandBCEB[i] = 0;
491  e5x5IslandBCEB[i] = 0;
492  nIslandBCEBRecHits[i] = 0;
493  for(int j=0;j<MAXBCEBRH;j++){
494  // indexIslandBCEBRecHits[i][j] = 0;
495  ietaIslandBCEBRecHits[i][j] = 0;
496  iphiIslandBCEBRecHits[i][j] = 0;
497  zsideIslandBCEBRecHits[i][j] = 0;
498  eIslandBCEBRecHits[i][j] = 0;
499  }
500  }
501 
502 
503  int iClus_recalib=0;
504  for(reco::BasicClusterCollection::const_iterator aClus = clusters_recalib.begin(); aClus != clusters_recalib.end(); aClus++) {
505  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;
506 
507  eIslandBCEB[nIslandBCEB] = aClus->energy();
508  etIslandBCEB[nIslandBCEB] = aClus->energy()*sin(aClus->position().theta());
509  etaIslandBCEB[nIslandBCEB] = aClus->position().eta();
510  phiIslandBCEB[nIslandBCEB] = aClus->position().phi();
511 
512  e2x2IslandBCEB[nIslandBCEB] = (*clustersshapes_p_recalib)[nIslandBCEB].e2x2();
513  e3x3IslandBCEB[nIslandBCEB] = (*clustersshapes_p_recalib)[nIslandBCEB].e3x3();
514  e5x5IslandBCEB[nIslandBCEB] = (*clustersshapes_p_recalib)[nIslandBCEB].e5x5();
515 
516  nIslandBCEBRecHits[nIslandBCEB] = aClus->size();
517 
518  std::vector<std::pair< DetId,float> > hits = aClus->hitsAndFractions();
519  std::vector<std::pair< DetId,float> >::iterator hit;
520  std::map<DetId, EcalRecHit>::iterator aHit;
521 
522  int irhcount=0;
523  for(hit = hits.begin(); hit != hits.end(); hit++)
524  {
525  // need to get hit by DetID in order to get energy
526  aHit = recHitsEB_map->find((*hit).first);
527  //cout << " RecHit #: "<<irhcount<<" from Basic Cluster with Energy: "<<aHit->second.energy()<<endl;
528 
529  EBDetId sel_rh = aHit->second.detid();
530  //cout << " RecHit: z,ieta,iphi "<<sel_rh.zside()<<" "<<sel_rh.ieta()<<" "<<sel_rh.iphi()<<endl;
531  //cout << " RecHit: tower_ieta,tower_iphi "<<sel_rh.tower_ieta()<<" "<<sel_rh.tower_iphi()<<endl;
532  //cout << " RecHit: iSM, ic "<<sel_rh.ism()<<" "<<sel_rh.ic()<<endl;
533 
534  ietaIslandBCEBRecHits[nIslandBCEB][irhcount] = sel_rh.ieta();
535  iphiIslandBCEBRecHits[nIslandBCEB][irhcount] = sel_rh.iphi();
536  zsideIslandBCEBRecHits[nIslandBCEB][irhcount] = sel_rh.zside();
537  eIslandBCEBRecHits[nIslandBCEB][irhcount] = aHit->second.energy();
538 
539  irhcount++;
540  }
541  nIslandBCEB++;
542  iClus_recalib++;
543 
544 
545  }
546 
547  // Selection, based on ECAL Barrel Basic Clusters
548 
549  if (nIslandBCEB > 1)
550  {
551  for(int i=0 ; i<nIslandBCEB ; i++)
552  {
553  for(int j=i+1 ; j<nIslandBCEB ; j++)
554  {
555 
556  if( etIslandBCEB[i]>selePi0PtGammaOneMin_ && etIslandBCEB[j]>selePi0PtGammaOneMin_)
557  {
558 
559  float theta_0 = 2. * atan(exp(-etaIslandBCEB[i]));
560  float theta_1 = 2. * atan(exp(-etaIslandBCEB[j]));
561 
562  float p0x = eIslandBCEB[i] * sin(theta_0) * cos(phiIslandBCEB[i]);
563  float p1x = eIslandBCEB[j] * sin(theta_1) * cos(phiIslandBCEB[j]);
564 
565  float p0y = eIslandBCEB[i] * sin(theta_0) * sin(phiIslandBCEB[i]);
566  float p1y = eIslandBCEB[j] * sin(theta_1) * sin(phiIslandBCEB[j]);
567 
568  float p0z = eIslandBCEB[i] * cos(theta_0);
569  float p1z = eIslandBCEB[j] * cos(theta_1);
570 
571  float pi0_px = p0x + p1x;
572  float pi0_py = p0y + p1y;
573  float pi0_pz = p0z + p1z;
574 
575  float pi0_ptot = sqrt (pi0_px*pi0_px + pi0_py*pi0_py + pi0_pz*pi0_pz);
576 
577  float pi0_theta = acos(pi0_pz/pi0_ptot);
578  float pi0_eta = -log(tan(pi0_theta/2));
579  float pi0_phi = atan(pi0_py/pi0_px);
580  //cout << " pi0_theta, pi0_eta, pi0_phi "<<pi0_theta<<" "<<pi0_eta<<" "<<pi0_phi<<endl;
581 
582  // belt isolation
583 
584  float et_belt=0;
585  for(Int_t k=0 ; k<nIslandBCEB ; k++)
586  {
587  if( (k != i) && (k != j) )
588  {
589  float dr_pi0_k = sqrt( (etaIslandBCEB[k]-pi0_eta)*(etaIslandBCEB[k]-pi0_eta) + (phiIslandBCEB[k]-pi0_phi)*(phiIslandBCEB[k]-pi0_phi) );
590  float deta_pi0_k = fabs(etaIslandBCEB[k]-pi0_eta);
591  if ( (dr_pi0_k<selePi0DRBelt_) && (deta_pi0_k<selePi0DetaBelt_) ) et_belt = et_belt + etIslandBCEB[k];
592  }
593  }
594 
595 
596  float pt_pi0 = sqrt( (p0x+p1x)*(p0x+p1x) + (p0y+p1y)*(p0y+p1y));
597  //float dr_pi0 = sqrt ( (etaIslandBCEB[i]-etaIslandBCEB[j])*(etaIslandBCEB[i]-etaIslandBCEB[j]) + (phiIslandBCEB[i]-phiIslandBCEB[j])*(phiIslandBCEB[i]-phiIslandBCEB[j]) );
598 
599  //cout <<" pi0 pt,dr: "<<pt_pi0<<" "<<dr_pi0<<endl;
600  if (pt_pi0 > selePi0PtPi0Min_)
601  {
602  float m_inv = sqrt ( (eIslandBCEB[i] + eIslandBCEB[j])*(eIslandBCEB[i] + eIslandBCEB[j]) - (p0x+p1x)*(p0x+p1x) - (p0y+p1y)*(p0y+p1y) - (p0z+p1z)*(p0z+p1z) );
603  cout <<" pi0 (pt>2.5 GeV) m_inv = "<<m_inv<<endl;
604 
605  float s4s9_1 = e2x2IslandBCEB[i]/e3x3IslandBCEB[i];
606  float s4s9_2 = e2x2IslandBCEB[j]/e3x3IslandBCEB[j];
607 
608  float s9s25_1 = e3x3IslandBCEB[i]/e5x5IslandBCEB[i];
609  float s9s25_2 = e3x3IslandBCEB[j]/e5x5IslandBCEB[j];
610 
611  //float s9Esc_1 = e3x3IslandBCEB[i]/eIslandBCEB[i];
612  //float s9Esc_2 = e3x3IslandBCEB[j]/eIslandBCEB[j];
613 
615  {
616  //good pizero candidate
618  {
619  //fill wxtals and mwxtals weights
620  cout<<" Pi0 Good candidate : minv = "<<m_inv<<endl;
621  for(int kk=0 ; kk<nIslandBCEBRecHits[i] ; kk++)
622  {
623  int ieta_xtal = ietaIslandBCEBRecHits[i][kk];
624  int iphi_xtal = iphiIslandBCEBRecHits[i][kk];
625  int sign = zsideIslandBCEBRecHits[i][kk]>0 ? 1 : 0;
626  wxtals[abs(ieta_xtal)-1][iphi_xtal-1][sign] = wxtals[abs(ieta_xtal)-1][iphi_xtal-1][sign] + eIslandBCEBRecHits[i][kk]/e3x3IslandBCEB[i];
627  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]);
628  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;
629  }
630 
631  for(int kk=0 ; kk<nIslandBCEBRecHits[j] ; kk++)
632  {
633  int ieta_xtal = ietaIslandBCEBRecHits[j][kk];
634  int iphi_xtal = iphiIslandBCEBRecHits[j][kk];
635  int sign = zsideIslandBCEBRecHits[j][kk]>0 ? 1 : 0;
636  wxtals[abs(ieta_xtal)-1][iphi_xtal-1][sign] = wxtals[abs(ieta_xtal)-1][iphi_xtal-1][sign] + eIslandBCEBRecHits[j][kk]/e3x3IslandBCEB[j];
637  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]);
638  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;
639  }
640 
641  }
642  }
643  }
644  }
645 
646 
647  } // End of the "j" loop over BCEB
648  } // End of the "i" loop over BCEB
649 
650 
651  } else {
652  cout<< " Not enough ECAL Barrel Basic Clusters: "<<nIslandBCEB<<endl;
653  }
654 
655 
656 
657 
658 
659 
660  return kContinue;
661 }
662 
663 // ----------------------------------------------------------------------------
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
void startingNewLoop(unsigned int iLoop) override
Called at beginning of loop.
void beginOfJob() override
Called at beginning of job.
Status endOfLoop(const edm::EventSetup &, unsigned int iLoop) override
Called at end of loop.
CaloTopology const * topology(0)
const self & getMap() const
void writeLine(EBDetId const &, float)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
std::vector< EcalRecHit >::const_iterator const_iterator
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
std::vector< ClusterShape > ClusterShapeCollection
collection of ClusterShape objects
IslandClusterAlgo::VerbosityLevel verbosity
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
reco::ClusterShape Calculate(const reco::BasicCluster &passedCluster, const EcalRecHitCollection *hits, const CaloSubdetectorGeometry *geometry, const CaloSubdetectorTopology *topology)
MVATrainerComputer * calib
Definition: MVATrainer.cc:64
T sqrt(T t)
Definition: SSEVec.h:18
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
ParameterDescriptionBase * add(U const &iLabel, T const &value)
const EcalRecHitCollection * ecalRecHitBarrelCollection
int k[5][pyjets_maxn]
const_iterator end() const
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< RectangularEtaPhiRegion > &regions=std::vector< RectangularEtaPhiRegion >())
T const * product() const
Definition: Handle.h:74
std::vector< Item >::const_iterator const_iterator
Status duringLoop(const edm::Event &, const edm::EventSetup &) override
Called at each event.
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
HLT enums.
size_type size() const
T get() const
Definition: EventSetup.h:71
const_iterator find(uint32_t rawId) const
const_iterator end() const
std::map< DetId, EcalRecHit > * recHitsEB_map
Pi0FixedMassWindowCalibration(const edm::ParameterSet &iConfig)
Constructor.
~Pi0FixedMassWindowCalibration() override
Destructor.
T const * product() const
Definition: ESHandle.h:86
const EcalRecHitCollection * recalibEcalRecHitCollection
void endOfJob() override
Called at end of job.
const_iterator begin() const
Definition: event.py:1
int zside() const
get the z-side of the crystal (1/-1)
Definition: EBDetId.h:45
float EcalIntercalibConstant