CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/JetMETCorrections/JetVertexAssociation/src/JetVertexMain.cc

Go to the documentation of this file.
00001 
00002 #include "JetMETCorrections/JetVertexAssociation/interface/JetVertexMain.h"
00003 #include "DataFormats/JetReco/interface/CaloJet.h"
00004 #include "DataFormats/TrackReco/interface/Track.h"
00005 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include <cmath>
00008 #include <string>
00009 using namespace reco;
00010 using namespace edm;
00011 
00012 JetVertexMain::JetVertexMain(const ParameterSet & parameters) {
00013 
00014   cutSigmaZ = parameters.getParameter<double>("JV_sigmaZ");
00015   cutDeltaZ = parameters.getParameter<double>("JV_deltaZ");
00016   threshold = parameters.getParameter<double>("JV_alpha_threshold");
00017   cone_size = parameters.getParameter<double>("JV_cone_size");
00018   Algo =  parameters.getParameter<int>("JV_type_Algo");
00019   cutType = parameters.getParameter<std::string>("JV_cutType");
00020 
00021 }
00022 
00023 
00024 std::pair<double,bool> JetVertexMain::Main(const reco::CaloJet& jet, edm::Handle<TrackCollection> tracks,
00025                                            double signal_vert_Z,  double signal_vert_z_error){
00026 
00027   std::pair<double, bool> parameter; 
00028  
00029   double jet_et = jet.et();
00030   double jet_phi = jet.phi();
00031   double jet_eta = jet.eta();
00032 
00033   //  cout<<"JET: "<<jet_et<<endl;
00034   double Pt_jets_X = 0. ;
00035   double Pt_jets_Y = 0. ;
00036   double Pt_jets_X_tot = 0. ;
00037   double Pt_jets_Y_tot = 0. ;
00038 
00039   TrackCollection::const_iterator track = tracks->begin ();
00040 
00041   if (tracks->size() > 0 )   { 
00042    for (; track != tracks->end (); track++) {
00043      double Vertex_Z = track->vz();
00044      double Vertex_Z_Error = track->dzError();
00045      double track_eta = track->eta();
00046      double track_phi = track->phi();
00047 
00048      if (DeltaR(track_eta,jet_eta, track_phi, jet_phi) < cone_size) {
00049 
00050                   double DeltaZ = Vertex_Z-signal_vert_Z;
00051                   double DeltaZ_Error = sqrt((Vertex_Z_Error*Vertex_Z_Error)+(signal_vert_z_error*signal_vert_z_error));
00052                   Pt_jets_X_tot += track->px();
00053                   Pt_jets_Y_tot += track->py();  
00054                   if (cutType == "sig") discriminator = (fabs(DeltaZ)/DeltaZ_Error) <= cutSigmaZ;
00055                   else discriminator = fabs(DeltaZ) < cutDeltaZ;
00056         
00057                   if (discriminator){
00058                     
00059                       Pt_jets_X += track->px();
00060                       Pt_jets_Y += track->py();
00061                        
00062                   }
00063  
00064    }
00065  } 
00066 }
00067   double Var = -1;
00068   
00069   if (Algo == 1) Var =  Track_Pt(Pt_jets_X, Pt_jets_Y)/jet_et;
00070   else if (Algo == 2) {
00071       if (Track_Pt(Pt_jets_X_tot, Pt_jets_Y_tot)!=0)  Var =  Track_Pt(Pt_jets_X, Pt_jets_Y)/Track_Pt(Pt_jets_X_tot, Pt_jets_Y_tot);
00072       else  std::cout << "[Jets] JetVertexAssociation: Warning! problems for  Algo = 2: possible division by zero .." << std::endl;
00073   }
00074   else {
00075     
00076       Var =  Track_Pt(Pt_jets_X, Pt_jets_Y)/jet_et;
00077       std::cout << "[Jets] JetVertexAssociation: Warning! Algo = " << Algo << " not found; using Algo = 1" << std::endl;
00078   }
00079 
00080   //  cout<<"Var = "<<Var<<endl;
00081 
00082   if (Var >= threshold) parameter = std::pair<double, bool>(Var, true);
00083   else  parameter = std::pair<double, bool>(Var, false);
00084 
00085   return parameter;
00086 
00087 }
00088 
00089 double JetVertexMain::DeltaR(double eta1, double eta2, double phi1, double phi2){
00090 
00091   double dphi = fabs(phi1-phi2);
00092   if(dphi > M_PI) dphi = 2*M_PI - dphi;
00093   double deta = fabs(eta1-eta2);
00094   return sqrt(dphi*dphi + deta*deta);
00095 
00096 }
00097 
00098 double JetVertexMain::Track_Pt(double px, double py){
00099 
00100   return sqrt(px*px+py*py);
00101 
00102 }