From 869cf33d7801add2122e7338ef61d51fff2d2253 Mon Sep 17 00:00:00 2001 From: Simone Pigazzi Date: Tue, 15 Feb 2022 10:58:20 +0100 Subject: [PATCH 01/13] Remove unused PhiSym code --- .../interface/PhiSymmetryCalibration.h | 166 ---- .../EcalCalibAlgos/plugins/SealModule.cc | 2 - .../src/PhiSymmetryCalibration.cc | 513 ----------- .../src/PhiSymmetryCalibration_step2.cc | 818 ----------------- .../src/PhiSymmetryCalibration_step2.h | 98 -- .../src/PhiSymmetryCalibration_step2_SM.cc | 863 ------------------ .../src/PhiSymmetryCalibration_step2_SM.h | 107 --- 7 files changed, 2567 deletions(-) delete mode 100644 Calibration/EcalCalibAlgos/interface/PhiSymmetryCalibration.h delete mode 100644 Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration.cc delete mode 100644 Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration_step2.cc delete mode 100644 Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration_step2.h delete mode 100644 Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration_step2_SM.cc delete mode 100644 Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration_step2_SM.h diff --git a/Calibration/EcalCalibAlgos/interface/PhiSymmetryCalibration.h b/Calibration/EcalCalibAlgos/interface/PhiSymmetryCalibration.h deleted file mode 100644 index ec976ea70b01a..0000000000000 --- a/Calibration/EcalCalibAlgos/interface/PhiSymmetryCalibration.h +++ /dev/null @@ -1,166 +0,0 @@ -#ifndef Calibration_EcalCalibAlgos_PhiSymmetryCalibration_h -#define Calibration_EcalCalibAlgos_PhiSymmetryCalibration_h - -// -// Package: Calibration/EcalCalibAlgos -// Class: PhiSymmetryCalibration -// -// -// Description: performs phi-symmetry calibration -// -// -// Original Author: David Futyan -// -// Responsible : Stefano Argiro, Valentina Sola -// - -#include - -#include "Calibration/EcalCalibAlgos/interface/EcalGeomPhiSymHelper.h" - -// Framework -#include "FWCore/Framework/interface/one/EDAnalyzer.h" -#include "FWCore/Framework/interface/EventSetup.h" -#include "FWCore/Framework/interface/ProducerBase.h" -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/Event.h" - -#include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h" -#include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h" -#include "CondFormats/EcalObjects/interface/EcalChannelStatus.h" -#include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h" -#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" -#include "DataFormats/DetId/interface/DetId.h" -#include "Geometry/CaloGeometry/interface/CaloGeometry.h" -#include "Geometry/Records/interface/CaloGeometryRecord.h" - -class TH1F; - -class PhiSymmetryCalibration - : public edm::one::EDAnalyzer { -public: - /// Constructor - PhiSymmetryCalibration(const edm::ParameterSet& iConfig); - - /// Destructor - ~PhiSymmetryCalibration() override; - - /// Called at beginning of job - void beginJob() override; - void beginRun(edm::Run const&, const edm::EventSetup&) override; - void endRun(edm::Run const&, const edm::EventSetup&) override; - void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; - void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; - - /// Called at end of job - void endJob() override; - - /// Called at each event - void analyze(const edm::Event&, const edm::EventSetup&) override; - - /// - void setUp(const edm::EventSetup& setup); - -private: - // private member functions - - void getKfactors(); - - // private data members - - static const int kNMiscalBinsEB = 21; - static const float kMiscalRangeEB; - - static const int kNMiscalBinsEE = 41; - static const float kMiscalRangeEE; - - EcalGeomPhiSymHelper e_; - - // Transverse energy sum arrays - double etsum_barl_[kBarlRings][kBarlWedges][kSides]; - double etsum_endc_[kEndcWedgesX][kEndcWedgesX][kSides]; - double etsum_endc_uncorr[kEndcWedgesX][kEndcWedgesX][kSides]; - double etsumMean_barl_[kBarlRings]; - double etsumMean_endc_[kEndcEtaRings]; - - unsigned int nhits_barl_[kBarlRings][kBarlWedges][kSides]; - unsigned int nhits_endc_[kEndcWedgesX][kEndcWedgesX][kSides]; - - double etsum_barl_miscal_[kNMiscalBinsEB][kBarlRings]; - double etsum_endc_miscal_[kNMiscalBinsEE][kEndcEtaRings]; - - double esumMean_barl_[kBarlRings]; - double esumMean_endc_[kEndcEtaRings]; - - // factors to convert from ET sum deviation to miscalibration - double k_barl_[kBarlRings]; - double k_endc_[kEndcEtaRings]; - double miscalEB_[kNMiscalBinsEB]; - double miscalEE_[kNMiscalBinsEE]; - - std::vector barrelCells; - std::vector endcapCells; - - // input calibration constants - double oldCalibs_barl[kBarlRings][kBarlWedges][kSides]; - double oldCalibs_endc[kEndcWedgesX][kEndcWedgesY][kSides]; - - // new calibration constants - double newCalibs_barl[kBarlRings][kBarlWedges][kSides]; - double newCalibs_endc[kEndcWedgesX][kEndcWedgesX][kSides]; - - // calibration constants not multiplied by old ones - float epsilon_M_barl[kBarlRings][kBarlWedges][kSides]; - float epsilon_M_endc[kEndcWedgesX][kEndcWedgesY][kSides]; - - // calibration const not corrected for k - float rawconst_barl[kBarlRings][kBarlWedges][kSides]; - float rawconst_endc[kEndcWedgesX][kEndcWedgesX][kSides]; - - // steering parameters - - const std::string ecalHitsProducer_; - const std::string barrelHits_; - const std::string endcapHits_; - - const edm::EDGetTokenT ebRecHitToken_; - const edm::EDGetTokenT eeRecHitToken_; - const edm::ESGetToken channelStatusToken_; - const edm::ESGetToken geometryToken_; - - // energy cut in the barrel - const double eCut_barl_; - - // parametrized energy cut EE : e_cut = ap + eta_ring*b - const double ap_; - const double b_; - - const int eventSet_; - /// threshold in channel status beyond which channel is marked bad - const int statusThreshold_; - - static const int kMaxEndciPhi = 360; - - float phi_endc[kMaxEndciPhi][kEndcEtaRings]; - - const bool reiteration_; - const std::string oldcalibfile_; //searched for in Calibration/EcalCalibAlgos/data - - /// the old calibration constants (when reiterating, the last ones derived) - EcalIntercalibConstants oldCalibs_; - - bool isfirstpass_; - - // Et and E spectra - std::vector et_spectrum_b_histos; //kBarlEtaRings - std::vector e_spectrum_b_histos; - std::vector et_spectrum_e_histos; //kEndcEtaRings - std::vector e_spectrum_e_histos; - - bool spectra; - int nevents_; - int eventsinrun_; - int eventsinlb_; -}; - -#endif diff --git a/Calibration/EcalCalibAlgos/plugins/SealModule.cc b/Calibration/EcalCalibAlgos/plugins/SealModule.cc index b1ce700d8dc01..1cdebadb88dec 100644 --- a/Calibration/EcalCalibAlgos/plugins/SealModule.cc +++ b/Calibration/EcalCalibAlgos/plugins/SealModule.cc @@ -3,13 +3,11 @@ #include "Calibration/EcalCalibAlgos/interface/InvRingCalib.h" #include "Calibration/EcalCalibAlgos/interface/miscalibExample.h" #include "Calibration/EcalCalibAlgos/interface/ZeeCalibration.h" -#include "Calibration/EcalCalibAlgos/interface/PhiSymmetryCalibration.h" #include "Calibration/EcalCalibAlgos/interface/Pi0FixedMassWindowCalibration.h" #include "Calibration/EcalCalibAlgos/interface/ECALpedestalPCLworker.h" #include "Calibration/EcalCalibAlgos/interface/ECALpedestalPCLHarvester.h" DEFINE_FWK_MODULE(miscalibExample); -DEFINE_FWK_MODULE(PhiSymmetryCalibration); DEFINE_FWK_LOOPER(Pi0FixedMassWindowCalibration); DEFINE_FWK_LOOPER(ZeeCalibration); DEFINE_FWK_LOOPER(EcalEleCalibLooper); diff --git a/Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration.cc b/Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration.cc deleted file mode 100644 index 65aef4d2e594c..0000000000000 --- a/Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration.cc +++ /dev/null @@ -1,513 +0,0 @@ -#include "Calibration/EcalCalibAlgos/interface/PhiSymmetryCalibration.h" - -// System include files -#include - -// Framework -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -#include "DataFormats/EcalDetId/interface/EBDetId.h" -#include "DataFormats/EcalDetId/interface/EEDetId.h" -#include "CondFormats/EcalObjects/interface/EcalIntercalibErrors.h" -#include "CondTools/Ecal/interface/EcalIntercalibConstantsXMLTranslator.h" -#include "FWCore/Framework/interface/LuminosityBlock.h" - -// Geometry -#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h" -#include "Geometry/CaloGeometry/interface/CaloCellGeometry.h" - -//Channel status -#include "CondFormats/EcalObjects/interface/EcalChannelStatusCode.h" - -#include "FWCore/Framework/interface/Run.h" - -using namespace std; -#include -#include -#include "TH2F.h" -#include "TFile.h" -#include "TTree.h" -#include "TH1F.h" -#include "TF1.h" -#include "TGraph.h" -#include "TCanvas.h" - -const float PhiSymmetryCalibration::kMiscalRangeEB = .05; -const float PhiSymmetryCalibration::kMiscalRangeEE = .10; - -//_____________________________________________________________________________ -// Class constructor - -PhiSymmetryCalibration::PhiSymmetryCalibration(const edm::ParameterSet& iConfig) - : ecalHitsProducer_(iConfig.getParameter("ecalRecHitsProducer")), - barrelHits_(iConfig.getParameter("barrelHitCollection")), - endcapHits_(iConfig.getParameter("endcapHitCollection")), - ebRecHitToken_(consumes(edm::InputTag(ecalHitsProducer_, barrelHits_))), - eeRecHitToken_(consumes(edm::InputTag(ecalHitsProducer_, endcapHits_))), - channelStatusToken_(esConsumes()), - geometryToken_(esConsumes()), - eCut_barl_(iConfig.getParameter("eCut_barrel")), - ap_(iConfig.getParameter("ap")), - b_(iConfig.getParameter("b")), - eventSet_(iConfig.getParameter("eventSet")), - statusThreshold_(iConfig.getUntrackedParameter("statusThreshold", 3)), - reiteration_(iConfig.getUntrackedParameter("reiteration", false)), - oldcalibfile_(iConfig.getUntrackedParameter("oldcalibfile", "EcalintercalibConstants.xml")) { - isfirstpass_ = true; - - et_spectrum_b_histos.resize(kBarlRings); - e_spectrum_b_histos.resize(kBarlRings); - et_spectrum_e_histos.resize(kEndcEtaRings); - e_spectrum_e_histos.resize(kEndcEtaRings); - - spectra = true; - - nevents_ = 0; - eventsinrun_ = 0; - eventsinlb_ = 0; - - // because ROOT draws something - usesResource(); -} - -//_____________________________________________________________________________ -// Close files, etc. - -PhiSymmetryCalibration::~PhiSymmetryCalibration() { - for (Int_t i = 0; i < kBarlRings; i++) { - delete et_spectrum_b_histos[i]; - delete e_spectrum_b_histos[i]; - } - for (Int_t i = 0; i < kEndcEtaRings; i++) { - delete et_spectrum_e_histos[i]; - delete e_spectrum_e_histos[i]; - } -} - -//_____________________________________________________________________________ -// Initialize algorithm - -void PhiSymmetryCalibration::beginJob() { - // initialize arrays - for (int sign = 0; sign < kSides; sign++) { - for (int ieta = 0; ieta < kBarlRings; ieta++) { - for (int iphi = 0; iphi < kBarlWedges; iphi++) { - etsum_barl_[ieta][iphi][sign] = 0.; - nhits_barl_[ieta][iphi][sign] = 0; - } - } - for (int ix = 0; ix < kEndcWedgesX; ix++) { - for (int iy = 0; iy < kEndcWedgesY; iy++) { - etsum_endc_[ix][iy][sign] = 0.; - nhits_endc_[ix][iy][sign] = 0; - } - } - } - - for (int imiscal = 0; imiscal < kNMiscalBinsEB; imiscal++) { - miscalEB_[imiscal] = (1 - kMiscalRangeEB) + float(imiscal) * (2 * kMiscalRangeEB / (kNMiscalBinsEB - 1)); - for (int ieta = 0; ieta < kBarlRings; ieta++) - etsum_barl_miscal_[imiscal][ieta] = 0.; - } - - for (int imiscal = 0; imiscal < kNMiscalBinsEE; imiscal++) { - miscalEE_[imiscal] = (1 - kMiscalRangeEE) + float(imiscal) * (2 * kMiscalRangeEE / (kNMiscalBinsEE - 1)); - for (int ring = 0; ring < kEndcEtaRings; ring++) - etsum_endc_miscal_[imiscal][ring] = 0.; - } - - // start spectra stuff - if (eventSet_ != 1) - spectra = false; - - if (spectra) { - ostringstream t; - for (Int_t i = 0; i < kBarlRings; i++) { - t << "et_spectrum_b_" << i + 1; - et_spectrum_b_histos[i] = new TH1F(t.str().c_str(), ";E_{T} [MeV]", 50, 0., 500.); - t.str(""); - - t << "e_spectrum_b_" << i + 1; - e_spectrum_b_histos[i] = new TH1F(t.str().c_str(), ";E [MeV]", 50, 0., 500.); - t.str(""); - } - for (Int_t i = 0; i < kEndcEtaRings; i++) { - t << "et_spectrum_e_" << i + 1; - et_spectrum_e_histos[i] = new TH1F(t.str().c_str(), ";E_{T} [MeV]", 75, 0., 1500.); - t.str(""); - - t << "e_spectrum_e_" << i + 1; - e_spectrum_e_histos[i] = new TH1F(t.str().c_str(), ";E [MeV]", 75, 0., 1500.); - t.str(""); - } - } - // end spectra stuff -} - -//_____________________________________________________________________________ -// Terminate algorithm - -void PhiSymmetryCalibration::endJob() { - edm::LogInfo("Calibration") << "[PhiSymmetryCalibration] At end of job"; - - // start spectra stuff - if (spectra) { - TFile f("Espectra_plus.root", "recreate"); - - for (int i = 0; i < kBarlRings; i++) { - et_spectrum_b_histos[i]->Write(); - e_spectrum_b_histos[i]->Write(); - } - - for (int i = 0; i < kEndcEtaRings; i++) { - et_spectrum_e_histos[i]->Write(); - e_spectrum_e_histos[i]->Write(); - } - - f.Close(); - } - - if (eventSet_ == 1) { - // calculate factors to convert from fractional deviation of ET sum from - // the mean to the estimate of the miscalibration factor - getKfactors(); - - std::ofstream k_barl_out("k_barl.dat", ios::out); - for (int ieta = 0; ieta < kBarlRings; ieta++) - k_barl_out << ieta << " " << k_barl_[ieta] << endl; - k_barl_out.close(); - - std::ofstream k_endc_out("k_endc.dat", ios::out); - for (int ring = 0; ring < kEndcEtaRings; ring++) - k_endc_out << ring << " " << k_endc_[ring] << endl; - k_endc_out.close(); - } - - if (eventSet_ != 0) { - // output ET sums - - stringstream etsum_file_barl; - etsum_file_barl << "etsum_barl_" << eventSet_ << ".dat"; - - std::ofstream etsum_barl_out(etsum_file_barl.str().c_str(), ios::out); - - for (int ieta = 0; ieta < kBarlRings; ieta++) { - for (int iphi = 0; iphi < kBarlWedges; iphi++) { - for (int sign = 0; sign < kSides; sign++) { - etsum_barl_out << eventSet_ << " " << ieta << " " << iphi << " " << sign << " " - << etsum_barl_[ieta][iphi][sign] << " " << nhits_barl_[ieta][iphi][sign] << endl; - } - } - } - etsum_barl_out.close(); - - stringstream etsum_file_endc; - etsum_file_endc << "etsum_endc_" << eventSet_ << ".dat"; - - std::ofstream etsum_endc_out(etsum_file_endc.str().c_str(), ios::out); - for (int ix = 0; ix < kEndcWedgesX; ix++) { - for (int iy = 0; iy < kEndcWedgesY; iy++) { - int ring = e_.endcapRing_[ix][iy]; - if (ring != -1) { - for (int sign = 0; sign < kSides; sign++) { - etsum_endc_out << eventSet_ << " " << ix << " " << iy << " " << sign << " " << etsum_endc_[ix][iy][sign] - << " " << nhits_endc_[ix][iy][sign] << " " << e_.endcapRing_[ix][iy] << endl; - } - } - } - } - etsum_endc_out.close(); - } - cout << "Events processed " << nevents_ << endl; -} - -//_____________________________________________________________________________ -// Called at each event - -void PhiSymmetryCalibration::analyze(const edm::Event& event, const edm::EventSetup& setup) { - using namespace edm; - using namespace std; - - if (isfirstpass_) { - setUp(setup); - isfirstpass_ = false; - } - - Handle barrelRecHitsHandle; - Handle endcapRecHitsHandle; - - event.getByToken(ebRecHitToken_, barrelRecHitsHandle); - if (!barrelRecHitsHandle.isValid()) { - LogError("") << "[PhiSymmetryCalibration] Error! Can't get product!" << std::endl; - } - - event.getByToken(ebRecHitToken_, endcapRecHitsHandle); - if (!endcapRecHitsHandle.isValid()) { - LogError("") << "[PhiSymmetryCalibration] Error! Can't get product!" << std::endl; - } - - // get the ecal geometry - const auto& geometry = setup.getData(geometryToken_); - const auto* barrelGeometry = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel); - const auto* endcapGeometry = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap); - - bool pass = false; - // select interesting EcalRecHits (barrel) - EBRecHitCollection::const_iterator itb; - for (itb = barrelRecHitsHandle->begin(); itb != barrelRecHitsHandle->end(); itb++) { - EBDetId hit = EBDetId(itb->id()); - float eta = barrelGeometry->getGeometry(hit)->getPosition().eta(); - float et = itb->energy() / cosh(eta); - float e = itb->energy(); - - // if iterating, correct by the previous calib constants found, - // which are supplied in the form of correction - if (reiteration_) { - et = et * oldCalibs_[hit]; - e = e * oldCalibs_[hit]; - } - - float et_thr = eCut_barl_ / cosh(eta) + 1.; - - int sign = hit.ieta() > 0 ? 1 : 0; - - if (e > eCut_barl_ && et < et_thr && e_.goodCell_barl[abs(hit.ieta()) - 1][hit.iphi() - 1][sign]) { - etsum_barl_[abs(hit.ieta()) - 1][hit.iphi() - 1][sign] += et; - nhits_barl_[abs(hit.ieta()) - 1][hit.iphi() - 1][sign]++; - pass = true; - } //if energy - - if (eventSet_ == 1) { - // apply a miscalibration to all crystals and increment the - // ET sum, combined for all crystals - for (int imiscal = 0; imiscal < kNMiscalBinsEB; imiscal++) { - if (miscalEB_[imiscal] * e > eCut_barl_ && miscalEB_[imiscal] * et < et_thr && - e_.goodCell_barl[abs(hit.ieta()) - 1][hit.iphi() - 1][sign]) { - etsum_barl_miscal_[imiscal][abs(hit.ieta()) - 1] += miscalEB_[imiscal] * et; - } - } - - // spectra stuff - if (spectra && hit.ieta() > 0) //POSITIVE!!! - // if(spectra && hit.ieta()<0) //NEGATIVE!!! - { - et_spectrum_b_histos[abs(hit.ieta()) - 1]->Fill(et * 1000.); - e_spectrum_b_histos[abs(hit.ieta()) - 1]->Fill(e * 1000.); - } //if spectra - - } //if eventSet_==1 - } //for barl - - // select interesting EcalRecHits (endcaps) - EERecHitCollection::const_iterator ite; - for (ite = endcapRecHitsHandle->begin(); ite != endcapRecHitsHandle->end(); ite++) { - EEDetId hit = EEDetId(ite->id()); - float eta = abs(endcapGeometry->getGeometry(hit)->getPosition().eta()); - //float phi = endcapGeometry->getGeometry(hit)->getPosition().phi(); - - float et = ite->energy() / cosh(eta); - float e = ite->energy(); - - // if iterating, multiply by the previous correction factor - if (reiteration_) { - et = et * oldCalibs_[hit]; - e = e * oldCalibs_[hit]; - } - - int sign = hit.zside() > 0 ? 1 : 0; - - // changes of eCut_endc_ -> variable linearthr - // e_cut = ap + eta_ring*b - - double eCut_endc = 0; - for (int ring = 0; ring < kEndcEtaRings; ring++) { - if (eta > e_.etaBoundary_[ring] && eta < e_.etaBoundary_[ring + 1]) { - float eta_ring = abs(e_.cellPos_[ring][50].eta()); - eCut_endc = ap_ + eta_ring * b_; - } - } - - float et_thr = eCut_endc / cosh(eta) + 1.; - - if (e > eCut_endc && et < et_thr && e_.goodCell_endc[hit.ix() - 1][hit.iy() - 1][sign]) { - etsum_endc_[hit.ix() - 1][hit.iy() - 1][sign] += et; - nhits_endc_[hit.ix() - 1][hit.iy() - 1][sign]++; - pass = true; - } - - if (eventSet_ == 1) { - // apply a miscalibration to all crystals and increment the - // ET sum, combined for all crystals - for (int imiscal = 0; imiscal < kNMiscalBinsEE; imiscal++) { - if (miscalEE_[imiscal] * e > eCut_endc && et * miscalEE_[imiscal] < et_thr && - e_.goodCell_endc[hit.ix() - 1][hit.iy() - 1][sign]) { - int ring = e_.endcapRing_[hit.ix() - 1][hit.iy() - 1]; - etsum_endc_miscal_[imiscal][ring] += miscalEE_[imiscal] * et; - } - } - - // spectra stuff - if (spectra && hit.zside() > 0) //POSITIVE!!! - - { - int ring = e_.endcapRing_[hit.ix() - 1][hit.iy() - 1]; - - et_spectrum_e_histos[ring]->Fill(et * 1000.); - e_spectrum_e_histos[ring]->Fill(e * 1000.); - - if (ring == 16) { - //int iphi_endc = 0; - for (int ip = 0; ip < e_.nRing_[ring]; ip++) { - //if (phi==e_.phi_endc_[ip][ring]) iphi_endc=ip; - } - } - } //if spectra - - } //if eventSet_==1 - } //for endc - - if (pass) { - nevents_++; - eventsinrun_++; - eventsinlb_++; - } -} - -void PhiSymmetryCalibration::beginRun(edm::Run const&, const edm::EventSetup&) {} - -void PhiSymmetryCalibration::endRun(edm::Run const& run, const edm::EventSetup&) { - std::cout << "PHIREPRT : run " << run.run() << " start " << (run.beginTime().value() >> 32) << " end " - << (run.endTime().value() >> 32) << " dur " - << (run.endTime().value() >> 32) - (run.beginTime().value() >> 32) - - << " npass " << eventsinrun_ << std::endl; - eventsinrun_ = 0; - - return; -} - -//_____________________________________________________________________________ - -void PhiSymmetryCalibration::getKfactors() { - float epsilon_T_eb[kNMiscalBinsEB]; - float epsilon_M_eb[kNMiscalBinsEB]; - - float epsilon_T_ee[kNMiscalBinsEE]; - float epsilon_M_ee[kNMiscalBinsEE]; - - std::vector k_barl_graph(kBarlRings); - std::vector k_barl_plot(kBarlRings); - - //Create our own TF1 to avoid threading problems - TF1 mypol1("mypol1", "pol1"); - for (int ieta = 0; ieta < kBarlRings; ieta++) { - for (int imiscal = 0; imiscal < kNMiscalBinsEB; imiscal++) { - int middlebin = int(kNMiscalBinsEB / 2); - epsilon_T_eb[imiscal] = etsum_barl_miscal_[imiscal][ieta] / etsum_barl_miscal_[middlebin][ieta] - 1.; - epsilon_M_eb[imiscal] = miscalEB_[imiscal] - 1.; - } - k_barl_graph[ieta] = new TGraph(kNMiscalBinsEB, epsilon_M_eb, epsilon_T_eb); - k_barl_graph[ieta]->Fit(&mypol1); - - ostringstream t; - t << "k_barl_" << ieta + 1; - k_barl_plot[ieta] = new TCanvas(t.str().c_str(), ""); - k_barl_plot[ieta]->SetFillColor(10); - k_barl_plot[ieta]->SetGrid(); - k_barl_graph[ieta]->SetMarkerSize(1.); - k_barl_graph[ieta]->SetMarkerColor(4); - k_barl_graph[ieta]->SetMarkerStyle(20); - k_barl_graph[ieta]->GetXaxis()->SetLimits(-1. * kMiscalRangeEB, kMiscalRangeEB); - k_barl_graph[ieta]->GetXaxis()->SetTitleSize(.05); - k_barl_graph[ieta]->GetYaxis()->SetTitleSize(.05); - k_barl_graph[ieta]->GetXaxis()->SetTitle("#epsilon_{M}"); - k_barl_graph[ieta]->GetYaxis()->SetTitle("#epsilon_{T}"); - k_barl_graph[ieta]->Draw("AP"); - - k_barl_[ieta] = k_barl_graph[ieta]->GetFunction("pol1")->GetParameter(1); - std::cout << "k_barl_[" << ieta << "]=" << k_barl_[ieta] << std::endl; - } - - std::vector k_endc_graph(kEndcEtaRings); - std::vector k_endc_plot(kEndcEtaRings); - - for (int ring = 0; ring < kEndcEtaRings; ring++) { - for (int imiscal = 0; imiscal < kNMiscalBinsEE; imiscal++) { - int middlebin = int(kNMiscalBinsEE / 2); - epsilon_T_ee[imiscal] = etsum_endc_miscal_[imiscal][ring] / etsum_endc_miscal_[middlebin][ring] - 1.; - epsilon_M_ee[imiscal] = miscalEE_[imiscal] - 1.; - } - k_endc_graph[ring] = new TGraph(kNMiscalBinsEE, epsilon_M_ee, epsilon_T_ee); - k_endc_graph[ring]->Fit(&mypol1); - - ostringstream t; - t << "k_endc_" << ring + 1; - k_endc_plot[ring] = new TCanvas(t.str().c_str(), ""); - k_endc_plot[ring]->SetFillColor(10); - k_endc_plot[ring]->SetGrid(); - k_endc_graph[ring]->SetMarkerSize(1.); - k_endc_graph[ring]->SetMarkerColor(4); - k_endc_graph[ring]->SetMarkerStyle(20); - k_endc_graph[ring]->GetXaxis()->SetLimits(-1 * kMiscalRangeEE, kMiscalRangeEE); - k_endc_graph[ring]->GetXaxis()->SetTitleSize(.05); - k_endc_graph[ring]->GetYaxis()->SetTitleSize(.05); - k_endc_graph[ring]->GetXaxis()->SetTitle("#epsilon_{M}"); - k_endc_graph[ring]->GetYaxis()->SetTitle("#epsilon_{T}"); - k_endc_graph[ring]->Draw("AP"); - - k_endc_[ring] = k_endc_graph[ring]->GetFunction("pol1")->GetParameter(1); - std::cout << "k_endc_[" << ring << "]=" << k_endc_[ring] << std::endl; - } - - TFile f("PhiSymmetryCalibration_kFactors.root", "recreate"); - for (int ieta = 0; ieta < kBarlRings; ieta++) { - k_barl_plot[ieta]->Write(); - delete k_barl_plot[ieta]; - delete k_barl_graph[ieta]; - } - for (int ring = 0; ring < kEndcEtaRings; ring++) { - k_endc_plot[ring]->Write(); - delete k_endc_plot[ring]; - delete k_endc_graph[ring]; - } - f.Close(); -} - -//_____________________________________________________________________________ - -void PhiSymmetryCalibration::setUp(const edm::EventSetup& setup) { - const auto& chStatus = setup.getData(channelStatusToken_); - - const auto& geometry = setup.getData(geometryToken_); - - e_.setup(&geometry, &chStatus, statusThreshold_); - - if (reiteration_) { - EcalCondHeader h; - // namespace fs = boost::filesystem; - // fs::path p(oldcalibfile_.c_str(),fs::native); - // if (!fs::exists(p)) edm::LogError("PhiSym") << "File not found: " - // << oldcalibfile_ <> 32) - (lb.beginTime().value() >> 32) < 60) - return; - - std::cout << "PHILB : run " << lb.run() << " id " << lb.id() << " start " << (lb.beginTime().value() >> 32) << " end " - << (lb.endTime().value() >> 32) << " dur " << (lb.endTime().value() >> 32) - (lb.beginTime().value() >> 32) - - << " npass " << eventsinlb_ << std::endl; - - eventsinlb_ = 0; -} diff --git a/Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration_step2.cc b/Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration_step2.cc deleted file mode 100644 index 525c8a40c77ea..0000000000000 --- a/Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration_step2.cc +++ /dev/null @@ -1,818 +0,0 @@ -#include "Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration_step2.h" -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h" -#include "CondTools/Ecal/interface/EcalIntercalibConstantsXMLTranslator.h" -#include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h" - -#include "TH2F.h" - -#include "TH1F.h" -#include "TFile.h" - -#include -#include - -using namespace std; - -PhiSymmetryCalibration_step2::~PhiSymmetryCalibration_step2() {} - -PhiSymmetryCalibration_step2::PhiSymmetryCalibration_step2(const edm::ParameterSet& iConfig) - : channelStatusToken_(esConsumes()), - geometryToken_(esConsumes()), - firstpass_(true), - statusThreshold_(iConfig.getUntrackedParameter("statusThreshold", 0)), - reiteration_(iConfig.getUntrackedParameter("reiteration", false)), - oldcalibfile_(iConfig.getUntrackedParameter("oldcalibfile", "EcalIntercalibConstants.xml")), - have_initial_miscalib_(iConfig.getUntrackedParameter("haveInitialMiscalib", false)), - initialmiscalibfile_(iConfig.getUntrackedParameter("initialmiscalibfile", "InitialMiscalib.xml")) {} - -void PhiSymmetryCalibration_step2::analyze(const edm::Event& ev, const edm::EventSetup& se) { - if (firstpass_) { - setUp(se); - firstpass_ = false; - } -} - -void PhiSymmetryCalibration_step2::setUp(const edm::EventSetup& se) { - const auto& chStatus = se.getData(channelStatusToken_); - - const auto& geometry = se.getData(geometryToken_); - - barrelCells = geometry.getValidDetIds(DetId::Ecal, EcalBarrel); - endcapCells = geometry.getValidDetIds(DetId::Ecal, EcalEndcap); - - e_.setup(&geometry, &chStatus, statusThreshold_); - - /// if a miscalibration was applied, load it, if not put it to 1 - if (have_initial_miscalib_) { - EcalCondHeader h; - namespace fs = std::filesystem; - fs::path p(initialmiscalibfile_.c_str()); - if (!fs::exists(p)) - edm::LogError("PhiSym") << "File not found: " << initialmiscalibfile_ << endl; - - int ret = EcalIntercalibConstantsXMLTranslator::readXML(initialmiscalibfile_, h, miscalib_); - if (ret) - edm::LogError("PhiSym") << "Error reading XML files" << endl; - ; - } else { - for (vector::iterator it = barrelCells.begin(); it != barrelCells.end(); ++it) { - miscalib_[*it] = 1; - } - - for (vector::iterator it = endcapCells.begin(); it != endcapCells.end(); ++it) { - miscalib_[*it] = 1; - } - } - - // if we are reiterating, read constants from previous iter - // if not put them to one - if (reiteration_) { - EcalCondHeader h; - namespace fs = std::filesystem; - fs::path p(oldcalibfile_.c_str()); - if (!fs::exists(p)) - edm::LogError("PhiSym") << "File not found: " << oldcalibfile_ << endl; - - int ret = EcalIntercalibConstantsXMLTranslator::readXML(oldcalibfile_, h, oldCalibs_); - - if (ret) - edm::LogError("PhiSym") << "Error reading XML files" << endl; - ; - - } else { - for (vector::iterator it = barrelCells.begin(); it != barrelCells.end(); ++it) - oldCalibs_[*it] = 1; - - for (vector::iterator it = endcapCells.begin(); it != endcapCells.end(); ++it) - oldCalibs_[*it] = 1; - - } // else -} - -void PhiSymmetryCalibration_step2::beginJob() { - for (int ieta = 0; ieta < kBarlRings; ieta++) { - for (int iphi = 0; iphi < kBarlWedges; iphi++) { - for (int sign = 0; sign < kSides; sign++) { - etsum_barl_[ieta][iphi][sign] = 0.; - nhits_barl_[ieta][iphi][sign] = 0; - esum_barl_[ieta][iphi][sign] = 0.; - } - } - } - - for (int ix = 0; ix < kEndcWedgesX; ix++) { - for (int iy = 0; iy < kEndcWedgesY; iy++) { - for (int sign = 0; sign < kSides; sign++) { - etsum_endc_[ix][iy][sign] = 0.; - nhits_endc_[ix][iy][sign] = 0; - esum_endc_[ix][iy][sign] = 0.; - } - } - } - - readEtSums(); - setupResidHistos(); -} - -void PhiSymmetryCalibration_step2::endJob() { - if (firstpass_) { - edm::LogError("PhiSym") << "Must process at least one event-Exiting" << endl; - return; - } - - // Here the real calculation of constants happens - - // perform the area correction for endcap etsum - // NOT USED ANYMORE - - for (int ix = 0; ix < kEndcWedgesX; ix++) { - for (int iy = 0; iy < kEndcWedgesY; iy++) { - int ring = e_.endcapRing_[ix][iy]; - - if (ring != -1) { - for (int sign = 0; sign < kSides; sign++) { - etsum_endc_uncorr[ix][iy][sign] = etsum_endc_[ix][iy][sign]; - etsum_endc_[ix][iy][sign] *= e_.meanCellArea_[ring] / e_.cellArea_[ix][iy]; - } - } - } - } - - // ETsum histos, maps and other usefull histos (area,...) - // are filled and saved here - fillHistos(); - - // write ETsum mean for all rings - std::ofstream etsumMean_barl_out("etsumMean_barl.dat", ios::out); - for (int ieta = 0; ieta < kBarlRings; ieta++) { - etsumMean_barl_out << ieta << " " << etsumMean_barl_[ieta] << endl; - } - etsumMean_barl_out.close(); - - std::ofstream etsumMean_endc_out("etsumMean_endc.dat", ios::out); - for (int ring = 0; ring < kEndcEtaRings; ring++) { - etsumMean_endc_out << e_.cellPos_[ring][50].eta() << " " << etsumMean_endc_[ring] << endl; - } - etsumMean_endc_out.close(); - - // determine barrel calibration constants - for (int ieta = 0; ieta < kBarlRings; ieta++) { - for (int iphi = 0; iphi < kBarlWedges; iphi++) { - for (int sign = 0; sign < kSides; sign++) { - if (e_.goodCell_barl[ieta][iphi][sign]) { - float etsum = etsum_barl_[ieta][iphi][sign]; - float epsilon_T = (etsum / etsumMean_barl_[ieta]) - 1.; - rawconst_barl[ieta][iphi][sign] = epsilon_T + 1.; - epsilon_M_barl[ieta][iphi][sign] = epsilon_T / k_barl_[ieta]; - } else { - rawconst_barl[ieta][iphi][sign] = 1.; - epsilon_M_barl[ieta][iphi][sign] = 0.; - } //if - } //sign - } //iphi - } //ieta - - // determine endcap calibration constants - for (int ix = 0; ix < kEndcWedgesX; ix++) { - for (int iy = 0; iy < kEndcWedgesY; iy++) { - for (int sign = 0; sign < kSides; sign++) { - int ring = e_.endcapRing_[ix][iy]; - if (ring != -1 && e_.goodCell_endc[ix][iy][sign]) { - float etsum = etsum_endc_[ix][iy][sign]; - float epsilon_T = (etsum / etsumMean_endc_[ring]) - 1.; - rawconst_endc[ix][iy][sign] = epsilon_T + 1.; - epsilon_M_endc[ix][iy][sign] = epsilon_T / k_endc_[ring]; - } else { - epsilon_M_endc[ix][iy][0] = 0.; - epsilon_M_endc[ix][iy][1] = 0.; - rawconst_endc[ix][iy][0] = 1.; - rawconst_endc[ix][iy][1] = 1.; - } //if - } //sign - } //iy - } //ix - - std::string newcalibfile("EcalIntercalibConstants_new.xml"); - - TFile ehistof("ehistos.root", "recreate"); - - TH1D ebhisto("eb", "eb", 100, 0., 2.); - - std::vector::const_iterator barrelIt = barrelCells.begin(); - for (; barrelIt != barrelCells.end(); barrelIt++) { - EBDetId eb(*barrelIt); - int ieta = abs(eb.ieta()) - 1; - int iphi = eb.iphi() - 1; - int sign = eb.zside() > 0 ? 1 : 0; - - /// this is the new constant, or better, the correction to be applied - /// to the old constant - newCalibs_[eb] = oldCalibs_[eb] / (1 + epsilon_M_barl[ieta][iphi][sign]); - - if (e_.goodCell_barl[ieta][iphi][sign]) { - ebhisto.Fill(newCalibs_[eb]); - - /// residual miscalibraition / expected precision - miscal_resid_barl_histos[ieta]->Fill(miscalib_[eb] * newCalibs_[eb]); - correl_barl_histos[ieta]->Fill(miscalib_[eb], newCalibs_[eb]); - } - - } // barrelit - - TH1D eehisto("ee", "ee", 100, 0., 2.); - std::vector::const_iterator endcapIt = endcapCells.begin(); - - for (; endcapIt != endcapCells.end(); endcapIt++) { - EEDetId ee(*endcapIt); - int ix = ee.ix() - 1; - int iy = ee.iy() - 1; - int sign = ee.zside() > 0 ? 1 : 0; - - newCalibs_[ee] = oldCalibs_[ee] / (1 + epsilon_M_endc[ix][iy][sign]); - - if (e_.goodCell_endc[ix][iy][sign]) { - eehisto.Fill(newCalibs_[ee]); - miscal_resid_endc_histos[e_.endcapRing_[ix][iy]]->Fill(miscalib_[ee] * newCalibs_[ee]); - ; - - correl_endc_histos[e_.endcapRing_[ix][iy]]->Fill(miscalib_[ee], newCalibs_[ee]); - } - } //endcapit - // Write xml file - EcalCondHeader header; - header.method_ = "phi symmetry"; - header.version_ = "0"; - header.datasource_ = "testdata"; - header.since_ = 1; - header.tag_ = "unknown"; - header.date_ = "Mar 24 1973"; - - EcalIntercalibConstantsXMLTranslator::writeXML(newcalibfile, header, newCalibs_); - - eehisto.Write(); - ebhisto.Write(); - ehistof.Close(); - - fillConstantsHistos(); - - outResidHistos(); - - // finally output global etsums - std::fstream ebf("etsummary_barl.dat", ios::out); - std::fstream eef("etsummary_endc.dat", ios::out); - - for (int ieta = 0; ieta < kBarlRings; ieta++) { - for (int iphi = 0; iphi < kBarlWedges; iphi++) { - for (int sign = 0; sign < kSides; sign++) { - ebf << ieta << " " << iphi << " " << sign << " " << etsum_barl_[ieta][iphi][sign] << endl; - } - } - } - - for (int ix = 0; ix < kEndcWedgesX; ix++) { - for (int iy = 0; iy < kEndcWedgesY; iy++) { - for (int sign = 0; sign < kSides; sign++) { - eef << ix << " " << iy << " " << sign << " " << etsum_endc_[ix][iy][sign] << endl; - } - } - } -} - -void PhiSymmetryCalibration_step2::fillConstantsHistos() { - TFile f("CalibHistos.root", "recreate"); - - TH2F barreletamap("barreletamap", "barreletamap", 171, -85, 86, 100, 0., 2.); - TH2F barreletamapraw("barreletamapraw", "barreletamapraw", 171, -85, 86, 100, 0., 2.); - - TH2F barrelmapold("barrelmapold", "barrelmapold", 360, 1., 361., 171, -85., 86.); - TH2F barrelmapnew("barrelmapnew", "barrelmapnew", 360, 1., 361., 171, -85., 86.); - TH2F barrelmapratio("barrelmapratio", "barrelmapratio", 360, 1., 361., 171, -85., 86.); - - TH1F rawconst_endc_h("rawconst_endc", "rawconst_endc", 100, 0., 2.); - TH1F const_endc_h("const_endc", "const_endc", 100, 0., 2.); - - TH1F oldconst_endc_h("oldconst_endc", "oldconst_endc;oldCalib;", 200, 0, 2); - TH2F newvsraw_endc_h("newvsraw_endc", "newvsraw_endc;rawConst;newCalib", 200, 0, 2, 200, 0, 2); - - TH2F endcapmapold_plus("endcapmapold_plus", "endcapmapold_plus", 100, 1., 101., 100, 1., 101.); - TH2F endcapmapnew_plus("endcapmapnew_plus", "endcapmapnew_plus", 100, 1., 101., 100, 1., 101.); - TH2F endcapmapratio_plus("endcapmapratio_plus", "endcapmapratio_plus", 100, 1., 101., 100, 1., 101.); - - TH2F endcapmapold_minus("endcapmapold_minus", "endcapmapold_minus", 100, 1., 101., 100, 1., 101.); - TH2F endcapmapnew_minus("endcapmapnew_minus", "endcapmapnew_minus", 100, 1., 101., 100, 1., 101.); - TH2F endcapmapratio_minus("endcapmapratio_minus", "endcapmapratio_minus", 100, 1., 101., 100, 1., 101.); - - for (int sign = 0; sign < kSides; sign++) { - int thesign = sign == 1 ? 1 : -1; - - for (int ieta = 0; ieta < kBarlRings; ieta++) { - for (int iphi = 0; iphi < kBarlWedges; iphi++) { - if (e_.goodCell_barl[ieta][iphi][sign]) { - EBDetId eb(thesign * (ieta + 1), iphi + 1); - //int mod20= (iphi+1)%20; - //if (mod20==0 || mod20==1 ||mod20==2) continue; // exclude SM boundaries - barreletamap.Fill(ieta * thesign + thesign, newCalibs_[eb]); - barreletamapraw.Fill(ieta * thesign + thesign, rawconst_barl[ieta][iphi][sign]); - - barrelmapold.Fill(iphi + 1, ieta * thesign + thesign, oldCalibs_[eb]); - barrelmapnew.Fill(iphi + 1, ieta * thesign + thesign, newCalibs_[eb]); - barrelmapratio.Fill(iphi + 1, ieta * thesign + thesign, newCalibs_[eb] / oldCalibs_[eb]); - } //if - } //iphi - } //ieta - - for (int ix = 0; ix < kEndcWedgesX; ix++) { - for (int iy = 0; iy < kEndcWedgesY; iy++) { - if (e_.goodCell_endc[ix][iy][sign]) { - if (!EEDetId::validDetId(ix + 1, iy + 1, thesign)) - continue; - EEDetId ee(ix + 1, iy + 1, thesign); - - rawconst_endc_h.Fill(rawconst_endc[ix][iy][sign]); - const_endc_h.Fill(newCalibs_[ee]); - oldconst_endc_h.Fill(oldCalibs_[ee]); - newvsraw_endc_h.Fill(rawconst_endc[ix][iy][sign], newCalibs_[ee]); - - if (sign == 1) { - endcapmapold_plus.Fill(ix + 1, iy + 1, oldCalibs_[ee]); - endcapmapnew_plus.Fill(ix + 1, iy + 1, newCalibs_[ee]); - endcapmapratio_plus.Fill(ix + 1, iy + 1, newCalibs_[ee] / oldCalibs_[ee]); - } else { - endcapmapold_minus.Fill(ix + 1, iy + 1, oldCalibs_[ee]); - endcapmapnew_minus.Fill(ix + 1, iy + 1, newCalibs_[ee]); - endcapmapratio_minus.Fill(ix + 1, iy + 1, newCalibs_[ee] / oldCalibs_[ee]); - } - - } //if - } //iy - } //ix - - } // sides - - barreletamap.Write(); - barreletamapraw.Write(); - rawconst_endc_h.Write(); - const_endc_h.Write(); - oldconst_endc_h.Write(); - newvsraw_endc_h.Write(); - barrelmapold.Write(); - barrelmapnew.Write(); - barrelmapratio.Write(); - endcapmapold_plus.Write(); - endcapmapnew_plus.Write(); - endcapmapratio_plus.Write(); - endcapmapold_minus.Write(); - endcapmapnew_minus.Write(); - endcapmapratio_minus.Write(); - - f.Close(); -} - -//_____________________________________________________________________________ - -void PhiSymmetryCalibration_step2::fillHistos() { - TFile f("PhiSymmetryCalibration.root", "recreate"); - - std::vector etsum_barl_histos(kBarlRings); - std::vector esum_barl_histos(kBarlRings); - - // determine ranges of ET sums to get histo bounds and book histos (barrel) - for (int ieta = 0; ieta < kBarlRings; ieta++) { - float low = 999999.; - float high = 0.; - float low_e = 999999.; - float high_e = 0.; - - for (int iphi = 0; iphi < kBarlWedges; iphi++) { - for (int sign = 0; sign < kSides; sign++) { - float etsum = etsum_barl_[ieta][iphi][sign]; - if (etsum < low && etsum != 0.) - low = etsum; - if (etsum > high) - high = etsum; - - float esum = esum_barl_[ieta][iphi][sign]; - if (esum < low_e && esum != 0.) - low_e = esum; - if (esum > high_e) - high_e = esum; - } - } - - ostringstream t; - t << "etsum_barl_" << ieta + 1; - etsum_barl_histos[ieta] = new TH1F(t.str().c_str(), "", 50, low - .2 * low, high + .1 * high); - t.str(""); - - t << "esum_barl_" << ieta + 1; - esum_barl_histos[ieta] = new TH1F(t.str().c_str(), "", 50, low_e - .2 * low_e, high_e + .1 * high_e); - t.str(""); - - // fill barrel ET sum histos - etsumMean_barl_[ieta] = 0.; - esumMean_barl_[ieta] = 0.; - for (int iphi = 0; iphi < kBarlWedges; iphi++) { - for (int sign = 0; sign < kSides; sign++) { - if (e_.goodCell_barl[ieta][iphi][sign]) { - float etsum = etsum_barl_[ieta][iphi][sign]; - float esum = esum_barl_[ieta][iphi][sign]; - etsum_barl_histos[ieta]->Fill(etsum); - esum_barl_histos[ieta]->Fill(esum); - etsumMean_barl_[ieta] += etsum; - esumMean_barl_[ieta] += esum; - } - } - } - - etsum_barl_histos[ieta]->Write(); - esum_barl_histos[ieta]->Write(); - etsumMean_barl_[ieta] /= (720. - e_.nBads_barl[ieta]); - esumMean_barl_[ieta] /= (720. - e_.nBads_barl[ieta]); - delete etsum_barl_histos[ieta]; - delete esum_barl_histos[ieta]; //VS - } - - std::vector etsum_endc_histos(kEndcEtaRings); - std::vector etsum_endc_uncorr_histos(kEndcEtaRings); - std::vector esum_endc_histos(kEndcEtaRings); - - std::vector etsumvsarea_endc_histos(kEndcEtaRings); - std::vector esumvsarea_endc_histos(kEndcEtaRings); - - // determine ranges of ET sums to get histo bounds and book histos (endcap) - for (int ring = 0; ring < kEndcEtaRings; ring++) { - float low = FLT_MAX; - float low_uncorr = FLT_MAX; - float high = 0.; - float high_uncorr = 0; - float low_e = FLT_MAX; - float high_e = 0.; - float low_a = 1.; - float high_a = 0.; - for (int ix = 0; ix < kEndcWedgesX; ix++) { - for (int iy = 0; iy < kEndcWedgesY; iy++) { - if (e_.endcapRing_[ix][iy] == ring) { - for (int sign = 0; sign < kSides; sign++) { - float etsum = etsum_endc_[ix][iy][sign]; - if (etsum < low && etsum != 0.) - low = etsum; - if (etsum > high) - high = etsum; - - float etsum_uncorr = etsum_endc_uncorr[ix][iy][sign]; - if (etsum_uncorr < low_uncorr && etsum_uncorr != 0.) - low_uncorr = etsum_uncorr; - if (etsum_uncorr > high_uncorr) - high_uncorr = etsum_uncorr; - - float esum = esum_endc_[ix][iy][sign]; - if (esum < low_e && esum != 0.) - low_e = esum; - if (esum > high_e) - high_e = esum; - - float area = e_.cellArea_[ix][iy]; - if (area < low_a) - low_a = area; - if (area > high_a) - high_a = area; - } - } - } - } - - ostringstream t; - t << "etsum_endc_" << ring + 1; - etsum_endc_histos[ring] = new TH1F(t.str().c_str(), "", 50, low - .2 * low, high + .1 * high); - t.str(""); - - t << "etsum_endc_uncorr_" << ring + 1; - etsum_endc_uncorr_histos[ring] = - new TH1F(t.str().c_str(), "", 50, low_uncorr - .2 * low_uncorr, high_uncorr + .1 * high_uncorr); - t.str(""); - - t << "esum_endc_" << ring + 1; - esum_endc_histos[ring] = new TH1F(t.str().c_str(), "", 50, low_e - .2 * low_e, high_e + .1 * high_e); - t.str(""); - - t << "etsumvsarea_endc_" << ring + 1; - etsumvsarea_endc_histos[ring] = - new TH2F(t.str().c_str(), ";A_{#eta#phi};#Sigma E_{T}", 50, low_a, high_a, 50, low, high); - t.str(""); - - t << "esumvsarea_endc_" << ring + 1; - esumvsarea_endc_histos[ring] = - new TH2F(t.str().c_str(), ";A_{#eta#phi};#Sigma E", 50, low_a, high_a, 50, low_e, high_e); - t.str(""); - - // fill endcap ET sum histos - etsumMean_endc_[ring] = 0.; - esumMean_endc_[ring] = 0.; - for (int ix = 0; ix < kEndcWedgesX; ix++) { - for (int iy = 0; iy < kEndcWedgesY; iy++) { - if (e_.endcapRing_[ix][iy] == ring) { - for (int sign = 0; sign < kSides; sign++) { - if (e_.goodCell_endc[ix][iy][sign]) { - float etsum = etsum_endc_[ix][iy][sign]; - float esum = esum_endc_[ix][iy][sign]; - float etsum_uncorr = etsum_endc_uncorr[ix][iy][sign]; - etsum_endc_histos[ring]->Fill(etsum); - etsum_endc_uncorr_histos[ring]->Fill(etsum_uncorr); - esum_endc_histos[ring]->Fill(esum); - - float area = e_.cellArea_[ix][iy]; - etsumvsarea_endc_histos[ring]->Fill(area, etsum); - esumvsarea_endc_histos[ring]->Fill(area, esum); - - etsumMean_endc_[ring] += etsum; - esumMean_endc_[ring] += esum; - } - } - } - } - } - - etsum_endc_histos[ring]->Write(); - etsum_endc_uncorr_histos[ring]->Write(); - esum_endc_histos[ring]->Write(); - etsumMean_endc_[ring] /= (float(e_.nRing_[ring] * 2 - e_.nBads_endc[ring])); - esumMean_endc_[ring] /= (float(e_.nRing_[ring] * 2 - e_.nBads_endc[ring])); - etsumvsarea_endc_histos[ring]->Write(); - esumvsarea_endc_histos[ring]->Write(); - - delete etsum_endc_histos[ring]; - delete etsum_endc_uncorr_histos[ring]; - delete esum_endc_histos[ring]; - delete etsumvsarea_endc_histos[ring]; - delete esumvsarea_endc_histos[ring]; - } //ring - - // Maps of etsum in EB and EE - TH2F barreletamap("barreletamap", "barreletamap", 171, -85, 86, 100, 0, 2); - TH2F barrelmap("barrelmap", "barrelmap - #frac{#Sigma E_{T}}{<#Sigma E_{T}>_{0}}", 360, 1, 360, 171, -85, 86); - TH2F barrelmap_e("barrelmape", "barrelmape - #frac{#Sigma E}{<#Sigma E>_{0}}", 360, 1, 360, 171, -85, 86); - TH2F barrelmap_divided("barrelmapdiv", "barrelmapdivided - #frac{#Sigma E_{T}}{hits}", 360, 1, 360, 171, -85, 86); - TH2F barrelmap_e_divided("barrelmapediv", "barrelmapedivided - #frac{#Sigma E}{hits}", 360, 1, 360, 171, -85, 86); - TH2F endcmap_plus_corr( - "endcapmapplus_corrected", "endcapmapplus - #frac{#Sigma E_{T}}{<#Sigma E_{T}>_{38}}", 100, 1, 101, 100, 1, 101); - TH2F endcmap_minus_corr( - "endcapmapminus_corrected", "endcapmapminus - #frac{#Sigma E_{T}}{<#Sigma E_{T}>_{38}}", 100, 1, 101, 100, 1, 101); - TH2F endcmap_plus_uncorr("endcapmapplus_uncorrected", - "endcapmapplus_uncor - #frac{#Sigma E_{T}}{<#Sigma E_{T}>_{38}}", - 100, - 1, - 101, - 100, - 1, - 101); - TH2F endcmap_minus_uncorr("endcapmapminus_uncorrected", - "endcapmapminus_uncor - #frac{#Sigma E_{T}}{<#Sigma E_{T}>_{38}}", - 100, - 1, - 101, - 100, - 1, - 101); - TH2F endcmap_e_plus("endcapmapeplus", "endcapmapeplus - #frac{#Sigma E}{<#Sigma E>_{38}}", 100, 1, 101, 100, 1, 101); - TH2F endcmap_e_minus( - "endcapmapeminus", "endcapmapeminus - #frac{#Sigma E}{<#Sigma E>_{38}}", 100, 1, 101, 100, 1, 101); - - for (int sign = 0; sign < kSides; sign++) { - int thesign = sign == 1 ? 1 : -1; - - for (int ieta = 0; ieta < kBarlRings; ieta++) { - for (int iphi = 0; iphi < kBarlWedges; iphi++) { - if (e_.goodCell_barl[ieta][iphi][sign]) { - barrelmap.Fill(iphi + 1, ieta * thesign + thesign, etsum_barl_[ieta][iphi][sign] / etsumMean_barl_[0]); - barrelmap_e.Fill(iphi + 1, ieta * thesign + thesign, esum_barl_[ieta][iphi][sign] / esumMean_barl_[0]); //VS - if (!nhits_barl_[ieta][iphi][sign]) - nhits_barl_[ieta][iphi][sign] = 1; - barrelmap_divided.Fill( - iphi + 1, ieta * thesign + thesign, etsum_barl_[ieta][iphi][sign] / nhits_barl_[ieta][iphi][sign]); - barrelmap_e_divided.Fill( - iphi + 1, ieta * thesign + thesign, esum_barl_[ieta][iphi][sign] / nhits_barl_[ieta][iphi][sign]); //VS - //int mod20= (iphi+1)%20; - //if (mod20==0 || mod20==1 ||mod20==2) continue; // exclude SM boundaries - barreletamap.Fill(ieta * thesign + thesign, etsum_barl_[ieta][iphi][sign] / etsumMean_barl_[0]); - } //if - } //iphi - } //ieta - - for (int ix = 0; ix < kEndcWedgesX; ix++) { - for (int iy = 0; iy < kEndcWedgesY; iy++) { - if (sign == 1) { - endcmap_plus_corr.Fill(ix + 1, iy + 1, etsum_endc_[ix][iy][sign] / etsumMean_endc_[38]); - endcmap_plus_uncorr.Fill(ix + 1, iy + 1, etsum_endc_uncorr[ix][iy][sign] / etsumMean_endc_[38]); - endcmap_e_plus.Fill(ix + 1, iy + 1, esum_endc_[ix][iy][sign] / esumMean_endc_[38]); - } else { - endcmap_minus_corr.Fill(ix + 1, iy + 1, etsum_endc_[ix][iy][sign] / etsumMean_endc_[38]); - endcmap_minus_uncorr.Fill(ix + 1, iy + 1, etsum_endc_uncorr[ix][iy][sign] / etsumMean_endc_[38]); - endcmap_e_minus.Fill(ix + 1, iy + 1, esum_endc_[ix][iy][sign] / esumMean_endc_[38]); - } - } //iy - } //ix - - } //sign - - barreletamap.Write(); - barrelmap_divided.Write(); - barrelmap.Write(); - barrelmap_e_divided.Write(); - barrelmap_e.Write(); - endcmap_plus_corr.Write(); - endcmap_minus_corr.Write(); - endcmap_plus_uncorr.Write(); - endcmap_minus_uncorr.Write(); - endcmap_e_plus.Write(); - endcmap_e_minus.Write(); - - vector etavsphi_endc(kEndcEtaRings); - vector areavsphi_endc(kEndcEtaRings); - vector etsumvsphi_endcp_corr(kEndcEtaRings); - vector etsumvsphi_endcm_corr(kEndcEtaRings); - vector etsumvsphi_endcp_uncorr(kEndcEtaRings); - vector etsumvsphi_endcm_uncorr(kEndcEtaRings); - vector esumvsphi_endcp(kEndcEtaRings); - vector esumvsphi_endcm(kEndcEtaRings); - - std::vector deltaeta_histos(kEndcEtaRings); - std::vector deltaphi_histos(kEndcEtaRings); - - for (int ring = 0; ring < kEndcEtaRings; ++ring) { - ostringstream t; - t << "etavsphi_endc_" << ring; - etavsphi_endc[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]); - t.str(""); - - t << "areavsphi_endc_" << ring; - areavsphi_endc[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]); - t.str(""); - - t << "etsumvsphi_endcp_corr_" << ring; - etsumvsphi_endcp_corr[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]); - t.str(""); - - t << "etsumvsphi_endcm_corr_" << ring; - etsumvsphi_endcm_corr[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]); - t.str(""); - - t << "etsumvsphi_endcp_uncorr_" << ring; - etsumvsphi_endcp_uncorr[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]); - t.str(""); - - t << "etsumvsphi_endcm_uncorr_" << ring; - etsumvsphi_endcm_uncorr[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]); - t.str(""); - - t << "esumvsphi_endcp_" << ring; - esumvsphi_endcp[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]); - t.str(""); - - t << "esumvsphi_endcm_" << ring; - esumvsphi_endcm[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]); - t.str(""); - - t << "deltaeta_" << ring; - deltaeta_histos[ring] = new TH1F(t.str().c_str(), "", 50, -.1, .1); - t.str(""); - t << "deltaphi_" << ring; - deltaphi_histos[ring] = new TH1F(t.str().c_str(), "", 50, -.1, .1); - t.str(""); - } - - for (int ix = 0; ix < kEndcWedgesX; ix++) { - for (int iy = 0; iy < kEndcWedgesY; iy++) { - int ring = e_.endcapRing_[ix][iy]; - if (ring != -1) { - int iphi_endc = -1; - for (int ip = 0; ip < e_.nRing_[ring]; ip++) { - if (e_.cellPhi_[ix][iy] == e_.phi_endc_[ip][ring]) - iphi_endc = ip; - } - - if (iphi_endc != -1) { - for (int sign = 0; sign < kSides; sign++) { - if (e_.goodCell_endc[ix][iy][sign]) { - if (sign == 1) { - etsumvsphi_endcp_corr[ring]->Fill(iphi_endc, etsum_endc_[ix][iy][sign]); - etsumvsphi_endcp_uncorr[ring]->Fill(iphi_endc, etsum_endc_uncorr[ix][iy][sign]); - esumvsphi_endcp[ring]->Fill(iphi_endc, esum_endc_[ix][iy][sign]); - } else { - etsumvsphi_endcm_corr[ring]->Fill(iphi_endc, etsum_endc_[ix][iy][sign]); - etsumvsphi_endcm_uncorr[ring]->Fill(iphi_endc, etsum_endc_uncorr[ix][iy][sign]); - esumvsphi_endcm[ring]->Fill(iphi_endc, esum_endc_[ix][iy][sign]); - } - } //if - } //sign - etavsphi_endc[ring]->Fill(iphi_endc, e_.cellPos_[ix][iy].eta()); - areavsphi_endc[ring]->Fill(iphi_endc, e_.cellArea_[ix][iy]); - } //if iphi_endc - - } //if ring - } //iy - } //ix - - for (int ring = 0; ring < kEndcEtaRings; ++ring) { - etavsphi_endc[ring]->Write(); - areavsphi_endc[ring]->Write(); - etsumvsphi_endcp_corr[ring]->Write(); - etsumvsphi_endcm_corr[ring]->Write(); - etsumvsphi_endcp_uncorr[ring]->Write(); - etsumvsphi_endcm_uncorr[ring]->Write(); - esumvsphi_endcp[ring]->Write(); - esumvsphi_endcm[ring]->Write(); - deltaeta_histos[ring]->Write(); - deltaphi_histos[ring]->Write(); - - delete etsumvsphi_endcp_corr[ring]; - delete etsumvsphi_endcm_corr[ring]; - delete etsumvsphi_endcp_uncorr[ring]; - delete etsumvsphi_endcm_uncorr[ring]; - delete etavsphi_endc[ring]; - delete areavsphi_endc[ring]; - delete esumvsphi_endcp[ring]; - delete esumvsphi_endcm[ring]; - delete deltaeta_histos[ring]; - delete deltaphi_histos[ring]; - } - - f.Close(); -} - -void PhiSymmetryCalibration_step2::readEtSums() { - //read in ET sums - - int ieta, iphi, sign, ix, iy, dummy; - double etsum; - unsigned int nhits; - std::ifstream etsum_barl_in("etsum_barl.dat", ios::in); - while (etsum_barl_in >> dummy >> ieta >> iphi >> sign >> etsum >> nhits) { - etsum_barl_[ieta][iphi][sign] += etsum; - nhits_barl_[ieta][iphi][sign] += nhits; - } - - std::ifstream etsum_endc_in("etsum_endc.dat", ios::in); - while (etsum_endc_in >> dummy >> ix >> iy >> sign >> etsum >> nhits >> dummy) { - etsum_endc_[ix][iy][sign] += etsum; - nhits_endc_[ix][iy][sign] += nhits; - } - - std::ifstream k_barl_in("k_barl.dat", ios::in); - for (int ieta = 0; ieta < kBarlRings; ieta++) { - k_barl_in >> dummy >> k_barl_[ieta]; - } - - std::ifstream k_endc_in("k_endc.dat", ios::in); - for (int ring = 0; ring < kEndcEtaRings; ring++) { - k_endc_in >> dummy >> k_endc_[ring]; - } -} - -void PhiSymmetryCalibration_step2::setupResidHistos() { - miscal_resid_barl_histos.resize(kBarlRings); - correl_barl_histos.resize(kBarlRings); - - for (int ieta = 0; ieta < kBarlRings; ieta++) { - ostringstream t1; - t1 << "mr_barl_" << ieta + 1; - miscal_resid_barl_histos[ieta] = new TH1F(t1.str().c_str(), "", 100, 0., 2.); - ostringstream t2; - t2 << "co_barl_" << ieta + 1; - correl_barl_histos[ieta] = new TH2F(t2.str().c_str(), "", 50, .5, 1.5, 50, .5, 1.5); - } - - miscal_resid_endc_histos.resize(kEndcEtaRings); - correl_endc_histos.resize(kEndcEtaRings); - - for (int ring = 0; ring < kEndcEtaRings; ring++) { - ostringstream t1; - t1 << "mr_endc_" << ring + 1; - miscal_resid_endc_histos[ring] = new TH1F(t1.str().c_str(), "", 100, 0., 2.); - ostringstream t2; - t2 << "co_endc_" << ring + 1; - correl_endc_histos[ring] = new TH2F(t2.str().c_str(), "", 50, .5, 1.5, 50, .5, 1.5); - } -} - -void PhiSymmetryCalibration_step2::outResidHistos() { - // output histograms of residual miscalibrations - TFile f("PhiSymmetryCalibration_miscal_resid.root", "recreate"); - for (int ieta = 0; ieta < 85; ieta++) { - miscal_resid_barl_histos[ieta]->Write(); - correl_barl_histos[ieta]->Write(); - - delete miscal_resid_barl_histos[ieta]; - delete correl_barl_histos[ieta]; - } - - for (int ring = 0; ring < 39; ring++) { - miscal_resid_endc_histos[ring]->Write(); - correl_endc_histos[ring]->Write(); - - delete miscal_resid_endc_histos[ring]; - delete correl_endc_histos[ring]; - } - f.Close(); -} diff --git a/Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration_step2.h b/Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration_step2.h deleted file mode 100644 index bc6de209ed439..0000000000000 --- a/Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration_step2.h +++ /dev/null @@ -1,98 +0,0 @@ -#ifndef Calibration_EcalCalibAlgos_PhiSymmetryCalibration_step2_h -#define Calibration_EcalCalibAlgos_PhiSymmetryCalibration_step2_h - -#include "Calibration/EcalCalibAlgos/interface/EcalGeomPhiSymHelper.h" -#include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h" -#include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h" -#include "Geometry/Records/interface/CaloGeometryRecord.h" -#include "Geometry/CaloGeometry/interface/CaloGeometry.h" -#include "FWCore/Framework/interface/one/EDAnalyzer.h" -#include "FWCore/Framework/interface/EventSetup.h" -#include "FWCore/Framework/interface/ProducerBase.h" -#include "FWCore/Framework/interface/Event.h" - -class TH1F; -class TH2F; - -class PhiSymmetryCalibration_step2 : public edm::one::EDAnalyzer<> { -public: - PhiSymmetryCalibration_step2(const edm::ParameterSet& iConfig); - ~PhiSymmetryCalibration_step2() override; - - void beginJob() override; - void endJob() override; - - void analyze(const edm::Event&, const edm::EventSetup&) override; - - void fillHistos(); - void fillConstantsHistos(); - void setupResidHistos(); - void outResidHistos(); - - void setUp(const edm::EventSetup& setup); - - void readEtSums(); - -private: - const edm::ESGetToken channelStatusToken_; - const edm::ESGetToken geometryToken_; - - // Transverse energy sum arrays - double etsum_barl_[kBarlRings][kBarlWedges][kSides]; - double etsum_endc_[kEndcWedgesX][kEndcWedgesX][kSides]; - double etsum_endc_uncorr[kEndcWedgesX][kEndcWedgesX][kSides]; - double etsumMean_barl_[kBarlRings]; - double etsumMean_endc_[kEndcEtaRings]; - - unsigned int nhits_barl_[kBarlRings][kBarlWedges][kSides]; - unsigned int nhits_endc_[kEndcWedgesX][kEndcWedgesX][kSides]; - - double esum_barl_[kBarlRings][kBarlWedges][kSides]; - double esum_endc_[kEndcWedgesX][kEndcWedgesX][kSides]; - - double esumMean_barl_[kBarlRings]; - double esumMean_endc_[kEndcEtaRings]; - - double k_barl_[kBarlRings]; - double k_endc_[kEndcEtaRings]; - - // calibration const not corrected for k - float rawconst_barl[kBarlRings][kBarlWedges][kSides]; - float rawconst_endc[kEndcWedgesX][kEndcWedgesX][kSides]; - - // calibration constants not multiplied by old ones - float epsilon_M_barl[kBarlRings][kBarlWedges][kSides]; - float epsilon_M_endc[kEndcWedgesX][kEndcWedgesY][kSides]; - - EcalGeomPhiSymHelper e_; - - std::vector barrelCells; - std::vector endcapCells; - - bool firstpass_; - const int statusThreshold_; - - const bool reiteration_; - const std::string oldcalibfile_; - - /// the old calibration constants (when reiterating, the last ones derived) - EcalIntercalibConstants oldCalibs_; - - /// calib constants that we are going to calculate - EcalIntercalibConstants newCalibs_; - - /// initial miscalibration applied if any) - EcalIntercalibConstants miscalib_; - - /// - const bool have_initial_miscalib_; - const std::string initialmiscalibfile_; - - /// res miscalib histos - std::vector miscal_resid_barl_histos; - std::vector correl_barl_histos; - - std::vector miscal_resid_endc_histos; - std::vector correl_endc_histos; -}; -#endif diff --git a/Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration_step2_SM.cc b/Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration_step2_SM.cc deleted file mode 100644 index 412de801b7bf1..0000000000000 --- a/Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration_step2_SM.cc +++ /dev/null @@ -1,863 +0,0 @@ -#include "Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration_step2_SM.h" -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h" -#include "CondTools/Ecal/interface/EcalIntercalibConstantsXMLTranslator.h" -#include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h" - -#include "TH2F.h" - -#include "TH1F.h" -#include "TFile.h" - -#include -#include - -using namespace std; - -PhiSymmetryCalibration_step2_SM::~PhiSymmetryCalibration_step2_SM() {} - -PhiSymmetryCalibration_step2_SM::PhiSymmetryCalibration_step2_SM(const edm::ParameterSet& iConfig) - : channelStatusToken_(esConsumes()), - geometryToken_(esConsumes()), - firstpass_(true), - statusThreshold_(iConfig.getUntrackedParameter("statusThreshold", 0)), - reiteration_(iConfig.getUntrackedParameter("reiteration", false)), - oldcalibfile_(iConfig.getUntrackedParameter("oldcalibfile", "EcalIntercalibConstants.xml")), - have_initial_miscalib_(iConfig.getUntrackedParameter("haveInitialMiscalib", false)), - initialmiscalibfile_(iConfig.getUntrackedParameter("initialmiscalibfile", "InitialMiscalib.xml")) {} - -void PhiSymmetryCalibration_step2_SM::analyze(const edm::Event& ev, const edm::EventSetup& se) { - if (firstpass_) { - setUp(se); - firstpass_ = false; - } -} - -void PhiSymmetryCalibration_step2_SM::setUp(const edm::EventSetup& se) { - const auto& chStatus = se.getData(channelStatusToken_); - - const auto& geometry = se.getData(geometryToken_); - - barrelCells = geometry.getValidDetIds(DetId::Ecal, EcalBarrel); - endcapCells = geometry.getValidDetIds(DetId::Ecal, EcalEndcap); - - e_.setup(&geometry, &chStatus, statusThreshold_); - - for (int sign = 0; sign < kSides; sign++) { - for (int ieta = 0; ieta < kBarlRings; ieta++) { - for (int iphi = 0; iphi < kBarlWedges; iphi++) { - int iphi_r = int(iphi / nscx); - if (!e_.goodCell_barl[ieta][iphi][sign]) { - nBads_barl_SM_[ieta][iphi_r][sign]++; - // std::cout << "N BAD CELL " << nBads_barl_SM_[ieta][iphi_r][sign] << endl; - } - } - } - } - - /// if a miscalibration was applied, load it, if not put it to 1 - if (have_initial_miscalib_) { - EcalCondHeader h; - namespace fs = std::filesystem; - fs::path p(initialmiscalibfile_.c_str()); - if (!fs::exists(p)) - edm::LogError("PhiSym") << "File not found: " << initialmiscalibfile_ << endl; - - int ret = EcalIntercalibConstantsXMLTranslator::readXML(initialmiscalibfile_, h, miscalib_); - if (ret) - edm::LogError("PhiSym") << "Error reading XML files" << endl; - } else { - for (vector::iterator it = barrelCells.begin(); it != barrelCells.end(); ++it) { - miscalib_[*it] = 1; - } - - for (vector::iterator it = endcapCells.begin(); it != endcapCells.end(); ++it) { - miscalib_[*it] = 1; - } - } - - // if we are reiterating, read constants from previous iter - // if not put them to one - if (reiteration_) { - EcalCondHeader h; - namespace fs = std::filesystem; - fs::path p(oldcalibfile_.c_str()); - if (!fs::exists(p)) - edm::LogError("PhiSym") << "File not found: " << oldcalibfile_ << endl; - - int ret = EcalIntercalibConstantsXMLTranslator::readXML(oldcalibfile_, h, oldCalibs_); - - if (ret) - edm::LogError("PhiSym") << "Error reading XML files" << endl; - ; - - } else { - for (vector::iterator it = barrelCells.begin(); it != barrelCells.end(); ++it) - oldCalibs_[*it] = 1; - - for (vector::iterator it = endcapCells.begin(); it != endcapCells.end(); ++it) - oldCalibs_[*it] = 1; - - } // else -} - -void PhiSymmetryCalibration_step2_SM::beginJob() { - for (int ieta = 0; ieta < kBarlRings; ieta++) { - for (int iphi = 0; iphi < kBarlWedges; iphi++) { - for (int sign = 0; sign < kSides; sign++) { - int iphi_r = int(iphi / nscx); - - etsum_barl_[ieta][iphi][sign] = 0.; - nhits_barl_[ieta][iphi][sign] = 0; - esum_barl_[ieta][iphi][sign] = 0.; - etsum_barl_SM_[ieta][iphi_r][sign] = 0; - nBads_barl_SM_[ieta][iphi_r][sign] = 0; - epsilon_M_barl_SM_[ieta][iphi_r][sign] = 0; - } - } - etsumMean_barl_SM_[ieta] = 0.; - } - - for (int ix = 0; ix < kEndcWedgesX; ix++) { - for (int iy = 0; iy < kEndcWedgesY; iy++) { - for (int sign = 0; sign < kSides; sign++) { - etsum_endc_[ix][iy][sign] = 0.; - nhits_endc_[ix][iy][sign] = 0; - esum_endc_[ix][iy][sign] = 0.; - } - } - } - - readEtSums(); - setupResidHistos(); -} - -void PhiSymmetryCalibration_step2_SM::endJob() { - if (firstpass_) { - edm::LogError("PhiSym") << "Must process at least one event-Exiting" << endl; - return; - } - - // Here the real calculation of constants happens - - // perform the area correction for endcap etsum - // NOT USED ANYMORE - - /* - for (int ix=0; ix0){ - // std::cout << "ETSUM" << etsum_barl_SM_[ieta][iphi_r][sign] << " " <::const_iterator barrelIt = barrelCells.begin(); - for (; barrelIt != barrelCells.end(); barrelIt++) { - EBDetId eb(*barrelIt); - int ieta = abs(eb.ieta()) - 1; - int iphi = eb.iphi() - 1; - int sign = eb.zside() > 0 ? 1 : 0; - - /// this is the new constant, or better, the correction to be applied - /// to the old constant - newCalibs_[eb] = oldCalibs_[eb] / (1 + epsilon_M_barl[ieta][iphi][sign]); - - if (e_.goodCell_barl[ieta][iphi][sign]) { - ebhisto.Fill(newCalibs_[eb]); - - /// residual miscalibraition / expected precision - miscal_resid_barl_histos[ieta]->Fill(miscalib_[eb] * newCalibs_[eb]); - correl_barl_histos[ieta]->Fill(miscalib_[eb], newCalibs_[eb]); - } - - } // barrelit - - TH1D eehisto("ee", "ee", 100, 0., 2.); - std::vector::const_iterator endcapIt = endcapCells.begin(); - - for (; endcapIt != endcapCells.end(); endcapIt++) { - EEDetId ee(*endcapIt); - int ix = ee.ix() - 1; - int iy = ee.iy() - 1; - int sign = ee.zside() > 0 ? 1 : 0; - - newCalibs_[ee] = oldCalibs_[ee] / (1 + epsilon_M_endc[ix][iy][sign]); - - if (e_.goodCell_endc[ix][iy][sign]) { - eehisto.Fill(newCalibs_[ee]); - miscal_resid_endc_histos[e_.endcapRing_[ix][iy]]->Fill(miscalib_[ee] * newCalibs_[ee]); - ; - - correl_endc_histos[e_.endcapRing_[ix][iy]]->Fill(miscalib_[ee], newCalibs_[ee]); - } - } //endcapit - // Write xml file - EcalCondHeader header; - header.method_ = "phi symmetry"; - header.version_ = "0"; - header.datasource_ = "testdata"; - header.since_ = 1; - header.tag_ = "unknown"; - header.date_ = "Mar 24 1973"; - - EcalIntercalibConstantsXMLTranslator::writeXML(newcalibfile, header, newCalibs_); - - eehisto.Write(); - ebhisto.Write(); - ehistof.Close(); - - fillConstantsHistos(); - - outResidHistos(); -} - -void PhiSymmetryCalibration_step2_SM::fillConstantsHistos() { - TFile f("CalibHistos.root", "recreate"); - - TH2F barreletamap("barreletamap", "barreletamap", 171, -85, 86, 100, 0., 2.); - TH2F barreletamapraw("barreletamapraw", "barreletamapraw", 171, -85, 86, 100, 0., 2.); - - TH2F barrelmapold("barrelmapold", "barrelmapold", 360, 1., 361., 171, -85., 86.); - TH2F barrelmapnew("barrelmapnew", "barrelmapnew", 360, 1., 361., 171, -85., 86.); - TH2F barrelmapratio("barrelmapratio", "barrelmapratio", 360, 1., 361., 171, -85., 86.); - - TH1F rawconst_endc_h("rawconst_endc", "rawconst_endc", 100, 0., 2.); - TH1F const_endc_h("const_endc", "const_endc", 100, 0., 2.); - - TH1F oldconst_endc_h("oldconst_endc", "oldconst_endc;oldCalib;", 200, 0, 2); - TH2F newvsraw_endc_h("newvsraw_endc", "newvsraw_endc;rawConst;newCalib", 200, 0, 2, 200, 0, 2); - - TH2F endcapmapold_plus("endcapmapold_plus", "endcapmapold_plus", 100, 1., 101., 100, 1., 101.); - TH2F endcapmapnew_plus("endcapmapnew_plus", "endcapmapnew_plus", 100, 1., 101., 100, 1., 101.); - TH2F endcapmapratio_plus("endcapmapratio_plus", "endcapmapratio_plus", 100, 1., 101., 100, 1., 101.); - - TH2F endcapmapold_minus("endcapmapold_minus", "endcapmapold_minus", 100, 1., 101., 100, 1., 101.); - TH2F endcapmapnew_minus("endcapmapnew_minus", "endcapmapnew_minus", 100, 1., 101., 100, 1., 101.); - TH2F endcapmapratio_minus("endcapmapratio_minus", "endcapmapratio_minus", 100, 1., 101., 100, 1., 101.); - - for (int sign = 0; sign < kSides; sign++) { - int thesign = sign == 1 ? 1 : -1; - - for (int ieta = 0; ieta < kBarlRings; ieta++) { - for (int iphi = 0; iphi < kBarlWedges; iphi++) { - if (e_.goodCell_barl[ieta][iphi][sign]) { - EBDetId eb(thesign * (ieta + 1), iphi + 1); - //int mod20= (iphi+1)%20; - //if (mod20==0 || mod20==1 ||mod20==2) continue; // exclude SM boundaries - barreletamap.Fill(ieta * thesign + thesign, newCalibs_[eb]); - barreletamapraw.Fill(ieta * thesign + thesign, rawconst_barl[ieta][iphi][sign]); - - barrelmapold.Fill(iphi + 1, ieta * thesign + thesign, oldCalibs_[eb]); - barrelmapnew.Fill(iphi + 1, ieta * thesign + thesign, newCalibs_[eb]); - barrelmapratio.Fill(iphi + 1, ieta * thesign + thesign, newCalibs_[eb] / oldCalibs_[eb]); - } //if - } //iphi - } //ieta - - for (int ix = 0; ix < kEndcWedgesX; ix++) { - for (int iy = 0; iy < kEndcWedgesY; iy++) { - if (e_.goodCell_endc[ix][iy][sign]) { - if (!EEDetId::validDetId(ix + 1, iy + 1, thesign)) - continue; - EEDetId ee(ix + 1, iy + 1, thesign); - - rawconst_endc_h.Fill(rawconst_endc[ix][iy][sign]); - const_endc_h.Fill(newCalibs_[ee]); - oldconst_endc_h.Fill(oldCalibs_[ee]); - newvsraw_endc_h.Fill(rawconst_endc[ix][iy][sign], newCalibs_[ee]); - - if (sign == 1) { - endcapmapold_plus.Fill(ix + 1, iy + 1, oldCalibs_[ee]); - endcapmapnew_plus.Fill(ix + 1, iy + 1, newCalibs_[ee]); - endcapmapratio_plus.Fill(ix + 1, iy + 1, newCalibs_[ee] / oldCalibs_[ee]); - } else { - endcapmapold_minus.Fill(ix + 1, iy + 1, oldCalibs_[ee]); - endcapmapnew_minus.Fill(ix + 1, iy + 1, newCalibs_[ee]); - endcapmapratio_minus.Fill(ix + 1, iy + 1, newCalibs_[ee] / oldCalibs_[ee]); - } - - } //if - } //iy - } //ix - - } // sides - - barreletamap.Write(); - barreletamapraw.Write(); - rawconst_endc_h.Write(); - const_endc_h.Write(); - oldconst_endc_h.Write(); - newvsraw_endc_h.Write(); - barrelmapold.Write(); - barrelmapnew.Write(); - barrelmapratio.Write(); - endcapmapold_plus.Write(); - endcapmapnew_plus.Write(); - endcapmapratio_plus.Write(); - endcapmapold_minus.Write(); - endcapmapnew_minus.Write(); - endcapmapratio_minus.Write(); - - f.Close(); -} - -//_____________________________________________________________________________ - -void PhiSymmetryCalibration_step2_SM::fillHistos() { - TFile f("PhiSymmetryCalibration.root", "recreate"); - - std::vector etsum_barl_histos(kBarlRings); - std::vector esum_barl_histos(kBarlRings); - - // determine ranges of ET sums to get histo bounds and book histos (barrel) - for (int ieta = 0; ieta < kBarlRings; ieta++) { - float low = 999999.; - float high = 0.; - float low_e = 999999.; - float high_e = 0.; - - for (int iphi = 0; iphi < kBarlWedges; iphi++) { - for (int sign = 0; sign < kSides; sign++) { - float etsum = etsum_barl_[ieta][iphi][sign]; - if (etsum < low && etsum != 0.) - low = etsum; - if (etsum > high) - high = etsum; - - float esum = esum_barl_[ieta][iphi][sign]; - if (esum < low_e && esum != 0.) - low_e = esum; - if (esum > high_e) - high_e = esum; - } - } - - ostringstream t; - t << "etsum_barl_" << ieta + 1; - etsum_barl_histos[ieta] = new TH1F(t.str().c_str(), "", 50, low - .2 * low, high + .1 * high); - t.str(""); - - t << "esum_barl_" << ieta + 1; - esum_barl_histos[ieta] = new TH1F(t.str().c_str(), "", 50, low_e - .2 * low_e, high_e + .1 * high_e); - t.str(""); - - // fill barrel ET sum histos - etsumMean_barl_[ieta] = 0.; - esumMean_barl_[ieta] = 0.; - - for (int iphi = 0; iphi < kBarlWedges; iphi++) { - for (int sign = 0; sign < kSides; sign++) { - // mean for the SC - int iphi_r = int(iphi / nscx); - - if (!(iphi % nscx)) { - // bad channel correction - etsum_barl_SM_[ieta][iphi_r][sign] = - etsum_barl_SM_[ieta][iphi_r][sign] * nscx / (nscx - nBads_barl_SM_[ieta][iphi_r][sign]); - // std::cout << "ETSUM M " << ieta << " " << iphi_r << " " << - // sign << " " << etsum_barl_SM_[ieta][iphi_r][sign] << " " << nBads_barl_SM_[ieta][iphi_r][sign]<< endl; - etsumMean_barl_SM_[ieta] += etsum_barl_SM_[ieta][iphi_r][sign] / (2 * int(kBarlWedges / nscx)); - } - if (e_.goodCell_barl[ieta][iphi][sign]) { - float etsum = etsum_barl_[ieta][iphi][sign]; - float esum = esum_barl_[ieta][iphi][sign]; - etsum_barl_histos[ieta]->Fill(etsum); - esum_barl_histos[ieta]->Fill(esum); - etsumMean_barl_[ieta] += etsum; - - esumMean_barl_[ieta] += esum; - } - } - } - - etsum_barl_histos[ieta]->Write(); - esum_barl_histos[ieta]->Write(); - etsumMean_barl_[ieta] /= (720. - e_.nBads_barl[ieta]); - esumMean_barl_[ieta] /= (720. - e_.nBads_barl[ieta]); - - delete etsum_barl_histos[ieta]; - delete esum_barl_histos[ieta]; //VS - } - - std::vector etsum_endc_histos(kEndcEtaRings); - std::vector etsum_endc_uncorr_histos(kEndcEtaRings); - std::vector esum_endc_histos(kEndcEtaRings); - - std::vector etsumvsarea_endc_histos(kEndcEtaRings); - std::vector esumvsarea_endc_histos(kEndcEtaRings); - - // determine ranges of ET sums to get histo bounds and book histos (endcap) - for (int ring = 0; ring < kEndcEtaRings; ring++) { - float low = FLT_MAX; - float low_uncorr = FLT_MAX; - float high = 0.; - float high_uncorr = 0; - float low_e = FLT_MAX; - float high_e = 0.; - float low_a = 1.; - float high_a = 0.; - for (int ix = 0; ix < kEndcWedgesX; ix++) { - for (int iy = 0; iy < kEndcWedgesY; iy++) { - if (e_.endcapRing_[ix][iy] == ring) { - for (int sign = 0; sign < kSides; sign++) { - float etsum = etsum_endc_[ix][iy][sign]; - if (etsum < low && etsum != 0.) - low = etsum; - if (etsum > high) - high = etsum; - - float etsum_uncorr = etsum_endc_uncorr[ix][iy][sign]; - if (etsum_uncorr < low_uncorr && etsum_uncorr != 0.) - low_uncorr = etsum_uncorr; - if (etsum_uncorr > high_uncorr) - high_uncorr = etsum_uncorr; - - float esum = esum_endc_[ix][iy][sign]; - if (esum < low_e && esum != 0.) - low_e = esum; - if (esum > high_e) - high_e = esum; - - float area = e_.cellArea_[ix][iy]; - if (area < low_a) - low_a = area; - if (area > high_a) - high_a = area; - } - } - } - } - - ostringstream t; - t << "etsum_endc_" << ring + 1; - etsum_endc_histos[ring] = new TH1F(t.str().c_str(), "", 50, low - .2 * low, high + .1 * high); - t.str(""); - - t << "etsum_endc_uncorr_" << ring + 1; - etsum_endc_uncorr_histos[ring] = - new TH1F(t.str().c_str(), "", 50, low_uncorr - .2 * low_uncorr, high_uncorr + .1 * high_uncorr); - t.str(""); - - t << "esum_endc_" << ring + 1; - esum_endc_histos[ring] = new TH1F(t.str().c_str(), "", 50, low_e - .2 * low_e, high_e + .1 * high_e); - t.str(""); - - t << "etsumvsarea_endc_" << ring + 1; - etsumvsarea_endc_histos[ring] = - new TH2F(t.str().c_str(), ";A_{#eta#phi};#Sigma E_{T}", 50, low_a, high_a, 50, low, high); - t.str(""); - - t << "esumvsarea_endc_" << ring + 1; - esumvsarea_endc_histos[ring] = - new TH2F(t.str().c_str(), ";A_{#eta#phi};#Sigma E", 50, low_a, high_a, 50, low_e, high_e); - t.str(""); - - // fill endcap ET sum histos - etsumMean_endc_[ring] = 0.; - esumMean_endc_[ring] = 0.; - for (int ix = 0; ix < kEndcWedgesX; ix++) { - for (int iy = 0; iy < kEndcWedgesY; iy++) { - if (e_.endcapRing_[ix][iy] == ring) { - for (int sign = 0; sign < kSides; sign++) { - if (e_.goodCell_endc[ix][iy][sign]) { - float etsum = etsum_endc_[ix][iy][sign]; - float esum = esum_endc_[ix][iy][sign]; - float etsum_uncorr = etsum_endc_uncorr[ix][iy][sign]; - etsum_endc_histos[ring]->Fill(etsum); - etsum_endc_uncorr_histos[ring]->Fill(etsum_uncorr); - esum_endc_histos[ring]->Fill(esum); - - float area = e_.cellArea_[ix][iy]; - etsumvsarea_endc_histos[ring]->Fill(area, etsum); - esumvsarea_endc_histos[ring]->Fill(area, esum); - - etsumMean_endc_[ring] += etsum; - esumMean_endc_[ring] += esum; - } - } - } - } - } - - etsum_endc_histos[ring]->Write(); - etsum_endc_uncorr_histos[ring]->Write(); - esum_endc_histos[ring]->Write(); - etsumMean_endc_[ring] /= (float(e_.nRing_[ring] * 2 - e_.nBads_endc[ring])); - esumMean_endc_[ring] /= (float(e_.nRing_[ring] * 2 - e_.nBads_endc[ring])); - etsumvsarea_endc_histos[ring]->Write(); - esumvsarea_endc_histos[ring]->Write(); - - delete etsum_endc_histos[ring]; - delete etsum_endc_uncorr_histos[ring]; - delete esum_endc_histos[ring]; - delete etsumvsarea_endc_histos[ring]; - delete esumvsarea_endc_histos[ring]; - } //ring - - // Maps of etsum in EB and EE - TH2F barreletamap("barreletamap", "barreletamap", 171, -85, 86, 100, 0, 2); - TH2F barrelmap("barrelmap", "barrelmap - #frac{#Sigma E_{T}}{<#Sigma E_{T}>_{0}}", 360, 1, 360, 171, -85, 86); - TH2F barrelmap_e("barrelmape", "barrelmape - #frac{#Sigma E}{<#Sigma E>_{0}}", 360, 1, 360, 171, -85, 86); - TH2F barrelmap_divided("barrelmapdiv", "barrelmapdivided - #frac{#Sigma E_{T}}{hits}", 360, 1, 360, 171, -85, 86); - TH2F barrelmap_e_divided("barrelmapediv", "barrelmapedivided - #frac{#Sigma E}{hits}", 360, 1, 360, 171, -85, 86); - TH2F endcmap_plus_corr( - "endcapmapplus_corrected", "endcapmapplus - #frac{#Sigma E_{T}}{<#Sigma E_{T}>_{38}}", 100, 1, 101, 100, 1, 101); - TH2F endcmap_minus_corr( - "endcapmapminus_corrected", "endcapmapminus - #frac{#Sigma E_{T}}{<#Sigma E_{T}>_{38}}", 100, 1, 101, 100, 1, 101); - TH2F endcmap_plus_uncorr("endcapmapplus_uncorrected", - "endcapmapplus_uncor - #frac{#Sigma E_{T}}{<#Sigma E_{T}>_{38}}", - 100, - 1, - 101, - 100, - 1, - 101); - TH2F endcmap_minus_uncorr("endcapmapminus_uncorrected", - "endcapmapminus_uncor - #frac{#Sigma E_{T}}{<#Sigma E_{T}>_{38}}", - 100, - 1, - 101, - 100, - 1, - 101); - TH2F endcmap_e_plus("endcapmapeplus", "endcapmapeplus - #frac{#Sigma E}{<#Sigma E>_{38}}", 100, 1, 101, 100, 1, 101); - TH2F endcmap_e_minus( - "endcapmapeminus", "endcapmapeminus - #frac{#Sigma E}{<#Sigma E>_{38}}", 100, 1, 101, 100, 1, 101); - - for (int sign = 0; sign < kSides; sign++) { - int thesign = sign == 1 ? 1 : -1; - - for (int ieta = 0; ieta < kBarlRings; ieta++) { - for (int iphi = 0; iphi < kBarlWedges; iphi++) { - if (e_.goodCell_barl[ieta][iphi][sign]) { - barrelmap.Fill(iphi + 1, ieta * thesign + thesign, etsum_barl_[ieta][iphi][sign] / etsumMean_barl_[0]); - barrelmap_e.Fill(iphi + 1, ieta * thesign + thesign, esum_barl_[ieta][iphi][sign] / esumMean_barl_[0]); //VS - if (!nhits_barl_[ieta][iphi][sign]) - nhits_barl_[ieta][iphi][sign] = 1; - barrelmap_divided.Fill( - iphi + 1, ieta * thesign + thesign, etsum_barl_[ieta][iphi][sign] / nhits_barl_[ieta][iphi][sign]); - barrelmap_e_divided.Fill( - iphi + 1, ieta * thesign + thesign, esum_barl_[ieta][iphi][sign] / nhits_barl_[ieta][iphi][sign]); //VS - //int mod20= (iphi+1)%20; - //if (mod20==0 || mod20==1 ||mod20==2) continue; // exclude SM boundaries - barreletamap.Fill(ieta * thesign + thesign, etsum_barl_[ieta][iphi][sign] / etsumMean_barl_[0]); - } //if - } //iphi - } //ieta - - for (int ix = 0; ix < kEndcWedgesX; ix++) { - for (int iy = 0; iy < kEndcWedgesY; iy++) { - if (sign == 1) { - endcmap_plus_corr.Fill(ix + 1, iy + 1, etsum_endc_[ix][iy][sign] / etsumMean_endc_[38]); - endcmap_plus_uncorr.Fill(ix + 1, iy + 1, etsum_endc_uncorr[ix][iy][sign] / etsumMean_endc_[38]); - endcmap_e_plus.Fill(ix + 1, iy + 1, esum_endc_[ix][iy][sign] / esumMean_endc_[38]); - } else { - endcmap_minus_corr.Fill(ix + 1, iy + 1, etsum_endc_[ix][iy][sign] / etsumMean_endc_[38]); - endcmap_minus_uncorr.Fill(ix + 1, iy + 1, etsum_endc_uncorr[ix][iy][sign] / etsumMean_endc_[38]); - endcmap_e_minus.Fill(ix + 1, iy + 1, esum_endc_[ix][iy][sign] / esumMean_endc_[38]); - } - } //iy - } //ix - - } //sign - - barreletamap.Write(); - barrelmap_divided.Write(); - barrelmap.Write(); - barrelmap_e_divided.Write(); - barrelmap_e.Write(); - endcmap_plus_corr.Write(); - endcmap_minus_corr.Write(); - endcmap_plus_uncorr.Write(); - endcmap_minus_uncorr.Write(); - endcmap_e_plus.Write(); - endcmap_e_minus.Write(); - - vector etavsphi_endc(kEndcEtaRings); - vector areavsphi_endc(kEndcEtaRings); - vector etsumvsphi_endcp_corr(kEndcEtaRings); - vector etsumvsphi_endcm_corr(kEndcEtaRings); - vector etsumvsphi_endcp_uncorr(kEndcEtaRings); - vector etsumvsphi_endcm_uncorr(kEndcEtaRings); - vector esumvsphi_endcp(kEndcEtaRings); - vector esumvsphi_endcm(kEndcEtaRings); - - std::vector deltaeta_histos(kEndcEtaRings); - std::vector deltaphi_histos(kEndcEtaRings); - - for (int ring = 0; ring < kEndcEtaRings; ++ring) { - ostringstream t; - t << "etavsphi_endc_" << ring; - etavsphi_endc[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]); - t.str(""); - - t << "areavsphi_endc_" << ring; - areavsphi_endc[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]); - t.str(""); - - t << "etsumvsphi_endcp_corr_" << ring; - etsumvsphi_endcp_corr[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]); - t.str(""); - - t << "etsumvsphi_endcm_corr_" << ring; - etsumvsphi_endcm_corr[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]); - t.str(""); - - t << "etsumvsphi_endcp_uncorr_" << ring; - etsumvsphi_endcp_uncorr[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]); - t.str(""); - - t << "etsumvsphi_endcm_uncorr_" << ring; - etsumvsphi_endcm_uncorr[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]); - t.str(""); - - t << "esumvsphi_endcp_" << ring; - esumvsphi_endcp[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]); - t.str(""); - - t << "esumvsphi_endcm_" << ring; - esumvsphi_endcm[ring] = new TH1F(t.str().c_str(), t.str().c_str(), e_.nRing_[ring], 0, e_.nRing_[ring]); - t.str(""); - - t << "deltaeta_" << ring; - deltaeta_histos[ring] = new TH1F(t.str().c_str(), "", 50, -.1, .1); - t.str(""); - t << "deltaphi_" << ring; - deltaphi_histos[ring] = new TH1F(t.str().c_str(), "", 50, -.1, .1); - t.str(""); - } - - for (int ix = 0; ix < kEndcWedgesX; ix++) { - for (int iy = 0; iy < kEndcWedgesY; iy++) { - int ring = e_.endcapRing_[ix][iy]; - if (ring != -1) { - int iphi_endc = -1; - for (int ip = 0; ip < e_.nRing_[ring]; ip++) { - if (e_.cellPhi_[ix][iy] == e_.phi_endc_[ip][ring]) - iphi_endc = ip; - } - - if (iphi_endc != -1) { - for (int sign = 0; sign < kSides; sign++) { - if (e_.goodCell_endc[ix][iy][sign]) { - if (sign == 1) { - etsumvsphi_endcp_corr[ring]->Fill(iphi_endc, etsum_endc_[ix][iy][sign]); - etsumvsphi_endcp_uncorr[ring]->Fill(iphi_endc, etsum_endc_uncorr[ix][iy][sign]); - esumvsphi_endcp[ring]->Fill(iphi_endc, esum_endc_[ix][iy][sign]); - } else { - etsumvsphi_endcm_corr[ring]->Fill(iphi_endc, etsum_endc_[ix][iy][sign]); - etsumvsphi_endcm_uncorr[ring]->Fill(iphi_endc, etsum_endc_uncorr[ix][iy][sign]); - esumvsphi_endcm[ring]->Fill(iphi_endc, esum_endc_[ix][iy][sign]); - } - } //if - } //sign - etavsphi_endc[ring]->Fill(iphi_endc, e_.cellPos_[ix][iy].eta()); - areavsphi_endc[ring]->Fill(iphi_endc, e_.cellArea_[ix][iy]); - } //if iphi_endc - - } //if ring - } //iy - } //ix - - for (int ring = 0; ring < kEndcEtaRings; ++ring) { - etavsphi_endc[ring]->Write(); - areavsphi_endc[ring]->Write(); - etsumvsphi_endcp_corr[ring]->Write(); - etsumvsphi_endcm_corr[ring]->Write(); - etsumvsphi_endcp_uncorr[ring]->Write(); - etsumvsphi_endcm_uncorr[ring]->Write(); - esumvsphi_endcp[ring]->Write(); - esumvsphi_endcm[ring]->Write(); - deltaeta_histos[ring]->Write(); - deltaphi_histos[ring]->Write(); - - delete etsumvsphi_endcp_corr[ring]; - delete etsumvsphi_endcm_corr[ring]; - delete etsumvsphi_endcp_uncorr[ring]; - delete etsumvsphi_endcm_uncorr[ring]; - delete etavsphi_endc[ring]; - delete areavsphi_endc[ring]; - delete esumvsphi_endcp[ring]; - delete esumvsphi_endcm[ring]; - delete deltaeta_histos[ring]; - delete deltaphi_histos[ring]; - } - - f.Close(); -} - -void PhiSymmetryCalibration_step2_SM::readEtSums() { - //read in ET sums - - int ieta, iphi, sign, ix, iy, dummy; - double etsum; - unsigned int nhits; - std::ifstream etsum_barl_in("etsum_barl.dat", ios::in); - while (etsum_barl_in >> dummy >> ieta >> iphi >> sign >> etsum >> nhits) { - etsum_barl_[ieta][iphi][sign] += etsum; - nhits_barl_[ieta][iphi][sign] += nhits; - - // fill etsums for the SM calibration - int iphi_r = int(iphi / nscx); - etsum_barl_SM_[ieta][iphi_r][sign] += etsum; - // etsum*nscx/(nscx- nBads_barl_SM_[ieta][iphi_r][sign]); - // if(nBads_barl_SM_[ieta][iphi_r][sign]>0){ - // std::cout << "ETSUM" << etsum_barl_SM_[ieta][iphi_r][sign] << " " << nscx << " " << nBads_barl_SM_[ieta][iphi_r][sign]<< endl; - // } - } - - std::ifstream etsum_endc_in("etsum_endc.dat", ios::in); - while (etsum_endc_in >> dummy >> ix >> iy >> sign >> etsum >> nhits >> dummy) { - etsum_endc_[ix][iy][sign] += etsum; - nhits_endc_[ix][iy][sign] += nhits; - } - - std::ifstream k_barl_in("k_barl.dat", ios::in); - for (int ieta = 0; ieta < kBarlRings; ieta++) { - k_barl_in >> dummy >> k_barl_[ieta]; - } - - std::ifstream k_endc_in("k_endc.dat", ios::in); - for (int ring = 0; ring < kEndcEtaRings; ring++) { - k_endc_in >> dummy >> k_endc_[ring]; - } -} - -void PhiSymmetryCalibration_step2_SM::setupResidHistos() { - miscal_resid_barl_histos.resize(kBarlRings); - correl_barl_histos.resize(kBarlRings); - - for (int ieta = 0; ieta < kBarlRings; ieta++) { - ostringstream t1; - t1 << "mr_barl_" << ieta + 1; - miscal_resid_barl_histos[ieta] = new TH1F(t1.str().c_str(), "", 100, 0., 2.); - ostringstream t2; - t2 << "co_barl_" << ieta + 1; - correl_barl_histos[ieta] = new TH2F(t2.str().c_str(), "", 50, .5, 1.5, 50, .5, 1.5); - } - - miscal_resid_endc_histos.resize(kEndcEtaRings); - correl_endc_histos.resize(kEndcEtaRings); - - for (int ring = 0; ring < kEndcEtaRings; ring++) { - ostringstream t1; - t1 << "mr_endc_" << ring + 1; - miscal_resid_endc_histos[ring] = new TH1F(t1.str().c_str(), "", 100, 0., 2.); - ostringstream t2; - t2 << "co_endc_" << ring + 1; - correl_endc_histos[ring] = new TH2F(t2.str().c_str(), "", 50, .5, 1.5, 50, .5, 1.5); - } -} - -void PhiSymmetryCalibration_step2_SM::outResidHistos() { - // output histograms of residual miscalibrations - TFile f("PhiSymmetryCalibration_miscal_resid.root", "recreate"); - for (int ieta = 0; ieta < 85; ieta++) { - miscal_resid_barl_histos[ieta]->Write(); - correl_barl_histos[ieta]->Write(); - - delete miscal_resid_barl_histos[ieta]; - delete correl_barl_histos[ieta]; - } - - for (int ring = 0; ring < 39; ring++) { - miscal_resid_endc_histos[ring]->Write(); - correl_endc_histos[ring]->Write(); - - delete miscal_resid_endc_histos[ring]; - delete correl_endc_histos[ring]; - } - f.Close(); -} diff --git a/Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration_step2_SM.h b/Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration_step2_SM.h deleted file mode 100644 index a042821b6c560..0000000000000 --- a/Calibration/EcalCalibAlgos/src/PhiSymmetryCalibration_step2_SM.h +++ /dev/null @@ -1,107 +0,0 @@ -#ifndef Calibration_EcalCalibAlgos_PhiSymmetryCalibration_step2_SM_h -#define Calibration_EcalCalibAlgos_PhiSymmetryCalibration_step2_SM_h - -#include "Calibration/EcalCalibAlgos/interface/EcalGeomPhiSymHelper.h" -#include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h" -#include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h" -#include "Geometry/Records/interface/CaloGeometryRecord.h" -#include "Geometry/CaloGeometry/interface/CaloGeometry.h" -#include "FWCore/Framework/interface/one/EDAnalyzer.h" -#include "FWCore/Framework/interface/EventSetup.h" -#include "FWCore/Framework/interface/ProducerBase.h" -#include "FWCore/Framework/interface/Event.h" - -class TH1F; -class TH2F; - -class PhiSymmetryCalibration_step2_SM : public edm::one::EDAnalyzer<> { -public: - PhiSymmetryCalibration_step2_SM(const edm::ParameterSet& iConfig); - ~PhiSymmetryCalibration_step2_SM() override; - - void beginJob() override; - void endJob() override; - - void analyze(const edm::Event&, const edm::EventSetup&) override; - - void fillHistos(); - void fillConstantsHistos(); - void setupResidHistos(); - void outResidHistos(); - - void setUp(const edm::EventSetup& setup); - - void readEtSums(); - -private: - const edm::ESGetToken channelStatusToken_; - const edm::ESGetToken geometryToken_; - - // Transverse energy sum arrays - double etsum_barl_[kBarlRings][kBarlWedges][kSides]; - - // energy sum for SM calibration - // number of crystals in a "supercrystal" - static const int nscx = 20; - double etsum_barl_SM_[kBarlRings][int(kBarlWedges / nscx)][kSides]; - int nBads_barl_SM_[kBarlRings][int(kBarlWedges / nscx)][kSides]; - double etsumMean_barl_SM_[kBarlRings]; - double epsilon_M_barl_SM_[kBarlRings][int(kBarlWedges / nscx)][kSides]; - - double etsum_endc_[kEndcWedgesX][kEndcWedgesX][kSides]; - double etsum_endc_uncorr[kEndcWedgesX][kEndcWedgesX][kSides]; - double etsumMean_barl_[kBarlRings]; - double etsumMean_endc_[kEndcEtaRings]; - - unsigned int nhits_barl_[kBarlRings][kBarlWedges][kSides]; - unsigned int nhits_endc_[kEndcWedgesX][kEndcWedgesX][kSides]; - - double esum_barl_[kBarlRings][kBarlWedges][kSides]; - double esum_endc_[kEndcWedgesX][kEndcWedgesX][kSides]; - - double esumMean_barl_[kBarlRings]; - double esumMean_endc_[kEndcEtaRings]; - - double k_barl_[kBarlRings]; - double k_endc_[kEndcEtaRings]; - - // calibration const not corrected for k - float rawconst_barl[kBarlRings][kBarlWedges][kSides]; - float rawconst_endc[kEndcWedgesX][kEndcWedgesX][kSides]; - - // calibration constants not multiplied by old ones - float epsilon_M_barl[kBarlRings][kBarlWedges][kSides]; - float epsilon_M_endc[kEndcWedgesX][kEndcWedgesY][kSides]; - - EcalGeomPhiSymHelper e_; - - std::vector barrelCells; - std::vector endcapCells; - - bool firstpass_; - const int statusThreshold_; - - const bool reiteration_; - const std::string oldcalibfile_; - - /// the old calibration constants (when reiterating, the last ones derived) - EcalIntercalibConstants oldCalibs_; - - /// calib constants that we are going to calculate - EcalIntercalibConstants newCalibs_; - - /// initial miscalibration applied if any) - EcalIntercalibConstants miscalib_; - - /// - const bool have_initial_miscalib_; - const std::string initialmiscalibfile_; - - /// res miscalib histos - std::vector miscal_resid_barl_histos; - std::vector correl_barl_histos; - - std::vector miscal_resid_endc_histos; - std::vector correl_endc_histos; -}; -#endif From 6ee4c6a0d3662ff307aae4f5b56aeab33fd21f69 Mon Sep 17 00:00:00 2001 From: Simone Pigazzi Date: Thu, 17 Feb 2022 00:07:54 +0100 Subject: [PATCH 02/13] Add EcalPhiSym workflow for Run3 --- .../EcalCalibAlgos/interface/EcalPhiSymInfo.h | 83 +++ .../interface/EcalPhiSymRecHit.h | 66 ++ .../EcalCalibAlgos/plugins/BuildFile.xml | 18 + .../plugins/EcalPhiSymFlatTableProducers.cc | 19 + .../plugins/EcalPhiSymRecHitProducers.cc | 648 ++++++++++++++++++ .../EcalPhiSymFlatTableProducers_cfi.py | 64 ++ .../python/EcalPhiSymRecHitProducers_cfi.py | 44 ++ .../python/EcalPhiSymRecoSequence_cff.py | 146 ++++ .../EcalCalibAlgos/src/EcalPhiSymRecHit.cc | 76 ++ Calibration/EcalCalibAlgos/src/classes.h | 18 + .../EcalCalibAlgos/src/classes_def.xml | 9 + .../EcalCalibAlgos/test/EcalPhiSymReco_cfg.py | 72 ++ 12 files changed, 1263 insertions(+) create mode 100644 Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h create mode 100644 Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h create mode 100644 Calibration/EcalCalibAlgos/plugins/EcalPhiSymFlatTableProducers.cc create mode 100644 Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc create mode 100644 Calibration/EcalCalibAlgos/python/EcalPhiSymFlatTableProducers_cfi.py create mode 100644 Calibration/EcalCalibAlgos/python/EcalPhiSymRecHitProducers_cfi.py create mode 100644 Calibration/EcalCalibAlgos/python/EcalPhiSymRecoSequence_cff.py create mode 100644 Calibration/EcalCalibAlgos/src/EcalPhiSymRecHit.cc create mode 100644 Calibration/EcalCalibAlgos/src/classes.h create mode 100644 Calibration/EcalCalibAlgos/src/classes_def.xml create mode 100644 Calibration/EcalCalibAlgos/test/EcalPhiSymReco_cfg.py diff --git a/Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h b/Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h new file mode 100644 index 0000000000000..6f8f154d50716 --- /dev/null +++ b/Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h @@ -0,0 +1,83 @@ +#ifndef ECAL_PHISYM_INFO_H +#define ECAL_PHISYM_INFO_H + +/** \class EcalPhiSymRecHit + * + * EcalPhiSym calibration lumi/run based information + * + * Original Author: Simone Pigazzini (2022) + */ + +#include + +class EcalPhiSymInfo +{ +public: + //---ctors--- + EcalPhiSymInfo(): + totHitsEB_(0), + totHitsEE_(0), + nEvents_(0), + nLumis_(0), + fillNumber_(0), + delivLumi_(0), + recLumi_(0) + {} + + EcalPhiSymInfo(uint64_t hitsEB, uint64_t hitsEE, + uint64_t nEvents, uint32_t nLumis, + uint16_t fill, float delivLumi, float recLumi): + totHitsEB_(hitsEB), + totHitsEE_(hitsEE), + nEvents_(nEvents), + nLumis_(nLumis), + fillNumber_(fill), + delivLumi_(delivLumi), + recLumi_(recLumi) + {} + + //---dtor--- + ~EcalPhiSymInfo() {}; + + //---getters--- + inline uint64_t totHits() const {return totHitsEB_+totHitsEE_;}; + inline uint64_t totHitsEB() const {return totHitsEB_;}; + inline uint64_t totHitsEE() const {return totHitsEE_;}; + inline uint32_t nEvents() const {return nEvents_;}; + inline uint16_t nLumis() const {return nLumis_;}; + inline uint16_t fillNumber() const {return fillNumber_;}; + inline float delivLumi() const {return delivLumi_;}; + inline float recLumi() const {return recLumi_;}; + + //---operators--- + EcalPhiSymInfo& operator+=(const EcalPhiSymInfo& rhs) + { + // The class at the moment is designed to + // hold at most data from a single run. + // This implies fillNumber has to be the same, + // unless it was not set, in that case it is 0. + if(fillNumber_!=0 && rhs.fillNumber()!=0) + assert(fillNumber_ == rhs.fillNumber()); + else + fillNumber_ = std::max(fillNumber_, rhs.fillNumber()); + totHitsEB_ += rhs.totHitsEB(); + totHitsEE_ += rhs.totHitsEE(); + nEvents_ += rhs.nEvents(); + nLumis_ += rhs.nLumis(); + delivLumi_ += rhs.delivLumi(); + recLumi_ += rhs.recLumi(); + + return *this; + } + +private: + uint64_t totHitsEB_; + uint64_t totHitsEE_; + uint32_t nEvents_; + uint16_t nLumis_; + uint16_t fillNumber_; + float delivLumi_; + float recLumi_; +}; + +#endif diff --git a/Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h b/Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h new file mode 100644 index 0000000000000..50e2dbabc6e47 --- /dev/null +++ b/Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h @@ -0,0 +1,66 @@ +#ifndef ECAL_PHISYM_RECHIT_H +#define ECAL_PHISYM_RECHIT_H + +/** \class EcalPhiSymRecHit + * + * Dataformat dedicated to Phi Symmetry ecal calibration + * + * Note: SumEt array ordering: + * 0 - central value + * 1<->N/2 - misCalib<1 + * N/2+1<->N - misCalib>1 + * + * Original Author: Simone Pigazzini (2022) + */ + +#include +#include + +#include "DataFormats/DetId/interface/DetId.h" +#include "DataFormats/EcalDetId/interface/EBDetId.h" +#include "DataFormats/EcalDetId/interface/EEDetId.h" +#include "DataFormats/EcalDetId/interface/EcalSubdetector.h" + +class EcalPhiSymRecHit +{ +public: + //---ctors--- + EcalPhiSymRecHit(); + EcalPhiSymRecHit(uint32_t id, unsigned int nMisCalibV, unsigned int status=0); + EcalPhiSymRecHit(uint32_t id, std::vector& etValues, unsigned int status=0); + + //---dtor--- + ~EcalPhiSymRecHit(); + + //---getters--- + inline uint32_t GetRawId() const {return id_;}; + inline unsigned int GetStatusCode() const {return chStatus_;}; + inline uint32_t GetNhits() const {return nHits_;}; + inline unsigned int GetNSumEt() const {return etSum_.size();}; + inline float GetSumEt(int i=0) const {return etSum_[i];}; + inline float GetSumEt2() const {return et2Sum_;}; + inline float GetLCSum() const {return lcSum_;}; + inline float GetLC2Sum() const {return lc2Sum_;}; + + //---utils--- + void AddHit(float* etValues, float laserCorr=0); + void AddHit(std::vector& etValues, float laserCorr=0); + void Reset(); + + //---operators--- + EcalPhiSymRecHit& operator+=(const EcalPhiSymRecHit& rhs); + +private: + + uint32_t id_; + unsigned int chStatus_; + uint32_t nHits_; + std::vector etSum_; + float et2Sum_; + float lcSum_; + float lc2Sum_; +}; + +typedef std::vector EcalPhiSymRecHitCollection; + +#endif diff --git a/Calibration/EcalCalibAlgos/plugins/BuildFile.xml b/Calibration/EcalCalibAlgos/plugins/BuildFile.xml index ed0f6b3dbf292..0ff87c65acf13 100644 --- a/Calibration/EcalCalibAlgos/plugins/BuildFile.xml +++ b/Calibration/EcalCalibAlgos/plugins/BuildFile.xml @@ -1,2 +1,20 @@ + + + + + + + + + + + + + + + + + + diff --git a/Calibration/EcalCalibAlgos/plugins/EcalPhiSymFlatTableProducers.cc b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymFlatTableProducers.cc new file mode 100644 index 0000000000000..def81958ed961 --- /dev/null +++ b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymFlatTableProducers.cc @@ -0,0 +1,19 @@ +#include "PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h" + +#include "Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h" +#include "Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h" + +typedef LumiSimpleFlatTableProducer EcalPhiSymRecHitFlatTableProducerLumi; + +typedef LumiSingletonSimpleFlatTableProducer EcalPhiSymInfoFlatTableProducerLumi; + +typedef RunSimpleFlatTableProducer EcalPhiSymRecHitFlatTableProducerRun; + +typedef RunSingletonSimpleFlatTableProducer EcalPhiSymInfoFlatTableProducerRun; + +#include "FWCore/Framework/interface/MakerMacros.h" +DEFINE_FWK_MODULE(EcalPhiSymRecHitFlatTableProducerLumi); +DEFINE_FWK_MODULE(EcalPhiSymInfoFlatTableProducerLumi); +DEFINE_FWK_MODULE(EcalPhiSymRecHitFlatTableProducerRun); +DEFINE_FWK_MODULE(EcalPhiSymInfoFlatTableProducerRun); + diff --git a/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc new file mode 100644 index 0000000000000..bf596920fb2a7 --- /dev/null +++ b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc @@ -0,0 +1,648 @@ +// -*- C++ -*- +// +// Package: Calibration/EcalCalibAlgos +// Class: EcalPhiSymRecHitProducer +// +// +// Original Author: Simone Pigazzini +// Created: Wed, 16 Mar 2022 15:52:48 GMT +// +// + +#ifndef _ECAL_PHISYM_RECHIT_PRODUCERS_ +#define _ECAL_PHISYM_RECHIT_PRODUCERS_ + +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/global/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/LuminosityBlock.h" +#include "FWCore/Framework/interface/ConsumesCollector.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ServiceRegistry/interface/Service.h" + +#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" +#include "DataFormats/EcalDetId/interface/EBDetId.h" +#include "DataFormats/EcalDetId/interface/EEDetId.h" + +#include "Calibration/Tools/interface/EcalRingCalibrationTools.h" +#include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbService.h" +#include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbRecord.h" + +#include "Geometry/Records/interface/CaloGeometryRecord.h" +#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h" +#include "Geometry/CaloGeometry/interface/CaloCellGeometry.h" +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" + +#include "CondFormats/EcalObjects/interface/EcalChannelStatus.h" +#include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h" +#include "CondFormats/EcalObjects/interface/EcalChannelStatusCode.h" +#include "CondFormats/RunInfo/interface/LHCInfo.h" +#include "CondFormats/DataRecord/interface/LHCInfoRcd.h" + +#include "Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h" +#include "Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h" + +using namespace std; + +//---Wrapper to handle cross-stream data +struct PhiSymCache { + mutable EcalPhiSymInfo ecalLumiInfo; + mutable EcalPhiSymRecHitCollection recHitCollEB; + mutable EcalPhiSymRecHitCollection recHitCollEE; + + void clear() + { + ecalLumiInfo = EcalPhiSymInfo(); + recHitCollEB.clear(); + recHitCollEE.clear(); + } +}; + +//**************************************************************************************** +// - EcalPhiSymRecHitProducerBase: base class implementing the main algorithm +// - EcalPhiSymRecHitProducerLumi: produces reduced collections per LuminosityBlock +// - EcalPhiSymRecHitProducerRun: produces reduced collections per Run +class EcalPhiSymRecHitProducerBase +{ +public: + explicit EcalPhiSymRecHitProducerBase(const edm::ParameterSet& pSet, + edm::ConsumesCollector&& cc); + ~EcalPhiSymRecHitProducerBase() {}; + + //---methods + // job + void initializeJob(); + // event + void processEvent(edm::StreamID stream, + edm::Event const& event, + edm::EventSetup const& setup, + PhiSymCache* cache) const; + // helpers + void initializeStreamCache(PhiSymCache* cache) const; + void initializeGlobalCache(edm::EventSetup const& setup, + edm::ESGetToken const& chStatusToken, + edm::ESGetToken const& geoToken, + std::shared_ptr& cache) const; + void sumCache(PhiSymCache* streamCache, PhiSymCache const* cache) const; + + //---data memebers + // available to derived classes +protected: + mutable std::vector barrelDetIds_; + mutable std::vector endcapDetIds_; + edm::ESGetToken geoToken_; + edm::ESGetToken laserDbToken_; + mutable edm::EDGetTokenT ebToken_; + mutable edm::EDGetTokenT eeToken_; + float etCutEB_; + vector eThresholdsEB_; + float etCutEE_; + vector A_; + vector B_; + float thrEEmod_; + int nMisCalib_; + int nSumEtValues_; + vector misCalibRangeEB_; + float misCalibStepsEB_[11]; + vector misCalibRangeEE_; + float misCalibStepsEE_[11]; + //---geometry + EcalRingCalibrationTools calibRing_; + static const short kNRingsEB = EcalRingCalibrationTools::N_RING_BARREL; + static const short kNRingsEE = EcalRingCalibrationTools::N_RING_ENDCAP; + static const short ringsInOneEE = kNRingsEE/2; + mutable float etCutsEB_[kNRingsEB]; + mutable float etCutsEE_[kNRingsEE]; + mutable float eThresholdsEE_[kNRingsEE]; +}; + +//----------IMPLEMENTATION---------------------------------------------------------------- +EcalPhiSymRecHitProducerBase::EcalPhiSymRecHitProducerBase(const edm::ParameterSet& pSet, + edm::ConsumesCollector&& cc): + geoToken_(cc.esConsumes()), + laserDbToken_(cc.esConsumes()), + ebToken_(cc.consumes(pSet.getParameter("barrelHitCollection"))), + eeToken_(cc.consumes(pSet.getParameter("endcapHitCollection"))), + etCutEB_(pSet.getParameter("etCut_barrel")), + eThresholdsEB_(pSet.getParameter >("eThresholds_barrel")), + etCutEE_(pSet.getParameter("etCut_endcap")), + A_(pSet.getParameter >("A")), + B_(pSet.getParameter >("B")), + thrEEmod_(pSet.getParameter("thrEEmod")), + nMisCalib_(pSet.getParameter("nMisCalib")/2), + nSumEtValues_(nMisCalib_*2+1), + misCalibRangeEB_(pSet.getParameter >("misCalibRangeEB")), + misCalibRangeEE_(pSet.getParameter >("misCalibRangeEE")) +{} + +void EcalPhiSymRecHitProducerBase::initializeJob() +{ + //---set E thresholds, Et cuts and miscalib steps + //---spectrum window: E > thr && Et < cut + //---NOTE: etCutsEE need the geometry, so it is set later in beginLumi + for(int iRing=0; iRing 0; -i -> [1...n/2]; +i -> [n/2+1...n] + int index = iMis > 0 ? iMis+nMisCalib_ : iMis == 0 ? 0 : iMis+nMisCalib_+1; + misCalibStepsEB_[index] = iMis*misCalibStepEB; + misCalibStepsEE_[index] = iMis*misCalibStepEE; + } +} + +void EcalPhiSymRecHitProducerBase::processEvent(edm::StreamID stream, + edm::Event const& event, + edm::EventSetup const& setup, + PhiSymCache* streamCache) const +{ + uint64_t totHitsEB=0; + uint64_t totHitsEE=0; + + //---get recHits collections + auto barrelRecHitsHandle = event.get(ebToken_); + auto endcapRecHitsHandle = event.get(eeToken_); + + //---get the laser corrections + edm::Timestamp evtTimeStamp(event.time().value()); + auto const& laser = setup.getData(laserDbToken_); + + //---get the geometry + auto const& geometry = setup.getData(geoToken_); + auto barrelGeometry = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel); + auto endcapGeometry = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap); + + //---EB--- + for(auto& recHit : barrelRecHitsHandle) + { + float energy = recHit.energy(); + EBDetId ebHit = EBDetId(recHit.id()); + int ring = calibRing_.getRingIndex(ebHit); + //---if recHit energy is below thr even with the highest miscalib skip this recHit + if(energy*misCalibRangeEB_[1] < eThresholdsEB_[ring]) + continue; + float eta=barrelGeometry->getGeometry(ebHit)->getPosition().eta(); + + //---compute et + miscalibration + float etValues[nSumEtValues_]; + //---one can do this in one for loop from -nMis to +nMis but in this way the + //---program is faster + //---NOTE: nMisCalib is half on the value set in the cfg python + etValues[0] = recHit.energy()/cosh(eta); + for(int iMis=-nMisCalib_; iMis<0; ++iMis) + { + //--- 0 -> 0; -i -> [1...n/2]; +i -> [n/2+1...n] + int index = iMis + nMisCalib_ + 1; + etValues[index] = etValues[0]*(1+misCalibStepsEB_[index]); + //---set et to zero if out of range [e_thr, et_thr+1] + if(etValues[index]*cosh(eta) < eThresholdsEB_[ring] || etValues[index] > etCutsEB_[ring]) + etValues[index] = 0; + } + for(int iMis=1; iMis<=nMisCalib_; ++iMis) + { + //--- 0 -> 0; -i -> [1...n/2]; +i -> [n/2+1...n] + int index = iMis + nMisCalib_; + etValues[index] = etValues[0]*(1+misCalibStepsEB_[index]); + //---set et to zero if out of range [e_thr, et_thr+1] + if(etValues[index]*cosh(eta) < eThresholdsEB_[ring] || etValues[index] > etCutsEB_[ring]) + etValues[index] = 0; + } + //---set et to zero if out of range [e_thr, et_thr+1] + if(energy < eThresholdsEB_[ring] || etValues[0] > etCutsEB_[ring]) + etValues[0] = 0; + else + ++totHitsEB; + //---update the rechHit sumEt + streamCache->recHitCollEB.at(ebHit.denseIndex()).AddHit(etValues, + laser.getLaserCorrection(recHit.id(), evtTimeStamp)); + } + + //---EE--- + for(auto& recHit : endcapRecHitsHandle) + { + EEDetId eeHit = EEDetId(recHit.id()); + int ring = calibRing_.getRingIndex(eeHit) - kNRingsEB; + float energy = recHit.energy(); + //---if recHit energy is below thr even with the highest miscalib skip this recHit + if(energy*misCalibRangeEE_[1] < eThresholdsEE_[ring]) + continue; + float eta=endcapGeometry->getGeometry(eeHit)->getPosition().eta(); + + //---compute et + miscalibration + float etValues[nSumEtValues_]; + //---one can do this in one for loop from -nMis to +nMis but in this way the + //---program is faster + //---NOTE: nMisCalib is half on the value set in the cfg python + etValues[0] = recHit.energy()/cosh(eta); + for(int iMis=-nMisCalib_; iMis<0; ++iMis) + { + //--- 0 -> 0; -i -> [1...n/2]; +i -> [n/2+1...n] + int index = iMis + nMisCalib_ + 1; + etValues[index] = etValues[0]*(1+misCalibStepsEE_[index]); + //---set et to zero if out of range [e_thr, et_thr+1] + if(etValues[index]*cosh(eta) < eThresholdsEE_[ring] || etValues[index] > etCutsEE_[ring]) + etValues[index] = 0; + } + for(int iMis=1; iMis<=nMisCalib_; ++iMis) + { + //--- 0 -> 0; -i -> [1...n/2]; +i -> [n/2+1...n] + int index = iMis + nMisCalib_; + etValues[index] = etValues[0]*(1+misCalibStepsEE_[index]); + //---set et to zero if out of range [e_thr, et_thr+1] + if(etValues[index]*cosh(eta) < eThresholdsEE_[ring] || etValues[index] > etCutsEE_[ring]) + etValues[index] = 0; + } + //---set et to zero if out of range [e_thr, et_thr+1] + if(energy < eThresholdsEE_[ring] || etValues[0] > etCutsEE_[ring]) + etValues[0] = 0; + else + ++totHitsEE; + //---update the rechHit sumEt + streamCache->recHitCollEE.at(eeHit.denseIndex()).AddHit(etValues, + laser.getLaserCorrection(recHit.id(), evtTimeStamp)); + } + + //---update the lumi info + EcalPhiSymInfo thisEvent(totHitsEB, totHitsEE, 1, 0, + 0, 0, 0); + streamCache->ecalLumiInfo += thisEvent; +} + +void EcalPhiSymRecHitProducerBase::initializeStreamCache(PhiSymCache* cache) const +{ + //---Initialize the per-stream RecHitCollection + // both collections are initialized to contain the total + // number of crystals, ordered accrodingly to the hashedIndex. + cache->clear(); + cache->recHitCollEB.resize(barrelDetIds_.size()); + cache->recHitCollEE.resize(endcapDetIds_.size()); + for(auto& ebDetId : barrelDetIds_) + { + EBDetId id(ebDetId); + cache->recHitCollEB.at(id.denseIndex()) = + EcalPhiSymRecHit(id.rawId(), nSumEtValues_); + } + for(auto& eeDetId : endcapDetIds_) + { + EEDetId id(eeDetId); + cache->recHitCollEE.at(id.denseIndex()) = + EcalPhiSymRecHit(id.rawId(), nSumEtValues_); + } +} + +void EcalPhiSymRecHitProducerBase::initializeGlobalCache( + edm::EventSetup const& setup, + edm::ESGetToken const& chStatusToken, + edm::ESGetToken const& geoToken, + std::shared_ptr& cache) const +{ + cache->clear(); + + //---get the ecal geometry + auto geometry = &setup.getData(geoToken); + calibRing_.setCaloGeometry(geometry); + + //---get the channels status + auto const& chStatus = setup.getData(chStatusToken); + + auto barrelGeometry = geometry->getSubdetectorGeometry(DetId::Ecal, EcalBarrel); + auto endcapGeometry = geometry->getSubdetectorGeometry(DetId::Ecal, EcalEndcap); + barrelDetIds_ = barrelGeometry->getValidDetIds(DetId::Ecal, EcalBarrel); + endcapDetIds_ = endcapGeometry->getValidDetIds(DetId::Ecal, EcalEndcap); + cache->recHitCollEB.resize(barrelDetIds_.size()); + cache->recHitCollEE.resize(endcapDetIds_.size()); + for(auto& ebDetId : barrelDetIds_) + { + EBDetId id(ebDetId); + ; + cache->recHitCollEB.at(id.denseIndex()) = + EcalPhiSymRecHit(ebDetId.rawId(), nSumEtValues_, chStatus[id].getStatusCode()); + int ring = calibRing_.getRingIndex(id); + //---set etCut if first pass + if(etCutsEB_[ring] == -1 && id.iphi()==1) + { + auto cellGeometry = barrelGeometry->getGeometry(id); + float eta = cellGeometry->getPosition().eta(); + etCutsEB_[ring] = eThresholdsEB_[ring]/cosh(eta) + etCutEB_; + } + } + for(auto& eeDetId : endcapDetIds_) + { + EEDetId id(eeDetId); + int ring = calibRing_.getRingIndex(id) - kNRingsEB; + cache->recHitCollEE.at(id.denseIndex()) = + EcalPhiSymRecHit(eeDetId.rawId(), nSumEtValues_, chStatus[id].getStatusCode()); + //---set eCutEE if first pass + if(ring < ringsInOneEE && etCutsEE_[ring] == -1 && id.ix() == 50) + { + auto cellGeometry = endcapGeometry->getGeometry(id); + etCutsEE_[ring] = eThresholdsEE_[ring]/cosh(cellGeometry->getPosition().eta()) + etCutEE_; + etCutsEE_[ring+ringsInOneEE] = etCutsEE_[ring]; + } + } +} + +void EcalPhiSymRecHitProducerBase::sumCache(PhiSymCache* streamCache, PhiSymCache const* cache) const +{ + //--- this could be improved. + // One has to make sure that the streamCache is the right hand argument + // in the sum to make sure that info like fillNumber and channel status + // are preserved since they are set in the global initialization and not + // in the stream one. + cache->ecalLumiInfo += streamCache->ecalLumiInfo; + + for(unsigned int i=0; irecHitCollEB.size(); ++i) + cache->recHitCollEB.at(i) += streamCache->recHitCollEB.at(i); + for(unsigned int i=0; irecHitCollEE.size(); ++i) + cache->recHitCollEE.at(i) += streamCache->recHitCollEE.at(i); +} + +//**************************************************************************************** +// Lumi producer +class EcalPhiSymRecHitProducerLumi: public edm::global::EDProducer, + edm::LuminosityBlockCache, + edm::EndLuminosityBlockProducer, + edm::Accumulator>, + public EcalPhiSymRecHitProducerBase +{ +public: + explicit EcalPhiSymRecHitProducerLumi(const edm::ParameterSet& pSet); + ~EcalPhiSymRecHitProducerLumi() {}; + +private: + //---methods + // job + void beginJob() { initializeJob(); }; + // lumi + std::shared_ptr globalBeginLuminosityBlock(edm::LuminosityBlock const& lumi, + edm::EventSetup const& setup) const override; + void globalEndLuminosityBlock(edm::LuminosityBlock const& lumi, + edm::EventSetup const& setup) const override {}; + void globalEndLuminosityBlockProduce(edm::LuminosityBlock& lumi, + edm::EventSetup const& setup) const override; + // stream + std::unique_ptr beginStream(edm::StreamID stream) const override; + void streamBeginLuminosityBlock(edm::StreamID stream, + edm::LuminosityBlock const& lumi, + edm::EventSetup const& setup) const override; + void streamEndLuminosityBlock(edm::StreamID stream, + edm::LuminosityBlock const& lumi, + edm::EventSetup const& setup) const override; + + // event + void accumulate(edm::StreamID stream, + edm::Event const& event, + edm::EventSetup const& setup) const; + + // data members + edm::ESGetToken lhcInfoTokenLumi_; + edm::ESGetToken chStatusTokenLumi_; + edm::ESGetToken geoTokenLumi_; +}; + +//----------IMPLEMENTATION---------------------------------------------------------------- +EcalPhiSymRecHitProducerLumi::EcalPhiSymRecHitProducerLumi(const edm::ParameterSet& pSet): + EcalPhiSymRecHitProducerBase(pSet, consumesCollector()), + lhcInfoTokenLumi_(esConsumes()), + chStatusTokenLumi_(esConsumes()), + geoTokenLumi_(esConsumes()) +{ + produces(); + produces("EB"); + produces("EE"); +} + +std::shared_ptr EcalPhiSymRecHitProducerLumi::globalBeginLuminosityBlock( + edm::LuminosityBlock const& lumi, + edm::EventSetup const& setup) const +{ + auto cache = std::make_shared(); + + //---Get LHC info + const auto& lhcinfo = setup.getData(lhcInfoTokenLumi_); + EcalPhiSymInfo thisLumi(0, 0, 0, 1, + lhcinfo.fillNumber(), lhcinfo.delivLumi(), lhcinfo.recLumi()); + + //---Reset global cache + initializeGlobalCache(setup, + chStatusTokenLumi_, + geoTokenLumi_, + cache); + cache->ecalLumiInfo += thisLumi; + + return cache; +} + +std::unique_ptr EcalPhiSymRecHitProducerLumi::beginStream(edm::StreamID stream) const +{ + //---create stream cache + return std::make_unique(); +} + +void EcalPhiSymRecHitProducerLumi::globalEndLuminosityBlockProduce( + edm::LuminosityBlock& lumi, + edm::EventSetup const& setup) const +{ + auto cache = luminosityBlockCache(lumi.index()); + + //---put the collections in the LuminosityBlocks tree + auto ecalLumiInfo = std::make_unique(); + *ecalLumiInfo = cache->ecalLumiInfo; + auto recHitCollEB = std::make_unique(); + *recHitCollEB = cache->recHitCollEB; + auto recHitCollEE = std::make_unique(); + *recHitCollEE = cache->recHitCollEE; + + lumi.put(std::move(ecalLumiInfo)); + lumi.put(std::move(recHitCollEB), "EB"); + lumi.put(std::move(recHitCollEE), "EE"); +} + +void EcalPhiSymRecHitProducerLumi::streamBeginLuminosityBlock( + edm::StreamID stream, + edm::LuminosityBlock const& lumi, + edm::EventSetup const& setup) const +{ + //---Reset cache + initializeStreamCache(streamCache(stream)); +} + +void EcalPhiSymRecHitProducerLumi::streamEndLuminosityBlock( + edm::StreamID stream, + edm::LuminosityBlock const& lumi, + edm::EventSetup const& setup) const +{ + //---sum data from different streams into the common lumi cache + sumCache(streamCache(stream), luminosityBlockCache(lumi.index())); +} + +void EcalPhiSymRecHitProducerLumi::accumulate(edm::StreamID stream, + edm::Event const& event, + edm::EventSetup const& setup) const +{ + processEvent(stream, event, setup, streamCache(stream)); +} + +//**************************************************************************************** +// Run producer +class EcalPhiSymRecHitProducerRun: public edm::global::EDProducer, + edm::RunCache, + edm::LuminosityBlockCache, + edm::EndRunProducer, + edm::Accumulator>, + public EcalPhiSymRecHitProducerBase +{ +public: + explicit EcalPhiSymRecHitProducerRun(const edm::ParameterSet& pSet); + ~EcalPhiSymRecHitProducerRun() {}; + +private: + //---methods + // job + void beginJob() { initializeJob(); }; + // run + std::shared_ptr globalBeginRun(edm::Run const& run, + edm::EventSetup const& setup) const override; + void globalEndRun(edm::Run const& run, + edm::EventSetup const& setup) const override {}; + void globalEndRunProduce(edm::Run& run, + edm::EventSetup const& setup) const override; + // lumi + std::shared_ptr globalBeginLuminosityBlock(edm::LuminosityBlock const& lumi, + edm::EventSetup const& setup) const override; + void globalEndLuminosityBlock(edm::LuminosityBlock const& lumi, + edm::EventSetup const& setup) const override {} ; + // stream + std::unique_ptr beginStream(edm::StreamID stream) const; + void streamBeginRun(edm::StreamID stream, + edm::Run const& run, + edm::EventSetup const& setup) const override; + void streamEndRun(edm::StreamID stream, + edm::Run const& run, + edm::EventSetup const& setup) const override; + // event + void accumulate(edm::StreamID stream, + edm::Event const& event, + edm::EventSetup const& setup) const; + + // data members + edm::ESGetToken lhcInfoTokenLumi_; + edm::ESGetToken chStatusTokenRun_; + edm::ESGetToken geoTokenRun_; +}; + +//----------IMPLEMENTATION---------------------------------------------------------------- +EcalPhiSymRecHitProducerRun::EcalPhiSymRecHitProducerRun(const edm::ParameterSet& pSet): + EcalPhiSymRecHitProducerBase(pSet, consumesCollector()), + lhcInfoTokenLumi_(esConsumes()), + chStatusTokenRun_(esConsumes()), + geoTokenRun_(esConsumes()) +{ + produces(); + produces("EB"); + produces("EE"); +} + +std::shared_ptr EcalPhiSymRecHitProducerRun::globalBeginRun( + edm::Run const& run, + edm::EventSetup const& setup) const +{ + auto cache = std::make_shared(); + initializeGlobalCache(setup, + chStatusTokenRun_, + geoTokenRun_, + cache); + return cache; +} + +//---globalBeginLuminosityBlock is called just to correctly update the LHCInfo +std::shared_ptr EcalPhiSymRecHitProducerRun::globalBeginLuminosityBlock( + edm::LuminosityBlock const& lumi, + edm::EventSetup const& setup) const +{ + //---Get LHC info + // LHCInfo only returns the correct luminosity information + // for each lumisection, accessing LHCInfo at the beginning + // of each run would return only the luminosity info of the + // first LS + const auto& lhcinfo = setup.getData(lhcInfoTokenLumi_); + EcalPhiSymInfo thisLumi(0, 0, 0, 1, + lhcinfo.fillNumber(), lhcinfo.delivLumi(), lhcinfo.recLumi()); + + runCache(lumi.getRun().index())->ecalLumiInfo += thisLumi; + + // dummy cache, it won't be used + return std::make_shared(); +} + +std::unique_ptr EcalPhiSymRecHitProducerRun::beginStream(edm::StreamID stream) const +{ + //---create stream cache + return std::make_unique(); +} + +void EcalPhiSymRecHitProducerRun::streamBeginRun( + edm::StreamID stream, + edm::Run const& run, + edm::EventSetup const& setup) const +{ + //---Reset global cache + initializeStreamCache(streamCache(stream)); +} + +void EcalPhiSymRecHitProducerRun::streamEndRun( + edm::StreamID stream, + edm::Run const& run, + edm::EventSetup const& setup) const +{ + //---sum data from different streams into the common run cache + sumCache(streamCache(stream), runCache(run.index())); +} + +void EcalPhiSymRecHitProducerRun::globalEndRunProduce( + edm::Run& run, + edm::EventSetup const& setup) const +{ + auto cache = runCache(run.index()); + + //---put the collections in the Runs tree + auto ecalLumiInfo = std::make_unique(); + *ecalLumiInfo = cache->ecalLumiInfo; + auto recHitCollEB = std::make_unique(); + *recHitCollEB = cache->recHitCollEB; + auto recHitCollEE = std::make_unique(); + *recHitCollEE = cache->recHitCollEE; + + run.put(std::move(ecalLumiInfo)); + run.put(std::move(recHitCollEB), "EB"); + run.put(std::move(recHitCollEE), "EE"); +} + +void EcalPhiSymRecHitProducerRun::accumulate(edm::StreamID stream, + edm::Event const& event, + edm::EventSetup const& setup) const +{ + processEvent(stream, event, setup, streamCache(stream)); +} + +DEFINE_FWK_MODULE(EcalPhiSymRecHitProducerLumi); +DEFINE_FWK_MODULE(EcalPhiSymRecHitProducerRun); + +#endif diff --git a/Calibration/EcalCalibAlgos/python/EcalPhiSymFlatTableProducers_cfi.py b/Calibration/EcalCalibAlgos/python/EcalPhiSymFlatTableProducers_cfi.py new file mode 100644 index 0000000000000..3eb9910093f48 --- /dev/null +++ b/Calibration/EcalCalibAlgos/python/EcalPhiSymFlatTableProducers_cfi.py @@ -0,0 +1,64 @@ +import FWCore.ParameterSet.Config as cms +from PhysicsTools.NanoAOD.common_cff import * + +# LuminosityBlock flat table producers +ecalPhiSymRecHitLumiTableEB = cms.EDProducer("EcalPhiSymRecHitFlatTableProducerLumi", + src = cms.InputTag("EcalPhiSymRecHitProducerLumi", "EB"), + cut = cms.string(""), + name = cms.string("EcalPhiSymEB"), + doc = cms.string("ECAL RecHits with information summed over a LS"), + variables = cms.PSet( + id = Var("GetRawId()", int, doc="ECAL PhiSym rechits: channel detector id"), + status = Var("GetStatusCode()", int, doc="ECAL PhiSym rechits: channel status"), + nHits = Var("GetNhits()", int, doc="ECAL PhiSym rechits: number of recorded hits"), + sumEt = Var("GetSumEt(0)", float, doc="ECAL PhiSym rechits: nominal et", precision=23), + sumEt2 = Var("GetSumEt2()", float, doc="ECAL PhiSym rechits: sum et^2", precision=23), + sumLC = Var("GetLCSum()", float, doc="ECAL PhiSym rechits: laser correction", precision=23), + sumLC2 = Var("GetLC2Sum()", float, doc="ECAL PhiSym rechits: sum lc^2", precision=23) + ) + ) + +ecalPhiSymRecHitLumiTableEE = ecalPhiSymRecHitLumiTableEB.clone( + src = cms.InputTag("EcalPhiSymRecHitProducerLumi", "EE"), + name = cms.string("EcalPhiSymEE") +) + +ecalPhiSymInfoLumiTable = cms.EDProducer("EcalPhiSymInfoFlatTableProducerLumi", + src = cms.InputTag("EcalPhiSymRecHitProducerLumi"), + cut = cms.string(""), + name = cms.string("EcalPhiSymInfo"), + doc = cms.string("Global phisym info with information summed over one or more LS"), + variables = cms.PSet( + hitsEB = Var("totHitsEB()", int, doc="Total number of rechits in EB"), + hitsEE = Var("totHitsEE()", int, doc="Total number of rechits in EE"), + nEvents = Var("nEvents()", int, doc="Total number of events recorded"), + nLumis = Var("nLumis()", int, doc="Total number of lumis recorded"), + fill = Var("fillNumber()", int, doc="LHC fill number"), + delivLumi = Var("delivLumi()", int, doc="LHC delivered integrated luminosity"), + recLumi = Var("recLumi()", int, doc="CMS recorded integrated luminosity"))) + +# Run flat table producers +ecalPhiSymRecHitRunTableEB = cms.EDProducer("EcalPhiSymRecHitFlatTableProducerRun", + src = cms.InputTag("EcalPhiSymRecHitProducerRun", "EB"), + cut = cms.string(""), + name = cms.string("EcalPhiSymEB"), + doc = cms.string("ECAL RecHits with information summed over a Run"), + variables = cms.PSet() + ) +ecalPhiSymRecHitRunTableEB.variables = ecalPhiSymRecHitLumiTableEB.variables + +ecalPhiSymRecHitRunTableEE = ecalPhiSymRecHitRunTableEB.clone( + src = cms.InputTag("EcalPhiSymRecHitProducerRun", "EE"), + name = cms.string("EcalPhiSymEE") +) + +ecalPhiSymInfoRunTable = cms.EDProducer("EcalPhiSymInfoFlatTableProducerRun", + src = cms.InputTag("EcalPhiSymRecHitProducerRun"), + cut = cms.string(""), + name = cms.string("EcalPhiSymInfo"), + doc = cms.string("Global phisym info with information summed over a run"), + variables = cms.PSet() + ) + +ecalPhiSymInfoRunTable.variables = ecalPhiSymInfoLumiTable.variables + diff --git a/Calibration/EcalCalibAlgos/python/EcalPhiSymRecHitProducers_cfi.py b/Calibration/EcalCalibAlgos/python/EcalPhiSymRecHitProducers_cfi.py new file mode 100644 index 0000000000000..84f0835a13e6c --- /dev/null +++ b/Calibration/EcalCalibAlgos/python/EcalPhiSymRecHitProducers_cfi.py @@ -0,0 +1,44 @@ +import FWCore.ParameterSet.Config as cms + +# - thrEEmod is the value in ADC count that rappresent the "5 sigma noise" threshold +# - A*ring + B is a ad-hoc parametrization of the equivalent noise level, in this way the thr is set in MeV + +phisym_params = { + "barrelHitCollection" : cms.InputTag('ecalRecHit', 'EcalRecHitsEB'), + "endcapHitCollection" : cms.InputTag('ecalRecHit', 'EcalRecHitsEE'), + "eThresholds_barrel" : cms.vdouble( + 1.00751, 1.01408, 1.01886, 1.02209, 1.02395, 1.02462, 1.02426, 1.02301, 1.02099, 1.01832, + 1.01508, 1.01139, 1.00731, 1.00292, 0.998285, 0.993462, 0.988504, 0.983455, 0.978355, 0.973239, + 0.968136, 0.963071, 0.958066, 0.953138, 0.948299, 0.943562, 0.938933, 0.934416, 0.930016, 0.925731, + 0.92156, 0.917501, 0.913549, 0.909699, 0.905944, 0.902278, 0.898694, 0.895184, 0.89174, 0.888355, + 0.885023, 0.881736, 0.878489, 0.875276, 0.872093, 0.868936, 0.865802, 0.862691, 0.859601, 0.856534, + 0.853489, 0.850472, 0.847485, 0.844534, 0.841625, 0.838765, 0.835961, 0.833224, 0.830561, 0.827984, + 0.825503, 0.823129, 0.820872, 0.818743, 0.816752, 0.814909, 0.813222, 0.811699, 0.810346, 0.809167, + 0.808164, 0.807336, 0.80668, 0.806189, 0.805852, 0.805656, 0.805582, 0.805606, 0.8057, 0.805828, + 0.805952, 0.806024, 0.80599, 0.805788, 0.805348, 0.805309, 0.80571, 0.805873, 0.805868, 0.805758, + 0.805595, 0.805427, 0.805295, 0.805232, 0.805267, 0.805424, 0.805722, 0.806174, 0.806791, 0.80758, + 0.808543, 0.809683, 0.810995, 0.812478, 0.814124, 0.815926, 0.817876, 0.819964, 0.822179, 0.824511, + 0.82695, 0.829484, 0.832104, 0.834798, 0.837558, 0.840375, 0.84324, 0.846146, 0.849088, 0.852061, + 0.85506, 0.858082, 0.861126, 0.864191, 0.867278, 0.870389, 0.873525, 0.876691, 0.879891, 0.88313, + 0.886414, 0.889751, 0.893146, 0.896607, 0.900142, 0.903758, 0.907462, 0.911262, 0.915162, 0.91917, + 0.923288, 0.92752, 0.931867, 0.936329, 0.940904, 0.945586, 0.950368, 0.95524, 0.960188, 0.965195, + 0.97024, 0.975298, 0.980339, 0.985329, 0.990229, 0.994993, 0.99957, 1.0039, 1.00792, 1.01156, + 1.01474, 1.01737, 1.01934, 1.02054, 1.02085, 1.02014, 1.01824, 1.01499, 1.01018, 1.00359 + ), + "etCut_barrel" : cms.double(1), #this is actually summed to eThr in order to define the upper bound + "etCut_endcap" : cms.double(1), #this is actually summed to eThr in order to define the upper bound + "A" : cms.vdouble(10, 112.5), # B + A*ring 2016 thr are defined as two linear cut (one for iring<30 and one above) + "B" : cms.vdouble(150, -2925), + "thrEEmod" : cms.double(10.), + "nMisCalib" : cms.int32(10), # <= 10; even; central value does not count + "misCalibRangeEB" : cms.vdouble(0.95, 1.05), + "misCalibRangeEE" : cms.vdouble(0.90, 1.10), +} + +EcalPhiSymRecHitProducerLumi = cms.EDProducer("EcalPhiSymRecHitProducerLumi") +for par, value in phisym_params.items(): + setattr(EcalPhiSymRecHitProducerLumi, par, value) + +EcalPhiSymRecHitProducerRun = cms.EDProducer("EcalPhiSymRecHitProducerRun") +for par, value in phisym_params.items(): + setattr(EcalPhiSymRecHitProducerRun, par, value) diff --git a/Calibration/EcalCalibAlgos/python/EcalPhiSymRecoSequence_cff.py b/Calibration/EcalCalibAlgos/python/EcalPhiSymRecoSequence_cff.py new file mode 100644 index 0000000000000..062405aafe3c2 --- /dev/null +++ b/Calibration/EcalCalibAlgos/python/EcalPhiSymRecoSequence_cff.py @@ -0,0 +1,146 @@ +import FWCore.ParameterSet.Config as cms +from PhysicsTools.NanoAOD.common_cff import * + +def ecal_phisym_workflow(process, + produce_by_run : bool=False, + save_edm : bool=False, + save_edmnano : bool=False, + save_flatnano : bool=True): + """ + Customize the process to include the entire EcalPhiSym workflow: + - ECAL local reco + - PhiSymRecHit producer + - EDM output (standard, EDMNANO, FlatNANO) + """ + + reco = ecal_phisym_reco_sequence(process, produce_by_run=produce_by_run) + tables = ecal_phisym_flattables(process, produce_by_run=produce_by_run) + outputs = ecal_phisym_output(process, + save_edm=save_edm, + save_edmnano=save_edmnano, + save_flatnano=save_flatnano) + + process.path = cms.Path(reco*tables) + process.output_step = cms.EndPath() + for out in outputs: + process.output_step += out + process.schedule = cms.Schedule(process.path, process.output_step) + +def ecal_phisym_reco_sequence(process, produce_by_run : bool=False): + """ + Customize process to include the EcalPhiSym standard reco sequence + """ + + process.load('RecoLuminosity.LumiProducer.bunchSpacingProducer_cfi') + process.load('RecoLocalCalo.EcalRecProducers.ecalMultiFitUncalibRecHit_cfi') + process.load('RecoLocalCalo.EcalRecProducers.ecalUncalibRecHit_cfi') + process.load('RecoLocalCalo.EcalRecProducers.ecalRecHit_cfi') + + #ecalMultiFitUncalibRecHit + process.ecalMultiFitUncalibRecHit.EBdigiCollection = cms.InputTag("hltEcalPhiSymFilter","phiSymEcalDigisEB") + process.ecalMultiFitUncalibRecHit.EEdigiCollection = cms.InputTag("hltEcalPhiSymFilter","phiSymEcalDigisEE") + + #ecalRecHit (no ricovery) + process.ecalRecHit.killDeadChannels = cms.bool( False ) + process.ecalRecHit.recoverEBVFE = cms.bool( False ) + process.ecalRecHit.recoverEEVFE = cms.bool( False ) + process.ecalRecHit.recoverEBFE = cms.bool( False ) + process.ecalRecHit.recoverEEFE = cms.bool( False ) + process.ecalRecHit.recoverEEIsolatedChannels = cms.bool( False ) + process.ecalRecHit.recoverEBIsolatedChannels = cms.bool( False ) + + # PHISYM producer + process.load('Calibration.EcalCalibAlgos.EcalPhiSymRecHitProducers_cfi') + + # SCHEDULE + reconstruction_step = cms.Sequence( process.bunchSpacingProducer * (process.ecalMultiFitUncalibRecHit + process.ecalRecHit) ) + reconstruction_step *= process.EcalPhiSymRecHitProducerRun if produce_by_run else process.EcalPhiSymRecHitProducerLumi + + return reconstruction_step + +def ecal_phisym_flattables(process, produce_by_run : bool=False): + """ + Add the NanoAOD flat table producers. + This functions adjust also the output columns. + Should be called once nMisCalib has been set in the EcalPhiSymRecHitProducer + """ + + process.load('Calibration.EcalCalibAlgos.EcalPhiSymFlatTableProducers_cfi') + + nmis = process.EcalPhiSymRecHitProducerRun.nMisCalib.value() + for imis in range(1, nmis+1): + # get the naming and indexing right. + if imis& etValues, + unsigned int status): + id_(id), chStatus_(status), nHits_(0), + etSum_(etValues.begin(), etValues.end()), + et2Sum_(0), lcSum_(0), lc2Sum_(0) +{} + +//**********destructor******************************************************************** +EcalPhiSymRecHit::~EcalPhiSymRecHit() +{} + +//**********utils************************************************************************* + +void EcalPhiSymRecHit::AddHit(float* etValues, float laserCorr) +{ + if(etValues[0] > 0.) + { + ++nHits_; + etSum_[0] += etValues[0]; + et2Sum_ += etValues[0]*etValues[0]; + lcSum_ += laserCorr; + lc2Sum_ += laserCorr*laserCorr; + } + for(unsigned int i=0; i& etValues, float laserCorr) +{ + AddHit(etValues.data()); +} + +void EcalPhiSymRecHit::Reset() +{ + nHits_ = 0.; + et2Sum_ = 0.; + lcSum_ = 0.; + lc2Sum_ = 0.; + etSum_ = std::vector(etSum_.size(), 0.); +} + +//**********operators********************************************************************* + +EcalPhiSymRecHit& EcalPhiSymRecHit::operator+=(const EcalPhiSymRecHit& rhs) +{ + // assume same id, do not check channel status + assert("EcalPhiSymRecHit operator+= : attempting to sum RecHits belonging to different channels" && + (id_ == rhs.GetRawId())); + nHits_ += rhs.GetNhits(); + et2Sum_ += rhs.GetSumEt2(); + lcSum_ += rhs.GetLCSum(); + lc2Sum_ += rhs.GetLC2Sum(); + for(unsigned int i=0; i dummy12; + edm::Wrapper dummy13; + + EcalPhiSymInfo dummy21; + std::vector dummy22; + edm::Wrapper dummy23; + }; +} diff --git a/Calibration/EcalCalibAlgos/src/classes_def.xml b/Calibration/EcalCalibAlgos/src/classes_def.xml new file mode 100644 index 0000000000000..1487310133218 --- /dev/null +++ b/Calibration/EcalCalibAlgos/src/classes_def.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/Calibration/EcalCalibAlgos/test/EcalPhiSymReco_cfg.py b/Calibration/EcalCalibAlgos/test/EcalPhiSymReco_cfg.py new file mode 100644 index 0000000000000..29c348a1332d6 --- /dev/null +++ b/Calibration/EcalCalibAlgos/test/EcalPhiSymReco_cfg.py @@ -0,0 +1,72 @@ +import FWCore.ParameterSet.Config as cms +from FWCore.ParameterSet.VarParsing import VarParsing + +# Cmd line options +options = VarParsing ('analysis') +options.register('produceByRun', + True, + VarParsing.multiplicity.singleton, + VarParsing.varType.bool, + "Accumulate EcalPhiSym RecHits by Run or by LuminosityBlock") +options.register('saveFlatNano', + True, + VarParsing.multiplicity.singleton, + VarParsing.varType.bool, + "Produce FlatNanoAOD output") +options.register('saveEDMNano', + False, + VarParsing.multiplicity.singleton, + VarParsing.varType.bool, + "Produce EDMNanoAOD output") +options.register('saveEDM', + False, + VarParsing.multiplicity.singleton, + VarParsing.varType.bool, + "Produce stadard EDM output") +options.inputFiles=[""] +options.parseArguments() + +process = cms.Process("ECALPHISYM") +process.load("FWCore.MessageService.MessageLogger_cfi") + +# Multi-threading +process.options.numberOfStreams = cms.untracked.uint32(4) +process.options.numberOfThreads = cms.untracked.uint32(4) + +# Conditions +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') +process.load('Configuration.Geometry.GeometryExtended2018Reco_cff') +process.load('Configuration.Geometry.GeometryExtended2018Reco_cff') + +from CondCore.CondDB.CondDB_cfi import * +process.GlobalTag = cms.ESSource("PoolDBESSource", + connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS'), + globaltag = cms.string('123X_dataRun2_v1') +) + +# Source data +# skip bad events +process.options = cms.untracked.PSet( + SkipEvent = cms.untracked.vstring('ProductNotFound'), +) +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(-1) +) +process.source = cms.Source("PoolSource", + fileNames = cms.untracked.vstring(options.inputFiles) + ) + +# Load EcalPhiSym workflow +from Calibration.EcalCalibAlgos.EcalPhiSymRecoSequence_cff import ecal_phisym_workflow +ecal_phisym_workflow(process, + produce_by_run=options.produceByRun, + save_flatnano=options.saveFlatNano, + save_edmnano=options.saveEDMNano, + save_edm=options.saveEDM) + +process.MessageLogger.cout.FwkSummary = cms.untracked.PSet( + reportEvery = cms.untracked.int32(100000)) +process.MessageLogger.cout.FwkReport = cms.untracked.PSet( + reportEvery = cms.untracked.int32(100000)) +process.MessageLogger.cerr.FwkSummary.reportEvery = 100000 +process.MessageLogger.cerr.FwkReport.reportEvery = 100000 From 9dea3c5e0cc7f599145930214bcc94ce8c76f619 Mon Sep 17 00:00:00 2001 From: Simone Pigazzi Date: Thu, 17 Feb 2022 00:19:32 +0100 Subject: [PATCH 03/13] format --- .../EcalCalibAlgos/interface/EcalPhiSymInfo.h | 107 +- .../interface/EcalPhiSymRecHit.h | 62 +- .../plugins/EcalPhiSymFlatTableProducers.cc | 1 - .../plugins/EcalPhiSymRecHitProducers.cc | 936 ++++++++---------- .../EcalCalibAlgos/src/EcalPhiSymRecHit.cc | 102 +- Calibration/EcalCalibAlgos/src/classes.h | 22 +- 6 files changed, 561 insertions(+), 669 deletions(-) diff --git a/Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h b/Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h index 6f8f154d50716..95d28ea25db53 100644 --- a/Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h +++ b/Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h @@ -10,74 +10,63 @@ #include -class EcalPhiSymInfo -{ +class EcalPhiSymInfo { public: - //---ctors--- - EcalPhiSymInfo(): - totHitsEB_(0), - totHitsEE_(0), - nEvents_(0), - nLumis_(0), - fillNumber_(0), - delivLumi_(0), - recLumi_(0) - {} + //---ctors--- + EcalPhiSymInfo() + : totHitsEB_(0), totHitsEE_(0), nEvents_(0), nLumis_(0), fillNumber_(0), delivLumi_(0), recLumi_(0) {} - EcalPhiSymInfo(uint64_t hitsEB, uint64_t hitsEE, - uint64_t nEvents, uint32_t nLumis, - uint16_t fill, float delivLumi, float recLumi): - totHitsEB_(hitsEB), + EcalPhiSymInfo( + uint64_t hitsEB, uint64_t hitsEE, uint64_t nEvents, uint32_t nLumis, uint16_t fill, float delivLumi, float recLumi) + : totHitsEB_(hitsEB), totHitsEE_(hitsEE), nEvents_(nEvents), nLumis_(nLumis), - fillNumber_(fill), + fillNumber_(fill), delivLumi_(delivLumi), - recLumi_(recLumi) - {} - - //---dtor--- - ~EcalPhiSymInfo() {}; - - //---getters--- - inline uint64_t totHits() const {return totHitsEB_+totHitsEE_;}; - inline uint64_t totHitsEB() const {return totHitsEB_;}; - inline uint64_t totHitsEE() const {return totHitsEE_;}; - inline uint32_t nEvents() const {return nEvents_;}; - inline uint16_t nLumis() const {return nLumis_;}; - inline uint16_t fillNumber() const {return fillNumber_;}; - inline float delivLumi() const {return delivLumi_;}; - inline float recLumi() const {return recLumi_;}; + recLumi_(recLumi) {} - //---operators--- - EcalPhiSymInfo& operator+=(const EcalPhiSymInfo& rhs) - { - // The class at the moment is designed to - // hold at most data from a single run. - // This implies fillNumber has to be the same, - // unless it was not set, in that case it is 0. - if(fillNumber_!=0 && rhs.fillNumber()!=0) - assert(fillNumber_ == rhs.fillNumber()); - else - fillNumber_ = std::max(fillNumber_, rhs.fillNumber()); - totHitsEB_ += rhs.totHitsEB(); - totHitsEE_ += rhs.totHitsEE(); - nEvents_ += rhs.nEvents(); - nLumis_ += rhs.nLumis(); - delivLumi_ += rhs.delivLumi(); - recLumi_ += rhs.recLumi(); + //---dtor--- + ~EcalPhiSymInfo(){}; + + //---getters--- + inline uint64_t totHits() const { return totHitsEB_ + totHitsEE_; }; + inline uint64_t totHitsEB() const { return totHitsEB_; }; + inline uint64_t totHitsEE() const { return totHitsEE_; }; + inline uint32_t nEvents() const { return nEvents_; }; + inline uint16_t nLumis() const { return nLumis_; }; + inline uint16_t fillNumber() const { return fillNumber_; }; + inline float delivLumi() const { return delivLumi_; }; + inline float recLumi() const { return recLumi_; }; + + //---operators--- + EcalPhiSymInfo& operator+=(const EcalPhiSymInfo& rhs) { + // The class at the moment is designed to + // hold at most data from a single run. + // This implies fillNumber has to be the same, + // unless it was not set, in that case it is 0. + if (fillNumber_ != 0 && rhs.fillNumber() != 0) + assert(fillNumber_ == rhs.fillNumber()); + else + fillNumber_ = std::max(fillNumber_, rhs.fillNumber()); + totHitsEB_ += rhs.totHitsEB(); + totHitsEE_ += rhs.totHitsEE(); + nEvents_ += rhs.nEvents(); + nLumis_ += rhs.nLumis(); + delivLumi_ += rhs.delivLumi(); + recLumi_ += rhs.recLumi(); + + return *this; + } - return *this; - } - private: - uint64_t totHitsEB_; - uint64_t totHitsEE_; - uint32_t nEvents_; - uint16_t nLumis_; - uint16_t fillNumber_; - float delivLumi_; - float recLumi_; + uint64_t totHitsEB_; + uint64_t totHitsEE_; + uint32_t nEvents_; + uint16_t nLumis_; + uint16_t fillNumber_; + float delivLumi_; + float recLumi_; }; #endif diff --git a/Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h b/Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h index 50e2dbabc6e47..efbb58c840a3b 100644 --- a/Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h +++ b/Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h @@ -21,44 +21,42 @@ #include "DataFormats/EcalDetId/interface/EEDetId.h" #include "DataFormats/EcalDetId/interface/EcalSubdetector.h" -class EcalPhiSymRecHit -{ +class EcalPhiSymRecHit { public: - //---ctors--- - EcalPhiSymRecHit(); - EcalPhiSymRecHit(uint32_t id, unsigned int nMisCalibV, unsigned int status=0); - EcalPhiSymRecHit(uint32_t id, std::vector& etValues, unsigned int status=0); - - //---dtor--- - ~EcalPhiSymRecHit(); + //---ctors--- + EcalPhiSymRecHit(); + EcalPhiSymRecHit(uint32_t id, unsigned int nMisCalibV, unsigned int status = 0); + EcalPhiSymRecHit(uint32_t id, std::vector& etValues, unsigned int status = 0); - //---getters--- - inline uint32_t GetRawId() const {return id_;}; - inline unsigned int GetStatusCode() const {return chStatus_;}; - inline uint32_t GetNhits() const {return nHits_;}; - inline unsigned int GetNSumEt() const {return etSum_.size();}; - inline float GetSumEt(int i=0) const {return etSum_[i];}; - inline float GetSumEt2() const {return et2Sum_;}; - inline float GetLCSum() const {return lcSum_;}; - inline float GetLC2Sum() const {return lc2Sum_;}; + //---dtor--- + ~EcalPhiSymRecHit(); - //---utils--- - void AddHit(float* etValues, float laserCorr=0); - void AddHit(std::vector& etValues, float laserCorr=0); - void Reset(); + //---getters--- + inline uint32_t GetRawId() const { return id_; }; + inline unsigned int GetStatusCode() const { return chStatus_; }; + inline uint32_t GetNhits() const { return nHits_; }; + inline unsigned int GetNSumEt() const { return etSum_.size(); }; + inline float GetSumEt(int i = 0) const { return etSum_[i]; }; + inline float GetSumEt2() const { return et2Sum_; }; + inline float GetLCSum() const { return lcSum_; }; + inline float GetLC2Sum() const { return lc2Sum_; }; - //---operators--- - EcalPhiSymRecHit& operator+=(const EcalPhiSymRecHit& rhs); + //---utils--- + void AddHit(float* etValues, float laserCorr = 0); + void AddHit(std::vector& etValues, float laserCorr = 0); + void Reset(); -private: + //---operators--- + EcalPhiSymRecHit& operator+=(const EcalPhiSymRecHit& rhs); - uint32_t id_; - unsigned int chStatus_; - uint32_t nHits_; - std::vector etSum_; - float et2Sum_; - float lcSum_; - float lc2Sum_; +private: + uint32_t id_; + unsigned int chStatus_; + uint32_t nHits_; + std::vector etSum_; + float et2Sum_; + float lcSum_; + float lc2Sum_; }; typedef std::vector EcalPhiSymRecHitCollection; diff --git a/Calibration/EcalCalibAlgos/plugins/EcalPhiSymFlatTableProducers.cc b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymFlatTableProducers.cc index def81958ed961..932ae97f1ef79 100644 --- a/Calibration/EcalCalibAlgos/plugins/EcalPhiSymFlatTableProducers.cc +++ b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymFlatTableProducers.cc @@ -16,4 +16,3 @@ DEFINE_FWK_MODULE(EcalPhiSymRecHitFlatTableProducerLumi); DEFINE_FWK_MODULE(EcalPhiSymInfoFlatTableProducerLumi); DEFINE_FWK_MODULE(EcalPhiSymRecHitFlatTableProducerRun); DEFINE_FWK_MODULE(EcalPhiSymInfoFlatTableProducerRun); - diff --git a/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc index bf596920fb2a7..91fe6adcb21b3 100644 --- a/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc +++ b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc @@ -49,597 +49,521 @@ using namespace std; //---Wrapper to handle cross-stream data struct PhiSymCache { - mutable EcalPhiSymInfo ecalLumiInfo; - mutable EcalPhiSymRecHitCollection recHitCollEB; - mutable EcalPhiSymRecHitCollection recHitCollEE; - - void clear() - { - ecalLumiInfo = EcalPhiSymInfo(); - recHitCollEB.clear(); - recHitCollEE.clear(); - } + mutable EcalPhiSymInfo ecalLumiInfo; + mutable EcalPhiSymRecHitCollection recHitCollEB; + mutable EcalPhiSymRecHitCollection recHitCollEE; + + void clear() { + ecalLumiInfo = EcalPhiSymInfo(); + recHitCollEB.clear(); + recHitCollEE.clear(); + } }; - + //**************************************************************************************** // - EcalPhiSymRecHitProducerBase: base class implementing the main algorithm // - EcalPhiSymRecHitProducerLumi: produces reduced collections per LuminosityBlock // - EcalPhiSymRecHitProducerRun: produces reduced collections per Run -class EcalPhiSymRecHitProducerBase -{ +class EcalPhiSymRecHitProducerBase { public: - explicit EcalPhiSymRecHitProducerBase(const edm::ParameterSet& pSet, - edm::ConsumesCollector&& cc); - ~EcalPhiSymRecHitProducerBase() {}; - - //---methods - // job - void initializeJob(); - // event - void processEvent(edm::StreamID stream, - edm::Event const& event, - edm::EventSetup const& setup, - PhiSymCache* cache) const; - // helpers - void initializeStreamCache(PhiSymCache* cache) const; - void initializeGlobalCache(edm::EventSetup const& setup, - edm::ESGetToken const& chStatusToken, - edm::ESGetToken const& geoToken, - std::shared_ptr& cache) const; - void sumCache(PhiSymCache* streamCache, PhiSymCache const* cache) const; - - //---data memebers - // available to derived classes + explicit EcalPhiSymRecHitProducerBase(const edm::ParameterSet& pSet, edm::ConsumesCollector&& cc); + ~EcalPhiSymRecHitProducerBase(){}; + + //---methods + // job + void initializeJob(); + // event + void processEvent(edm::StreamID stream, + edm::Event const& event, + edm::EventSetup const& setup, + PhiSymCache* cache) const; + // helpers + void initializeStreamCache(PhiSymCache* cache) const; + void initializeGlobalCache(edm::EventSetup const& setup, + edm::ESGetToken const& chStatusToken, + edm::ESGetToken const& geoToken, + std::shared_ptr& cache) const; + void sumCache(PhiSymCache* streamCache, PhiSymCache const* cache) const; + + //---data memebers + // available to derived classes protected: - mutable std::vector barrelDetIds_; - mutable std::vector endcapDetIds_; - edm::ESGetToken geoToken_; - edm::ESGetToken laserDbToken_; - mutable edm::EDGetTokenT ebToken_; - mutable edm::EDGetTokenT eeToken_; - float etCutEB_; - vector eThresholdsEB_; - float etCutEE_; - vector A_; - vector B_; - float thrEEmod_; - int nMisCalib_; - int nSumEtValues_; - vector misCalibRangeEB_; - float misCalibStepsEB_[11]; - vector misCalibRangeEE_; - float misCalibStepsEE_[11]; - //---geometry - EcalRingCalibrationTools calibRing_; - static const short kNRingsEB = EcalRingCalibrationTools::N_RING_BARREL; - static const short kNRingsEE = EcalRingCalibrationTools::N_RING_ENDCAP; - static const short ringsInOneEE = kNRingsEE/2; - mutable float etCutsEB_[kNRingsEB]; - mutable float etCutsEE_[kNRingsEE]; - mutable float eThresholdsEE_[kNRingsEE]; + mutable std::vector barrelDetIds_; + mutable std::vector endcapDetIds_; + edm::ESGetToken geoToken_; + edm::ESGetToken laserDbToken_; + mutable edm::EDGetTokenT ebToken_; + mutable edm::EDGetTokenT eeToken_; + float etCutEB_; + vector eThresholdsEB_; + float etCutEE_; + vector A_; + vector B_; + float thrEEmod_; + int nMisCalib_; + int nSumEtValues_; + vector misCalibRangeEB_; + float misCalibStepsEB_[11]; + vector misCalibRangeEE_; + float misCalibStepsEE_[11]; + //---geometry + EcalRingCalibrationTools calibRing_; + static const short kNRingsEB = EcalRingCalibrationTools::N_RING_BARREL; + static const short kNRingsEE = EcalRingCalibrationTools::N_RING_ENDCAP; + static const short ringsInOneEE = kNRingsEE / 2; + mutable float etCutsEB_[kNRingsEB]; + mutable float etCutsEE_[kNRingsEE]; + mutable float eThresholdsEE_[kNRingsEE]; }; //----------IMPLEMENTATION---------------------------------------------------------------- -EcalPhiSymRecHitProducerBase::EcalPhiSymRecHitProducerBase(const edm::ParameterSet& pSet, - edm::ConsumesCollector&& cc): - geoToken_(cc.esConsumes()), - laserDbToken_(cc.esConsumes()), - ebToken_(cc.consumes(pSet.getParameter("barrelHitCollection"))), - eeToken_(cc.consumes(pSet.getParameter("endcapHitCollection"))), - etCutEB_(pSet.getParameter("etCut_barrel")), - eThresholdsEB_(pSet.getParameter >("eThresholds_barrel")), - etCutEE_(pSet.getParameter("etCut_endcap")), - A_(pSet.getParameter >("A")), - B_(pSet.getParameter >("B")), - thrEEmod_(pSet.getParameter("thrEEmod")), - nMisCalib_(pSet.getParameter("nMisCalib")/2), - nSumEtValues_(nMisCalib_*2+1), - misCalibRangeEB_(pSet.getParameter >("misCalibRangeEB")), - misCalibRangeEE_(pSet.getParameter >("misCalibRangeEE")) -{} - -void EcalPhiSymRecHitProducerBase::initializeJob() -{ - //---set E thresholds, Et cuts and miscalib steps - //---spectrum window: E > thr && Et < cut - //---NOTE: etCutsEE need the geometry, so it is set later in beginLumi - for(int iRing=0; iRing 0; -i -> [1...n/2]; +i -> [n/2+1...n] - int index = iMis > 0 ? iMis+nMisCalib_ : iMis == 0 ? 0 : iMis+nMisCalib_+1; - misCalibStepsEB_[index] = iMis*misCalibStepEB; - misCalibStepsEE_[index] = iMis*misCalibStepEE; - } +EcalPhiSymRecHitProducerBase::EcalPhiSymRecHitProducerBase(const edm::ParameterSet& pSet, edm::ConsumesCollector&& cc) + : geoToken_(cc.esConsumes()), + laserDbToken_(cc.esConsumes()), + ebToken_(cc.consumes(pSet.getParameter("barrelHitCollection"))), + eeToken_(cc.consumes(pSet.getParameter("endcapHitCollection"))), + etCutEB_(pSet.getParameter("etCut_barrel")), + eThresholdsEB_(pSet.getParameter >("eThresholds_barrel")), + etCutEE_(pSet.getParameter("etCut_endcap")), + A_(pSet.getParameter >("A")), + B_(pSet.getParameter >("B")), + thrEEmod_(pSet.getParameter("thrEEmod")), + nMisCalib_(pSet.getParameter("nMisCalib") / 2), + nSumEtValues_(nMisCalib_ * 2 + 1), + misCalibRangeEB_(pSet.getParameter >("misCalibRangeEB")), + misCalibRangeEE_(pSet.getParameter >("misCalibRangeEE")) {} + +void EcalPhiSymRecHitProducerBase::initializeJob() { + //---set E thresholds, Et cuts and miscalib steps + //---spectrum window: E > thr && Et < cut + //---NOTE: etCutsEE need the geometry, so it is set later in beginLumi + for (int iRing = 0; iRing < kNRingsEB; ++iRing) + etCutsEB_[iRing] = -1; + for (int iRing = 0; iRing < ringsInOneEE; ++iRing) { + if (iRing < 30) + eThresholdsEE_[iRing] = thrEEmod_ * (B_[0] + A_[0] * iRing) / 1000; + else + eThresholdsEE_[iRing] = thrEEmod_ * (B_[1] + A_[1] * iRing) / 1000; + eThresholdsEE_[iRing + ringsInOneEE] = eThresholdsEE_[iRing]; + etCutsEE_[iRing] = -1; + etCutsEE_[iRing + ringsInOneEE] = -1; + } + + //---misCalib value init (nMisCalib is half oj the correct value!) + float misCalibStepEB = fabs(misCalibRangeEB_[1] - misCalibRangeEB_[0]) / (nMisCalib_ * 2); + float misCalibStepEE = fabs(misCalibRangeEE_[1] - misCalibRangeEE_[0]) / (nMisCalib_ * 2); + for (int iMis = -nMisCalib_; iMis <= nMisCalib_; ++iMis) { + //--- 0 -> 0; -i -> [1...n/2]; +i -> [n/2+1...n] + int index = iMis > 0 ? iMis + nMisCalib_ : iMis == 0 ? 0 : iMis + nMisCalib_ + 1; + misCalibStepsEB_[index] = iMis * misCalibStepEB; + misCalibStepsEE_[index] = iMis * misCalibStepEE; + } } -void EcalPhiSymRecHitProducerBase::processEvent(edm::StreamID stream, +void EcalPhiSymRecHitProducerBase::processEvent(edm::StreamID stream, edm::Event const& event, edm::EventSetup const& setup, - PhiSymCache* streamCache) const -{ - uint64_t totHitsEB=0; - uint64_t totHitsEE=0; - - //---get recHits collections - auto barrelRecHitsHandle = event.get(ebToken_); - auto endcapRecHitsHandle = event.get(eeToken_); - - //---get the laser corrections - edm::Timestamp evtTimeStamp(event.time().value()); - auto const& laser = setup.getData(laserDbToken_); - - //---get the geometry - auto const& geometry = setup.getData(geoToken_); - auto barrelGeometry = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel); - auto endcapGeometry = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap); - - //---EB--- - for(auto& recHit : barrelRecHitsHandle) - { - float energy = recHit.energy(); - EBDetId ebHit = EBDetId(recHit.id()); - int ring = calibRing_.getRingIndex(ebHit); - //---if recHit energy is below thr even with the highest miscalib skip this recHit - if(energy*misCalibRangeEB_[1] < eThresholdsEB_[ring]) - continue; - float eta=barrelGeometry->getGeometry(ebHit)->getPosition().eta(); - - //---compute et + miscalibration - float etValues[nSumEtValues_]; - //---one can do this in one for loop from -nMis to +nMis but in this way the - //---program is faster - //---NOTE: nMisCalib is half on the value set in the cfg python - etValues[0] = recHit.energy()/cosh(eta); - for(int iMis=-nMisCalib_; iMis<0; ++iMis) - { - //--- 0 -> 0; -i -> [1...n/2]; +i -> [n/2+1...n] - int index = iMis + nMisCalib_ + 1; - etValues[index] = etValues[0]*(1+misCalibStepsEB_[index]); - //---set et to zero if out of range [e_thr, et_thr+1] - if(etValues[index]*cosh(eta) < eThresholdsEB_[ring] || etValues[index] > etCutsEB_[ring]) - etValues[index] = 0; - } - for(int iMis=1; iMis<=nMisCalib_; ++iMis) - { - //--- 0 -> 0; -i -> [1...n/2]; +i -> [n/2+1...n] - int index = iMis + nMisCalib_; - etValues[index] = etValues[0]*(1+misCalibStepsEB_[index]); - //---set et to zero if out of range [e_thr, et_thr+1] - if(etValues[index]*cosh(eta) < eThresholdsEB_[ring] || etValues[index] > etCutsEB_[ring]) - etValues[index] = 0; - } - //---set et to zero if out of range [e_thr, et_thr+1] - if(energy < eThresholdsEB_[ring] || etValues[0] > etCutsEB_[ring]) - etValues[0] = 0; - else - ++totHitsEB; - //---update the rechHit sumEt - streamCache->recHitCollEB.at(ebHit.denseIndex()).AddHit(etValues, - laser.getLaserCorrection(recHit.id(), evtTimeStamp)); + PhiSymCache* streamCache) const { + uint64_t totHitsEB = 0; + uint64_t totHitsEE = 0; + + //---get recHits collections + auto barrelRecHitsHandle = event.get(ebToken_); + auto endcapRecHitsHandle = event.get(eeToken_); + + //---get the laser corrections + edm::Timestamp evtTimeStamp(event.time().value()); + auto const& laser = setup.getData(laserDbToken_); + + //---get the geometry + auto const& geometry = setup.getData(geoToken_); + auto barrelGeometry = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel); + auto endcapGeometry = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap); + + //---EB--- + for (auto& recHit : barrelRecHitsHandle) { + float energy = recHit.energy(); + EBDetId ebHit = EBDetId(recHit.id()); + int ring = calibRing_.getRingIndex(ebHit); + //---if recHit energy is below thr even with the highest miscalib skip this recHit + if (energy * misCalibRangeEB_[1] < eThresholdsEB_[ring]) + continue; + float eta = barrelGeometry->getGeometry(ebHit)->getPosition().eta(); + + //---compute et + miscalibration + float etValues[nSumEtValues_]; + //---one can do this in one for loop from -nMis to +nMis but in this way the + //---program is faster + //---NOTE: nMisCalib is half on the value set in the cfg python + etValues[0] = recHit.energy() / cosh(eta); + for (int iMis = -nMisCalib_; iMis < 0; ++iMis) { + //--- 0 -> 0; -i -> [1...n/2]; +i -> [n/2+1...n] + int index = iMis + nMisCalib_ + 1; + etValues[index] = etValues[0] * (1 + misCalibStepsEB_[index]); + //---set et to zero if out of range [e_thr, et_thr+1] + if (etValues[index] * cosh(eta) < eThresholdsEB_[ring] || etValues[index] > etCutsEB_[ring]) + etValues[index] = 0; } - - //---EE--- - for(auto& recHit : endcapRecHitsHandle) - { - EEDetId eeHit = EEDetId(recHit.id()); - int ring = calibRing_.getRingIndex(eeHit) - kNRingsEB; - float energy = recHit.energy(); - //---if recHit energy is below thr even with the highest miscalib skip this recHit - if(energy*misCalibRangeEE_[1] < eThresholdsEE_[ring]) - continue; - float eta=endcapGeometry->getGeometry(eeHit)->getPosition().eta(); - - //---compute et + miscalibration - float etValues[nSumEtValues_]; - //---one can do this in one for loop from -nMis to +nMis but in this way the - //---program is faster - //---NOTE: nMisCalib is half on the value set in the cfg python - etValues[0] = recHit.energy()/cosh(eta); - for(int iMis=-nMisCalib_; iMis<0; ++iMis) - { - //--- 0 -> 0; -i -> [1...n/2]; +i -> [n/2+1...n] - int index = iMis + nMisCalib_ + 1; - etValues[index] = etValues[0]*(1+misCalibStepsEE_[index]); - //---set et to zero if out of range [e_thr, et_thr+1] - if(etValues[index]*cosh(eta) < eThresholdsEE_[ring] || etValues[index] > etCutsEE_[ring]) - etValues[index] = 0; - } - for(int iMis=1; iMis<=nMisCalib_; ++iMis) - { - //--- 0 -> 0; -i -> [1...n/2]; +i -> [n/2+1...n] - int index = iMis + nMisCalib_; - etValues[index] = etValues[0]*(1+misCalibStepsEE_[index]); - //---set et to zero if out of range [e_thr, et_thr+1] - if(etValues[index]*cosh(eta) < eThresholdsEE_[ring] || etValues[index] > etCutsEE_[ring]) - etValues[index] = 0; - } - //---set et to zero if out of range [e_thr, et_thr+1] - if(energy < eThresholdsEE_[ring] || etValues[0] > etCutsEE_[ring]) - etValues[0] = 0; - else - ++totHitsEE; - //---update the rechHit sumEt - streamCache->recHitCollEE.at(eeHit.denseIndex()).AddHit(etValues, - laser.getLaserCorrection(recHit.id(), evtTimeStamp)); + for (int iMis = 1; iMis <= nMisCalib_; ++iMis) { + //--- 0 -> 0; -i -> [1...n/2]; +i -> [n/2+1...n] + int index = iMis + nMisCalib_; + etValues[index] = etValues[0] * (1 + misCalibStepsEB_[index]); + //---set et to zero if out of range [e_thr, et_thr+1] + if (etValues[index] * cosh(eta) < eThresholdsEB_[ring] || etValues[index] > etCutsEB_[ring]) + etValues[index] = 0; } - - //---update the lumi info - EcalPhiSymInfo thisEvent(totHitsEB, totHitsEE, 1, 0, - 0, 0, 0); - streamCache->ecalLumiInfo += thisEvent; -} - -void EcalPhiSymRecHitProducerBase::initializeStreamCache(PhiSymCache* cache) const -{ - //---Initialize the per-stream RecHitCollection - // both collections are initialized to contain the total - // number of crystals, ordered accrodingly to the hashedIndex. - cache->clear(); - cache->recHitCollEB.resize(barrelDetIds_.size()); - cache->recHitCollEE.resize(endcapDetIds_.size()); - for(auto& ebDetId : barrelDetIds_) - { - EBDetId id(ebDetId); - cache->recHitCollEB.at(id.denseIndex()) = - EcalPhiSymRecHit(id.rawId(), nSumEtValues_); + //---set et to zero if out of range [e_thr, et_thr+1] + if (energy < eThresholdsEB_[ring] || etValues[0] > etCutsEB_[ring]) + etValues[0] = 0; + else + ++totHitsEB; + //---update the rechHit sumEt + streamCache->recHitCollEB.at(ebHit.denseIndex()) + .AddHit(etValues, laser.getLaserCorrection(recHit.id(), evtTimeStamp)); + } + + //---EE--- + for (auto& recHit : endcapRecHitsHandle) { + EEDetId eeHit = EEDetId(recHit.id()); + int ring = calibRing_.getRingIndex(eeHit) - kNRingsEB; + float energy = recHit.energy(); + //---if recHit energy is below thr even with the highest miscalib skip this recHit + if (energy * misCalibRangeEE_[1] < eThresholdsEE_[ring]) + continue; + float eta = endcapGeometry->getGeometry(eeHit)->getPosition().eta(); + + //---compute et + miscalibration + float etValues[nSumEtValues_]; + //---one can do this in one for loop from -nMis to +nMis but in this way the + //---program is faster + //---NOTE: nMisCalib is half on the value set in the cfg python + etValues[0] = recHit.energy() / cosh(eta); + for (int iMis = -nMisCalib_; iMis < 0; ++iMis) { + //--- 0 -> 0; -i -> [1...n/2]; +i -> [n/2+1...n] + int index = iMis + nMisCalib_ + 1; + etValues[index] = etValues[0] * (1 + misCalibStepsEE_[index]); + //---set et to zero if out of range [e_thr, et_thr+1] + if (etValues[index] * cosh(eta) < eThresholdsEE_[ring] || etValues[index] > etCutsEE_[ring]) + etValues[index] = 0; } - for(auto& eeDetId : endcapDetIds_) - { - EEDetId id(eeDetId); - cache->recHitCollEE.at(id.denseIndex()) = - EcalPhiSymRecHit(id.rawId(), nSumEtValues_); + for (int iMis = 1; iMis <= nMisCalib_; ++iMis) { + //--- 0 -> 0; -i -> [1...n/2]; +i -> [n/2+1...n] + int index = iMis + nMisCalib_; + etValues[index] = etValues[0] * (1 + misCalibStepsEE_[index]); + //---set et to zero if out of range [e_thr, et_thr+1] + if (etValues[index] * cosh(eta) < eThresholdsEE_[ring] || etValues[index] > etCutsEE_[ring]) + etValues[index] = 0; } + //---set et to zero if out of range [e_thr, et_thr+1] + if (energy < eThresholdsEE_[ring] || etValues[0] > etCutsEE_[ring]) + etValues[0] = 0; + else + ++totHitsEE; + //---update the rechHit sumEt + streamCache->recHitCollEE.at(eeHit.denseIndex()) + .AddHit(etValues, laser.getLaserCorrection(recHit.id(), evtTimeStamp)); + } + + //---update the lumi info + EcalPhiSymInfo thisEvent(totHitsEB, totHitsEE, 1, 0, 0, 0, 0); + streamCache->ecalLumiInfo += thisEvent; +} + +void EcalPhiSymRecHitProducerBase::initializeStreamCache(PhiSymCache* cache) const { + //---Initialize the per-stream RecHitCollection + // both collections are initialized to contain the total + // number of crystals, ordered accrodingly to the hashedIndex. + cache->clear(); + cache->recHitCollEB.resize(barrelDetIds_.size()); + cache->recHitCollEE.resize(endcapDetIds_.size()); + for (auto& ebDetId : barrelDetIds_) { + EBDetId id(ebDetId); + cache->recHitCollEB.at(id.denseIndex()) = EcalPhiSymRecHit(id.rawId(), nSumEtValues_); + } + for (auto& eeDetId : endcapDetIds_) { + EEDetId id(eeDetId); + cache->recHitCollEE.at(id.denseIndex()) = EcalPhiSymRecHit(id.rawId(), nSumEtValues_); + } } void EcalPhiSymRecHitProducerBase::initializeGlobalCache( edm::EventSetup const& setup, edm::ESGetToken const& chStatusToken, edm::ESGetToken const& geoToken, - std::shared_ptr& cache) const -{ - cache->clear(); - - //---get the ecal geometry - auto geometry = &setup.getData(geoToken); - calibRing_.setCaloGeometry(geometry); - - //---get the channels status - auto const& chStatus = setup.getData(chStatusToken); - - auto barrelGeometry = geometry->getSubdetectorGeometry(DetId::Ecal, EcalBarrel); - auto endcapGeometry = geometry->getSubdetectorGeometry(DetId::Ecal, EcalEndcap); - barrelDetIds_ = barrelGeometry->getValidDetIds(DetId::Ecal, EcalBarrel); - endcapDetIds_ = endcapGeometry->getValidDetIds(DetId::Ecal, EcalEndcap); - cache->recHitCollEB.resize(barrelDetIds_.size()); - cache->recHitCollEE.resize(endcapDetIds_.size()); - for(auto& ebDetId : barrelDetIds_) - { - EBDetId id(ebDetId); - ; - cache->recHitCollEB.at(id.denseIndex()) = - EcalPhiSymRecHit(ebDetId.rawId(), nSumEtValues_, chStatus[id].getStatusCode()); - int ring = calibRing_.getRingIndex(id); - //---set etCut if first pass - if(etCutsEB_[ring] == -1 && id.iphi()==1) - { - auto cellGeometry = barrelGeometry->getGeometry(id); - float eta = cellGeometry->getPosition().eta(); - etCutsEB_[ring] = eThresholdsEB_[ring]/cosh(eta) + etCutEB_; - } + std::shared_ptr& cache) const { + cache->clear(); + + //---get the ecal geometry + auto geometry = &setup.getData(geoToken); + calibRing_.setCaloGeometry(geometry); + + //---get the channels status + auto const& chStatus = setup.getData(chStatusToken); + + auto barrelGeometry = geometry->getSubdetectorGeometry(DetId::Ecal, EcalBarrel); + auto endcapGeometry = geometry->getSubdetectorGeometry(DetId::Ecal, EcalEndcap); + barrelDetIds_ = barrelGeometry->getValidDetIds(DetId::Ecal, EcalBarrel); + endcapDetIds_ = endcapGeometry->getValidDetIds(DetId::Ecal, EcalEndcap); + cache->recHitCollEB.resize(barrelDetIds_.size()); + cache->recHitCollEE.resize(endcapDetIds_.size()); + for (auto& ebDetId : barrelDetIds_) { + EBDetId id(ebDetId); + ; + cache->recHitCollEB.at(id.denseIndex()) = + EcalPhiSymRecHit(ebDetId.rawId(), nSumEtValues_, chStatus[id].getStatusCode()); + int ring = calibRing_.getRingIndex(id); + //---set etCut if first pass + if (etCutsEB_[ring] == -1 && id.iphi() == 1) { + auto cellGeometry = barrelGeometry->getGeometry(id); + float eta = cellGeometry->getPosition().eta(); + etCutsEB_[ring] = eThresholdsEB_[ring] / cosh(eta) + etCutEB_; } - for(auto& eeDetId : endcapDetIds_) - { - EEDetId id(eeDetId); - int ring = calibRing_.getRingIndex(id) - kNRingsEB; - cache->recHitCollEE.at(id.denseIndex()) = - EcalPhiSymRecHit(eeDetId.rawId(), nSumEtValues_, chStatus[id].getStatusCode()); - //---set eCutEE if first pass - if(ring < ringsInOneEE && etCutsEE_[ring] == -1 && id.ix() == 50) - { - auto cellGeometry = endcapGeometry->getGeometry(id); - etCutsEE_[ring] = eThresholdsEE_[ring]/cosh(cellGeometry->getPosition().eta()) + etCutEE_; - etCutsEE_[ring+ringsInOneEE] = etCutsEE_[ring]; - } + } + for (auto& eeDetId : endcapDetIds_) { + EEDetId id(eeDetId); + int ring = calibRing_.getRingIndex(id) - kNRingsEB; + cache->recHitCollEE.at(id.denseIndex()) = + EcalPhiSymRecHit(eeDetId.rawId(), nSumEtValues_, chStatus[id].getStatusCode()); + //---set eCutEE if first pass + if (ring < ringsInOneEE && etCutsEE_[ring] == -1 && id.ix() == 50) { + auto cellGeometry = endcapGeometry->getGeometry(id); + etCutsEE_[ring] = eThresholdsEE_[ring] / cosh(cellGeometry->getPosition().eta()) + etCutEE_; + etCutsEE_[ring + ringsInOneEE] = etCutsEE_[ring]; } + } } -void EcalPhiSymRecHitProducerBase::sumCache(PhiSymCache* streamCache, PhiSymCache const* cache) const -{ - //--- this could be improved. - // One has to make sure that the streamCache is the right hand argument - // in the sum to make sure that info like fillNumber and channel status - // are preserved since they are set in the global initialization and not - // in the stream one. - cache->ecalLumiInfo += streamCache->ecalLumiInfo; - - for(unsigned int i=0; irecHitCollEB.size(); ++i) - cache->recHitCollEB.at(i) += streamCache->recHitCollEB.at(i); - for(unsigned int i=0; irecHitCollEE.size(); ++i) - cache->recHitCollEE.at(i) += streamCache->recHitCollEE.at(i); +void EcalPhiSymRecHitProducerBase::sumCache(PhiSymCache* streamCache, PhiSymCache const* cache) const { + //--- this could be improved. + // One has to make sure that the streamCache is the right hand argument + // in the sum to make sure that info like fillNumber and channel status + // are preserved since they are set in the global initialization and not + // in the stream one. + cache->ecalLumiInfo += streamCache->ecalLumiInfo; + + for (unsigned int i = 0; i < cache->recHitCollEB.size(); ++i) + cache->recHitCollEB.at(i) += streamCache->recHitCollEB.at(i); + for (unsigned int i = 0; i < cache->recHitCollEE.size(); ++i) + cache->recHitCollEE.at(i) += streamCache->recHitCollEE.at(i); } //**************************************************************************************** // Lumi producer -class EcalPhiSymRecHitProducerLumi: public edm::global::EDProducer, - edm::LuminosityBlockCache, - edm::EndLuminosityBlockProducer, - edm::Accumulator>, - public EcalPhiSymRecHitProducerBase -{ +class EcalPhiSymRecHitProducerLumi : public edm::global::EDProducer, + edm::LuminosityBlockCache, + edm::EndLuminosityBlockProducer, + edm::Accumulator>, + public EcalPhiSymRecHitProducerBase { public: - explicit EcalPhiSymRecHitProducerLumi(const edm::ParameterSet& pSet); - ~EcalPhiSymRecHitProducerLumi() {}; + explicit EcalPhiSymRecHitProducerLumi(const edm::ParameterSet& pSet); + ~EcalPhiSymRecHitProducerLumi(){}; private: - //---methods - // job - void beginJob() { initializeJob(); }; - // lumi - std::shared_ptr globalBeginLuminosityBlock(edm::LuminosityBlock const& lumi, - edm::EventSetup const& setup) const override; - void globalEndLuminosityBlock(edm::LuminosityBlock const& lumi, - edm::EventSetup const& setup) const override {}; - void globalEndLuminosityBlockProduce(edm::LuminosityBlock& lumi, - edm::EventSetup const& setup) const override; - // stream - std::unique_ptr beginStream(edm::StreamID stream) const override; - void streamBeginLuminosityBlock(edm::StreamID stream, - edm::LuminosityBlock const& lumi, - edm::EventSetup const& setup) const override; - void streamEndLuminosityBlock(edm::StreamID stream, + //---methods + // job + void beginJob() { initializeJob(); }; + // lumi + std::shared_ptr globalBeginLuminosityBlock(edm::LuminosityBlock const& lumi, + edm::EventSetup const& setup) const override; + void globalEndLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& setup) const override{}; + void globalEndLuminosityBlockProduce(edm::LuminosityBlock& lumi, edm::EventSetup const& setup) const override; + // stream + std::unique_ptr beginStream(edm::StreamID stream) const override; + void streamBeginLuminosityBlock(edm::StreamID stream, edm::LuminosityBlock const& lumi, edm::EventSetup const& setup) const override; + void streamEndLuminosityBlock(edm::StreamID stream, + edm::LuminosityBlock const& lumi, + edm::EventSetup const& setup) const override; - // event - void accumulate(edm::StreamID stream, - edm::Event const& event, - edm::EventSetup const& setup) const; + // event + void accumulate(edm::StreamID stream, edm::Event const& event, edm::EventSetup const& setup) const; - // data members - edm::ESGetToken lhcInfoTokenLumi_; - edm::ESGetToken chStatusTokenLumi_; - edm::ESGetToken geoTokenLumi_; + // data members + edm::ESGetToken lhcInfoTokenLumi_; + edm::ESGetToken chStatusTokenLumi_; + edm::ESGetToken geoTokenLumi_; }; //----------IMPLEMENTATION---------------------------------------------------------------- -EcalPhiSymRecHitProducerLumi::EcalPhiSymRecHitProducerLumi(const edm::ParameterSet& pSet): - EcalPhiSymRecHitProducerBase(pSet, consumesCollector()), - lhcInfoTokenLumi_(esConsumes()), - chStatusTokenLumi_(esConsumes()), - geoTokenLumi_(esConsumes()) -{ - produces(); - produces("EB"); - produces("EE"); +EcalPhiSymRecHitProducerLumi::EcalPhiSymRecHitProducerLumi(const edm::ParameterSet& pSet) + : EcalPhiSymRecHitProducerBase(pSet, consumesCollector()), + lhcInfoTokenLumi_(esConsumes()), + chStatusTokenLumi_(esConsumes()), + geoTokenLumi_(esConsumes()) { + produces(); + produces("EB"); + produces("EE"); } std::shared_ptr EcalPhiSymRecHitProducerLumi::globalBeginLuminosityBlock( - edm::LuminosityBlock const& lumi, - edm::EventSetup const& setup) const -{ - auto cache = std::make_shared(); - - //---Get LHC info - const auto& lhcinfo = setup.getData(lhcInfoTokenLumi_); - EcalPhiSymInfo thisLumi(0, 0, 0, 1, - lhcinfo.fillNumber(), lhcinfo.delivLumi(), lhcinfo.recLumi()); - - //---Reset global cache - initializeGlobalCache(setup, - chStatusTokenLumi_, - geoTokenLumi_, - cache); - cache->ecalLumiInfo += thisLumi; - - return cache; + edm::LuminosityBlock const& lumi, edm::EventSetup const& setup) const { + auto cache = std::make_shared(); + + //---Get LHC info + const auto& lhcinfo = setup.getData(lhcInfoTokenLumi_); + EcalPhiSymInfo thisLumi(0, 0, 0, 1, lhcinfo.fillNumber(), lhcinfo.delivLumi(), lhcinfo.recLumi()); + + //---Reset global cache + initializeGlobalCache(setup, chStatusTokenLumi_, geoTokenLumi_, cache); + cache->ecalLumiInfo += thisLumi; + + return cache; } -std::unique_ptr EcalPhiSymRecHitProducerLumi::beginStream(edm::StreamID stream) const -{ - //---create stream cache - return std::make_unique(); +std::unique_ptr EcalPhiSymRecHitProducerLumi::beginStream(edm::StreamID stream) const { + //---create stream cache + return std::make_unique(); } -void EcalPhiSymRecHitProducerLumi::globalEndLuminosityBlockProduce( - edm::LuminosityBlock& lumi, - edm::EventSetup const& setup) const -{ - auto cache = luminosityBlockCache(lumi.index()); - - //---put the collections in the LuminosityBlocks tree - auto ecalLumiInfo = std::make_unique(); - *ecalLumiInfo = cache->ecalLumiInfo; - auto recHitCollEB = std::make_unique(); - *recHitCollEB = cache->recHitCollEB; - auto recHitCollEE = std::make_unique(); - *recHitCollEE = cache->recHitCollEE; - - lumi.put(std::move(ecalLumiInfo)); - lumi.put(std::move(recHitCollEB), "EB"); - lumi.put(std::move(recHitCollEE), "EE"); +void EcalPhiSymRecHitProducerLumi::globalEndLuminosityBlockProduce(edm::LuminosityBlock& lumi, + edm::EventSetup const& setup) const { + auto cache = luminosityBlockCache(lumi.index()); + + //---put the collections in the LuminosityBlocks tree + auto ecalLumiInfo = std::make_unique(); + *ecalLumiInfo = cache->ecalLumiInfo; + auto recHitCollEB = std::make_unique(); + *recHitCollEB = cache->recHitCollEB; + auto recHitCollEE = std::make_unique(); + *recHitCollEE = cache->recHitCollEE; + + lumi.put(std::move(ecalLumiInfo)); + lumi.put(std::move(recHitCollEB), "EB"); + lumi.put(std::move(recHitCollEE), "EE"); } -void EcalPhiSymRecHitProducerLumi::streamBeginLuminosityBlock( - edm::StreamID stream, - edm::LuminosityBlock const& lumi, - edm::EventSetup const& setup) const -{ - //---Reset cache - initializeStreamCache(streamCache(stream)); +void EcalPhiSymRecHitProducerLumi::streamBeginLuminosityBlock(edm::StreamID stream, + edm::LuminosityBlock const& lumi, + edm::EventSetup const& setup) const { + //---Reset cache + initializeStreamCache(streamCache(stream)); } -void EcalPhiSymRecHitProducerLumi::streamEndLuminosityBlock( - edm::StreamID stream, - edm::LuminosityBlock const& lumi, - edm::EventSetup const& setup) const -{ - //---sum data from different streams into the common lumi cache - sumCache(streamCache(stream), luminosityBlockCache(lumi.index())); +void EcalPhiSymRecHitProducerLumi::streamEndLuminosityBlock(edm::StreamID stream, + edm::LuminosityBlock const& lumi, + edm::EventSetup const& setup) const { + //---sum data from different streams into the common lumi cache + sumCache(streamCache(stream), luminosityBlockCache(lumi.index())); } void EcalPhiSymRecHitProducerLumi::accumulate(edm::StreamID stream, edm::Event const& event, - edm::EventSetup const& setup) const -{ - processEvent(stream, event, setup, streamCache(stream)); + edm::EventSetup const& setup) const { + processEvent(stream, event, setup, streamCache(stream)); } //**************************************************************************************** // Run producer -class EcalPhiSymRecHitProducerRun: public edm::global::EDProducer, - edm::RunCache, - edm::LuminosityBlockCache, - edm::EndRunProducer, - edm::Accumulator>, - public EcalPhiSymRecHitProducerBase -{ +class EcalPhiSymRecHitProducerRun : public edm::global::EDProducer, + edm::RunCache, + edm::LuminosityBlockCache, + edm::EndRunProducer, + edm::Accumulator>, + public EcalPhiSymRecHitProducerBase { public: - explicit EcalPhiSymRecHitProducerRun(const edm::ParameterSet& pSet); - ~EcalPhiSymRecHitProducerRun() {}; + explicit EcalPhiSymRecHitProducerRun(const edm::ParameterSet& pSet); + ~EcalPhiSymRecHitProducerRun(){}; private: - //---methods - // job - void beginJob() { initializeJob(); }; - // run - std::shared_ptr globalBeginRun(edm::Run const& run, - edm::EventSetup const& setup) const override; - void globalEndRun(edm::Run const& run, - edm::EventSetup const& setup) const override {}; - void globalEndRunProduce(edm::Run& run, - edm::EventSetup const& setup) const override; - // lumi - std::shared_ptr globalBeginLuminosityBlock(edm::LuminosityBlock const& lumi, - edm::EventSetup const& setup) const override; - void globalEndLuminosityBlock(edm::LuminosityBlock const& lumi, - edm::EventSetup const& setup) const override {} ; - // stream - std::unique_ptr beginStream(edm::StreamID stream) const; - void streamBeginRun(edm::StreamID stream, - edm::Run const& run, - edm::EventSetup const& setup) const override; - void streamEndRun(edm::StreamID stream, - edm::Run const& run, - edm::EventSetup const& setup) const override; - // event - void accumulate(edm::StreamID stream, - edm::Event const& event, - edm::EventSetup const& setup) const; - - // data members - edm::ESGetToken lhcInfoTokenLumi_; - edm::ESGetToken chStatusTokenRun_; - edm::ESGetToken geoTokenRun_; + //---methods + // job + void beginJob() { initializeJob(); }; + // run + std::shared_ptr globalBeginRun(edm::Run const& run, edm::EventSetup const& setup) const override; + void globalEndRun(edm::Run const& run, edm::EventSetup const& setup) const override{}; + void globalEndRunProduce(edm::Run& run, edm::EventSetup const& setup) const override; + // lumi + std::shared_ptr globalBeginLuminosityBlock(edm::LuminosityBlock const& lumi, + edm::EventSetup const& setup) const override; + void globalEndLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& setup) const override{}; + // stream + std::unique_ptr beginStream(edm::StreamID stream) const; + void streamBeginRun(edm::StreamID stream, edm::Run const& run, edm::EventSetup const& setup) const override; + void streamEndRun(edm::StreamID stream, edm::Run const& run, edm::EventSetup const& setup) const override; + // event + void accumulate(edm::StreamID stream, edm::Event const& event, edm::EventSetup const& setup) const; + + // data members + edm::ESGetToken lhcInfoTokenLumi_; + edm::ESGetToken chStatusTokenRun_; + edm::ESGetToken geoTokenRun_; }; //----------IMPLEMENTATION---------------------------------------------------------------- -EcalPhiSymRecHitProducerRun::EcalPhiSymRecHitProducerRun(const edm::ParameterSet& pSet): - EcalPhiSymRecHitProducerBase(pSet, consumesCollector()), - lhcInfoTokenLumi_(esConsumes()), - chStatusTokenRun_(esConsumes()), - geoTokenRun_(esConsumes()) -{ - produces(); - produces("EB"); - produces("EE"); +EcalPhiSymRecHitProducerRun::EcalPhiSymRecHitProducerRun(const edm::ParameterSet& pSet) + : EcalPhiSymRecHitProducerBase(pSet, consumesCollector()), + lhcInfoTokenLumi_(esConsumes()), + chStatusTokenRun_(esConsumes()), + geoTokenRun_(esConsumes()) { + produces(); + produces("EB"); + produces("EE"); } -std::shared_ptr EcalPhiSymRecHitProducerRun::globalBeginRun( - edm::Run const& run, - edm::EventSetup const& setup) const -{ - auto cache = std::make_shared(); - initializeGlobalCache(setup, - chStatusTokenRun_, - geoTokenRun_, - cache); - return cache; +std::shared_ptr EcalPhiSymRecHitProducerRun::globalBeginRun(edm::Run const& run, + edm::EventSetup const& setup) const { + auto cache = std::make_shared(); + initializeGlobalCache(setup, chStatusTokenRun_, geoTokenRun_, cache); + return cache; } //---globalBeginLuminosityBlock is called just to correctly update the LHCInfo std::shared_ptr EcalPhiSymRecHitProducerRun::globalBeginLuminosityBlock( - edm::LuminosityBlock const& lumi, - edm::EventSetup const& setup) const -{ - //---Get LHC info - // LHCInfo only returns the correct luminosity information - // for each lumisection, accessing LHCInfo at the beginning - // of each run would return only the luminosity info of the - // first LS - const auto& lhcinfo = setup.getData(lhcInfoTokenLumi_); - EcalPhiSymInfo thisLumi(0, 0, 0, 1, - lhcinfo.fillNumber(), lhcinfo.delivLumi(), lhcinfo.recLumi()); - - runCache(lumi.getRun().index())->ecalLumiInfo += thisLumi; - - // dummy cache, it won't be used - return std::make_shared(); + edm::LuminosityBlock const& lumi, edm::EventSetup const& setup) const { + //---Get LHC info + // LHCInfo only returns the correct luminosity information + // for each lumisection, accessing LHCInfo at the beginning + // of each run would return only the luminosity info of the + // first LS + const auto& lhcinfo = setup.getData(lhcInfoTokenLumi_); + EcalPhiSymInfo thisLumi(0, 0, 0, 1, lhcinfo.fillNumber(), lhcinfo.delivLumi(), lhcinfo.recLumi()); + + runCache(lumi.getRun().index())->ecalLumiInfo += thisLumi; + + // dummy cache, it won't be used + return std::make_shared(); } -std::unique_ptr EcalPhiSymRecHitProducerRun::beginStream(edm::StreamID stream) const -{ - //---create stream cache - return std::make_unique(); +std::unique_ptr EcalPhiSymRecHitProducerRun::beginStream(edm::StreamID stream) const { + //---create stream cache + return std::make_unique(); } -void EcalPhiSymRecHitProducerRun::streamBeginRun( - edm::StreamID stream, - edm::Run const& run, - edm::EventSetup const& setup) const -{ - //---Reset global cache - initializeStreamCache(streamCache(stream)); +void EcalPhiSymRecHitProducerRun::streamBeginRun(edm::StreamID stream, + edm::Run const& run, + edm::EventSetup const& setup) const { + //---Reset global cache + initializeStreamCache(streamCache(stream)); } -void EcalPhiSymRecHitProducerRun::streamEndRun( - edm::StreamID stream, - edm::Run const& run, - edm::EventSetup const& setup) const -{ - //---sum data from different streams into the common run cache - sumCache(streamCache(stream), runCache(run.index())); +void EcalPhiSymRecHitProducerRun::streamEndRun(edm::StreamID stream, + edm::Run const& run, + edm::EventSetup const& setup) const { + //---sum data from different streams into the common run cache + sumCache(streamCache(stream), runCache(run.index())); } -void EcalPhiSymRecHitProducerRun::globalEndRunProduce( - edm::Run& run, - edm::EventSetup const& setup) const -{ - auto cache = runCache(run.index()); - - //---put the collections in the Runs tree - auto ecalLumiInfo = std::make_unique(); - *ecalLumiInfo = cache->ecalLumiInfo; - auto recHitCollEB = std::make_unique(); - *recHitCollEB = cache->recHitCollEB; - auto recHitCollEE = std::make_unique(); - *recHitCollEE = cache->recHitCollEE; - - run.put(std::move(ecalLumiInfo)); - run.put(std::move(recHitCollEB), "EB"); - run.put(std::move(recHitCollEE), "EE"); +void EcalPhiSymRecHitProducerRun::globalEndRunProduce(edm::Run& run, edm::EventSetup const& setup) const { + auto cache = runCache(run.index()); + + //---put the collections in the Runs tree + auto ecalLumiInfo = std::make_unique(); + *ecalLumiInfo = cache->ecalLumiInfo; + auto recHitCollEB = std::make_unique(); + *recHitCollEB = cache->recHitCollEB; + auto recHitCollEE = std::make_unique(); + *recHitCollEE = cache->recHitCollEE; + + run.put(std::move(ecalLumiInfo)); + run.put(std::move(recHitCollEB), "EB"); + run.put(std::move(recHitCollEE), "EE"); } void EcalPhiSymRecHitProducerRun::accumulate(edm::StreamID stream, edm::Event const& event, - edm::EventSetup const& setup) const -{ - processEvent(stream, event, setup, streamCache(stream)); + edm::EventSetup const& setup) const { + processEvent(stream, event, setup, streamCache(stream)); } DEFINE_FWK_MODULE(EcalPhiSymRecHitProducerLumi); diff --git a/Calibration/EcalCalibAlgos/src/EcalPhiSymRecHit.cc b/Calibration/EcalCalibAlgos/src/EcalPhiSymRecHit.cc index b369507208608..294df74d22821 100644 --- a/Calibration/EcalCalibAlgos/src/EcalPhiSymRecHit.cc +++ b/Calibration/EcalCalibAlgos/src/EcalPhiSymRecHit.cc @@ -1,76 +1,60 @@ #include "Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h" //**********constructors****************************************************************** -EcalPhiSymRecHit::EcalPhiSymRecHit(): - id_(0), chStatus_(0), nHits_(0), - etSum_(1, 0.), et2Sum_(0), - lcSum_(0), lc2Sum_(0) -{} - -EcalPhiSymRecHit::EcalPhiSymRecHit(uint32_t id, - unsigned int nMisCalibV, - unsigned int status): - id_(id), chStatus_(status), nHits_(0), - etSum_(nMisCalibV, 0.), et2Sum_(0), - lcSum_(0), lc2Sum_(0) -{} +EcalPhiSymRecHit::EcalPhiSymRecHit() + : id_(0), chStatus_(0), nHits_(0), etSum_(1, 0.), et2Sum_(0), lcSum_(0), lc2Sum_(0) {} -EcalPhiSymRecHit::EcalPhiSymRecHit(uint32_t id, - std::vector& etValues, - unsigned int status): - id_(id), chStatus_(status), nHits_(0), - etSum_(etValues.begin(), etValues.end()), - et2Sum_(0), lcSum_(0), lc2Sum_(0) -{} +EcalPhiSymRecHit::EcalPhiSymRecHit(uint32_t id, unsigned int nMisCalibV, unsigned int status) + : id_(id), chStatus_(status), nHits_(0), etSum_(nMisCalibV, 0.), et2Sum_(0), lcSum_(0), lc2Sum_(0) {} + +EcalPhiSymRecHit::EcalPhiSymRecHit(uint32_t id, std::vector& etValues, unsigned int status) + : id_(id), + chStatus_(status), + nHits_(0), + etSum_(etValues.begin(), etValues.end()), + et2Sum_(0), + lcSum_(0), + lc2Sum_(0) {} //**********destructor******************************************************************** -EcalPhiSymRecHit::~EcalPhiSymRecHit() -{} +EcalPhiSymRecHit::~EcalPhiSymRecHit() {} //**********utils************************************************************************* -void EcalPhiSymRecHit::AddHit(float* etValues, float laserCorr) -{ - if(etValues[0] > 0.) - { - ++nHits_; - etSum_[0] += etValues[0]; - et2Sum_ += etValues[0]*etValues[0]; - lcSum_ += laserCorr; - lc2Sum_ += laserCorr*laserCorr; - } - for(unsigned int i=0; i 0.) { + ++nHits_; + etSum_[0] += etValues[0]; + et2Sum_ += etValues[0] * etValues[0]; + lcSum_ += laserCorr; + lc2Sum_ += laserCorr * laserCorr; + } + for (unsigned int i = 0; i < etSum_.size(); ++i) + etSum_[i] += etValues[i]; } +void EcalPhiSymRecHit::AddHit(std::vector& etValues, float laserCorr) { AddHit(etValues.data()); } -void EcalPhiSymRecHit::AddHit(std::vector& etValues, float laserCorr) -{ - AddHit(etValues.data()); -} - -void EcalPhiSymRecHit::Reset() -{ - nHits_ = 0.; - et2Sum_ = 0.; - lcSum_ = 0.; - lc2Sum_ = 0.; - etSum_ = std::vector(etSum_.size(), 0.); +void EcalPhiSymRecHit::Reset() { + nHits_ = 0.; + et2Sum_ = 0.; + lcSum_ = 0.; + lc2Sum_ = 0.; + etSum_ = std::vector(etSum_.size(), 0.); } //**********operators********************************************************************* -EcalPhiSymRecHit& EcalPhiSymRecHit::operator+=(const EcalPhiSymRecHit& rhs) -{ - // assume same id, do not check channel status - assert("EcalPhiSymRecHit operator+= : attempting to sum RecHits belonging to different channels" && - (id_ == rhs.GetRawId())); - nHits_ += rhs.GetNhits(); - et2Sum_ += rhs.GetSumEt2(); - lcSum_ += rhs.GetLCSum(); - lc2Sum_ += rhs.GetLC2Sum(); - for(unsigned int i=0; i dummy12; - edm::Wrapper dummy13; +namespace { + struct dictionary { + EcalPhiSymRecHit dummy11; + std::vector dummy12; + edm::Wrapper dummy13; - EcalPhiSymInfo dummy21; - std::vector dummy22; - edm::Wrapper dummy23; - }; -} + EcalPhiSymInfo dummy21; + std::vector dummy22; + edm::Wrapper dummy23; + }; +} // namespace From 857749e3a85c0ebc4de882057c0ad5c5f1d8ad40 Mon Sep 17 00:00:00 2001 From: Simone Pigazzi Date: Thu, 17 Feb 2022 00:39:07 +0100 Subject: [PATCH 04/13] code-checks --- .../plugins/EcalPhiSymRecHitProducers.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc index 91fe6adcb21b3..92700fadfbfe6 100644 --- a/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc +++ b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc @@ -356,12 +356,12 @@ class EcalPhiSymRecHitProducerLumi : public edm::global::EDProducer globalBeginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& setup) const override; @@ -377,7 +377,7 @@ class EcalPhiSymRecHitProducerLumi : public edm::global::EDProducer lhcInfoTokenLumi_; @@ -463,12 +463,12 @@ class EcalPhiSymRecHitProducerRun : public edm::global::EDProducer globalBeginRun(edm::Run const& run, edm::EventSetup const& setup) const override; void globalEndRun(edm::Run const& run, edm::EventSetup const& setup) const override{}; @@ -478,11 +478,11 @@ class EcalPhiSymRecHitProducerRun : public edm::global::EDProducer beginStream(edm::StreamID stream) const; + std::unique_ptr beginStream(edm::StreamID stream) const override; void streamBeginRun(edm::StreamID stream, edm::Run const& run, edm::EventSetup const& setup) const override; void streamEndRun(edm::StreamID stream, edm::Run const& run, edm::EventSetup const& setup) const override; // event - void accumulate(edm::StreamID stream, edm::Event const& event, edm::EventSetup const& setup) const; + void accumulate(edm::StreamID stream, edm::Event const& event, edm::EventSetup const& setup) const override; // data members edm::ESGetToken lhcInfoTokenLumi_; From cd2fa5489fbc6264b9c9bd5514e51fdf4777bf04 Mon Sep 17 00:00:00 2001 From: Simone Pigazzi Date: Fri, 18 Feb 2022 12:42:55 +0100 Subject: [PATCH 05/13] addressing PR comments + missing bookeeping variables in EcalPhiSymIndo --- .../EcalCalibAlgos/interface/EcalPhiSymInfo.h | 48 +++++++++-- .../interface/EcalPhiSymRecHit.h | 27 +++---- .../plugins/EcalPhiSymRecHitProducers.cc | 81 ++++++++----------- .../EcalPhiSymFlatTableProducers_cfi.py | 24 +++--- .../python/EcalPhiSymRecoSequence_cff.py | 8 +- .../EcalCalibAlgos/src/EcalPhiSymRecHit.cc | 25 +++--- Calibration/EcalCalibAlgos/src/classes.h | 5 ++ .../EcalCalibAlgos/test/EcalPhiSymReco_cfg.py | 8 +- 8 files changed, 126 insertions(+), 100 deletions(-) diff --git a/Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h b/Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h index 95d28ea25db53..25d83bc56bc7e 100644 --- a/Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h +++ b/Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h @@ -1,7 +1,7 @@ -#ifndef ECAL_PHISYM_INFO_H -#define ECAL_PHISYM_INFO_H +#ifndef Calibration_EcalCalibAlgos_EcalPhiSymInfo_h +#define Calibration_EcalCalibAlgos_EcalPhiSymInfo_h -/** \class EcalPhiSymRecHit +/** \class EcalPhiSymInfo * * EcalPhiSym calibration lumi/run based information * @@ -14,7 +14,18 @@ class EcalPhiSymInfo { public: //---ctors--- EcalPhiSymInfo() - : totHitsEB_(0), totHitsEE_(0), nEvents_(0), nLumis_(0), fillNumber_(0), delivLumi_(0), recLumi_(0) {} + : totHitsEB_(0), + totHitsEE_(0), + nEvents_(0), + nLumis_(0), + fillNumber_(0), + delivLumi_(0), + recLumi_(0), + nMis_(0), + minMisEB_(0), + maxMisEB_(0), + minMisEE_(0), + maxMisEE_(0) {} EcalPhiSymInfo( uint64_t hitsEB, uint64_t hitsEE, uint64_t nEvents, uint32_t nLumis, uint16_t fill, float delivLumi, float recLumi) @@ -24,10 +35,25 @@ class EcalPhiSymInfo { nLumis_(nLumis), fillNumber_(fill), delivLumi_(delivLumi), - recLumi_(recLumi) {} + recLumi_(recLumi), + nMis_(0), + minMisEB_(0), + maxMisEB_(0), + minMisEE_(0), + maxMisEE_(0) {} //---dtor--- - ~EcalPhiSymInfo(){}; + ~EcalPhiSymInfo() = default; + + //---setters--- + inline void setMiscalibInfo( + const int& nmis, const float& minEB, const float& maxEB, const float& minEE, const float& maxEE) { + nMis_ = nmis; + minMisEB_ = minEB; + maxMisEB_ = maxEB; + minMisEE_ = minEE; + maxMisEE_ = maxEE; + }; //---getters--- inline uint64_t totHits() const { return totHitsEB_ + totHitsEE_; }; @@ -38,6 +64,11 @@ class EcalPhiSymInfo { inline uint16_t fillNumber() const { return fillNumber_; }; inline float delivLumi() const { return delivLumi_; }; inline float recLumi() const { return recLumi_; }; + inline uint8_t nMis() const { return nMis_; }; + inline float minMisEB() const { return minMisEB_; }; + inline float maxMisEB() const { return maxMisEB_; }; + inline float minMisEE() const { return minMisEE_; }; + inline float maxMisEE() const { return maxMisEE_; }; //---operators--- EcalPhiSymInfo& operator+=(const EcalPhiSymInfo& rhs) { @@ -67,6 +98,11 @@ class EcalPhiSymInfo { uint16_t fillNumber_; float delivLumi_; float recLumi_; + uint8_t nMis_; + float minMisEB_; + float maxMisEB_; + float minMisEE_; + float maxMisEE_; }; #endif diff --git a/Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h b/Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h index efbb58c840a3b..f1af83d73f303 100644 --- a/Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h +++ b/Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h @@ -1,5 +1,5 @@ -#ifndef ECAL_PHISYM_RECHIT_H -#define ECAL_PHISYM_RECHIT_H +#ifndef Calibration_EcalCalibAlgos_EcalPhiSymRecHit_h +#define Calibration_EcalCalibAlgos_EcalPhiSymRecHit_h /** \class EcalPhiSymRecHit * @@ -29,22 +29,21 @@ class EcalPhiSymRecHit { EcalPhiSymRecHit(uint32_t id, std::vector& etValues, unsigned int status = 0); //---dtor--- - ~EcalPhiSymRecHit(); + ~EcalPhiSymRecHit() = default; //---getters--- - inline uint32_t GetRawId() const { return id_; }; - inline unsigned int GetStatusCode() const { return chStatus_; }; - inline uint32_t GetNhits() const { return nHits_; }; - inline unsigned int GetNSumEt() const { return etSum_.size(); }; - inline float GetSumEt(int i = 0) const { return etSum_[i]; }; - inline float GetSumEt2() const { return et2Sum_; }; - inline float GetLCSum() const { return lcSum_; }; - inline float GetLC2Sum() const { return lc2Sum_; }; + inline uint32_t rawId() const { return id_; }; + inline unsigned int statusCode() const { return chStatus_; }; + inline uint32_t nHits() const { return nHits_; }; + inline unsigned int nSumEt() const { return etSum_.size(); }; + inline float sumEt(int i = 0) const { return etSum_[i]; }; + inline float sumEt2() const { return et2Sum_; }; + inline float lcSum() const { return lcSum_; }; + inline float lc2Sum() const { return lc2Sum_; }; //---utils--- - void AddHit(float* etValues, float laserCorr = 0); - void AddHit(std::vector& etValues, float laserCorr = 0); - void Reset(); + void addHit(const std::vector& etValues, const float laserCorr = 0); + void reset(); //---operators--- EcalPhiSymRecHit& operator+=(const EcalPhiSymRecHit& rhs); diff --git a/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc index 92700fadfbfe6..ed31d84497f1d 100644 --- a/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc +++ b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc @@ -8,10 +8,6 @@ // Created: Wed, 16 Mar 2022 15:52:48 GMT // // - -#ifndef _ECAL_PHISYM_RECHIT_PRODUCERS_ -#define _ECAL_PHISYM_RECHIT_PRODUCERS_ - #include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/Framework/interface/MakerMacros.h" #include "FWCore/Framework/interface/global/EDProducer.h" @@ -73,10 +69,7 @@ class EcalPhiSymRecHitProducerBase { // job void initializeJob(); // event - void processEvent(edm::StreamID stream, - edm::Event const& event, - edm::EventSetup const& setup, - PhiSymCache* cache) const; + void processEvent(edm::Event const& event, edm::EventSetup const& setup, PhiSymCache* cache) const; // helpers void initializeStreamCache(PhiSymCache* cache) const; void initializeGlobalCache(edm::EventSetup const& setup, @@ -103,9 +96,9 @@ class EcalPhiSymRecHitProducerBase { int nMisCalib_; int nSumEtValues_; vector misCalibRangeEB_; - float misCalibStepsEB_[11]; + vector misCalibStepsEB_; vector misCalibRangeEE_; - float misCalibStepsEE_[11]; + vector misCalibStepsEE_; //---geometry EcalRingCalibrationTools calibRing_; static const short kNRingsEB = EcalRingCalibrationTools::N_RING_BARREL; @@ -149,9 +142,11 @@ void EcalPhiSymRecHitProducerBase::initializeJob() { etCutsEE_[iRing + ringsInOneEE] = -1; } - //---misCalib value init (nMisCalib is half oj the correct value!) - float misCalibStepEB = fabs(misCalibRangeEB_[1] - misCalibRangeEB_[0]) / (nMisCalib_ * 2); - float misCalibStepEE = fabs(misCalibRangeEE_[1] - misCalibRangeEE_[0]) / (nMisCalib_ * 2); + //---misCalib value init (nMisCalib is half of the correct value!) + float misCalibStepEB = std::abs(misCalibRangeEB_[1] - misCalibRangeEB_[0]) / (nMisCalib_ * 2); + float misCalibStepEE = std::abs(misCalibRangeEE_[1] - misCalibRangeEE_[0]) / (nMisCalib_ * 2); + misCalibStepsEB_.resize(nSumEtValues_); + misCalibStepsEE_.resize(nSumEtValues_); for (int iMis = -nMisCalib_; iMis <= nMisCalib_; ++iMis) { //--- 0 -> 0; -i -> [1...n/2]; +i -> [n/2+1...n] int index = iMis > 0 ? iMis + nMisCalib_ : iMis == 0 ? 0 : iMis + nMisCalib_ + 1; @@ -160,16 +155,15 @@ void EcalPhiSymRecHitProducerBase::initializeJob() { } } -void EcalPhiSymRecHitProducerBase::processEvent(edm::StreamID stream, - edm::Event const& event, +void EcalPhiSymRecHitProducerBase::processEvent(edm::Event const& event, edm::EventSetup const& setup, PhiSymCache* streamCache) const { uint64_t totHitsEB = 0; uint64_t totHitsEE = 0; //---get recHits collections - auto barrelRecHitsHandle = event.get(ebToken_); - auto endcapRecHitsHandle = event.get(eeToken_); + auto barrelRecHits = event.get(ebToken_); + auto endcapRecHits = event.get(eeToken_); //---get the laser corrections edm::Timestamp evtTimeStamp(event.time().value()); @@ -181,7 +175,7 @@ void EcalPhiSymRecHitProducerBase::processEvent(edm::StreamID stream, auto endcapGeometry = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap); //---EB--- - for (auto& recHit : barrelRecHitsHandle) { + for (auto& recHit : barrelRecHits) { float energy = recHit.energy(); EBDetId ebHit = EBDetId(recHit.id()); int ring = calibRing_.getRingIndex(ebHit); @@ -191,7 +185,7 @@ void EcalPhiSymRecHitProducerBase::processEvent(edm::StreamID stream, float eta = barrelGeometry->getGeometry(ebHit)->getPosition().eta(); //---compute et + miscalibration - float etValues[nSumEtValues_]; + vector etValues(nSumEtValues_, 0); //---one can do this in one for loop from -nMis to +nMis but in this way the //---program is faster //---NOTE: nMisCalib is half on the value set in the cfg python @@ -219,11 +213,11 @@ void EcalPhiSymRecHitProducerBase::processEvent(edm::StreamID stream, ++totHitsEB; //---update the rechHit sumEt streamCache->recHitCollEB.at(ebHit.denseIndex()) - .AddHit(etValues, laser.getLaserCorrection(recHit.id(), evtTimeStamp)); + .addHit(etValues, laser.getLaserCorrection(recHit.id(), evtTimeStamp)); } //---EE--- - for (auto& recHit : endcapRecHitsHandle) { + for (auto& recHit : endcapRecHits) { EEDetId eeHit = EEDetId(recHit.id()); int ring = calibRing_.getRingIndex(eeHit) - kNRingsEB; float energy = recHit.energy(); @@ -233,7 +227,7 @@ void EcalPhiSymRecHitProducerBase::processEvent(edm::StreamID stream, float eta = endcapGeometry->getGeometry(eeHit)->getPosition().eta(); //---compute et + miscalibration - float etValues[nSumEtValues_]; + vector etValues(nSumEtValues_, 0); //---one can do this in one for loop from -nMis to +nMis but in this way the //---program is faster //---NOTE: nMisCalib is half on the value set in the cfg python @@ -261,7 +255,7 @@ void EcalPhiSymRecHitProducerBase::processEvent(edm::StreamID stream, ++totHitsEE; //---update the rechHit sumEt streamCache->recHitCollEE.at(eeHit.denseIndex()) - .AddHit(etValues, laser.getLaserCorrection(recHit.id(), evtTimeStamp)); + .addHit(etValues, laser.getLaserCorrection(recHit.id(), evtTimeStamp)); } //---update the lumi info @@ -294,21 +288,20 @@ void EcalPhiSymRecHitProducerBase::initializeGlobalCache( cache->clear(); //---get the ecal geometry - auto geometry = &setup.getData(geoToken); + const auto* geometry = &setup.getData(geoToken); calibRing_.setCaloGeometry(geometry); //---get the channels status auto const& chStatus = setup.getData(chStatusToken); - auto barrelGeometry = geometry->getSubdetectorGeometry(DetId::Ecal, EcalBarrel); - auto endcapGeometry = geometry->getSubdetectorGeometry(DetId::Ecal, EcalEndcap); + const auto* barrelGeometry = geometry->getSubdetectorGeometry(DetId::Ecal, EcalBarrel); + const auto* endcapGeometry = geometry->getSubdetectorGeometry(DetId::Ecal, EcalEndcap); barrelDetIds_ = barrelGeometry->getValidDetIds(DetId::Ecal, EcalBarrel); endcapDetIds_ = endcapGeometry->getValidDetIds(DetId::Ecal, EcalEndcap); cache->recHitCollEB.resize(barrelDetIds_.size()); cache->recHitCollEE.resize(endcapDetIds_.size()); for (auto& ebDetId : barrelDetIds_) { EBDetId id(ebDetId); - ; cache->recHitCollEB.at(id.denseIndex()) = EcalPhiSymRecHit(ebDetId.rawId(), nSumEtValues_, chStatus[id].getStatusCode()); int ring = calibRing_.getRingIndex(id); @@ -325,7 +318,7 @@ void EcalPhiSymRecHitProducerBase::initializeGlobalCache( cache->recHitCollEE.at(id.denseIndex()) = EcalPhiSymRecHit(eeDetId.rawId(), nSumEtValues_, chStatus[id].getStatusCode()); //---set eCutEE if first pass - if (ring < ringsInOneEE && etCutsEE_[ring] == -1 && id.ix() == 50) { + if (ring < ringsInOneEE && etCutsEE_[ring] == -1 && id.ix() == EEDetId::IX_MAX / 2) { auto cellGeometry = endcapGeometry->getGeometry(id); etCutsEE_[ring] = eThresholdsEE_[ring] / cosh(cellGeometry->getPosition().eta()) + etCutEE_; etCutsEE_[ring + ringsInOneEE] = etCutsEE_[ring]; @@ -342,9 +335,9 @@ void EcalPhiSymRecHitProducerBase::sumCache(PhiSymCache* streamCache, PhiSymCach cache->ecalLumiInfo += streamCache->ecalLumiInfo; for (unsigned int i = 0; i < cache->recHitCollEB.size(); ++i) - cache->recHitCollEB.at(i) += streamCache->recHitCollEB.at(i); + cache->recHitCollEB[i] += streamCache->recHitCollEB[i]; for (unsigned int i = 0; i < cache->recHitCollEE.size(); ++i) - cache->recHitCollEE.at(i) += streamCache->recHitCollEE.at(i); + cache->recHitCollEE[i] += streamCache->recHitCollEE[i]; } //**************************************************************************************** @@ -421,12 +414,11 @@ void EcalPhiSymRecHitProducerLumi::globalEndLuminosityBlockProduce(edm::Luminosi auto cache = luminosityBlockCache(lumi.index()); //---put the collections in the LuminosityBlocks tree - auto ecalLumiInfo = std::make_unique(); - *ecalLumiInfo = cache->ecalLumiInfo; - auto recHitCollEB = std::make_unique(); - *recHitCollEB = cache->recHitCollEB; - auto recHitCollEE = std::make_unique(); - *recHitCollEE = cache->recHitCollEE; + auto ecalLumiInfo = std::make_unique(cache->ecalLumiInfo); + ecalLumiInfo->setMiscalibInfo( + nMisCalib_ * 2, misCalibRangeEB_[0], misCalibRangeEB_[1], misCalibRangeEE_[0], misCalibRangeEE_[1]); + auto recHitCollEB = std::make_unique(cache->recHitCollEB); + auto recHitCollEE = std::make_unique(cache->recHitCollEB); lumi.put(std::move(ecalLumiInfo)); lumi.put(std::move(recHitCollEB), "EB"); @@ -450,7 +442,7 @@ void EcalPhiSymRecHitProducerLumi::streamEndLuminosityBlock(edm::StreamID stream void EcalPhiSymRecHitProducerLumi::accumulate(edm::StreamID stream, edm::Event const& event, edm::EventSetup const& setup) const { - processEvent(stream, event, setup, streamCache(stream)); + processEvent(event, setup, streamCache(stream)); } //**************************************************************************************** @@ -548,12 +540,11 @@ void EcalPhiSymRecHitProducerRun::globalEndRunProduce(edm::Run& run, edm::EventS auto cache = runCache(run.index()); //---put the collections in the Runs tree - auto ecalLumiInfo = std::make_unique(); - *ecalLumiInfo = cache->ecalLumiInfo; - auto recHitCollEB = std::make_unique(); - *recHitCollEB = cache->recHitCollEB; - auto recHitCollEE = std::make_unique(); - *recHitCollEE = cache->recHitCollEE; + auto ecalLumiInfo = std::make_unique(cache->ecalLumiInfo); + ecalLumiInfo->setMiscalibInfo( + nMisCalib_ * 2, misCalibRangeEB_[0], misCalibRangeEB_[1], misCalibRangeEE_[0], misCalibRangeEE_[1]); + auto recHitCollEB = std::make_unique(cache->recHitCollEB); + auto recHitCollEE = std::make_unique(cache->recHitCollEE); run.put(std::move(ecalLumiInfo)); run.put(std::move(recHitCollEB), "EB"); @@ -563,10 +554,8 @@ void EcalPhiSymRecHitProducerRun::globalEndRunProduce(edm::Run& run, edm::EventS void EcalPhiSymRecHitProducerRun::accumulate(edm::StreamID stream, edm::Event const& event, edm::EventSetup const& setup) const { - processEvent(stream, event, setup, streamCache(stream)); + processEvent(event, setup, streamCache(stream)); } DEFINE_FWK_MODULE(EcalPhiSymRecHitProducerLumi); DEFINE_FWK_MODULE(EcalPhiSymRecHitProducerRun); - -#endif diff --git a/Calibration/EcalCalibAlgos/python/EcalPhiSymFlatTableProducers_cfi.py b/Calibration/EcalCalibAlgos/python/EcalPhiSymFlatTableProducers_cfi.py index 3eb9910093f48..325baf447171e 100644 --- a/Calibration/EcalCalibAlgos/python/EcalPhiSymFlatTableProducers_cfi.py +++ b/Calibration/EcalCalibAlgos/python/EcalPhiSymFlatTableProducers_cfi.py @@ -8,13 +8,13 @@ name = cms.string("EcalPhiSymEB"), doc = cms.string("ECAL RecHits with information summed over a LS"), variables = cms.PSet( - id = Var("GetRawId()", int, doc="ECAL PhiSym rechits: channel detector id"), - status = Var("GetStatusCode()", int, doc="ECAL PhiSym rechits: channel status"), - nHits = Var("GetNhits()", int, doc="ECAL PhiSym rechits: number of recorded hits"), - sumEt = Var("GetSumEt(0)", float, doc="ECAL PhiSym rechits: nominal et", precision=23), - sumEt2 = Var("GetSumEt2()", float, doc="ECAL PhiSym rechits: sum et^2", precision=23), - sumLC = Var("GetLCSum()", float, doc="ECAL PhiSym rechits: laser correction", precision=23), - sumLC2 = Var("GetLC2Sum()", float, doc="ECAL PhiSym rechits: sum lc^2", precision=23) + id = Var("rawId()", int, doc="ECAL PhiSym rechits: channel detector id"), + status = Var("statusCode()", int, doc="ECAL PhiSym rechits: channel status"), + nHits = Var("nHits()", int, doc="ECAL PhiSym rechits: number of recorded hits"), + sumEt = Var("sumEt(0)", float, doc="ECAL PhiSym rechits: nominal et", precision=23), + sumEt2 = Var("sumEt2()", float, doc="ECAL PhiSym rechits: sum et^2", precision=23), + sumLC = Var("lcSum()", float, doc="ECAL PhiSym rechits: laser correction", precision=23), + sumLC2 = Var("lc2Sum()", float, doc="ECAL PhiSym rechits: sum lc^2", precision=23) ) ) @@ -34,8 +34,14 @@ nEvents = Var("nEvents()", int, doc="Total number of events recorded"), nLumis = Var("nLumis()", int, doc="Total number of lumis recorded"), fill = Var("fillNumber()", int, doc="LHC fill number"), - delivLumi = Var("delivLumi()", int, doc="LHC delivered integrated luminosity"), - recLumi = Var("recLumi()", int, doc="CMS recorded integrated luminosity"))) + delivLumi = Var("delivLumi()", float, doc="LHC delivered integrated luminosity"), + recLumi = Var("recLumi()", float, doc="CMS recorded integrated luminosity"), + nMis = Var("nMis()", float, doc="Number of mis-calibration steps injected (nominal value excluded)"), + minMisEB = Var("minMisEB()", float, doc="Minimum mis-calibration value in EB"), + maxMisEB = Var("maxMisEB()", float, doc="Maximum mis-calibration value in EB"), + minMisEE = Var("minMisEE()", float, doc="Minimum mis-calibration value in EE"), + maxMisEE = Var("maxMisEE()", float, doc="Maximum mis-calibration value in EE"))) + # Run flat table producers ecalPhiSymRecHitRunTableEB = cms.EDProducer("EcalPhiSymRecHitFlatTableProducerRun", diff --git a/Calibration/EcalCalibAlgos/python/EcalPhiSymRecoSequence_cff.py b/Calibration/EcalCalibAlgos/python/EcalPhiSymRecoSequence_cff.py index 062405aafe3c2..933de5dacc7cd 100644 --- a/Calibration/EcalCalibAlgos/python/EcalPhiSymRecoSequence_cff.py +++ b/Calibration/EcalCalibAlgos/python/EcalPhiSymRecoSequence_cff.py @@ -71,11 +71,11 @@ def ecal_phisym_flattables(process, produce_by_run : bool=False): for imis in range(1, nmis+1): # get the naming and indexing right. if imis& etValues, un lcSum_(0), lc2Sum_(0) {} -//**********destructor******************************************************************** -EcalPhiSymRecHit::~EcalPhiSymRecHit() {} - //**********utils************************************************************************* - -void EcalPhiSymRecHit::AddHit(float* etValues, float laserCorr) { +void EcalPhiSymRecHit::addHit(const std::vector& etValues, const float laserCorr) { if (etValues[0] > 0.) { ++nHits_; - etSum_[0] += etValues[0]; et2Sum_ += etValues[0] * etValues[0]; lcSum_ += laserCorr; lc2Sum_ += laserCorr * laserCorr; } - for (unsigned int i = 0; i < etSum_.size(); ++i) + for (unsigned int i = 0; i < std::min(etSum_.size(), etValues.size()); ++i) etSum_[i] += etValues[i]; } -void EcalPhiSymRecHit::AddHit(std::vector& etValues, float laserCorr) { AddHit(etValues.data()); } - -void EcalPhiSymRecHit::Reset() { +void EcalPhiSymRecHit::reset() { nHits_ = 0.; et2Sum_ = 0.; lcSum_ = 0.; @@ -48,13 +41,13 @@ void EcalPhiSymRecHit::Reset() { EcalPhiSymRecHit& EcalPhiSymRecHit::operator+=(const EcalPhiSymRecHit& rhs) { // assume same id, do not check channel status assert("EcalPhiSymRecHit operator+= : attempting to sum RecHits belonging to different channels" && - (id_ == rhs.GetRawId())); - nHits_ += rhs.GetNhits(); - et2Sum_ += rhs.GetSumEt2(); - lcSum_ += rhs.GetLCSum(); - lc2Sum_ += rhs.GetLC2Sum(); + (id_ == rhs.rawId())); + nHits_ += rhs.nHits(); + et2Sum_ += rhs.sumEt2(); + lcSum_ += rhs.lcSum(); + lc2Sum_ += rhs.lc2Sum(); for (unsigned int i = 0; i < etSum_.size(); ++i) - etSum_[i] += rhs.GetSumEt(i); + etSum_[i] += rhs.sumEt(i); return *this; } diff --git a/Calibration/EcalCalibAlgos/src/classes.h b/Calibration/EcalCalibAlgos/src/classes.h index 471c7cd595c42..489385c5632c2 100644 --- a/Calibration/EcalCalibAlgos/src/classes.h +++ b/Calibration/EcalCalibAlgos/src/classes.h @@ -1,3 +1,6 @@ +#ifndef Calibration_EcalCalibAlgos_classes_h +#define Calibration_EcalCalibAlgos_classes_h + #include "DataFormats/Common/interface/Wrapper.h" #include "Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h" @@ -14,3 +17,5 @@ namespace { edm::Wrapper dummy23; }; } // namespace + +#endif diff --git a/Calibration/EcalCalibAlgos/test/EcalPhiSymReco_cfg.py b/Calibration/EcalCalibAlgos/test/EcalPhiSymReco_cfg.py index 29c348a1332d6..d8937b4e8f1ed 100644 --- a/Calibration/EcalCalibAlgos/test/EcalPhiSymReco_cfg.py +++ b/Calibration/EcalCalibAlgos/test/EcalPhiSymReco_cfg.py @@ -38,11 +38,9 @@ process.load('Configuration.Geometry.GeometryExtended2018Reco_cff') process.load('Configuration.Geometry.GeometryExtended2018Reco_cff') -from CondCore.CondDB.CondDB_cfi import * -process.GlobalTag = cms.ESSource("PoolDBESSource", - connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS'), - globaltag = cms.string('123X_dataRun2_v1') -) +# use auto:run2_data to be able to test on run2 data for the time being. +from Configuration.AlCa.GlobalTag import GlobalTag +process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_data', '') # Source data # skip bad events From 4d3d7c80a682f3bfa2fe26e2a9ed0f3be2b8e3fd Mon Sep 17 00:00:00 2001 From: Simone Pigazzi Date: Sat, 19 Feb 2022 23:38:40 +0100 Subject: [PATCH 06/13] iring for EE channels --- .../interface/EcalPhiSymRecHit.h | 5 +++ .../plugins/EcalPhiSymRecHitProducers.cc | 37 +++++++++---------- .../EcalPhiSymFlatTableProducers_cfi.py | 4 ++ .../EcalCalibAlgos/src/EcalPhiSymRecHit.cc | 5 ++- Calibration/EcalCalibAlgos/src/classes.h | 12 ------ 5 files changed, 30 insertions(+), 33 deletions(-) diff --git a/Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h b/Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h index f1af83d73f303..8526bcc28bc96 100644 --- a/Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h +++ b/Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h @@ -33,6 +33,7 @@ class EcalPhiSymRecHit { //---getters--- inline uint32_t rawId() const { return id_; }; + inline int8_t eeRing() const { return eeRing_; }; inline unsigned int statusCode() const { return chStatus_; }; inline uint32_t nHits() const { return nHits_; }; inline unsigned int nSumEt() const { return etSum_.size(); }; @@ -41,6 +42,9 @@ class EcalPhiSymRecHit { inline float lcSum() const { return lcSum_; }; inline float lc2Sum() const { return lc2Sum_; }; + //---setters--- + void setEERing(const int8_t& eering) { eeRing_ = eering; }; + //---utils--- void addHit(const std::vector& etValues, const float laserCorr = 0); void reset(); @@ -50,6 +54,7 @@ class EcalPhiSymRecHit { private: uint32_t id_; + int8_t eeRing_; unsigned int chStatus_; uint32_t nHits_; std::vector etSum_; diff --git a/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc index ed31d84497f1d..84553524d91c4 100644 --- a/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc +++ b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc @@ -41,11 +41,9 @@ #include "Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h" #include "Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h" -using namespace std; - //---Wrapper to handle cross-stream data struct PhiSymCache { - mutable EcalPhiSymInfo ecalLumiInfo; + mutable EcalPhiSymInfo ecalLumiInfo; mutable EcalPhiSymRecHitCollection recHitCollEB; mutable EcalPhiSymRecHitCollection recHitCollEE; @@ -88,17 +86,17 @@ class EcalPhiSymRecHitProducerBase { mutable edm::EDGetTokenT ebToken_; mutable edm::EDGetTokenT eeToken_; float etCutEB_; - vector eThresholdsEB_; + std::vector eThresholdsEB_; float etCutEE_; - vector A_; - vector B_; + std::vector A_; + std::vector B_; float thrEEmod_; int nMisCalib_; int nSumEtValues_; - vector misCalibRangeEB_; - vector misCalibStepsEB_; - vector misCalibRangeEE_; - vector misCalibStepsEE_; + std::vector misCalibRangeEB_; + std::vector misCalibStepsEB_; + std::vector misCalibRangeEE_; + std::vector misCalibStepsEE_; //---geometry EcalRingCalibrationTools calibRing_; static const short kNRingsEB = EcalRingCalibrationTools::N_RING_BARREL; @@ -116,15 +114,15 @@ EcalPhiSymRecHitProducerBase::EcalPhiSymRecHitProducerBase(const edm::ParameterS ebToken_(cc.consumes(pSet.getParameter("barrelHitCollection"))), eeToken_(cc.consumes(pSet.getParameter("endcapHitCollection"))), etCutEB_(pSet.getParameter("etCut_barrel")), - eThresholdsEB_(pSet.getParameter >("eThresholds_barrel")), + eThresholdsEB_(pSet.getParameter >("eThresholds_barrel")), etCutEE_(pSet.getParameter("etCut_endcap")), - A_(pSet.getParameter >("A")), - B_(pSet.getParameter >("B")), + A_(pSet.getParameter >("A")), + B_(pSet.getParameter >("B")), thrEEmod_(pSet.getParameter("thrEEmod")), nMisCalib_(pSet.getParameter("nMisCalib") / 2), nSumEtValues_(nMisCalib_ * 2 + 1), - misCalibRangeEB_(pSet.getParameter >("misCalibRangeEB")), - misCalibRangeEE_(pSet.getParameter >("misCalibRangeEE")) {} + misCalibRangeEB_(pSet.getParameter >("misCalibRangeEB")), + misCalibRangeEE_(pSet.getParameter >("misCalibRangeEE")) {} void EcalPhiSymRecHitProducerBase::initializeJob() { //---set E thresholds, Et cuts and miscalib steps @@ -185,7 +183,7 @@ void EcalPhiSymRecHitProducerBase::processEvent(edm::Event const& event, float eta = barrelGeometry->getGeometry(ebHit)->getPosition().eta(); //---compute et + miscalibration - vector etValues(nSumEtValues_, 0); + std::vector etValues(nSumEtValues_, 0); //---one can do this in one for loop from -nMis to +nMis but in this way the //---program is faster //---NOTE: nMisCalib is half on the value set in the cfg python @@ -227,7 +225,7 @@ void EcalPhiSymRecHitProducerBase::processEvent(edm::Event const& event, float eta = endcapGeometry->getGeometry(eeHit)->getPosition().eta(); //---compute et + miscalibration - vector etValues(nSumEtValues_, 0); + std::vector etValues(nSumEtValues_, 0); //---one can do this in one for loop from -nMis to +nMis but in this way the //---program is faster //---NOTE: nMisCalib is half on the value set in the cfg python @@ -317,6 +315,7 @@ void EcalPhiSymRecHitProducerBase::initializeGlobalCache( int ring = calibRing_.getRingIndex(id) - kNRingsEB; cache->recHitCollEE.at(id.denseIndex()) = EcalPhiSymRecHit(eeDetId.rawId(), nSumEtValues_, chStatus[id].getStatusCode()); + cache->recHitCollEE.at(id.denseIndex()).setEERing(ringgetGeometry(id); @@ -332,7 +331,7 @@ void EcalPhiSymRecHitProducerBase::sumCache(PhiSymCache* streamCache, PhiSymCach // in the sum to make sure that info like fillNumber and channel status // are preserved since they are set in the global initialization and not // in the stream one. - cache->ecalLumiInfo += streamCache->ecalLumiInfo; + cache->ecalLumiInfo += streamCache->ecalLumiInfo; for (unsigned int i = 0; i < cache->recHitCollEB.size(); ++i) cache->recHitCollEB[i] += streamCache->recHitCollEB[i]; @@ -418,7 +417,7 @@ void EcalPhiSymRecHitProducerLumi::globalEndLuminosityBlockProduce(edm::Luminosi ecalLumiInfo->setMiscalibInfo( nMisCalib_ * 2, misCalibRangeEB_[0], misCalibRangeEB_[1], misCalibRangeEE_[0], misCalibRangeEE_[1]); auto recHitCollEB = std::make_unique(cache->recHitCollEB); - auto recHitCollEE = std::make_unique(cache->recHitCollEB); + auto recHitCollEE = std::make_unique(cache->recHitCollEE); lumi.put(std::move(ecalLumiInfo)); lumi.put(std::move(recHitCollEB), "EB"); diff --git a/Calibration/EcalCalibAlgos/python/EcalPhiSymFlatTableProducers_cfi.py b/Calibration/EcalCalibAlgos/python/EcalPhiSymFlatTableProducers_cfi.py index 325baf447171e..a140fb14c4548 100644 --- a/Calibration/EcalCalibAlgos/python/EcalPhiSymFlatTableProducers_cfi.py +++ b/Calibration/EcalCalibAlgos/python/EcalPhiSymFlatTableProducers_cfi.py @@ -22,6 +22,8 @@ src = cms.InputTag("EcalPhiSymRecHitProducerLumi", "EE"), name = cms.string("EcalPhiSymEE") ) +# iring is saved only for EE channels +setattr(ecalPhiSymRecHitLumiTableEE.variables, 'ring', Var("eeRing()", int, doc="ECAL PhiSym rechits: EE channel ring index")) ecalPhiSymInfoLumiTable = cms.EDProducer("EcalPhiSymInfoFlatTableProducerLumi", src = cms.InputTag("EcalPhiSymRecHitProducerLumi"), @@ -57,6 +59,8 @@ src = cms.InputTag("EcalPhiSymRecHitProducerRun", "EE"), name = cms.string("EcalPhiSymEE") ) +# iring is saved only for EE channels +setattr(ecalPhiSymRecHitRunTableEE.variables, 'ring', Var("eeRing()", int, doc="ECAL PhiSym rechits: EE channel ring index")) ecalPhiSymInfoRunTable = cms.EDProducer("EcalPhiSymInfoFlatTableProducerRun", src = cms.InputTag("EcalPhiSymRecHitProducerRun"), diff --git a/Calibration/EcalCalibAlgos/src/EcalPhiSymRecHit.cc b/Calibration/EcalCalibAlgos/src/EcalPhiSymRecHit.cc index 5ba5a8e1750bf..cde93e0d6220e 100644 --- a/Calibration/EcalCalibAlgos/src/EcalPhiSymRecHit.cc +++ b/Calibration/EcalCalibAlgos/src/EcalPhiSymRecHit.cc @@ -2,13 +2,14 @@ //**********constructors****************************************************************** EcalPhiSymRecHit::EcalPhiSymRecHit() - : id_(0), chStatus_(0), nHits_(0), etSum_(1, 0.), et2Sum_(0), lcSum_(0), lc2Sum_(0) {} + : id_(0), eeRing_(0), chStatus_(0), nHits_(0), etSum_(1, 0.), et2Sum_(0), lcSum_(0), lc2Sum_(0) {} EcalPhiSymRecHit::EcalPhiSymRecHit(uint32_t id, unsigned int nMisCalibV, unsigned int status) - : id_(id), chStatus_(status), nHits_(0), etSum_(nMisCalibV, 0.), et2Sum_(0), lcSum_(0), lc2Sum_(0) {} + : id_(id), eeRing_(0), chStatus_(status), nHits_(0), etSum_(nMisCalibV, 0.), et2Sum_(0), lcSum_(0), lc2Sum_(0) {} EcalPhiSymRecHit::EcalPhiSymRecHit(uint32_t id, std::vector& etValues, unsigned int status) : id_(id), + eeRing_(0), chStatus_(status), nHits_(0), etSum_(etValues.begin(), etValues.end()), diff --git a/Calibration/EcalCalibAlgos/src/classes.h b/Calibration/EcalCalibAlgos/src/classes.h index 489385c5632c2..07fd7ba7baf0f 100644 --- a/Calibration/EcalCalibAlgos/src/classes.h +++ b/Calibration/EcalCalibAlgos/src/classes.h @@ -6,16 +6,4 @@ #include "Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h" #include "Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h" -namespace { - struct dictionary { - EcalPhiSymRecHit dummy11; - std::vector dummy12; - edm::Wrapper dummy13; - - EcalPhiSymInfo dummy21; - std::vector dummy22; - edm::Wrapper dummy23; - }; -} // namespace - #endif From 2bb0e06f6fee6e501bcbe1e10de599ac398206cb Mon Sep 17 00:00:00 2001 From: Simone Pigazzi Date: Mon, 21 Feb 2022 11:04:25 +0100 Subject: [PATCH 07/13] using tbb::concurrent_vector to improve thread safety --- .../plugins/EcalPhiSymRecHitProducers.cc | 66 +++++++++++-------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc index 84553524d91c4..1a3303fd08287 100644 --- a/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc +++ b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc @@ -43,12 +43,25 @@ //---Wrapper to handle cross-stream data struct PhiSymCache { + mutable tbb::concurrent_vector ecalLumiInfo; + mutable tbb::concurrent_vector recHitCollEB; + mutable tbb::concurrent_vector recHitCollEE; + + void clear() { + ecalLumiInfo.clear(); + recHitCollEB.clear(); + recHitCollEE.clear(); + } +}; + +//---Wrapper to handle stream data +struct PhiSymStreamCache { mutable EcalPhiSymInfo ecalLumiInfo; - mutable EcalPhiSymRecHitCollection recHitCollEB; - mutable EcalPhiSymRecHitCollection recHitCollEE; + mutable EcalPhiSymRecHitCollection recHitCollEB; + mutable EcalPhiSymRecHitCollection recHitCollEE; void clear() { - ecalLumiInfo = EcalPhiSymInfo(); + ecalLumiInfo = EcalPhiSymInfo(); recHitCollEB.clear(); recHitCollEE.clear(); } @@ -67,14 +80,14 @@ class EcalPhiSymRecHitProducerBase { // job void initializeJob(); // event - void processEvent(edm::Event const& event, edm::EventSetup const& setup, PhiSymCache* cache) const; + void processEvent(edm::Event const& event, edm::EventSetup const& setup, PhiSymStreamCache* cache) const; // helpers - void initializeStreamCache(PhiSymCache* cache) const; + void initializeStreamCache(PhiSymStreamCache* cache) const; void initializeGlobalCache(edm::EventSetup const& setup, edm::ESGetToken const& chStatusToken, edm::ESGetToken const& geoToken, std::shared_ptr& cache) const; - void sumCache(PhiSymCache* streamCache, PhiSymCache const* cache) const; + void sumCache(PhiSymStreamCache* streamCache, PhiSymCache const* cache) const; //---data memebers // available to derived classes @@ -155,7 +168,7 @@ void EcalPhiSymRecHitProducerBase::initializeJob() { void EcalPhiSymRecHitProducerBase::processEvent(edm::Event const& event, edm::EventSetup const& setup, - PhiSymCache* streamCache) const { + PhiSymStreamCache* streamCache) const { uint64_t totHitsEB = 0; uint64_t totHitsEE = 0; @@ -261,7 +274,7 @@ void EcalPhiSymRecHitProducerBase::processEvent(edm::Event const& event, streamCache->ecalLumiInfo += thisEvent; } -void EcalPhiSymRecHitProducerBase::initializeStreamCache(PhiSymCache* cache) const { +void EcalPhiSymRecHitProducerBase::initializeStreamCache(PhiSymStreamCache* cache) const { //---Initialize the per-stream RecHitCollection // both collections are initialized to contain the total // number of crystals, ordered accrodingly to the hashedIndex. @@ -325,13 +338,13 @@ void EcalPhiSymRecHitProducerBase::initializeGlobalCache( } } -void EcalPhiSymRecHitProducerBase::sumCache(PhiSymCache* streamCache, PhiSymCache const* cache) const { +void EcalPhiSymRecHitProducerBase::sumCache(PhiSymStreamCache* streamCache, PhiSymCache const* cache) const { //--- this could be improved. // One has to make sure that the streamCache is the right hand argument // in the sum to make sure that info like fillNumber and channel status // are preserved since they are set in the global initialization and not // in the stream one. - cache->ecalLumiInfo += streamCache->ecalLumiInfo; + cache->ecalLumiInfo[0] += streamCache->ecalLumiInfo; for (unsigned int i = 0; i < cache->recHitCollEB.size(); ++i) cache->recHitCollEB[i] += streamCache->recHitCollEB[i]; @@ -341,7 +354,7 @@ void EcalPhiSymRecHitProducerBase::sumCache(PhiSymCache* streamCache, PhiSymCach //**************************************************************************************** // Lumi producer -class EcalPhiSymRecHitProducerLumi : public edm::global::EDProducer, +class EcalPhiSymRecHitProducerLumi : public edm::global::EDProducer, edm::LuminosityBlockCache, edm::EndLuminosityBlockProducer, edm::Accumulator>, @@ -360,7 +373,7 @@ class EcalPhiSymRecHitProducerLumi : public edm::global::EDProducer beginStream(edm::StreamID stream) const override; + std::unique_ptr beginStream(edm::StreamID stream) const override; void streamBeginLuminosityBlock(edm::StreamID stream, edm::LuminosityBlock const& lumi, edm::EventSetup const& setup) const override; @@ -398,14 +411,14 @@ std::shared_ptr EcalPhiSymRecHitProducerLumi::globalBeginLuminosity //---Reset global cache initializeGlobalCache(setup, chStatusTokenLumi_, geoTokenLumi_, cache); - cache->ecalLumiInfo += thisLumi; + cache->ecalLumiInfo.push_back(thisLumi); return cache; } -std::unique_ptr EcalPhiSymRecHitProducerLumi::beginStream(edm::StreamID stream) const { +std::unique_ptr EcalPhiSymRecHitProducerLumi::beginStream(edm::StreamID stream) const { //---create stream cache - return std::make_unique(); + return std::make_unique(); } void EcalPhiSymRecHitProducerLumi::globalEndLuminosityBlockProduce(edm::LuminosityBlock& lumi, @@ -413,11 +426,11 @@ void EcalPhiSymRecHitProducerLumi::globalEndLuminosityBlockProduce(edm::Luminosi auto cache = luminosityBlockCache(lumi.index()); //---put the collections in the LuminosityBlocks tree - auto ecalLumiInfo = std::make_unique(cache->ecalLumiInfo); + auto ecalLumiInfo = std::make_unique(cache->ecalLumiInfo[0]); ecalLumiInfo->setMiscalibInfo( nMisCalib_ * 2, misCalibRangeEB_[0], misCalibRangeEB_[1], misCalibRangeEE_[0], misCalibRangeEE_[1]); - auto recHitCollEB = std::make_unique(cache->recHitCollEB); - auto recHitCollEE = std::make_unique(cache->recHitCollEE); + auto recHitCollEB = std::make_unique(cache->recHitCollEB.begin(), cache->recHitCollEB.end()); + auto recHitCollEE = std::make_unique(cache->recHitCollEE.begin(), cache->recHitCollEE.end()); lumi.put(std::move(ecalLumiInfo)); lumi.put(std::move(recHitCollEB), "EB"); @@ -446,7 +459,7 @@ void EcalPhiSymRecHitProducerLumi::accumulate(edm::StreamID stream, //**************************************************************************************** // Run producer -class EcalPhiSymRecHitProducerRun : public edm::global::EDProducer, +class EcalPhiSymRecHitProducerRun : public edm::global::EDProducer, edm::RunCache, edm::LuminosityBlockCache, edm::EndRunProducer, @@ -469,7 +482,7 @@ class EcalPhiSymRecHitProducerRun : public edm::global::EDProducer beginStream(edm::StreamID stream) const override; + std::unique_ptr beginStream(edm::StreamID stream) const override; void streamBeginRun(edm::StreamID stream, edm::Run const& run, edm::EventSetup const& setup) const override; void streamEndRun(edm::StreamID stream, edm::Run const& run, edm::EventSetup const& setup) const override; // event @@ -495,6 +508,7 @@ EcalPhiSymRecHitProducerRun::EcalPhiSymRecHitProducerRun(const edm::ParameterSet std::shared_ptr EcalPhiSymRecHitProducerRun::globalBeginRun(edm::Run const& run, edm::EventSetup const& setup) const { auto cache = std::make_shared(); + cache->ecalLumiInfo.push_back(EcalPhiSymInfo()); initializeGlobalCache(setup, chStatusTokenRun_, geoTokenRun_, cache); return cache; } @@ -510,15 +524,15 @@ std::shared_ptr EcalPhiSymRecHitProducerRun::globalBeginLuminosityB const auto& lhcinfo = setup.getData(lhcInfoTokenLumi_); EcalPhiSymInfo thisLumi(0, 0, 0, 1, lhcinfo.fillNumber(), lhcinfo.delivLumi(), lhcinfo.recLumi()); - runCache(lumi.getRun().index())->ecalLumiInfo += thisLumi; + runCache(lumi.getRun().index())->ecalLumiInfo[0] += thisLumi; // dummy cache, it won't be used return std::make_shared(); } -std::unique_ptr EcalPhiSymRecHitProducerRun::beginStream(edm::StreamID stream) const { +std::unique_ptr EcalPhiSymRecHitProducerRun::beginStream(edm::StreamID stream) const { //---create stream cache - return std::make_unique(); + return std::make_unique(); } void EcalPhiSymRecHitProducerRun::streamBeginRun(edm::StreamID stream, @@ -539,11 +553,11 @@ void EcalPhiSymRecHitProducerRun::globalEndRunProduce(edm::Run& run, edm::EventS auto cache = runCache(run.index()); //---put the collections in the Runs tree - auto ecalLumiInfo = std::make_unique(cache->ecalLumiInfo); + auto ecalLumiInfo = std::make_unique(cache->ecalLumiInfo[0]); ecalLumiInfo->setMiscalibInfo( nMisCalib_ * 2, misCalibRangeEB_[0], misCalibRangeEB_[1], misCalibRangeEE_[0], misCalibRangeEE_[1]); - auto recHitCollEB = std::make_unique(cache->recHitCollEB); - auto recHitCollEE = std::make_unique(cache->recHitCollEE); + auto recHitCollEB = std::make_unique(cache->recHitCollEB.begin(), cache->recHitCollEB.end()); + auto recHitCollEE = std::make_unique(cache->recHitCollEE.begin(), cache->recHitCollEE.end()); run.put(std::move(ecalLumiInfo)); run.put(std::move(recHitCollEB), "EB"); From 2c7c134552098da621d0d8b66260bbd5aaa7bb04 Mon Sep 17 00:00:00 2001 From: Simone Pigazzi Date: Tue, 22 Feb 2022 10:42:46 +0100 Subject: [PATCH 08/13] producers working in multithread mode --- .../interface/EcalPhiSymRecHit.h | 10 +- .../plugins/EcalPhiSymRecHitProducers.cc | 125 +++++++++--------- .../EcalCalibAlgos/src/EcalPhiSymRecHit.cc | 2 +- 3 files changed, 69 insertions(+), 68 deletions(-) diff --git a/Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h b/Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h index 8526bcc28bc96..b553f5a36a5e5 100644 --- a/Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h +++ b/Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h @@ -33,7 +33,7 @@ class EcalPhiSymRecHit { //---getters--- inline uint32_t rawId() const { return id_; }; - inline int8_t eeRing() const { return eeRing_; }; + inline int8_t eeRing() const { return eeRing_; }; inline unsigned int statusCode() const { return chStatus_; }; inline uint32_t nHits() const { return nHits_; }; inline unsigned int nSumEt() const { return etSum_.size(); }; @@ -42,9 +42,9 @@ class EcalPhiSymRecHit { inline float lcSum() const { return lcSum_; }; inline float lc2Sum() const { return lc2Sum_; }; - //---setters--- - void setEERing(const int8_t& eering) { eeRing_ = eering; }; - + //---setters--- + void setEERing(const int8_t& eering) { eeRing_ = eering; }; + //---utils--- void addHit(const std::vector& etValues, const float laserCorr = 0); void reset(); @@ -54,7 +54,7 @@ class EcalPhiSymRecHit { private: uint32_t id_; - int8_t eeRing_; + int8_t eeRing_; unsigned int chStatus_; uint32_t nHits_; std::vector etSum_; diff --git a/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc index 1a3303fd08287..83ab07fc54c4d 100644 --- a/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc +++ b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc @@ -41,30 +41,23 @@ #include "Calibration/EcalCalibAlgos/interface/EcalPhiSymRecHit.h" #include "Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h" -//---Wrapper to handle cross-stream data -struct PhiSymCache { - mutable tbb::concurrent_vector ecalLumiInfo; - mutable tbb::concurrent_vector recHitCollEB; - mutable tbb::concurrent_vector recHitCollEE; +//---Wrapper to handle stream data +struct PhiSymStreamCache { + mutable EcalPhiSymInfo ecalLumiInfo; + mutable EcalPhiSymRecHitCollection recHitCollEB; + mutable EcalPhiSymRecHitCollection recHitCollEE; void clear() { - ecalLumiInfo.clear(); + ecalLumiInfo = EcalPhiSymInfo(); recHitCollEB.clear(); recHitCollEE.clear(); } }; -//---Wrapper to handle stream data -struct PhiSymStreamCache { - mutable EcalPhiSymInfo ecalLumiInfo; - mutable EcalPhiSymRecHitCollection recHitCollEB; - mutable EcalPhiSymRecHitCollection recHitCollEE; +struct PhiSymCache { + mutable tbb::concurrent_vector c; - void clear() { - ecalLumiInfo = EcalPhiSymInfo(); - recHitCollEB.clear(); - recHitCollEE.clear(); - } + void clear() { c.clear(); } }; //**************************************************************************************** @@ -86,8 +79,8 @@ class EcalPhiSymRecHitProducerBase { void initializeGlobalCache(edm::EventSetup const& setup, edm::ESGetToken const& chStatusToken, edm::ESGetToken const& geoToken, - std::shared_ptr& cache) const; - void sumCache(PhiSymStreamCache* streamCache, PhiSymCache const* cache) const; + std::shared_ptr& vcache) const; + void sumCache(tbb::concurrent_vector& vcache) const; //---data memebers // available to derived classes @@ -99,7 +92,7 @@ class EcalPhiSymRecHitProducerBase { mutable edm::EDGetTokenT ebToken_; mutable edm::EDGetTokenT eeToken_; float etCutEB_; - std::vector eThresholdsEB_; + std::vector eThresholdsEB_; float etCutEE_; std::vector A_; std::vector B_; @@ -295,8 +288,11 @@ void EcalPhiSymRecHitProducerBase::initializeGlobalCache( edm::EventSetup const& setup, edm::ESGetToken const& chStatusToken, edm::ESGetToken const& geoToken, - std::shared_ptr& cache) const { - cache->clear(); + std::shared_ptr& vcache) const { + vcache->c.clear(); + vcache->c.push_back(PhiSymStreamCache()); + + auto& cache = vcache->c[0]; //---get the ecal geometry const auto* geometry = &setup.getData(geoToken); @@ -309,11 +305,11 @@ void EcalPhiSymRecHitProducerBase::initializeGlobalCache( const auto* endcapGeometry = geometry->getSubdetectorGeometry(DetId::Ecal, EcalEndcap); barrelDetIds_ = barrelGeometry->getValidDetIds(DetId::Ecal, EcalBarrel); endcapDetIds_ = endcapGeometry->getValidDetIds(DetId::Ecal, EcalEndcap); - cache->recHitCollEB.resize(barrelDetIds_.size()); - cache->recHitCollEE.resize(endcapDetIds_.size()); + cache.recHitCollEB.resize(barrelDetIds_.size()); + cache.recHitCollEE.resize(endcapDetIds_.size()); for (auto& ebDetId : barrelDetIds_) { EBDetId id(ebDetId); - cache->recHitCollEB.at(id.denseIndex()) = + cache.recHitCollEB.at(id.denseIndex()) = EcalPhiSymRecHit(ebDetId.rawId(), nSumEtValues_, chStatus[id].getStatusCode()); int ring = calibRing_.getRingIndex(id); //---set etCut if first pass @@ -326,9 +322,10 @@ void EcalPhiSymRecHitProducerBase::initializeGlobalCache( for (auto& eeDetId : endcapDetIds_) { EEDetId id(eeDetId); int ring = calibRing_.getRingIndex(id) - kNRingsEB; - cache->recHitCollEE.at(id.denseIndex()) = + cache.recHitCollEE.at(id.denseIndex()) = EcalPhiSymRecHit(eeDetId.rawId(), nSumEtValues_, chStatus[id].getStatusCode()); - cache->recHitCollEE.at(id.denseIndex()).setEERing(ringgetGeometry(id); @@ -338,18 +335,17 @@ void EcalPhiSymRecHitProducerBase::initializeGlobalCache( } } -void EcalPhiSymRecHitProducerBase::sumCache(PhiSymStreamCache* streamCache, PhiSymCache const* cache) const { - //--- this could be improved. - // One has to make sure that the streamCache is the right hand argument - // in the sum to make sure that info like fillNumber and channel status - // are preserved since they are set in the global initialization and not - // in the stream one. - cache->ecalLumiInfo[0] += streamCache->ecalLumiInfo; - - for (unsigned int i = 0; i < cache->recHitCollEB.size(); ++i) - cache->recHitCollEB[i] += streamCache->recHitCollEB[i]; - for (unsigned int i = 0; i < cache->recHitCollEE.size(); ++i) - cache->recHitCollEE[i] += streamCache->recHitCollEE[i]; +void EcalPhiSymRecHitProducerBase::sumCache(tbb::concurrent_vector& vcache) const { + //---The first element of the cache is the "global" cache that + // contains static global information. The stream partial sums are + // stored from index=1 + for (unsigned int is = 1; is < vcache.size(); ++is) { + vcache[0].ecalLumiInfo += vcache[is].ecalLumiInfo; + for (unsigned int i = 0; i < vcache[0].recHitCollEB.size(); ++i) + vcache[0].recHitCollEB[i] += vcache[is].recHitCollEB[i]; + for (unsigned int i = 0; i < vcache[0].recHitCollEE.size(); ++i) + vcache[0].recHitCollEE[i] += vcache[is].recHitCollEE[i]; + } } //**************************************************************************************** @@ -381,7 +377,7 @@ class EcalPhiSymRecHitProducerLumi : public edm::global::EDProducer EcalPhiSymRecHitProducerLumi::globalBeginLuminosity //---Reset global cache initializeGlobalCache(setup, chStatusTokenLumi_, geoTokenLumi_, cache); - cache->ecalLumiInfo.push_back(thisLumi); + cache->c[0].ecalLumiInfo = thisLumi; return cache; } -std::unique_ptr EcalPhiSymRecHitProducerLumi::beginStream(edm::StreamID stream) const { - //---create stream cache - return std::make_unique(); -} - void EcalPhiSymRecHitProducerLumi::globalEndLuminosityBlockProduce(edm::LuminosityBlock& lumi, edm::EventSetup const& setup) const { - auto cache = luminosityBlockCache(lumi.index()); + auto& vcache = luminosityBlockCache(lumi.index())->c; + sumCache(vcache); //---put the collections in the LuminosityBlocks tree - auto ecalLumiInfo = std::make_unique(cache->ecalLumiInfo[0]); + auto ecalLumiInfo = std::make_unique(vcache[0].ecalLumiInfo); ecalLumiInfo->setMiscalibInfo( nMisCalib_ * 2, misCalibRangeEB_[0], misCalibRangeEB_[1], misCalibRangeEE_[0], misCalibRangeEE_[1]); - auto recHitCollEB = std::make_unique(cache->recHitCollEB.begin(), cache->recHitCollEB.end()); - auto recHitCollEE = std::make_unique(cache->recHitCollEE.begin(), cache->recHitCollEE.end()); + auto recHitCollEB = + std::make_unique(vcache[0].recHitCollEB.begin(), vcache[0].recHitCollEB.end()); + auto recHitCollEE = + std::make_unique(vcache[0].recHitCollEE.begin(), vcache[0].recHitCollEE.end()); lumi.put(std::move(ecalLumiInfo)); lumi.put(std::move(recHitCollEB), "EB"); lumi.put(std::move(recHitCollEE), "EE"); } +std::unique_ptr EcalPhiSymRecHitProducerLumi::beginStream(edm::StreamID stream) const { + //---create stream cache + return std::make_unique(); +} + void EcalPhiSymRecHitProducerLumi::streamBeginLuminosityBlock(edm::StreamID stream, edm::LuminosityBlock const& lumi, edm::EventSetup const& setup) const { - //---Reset cache + //---Reset stream cache initializeStreamCache(streamCache(stream)); } void EcalPhiSymRecHitProducerLumi::streamEndLuminosityBlock(edm::StreamID stream, edm::LuminosityBlock const& lumi, edm::EventSetup const& setup) const { - //---sum data from different streams into the common lumi cache - sumCache(streamCache(stream), luminosityBlockCache(lumi.index())); + //---add stream cache to global cache container + luminosityBlockCache(lumi.index())->c.push_back(*streamCache(stream)); } void EcalPhiSymRecHitProducerLumi::accumulate(edm::StreamID stream, @@ -482,7 +481,7 @@ class EcalPhiSymRecHitProducerRun : public edm::global::EDProducer beginStream(edm::StreamID stream) const override; + std::unique_ptr be overrideginStream(edm::StreamID stream) const override; void streamBeginRun(edm::StreamID stream, edm::Run const& run, edm::EventSetup const& setup) const override; void streamEndRun(edm::StreamID stream, edm::Run const& run, edm::EventSetup const& setup) const override; // event @@ -508,7 +507,6 @@ EcalPhiSymRecHitProducerRun::EcalPhiSymRecHitProducerRun(const edm::ParameterSet std::shared_ptr EcalPhiSymRecHitProducerRun::globalBeginRun(edm::Run const& run, edm::EventSetup const& setup) const { auto cache = std::make_shared(); - cache->ecalLumiInfo.push_back(EcalPhiSymInfo()); initializeGlobalCache(setup, chStatusTokenRun_, geoTokenRun_, cache); return cache; } @@ -524,7 +522,7 @@ std::shared_ptr EcalPhiSymRecHitProducerRun::globalBeginLuminosityB const auto& lhcinfo = setup.getData(lhcInfoTokenLumi_); EcalPhiSymInfo thisLumi(0, 0, 0, 1, lhcinfo.fillNumber(), lhcinfo.delivLumi(), lhcinfo.recLumi()); - runCache(lumi.getRun().index())->ecalLumiInfo[0] += thisLumi; + runCache(lumi.getRun().index())->c[0].ecalLumiInfo += thisLumi; // dummy cache, it won't be used return std::make_shared(); @@ -538,26 +536,29 @@ std::unique_ptr EcalPhiSymRecHitProducerRun::beginStream(edm: void EcalPhiSymRecHitProducerRun::streamBeginRun(edm::StreamID stream, edm::Run const& run, edm::EventSetup const& setup) const { - //---Reset global cache + //---Reset and add this stream cache to the global cache container. initializeStreamCache(streamCache(stream)); } void EcalPhiSymRecHitProducerRun::streamEndRun(edm::StreamID stream, edm::Run const& run, edm::EventSetup const& setup) const { - //---sum data from different streams into the common run cache - sumCache(streamCache(stream), runCache(run.index())); + //---add stream cache to global cache container + runCache(run.index())->c.push_back(*streamCache(stream)); } void EcalPhiSymRecHitProducerRun::globalEndRunProduce(edm::Run& run, edm::EventSetup const& setup) const { - auto cache = runCache(run.index()); + auto& vcache = runCache(run.index())->c; + sumCache(vcache); //---put the collections in the Runs tree - auto ecalLumiInfo = std::make_unique(cache->ecalLumiInfo[0]); + auto ecalLumiInfo = std::make_unique(vcache[0].ecalLumiInfo); ecalLumiInfo->setMiscalibInfo( nMisCalib_ * 2, misCalibRangeEB_[0], misCalibRangeEB_[1], misCalibRangeEE_[0], misCalibRangeEE_[1]); - auto recHitCollEB = std::make_unique(cache->recHitCollEB.begin(), cache->recHitCollEB.end()); - auto recHitCollEE = std::make_unique(cache->recHitCollEE.begin(), cache->recHitCollEE.end()); + auto recHitCollEB = + std::make_unique(vcache[0].recHitCollEB.begin(), vcache[0].recHitCollEB.end()); + auto recHitCollEE = + std::make_unique(vcache[0].recHitCollEE.begin(), vcache[0].recHitCollEE.end()); run.put(std::move(ecalLumiInfo)); run.put(std::move(recHitCollEB), "EB"); diff --git a/Calibration/EcalCalibAlgos/src/EcalPhiSymRecHit.cc b/Calibration/EcalCalibAlgos/src/EcalPhiSymRecHit.cc index cde93e0d6220e..d981ccbbf3bcc 100644 --- a/Calibration/EcalCalibAlgos/src/EcalPhiSymRecHit.cc +++ b/Calibration/EcalCalibAlgos/src/EcalPhiSymRecHit.cc @@ -9,7 +9,7 @@ EcalPhiSymRecHit::EcalPhiSymRecHit(uint32_t id, unsigned int nMisCalibV, unsigne EcalPhiSymRecHit::EcalPhiSymRecHit(uint32_t id, std::vector& etValues, unsigned int status) : id_(id), - eeRing_(0), + eeRing_(0), chStatus_(status), nHits_(0), etSum_(etValues.begin(), etValues.end()), From 277192837d561620f3cb213d5d83f044bbae1dff Mon Sep 17 00:00:00 2001 From: Simone Pigazzi Date: Tue, 22 Feb 2022 11:50:37 +0100 Subject: [PATCH 09/13] removing unnecessary mutables and renaming confusing method --- .../plugins/EcalPhiSymRecHitProducers.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc index 83ab07fc54c4d..79c364cff9963 100644 --- a/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc +++ b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc @@ -43,9 +43,9 @@ //---Wrapper to handle stream data struct PhiSymStreamCache { - mutable EcalPhiSymInfo ecalLumiInfo; - mutable EcalPhiSymRecHitCollection recHitCollEB; - mutable EcalPhiSymRecHitCollection recHitCollEE; + EcalPhiSymInfo ecalLumiInfo; + EcalPhiSymRecHitCollection recHitCollEB; + EcalPhiSymRecHitCollection recHitCollEE; void clear() { ecalLumiInfo = EcalPhiSymInfo(); @@ -76,7 +76,7 @@ class EcalPhiSymRecHitProducerBase { void processEvent(edm::Event const& event, edm::EventSetup const& setup, PhiSymStreamCache* cache) const; // helpers void initializeStreamCache(PhiSymStreamCache* cache) const; - void initializeGlobalCache(edm::EventSetup const& setup, + void initializePhiSymCache(edm::EventSetup const& setup, edm::ESGetToken const& chStatusToken, edm::ESGetToken const& geoToken, std::shared_ptr& vcache) const; @@ -284,7 +284,7 @@ void EcalPhiSymRecHitProducerBase::initializeStreamCache(PhiSymStreamCache* cach } } -void EcalPhiSymRecHitProducerBase::initializeGlobalCache( +void EcalPhiSymRecHitProducerBase::initializePhiSymCache( edm::EventSetup const& setup, edm::ESGetToken const& chStatusToken, edm::ESGetToken const& geoToken, @@ -406,7 +406,7 @@ std::shared_ptr EcalPhiSymRecHitProducerLumi::globalBeginLuminosity EcalPhiSymInfo thisLumi(0, 0, 0, 1, lhcinfo.fillNumber(), lhcinfo.delivLumi(), lhcinfo.recLumi()); //---Reset global cache - initializeGlobalCache(setup, chStatusTokenLumi_, geoTokenLumi_, cache); + initializePhiSymCache(setup, chStatusTokenLumi_, geoTokenLumi_, cache); cache->c[0].ecalLumiInfo = thisLumi; return cache; @@ -481,7 +481,7 @@ class EcalPhiSymRecHitProducerRun : public edm::global::EDProducer be overrideginStream(edm::StreamID stream) const override; + std::unique_ptr beginStream(edm::StreamID stream) const override; void streamBeginRun(edm::StreamID stream, edm::Run const& run, edm::EventSetup const& setup) const override; void streamEndRun(edm::StreamID stream, edm::Run const& run, edm::EventSetup const& setup) const override; // event @@ -507,7 +507,7 @@ EcalPhiSymRecHitProducerRun::EcalPhiSymRecHitProducerRun(const edm::ParameterSet std::shared_ptr EcalPhiSymRecHitProducerRun::globalBeginRun(edm::Run const& run, edm::EventSetup const& setup) const { auto cache = std::make_shared(); - initializeGlobalCache(setup, chStatusTokenRun_, geoTokenRun_, cache); + initializePhiSymCache(setup, chStatusTokenRun_, geoTokenRun_, cache); return cache; } From 8a9091a36f1cbe8c68083d5e361d501fdbdf3183 Mon Sep 17 00:00:00 2001 From: Simone Pigazzi Date: Thu, 10 Mar 2022 12:36:32 +0100 Subject: [PATCH 10/13] Proper multi-thread safe implementation using StreamCache, Run/LumiCache and Run/LumiSummaryCache --- .../plugins/EcalPhiSymRecHitProducers.cc | 357 ++++++++++-------- 1 file changed, 205 insertions(+), 152 deletions(-) diff --git a/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc index 79c364cff9963..d0b302cf42b9f 100644 --- a/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc +++ b/Calibration/EcalCalibAlgos/plugins/EcalPhiSymRecHitProducers.cc @@ -42,7 +42,7 @@ #include "Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h" //---Wrapper to handle stream data -struct PhiSymStreamCache { +struct PhiSymCache { EcalPhiSymInfo ecalLumiInfo; EcalPhiSymRecHitCollection recHitCollEB; EcalPhiSymRecHitCollection recHitCollEE; @@ -54,10 +54,12 @@ struct PhiSymStreamCache { } }; -struct PhiSymCache { - mutable tbb::concurrent_vector c; - - void clear() { c.clear(); } +// cache structure for LuminosityBlock/Run Cache +struct ConfigCache { + float etCutsEB[EcalRingCalibrationTools::N_RING_BARREL]; + float etCutsEE[EcalRingCalibrationTools::N_RING_ENDCAP]; + std::vector barrelDetIds; + std::vector endcapDetIds; }; //**************************************************************************************** @@ -73,24 +75,28 @@ class EcalPhiSymRecHitProducerBase { // job void initializeJob(); // event - void processEvent(edm::Event const& event, edm::EventSetup const& setup, PhiSymStreamCache* cache) const; + void processEvent(edm::Event const& event, + edm::EventSetup const& setup, + ConfigCache const* config, + PhiSymCache* cache) const; // helpers - void initializeStreamCache(PhiSymStreamCache* cache) const; + void initializeStreamCache(ConfigCache const* config, PhiSymCache* cache) const; void initializePhiSymCache(edm::EventSetup const& setup, edm::ESGetToken const& chStatusToken, + ConfigCache const* config, + std::shared_ptr& cache) const; + void initializeConfigCache(edm::EventSetup const& setup, edm::ESGetToken const& geoToken, - std::shared_ptr& vcache) const; - void sumCache(tbb::concurrent_vector& vcache) const; + std::shared_ptr& cache) const; + void sumCache(PhiSymCache* summaryc, PhiSymCache* streamc) const; //---data memebers // available to derived classes protected: - mutable std::vector barrelDetIds_; - mutable std::vector endcapDetIds_; edm::ESGetToken geoToken_; edm::ESGetToken laserDbToken_; - mutable edm::EDGetTokenT ebToken_; - mutable edm::EDGetTokenT eeToken_; + edm::EDGetTokenT ebToken_; + edm::EDGetTokenT eeToken_; float etCutEB_; std::vector eThresholdsEB_; float etCutEE_; @@ -108,9 +114,7 @@ class EcalPhiSymRecHitProducerBase { static const short kNRingsEB = EcalRingCalibrationTools::N_RING_BARREL; static const short kNRingsEE = EcalRingCalibrationTools::N_RING_ENDCAP; static const short ringsInOneEE = kNRingsEE / 2; - mutable float etCutsEB_[kNRingsEB]; - mutable float etCutsEE_[kNRingsEE]; - mutable float eThresholdsEE_[kNRingsEE]; + float eThresholdsEE_[kNRingsEE]; }; //----------IMPLEMENTATION---------------------------------------------------------------- @@ -131,19 +135,13 @@ EcalPhiSymRecHitProducerBase::EcalPhiSymRecHitProducerBase(const edm::ParameterS misCalibRangeEE_(pSet.getParameter >("misCalibRangeEE")) {} void EcalPhiSymRecHitProducerBase::initializeJob() { - //---set E thresholds, Et cuts and miscalib steps - //---spectrum window: E > thr && Et < cut - //---NOTE: etCutsEE need the geometry, so it is set later in beginLumi - for (int iRing = 0; iRing < kNRingsEB; ++iRing) - etCutsEB_[iRing] = -1; + //---Compute the endcap thresholds using the provived parametric formula for (int iRing = 0; iRing < ringsInOneEE; ++iRing) { if (iRing < 30) eThresholdsEE_[iRing] = thrEEmod_ * (B_[0] + A_[0] * iRing) / 1000; else eThresholdsEE_[iRing] = thrEEmod_ * (B_[1] + A_[1] * iRing) / 1000; eThresholdsEE_[iRing + ringsInOneEE] = eThresholdsEE_[iRing]; - etCutsEE_[iRing] = -1; - etCutsEE_[iRing + ringsInOneEE] = -1; } //---misCalib value init (nMisCalib is half of the correct value!) @@ -161,7 +159,8 @@ void EcalPhiSymRecHitProducerBase::initializeJob() { void EcalPhiSymRecHitProducerBase::processEvent(edm::Event const& event, edm::EventSetup const& setup, - PhiSymStreamCache* streamCache) const { + ConfigCache const* configCache, + PhiSymCache* streamCache) const { uint64_t totHitsEB = 0; uint64_t totHitsEE = 0; @@ -199,7 +198,7 @@ void EcalPhiSymRecHitProducerBase::processEvent(edm::Event const& event, int index = iMis + nMisCalib_ + 1; etValues[index] = etValues[0] * (1 + misCalibStepsEB_[index]); //---set et to zero if out of range [e_thr, et_thr+1] - if (etValues[index] * cosh(eta) < eThresholdsEB_[ring] || etValues[index] > etCutsEB_[ring]) + if (etValues[index] * cosh(eta) < eThresholdsEB_[ring] || etValues[index] > configCache->etCutsEB[ring]) etValues[index] = 0; } for (int iMis = 1; iMis <= nMisCalib_; ++iMis) { @@ -207,11 +206,11 @@ void EcalPhiSymRecHitProducerBase::processEvent(edm::Event const& event, int index = iMis + nMisCalib_; etValues[index] = etValues[0] * (1 + misCalibStepsEB_[index]); //---set et to zero if out of range [e_thr, et_thr+1] - if (etValues[index] * cosh(eta) < eThresholdsEB_[ring] || etValues[index] > etCutsEB_[ring]) + if (etValues[index] * cosh(eta) < eThresholdsEB_[ring] || etValues[index] > configCache->etCutsEB[ring]) etValues[index] = 0; } //---set et to zero if out of range [e_thr, et_thr+1] - if (energy < eThresholdsEB_[ring] || etValues[0] > etCutsEB_[ring]) + if (energy < eThresholdsEB_[ring] || etValues[0] > configCache->etCutsEB[ring]) etValues[0] = 0; else ++totHitsEB; @@ -241,7 +240,7 @@ void EcalPhiSymRecHitProducerBase::processEvent(edm::Event const& event, int index = iMis + nMisCalib_ + 1; etValues[index] = etValues[0] * (1 + misCalibStepsEE_[index]); //---set et to zero if out of range [e_thr, et_thr+1] - if (etValues[index] * cosh(eta) < eThresholdsEE_[ring] || etValues[index] > etCutsEE_[ring]) + if (etValues[index] * cosh(eta) < eThresholdsEE_[ring] || etValues[index] > configCache->etCutsEE[ring]) etValues[index] = 0; } for (int iMis = 1; iMis <= nMisCalib_; ++iMis) { @@ -249,11 +248,11 @@ void EcalPhiSymRecHitProducerBase::processEvent(edm::Event const& event, int index = iMis + nMisCalib_; etValues[index] = etValues[0] * (1 + misCalibStepsEE_[index]); //---set et to zero if out of range [e_thr, et_thr+1] - if (etValues[index] * cosh(eta) < eThresholdsEE_[ring] || etValues[index] > etCutsEE_[ring]) + if (etValues[index] * cosh(eta) < eThresholdsEE_[ring] || etValues[index] > configCache->etCutsEE[ring]) etValues[index] = 0; } //---set et to zero if out of range [e_thr, et_thr+1] - if (energy < eThresholdsEE_[ring] || etValues[0] > etCutsEE_[ring]) + if (energy < eThresholdsEE_[ring] || etValues[0] > configCache->etCutsEE[ring]) etValues[0] = 0; else ++totHitsEE; @@ -267,18 +266,18 @@ void EcalPhiSymRecHitProducerBase::processEvent(edm::Event const& event, streamCache->ecalLumiInfo += thisEvent; } -void EcalPhiSymRecHitProducerBase::initializeStreamCache(PhiSymStreamCache* cache) const { +void EcalPhiSymRecHitProducerBase::initializeStreamCache(ConfigCache const* config, PhiSymCache* cache) const { //---Initialize the per-stream RecHitCollection // both collections are initialized to contain the total // number of crystals, ordered accrodingly to the hashedIndex. cache->clear(); - cache->recHitCollEB.resize(barrelDetIds_.size()); - cache->recHitCollEE.resize(endcapDetIds_.size()); - for (auto& ebDetId : barrelDetIds_) { + cache->recHitCollEB.resize(config->barrelDetIds.size()); + cache->recHitCollEE.resize(config->endcapDetIds.size()); + for (auto& ebDetId : config->barrelDetIds) { EBDetId id(ebDetId); cache->recHitCollEB.at(id.denseIndex()) = EcalPhiSymRecHit(id.rawId(), nSumEtValues_); } - for (auto& eeDetId : endcapDetIds_) { + for (auto& eeDetId : config->endcapDetIds) { EEDetId id(eeDetId); cache->recHitCollEE.at(id.denseIndex()) = EcalPhiSymRecHit(id.rawId(), nSumEtValues_); } @@ -287,71 +286,87 @@ void EcalPhiSymRecHitProducerBase::initializeStreamCache(PhiSymStreamCache* cach void EcalPhiSymRecHitProducerBase::initializePhiSymCache( edm::EventSetup const& setup, edm::ESGetToken const& chStatusToken, - edm::ESGetToken const& geoToken, - std::shared_ptr& vcache) const { - vcache->c.clear(); - vcache->c.push_back(PhiSymStreamCache()); + ConfigCache const* config, + std::shared_ptr& cache) const { + cache->clear(); - auto& cache = vcache->c[0]; + //---get the channels status + auto const& chStatus = setup.getData(chStatusToken); + + cache->recHitCollEB.resize(config->barrelDetIds.size()); + cache->recHitCollEE.resize(config->endcapDetIds.size()); + for (auto& ebDetId : config->barrelDetIds) { + EBDetId id(ebDetId); + cache->recHitCollEB.at(id.denseIndex()) = + EcalPhiSymRecHit(ebDetId.rawId(), nSumEtValues_, chStatus[id].getStatusCode()); + } + for (auto& eeDetId : config->endcapDetIds) { + EEDetId id(eeDetId); + int ring = calibRing_.getRingIndex(id) - kNRingsEB; + cache->recHitCollEE.at(id.denseIndex()) = + EcalPhiSymRecHit(eeDetId.rawId(), nSumEtValues_, chStatus[id].getStatusCode()); + cache->recHitCollEE.at(id.denseIndex()) + .setEERing(ring < kNRingsEE / 2 ? ring - kNRingsEE / 2 : ring - kNRingsEE / 2 + 1); + } +} +void EcalPhiSymRecHitProducerBase::initializeConfigCache( + edm::EventSetup const& setup, + edm::ESGetToken const& geoToken, + std::shared_ptr& cache) const { //---get the ecal geometry const auto* geometry = &setup.getData(geoToken); calibRing_.setCaloGeometry(geometry); - //---get the channels status - auto const& chStatus = setup.getData(chStatusToken); - const auto* barrelGeometry = geometry->getSubdetectorGeometry(DetId::Ecal, EcalBarrel); const auto* endcapGeometry = geometry->getSubdetectorGeometry(DetId::Ecal, EcalEndcap); - barrelDetIds_ = barrelGeometry->getValidDetIds(DetId::Ecal, EcalBarrel); - endcapDetIds_ = endcapGeometry->getValidDetIds(DetId::Ecal, EcalEndcap); - cache.recHitCollEB.resize(barrelDetIds_.size()); - cache.recHitCollEE.resize(endcapDetIds_.size()); - for (auto& ebDetId : barrelDetIds_) { + cache->barrelDetIds = barrelGeometry->getValidDetIds(DetId::Ecal, EcalBarrel); + cache->endcapDetIds = endcapGeometry->getValidDetIds(DetId::Ecal, EcalEndcap); + + for (auto& ebDetId : cache->barrelDetIds) { EBDetId id(ebDetId); - cache.recHitCollEB.at(id.denseIndex()) = - EcalPhiSymRecHit(ebDetId.rawId(), nSumEtValues_, chStatus[id].getStatusCode()); int ring = calibRing_.getRingIndex(id); //---set etCut if first pass - if (etCutsEB_[ring] == -1 && id.iphi() == 1) { + if (id.iphi() == 1) { auto cellGeometry = barrelGeometry->getGeometry(id); float eta = cellGeometry->getPosition().eta(); - etCutsEB_[ring] = eThresholdsEB_[ring] / cosh(eta) + etCutEB_; + cache->etCutsEB[ring] = eThresholdsEB_[ring] / cosh(eta) + etCutEB_; } } - for (auto& eeDetId : endcapDetIds_) { + for (auto& eeDetId : cache->endcapDetIds) { EEDetId id(eeDetId); int ring = calibRing_.getRingIndex(id) - kNRingsEB; - cache.recHitCollEE.at(id.denseIndex()) = - EcalPhiSymRecHit(eeDetId.rawId(), nSumEtValues_, chStatus[id].getStatusCode()); - cache.recHitCollEE.at(id.denseIndex()) - .setEERing(ring < kNRingsEE / 2 ? ring - kNRingsEE / 2 : ring - kNRingsEE / 2 + 1); //---set eCutEE if first pass - if (ring < ringsInOneEE && etCutsEE_[ring] == -1 && id.ix() == EEDetId::IX_MAX / 2) { + if (ring < ringsInOneEE && id.ix() == EEDetId::IX_MAX / 2) { auto cellGeometry = endcapGeometry->getGeometry(id); - etCutsEE_[ring] = eThresholdsEE_[ring] / cosh(cellGeometry->getPosition().eta()) + etCutEE_; - etCutsEE_[ring + ringsInOneEE] = etCutsEE_[ring]; + cache->etCutsEE[ring] = eThresholdsEE_[ring] / cosh(cellGeometry->getPosition().eta()) + etCutEE_; + cache->etCutsEE[ring + ringsInOneEE] = cache->etCutsEE[ring]; } } } -void EcalPhiSymRecHitProducerBase::sumCache(tbb::concurrent_vector& vcache) const { - //---The first element of the cache is the "global" cache that - // contains static global information. The stream partial sums are - // stored from index=1 - for (unsigned int is = 1; is < vcache.size(); ++is) { - vcache[0].ecalLumiInfo += vcache[is].ecalLumiInfo; - for (unsigned int i = 0; i < vcache[0].recHitCollEB.size(); ++i) - vcache[0].recHitCollEB[i] += vcache[is].recHitCollEB[i]; - for (unsigned int i = 0; i < vcache[0].recHitCollEE.size(); ++i) - vcache[0].recHitCollEE[i] += vcache[is].recHitCollEE[i]; - } +void EcalPhiSymRecHitProducerBase::sumCache(PhiSymCache* summaryc, PhiSymCache* streamc) const { + //---The first argument is the summary cache that + // contains the lumi/run summary information. + // The stream partial sums are passed as second argument + summaryc->ecalLumiInfo += streamc->ecalLumiInfo; + for (unsigned int i = 0; i < summaryc->recHitCollEB.size(); ++i) + summaryc->recHitCollEB[i] += streamc->recHitCollEB[i]; + for (unsigned int i = 0; i < summaryc->recHitCollEE.size(); ++i) + summaryc->recHitCollEE[i] += streamc->recHitCollEE[i]; } //**************************************************************************************** // Lumi producer -class EcalPhiSymRecHitProducerLumi : public edm::global::EDProducer, - edm::LuminosityBlockCache, +// The StreamCache and LuminosityBlockSummaryCache contain the rec hit data, summed per +// stream, in the stream cache, and per lumi in the summary cache. +// The LuminosityBlockCache contains a set of information (detIds and thresholds) +// that requires access to the geometry record to be created. Not using the LuminosityBlockCache +// would require making the objects contained in it mutable class members which is +// discouraged. +class EcalPhiSymRecHitProducerLumi : public edm::global::EDProducer, + edm::LuminosityBlockCache, + edm::LuminosityBlockSummaryCache, edm::EndLuminosityBlockProducer, edm::Accumulator>, public EcalPhiSymRecHitProducerBase { @@ -364,20 +379,28 @@ class EcalPhiSymRecHitProducerLumi : public edm::global::EDProducer globalBeginLuminosityBlock(edm::LuminosityBlock const& lumi, + std::shared_ptr globalBeginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& setup) const override; void globalEndLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& setup) const override{}; - void globalEndLuminosityBlockProduce(edm::LuminosityBlock& lumi, edm::EventSetup const& setup) const override; + std::shared_ptr globalBeginLuminosityBlockSummary(edm::LuminosityBlock const& lumi, + edm::EventSetup const& setup) const override; + void globalEndLuminosityBlockSummary(edm::LuminosityBlock const& lumi, + edm::EventSetup const& setup, + PhiSymCache* cache) const override{}; + void globalEndLuminosityBlockProduce(edm::LuminosityBlock& lumi, + edm::EventSetup const& setup, + PhiSymCache const* cache) const override; // stream - std::unique_ptr beginStream(edm::StreamID stream) const override; + std::unique_ptr beginStream(edm::StreamID stream) const override; void streamBeginLuminosityBlock(edm::StreamID stream, edm::LuminosityBlock const& lumi, edm::EventSetup const& setup) const override; - void streamEndLuminosityBlock(edm::StreamID stream, - edm::LuminosityBlock const& lumi, - edm::EventSetup const& setup) const override; + void streamEndLuminosityBlockSummary(edm::StreamID stream, + edm::LuminosityBlock const& lumi, + edm::EventSetup const& setup, + PhiSymCache* cache) const override; - // overrideevent + // event void accumulate(edm::StreamID stream, edm::Event const& event, edm::EventSetup const& setup) const override; // data members @@ -397,7 +420,17 @@ EcalPhiSymRecHitProducerLumi::EcalPhiSymRecHitProducerLumi(const edm::ParameterS produces("EE"); } -std::shared_ptr EcalPhiSymRecHitProducerLumi::globalBeginLuminosityBlock( +std::shared_ptr EcalPhiSymRecHitProducerLumi::globalBeginLuminosityBlock( + edm::LuminosityBlock const& lumi, edm::EventSetup const& setup) const { + auto cache = std::make_shared(); + + //---Reset cache with config values + initializeConfigCache(setup, geoTokenLumi_, cache); + + return cache; +} + +std::shared_ptr EcalPhiSymRecHitProducerLumi::globalBeginLuminosityBlockSummary( edm::LuminosityBlock const& lumi, edm::EventSetup const& setup) const { auto cache = std::make_shared(); @@ -406,61 +439,66 @@ std::shared_ptr EcalPhiSymRecHitProducerLumi::globalBeginLuminosity EcalPhiSymInfo thisLumi(0, 0, 0, 1, lhcinfo.fillNumber(), lhcinfo.delivLumi(), lhcinfo.recLumi()); //---Reset global cache - initializePhiSymCache(setup, chStatusTokenLumi_, geoTokenLumi_, cache); - cache->c[0].ecalLumiInfo = thisLumi; + initializePhiSymCache(setup, chStatusTokenLumi_, luminosityBlockCache(lumi.index()), cache); + cache->ecalLumiInfo = thisLumi; return cache; } void EcalPhiSymRecHitProducerLumi::globalEndLuminosityBlockProduce(edm::LuminosityBlock& lumi, - edm::EventSetup const& setup) const { - auto& vcache = luminosityBlockCache(lumi.index())->c; - sumCache(vcache); - + edm::EventSetup const& setup, + PhiSymCache const* cache) const { //---put the collections in the LuminosityBlocks tree - auto ecalLumiInfo = std::make_unique(vcache[0].ecalLumiInfo); + auto ecalLumiInfo = std::make_unique(cache->ecalLumiInfo); ecalLumiInfo->setMiscalibInfo( nMisCalib_ * 2, misCalibRangeEB_[0], misCalibRangeEB_[1], misCalibRangeEE_[0], misCalibRangeEE_[1]); auto recHitCollEB = - std::make_unique(vcache[0].recHitCollEB.begin(), vcache[0].recHitCollEB.end()); + std::make_unique(cache->recHitCollEB.begin(), cache->recHitCollEB.end()); auto recHitCollEE = - std::make_unique(vcache[0].recHitCollEE.begin(), vcache[0].recHitCollEE.end()); + std::make_unique(cache->recHitCollEE.begin(), cache->recHitCollEE.end()); lumi.put(std::move(ecalLumiInfo)); lumi.put(std::move(recHitCollEB), "EB"); lumi.put(std::move(recHitCollEE), "EE"); } -std::unique_ptr EcalPhiSymRecHitProducerLumi::beginStream(edm::StreamID stream) const { +std::unique_ptr EcalPhiSymRecHitProducerLumi::beginStream(edm::StreamID stream) const { //---create stream cache - return std::make_unique(); + return std::make_unique(); } void EcalPhiSymRecHitProducerLumi::streamBeginLuminosityBlock(edm::StreamID stream, edm::LuminosityBlock const& lumi, edm::EventSetup const& setup) const { //---Reset stream cache - initializeStreamCache(streamCache(stream)); + initializeStreamCache(luminosityBlockCache(lumi.index()), streamCache(stream)); } -void EcalPhiSymRecHitProducerLumi::streamEndLuminosityBlock(edm::StreamID stream, - edm::LuminosityBlock const& lumi, - edm::EventSetup const& setup) const { - //---add stream cache to global cache container - luminosityBlockCache(lumi.index())->c.push_back(*streamCache(stream)); +void EcalPhiSymRecHitProducerLumi::streamEndLuminosityBlockSummary(edm::StreamID stream, + edm::LuminosityBlock const& lumi, + edm::EventSetup const& setup, + PhiSymCache* scache) const { + //---sum stream cache to summary cache + sumCache(scache, streamCache(stream)); } void EcalPhiSymRecHitProducerLumi::accumulate(edm::StreamID stream, edm::Event const& event, edm::EventSetup const& setup) const { - processEvent(event, setup, streamCache(stream)); + processEvent(event, setup, luminosityBlockCache(event.getLuminosityBlock().index()), streamCache(stream)); } //**************************************************************************************** // Run producer -class EcalPhiSymRecHitProducerRun : public edm::global::EDProducer, - edm::RunCache, - edm::LuminosityBlockCache, +// The StreamCache and RunSummaryCache contain the rec hit data, summed per +// stream, in the stream cache, and per run in the summary cache. +// The RunCache contains a set of information (detIds and thresholds) +// that requires access to the geometry record to be created. Not using the RunCache +// would require making the objects contained in it mutable class members which is +// discouraged. +class EcalPhiSymRecHitProducerRun : public edm::global::EDProducer, + edm::RunCache, + edm::RunSummaryCache, edm::EndRunProducer, edm::Accumulator>, public EcalPhiSymRecHitProducerBase { @@ -473,17 +511,21 @@ class EcalPhiSymRecHitProducerRun : public edm::global::EDProducer globalBeginRun(edm::Run const& run, edm::EventSetup const& setup) const override; + std::shared_ptr globalBeginRun(edm::Run const& run, edm::EventSetup const& setup) const override; + std::shared_ptr globalBeginRunSummary(edm::Run const& run, edm::EventSetup const& setup) const override; void globalEndRun(edm::Run const& run, edm::EventSetup const& setup) const override{}; - void globalEndRunProduce(edm::Run& run, edm::EventSetup const& setup) const override; - // lumi - std::shared_ptr globalBeginLuminosityBlock(edm::LuminosityBlock const& lumi, - edm::EventSetup const& setup) const override; - void globalEndLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& setup) const override{}; + void globalEndRunSummary(edm::Run const& run, edm::EventSetup const& setup, PhiSymCache* cache) const override{}; + void globalEndRunProduce(edm::Run& run, edm::EventSetup const& setup, PhiSymCache const* cache) const override; // stream - std::unique_ptr beginStream(edm::StreamID stream) const override; + std::unique_ptr beginStream(edm::StreamID stream) const override; + void streamBeginLuminosityBlock(edm::StreamID stream, + edm::LuminosityBlock const& lumi, + edm::EventSetup const& setup) const override; void streamBeginRun(edm::StreamID stream, edm::Run const& run, edm::EventSetup const& setup) const override; - void streamEndRun(edm::StreamID stream, edm::Run const& run, edm::EventSetup const& setup) const override; + void streamEndRunSummary(edm::StreamID stream, + edm::Run const& run, + edm::EventSetup const& setup, + PhiSymCache* cache) const override; // event void accumulate(edm::StreamID stream, edm::Event const& event, edm::EventSetup const& setup) const override; @@ -504,71 +546,82 @@ EcalPhiSymRecHitProducerRun::EcalPhiSymRecHitProducerRun(const edm::ParameterSet produces("EE"); } -std::shared_ptr EcalPhiSymRecHitProducerRun::globalBeginRun(edm::Run const& run, +std::shared_ptr EcalPhiSymRecHitProducerRun::globalBeginRun(edm::Run const& run, edm::EventSetup const& setup) const { - auto cache = std::make_shared(); - initializePhiSymCache(setup, chStatusTokenRun_, geoTokenRun_, cache); + auto cache = std::make_shared(); + + //---Reset cache with config values + initializeConfigCache(setup, geoTokenRun_, cache); + return cache; } -//---globalBeginLuminosityBlock is called just to correctly update the LHCInfo -std::shared_ptr EcalPhiSymRecHitProducerRun::globalBeginLuminosityBlock( - edm::LuminosityBlock const& lumi, edm::EventSetup const& setup) const { - //---Get LHC info - // LHCInfo only returns the correct luminosity information - // for each lumisection, accessing LHCInfo at the beginning - // of each run would return only the luminosity info of the - // first LS - const auto& lhcinfo = setup.getData(lhcInfoTokenLumi_); - EcalPhiSymInfo thisLumi(0, 0, 0, 1, lhcinfo.fillNumber(), lhcinfo.delivLumi(), lhcinfo.recLumi()); +std::shared_ptr EcalPhiSymRecHitProducerRun::globalBeginRunSummary(edm::Run const& run, + edm::EventSetup const& setup) const { + auto cache = std::make_shared(); + initializePhiSymCache(setup, chStatusTokenRun_, runCache(run.index()), cache); + return cache; +} - runCache(lumi.getRun().index())->c[0].ecalLumiInfo += thisLumi; +void EcalPhiSymRecHitProducerRun::globalEndRunProduce(edm::Run& run, + edm::EventSetup const& setup, + PhiSymCache const* cache) const { + //---put the collections in the Runs tree + auto ecalLumiInfo = std::make_unique(cache->ecalLumiInfo); + ecalLumiInfo->setMiscalibInfo( + nMisCalib_ * 2, misCalibRangeEB_[0], misCalibRangeEB_[1], misCalibRangeEE_[0], misCalibRangeEE_[1]); + auto recHitCollEB = + std::make_unique(cache->recHitCollEB.begin(), cache->recHitCollEB.end()); + auto recHitCollEE = + std::make_unique(cache->recHitCollEE.begin(), cache->recHitCollEE.end()); - // dummy cache, it won't be used - return std::make_shared(); + run.put(std::move(ecalLumiInfo)); + run.put(std::move(recHitCollEB), "EB"); + run.put(std::move(recHitCollEE), "EE"); } -std::unique_ptr EcalPhiSymRecHitProducerRun::beginStream(edm::StreamID stream) const { +std::unique_ptr EcalPhiSymRecHitProducerRun::beginStream(edm::StreamID stream) const { //---create stream cache - return std::make_unique(); + return std::make_unique(); } void EcalPhiSymRecHitProducerRun::streamBeginRun(edm::StreamID stream, edm::Run const& run, edm::EventSetup const& setup) const { - //---Reset and add this stream cache to the global cache container. - initializeStreamCache(streamCache(stream)); + //---Reset stream cache + initializeStreamCache(runCache(run.index()), streamCache(stream)); } -void EcalPhiSymRecHitProducerRun::streamEndRun(edm::StreamID stream, - edm::Run const& run, - edm::EventSetup const& setup) const { - //---add stream cache to global cache container - runCache(run.index())->c.push_back(*streamCache(stream)); +void EcalPhiSymRecHitProducerRun::streamBeginLuminosityBlock(edm::StreamID stream, + edm::LuminosityBlock const& lumi, + edm::EventSetup const& setup) const { + //---Get LHC info + // LHCInfo only returns the correct luminosity information + // for each lumisection, accessing LHCInfo at the beginning + // of each run would return only the luminosity info of the + // first LS. + // Therefore the LHCInfo is accessed only by the first stream + // each time a new LS is processed + if (stream.value() == 0) { + const auto& lhcinfo = setup.getData(lhcInfoTokenLumi_); + EcalPhiSymInfo thisLumi(0, 0, 0, 1, lhcinfo.fillNumber(), lhcinfo.delivLumi(), lhcinfo.recLumi()); + + streamCache(stream)->ecalLumiInfo += thisLumi; + } } -void EcalPhiSymRecHitProducerRun::globalEndRunProduce(edm::Run& run, edm::EventSetup const& setup) const { - auto& vcache = runCache(run.index())->c; - sumCache(vcache); - - //---put the collections in the Runs tree - auto ecalLumiInfo = std::make_unique(vcache[0].ecalLumiInfo); - ecalLumiInfo->setMiscalibInfo( - nMisCalib_ * 2, misCalibRangeEB_[0], misCalibRangeEB_[1], misCalibRangeEE_[0], misCalibRangeEE_[1]); - auto recHitCollEB = - std::make_unique(vcache[0].recHitCollEB.begin(), vcache[0].recHitCollEB.end()); - auto recHitCollEE = - std::make_unique(vcache[0].recHitCollEE.begin(), vcache[0].recHitCollEE.end()); - - run.put(std::move(ecalLumiInfo)); - run.put(std::move(recHitCollEB), "EB"); - run.put(std::move(recHitCollEE), "EE"); +void EcalPhiSymRecHitProducerRun::streamEndRunSummary(edm::StreamID stream, + edm::Run const& run, + edm::EventSetup const& setup, + PhiSymCache* scache) const { + //---sum stream cache to run cache + sumCache(scache, streamCache(stream)); } void EcalPhiSymRecHitProducerRun::accumulate(edm::StreamID stream, edm::Event const& event, edm::EventSetup const& setup) const { - processEvent(event, setup, streamCache(stream)); + processEvent(event, setup, runCache(event.getRun().index()), streamCache(stream)); } DEFINE_FWK_MODULE(EcalPhiSymRecHitProducerLumi); From 42e1c3e10d8fef43c28728c1a8af0c52d6059607 Mon Sep 17 00:00:00 2001 From: Simone Pigazzi Date: Wed, 16 Mar 2022 09:34:30 +0100 Subject: [PATCH 11/13] ALCARECO-like workflow to be run in an open ended production campaign --- .../python/ALCARECOEcalPhiSym_Output_cff.py | 15 ++++++ .../python/ALCARECOEcalPhiSym_cff.py | 51 +++++++++++++++++++ .../python/EcalPhiSymRecoSequence_cff.py | 26 ++++++++++ .../EventContent/python/AlCaRecoOutput_cff.py | 2 + .../python/AlCaRecoStreams_cff.py | 24 ++++++++- 5 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 Calibration/EcalCalibAlgos/python/ALCARECOEcalPhiSym_Output_cff.py create mode 100644 Calibration/EcalCalibAlgos/python/ALCARECOEcalPhiSym_cff.py diff --git a/Calibration/EcalCalibAlgos/python/ALCARECOEcalPhiSym_Output_cff.py b/Calibration/EcalCalibAlgos/python/ALCARECOEcalPhiSym_Output_cff.py new file mode 100644 index 0000000000000..517ab2acfea38 --- /dev/null +++ b/Calibration/EcalCalibAlgos/python/ALCARECOEcalPhiSym_Output_cff.py @@ -0,0 +1,15 @@ +import FWCore.ParameterSet.Config as cms +import copy + +OutALCARECOEcalPhiSymByRun_noDrop = cms.PSet( + SelectEvents=cms.untracked.PSet( + SelectEvents=cms.vstring( + 'pathALCARECOEcalPhiSym*') + ), + outputCommands=cms.untracked.vstring() +) +OutALCARECOEcalPhiSymByRun = copy.deepcopy(OutALCARECOEcalPhiSymByRun_noDrop) +OutALCARECOEcalPhiSymByRun.outputCommands.insert(0, "drop *") + +OutALCARECOEcalPhiSymByLumi_noDrop = copy.deepcopy(OutALCARECOEcalPhiSymByRun_noDrop) +OutALCARECOEcalPhiSymByLumi = copy.deepcopy(OutALCARECOEcalPhiSymByRun) diff --git a/Calibration/EcalCalibAlgos/python/ALCARECOEcalPhiSym_cff.py b/Calibration/EcalCalibAlgos/python/ALCARECOEcalPhiSym_cff.py new file mode 100644 index 0000000000000..80d5e1e7bb9fe --- /dev/null +++ b/Calibration/EcalCalibAlgos/python/ALCARECOEcalPhiSym_cff.py @@ -0,0 +1,51 @@ +import FWCore.ParameterSet.Config as cms +from PhysicsTools.NanoAOD.common_cff import * + +# # PHISYM producer +from Calibration.EcalCalibAlgos.EcalPhiSymRecHitProducers_cfi import EcalPhiSymRecHitProducerRun, EcalPhiSymRecHitProducerLumi + +# Sum info by run or lumi sequences +ALCARECOEcalPhiSymRecHitProducerRun = EcalPhiSymRecHitProducerRun.clone() +ALCARECOEcalPhiSymRecHitProducerLumi = EcalPhiSymRecHitProducerLumi.clone() + +# # NANOAOD flat table producers +import Calibration.EcalCalibAlgos.EcalPhiSymFlatTableProducers_cfi +ALCARECOecalPhiSymRecHitRunTableEB = Calibration.EcalCalibAlgos.EcalPhiSymFlatTableProducers_cfi.ecalPhiSymRecHitRunTableEB +ALCARECOecalPhiSymRecHitRunTableEE = Calibration.EcalCalibAlgos.EcalPhiSymFlatTableProducers_cfi.ecalPhiSymRecHitRunTableEE +ALCARECOecalPhiSymInfoRunTable = Calibration.EcalCalibAlgos.EcalPhiSymFlatTableProducers_cfi.ecalPhiSymInfoRunTable +ALCARECOecalPhiSymRecHitLumiTableEB = Calibration.EcalCalibAlgos.EcalPhiSymFlatTableProducers_cfi.ecalPhiSymRecHitLumiTableEB +ALCARECOecalPhiSymRecHitLumiTableEE = Calibration.EcalCalibAlgos.EcalPhiSymFlatTableProducers_cfi.ecalPhiSymRecHitLumiTableEE +ALCARECOecalPhiSymInfoLumiTable = Calibration.EcalCalibAlgos.EcalPhiSymFlatTableProducers_cfi.ecalPhiSymInfoLumiTable + +ALCARECOecalPhiSymRecHitRunTableEB.src = cms.InputTag("ALCARECOEcalPhiSymRecHitProducerRun", "EB") +ALCARECOecalPhiSymRecHitRunTableEE.src = cms.InputTag("ALCARECOEcalPhiSymRecHitProducerRun", "EE") +ALCARECOecalPhiSymInfoRunTable.src = cms.InputTag("ALCARECOEcalPhiSymRecHitProducerRun") +ALCARECOecalPhiSymRecHitLumiTableEB.src = cms.InputTag("ALCARECOEcalPhiSymRecHitProducerLumi", "EB") +ALCARECOecalPhiSymRecHitLumiTableEE.src = cms.InputTag("ALCARECOEcalPhiSymRecHitProducerLumi", "EE") +ALCARECOecalPhiSymInfoLumiTable.src = cms.InputTag("ALCARECOEcalPhiSymRecHitProducerLumi") + +nmis = ALCARECOEcalPhiSymRecHitProducerRun.nMisCalib.value() +for imis in range(1, nmis+1): + # get the naming and indexing right. + if imis Date: Wed, 16 Mar 2022 12:09:33 +0100 Subject: [PATCH 12/13] Working switch between run and LS producers/output paths --- .../EcalCalibAlgos/python/EcalPhiSymRecoSequence_cff.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Calibration/EcalCalibAlgos/python/EcalPhiSymRecoSequence_cff.py b/Calibration/EcalCalibAlgos/python/EcalPhiSymRecoSequence_cff.py index 5848101da2da2..c22e772e5fe23 100644 --- a/Calibration/EcalCalibAlgos/python/EcalPhiSymRecoSequence_cff.py +++ b/Calibration/EcalCalibAlgos/python/EcalPhiSymRecoSequence_cff.py @@ -165,8 +165,11 @@ def customise(process): process.ecalRecHit.cpu.recoverEEIsolatedChannels = cms.bool( False ) process.ecalRecHit.cpu.recoverEBIsolatedChannels = cms.bool( False ) - process.schedule.remove(process.ALCARECOStreamEcalPhiSymByRunOutPath) - process.ALCARECOStreamEcalPhiSymByRunOutNanoPath = cms.EndPath(ecal_phisym_output(process, save_flatnano=True)[0]) - process.schedule.append(process.ALCARECOStreamEcalPhiSymByRunOutNanoPath) + if "ALCARECOStreamEcalPhiSymByRunOutPath" in process.pathNames(): + process.schedule.remove(process.ALCARECOStreamEcalPhiSymByRunOutPath) + if "ALCARECOStreamEcalPhiSymByLumiOutPath" in process.pathNames(): + process.schedule.remove(process.ALCARECOStreamEcalPhiSymByLumiOutPath) + process.ALCARECOStreamEcalPhiSymOutNanoPath = cms.EndPath(ecal_phisym_output(process, save_flatnano=True)[0]) + process.schedule.append(process.ALCARECOStreamEcalPhiSymOutNanoPath) return process From 52671111d24b034e362ef2be3b96ada901b6993b Mon Sep 17 00:00:00 2001 From: Simone Pigazzi Date: Tue, 22 Mar 2022 14:02:17 +0100 Subject: [PATCH 13/13] ClassVersion + headers checks --- Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h | 2 ++ Calibration/EcalCalibAlgos/src/classes_def.xml | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h b/Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h index 25d83bc56bc7e..65ca63fc0f6bb 100644 --- a/Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h +++ b/Calibration/EcalCalibAlgos/interface/EcalPhiSymInfo.h @@ -9,6 +9,8 @@ */ #include +#include +#include class EcalPhiSymInfo { public: diff --git a/Calibration/EcalCalibAlgos/src/classes_def.xml b/Calibration/EcalCalibAlgos/src/classes_def.xml index 1487310133218..b560855ddf903 100644 --- a/Calibration/EcalCalibAlgos/src/classes_def.xml +++ b/Calibration/EcalCalibAlgos/src/classes_def.xml @@ -1,9 +1,13 @@ - + + + - + + +