CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
JetPlusTrackProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: JetPlusTracks
4 // Class: JetPlusTrackProducer
5 //
13 //
14 // Original Author: Olga Kodolova,40 R-A12,+41227671273,
15 // Created: Fri Feb 19 10:14:02 CET 2010
16 // $Id: JetPlusTrackProducer.cc,v 1.7 2011/12/12 19:52:42 dlange Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
27 
30 
32 
45 
46 #include <string>
47 
48 using namespace std;
49 using namespace jpt;
50 
51 //
52 // constants, enums and typedefs
53 //
54 
55 
56 //
57 // static data member definitions
58 //
59 
60 //
61 // constructors and destructor
62 //
64 {
65  //register your products
66  src = iConfig.getParameter<edm::InputTag>("src");
67  alias = iConfig.getUntrackedParameter<string>("alias");
68  srcPVs_ = iConfig.getParameter<edm::InputTag>("srcPVs");
69  vectorial_ = iConfig.getParameter<bool>("VectorialCorrection");
70  useZSP = iConfig.getParameter<bool>("UseZSP");
71  mJPTalgo = new JetPlusTrackCorrector(iConfig);
72  if(useZSP) mZSPalgo = new ZSPJPTJetCorrector(iConfig);
73 
74  produces<reco::JPTJetCollection>().setBranchAlias(alias);
75 
76 }
77 
78 
80 {
81 
82  // do anything here that needs to be done at desctruction time
83  // (e.g. close files, deallocate resources etc.)
84 
85 }
86 
87 
88 //
89 // member functions
90 //
91 
92 // ------------ method called to produce the data ------------
93 void
95 {
96  using namespace edm;
97 
98 
99 // std::cout<<" RecoJets::JetPlusTrackProducer::produce "<<std::endl;
100 
101 
102 // get stuff from Event
104  iEvent.getByLabel (src, jets_h);
105 
106 // std::auto_ptr<reco::CaloJetCollection> pOut(new reco::CaloJetCollection());
107  std::auto_ptr<reco::JPTJetCollection> pOut(new reco::JPTJetCollection());
108 
109  for (unsigned i = 0; i < jets_h->size(); ++i) {
110 
111  const reco::CaloJet* oldjet = &(*(jets_h->refAt(i)));
112 
113  reco::CaloJet corrected = *oldjet;
114 
115 // ZSP corrections
116 
117  double factorZSP = 1.;
118  if(useZSP) factorZSP = mZSPalgo->correction(corrected, iEvent, iSetup);
119 
120  corrected.scaleEnergy (factorZSP);
121 
122 // JPT corrections
123 
124  double scaleJPT = 1.;
125 
127 
128  jpt::MatchedTracks pions;
130  jpt::MatchedTracks elecs;
131  bool ok=false;
132 
133  if ( !vectorial_ ) {
134 
135  scaleJPT = mJPTalgo->correction ( corrected, *oldjet, iEvent, iSetup, pions, muons, elecs,ok );
136  p4 = math::XYZTLorentzVector( corrected.px()*scaleJPT,
137  corrected.py()*scaleJPT,
138  corrected.pz()*scaleJPT,
139  corrected.energy()*scaleJPT );
140  } else {
141  scaleJPT = mJPTalgo->correction( corrected, *oldjet, iEvent, iSetup, p4, pions, muons, elecs,ok );
142  }
143 
144 
146 
147  if(ok) {
148  specific.pionsInVertexInCalo = pions.inVertexInCalo_;
149  specific.pionsInVertexOutCalo = pions.inVertexOutOfCalo_;
150  specific.pionsOutVertexInCalo = pions.outOfVertexInCalo_;
151  specific.muonsInVertexInCalo = muons.inVertexInCalo_;
152  specific.muonsInVertexOutCalo = muons.inVertexOutOfCalo_;
153  specific.muonsOutVertexInCalo = muons.outOfVertexInCalo_;
154  specific.elecsInVertexInCalo = elecs.inVertexInCalo_;
155  specific.elecsInVertexOutCalo = elecs.inVertexOutOfCalo_;
156  specific.elecsOutVertexInCalo = elecs.outOfVertexInCalo_;
157  }
158 
159 // Fill JPT Specific
160  edm::RefToBase<reco::Jet> myjet = (edm::RefToBase<reco::Jet>)jets_h->refAt(i);
161  specific.theCaloJetRef = myjet;
162  specific.mZSPCor = factorZSP;
163  specific.mResponseOfChargedWithEff = (float)mJPTalgo->getResponseOfChargedWithEff();
164  specific.mResponseOfChargedWithoutEff = (float)mJPTalgo->getResponseOfChargedWithoutEff();
165  specific.mSumPtOfChargedWithEff = (float)mJPTalgo->getSumPtWithEff();
166  specific.mSumPtOfChargedWithoutEff = (float)mJPTalgo->getSumPtWithoutEff();
167  specific.mSumEnergyOfChargedWithEff = (float)mJPTalgo->getSumEnergyWithEff();
168  specific.mSumEnergyOfChargedWithoutEff = (float)mJPTalgo->getSumEnergyWithoutEff();
169  specific.mChargedHadronEnergy = (float)mJPTalgo->getSumEnergyWithoutEff();
170 
171 // Fill Charged Jet shape parameters
172  double deR2Tr = 0.;
173  double deEta2Tr = 0.;
174  double dePhi2Tr = 0.;
175  double Zch = 0.;
176  double Pout2 = 0.;
177  double Pout = 0.;
178  double denominator_tracks = 0.;
179  int ntracks = 0;
180 
181  for( reco::TrackRefVector::const_iterator it = pions.inVertexInCalo_.begin(); it != pions.inVertexInCalo_.end(); it++) {
182  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
183  double deEta = (*it)->eta() - p4.eta();
184  double dePhi = deltaPhi((*it)->phi(), p4.phi());
185  if((**it).ptError()/(**it).pt() < 0.1) {
186  deR2Tr = deR2Tr + deR*deR*(*it)->pt();
187  deEta2Tr = deEta2Tr + deEta*deEta*(*it)->pt();
188  dePhi2Tr = dePhi2Tr + dePhi*dePhi*(*it)->pt();
189  denominator_tracks = denominator_tracks + (*it)->pt();
190  Zch = Zch + (*it)->pt();
191 
192  Pout2 = Pout2 + (**it).p()*(**it).p() - (Zch*p4.P())*(Zch*p4.P());
193  ntracks++;
194  }
195  }
196 
197 
198 
199  for( reco::TrackRefVector::const_iterator it = muons.inVertexInCalo_.begin(); it != muons.inVertexInCalo_.end(); it++) {
200  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
201  double deEta = (*it)->eta() - p4.eta();
202  double dePhi = deltaPhi((*it)->phi(), p4.phi());
203  if((**it).ptError()/(**it).pt() < 0.1) {
204  deR2Tr = deR2Tr + deR*deR*(*it)->pt();
205  deEta2Tr = deEta2Tr + deEta*deEta*(*it)->pt();
206  dePhi2Tr = dePhi2Tr + dePhi*dePhi*(*it)->pt();
207  denominator_tracks = denominator_tracks + (*it)->pt();
208  Zch = Zch + (*it)->pt();
209 
210  Pout2 = Pout2 + (**it).p()*(**it).p() - (Zch*p4.P())*(Zch*p4.P());
211  ntracks++;
212  }
213  }
214  for( reco::TrackRefVector::const_iterator it = elecs.inVertexInCalo_.begin(); it != elecs.inVertexInCalo_.end(); it++) {
215  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
216  double deEta = (*it)->eta() - p4.eta();
217  double dePhi = deltaPhi((*it)->phi(), p4.phi());
218  if((**it).ptError()/(**it).pt() < 0.1) {
219  deR2Tr = deR2Tr + deR*deR*(*it)->pt();
220  deEta2Tr = deEta2Tr + deEta*deEta*(*it)->pt();
221  dePhi2Tr = dePhi2Tr + dePhi*dePhi*(*it)->pt();
222  denominator_tracks = denominator_tracks + (*it)->pt();
223  Zch = Zch + (*it)->pt();
224 
225  Pout2 = Pout2 + (**it).p()*(**it).p() - (Zch*p4.P())*(Zch*p4.P());
226  ntracks++;
227  }
228  }
229  for( reco::TrackRefVector::const_iterator it = pions.inVertexOutOfCalo_.begin(); it != pions.inVertexOutOfCalo_.end(); it++) {
230  Zch = Zch + (*it)->pt();
231  }
232  for( reco::TrackRefVector::const_iterator it = muons.inVertexOutOfCalo_.begin(); it != muons.inVertexOutOfCalo_.end(); it++) {
233  Zch = Zch + (*it)->pt();
234  }
235  for( reco::TrackRefVector::const_iterator it = elecs.inVertexOutOfCalo_.begin(); it != elecs.inVertexOutOfCalo_.end(); it++) {
236  Zch = Zch + (*it)->pt();
237  }
238 
239  if(mJPTalgo->getSumPtForBeta()> 0.) Zch = Zch/mJPTalgo->getSumPtForBeta();
240 
241 // std::cout<<" Zch "<< Zch<<" "<<mJPTalgo->getSumPtForBeta()<<std::endl;
242 
243  if(ntracks > 0) {
244  Pout = sqrt(fabs(Pout2))/ntracks;
245  }
246  if (denominator_tracks!=0){
247  deR2Tr = deR2Tr/denominator_tracks;
248  deEta2Tr= deEta2Tr/denominator_tracks;
249  dePhi2Tr= dePhi2Tr/denominator_tracks;
250  }
251 
252  specific.R2momtr = deR2Tr;
253  specific.Eta2momtr = deEta2Tr;
254  specific.Phi2momtr = dePhi2Tr;
255  specific.Pout = Pout;
256  specific.Zch = Zch;
257 
258 
259 // std::cout<<" Moments for charged component "<<deR2_Tr<<" "<<deEta2_Tr<<" "<<dePhi2_Tr<<std::endl;
260 
261 
262 // Create JPT jet
263 
265 
266 // If we add primary vertex
268  iEvent.getByLabel(srcPVs_,pvCollection);
269  if ( pvCollection.isValid() && pvCollection->size()>0 ) vertex_=pvCollection->begin()->position();
270 
271  reco::JPTJet fJet(p4, vertex_, specific, corrected.getJetConstituents());
272 
273  // fJet.printJet();
274 
275 // Output module
276  pOut->push_back(fJet);
277 
278  }
279 
280  iEvent.put(pOut);
281 
282 }
283 
284 // ------------ method called once each job just before starting event loop ------------
285 void
287 {
288 }
289 
290 // ------------ method called once each job just after ending the event loop ------------
291 void
293 }
294 
295 //define this as a plug-in
296 //DEFINE_FWK_MODULE(JetPlusTrackProducer);
reco::TrackRefVector muonsInVertexOutCalo
Definition: JPTJet.h:57
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
float mSumEnergyOfChargedWithoutEff
Definition: JPTJet.h:71
dictionary specific
virtual void produce(edm::Event &, const edm::EventSetup &)
Jets made from CaloTowers.
Definition: CaloJet.h:30
reco::TrackRefVector muonsInVertexInCalo
Definition: JPTJet.h:56
std::vector< JPTJet > JPTJetCollection
collection of CaloJet objects
float mChargedHadronEnergy
Definition: JPTJet.h:62
float mSumPtOfChargedWithEff
Definition: JPTJet.h:68
reco::TrackRefVector inVertexInCalo_
reco::TrackRefVector muonsOutVertexInCalo
Definition: JPTJet.h:58
virtual void scaleEnergy(double fScale)
scale energy of the jet
Definition: Jet.cc:445
reco::TrackRefVector inVertexOutOfCalo_
float mResponseOfChargedWithEff
Definition: JPTJet.h:66
reco::TrackRefVector elecsOutVertexInCalo
Definition: JPTJet.h:61
reco::TrackRefVector pionsInVertexOutCalo
Definition: JPTJet.h:54
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:249
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:244
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
virtual double energy() const
energy
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
T sqrt(T t)
Definition: SSEVec.h:46
double p4[4]
Definition: TauolaWrapper.h:92
Jets made from CaloJets corrected for ZSP and tracks.
Definition: JPTJet.h:29
reco::TrackRefVector pionsOutVertexInCalo
Definition: JPTJet.h:55
float mSumEnergyOfChargedWithEff
Definition: JPTJet.h:70
math::XYZPoint Point
point in the space
Definition: Particle.h:29
reco::TrackRefVector outOfVertexInCalo_
reco::TrackRefVector elecsInVertexInCalo
Definition: JPTJet.h:59
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
edm::RefToBase< reco::Jet > theCaloJetRef
Definition: JPTJet.h:52
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
JetPlusTrackProducer(const edm::ParameterSet &)
float mResponseOfChargedWithoutEff
Definition: JPTJet.h:67
reco::TrackRefVector pionsInVertexInCalo
Definition: JPTJet.h:53
virtual double px() const
x coordinate of momentum vector
float mSumPtOfChargedWithoutEff
Definition: JPTJet.h:69
reco::TrackRefVector elecsInVertexOutCalo
Definition: JPTJet.h:60
virtual double pz() const
z coordinate of momentum vector
Particles matched to tracks that are in/in, in/out, out/in at Vertex and CaloFace.
Jet energy correction algorithm using tracks.
tuple muons
Definition: patZpeak.py:38
virtual double py() const
y coordinate of momentum vector
math::XYZPoint Point
point in the space
Definition: LeafCandidate.h:29
virtual Constituents getJetConstituents() const
list of constituents
Definition: Jet.cc:351