Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-12-25 02:13:48

0001 #ifndef RecoParticleFlow_PFProducer_PFAlgo_h
0002 #define RecoParticleFlow_PFProducer_PFAlgo_h
0003 
0004 #include "DataFormats/Common/interface/Handle.h"
0005 #include "DataFormats/Common/interface/OrphanHandle.h"
0006 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0007 #include "DataFormats/ParticleFlowReco/interface/PFBlockFwd.h"
0008 #include "DataFormats/ParticleFlowReco/interface/PFBlock.h"
0009 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0010 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
0011 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateElectronExtra.h"
0012 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateElectronExtraFwd.h"
0013 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidatePhotonExtra.h"
0014 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidatePhotonExtraFwd.h"
0015 #include "DataFormats/ParticleFlowReco/interface/PFBlockElement.h"
0016 #include "DataFormats/ParticleFlowReco/interface/PFRecHitFwd.h"
0017 #include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h"
0018 #include "DataFormats/ParticleFlowReco/interface/PFRecTrackFwd.h"
0019 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0020 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0021 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
0022 #include "DataFormats/Common/interface/ValueMap.h"
0023 #include "RecoParticleFlow/PFProducer/interface/PFCandConnector.h"
0024 #include "RecoParticleFlow/PFProducer/interface/PFMuonAlgo.h"
0025 #include "RecoParticleFlow/PFProducer/interface/PFEGammaFilters.h"
0026 
0027 #include <iostream>
0028 
0029 #include "RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibration.h"
0030 #include "RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibrationHF.h"
0031 
0032 /// \brief Particle Flow Algorithm
0033 /*!
0034   \author Colin Bernet
0035   \date January 2006
0036 */
0037 
0038 class PFMuonAlgo;
0039 
0040 class ElementIndices {
0041 public:
0042   std::vector<unsigned> hcalIs;
0043   std::vector<unsigned> hoIs;
0044   std::vector<unsigned> ecalIs;
0045   std::vector<unsigned> trackIs;
0046   std::vector<unsigned> ps1Is;
0047   std::vector<unsigned> ps2Is;
0048 
0049   std::vector<unsigned> hfEmIs;
0050   std::vector<unsigned> hfHadIs;
0051 };
0052 
0053 class PFAlgo {
0054 public:
0055   /// constructor
0056   PFAlgo(double nSigmaECAL,
0057          double nSigmaHCAL,
0058          double nSigmaHFEM,
0059          double nSigmaHFHAD,
0060          std::vector<double> resolHF_square,
0061          PFEnergyCalibration& calibration,
0062          PFEnergyCalibrationHF& thepfEnergyCalibrationHF,
0063          const edm::ParameterSet& pset);
0064 
0065   void setHOTag(bool ho) { useHO_ = ho; }
0066   void setMuonHandle(const edm::Handle<reco::MuonCollection>& muons) { muonHandle_ = muons; }
0067 
0068   void setCandConnectorParameters(const edm::ParameterSet& iCfgCandConnector) {
0069     connector_.setParameters(iCfgCandConnector);
0070   }
0071 
0072   void setCandConnectorParameters(bool bCorrect,
0073                                   bool bCalibPrimary,
0074                                   double dptRel_PrimaryTrack,
0075                                   double dptRel_MergedTrack,
0076                                   double ptErrorSecondary,
0077                                   const std::vector<double>& nuclCalibFactors) {
0078     connector_.setParameters(
0079         bCorrect, bCalibPrimary, dptRel_PrimaryTrack, dptRel_MergedTrack, ptErrorSecondary, nuclCalibFactors);
0080   }
0081 
0082   PFMuonAlgo* getPFMuonAlgo();
0083 
0084   void setEGammaParameters(bool use_EGammaFilters, bool useProtectionsForJetMET);
0085 
0086   void setEGammaCollections(const edm::View<reco::PFCandidate>& pfEgammaCandidates,
0087                             const edm::ValueMap<reco::GsfElectronRef>& valueMapGedElectrons,
0088                             const edm::ValueMap<reco::PhotonRef>& valueMapGedPhotons);
0089 
0090   void setPostHFCleaningParameters(bool postHFCleaning, const edm::ParameterSet& pfHFCleaningParams);
0091 
0092   void setDisplacedVerticesParameters(bool rejectTracks_Bad,
0093                                       bool rejectTracks_Step45,
0094                                       bool usePFNuclearInteractions,
0095                                       bool usePFConversions,
0096                                       bool usePFDecays,
0097                                       double dptRel_DispVtx);
0098 
0099   //MIKEB : Parameters for the vertices..
0100   void setPFVertexParameters(bool useVertex, reco::VertexCollection const& primaryVertices);
0101 
0102   // FlorianB : Collection of e/g electrons
0103   void setEGElectronCollection(const reco::GsfElectronCollection& egelectrons);
0104 
0105   /// reconstruct particles
0106   void reconstructParticles(const reco::PFBlockHandle& blockHandle, PFEGammaFilters const* pfegamma);
0107 
0108   /// Check HF Cleaning
0109   void checkCleaning(const reco::PFRecHitCollection& cleanedHF);
0110 
0111   /// \return collection of cleaned HF candidates
0112   reco::PFCandidateCollection& getCleanedCandidates() { return pfCleanedCandidates_; }
0113 
0114   /// \return the collection of candidates
0115   reco::PFCandidateCollection makeConnectedCandidates() { return connector_.connect(pfCandidates_); }
0116 
0117   friend std::ostream& operator<<(std::ostream& out, const PFAlgo& algo);
0118 
0119   void clear() {
0120     pfCandidates_.clear();
0121     pfCleanedCandidates_.clear();
0122     if (useVertices_) {
0123       primaryVertex_ = decltype(primaryVertex_)();
0124     }
0125   };
0126 
0127 private:
0128   void egammaFilters(const reco::PFBlockRef& blockref, std::vector<bool>& active, PFEGammaFilters const* pfegamma);
0129   void conversionAlgo(const edm::OwnVector<reco::PFBlockElement>& elements, std::vector<bool>& active);
0130   bool checkAndReconstructSecondaryInteraction(const reco::PFBlockRef& blockref,
0131                                                const edm::OwnVector<reco::PFBlockElement>& elements,
0132                                                bool isActive,
0133                                                int iElement);
0134   bool checkHasDeadHcal(const std::multimap<double, unsigned>& hcalElems, const std::vector<bool>& deadArea);
0135   void relinkTrackToHcal(const reco::PFBlock& block,
0136                          std::multimap<double, unsigned>& ecalElems,
0137                          std::multimap<double, unsigned>& hcalElems,
0138                          const std::vector<bool>& active,
0139                          reco::PFBlock::LinkData& linkData,
0140                          unsigned int iTrack);
0141   bool checkGoodTrackDeadHcal(const reco::TrackRef& trackRef, bool hasDeadHcal);
0142   void elementLoop(const reco::PFBlock& block,
0143                    reco::PFBlock::LinkData& linkData,
0144                    const edm::OwnVector<reco::PFBlockElement>& elements,
0145                    std::vector<bool>& active,
0146                    const reco::PFBlockRef& blockref,
0147                    ElementIndices& inds,
0148                    std::vector<bool>& deadArea);
0149   int decideType(const edm::OwnVector<reco::PFBlockElement>& elements,
0150                  const reco::PFBlockElement::Type type,
0151                  std::vector<bool>& active,
0152                  ElementIndices& inds,
0153                  std::vector<bool>& deadArea,
0154                  unsigned int iEle);
0155   bool recoTracksNotHCAL(const reco::PFBlock& block,
0156                          reco::PFBlock::LinkData& linkData,
0157                          const edm::OwnVector<reco::PFBlockElement>& elements,
0158                          const reco::PFBlockRef& blockref,
0159                          std::vector<bool>& active,
0160                          bool goodTrackDeadHcal,
0161                          bool hasDeadHcal,
0162                          unsigned int iTrack,
0163                          std::multimap<double, unsigned>& ecalElems,
0164                          reco::TrackRef& trackRef);
0165 
0166   //Looks for a HF-associated element in the block and produces a PFCandidate from it with HF_EM and/or HF_HAD calibrations
0167   void createCandidatesHF(const reco::PFBlock& block,
0168                           reco::PFBlock::LinkData& linkData,
0169                           const edm::OwnVector<reco::PFBlockElement>& elements,
0170                           std::vector<bool>& active,
0171                           const reco::PFBlockRef& blockref,
0172                           ElementIndices& inds);
0173 
0174   void createCandidatesHCAL(const reco::PFBlock& block,
0175                             reco::PFBlock::LinkData& linkData,
0176                             const edm::OwnVector<reco::PFBlockElement>& elements,
0177                             std::vector<bool>& active,
0178                             const reco::PFBlockRef& blockref,
0179                             ElementIndices& inds,
0180                             std::vector<bool>& deadArea);
0181   void createCandidatesHCALUnlinked(const reco::PFBlock& block,
0182                                     reco::PFBlock::LinkData& linkData,
0183                                     const edm::OwnVector<reco::PFBlockElement>& elements,
0184                                     std::vector<bool>& active,
0185                                     const reco::PFBlockRef& blockref,
0186                                     ElementIndices& inds,
0187                                     std::vector<bool>& deadArea);
0188 
0189   void createCandidatesECAL(const reco::PFBlock& block,
0190                             reco::PFBlock::LinkData& linkData,
0191                             const edm::OwnVector<reco::PFBlockElement>& elements,
0192                             std::vector<bool>& active,
0193                             const reco::PFBlockRef& blockref,
0194                             ElementIndices& inds,
0195                             std::vector<bool>& deadArea);
0196 
0197   /// process one block. can be reimplemented in more sophisticated
0198   /// algorithms
0199   void processBlock(const reco::PFBlockRef& blockref,
0200                     std::list<reco::PFBlockRef>& hcalBlockRefs,
0201                     std::list<reco::PFBlockRef>& ecalBlockRefs,
0202                     PFEGammaFilters const* pfegamma);
0203 
0204   /// Reconstruct a charged particle from a track
0205   /// Returns the index of the newly created candidate in pfCandidates_
0206   /// Michalis added a flag here to treat muons inside jets
0207   unsigned reconstructTrack(const reco::PFBlockElement& elt, bool allowLoose = false);
0208 
0209   /// Reconstruct a neutral particle from a cluster.
0210   /// If chargedEnergy is specified, the neutral
0211   /// particle is created only if the cluster energy is significantly
0212   /// larger than the chargedEnergy. In this case, the energy of the
0213   /// neutral particle is cluster energy - chargedEnergy
0214 
0215   unsigned reconstructCluster(const reco::PFCluster& cluster,
0216                               double particleEnergy,
0217                               bool useDirection = false,
0218                               double particleX = 0.,
0219                               double particleY = 0.,
0220                               double particleZ = 0.);
0221 
0222   void setHcalDepthInfo(reco::PFCandidate& cand, const reco::PFCluster& cluster) const;
0223 
0224   /// todo: use PFClusterTools for this
0225   double neutralHadronEnergyResolution(double clusterEnergy, double clusterEta) const;
0226 
0227   double nSigmaHCAL(double clusterEnergy, double clusterEta) const;
0228 
0229   double hfEnergyResolution(double clusterEnergy) const;
0230 
0231   double nSigmaHFEM(double clusterEnergy) const;
0232   double nSigmaHFHAD(double clusterEnergy) const;
0233 
0234   reco::PFCandidateCollection pfCandidates_;
0235   // the post-HF-cleaned candidates
0236   reco::PFCandidateCollection pfCleanedCandidates_;
0237 
0238   /// Associate PS clusters to a given ECAL cluster, and return their energy
0239   void associatePSClusters(unsigned iEcal,
0240                            reco::PFBlockElement::Type psElementType,
0241                            const reco::PFBlock& block,
0242                            const edm::OwnVector<reco::PFBlockElement>& elements,
0243                            const reco::PFBlock::LinkData& linkData,
0244                            std::vector<bool>& active,
0245                            std::vector<double>& psEne);
0246 
0247   bool isFromSecInt(const reco::PFBlockElement& eTrack, std::string order) const;
0248 
0249   // Post HF Cleaning
0250   void postCleaning();
0251 
0252   /// number of sigma to judge energy excess in ECAL
0253   const double nSigmaECAL_;
0254 
0255   /// number of sigma to judge energy excess in HCAL
0256   const double nSigmaHCAL_;
0257 
0258   /// number of sigma to judge energy excess in HF
0259   const double nSigmaHFEM_;
0260   const double nSigmaHFHAD_;
0261 
0262   // HF resolution
0263   const std::vector<double> resolHF_square_;
0264 
0265   PFEnergyCalibration& calibration_;
0266   PFEnergyCalibrationHF& thepfEnergyCalibrationHF_;
0267 
0268   bool useHO_;
0269 
0270   std::unique_ptr<PFMuonAlgo> pfmu_;
0271 
0272   /// Variables for NEW EGAMMA selection
0273   bool useEGammaFilters_;
0274   bool useProtectionsForJetMET_;
0275   const edm::View<reco::PFCandidate>* pfEgammaCandidates_;
0276   const edm::ValueMap<reco::GsfElectronRef>* valueMapGedElectrons_;
0277   const edm::ValueMap<reco::PhotonRef>* valueMapGedPhotons_;
0278 
0279   // Option to let PF decide the muon momentum
0280   bool usePFMuonMomAssign_;
0281 
0282   /// Flags to use the protection against fakes
0283   /// and not reconstructed displaced vertices
0284   bool rejectTracks_Bad_;
0285   bool rejectTracks_Step45_;
0286 
0287   bool usePFNuclearInteractions_;
0288   bool usePFConversions_;
0289   bool usePFDecays_;
0290 
0291   /// Maximal relative uncertainty on the tracks going to or incoming from the
0292   /// displcaed vertex to be used in the PFAlgo
0293   double dptRel_DispVtx_;
0294   int nVtx_;
0295 
0296   /// A tool used for a postprocessing of displaced vertices
0297   /// based on reconstructed PFCandidates
0298   PFCandConnector connector_;
0299 
0300   /// Variables for muons and fakes
0301   std::vector<double> muonHCAL_;
0302   std::vector<double> muonECAL_;
0303   std::vector<double> muonHO_;
0304   double nSigmaTRACK_;
0305   double ptError_;
0306   std::vector<double> factors45_;
0307 
0308   /// Variables for track cleaning in bad HCal areas
0309   float goodTrackDeadHcal_ptErrRel_;
0310   float goodTrackDeadHcal_chi2n_;
0311   int goodTrackDeadHcal_layers_;
0312   float goodTrackDeadHcal_validFr_;
0313   float goodTrackDeadHcal_dxy_;
0314 
0315   float goodPixelTrackDeadHcal_minEta_;
0316   float goodPixelTrackDeadHcal_maxPt_;
0317   float goodPixelTrackDeadHcal_ptErrRel_;
0318   float goodPixelTrackDeadHcal_chi2n_;
0319   int goodPixelTrackDeadHcal_maxLost3Hit_;
0320   int goodPixelTrackDeadHcal_maxLost4Hit_;
0321   float goodPixelTrackDeadHcal_dxy_;
0322   float goodPixelTrackDeadHcal_dz_;
0323 
0324   // Parameters for post HF cleaning
0325   bool postHFCleaning_;
0326   bool postMuonCleaning_;
0327   double minHFCleaningPt_;
0328   double minSignificance_;
0329   double maxSignificance_;
0330   double minSignificanceReduction_;
0331   double maxDeltaPhiPt_;
0332   double minDeltaMet_;
0333   double useBestMuonTrack_;
0334 
0335   //MIKE -May19th: Add option for the vertices....
0336   reco::Vertex primaryVertex_;
0337   bool useVertices_ = false;
0338 
0339   edm::Handle<reco::MuonCollection> muonHandle_;
0340 
0341   // Named constants
0342   const double nSigmaEConstHCAL = 100.;
0343   const double nSigmaEConstHFEM = 100.;
0344   const double nSigmaEConstHFHAD = 100.;
0345 };
0346 
0347 #endif