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 {
57  public:
58  reco::TrackRef getLeadTrack(const T& tau) const
59  {
60  return tau.leadTrack();
61  }
62  double getTrackPtSum(const T& tau) const
63  {
64  double trackPtSum = 0.;
65  for ( TrackRefVector::const_iterator signalTrack = tau.signalTracks().begin();
66  signalTrack != tau.signalTracks().end(); ++signalTrack ) {
67  trackPtSum += (*signalTrack)->pt();
68  }
69  return trackPtSum;
70  }
71 };
72 
73 // define acess to lead. track for PFTaus
74 template <>
75 class TauLeadTrackExtractor<reco::PFTau>
76 {
77  public:
78  reco::TrackRef getLeadTrack(const reco::PFTau& tau) const
79  {
80  return tau.leadPFChargedHadrCand()->trackRef();
81  }
82  double getTrackPtSum(const reco::PFTau& tau) const
83  {
84  double trackPtSum = 0.;
85  for ( std::vector<CandidatePtr>::const_iterator signalTrack = tau.signalChargedHadrCands().begin();
86  signalTrack != tau.signalChargedHadrCands().end(); ++signalTrack ) {
87  trackPtSum += (*signalTrack)->pt();
88  }
89  return trackPtSum;
90  }
91 };
92 
93 template<class TauType, class TauDiscriminator>
94 class TauDiscriminationAgainstCaloMuon final : public TauDiscriminationProducerBase<TauType, TauDiscriminator>
95 {
96  public:
97  // setup framework types for this tautype
98  typedef std::vector<TauType> TauCollection;
100 
101  explicit TauDiscriminationAgainstCaloMuon(const edm::ParameterSet&);
102  ~TauDiscriminationAgainstCaloMuon() override {}
103 
104  // called at the beginning of every event
105  void beginEvent(const edm::Event&, const edm::EventSetup&) override;
106 
107  double discriminate(const TauRef&) const override;
108 
109  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
110 
111  private:
112  edm::InputTag srcEcalRecHitsBarrel_;
114  edm::InputTag srcEcalRecHitsEndcap_;
116  edm::InputTag srcHcalRecHits_;
118 
119  edm::InputTag srcVertex_;
120  GlobalPoint eventVertexPosition_;
121 
122  const TransientTrackBuilder* trackBuilder_;
123  const CaloGeometry* caloGeometry_;
124 
125  TauLeadTrackExtractor<TauType> leadTrackExtractor_;
126 
127  double minLeadTrackPt_;
128  double minLeadTrackPtFraction_;
129 
130  double drEcal_;
131  double drHcal_;
132 
133  double maxEnEcal_;
134  double maxEnHcal_;
135 
136  double maxEnToTrackRatio_;
137 };
138 
139 template<class TauType, class TauDiscriminator>
140 TauDiscriminationAgainstCaloMuon<TauType, TauDiscriminator>::TauDiscriminationAgainstCaloMuon(const edm::ParameterSet& cfg)
141  : TauDiscriminationProducerBase<TauType, TauDiscriminator>(cfg)
142 {
143  srcEcalRecHitsBarrel_ = cfg.getParameter<edm::InputTag>("srcEcalRecHitsBarrel");
144  srcEcalRecHitsEndcap_ = cfg.getParameter<edm::InputTag>("srcEcalRecHitsEndcap");
145  srcHcalRecHits_ = cfg.getParameter<edm::InputTag>("srcHcalRecHits");
146 
147  srcVertex_ = cfg.getParameter<edm::InputTag>("srcVertex");
148 
149  minLeadTrackPt_ = cfg.getParameter<double>("minLeadTrackPt");
150  minLeadTrackPtFraction_ = cfg.getParameter<double>("minLeadTrackPtFraction");
151 
152  drEcal_ = cfg.getParameter<double>("dRecal");
153  drHcal_ = cfg.getParameter<double>("dRhcal");
154 
155  maxEnEcal_ = cfg.getParameter<double>("maxEnEcal");
156  maxEnHcal_ = cfg.getParameter<double>("maxEnHcal");
157 
158  maxEnToTrackRatio_ = cfg.getParameter<double>("maxEnToTrackRatio");
159 }
160 
161 template<class TauType, class TauDiscriminator>
162 void TauDiscriminationAgainstCaloMuon<TauType, TauDiscriminator>::beginEvent(const edm::Event& evt, const edm::EventSetup& evtSetup)
163 {
164  evt.getByLabel(srcEcalRecHitsBarrel_, ebRecHits_);
165  evt.getByLabel(srcEcalRecHitsEndcap_, eeRecHits_);
166  evt.getByLabel(srcHcalRecHits_, hbheRecHits_);
167 
168  edm::ESHandle<TransientTrackBuilder> trackBuilderHandle;
169  evtSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", trackBuilderHandle);
170  trackBuilder_ = trackBuilderHandle.product();
171  if ( !trackBuilder_ ) {
172  edm::LogError ("TauDiscriminationAgainstCaloMuon::discriminate")
173  << " Failed to access TransientTrackBuilder !!";
174  }
175 
176  edm::ESHandle<CaloGeometry> caloGeometryHandle;
177  evtSetup.get<CaloGeometryRecord>().get(caloGeometryHandle);
178  caloGeometry_ = caloGeometryHandle.product();
179  if ( !caloGeometry_ ) {
180  edm::LogError ("TauDiscriminationAgainstCaloMuon::discriminate")
181  << " Failed to access CaloGeometry !!";
182  }
183 
185  evt.getByLabel(srcVertex_, vertices);
186  eventVertexPosition_ = GlobalPoint(0., 0., 0.);
187  if (!vertices->empty()) {
188  const reco::Vertex& thePrimaryEventVertex = (*vertices->begin());
189  eventVertexPosition_ = GlobalPoint(thePrimaryEventVertex.x(), thePrimaryEventVertex.y(), thePrimaryEventVertex.z());
190  }
191 }
192 
193 double compEcalEnergySum(const EcalRecHitCollection& ecalRecHits,
194  const CaloSubdetectorGeometry* detGeometry,
195  const reco::TransientTrack& transientTrack, double dR,
196  const GlobalPoint& eventVertexPosition)
197 {
198  double ecalEnergySum = 0.;
200  ecalRecHit != ecalRecHits.end(); ++ecalRecHit ) {
201  auto cellGeometry = detGeometry->getGeometry(ecalRecHit->detid());
202 
203  if ( !cellGeometry ) {
204  edm::LogError ("compEcalEnergySum")
205  << " Failed to access ECAL geometry for detId = " << ecalRecHit->detid().rawId()
206  << " --> skipping !!";
207  continue;
208  }
209 
210  const GlobalPoint& cellPosition = cellGeometry->getPosition();
211 
212 //--- CV: speed up computation by requiring eta-phi distance
213 // between cell position and track direction to be dR < 0.5
214  Vector3DBase<float, GlobalTag> cellPositionRelVertex = (cellPosition) - eventVertexPosition;
215  if ( deltaR(cellPositionRelVertex.eta(), cellPositionRelVertex.phi(),
216  transientTrack.track().eta(), transientTrack.track().phi()) > 0.5 ) continue;
217 
218  TrajectoryStateClosestToPoint dcaPosition = transientTrack.trajectoryStateClosestToPoint(cellPosition);
219 
220  Vector3DBase<float, GlobalTag> d = (cellPosition - dcaPosition.position());
221 
222  TVector3 d3(d.x(), d.y(), d.z());
223  TVector3 dir(transientTrack.track().px(), transientTrack.track().py(), transientTrack.track().pz());
224 
225  double dPerp = d3.Cross(dir.Unit()).Mag();
226  double dParl = TVector3(cellPosition.x(), cellPosition.y(), cellPosition.z()).Dot(dir.Unit());
227 
228  if ( dPerp < dR && dParl > 100. ) {
229  ecalEnergySum += ecalRecHit->energy();
230  }
231  }
232 
233  return ecalEnergySum;
234 }
235 
236 double compHcalEnergySum(const HBHERecHitCollection& hcalRecHits,
237  const HcalGeometry* hcGeometry,
238  const reco::TransientTrack& transientTrack, double dR,
239  const GlobalPoint& eventVertexPosition)
240 {
241  double hcalEnergySum = 0.;
242  for ( HBHERecHitCollection::const_iterator hcalRecHit = hcalRecHits.begin();
243  hcalRecHit != hcalRecHits.end(); ++hcalRecHit ) {
244 
245  const GlobalPoint cellPosition = hcGeometry->getPosition(hcalRecHit->detid());
246 
247 //--- CV: speed up computation by requiring eta-phi distance
248 // between cell position and track direction to be dR < 0.5
249  Vector3DBase<float, GlobalTag> cellPositionRelVertex = (cellPosition) - eventVertexPosition;
250  if ( deltaR(cellPositionRelVertex.eta(), cellPositionRelVertex.phi(),
251  transientTrack.track().eta(), transientTrack.track().phi()) > 0.5 ) continue;
252 
253  TrajectoryStateClosestToPoint dcaPosition = transientTrack.trajectoryStateClosestToPoint(cellPosition);
254 
255  Vector3DBase<float, GlobalTag> d = ((cellPosition) - dcaPosition.position());
256 
257  TVector3 d3(d.x(), d.y(), d.z());
258  TVector3 dir(transientTrack.track().px(), transientTrack.track().py(), transientTrack.track().pz());
259 
260  double dPerp = d3.Cross(dir.Unit()).Mag();
261  double dParl = TVector3(cellPosition.x(), cellPosition.y(), cellPosition.z()).Dot(dir.Unit());
262 
263  if ( dPerp < dR && dParl > 100. ) {
264  hcalEnergySum += hcalRecHit->energy();
265  }
266  }
267 
268  return hcalEnergySum;
269 }
270 
271 template<class TauType, class TauDiscriminator>
272 double TauDiscriminationAgainstCaloMuon<TauType, TauDiscriminator>::discriminate(const TauRef& tau) const
273 {
274  if ( !(trackBuilder_ && caloGeometry_) ) return 0.;
275 
276  const CaloSubdetectorGeometry* ebGeometry = caloGeometry_->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
277  const CaloSubdetectorGeometry* eeGeometry = caloGeometry_->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
278  const HcalGeometry* hcGeometry = static_cast<const HcalGeometry*>(caloGeometry_->getSubdetectorGeometry(DetId::Hcal, HcalBarrel));
279 
280  TrackRef leadTrackRef = leadTrackExtractor_.getLeadTrack(*tau);
281 
282  if ( (leadTrackRef.isAvailable() || leadTrackRef.isTransient()) && leadTrackRef.isNonnull() ) {
283  double leadTrackPt = leadTrackRef->pt();
284  double trackPtSum = leadTrackExtractor_.getTrackPtSum(*tau);
285 
286  double leadTrackPtFraction = ( trackPtSum > 0. ) ? (leadTrackPt/trackPtSum) : -1.;
287 
288  if ( leadTrackPt > minLeadTrackPt_ && leadTrackPtFraction > minLeadTrackPtFraction_ ) {
289  reco::TransientTrack transientTrack = trackBuilder_->build(leadTrackRef);
290 
291  double ebEnergySum = compEcalEnergySum(*ebRecHits_, ebGeometry, transientTrack, drEcal_, eventVertexPosition_);
292  double eeEnergySum = compEcalEnergySum(*eeRecHits_, eeGeometry, transientTrack, drEcal_, eventVertexPosition_);
293  double ecalEnergySum = ebEnergySum + eeEnergySum;
294 
295  double hbheEnergySum = compHcalEnergySum(*hbheRecHits_, hcGeometry, transientTrack, drHcal_, eventVertexPosition_);
296 
297  double caloEnergySum = ecalEnergySum + hbheEnergySum;
298 
299  if ( ecalEnergySum < maxEnEcal_ &&
300  hbheEnergySum < maxEnHcal_ &&
301  caloEnergySum < (maxEnToTrackRatio_*leadTrackPt) ) return 0.;
302  }
303  }
304 
305  return 1.;
306 }
307 
308 }
309 
311 
312 typedef TauDiscriminationAgainstCaloMuon<PFTau, PFTauDiscriminator> PFRecoTauDiscriminationAgainstCaloMuon;
313 typedef TauDiscriminationAgainstCaloMuon<CaloTau, CaloTauDiscriminator> CaloRecoTauDiscriminationAgainstCaloMuon;
314 
315 // accordingly method for specific class
316 template<>
317 void
319  // pfRecoTauDiscriminationAgainstCaloMuon
321  desc.add<edm::InputTag>("srcHcalRecHits", edm::InputTag("hbhereco"));
322  desc.add<double>("minLeadTrackPt", 15.0);
323  desc.add<double>("maxEnToTrackRatio", 0.25);
324  desc.add<edm::InputTag>("srcVertex", edm::InputTag("offlinePrimaryVertices"));
325  desc.add<edm::InputTag>("PFTauProducer", edm::InputTag("pfRecoTauProducer"));
326  desc.add<edm::InputTag>("srcEcalRecHitsBarrel", edm::InputTag("ecalRecHit","EcalRecHitsEB"));
327  desc.add<double>("dRhcal", 25.0);
328  {
330  psd0.add<std::string>("BooleanOperator", "and");
331  {
333  psd1.add<double>("cut");
334  psd1.add<edm::InputTag>("Producer");
335  psd0.addOptional<edm::ParameterSetDescription>("leadTrack", psd1);
336  }
337  desc.add<edm::ParameterSetDescription>("Prediscriminants", psd0);
338  }
339  desc.add<double>("maxEnHcal", 8.0);
340  desc.add<double>("dRecal", 15.0);
341  desc.add<edm::InputTag>("srcEcalRecHitsEndcap", edm::InputTag("ecalRecHit","EcalRecHitsEE"));
342  desc.add<double>("minLeadTrackPtFraction", 0.8);
343  desc.add<double>("maxEnEcal", 3.0);
344  descriptions.add("pfRecoTauDiscriminationAgainstCaloMuon", desc);
345 }
346 
347 template<>
348 void
350  // there was no cfi file for this plugin
351 }
352 
353 DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstCaloMuon);
354 DEFINE_FWK_MODULE(CaloRecoTauDiscriminationAgainstCaloMuon);
bool isAvailable() const
Definition: Ref.h:575
T getParameter(std::string const &) const
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
edm::Ref< TauBxCollection > TauRef
Definition: Tau.h:13
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:276
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< EcalRecHit >::const_iterator const_iterator
std::vector< Tau > TauCollection
Definition: Tau.h:37
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:684
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:666
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:442
TauDiscriminationAgainstCaloMuon< PFTau, PFTauDiscriminator > PFRecoTauDiscriminationAgainstCaloMuon
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:690
double z() const
z coordinate
Definition: Vertex.h:115
const edm::EventSetup * evtSetup() const
ParameterDescriptionBase * add(U const &iLabel, T const &value)
TauDiscriminationAgainstCaloMuon< CaloTau, CaloTauDiscriminator > CaloRecoTauDiscriminationAgainstCaloMuon
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
GlobalPoint getPosition(const DetId &id) const
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:678
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
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const std::vector< reco::CandidatePtr > & signalChargedHadrCands() const
Charged hadrons in signal region.
Definition: PFTau.cc:80
fixed size matrix
T get() const
Definition: EventSetup.h:71
const PFCandidatePtr leadPFChargedHadrCand() const
Getters for different PFCandidates for PFTaus made from PFCandidates.
Definition: PFTau.cc:154
dbl *** dir
Definition: mlp_gen.cc:35
long double T
T const * product() const
Definition: ESHandle.h:86
const_iterator begin() const
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:672