CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/RecoJets/JetPlusTracks/plugins/JetPlusTrackProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    JetPlusTracks
00004 // Class:      JetPlusTrackProducer
00005 // 
00013 //
00014 // Original Author:  Olga Kodolova,40 R-A12,+41227671273,
00015 //         Created:  Fri Feb 19 10:14:02 CET 2010
00016 // $Id: JetPlusTrackProducer.cc,v 1.8 2012/10/18 08:46:42 eulisse Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
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/JetPlusTrackProducer.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 #include <string>
00047 
00048 using namespace std;
00049 using namespace jpt;
00050 
00051 //
00052 // constants, enums and typedefs
00053 //
00054 
00055 
00056 //
00057 // static data member definitions
00058 //
00059 
00060 //
00061 // constructors and destructor
00062 //
00063 JetPlusTrackProducer::JetPlusTrackProducer(const edm::ParameterSet& iConfig)
00064 {
00065    //register your products
00066    src = iConfig.getParameter<edm::InputTag>("src");
00067    alias = iConfig.getUntrackedParameter<string>("alias");
00068    srcPVs_ = iConfig.getParameter<edm::InputTag>("srcPVs");
00069    vectorial_ = iConfig.getParameter<bool>("VectorialCorrection");
00070    useZSP = iConfig.getParameter<bool>("UseZSP");
00071    mJPTalgo  = new JetPlusTrackCorrector(iConfig);
00072    if(useZSP) mZSPalgo  = new ZSPJPTJetCorrector(iConfig);
00073  
00074    produces<reco::JPTJetCollection>().setBranchAlias(alias); 
00075    
00076 }
00077 
00078 
00079 JetPlusTrackProducer::~JetPlusTrackProducer()
00080 {
00081  
00082    // do anything here that needs to be done at desctruction time
00083    // (e.g. close files, deallocate resources etc.)
00084 
00085 }
00086 
00087 
00088 //
00089 // member functions
00090 //
00091 
00092 // ------------ method called to produce the data  ------------
00093 void
00094 JetPlusTrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00095 {
00096    using namespace edm; 
00097 
00098 
00099 //  std::cout<<" RecoJets::JetPlusTrackProducer::produce "<<std::endl;
00100 
00101 
00102 // get stuff from Event
00103   edm::Handle <edm::View <reco::CaloJet> > jets_h;
00104   iEvent.getByLabel (src, jets_h);
00105 
00106 //  std::auto_ptr<reco::CaloJetCollection> pOut(new reco::CaloJetCollection());
00107   std::auto_ptr<reco::JPTJetCollection> pOut(new reco::JPTJetCollection());
00108 
00109   for (unsigned i = 0; i < jets_h->size(); ++i) {
00110 
00111    const reco::CaloJet* oldjet = &(*(jets_h->refAt(i)));
00112    
00113    reco::CaloJet corrected = *oldjet; 
00114    
00115 // ZSP corrections    
00116 
00117    double factorZSP = 1.;
00118    if(useZSP) factorZSP = mZSPalgo->correction(corrected, iEvent, iSetup);
00119 
00120    corrected.scaleEnergy (factorZSP);
00121 
00122 // JPT corrections 
00123 
00124    double scaleJPT = 1.; 
00125 
00126    math::XYZTLorentzVector p4;
00127 
00128   jpt::MatchedTracks pions;
00129   jpt::MatchedTracks muons;
00130   jpt::MatchedTracks elecs;
00131   bool ok=false;
00132 
00133    if ( !vectorial_ ) {
00134             
00135      scaleJPT = mJPTalgo->correction ( corrected, *oldjet, iEvent, iSetup, pions, muons, elecs,ok );
00136    p4 = math::XYZTLorentzVector( corrected.px()*scaleJPT, 
00137                                  corrected.py()*scaleJPT,
00138                                  corrected.pz()*scaleJPT, 
00139                                  corrected.energy()*scaleJPT );
00140    } else {
00141      scaleJPT = mJPTalgo->correction( corrected, *oldjet, iEvent, iSetup, p4, pions, muons, elecs,ok );
00142   }         
00143 
00144    
00145   reco::JPTJet::Specific specific;
00146 
00147   if(ok) {
00148     specific.pionsInVertexInCalo = pions.inVertexInCalo_;
00149     specific.pionsInVertexOutCalo = pions.inVertexOutOfCalo_;
00150     specific.pionsOutVertexInCalo = pions.outOfVertexInCalo_;
00151     specific.muonsInVertexInCalo = muons.inVertexInCalo_;
00152     specific.muonsInVertexOutCalo = muons.inVertexOutOfCalo_;
00153     specific.muonsOutVertexInCalo = muons.outOfVertexInCalo_;
00154     specific.elecsInVertexInCalo = elecs.inVertexInCalo_;
00155     specific.elecsInVertexOutCalo = elecs.inVertexOutOfCalo_;
00156     specific.elecsOutVertexInCalo = elecs.outOfVertexInCalo_;
00157   }
00158 
00159 // Fill JPT Specific
00160     edm::RefToBase<reco::Jet> myjet = (edm::RefToBase<reco::Jet>)jets_h->refAt(i);
00161     specific.theCaloJetRef = myjet;
00162     specific.mZSPCor = factorZSP;
00163     specific.mResponseOfChargedWithEff = (float)mJPTalgo->getResponseOfChargedWithEff();
00164     specific.mResponseOfChargedWithoutEff = (float)mJPTalgo->getResponseOfChargedWithoutEff();
00165     specific.mSumPtOfChargedWithEff = (float)mJPTalgo->getSumPtWithEff();
00166     specific.mSumPtOfChargedWithoutEff = (float)mJPTalgo->getSumPtWithoutEff();
00167     specific.mSumEnergyOfChargedWithEff = (float)mJPTalgo->getSumEnergyWithEff();
00168     specific.mSumEnergyOfChargedWithoutEff = (float)mJPTalgo->getSumEnergyWithoutEff();
00169     specific.mChargedHadronEnergy = (float)mJPTalgo->getSumEnergyWithoutEff();
00170 
00171 // Fill Charged Jet shape parameters
00172    double deR2Tr = 0.;
00173    double deEta2Tr = 0.;
00174    double dePhi2Tr = 0.;
00175    double Zch = 0.;
00176    double Pout2 = 0.;
00177    double Pout = 0.;
00178    double denominator_tracks = 0.;
00179    int ntracks = 0;
00180 
00181    for( reco::TrackRefVector::const_iterator it = pions.inVertexInCalo_.begin(); it != pions.inVertexInCalo_.end(); it++) { 
00182     double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
00183     double deEta = (*it)->eta() - p4.eta();
00184     double dePhi = deltaPhi((*it)->phi(), p4.phi());
00185      if((**it).ptError()/(**it).pt() < 0.1) {
00186        deR2Tr   =  deR2Tr + deR*deR*(*it)->pt();
00187        deEta2Tr = deEta2Tr + deEta*deEta*(*it)->pt();
00188        dePhi2Tr = dePhi2Tr + dePhi*dePhi*(*it)->pt();
00189        denominator_tracks = denominator_tracks + (*it)->pt();
00190        Zch    =  Zch + (*it)->pt();
00191        
00192        Pout2 = Pout2 + (**it).p()*(**it).p() - (Zch*p4.P())*(Zch*p4.P());
00193        ntracks++;
00194      }
00195    }
00196 
00197 
00198 
00199    for( reco::TrackRefVector::const_iterator it = muons.inVertexInCalo_.begin(); it != muons.inVertexInCalo_.end(); it++) {
00200     double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
00201     double deEta = (*it)->eta() - p4.eta();
00202     double dePhi = deltaPhi((*it)->phi(), p4.phi());
00203      if((**it).ptError()/(**it).pt() < 0.1) {
00204        deR2Tr   =  deR2Tr + deR*deR*(*it)->pt();
00205        deEta2Tr = deEta2Tr + deEta*deEta*(*it)->pt();
00206        dePhi2Tr = dePhi2Tr + dePhi*dePhi*(*it)->pt();
00207        denominator_tracks = denominator_tracks + (*it)->pt();
00208        Zch    = Zch + (*it)->pt();
00209        
00210        Pout2 = Pout2 + (**it).p()*(**it).p() - (Zch*p4.P())*(Zch*p4.P());
00211        ntracks++;
00212      }
00213    }
00214    for( reco::TrackRefVector::const_iterator it = elecs.inVertexInCalo_.begin(); it != elecs.inVertexInCalo_.end(); it++) {
00215     double deR = deltaR((*it)->eta(), (*it)->phi(), p4.eta(), p4.phi());
00216     double deEta = (*it)->eta() - p4.eta();
00217     double dePhi = deltaPhi((*it)->phi(), p4.phi());
00218      if((**it).ptError()/(**it).pt() < 0.1) {
00219        deR2Tr   =  deR2Tr + deR*deR*(*it)->pt();
00220        deEta2Tr = deEta2Tr + deEta*deEta*(*it)->pt();
00221        dePhi2Tr = dePhi2Tr + dePhi*dePhi*(*it)->pt();
00222        denominator_tracks = denominator_tracks + (*it)->pt();
00223        Zch    = Zch + (*it)->pt();
00224        
00225        Pout2 = Pout2 + (**it).p()*(**it).p() - (Zch*p4.P())*(Zch*p4.P());
00226        ntracks++;
00227      }
00228    }
00229    for( reco::TrackRefVector::const_iterator it = pions.inVertexOutOfCalo_.begin(); it != pions.inVertexOutOfCalo_.end(); it++) { 
00230      Zch    =  Zch + (*it)->pt();
00231    }
00232    for( reco::TrackRefVector::const_iterator it = muons.inVertexOutOfCalo_.begin(); it != muons.inVertexOutOfCalo_.end(); it++) { 
00233      Zch    =  Zch + (*it)->pt();
00234    }
00235    for( reco::TrackRefVector::const_iterator it = elecs.inVertexOutOfCalo_.begin(); it != elecs.inVertexOutOfCalo_.end(); it++) { 
00236      Zch    =  Zch + (*it)->pt();
00237    }
00238 
00239      if(mJPTalgo->getSumPtForBeta()> 0.) Zch = Zch/mJPTalgo->getSumPtForBeta();
00240 
00241 //     std::cout<<" Zch "<< Zch<<" "<<mJPTalgo->getSumPtForBeta()<<std::endl;
00242 
00243         if(ntracks > 0) {
00244           Pout   = sqrt(fabs(Pout2))/ntracks;          
00245         }
00246           if (denominator_tracks!=0){
00247             deR2Tr  = deR2Tr/denominator_tracks;
00248             deEta2Tr= deEta2Tr/denominator_tracks;
00249             dePhi2Tr= dePhi2Tr/denominator_tracks;
00250           }
00251    
00252       specific.R2momtr = deR2Tr;
00253       specific.Eta2momtr = deEta2Tr;
00254       specific.Phi2momtr = dePhi2Tr;
00255       specific.Pout = Pout;
00256       specific.Zch = Zch;
00257 
00258 
00259 //       std::cout<<" Moments for charged component "<<deR2_Tr<<" "<<deEta2_Tr<<" "<<dePhi2_Tr<<std::endl;
00260 
00261 
00262 // Create JPT jet
00263 
00264    reco::Particle::Point vertex_=reco::Jet::Point(0,0,0);
00265    
00266 // If we add primary vertex
00267    edm::Handle<reco::VertexCollection> pvCollection;
00268    iEvent.getByLabel(srcPVs_,pvCollection);
00269    if ( pvCollection.isValid() && pvCollection->size()>0 ) vertex_=pvCollection->begin()->position();
00270 
00271    reco::JPTJet fJet(p4, vertex_, specific, corrected.getJetConstituents()); 
00272 
00273    //   fJet.printJet();
00274 
00275 // Output module
00276     pOut->push_back(fJet); 
00277           
00278   }
00279   
00280   iEvent.put(pOut);
00281    
00282 }
00283 
00284 // ------------ method called once each job just before starting event loop  ------------
00285 void 
00286 JetPlusTrackProducer::beginJob()
00287 {
00288 }
00289 
00290 // ------------ method called once each job just after ending the event loop  ------------
00291 void 
00292 JetPlusTrackProducer::endJob() {
00293 }
00294 
00295 //define this as a plug-in
00296 //DEFINE_FWK_MODULE(JetPlusTrackProducer);