Skip to content

Commit

Permalink
Merge pull request #36987 from bsunanda/Run3-alca218D
Browse files Browse the repository at this point in the history
Run3-alca218D Clean some of the remaining Hcal calibration codes in Calibration/HcalCalibAlgos
  • Loading branch information
cmsbuild committed Feb 17, 2022
2 parents 72a3ef1 + 6d4a1b8 commit 0aad040
Show file tree
Hide file tree
Showing 7 changed files with 310 additions and 388 deletions.
70 changes: 31 additions & 39 deletions Calibration/HcalCalibAlgos/plugins/HOCalibAnalyzer.cc
Expand Up @@ -84,13 +84,13 @@ class HOCalibAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {

int mypow_2[31];

bool m_cosmic;
bool m_zeroField;
int m_bins;
double m_low;
double m_ahigh;
bool m_histFill; //Stored signals of individual HO towers with default selection criteria
bool m_treeFill; //Store rootuple without almost any selection criteria except a quality on muon
const bool m_cosmic;
const bool m_zeroField;
const int m_bins;
const double m_low;
const double m_ahigh;
const bool m_histFill; //Stored signals of individual HO towers with default selection criteria
const bool m_treeFill; //Store rootuple without almost any selection criteria except a quality on muon

int ipass;

Expand Down Expand Up @@ -130,8 +130,8 @@ class HOCalibAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
float ncount[ringmx][ncut + 10];

edm::InputTag hoCalibVariableCollectionTag;
edm::EDGetTokenT<HOCalibVariableCollection> tok_ho_;
edm::EDGetTokenT<HORecHitCollection> tok_allho_;
const edm::EDGetTokenT<HOCalibVariableCollection> tok_ho_;
const edm::EDGetTokenT<HORecHitCollection> tok_allho_;
// ----------member data ---------------------------
};

Expand All @@ -147,30 +147,27 @@ class HOCalibAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
// constructors and destructor
//

HOCalibAnalyzer::HOCalibAnalyzer(const edm::ParameterSet& iConfig) {
HOCalibAnalyzer::HOCalibAnalyzer(const edm::ParameterSet& iConfig)
: m_cosmic(iConfig.getUntrackedParameter<bool>("cosmic", true)),
m_zeroField(iConfig.getUntrackedParameter<bool>("zeroField", false)),
m_bins(iConfig.getUntrackedParameter<int>("HOSignalBins", 120)),
m_low(iConfig.getUntrackedParameter<double>("lowerRange", -1.0)),
m_ahigh(iConfig.getUntrackedParameter<double>("upperRange", 29.0)),
m_histFill(iConfig.getUntrackedParameter<bool>("histFill", true)),
m_treeFill(iConfig.getUntrackedParameter<bool>("treeFill", false)),
tok_ho_(consumes<HOCalibVariableCollection>(iConfig.getParameter<edm::InputTag>("hoCalibVariableCollectionTag"))),
tok_allho_(consumes<HORecHitCollection>(iConfig.getParameter<edm::InputTag>("hoInputTag"))) {
// It is very likely you want the following in your configuration
// hoCalibVariableCollectionTag = cms.InputTag('hoCalibProducer', 'HOCalibVariableCollection')

usesResource(TFileService::kSharedResource);

tok_ho_ = consumes<HOCalibVariableCollection>(iConfig.getParameter<edm::InputTag>("hoCalibVariableCollectionTag"));
tok_allho_ = consumes<HORecHitCollection>(iConfig.getParameter<edm::InputTag>("hoInputTag"));
//now do what ever initialization is needed
ipass = 0;
for (int ij = 0; ij < 10; ij++) {
nevents[ij] = 0;
}

m_cosmic = iConfig.getUntrackedParameter<bool>("cosmic", true);
m_zeroField = iConfig.getUntrackedParameter<bool>("zeroField", false);

m_bins = iConfig.getUntrackedParameter<int>("HOSignalBins", 120);
m_low = iConfig.getUntrackedParameter<double>("lowerRange", -1.0);
m_ahigh = iConfig.getUntrackedParameter<double>("upperRange", 29.0);

m_histFill = iConfig.getUntrackedParameter<bool>("histFill", true);
m_treeFill = iConfig.getUntrackedParameter<bool>("treeFill", false);

edm::Service<TFileService> fs;

T1 = fs->make<TTree>("T1", "HOSignal");
Expand Down Expand Up @@ -320,9 +317,10 @@ HOCalibAnalyzer::~HOCalibAnalyzer() {
// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)

edm::LogVerbatim("HOCalib") << " Total events = " << setw(7) << nevents[0] << " " << setw(7) << nevents[1] << " "
<< setw(7) << nevents[2] << " " << setw(7) << nevents[3] << " " << setw(7) << nevents[4]
<< " " << setw(7) << nevents[5] << " Selected events # is " << ipass;
edm::LogVerbatim("HOCalibAnalyzer") << " Total events = " << setw(7) << nevents[0] << " " << setw(7) << nevents[1]
<< " " << setw(7) << nevents[2] << " " << setw(7) << nevents[3] << " " << setw(7)
<< nevents[4] << " " << setw(7) << nevents[5] << " Selected events # is "
<< ipass;
}

//
Expand All @@ -340,16 +338,14 @@ void HOCalibAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& i
ievt = iEvent.id().event();
ilumi = iEvent.luminosityBlock();

edm::Handle<HOCalibVariableCollection> HOCalib;

iEvent.getByToken(tok_ho_, HOCalib);
const edm::Handle<HOCalibVariableCollection>& HOCalib = iEvent.getHandle(tok_ho_);

if (nevents[0] % 20000 == 1) {
edm::LogVerbatim("HOCalib") << "nmuon event # " << setw(7) << nevents[0] << " " << setw(7) << nevents[1] << " "
<< setw(7) << nevents[2] << " " << setw(7) << nevents[3] << " " << setw(7) << nevents[4]
<< " " << setw(7) << nevents[5];
edm::LogVerbatim("HOCalib") << " Run # " << iEvent.id().run() << " Evt # " << iEvent.id().event() << " "
<< int(HOCalib.isValid()) << " " << ipass;
edm::LogVerbatim("HOCalibAnalyzer") << "nmuon event # " << setw(7) << nevents[0] << " " << setw(7) << nevents[1]
<< " " << setw(7) << nevents[2] << " " << setw(7) << nevents[3] << " "
<< setw(7) << nevents[4] << " " << setw(7) << nevents[5];
edm::LogVerbatim("HOCalibAnalyzer") << " Run # " << iEvent.id().run() << " Evt # " << iEvent.id().event() << " "
<< int(HOCalib.isValid()) << " " << ipass;
}

if (HOCalib.isValid()) {
Expand Down Expand Up @@ -397,13 +393,13 @@ void HOCalibAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& i
for (int ij = 0; ij < 9; ij++) {
hosig[ij] = (*hoC).hosig[ij];
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HOCalib") << "hosig " << ij << " " << hosig[ij];
edm::LogVerbatim("HOCalibAnalyzer") << "hosig " << ij << " " << hosig[ij];
#endif
}
for (int ij = 0; ij < 18; ij++) {
hocorsig[ij] = (*hoC).hocorsig[ij];
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HOCalib") << "hocorsig " << ij << " " << hocorsig[ij];
edm::LogVerbatim("HOCalibAnalyzer") << "hocorsig " << ij << " " << hocorsig[ij];
#endif
}
hocro = (*hoC).hocro;
Expand Down Expand Up @@ -444,10 +440,6 @@ void HOCalibAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& i
nevents[5]++;
int iphi = abs(isect) % 100;

int tmpsect = int((iphi + 1) / 6.) + 1;
if (tmpsect > 12)
tmpsect = 1;

int iring = 0;

int iring2 = iring + 2;
Expand Down
96 changes: 46 additions & 50 deletions Calibration/HcalCalibAlgos/plugins/HcalCalibrator.cc
Expand Up @@ -51,7 +51,7 @@ to the actual calibration code in "endJob()".
class HcalCalibrator : public edm::one::EDAnalyzer<> {
public:
explicit HcalCalibrator(const edm::ParameterSet&);
~HcalCalibrator() override;
~HcalCalibrator() override = default;

// Added for running the CaloTower creation algorithm

Expand All @@ -60,46 +60,46 @@ class HcalCalibrator : public edm::one::EDAnalyzer<> {
void analyze(const edm::Event&, const edm::EventSetup&) override;
void endJob() override;

std::string mOutputFile;
std::string mInputFileList;
const std::string mOutputFile;
const std::string mInputFileList;

std::string mCalibType;
std::string mCalibMethod;
double mMinTargetE;
double mMaxTargetE;
double mMinCellE;
double mMinEOverP;
double mMaxEOverP;
double mMaxTrkEmE;
const std::string mCalibType;
const std::string mCalibMethod;
const double mMinTargetE;
const double mMaxTargetE;
const double mMinCellE;
const double mMinEOverP;
const double mMaxEOverP;
const double mMaxTrkEmE;

double mMaxEtThirdJet;
double mMinDPhiDiJets;
bool mSumDepths;
bool mSumSmallDepths;
bool mCombinePhi;
int mHbClusterSize;
int mHeClusterSize;
const double mMaxEtThirdJet;
const double mMinDPhiDiJets;
const bool mSumDepths;
const bool mSumSmallDepths;
const bool mCombinePhi;
const int mHbClusterSize;
const int mHeClusterSize;

bool mUseConeClustering;
double mMaxConeDist;
const bool mUseConeClustering;
const double mMaxConeDist;

int mCalibAbsIEtaMax;
int mCalibAbsIEtaMin;
const int mCalibAbsIEtaMax;
const int mCalibAbsIEtaMin;

double mMaxProbeJetEmFrac;
double mMaxTagJetEmFrac;
double mMaxTagJetAbsEta;
double mMinTagJetEt;
double mMinProbeJetAbsEta;
const double mMaxProbeJetEmFrac;
const double mMaxTagJetEmFrac;
const double mMaxTagJetAbsEta;
const double mMinTagJetEt;
const double mMinProbeJetAbsEta;

std::string mPhiSymCorFileName;
bool mApplyPhiSymCorFlag;
const std::string mPhiSymCorFileName;
const bool mApplyPhiSymCorFlag;

std::string mOutputCorCoefFileName;
std::string mHistoFileName;
const std::string mOutputCorCoefFileName;
const std::string mHistoFileName;

edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tok_geom_;
edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> tok_htopo_;
const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tok_geom_;
const edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> tok_htopo_;

const CaloGeometry* mTheCaloGeometry;
const HcalTopology* mTheHcalTopology;
Expand Down Expand Up @@ -141,14 +141,9 @@ HcalCalibrator::HcalCalibrator(const edm::ParameterSet& conf)
mPhiSymCorFileName(conf.getUntrackedParameter<std::string>("phiSymCorFileName")),
mApplyPhiSymCorFlag(conf.getUntrackedParameter<bool>("applyPhiSymCorFlag")),
mOutputCorCoefFileName(conf.getUntrackedParameter<std::string>("outputCorCoefFileName")),
mHistoFileName(conf.getUntrackedParameter<std::string>("histoFileName")) {
tok_geom_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
tok_htopo_ = esConsumes<HcalTopology, HcalRecNumberingRecord>();
}

// destructor

HcalCalibrator::~HcalCalibrator() {}
mHistoFileName(conf.getUntrackedParameter<std::string>("histoFileName")),
tok_geom_(esConsumes<CaloGeometry, CaloGeometryRecord>()),
tok_htopo_(esConsumes<HcalTopology, HcalRecNumberingRecord>()) {}

// ------------ method called to for each event ------------

Expand All @@ -165,26 +160,27 @@ void HcalCalibrator::beginJob() {}

void HcalCalibrator::endJob() {
if (mCalibType != "DI_JET" && mCalibType != "ISO_TRACK") {
edm::LogVerbatim("HcalCalib") << "\n\nUnknown calibration type " << mCalibType;
edm::LogVerbatim("HcalCalib") << "Please select ISO_TRACK or DI_JET in the python file.";
edm::LogVerbatim("HcalCalibrator") << "\n\nUnknown calibration type " << mCalibType;
edm::LogVerbatim("HcalCalibrator") << "Please select ISO_TRACK or DI_JET in the python file.";
return;
}

if (mCalibMethod != "L3" && mCalibMethod != "MATRIX_INV_OF_ETA_AVE" && mCalibMethod != "L3_AND_MTRX_INV") {
edm::LogVerbatim("HcalCalib") << "\n\nUnknown calibration method " << mCalibMethod;
edm::LogVerbatim("HcalCalib")
edm::LogVerbatim("HcalCalibrator") << "\n\nUnknown calibration method " << mCalibMethod;
edm::LogVerbatim("HcalCalibrator")
<< "Supported methods for IsoTrack calibration are: L3, MATRIX_INV_OF_ETA_AVE, L3_AND_MTRX_INV";
edm::LogVerbatim("HcalCalib") << "For DiJets the supported method is L3";
edm::LogVerbatim("HcalCalibrator") << "For DiJets the supported method is L3";
return;
}

if (mCalibType == "DI_JET" && mCalibMethod != "L3") {
edm::LogVerbatim("HcalCalib") << "\n\nDiJet calibration can use only the L3 method. Please change the python file.";
edm::LogVerbatim("HcalCalibrator")
<< "\n\nDiJet calibration can use only the L3 method. Please change the python file.";
return;
}

if (mCalibAbsIEtaMin < 1 || mCalibAbsIEtaMax > 41 || mCalibAbsIEtaMin > mCalibAbsIEtaMax) {
edm::LogVerbatim("HcalCalib")
edm::LogVerbatim("HcalCalibrator")
<< "\n\nInvalid ABS(iEta) calibration range. Check calibAbsIEtaMin and calibAbsIEtaMax in the python file.";
return;
}
Expand Down Expand Up @@ -243,9 +239,9 @@ void HcalCalibrator::endJob() {
}
inputFileList.close();

edm::LogVerbatim("HcalCalib") << "\nInput files for processing:";
edm::LogVerbatim("HcalCalibrator") << "\nInput files for processing:";
for (std::vector<TString>::iterator it = inputFiles.begin(); it != inputFiles.end(); ++it) {
edm::LogVerbatim("HcalCalib") << "file: " << it->Data();
edm::LogVerbatim("HcalCalibrator") << "file: " << it->Data();
}

TChain* fChain = new TChain("hcalCalibTree");
Expand Down
27 changes: 12 additions & 15 deletions Calibration/HcalCalibAlgos/plugins/HitReCalibrator.cc
Expand Up @@ -46,22 +46,22 @@ namespace cms {

bool allowMissingInputs_;

edm::EDGetTokenT<HBHERecHitCollection> tok_hbhe_;
edm::EDGetTokenT<HORecHitCollection> tok_ho_;
edm::EDGetTokenT<HFRecHitCollection> tok_hf_;
const edm::EDGetTokenT<HBHERecHitCollection> tok_hbhe_;
const edm::EDGetTokenT<HORecHitCollection> tok_ho_;
const edm::EDGetTokenT<HFRecHitCollection> tok_hf_;

edm::ESGetToken<HcalRespCorrs, HcalRespCorrsRcd> tok_resp_;
const edm::ESGetToken<HcalRespCorrs, HcalRespCorrsRcd> tok_resp_;
};
} // end namespace cms

namespace cms {

HitReCalibrator::HitReCalibrator(const edm::ParameterSet& iConfig) {
tok_hbhe_ = consumes<HBHERecHitCollection>(iConfig.getParameter<edm::InputTag>("hbheInput"));
tok_ho_ = consumes<HORecHitCollection>(iConfig.getParameter<edm::InputTag>("hoInput"));
tok_hf_ = consumes<HFRecHitCollection>(iConfig.getParameter<edm::InputTag>("hfInput"));
HitReCalibrator::HitReCalibrator(const edm::ParameterSet& iConfig)
: tok_hbhe_(consumes<HBHERecHitCollection>(iConfig.getParameter<edm::InputTag>("hbheInput"))),
tok_ho_(consumes<HORecHitCollection>(iConfig.getParameter<edm::InputTag>("hoInput"))),
tok_hf_(consumes<HFRecHitCollection>(iConfig.getParameter<edm::InputTag>("hfInput"))),
tok_resp_(esConsumes<HcalRespCorrs, HcalRespCorrsRcd>()) {
allowMissingInputs_ = true;
tok_resp_ = esConsumes<HcalRespCorrs, HcalRespCorrsRcd>();

//register your products

Expand All @@ -82,8 +82,7 @@ namespace cms {
const HcalRespCorrs* jetRecalib = &iSetup.getData(tok_resp_);

try {
edm::Handle<HBHERecHitCollection> hbhe;
iEvent.getByToken(tok_hbhe_, hbhe);
const edm::Handle<HBHERecHitCollection>& hbhe = iEvent.getHandle(tok_hbhe_);
const HBHERecHitCollection Hithbhe = *(hbhe.product());
for (HBHERecHitCollection::const_iterator hbheItr = Hithbhe.begin(); hbheItr != Hithbhe.end(); hbheItr++) {
DetId id = hbheItr->detid();
Expand All @@ -105,8 +104,7 @@ namespace cms {
}

try {
edm::Handle<HORecHitCollection> ho;
iEvent.getByToken(tok_ho_, ho);
const edm::Handle<HORecHitCollection>& ho = iEvent.getHandle(tok_ho_);
const HORecHitCollection Hitho = *(ho.product());
for (HORecHitCollection::const_iterator hoItr = Hitho.begin(); hoItr != Hitho.end(); hoItr++) {
DetId id = hoItr->detid();
Expand All @@ -128,8 +126,7 @@ namespace cms {
}

try {
edm::Handle<HFRecHitCollection> hf;
iEvent.getByToken(tok_hf_, hf);
const edm::Handle<HFRecHitCollection>& hf = iEvent.getHandle(tok_hf_);
const HFRecHitCollection Hithf = *(hf.product());
for (HFRecHitCollection::const_iterator hfItr = Hithf.begin(); hfItr != Hithf.end(); hfItr++) {
DetId id = hfItr->detid();
Expand Down

0 comments on commit 0aad040

Please sign in to comment.