Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // system include files
0002 #include <atomic>
0003 #include <cmath>
0004 #include <memory>
0005 #include <string>
0006 #include <vector>
0007 
0008 // Root objects
0009 #include "TROOT.h"
0010 #include "TSystem.h"
0011 #include "TFile.h"
0012 #include "TProfile.h"
0013 #include "TDirectory.h"
0014 #include "TTree.h"
0015 #include "TLorentzVector.h"
0016 #include "TInterpreter.h"
0017 
0018 #include "CondFormats/EcalObjects/interface/EcalPFRecHitThresholds.h"
0019 #include "CondFormats/DataRecord/interface/EcalPFRecHitThresholdsRcd.h"
0020 
0021 #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
0022 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0023 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
0024 
0025 // Vertices
0026 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0027 #include "DataFormats/VertexReco/interface/Vertex.h"
0028 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0029 
0030 //Triggers
0031 #include "DataFormats/Common/interface/TriggerResults.h"
0032 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
0033 #include "DataFormats/HLTReco/interface/TriggerObject.h"
0034 #include "DataFormats/Luminosity/interface/LumiDetails.h"
0035 #include "DataFormats/Math/interface/LorentzVector.h"
0036 #include "DataFormats/Math/interface/deltaR.h"
0037 
0038 #include "L1Trigger/L1TGlobal/interface/L1TGlobalUtil.h"
0039 #include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
0040 #include "DataFormats/L1TGlobal/interface/GlobalExtBlk.h"
0041 #include "DataFormats/L1Trigger/interface/BXVector.h"
0042 
0043 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
0044 #include "CondFormats/DataRecord/interface/HcalRespCorrsRcd.h"
0045 #include "CondFormats/HcalObjects/interface/HcalRespCorrs.h"
0046 
0047 //Generator information
0048 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0049 #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
0050 #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
0051 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
0052 
0053 #include "FWCore/Framework/interface/Frameworkfwd.h"
0054 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0055 
0056 #include "FWCore/Framework/interface/Event.h"
0057 #include "FWCore/Framework/interface/MakerMacros.h"
0058 #include "FWCore/ServiceRegistry/interface/Service.h"
0059 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0060 #include "FWCore/Common/interface/TriggerNames.h"
0061 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0062 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0063 
0064 #include "Calibration/IsolatedParticles/interface/CaloPropagateTrack.h"
0065 #include "Calibration/IsolatedParticles/interface/ChargeIsolation.h"
0066 #include "Calibration/IsolatedParticles/interface/eCone.h"
0067 #include "Calibration/IsolatedParticles/interface/eECALMatrix.h"
0068 #include "Calibration/IsolatedParticles/interface/eHCALMatrix.h"
0069 
0070 #include "MagneticField/Engine/interface/MagneticField.h"
0071 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0072 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0073 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0074 #include "Geometry/Records/interface/CaloTopologyRecord.h"
0075 #include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h"
0076 #include "Geometry/CaloTopology/interface/HcalTopology.h"
0077 #include "Geometry/CaloTopology/interface/CaloTopology.h"
0078 #include "Geometry/HcalCommonData/interface/HcalDDDRecConstants.h"
0079 #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h"
0080 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h"
0081 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h"
0082 
0083 //#define EDM_ML_DEBUG
0084 
0085 class HcalIsoTrkSimAnalyzer : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
0086 public:
0087   explicit HcalIsoTrkSimAnalyzer(edm::ParameterSet const&);
0088   ~HcalIsoTrkSimAnalyzer() override = default;
0089 
0090   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0091 
0092 private:
0093   void analyze(edm::Event const&, edm::EventSetup const&) override;
0094   void beginJob() override;
0095   void beginRun(edm::Run const&, edm::EventSetup const&) override;
0096   void endRun(edm::Run const&, edm::EventSetup const&) override;
0097 
0098   std::array<int, 3> fillTree(std::vector<math::XYZTLorentzVector>& vecL1,
0099                               std::vector<math::XYZTLorentzVector>& vecL3,
0100                               math::XYZPoint& leadPV,
0101                               std::vector<spr::propagatedGenParticleID>& trackIDs,
0102                               const CaloGeometry* geo,
0103                               const CaloTopology* topo,
0104                               const HcalTopology* theHBHETopology,
0105                               const EcalChannelStatus* theEcalChStatus,
0106                               const EcalSeverityLevelAlgo* theEcalSevlv,
0107                               edm::Handle<EcalRecHitCollection>& barrelRecHitsHandle,
0108                               edm::Handle<EcalRecHitCollection>& endcapRecHitsHandle,
0109                               edm::Handle<HBHERecHitCollection>& hbhe,
0110                               const edm::Handle<CaloTowerCollection>& towerHandle,
0111                               edm::Handle<reco::GenParticleCollection>& genParticles,
0112                               const HcalRespCorrs* respCorrs);
0113   double dR(math::XYZTLorentzVector&, math::XYZTLorentzVector&);
0114   double rhoh(const edm::Handle<CaloTowerCollection>&);
0115   double eThreshold(const DetId& id, const CaloGeometry* geo) const;
0116   DetId newId(const DetId&);
0117   void storeEnergy(int indx,
0118                    const HcalRespCorrs* respCorrs,
0119                    const std::vector<DetId>& ids,
0120                    std::vector<double>& edet,
0121                    double& eHcal,
0122                    std::vector<unsigned int>* detIds,
0123                    std::vector<double>* hitEnergies);
0124   bool notaMuon(const reco::GenParticle* pTrack);
0125 
0126   l1t::L1TGlobalUtil* l1GtUtils_;
0127   HLTConfigProvider hltConfig_;
0128   const std::vector<std::string> trigNames_;
0129   const std::string processName_, l1Filter_;
0130   const std::string l2Filter_, l3Filter_;
0131   const double ptMin_, etaMax_;
0132   const double a_coneR_, a_mipR_, a_mipR2_, a_mipR3_;
0133   const double a_mipR4_, a_mipR5_, pTrackMin_, eEcalMax_;
0134   const double maxRestrictionP_, slopeRestrictionP_;
0135   const double hcalScale_, eIsolate1_, eIsolate2_;
0136   const double pTrackLow_, pTrackHigh_;
0137   const int prescaleLow_, prescaleHigh_;
0138   const int useRaw_, dataType_, mode_;
0139   const bool ignoreTrigger_, useL1Trigger_;
0140   const bool unCorrect_, collapseDepth_;
0141   const double hitEthrEB_, hitEthrEE0_, hitEthrEE1_;
0142   const double hitEthrEE2_, hitEthrEE3_;
0143   const double hitEthrEELo_, hitEthrEEHi_;
0144   const edm::InputTag triggerEvent_, theTriggerResultsLabel_;
0145   const std::string labelGenTrack_, labelRecVtx_, labelEB_;
0146   const std::string labelEE_, labelHBHE_, labelTower_, l1TrigName_;
0147   const std::vector<int> oldID_, newDepth_;
0148   const bool hep17_;
0149   const bool usePFThresh_;
0150   const std::string labelBS_, modnam_, prdnam_;
0151   const edm::InputTag algTag_, extTag_;
0152 
0153   edm::EDGetTokenT<trigger::TriggerEvent> tok_trigEvt_;
0154   edm::EDGetTokenT<edm::TriggerResults> tok_trigRes_;
0155   edm::EDGetTokenT<reco::BeamSpot> tok_bs_;
0156   edm::EDGetTokenT<reco::VertexCollection> tok_recVtx_;
0157   edm::EDGetTokenT<EcalRecHitCollection> tok_EB_;
0158   edm::EDGetTokenT<EcalRecHitCollection> tok_EE_;
0159   edm::EDGetTokenT<HBHERecHitCollection> tok_hbhe_;
0160   edm::EDGetTokenT<GenEventInfoProduct> tok_ew_;
0161   edm::EDGetTokenT<reco::GenParticleCollection> tok_parts_;
0162   edm::EDGetTokenT<CaloTowerCollection> tok_cala_;
0163   edm::EDGetTokenT<BXVector<GlobalAlgBlk> > tok_alg_;
0164 
0165   edm::ESGetToken<HcalDDDRecConstants, HcalRecNumberingRecord> tok_ddrec_;
0166   edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> tok_bFieldH_;
0167   edm::ESGetToken<EcalChannelStatus, EcalChannelStatusRcd> tok_ecalChStatus_;
0168   edm::ESGetToken<EcalSeverityLevelAlgo, EcalSeverityLevelAlgoRcd> tok_sevlv_;
0169   edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tok_geom_;
0170   edm::ESGetToken<CaloTopology, CaloTopologyRecord> tok_caloTopology_;
0171   edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> tok_htopo_;
0172   edm::ESGetToken<HcalRespCorrs, HcalRespCorrsRcd> tok_resp_;
0173   edm::ESGetToken<HepPDT::ParticleDataTable, PDTRecord> tok_pdt_;
0174   edm::ESGetToken<EcalPFRecHitThresholds, EcalPFRecHitThresholdsRcd> tok_ecalPFRecHitThresholds_;
0175 
0176   unsigned int nRun_, nLow_, nHigh_;
0177   double a_charIsoR_, a_coneR1_, a_coneR2_;
0178   const HcalDDDRecConstants* hdc_;
0179   const EcalPFRecHitThresholds* eThresholds_;
0180 
0181   std::vector<double> etabins_, phibins_;
0182   std::vector<int> oldDet_, oldEta_, oldDepth_;
0183   double etadist_, phidist_, etahalfdist_, phihalfdist_;
0184 
0185   TTree *tree, *tree2;
0186   unsigned int t_RunNo, t_EventNo;
0187   int t_Run, t_Event, t_DataType, t_ieta, t_iphi;
0188   int t_goodPV, t_nVtx, t_nTrk;
0189   double t_EventWeight, t_p, t_pt, t_phi;
0190   double t_l1pt, t_l1eta, t_l1phi;
0191   double t_l3pt, t_l3eta, t_l3phi;
0192   double t_mindR1, t_mindR2;
0193   double t_eMipDR, t_eMipDR2, t_eMipDR3, t_eMipDR4;
0194   double t_eMipDR5, t_hmaxNearP, t_gentrackP;
0195   double t_emaxNearP, t_eAnnular, t_hAnnular;
0196   double t_eHcal, t_eHcal10, t_eHcal30, t_rhoh;
0197   bool t_selectTk, t_qltyFlag, t_qltyMissFlag;
0198   bool t_qltyPVFlag, t_TrigPass, t_TrigPassSel;
0199   std::vector<unsigned int>*t_DetIds, *t_DetIds1, *t_DetIds3;
0200   std::vector<double>*t_HitEnergies, *t_HitEnergies1, *t_HitEnergies3;
0201   std::vector<bool>*t_trgbits, *t_hltbits;
0202   bool t_L1Bit;
0203   int t_Tracks, t_TracksProp, t_TracksSaved;
0204   int t_TracksLoose, t_TracksTight, t_allvertex;
0205   std::vector<int>*t_ietaAll, *t_ietaGood, *t_trackType;
0206 };
0207 
0208 HcalIsoTrkSimAnalyzer::HcalIsoTrkSimAnalyzer(const edm::ParameterSet& iConfig)
0209     : trigNames_(iConfig.getParameter<std::vector<std::string> >("triggers")),
0210       processName_(iConfig.getParameter<std::string>("processName")),
0211       l1Filter_(iConfig.getParameter<std::string>("l1Filter")),
0212       l2Filter_(iConfig.getParameter<std::string>("l2Filter")),
0213       l3Filter_(iConfig.getParameter<std::string>("l3Filter")),
0214       ptMin_(iConfig.getParameter<double>("pTMin")),
0215       etaMax_(iConfig.getParameter<double>("maxChargedHadronEta")),
0216       a_coneR_(iConfig.getParameter<double>("coneRadius")),
0217       a_mipR_(iConfig.getParameter<double>("coneRadiusMIP")),
0218       a_mipR2_(iConfig.getParameter<double>("coneRadiusMIP2")),
0219       a_mipR3_(iConfig.getParameter<double>("coneRadiusMIP3")),
0220       a_mipR4_(iConfig.getParameter<double>("coneRadiusMIP4")),
0221       a_mipR5_(iConfig.getParameter<double>("coneRadiusMIP5")),
0222       pTrackMin_(iConfig.getParameter<double>("minimumTrackP")),
0223       eEcalMax_(iConfig.getParameter<double>("maximumEcalEnergy")),
0224       maxRestrictionP_(iConfig.getParameter<double>("maxTrackP")),
0225       slopeRestrictionP_(iConfig.getParameter<double>("slopeTrackP")),
0226       hcalScale_(iConfig.getUntrackedParameter<double>("hHcalScale", 1.0)),
0227       eIsolate1_(iConfig.getParameter<double>("isolationEnergyTight")),
0228       eIsolate2_(iConfig.getParameter<double>("isolationEnergyLoose")),
0229       pTrackLow_(iConfig.getParameter<double>("momentumLow")),
0230       pTrackHigh_(iConfig.getParameter<double>("momentumHigh")),
0231       prescaleLow_(iConfig.getParameter<int>("prescaleLow")),
0232       prescaleHigh_(iConfig.getParameter<int>("prescaleHigh")),
0233       useRaw_(iConfig.getUntrackedParameter<int>("useRaw", 0)),
0234       dataType_(iConfig.getUntrackedParameter<int>("dataType", 0)),
0235       mode_(iConfig.getUntrackedParameter<int>("outMode", 11)),
0236       ignoreTrigger_(iConfig.getUntrackedParameter<bool>("ignoreTriggers", false)),
0237       useL1Trigger_(iConfig.getUntrackedParameter<bool>("useL1Trigger", false)),
0238       unCorrect_(iConfig.getUntrackedParameter<bool>("unCorrect", false)),
0239       collapseDepth_(iConfig.getUntrackedParameter<bool>("collapseDepth", false)),
0240       hitEthrEB_(iConfig.getParameter<double>("EBHitEnergyThreshold")),
0241       hitEthrEE0_(iConfig.getParameter<double>("EEHitEnergyThreshold0")),
0242       hitEthrEE1_(iConfig.getParameter<double>("EEHitEnergyThreshold1")),
0243       hitEthrEE2_(iConfig.getParameter<double>("EEHitEnergyThreshold2")),
0244       hitEthrEE3_(iConfig.getParameter<double>("EEHitEnergyThreshold3")),
0245       hitEthrEELo_(iConfig.getParameter<double>("EEHitEnergyThresholdLow")),
0246       hitEthrEEHi_(iConfig.getParameter<double>("EEHitEnergyThresholdHigh")),
0247       triggerEvent_(iConfig.getParameter<edm::InputTag>("labelTriggerEvent")),
0248       theTriggerResultsLabel_(iConfig.getParameter<edm::InputTag>("labelTriggerResult")),
0249       labelGenTrack_(iConfig.getParameter<std::string>("labelTrack")),
0250       labelRecVtx_(iConfig.getParameter<std::string>("labelVertex")),
0251       labelEB_(iConfig.getParameter<std::string>("labelEBRecHit")),
0252       labelEE_(iConfig.getParameter<std::string>("labelEERecHit")),
0253       labelHBHE_(iConfig.getParameter<std::string>("labelHBHERecHit")),
0254       labelTower_(iConfig.getParameter<std::string>("labelCaloTower")),
0255       l1TrigName_(iConfig.getUntrackedParameter<std::string>("l1TrigName", "L1_SingleJet60")),
0256       oldID_(iConfig.getUntrackedParameter<std::vector<int> >("oldID")),
0257       newDepth_(iConfig.getUntrackedParameter<std::vector<int> >("newDepth")),
0258       hep17_(iConfig.getUntrackedParameter<bool>("hep17")),
0259       usePFThresh_(iConfig.getParameter<bool>("usePFThreshold")),
0260       labelBS_(iConfig.getParameter<std::string>("labelBeamSpot")),
0261       modnam_(iConfig.getUntrackedParameter<std::string>("moduleName", "")),
0262       prdnam_(iConfig.getUntrackedParameter<std::string>("producerName", "")),
0263       algTag_(iConfig.getParameter<edm::InputTag>("algInputTag")),
0264       extTag_(iConfig.getParameter<edm::InputTag>("extInputTag")),
0265       tok_trigEvt_(consumes<trigger::TriggerEvent>(triggerEvent_)),
0266       tok_trigRes_(consumes<edm::TriggerResults>(theTriggerResultsLabel_)),
0267       tok_bs_(consumes<reco::BeamSpot>(labelBS_)),
0268       tok_recVtx_((modnam_.empty()) ? consumes<reco::VertexCollection>(labelRecVtx_)
0269                                     : consumes<reco::VertexCollection>(edm::InputTag(modnam_, labelRecVtx_, prdnam_))),
0270       tok_EB_((modnam_.empty()) ? consumes<EcalRecHitCollection>(edm::InputTag("ecalRecHit", labelEB_))
0271                                 : consumes<EcalRecHitCollection>(edm::InputTag(modnam_, labelEB_, prdnam_))),
0272       tok_EE_((modnam_.empty()) ? consumes<EcalRecHitCollection>(edm::InputTag("ecalRecHit", labelEE_))
0273                                 : consumes<EcalRecHitCollection>(edm::InputTag(modnam_, labelEE_, prdnam_))),
0274       tok_hbhe_((modnam_.empty()) ? consumes<HBHERecHitCollection>(labelHBHE_)
0275                                   : consumes<HBHERecHitCollection>(edm::InputTag(modnam_, labelHBHE_, prdnam_))),
0276       tok_ew_(consumes<GenEventInfoProduct>(edm::InputTag("generator"))),
0277       tok_parts_(consumes<reco::GenParticleCollection>(edm::InputTag("genParticles"))),
0278       tok_cala_(consumes<CaloTowerCollection>(labelTower_)),
0279       tok_alg_(consumes<BXVector<GlobalAlgBlk> >(algTag_)),
0280       tok_ddrec_(esConsumes<HcalDDDRecConstants, HcalRecNumberingRecord, edm::Transition::BeginRun>()),
0281       tok_bFieldH_(esConsumes<MagneticField, IdealMagneticFieldRecord>()),
0282       tok_ecalChStatus_(esConsumes<EcalChannelStatus, EcalChannelStatusRcd>()),
0283       tok_sevlv_(esConsumes<EcalSeverityLevelAlgo, EcalSeverityLevelAlgoRcd>()),
0284       tok_geom_(esConsumes<CaloGeometry, CaloGeometryRecord>()),
0285       tok_caloTopology_(esConsumes<CaloTopology, CaloTopologyRecord>()),
0286       tok_htopo_(esConsumes<HcalTopology, HcalRecNumberingRecord>()),
0287       tok_resp_(esConsumes<HcalRespCorrs, HcalRespCorrsRcd>()),
0288       tok_pdt_(esConsumes<HepPDT::ParticleDataTable, PDTRecord>()),
0289       tok_ecalPFRecHitThresholds_(esConsumes<EcalPFRecHitThresholds, EcalPFRecHitThresholdsRcd>()),
0290       nRun_(0),
0291       nLow_(0),
0292       nHigh_(0),
0293       hdc_(nullptr) {
0294   usesResource(TFileService::kSharedResource);
0295 
0296   //now do whatever initialization is needed
0297   const double isolationRadius(28.9), innerR(10.0), outerR(30.0);
0298   a_charIsoR_ = a_coneR_ + isolationRadius;
0299   a_coneR1_ = a_coneR_ + innerR;
0300   a_coneR2_ = a_coneR_ + outerR;
0301   // Different isolation cuts are described in DN-2016/029
0302   // Tight cut uses 2 GeV; Loose cut uses 10 GeV
0303   // Eta dependent cut uses (maxRestrictionP_ * exp(|ieta|*log(2.5)/18))
0304   // with the factor for exponential slopeRestrictionP_ = log(2.5)/18
0305   // maxRestrictionP_ = 8 GeV as came from a study
0306 
0307   for (unsigned int k = 0; k < oldID_.size(); ++k) {
0308     oldDet_.emplace_back((oldID_[k] / 10000) % 10);
0309     oldEta_.emplace_back((oldID_[k] / 100) % 100);
0310     oldDepth_.emplace_back(oldID_[k] % 100);
0311   }
0312 
0313   l1GtUtils_ =
0314       new l1t::L1TGlobalUtil(iConfig, consumesCollector(), *this, algTag_, extTag_, l1t::UseEventSetupIn::Event);
0315 
0316   if (modnam_.empty()) {
0317     edm::LogVerbatim("HcalIsoTrack") << "Labels used " << triggerEvent_ << " " << theTriggerResultsLabel_ << " "
0318                                      << labelBS_ << " " << labelRecVtx_ << " " << labelGenTrack_ << " "
0319                                      << edm::InputTag("ecalRecHit", labelEB_) << " "
0320                                      << edm::InputTag("ecalRecHit", labelEE_) << " " << labelHBHE_ << " "
0321                                      << labelTower_;
0322   } else {
0323     edm::LogVerbatim("HcalIsoTrack") << "Labels used " << triggerEvent_ << " " << theTriggerResultsLabel_ << " "
0324                                      << labelBS_ << " " << edm::InputTag(modnam_, labelRecVtx_, prdnam_) << " "
0325                                      << labelGenTrack_ << " " << edm::InputTag(modnam_, labelEB_, prdnam_) << " "
0326                                      << edm::InputTag(modnam_, labelEE_, prdnam_) << " "
0327                                      << edm::InputTag(modnam_, labelHBHE_, prdnam_) << " " << labelTower_;
0328   }
0329 
0330   edm::LogVerbatim("HcalIsoTrack") << "Parameters read from config file \n"
0331                                    << "\t minPt " << ptMin_ << "\t etaMax " << etaMax_ << "\t a_coneR " << a_coneR_
0332                                    << ":" << a_coneR1_ << ":" << a_coneR2_ << "\t a_charIsoR " << a_charIsoR_
0333                                    << "\t a_mipR " << a_mipR_ << "\t a_mipR2 " << a_mipR2_ << "\t a_mipR3 " << a_mipR3_
0334                                    << "\t a_mipR4 " << a_mipR4_ << "\t a_mipR5 " << a_mipR5_ << "\n pTrackMin_ "
0335                                    << pTrackMin_ << "\t eEcalMax_ " << eEcalMax_ << "\t maxRestrictionP_ "
0336                                    << maxRestrictionP_ << "\t slopeRestrictionP_ " << slopeRestrictionP_
0337                                    << "\t eIsolateStrong_ " << eIsolate1_ << "\t eIsolateSoft_ " << eIsolate2_
0338                                    << "\t hcalScale_ " << hcalScale_ << "\n\t momentumLow_ " << pTrackLow_
0339                                    << "\t prescaleLow_ " << prescaleLow_ << "\t momentumHigh_ " << pTrackHigh_
0340                                    << "\t prescaleHigh_ " << prescaleHigh_ << "\n\t useRaw_ " << useRaw_
0341                                    << "\t ignoreTrigger_ " << ignoreTrigger_ << "\n\t useL1Trigegr_ " << useL1Trigger_
0342                                    << "\t dataType_      " << dataType_ << "\t mode_          " << mode_
0343                                    << "\t unCorrect_     " << unCorrect_ << "\t collapseDepth_ " << collapseDepth_
0344                                    << "\t L1TrigName_    " << l1TrigName_ << "\nThreshold flag used " << usePFThresh_
0345                                    << " value for EB " << hitEthrEB_ << " EE " << hitEthrEE0_ << ":" << hitEthrEE1_
0346                                    << ":" << hitEthrEE2_ << ":" << hitEthrEE3_ << ":" << hitEthrEELo_ << ":"
0347                                    << hitEthrEEHi_;
0348   edm::LogVerbatim("HcalIsoTrack") << "Process " << processName_ << " L1Filter:" << l1Filter_
0349                                    << " L2Filter:" << l2Filter_ << " L3Filter:" << l3Filter_;
0350   for (unsigned int k = 0; k < trigNames_.size(); ++k) {
0351     edm::LogVerbatim("HcalIsoTrack") << "Trigger[" << k << "] " << trigNames_[k];
0352   }
0353   edm::LogVerbatim("HcalIsoTrack") << oldID_.size() << " DetIDs to be corrected with HEP17 flag:" << hep17_;
0354   for (unsigned int k = 0; k < oldID_.size(); ++k)
0355     edm::LogVerbatim("HcalIsoTrack") << "[" << k << "] Det " << oldDet_[k] << " EtaAbs " << oldEta_[k] << " Depth "
0356                                      << oldDepth_[k] << ":" << newDepth_[k];
0357 
0358   for (int i = 0; i < 10; i++)
0359     phibins_.push_back(-M_PI + 0.1 * (2 * i + 1) * M_PI);
0360   for (int i = 0; i < 8; ++i)
0361     etabins_.push_back(-2.1 + 0.6 * i);
0362   etadist_ = etabins_[1] - etabins_[0];
0363   phidist_ = phibins_[1] - phibins_[0];
0364   etahalfdist_ = 0.5 * etadist_;
0365   phihalfdist_ = 0.5 * phidist_;
0366   edm::LogVerbatim("HcalIsoTrack") << "EtaDist " << etadist_ << " " << etahalfdist_ << " PhiDist " << phidist_ << " "
0367                                    << phihalfdist_;
0368   unsigned int k1(0), k2(0);
0369   for (auto phi : phibins_) {
0370     edm::LogVerbatim("HcalIsoTrack") << "phibin_[" << k1 << "] " << phi;
0371     ++k1;
0372   }
0373   for (auto eta : etabins_) {
0374     edm::LogVerbatim("HcalIsoTrack") << "etabin_[" << k2 << "] " << eta;
0375     ++k2;
0376   }
0377 }
0378 
0379 void HcalIsoTrkSimAnalyzer::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
0380   t_Run = iEvent.id().run();
0381   t_Event = iEvent.id().event();
0382   t_DataType = dataType_;
0383 #ifdef EDM_ML_DEBUG
0384   edm::LogVerbatim("HcalIsoTrack") << "Run " << t_Run << " Event " << t_Event << " type " << t_DataType
0385                                    << " Luminosity " << iEvent.luminosityBlock() << " Bunch " << iEvent.bunchCrossing();
0386 #endif
0387   //Get magnetic field and ECAL channel status
0388   const MagneticField* bField = &iSetup.getData(tok_bFieldH_);
0389   const EcalChannelStatus* theEcalChStatus = &iSetup.getData(tok_ecalChStatus_);
0390   const EcalSeverityLevelAlgo* theEcalSevlv = &iSetup.getData(tok_sevlv_);
0391 
0392   // get calogeometry and calotopology
0393   const CaloGeometry* geo = &iSetup.getData(tok_geom_);
0394   const CaloTopology* caloTopology = &iSetup.getData(tok_caloTopology_);
0395   const HcalTopology* theHBHETopology = &iSetup.getData(tok_htopo_);
0396 
0397   // get response correction
0398   const HcalRespCorrs* resp = &iSetup.getData(tok_resp_);
0399   HcalRespCorrs* respCorrs = new HcalRespCorrs(*resp);
0400   respCorrs->setTopo(theHBHETopology);
0401 
0402   // get ECAL thresholds
0403   eThresholds_ = &iSetup.getData(tok_ecalPFRecHitThresholds_);
0404 
0405   // get particle data table
0406   const HepPDT::ParticleDataTable* pdt = &iSetup.getData(tok_pdt_);
0407 
0408   //=== genParticle information
0409   bool okC(true);
0410   edm::Handle<reco::GenParticleCollection> genParticles = iEvent.getHandle(tok_parts_);
0411   if (!genParticles.isValid()) {
0412     edm::LogWarning("HcalIsoTrack") << "Cannot access the genParticles collection";
0413     okC = false;
0414   }
0415 
0416   //event weight for FLAT sample
0417   t_EventWeight = 1.0;
0418   const edm::Handle<GenEventInfoProduct> genEventInfo = iEvent.getHandle(tok_ew_);
0419   if (genEventInfo.isValid())
0420     t_EventWeight = genEventInfo->weight();
0421 
0422   //Define the best vertex and the beamspot
0423   const edm::Handle<reco::VertexCollection> recVtxs = iEvent.getHandle(tok_recVtx_);
0424   const edm::Handle<reco::BeamSpot> beamSpotH = iEvent.getHandle(tok_bs_);
0425   math::XYZPoint leadPV(0, 0, 0);
0426   t_goodPV = t_nVtx = 0;
0427   if (recVtxs.isValid() && !(recVtxs->empty())) {
0428     t_nVtx = recVtxs->size();
0429     for (unsigned int k = 0; k < recVtxs->size(); ++k) {
0430       if (!((*recVtxs)[k].isFake()) && ((*recVtxs)[k].ndof() > 4)) {
0431         if (t_goodPV == 0)
0432           leadPV = math::XYZPoint((*recVtxs)[k].x(), (*recVtxs)[k].y(), (*recVtxs)[k].z());
0433         t_goodPV++;
0434       }
0435     }
0436   }
0437   if (t_goodPV == 0 && beamSpotH.isValid()) {
0438     leadPV = beamSpotH->position();
0439   }
0440   t_allvertex = t_goodPV;
0441 #ifdef EDM_ML_DEBUG
0442   edm::LogVerbatim("HcalIsoTrack") << "Primary Vertex " << leadPV << " out of " << t_goodPV << " vertex";
0443   if (beamSpotH.isValid()) {
0444     edm::LogVerbatim("HcalIsoTrack") << " Beam Spot " << beamSpotH->position();
0445   }
0446 #endif
0447   // RecHits
0448   edm::Handle<EcalRecHitCollection> barrelRecHitsHandle = iEvent.getHandle(tok_EB_);
0449   if (!barrelRecHitsHandle.isValid()) {
0450     edm::LogWarning("HcalIsoTrack") << "Cannot access the collection " << labelEB_;
0451     okC = false;
0452   }
0453   edm::Handle<EcalRecHitCollection> endcapRecHitsHandle = iEvent.getHandle(tok_EE_);
0454   if (!endcapRecHitsHandle.isValid()) {
0455     edm::LogWarning("HcalIsoTrack") << "Cannot access the collection " << labelEE_;
0456     okC = false;
0457   }
0458   edm::Handle<HBHERecHitCollection> hbhe = iEvent.getHandle(tok_hbhe_);
0459   if (!hbhe.isValid()) {
0460     edm::LogWarning("HcalIsoTrack") << "Cannot access the collection " << labelHBHE_;
0461     okC = false;
0462   }
0463   const edm::Handle<CaloTowerCollection> caloTower = iEvent.getHandle(tok_cala_);
0464 
0465   //Propagate tracks to calorimeter surface)
0466   std::vector<spr::propagatedGenParticleID> trackIDs =
0467       spr::propagateCALO(genParticles, pdt, geo, bField, etaMax_, false);
0468   std::vector<math::XYZTLorentzVector> vecL1, vecL3;
0469   t_RunNo = iEvent.id().run();
0470   t_EventNo = iEvent.id().event();
0471   t_Tracks = (genParticles.product())->size();
0472   t_TracksProp = trackIDs.size();
0473   t_ietaAll->clear();
0474   t_ietaGood->clear();
0475   t_trackType->clear();
0476   t_trgbits->clear();
0477   t_hltbits->clear();
0478 #ifdef EDM_ML_DEBUG
0479   edm::LogVerbatim("HcalIsoTrack") << "# of propagated tracks " << t_TracksProp << " out of " << t_Tracks
0480                                    << " with Trigger " << ignoreTrigger_;
0481 #endif
0482 
0483   //Trigger
0484   t_trgbits->assign(trigNames_.size(), false);
0485   t_hltbits->assign(trigNames_.size(), false);
0486   t_TracksSaved = t_TracksLoose = t_TracksTight = 0;
0487   t_L1Bit = true;
0488   t_TrigPass = false;
0489 
0490   if (!ignoreTrigger_) {
0491     //L1
0492     l1GtUtils_->retrieveL1(iEvent, iSetup, tok_alg_);
0493     const std::vector<std::pair<std::string, bool> >& finalDecisions = l1GtUtils_->decisionsFinal();
0494     for (const auto& decision : finalDecisions) {
0495       if (decision.first.find(l1TrigName_) != std::string::npos) {
0496         t_L1Bit = decision.second;
0497         break;
0498       }
0499     }
0500 #ifdef EDM_ML_DEBUG
0501     edm::LogVerbatim("HcalIsoTrack") << "Trigger Information for " << l1TrigName_ << " is " << t_L1Bit
0502                                      << " from a list of " << finalDecisions.size() << " decisions";
0503 #endif
0504 
0505     //HLT
0506     const edm::Handle<edm::TriggerResults> triggerResults = iEvent.getHandle(tok_trigRes_);
0507     if (triggerResults.isValid()) {
0508       const edm::TriggerNames& triggerNames = iEvent.triggerNames(*triggerResults);
0509       const std::vector<std::string>& names = triggerNames.triggerNames();
0510       if (!trigNames_.empty()) {
0511         for (unsigned int iHLT = 0; iHLT < triggerResults->size(); iHLT++) {
0512           int hlt = triggerResults->accept(iHLT);
0513           for (unsigned int i = 0; i < trigNames_.size(); ++i) {
0514             if (names[iHLT].find(trigNames_[i]) != std::string::npos) {
0515               t_trgbits->at(i) = (hlt > 0);
0516               t_hltbits->at(i) = (hlt > 0);
0517               if (hlt > 0)
0518                 t_TrigPass = true;
0519 #ifdef EDM_ML_DEBUG
0520               edm::LogVerbatim("HcalIsoTrack")
0521                   << "This trigger " << names[iHLT] << " Flag " << hlt << ":" << t_trgbits->at(i);
0522 #endif
0523             }
0524           }
0525         }
0526       }
0527     }
0528 #ifdef EDM_ML_DEBUG
0529     edm::LogVerbatim("HcalIsoTrack") << "HLT Information shows " << t_TrigPass << ":" << trigNames_.empty() << ":"
0530                                      << okC;
0531 #endif
0532   }
0533 
0534   std::array<int, 3> ntksave{{0, 0, 0}};
0535   if (ignoreTrigger_ || useL1Trigger_) {
0536     t_l1pt = t_l1eta = t_l1phi = 0;
0537     t_l3pt = t_l3eta = t_l3phi = 0;
0538     if (ignoreTrigger_ || t_L1Bit)
0539       ntksave = fillTree(vecL1,
0540                          vecL3,
0541                          leadPV,
0542                          trackIDs,
0543                          geo,
0544                          caloTopology,
0545                          theHBHETopology,
0546                          theEcalChStatus,
0547                          theEcalSevlv,
0548                          barrelRecHitsHandle,
0549                          endcapRecHitsHandle,
0550                          hbhe,
0551                          caloTower,
0552                          genParticles,
0553                          respCorrs);
0554     t_TracksSaved = ntksave[0];
0555     t_TracksLoose = ntksave[1];
0556     t_TracksTight = ntksave[2];
0557   } else {
0558     trigger::TriggerEvent triggerEvent;
0559     edm::Handle<trigger::TriggerEvent> triggerEventHandle = iEvent.getHandle(tok_trigEvt_);
0560     if (!triggerEventHandle.isValid()) {
0561       edm::LogWarning("HcalIsoTrack") << "Error! Can't get the product " << triggerEvent_.label();
0562     } else if (okC) {
0563       triggerEvent = *(triggerEventHandle.product());
0564       const edm::Handle<edm::TriggerResults> triggerResults = iEvent.getHandle(tok_trigRes_);
0565       const trigger::TriggerObjectCollection& TOC(triggerEvent.getObjects());
0566       bool done(false);
0567       if (triggerResults.isValid()) {
0568         std::vector<std::string> modules;
0569         const edm::TriggerNames& triggerNames = iEvent.triggerNames(*triggerResults);
0570         const std::vector<std::string>& names = triggerNames.triggerNames();
0571         for (unsigned int iHLT = 0; iHLT < triggerResults->size(); iHLT++) {
0572           bool ok = (t_TrigPass) || (trigNames_.empty());
0573           if (ok) {
0574             unsigned int triggerindx = hltConfig_.triggerIndex(names[iHLT]);
0575             const std::vector<std::string>& moduleLabels(hltConfig_.moduleLabels(triggerindx));
0576             std::vector<math::XYZTLorentzVector> vecL2;
0577             vecL1.clear();
0578             vecL3.clear();
0579             //loop over all trigger filters in event (i.e. filters passed)
0580             for (unsigned int ifilter = 0; ifilter < triggerEvent.sizeFilters(); ++ifilter) {
0581               std::vector<int> Keys;
0582               std::string label = triggerEvent.filterTag(ifilter).label();
0583               //loop over keys to objects passing this filter
0584               for (unsigned int imodule = 0; imodule < moduleLabels.size(); imodule++) {
0585                 if (label.find(moduleLabels[imodule]) != std::string::npos) {
0586 #ifdef EDM_ML_DEBUG
0587                   edm::LogVerbatim("HcalIsoTrack") << "FilterName " << label;
0588 #endif
0589                   for (unsigned int ifiltrKey = 0; ifiltrKey < triggerEvent.filterKeys(ifilter).size(); ++ifiltrKey) {
0590                     Keys.push_back(triggerEvent.filterKeys(ifilter)[ifiltrKey]);
0591                     const trigger::TriggerObject& TO(TOC[Keys[ifiltrKey]]);
0592                     math::XYZTLorentzVector v4(TO.px(), TO.py(), TO.pz(), TO.energy());
0593                     if (label.find(l2Filter_) != std::string::npos) {
0594                       vecL2.push_back(v4);
0595                     } else if (label.find(l3Filter_) != std::string::npos) {
0596                       vecL3.push_back(v4);
0597                     } else if ((label.find(l1Filter_) != std::string::npos) || (l1Filter_.empty())) {
0598                       vecL1.push_back(v4);
0599                     }
0600 #ifdef EDM_ML_DEBUG
0601                     edm::LogVerbatim("HcalIsoTrack")
0602                         << "key " << ifiltrKey << " : pt " << TO.pt() << " eta " << TO.eta() << " phi " << TO.phi()
0603                         << " mass " << TO.mass() << " Id " << TO.id();
0604 #endif
0605                   }
0606 #ifdef EDM_ML_DEBUG
0607                   edm::LogVerbatim("HcalIsoTrack")
0608                       << "sizes " << vecL1.size() << ":" << vecL2.size() << ":" << vecL3.size();
0609 #endif
0610                 }
0611               }
0612             }
0613             //// deta, dphi and dR for leading L1 object with L2 objects
0614             math::XYZTLorentzVector mindRvec1;
0615             double mindR1(999);
0616             for (unsigned int i = 0; i < vecL2.size(); i++) {
0617               double dr = dR(vecL1[0], vecL2[i]);
0618 #ifdef EDM_ML_DEBUG
0619               edm::LogVerbatim("HcalIsoTrack") << "lvl2[" << i << "] dR " << dr;
0620 #endif
0621               if (dr < mindR1) {
0622                 mindR1 = dr;
0623                 mindRvec1 = vecL2[i];
0624               }
0625             }
0626 #ifdef EDM_ML_DEBUG
0627             edm::LogVerbatim("HcalIsoTrack") << "L2 object closest to L1 " << mindRvec1 << " at Dr " << mindR1;
0628 #endif
0629 
0630             if (!vecL1.empty()) {
0631               t_l1pt = vecL1[0].pt();
0632               t_l1eta = vecL1[0].eta();
0633               t_l1phi = vecL1[0].phi();
0634             } else {
0635               t_l1pt = t_l1eta = t_l1phi = 0;
0636             }
0637             if (!vecL3.empty()) {
0638               t_l3pt = vecL3[0].pt();
0639               t_l3eta = vecL3[0].eta();
0640               t_l3phi = vecL3[0].phi();
0641             } else {
0642               t_l3pt = t_l3eta = t_l3phi = 0;
0643             }
0644             // Now fill in the tree for each selected track
0645             if (!done) {
0646               ntksave = fillTree(vecL1,
0647                                  vecL3,
0648                                  leadPV,
0649                                  trackIDs,
0650                                  geo,
0651                                  caloTopology,
0652                                  theHBHETopology,
0653                                  theEcalChStatus,
0654                                  theEcalSevlv,
0655                                  barrelRecHitsHandle,
0656                                  endcapRecHitsHandle,
0657                                  hbhe,
0658                                  caloTower,
0659                                  genParticles,
0660                                  respCorrs);
0661               t_TracksSaved += ntksave[0];
0662               t_TracksLoose += ntksave[1];
0663               t_TracksTight += ntksave[2];
0664               done = true;
0665             }
0666           }
0667         }
0668       }
0669     }
0670   }
0671 #ifdef EDM_ML_DEBUG
0672   edm::LogVerbatim("HcalIsoTrack") << "Final results on selected tracks " << t_TracksSaved << ":" << t_TracksLoose
0673                                    << ":" << t_TracksTight;
0674 #endif
0675   t_TrigPassSel = (t_TracksSaved > 0);
0676   tree2->Fill();
0677 }
0678 
0679 void HcalIsoTrkSimAnalyzer::beginJob() {
0680   edm::Service<TFileService> fs;
0681   tree = fs->make<TTree>("CalibTree", "CalibTree");
0682 
0683   tree->Branch("t_Run", &t_Run, "t_Run/I");
0684   tree->Branch("t_Event", &t_Event, "t_Event/I");
0685   tree->Branch("t_DataType", &t_DataType, "t_DataType/I");
0686   tree->Branch("t_ieta", &t_ieta, "t_ieta/I");
0687   tree->Branch("t_iphi", &t_iphi, "t_iphi/I");
0688   tree->Branch("t_EventWeight", &t_EventWeight, "t_EventWeight/D");
0689   tree->Branch("t_nVtx", &t_nVtx, "t_nVtx/I");
0690   tree->Branch("t_nTrk", &t_nTrk, "t_nTrk/I");
0691   tree->Branch("t_goodPV", &t_goodPV, "t_goodPV/I");
0692   tree->Branch("t_l1pt", &t_l1pt, "t_l1pt/D");
0693   tree->Branch("t_l1eta", &t_l1eta, "t_l1eta/D");
0694   tree->Branch("t_l1phi", &t_l1phi, "t_l1phi/D");
0695   tree->Branch("t_l3pt", &t_l3pt, "t_l3pt/D");
0696   tree->Branch("t_l3eta", &t_l3eta, "t_l3eta/D");
0697   tree->Branch("t_l3phi", &t_l3phi, "t_l3phi/D");
0698   tree->Branch("t_p", &t_p, "t_p/D");
0699   tree->Branch("t_pt", &t_pt, "t_pt/D");
0700   tree->Branch("t_phi", &t_phi, "t_phi/D");
0701   tree->Branch("t_mindR1", &t_mindR1, "t_mindR1/D");
0702   tree->Branch("t_mindR2", &t_mindR2, "t_mindR2/D");
0703   tree->Branch("t_eMipDR", &t_eMipDR, "t_eMipDR/D");
0704   tree->Branch("t_eMipDR2", &t_eMipDR2, "t_eMipDR2/D");
0705   tree->Branch("t_eMipDR3", &t_eMipDR3, "t_eMipDR3/D");
0706   tree->Branch("t_eMipDR4", &t_eMipDR4, "t_eMipDR4/D");
0707   tree->Branch("t_eMipDR5", &t_eMipDR5, "t_eMipDR5/D");
0708   tree->Branch("t_eHcal", &t_eHcal, "t_eHcal/D");
0709   tree->Branch("t_eHcal10", &t_eHcal10, "t_eHcal10/D");
0710   tree->Branch("t_eHcal30", &t_eHcal30, "t_eHcal30/D");
0711   tree->Branch("t_hmaxNearP", &t_hmaxNearP, "t_hmaxNearP/D");
0712   tree->Branch("t_emaxNearP", &t_emaxNearP, "t_emaxNearP/D");
0713   tree->Branch("t_eAnnular", &t_eAnnular, "t_eAnnular/D");
0714   tree->Branch("t_hAnnular", &t_hAnnular, "t_hAnnular/D");
0715   tree->Branch("t_rhoh", &t_rhoh, "t_rhoh/D");
0716   tree->Branch("t_selectTk", &t_selectTk, "t_selectTk/O");
0717   tree->Branch("t_qltyFlag", &t_qltyFlag, "t_qltyFlag/O");
0718   tree->Branch("t_qltyMissFlag", &t_qltyMissFlag, "t_qltyMissFlag/O");
0719   tree->Branch("t_qltyPVFlag", &t_qltyPVFlag, "t_qltyPVFlag/O");
0720   tree->Branch("t_gentrackP", &t_gentrackP, "t_gentrackP/D");
0721 
0722   t_DetIds = new std::vector<unsigned int>();
0723   t_DetIds1 = new std::vector<unsigned int>();
0724   t_DetIds3 = new std::vector<unsigned int>();
0725   t_HitEnergies = new std::vector<double>();
0726   t_HitEnergies1 = new std::vector<double>();
0727   t_HitEnergies3 = new std::vector<double>();
0728   t_trgbits = new std::vector<bool>();
0729   tree->Branch("t_DetIds", "std::vector<unsigned int>", &t_DetIds);
0730   tree->Branch("t_HitEnergies", "std::vector<double>", &t_HitEnergies);
0731   tree->Branch("t_trgbits", "std::vector<bool>", &t_trgbits);
0732   tree->Branch("t_DetIds1", "std::vector<unsigned int>", &t_DetIds1);
0733   tree->Branch("t_DetIds3", "std::vector<unsigned int>", &t_DetIds3);
0734   tree->Branch("t_HitEnergies1", "std::vector<double>", &t_HitEnergies1);
0735   tree->Branch("t_HitEnergies3", "std::vector<double>", &t_HitEnergies3);
0736 
0737   tree2 = fs->make<TTree>("EventInfo", "Event Information");
0738 
0739   tree2->Branch("t_RunNo", &t_RunNo, "t_RunNo/i");
0740   tree2->Branch("t_EventNo", &t_EventNo, "t_EventNo/i");
0741   tree2->Branch("t_Tracks", &t_Tracks, "t_Tracks/I");
0742   tree2->Branch("t_TracksProp", &t_TracksProp, "t_TracksProp/I");
0743   tree2->Branch("t_TracksSaved", &t_TracksSaved, "t_TracksSaved/I");
0744   tree2->Branch("t_TracksLoose", &t_TracksLoose, "t_TracksLoose/I");
0745   tree2->Branch("t_TracksTight", &t_TracksTight, "t_TracksTight/I");
0746   tree2->Branch("t_TrigPass", &t_TrigPass, "t_TrigPass/O");
0747   tree2->Branch("t_TrigPassSel", &t_TrigPassSel, "t_TrigPassSel/O");
0748   tree2->Branch("t_L1Bit", &t_L1Bit, "t_L1Bit/O");
0749   tree2->Branch("t_allvertex", &t_allvertex, "t_allvertex/I");
0750   t_hltbits = new std::vector<bool>();
0751   t_ietaAll = new std::vector<int>();
0752   t_ietaGood = new std::vector<int>();
0753   t_trackType = new std::vector<int>();
0754   tree2->Branch("t_ietaAll", "std::vector<int>", &t_ietaAll);
0755   tree2->Branch("t_ietaGood", "std::vector<int>", &t_ietaGood);
0756   tree2->Branch("t_trackType", "std::vector<int>", &t_trackType);
0757   tree2->Branch("t_hltbits", "std::vector<bool>", &t_hltbits);
0758 }
0759 
0760 // ------------ method called when starting to processes a run  ------------
0761 void HcalIsoTrkSimAnalyzer::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
0762   hdc_ = &iSetup.getData(tok_ddrec_);
0763 
0764   bool changed_(true);
0765   bool flag = hltConfig_.init(iRun, iSetup, processName_, changed_);
0766   edm::LogVerbatim("HcalIsoTrack") << "Run[" << nRun_ << "] " << iRun.run() << " process " << processName_
0767                                    << " init flag " << flag << " change flag " << changed_;
0768   // check if trigger names in (new) config
0769   if (changed_) {
0770 #ifdef EDM_ML_DEBUG
0771     edm::LogVerbatim("HcalIsoTrack") << "New trigger menu found !!!";
0772 #endif
0773     const unsigned int n(hltConfig_.size());
0774     for (unsigned itrig = 0; itrig < trigNames_.size(); itrig++) {
0775       unsigned int triggerindx = hltConfig_.triggerIndex(trigNames_[itrig]);
0776       if (triggerindx >= n) {
0777         edm::LogWarning("HcalIsoTrack") << trigNames_[itrig] << " " << triggerindx << " does not exist in "
0778                                         << "the current menu";
0779 #ifdef EDM_ML_DEBUG
0780       } else {
0781         edm::LogVerbatim("HcalIsoTrack") << trigNames_[itrig] << " " << triggerindx << " exists";
0782 #endif
0783       }
0784     }
0785   }
0786 }
0787 
0788 // ------------ method called when ending the processing of a run  ------------
0789 void HcalIsoTrkSimAnalyzer::endRun(edm::Run const& iRun, edm::EventSetup const&) {
0790   nRun_++;
0791   edm::LogVerbatim("HcalIsoTrack") << "endRun[" << nRun_ << "] " << iRun.run();
0792 }
0793 
0794 void HcalIsoTrkSimAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0795   edm::ParameterSetDescription desc;
0796   std::vector<std::string> trig = {"HLT_PFJet40",
0797                                    "HLT_PFJet60",
0798                                    "HLT_PFJet80",
0799                                    "HLT_PFJet140",
0800                                    "HLT_PFJet200",
0801                                    "HLT_PFJet260",
0802                                    "HLT_PFJet320",
0803                                    "HLT_PFJet400",
0804                                    "HLT_PFJet450",
0805                                    "HLT_PFJet500"};
0806   desc.add<std::vector<std::string> >("triggers", trig);
0807   desc.add<std::string>("processName", "HLT");
0808   desc.add<std::string>("l1Filter", "");
0809   desc.add<std::string>("l2Filter", "L2Filter");
0810   desc.add<std::string>("l3Filter", "Filter");
0811   desc.add<double>("pTMin", 1.0), desc.add<double>("maxChargedHadronEta", 3.0);
0812   // Minimum momentum of selected isolated track and signal zone
0813   desc.add<double>("minimumTrackP", 10.0);
0814   desc.add<double>("coneRadius", 34.98);
0815   // signal zone in ECAL and MIP energy cutoff
0816   desc.add<double>("coneRadiusMIP", 14.0);
0817   desc.add<double>("coneRadiusMIP2", 18.0);
0818   desc.add<double>("coneRadiusMIP3", 20.0);
0819   desc.add<double>("coneRadiusMIP4", 22.0);
0820   desc.add<double>("coneRadiusMIP5", 24.0);
0821   desc.add<double>("maximumEcalEnergy", 2.0);
0822   // following 4 parameters are for isolation cuts and described in the code
0823   desc.add<double>("maxTrackP", 8.0);
0824   desc.add<double>("slopeTrackP", 0.05090504066);
0825   desc.add<double>("isolationEnergyTight", 2.0);
0826   desc.add<double>("isolationEnergyLoose", 10.0);
0827   // energy thershold for ECAL (from Egamma group)
0828   desc.add<double>("EBHitEnergyThreshold", 0.08);
0829   desc.add<double>("EEHitEnergyThreshold0", 0.30);
0830   desc.add<double>("EEHitEnergyThreshold1", 0.00);
0831   desc.add<double>("EEHitEnergyThreshold2", 0.00);
0832   desc.add<double>("EEHitEnergyThreshold3", 0.00);
0833   desc.add<double>("EEHitEnergyThresholdLow", 0.30);
0834   desc.add<double>("EEHitEnergyThresholdHigh", 0.30);
0835   // prescale factors
0836   desc.add<double>("momentumLow", 40.0);
0837   desc.add<double>("momentumHigh", 60.0);
0838   desc.add<int>("prescaleLow", 1);
0839   desc.add<int>("prescaleHigh", 1);
0840   // various labels for collections used in the code
0841   desc.add<edm::InputTag>("labelTriggerEvent", edm::InputTag("hltTriggerSummaryAOD", "", "HLT"));
0842   desc.add<edm::InputTag>("labelTriggerResult", edm::InputTag("TriggerResults", "", "HLT"));
0843   desc.add<std::string>("labelTrack", "generalTracks");
0844   desc.add<std::string>("labelVertex", "offlinePrimaryVertices");
0845   desc.add<std::string>("labelEBRecHit", "EcalRecHitsEB");
0846   desc.add<std::string>("labelEERecHit", "EcalRecHitsEE");
0847   desc.add<std::string>("labelHBHERecHit", "hbhereco");
0848   desc.add<std::string>("labelBeamSpot", "offlineBeamSpot");
0849   desc.add<std::string>("labelCaloTower", "towerMaker");
0850   desc.add<edm::InputTag>("algInputTag", edm::InputTag("gtStage2Digis"));
0851   desc.add<edm::InputTag>("extInputTag", edm::InputTag("gtStage2Digis"));
0852   desc.addUntracked<std::string>("moduleName", "");
0853   desc.addUntracked<std::string>("producerName", "");
0854   //  Various flags used for selecting tracks, choice of energy Method2/0
0855   //  Data type 0/1 for single jet trigger or others
0856   desc.addUntracked<int>("useRaw", 0);
0857   desc.addUntracked<bool>("ignoreTriggers", false);
0858   desc.addUntracked<bool>("useL1Trigger", false);
0859   desc.addUntracked<double>("hcalScale", 1.0);
0860   desc.addUntracked<int>("dataType", 0);
0861   desc.addUntracked<bool>("unCorrect", false);
0862   desc.addUntracked<bool>("collapseDepth", false);
0863   desc.addUntracked<std::string>("l1TrigName", "L1_SingleJet60");
0864   desc.addUntracked<int>("outMode", 11);
0865   std::vector<int> dummy;
0866   desc.addUntracked<std::vector<int> >("oldID", dummy);
0867   desc.addUntracked<std::vector<int> >("newDepth", dummy);
0868   desc.addUntracked<bool>("hep17", false);
0869   desc.add<bool>("usePFThreshold", true);
0870   descriptions.add("hcalIsoTrkSimAnalyzer", desc);
0871 }
0872 
0873 std::array<int, 3> HcalIsoTrkSimAnalyzer::fillTree(std::vector<math::XYZTLorentzVector>& vecL1,
0874                                                    std::vector<math::XYZTLorentzVector>& vecL3,
0875                                                    math::XYZPoint& leadPV,
0876                                                    std::vector<spr::propagatedGenParticleID>& trackIDs,
0877                                                    const CaloGeometry* geo,
0878                                                    const CaloTopology* caloTopology,
0879                                                    const HcalTopology* theHBHETopology,
0880                                                    const EcalChannelStatus* theEcalChStatus,
0881                                                    const EcalSeverityLevelAlgo* theEcalSevlv,
0882                                                    edm::Handle<EcalRecHitCollection>& barrelRecHitsHandle,
0883                                                    edm::Handle<EcalRecHitCollection>& endcapRecHitsHandle,
0884                                                    edm::Handle<HBHERecHitCollection>& hbhe,
0885                                                    const edm::Handle<CaloTowerCollection>& tower,
0886                                                    edm::Handle<reco::GenParticleCollection>& genParticles,
0887                                                    const HcalRespCorrs* respCorrs) {
0888   int nSave(0), nLoose(0), nTight(0);
0889   //Loop over tracks
0890   unsigned int nTracks(0), nselTracks(0);
0891   t_nTrk = trackIDs.size();
0892   t_rhoh = (tower.isValid()) ? rhoh(tower) : 0;
0893   for (auto const& trkDetItr : trackIDs) {
0894     const reco::GenParticle* pTrack = &(*(trkDetItr.trkItr));
0895     math::XYZTLorentzVector v4(pTrack->px(), pTrack->py(), pTrack->pz(), pTrack->p());
0896 #ifdef EDM_ML_DEBUG
0897     edm::LogVerbatim("HcalIsoTrack") << "This track : " << nTracks << " (pt|eta|phi|p) :" << pTrack->pt() << "|"
0898                                      << pTrack->eta() << "|" << pTrack->phi() << "|" << pTrack->p();
0899 #endif
0900     t_mindR2 = 999;
0901     for (unsigned int k = 0; k < vecL3.size(); ++k) {
0902       double dr = dR(vecL3[k], v4);
0903       if (dr < t_mindR2) {
0904         t_mindR2 = dr;
0905       }
0906     }
0907     t_mindR1 = (!vecL1.empty()) ? dR(vecL1[0], v4) : 999;
0908 #ifdef EDM_ML_DEBUG
0909     edm::LogVerbatim("HcalIsoTrack") << "Closest L3 object at dr :" << t_mindR2 << " and from L1 " << t_mindR1;
0910 #endif
0911     t_ieta = t_iphi = 0;
0912     if (trkDetItr.okHCAL) {
0913       HcalDetId detId = (HcalDetId)(trkDetItr.detIdHCAL);
0914       t_ieta = detId.ieta();
0915       t_iphi = detId.iphi();
0916       if (t_p > 40.0 && t_p <= 60.0)
0917         t_ietaAll->emplace_back(t_ieta);
0918     }
0919     //Selection of good track
0920     t_selectTk = t_qltyMissFlag = t_qltyPVFlag = true;
0921     double eIsolation = maxRestrictionP_ * exp(slopeRestrictionP_ * std::abs((double)t_ieta));
0922     if (eIsolation < eIsolate1_)
0923       eIsolation = eIsolate1_;
0924     if (eIsolation < eIsolate2_)
0925       eIsolation = eIsolate2_;
0926 #ifdef EDM_ML_DEBUG
0927     edm::LogVerbatim("HcalIsoTrack") << "qltyFlag|okECAL|okHCAL : " << t_qltyFlag << "|" << trkDetItr.okECAL << "|"
0928                                      << trkDetItr.okHCAL << " eIsolation " << eIsolation;
0929 #endif
0930     t_qltyFlag = (t_selectTk && trkDetItr.okECAL && trkDetItr.okHCAL);
0931     bool notMuon = notaMuon(pTrack);
0932     if (t_qltyFlag && notMuon) {
0933       nselTracks++;
0934       int nNearTRKs(0);
0935       ////////////////////////////////-MIP STUFF-//////////////////////////////
0936       std::vector<DetId> eIds;
0937       std::vector<double> eHit;
0938       t_eMipDR = spr::eCone_ecal(geo,
0939                                  barrelRecHitsHandle,
0940                                  endcapRecHitsHandle,
0941                                  trkDetItr.pointHCAL,
0942                                  trkDetItr.pointECAL,
0943                                  a_mipR_,
0944                                  trkDetItr.directionECAL,
0945                                  eIds,
0946                                  eHit);
0947       double eEcal(0);
0948       for (unsigned int k = 0; k < eIds.size(); ++k) {
0949         if (eHit[k] > eThreshold(eIds[k], geo))
0950           eEcal += eHit[k];
0951       }
0952 #ifdef EDM_ML_DEBUG
0953       edm::LogVerbatim("HcalIsoTrack") << "eMIP before and after: " << t_eMipDR << ":" << eEcal;
0954 #endif
0955       t_eMipDR = eEcal;
0956       ////////////////////////////////-MIP STUFF-///////////////////////////////
0957       ////////////////////////////////-MIP STUFF-2//////////////////////////////
0958       std::vector<DetId> eIds2;
0959       std::vector<double> eHit2;
0960       t_eMipDR2 = spr::eCone_ecal(geo,
0961                                   barrelRecHitsHandle,
0962                                   endcapRecHitsHandle,
0963                                   trkDetItr.pointHCAL,
0964                                   trkDetItr.pointECAL,
0965                                   a_mipR2_,
0966                                   trkDetItr.directionECAL,
0967                                   eIds2,
0968                                   eHit2);
0969       double eEcal2(0);
0970       for (unsigned int k = 0; k < eIds2.size(); ++k) {
0971         if (eHit2[k] > eThreshold(eIds2[k], geo))
0972           eEcal2 += eHit2[k];
0973       }
0974 #ifdef EDM_ML_DEBUG
0975       edm::LogVerbatim("HcalIsoTrack") << "eMIP before and after: " << t_eMipDR2 << ":" << eEcal2;
0976 #endif
0977       t_eMipDR2 = eEcal2;
0978       ////////////////////////////////-MIP STUFF-2/////////////////////////////
0979       ////////////////////////////////-MIP STUFF-3/////////////////////////////
0980       std::vector<DetId> eIds3;
0981       std::vector<double> eHit3;
0982       t_eMipDR3 = spr::eCone_ecal(geo,
0983                                   barrelRecHitsHandle,
0984                                   endcapRecHitsHandle,
0985                                   trkDetItr.pointHCAL,
0986                                   trkDetItr.pointECAL,
0987                                   a_mipR3_,
0988                                   trkDetItr.directionECAL,
0989                                   eIds3,
0990                                   eHit3);
0991       double eEcal3(0);
0992       for (unsigned int k = 0; k < eIds3.size(); ++k) {
0993         if (eHit3[k] > eThreshold(eIds3[k], geo))
0994           eEcal3 += eHit3[k];
0995       }
0996 #ifdef EDM_ML_DEBUG
0997       edm::LogVerbatim("HcalIsoTrack") << "eMIP before and after: " << t_eMipDR3 << ":" << eEcal3;
0998 #endif
0999       t_eMipDR3 = eEcal3;
1000       ////////////////////////////////-MIP STUFF-3/////////////////////////////
1001       ////////////////////////////////-MIP STUFF-4/////////////////////////////
1002       std::vector<DetId> eIds4;
1003       std::vector<double> eHit4;
1004       t_eMipDR4 = spr::eCone_ecal(geo,
1005                                   barrelRecHitsHandle,
1006                                   endcapRecHitsHandle,
1007                                   trkDetItr.pointHCAL,
1008                                   trkDetItr.pointECAL,
1009                                   a_mipR4_,
1010                                   trkDetItr.directionECAL,
1011                                   eIds4,
1012                                   eHit4);
1013       double eEcal4(0);
1014       for (unsigned int k = 0; k < eIds4.size(); ++k) {
1015         if (eHit4[k] > eThreshold(eIds4[k], geo))
1016           eEcal4 += eHit4[k];
1017       }
1018 #ifdef EDM_ML_DEBUG
1019       edm::LogVerbatim("HcalIsoTrack") << "eMIP before and after: " << t_eMipDR4 << ":" << eEcal4;
1020 #endif
1021       t_eMipDR4 = eEcal4;
1022       ////////////////////////////////-MIP STUFF-4/////////////////////////////
1023       ////////////////////////////////-MIP STUFF-5/////////////////////////////
1024       std::vector<DetId> eIds5;
1025       std::vector<double> eHit5;
1026       t_eMipDR5 = spr::eCone_ecal(geo,
1027                                   barrelRecHitsHandle,
1028                                   endcapRecHitsHandle,
1029                                   trkDetItr.pointHCAL,
1030                                   trkDetItr.pointECAL,
1031                                   a_mipR5_,
1032                                   trkDetItr.directionECAL,
1033                                   eIds5,
1034                                   eHit5);
1035       double eEcal5(0);
1036       for (unsigned int k = 0; k < eIds5.size(); ++k) {
1037         if (eHit5[k] > eThreshold(eIds5[k], geo))
1038           eEcal5 += eHit5[k];
1039       }
1040 #ifdef EDM_ML_DEBUG
1041       edm::LogVerbatim("HcalIsoTrack") << "eMIP before and after: " << t_eMipDR5 << ":" << eEcal5;
1042 #endif
1043       t_eMipDR5 = eEcal5;
1044       ////////////////////////////////-MIP STUFF-5/////////////////////////////
1045 
1046       t_emaxNearP = spr::chargeIsolationGenEcal(nTracks, trackIDs, geo, caloTopology, 15, 15);
1047       const DetId cellE(trkDetItr.detIdECAL);
1048       std::pair<double, bool> e11x11P = spr::eECALmatrix(cellE,
1049                                                          barrelRecHitsHandle,
1050                                                          endcapRecHitsHandle,
1051                                                          *theEcalChStatus,
1052                                                          geo,
1053                                                          caloTopology,
1054                                                          theEcalSevlv,
1055                                                          5,
1056                                                          5,
1057                                                          -100.0,
1058                                                          -100.0,
1059                                                          -100.0,
1060                                                          100.0);
1061       std::pair<double, bool> e15x15P = spr::eECALmatrix(cellE,
1062                                                          barrelRecHitsHandle,
1063                                                          endcapRecHitsHandle,
1064                                                          *theEcalChStatus,
1065                                                          geo,
1066                                                          caloTopology,
1067                                                          theEcalSevlv,
1068                                                          7,
1069                                                          7,
1070                                                          -100.0,
1071                                                          -100.0,
1072                                                          -100.0,
1073                                                          100.0);
1074       if (e11x11P.second && e15x15P.second) {
1075         t_eAnnular = (e15x15P.first - e11x11P.first);
1076       } else {
1077         t_eAnnular = -(e15x15P.first - e11x11P.first);
1078       }
1079       t_hmaxNearP = spr::chargeIsolationGenCone(nTracks, trackIDs, a_charIsoR_, nNearTRKs, false);
1080       const DetId cellH(trkDetItr.detIdHCAL);
1081       double h5x5 = spr::eHCALmatrix(
1082           theHBHETopology, cellH, hbhe, 2, 2, false, true, -100.0, -100.0, -100.0, -100.0, -100.0, 100.0);
1083       double h7x7 = spr::eHCALmatrix(
1084           theHBHETopology, cellH, hbhe, 3, 3, false, true, -100.0, -100.0, -100.0, -100.0, -100.0, 100.0);
1085       t_hAnnular = h7x7 - h5x5;
1086 #ifdef EDM_ML_DEBUG
1087       edm::LogVerbatim("HcalIsoTrack") << "max p Near (Ecal) " << t_emaxNearP << " (Hcal) " << t_hmaxNearP
1088                                        << " Annular E (Ecal) " << e11x11P.first << ":" << e15x15P.first << ":"
1089                                        << t_eAnnular << " (Hcal) " << h5x5 << ":" << h7x7 << ":" << t_hAnnular;
1090 #endif
1091       t_gentrackP = pTrack->p();
1092       if (t_eMipDR < eEcalMax_ && t_hmaxNearP < eIsolation) {
1093         t_DetIds->clear();
1094         t_HitEnergies->clear();
1095         t_DetIds1->clear();
1096         t_HitEnergies1->clear();
1097         t_DetIds3->clear();
1098         t_HitEnergies3->clear();
1099         int nRecHits(-999), nRecHits1(-999), nRecHits3(-999);
1100         std::vector<DetId> ids, ids1, ids3;
1101         std::vector<double> edet0, edet1, edet3;
1102         t_eHcal = spr::eCone_hcal(geo,
1103                                   hbhe,
1104                                   trkDetItr.pointHCAL,
1105                                   trkDetItr.pointECAL,
1106                                   a_coneR_,
1107                                   trkDetItr.directionHCAL,
1108                                   nRecHits,
1109                                   ids,
1110                                   edet0,
1111                                   useRaw_);
1112         if (!oldID_.empty()) {
1113           for (unsigned k = 0; k < ids.size(); ++k)
1114             ids[k] = newId(ids[k]);
1115         }
1116         storeEnergy(0, respCorrs, ids, edet0, t_eHcal, t_DetIds, t_HitEnergies);
1117 
1118         //----- hcal energy in the extended cone 1 (a_coneR+10) --------------
1119         t_eHcal10 = spr::eCone_hcal(geo,
1120                                     hbhe,
1121                                     trkDetItr.pointHCAL,
1122                                     trkDetItr.pointECAL,
1123                                     a_coneR1_,
1124                                     trkDetItr.directionHCAL,
1125                                     nRecHits1,
1126                                     ids1,
1127                                     edet1,
1128                                     useRaw_);
1129         if (!oldID_.empty()) {
1130           for (unsigned k = 0; k < ids1.size(); ++k)
1131             ids1[k] = newId(ids1[k]);
1132         }
1133         storeEnergy(1, respCorrs, ids1, edet1, t_eHcal10, t_DetIds1, t_HitEnergies1);
1134 
1135         //----- hcal energy in the extended cone 3 (a_coneR+30) --------------
1136         t_eHcal30 = spr::eCone_hcal(geo,
1137                                     hbhe,
1138                                     trkDetItr.pointHCAL,
1139                                     trkDetItr.pointECAL,
1140                                     a_coneR2_,
1141                                     trkDetItr.directionHCAL,
1142                                     nRecHits3,
1143                                     ids3,
1144                                     edet3,
1145                                     useRaw_);
1146         if (!oldID_.empty()) {
1147           for (unsigned k = 0; k < ids3.size(); ++k)
1148             ids3[k] = newId(ids3[k]);
1149         }
1150         storeEnergy(3, respCorrs, ids3, edet3, t_eHcal30, t_DetIds3, t_HitEnergies3);
1151 
1152         t_p = pTrack->p();
1153         t_pt = pTrack->pt();
1154         t_phi = pTrack->phi();
1155 
1156 #ifdef EDM_ML_DEBUG
1157         edm::LogVerbatim("HcalIsoTrack") << "This track : " << nTracks << " (pt|eta|phi|p) :" << t_pt << "|"
1158                                          << pTrack->eta() << "|" << t_phi << "|" << t_p << " Generator Level p "
1159                                          << t_gentrackP;
1160         edm::LogVerbatim("HcalIsoTrack") << "e_MIP " << t_eMipDR << " Chg Isolation " << t_hmaxNearP << " eHcal"
1161                                          << t_eHcal << " ieta " << t_ieta << " Quality " << t_qltyMissFlag << ":"
1162                                          << t_qltyPVFlag << ":" << t_selectTk;
1163         for (unsigned int ll = 0; ll < t_DetIds->size(); ll++) {
1164           edm::LogVerbatim("HcalIsoTrack")
1165               << "det id is = " << t_DetIds->at(ll) << "   hit enery is  = " << t_HitEnergies->at(ll);
1166         }
1167         for (unsigned int ll = 0; ll < t_DetIds1->size(); ll++) {
1168           edm::LogVerbatim("HcalIsoTrack")
1169               << "det id is = " << t_DetIds1->at(ll) << "   hit enery is  = " << t_HitEnergies1->at(ll);
1170         }
1171         for (unsigned int ll = 0; ll < t_DetIds3->size(); ll++) {
1172           edm::LogVerbatim("HcalIsoTrack")
1173               << "det id is = " << t_DetIds3->at(ll) << "   hit enery is  = " << t_HitEnergies3->at(ll);
1174         }
1175 #endif
1176         bool accept(false);
1177         if (t_p > pTrackMin_) {
1178           if (t_p < pTrackLow_) {
1179             ++nLow_;
1180             if (prescaleLow_ <= 1)
1181               accept = true;
1182             else if (nLow_ % prescaleLow_ == 1)
1183               accept = true;
1184           } else if (t_p > pTrackHigh_) {
1185             ++nHigh_;
1186             if (prescaleHigh_ <= 1)
1187               accept = true;
1188             else if (nHigh_ % prescaleHigh_ == 1)
1189               accept = true;
1190           } else {
1191             accept = true;
1192           }
1193         }
1194         if (accept) {
1195           tree->Fill();
1196           nSave++;
1197           int type(0);
1198           if (t_eMipDR < 1.0) {
1199             if (t_hmaxNearP < eIsolate2_) {
1200               ++nLoose;
1201               type = 1;
1202             }
1203             if (t_hmaxNearP < eIsolate1_) {
1204               ++nTight;
1205               type = 2;
1206             }
1207           }
1208           if (t_p > 40.0 && t_p <= 60.0 && t_selectTk) {
1209             t_ietaGood->emplace_back(t_ieta);
1210             t_trackType->emplace_back(type);
1211           }
1212 #ifdef EDM_ML_DEBUG
1213           for (unsigned int k = 0; k < t_trgbits->size(); k++) {
1214             edm::LogVerbatim("HcalIsoTrack") << "trigger bit is  = " << t_trgbits->at(k);
1215           }
1216 #endif
1217         }
1218       }
1219     }
1220     ++nTracks;
1221   }
1222   std::array<int, 3> i3{{nSave, nLoose, nTight}};
1223   return i3;
1224 }
1225 
1226 double HcalIsoTrkSimAnalyzer::dR(math::XYZTLorentzVector& vec1, math::XYZTLorentzVector& vec2) {
1227   return reco::deltaR(vec1.eta(), vec1.phi(), vec2.eta(), vec2.phi());
1228 }
1229 
1230 double HcalIsoTrkSimAnalyzer::rhoh(const edm::Handle<CaloTowerCollection>& tower) {
1231   std::vector<double> sumPFNallSMDQH2;
1232   sumPFNallSMDQH2.reserve(phibins_.size() * etabins_.size());
1233 
1234   for (auto eta : etabins_) {
1235     for (auto phi : phibins_) {
1236       double hadder = 0;
1237       for (const auto& pf_it : (*tower)) {
1238         if (fabs(eta - pf_it.eta()) > etahalfdist_)
1239           continue;
1240         if (fabs(reco::deltaPhi(phi, pf_it.phi())) > phihalfdist_)
1241           continue;
1242         hadder += pf_it.hadEt();
1243       }
1244       sumPFNallSMDQH2.emplace_back(hadder);
1245     }
1246   }
1247 
1248   double evt_smdq(0);
1249   std::sort(sumPFNallSMDQH2.begin(), sumPFNallSMDQH2.end());
1250   if (sumPFNallSMDQH2.size() % 2)
1251     evt_smdq = sumPFNallSMDQH2[(sumPFNallSMDQH2.size() - 1) / 2];
1252   else
1253     evt_smdq = (sumPFNallSMDQH2[sumPFNallSMDQH2.size() / 2] + sumPFNallSMDQH2[(sumPFNallSMDQH2.size() - 2) / 2]) / 2.;
1254   double rhoh = evt_smdq / (etadist_ * phidist_);
1255 #ifdef EDM_ML_DEBUG
1256   edm::LogVerbatim("HcalIsoTrack") << "Rho " << evt_smdq << ":" << rhoh;
1257 #endif
1258   return rhoh;
1259 }
1260 
1261 double HcalIsoTrkSimAnalyzer::eThreshold(const DetId& id, const CaloGeometry* geo) const {
1262   double eThr(hitEthrEB_);
1263   if (usePFThresh_) {
1264     eThr = static_cast<double>((*eThresholds_)[id]);
1265   } else {
1266     const GlobalPoint& pos = geo->getPosition(id);
1267     double eta = std::abs(pos.eta());
1268     if (id.subdetId() != EcalBarrel) {
1269       eThr = (((eta * hitEthrEE3_ + hitEthrEE2_) * eta + hitEthrEE1_) * eta + hitEthrEE0_);
1270       if (eThr < hitEthrEELo_)
1271         eThr = hitEthrEELo_;
1272       else if (eThr > hitEthrEEHi_)
1273         eThr = hitEthrEEHi_;
1274     }
1275   }
1276   return eThr;
1277 }
1278 
1279 DetId HcalIsoTrkSimAnalyzer::newId(const DetId& id) {
1280   HcalDetId hid(id);
1281   if (hep17_ && ((hid.iphi() < 63) || (hid.iphi() > 66) || (hid.zside() < 0)))
1282     return id;
1283   for (unsigned int k = 0; k < oldID_.size(); ++k) {
1284     if ((hid.subdetId() == oldDet_[k]) && (hid.ietaAbs() == oldEta_[k]) && (hid.depth() == oldDepth_[k])) {
1285       return static_cast<DetId>(HcalDetId(hid.subdet(), hid.ieta(), hid.iphi(), newDepth_[k]));
1286     }
1287   }
1288   return id;
1289 }
1290 
1291 void HcalIsoTrkSimAnalyzer::storeEnergy(int indx,
1292                                         const HcalRespCorrs* respCorrs,
1293                                         const std::vector<DetId>& ids,
1294                                         std::vector<double>& edet,
1295                                         double& eHcal,
1296                                         std::vector<unsigned int>* detIds,
1297                                         std::vector<double>* hitEnergies) {
1298   double ehcal(0);
1299   if (unCorrect_) {
1300     for (unsigned int k = 0; k < ids.size(); ++k) {
1301       double corr = (respCorrs->getValues(ids[k]))->getValue();
1302       if (corr != 0)
1303         edet[k] /= corr;
1304       ehcal += edet[k];
1305     }
1306   } else {
1307     for (const auto& en : edet)
1308       ehcal += en;
1309   }
1310   if ((std::abs(ehcal - eHcal) > 0.001) && (!unCorrect_))
1311     edm::LogWarning("HcalIsoTrack") << "Check inconsistent energies: " << indx << " " << eHcal << ":" << ehcal
1312                                     << " from " << ids.size() << " cells";
1313   eHcal = hcalScale_ * ehcal;
1314 
1315   if (collapseDepth_) {
1316     std::map<HcalDetId, double> hitMap;
1317     for (unsigned int k = 0; k < ids.size(); ++k) {
1318       HcalDetId id = hdc_->mergedDepthDetId(HcalDetId(ids[k]));
1319       auto itr = hitMap.find(id);
1320       if (itr == hitMap.end()) {
1321         hitMap[id] = edet[k];
1322       } else {
1323         (itr->second) += edet[k];
1324       }
1325     }
1326     detIds->reserve(hitMap.size());
1327     hitEnergies->reserve(hitMap.size());
1328     for (const auto& hit : hitMap) {
1329       detIds->emplace_back(hit.first.rawId());
1330       hitEnergies->emplace_back(hit.second);
1331     }
1332   } else {
1333     detIds->reserve(ids.size());
1334     hitEnergies->reserve(ids.size());
1335     for (unsigned int k = 0; k < ids.size(); ++k) {
1336       detIds->emplace_back(ids[k].rawId());
1337       hitEnergies->emplace_back(edet[k]);
1338     }
1339   }
1340 #ifdef EDM_ML_DEBUG
1341   edm::LogVerbatim("HcalIsoTrack") << "Input to storeEnergy with " << ids.size() << " cells";
1342   for (unsigned int k = 0; k < ids.size(); ++k)
1343     edm::LogVerbatim("HcalIsoTrack") << "Hit [" << k << "] " << HcalDetId(ids[k]) << " E " << edet[k];
1344   edm::LogVerbatim("HcalIsoTrack") << "Output of storeEnergy with " << detIds->size() << " cells and Etot " << eHcal;
1345   for (unsigned int k = 0; k < detIds->size(); ++k)
1346     edm::LogVerbatim("HcalIsoTrack") << "Hit [" << k << "] " << HcalDetId((*detIds)[k]) << " E " << (*hitEnergies)[k];
1347 #endif
1348 }
1349 
1350 bool HcalIsoTrkSimAnalyzer::notaMuon(const reco::GenParticle* pTrack) {
1351   int id = pTrack->pdgId();
1352   bool flag = ((id != 13) && (id != -13) && (pTrack->charge() != 0));
1353 #ifdef EDM_ML_DEBUG
1354   edm::LogVerbatim("HcalIsoTrack") << "notaMuon: ID " << id << " charge " << pTrack->charge() << " Flag " << flag;
1355 #endif
1356   return flag;
1357 }
1358 
1359 //define this as a plug-in
1360 DEFINE_FWK_MODULE(HcalIsoTrkSimAnalyzer);