CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstCaloMuon.cc

Go to the documentation of this file.
00001 
00002 /* 
00003  * class TauDiscriminationAgainstCaloMuon
00004  * created : Nov 20 2010
00005  * revised : 
00006  * Authors : Christian Veelken (UC Davis)
00007  */
00008 
00009 #include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h"
00010 
00011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00012 #include "FWCore/Utilities/interface/InputTag.h"
00013 
00014 #include "DataFormats/MuonReco/interface/Muon.h"
00015 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00016 
00017 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00018 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00019 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00020 #include "DataFormats/HcalRecHit/interface/HBHERecHit.h"
00021 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00022 #include "DataFormats/CaloTowers/interface/CaloTower.h"
00023 #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
00024 
00025 #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
00026 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00027 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
00028 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateClosestToPoint.h"
00029 
00030 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00031 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00032 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00033 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00034 
00035 #include "DataFormats/Math/interface/deltaR.h"
00036 
00037 #include <TVector3.h>
00038 #include <TMath.h>
00039 
00040 #include <string>
00041 
00042 using namespace reco;
00043 
00044 // define acess to lead. track for CaloTaus
00045 template <typename T>
00046 class TauLeadTrackExtractor
00047 {
00048  public:
00049   reco::TrackRef getLeadTrack(const T& tau) const
00050   {
00051     return tau.leadTrack();
00052   }
00053   double getTrackPtSum(const T& tau) const
00054   {
00055     double trackPtSum = 0.;
00056     for ( TrackRefVector::const_iterator signalTrack = tau.signalTracks().begin();
00057           signalTrack != tau.signalTracks().end(); ++signalTrack ) {
00058       trackPtSum += (*signalTrack)->pt();
00059     }
00060     return trackPtSum;
00061   }
00062 };
00063 
00064 // define acess to lead. track for PFTaus
00065 template <>
00066 class TauLeadTrackExtractor<reco::PFTau>
00067 {
00068  public:
00069   reco::TrackRef getLeadTrack(const reco::PFTau& tau) const
00070   {
00071     return tau.leadPFChargedHadrCand()->trackRef();
00072   }
00073   double getTrackPtSum(const reco::PFTau& tau) const
00074   {
00075     double trackPtSum = 0.;
00076     for ( PFCandidateRefVector::const_iterator signalTrack = tau.signalPFChargedHadrCands().begin();
00077           signalTrack != tau.signalPFChargedHadrCands().end(); ++signalTrack ) {
00078       trackPtSum += (*signalTrack)->pt();
00079     }
00080     return trackPtSum;
00081   }
00082 };
00083 
00084 template<class TauType, class TauDiscriminator>
00085 class TauDiscriminationAgainstCaloMuon : public TauDiscriminationProducerBase<TauType, TauDiscriminator>
00086 {
00087  public:
00088   // setup framework types for this tautype
00089   typedef std::vector<TauType>    TauCollection; 
00090   typedef edm::Ref<TauCollection> TauRef;    
00091 
00092   explicit TauDiscriminationAgainstCaloMuon(const edm::ParameterSet&);
00093   ~TauDiscriminationAgainstCaloMuon() {} 
00094 
00095   // called at the beginning of every event
00096   void beginEvent(const edm::Event&, const edm::EventSetup&);
00097 
00098   double discriminate(const TauRef&);
00099 
00100  private:  
00101   edm::InputTag srcEcalRecHitsBarrel_;
00102   edm::Handle<EcalRecHitCollection> ebRecHits_;
00103   edm::InputTag srcEcalRecHitsEndcap_;
00104   edm::Handle<EcalRecHitCollection> eeRecHits_;
00105   edm::InputTag srcHcalRecHits_;
00106   edm::Handle<HBHERecHitCollection> hbheRecHits_;
00107 
00108   const TransientTrackBuilder* trackBuilder_;
00109   const CaloGeometry* caloGeometry_;
00110 
00111   TauLeadTrackExtractor<TauType> leadTrackExtractor_;
00112 
00113   double minLeadTrackPt_;
00114   double minLeadTrackPtFraction_;
00115 
00116   double drEcal_;
00117   double drHcal_;
00118 
00119   double maxEnEcal_;
00120   double maxEnHcal_;
00121 
00122   double maxEnToTrackRatio_;
00123 };
00124 
00125 template<class TauType, class TauDiscriminator>
00126 TauDiscriminationAgainstCaloMuon<TauType, TauDiscriminator>::TauDiscriminationAgainstCaloMuon(const edm::ParameterSet& cfg)
00127   : TauDiscriminationProducerBase<TauType, TauDiscriminator>(cfg) 
00128 {
00129   srcEcalRecHitsBarrel_ = cfg.getParameter<edm::InputTag>("srcEcalRecHitsBarrel");
00130   srcEcalRecHitsEndcap_ = cfg.getParameter<edm::InputTag>("srcEcalRecHitsEndcap");
00131   srcHcalRecHits_ = cfg.getParameter<edm::InputTag>("srcHcalRecHits");
00132 
00133   minLeadTrackPt_ = cfg.getParameter<double>("minLeadTrackPt");
00134   minLeadTrackPtFraction_ = cfg.getParameter<double>("minLeadTrackPtFraction");
00135 
00136   drEcal_ = cfg.getParameter<double>("dRecal");
00137   drHcal_ = cfg.getParameter<double>("dRhcal");
00138 
00139   maxEnEcal_ = cfg.getParameter<double>("maxEnEcal");
00140   maxEnHcal_ = cfg.getParameter<double>("maxEnHcal");
00141 
00142   maxEnToTrackRatio_ = cfg.getParameter<double>("maxEnToTrackRatio");
00143 }
00144 
00145 template<class TauType, class TauDiscriminator>
00146 void TauDiscriminationAgainstCaloMuon<TauType, TauDiscriminator>::beginEvent(const edm::Event& evt, const edm::EventSetup& evtSetup)
00147 {
00148   evt.getByLabel(srcEcalRecHitsBarrel_, ebRecHits_);
00149   evt.getByLabel(srcEcalRecHitsEndcap_, eeRecHits_);
00150   evt.getByLabel(srcHcalRecHits_, hbheRecHits_);
00151   
00152   edm::ESHandle<TransientTrackBuilder> trackBuilderHandle;
00153   evtSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", trackBuilderHandle);
00154   trackBuilder_ = trackBuilderHandle.product();
00155   if ( !trackBuilder_ ) {
00156     edm::LogError ("TauDiscriminationAgainstCaloMuon::discriminate")
00157       << " Failed to access TransientTrackBuilder !!";
00158   }
00159 
00160   edm::ESHandle<CaloGeometry> caloGeometryHandle;
00161   evtSetup.get<CaloGeometryRecord>().get(caloGeometryHandle);
00162   caloGeometry_ = caloGeometryHandle.product();
00163   if ( !caloGeometry_ ) {
00164     edm::LogError ("TauDiscriminationAgainstCaloMuon::discriminate")
00165       << " Failed to access CaloGeometry !!";
00166   }
00167 }               
00168 
00169 double compEcalEnergySum(const EcalRecHitCollection& ecalRecHits, 
00170                          const CaloSubdetectorGeometry* detGeometry, 
00171                          const reco::TransientTrack& transientTrack, double dR)
00172 {
00173   double ecalEnergySum = 0.;
00174   for ( EcalRecHitCollection::const_iterator ecalRecHit = ecalRecHits.begin();
00175         ecalRecHit != ecalRecHits.end(); ++ecalRecHit ) {
00176     const CaloCellGeometry* cellGeometry = detGeometry->getGeometry(ecalRecHit->detid());
00177     
00178     if ( !cellGeometry ) {
00179       edm::LogError ("compEcalEnergySum") 
00180         << " Failed to access ECAL geometry for detId = " << ecalRecHit->detid().rawId()
00181         << " --> skipping !!";
00182       continue;
00183     }
00184 
00185     const GlobalPoint& cellPosition = cellGeometry->getPosition();
00186 
00187     TrajectoryStateClosestToPoint dcaPosition = transientTrack.trajectoryStateClosestToPoint(cellPosition);
00188     
00189     Vector3DBase<float, GlobalTag> d = (cellPosition - dcaPosition.position());
00190 
00191     TVector3 d3(d.x(), d.y(), d.z());
00192     TVector3 dir(transientTrack.track().px(), transientTrack.track().py(), transientTrack.track().pz());
00193 
00194     double dPerp = d3.Cross(dir.Unit()).Mag();
00195     double dParl = TVector3(cellPosition.x(), cellPosition.y(), cellPosition.z()).Dot(dir.Unit());
00196     
00197     if ( dPerp < dR && dParl > 100. ) {
00198       ecalEnergySum += ecalRecHit->energy();
00199     }
00200   }
00201   
00202   return ecalEnergySum;
00203 }
00204 
00205 double compHcalEnergySum(const HBHERecHitCollection& hcalRecHits, 
00206                          const CaloSubdetectorGeometry* hbGeometry, const CaloSubdetectorGeometry* heGeometry, 
00207                          const reco::TransientTrack& transientTrack, double dR)
00208 {
00209   double hcalEnergySum = 0.;
00210   for ( HBHERecHitCollection::const_iterator hcalRecHit = hcalRecHits.begin();
00211         hcalRecHit != hcalRecHits.end(); ++hcalRecHit ) {
00212     const CaloCellGeometry* hbCellGeometry = hbGeometry->getGeometry(hcalRecHit->detid());
00213     const CaloCellGeometry* heCellGeometry = heGeometry->getGeometry(hcalRecHit->detid());
00214 
00215     const GlobalPoint* cellPosition = 0;
00216     if ( hbCellGeometry ) cellPosition = &(hbCellGeometry->getPosition());
00217     if ( heCellGeometry ) cellPosition = &(heCellGeometry->getPosition());
00218 
00219     if ( !cellPosition ) {
00220       edm::LogError ("compHcalEnergySum") 
00221         << " Failed to access HCAL geometry for detId = " << hcalRecHit->detid().rawId()
00222         << " --> skipping !!";
00223       continue;
00224     }
00225 
00226     TrajectoryStateClosestToPoint dcaPosition = transientTrack.trajectoryStateClosestToPoint(*cellPosition);
00227     
00228     Vector3DBase<float, GlobalTag> d = ((*cellPosition) - dcaPosition.position());
00229 
00230     TVector3 d3(d.x(), d.y(), d.z());
00231     TVector3 dir(transientTrack.track().px(), transientTrack.track().py(), transientTrack.track().pz());
00232 
00233     double dPerp = d3.Cross(dir.Unit()).Mag();
00234     double dParl = TVector3(cellPosition->x(), cellPosition->y(), cellPosition->z()).Dot(dir.Unit());
00235 
00236     if ( dPerp < dR && dParl > 100. ) {
00237       hcalEnergySum += hcalRecHit->energy();
00238     }
00239   }
00240   
00241   return hcalEnergySum;
00242 }
00243 
00244 template<class TauType, class TauDiscriminator>
00245 double TauDiscriminationAgainstCaloMuon<TauType, TauDiscriminator>::discriminate(const TauRef& tau)
00246 {
00247   if ( !(trackBuilder_ && caloGeometry_) ) return 0.;
00248 
00249   const CaloSubdetectorGeometry* ebGeometry = caloGeometry_->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
00250   const CaloSubdetectorGeometry* eeGeometry = caloGeometry_->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
00251   const CaloSubdetectorGeometry* hbGeometry = caloGeometry_->getSubdetectorGeometry(DetId::Hcal, HcalBarrel);
00252   const CaloSubdetectorGeometry* heGeometry = caloGeometry_->getSubdetectorGeometry(DetId::Hcal, HcalEndcap);
00253 
00254   TrackRef leadTrackRef = leadTrackExtractor_.getLeadTrack(*tau);
00255 
00256   if ( (leadTrackRef.isAvailable() || leadTrackRef.isTransient()) && leadTrackRef.isNonnull() ) {
00257     double leadTrackPt = leadTrackRef->pt();
00258     double trackPtSum = leadTrackExtractor_.getTrackPtSum(*tau);
00259     
00260     double leadTrackPtFraction = ( trackPtSum > 0. ) ? (leadTrackPt/trackPtSum) : -1.;
00261     
00262     if ( leadTrackPt > minLeadTrackPt_ && leadTrackPtFraction > minLeadTrackPtFraction_ ) {
00263       reco::TransientTrack transientTrack = trackBuilder_->build(leadTrackRef);
00264 
00265       double ebEnergySum = compEcalEnergySum(*ebRecHits_, ebGeometry, transientTrack, drEcal_);
00266       double eeEnergySum = compEcalEnergySum(*eeRecHits_, eeGeometry, transientTrack, drEcal_);
00267       double ecalEnergySum = ebEnergySum + eeEnergySum;
00268       
00269       double hbheEnergySum = compHcalEnergySum(*hbheRecHits_, hbGeometry, heGeometry, transientTrack, drHcal_);
00270       
00271       double caloEnergySum = ecalEnergySum + hbheEnergySum;
00272 
00273       if ( ecalEnergySum <  maxEnEcal_ &&
00274            hbheEnergySum <  maxEnHcal_ &&
00275            caloEnergySum < (maxEnToTrackRatio_*leadTrackPt) ) return 0.;
00276     }
00277   }
00278 
00279   return 1.;
00280 }
00281 
00282 #include "FWCore/Framework/interface/MakerMacros.h"
00283 
00284 typedef TauDiscriminationAgainstCaloMuon<PFTau, PFTauDiscriminator> PFRecoTauDiscriminationAgainstCaloMuon;
00285 typedef TauDiscriminationAgainstCaloMuon<CaloTau, CaloTauDiscriminator> CaloRecoTauDiscriminationAgainstCaloMuon;
00286 
00287 DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstCaloMuon);
00288 DEFINE_FWK_MODULE(CaloRecoTauDiscriminationAgainstCaloMuon);