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 
184  for (reco::TrackRefVector::const_iterator it = muons.inVertexInCalo_.begin(); it != muons.inVertexInCalo_.end();
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  }
200  for (reco::TrackRefVector::const_iterator it = elecs.inVertexInCalo_.begin(); it != elecs.inVertexInCalo_.end();
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  }
221  for (reco::TrackRefVector::const_iterator it = muons.inVertexOutOfCalo_.begin();
222  it != muons.inVertexOutOfCalo_.end();
223  it++) {
224  Zch = Zch + (*it)->pt();
225  }
226  for (reco::TrackRefVector::const_iterator it = elecs.inVertexOutOfCalo_.begin();
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::JPTJet
Jets made from CaloJets corrected for ZSP and tracks.
Definition: JPTJet.h:28
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
CaloJetCollection.h
reco::CaloJet
Jets made from CaloTowers.
Definition: CaloJet.h:27
reco::Jet::scaleEnergy
virtual void scaleEnergy(double fScale)
scale energy of the jet
CaloJet.h
mps_fire.i
i
Definition: mps_fire.py:355
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
reco::LeafCandidate::Point
math::XYZPoint Point
point in the space
Definition: LeafCandidate.h:27
RecoJPTJets_cff.ptCUT
ptCUT
Definition: RecoJPTJets_cff.py:3
jpt::MatchedTracks::inVertexOutOfCalo_
reco::TrackRefVector inVertexOutOfCalo_
Definition: JetPlusTrackCorrector.h:148
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::RefVector::begin
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:223
Jet.h
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
jpt::MatchedTracks::inVertexInCalo_
reco::TrackRefVector inVertexInCalo_
Definition: JetPlusTrackCorrector.h:146
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
edm::Handle
Definition: AssociativeIterator.h:50
ZSPJPTJetCorrector
Definition: ZSPJPTJetCorrector.h:21
JetPlusTrackProducer.h
jpt::MatchedTracks
Particles matched to tracks that are in/in, in/out, out/in at Vertex and CaloFace.
Definition: JetPlusTrackCorrector.h:141
deltaR.h
MakerMacros.h
edm::RefVector::end
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:228
JetPlusTrackProducer::~JetPlusTrackProducer
~JetPlusTrackProducer() override
Definition: JetPlusTrackProducer.cc:75
Track.h
TrackFwd.h
SiPixelRawToDigiRegional_cfi.deltaPhi
deltaPhi
Definition: SiPixelRawToDigiRegional_cfi.py:9
reco::LeafCandidate::py
double py() const final
y coordinate of momentum vector
Definition: LeafCandidate.h:142
timingPdfMaker.specific
specific
Definition: timingPdfMaker.py:78
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
reco::Jet::getJetConstituents
virtual Constituents getJetConstituents() const
list of constituents
singleTopDQM_cfi.elecs
elecs
Definition: singleTopDQM_cfi.py:41
jpt
Definition: JetPlusTrackCorrector.h:37
anotherprimaryvertexanalyzer_cfi.pvCollection
pvCollection
Definition: anotherprimaryvertexanalyzer_cfi.py:4
JPTJetCollection.h
reco::JPTJet::Specific
Definition: JPTJet.h:30
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
Vertex.h
edm::ParameterSet
Definition: ParameterSet.h:36
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
JetPlusTrackCorrector
Jet energy correction algorithm using tracks.
Definition: JetPlusTrackCorrector.h:168
iEvent
int iEvent
Definition: GenABIO.cc:224
p4
double p4[4]
Definition: TauolaWrapper.h:92
edm::EventSetup
Definition: EventSetup.h:57
VertexFwd.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
jpt::MatchedTracks::outOfVertexInCalo_
reco::TrackRefVector outOfVertexInCalo_
Definition: JetPlusTrackCorrector.h:147
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
SiStripOfflineCRack_cfg.alias
alias
Definition: SiStripOfflineCRack_cfg.py:129
edm::RefVectorIterator
Definition: EDProductfwd.h:33
edm::RefToBase< reco::Jet >
reco::LeafCandidate::energy
double energy() const final
energy
Definition: LeafCandidate.h:125
reco::Particle::Point
math::XYZPoint Point
point in the space
Definition: Particle.h:25
ParameterSet.h
edm::Event
Definition: Event.h:73
reco::LeafCandidate::px
double px() const final
x coordinate of momentum vector
Definition: LeafCandidate.h:140
reco::LeafCandidate::pz
double pz() const final
z coordinate of momentum vector
Definition: LeafCandidate.h:144
edm::InputTag
Definition: InputTag.h:15
deltaPhi.h
JPTJet.h
JetPlusTrackProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: JetPlusTrackProducer.cc:85
JetPlusTrackProducer::JetPlusTrackProducer
JetPlusTrackProducer(const edm::ParameterSet &)
Definition: JetPlusTrackProducer.cc:57