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.9 2013/04/30 09:02:46 kodolova 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  ptCUT = iConfig.getParameter<double>("ptCUT");
72  mJPTalgo = new JetPlusTrackCorrector(iConfig);
73  if(useZSP) mZSPalgo = new ZSPJPTJetCorrector(iConfig);
74 
75  produces<reco::JPTJetCollection>().setBranchAlias(alias);
76 
77 }
78 
79 
81 {
82 
83  // do anything here that needs to be done at desctruction time
84  // (e.g. close files, deallocate resources etc.)
85 
86 }
87 
88 
89 //
90 // member functions
91 //
92 
93 // ------------ method called to produce the data ------------
94 void
96 {
97  using namespace edm;
98 
99 
100 // std::cout<<" RecoJets::JetPlusTrackProducer::produce "<<std::endl;
101 
102 
103 // get stuff from Event
105  iEvent.getByLabel (src, jets_h);
106 
107 // std::auto_ptr<reco::CaloJetCollection> pOut(new reco::CaloJetCollection());
108  std::auto_ptr<reco::JPTJetCollection> pOut(new reco::JPTJetCollection());
109 
110  for (unsigned i = 0; i < jets_h->size(); ++i) {
111 
112  const reco::CaloJet* oldjet = &(*(jets_h->refAt(i)));
113 
114  reco::CaloJet corrected = *oldjet;
115 
116 // ZSP corrections
117 
118  double factorZSP = 1.;
119  if(useZSP) factorZSP = mZSPalgo->correction(corrected, iEvent, iSetup);
120 
121  corrected.scaleEnergy (factorZSP);
122 
123 // JPT corrections
124 
125  double scaleJPT = 1.;
126 
128 
129  jpt::MatchedTracks pions;
131  jpt::MatchedTracks elecs;
132  bool ok=false;
133 
134  if ( !vectorial_ ) {
135 
136  scaleJPT = mJPTalgo->correction ( corrected, *oldjet, iEvent, iSetup, pions, muons, elecs,ok );
137  p4 = math::XYZTLorentzVector( corrected.px()*scaleJPT,
138  corrected.py()*scaleJPT,
139  corrected.pz()*scaleJPT,
140  corrected.energy()*scaleJPT );
141  } else {
142  scaleJPT = mJPTalgo->correction( corrected, *oldjet, iEvent, iSetup, p4, pions, muons, elecs,ok );
143  }
144 
145 
147 
148  if(ok) {
149  specific.pionsInVertexInCalo = pions.inVertexInCalo_;
150  specific.pionsInVertexOutCalo = pions.inVertexOutOfCalo_;
151  specific.pionsOutVertexInCalo = pions.outOfVertexInCalo_;
152  specific.muonsInVertexInCalo = muons.inVertexInCalo_;
153  specific.muonsInVertexOutCalo = muons.inVertexOutOfCalo_;
154  specific.muonsOutVertexInCalo = muons.outOfVertexInCalo_;
155  specific.elecsInVertexInCalo = elecs.inVertexInCalo_;
156  specific.elecsInVertexOutCalo = elecs.inVertexOutOfCalo_;
157  specific.elecsOutVertexInCalo = elecs.outOfVertexInCalo_;
158  }
159 
160 // Fill JPT Specific
161  edm::RefToBase<reco::Jet> myjet = (edm::RefToBase<reco::Jet>)jets_h->refAt(i);
162  specific.theCaloJetRef = myjet;
163  specific.mZSPCor = factorZSP;
164  specific.mResponseOfChargedWithEff = (float)mJPTalgo->getResponseOfChargedWithEff();
165  specific.mResponseOfChargedWithoutEff = (float)mJPTalgo->getResponseOfChargedWithoutEff();
166  specific.mSumPtOfChargedWithEff = (float)mJPTalgo->getSumPtWithEff();
167  specific.mSumPtOfChargedWithoutEff = (float)mJPTalgo->getSumPtWithoutEff();
168  specific.mSumEnergyOfChargedWithEff = (float)mJPTalgo->getSumEnergyWithEff();
169  specific.mSumEnergyOfChargedWithoutEff = (float)mJPTalgo->getSumEnergyWithoutEff();
170  specific.mChargedHadronEnergy = (float)mJPTalgo->getSumEnergyWithoutEff();
171 
172 // Fill Charged Jet shape parameters
173  double deR2Tr = 0.;
174  double deEta2Tr = 0.;
175  double dePhi2Tr = 0.;
176  double Zch = 0.;
177  double Pout2 = 0.;
178  double Pout = 0.;
179  double denominator_tracks = 0.;
180  int ntracks = 0;
181 
182  for( reco::TrackRefVector::const_iterator it = pions.inVertexInCalo_.begin(); it != pions.inVertexInCalo_.end(); it++) {
183  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
184  double deEta = (*it)->eta() - p4.eta();
185  double dePhi = deltaPhi((*it)->phi(), p4.phi());
186  if((**it).ptError()/(**it).pt() < 0.1) {
187  deR2Tr = deR2Tr + deR*deR*(*it)->pt();
188  deEta2Tr = deEta2Tr + deEta*deEta*(*it)->pt();
189  dePhi2Tr = dePhi2Tr + dePhi*dePhi*(*it)->pt();
190  denominator_tracks = denominator_tracks + (*it)->pt();
191  Zch = Zch + (*it)->pt();
192 
193  Pout2 = Pout2 + (**it).p()*(**it).p() - (Zch*p4.P())*(Zch*p4.P());
194  ntracks++;
195  }
196  }
197 
198 
199 
200  for( reco::TrackRefVector::const_iterator it = muons.inVertexInCalo_.begin(); it != muons.inVertexInCalo_.end(); it++) {
201  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
202  double deEta = (*it)->eta() - p4.eta();
203  double dePhi = deltaPhi((*it)->phi(), p4.phi());
204  if((**it).ptError()/(**it).pt() < 0.1) {
205  deR2Tr = deR2Tr + deR*deR*(*it)->pt();
206  deEta2Tr = deEta2Tr + deEta*deEta*(*it)->pt();
207  dePhi2Tr = dePhi2Tr + dePhi*dePhi*(*it)->pt();
208  denominator_tracks = denominator_tracks + (*it)->pt();
209  Zch = Zch + (*it)->pt();
210 
211  Pout2 = Pout2 + (**it).p()*(**it).p() - (Zch*p4.P())*(Zch*p4.P());
212  ntracks++;
213  }
214  }
215  for( reco::TrackRefVector::const_iterator it = elecs.inVertexInCalo_.begin(); it != elecs.inVertexInCalo_.end(); it++) {
216  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
217  double deEta = (*it)->eta() - p4.eta();
218  double dePhi = deltaPhi((*it)->phi(), p4.phi());
219  if((**it).ptError()/(**it).pt() < 0.1) {
220  deR2Tr = deR2Tr + deR*deR*(*it)->pt();
221  deEta2Tr = deEta2Tr + deEta*deEta*(*it)->pt();
222  dePhi2Tr = dePhi2Tr + dePhi*dePhi*(*it)->pt();
223  denominator_tracks = denominator_tracks + (*it)->pt();
224  Zch = Zch + (*it)->pt();
225 
226  Pout2 = Pout2 + (**it).p()*(**it).p() - (Zch*p4.P())*(Zch*p4.P());
227  ntracks++;
228  }
229  }
230  for( reco::TrackRefVector::const_iterator it = pions.inVertexOutOfCalo_.begin(); it != pions.inVertexOutOfCalo_.end(); it++) {
231  Zch = Zch + (*it)->pt();
232  }
233  for( reco::TrackRefVector::const_iterator it = muons.inVertexOutOfCalo_.begin(); it != muons.inVertexOutOfCalo_.end(); it++) {
234  Zch = Zch + (*it)->pt();
235  }
236  for( reco::TrackRefVector::const_iterator it = elecs.inVertexOutOfCalo_.begin(); it != elecs.inVertexOutOfCalo_.end(); it++) {
237  Zch = Zch + (*it)->pt();
238  }
239 
240  if(mJPTalgo->getSumPtForBeta()> 0.) Zch = Zch/mJPTalgo->getSumPtForBeta();
241 
242 // std::cout<<" Zch "<< Zch<<" "<<mJPTalgo->getSumPtForBeta()<<std::endl;
243 
244  if(ntracks > 0) {
245  Pout = sqrt(fabs(Pout2))/ntracks;
246  }
247  if (denominator_tracks!=0){
248  deR2Tr = deR2Tr/denominator_tracks;
249  deEta2Tr= deEta2Tr/denominator_tracks;
250  dePhi2Tr= dePhi2Tr/denominator_tracks;
251  }
252 
253  specific.R2momtr = deR2Tr;
254  specific.Eta2momtr = deEta2Tr;
255  specific.Phi2momtr = dePhi2Tr;
256  specific.Pout = Pout;
257  specific.Zch = Zch;
258 
259 
260 // std::cout<<" Moments for charged component "<<deR2_Tr<<" "<<deEta2_Tr<<" "<<dePhi2_Tr<<std::endl;
261 
262 
263 // Create JPT jet
264 
266 
267 // If we add primary vertex
269  iEvent.getByLabel(srcPVs_,pvCollection);
270  if ( pvCollection.isValid() && pvCollection->size()>0 ) vertex_=pvCollection->begin()->position();
271 
272  reco::JPTJet fJet(p4, vertex_, specific, corrected.getJetConstituents());
273 
274  // fJet.printJet();
275 
276 // Output module
277  if(fJet.pt()>ptCUT) pOut->push_back(fJet);
278 
279  }
280 
281  iEvent.put(pOut);
282 
283 }
284 
285 // ------------ method called once each job just before starting event loop ------------
286 void
288 {
289 }
290 
291 // ------------ method called once each job just after ending the event loop ------------
292 void
294 }
295 
296 //define this as a plug-in
297 //DEFINE_FWK_MODULE(JetPlusTrackProducer);
reco::TrackRefVector muonsInVertexOutCalo
Definition: JPTJet.h:57
virtual double energy() const GCC11_FINAL
energy
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
virtual double pz() const GCC11_FINAL
z coordinate of momentum vector
virtual double py() const GCC11_FINAL
y coordinate of momentum vector
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
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
T sqrt(T t)
Definition: SSEVec.h:48
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
virtual double px() const GCC11_FINAL
x coordinate of momentum vector
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:361
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
float mSumPtOfChargedWithoutEff
Definition: JPTJet.h:69
reco::TrackRefVector elecsInVertexOutCalo
Definition: JPTJet.h:60
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
math::XYZPoint Point
point in the space
Definition: LeafCandidate.h:30
virtual Constituents getJetConstituents() const
list of constituents
Definition: Jet.cc:351