CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PixelJetPuId.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PixelJetPuId
4 // Class: PixelJetPuId
5 //
15 //
16 // Original Author: Silvio DONATO
17 // Created: Wed Dec 18 10:05:40 CET 2013
18 //
19 //
20 
21 // system include files
22 #include <memory>
23 #include <algorithm>
24 
25 // user include files
28 
32 
37 
43 
48 
52 //
53 // class declaration
54 //
55 
57 public:
59  ~PixelJetPuId() override;
60 
61  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
62 
63 private:
64  void produce(edm::StreamID sid, edm::Event&, const edm::EventSetup&) const override;
65 
66  // ----------member data ---------------------------
68 
76 
77  double m_MinTrackPt;
80 
81  bool m_fwjets;
84 
87 };
88 
89 //
90 // constructors and destructor
91 //
93  : transientTrackRecordToken_(esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))) {
94  //InputTag
95  m_tracks = iConfig.getParameter<edm::InputTag>("tracks");
96  tracksToken = consumes<std::vector<reco::Track> >(m_tracks);
97  m_jets = iConfig.getParameter<edm::InputTag>("jets");
98  jetsToken = consumes<edm::View<reco::CaloJet> >(m_jets);
99  generaljetsToken = consumes<edm::View<reco::Jet> >(m_jets);
100  m_primaryVertex = iConfig.getParameter<edm::InputTag>("primaryVertex");
101  primaryVertexToken = consumes<reco::VertexCollection>(m_primaryVertex);
102 
103  //Tracks Selection
104  m_MinTrackPt = iConfig.getParameter<double>("MinTrackPt");
105  m_MaxTrackDistanceToJet = iConfig.getParameter<double>("MaxTrackDistanceToJet");
106  m_MaxTrackChi2 = iConfig.getParameter<double>("MaxTrackChi2");
107 
108  //A jet is defined as a signal jet if Sum(trackPt) > minPt or Sum(comp.trackPt)/CaloJetPt > minPtRatio
109  m_MinGoodJetTrackPt = iConfig.getParameter<double>("MinGoodJetTrackPt");
110  m_MinGoodJetTrackPtRatio = iConfig.getParameter<double>("MinGoodJetTrackPtRatio");
111 
112  m_fwjets = iConfig.getParameter<bool>("UseForwardJetsAsNoPU");
113  m_mineta_fwjets = iConfig.getParameter<double>("MinEtaForwardJets");
114  m_minet_fwjets = iConfig.getParameter<double>("MinEtForwardJets");
115 
116  produces<std::vector<reco::CaloJet> >();
117  produces<std::vector<reco::CaloJet> >("PUjets");
118  produces<reco::JetTagCollection>();
119 }
120 
121 PixelJetPuId::~PixelJetPuId() = default;
122 
125  desc.add<edm::InputTag>("jets", edm::InputTag("hltCaloJetL1FastJetCorrected"));
126  desc.add<edm::InputTag>("tracks", edm::InputTag("hltPixelTracksNoPU"));
127  desc.add<edm::InputTag>("primaryVertex", edm::InputTag("hltFastPVPixelVertices"));
128  desc.add<double>("MinGoodJetTrackPtRatio", 0.045);
129  desc.add<double>("MinGoodJetTrackPt", 1.8);
130  desc.add<double>("MaxTrackDistanceToJet", 0.04);
131  desc.add<double>("MinTrackPt", 0.6);
132  desc.add<double>("MaxTrackChi2", 20.);
133  desc.add<bool>("UseForwardJetsAsNoPU", true);
134  desc.add<double>("MinEtaForwardJets", 2.4);
135  desc.add<double>("MinEtForwardJets", 40.);
136  descriptions.add("pixelJetPuId", desc);
137 }
138 
139 //
140 // member functions
141 //
142 
143 // ------------ method called on each new Event ------------
145  using namespace edm;
146  std::unique_ptr<std::vector<reco::CaloJet> > pOut(new std::vector<reco::CaloJet>);
147  std::unique_ptr<std::vector<reco::CaloJet> > pOut_PUjets(new std::vector<reco::CaloJet>);
148  std::unique_ptr<reco::JetTagCollection> pOut_jetTagCollection(new reco::JetTagCollection);
149 
150  //get tracks
152  iEvent.getByToken(tracksToken, tracks);
153  uint const asize = std::max(1u, (uint)tracks->size());
154  float teta[asize], tphi[asize];
155  uint tsize = 0;
156  for (auto const& tr : *tracks) {
157  teta[tsize] = tr.eta();
158  tphi[tsize] = tr.phi();
159  ++tsize;
160  }
161 
162  //get jets
164  iEvent.getByToken(jetsToken, jets);
165 
166  Handle<edm::View<reco::Jet> > generaljets;
167  iEvent.getByToken(generaljetsToken, generaljets);
168 
169  //get primary vertices
172 
173  //get Transient Track Builder
174  auto const& builder = iSetup.getHandle(transientTrackRecordToken_);
175 
176  //init JetTagCollection
177  if (!generaljets.product()->empty()) {
179  pOut_jetTagCollection = std::make_unique<reco::JetTagCollection>(edm::makeRefToBaseProdFrom(jj, iEvent));
180  }
181 
182  //loop on trackIPTagInfos
183  if (!primaryVertex->empty()) {
184  const reco::Vertex* pv = &*primaryVertex->begin();
185  //loop on jets
186  for (edm::View<reco::CaloJet>::const_iterator itJet = jets->begin(); itJet != jets->end(); itJet++) {
187  math::XYZVector jetMomentum = itJet->momentum();
188  GlobalVector direction(jetMomentum.x(), jetMomentum.y(), jetMomentum.z());
189 
190  math::XYZVector trMomentum;
191 
192  if (fabs(itJet->eta()) > m_mineta_fwjets) {
193  if ((m_fwjets) && (itJet->et() > m_minet_fwjets))
194  pOut->push_back(*itJet); // fill forward jet as signal jet
195  } else {
196  //loop on tracks
197  auto itTrack = tracks->begin();
198  for (unsigned int i = 0; i < tsize; ++i) {
199  float deltaR2 = reco::deltaR2(itJet->eta(), itJet->phi(), teta[i], tphi[i]);
200  if (deltaR2 < 0.25) {
201  reco::TransientTrack transientTrack = builder->build(*itTrack);
202  float jetTrackDistance = -((IPTools::jetTrackDistance(transientTrack, direction, *pv)).second).value();
203 
204  //select the tracks compabible with the jet
205  if ((itTrack->pt() > m_MinTrackPt) && (itTrack->normalizedChi2() < m_MaxTrackChi2) &&
206  (jetTrackDistance < m_MaxTrackDistanceToJet)) {
207  trMomentum += itTrack->momentum(); //calculate the Sum(trackPt)
208  }
209  }
210  itTrack++;
211  }
212  //if Sum(comp.trackPt)/CaloJetPt > minPtRatio or Sum(trackPt) > minPt the jet is a signal jet
213  if (trMomentum.rho() / jetMomentum.rho() > m_MinGoodJetTrackPtRatio || trMomentum.rho() > m_MinGoodJetTrackPt) {
214  pOut->push_back(*itJet); // fill it as signal jet
215  } else //else it is a PUjet
216  {
217  pOut_PUjets->push_back(*itJet); // fill it as PUjets
218  }
219  }
220  RefToBase<reco::Jet> jRef(generaljets, itJet - jets->begin());
221  (*pOut_jetTagCollection)[jRef] = trMomentum.rho(); // fill jetTagCollection
222  }
223  }
224  iEvent.put(std::move(pOut));
225  iEvent.put(std::move(pOut_PUjets), "PUjets");
226  iEvent.put(std::move(pOut_jetTagCollection));
227 }
228 
229 // declare this class as a framework plugin
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
double m_MinGoodJetTrackPt
Definition: PixelJetPuId.cc:85
edm::InputTag m_jets
Definition: PixelJetPuId.cc:71
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
void produce(edm::StreamID sid, edm::Event &, const edm::EventSetup &) const override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
double m_MaxTrackChi2
Definition: PixelJetPuId.cc:78
auto const & tracks
cannot be loose
edm::EDGetTokenT< edm::View< reco::Jet > > generaljetsToken
Definition: PixelJetPuId.cc:74
edm::EDGetTokenT< edm::View< reco::CaloJet > > jetsToken
Definition: PixelJetPuId.cc:73
std::pair< double, Measurement1D > jetTrackDistance(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:206
U second(std::pair< T, U > const &p)
edm::InputTag m_primaryVertex
Definition: PixelJetPuId.cc:69
int iEvent
Definition: GenABIO.cc:224
vector< PseudoJet > jets
def move
Definition: eostools.py:511
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< reco::VertexCollection > primaryVertexToken
Definition: PixelJetPuId.cc:75
ParameterDescriptionBase * add(U const &iLabel, T const &value)
double m_MaxTrackDistanceToJet
Definition: PixelJetPuId.cc:79
double m_minet_fwjets
Definition: PixelJetPuId.cc:83
double m_mineta_fwjets
Definition: PixelJetPuId.cc:82
PixelJetPuId(const edm::ParameterSet &)
Definition: PixelJetPuId.cc:92
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
edm::EDGetTokenT< std::vector< reco::Track > > tracksToken
Definition: PixelJetPuId.cc:72
edm::InputTag m_tracks
Definition: PixelJetPuId.cc:70
double m_MinTrackPt
Definition: PixelJetPuId.cc:77
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void add(std::string const &label, ParameterSetDescription const &psetDescription)
~PixelJetPuId() override
RefToBaseProd< T > makeRefToBaseProdFrom(RefToBase< T > const &iRef, Event const &iEvent)
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
double m_MinGoodJetTrackPtRatio
Definition: PixelJetPuId.cc:86
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > const transientTrackRecordToken_
Definition: PixelJetPuId.cc:67
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283