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 
19 
27 
32 
38 
41 
43 
44 #include <TVector3.h>
45 #include <TMath.h>
46 
47 #include <string>
48 
49 namespace {
50 
51  using namespace reco;
52 
53  // define acess to lead. track for CaloTaus
54  template <typename T>
55  class TauLeadTrackExtractor {
56  public:
57  reco::TrackRef getLeadTrack(const T& tau) const { return tau.leadTrack(); }
58  double getTrackPtSum(const T& tau) const {
59  double trackPtSum = 0.;
60  for (TrackRefVector::const_iterator signalTrack = tau.signalTracks().begin();
61  signalTrack != tau.signalTracks().end();
62  ++signalTrack) {
63  trackPtSum += (*signalTrack)->pt();
64  }
65  return trackPtSum;
66  }
67  };
68 
69  // define acess to lead. track for PFTaus
70  template <>
71  class TauLeadTrackExtractor<reco::PFTau> {
72  public:
73  reco::TrackRef getLeadTrack(const reco::PFTau& tau) const { return tau.leadPFChargedHadrCand()->trackRef(); }
74  double getTrackPtSum(const reco::PFTau& tau) const {
75  double trackPtSum = 0.;
76  for (std::vector<CandidatePtr>::const_iterator signalTrack = tau.signalChargedHadrCands().begin();
77  signalTrack != tau.signalChargedHadrCands().end();
78  ++signalTrack) {
79  trackPtSum += (*signalTrack)->pt();
80  }
81  return trackPtSum;
82  }
83  };
84 
85  template <class TauType, class TauDiscriminator>
86  class TauDiscriminationAgainstCaloMuon final : public TauDiscriminationProducerBase<TauType, TauDiscriminator> {
87  public:
88  // setup framework types for this tautype
89  typedef std::vector<TauType> TauCollection;
91 
92  explicit TauDiscriminationAgainstCaloMuon(const edm::ParameterSet&);
93  ~TauDiscriminationAgainstCaloMuon() override {}
94 
95  // called at the beginning of every event
96  void beginEvent(const edm::Event&, const edm::EventSetup&) override;
97 
98  double discriminate(const TauRef&) const override;
99 
100  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
101 
102  private:
103  edm::InputTag srcEcalRecHitsBarrel_;
105  edm::InputTag srcEcalRecHitsEndcap_;
107  edm::InputTag srcHcalRecHits_;
109 
110  edm::InputTag srcVertex_;
111  GlobalPoint eventVertexPosition_;
112 
113  const TransientTrackBuilder* trackBuilder_;
114  const CaloGeometry* caloGeometry_;
116  const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> caloGeometryToken_;
117 
118  TauLeadTrackExtractor<TauType> leadTrackExtractor_;
119 
120  double minLeadTrackPt_;
121  double minLeadTrackPtFraction_;
122 
123  double drEcal_;
124  double drHcal_;
125 
126  double maxEnEcal_;
127  double maxEnHcal_;
128 
129  double maxEnToTrackRatio_;
130  };
131 
132  template <class TauType, class TauDiscriminator>
133  TauDiscriminationAgainstCaloMuon<TauType, TauDiscriminator>::TauDiscriminationAgainstCaloMuon(
134  const edm::ParameterSet& cfg)
135  : TauDiscriminationProducerBase<TauType, TauDiscriminator>(cfg),
136  trackBuilderToken_(this->esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))),
137  caloGeometryToken_(this->esConsumes()) {
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,
158  const edm::EventSetup& evtSetup) {
159  evt.getByLabel(srcEcalRecHitsBarrel_, ebRecHits_);
160  evt.getByLabel(srcEcalRecHitsEndcap_, eeRecHits_);
161  evt.getByLabel(srcHcalRecHits_, hbheRecHits_);
162 
163  trackBuilder_ = &evtSetup.getData(trackBuilderToken_);
164  if (!trackBuilder_) {
165  edm::LogError("TauDiscriminationAgainstCaloMuon::discriminate") << " Failed to access TransientTrackBuilder !!";
166  }
167 
168  caloGeometry_ = &evtSetup.getData(caloGeometryToken_);
169  if (!caloGeometry_) {
170  edm::LogError("TauDiscriminationAgainstCaloMuon::discriminate") << " Failed to access CaloGeometry !!";
171  }
172 
174  evt.getByLabel(srcVertex_, vertices);
175  eventVertexPosition_ = GlobalPoint(0., 0., 0.);
176  if (!vertices->empty()) {
177  const reco::Vertex& thePrimaryEventVertex = (*vertices->begin());
178  eventVertexPosition_ =
179  GlobalPoint(thePrimaryEventVertex.x(), thePrimaryEventVertex.y(), thePrimaryEventVertex.z());
180  }
181  }
182 
183  double compEcalEnergySum(const EcalRecHitCollection& ecalRecHits,
184  const CaloSubdetectorGeometry* detGeometry,
185  const reco::TransientTrack& transientTrack,
186  double dR,
187  const GlobalPoint& eventVertexPosition) {
188  double ecalEnergySum = 0.;
189  for (EcalRecHitCollection::const_iterator ecalRecHit = ecalRecHits.begin(); ecalRecHit != ecalRecHits.end();
190  ++ecalRecHit) {
191  auto cellGeometry = detGeometry->getGeometry(ecalRecHit->detid());
192 
193  if (!cellGeometry) {
194  edm::LogError("compEcalEnergySum")
195  << " Failed to access ECAL geometry for detId = " << ecalRecHit->detid().rawId() << " --> skipping !!";
196  continue;
197  }
198 
199  const GlobalPoint& cellPosition = cellGeometry->getPosition();
200 
201  //--- CV: speed up computation by requiring eta-phi distance
202  // between cell position and track direction to be dR < 0.5
203  Vector3DBase<float, GlobalTag> cellPositionRelVertex = (cellPosition)-eventVertexPosition;
204  if (deltaR(cellPositionRelVertex.eta(),
205  cellPositionRelVertex.phi(),
206  transientTrack.track().eta(),
207  transientTrack.track().phi()) > 0.5)
208  continue;
209 
210  TrajectoryStateClosestToPoint dcaPosition = transientTrack.trajectoryStateClosestToPoint(cellPosition);
211 
212  Vector3DBase<float, GlobalTag> d = (cellPosition - dcaPosition.position());
213 
214  TVector3 d3(d.x(), d.y(), d.z());
215  TVector3 dir(transientTrack.track().px(), transientTrack.track().py(), transientTrack.track().pz());
216 
217  double dPerp = d3.Cross(dir.Unit()).Mag();
218  double dParl = TVector3(cellPosition.x(), cellPosition.y(), cellPosition.z()).Dot(dir.Unit());
219 
220  if (dPerp < dR && dParl > 100.) {
221  ecalEnergySum += ecalRecHit->energy();
222  }
223  }
224 
225  return ecalEnergySum;
226  }
227 
228  double compHcalEnergySum(const HBHERecHitCollection& hcalRecHits,
229  const HcalGeometry* hcGeometry,
230  const reco::TransientTrack& transientTrack,
231  double dR,
232  const GlobalPoint& eventVertexPosition) {
233  double hcalEnergySum = 0.;
234  for (HBHERecHitCollection::const_iterator hcalRecHit = hcalRecHits.begin(); hcalRecHit != hcalRecHits.end();
235  ++hcalRecHit) {
236  const GlobalPoint cellPosition = hcGeometry->getPosition(hcalRecHit->detid());
237 
238  //--- CV: speed up computation by requiring eta-phi distance
239  // between cell position and track direction to be dR < 0.5
240  Vector3DBase<float, GlobalTag> cellPositionRelVertex = (cellPosition)-eventVertexPosition;
241  if (deltaR(cellPositionRelVertex.eta(),
242  cellPositionRelVertex.phi(),
243  transientTrack.track().eta(),
244  transientTrack.track().phi()) > 0.5)
245  continue;
246 
247  TrajectoryStateClosestToPoint dcaPosition = transientTrack.trajectoryStateClosestToPoint(cellPosition);
248 
249  Vector3DBase<float, GlobalTag> d = ((cellPosition)-dcaPosition.position());
250 
251  TVector3 d3(d.x(), d.y(), d.z());
252  TVector3 dir(transientTrack.track().px(), transientTrack.track().py(), transientTrack.track().pz());
253 
254  double dPerp = d3.Cross(dir.Unit()).Mag();
255  double dParl = TVector3(cellPosition.x(), cellPosition.y(), cellPosition.z()).Dot(dir.Unit());
256 
257  if (dPerp < dR && dParl > 100.) {
258  hcalEnergySum += hcalRecHit->energy();
259  }
260  }
261 
262  return hcalEnergySum;
263  }
264 
265  template <class TauType, class TauDiscriminator>
266  double TauDiscriminationAgainstCaloMuon<TauType, TauDiscriminator>::discriminate(const TauRef& tau) const {
267  if (!(trackBuilder_ && caloGeometry_))
268  return 0.;
269 
270  const CaloSubdetectorGeometry* ebGeometry = caloGeometry_->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
271  const CaloSubdetectorGeometry* eeGeometry = caloGeometry_->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
272  const HcalGeometry* hcGeometry =
273  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 =
291  compHcalEnergySum(*hbheRecHits_, hcGeometry, transientTrack, drHcal_, eventVertexPosition_);
292 
293  double caloEnergySum = ecalEnergySum + hbheEnergySum;
294 
295  if (ecalEnergySum < maxEnEcal_ && hbheEnergySum < maxEnHcal_ &&
296  caloEnergySum < (maxEnToTrackRatio_ * leadTrackPt))
297  return 0.;
298  }
299  }
300 
301  return 1.;
302  }
303 
304 } // namespace
305 
307 
308 typedef TauDiscriminationAgainstCaloMuon<PFTau, PFTauDiscriminator> PFRecoTauDiscriminationAgainstCaloMuon;
309 
310 // accordingly method for specific class
311 template <>
313  edm::ConfigurationDescriptions& descriptions) {
314  // pfRecoTauDiscriminationAgainstCaloMuon
316  desc.add<edm::InputTag>("srcHcalRecHits", edm::InputTag("hbhereco"));
317  desc.add<double>("minLeadTrackPt", 15.0);
318  desc.add<double>("maxEnToTrackRatio", 0.25);
319  desc.add<edm::InputTag>("srcVertex", edm::InputTag("offlinePrimaryVertices"));
320  desc.add<edm::InputTag>("PFTauProducer", edm::InputTag("pfRecoTauProducer"));
321  desc.add<edm::InputTag>("srcEcalRecHitsBarrel", edm::InputTag("ecalRecHit", "EcalRecHitsEB"));
322  desc.add<double>("dRhcal", 25.0);
323  {
325  psd0.add<std::string>("BooleanOperator", "and");
326  {
328  psd1.add<double>("cut");
329  psd1.add<edm::InputTag>("Producer");
330  psd0.addOptional<edm::ParameterSetDescription>("leadTrack", psd1);
331  }
332  desc.add<edm::ParameterSetDescription>("Prediscriminants", psd0);
333  }
334  desc.add<double>("maxEnHcal", 8.0);
335  desc.add<double>("dRecal", 15.0);
336  desc.add<edm::InputTag>("srcEcalRecHitsEndcap", edm::InputTag("ecalRecHit", "EcalRecHitsEE"));
337  desc.add<double>("minLeadTrackPtFraction", 0.8);
338  desc.add<double>("maxEnEcal", 3.0);
339  descriptions.add("pfRecoTauDiscriminationAgainstCaloMuon", desc);
340 }
341 
const Track & track() const
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
double z() const
z coordinate
Definition: Vertex.h:133
T z() const
Definition: PV3DBase.h:61
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:640
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< EcalRecHit >::const_iterator const_iterator
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:643
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
std::vector< Tau > TauCollection
Definition: Tau.h:35
Log< level::Error, false > LogError
bool isTransient() const
Checks if this ref is transient (i.e. not persistable).
Definition: Ref.h:263
TrajectoryStateClosestToPoint trajectoryStateClosestToPoint(const GlobalPoint &point) const
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
TauDiscriminationAgainstCaloMuon< PFTau, PFTauDiscriminator > PFRecoTauDiscriminationAgainstCaloMuon
bool isAvailable() const
Definition: Ref.h:537
edm::Ref< TauBxCollection > TauRef
Definition: Tau.h:12
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:649
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool getData(T &iHolder) const
Definition: EventSetup.h:122
const_iterator begin() const
double x() const
x coordinate
Definition: Vertex.h:129
ParameterDescriptionBase * add(U const &iLabel, T const &value)
d
Definition: ztail.py:151
double y() const
y coordinate
Definition: Vertex.h:131
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.
const_iterator end() const
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:652
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:646
void add(std::string const &label, ParameterSetDescription const &psetDescription)
fixed size matrix
HLT enums.
GlobalPoint getPosition(const DetId &id) const
long double T
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:501