Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:27

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 private:
0120   void egammaFilters(const reco::PFBlockRef& blockref, std::vector<bool>& active, PFEGammaFilters const* pfegamma);
0121   void conversionAlgo(const edm::OwnVector<reco::PFBlockElement>& elements, std::vector<bool>& active);
0122   bool checkAndReconstructSecondaryInteraction(const reco::PFBlockRef& blockref,
0123                                                const edm::OwnVector<reco::PFBlockElement>& elements,
0124                                                bool isActive,
0125                                                int iElement);
0126   bool checkHasDeadHcal(const std::multimap<double, unsigned>& hcalElems, const std::vector<bool>& deadArea);
0127   void relinkTrackToHcal(const reco::PFBlock& block,
0128                          std::multimap<double, unsigned>& ecalElems,
0129                          std::multimap<double, unsigned>& hcalElems,
0130                          const std::vector<bool>& active,
0131                          reco::PFBlock::LinkData& linkData,
0132                          unsigned int iTrack);
0133   bool checkGoodTrackDeadHcal(const reco::TrackRef& trackRef, bool hasDeadHcal);
0134   void elementLoop(const reco::PFBlock& block,
0135                    reco::PFBlock::LinkData& linkData,
0136                    const edm::OwnVector<reco::PFBlockElement>& elements,
0137                    std::vector<bool>& active,
0138                    const reco::PFBlockRef& blockref,
0139                    ElementIndices& inds,
0140                    std::vector<bool>& deadArea);
0141   int decideType(const edm::OwnVector<reco::PFBlockElement>& elements,
0142                  const reco::PFBlockElement::Type type,
0143                  std::vector<bool>& active,
0144                  ElementIndices& inds,
0145                  std::vector<bool>& deadArea,
0146                  unsigned int iEle);
0147   bool recoTracksNotHCAL(const reco::PFBlock& block,
0148                          reco::PFBlock::LinkData& linkData,
0149                          const edm::OwnVector<reco::PFBlockElement>& elements,
0150                          const reco::PFBlockRef& blockref,
0151                          std::vector<bool>& active,
0152                          bool goodTrackDeadHcal,
0153                          bool hasDeadHcal,
0154                          unsigned int iTrack,
0155                          std::multimap<double, unsigned>& ecalElems,
0156                          reco::TrackRef& trackRef);
0157 
0158   //Looks for a HF-associated element in the block and produces a PFCandidate from it with HF_EM and/or HF_HAD calibrations
0159   void createCandidatesHF(const reco::PFBlock& block,
0160                           reco::PFBlock::LinkData& linkData,
0161                           const edm::OwnVector<reco::PFBlockElement>& elements,
0162                           std::vector<bool>& active,
0163                           const reco::PFBlockRef& blockref,
0164                           ElementIndices& inds);
0165 
0166   void createCandidatesHCAL(const reco::PFBlock& block,
0167                             reco::PFBlock::LinkData& linkData,
0168                             const edm::OwnVector<reco::PFBlockElement>& elements,
0169                             std::vector<bool>& active,
0170                             const reco::PFBlockRef& blockref,
0171                             ElementIndices& inds,
0172                             std::vector<bool>& deadArea);
0173   void createCandidatesHCALUnlinked(const reco::PFBlock& block,
0174                                     reco::PFBlock::LinkData& linkData,
0175                                     const edm::OwnVector<reco::PFBlockElement>& elements,
0176                                     std::vector<bool>& active,
0177                                     const reco::PFBlockRef& blockref,
0178                                     ElementIndices& inds,
0179                                     std::vector<bool>& deadArea);
0180 
0181   void createCandidatesECAL(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   /// process one block. can be reimplemented in more sophisticated
0190   /// algorithms
0191   void processBlock(const reco::PFBlockRef& blockref,
0192                     std::list<reco::PFBlockRef>& hcalBlockRefs,
0193                     std::list<reco::PFBlockRef>& ecalBlockRefs,
0194                     PFEGammaFilters const* pfegamma);
0195 
0196   /// Reconstruct a charged particle from a track
0197   /// Returns the index of the newly created candidate in pfCandidates_
0198   /// Michalis added a flag here to treat muons inside jets
0199   unsigned reconstructTrack(const reco::PFBlockElement& elt, bool allowLoose = false);
0200 
0201   /// Reconstruct a neutral particle from a cluster.
0202   /// If chargedEnergy is specified, the neutral
0203   /// particle is created only if the cluster energy is significantly
0204   /// larger than the chargedEnergy. In this case, the energy of the
0205   /// neutral particle is cluster energy - chargedEnergy
0206 
0207   unsigned reconstructCluster(const reco::PFCluster& cluster,
0208                               double particleEnergy,
0209                               bool useDirection = false,
0210                               double particleX = 0.,
0211                               double particleY = 0.,
0212                               double particleZ = 0.);
0213 
0214   void setHcalDepthInfo(reco::PFCandidate& cand, const reco::PFCluster& cluster) const;
0215 
0216   /// todo: use PFClusterTools for this
0217   double neutralHadronEnergyResolution(double clusterEnergy, double clusterEta) const;
0218 
0219   double nSigmaHCAL(double clusterEnergy, double clusterEta) const;
0220 
0221   double hfEnergyResolution(double clusterEnergy) const;
0222 
0223   double nSigmaHFEM(double clusterEnergy) const;
0224   double nSigmaHFHAD(double clusterEnergy) const;
0225 
0226   std::unique_ptr<reco::PFCandidateCollection> pfCandidates_;
0227   // the post-HF-cleaned candidates
0228   reco::PFCandidateCollection pfCleanedCandidates_;
0229 
0230   /// Associate PS clusters to a given ECAL cluster, and return their energy
0231   void associatePSClusters(unsigned iEcal,
0232                            reco::PFBlockElement::Type psElementType,
0233                            const reco::PFBlock& block,
0234                            const edm::OwnVector<reco::PFBlockElement>& elements,
0235                            const reco::PFBlock::LinkData& linkData,
0236                            std::vector<bool>& active,
0237                            std::vector<double>& psEne);
0238 
0239   bool isFromSecInt(const reco::PFBlockElement& eTrack, std::string order) const;
0240 
0241   // Post HF Cleaning
0242   void postCleaning();
0243 
0244   /// number of sigma to judge energy excess in ECAL
0245   const double nSigmaECAL_;
0246 
0247   /// number of sigma to judge energy excess in HCAL
0248   const double nSigmaHCAL_;
0249 
0250   /// number of sigma to judge energy excess in HF
0251   const double nSigmaHFEM_;
0252   const double nSigmaHFHAD_;
0253 
0254   // HF resolution
0255   const std::vector<double> resolHF_square_;
0256 
0257   PFEnergyCalibration& calibration_;
0258   PFEnergyCalibrationHF& thepfEnergyCalibrationHF_;
0259 
0260   bool useHO_;
0261 
0262   std::unique_ptr<PFMuonAlgo> pfmu_;
0263 
0264   /// Variables for NEW EGAMMA selection
0265   bool useEGammaFilters_;
0266   bool useProtectionsForJetMET_;
0267   const edm::View<reco::PFCandidate>* pfEgammaCandidates_;
0268   const edm::ValueMap<reco::GsfElectronRef>* valueMapGedElectrons_;
0269   const edm::ValueMap<reco::PhotonRef>* valueMapGedPhotons_;
0270 
0271   // Option to let PF decide the muon momentum
0272   bool usePFMuonMomAssign_;
0273 
0274   /// Flags to use the protection against fakes
0275   /// and not reconstructed displaced vertices
0276   bool rejectTracks_Bad_;
0277   bool rejectTracks_Step45_;
0278 
0279   bool usePFNuclearInteractions_;
0280   bool usePFConversions_;
0281   bool usePFDecays_;
0282 
0283   /// Maximal relative uncertainty on the tracks going to or incoming from the
0284   /// displcaed vertex to be used in the PFAlgo
0285   double dptRel_DispVtx_;
0286   int nVtx_;
0287 
0288   /// A tool used for a postprocessing of displaced vertices
0289   /// based on reconstructed PFCandidates
0290   PFCandConnector connector_;
0291 
0292   /// Variables for muons and fakes
0293   std::vector<double> muonHCAL_;
0294   std::vector<double> muonECAL_;
0295   std::vector<double> muonHO_;
0296   double nSigmaTRACK_;
0297   double ptError_;
0298   std::vector<double> factors45_;
0299 
0300   /// Variables for track cleaning in bad HCal areas
0301   float goodTrackDeadHcal_ptErrRel_;
0302   float goodTrackDeadHcal_chi2n_;
0303   int goodTrackDeadHcal_layers_;
0304   float goodTrackDeadHcal_validFr_;
0305   float goodTrackDeadHcal_dxy_;
0306 
0307   float goodPixelTrackDeadHcal_minEta_;
0308   float goodPixelTrackDeadHcal_maxPt_;
0309   float goodPixelTrackDeadHcal_ptErrRel_;
0310   float goodPixelTrackDeadHcal_chi2n_;
0311   int goodPixelTrackDeadHcal_maxLost3Hit_;
0312   int goodPixelTrackDeadHcal_maxLost4Hit_;
0313   float goodPixelTrackDeadHcal_dxy_;
0314   float goodPixelTrackDeadHcal_dz_;
0315 
0316   // Parameters for post HF cleaning
0317   bool postHFCleaning_;
0318   bool postMuonCleaning_;
0319   double minHFCleaningPt_;
0320   double minSignificance_;
0321   double maxSignificance_;
0322   double minSignificanceReduction_;
0323   double maxDeltaPhiPt_;
0324   double minDeltaMet_;
0325   double useBestMuonTrack_;
0326 
0327   //MIKE -May19th: Add option for the vertices....
0328   reco::Vertex primaryVertex_;
0329   bool useVertices_ = false;
0330 
0331   edm::Handle<reco::MuonCollection> muonHandle_;
0332 
0333   // Named constants
0334   const double nSigmaEConstHCAL = 100.;
0335   const double nSigmaEConstHFEM = 100.;
0336   const double nSigmaEConstHFHAD = 100.;
0337 };
0338 
0339 #endif