Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-09-18 22:51:07

0001 #include <cassert>
0002 
0003 #include "RecoLocalCalo/HcalRecAlgos/interface/parseHBHEPhase1AlgoDescription.h"
0004 #include "FWCore/Framework/interface/ConsumesCollector.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 
0008 #include "RecoLocalCalo/HcalRecAlgos/interface/PulseShapeFitOOTPileupCorrection.h"
0009 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalDeterministicFit.h"
0010 
0011 // Phase 1 HBHE reco algorithm headers
0012 #include "RecoLocalCalo/HcalRecAlgos/interface/SimpleHBHEPhase1Algo.h"
0013 
0014 static std::unique_ptr<MahiFit> parseHBHEMahiDescription(const edm::ParameterSet& conf) {
0015   const bool iDynamicPed = conf.getParameter<bool>("dynamicPed");
0016   const double iTS4Thresh = conf.getParameter<double>("ts4Thresh");
0017   const double chiSqSwitch = conf.getParameter<double>("chiSqSwitch");
0018 
0019   const bool iApplyTimeSlew = conf.getParameter<bool>("applyTimeSlew");
0020 
0021   const bool iCalculateArrivalTime = conf.getParameter<bool>("calculateArrivalTime");
0022   const int iTimeAlgo = conf.getParameter<int>("timeAlgo");
0023   const double iThEnergeticPulses = conf.getParameter<double>("thEnergeticPulses");
0024   const double iMeanTime = conf.getParameter<double>("meanTime");
0025   const double iTimeSigmaHPD = conf.getParameter<double>("timeSigmaHPD");
0026   const double iTimeSigmaSiPM = conf.getParameter<double>("timeSigmaSiPM");
0027 
0028   const std::vector<int> iActiveBXs = conf.getParameter<std::vector<int>>("activeBXs");
0029   const int iNMaxItersMin = conf.getParameter<int>("nMaxItersMin");
0030   const int iNMaxItersNNLS = conf.getParameter<int>("nMaxItersNNLS");
0031   const double iDeltaChiSqThresh = conf.getParameter<double>("deltaChiSqThresh");
0032   const double iNnlsThresh = conf.getParameter<double>("nnlsThresh");
0033 
0034   std::unique_ptr<MahiFit> corr = std::make_unique<MahiFit>();
0035 
0036   corr->setParameters(iDynamicPed,
0037                       iTS4Thresh,
0038                       chiSqSwitch,
0039                       iApplyTimeSlew,
0040                       HcalTimeSlew::Medium,
0041                       iCalculateArrivalTime,
0042                       iTimeAlgo,
0043                       iThEnergeticPulses,
0044                       iMeanTime,
0045                       iTimeSigmaHPD,
0046                       iTimeSigmaSiPM,
0047                       iActiveBXs,
0048                       iNMaxItersMin,
0049                       iNMaxItersNNLS,
0050                       iDeltaChiSqThresh,
0051                       iNnlsThresh);
0052 
0053   return corr;
0054 }
0055 
0056 static std::unique_ptr<PulseShapeFitOOTPileupCorrection> parseHBHEMethod2Description(const edm::ParameterSet& conf) {
0057   const bool iPedestalConstraint = conf.getParameter<bool>("applyPedConstraint");
0058   const bool iTimeConstraint = conf.getParameter<bool>("applyTimeConstraint");
0059   const bool iAddPulseJitter = conf.getParameter<bool>("applyPulseJitter");
0060   const bool iApplyTimeSlew = conf.getParameter<bool>("applyTimeSlew");
0061   const double iTS4Min = conf.getParameter<double>("ts4Min");
0062   const std::vector<double> iTS4Max = conf.getParameter<std::vector<double>>("ts4Max");
0063   const double iPulseJitter = conf.getParameter<double>("pulseJitter");
0064   const double iTimeMean = conf.getParameter<double>("meanTime");
0065   const double iTimeSigHPD = conf.getParameter<double>("timeSigmaHPD");
0066   const double iTimeSigSiPM = conf.getParameter<double>("timeSigmaSiPM");
0067   const double iPedMean = conf.getParameter<double>("meanPed");
0068   const double iTMin = conf.getParameter<double>("timeMin");
0069   const double iTMax = conf.getParameter<double>("timeMax");
0070   const std::vector<double> its4Chi2 = conf.getParameter<std::vector<double>>("ts4chi2");
0071   const int iFitTimes = conf.getParameter<int>("fitTimes");
0072 
0073   if (iTimeConstraint)
0074     assert(iTimeSigHPD);
0075   if (iTimeConstraint)
0076     assert(iTimeSigSiPM);
0077 
0078   std::unique_ptr<PulseShapeFitOOTPileupCorrection> corr = std::make_unique<PulseShapeFitOOTPileupCorrection>();
0079 
0080   corr->setPUParams(iPedestalConstraint,
0081                     iTimeConstraint,
0082                     iAddPulseJitter,
0083                     iApplyTimeSlew,
0084                     iTS4Min,
0085                     iTS4Max,
0086                     iPulseJitter,
0087                     iTimeMean,
0088                     iTimeSigHPD,
0089                     iTimeSigSiPM,
0090                     iPedMean,
0091                     iTMin,
0092                     iTMax,
0093                     its4Chi2,
0094                     HcalTimeSlew::Medium,
0095                     iFitTimes);
0096 
0097   return corr;
0098 }
0099 
0100 static std::unique_ptr<HcalDeterministicFit> parseHBHEMethod3Description(const edm::ParameterSet& conf) {
0101   const bool iApplyTimeSlew = conf.getParameter<bool>("applyTimeSlewM3");
0102   const int iTimeSlewParsType = conf.getParameter<int>("timeSlewParsType");
0103   const double irespCorrM3 = conf.getParameter<double>("respCorrM3");
0104 
0105   std::unique_ptr<HcalDeterministicFit> fit = std::make_unique<HcalDeterministicFit>();
0106 
0107   fit->init((HcalTimeSlew::ParaSource)iTimeSlewParsType, HcalTimeSlew::Medium, iApplyTimeSlew, irespCorrM3);
0108 
0109   return fit;
0110 }
0111 
0112 std::unique_ptr<AbsHBHEPhase1Algo> parseHBHEPhase1AlgoDescription(const edm::ParameterSet& ps,
0113                                                                   edm::ConsumesCollector iC) {
0114   std::unique_ptr<AbsHBHEPhase1Algo> algo;
0115 
0116   const std::string& className = ps.getParameter<std::string>("Class");
0117 
0118   if (className == "SimpleHBHEPhase1Algo") {
0119     std::unique_ptr<MahiFit> mahi;
0120     std::unique_ptr<PulseShapeFitOOTPileupCorrection> m2;
0121     std::unique_ptr<HcalDeterministicFit> detFit;
0122 
0123     // only run Mahi OR Method 2 but not both
0124     if (ps.getParameter<bool>("useMahi") && ps.getParameter<bool>("useM2")) {
0125       throw cms::Exception("ConfigurationError")
0126           << "SimpleHBHEPhase1Algo does not allow both Mahi and Method 2 to be turned on together.";
0127     }
0128     if (ps.getParameter<bool>("useMahi"))
0129       mahi = parseHBHEMahiDescription(ps);
0130     if (ps.getParameter<bool>("useM2"))
0131       m2 = parseHBHEMethod2Description(ps);
0132     if (ps.getParameter<bool>("useM3"))
0133       detFit = parseHBHEMethod3Description(ps);
0134 
0135     algo = std::make_unique<SimpleHBHEPhase1Algo>(ps.getParameter<int>("firstSampleShift"),
0136                                                   ps.getParameter<int>("samplesToAdd"),
0137                                                   ps.getParameter<double>("correctionPhaseNS"),
0138                                                   ps.getParameter<double>("tdcTimeShift"),
0139                                                   ps.getParameter<bool>("correctForPhaseContainment"),
0140                                                   ps.getParameter<bool>("applyLegacyHBMCorrection"),
0141                                                   ps.getParameter<bool>("applyFixPCC"),
0142                                                   std::move(m2),
0143                                                   std::move(detFit),
0144                                                   std::move(mahi),
0145                                                   iC);
0146   }
0147 
0148   return algo;
0149 }
0150 
0151 edm::ParameterSetDescription fillDescriptionForParseHBHEPhase1Algo() {
0152   edm::ParameterSetDescription desc;
0153 
0154   desc.setAllowAnything();
0155   desc.add<std::string>("Class", "SimpleHBHEPhase1Algo");
0156   desc.add<bool>("useM2", false);
0157   desc.add<bool>("useM3", true);
0158   desc.add<bool>("useMahi", true);
0159   desc.add<int>("firstSampleShift", 0);
0160   desc.add<int>("samplesToAdd", 2);
0161   desc.add<double>("correctionPhaseNS", 6.0);
0162   desc.add<double>("tdcTimeShift", 0.0);
0163   desc.add<bool>("correctForPhaseContainment", true);
0164   desc.add<bool>("applyLegacyHBMCorrection", true);
0165   desc.add<bool>("calculateArrivalTime", false);
0166   desc.add<int>("timeAlgo", 1);
0167   desc.add<double>("thEnergeticPulses", 5.);
0168   desc.add<bool>("applyFixPCC", false);
0169 
0170   return desc;
0171 }