Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

TMBBTag.cpp

Go to the documentation of this file.
00001 
00002 //
00003 // Name: TMBBTag.cpp
00004 //
00005 // Purpose: Implementation for class TMBBTag.
00006 //
00007 // Created: 25-Jan-2005
00008 //
00010 
00011 #include "tmb_tree/TMBBTag.hpp"
00012 #include "tmb_tree/TMBMuon.hpp"
00013 #include "tmb_tree/TMBJet.hpp"
00014 #include "TTree.h"
00015 #include "TBranch.h"
00016 #include <iostream>
00017 
00018 TMBBTag::TMBBTag() :
00019   _taggable(kFALSE),
00020   _tagged(kFALSE),
00021   _neg_tagged(kFALSE),
00022   _trf_data(0),
00023   _trf_data_err(0),
00024   _trf_mc(0),
00025   _trf_sf(0),
00026   _mc_flavor(-1),
00027   _num_tracks(0),
00028   _num_neg_tracks(0)
00029   //
00030   // Purpose: Default constructor.
00031   //
00032 {}
00033 
00034 TMBBTag::TMBBTag(Bool_t taggable,
00035                  Bool_t tagged,
00036                  Bool_t neg_tagged,
00037                  Int_t mc_flavor,
00038                  const TMBJet* jet,
00039                  const TMBMuon* muon,
00040                  const TRefArray* tracks,
00041                  const TRefArray* neg_tracks) :
00042   _taggable(taggable),
00043   _tagged(tagged),
00044   _neg_tagged(neg_tagged),
00045   _trf_data(0),
00046   _trf_data_err(0),
00047   _trf_mc(0),
00048   _trf_sf(0),
00049   _mc_flavor(mc_flavor)
00050   //
00051   // Purpose: Initializing constructor.
00052   //
00053   // Arguments: taggable   - Taggable flag.
00054   //            tagged     - Tag decision (positive).
00055   //            neg_tagged - Tag decision (negative).
00056   //            mc_flavor  - MC jet flavor (-1=unknown, 0=light, 4=c, 5=b).
00057   //            jet        - Associated reconstructed jet (TMBJet).
00058   //            muon       - Associated reconstructed muon (TMBMuon).
00059   //            tracks     - Associated tracks (TMBTrack).
00060   //            neg_tracks - Associated negative tracks (TMBTrack).
00061   //
00062 {
00063   _jet = (TMBJet*)jet;
00064   _muon = (TMBMuon*)muon;
00065 
00066   //std::cout<<"Make BTag..."<<std::endl;
00067   //if (!_jet.IsValid()) std::cout<<"invalid jet!"<<std::endl;
00068 
00069   _tracks.Clear();
00070   if (tracks) {
00071     for (Int_t i=0; i<tracks->GetLast()+1; i++) {
00072       _tracks.Add( tracks->At(i) );
00073     }
00074   }
00075 
00076   _neg_tracks.Clear();
00077   if (neg_tracks) {
00078     for (Int_t i=0; i<neg_tracks->GetLast()+1; i++) {
00079       _neg_tracks.Add( neg_tracks->At(i) );
00080     }
00081   }
00082   
00083   //_tracks = *tracks;
00084   //_neg_tracks = *neg_tracks;
00085   
00086   _num_tracks = _tracks.GetEntriesFast();
00087   _num_neg_tracks = _neg_tracks.GetEntriesFast();
00088 }
00089 
00090 TMBBTag::~TMBBTag()
00091 //
00092 // Purpose: Destructor.
00093 //
00094 {}
00095 
00096 bool TMBBTag::print() const
00097 {
00098   bool ret=true;
00099   std::cout<<"BTag:";
00100   if (GetJet()) {
00101     if (GetJet()->isEM()) std::cout<<" isEM ";
00102     if (GetJet()->isBad()) std::cout<<" isBad ";
00103     std::cout<<" taggable: "<<_taggable<<"="<<GetJet()->taggable();
00104     if (_taggable!=GetJet()->taggable()) {std::cout<<" - mismatch!"; ret=false;}
00105     std::cout<<" id: "<<GetId()<<"="<<GetJet()->btagdictcheck(_algo);
00106     if (GetId()!=GetJet()->btagdictcheck(_algo)) {std::cout<<" - mismatch!"; ret=false;}
00107   }
00108   else {std::cout<<" bad associated jet"; ret=false;}
00109   
00110   std::cout<<std::endl;
00111   return ret;
00112 }
00113 
00114 const TMBJet* TMBBTag::GetJet() const {
00115   //First make sure we read the jet branch
00116   TTree *tree = (TTree*)gROOT->FindObject("TMBTree");
00117   if (tree){
00118     //std::cout<<"finding branch "<<_algo<<std::endl;
00119     TBranch *b =tree->GetBranch("BTag_"+_algo);
00120     if (b) {
00121       //std::cout<<"finding current entry"<<std::endl;
00122       Long64_t current = b->GetReadEntry();
00123       //std::cout<<"entry="<<current<<std::endl;
00124       b =tree->GetBranch(_jetbranch);
00125       if (current>=0 && b) {
00126         Long64_t other_current = b->GetReadEntry();
00127         //std::cout<<"other entry="<<other_current<<std::endl;
00128         if (other_current!=current) {
00129           //std::cout<<"reading entry "<<current<<" from branch "<<_jetbranch<<std::endl;
00130           b->GetEntry(current);
00131         }
00132       }
00133     }
00134   }
00135   return _jet.IsValid() ? (const TMBJet *)_jet.GetObject() : 0;
00136 }
00137 
00138 const TMBMuon* TMBBTag::GetMuon() const {
00139   //First make sure we read the muon branch
00140   TTree *tree = (TTree*)gROOT->FindObject("TMBTree");
00141   if (tree){
00142     //std::cout<<"finding branch "<<_algo<<std::endl;
00143     TBranch *b =tree->GetBranch("BTag_"+_algo);
00144     if (b) {
00145       //std::cout<<"finding current entry"<<std::endl;
00146       Long64_t current = b->GetReadEntry();
00147       //std::cout<<"entry="<<current<<std::endl;
00148       b =tree->GetBranch(_muonbranch);
00149       if (current>=0 && b) {
00150         Long64_t other_current = b->GetReadEntry();
00151         //std::cout<<"other entry="<<other_current<<std::endl;
00152         if (other_current!=current) {
00153           //std::cout<<"reading entry "<<current<<" from branch "<<_muonbranch<<std::endl;
00154           b->GetEntry(current);
00155         }
00156       }
00157     }
00158   }
00159   return _muon.IsValid() ? (const TMBMuon *)_muon.GetObject() : 0;
00160 }
00161 

Generated on Tue Mar 28 10:13:04 2006 for CAF by doxygen 1.3.4