00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <memory>
00023
00024
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDProducer.h"
00027
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032
00033 #include "RecoJets/JetPlusTracks/plugins/JetPlusTrackProducerAA.h"
00034 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00035 #include "DataFormats/JetReco/interface/CaloJet.h"
00036 #include "DataFormats/JetReco/interface/JPTJetCollection.h"
00037 #include "DataFormats/JetReco/interface/JPTJet.h"
00038 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00039 #include "DataFormats/TrackReco/interface/Track.h"
00040 #include "DataFormats/JetReco/interface/Jet.h"
00041 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00042 #include "DataFormats/VertexReco/interface/Vertex.h"
00043 #include "DataFormats/Math/interface/deltaPhi.h"
00044 #include "DataFormats/Math/interface/deltaR.h"
00045
00046
00047 #include "RecoJets/JetAssociationAlgorithms/interface/JetTracksAssociationXtrpCalo.h"
00048 #include "DataFormats/GeometrySurface/interface/Cylinder.h"
00049 #include "DataFormats/GeometrySurface/interface/Plane.h"
00050 #include "DataFormats/Math/interface/deltaR.h"
00051 #include "DataFormats/Math/interface/Vector3D.h"
00052 #include "MagneticField/Engine/interface/MagneticField.h"
00053 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
00054 #include "TrackingTools/TrajectoryParametrization/interface/GlobalTrajectoryParameters.h"
00055 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
00056 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00057 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00058 #include "DataFormats/DetId/interface/DetId.h"
00059 #include "DataFormats/JetReco/interface/CaloJet.h"
00060 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00061
00062
00063 #include <string>
00064
00065 using namespace std;
00066 using namespace jpt;
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 JetPlusTrackProducerAA::JetPlusTrackProducerAA(const edm::ParameterSet& iConfig)
00081 {
00082
00083 src = iConfig.getParameter<edm::InputTag>("src");
00084 alias = iConfig.getUntrackedParameter<string>("alias");
00085 mTracks = iConfig.getParameter<edm::InputTag> ("tracks");
00086 srcPVs_ = iConfig.getParameter<edm::InputTag>("srcPVs");
00087 vectorial_ = iConfig.getParameter<bool>("VectorialCorrection");
00088 useZSP = iConfig.getParameter<bool>("UseZSP");
00089 std::string tq = iConfig.getParameter<std::string>("TrackQuality");
00090 trackQuality_ = reco::TrackBase::qualityByName(tq);
00091 mConeSize = iConfig.getParameter<double> ("coneSize");
00092
00093 mExtrapolations = iConfig.getParameter<edm::InputTag> ("extrapolations");
00094
00095 mJPTalgo = new JetPlusTrackCorrector(iConfig);
00096 mZSPalgo = new ZSPJPTJetCorrector(iConfig);
00097
00098 produces<reco::JPTJetCollection>().setBranchAlias(alias);
00099
00100 }
00101
00102
00103 JetPlusTrackProducerAA::~JetPlusTrackProducerAA()
00104 {
00105
00106
00107
00108
00109 }
00110
00111
00112
00113
00114
00115
00116
00117 void
00118 JetPlusTrackProducerAA::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00119 {
00120 using namespace edm;
00121
00122
00123
00124
00125
00126 edm::Handle <edm::View <reco::CaloJet> > jets_h;
00127 iEvent.getByLabel (src, jets_h);
00128
00129 edm::Handle <reco::TrackCollection> tracks_h;
00130 iEvent.getByLabel (mTracks, tracks_h);
00131
00132 std::vector <reco::TrackRef> fTracks;
00133 fTracks.reserve (tracks_h->size());
00134 for (unsigned i = 0; i < tracks_h->size(); ++i) {
00135 fTracks.push_back (reco::TrackRef (tracks_h, i));
00136 }
00137
00138
00139 edm::Handle <std::vector<reco::TrackExtrapolation> > extrapolations_h;
00140 iEvent.getByLabel (mExtrapolations, extrapolations_h);
00141
00142
00143
00144
00145 std::auto_ptr<reco::JPTJetCollection> pOut(new reco::JPTJetCollection());
00146
00147 reco::JPTJetCollection tmpColl;
00148
00149 for (unsigned i = 0; i < jets_h->size(); ++i) {
00150
00151 const reco::CaloJet* oldjet = &(*(jets_h->refAt(i)));
00152
00153 reco::CaloJet corrected = *oldjet;
00154
00155
00156
00157 double factorZSP = 1.;
00158 if(useZSP) factorZSP = mZSPalgo->correction(corrected, iEvent, iSetup);
00159
00160
00161
00162
00163 corrected.scaleEnergy (factorZSP);
00164
00165
00166
00167 double scaleJPT = 1.;
00168
00169 math::XYZTLorentzVector p4;
00170
00171 if ( !vectorial_ ) {
00172
00173 scaleJPT = mJPTalgo->correction ( corrected, *oldjet, iEvent, iSetup );
00174 p4 = math::XYZTLorentzVector( corrected.px()*scaleJPT,
00175 corrected.py()*scaleJPT,
00176 corrected.pz()*scaleJPT,
00177 corrected.energy()*scaleJPT );
00178 } else {
00179 scaleJPT = mJPTalgo->correction( corrected, *oldjet, iEvent, iSetup, p4 );
00180 }
00181
00182
00183 jpt::MatchedTracks pions;
00184 jpt::MatchedTracks muons;
00185 jpt::MatchedTracks elecs;
00186
00187 bool ok = mJPTalgo->matchTracks( *oldjet,
00188 iEvent,
00189 iSetup,
00190 pions,
00191 muons,
00192 elecs );
00193
00194
00195 reco::JPTJet::Specific specific;
00196
00197 if(ok) {
00198
00199
00200
00201
00202
00203 specific.pionsInVertexInCalo = pions.inVertexInCalo_;
00204 specific.pionsInVertexOutCalo = pions.inVertexOutOfCalo_;
00205 specific.pionsOutVertexInCalo = pions.outOfVertexInCalo_;
00206 specific.muonsInVertexInCalo = muons.inVertexInCalo_;
00207 specific.muonsInVertexOutCalo = muons.inVertexOutOfCalo_;
00208 specific.muonsOutVertexInCalo = muons.outOfVertexInCalo_;
00209 specific.elecsInVertexInCalo = elecs.inVertexInCalo_;
00210 specific.elecsInVertexOutCalo = elecs.inVertexOutOfCalo_;
00211 specific.elecsOutVertexInCalo = elecs.outOfVertexInCalo_;
00212 }
00213
00214
00215 edm::RefToBase<reco::Jet> myjet = (edm::RefToBase<reco::Jet>)jets_h->refAt(i);
00216 specific.theCaloJetRef = myjet;
00217 specific.mZSPCor = factorZSP;
00218 specific.mResponseOfChargedWithEff = (float)mJPTalgo->getResponseOfChargedWithEff();
00219 specific.mResponseOfChargedWithoutEff = (float)mJPTalgo->getResponseOfChargedWithoutEff();
00220 specific.mSumPtOfChargedWithEff = (float)mJPTalgo->getSumPtWithEff();
00221 specific.mSumPtOfChargedWithoutEff = (float)mJPTalgo->getSumPtWithoutEff();
00222 specific.mSumEnergyOfChargedWithEff = (float)mJPTalgo->getSumEnergyWithEff();
00223 specific.mSumEnergyOfChargedWithoutEff = (float)mJPTalgo->getSumEnergyWithoutEff();
00224 specific.mChargedHadronEnergy = (float)mJPTalgo->getSumEnergyWithoutEff();
00225
00226 double deR2Tr = 0.;
00227 double deEta2Tr = 0.;
00228 double dePhi2Tr = 0.;
00229 double Zch = 0.;
00230 double Pout2 = 0.;
00231 double Pout = 0.;
00232 double denominator_tracks = 0.;
00233 int ntracks = 0;
00234
00235 for( reco::TrackRefVector::const_iterator it = pions.inVertexInCalo_.begin(); it != pions.inVertexInCalo_.end(); it++) {
00236 double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
00237 double deEta = (*it)->eta() - p4.eta();
00238 double dePhi = deltaPhi((*it)->phi(), p4.phi());
00239 if((**it).ptError()/(**it).pt() < 0.1) {
00240 deR2Tr = deR2Tr + deR*deR*(*it)->pt();
00241 deEta2Tr = deEta2Tr + deEta*deEta*(*it)->pt();
00242 dePhi2Tr = dePhi2Tr + dePhi*dePhi*(*it)->pt();
00243 denominator_tracks = denominator_tracks + (*it)->pt();
00244 Zch = Zch +
00245 ((*it)->px()*p4.Px()+(*it)->py()*p4.Py()+(*it)->pz()*p4.Pz())/(p4.P()*p4.P());
00246 Pout2 = Pout2 + (**it).p()*(**it).p() - (Zch*p4.P())*(Zch*p4.P());
00247 ntracks++;
00248 }
00249 }
00250 for( reco::TrackRefVector::const_iterator it = muons.inVertexInCalo_.begin(); it != muons.inVertexInCalo_.end(); it++) {
00251 double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
00252 double deEta = (*it)->eta() - p4.eta();
00253 double dePhi = deltaPhi((*it)->phi(), p4.phi());
00254 if((**it).ptError()/(**it).pt() < 0.1) {
00255 deR2Tr = deR2Tr + deR*deR*(*it)->pt();
00256 deEta2Tr = deEta2Tr + deEta*deEta*(*it)->pt();
00257 dePhi2Tr = dePhi2Tr + dePhi*dePhi*(*it)->pt();
00258 denominator_tracks = denominator_tracks + (*it)->pt();
00259 Zch = Zch +
00260 ((*it)->px()*p4.Px()+(*it)->py()*p4.Py()+(*it)->pz()*p4.Pz())/(p4.P()*p4.P());
00261 Pout2 = Pout2 + (**it).p()*(**it).p() - (Zch*p4.P())*(Zch*p4.P());
00262 ntracks++;
00263 }
00264 }
00265 for( reco::TrackRefVector::const_iterator it = elecs.inVertexInCalo_.begin(); it != elecs.inVertexInCalo_.end(); it++) {
00266 double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
00267 double deEta = (*it)->eta() - p4.eta();
00268 double dePhi = deltaPhi((*it)->phi(), p4.phi());
00269 if((**it).ptError()/(**it).pt() < 0.1) {
00270 deR2Tr = deR2Tr + deR*deR*(*it)->pt();
00271 deEta2Tr = deEta2Tr + deEta*deEta*(*it)->pt();
00272 dePhi2Tr = dePhi2Tr + dePhi*dePhi*(*it)->pt();
00273 denominator_tracks = denominator_tracks + (*it)->pt();
00274 Zch = Zch +
00275 ((*it)->px()*p4.Px()+(*it)->py()*p4.Py()+(*it)->pz()*p4.Pz())/(p4.P()*p4.P());
00276 Pout2 = Pout2 + (**it).p()*(**it).p() - (Zch*p4.P())*(Zch*p4.P());
00277 ntracks++;
00278 }
00279 }
00280
00281 if(ntracks > 0) {
00282 Pout = sqrt(fabs(Pout2))/ntracks;
00283 Zch = Zch/ntracks;
00284 }
00285
00286
00287 if (denominator_tracks!=0){
00288 deR2Tr = deR2Tr/denominator_tracks;
00289 deEta2Tr= deEta2Tr/denominator_tracks;
00290 dePhi2Tr= dePhi2Tr/denominator_tracks;
00291 }
00292
00293 specific.R2momtr = deR2Tr;
00294 specific.Eta2momtr = deEta2Tr;
00295 specific.Phi2momtr = dePhi2Tr;
00296 specific.Pout = Pout;
00297 specific.Zch = Zch;
00298
00299
00300
00301 reco::Particle::Point vertex_=reco::Jet::Point(0,0,0);
00302
00303
00304 edm::Handle<reco::VertexCollection> pvCollection;
00305 iEvent.getByLabel(srcPVs_,pvCollection);
00306 if ( pvCollection.isValid() && pvCollection->size()>0 ) vertex_=pvCollection->begin()->position();
00307
00308 reco::JPTJet fJet(p4, vertex_, specific, corrected.getJetConstituents());
00309
00310
00311
00312
00313 tmpColl.push_back(fJet);
00314
00315 }
00316
00317
00318
00319
00320 reco::TrackRefVector trBgOutOfCalo;
00321 reco::TrackRefVector trBgOutOfVertex = calculateBGtracksJet(tmpColl,fTracks,extrapolations_h,trBgOutOfCalo);
00322
00323
00324 std::map<reco::JPTJetCollection::iterator, double> AreaNonJet;
00325
00326 for(reco::JPTJetCollection::iterator ij1=tmpColl.begin(); ij1!=tmpColl.end(); ij1++)
00327 {
00328 int nj1 = 1;
00329 for(reco::JPTJetCollection::iterator ij2=tmpColl.begin(); ij2!=tmpColl.end(); ij2++)
00330 {
00331 if(ij2 == ij1) continue;
00332 if(fabs((*ij1).eta() - (*ij2).eta()) > 0.5 ) continue;
00333 nj1++;
00334
00335 }
00336
00337 AreaNonJet[ij1] = 4*M_PI*mConeSize - nj1*4*mConeSize*mConeSize;
00338
00339
00340 }
00341
00342
00343
00344
00345
00346
00347
00348
00349 for(reco::JPTJetCollection::iterator ij=tmpColl.begin(); ij!=tmpColl.end(); ij++)
00350 {
00351
00352
00353 const reco::TrackRefVector pioninin = (*ij).getPionsInVertexInCalo();
00354 const reco::TrackRefVector pioninout = (*ij).getPionsInVertexOutCalo();
00355
00356 double ja = (AreaNonJet.find(ij))->second;
00357
00358
00359
00360 double factorPU = mJPTalgo->correctAA(*ij,trBgOutOfVertex,mConeSize,pioninin,pioninout,ja,trBgOutOfCalo);
00361
00362 (*ij).scaleEnergy (factorPU);
00363
00364
00365
00366
00367 pOut->push_back(*ij);
00368
00369
00370
00371 }
00372
00373 iEvent.put(pOut);
00374
00375 }
00376
00377
00378
00379
00380 reco::TrackRefVector JetPlusTrackProducerAA::calculateBGtracksJet(reco::JPTJetCollection& fJets, std::vector <reco::TrackRef>& fTracks,
00381 edm::Handle <std::vector<reco::TrackExtrapolation> > & extrapolations_h,
00382 reco::TrackRefVector& trBgOutOfCalo){
00383
00384
00385 reco::TrackRefVector trBgOutOfVertex;
00386
00387 for (unsigned t = 0; t < fTracks.size(); ++t) {
00388
00389 int track_bg = 0;
00390
00391
00392
00393
00394
00395
00396
00397 const reco::Track* track = &*(fTracks[t]);
00398 double trackEta = track->eta();
00399 double trackPhi = track->phi();
00400
00401
00402
00403
00404
00405 for (unsigned j = 0; j < fJets.size(); ++j) {
00406
00407 const reco::Jet* jet = &(fJets[j]);
00408 double jetEta = jet->eta();
00409 double jetPhi = jet->phi();
00410
00411
00412
00413
00414 if(fabs(jetEta - trackEta) < mConeSize) {
00415 double dphiTrackJet = fabs(trackPhi - jetPhi);
00416 if(dphiTrackJet > M_PI) dphiTrackJet = 2*M_PI - dphiTrackJet;
00417
00418 if(dphiTrackJet < mConeSize)
00419 {
00420 track_bg = 1;
00421
00422
00423
00424 }
00425 }
00426 }
00427
00428 if( track_bg == 0 )
00429 {
00430 trBgOutOfVertex.push_back (fTracks[t]);
00431
00432
00433
00434 }
00435
00436 }
00437
00438
00439 int nValid = 0;
00440 for ( std::vector<reco::TrackExtrapolation>::const_iterator xtrpBegin = extrapolations_h->begin(),
00441 xtrpEnd = extrapolations_h->end(), ixtrp = xtrpBegin;
00442 ixtrp != xtrpEnd; ++ixtrp ) {
00443
00444
00445
00446
00447
00448
00449
00450 nValid++;
00451
00452 reco::TrackRefVector::iterator it = find(trBgOutOfVertex.begin(),trBgOutOfVertex.end(),(*ixtrp).track() );
00453
00454 if ( it != trBgOutOfVertex.end() ){
00455 trBgOutOfCalo.push_back (*it);
00456
00457
00458
00459 }
00460
00461 }
00462
00463
00464
00465
00466
00467 return trBgOutOfVertex;
00468 }
00469
00470 void
00471 JetPlusTrackProducerAA::beginJob()
00472 {
00473 }
00474
00475
00476 void
00477 JetPlusTrackProducerAA::endJob() {
00478 }
00479
00480
00481