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 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
24 
26 
28 
41 
42 #include <string>
43 
44 using namespace std;
45 using namespace jpt;
46 
47 //
48 // constants, enums and typedefs
49 //
50 
51 
52 //
53 // static data member definitions
54 //
55 
56 //
57 // constructors and destructor
58 //
60 {
61  //register your products
62  src = iConfig.getParameter<edm::InputTag>("src");
63  alias = iConfig.getUntrackedParameter<string>("alias");
64  srcPVs_ = iConfig.getParameter<edm::InputTag>("srcPVs");
65  vectorial_ = iConfig.getParameter<bool>("VectorialCorrection");
66  useZSP = iConfig.getParameter<bool>("UseZSP");
67  ptCUT = iConfig.getParameter<double>("ptCUT");
68  mJPTalgo = new JetPlusTrackCorrector(iConfig, consumesCollector());
69  if(useZSP) mZSPalgo = new ZSPJPTJetCorrector(iConfig);
70 
71  produces<reco::JPTJetCollection>().setBranchAlias(alias);
72 
73  input_jets_token_ = consumes<edm::View<reco::CaloJet> >(src);
74  input_vertex_token_ = consumes<reco::VertexCollection>(srcPVs_);
75 
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.getByToken (input_jets_token_, 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.getByToken(input_vertex_token_, 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 //define this as a plug-in
286 //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
Jets made from CaloTowers.
Definition: CaloJet.h:29
reco::TrackRefVector muonsInVertexInCalo
Definition: JPTJet.h:56
virtual void scaleEnergy(double fScale)
scale energy of the jet
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
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
reco::TrackRefVector inVertexOutOfCalo_
float mResponseOfChargedWithEff
Definition: JPTJet.h:66
virtual void produce(edm::Event &, const edm::EventSetup &) override
reco::TrackRefVector elecsOutVertexInCalo
Definition: JPTJet.h:61
virtual Constituents getJetConstituents() const
list of constituents
reco::TrackRefVector pionsInVertexOutCalo
Definition: JPTJet.h:54
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:255
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:250
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
virtual double energy() const
energy
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
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
math::XYZPoint Point
point in the space
Definition: Particle.h:25
reco::TrackRefVector outOfVertexInCalo_
reco::TrackRefVector elecsInVertexInCalo
Definition: JPTJet.h:59
bool isValid() const
Definition: HandleBase.h:75
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:27