CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/ElectroWeakAnalysis/Skimming/plugins/ZMuMuTrackUserData.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/EDProducer.h"
00002 #include "FWCore/Utilities/interface/InputTag.h"
00003 #include "DataFormats/Common/interface/Handle.h"
00004 #include "FWCore/Framework/interface/Event.h"
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 #include "DataFormats/PatCandidates/interface/GenericParticle.h"
00007 #include "FWCore/Utilities/interface/EDMException.h"
00008 
00009 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
00010 #include "DataFormats/RecoCandidate/interface/IsoDepositFwd.h"
00011 #include "DataFormats/PatCandidates/interface/Isolation.h"
00012 #include "DataFormats/RecoCandidate/interface/IsoDepositVetos.h"
00013 #include "DataFormats/RecoCandidate/interface/IsoDepositDirection.h"
00014 
00015 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00016 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00017 #include "DataFormats/VertexReco/interface/Vertex.h"
00018 
00019 #include <vector>
00020 
00021 using namespace edm;
00022 using namespace std;
00023 using namespace reco;
00024 using namespace isodeposit;
00025 //using namespace pat;
00026 
00027 class ZMuMuTrackUserData : public edm::EDProducer {
00028 public:
00029   ZMuMuTrackUserData( const edm::ParameterSet & );   
00030 private:
00031   void produce( edm::Event &, const edm::EventSetup & );
00032   
00033   InputTag src_,beamSpot_, primaryVertices_;
00034   double ptThreshold_, etEcalThreshold_, etHcalThreshold_ ,dRVetoTrk_, dRTrk_, dREcal_ , dRHcal_;
00035   double alpha_, beta_; 
00036   template<typename T>
00037   vector<double> isolation(const T & t, double ptThreshold, double etEcalThreshold, double etHcalThreshold , double dRVetoTrk, double dRTrk, double dREcal , double dRHcal,  double alpha, double beta);
00038 
00039 };
00040 
00041 template<typename T>
00042 vector<double> ZMuMuTrackUserData::isolation(const T & t, double ptThreshold, double etEcalThreshold, double etHcalThreshold , double dRVetoTrk, double dRTrk, double dREcal , double dRHcal,  double alpha, double beta) {
00043 
00044   vector<double> iso;
00045   const pat::IsoDeposit * trkIso = t.isoDeposit(pat::TrackIso);
00046   const pat::IsoDeposit * ecalIso = t.isoDeposit(pat::EcalIso);
00047   const pat::IsoDeposit * hcalIso = t.isoDeposit(pat::HcalIso);  
00048   
00049   Direction dir = Direction(t.eta(), t.phi());
00050 
00051    
00052   pat::IsoDeposit::AbsVetos vetosTrk;
00053   vetosTrk.push_back(new ConeVeto( dir, dRVetoTrk ));
00054   vetosTrk.push_back(new ThresholdVeto( ptThreshold ));
00055   
00056   pat::IsoDeposit::AbsVetos vetosEcal;
00057   vetosEcal.push_back(new ConeVeto( dir, 0.));
00058   vetosEcal.push_back(new ThresholdVeto( etEcalThreshold ));
00059   
00060   pat::IsoDeposit::AbsVetos vetosHcal;
00061   vetosHcal.push_back(new ConeVeto( dir, 0. ));
00062   vetosHcal.push_back(new ThresholdVeto( etHcalThreshold ));
00063   
00064   double isovalueTrk = (trkIso->sumWithin(dRTrk,vetosTrk));
00065   double isovalueEcal = (ecalIso->sumWithin(dREcal,vetosEcal));
00066   double isovalueHcal = (hcalIso->sumWithin(dRHcal,vetosHcal));
00067 
00068   iso.push_back(isovalueTrk);
00069   iso.push_back(isovalueEcal);
00070   iso.push_back(isovalueHcal);
00071 
00072   //double iso =  isovalueTrk + isovalueEcal + isovalueHcal;
00073   double combIso = alpha*( ((1+beta)/2*isovalueEcal) + ((1-beta)/2*isovalueHcal) ) + ((1-alpha)*isovalueTrk);
00074  
00075   iso.push_back(combIso);
00076   double relIso = combIso /= t.pt();
00077   iso.push_back(relIso);
00078   return iso;
00079 }
00080 
00081 ZMuMuTrackUserData::ZMuMuTrackUserData( const ParameterSet & cfg ):
00082   src_( cfg.getParameter<InputTag>( "src" ) ),
00083   beamSpot_(cfg.getParameter<InputTag>( "beamSpot" ) ),
00084   primaryVertices_(cfg.getParameter<InputTag>( "primaryVertices" ) ),
00085   ptThreshold_(cfg.getParameter<double >("ptThreshold") ),
00086   etEcalThreshold_(cfg.getParameter<double >("etEcalThreshold") ),
00087   etHcalThreshold_(cfg.getParameter<double >("etHcalThreshold") ),
00088   dRVetoTrk_(cfg.getParameter<double >("dRVetoTrk") ),
00089   dRTrk_(cfg.getParameter<double >("dRTrk") ),
00090   dREcal_(cfg.getParameter<double >("dREcal") ),
00091   dRHcal_(cfg.getParameter<double >("dRHcal") ),
00092   alpha_(cfg.getParameter<double>("alpha") ),
00093   beta_(cfg.getParameter<double>("beta") ){
00094   produces<std::vector<pat::GenericParticle> >();
00095 }
00096 
00097 void ZMuMuTrackUserData::produce( Event & evt, const EventSetup & ) {
00098   Handle<vector<pat::GenericParticle>  > tracks;
00099   evt.getByLabel(src_,tracks);
00100 
00101   Handle<BeamSpot> beamSpotHandle;
00102   evt.getByLabel(beamSpot_, beamSpotHandle);
00103   
00104 
00105   Handle<VertexCollection> primaryVertices;  // Collection of primary Vertices
00106   evt.getByLabel(primaryVertices_, primaryVertices);
00107   
00108   auto_ptr<vector<pat::GenericParticle> > tkColl( new vector<pat::GenericParticle> (*tracks) );
00109   for (unsigned int i = 0; i< tkColl->size();++i){
00110     pat::GenericParticle & tk = (*tkColl)[i];
00111     vector<double> iso = isolation(tk,ptThreshold_, etEcalThreshold_, etHcalThreshold_ ,dRVetoTrk_, dRTrk_, dREcal_ , dRHcal_, alpha_, beta_);
00112     tk.setIsolation(pat::User1Iso, iso[0]);
00113     //    cout << "track User1Iso " << iso[0] << endl; 
00114     tk.setIsolation(pat::User2Iso, iso[1]);
00115     //cout << "track User2Iso " << iso[1] << endl; 
00116     tk.setIsolation(pat::User3Iso, iso[2]);
00117     //cout << "track User3Iso " << iso[2] << endl; 
00118     tk.setIsolation(pat::User4Iso, iso[3]);
00119     //cout << "track User4Iso " << iso[3] << endl; 
00120     tk.setIsolation(pat::User5Iso, iso[4]);
00121     //cout << "track User5Iso " << iso[4] << endl; 
00122   
00123     
00124 
00125     float zDaudxyFromBS = -1 ;
00126     float zDaudzFromBS = -1;
00127     float zDaudxyFromPV = -1;
00128     float zDaudzFromPV = -1;    
00129     float zDauNofMuChambers = -1;
00130     float zDauNofMuMatches = -1;
00131     float zDauChi2 = -1;
00132     float zDauTrkChi2 = -1;
00133     float zDauSaChi2 = -1;
00134     float zDauNofMuonHits =- 1;
00135     float zDauNofStripHits = -1;
00136     float zDauNofPixelHits = -1;
00137     float zDauMuEnergyEm = -1;
00138     float zDauMuEnergyHad = -1;
00139 
00140     TrackRef muTrkRef = tk.track();
00141     if (muTrkRef.isNonnull()){ 
00142       zDaudxyFromBS = muTrkRef->dxy(beamSpotHandle->position());
00143       zDaudzFromBS = muTrkRef->dz(beamSpotHandle->position());
00144       zDaudxyFromPV = muTrkRef->dxy(primaryVertices->begin()->position() );
00145       zDaudzFromPV = muTrkRef->dz(primaryVertices->begin()->position() );       
00146       zDauChi2 = muTrkRef->normalizedChi2();
00147       zDauTrkChi2 = muTrkRef->normalizedChi2();
00148       zDauNofStripHits = muTrkRef->hitPattern().numberOfValidStripHits();
00149       zDauNofPixelHits = muTrkRef->hitPattern().numberOfValidPixelHits();
00150     }
00151     tk.addUserFloat("zDau_dxyFromBS", zDaudxyFromBS);
00152     tk.addUserFloat("zDau_dzFromBS", zDaudzFromBS);
00153     tk.addUserFloat("zDau_dxyFromPV", zDaudxyFromPV);
00154     tk.addUserFloat("zDau_dzFromPV", zDaudzFromPV);
00155     tk.addUserFloat("zDau_NofMuonHits" , zDauNofMuonHits ); 
00156     tk.addUserFloat("zDau_TrkNofStripHits" , zDauNofStripHits ); 
00157     tk.addUserFloat("zDau_TrkNofPixelHits" , zDauNofPixelHits ); 
00158     tk.addUserFloat("zDau_NofMuChambers", zDauNofMuChambers);
00159     tk.addUserFloat("zDau_NofMuMatches", zDauNofMuMatches);
00160     tk.addUserFloat("zDau_Chi2", zDauChi2);
00161     tk.addUserFloat("zDau_TrkChi2", zDauTrkChi2);
00162     tk.addUserFloat("zDau_SaChi2", zDauSaChi2);
00163     tk.addUserFloat("zDau_MuEnergyEm", zDauMuEnergyEm);
00164     tk.addUserFloat("zDau_MuEnergyHad", zDauMuEnergyHad);
00165 
00166 
00167   }
00168 
00169   evt.put( tkColl);
00170 }
00171 
00172 #include "FWCore/Framework/interface/MakerMacros.h"
00173 
00174 DEFINE_FWK_MODULE( ZMuMuTrackUserData );
00175