CMS 3D CMS Logo

TauDiscriminationAgainstCaloMuon.cc
Go to the documentation of this file.
1 
2 /*
3  * class TauDiscriminationAgainstCaloMuon
4  * created : Nov 20 2010
5  * revised :
6  * Authors : Christian Veelken (UC Davis)
7  */
8 
10 
13 
16 
24 
29 
35 
38 
40 
41 #include <TVector3.h>
42 #include <TMath.h>
43 
44 #include <string>
45 
46 namespace {
47 
48 using namespace reco;
49 
50 // define acess to lead. track for CaloTaus
51 template <typename T>
52 class TauLeadTrackExtractor
53 {
54  public:
55  reco::TrackRef getLeadTrack(const T& tau) const
56  {
57  return tau.leadTrack();
58  }
59  double getTrackPtSum(const T& tau) const
60  {
61  double trackPtSum = 0.;
62  for ( TrackRefVector::const_iterator signalTrack = tau.signalTracks().begin();
63  signalTrack != tau.signalTracks().end(); ++signalTrack ) {
64  trackPtSum += (*signalTrack)->pt();
65  }
66  return trackPtSum;
67  }
68 };
69 
70 // define acess to lead. track for PFTaus
71 template <>
72 class TauLeadTrackExtractor<reco::PFTau>
73 {
74  public:
75  reco::TrackRef getLeadTrack(const reco::PFTau& tau) const
76  {
77  return tau.leadPFChargedHadrCand()->trackRef();
78  }
79  double getTrackPtSum(const reco::PFTau& tau) const
80  {
81  double trackPtSum = 0.;
82  for ( std::vector<PFCandidatePtr>::const_iterator signalTrack = tau.signalPFChargedHadrCands().begin();
83  signalTrack != tau.signalPFChargedHadrCands().end(); ++signalTrack ) {
84  trackPtSum += (*signalTrack)->pt();
85  }
86  return trackPtSum;
87  }
88 };
89 
90 template<class TauType, class TauDiscriminator>
91 class TauDiscriminationAgainstCaloMuon final : public TauDiscriminationProducerBase<TauType, TauDiscriminator>
92 {
93  public:
94  // setup framework types for this tautype
95  typedef std::vector<TauType> TauCollection;
97 
98  explicit TauDiscriminationAgainstCaloMuon(const edm::ParameterSet&);
99  ~TauDiscriminationAgainstCaloMuon() override {}
100 
101  // called at the beginning of every event
102  void beginEvent(const edm::Event&, const edm::EventSetup&) override;
103 
104  double discriminate(const TauRef&) const override;
105 
106  private:
107  edm::InputTag srcEcalRecHitsBarrel_;
109  edm::InputTag srcEcalRecHitsEndcap_;
111  edm::InputTag srcHcalRecHits_;
113 
114  edm::InputTag srcVertex_;
115  GlobalPoint eventVertexPosition_;
116 
117  const TransientTrackBuilder* trackBuilder_;
118  const CaloGeometry* caloGeometry_;
119 
120  TauLeadTrackExtractor<TauType> leadTrackExtractor_;
121 
122  double minLeadTrackPt_;
123  double minLeadTrackPtFraction_;
124 
125  double drEcal_;
126  double drHcal_;
127 
128  double maxEnEcal_;
129  double maxEnHcal_;
130 
131  double maxEnToTrackRatio_;
132 };
133 
134 template<class TauType, class TauDiscriminator>
135 TauDiscriminationAgainstCaloMuon<TauType, TauDiscriminator>::TauDiscriminationAgainstCaloMuon(const edm::ParameterSet& cfg)
136  : TauDiscriminationProducerBase<TauType, TauDiscriminator>(cfg)
137 {
138  srcEcalRecHitsBarrel_ = cfg.getParameter<edm::InputTag>("srcEcalRecHitsBarrel");
139  srcEcalRecHitsEndcap_ = cfg.getParameter<edm::InputTag>("srcEcalRecHitsEndcap");
140  srcHcalRecHits_ = cfg.getParameter<edm::InputTag>("srcHcalRecHits");
141 
142  srcVertex_ = cfg.getParameter<edm::InputTag>("srcVertex");
143 
144  minLeadTrackPt_ = cfg.getParameter<double>("minLeadTrackPt");
145  minLeadTrackPtFraction_ = cfg.getParameter<double>("minLeadTrackPtFraction");
146 
147  drEcal_ = cfg.getParameter<double>("dRecal");
148  drHcal_ = cfg.getParameter<double>("dRhcal");
149 
150  maxEnEcal_ = cfg.getParameter<double>("maxEnEcal");
151  maxEnHcal_ = cfg.getParameter<double>("maxEnHcal");
152 
153  maxEnToTrackRatio_ = cfg.getParameter<double>("maxEnToTrackRatio");
154 }
155 
156 template<class TauType, class TauDiscriminator>
157 void TauDiscriminationAgainstCaloMuon<TauType, TauDiscriminator>::beginEvent(const edm::Event& evt, const edm::EventSetup& evtSetup)
158 {
159  evt.getByLabel(srcEcalRecHitsBarrel_, ebRecHits_);
160  evt.getByLabel(srcEcalRecHitsEndcap_, eeRecHits_);
161  evt.getByLabel(srcHcalRecHits_, hbheRecHits_);
162 
163  edm::ESHandle<TransientTrackBuilder> trackBuilderHandle;
164  evtSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", trackBuilderHandle);
165  trackBuilder_ = trackBuilderHandle.product();
166  if ( !trackBuilder_ ) {
167  edm::LogError ("TauDiscriminationAgainstCaloMuon::discriminate")
168  << " Failed to access TransientTrackBuilder !!";
169  }
170 
171  edm::ESHandle<CaloGeometry> caloGeometryHandle;
172  evtSetup.get<CaloGeometryRecord>().get(caloGeometryHandle);
173  caloGeometry_ = caloGeometryHandle.product();
174  if ( !caloGeometry_ ) {
175  edm::LogError ("TauDiscriminationAgainstCaloMuon::discriminate")
176  << " Failed to access CaloGeometry !!";
177  }
178 
180  evt.getByLabel(srcVertex_, vertices);
181  eventVertexPosition_ = GlobalPoint(0., 0., 0.);
182  if (!vertices->empty()) {
183  const reco::Vertex& thePrimaryEventVertex = (*vertices->begin());
184  eventVertexPosition_ = GlobalPoint(thePrimaryEventVertex.x(), thePrimaryEventVertex.y(), thePrimaryEventVertex.z());
185  }
186 }
187 
188 double compEcalEnergySum(const EcalRecHitCollection& ecalRecHits,
189  const CaloSubdetectorGeometry* detGeometry,
190  const reco::TransientTrack& transientTrack, double dR,
191  const GlobalPoint& eventVertexPosition)
192 {
193  double ecalEnergySum = 0.;
195  ecalRecHit != ecalRecHits.end(); ++ecalRecHit ) {
196  auto cellGeometry = detGeometry->getGeometry(ecalRecHit->detid());
197 
198  if ( !cellGeometry ) {
199  edm::LogError ("compEcalEnergySum")
200  << " Failed to access ECAL geometry for detId = " << ecalRecHit->detid().rawId()
201  << " --> skipping !!";
202  continue;
203  }
204 
205  const GlobalPoint& cellPosition = cellGeometry->getPosition();
206 
207 //--- CV: speed up computation by requiring eta-phi distance
208 // between cell position and track direction to be dR < 0.5
209  Vector3DBase<float, GlobalTag> cellPositionRelVertex = (cellPosition) - eventVertexPosition;
210  if ( deltaR(cellPositionRelVertex.eta(), cellPositionRelVertex.phi(),
211  transientTrack.track().eta(), transientTrack.track().phi()) > 0.5 ) continue;
212 
213  TrajectoryStateClosestToPoint dcaPosition = transientTrack.trajectoryStateClosestToPoint(cellPosition);
214 
215  Vector3DBase<float, GlobalTag> d = (cellPosition - dcaPosition.position());
216 
217  TVector3 d3(d.x(), d.y(), d.z());
218  TVector3 dir(transientTrack.track().px(), transientTrack.track().py(), transientTrack.track().pz());
219 
220  double dPerp = d3.Cross(dir.Unit()).Mag();
221  double dParl = TVector3(cellPosition.x(), cellPosition.y(), cellPosition.z()).Dot(dir.Unit());
222 
223  if ( dPerp < dR && dParl > 100. ) {
224  ecalEnergySum += ecalRecHit->energy();
225  }
226  }
227 
228  return ecalEnergySum;
229 }
230 
231 double compHcalEnergySum(const HBHERecHitCollection& hcalRecHits,
232  const HcalGeometry* hcGeometry,
233  const reco::TransientTrack& transientTrack, double dR,
234  const GlobalPoint& eventVertexPosition)
235 {
236  double hcalEnergySum = 0.;
237  for ( HBHERecHitCollection::const_iterator hcalRecHit = hcalRecHits.begin();
238  hcalRecHit != hcalRecHits.end(); ++hcalRecHit ) {
239 
240  const GlobalPoint cellPosition = hcGeometry->getPosition(hcalRecHit->detid());
241 
242 //--- CV: speed up computation by requiring eta-phi distance
243 // between cell position and track direction to be dR < 0.5
244  Vector3DBase<float, GlobalTag> cellPositionRelVertex = (cellPosition) - eventVertexPosition;
245  if ( deltaR(cellPositionRelVertex.eta(), cellPositionRelVertex.phi(),
246  transientTrack.track().eta(), transientTrack.track().phi()) > 0.5 ) continue;
247 
248  TrajectoryStateClosestToPoint dcaPosition = transientTrack.trajectoryStateClosestToPoint(cellPosition);
249 
250  Vector3DBase<float, GlobalTag> d = ((cellPosition) - dcaPosition.position());
251 
252  TVector3 d3(d.x(), d.y(), d.z());
253  TVector3 dir(transientTrack.track().px(), transientTrack.track().py(), transientTrack.track().pz());
254 
255  double dPerp = d3.Cross(dir.Unit()).Mag();
256  double dParl = TVector3(cellPosition.x(), cellPosition.y(), cellPosition.z()).Dot(dir.Unit());
257 
258  if ( dPerp < dR && dParl > 100. ) {
259  hcalEnergySum += hcalRecHit->energy();
260  }
261  }
262 
263  return hcalEnergySum;
264 }
265 
266 template<class TauType, class TauDiscriminator>
267 double TauDiscriminationAgainstCaloMuon<TauType, TauDiscriminator>::discriminate(const TauRef& tau) const
268 {
269  if ( !(trackBuilder_ && caloGeometry_) ) return 0.;
270 
271  const CaloSubdetectorGeometry* ebGeometry = caloGeometry_->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
272  const CaloSubdetectorGeometry* eeGeometry = caloGeometry_->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
273  const HcalGeometry* hcGeometry = static_cast<const HcalGeometry*>(caloGeometry_->getSubdetectorGeometry(DetId::Hcal, HcalBarrel));
274 
275  TrackRef leadTrackRef = leadTrackExtractor_.getLeadTrack(*tau);
276 
277  if ( (leadTrackRef.isAvailable() || leadTrackRef.isTransient()) && leadTrackRef.isNonnull() ) {
278  double leadTrackPt = leadTrackRef->pt();
279  double trackPtSum = leadTrackExtractor_.getTrackPtSum(*tau);
280 
281  double leadTrackPtFraction = ( trackPtSum > 0. ) ? (leadTrackPt/trackPtSum) : -1.;
282 
283  if ( leadTrackPt > minLeadTrackPt_ && leadTrackPtFraction > minLeadTrackPtFraction_ ) {
284  reco::TransientTrack transientTrack = trackBuilder_->build(leadTrackRef);
285 
286  double ebEnergySum = compEcalEnergySum(*ebRecHits_, ebGeometry, transientTrack, drEcal_, eventVertexPosition_);
287  double eeEnergySum = compEcalEnergySum(*eeRecHits_, eeGeometry, transientTrack, drEcal_, eventVertexPosition_);
288  double ecalEnergySum = ebEnergySum + eeEnergySum;
289 
290  double hbheEnergySum = compHcalEnergySum(*hbheRecHits_, hcGeometry, transientTrack, drHcal_, eventVertexPosition_);
291 
292  double caloEnergySum = ecalEnergySum + hbheEnergySum;
293 
294  if ( ecalEnergySum < maxEnEcal_ &&
295  hbheEnergySum < maxEnHcal_ &&
296  caloEnergySum < (maxEnToTrackRatio_*leadTrackPt) ) return 0.;
297  }
298  }
299 
300  return 1.;
301 }
302 
303 }
304 
306 
307 typedef TauDiscriminationAgainstCaloMuon<PFTau, PFTauDiscriminator> PFRecoTauDiscriminationAgainstCaloMuon;
308 typedef TauDiscriminationAgainstCaloMuon<CaloTau, CaloTauDiscriminator> CaloRecoTauDiscriminationAgainstCaloMuon;
309 
310 DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstCaloMuon);
311 DEFINE_FWK_MODULE(CaloRecoTauDiscriminationAgainstCaloMuon);
bool isAvailable() const
Definition: Ref.h:577
T getParameter(std::string const &) const
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
edm::Ref< TauBxCollection > TauRef
Definition: Tau.h:13
const PFCandidatePtr & leadPFChargedHadrCand() const
Definition: PFTau.cc:67
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
double y() const
y coordinate
Definition: Vertex.h:113
bool isTransient() const
Checks if this ref is transient (i.e. not persistable).
Definition: Ref.h:278
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< EcalRecHit >::const_iterator const_iterator
T y() const
Definition: PV3DBase.h:63
std::vector< Tau > TauCollection
Definition: Tau.h:36
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:645
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:627
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:442
TauDiscriminationAgainstCaloMuon< PFTau, PFTauDiscriminator > PFRecoTauDiscriminationAgainstCaloMuon
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:651
T z() const
Definition: PV3DBase.h:64
double z() const
z coordinate
Definition: Vertex.h:115
const edm::EventSetup * evtSetup() const
TauDiscriminationAgainstCaloMuon< CaloTau, CaloTauDiscriminator > CaloRecoTauDiscriminationAgainstCaloMuon
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:535
GlobalPoint getPosition(const DetId &id) const
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:639
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
const_iterator end() const
double x() const
x coordinate
Definition: Vertex.h:111
const Track & track() const
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
TrajectoryStateClosestToPoint trajectoryStateClosestToPoint(const GlobalPoint &point) const
T eta() const
Definition: PV3DBase.h:76
fixed size matrix
T get() const
Definition: EventSetup.h:63
dbl *** dir
Definition: mlp_gen.cc:35
long double T
T x() const
Definition: PV3DBase.h:62
T const * product() const
Definition: ESHandle.h:86
const std::vector< reco::PFCandidatePtr > & signalPFChargedHadrCands() const
Charged hadrons in signal region.
Definition: PFTau.cc:80
const_iterator begin() const
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:633