CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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");
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 =
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,
104  posCalculator_,
105  seedflagsexclEB,
106  seedflagsexclEE,
107  flagsexclEB,
108  flagsexclEE,
109  verbosity);
110 
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) {
220  newCalibs_barl[ieta][iphi][sign] = oldCalibs_barl[ieta][iphi][sign];
221  } else {
222  newCalibs_barl[ieta][iphi][sign] =
223  oldCalibs_barl[ieta][iphi][sign] * (mwxtals[ieta][iphi][sign] / wxtals[ieta][iphi][sign]);
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++) {
253  oldCalibs_barl[ieta][iphi][sign] = newCalibs_barl[ieta][iphi][sign];
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  int nRecHitsEB = 0;
331  Handle<EcalRecHitCollection> pEcalRecHitBarrelCollection;
332  event.getByToken(recHitToken_, pEcalRecHitBarrelCollection);
333  const EcalRecHitCollection* ecalRecHitBarrelCollection = pEcalRecHitBarrelCollection.product();
334  cout << " ECAL Barrel RecHits # " << ecalRecHitBarrelCollection->size() << endl;
336  aRecHitEB != ecalRecHitBarrelCollection->end();
337  aRecHitEB++) {
338  //cout << " ECAL Barrel RecHit #,E,time,det,subdetid: "<<nRecHitsEB<<" "<<aRecHitEB->energy()<<" "<<aRecHitEB->time()<<" "<<aRecHitEB->detid().det()<<" "<<aRecHitEB->detid().subdetId()<<endl;
339 
340  EBDetId ebrhdetid = aRecHitEB->detid();
341  //cout << " EBDETID: z,ieta,iphi "<<ebrhdetid.zside()<<" "<<ebrhdetid.ieta()<<" "<<ebrhdetid.iphi()<<endl;
342  //cout << " EBDETID: tower_ieta,tower_iphi "<<ebrhdetid.tower_ieta()<<" "<<ebrhdetid.tower_iphi()<<endl;
343  //cout << " EBDETID: iSM, ic "<<ebrhdetid.ism()<<" "<<ebrhdetid.ic()<<endl;
344 
345  int sign = ebrhdetid.zside() > 0 ? 1 : 0;
346  EcalRecHit aHit(aRecHitEB->id(),
347  aRecHitEB->energy() * oldCalibs_barl[abs(ebrhdetid.ieta()) - 1][ebrhdetid.iphi() - 1][sign],
348  aRecHitEB->time());
349  recalibEcalRecHitCollection->push_back(aHit);
350 
351  nRecHitsEB++;
352  }
353 
354  // cout<<" Recalib size: "<<recalibEcalRecHitCollection->size()<<endl;
355  int irecalib = 0;
356  for (EcalRecHitCollection::const_iterator aRecHitEB = recalibEcalRecHitCollection->begin();
357  aRecHitEB != recalibEcalRecHitCollection->end();
358  aRecHitEB++) {
359  //cout << " [recalibrated] ECAL Barrel RecHit #,E,time,det,subdetid: "<<irecalib<<" "<<aRecHitEB->energy()<<" "<<aRecHitEB->time()<<" "<<aRecHitEB->detid().det()<<" "<<aRecHitEB->detid().subdetId()<<endl;
360 
361  // EBDetId ebrhdetid = aRecHitEB->detid();
362  //cout << " [recalibrated] EBDETID: z,ieta,iphi "<<ebrhdetid.zside()<<" "<<ebrhdetid.ieta()<<" "<<ebrhdetid.iphi()<<endl;
363  //cout << " [recalibrated] EBDETID: tower_ieta,tower_iphi "<<ebrhdetid.tower_ieta()<<" "<<ebrhdetid.tower_iphi()<<endl;
364  //cout << " [recalibrated] EBDETID: iSM, ic "<<ebrhdetid.ism()<<" "<<ebrhdetid.ic()<<endl;
365 
366  std::pair<DetId, EcalRecHit> map_entry(aRecHitEB->id(), *aRecHitEB);
367  recHitsEB_map->insert(map_entry);
368 
369  irecalib++;
370  }
371 
372  const CaloSubdetectorGeometry* geometry_p;
373 
374  std::string clustershapetag;
375  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
376  EcalBarrelTopology topology{geometry};
377 
378  const CaloSubdetectorGeometry* geometryES_p;
379  geometryES_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
380 
381  /*
382  reco::BasicClusterCollection clusters;
383  clusters = island_p->makeClusters(ecalRecHitBarrelCollection,geometry_p,&topology,geometryES_p,IslandClusterAlgo::barrel);
384 
385  //Create associated ClusterShape objects.
386  std::vector <reco::ClusterShape> ClusVec;
387  for (int erg=0;erg<int(clusters.size());++erg){
388  reco::ClusterShape TestShape = shapeAlgo_.Calculate(clusters[erg],ecalRecHitBarrelCollection,geometry_p,&topology);
389  ClusVec.push_back(TestShape);
390  }
391 
392  //Put clustershapes in event, but retain a Handle on them.
393  std::unique_ptr<reco::ClusterShapeCollection> clustersshapes_p(new reco::ClusterShapeCollection);
394  clustersshapes_p->assign(ClusVec.begin(), ClusVec.end());
395 
396  cout<<"[Pi0Calibration] Basic Cluster collection size: "<<clusters.size()<<endl;
397  cout<<"[Pi0Calibration] Basic Cluster Shape Collection size: "<<clustersshapes_p->size()<<endl;
398 
399  int iClus=0;
400  for(reco::BasicClusterCollection::const_iterator aClus = clusters.begin(); aClus != clusters.end(); aClus++) {
401  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;
402  iClus++;
403  }
404  */
405 
406  // recalibrated clusters
407  reco::BasicClusterCollection clusters_recalib;
408  clusters_recalib = island_p->makeClusters(
409  recalibEcalRecHitCollection, geometry_p, &topology, geometryES_p, IslandClusterAlgo::barrel);
410 
411  //Create associated ClusterShape objects.
412  std::vector<reco::ClusterShape> ClusVec_recalib;
413  for (int erg = 0; erg < int(clusters_recalib.size()); ++erg) {
414  reco::ClusterShape TestShape_recalib =
415  shapeAlgo_.Calculate(clusters_recalib[erg], recalibEcalRecHitCollection, geometry_p, &topology);
416  ClusVec_recalib.push_back(TestShape_recalib);
417  }
418 
419  //Put clustershapes in event, but retain a Handle on them.
420  std::unique_ptr<reco::ClusterShapeCollection> clustersshapes_p_recalib(new reco::ClusterShapeCollection);
421  clustersshapes_p_recalib->assign(ClusVec_recalib.begin(), ClusVec_recalib.end());
422 
423  cout << "[Pi0FixedMassWindowCalibration][recalibration] Basic Cluster collection size: " << clusters_recalib.size()
424  << endl;
425  cout << "[Pi0FixedMassWindowCalibration][recalibration] Basic Cluster Shape Collection size: "
426  << clustersshapes_p_recalib->size() << endl;
427 
428  // pizero selection
429 
430  // Get ECAL Barrel Island Basic Clusters collection
431  // ECAL Barrel Island Basic Clusters
432  static const int MAXBCEB = 200;
433  static const int MAXBCEBRH = 200;
434  int nIslandBCEB;
435  float eIslandBCEB[MAXBCEB];
436  float etIslandBCEB[MAXBCEB];
437  float etaIslandBCEB[MAXBCEB];
438  float phiIslandBCEB[MAXBCEB];
439  float e2x2IslandBCEB[MAXBCEB];
440  float e3x3IslandBCEB[MAXBCEB];
441  float e5x5IslandBCEB[MAXBCEB];
442  // indexes to the RecHits assiciated with
443  // ECAL Barrel Island Basic Clusters
444  int nIslandBCEBRecHits[MAXBCEB];
445  // int indexIslandBCEBRecHits[MAXBCEB][MAXBCEBRH];
446  int ietaIslandBCEBRecHits[MAXBCEB][MAXBCEBRH];
447  int iphiIslandBCEBRecHits[MAXBCEB][MAXBCEBRH];
448  int zsideIslandBCEBRecHits[MAXBCEB][MAXBCEBRH];
449  float eIslandBCEBRecHits[MAXBCEB][MAXBCEBRH];
450 
451  nIslandBCEB = 0;
452  for (int i = 0; i < MAXBCEB; i++) {
453  eIslandBCEB[i] = 0;
454  etIslandBCEB[i] = 0;
455  etaIslandBCEB[i] = 0;
456  phiIslandBCEB[i] = 0;
457  e2x2IslandBCEB[i] = 0;
458  e3x3IslandBCEB[i] = 0;
459  e5x5IslandBCEB[i] = 0;
460  nIslandBCEBRecHits[i] = 0;
461  for (int j = 0; j < MAXBCEBRH; j++) {
462  // indexIslandBCEBRecHits[i][j] = 0;
463  ietaIslandBCEBRecHits[i][j] = 0;
464  iphiIslandBCEBRecHits[i][j] = 0;
465  zsideIslandBCEBRecHits[i][j] = 0;
466  eIslandBCEBRecHits[i][j] = 0;
467  }
468  }
469 
470  int iClus_recalib = 0;
471  for (reco::BasicClusterCollection::const_iterator aClus = clusters_recalib.begin(); aClus != clusters_recalib.end();
472  aClus++) {
473  cout << " CLUSTER [recalibration] : #,NHits,e,et,eta,phi,e2x2,e3x3,e5x5: " << iClus_recalib << " " << aClus->size()
474  << " " << aClus->energy() << " " << aClus->energy() * sin(aClus->position().theta()) << " "
475  << aClus->position().eta() << " " << aClus->position().phi() << " "
476  << (*clustersshapes_p_recalib)[iClus_recalib].e2x2() << " "
477  << (*clustersshapes_p_recalib)[iClus_recalib].e3x3() << " "
478  << (*clustersshapes_p_recalib)[iClus_recalib].e5x5() << endl;
479 
480  eIslandBCEB[nIslandBCEB] = aClus->energy();
481  etIslandBCEB[nIslandBCEB] = aClus->energy() * sin(aClus->position().theta());
482  etaIslandBCEB[nIslandBCEB] = aClus->position().eta();
483  phiIslandBCEB[nIslandBCEB] = aClus->position().phi();
484 
485  e2x2IslandBCEB[nIslandBCEB] = (*clustersshapes_p_recalib)[nIslandBCEB].e2x2();
486  e3x3IslandBCEB[nIslandBCEB] = (*clustersshapes_p_recalib)[nIslandBCEB].e3x3();
487  e5x5IslandBCEB[nIslandBCEB] = (*clustersshapes_p_recalib)[nIslandBCEB].e5x5();
488 
489  nIslandBCEBRecHits[nIslandBCEB] = aClus->size();
490 
491  std::vector<std::pair<DetId, float>> hits = aClus->hitsAndFractions();
492  std::vector<std::pair<DetId, float>>::iterator hit;
493  std::map<DetId, EcalRecHit>::iterator aHit;
494 
495  int irhcount = 0;
496  for (hit = hits.begin(); hit != hits.end(); hit++) {
497  // need to get hit by DetID in order to get energy
498  aHit = recHitsEB_map->find((*hit).first);
499  //cout << " RecHit #: "<<irhcount<<" from Basic Cluster with Energy: "<<aHit->second.energy()<<endl;
500 
501  EBDetId sel_rh = aHit->second.detid();
502  //cout << " RecHit: z,ieta,iphi "<<sel_rh.zside()<<" "<<sel_rh.ieta()<<" "<<sel_rh.iphi()<<endl;
503  //cout << " RecHit: tower_ieta,tower_iphi "<<sel_rh.tower_ieta()<<" "<<sel_rh.tower_iphi()<<endl;
504  //cout << " RecHit: iSM, ic "<<sel_rh.ism()<<" "<<sel_rh.ic()<<endl;
505 
506  ietaIslandBCEBRecHits[nIslandBCEB][irhcount] = sel_rh.ieta();
507  iphiIslandBCEBRecHits[nIslandBCEB][irhcount] = sel_rh.iphi();
508  zsideIslandBCEBRecHits[nIslandBCEB][irhcount] = sel_rh.zside();
509  eIslandBCEBRecHits[nIslandBCEB][irhcount] = aHit->second.energy();
510 
511  irhcount++;
512  }
513  nIslandBCEB++;
514  iClus_recalib++;
515  }
516 
517  // Selection, based on ECAL Barrel Basic Clusters
518 
519  if (nIslandBCEB > 1) {
520  for (int i = 0; i < nIslandBCEB; i++) {
521  for (int j = i + 1; j < nIslandBCEB; j++) {
522  if (etIslandBCEB[i] > selePi0PtGammaOneMin_ && etIslandBCEB[j] > selePi0PtGammaOneMin_) {
523  float theta_0 = 2. * atan(exp(-etaIslandBCEB[i]));
524  float theta_1 = 2. * atan(exp(-etaIslandBCEB[j]));
525 
526  float p0x = eIslandBCEB[i] * sin(theta_0) * cos(phiIslandBCEB[i]);
527  float p1x = eIslandBCEB[j] * sin(theta_1) * cos(phiIslandBCEB[j]);
528 
529  float p0y = eIslandBCEB[i] * sin(theta_0) * sin(phiIslandBCEB[i]);
530  float p1y = eIslandBCEB[j] * sin(theta_1) * sin(phiIslandBCEB[j]);
531 
532  float p0z = eIslandBCEB[i] * cos(theta_0);
533  float p1z = eIslandBCEB[j] * cos(theta_1);
534 
535  float pi0_px = p0x + p1x;
536  float pi0_py = p0y + p1y;
537  float pi0_pz = p0z + p1z;
538 
539  float pi0_ptot = sqrt(pi0_px * pi0_px + pi0_py * pi0_py + pi0_pz * pi0_pz);
540 
541  float pi0_theta = acos(pi0_pz / pi0_ptot);
542  float pi0_eta = -log(tan(pi0_theta / 2));
543  float pi0_phi = atan(pi0_py / pi0_px);
544  //cout << " pi0_theta, pi0_eta, pi0_phi "<<pi0_theta<<" "<<pi0_eta<<" "<<pi0_phi<<endl;
545 
546  // belt isolation
547 
548  float et_belt = 0;
549  for (Int_t k = 0; k < nIslandBCEB; k++) {
550  if ((k != i) && (k != j)) {
551  float dr_pi0_k = sqrt((etaIslandBCEB[k] - pi0_eta) * (etaIslandBCEB[k] - pi0_eta) +
552  (phiIslandBCEB[k] - pi0_phi) * (phiIslandBCEB[k] - pi0_phi));
553  float deta_pi0_k = fabs(etaIslandBCEB[k] - pi0_eta);
554  if ((dr_pi0_k < selePi0DRBelt_) && (deta_pi0_k < selePi0DetaBelt_))
555  et_belt = et_belt + etIslandBCEB[k];
556  }
557  }
558 
559  float pt_pi0 = sqrt((p0x + p1x) * (p0x + p1x) + (p0y + p1y) * (p0y + p1y));
560  //float dr_pi0 = sqrt ( (etaIslandBCEB[i]-etaIslandBCEB[j])*(etaIslandBCEB[i]-etaIslandBCEB[j]) + (phiIslandBCEB[i]-phiIslandBCEB[j])*(phiIslandBCEB[i]-phiIslandBCEB[j]) );
561 
562  //cout <<" pi0 pt,dr: "<<pt_pi0<<" "<<dr_pi0<<endl;
563  if (pt_pi0 > selePi0PtPi0Min_) {
564  float m_inv = sqrt((eIslandBCEB[i] + eIslandBCEB[j]) * (eIslandBCEB[i] + eIslandBCEB[j]) -
565  (p0x + p1x) * (p0x + p1x) - (p0y + p1y) * (p0y + p1y) - (p0z + p1z) * (p0z + p1z));
566  cout << " pi0 (pt>2.5 GeV) m_inv = " << m_inv << endl;
567 
568  float s4s9_1 = e2x2IslandBCEB[i] / e3x3IslandBCEB[i];
569  float s4s9_2 = e2x2IslandBCEB[j] / e3x3IslandBCEB[j];
570 
571  float s9s25_1 = e3x3IslandBCEB[i] / e5x5IslandBCEB[i];
572  float s9s25_2 = e3x3IslandBCEB[j] / e5x5IslandBCEB[j];
573 
574  //float s9Esc_1 = e3x3IslandBCEB[i]/eIslandBCEB[i];
575  //float s9Esc_2 = e3x3IslandBCEB[j]/eIslandBCEB[j];
576 
577  if (s4s9_1 > selePi0S4S9GammaOneMin_ && s4s9_2 > selePi0S4S9GammaTwoMin_ &&
578  s9s25_1 > selePi0S9S25GammaOneMin_ && s9s25_2 > selePi0S9S25GammaTwoMin_ &&
579  (et_belt / pt_pi0 < selePi0EtBeltIsoRatioMax_)) {
580  //good pizero candidate
581  if (m_inv > (selePi0MinvMeanFixed_ - 2 * selePi0MinvSigmaFixed_) &&
583  //fill wxtals and mwxtals weights
584  cout << " Pi0 Good candidate : minv = " << m_inv << endl;
585  for (int kk = 0; kk < nIslandBCEBRecHits[i]; kk++) {
586  int ieta_xtal = ietaIslandBCEBRecHits[i][kk];
587  int iphi_xtal = iphiIslandBCEBRecHits[i][kk];
588  int sign = zsideIslandBCEBRecHits[i][kk] > 0 ? 1 : 0;
589  wxtals[abs(ieta_xtal) - 1][iphi_xtal - 1][sign] =
590  wxtals[abs(ieta_xtal) - 1][iphi_xtal - 1][sign] + eIslandBCEBRecHits[i][kk] / e3x3IslandBCEB[i];
591  mwxtals[abs(ieta_xtal) - 1][iphi_xtal - 1][sign] =
592  mwxtals[abs(ieta_xtal) - 1][iphi_xtal - 1][sign] +
593  (selePi0MinvMeanFixed_ / m_inv) * (selePi0MinvMeanFixed_ / m_inv) *
594  (eIslandBCEBRecHits[i][kk] / e3x3IslandBCEB[i]);
595  cout << "[Pi0FixedMassWindowCalibration] eta, phi, sign, e, e3x3, wxtals and mwxtals: " << ieta_xtal
596  << " " << iphi_xtal << " " << sign << " " << eIslandBCEBRecHits[i][kk] << " "
597  << e3x3IslandBCEB[i] << " " << wxtals[abs(ieta_xtal) - 1][iphi_xtal - 1][sign] << " "
598  << mwxtals[abs(ieta_xtal) - 1][iphi_xtal - 1][sign] << endl;
599  }
600 
601  for (int kk = 0; kk < nIslandBCEBRecHits[j]; kk++) {
602  int ieta_xtal = ietaIslandBCEBRecHits[j][kk];
603  int iphi_xtal = iphiIslandBCEBRecHits[j][kk];
604  int sign = zsideIslandBCEBRecHits[j][kk] > 0 ? 1 : 0;
605  wxtals[abs(ieta_xtal) - 1][iphi_xtal - 1][sign] =
606  wxtals[abs(ieta_xtal) - 1][iphi_xtal - 1][sign] + eIslandBCEBRecHits[j][kk] / e3x3IslandBCEB[j];
607  mwxtals[abs(ieta_xtal) - 1][iphi_xtal - 1][sign] =
608  mwxtals[abs(ieta_xtal) - 1][iphi_xtal - 1][sign] +
609  (selePi0MinvMeanFixed_ / m_inv) * (selePi0MinvMeanFixed_ / m_inv) *
610  (eIslandBCEBRecHits[j][kk] / e3x3IslandBCEB[j]);
611  cout << "[Pi0FixedMassWindowCalibration] eta, phi, sign, e, e3x3, wxtals and mwxtals: " << ieta_xtal
612  << " " << iphi_xtal << " " << sign << " " << eIslandBCEBRecHits[j][kk] << " "
613  << e3x3IslandBCEB[j] << " " << wxtals[abs(ieta_xtal) - 1][iphi_xtal - 1][sign] << " "
614  << mwxtals[abs(ieta_xtal) - 1][iphi_xtal - 1][sign] << endl;
615  }
616  }
617  }
618  }
619  }
620 
621  } // End of the "j" loop over BCEB
622  } // End of the "i" loop over BCEB
623 
624  } else {
625  cout << " Not enough ECAL Barrel Basic Clusters: " << nIslandBCEB << endl;
626  }
627 
628  return kContinue;
629 }
630 
631 // ----------------------------------------------------------------------------
void startingNewLoop(unsigned int iLoop) override
Called at beginning of loop.
void beginOfJob() override
Called at beginning of job.
static std::vector< std::string > checklist log
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.
void writeLine(EBDetId const &, float)
double sign(double x)
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:57
std::vector< EcalRecHit >::const_iterator const_iterator
std::vector< ClusterShape > ClusterShapeCollection
collection of ClusterShape objects
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
IslandClusterAlgo::VerbosityLevel verbosity
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
bool getData(T &iHolder) const
Definition: EventSetup.h:128
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
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
tuple posCalcParameters
ParameterDescriptionBase * add(U const &iLabel, T const &value)
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 >())
std::vector< Item >::const_iterator const_iterator
Status duringLoop(const edm::Event &, const edm::EventSetup &) override
Called at each event.
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
size_type size() const
tuple cout
Definition: gather_cfg.py:144
std::map< DetId, EcalRecHit > * recHitsEB_map
Pi0FixedMassWindowCalibration(const edm::ParameterSet &iConfig)
Constructor.
~Pi0FixedMassWindowCalibration() override
Destructor.
const EcalRecHitCollection * recalibEcalRecHitCollection
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void endOfJob() override
Called at end of job.
const_iterator begin() const
int zside() const
get the z-side of the crystal (1/-1)
Definition: EBDetId.h:45
float EcalIntercalibConstant