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