Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:46

0001 #ifndef GsfElectronAlgo_H
0002 #define GsfElectronAlgo_H
0003 
0004 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0005 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0006 #include "Geometry/Records/interface/CaloTopologyRecord.h"
0007 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
0008 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0009 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
0010 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0011 #include "DataFormats/CaloRecHit/interface/CaloClusterFwd.h"
0012 #include "DataFormats/Common/interface/ValueMap.h"
0013 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0014 #include "DataFormats/EgammaCandidates/interface/GsfElectronCoreFwd.h"
0015 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
0016 #include "DataFormats/EgammaCandidates/interface/Conversion.h"
0017 #include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h"
0018 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
0019 #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h"
0020 #include "DataFormats/ParticleFlowReco/interface/GsfPFRecTrackFwd.h"
0021 #include "DataFormats/Provenance/interface/ParameterSetID.h"
0022 #include "DataFormats/TrackReco/interface/HitPattern.h"
0023 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0024 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
0025 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0026 #include "FWCore/Framework/interface/ConsumesCollector.h"
0027 #include "FWCore/Framework/interface/ESHandle.h"
0028 #include "FWCore/Framework/interface/Event.h"
0029 #include "FWCore/Framework/interface/EventSetup.h"
0030 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0031 #include "Geometry/CaloTopology/interface/CaloTopology.h"
0032 #include "MagneticField/Engine/interface/MagneticField.h"
0033 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionBaseClass.h"
0034 #include "RecoEgamma/EgammaElectronAlgos/interface/ElectronHcalHelper.h"
0035 #include "RecoEgamma/EgammaElectronAlgos/interface/RegressionHelper.h"
0036 #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaRecHitIsolation.h"
0037 #include "RecoEgamma/EgammaIsolationAlgos/interface/EleTkIsolFromCands.h"
0038 #include "RecoEgamma/ElectronIdentification/interface/ElectronMVAEstimator.h"
0039 #include "RecoEgamma/ElectronIdentification/interface/SoftElectronMVAEstimator.h"
0040 #include "RecoEgamma/ElectronIdentification/interface/ElectronDNNEstimator.h"
0041 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h"
0042 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgoRcd.h"
0043 #include "TrackingTools/GsfTools/interface/MultiTrajectoryStateMode.h"
0044 #include "TrackingTools/GsfTools/interface/MultiTrajectoryStateTransform.h"
0045 #include "TrackingTools/GsfTracking/interface/GsfConstraintAtVertex.h"
0046 #include "TrackingTools/MaterialEffects/interface/PropagatorWithMaterial.h"
0047 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0048 #include "RecoEgamma/EgammaElectronAlgos/interface/ConversionFinder.h"
0049 #include "CondFormats/EcalObjects/interface/EcalPFRecHitThresholds.h"
0050 #include "CondFormats/DataRecord/interface/EcalPFRecHitThresholdsRcd.h"
0051 #include "RecoEgamma/EgammaIsolationAlgos/interface/EcalPFClusterIsolation.h"
0052 #include "RecoEgamma/EgammaIsolationAlgos/interface/HcalPFClusterIsolation.h"
0053 
0054 class GsfElectronAlgo {
0055 public:
0056   class HeavyObjectCache {
0057   public:
0058     HeavyObjectCache(const edm::ParameterSet&);
0059     std::unique_ptr<const SoftElectronMVAEstimator> sElectronMVAEstimator;
0060     std::unique_ptr<const ElectronMVAEstimator> iElectronMVAEstimator;
0061     std::unique_ptr<const ElectronDNNEstimator> iElectronDNNEstimator;
0062   };
0063 
0064   struct Tokens {
0065     edm::EDGetTokenT<reco::GsfElectronCoreCollection> gsfElectronCores;
0066     edm::EDGetTokenT<HBHERecHitCollection> hbheRecHitsTag;
0067     edm::EDGetTokenT<reco::SuperClusterCollection> barrelSuperClusters;
0068     edm::EDGetTokenT<reco::SuperClusterCollection> endcapSuperClusters;
0069     edm::EDGetTokenT<EcalRecHitCollection> barrelRecHitCollection;
0070     edm::EDGetTokenT<EcalRecHitCollection> endcapRecHitCollection;
0071     edm::EDGetTokenT<reco::ElectronSeedCollection> seedsTag;
0072     edm::EDGetTokenT<reco::TrackCollection> ctfTracks;
0073     edm::EDGetTokenT<reco::BeamSpot> beamSpotTag;
0074     edm::EDGetTokenT<reco::VertexCollection> vtxCollectionTag;
0075     edm::EDGetTokenT<reco::ConversionCollection> conversions;
0076 
0077     edm::EDGetTokenT<reco::PFClusterCollection> pfClusterProducer;
0078     edm::EDGetTokenT<reco::PFClusterCollection> pfClusterProducerHCAL;
0079     edm::EDGetTokenT<reco::PFClusterCollection> pfClusterProducerHFEM;
0080     edm::EDGetTokenT<reco::PFClusterCollection> pfClusterProducerHFHAD;
0081   };
0082 
0083   struct StrategyConfiguration {
0084     // if true, electron preselection is applied
0085     bool applyPreselection;
0086     // if true, electron level escale corrections are
0087     // used on top of the cluster level corrections
0088     bool ecalDrivenEcalEnergyFromClassBasedParameterization;
0089     bool ecalDrivenEcalErrorFromClassBasedParameterization;
0090     bool pureTrackerDrivenEcalErrorFromSimpleParameterization;
0091     // ambiguity solving
0092     bool applyAmbResolution;  // if not true, ambiguity solving is not applied
0093     bool ignoreNotPreselected;
0094     unsigned ambSortingStrategy;          // 0:isBetter, 1:isInnermost
0095     unsigned ambClustersOverlapStrategy;  // 0:sc adresses, 1:bc shared energy
0096     // for backward compatibility
0097     bool ctfTracksCheck;
0098     float PreSelectMVA;
0099     float MaxElePtForOnlyMVA;
0100     bool useDefaultEnergyCorrection;
0101     // GED-Regression (ECAL and combination)
0102     bool useEcalRegression;
0103     bool useCombinationRegression;
0104     //heavy ion in 2015 has no conversions and so cant fill conv vtx fit prob so this bool
0105     //stops it from being filled
0106     bool fillConvVtxFitProb;
0107     // Compute PFcluster isolation for egamma PFID DNN
0108     bool computePfClusterIso;
0109   };
0110 
0111   struct CutsConfiguration {
0112     // minimum SC Et
0113     double minSCEtBarrel;
0114     double minSCEtEndcaps;
0115     // maximum E/p where E is the supercluster corrected energy and p the track momentum at innermost state
0116     double maxEOverPBarrel;
0117     double maxEOverPEndcaps;
0118     // minimum E/p where E is the supercluster corrected energy and p the track momentum at innermost state
0119     double minEOverPBarrel;
0120     double minEOverPEndcaps;
0121 
0122     // H/E
0123     double maxHOverEBarrelCone;
0124     double maxHOverEEndcapsCone;
0125     double maxHBarrelCone;
0126     double maxHEndcapsCone;
0127     double maxHOverEBarrelBc;
0128     double maxHOverEEndcapsBc;
0129     double maxHBarrelBc;
0130     double maxHEndcapsBc;
0131 
0132     // maximum eta difference between the supercluster position and the track position at the closest impact to the supercluster
0133     double maxDeltaEtaBarrel;
0134     double maxDeltaEtaEndcaps;
0135 
0136     // maximum phi difference between the supercluster position and the track position at the closest impact to the supercluster
0137     // position to the supercluster
0138     double maxDeltaPhiBarrel;
0139     double maxDeltaPhiEndcaps;
0140 
0141     // maximum sigma ieta ieta
0142     double maxSigmaIetaIetaBarrel;
0143     double maxSigmaIetaIetaEndcaps;
0144     // maximum fbrem
0145 
0146     double maxFbremBarrel;
0147     double maxFbremEndcaps;
0148 
0149     // fiducial regions
0150     bool isBarrel;
0151     bool isEndcaps;
0152     bool isFiducial;
0153 
0154     // transverse impact parameter wrt beam spot
0155     double maxTIP;
0156 
0157     // only make sense for ecal driven electrons
0158     bool seedFromTEC;
0159 
0160     // noise cleaning
0161     double multThresEB;
0162     double multThresEE;
0163   };
0164 
0165   // Ecal rec hits
0166   struct EcalRecHitsConfiguration {
0167     std::vector<int> recHitFlagsToBeExcludedBarrel;
0168     std::vector<int> recHitFlagsToBeExcludedEndcaps;
0169     std::vector<int> recHitSeverityToBeExcludedBarrel;
0170     std::vector<int> recHitSeverityToBeExcludedEndcaps;
0171     //int severityLevelCut ;
0172   };
0173 
0174   // isolation variables parameters
0175   struct IsolationConfiguration {
0176     double intRadiusHcal;
0177     double etMinHcal;
0178     double intRadiusEcalBarrel;
0179     double intRadiusEcalEndcaps;
0180     double jurassicWidth;
0181     double etMinBarrel;
0182     double eMinBarrel;
0183     double etMinEndcaps;
0184     double eMinEndcaps;
0185     bool vetoClustered;
0186     bool useNumCrystals;
0187   };
0188 
0189   struct PFClusterIsolationConfiguration {
0190     double ecaldrMax;
0191     double ecaldrVetoBarrel;
0192     double ecaldrVetoEndcap;
0193     double ecaletaStripBarrel;
0194     double ecaletaStripEndcap;
0195     double ecalenergyBarrel;
0196     double ecalenergyEndcap;
0197 
0198     bool useHF;
0199     double hcaldrMax;
0200     double hcaldrVetoBarrel;
0201     double hcaldrVetoEndcap;
0202     double hcaletaStripBarrel;
0203     double hcaletaStripEndcap;
0204     double hcalenergyBarrel;
0205     double hcalenergyEndcap;
0206     bool hcaluseEt;
0207   };
0208 
0209   GsfElectronAlgo(const Tokens&,
0210                   const StrategyConfiguration&,
0211                   const CutsConfiguration& cutsCfg,
0212                   const ElectronHcalHelper::Configuration& hcalCone,
0213                   const ElectronHcalHelper::Configuration& hcalBc,
0214                   const IsolationConfiguration&,
0215                   const PFClusterIsolationConfiguration&,
0216                   const EcalRecHitsConfiguration&,
0217                   std::unique_ptr<EcalClusterFunctionBaseClass>&& crackCorrectionFunction,
0218                   const RegressionHelper::Configuration& regCfg,
0219                   const edm::ParameterSet& tkIsol03Cfg,
0220                   const edm::ParameterSet& tkIsol04Cfg,
0221                   const edm::ParameterSet& tkIsolHEEP03Cfg,
0222                   const edm::ParameterSet& tkIsolHEEP04Cfg,
0223                   edm::ConsumesCollector&& cc);
0224 
0225   // main methods
0226   reco::GsfElectronCollection completeElectrons(edm::Event const& event,
0227                                                 edm::EventSetup const& eventSetup,
0228                                                 const HeavyObjectCache* hoc,
0229                                                 const HcalPFCuts* hcalCuts);
0230 
0231 private:
0232   // internal structures
0233 
0234   struct Configuration {
0235     // configurables
0236     const Tokens tokens;
0237     const StrategyConfiguration strategy;
0238     const CutsConfiguration cuts;
0239     const IsolationConfiguration iso;
0240     const PFClusterIsolationConfiguration pfiso;
0241     const EcalRecHitsConfiguration recHits;
0242   };
0243 
0244   struct EventData;
0245   struct ElectronData;
0246 
0247   void checkSetup(edm::EventSetup const& eventSetup);
0248   EventData beginEvent(edm::Event const& event,
0249                        CaloGeometry const& caloGeometry,
0250                        EcalSeverityLevelAlgo const& ecalSeveretyLevelAlgo);
0251 
0252   void createElectron(reco::GsfElectronCollection& electrons,
0253                       ElectronData& electronData,
0254                       EventData& eventData,
0255                       CaloTopology const& topology,
0256                       CaloGeometry const& geometry,
0257                       MultiTrajectoryStateTransform const& mtsTransform,
0258                       double magneticFieldInTesla,
0259                       const HeavyObjectCache*,
0260                       egamma::conv::TrackTableView ctfTable,
0261                       egamma::conv::TrackTableView gsfTable,
0262                       EcalPFRecHitThresholds const& thresholds,
0263                       const HcalPFCuts* hcalCuts);
0264 
0265   void setCutBasedPreselectionFlag(reco::GsfElectron& ele, const reco::BeamSpot&) const;
0266 
0267   template <bool full5x5>
0268   reco::GsfElectron::ShowerShape calculateShowerShape(const reco::SuperClusterRef&,
0269                                                       ElectronHcalHelper const& hcalHelperCone,
0270                                                       ElectronHcalHelper const& hcalHelperBc,
0271                                                       EventData const& eventData,
0272                                                       CaloTopology const& topology,
0273                                                       CaloGeometry const& geometry,
0274                                                       EcalPFRecHitThresholds const& thresholds,
0275                                                       const HcalPFCuts* hcalCuts) const;
0276   reco::GsfElectron::SaturationInfo calculateSaturationInfo(const reco::SuperClusterRef&,
0277                                                             EventData const& eventData) const;
0278 
0279   // Pixel match variables
0280   void setPixelMatchInfomation(reco::GsfElectron&) const;
0281 
0282   // constant class members
0283   const Configuration cfg_;
0284 
0285   const EleTkIsolFromCands::Configuration tkIsol03CalcCfg_;
0286   const EleTkIsolFromCands::Configuration tkIsol04CalcCfg_;
0287   const EleTkIsolFromCands::Configuration tkIsolHEEP03CalcCfg_;
0288   const EleTkIsolFromCands::Configuration tkIsolHEEP04CalcCfg_;
0289 
0290   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magneticFieldToken_;
0291   const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> caloGeometryToken_;
0292   const edm::ESGetToken<CaloTopology, CaloTopologyRecord> caloTopologyToken_;
0293   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> trackerGeometryToken_;
0294   const edm::ESGetToken<EcalSeverityLevelAlgo, EcalSeverityLevelAlgoRcd> ecalSeveretyLevelAlgoToken_;
0295   const edm::ESGetToken<EcalPFRecHitThresholds, EcalPFRecHitThresholdsRcd> ecalPFRechitThresholdsToken_;
0296 
0297   // additional configuration and helpers
0298   ElectronHcalHelper hcalHelperCone_;
0299   ElectronHcalHelper hcalHelperBc_;
0300   std::unique_ptr<EcalClusterFunctionBaseClass> crackCorrectionFunction_;
0301   RegressionHelper regHelper_;
0302 
0303   // Algos for PfCluster Isolation
0304   typedef EcalPFClusterIsolation<reco::GsfElectron> ElectronEcalPFClusterIsolation;
0305   std::unique_ptr<ElectronEcalPFClusterIsolation> ecalisoAlgo_;
0306   typedef HcalPFClusterIsolation<reco::GsfElectron> ElectronHcalPFClusterIsolation;
0307   std::unique_ptr<ElectronHcalPFClusterIsolation> hcalisoAlgo_;
0308 };
0309 
0310 #endif  // GsfElectronAlgo_H