33 : theMaxLoops(iConfig.getUntrackedParameter<unsigned
int>(
"maxLoops", 0)),
34 ecalHitsProducer_(iConfig.getParameter<
std::
string>(
"ecalRecHitsProducer")),
35 barrelHits_(iConfig.getParameter<
std::
string>(
"barrelHitCollection")),
39 std::cout <<
"[Pi0FixedMassWindowCalibration] Constructor " << std::endl;
42 if (verbosityString ==
"DEBUG")
44 else if (verbosityString ==
"WARNING")
46 else if (verbosityString ==
"INFO")
55 double barrelSeedThreshold = iConfig.
getParameter<
double>(
"IslandBarrelSeedThr");
56 double endcapSeedThreshold = iConfig.
getParameter<
double>(
"IslandEndcapSeedThr");
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);
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);
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);
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);
122 desc.add<
unsigned int>(
"maxLoops", 0);
129 desc.add<
double>(
"IslandBarrelSeedThr", 0);
130 desc.add<
double>(
"IslandEndcapSeedThr", 0);
132 desc.add<
double>(
"selePi0PtGammaOneMin", 0);
133 desc.add<
double>(
"selePi0PtGammaTwoMin", 0);
135 desc.add<
double>(
"selePi0DRBelt", 0);
136 desc.add<
double>(
"selePi0DetaBelt", 0);
138 desc.add<
double>(
"selePi0PtPi0Min", 0);
140 desc.add<
double>(
"selePi0S4S9GammaOneMin", 0);
141 desc.add<
double>(
"selePi0S4S9GammaTwoMin", 0);
142 desc.add<
double>(
"selePi0S9S25GammaOneMin", 0);
143 desc.add<
double>(
"selePi0S9S25GammaTwoMin", 0);
145 desc.add<
double>(
"selePi0EtBeltIsoRatioMax", 0);
147 desc.add<
double>(
"selePi0MinvMeanFixed", 0);
148 desc.add<
double>(
"selePi0MinvSigmaFixed", 0);
159 desc.add<
std::string>(
"clustershapecollectionEB",
"islandBarrelShape");
160 desc.add<
std::string>(
"barrelShapeAssociation",
"islandBarrelShapeAssoc");
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", {});
167 descriptions.
add(
"Pi0FixedMassWindowCalibration",
desc);
180 std::cout <<
"[Pi0FixedMassWindowCalibration] endOfJob" << endl;
186 std::vector<DetId>::const_iterator barrelIt =
barrelCells.begin();
187 for (; barrelIt !=
barrelCells.end(); barrelIt++) {
207 std::cout <<
"[Pi0FixedMassWindowCalibration] Starting loop number " << iLoop << std::endl;
214 std::cout <<
"[Pi0FixedMassWindowCalibration] Ending loop " << iLoop << std::endl;
225 cout <<
" New calibration constant: ieta iphi sign - old,mwxtals,wxtals,new: " <<
ieta <<
" " <<
iphi <<
" " 234 std::vector<DetId>::const_iterator barrelIt =
barrelCells.begin();
235 for (; barrelIt !=
barrelCells.end(); barrelIt++) {
242 std::cout <<
"Calib constant for barrel crystal " 295 const auto& imap = pIcal.getMap();
296 std::cout <<
"imap.size() = " << imap.size() << std::endl;
300 std::vector<DetId>::const_iterator barrelIt;
306 if (itcalib == imap.end()) {
313 std::cout <<
"Read old constant for crystal " 314 <<
" (" << eb.
ieta() <<
"," << eb.
iphi() <<
") : " <<
calib << std::endl;
324 std::cout <<
"[Pi0FixedMassWindowCalibration] Events processed: " <<
nevent << std::endl;
331 event.getByToken(
recHitToken_, pEcalRecHitBarrelCollection);
337 EBDetId ebrhdetid = aRecHitEB->detid();
342 int sign = ebrhdetid.
zside() > 0 ? 1 : 0;
358 std::pair<DetId, EcalRecHit> map_entry(aRecHitEB->id(), *aRecHitEB);
402 std::vector<reco::ClusterShape> ClusVec_recalib;
403 for (
int erg = 0; erg <
int(clusters_recalib.size()); ++erg) {
406 ClusVec_recalib.push_back(TestShape_recalib);
411 clustersshapes_p_recalib->assign(ClusVec_recalib.begin(), ClusVec_recalib.end());
413 cout <<
"[Pi0FixedMassWindowCalibration][recalibration] Basic Cluster collection size: " << clusters_recalib.size()
415 cout <<
"[Pi0FixedMassWindowCalibration][recalibration] Basic Cluster Shape Collection size: " 416 << clustersshapes_p_recalib->size() << endl;
422 static const int MAXBCEB = 200;
423 static const int MAXBCEBRH = 200;
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];
434 int nIslandBCEBRecHits[MAXBCEB];
436 int ietaIslandBCEBRecHits[MAXBCEB][MAXBCEBRH];
437 int iphiIslandBCEBRecHits[MAXBCEB][MAXBCEBRH];
438 int zsideIslandBCEBRecHits[MAXBCEB][MAXBCEBRH];
439 float eIslandBCEBRecHits[MAXBCEB][MAXBCEBRH];
442 for (
int i = 0;
i < MAXBCEB;
i++) {
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++) {
453 ietaIslandBCEBRecHits[
i][
j] = 0;
454 iphiIslandBCEBRecHits[
i][
j] = 0;
455 zsideIslandBCEBRecHits[
i][
j] = 0;
456 eIslandBCEBRecHits[
i][
j] = 0;
460 int iClus_recalib = 0;
461 for (reco::BasicClusterCollection::const_iterator aClus = clusters_recalib.begin(); aClus != clusters_recalib.end();
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;
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();
475 e2x2IslandBCEB[nIslandBCEB] = (*clustersshapes_p_recalib)[nIslandBCEB].e2x2();
476 e3x3IslandBCEB[nIslandBCEB] = (*clustersshapes_p_recalib)[nIslandBCEB].e3x3();
477 e5x5IslandBCEB[nIslandBCEB] = (*clustersshapes_p_recalib)[nIslandBCEB].e5x5();
479 nIslandBCEBRecHits[nIslandBCEB] = aClus->size();
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;
491 EBDetId sel_rh = aHit->second.detid();
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();
509 if (nIslandBCEB > 1) {
510 for (
int i = 0;
i < nIslandBCEB;
i++) {
511 for (
int j =
i + 1;
j < nIslandBCEB;
j++) {
513 float theta_0 = 2. * atan(
exp(-etaIslandBCEB[
i]));
514 float theta_1 = 2. * atan(
exp(-etaIslandBCEB[
j]));
516 float p0x = eIslandBCEB[
i] *
sin(theta_0) *
cos(phiIslandBCEB[
i]);
517 float p1x = eIslandBCEB[
j] *
sin(theta_1) *
cos(phiIslandBCEB[
j]);
519 float p0y = eIslandBCEB[
i] *
sin(theta_0) *
sin(phiIslandBCEB[
i]);
520 float p1y = eIslandBCEB[
j] *
sin(theta_1) *
sin(phiIslandBCEB[
j]);
522 float p0z = eIslandBCEB[
i] *
cos(theta_0);
523 float p1z = eIslandBCEB[
j] *
cos(theta_1);
525 float pi0_px = p0x + p1x;
526 float pi0_py = p0y + p1y;
527 float pi0_pz = p0z + p1z;
529 float pi0_ptot =
sqrt(pi0_px * pi0_px + pi0_py * pi0_py + pi0_pz * pi0_pz);
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);
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);
545 et_belt = et_belt + etIslandBCEB[
k];
549 float pt_pi0 =
sqrt((p0x + p1x) * (p0x + p1x) + (p0y + p1y) * (p0y + p1y));
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;
558 float s4s9_1 = e2x2IslandBCEB[
i] / e3x3IslandBCEB[
i];
559 float s4s9_2 = e2x2IslandBCEB[
j] / e3x3IslandBCEB[
j];
561 float s9s25_1 = e3x3IslandBCEB[
i] / e5x5IslandBCEB[
i];
562 float s9s25_2 = e3x3IslandBCEB[
j] / e5x5IslandBCEB[
j];
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;
580 wxtals[
abs(ieta_xtal) - 1][iphi_xtal - 1][
sign] + eIslandBCEBRecHits[
i][
kk] / e3x3IslandBCEB[
i];
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] <<
" " 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;
596 wxtals[
abs(ieta_xtal) - 1][iphi_xtal - 1][
sign] + eIslandBCEBRecHits[
j][
kk] / e3x3IslandBCEB[
j];
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] <<
" " 615 cout <<
" Not enough ECAL Barrel Basic Clusters: " << nIslandBCEB << endl;
double selePi0PtGammaTwoMin_
edm::ParameterSet theParameterSet
void startingNewLoop(unsigned int iLoop) override
Called at beginning of loop.
T getParameter(std::string const &) const
void beginOfJob() override
Called at beginning of job.
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geometryToken_
std::string clustershapecollectionEB_
const edm::ESGetToken< EcalIntercalibConstants, EcalIntercalibConstantsRcd > intercalibConstantsToken_
double selePi0S9S25GammaOneMin_
Status endOfLoop(const edm::EventSetup &, unsigned int iLoop) override
Called at end of loop.
int iphi() const
get the crystal iphi
void writeLine(EBDetId const &, float)
Sin< T >::type sin(const T &t)
std::vector< DetId > barrelCells
double selePi0S4S9GammaOneMin_
const unsigned int theMaxLoops
T const * product() const
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
PositionCalc posCalculator_
int ieta() const
get the crystal ieta
double selePi0PtGammaOneMin_
reco::ClusterShape Calculate(const reco::BasicCluster &passedCluster, const EcalRecHitCollection *hits, const CaloSubdetectorGeometry *geometry, const CaloSubdetectorTopology *topology)
double selePi0MinvMeanFixed_
std::string barrelClusterCollection_
Cos< T >::type cos(const T &t)
Tan< T >::type tan(const T &t)
double selePi0MinvSigmaFixed_
Abs< T >::type abs(const T &t)
double selePi0S9S25GammaTwoMin_
const_iterator begin() const
int zside() const
get the z-side of the crystal (1/-1)
const EcalRecHitCollection * ecalRecHitBarrelCollection
const_iterator end() const
const edm::EDGetTokenT< EcalRecHitCollection > recHitToken_
double newCalibs_barl[85][360][2]
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 > ®ions=std::vector< RectangularEtaPhiRegion >())
double selePi0EtBeltIsoRatioMax_
constexpr uint32_t rawId() const
get the raw id
std::vector< Item >::const_iterator const_iterator
Status duringLoop(const edm::Event &, const edm::EventSetup &) override
Called at each event.
double selePi0S4S9GammaTwoMin_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
std::string barrelClusterShapeAssociation_
IslandClusterAlgo * island_p
double mwxtals[85][360][2]
double oldCalibs_barl[85][360][2]
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.
ClusterShapeAlgo shapeAlgo_
float EcalIntercalibConstant
double wxtals[85][360][2]