Index: validation/Validation.cpp
===================================================================
--- validation/Validation.cpp	(revision e605a994a472ca9598b9b89b505104f84baaedee)
+++ validation/Validation.cpp	(revision 78d1846b8d9dd50645b8b4fb49d6ea17945256b7)
@@ -253,6 +253,6 @@
       if(eta > etamax || eta < etamin ) continue;
 
-      //cout<<"b parton: "<<pt<<endl;
       if (particle->PID == pdgID && genMomentum.Pt() > ptmin && genMomentum.Pt() < ptmax )
+      //if (TMath::Abs(particle->PID) == pdgID && (particle->Status>20 && particle->Status <30) && genMomentum.Pt() > ptmin && genMomentum.Pt() < ptmax )
       {
         // Loop over all reco object in event
@@ -261,6 +261,4 @@
           recoObj = (T*)branchReco->At(j);
           recoMomentum = recoObj->P4();
-          // this is simply to avoid warnings from initial state particle
-          // having infite rapidity ...
         //if(Momentum.Px() == 0 && genMomentum.Py() == 0) continue;
 
@@ -317,4 +315,5 @@
 }
 
+
 template<typename T>
 TH1D* GetEffEta(TClonesArray *branchReco, TClonesArray *branchParticle, TString name, int pdgID, double ptmin, double ptmax, double etamin, double etamax, ExRootTreeReader *treeReader)
@@ -363,4 +362,5 @@
 
       if (particle->PID == pdgID && genMomentum.Pt() > ptmin && genMomentum.Pt() < ptmax )
+      //if (TMath::Abs(particle->PID) == pdgID && (particle->Status>20 && particle->Status <30) && genMomentum.Pt() > ptmin && genMomentum.Pt() < ptmax )
       {
         // Loop over all reco object in event
@@ -422,4 +422,176 @@
 
 
+//------------------------------------------------------------------------------
+
+template<typename T>
+TH1D* GetJetEffPt(TClonesArray *branchJet, TString name, int pdgID, double ptmin, double ptmax, double etamin, double etamax, ExRootTreeReader *treeReader)
+{
+
+  cout << "** Computing Efficiency of reconstructing "<< branchJet->GetName() << " with PID " << pdgID << endl;
+
+  Long64_t allEntries = treeReader->GetEntries();
+
+  T *recoObj;
+
+  TLorentzVector recoMomentum, genMomentum, bestRecoMomentum;
+
+  Float_t pt, eta;
+  Long64_t entry;
+
+  Int_t j;
+
+  TH1D *histGenPt = new TH1D(name+" gen spectra Pt",name+" gen spectra cen", Nbins, TMath::Log10(ptmin), TMath::Log10(ptmax));
+  TH1D *histRecoPt = new TH1D(name+" reco spectra Pt",name+" reco spectra cen", Nbins, TMath::Log10(ptmin), TMath::Log10(ptmax));
+
+  histGenPt->SetDirectory(0);
+  histRecoPt->SetDirectory(0);
+
+  BinLogX(histGenPt);
+  BinLogX(histRecoPt);
+
+  // Loop over all events
+  for(entry = 0; entry < allEntries; ++entry)
+  {
+    // Load selected branches with data from specified event
+    treeReader->ReadEntry(entry);
+
+    // Loop over all reco object in event
+    for(j = 0; j < branchJet->GetEntriesFast(); ++j)
+    {
+      recoObj = (T*)branchJet->At(j);
+      recoMomentum = recoObj->P4();
+      pt =   recoMomentum.Pt();      
+      eta = TMath::Abs(recoMomentum.Eta());
+      Jet *jet = (Jet *)recoObj;
+          
+      if(eta > etamax || eta < etamin ) continue;
+      if(pt < ptmin || pt > ptmax) continue;
+      
+      Int_t flavor = jet->Flavor;
+      if(flavor == 21) flavor = 0;
+    
+      if(TMath::Abs(pdgID) == 1)
+      {
+        
+        if(flavor < 4)
+        {
+          histGenPt->Fill(pt);
+          if( jet->BTag & (1 << 0) ) histRecoPt->Fill(pt);
+        }
+      }
+      if(TMath::Abs(pdgID) == 4)
+      {
+        if(flavor == 4)
+        {
+          histGenPt->Fill(pt);
+          if( jet->BTag & (1 << 0) ) histRecoPt->Fill(pt);
+        }
+      }
+      if(TMath::Abs(pdgID) == 5)
+      {
+        if(flavor == 5)
+        {
+          histGenPt->Fill(pt);
+          if( jet->BTag & (1 << 0) ) histRecoPt->Fill(pt);
+        }
+      }
+   }
+
+  }
+
+  histRecoPt->Sumw2();
+  histGenPt->Sumw2();
+
+  histRecoPt->Divide(histGenPt);
+  histRecoPt->Scale(100.);
+
+  return histRecoPt;
+}
+
+// ------------------------------------------------------------------------------------------------------------------------------------------------------
+
+template<typename T>
+TH1D* GetJetEffEta(TClonesArray *branchJet, TString name, int pdgID, double ptmin, double ptmax, double etamin, double etamax, ExRootTreeReader *treeReader)
+{
+
+  cout << "** Computing Efficiency of reconstructing "<< branchJet->GetName() << " with PID " << pdgID << endl;
+
+  Long64_t allEntries = treeReader->GetEntries();
+
+  T *recoObj;
+
+  TLorentzVector recoMomentum, genMomentum, bestRecoMomentum;
+
+  Float_t pt, eta;
+  Long64_t entry;
+
+  Int_t j;
+
+  TH1D *histGenEta = new TH1D(name+" gen spectra Eta",name+" gen spectra", Nbins, etamin, etamax);
+  TH1D *histRecoEta = new TH1D(name+" reco spectra Eta",name+" reco spectra", Nbins, etamin, etamax);
+
+  histGenEta->SetDirectory(0);
+  histRecoEta->SetDirectory(0);
+  // Loop over all events
+  for(entry = 0; entry < allEntries; ++entry)
+  {
+    // Load selected branches with data from specified event
+    treeReader->ReadEntry(entry);
+
+    // Loop over all reco object in event
+    for(j = 0; j < branchJet->GetEntriesFast(); ++j)
+    {
+      recoObj = (T*)branchJet->At(j);
+      recoMomentum = recoObj->P4();
+      pt =   recoMomentum.Pt();      
+      eta = recoMomentum.Eta();
+      Jet *jet = (Jet *)recoObj;
+          
+      if(eta > etamax || eta < etamin ) continue;
+      if(pt < ptmin || pt > ptmax) continue;
+      
+      Int_t flavor = jet->Flavor;
+      if(flavor == 21) flavor = 0;
+         
+      if(TMath::Abs(pdgID) == 1)
+      {
+        if(flavor  == 1 || flavor == 21)
+        {
+          histGenEta->Fill(eta);
+          if( jet->BTag & (1 << 0) ) histRecoEta->Fill(eta);
+        }
+      }
+      if(TMath::Abs(pdgID) == 4)
+      {
+        if(flavor == 4)
+        {
+          histGenEta->Fill(eta);
+          if( jet->BTag & (1 << 0) ) histRecoEta->Fill(eta);
+        }
+      }
+      if(TMath::Abs(pdgID) == 5)
+      {
+        if(flavor == 5)
+        {
+          histGenEta->Fill(eta);
+          if( jet->BTag & (1 << 0) ) histRecoEta->Fill(eta);
+        }
+      }
+   }
+
+  }
+
+
+  histRecoEta->Sumw2();
+  histGenEta->Sumw2();
+
+  histRecoEta->Divide(histGenEta);
+  histRecoEta->Scale(100.);
+
+  return histRecoEta;
+}
+
+
+// -----------------------------------------------------------------------------------------------------------------------------------------------------
 
 template<typename T>
@@ -2468,6 +2640,5 @@
     c_recpho_eff_eta->Print(figPath+"img_recpho_eff_eta.pdf","pdf");
     c_recpho_eff_eta->Print(figPath+"img_recpho_eff_eta.png","png");
-
-
+    
     /////////////////////////////////////////
     // B-jets  Efficiency/ mistag rates   ///
@@ -2488,5 +2659,6 @@
     {
 
-       h_recbjet_eff_pt = GetEffPt<Jet>(branchPFBJet, branchParticleBJet, "BJet", 5, ptMin, ptMax, etaVals.at(k), etaVals.at(k+1), treeReaderBJet);
+       h_recbjet_eff_pt = GetJetEffPt<Jet>(branchPFBJet, "BJet", 5, ptMin, ptMax, etaVals.at(k), etaVals.at(k+1), treeReaderBJet);
+       //h_recbjet_eff_pt = GetEffPt<Jet>(branchPFBJet, branchParticleBJet, "BJet", 5, ptMin, ptMax, etaVals.at(k), etaVals.at(k+1), treeReaderBJet);
        gr_recbjet_eff_pt[k] = TGraphErrors(h_recbjet_eff_pt);
 
@@ -2504,5 +2676,6 @@
     for (k = 0; k < ptVals.size(); k++)
     {
-       h_recbjet_eff_eta = GetEffEta<Jet>(branchPFBJet, branchParticleBJet, "BJet", 5, 0.5*ptVals.at(k), 2.0*ptVals.at(k) ,etaMin, etaMax , treeReaderBJet);
+       h_recbjet_eff_eta = GetJetEffEta<Jet>(branchPFBJet, "BJet", 5, 0.5*ptVals.at(k), 2.0*ptVals.at(k) ,etaMin, etaMax , treeReaderBJet);
+       //h_recbjet_eff_eta = GetEffEta<Jet>(branchPFBJet, branchParticleBJet, "BJet", 5, 0.5*ptVals.at(k), 2.0*ptVals.at(k) ,etaMin, etaMax , treeReaderBJet);
        gr_recbjet_eff_eta[k] = TGraphErrors(h_recbjet_eff_eta);
 
@@ -2551,5 +2724,6 @@
     {
 
-       h_recbjet_cmis_pt = GetEffPt<Jet>(branchPFCJet, branchParticleCJet, "CJet", 4, ptMin, ptMax, etaVals.at(k), etaVals.at(k+1), treeReaderCJet);
+       h_recbjet_cmis_pt = GetJetEffPt<Jet>(branchPFCJet, "CJet", 4, ptMin, ptMax, etaVals.at(k), etaVals.at(k+1), treeReaderCJet);
+       //h_recbjet_cmis_pt = GetEffPt<Jet>(branchPFCJet, branchParticleCJet, "CJet", 4, ptMin, ptMax, etaVals.at(k), etaVals.at(k+1), treeReaderCJet);
        gr_recbjet_cmis_pt[k] = TGraphErrors(h_recbjet_cmis_pt);
 
@@ -2567,5 +2741,6 @@
     for (k = 0; k < ptVals.size(); k++)
     {
-       h_recbjet_cmis_eta = GetEffEta<Jet>(branchPFCJet, branchParticleCJet, "CJet", 4, 0.5*ptVals.at(k), 2.0*ptVals.at(k) ,etaMin, etaMax , treeReaderCJet);
+       h_recbjet_cmis_eta = GetJetEffEta<Jet>(branchPFCJet, "CJet", 4, 0.5*ptVals.at(k), 2.0*ptVals.at(k) ,etaMin, etaMax , treeReaderCJet);
+       //h_recbjet_cmis_eta = GetEffEta<Jet>(branchPFCJet, branchParticleCJet, "CJet", 4, 0.5*ptVals.at(k), 2.0*ptVals.at(k) ,etaMin, etaMax , treeReaderCJet);
        gr_recbjet_cmis_eta[k] = TGraphErrors(h_recbjet_cmis_eta);
 
@@ -2614,5 +2789,6 @@
     {
 
-       h_recbjet_lmis_pt = GetEffPt<Jet>(branchJet, branchParticleJet, "Jet", 1, ptMin, ptMax, etaVals.at(k), etaVals.at(k+1), treeReaderJet);
+       h_recbjet_lmis_pt = GetJetEffPt<Jet>(branchJet, "Jet", 1, ptMin, ptMax, etaVals.at(k), etaVals.at(k+1), treeReaderJet);
+       //h_recbjet_lmis_pt = GetEffPt<Jet>(branchJet, branchParticleJet, "Jet", 1, ptMin, ptMax, etaVals.at(k), etaVals.at(k+1), treeReaderJet);
        gr_recbjet_lmis_pt[k] = TGraphErrors(h_recbjet_lmis_pt);
 
@@ -2630,5 +2806,6 @@
     for (k = 0; k < ptVals.size(); k++)
     {
-       h_recbjet_lmis_eta = GetEffEta<Jet>(branchJet, branchParticleJet, "Jet", 1, 0.5*ptVals.at(k), 2.0*ptVals.at(k) ,etaMin, etaMax , treeReaderJet);
+       h_recbjet_lmis_eta = GetJetEffEta<Jet>(branchJet, "Jet", 1, 0.5*ptVals.at(k), 2.0*ptVals.at(k) ,etaMin, etaMax , treeReaderJet);
+       //h_recbjet_lmis_eta = GetEffEta<Jet>(branchJet, branchParticleJet, "Jet", 1, 0.5*ptVals.at(k), 2.0*ptVals.at(k) ,etaMin, etaMax , treeReaderJet);
        gr_recbjet_lmis_eta[k] = TGraphErrors(h_recbjet_lmis_eta);
 
@@ -2643,5 +2820,5 @@
     mg_recbjet_lmis_pt->Draw("APE");
     
-    DrawAxis(mg_recbjet_lmis_pt, leg_recbjet_lmis_pt, ptMin, ptMax, 0.0, 10.0, "p_{T} [GeV]", "light - mistag rate (%)", true, false);
+    DrawAxis(mg_recbjet_lmis_pt, leg_recbjet_lmis_pt, ptMin, ptMax, 0.0, 1.0, "p_{T} [GeV]", "light - mistag rate (%)", true, false);
     
     leg_recbjet_lmis_pt->Draw();
@@ -2655,5 +2832,5 @@
 
     mg_recbjet_lmis_eta->Draw("APE");
-    DrawAxis(mg_recbjet_lmis_eta, leg_recbjet_lmis_eta, etaMin, etaMax, 0.0, 10.0, " #eta ", "light - mistag rate (%)", false, false);
+    DrawAxis(mg_recbjet_lmis_eta, leg_recbjet_lmis_eta, etaMin, etaMax, 0.0, 1.0, " #eta ", "light - mistag rate (%)", false, false);
     leg_recbjet_lmis_eta->Draw();
     pave->Draw();
@@ -2837,6 +3014,4 @@
 
   fout->Write();
-
-
 
 
