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.3 2010/05/05 13:58:08 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  mJPTalgo = new JetPlusTrackCorrector(iConfig);
72  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  if ( !vectorial_ ) {
129 
130  scaleJPT = mJPTalgo->correction ( corrected, *oldjet, iEvent, iSetup );
131  p4 = math::XYZTLorentzVector( corrected.px()*scaleJPT,
132  corrected.py()*scaleJPT,
133  corrected.pz()*scaleJPT,
134  corrected.energy()*scaleJPT );
135  } else {
136  scaleJPT = mJPTalgo->correction( corrected, *oldjet, iEvent, iSetup, p4 );
137  }
138 
139 // Construct JPTJet constituent
140  jpt::MatchedTracks pions;
142  jpt::MatchedTracks elecs;
143 
144  bool ok = mJPTalgo->matchTracks( *oldjet,
145  iEvent,
146  iSetup,
147  pions,
148  muons,
149  elecs );
150 
151 
152  reco::JPTJet::Specific specific;
153 
154  if(ok) {
155  specific.pionsInVertexInCalo = pions.inVertexInCalo_;
156  specific.pionsInVertexOutCalo = pions.inVertexOutOfCalo_;
157  specific.pionsOutVertexInCalo = pions.outOfVertexInCalo_;
158  specific.muonsInVertexInCalo = muons.inVertexInCalo_;
159  specific.muonsInVertexOutCalo = muons.inVertexOutOfCalo_;
160  specific.muonsOutVertexInCalo = muons.outOfVertexInCalo_;
161  specific.elecsInVertexInCalo = elecs.inVertexInCalo_;
162  specific.elecsInVertexOutCalo = elecs.inVertexOutOfCalo_;
163  specific.elecsOutVertexInCalo = elecs.outOfVertexInCalo_;
164  }
165 
166 // Fill JPT Specific
167  edm::RefToBase<reco::Jet> myjet = (edm::RefToBase<reco::Jet>)jets_h->refAt(i);
168  specific.theCaloJetRef = myjet;
169  specific.mZSPCor = factorZSP;
170  specific.mResponseOfChargedWithEff = (float)mJPTalgo->getResponseOfChargedWithEff();
171  specific.mResponseOfChargedWithoutEff = (float)mJPTalgo->getResponseOfChargedWithoutEff();
172  specific.mSumPtOfChargedWithEff = (float)mJPTalgo->getSumPtWithEff();
173  specific.mSumPtOfChargedWithoutEff = (float)mJPTalgo->getSumPtWithoutEff();
174  specific.mSumEnergyOfChargedWithEff = (float)mJPTalgo->getSumEnergyWithEff();
175  specific.mSumEnergyOfChargedWithoutEff = (float)mJPTalgo->getSumEnergyWithoutEff();
176  specific.mChargedHadronEnergy = (float)mJPTalgo->getSumEnergyWithoutEff();
177 
178 // Fill Charged Jet shape parameters
179  double deR2Tr = 0.;
180  double deEta2Tr = 0.;
181  double dePhi2Tr = 0.;
182  double Zch = 0.;
183  double Pout2 = 0.;
184  double Pout = 0.;
185  double denominator_tracks = 0.;
186  int ntracks = 0;
187 
188  for( reco::TrackRefVector::const_iterator it = pions.inVertexInCalo_.begin(); it != pions.inVertexInCalo_.end(); it++) {
189  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
190  double deEta = (*it)->eta() - p4.eta();
191  double dePhi = deltaPhi((*it)->phi(), p4.phi());
192  if((**it).ptError()/(**it).pt() < 0.1) {
193  deR2Tr = deR2Tr + deR*deR*(*it)->pt();
194  deEta2Tr = deEta2Tr + deEta*deEta*(*it)->pt();
195  dePhi2Tr = dePhi2Tr + dePhi*dePhi*(*it)->pt();
196  denominator_tracks = denominator_tracks + (*it)->pt();
197  Zch = Zch +
198  ((*it)->px()*p4.Px()+(*it)->py()*p4.Py()+(*it)->pz()*p4.Pz())/(p4.P()*p4.P());
199  Pout2 = Pout2 + (**it).p()*(**it).p() - (Zch*p4.P())*(Zch*p4.P());
200  ntracks++;
201  }
202  }
203 
204 
205 
206  for( reco::TrackRefVector::const_iterator it = muons.inVertexInCalo_.begin(); it != muons.inVertexInCalo_.end(); it++) {
207  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
208  double deEta = (*it)->eta() - p4.eta();
209  double dePhi = deltaPhi((*it)->phi(), p4.phi());
210  if((**it).ptError()/(**it).pt() < 0.1) {
211  deR2Tr = deR2Tr + deR*deR*(*it)->pt();
212  deEta2Tr = deEta2Tr + deEta*deEta*(*it)->pt();
213  dePhi2Tr = dePhi2Tr + dePhi*dePhi*(*it)->pt();
214  denominator_tracks = denominator_tracks + (*it)->pt();
215  Zch = Zch +
216  ((*it)->px()*p4.Px()+(*it)->py()*p4.Py()+(*it)->pz()*p4.Pz())/(p4.P()*p4.P());
217  Pout2 = Pout2 + (**it).p()*(**it).p() - (Zch*p4.P())*(Zch*p4.P());
218  ntracks++;
219  }
220  }
221  for( reco::TrackRefVector::const_iterator it = elecs.inVertexInCalo_.begin(); it != elecs.inVertexInCalo_.end(); it++) {
222  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
223  double deEta = (*it)->eta() - p4.eta();
224  double dePhi = deltaPhi((*it)->phi(), p4.phi());
225  if((**it).ptError()/(**it).pt() < 0.1) {
226  deR2Tr = deR2Tr + deR*deR*(*it)->pt();
227  deEta2Tr = deEta2Tr + deEta*deEta*(*it)->pt();
228  dePhi2Tr = dePhi2Tr + dePhi*dePhi*(*it)->pt();
229  denominator_tracks = denominator_tracks + (*it)->pt();
230  Zch = Zch +
231  ((*it)->px()*p4.Px()+(*it)->py()*p4.Py()+(*it)->pz()*p4.Pz())/(p4.P()*p4.P());
232  Pout2 = Pout2 + (**it).p()*(**it).p() - (Zch*p4.P())*(Zch*p4.P());
233  ntracks++;
234  }
235  }
236 
237  if(ntracks > 0) {
238  Pout = sqrt(fabs(Pout2))/ntracks;
239  Zch = Zch/ntracks;
240  }
241  if (denominator_tracks!=0){
242  deR2Tr = deR2Tr/denominator_tracks;
243  deEta2Tr= deEta2Tr/denominator_tracks;
244  dePhi2Tr= dePhi2Tr/denominator_tracks;
245  }
246 
247  specific.R2momtr = deR2Tr;
248  specific.Eta2momtr = deEta2Tr;
249  specific.Phi2momtr = dePhi2Tr;
250  specific.Pout = Pout;
251  specific.Zch = Zch;
252 
253 
254 // std::cout<<" Moments for charged component "<<deR2_Tr<<" "<<deEta2_Tr<<" "<<dePhi2_Tr<<std::endl;
255 
256 
257 // Create JPT jet
258 
260 
261 // If we add primary vertex
263  iEvent.getByLabel(srcPVs_,pvCollection);
264  if ( pvCollection.isValid() && pvCollection->size()>0 ) vertex_=pvCollection->begin()->position();
265 
266  reco::JPTJet fJet(p4, vertex_, specific, corrected.getJetConstituents());
267 
268  // fJet.printJet();
269 
270 // Output module
271  pOut->push_back(fJet);
272 
273  }
274 
275  iEvent.put(pOut);
276 
277 }
278 
279 // ------------ method called once each job just before starting event loop ------------
280 void
282 {
283 }
284 
285 // ------------ method called once each job just after ending the event loop ------------
286 void
288 }
289 
290 //define this as a plug-in
291 //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
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
double deltaPhi(float phi1, float phi2)
Definition: VectorUtil.h:30
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:386
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:242
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:237
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:84
T sqrt(T t)
Definition: SSEVec.h:28
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:30
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:359
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.
virtual double py() const
y coordinate of momentum vector
math::XYZPoint Point
point in the space
Definition: LeafCandidate.h:29
tuple src
Definition: align_tpl.py:87
virtual Constituents getJetConstituents() const
list of constituents
Definition: Jet.cc:349