TMBJet.cpp

Go to the documentation of this file.
00001 #include "tmb_tree/TMBJet.hpp"
00002 #include <iostream>
00003 #include "TRandom.h" //for btag check
00004 #include "TTree.h"
00005 #include "TBranch.h"
00006 
00007 #include <cassert>
00008 #include <stdexcept>
00009 
00010 ClassImp(TMBJet);
00011 
00012 TMBJet::TMBJet()
00013 {
00014 }
00015 
00016 TMBJet::TMBJet      (Float_t E, Float_t pT,   Float_t phi,  Float_t eta)
00017 {
00018     Set0   (E, pT, phi, eta);
00019 }
00020 
00021 TMBJet::~TMBJet()
00022 {
00023 }
00024 
00025 void TMBJet::Set0    (Float_t E, Float_t pT,   Float_t phi,  Float_t eta)
00026 {
00027 
00028     SetPtEtaPhiE(pT, eta, phi, E);
00029 
00030     //  alwyas initialize corrections to 0 
00031     _jes_C=0.0;
00032     _jesMU_C=0.0;
00033     _jes_dC_stat=0.0;
00034     _jesMU_dC_stat=0.0;
00035     _jes_dC_stat_up=0.0;
00036     _jesMU_dC_stat_up=0.0;
00037     _jes_dC_stat_down=0.0;
00038     _jesMU_dC_stat_down=0.0;
00039     _jes_dC_sys=0.0;
00040     _jesMU_dC_sys=0.0;
00041     _jes_dC_sys_up=0.0;
00042     _jesMU_dC_sys_up=0.0;
00043     _jes_dC_sys_down=0.0;
00044     _jesMU_dC_sys_down=0.0;
00045     _jes_metC=0.0;
00046     _jesMU_metC=0.0;
00047     _jes_metdC_stat=0.0;
00048     _jesMU_metdC_stat=0.0;
00049     _jes_metdC_sys=0.0;
00050     _jesMU_metdC_sys=0.0;
00051     _smear_coeff = 1.0;
00052     _smear_coeffMU = 1.0;
00053     _isGood = 1;
00054     _isL1Conf = 0;
00055     _isBad = 0;
00056     _isNoise = 0;
00057     _isEM = 0;
00058     _hasMU = 0;
00059     _isSmeared = 0;
00060     _isSmearedMU = 0;
00061     _actas = 0;
00062 
00063     ClearAllBTags();
00064 }
00065 
00066 void TMBJet::ActAsUnCorrected() const
00067 {
00068   if (_actas==kUnCorrected) return;
00069   const_cast<TMBJet&>(*this).SetPtEtaPhiE(_uncorrected.Pt(), _uncorrected.Eta(), _uncorrected.Phi(), _uncorrected.E());
00070   _actas = kUnCorrected;
00071   return;
00072 }
00073 
00074 void TMBJet::ActAsJESCorrected() const
00075 {
00076   if (_actas==kJESCorrected) return;
00077   const_cast<TMBJet&>(*this).SetPEtaPhiE(_uncorrected.P()*_jes_C, _uncorrected.Eta(), _uncorrected.Phi(), _uncorrected.E()*_jes_C);
00078   _actas = kJESCorrected;
00079   return;
00080 }
00081 
00082 void TMBJet::ActAsJESCorrectedShiftedPlus() const
00083 {
00084   if (_actas==kJESCorrectedShiftedPlus) return;
00085   const_cast<TMBJet&>(*this).SetPEtaPhiE(_uncorrected.P()*(_jes_C+sqrt(_jes_dC_sys_up*_jes_dC_sys_up+_jes_dC_stat_up*_jes_dC_stat_up)),
00086                  _uncorrected.Eta(), _uncorrected.Phi(), 
00087                  _uncorrected.E()*(_jes_C+sqrt(_jes_dC_sys_up*_jes_dC_sys_up+_jes_dC_stat_up*_jes_dC_stat_up)));
00088   _actas = kJESCorrectedShiftedPlus;
00089   return;
00090 }
00091 
00092 void TMBJet::ActAsJESCorrectedShiftedMinus() const
00093 {
00094   if (_actas==kJESCorrectedShiftedMinus) return;
00095   const_cast<TMBJet&>(*this).SetPEtaPhiE(_uncorrected.P()*(_jes_C-sqrt(_jes_dC_sys_down*_jes_dC_sys_down+_jes_dC_stat_down*_jes_dC_stat_down)), 
00096                 _uncorrected.Eta(), _uncorrected.Phi(), 
00097                 _uncorrected.E()*(_jes_C-sqrt(_jes_dC_sys_down*_jes_dC_sys_down+_jes_dC_stat_down*_jes_dC_stat_down)));
00098   _actas = kJESCorrectedShiftedMinus;
00099   return;
00100 }
00101 
00102 void TMBJet::ActAsJESMUCorrected() const
00103 {
00104   if (_actas==kJESMUCorrected) return;
00105   const_cast<TMBJet&>(*this).SetPEtaPhiE(_uncorrected.P()*_jesMU_C, _uncorrected.Eta(), _uncorrected.Phi(), _uncorrected.E()*_jesMU_C);
00106   _actas = kJESMUCorrected;
00107   return;
00108 }
00109 
00110 void TMBJet::ActAsJESMUCorrectedShiftedPlus() const
00111 {
00112   if (_actas==kJESMUCorrectedShiftedPlus) return;
00113   const_cast<TMBJet&>(*this).SetPEtaPhiE(_uncorrected.P()*(_jesMU_C+sqrt(_jesMU_dC_sys_up*_jesMU_dC_sys_up+_jesMU_dC_stat_up*_jesMU_dC_stat_up)),
00114                                          _uncorrected.Eta(), _uncorrected.Phi(), 
00115                                          _uncorrected.E()*(_jesMU_C+sqrt(_jesMU_dC_sys_up*_jesMU_dC_sys_up+_jesMU_dC_stat_up*_jesMU_dC_stat_up)));
00116   _actas = kJESMUCorrectedShiftedPlus;
00117   return;
00118 }
00119 
00120 void TMBJet::ActAsJESMUCorrectedShiftedMinus() const
00121 {
00122   if (_actas==kJESMUCorrectedShiftedMinus) return;
00123   const_cast<TMBJet&>(*this).SetPEtaPhiE(_uncorrected.P()*(_jesMU_C-sqrt(_jesMU_dC_sys_down*_jesMU_dC_sys_down+_jesMU_dC_stat_down*_jesMU_dC_stat_down)), 
00124                                          _uncorrected.Eta(), _uncorrected.Phi(), 
00125                                          _uncorrected.E()*(_jesMU_C-sqrt(_jesMU_dC_sys_down*_jesMU_dC_sys_down+_jesMU_dC_stat_down*_jesMU_dC_stat_down)));
00126   _actas = kJESMUCorrectedShiftedMinus;
00127   return;
00128 }
00129 
00130 void TMBJet::ActAsSmeared() const
00131 {
00132   if (_actas==kSmeared) return;
00133   const_cast<TMBJet&>(*this).SetPEtaPhiE(_uncorrected.P()*_jes_C*_smear_coeff, _uncorrected.Eta(), _uncorrected.Phi(), _uncorrected.E()*_jes_C*_smear_coeff);
00134   _actas = kSmeared;
00135   return;
00136 }
00137 
00138 void TMBJet::ActAsSmearedMU() const
00139 {
00140   if (_actas==kSmearedMU) return;
00141   const_cast<TMBJet&>(*this).SetPEtaPhiE(_uncorrected.P()*_jesMU_C*_smear_coeffMU, _uncorrected.Eta(), _uncorrected.Phi(), _uncorrected.E()*_jesMU_C*_smear_coeffMU);
00142   _actas = kSmearedMU;
00143   return;
00144 }
00145 
00146 void TMBJet::SetActAs(const Int_t ActAs) const
00147 {
00148   if (ActAs == TMBJet::kUnCorrected) {
00149     ActAsUnCorrected();
00150   } else if (ActAs == TMBJet::kJESCorrected) {
00151     ActAsJESCorrected();
00152   } else if (ActAs == TMBJet::kJESCorrectedShiftedPlus) {
00153     ActAsJESCorrectedShiftedPlus();
00154   } else if (ActAs == TMBJet::kJESCorrectedShiftedMinus) {
00155     ActAsJESCorrectedShiftedMinus();
00156   } else if (ActAs == TMBJet::kJESMUCorrected) {
00157     ActAsJESMUCorrected();
00158   } else if (ActAs == TMBJet::kJESMUCorrectedShiftedPlus) {
00159     ActAsJESMUCorrectedShiftedPlus();
00160   } else if (ActAs == TMBJet::kJESMUCorrectedShiftedMinus) {
00161     ActAsJESMUCorrectedShiftedMinus();
00162   } else if (ActAs == TMBJet::kSmeared) {
00163     ActAsSmeared();
00164   } else if (ActAs == TMBJet::kSmearedMU) {
00165     ActAsSmearedMU();
00166   } else {
00167     throw std::runtime_error( Form ("TMBJet: Can't reset jet's ActAs to unknown JES type (%d)", ActAs));
00168   }
00169   return;
00170 }
00171 
00172 void TMBJet::Set1    (Float_t q, Float_t dphi, Float_t deta, 
00173                       Float_t emf,  Float_t em1f, Float_t em2f, Float_t em3f,
00174                       Float_t ccmg, Float_t icdf, Float_t ecmg, Float_t icrf,
00175                       Float_t fh1f, Float_t fh2f, Float_t fh3f, Float_t chf,
00176                       Float_t emcc, Float_t hadcc,Float_t emec, Float_t hadec,
00177                       Float_t hot,  Float_t mxET,
00178                       Float_t cpsE, Float_t etaW, Float_t phiW, 
00179                       Float_t sET,  Float_t vPT,  Float_t iPT,  Float_t seedET,
00180                       Float_t pxCH, Float_t pyCH, Float_t pzCH)
00181 {
00182     _q     = q;
00183     _dphi  = dphi; 
00184     _deta  = deta; 
00185     _emf   = emf; 
00186     _em1f  = em1f; 
00187     _em2f  = em2f; 
00188     _em3f  = em3f;
00189     _ccmg  = ccmg;
00190     _icdf  = icdf; 
00191     _ecmg  = ecmg;
00192     _icrf  = icrf; 
00193     _fh1f  = fh1f; 
00194     _fh2f  = fh2f; 
00195     _fh3f  = fh3f; 
00196     _emcc  = emcc;
00197     _hadcc = hadcc;
00198     _emec  = emec;
00199     _hadec = hadec;
00200     _chf   = chf; 
00201     _hot   = hot; 
00202     _mxET  = mxET; 
00203     _cpsE  = cpsE; 
00204     _etaW  = etaW; 
00205     _phiW  = phiW; 
00206     _sET   = sET; 
00207     _vPT   = vPT; 
00208     _iPT   = iPT; 
00209     _seedET= seedET; 
00210     _pxCH = pxCH;
00211     _pyCH = pyCH;
00212     _pzCH = pzCH;
00213 }
00214 
00215 
00216 void TMBJet::Set2    (Int_t ntrk, Int_t nps,  Int_t Nitems, 
00217                       Int_t n90,  Int_t split_merge_word, 
00218                       const char *algoname, const TRefArray *tracks, TRef vtxref)
00219 {
00220     _ntrk  = ntrk; 
00221     _nps   = nps; 
00222     _Nitems= Nitems; 
00223     _n90   = n90;
00224     _split_merge_word =  split_merge_word;
00225     _algoname = algoname;              
00226     _vtxref   = vtxref;
00227 
00228     _tracks.Clear();
00229     if (tracks) {
00230         for (Int_t i=0; i<tracks->GetLast()+1; i++) {
00231             _tracks.Add( tracks->At(i) );
00232         }
00233     }
00234 }
00235 
00236 void TMBJet::SetJetShapes(const std::vector<std::pair<Char_t, UChar_t> >& jetTowers, 
00237                           const std::vector<Float_t>& jetShapes)
00238 {
00239   _jetTowers=jetTowers;
00240   _jetShapes=jetShapes;
00241 }
00242 
00243 void TMBJet::SetL1(Float_t l1set, Float_t l1pt, Float_t l1em)
00244 {
00245     _l1set = l1set;
00246     _l1pt  = l1pt;
00247     _l1em  = l1em;
00248 }
00249 
00250 void TMBJet::SetCorr (Float_t jes_C, Float_t jes_dC_stat, Float_t jes_dC_sys,
00251                       Float_t jes_metC, Float_t jes_metdC_stat, Float_t jes_metdC_sys)
00252 {
00253     _jes_C=jes_C;
00254     _jes_dC_stat=jes_dC_stat;
00255     _jes_dC_sys=jes_dC_sys;
00256     _jes_metC=jes_metC;
00257     _jes_metdC_stat=jes_metdC_stat;
00258     _jes_metdC_sys=jes_metdC_sys;
00259 
00260  
00261     switch(_actas) {
00262     case kJESCorrected:
00263         _actas = kUnCorrected;
00264         ActAsJESCorrected();
00265         break;
00266     case kJESCorrectedShiftedPlus:
00267         _actas = kUnCorrected;
00268         ActAsJESCorrectedShiftedPlus();
00269         break;
00270     case kJESCorrectedShiftedMinus:
00271         _actas = kUnCorrected;
00272         ActAsJESCorrectedShiftedMinus();
00273         break;
00274     default:
00275         break;
00276     }    
00277 }
00278 
00279 void TMBJet::SetCorr (Float_t jes_C, Float_t jes_dC_stat_up, Float_t jes_dC_sys_up, Float_t jes_dC_stat_down, Float_t jes_dC_sys_down,
00280                       Float_t jes_metC, Float_t jes_metdC_stat, Float_t jes_metdC_sys)
00281 {
00282     _jes_C=jes_C;
00283     _jes_dC_stat_down=jes_dC_stat_down;
00284     _jes_dC_sys_down=jes_dC_sys_down;
00285     _jes_dC_stat_up=jes_dC_stat_up;
00286     _jes_dC_sys_up=jes_dC_sys_up;
00287     _jes_dC_stat = _jes_dC_stat_up >= _jes_dC_stat_down ? _jes_dC_stat_up : _jes_dC_stat_down ;
00288     _jes_dC_sys  = _jes_dC_sys_up >= _jes_dC_sys_down ? _jes_dC_sys_up : _jes_dC_sys_down ;
00289     _jes_metC=jes_metC;
00290     _jes_metdC_stat=jes_metdC_stat;
00291     _jes_metdC_sys=jes_metdC_sys;
00292  
00293     switch(_actas) {
00294     case kJESCorrected:
00295         _actas = kUnCorrected;
00296         ActAsJESCorrected();
00297         break;
00298     case kJESCorrectedShiftedPlus:
00299         _actas = kUnCorrected;
00300         ActAsJESCorrectedShiftedPlus();
00301         break;
00302     case kJESCorrectedShiftedMinus:
00303         _actas = kUnCorrected;
00304         ActAsJESCorrectedShiftedMinus();
00305         break;
00306     default:
00307         break;
00308     }
00309 
00310 }
00311 
00312 void TMBJet::SetCorrMU(Float_t jes_C, Float_t jes_dC_stat, Float_t jes_dC_sys,
00313                       Float_t jes_metC, Float_t jes_metdC_stat, Float_t jes_metdC_sys)
00314 {
00315     _jesMU_C=jes_C;
00316     _jesMU_dC_stat=jes_dC_stat;
00317     _jesMU_dC_sys=jes_dC_sys;
00318     _jesMU_metC=jes_metC;
00319     _jesMU_metdC_stat=jes_metdC_stat;
00320     _jesMU_metdC_sys=jes_metdC_sys;
00321 
00322 
00323     switch(_actas) {
00324     case kJESMUCorrected:
00325         _actas = kUnCorrected;
00326         ActAsJESMUCorrected();
00327         break;
00328     case kJESMUCorrectedShiftedPlus:
00329         _actas = kUnCorrected;
00330         ActAsJESMUCorrectedShiftedPlus();
00331         break;
00332     case kJESMUCorrectedShiftedMinus:
00333         _actas = kUnCorrected;
00334         ActAsJESMUCorrectedShiftedMinus();
00335         break;
00336     default:
00337         break;
00338     }   
00339 }
00340 
00341 void TMBJet::SetCorrMU(Float_t jes_C, Float_t jes_dC_stat_up, Float_t jes_dC_sys_up, Float_t jes_dC_stat_down, Float_t jes_dC_sys_down,
00342                       Float_t jes_metC, Float_t jes_metdC_stat, Float_t jes_metdC_sys)
00343 {
00344     _jesMU_C=jes_C;
00345     _jesMU_dC_stat_up=jes_dC_stat_up;
00346     _jesMU_dC_sys_up=jes_dC_sys_up;
00347     _jesMU_dC_stat_down=jes_dC_stat_down;
00348     _jesMU_dC_sys_down=jes_dC_sys_down;
00349     _jesMU_dC_stat = _jesMU_dC_stat_up >= _jesMU_dC_stat_down ? _jesMU_dC_stat_up : _jesMU_dC_stat_down ;
00350     _jesMU_dC_sys  = _jesMU_dC_sys_up >= _jesMU_dC_sys_down ? _jesMU_dC_sys_up : _jesMU_dC_sys_down ;
00351     _jesMU_metC=jes_metC;
00352     _jesMU_metdC_stat=jes_metdC_stat;
00353     _jesMU_metdC_sys=jes_metdC_sys;
00354 
00355 
00356     switch(_actas) {
00357     case kJESMUCorrected:
00358         _actas = kUnCorrected;
00359         ActAsJESMUCorrected();
00360         break;
00361     case kJESMUCorrectedShiftedPlus:
00362         _actas = kUnCorrected;
00363         ActAsJESMUCorrectedShiftedPlus();
00364         break;
00365     case kJESMUCorrectedShiftedMinus:
00366         _actas = kUnCorrected;
00367         ActAsJESMUCorrectedShiftedMinus();
00368         break;
00369     default:
00370         break;
00371     }
00372 }
00373 
00374 void TMBJet::SetFlag(Int_t isGood, Int_t isL1Conf, Int_t isBad, Int_t isNoise, Int_t isEM, Int_t hasMU, Int_t isSmeared, Int_t isSmearedMU)
00375 {
00376   _isGood      = isGood;
00377   _isL1Conf    = isL1Conf;
00378   _isBad       = isBad;
00379   _isNoise     = isNoise;
00380   _isEM        = isEM;
00381   _hasMU       = hasMU;
00382   _isSmeared   = isSmeared;
00383   _isSmearedMU = isSmearedMU;
00384 
00385 }
00386                                                                                                                            
00387 void TMBJet::SetUnCorr(Float_t p, Float_t eta, Float_t phi, Float_t E)
00388 {
00389   TMBLorentzVector temp(p,eta,phi,E,kPEtaPhiE);
00390   _uncorrected = temp;
00391 }
00392 
00393 void TMBJet::SetSmearCoeff(Float_t coeff, Float_t coeffMU)
00394 {
00395     _smear_coeff = coeff;
00396     _smear_coeffMU = coeffMU;
00397 
00398     switch(_actas) {
00399     case kSmeared:
00400         _actas = kUnCorrected;
00401         ActAsSmeared();
00402         break;
00403     case kSmearedMU:
00404         _actas = kUnCorrected;
00405         ActAsSmearedMU();
00406         break;
00407     default:
00408         break;
00409     }
00410 }
00411 
00412 void TMBJet::SetJetID(Float_t cpf0, Float_t cpf, Int_t ntrkMultiplicity0,
00413                       Int_t ntrkMultiplicity, TRef cpfvtxref)
00414 {
00415     _cpf0 = cpf0;
00416     _cpf  = cpf;
00417     _ntrkMultiplicity0 = ntrkMultiplicity0;
00418     _ntrkMultiplicity  = ntrkMultiplicity;
00419     _cpfvtxref = cpfvtxref;
00420 }
00421 
00422 void TMBJet::SetCellList(TMBCellContainer *cont, 
00423                          const std::vector<TMBCellContainer::Index_t>& cells)
00424 {
00425     _container = cont;
00426     _cells = cells;
00427 }
00428 
00429 
00430 UInt_t TMBJet::ncells() const
00431 {
00432     return _cells.size();
00433 }
00434 
00436 const TMBCaloCell *TMBJet::GetCaloCell(UInt_t icell) const
00437 {
00438 
00439     assert(icell < (UInt_t)_cells.size());
00440     if(TMBCellContainer *c = _container.IsValid() ? (TMBCellContainer *)_container.GetObject() : 0) {
00441         assert(_cells[icell] < c->NumCells());
00442         return c->GetCell(_cells[icell]);
00443     } else {
00444         return 0;
00445     }    
00446 }
00447 
00448 /*
00449 namespace {
00450 
00451     //Read the BTag branch being refered to
00452     bool ReadBTagBranch(const TString& algo, const TString& bname){
00453         TTree *tree = (TTree*)gROOT->FindObject("TMBTree");
00454         if (tree){
00455             Long64_t current = tree->GetReadEntry();
00456             //std::cout<<"entry="<<current<<std::endl;
00457             TBranch *b =tree->GetBranch("BTag_corr"+algo+"_"+bname);
00458             if (current>=0 && b) {
00459                 Long64_t other_current = b->GetReadEntry();
00460                 //std::cout<<"other entry="<<other_current<<std::endl;
00461                 if (other_current!=current) {
00462                     //std::cout<<"reading entry "<<current<<" from branch "<<"BTag_corrJCCB_"+i->first<<std::endl;
00463                     b->GetEntry(current);
00464                 }
00465             }
00466             return true;
00467         }
00468         return false;
00469     }
00470 }
00471 */
00472 
00476 // Return a pointer the TMBBTag object associated with this jet 
00477 // for a particular tag type ("SVT", etc.) and cut ("LOOSE", etc.). 
00478 // Note, you may have to do a dynamic_cast to access the subclass info, as for TMBBTagSVT objects, 
00479 // for instance:
00480 //    TMBBTagSVT* tag = dynamic_cast<TMBBTagSVT*> GetBTag("NN","MEDIUM");
00481 // Also, you should check that the pointer returned is not NULL! 
00482 // It will be if no tag info for that type of tag is associated with the jet.
00483 const TMBBTag* TMBJet::GetBTag(const TString &type, const TString &cut) const {
00484     TString typecut(type+"_"+cut);
00485     return GetBTag(typecut);
00486 }
00487 
00488 const TMBBTag* TMBJet::GetBTag(const TString &typecut) const {
00489 
00490     //first get the btag check integer
00491     int check = -1;
00492     std::map< TString, int >::const_iterator c = _btagdictcheck.find(typecut);
00493     if (_btagdictcheck.end()!=c) {
00494         check = c->second;
00495     }
00496 
00497     std::map< TString, TRef >::const_iterator i = _btagdict.find(typecut);
00498     if (_btagdict.end()!=i && i->second.IsValid()) {
00499     
00500         //First make sure we read the BTag branch being referenced
00501         //ReadBTagBranch(_algoname, i->first);
00502     
00503         const TMBBTag* tag = (const TMBBTag*)(i->second.GetObject());
00504         if (tag) {
00505           if (tag->GetId()!=check){
00506             std::cout<<"WARNING! ID check failed in GetBTag!"<<std::endl;
00507           }
00508         }
00509         return tag;
00510     }
00511     else {
00512         return 0;
00513     }
00514 }
00515 
00522 const TMBBTag* TMBJet::GetBTag(const char *type, const char *cut) const
00523 {
00524     return GetBTag (TString (type), TString (cut));
00525 }
00526 
00527 //Get the first BTag object available 
00528 //(useful when you don't care about the algorithm itself, like for taggability or mc_flavor...
00529 const TMBBTag* TMBJet::GetFirstBTag() const 
00530 {  
00531     std::map< TString, TRef >::const_iterator i = _btagdict.begin();
00532     while (i != _btagdict.end()) {
00533       const TMBBTag *result = GetBTag(i->first);
00534       if (result != 0) {
00535         return result;
00536       }
00537       i++;
00538     }
00539     return 0;
00540 }
00541 
00542 //Print the list of associated, valid BTags in the map
00543 bool TMBJet::btag_print() const 
00544 {
00545     std::cout<<"btags for this jet:";
00546     bool ret=true;
00547     std::map< TString, TRef >::const_iterator i = _btagdict.begin();
00548     while (_btagdict.end()!=i) {
00549 
00550       //First make sure we read the BTag branch being referenced
00551       //ReadBTagBranch(_algoname, i->first);
00552       
00553       std::cout<<" "<<i->first;
00554       if (!i->second.IsValid()) {std::cout<<"-invalid! "; ret=false;}
00555       
00556       const TMBBTag* tag = (const TMBBTag*)(i->second.GetObject());
00557       if (!tag) {std::cout<<" <-tag==0!"; ret=false;}
00558       else {
00559         
00560         //check btag int
00561         std::cout<<" "<<tag->GetId()<<"="<<btagdictcheck(i->first);
00562         if (tag->GetId()!=btagdictcheck(i->first)) {std::cout<<" <-mismatch!"; ret=false;}      
00563         
00564         //check jet ref
00565         const TMBJet* jet = tag->GetJet();
00566         if (!jet) std::cout<<" bad jet ref";
00567         else {
00568           
00569           //do the Pt's match?
00570           std::cout<<" "<<jet->Pt()<<"="<<this->Pt();
00571           if (fabs(jet->Pt()-this->Pt())>0.000001) {std::cout<<" <-mismatch!"; ret=false;}
00572           
00573           //check btag int
00574           std::cout<<" "<<tag->GetId()<<"="<<jet->btagdictcheck(i->first);
00575           if (tag->GetId()!=jet->btagdictcheck(i->first)) {std::cout<<" <-mismatch!"; ret=false;}
00576           
00577         }
00578         
00579       }
00580       ++i;
00581     }
00582     std::cout<<std::endl;
00583     return ret;
00584 }
00585 
00593 void TMBJet::AddBTag(const TString &type, const TString &cut, TMBBTag* btag)
00594 {
00595     TString typecut(type+"_"+cut);
00596 
00597     //This is a check.... generate a random integer, and store it in both the btag and the map of the jet.
00598     //Later you can check that they still match!
00599     int r = gRandom->Integer(1000000000);
00600     btag->SetId(r);
00601     _btagdictcheck[typecut] = r;
00602 
00603     //This is the real map entry
00604     _btagdict[typecut] = btag;
00605 }
00606 
00610 void TMBJet::ClearAllBTags()
00611 {
00612     _btagdict.clear();
00613     _btagdictcheck.clear();
00614 }
00615 
00621 void TMBJet::ClearBTag (const TString &type, const TString &cut)
00622 {
00623     std::map<TString, TRef>::iterator itr = _btagdict.find(type+"_"+cut);
00624     if (itr != _btagdict.end()) {
00625         _btagdict.erase(itr);
00626         //std::cout<<"Erasing tag for "<<type<<" _ "<<cut<<" - size = "<<_btagdict.size()<<std::endl;
00627     }
00628     std::map<TString, int>::iterator itr2 = _btagdictcheck.find(type+"_"+cut);
00629     if (itr2 != _btagdictcheck.end()) {
00630         _btagdictcheck.erase(itr2);
00631         //std::cout<<"Erasing check tag for "<<type<<" _ "<<cut<<" - size = "<<_btagdictcheck.size()<<std::endl;
00632     }
00633 }
00634 
00635 int TMBJet::btagdictcheck(const char* t) const 
00636 {
00637     if (_btagdictcheck.size()==0) return -2;
00638     TString s(t);
00639 
00640     std::map< TString, int >::const_iterator i = _btagdictcheck.find(s);
00641     if (i!=_btagdictcheck.end()) return i->second;
00642   
00643     //now look for a close match... something ending in the TString key, like the algo name
00644     for (i=_btagdictcheck.begin(); i!=_btagdictcheck.end(); ++i){
00645         if (s.EndsWith(i->first)) return i->second;
00646     }
00647 
00648     // If there is only one associated btag object, return that.
00649     if (_btagdictcheck.size() == 1)
00650       return _btagdictcheck.begin()->second;
00651   
00652     //ok, nothing's close
00653     return -1;
00654 }
00655 
00656 int TMBJet::taggable() const 
00657 { 
00658     const TMBBTag* svt = GetFirstBTag();
00659     if (svt) return svt->is_taggable();
00660     else return -1;
00661 }
00662 
00663 int TMBJet::mc_flavor() const 
00664 { 
00665     const TMBBTag* svt = GetFirstBTag();
00666     if (svt) return svt->mc_flavor();
00667     else return -1;
00668 }
00669 

Generated on Thu Apr 3 04:14:23 2008 for CAF by doxygen 1.3.4