Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-18 08:23:04

0001 // -*- C++ -*-F
0002 //---------------------------------------------------------------------------------
0003 // Package:    HcalCalibrator
0004 // Class:      HcalCalibrator
0005 //
0006 /**\class HcalCalibrator HcalCalibrator.cc MyPackages/HcalCalibrator/src/HcalCalibrator.cc
0007 
0008 Description: <one line class summary>
0009 
0010 Implementation:
0011 
0012 This is an interface to run the the hcal calibration code for isolated tracsk and dijets.
0013 It takes tha parameters for the calibration settings from a python file and passes them 
0014 to the actual calibration code in "endJob()". 
0015 
0016 
0017 
0018 */
0019 //
0020 // Original Author:  "Anton Anastassov"
0021 //         Created:  Tue Sept 24 09:13:48 CDT 2008
0022 //
0023 //
0024 //_________________________________________________________________________________
0025 
0026 // system include files
0027 #include <memory>
0028 #include <fstream>
0029 #include <iostream>
0030 #include <string>
0031 
0032 // user include files
0033 
0034 #include "Calibration/HcalCalibAlgos/interface/hcalCalib.h"
0035 #include "DataFormats/Common/interface/Handle.h"
0036 
0037 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0038 #include "FWCore/Framework/interface/Event.h"
0039 #include "FWCore/Framework/interface/EventSetup.h"
0040 #include "FWCore/Framework/interface/Frameworkfwd.h"
0041 #include "FWCore/Framework/interface/MakerMacros.h"
0042 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0043 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0044 #include "FWCore/ServiceRegistry/interface/Service.h"
0045 
0046 #include "Geometry/CaloTopology/interface/HcalTopology.h"
0047 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0048 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0049 #include "Geometry/Records/interface/HcalRecNumberingRecord.h"
0050 
0051 class HcalCalibrator : public edm::one::EDAnalyzer<> {
0052 public:
0053   explicit HcalCalibrator(const edm::ParameterSet&);
0054   ~HcalCalibrator() override = default;
0055 
0056   // Added for running the CaloTower creation algorithm
0057 
0058 private:
0059   void beginJob() override;
0060   void analyze(const edm::Event&, const edm::EventSetup&) override;
0061   void endJob() override;
0062 
0063   const std::string mOutputFile;
0064   const std::string mInputFileList;
0065 
0066   const std::string mCalibType;
0067   const std::string mCalibMethod;
0068   const double mMinTargetE;
0069   const double mMaxTargetE;
0070   const double mMinCellE;
0071   const double mMinEOverP;
0072   const double mMaxEOverP;
0073   const double mMaxTrkEmE;
0074 
0075   const double mMaxEtThirdJet;
0076   const double mMinDPhiDiJets;
0077   const bool mSumDepths;
0078   const bool mSumSmallDepths;
0079   const bool mCombinePhi;
0080   const int mHbClusterSize;
0081   const int mHeClusterSize;
0082 
0083   const bool mUseConeClustering;
0084   const double mMaxConeDist;
0085 
0086   const int mCalibAbsIEtaMax;
0087   const int mCalibAbsIEtaMin;
0088 
0089   const double mMaxProbeJetEmFrac;
0090   const double mMaxTagJetEmFrac;
0091   const double mMaxTagJetAbsEta;
0092   const double mMinTagJetEt;
0093   const double mMinProbeJetAbsEta;
0094 
0095   const std::string mPhiSymCorFileName;
0096   const bool mApplyPhiSymCorFlag;
0097 
0098   const std::string mOutputCorCoefFileName;
0099   const std::string mHistoFileName;
0100 
0101   const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tok_geom_;
0102   const edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> tok_htopo_;
0103 
0104   const CaloGeometry* mTheCaloGeometry;
0105   const HcalTopology* mTheHcalTopology;
0106 
0107   bool allowMissingInputs_;
0108 };
0109 
0110 // constructor
0111 
0112 HcalCalibrator::HcalCalibrator(const edm::ParameterSet& conf)
0113     : mInputFileList(conf.getUntrackedParameter<std::string>("inputFileList")),
0114       //  mOutputFile(conf.getUntrackedParameter<std::string>("outputFile")),
0115       mCalibType(conf.getUntrackedParameter<std::string>("calibType")),
0116       mCalibMethod(conf.getUntrackedParameter<std::string>("calibMethod")),
0117       mMinTargetE(conf.getUntrackedParameter<double>("minTargetE")),
0118       mMaxTargetE(conf.getUntrackedParameter<double>("maxTargetE")),
0119       mMinCellE(conf.getUntrackedParameter<double>("minCellE")),
0120       mMinEOverP(conf.getUntrackedParameter<double>("minEOverP")),
0121       mMaxEOverP(conf.getUntrackedParameter<double>("maxEOverP")),
0122       mMaxTrkEmE(conf.getUntrackedParameter<double>("maxTrkEmE")),
0123       mMaxEtThirdJet(conf.getUntrackedParameter<double>("maxEtThirdJet")),
0124       mMinDPhiDiJets(conf.getUntrackedParameter<double>("minDPhiDiJets")),
0125       mSumDepths(conf.getUntrackedParameter<bool>("sumDepths")),
0126       mSumSmallDepths(conf.getUntrackedParameter<bool>("sumSmallDepths")),
0127       mCombinePhi(conf.getUntrackedParameter<bool>("combinePhi")),
0128       mHbClusterSize(conf.getUntrackedParameter<int>("hbClusterSize")),
0129       mHeClusterSize(conf.getUntrackedParameter<int>("heClusterSize")),
0130 
0131       mUseConeClustering(conf.getUntrackedParameter<bool>("useConeClustering")),
0132       mMaxConeDist(conf.getUntrackedParameter<double>("maxConeDist")),
0133 
0134       mCalibAbsIEtaMax(conf.getUntrackedParameter<int>("calibAbsIEtaMax")),
0135       mCalibAbsIEtaMin(conf.getUntrackedParameter<int>("calibAbsIEtaMin")),
0136       mMaxProbeJetEmFrac(conf.getUntrackedParameter<double>("maxProbeJetEmFrac")),
0137       mMaxTagJetEmFrac(conf.getUntrackedParameter<double>("maxTagJetEmFrac")),
0138       mMaxTagJetAbsEta(conf.getUntrackedParameter<double>("maxTagJetAbsEta")),
0139       mMinTagJetEt(conf.getUntrackedParameter<double>("minTagJetEt")),
0140       mMinProbeJetAbsEta(conf.getUntrackedParameter<double>("minProbeJetAbsEta")),
0141       mPhiSymCorFileName(conf.getUntrackedParameter<std::string>("phiSymCorFileName")),
0142       mApplyPhiSymCorFlag(conf.getUntrackedParameter<bool>("applyPhiSymCorFlag")),
0143       mOutputCorCoefFileName(conf.getUntrackedParameter<std::string>("outputCorCoefFileName")),
0144       mHistoFileName(conf.getUntrackedParameter<std::string>("histoFileName")),
0145       tok_geom_(esConsumes<CaloGeometry, CaloGeometryRecord>()),
0146       tok_htopo_(esConsumes<HcalTopology, HcalRecNumberingRecord>()) {}
0147 
0148 // ------------ method called to for each event  ------------
0149 
0150 void HcalCalibrator::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0151   mTheCaloGeometry = &iSetup.getData(tok_geom_);
0152   mTheHcalTopology = &iSetup.getData(tok_htopo_);
0153 }
0154 
0155 // ------------ method called once each job just before starting event loop  ------------
0156 
0157 void HcalCalibrator::beginJob() {}
0158 
0159 // ------------ method called once each job just after ending the event loop  ------------
0160 
0161 void HcalCalibrator::endJob() {
0162   if (mCalibType != "DI_JET" && mCalibType != "ISO_TRACK") {
0163     edm::LogVerbatim("HcalCalibrator") << "\n\nUnknown calibration type " << mCalibType;
0164     edm::LogVerbatim("HcalCalibrator") << "Please select ISO_TRACK or DI_JET in the python file.";
0165     return;
0166   }
0167 
0168   if (mCalibMethod != "L3" && mCalibMethod != "MATRIX_INV_OF_ETA_AVE" && mCalibMethod != "L3_AND_MTRX_INV") {
0169     edm::LogVerbatim("HcalCalibrator") << "\n\nUnknown calibration method " << mCalibMethod;
0170     edm::LogVerbatim("HcalCalibrator")
0171         << "Supported methods for IsoTrack calibration are: L3, MATRIX_INV_OF_ETA_AVE, L3_AND_MTRX_INV";
0172     edm::LogVerbatim("HcalCalibrator") << "For DiJets the supported method is L3";
0173     return;
0174   }
0175 
0176   if (mCalibType == "DI_JET" && mCalibMethod != "L3") {
0177     edm::LogVerbatim("HcalCalibrator")
0178         << "\n\nDiJet calibration can use only the L3 method. Please change the python file.";
0179     return;
0180   }
0181 
0182   if (mCalibAbsIEtaMin < 1 || mCalibAbsIEtaMax > 41 || mCalibAbsIEtaMin > mCalibAbsIEtaMax) {
0183     edm::LogVerbatim("HcalCalibrator")
0184         << "\n\nInvalid ABS(iEta) calibration range. Check calibAbsIEtaMin and calibAbsIEtaMax in the python file.";
0185     return;
0186   }
0187 
0188   hcalCalib* calibrator = new hcalCalib();
0189 
0190   // set the parameters controlling the calibratoration
0191 
0192   calibrator->SetCalibType(mCalibType);
0193   calibrator->SetCalibMethod(mCalibMethod);
0194   calibrator->SetMinTargetE(mMinTargetE);
0195   calibrator->SetMaxTargetE(mMaxTargetE);
0196   calibrator->SetMaxEtThirdJet(mMaxEtThirdJet);
0197   calibrator->SetMinDPhiDiJets(mMinDPhiDiJets);
0198   calibrator->SetSumDepthsFlag(mSumDepths);
0199   calibrator->SetSumSmallDepthsFlag(mSumSmallDepths);
0200   calibrator->SetCombinePhiFlag(mCombinePhi);
0201   calibrator->SetMinCellE(mMinCellE);
0202   calibrator->SetMinEOverP(mMinEOverP);
0203   calibrator->SetMaxEOverP(mMaxEOverP);
0204   calibrator->SetMaxTrkEmE(mMaxTrkEmE);
0205   calibrator->SetHbClusterSize(mHbClusterSize);
0206   calibrator->SetHeClusterSize(mHeClusterSize);
0207 
0208   calibrator->SetUseConeClustering(mUseConeClustering);
0209   calibrator->SetConeMaxDist(mMaxConeDist);
0210 
0211   calibrator->SetCalibAbsIEtaMax(mCalibAbsIEtaMax);
0212   calibrator->SetCalibAbsIEtaMin(mCalibAbsIEtaMin);
0213   calibrator->SetMaxProbeJetEmFrac(mMaxProbeJetEmFrac);
0214   calibrator->SetMaxTagJetEmFrac(mMaxTagJetEmFrac);
0215   calibrator->SetMaxTagJetAbsEta(mMaxTagJetAbsEta);
0216 
0217   calibrator->SetMinTagJetEt(mMinTagJetEt);
0218 
0219   calibrator->SetMinProbeJetAbsEta(mMinProbeJetAbsEta);
0220   calibrator->SetApplyPhiSymCorFlag(mApplyPhiSymCorFlag);
0221   calibrator->SetPhiSymCorFileName(mPhiSymCorFileName);
0222   calibrator->SetOutputCorCoefFileName(mOutputCorCoefFileName);
0223 
0224   calibrator->SetHistoFileName(mHistoFileName);
0225 
0226   calibrator->SetCaloGeometry(mTheCaloGeometry, mTheHcalTopology);
0227 
0228   std::ifstream inputFileList;  // contains list of input root files
0229 
0230   TString files = mInputFileList;
0231   inputFileList.open(files.Data());
0232 
0233   std::vector<TString> inputFiles;
0234   while (!inputFileList.eof()) {
0235     TString fileName;
0236     inputFileList >> fileName;
0237     if (!fileName.BeginsWith("#") && !fileName.Contains(" ") && fileName != "")
0238       inputFiles.push_back(fileName);
0239   }
0240   inputFileList.close();
0241 
0242   edm::LogVerbatim("HcalCalibrator") << "\nInput files for processing:";
0243   for (std::vector<TString>::iterator it = inputFiles.begin(); it != inputFiles.end(); ++it) {
0244     edm::LogVerbatim("HcalCalibrator") << "file: " << it->Data();
0245   }
0246 
0247   TChain* fChain = new TChain("hcalCalibTree");
0248 
0249   for (std::vector<TString>::iterator f_it = inputFiles.begin(); f_it != inputFiles.end(); ++f_it) {
0250     fChain->Add(f_it->Data());
0251   }
0252 
0253   fChain->Process(calibrator);
0254 
0255   if (fChain)
0256     delete fChain;
0257   delete calibrator;
0258 
0259   return;
0260 }
0261 
0262 //define this as a plug-in
0263 DEFINE_FWK_MODULE(HcalCalibrator);