CMS 3D CMS Logo

L2TauPixelIsoTagProducer.cc
Go to the documentation of this file.
1 //
2 // Original Author: Vadim Khotilovich
3 // Created: 2012-03-07
4 //
5 
7 
11 //#include "FWCore/MessageLogger/interface/MessageLogger.h"
12 
15 
16 
18  m_jetSrc_token( consumes<edm::View<reco::Jet> >(conf.getParameter<edm::InputTag>("JetSrc") ) ),
19  m_vertexSrc_token( consumes<reco::VertexCollection>(conf.getParameter<edm::InputTag>("VertexSrc") ) ),
20  m_trackSrc_token( consumes<reco::TrackCollection>(conf.getParameter<edm::InputTag>("TrackSrc") ) ), // for future use (now tracks are taken directly from PV)
21  m_beamSpotSrc_token( consumes<reco::BeamSpot>(conf.getParameter<edm::InputTag>("BeamSpotSrc") ) ),
22  m_maxNumberPV( conf.getParameter<int>("MaxNumberPV") ), // for future use, now is assumed to be = 1
23  m_trackMinPt( conf.getParameter<double>("TrackMinPt") ),
24  m_trackMaxDxy( conf.getParameter<double>("TrackMaxDxy") ),
25  m_trackMaxNChi2( conf.getParameter<double>("TrackMaxNChi2") ),
26  m_trackMinNHits( conf.getParameter<int>("TrackMinNHits") ),
27  m_trackPVMaxDZ( conf.getParameter<double>("TrackPVMaxDZ") ), // for future use with tracks not from PV
28  m_isoCone2Min( std::pow(conf.getParameter<double>("IsoConeMin"), 2) ),
29  m_isoCone2Max( std::pow(conf.getParameter<double>("IsoConeMax"), 2) )
30 {
31  produces<reco::JetTagCollection>();
32 }
33 
34 
36 {
37  using namespace reco;
38  using namespace std;
39  using namespace edm;
40  //m_trackSrc.encode();
41 
44 
45 
46  // Get jets
47  Handle< View<Jet> > jets_h;
48  ev.getByToken (m_jetSrc_token, jets_h);
49  vector<RefToBase<Jet> > jets;
50  jets.reserve (jets_h->size());
51  for (size_t i = 0; i < jets_h->size(); ++i) jets.push_back( jets_h->refAt(i) );
52 
53 
54  // define the product to store
55  unique_ptr<JetTagCollection> jetTagCollection;
56  if (jets.empty())
57  {
58  jetTagCollection.reset( new JetTagCollection() );
59  }
60  else
61  {
62  jetTagCollection.reset( new JetTagCollection( RefToBaseProd<Jet>( jets_h ) ) );
63  }
64  // by default, initialize all the jets as isolated:
65  for (const auto &jet : jets) (*jetTagCollection)[jet] = 0.f;
66 
67 
68  // Get pixel vertices (their x,y positions are already supposed to be defined from the BeamSpot)
70  ev.getByToken(m_vertexSrc_token, vertices);
71 
72  // find the primary vertex (the 1st valid non-fake vertex in the collection)
73  const Vertex *pv = nullptr;
74  for(const auto & v : *(vertices.product()) )
75  {
76  if(!v.isValid() || v.isFake()) continue;
77  pv = &v;
78  break;
79  }
80 
81  // If primary vertex exists, calculate jets' isolation:
82  if(pv && !jets.empty())
83  {
84  for (const auto & jet : jets)
85  {
86  // re-calculate jet eta in PV:
87  float jet_eta = Jet::physicsEta(pv->z(), jet->eta());
88  float jet_phi = jet->phi();
89 
90  // to calculate isolation, use only tracks that were assigned to the vertex
91  float iso = 0.f;
92  for(vector<TrackBaseRef>::const_iterator tr = pv->tracks_begin(); tr != pv->tracks_end(); ++tr)
93  {
94  if ((*tr)->pt() < m_trackMinPt) continue;
95  if ((*tr)->numberOfValidHits() < m_trackMinNHits) continue;
96  if ((*tr)->normalizedChi2() > m_trackMaxNChi2) continue;
97  if (std::abs( (*tr)->dxy(*bs) ) > m_trackMaxDxy) continue;
98 
99  float dr2 = deltaR2 (jet_eta, jet_phi, (*tr)->eta(), (*tr)->phi());
100 
101  // sum pT based isolation
102  if (dr2 >= m_isoCone2Min && dr2 <= m_isoCone2Max) iso += (*tr)->pt();
103  }
104 
105  (*jetTagCollection)[jet] = iso;
106  }
107  }
108 
109  ev.put(std::move(jetTagCollection));
110 }
111 
113 {
115  desc.add<edm::InputTag>("JetSrc",edm::InputTag("hltL2DiTauCaloJets"))->setComment("Jet source collection");
116  desc.add<edm::InputTag>("BeamSpotSrc",edm::InputTag("hltOnlineBeamSpot"));
117  desc.add<edm::InputTag>("VertexSrc",edm::InputTag("hltPixelVertices"))->setComment("Collection of vertices where isolation tracks come from");
118  desc.add<int>("MaxNumberPV",1)->setComment("No. of considered vertices (not used yet)");
119  desc.add<double>("IsoConeMax",0.4)->setComment("Outer radius of isolation annulus");
120  desc.add<double>("IsoConeMin",0.2)->setComment("Inner radius of isolation annulus");
121  desc.add<double>("TrackMinPt",1.6)->setComment("Isolation track quality: min. pT");
122  desc.add<int>("TrackMinNHits",3)->setComment("Isolation track quality: min. no. of hits");
123  desc.add<double>("TrackMaxNChi2",100.0)->setComment("Isolation track quality: max. chi2/ndof");
124  desc.add<double>("TrackPVMaxDZ",0.1)->setComment("Isolation track quality: max. dz");;
125  desc.add<double>("TrackMaxDxy",0.2)->setComment("Isolation track quality: max. dxy");;
126  desc.add<edm::InputTag>("TrackSrc",edm::InputTag(""))->setComment("Not used yet");
127  descriptions.setComment("Produces isolation tag for caloJets/L2Taus");
128  descriptions.add("L2TauPixelIsoTagProducer",desc);
129 
130 }
void setComment(std::string const &value)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
trackRef_iterator tracks_end() const
last iterator over tracks
Definition: Vertex.cc:81
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
const edm::EDGetTokenT< edm::View< reco::Jet > > m_jetSrc_token
const edm::EDGetTokenT< reco::VertexCollection > m_vertexSrc_token
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:15
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
bool ev
const edm::EDGetTokenT< reco::BeamSpot > m_beamSpotSrc_token
JetFloatAssociation::Container JetTagCollection
Definition: JetTag.h:18
Definition: Jet.py:1
vector< PseudoJet > jets
def pv(vc)
Definition: MetAnalyzer.py:7
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double z() const
z coordinate
Definition: Vertex.h:115
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void setComment(std::string const &value)
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
T const * product() const
Definition: Handle.h:74
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
fixed size matrix
HLT enums.
trackRef_iterator tracks_begin() const
first iterator over tracks
Definition: Vertex.cc:76
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
def move(src, dest)
Definition: eostools.py:511
L2TauPixelIsoTagProducer(const edm::ParameterSet &)