CMS 3D CMS Logo

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 
22 // system include files
23 #include <memory>
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 ---------------------------
74 
75  double m_MinTrackPt;
76  double m_MaxTrackChi2;
78 
79  bool m_fwjets;
82 
85 };
86 
87 
88 //
89 // constructors and destructor
90 //
92 {
93  //InputTag
94  m_tracks = iConfig.getParameter<edm::InputTag>("tracks");
95  tracksToken = consumes<std::vector<reco::Track> >(m_tracks);
96  m_jets = iConfig.getParameter<edm::InputTag>("jets");
97  jetsToken = consumes<edm::View<reco::CaloJet> >(m_jets);
98  generaljetsToken = consumes<edm::View<reco::Jet> >(m_jets);
99  m_primaryVertex = iConfig.getParameter<edm::InputTag>("primaryVertex");
100  primaryVertexToken = consumes<reco::VertexCollection>(m_primaryVertex);
101 
102  //Tracks Selection
103  m_MinTrackPt = iConfig.getParameter<double>("MinTrackPt");
104  m_MaxTrackDistanceToJet = iConfig.getParameter<double>("MaxTrackDistanceToJet");
105  m_MaxTrackChi2 = iConfig.getParameter<double>("MaxTrackChi2");
106 
107  //A jet is defined as a signal jet if Sum(trackPt) > minPt or Sum(comp.trackPt)/CaloJetPt > minPtRatio
108  m_MinGoodJetTrackPt = iConfig.getParameter<double>("MinGoodJetTrackPt");
109  m_MinGoodJetTrackPtRatio = iConfig.getParameter<double>("MinGoodJetTrackPtRatio");
110 
111  m_fwjets = iConfig.getParameter<bool>("UseForwardJetsAsNoPU");
112  m_mineta_fwjets = iConfig.getParameter<double>("MinEtaForwardJets");
113  m_minet_fwjets = iConfig.getParameter<double>("MinEtForwardJets");
114 
115  produces<std::vector<reco::CaloJet> >();
116  produces<std::vector<reco::CaloJet> >("PUjets");
117  produces<reco::JetTagCollection>();
118 }
119 
120 
121 PixelJetPuId::~PixelJetPuId() = default;
122 
123 
124 void
127  desc.add<edm::InputTag> ("jets",edm::InputTag("hltCaloJetL1FastJetCorrected"));
128  desc.add<edm::InputTag> ("tracks",edm::InputTag("hltPixelTracksNoPU"));
129  desc.add<edm::InputTag> ("primaryVertex",edm::InputTag("hltFastPVPixelVertices"));
130  desc.add<double>("MinGoodJetTrackPtRatio",0.045);
131  desc.add<double>("MinGoodJetTrackPt",1.8);
132  desc.add<double>("MaxTrackDistanceToJet",0.04);
133  desc.add<double>("MinTrackPt",0.6);
134  desc.add<double>("MaxTrackChi2",20.);
135  desc.add<bool>("UseForwardJetsAsNoPU",true);
136  desc.add<double>("MinEtaForwardJets",2.4);
137  desc.add<double>("MinEtForwardJets",40.);
138  descriptions.add("pixelJetPuId",desc);
139 }
140 
141 //
142 // member functions
143 //
144 
145 // ------------ method called on each new Event ------------
147 {
148  using namespace edm;
149  std::unique_ptr<std::vector<reco::CaloJet> > pOut(new std::vector<reco::CaloJet> );
150  std::unique_ptr<std::vector<reco::CaloJet> > pOut_PUjets(new std::vector<reco::CaloJet> );
151  std::unique_ptr<reco::JetTagCollection > pOut_jetTagCollection(new reco::JetTagCollection );
152 
153  //get tracks
155  iEvent.getByToken(tracksToken, tracks);
156  unsigned int tsize = tracks->size();
157  float teta[tsize], tphi[tsize];
158  unsigned int i=0;
159  for (auto const & tr : *tracks) { teta[i]=tr.eta(); tphi[i]=tr.phi();++i;}
160 
161  //get jets
163  iEvent.getByToken(jetsToken, jets);
164 
165  Handle<edm::View<reco::Jet> > generaljets;
166  iEvent.getByToken(generaljetsToken, generaljets);
167 
168  //get primary vertices
170  iEvent.getByToken(primaryVertexToken, primaryVertex);
171 
172  //get Transient Track Builder
174  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
175 
176  //init JetTagCollection
177  if(!generaljets.product()->empty())
178  {
180  pOut_jetTagCollection.reset(new reco::JetTagCollection(edm::makeRefToBaseProdFrom(jj, iEvent)));
181  }
182 
183  //loop on trackIPTagInfos
184  if(!primaryVertex->empty())
185  {
186  const reco::Vertex* pv = &*primaryVertex->begin();
187  //loop on jets
188  for(edm::View<reco::CaloJet>::const_iterator itJet = jets->begin(); itJet != jets->end(); itJet++ ) {
189 
190  math::XYZVector jetMomentum = itJet->momentum();
191  GlobalVector direction(jetMomentum.x(), jetMomentum.y(), jetMomentum.z());
192 
193  math::XYZVector trMomentum;
194 
195  if(fabs(itJet->eta())>m_mineta_fwjets)
196  {
197  if((m_fwjets) && (itJet->et()>m_minet_fwjets))
198  pOut->push_back(*itJet);// fill forward jet as signal jet
199  }
200  else
201  {
202  //loop on tracks
203  auto itTrack = tracks->begin();
204  for (unsigned int i=0; i<tsize; ++i) {
205  float deltaR2=reco::deltaR2(itJet->eta(),itJet->phi(), teta[i],tphi[i]);
206  if(deltaR2<0.25) {
207  reco::TransientTrack transientTrack = builder->build(*itTrack);
208  float jetTrackDistance = -((IPTools::jetTrackDistance(transientTrack, direction, *pv)).second).value();
209 
210  //select the tracks compabible with the jet
211  if(( itTrack->pt() > m_MinTrackPt) && ( itTrack->normalizedChi2() < m_MaxTrackChi2) && (jetTrackDistance<m_MaxTrackDistanceToJet))
212  {
213  trMomentum += itTrack->momentum(); //calculate the Sum(trackPt)
214  }
215  }
216  itTrack++;
217  }
218  //if Sum(comp.trackPt)/CaloJetPt > minPtRatio or Sum(trackPt) > minPt the jet is a signal jet
219  if(trMomentum.rho()/jetMomentum.rho() > m_MinGoodJetTrackPtRatio || trMomentum.rho() > m_MinGoodJetTrackPt )
220  {
221  pOut->push_back(*itJet); // fill it as signal jet
222  }
223  else//else it is a PUjet
224  {
225  pOut_PUjets->push_back(*itJet); // fill it as PUjets
226  }
227  }
228  RefToBase<reco::Jet> jRef(generaljets, itJet-jets->begin());
229  (*pOut_jetTagCollection)[jRef] = trMomentum.rho(); // fill jetTagCollection
230  }
231  }
232  iEvent.put(std::move(pOut));
233  iEvent.put(std::move(pOut_PUjets),"PUjets");
234  iEvent.put(std::move(pOut_jetTagCollection));
235 }
236 
237 // declare this class as a framework plugin
239 
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
double m_MinGoodJetTrackPt
Definition: PixelJetPuId.cc:83
edm::InputTag m_jets
Definition: PixelJetPuId.cc:69
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
double m_MaxTrackChi2
Definition: PixelJetPuId.cc:76
reco::TransientTrack build(const reco::Track *p) const
edm::EDGetTokenT< edm::View< reco::Jet > > generaljetsToken
Definition: PixelJetPuId.cc:72
edm::EDGetTokenT< edm::View< reco::CaloJet > > jetsToken
Definition: PixelJetPuId.cc:71
std::pair< double, Measurement1D > jetTrackDistance(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:200
U second(std::pair< T, U > const &p)
edm::InputTag m_primaryVertex
Definition: PixelJetPuId.cc:67
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
vector< PseudoJet > jets
def pv(vc)
Definition: MetAnalyzer.py:7
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< reco::VertexCollection > primaryVertexToken
Definition: PixelJetPuId.cc:73
ParameterDescriptionBase * add(U const &iLabel, T const &value)
double m_MaxTrackDistanceToJet
Definition: PixelJetPuId.cc:77
double m_minet_fwjets
Definition: PixelJetPuId.cc:81
double m_mineta_fwjets
Definition: PixelJetPuId.cc:80
PixelJetPuId(const edm::ParameterSet &)
Definition: PixelJetPuId.cc:91
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:70
edm::InputTag m_tracks
Definition: PixelJetPuId.cc:68
double m_MinTrackPt
Definition: PixelJetPuId.cc:75
T const * product() const
Definition: Handle.h:74
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
void add(std::string const &label, ParameterSetDescription const &psetDescription)
~PixelJetPuId() override
RefToBaseProd< T > makeRefToBaseProdFrom(RefToBase< T > const &iRef, Event const &iEvent)
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
T get() const
Definition: EventSetup.h:71
double m_MinGoodJetTrackPtRatio
Definition: PixelJetPuId.cc:84
def move(src, dest)
Definition: eostools.py:511
void produce(edm::StreamID sid, edm::Event &, const edm::EventSetup &) const override