Пример #1
0
unsigned int loop(T& tree, TH3F* hist3D, TH2F* hist2D)
{
  unsigned int nEvtsRead = 0;
  unsigned int nEB = 0;
  Long64_t N = tree.fChain->GetEntriesFast();
  for (Long64_t iEvt = 0; iEvt < N; ++iEvt) {
    Long64_t localEntry = tree.LoadTree(iEvt);
    if (localEntry < 0) break;
    ++nEvtsRead;
    tree.fChain->GetEntry(iEvt);
    TObject* object = tree.fChain->GetListOfBranches()->FindObject("totalWeight");
    TBranch* branch = NULL;
    Float_t totalWeight = 1.0;
    if (object != 0) {
      branch = (TBranch*)object;
      totalWeight = *(Float_t*)branch->GetAddress();
    }
    if (fabs(tree.probe_SC_eta) < 1.4442) {
      ++nEB;
      hist3D->Fill(tree.dRTagProbe, tree.probe_nJets05, tree.event_nPV, totalWeight);
      hist2D->Fill(tree.dRTagProbe, tree.probe_passing, totalWeight);
    }
  }
  cout << "No. of probes in EB: " << nEB << endl;
  return nEvtsRead;
}
Пример #2
0
/// Load the specified event
Int_t DDG4EventHandler::ReadEvent(Long64_t event_number)   {
    m_data.clear();
    m_hasEvent = false;
    if ( hasFile() )  {
        if ( event_number >= m_file.second->GetEntries() )  {
            event_number = m_file.second->GetEntries()-1;
            printout(ERROR,"DDG4EventHandler","+++ ReadEvent: Cannot read across End-of-file! Reading last event:%d.",event_number);
        }
        else if ( event_number < 0 )  {
            event_number = 0;
            printout(ERROR,"DDG4EventHandler","+++ nextEvent: Cannot read across Start-of-file! Reading first event:%d.",event_number);
        }

        Int_t nbytes = m_file.second->GetEntry(event_number);
        if ( nbytes >= 0 )   {
            printout(ERROR,"DDG4EventHandler","+++ ReadEvent: Read %d bytes of event data for entry:%d",nbytes,event_number);
            for(Branches::const_iterator i=m_branches.begin(); i != m_branches.end(); ++i)  {
                TBranch* b = (*i).second.first;
                std::vector<void*>* ptr_data = *(std::vector<void*>**)b->GetAddress();
                m_data[b->GetClassName()].push_back(make_pair(b->GetName(),ptr_data->size()));
            }
            m_hasEvent = true;
            return nbytes;
        }
        printout(ERROR,"DDG4EventHandler","+++ ReadEvent: Cannot read event data for entry:%d",event_number);
        throw runtime_error("+++ EventHandler::readEvent: Failed to read event");
    }
    throw runtime_error("+++ EventHandler::readEvent: No file open!");
}
Пример #3
0
template <class HolderClass> bool verifyBranch(const char *testname, TTree *chain, const char *bname, int type = 0) {
   static HolderClass *gHolder = new HolderClass;
   HolderClass **add = 0;
   HolderClass *holder = 0;

   TBranch *branch = chain->GetBranch(bname);
   if (branch==0) {
      TestError("treeReading",Form("Missing branch: %s",bname));
      return false;
   }
   
   if (branch->InheritsFrom("TBranchObject")) {
      TLeafObject *tbo = dynamic_cast<TLeafObject*>(branch->GetListOfLeaves()->At(0));
      holder = (HolderClass*)(tbo->GetObject());

      if (holder==0) {
         TestError("treeReading",Form("BranchObject %s with holder == 0!",bname));
         return false;         
      }
   } else {
      add = (HolderClass**)branch->GetAddress();
      if (add==0) {
         TestError("treeReading",Form("Branch %s with add == 0!",bname));
         return false;
      }
      void **p;
      switch (type) {
         case 0: holder = *add; break;
         case 1: p = (void**) &(gHolder->fScalarPtr); *p = ((TBranchElement*)branch)->GetObject(); break;
         case 2: p = (void**) &(gHolder->fObjectPtr); *p = ((TBranchElement*)branch)->GetObject(); break;
         case 3: p = (void**) &(gHolder->fNestedPtr); *p = ((TBranchElement*)branch)->GetObject(); break;
      }
   }
   
   int splitlevel = branch->GetSplitLevel();

   switch (type) {
      case 0: return holder->Verify(chain->GetTree()->GetReadEntry(),Form("%s %s",testname,bname),splitlevel);
      case 1: return gHolder->VerifyScalarPtr(chain->GetTree()->GetReadEntry(),Form("%s %s",testname,bname),splitlevel);
      case 2: return gHolder->VerifyObjectPtr(chain->GetTree()->GetReadEntry(),Form("%s %s",testname,bname),splitlevel);
      case 3: return gHolder->VerifyNestedPtr(chain->GetTree()->GetReadEntry(),Form("%s %s",testname,bname),splitlevel);
      default: 
         TestError("treeReading",Form("Unknown type %d in verifyBranch",type));
         return false;
   }
}