CMS 3D CMS Logo

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 // auto pOut = std::make_unique<reco::CaloJetCollection>();
108  auto pOut = std::make_unique<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;
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 
146  reco::JPTJet::Specific specific;
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->empty() ) 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(std::move(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
float mSumEnergyOfChargedWithoutEff
Definition: JPTJet.h:71
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
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:508
double px() const final
x coordinate of momentum vector
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
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:253
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:248
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
int iEvent
Definition: GenABIO.cc:230
double pz() const final
z coordinate of momentum vector
T sqrt(T t)
Definition: SSEVec.h:18
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
double energy() const final
energy
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:74
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
double py() const final
y coordinate of momentum vector
reco::TrackRefVector elecsInVertexOutCalo
Definition: JPTJet.h:60
Particles matched to tracks that are in/in, in/out, out/in at Vertex and CaloFace.
HLT enums.
Jet energy correction algorithm using tracks.
def move(src, dest)
Definition: eostools.py:510
math::XYZPoint Point
point in the space
Definition: LeafCandidate.h:27