CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
22 // system include files
23 #include <memory>
24 
25 // user include files
28 
31 
36 
42 
47 
49 
50 //
51 // class declaration
52 //
53 
55  public:
57  virtual ~PixelJetPuId();
58 
59  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
60 
61  private:
62  virtual void produce(edm::StreamID sid, edm::Event&, const edm::EventSetup&) const override;
63 
64 
65  // ----------member data ---------------------------
72 
73  double m_MinTrackPt;
74  double m_MaxTrackChi2;
76 
77  bool m_fwjets;
80 
83 };
84 
85 
86 //
87 // constructors and destructor
88 //
90 {
91  //InputTag
92  m_tracks = iConfig.getParameter<edm::InputTag>("tracks");
93  tracksToken = consumes<std::vector<reco::Track> >(m_tracks);
94  m_jets = iConfig.getParameter<edm::InputTag>("jets");
95  jetsToken = consumes<edm::View<reco::CaloJet> >(m_jets);
96  m_primaryVertex = iConfig.getParameter<edm::InputTag>("primaryVertex");
97  primaryVertexToken = consumes<reco::VertexCollection>(m_primaryVertex);
98 
99  //Tracks Selection
100  m_MinTrackPt = iConfig.getParameter<double>("MinTrackPt");
101  m_MaxTrackDistanceToJet = iConfig.getParameter<double>("MaxTrackDistanceToJet");
102  m_MaxTrackChi2 = iConfig.getParameter<double>("MaxTrackChi2");
103 
104  //A jet is defined as a signal jet if Sum(trackPt) > minPt or Sum(comp.trackPt)/CaloJetPt > minPtRatio
105  m_MinGoodJetTrackPt = iConfig.getParameter<double>("MinGoodJetTrackPt");
106  m_MinGoodJetTrackPtRatio = iConfig.getParameter<double>("MinGoodJetTrackPtRatio");
107 
108  m_fwjets = iConfig.getParameter<bool>("UseForwardJetsAsNoPU");
109  m_mineta_fwjets = iConfig.getParameter<double>("MinEtaForwardJets");
110  m_minet_fwjets = iConfig.getParameter<double>("MinEtForwardJets");
111 
112  produces<std::vector<reco::CaloJet> >();
113  produces<std::vector<reco::CaloJet> >("PUjets");
114 }
115 
116 
118 
119 
120 void
123  desc.add<edm::InputTag> ("jets",edm::InputTag("hltCaloJetL1FastJetCorrected"));
124  desc.add<edm::InputTag> ("tracks",edm::InputTag("hltPixelTracksNoPU"));
125  desc.add<edm::InputTag> ("primaryVertex",edm::InputTag("hltFastPVPixelVertices"));
126  desc.add<double>("MinGoodJetTrackPtRatio",0.045);
127  desc.add<double>("MinGoodJetTrackPt",1.8);
128  desc.add<double>("MaxTrackDistanceToJet",0.04);
129  desc.add<double>("MinTrackPt",0.6);
130  desc.add<double>("MaxTrackChi2",20.);
131  desc.add<bool>("UseForwardJetsAsNoPU",true);
132  desc.add<double>("MinEtaForwardJets",2.4);
133  desc.add<double>("MinEtForwardJets",40.);
134  descriptions.add("pixelJetPuId",desc);
135 }
136 
137 //
138 // member functions
139 //
140 
141 // ------------ method called on each new Event ------------
143 {
144  using namespace edm;
145  std::auto_ptr<std::vector<reco::CaloJet> > pOut(new std::vector<reco::CaloJet> );
146  std::auto_ptr<std::vector<reco::CaloJet> > pOut_PUjets(new std::vector<reco::CaloJet> );
147 
148  //get tracks
150  iEvent.getByToken(tracksToken, tracks);
151  unsigned int tsize = tracks->size();
152  float teta[tsize], tphi[tsize];
153  unsigned int i=0;
154  for (auto const & tr : *tracks) { teta[i]=tr.eta(); tphi[i]=tr.phi();++i;}
155 
156  //get jets
158  iEvent.getByToken(jetsToken, jets);
159 
160  //get primary vertices
163 
164  //get Transient Track Builder
166  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
167 
168  //loop on trackIPTagInfos
169  if(primaryVertex->size()>0)
170  {
171  const reco::Vertex* pv = &*primaryVertex->begin();
172  //loop on jets
173  for(edm::View<reco::CaloJet>::const_iterator itJet = jets->begin(); itJet != jets->end(); itJet++ ) {
174 
175  math::XYZVector jetMomentum = itJet->momentum();
176  GlobalVector direction(jetMomentum.x(), jetMomentum.y(), jetMomentum.z());
177 
178  math::XYZVector trMomentum;
179 
180  //loop on tracks
181  if(fabs(itJet->eta())>m_mineta_fwjets)
182  {
183  if((m_fwjets) && (itJet->et()>m_minet_fwjets))
184  pOut->push_back(*itJet);// fill forward jet as signal jet
185  }
186  else
187  {
188  std::vector<reco::Track>::const_iterator itTrack = tracks->begin();
189  for (unsigned int i=0; i<tsize; ++i) {
190  float deltaR2=reco::deltaR2(itJet->eta(),itJet->phi(), teta[i],tphi[i]);
191  if(deltaR2<0.25) {
192  reco::TransientTrack transientTrack = builder->build(*itTrack);
193  float jetTrackDistance = -((IPTools::jetTrackDistance(transientTrack, direction, *pv)).second).value();
194 
195  //select the tracks compabible with the jet
196  if(( itTrack->pt() > m_MinTrackPt) && ( itTrack->normalizedChi2() < m_MaxTrackChi2) && (jetTrackDistance<m_MaxTrackDistanceToJet))
197  {
198  trMomentum += itTrack->momentum(); //calculate the Sum(trackPt)
199  }
200  }
201  itTrack++;
202  }
203  //if Sum(comp.trackPt)/CaloJetPt > minPtRatio or Sum(trackPt) > minPt the jet is a signal jet
204  if(trMomentum.rho()/jetMomentum.rho() > m_MinGoodJetTrackPtRatio || trMomentum.rho() > m_MinGoodJetTrackPt )
205  {
206  pOut->push_back(*itJet); // fill it as signal jet
207  }
208  else//else it is a PUjet
209  {
210  pOut_PUjets->push_back(*itJet); // fill it as PUjets
211  }
212  }
213  }
214  }
215  iEvent.put(pOut);
216  iEvent.put(pOut_PUjets,"PUjets");
217 
218 }
219 
220 //define this as a plug-in
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
double m_MinGoodJetTrackPt
Definition: PixelJetPuId.cc:81
edm::InputTag m_jets
Definition: PixelJetPuId.cc:68
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
virtual void produce(edm::StreamID sid, edm::Event &, const edm::EventSetup &) const override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
double m_MaxTrackChi2
Definition: PixelJetPuId.cc:74
edm::EDGetTokenT< edm::View< reco::CaloJet > > jetsToken
Definition: PixelJetPuId.cc:70
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:66
int iEvent
Definition: GenABIO.cc:230
virtual ~PixelJetPuId()
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115
vector< PseudoJet > jets
double deltaR2(const T1 &t1, const T2 &t2)
Definition: deltaR.h:36
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< reco::VertexCollection > primaryVertexToken
Definition: PixelJetPuId.cc:71
ParameterDescriptionBase * add(U const &iLabel, T const &value)
double m_MaxTrackDistanceToJet
Definition: PixelJetPuId.cc:75
double m_minet_fwjets
Definition: PixelJetPuId.cc:79
double m_mineta_fwjets
Definition: PixelJetPuId.cc:78
PixelJetPuId(const edm::ParameterSet &)
Definition: PixelJetPuId.cc:89
edm::EDGetTokenT< std::vector< reco::Track > > tracksToken
Definition: PixelJetPuId.cc:69
edm::InputTag m_tracks
Definition: PixelJetPuId.cc:67
double m_MinTrackPt
Definition: PixelJetPuId.cc:73
tuple tracks
Definition: testEve_cfg.py:39
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
const T & get() const
Definition: EventSetup.h:55
void add(std::string const &label, ParameterSetDescription const &psetDescription)
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:85
double m_MinGoodJetTrackPtRatio
Definition: PixelJetPuId.cc:82