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 // system include files
20 #include <memory>
21 
22 // user include files
23 
25 
27 
40 
41 #include <string>
42 
43 using namespace std;
44 using namespace jpt;
45 
46 //
47 // constants, enums and typedefs
48 //
49 
50 //
51 // static data member definitions
52 //
53 
54 //
55 // constructors and destructor
56 //
58  //register your products
59  src = iConfig.getParameter<edm::InputTag>("src");
60  alias = iConfig.getUntrackedParameter<string>("alias");
61  srcPVs_ = iConfig.getParameter<edm::InputTag>("srcPVs");
62  vectorial_ = iConfig.getParameter<bool>("VectorialCorrection");
63  useZSP = iConfig.getParameter<bool>("UseZSP");
64  ptCUT = iConfig.getParameter<double>("ptCUT");
65  mJPTalgo = new JetPlusTrackCorrector(iConfig, consumesCollector());
66  if (useZSP)
67  mZSPalgo = new ZSPJPTJetCorrector(iConfig);
68 
69  produces<reco::JPTJetCollection>().setBranchAlias(alias);
70 
71  input_jets_token_ = consumes<edm::View<reco::CaloJet> >(src);
72  input_vertex_token_ = consumes<reco::VertexCollection>(srcPVs_);
73 }
74 
76  // do anything here that needs to be done at desctruction time
77  // (e.g. close files, deallocate resources etc.)
78 }
79 
80 //
81 // member functions
82 //
83 
84 // ------------ method called to produce the data ------------
86  using namespace edm;
87 
88  // std::cout<<" RecoJets::JetPlusTrackProducer::produce "<<std::endl;
89 
90  // get stuff from Event
92  iEvent.getByToken(input_jets_token_, jets_h);
93 
94  // auto pOut = std::make_unique<reco::CaloJetCollection>();
95  auto pOut = std::make_unique<reco::JPTJetCollection>();
96 
97  for (unsigned i = 0; i < jets_h->size(); ++i) {
98  const reco::CaloJet* oldjet = &(*(jets_h->refAt(i)));
99 
100  reco::CaloJet corrected = *oldjet;
101 
102  // ZSP corrections
103 
104  double factorZSP = 1.;
105  if (useZSP)
106  factorZSP = mZSPalgo->correction(corrected, iEvent, iSetup);
107 
108  corrected.scaleEnergy(factorZSP);
109 
110  // JPT corrections
111 
112  double scaleJPT = 1.;
113 
115 
116  jpt::MatchedTracks pions;
119  bool ok = false;
120 
121  if (!vectorial_) {
122  scaleJPT = mJPTalgo->correction(corrected, *oldjet, iEvent, iSetup, pions, muons, elecs, ok);
123  p4 = math::XYZTLorentzVector(corrected.px() * scaleJPT,
124  corrected.py() * scaleJPT,
125  corrected.pz() * scaleJPT,
126  corrected.energy() * scaleJPT);
127  } else {
128  scaleJPT = mJPTalgo->correction(corrected, *oldjet, iEvent, iSetup, p4, pions, muons, elecs, ok);
129  }
130 
132 
133  if (ok) {
134  specific.pionsInVertexInCalo = pions.inVertexInCalo_;
135  specific.pionsInVertexOutCalo = pions.inVertexOutOfCalo_;
136  specific.pionsOutVertexInCalo = pions.outOfVertexInCalo_;
137  specific.muonsInVertexInCalo = muons.inVertexInCalo_;
138  specific.muonsInVertexOutCalo = muons.inVertexOutOfCalo_;
139  specific.muonsOutVertexInCalo = muons.outOfVertexInCalo_;
140  specific.elecsInVertexInCalo = elecs.inVertexInCalo_;
141  specific.elecsInVertexOutCalo = elecs.inVertexOutOfCalo_;
142  specific.elecsOutVertexInCalo = elecs.outOfVertexInCalo_;
143  }
144 
145  // Fill JPT Specific
146  edm::RefToBase<reco::Jet> myjet = (edm::RefToBase<reco::Jet>)jets_h->refAt(i);
147  specific.theCaloJetRef = myjet;
148  specific.mZSPCor = factorZSP;
149  specific.mResponseOfChargedWithEff = (float)mJPTalgo->getResponseOfChargedWithEff();
150  specific.mResponseOfChargedWithoutEff = (float)mJPTalgo->getResponseOfChargedWithoutEff();
151  specific.mSumPtOfChargedWithEff = (float)mJPTalgo->getSumPtWithEff();
152  specific.mSumPtOfChargedWithoutEff = (float)mJPTalgo->getSumPtWithoutEff();
153  specific.mSumEnergyOfChargedWithEff = (float)mJPTalgo->getSumEnergyWithEff();
154  specific.mSumEnergyOfChargedWithoutEff = (float)mJPTalgo->getSumEnergyWithoutEff();
155  specific.mChargedHadronEnergy = (float)mJPTalgo->getSumEnergyWithoutEff();
156 
157  // Fill Charged Jet shape parameters
158  double deR2Tr = 0.;
159  double deEta2Tr = 0.;
160  double dePhi2Tr = 0.;
161  double Zch = 0.;
162  double Pout2 = 0.;
163  double Pout = 0.;
164  double denominator_tracks = 0.;
165  int ntracks = 0;
166 
168  it++) {
169  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
170  double deEta = (*it)->eta() - p4.eta();
171  double dePhi = deltaPhi((*it)->phi(), p4.phi());
172  if ((**it).ptError() / (**it).pt() < 0.1) {
173  deR2Tr = deR2Tr + deR * deR * (*it)->pt();
174  deEta2Tr = deEta2Tr + deEta * deEta * (*it)->pt();
175  dePhi2Tr = dePhi2Tr + dePhi * dePhi * (*it)->pt();
176  denominator_tracks = denominator_tracks + (*it)->pt();
177  Zch = Zch + (*it)->pt();
178 
179  Pout2 = Pout2 + (**it).p() * (**it).p() - (Zch * p4.P()) * (Zch * p4.P());
180  ntracks++;
181  }
182  }
183 
185  it++) {
186  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
187  double deEta = (*it)->eta() - p4.eta();
188  double dePhi = deltaPhi((*it)->phi(), p4.phi());
189  if ((**it).ptError() / (**it).pt() < 0.1) {
190  deR2Tr = deR2Tr + deR * deR * (*it)->pt();
191  deEta2Tr = deEta2Tr + deEta * deEta * (*it)->pt();
192  dePhi2Tr = dePhi2Tr + dePhi * dePhi * (*it)->pt();
193  denominator_tracks = denominator_tracks + (*it)->pt();
194  Zch = Zch + (*it)->pt();
195 
196  Pout2 = Pout2 + (**it).p() * (**it).p() - (Zch * p4.P()) * (Zch * p4.P());
197  ntracks++;
198  }
199  }
201  it++) {
202  double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
203  double deEta = (*it)->eta() - p4.eta();
204  double dePhi = deltaPhi((*it)->phi(), p4.phi());
205  if ((**it).ptError() / (**it).pt() < 0.1) {
206  deR2Tr = deR2Tr + deR * deR * (*it)->pt();
207  deEta2Tr = deEta2Tr + deEta * deEta * (*it)->pt();
208  dePhi2Tr = dePhi2Tr + dePhi * dePhi * (*it)->pt();
209  denominator_tracks = denominator_tracks + (*it)->pt();
210  Zch = Zch + (*it)->pt();
211 
212  Pout2 = Pout2 + (**it).p() * (**it).p() - (Zch * p4.P()) * (Zch * p4.P());
213  ntracks++;
214  }
215  }
217  it != pions.inVertexOutOfCalo_.end();
218  it++) {
219  Zch = Zch + (*it)->pt();
220  }
222  it != muons.inVertexOutOfCalo_.end();
223  it++) {
224  Zch = Zch + (*it)->pt();
225  }
227  it != elecs.inVertexOutOfCalo_.end();
228  it++) {
229  Zch = Zch + (*it)->pt();
230  }
231 
232  if (mJPTalgo->getSumPtForBeta() > 0.)
233  Zch = Zch / mJPTalgo->getSumPtForBeta();
234 
235  // std::cout<<" Zch "<< Zch<<" "<<mJPTalgo->getSumPtForBeta()<<std::endl;
236 
237  if (ntracks > 0) {
238  Pout = sqrt(fabs(Pout2)) / ntracks;
239  }
240  if (denominator_tracks != 0) {
241  deR2Tr = deR2Tr / denominator_tracks;
242  deEta2Tr = deEta2Tr / denominator_tracks;
243  dePhi2Tr = dePhi2Tr / denominator_tracks;
244  }
245 
246  specific.R2momtr = deR2Tr;
247  specific.Eta2momtr = deEta2Tr;
248  specific.Phi2momtr = dePhi2Tr;
249  specific.Pout = Pout;
250  specific.Zch = Zch;
251 
252  // std::cout<<" Moments for charged component "<<deR2_Tr<<" "<<deEta2_Tr<<" "<<dePhi2_Tr<<std::endl;
253 
254  // Create JPT jet
255 
256  reco::Particle::Point vertex_ = reco::Jet::Point(0, 0, 0);
257 
258  // If we add primary vertex
260  iEvent.getByToken(input_vertex_token_, pvCollection);
261  if (pvCollection.isValid() && !pvCollection->empty())
262  vertex_ = pvCollection->begin()->position();
263 
264  reco::JPTJet fJet(p4, vertex_, specific, corrected.getJetConstituents());
265 
266  // fJet.printJet();
267 
268  // Output module
269  if (fJet.pt() > ptCUT)
270  pOut->push_back(fJet);
271  }
272 
273  iEvent.put(std::move(pOut));
274 }
275 
276 //define this as a plug-in
277 //DEFINE_FWK_MODULE(JetPlusTrackProducer);
reco::TrackRefVector muonsInVertexOutCalo
Definition: JPTJet.h:54
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
float mSumEnergyOfChargedWithoutEff
Definition: JPTJet.h:68
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
Jets made from CaloTowers.
Definition: CaloJet.h:27
reco::TrackRefVector muonsInVertexInCalo
Definition: JPTJet.h:53
virtual void scaleEnergy(double fScale)
scale energy of the jet
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
double px() const final
x coordinate of momentum vector
float mChargedHadronEnergy
Definition: JPTJet.h:59
float mSumPtOfChargedWithEff
Definition: JPTJet.h:65
reco::TrackRefVector inVertexInCalo_
reco::TrackRefVector muonsOutVertexInCalo
Definition: JPTJet.h:55
reco::TrackRefVector inVertexOutOfCalo_
float mResponseOfChargedWithEff
Definition: JPTJet.h:63
void produce(edm::Event &, const edm::EventSetup &) override
reco::TrackRefVector elecsOutVertexInCalo
Definition: JPTJet.h:58
virtual Constituents getJetConstituents() const
list of constituents
reco::TrackRefVector pionsInVertexOutCalo
Definition: JPTJet.h:51
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:228
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:223
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
int iEvent
Definition: GenABIO.cc:224
double pz() const final
z coordinate of momentum vector
T sqrt(T t)
Definition: SSEVec.h:19
double p4[4]
Definition: TauolaWrapper.h:92
Jets made from CaloJets corrected for ZSP and tracks.
Definition: JPTJet.h:28
reco::TrackRefVector pionsOutVertexInCalo
Definition: JPTJet.h:52
double energy() const final
energy
float mSumEnergyOfChargedWithEff
Definition: JPTJet.h:67
math::XYZPoint Point
point in the space
Definition: Particle.h:25
reco::TrackRefVector outOfVertexInCalo_
reco::TrackRefVector elecsInVertexInCalo
Definition: JPTJet.h:56
bool isValid() const
Definition: HandleBase.h:70
edm::RefToBase< reco::Jet > theCaloJetRef
Definition: JPTJet.h:49
JetPlusTrackProducer(const edm::ParameterSet &)
float mResponseOfChargedWithoutEff
Definition: JPTJet.h:64
reco::TrackRefVector pionsInVertexInCalo
Definition: JPTJet.h:50
float mSumPtOfChargedWithoutEff
Definition: JPTJet.h:66
double py() const final
y coordinate of momentum vector
reco::TrackRefVector elecsInVertexOutCalo
Definition: JPTJet.h:57
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:511
math::XYZPoint Point
point in the space
Definition: LeafCandidate.h:27