ROOT logo
HYDRA - THE HADES ANALYSIS PACKAGE » UTIL » HLoop

class HLoop: public TObject

_HADES_CLASS_DESCRIPTION


 HLoop is a helper class to allow for fast looping of HADES dsts.
 The categories are maped directly from the Tree and allow partical
 reading to speed up. If Hades object exists, the current event structure
 will be replaced by the one defined by HLoop. If Hades not exists, it
 can be created by HLoop constructor. The Hades eventstructure is important
 if one wants to access the data via gHades->getCurrentEvent()->getCategory(cattype)
 or implicit by Classes like HParticleTrackSorter. See the example below for
 further explanation.



    HEventHeader* getEventHeader()  // retrieve the pointer to the HADES HEventHeader
    TTree*        getTree       ()  // retrieve the pointer to the HADES tree
    TChain*       getChain      ()  // retrieve TChain pointer
    Long64_t      getEntries    ()  // get Number of events in the chain


 example:

 #include "hloop.h"
 #include "hcategory.h"
 #include "hzip.h"
 #include "heventheader.h"
 #include "hgeantmedia.h"
 #include "hparticlecand.h"
 #include "hparticletracksorter.h"

 #include "TIterator.h"

 #include <iostream>
 using namespace std;
 void myLoop()
 {

    //---------------LOOP CONFIG----------------------------------------------------------------
    Bool_t createHades = kTRUE;  // kTRUE = create HADES new
    HLoop* loop = new HLoop(createHades); // create HADES (needed if one wants to use gHades)
    loop.setTreeCacheSize(8000000);//8MB (default is 8MB, values <= 0 will disable the cache)
    //--------------------------------------------------------------------------------------------
    loop->readSectorFileList("selection.list",kFALSE,kTRUE);  // hldname_without_evtbuilder 1 1 1 1 1 1
                                                              // a map of all files to active sector is filled
                                                              // see functions HLoop::getSectors(Int_t*), Bool_t HLoop::goodSector(Int_t sector),HSectorSelector& getSectorSelector()
                                                              // for file format description see HSectorSelector
                                                              // parmeters: default value for files not inside the list (kTRUE all sectors on, kFALSE all sectors off)
                                                              //            print the filelist during read
                                                              // If no list is read, all sectors are on by default
                                                              // reading the files list is optional
                                                              // lines which uses the feature are marked ##SECTOR_SELECTION## in the following example
    //--------------------------------------------------------------------------------------------

    // add files : Input sources may be combined
    loop->addFile ("myFile1.root");
    loop->addFile ("myFile2.root");  // ....
    loop->addFilesList("list.txt");  // add all files in ascii file list. list contains 1 root file per line (including path)
    loop->addFiles("myFiles*.root"); // add all files matching this expression
    loop->addMultFiles("file1.root,file2.root,file3.root");  add files as comma separated list
    HZip::makeChain("all_files.zip",loop->getChain()); // add all root files contained in zip file (this file has to be produced by hzip)

    if(!loop->setInput("-*,+HParticleCand")) // global disable "-*" has to be first in the list
    {                                        // read only one category from file (HEventHeader is allways on)
        exit(1);
    }
    loop->printCategories(); // print status from all categories in event
    //------------------------------------------------------------------------------------------

    TIterator* iterCand = 0;
    if (loop->getCategory("HParticleCand")) iterCand = loop->getCategory("HParticleCand")->MakeIterator();
    HEventHeader* header = loop->getEventHeader();
    HGeantMedia* media = loop->getGeantMedia();
    if(media){  // NULL for real data or if not in sim input
       media->print();
    }

    //--------------------------CONFIGURATION---------------------------------------------------
    //At begin of the program (outside the event loop)

    HParticleTrackSorter sorter;
    //sorter.setDebug();                                            // for debug
    //sorter.setPrintLevel(3);                                      // max prints
    //sorter.setRICHMatching(HParticleTrackSorter::kUseRKRICHWindow,4.); // select matching RICH-MDC for selectLeptons() function
    //sorter.setUseYMatching(kTRUE);                                // use meta cell build in select functions
    //sorter.setMetaBoundary(3.);                                   // match in 3 mm to meta cell
    //sorter.setUseBeta(kTRUE);                                     // require beta >0 in build in select functions
    //sorter.setBetaLeptonCut(0.9);                                 // lower beta cut for lepton select
    //sorter.setUseFakeRejection(kTRUE);                            // reject fakes in  build in select functions (default kTRUE)
    //sorter.setIgnoreInnerMDC();                                   // do not reject Double_t inner MDC hits
    //sorter.setIgnoreOuterMDC();                                   // do not reject Double_t outer MDC hits
    //sorter.setIgnoreMETA();                                       // do not reject Double_t META hits
    //sorter.setIgnorePreviousIndex();                              // do not reject indices from previous selctions
    sorter.init();                                                  // get catgegory pointers etc...
    //--------------------------------------------------------------------------------------------
    Int_t nFile = 0;

    //--------------------------------------------------------------------------------------------
    ##SECTOR_SELECTION##
    Int_t sectors[6];  // array of active sector  (1 active, 0 off) will be retrive inside loop for each event
    //--------------------------------------------------------------------------------------------

    for (Int_t i = 0; i < 10; i++) {
        if(loop->nextEvent(i) <= 0) break;  // get next event. categories will be cleared before
                                            // if 0 (entry not found) or -1 (Io error) is returned stop the loop
        //--------------------------------------------------------------------------------------------
        ##SECTOR_SELECTION##
        loop->getSectors(sectors);  // get active sectors for current event (somethime arrays are useful)
        //--------------------------------------------------------------------------------------------

        cout<<i<<"----------------------------------- "<<endl;
        cout<<"sequence Nr = "<<header->getEventSeqNumber()<<endl; // retrieve full header infos
        TString filename;
        if(loop->isNewFile(filename)){ // new file opened from chain ?
            cout<<"new File found "<<filename.Data()<<endl;
            nFile++;
	  }

        sorter.cleanUp();
        sorter.resetFlags(kTRUE,kTRUE,kTRUE,kTRUE);     // reset all flags for flags (0-28) ,reject,used,lepton
        Int_t nCandLep     = sorter.fill(HParticleTrackSorter::selectLeptons);   // fill only good leptons
        Int_t nCandLepBest = sorter.selectBest(HParticleTrackSorter::kIsBestRKRKMETA,HParticleTrackSorter::kIsLepton);
        Int_t nCandHad     = sorter.fill(HParticleTrackSorter::selectHadrons);   // fill only good hadrons (already marked good leptons will be skipped)
        Int_t nCandHadBest = sorter.selectBest(HParticleTrackSorter::kIsBestRKRKMETA,HParticleTrackSorter::kIsHadron);

        if(iterCand){
           iterCand->Reset();

           HParticleCand* cand;
           while ( (cand = (HParticleCand*)iterCand->Next()) != 0 ){
              // do some work  ....
              //--------------------------------------------------------------------------------------------
              ##SECTOR_SELECTION##
              if(!loop->goodSector(cand->getSector())) continue;  // skipp all candidates from inactive sectors
              //--------------------------------------------------------------------------------------------
          }
       }
    }
    sorter.finalize(); // clean up stuff

   if(createHades) delete gHades; // delete Hades or call destructor of HLoop.
 }



 A second example running a task with hloop.
 The task can use parameter containers if HSpectrometer
 and parameterio are specified. The task will be executed
 inside nextEvent() function.

 void hloopDst()
{
    Bool_t createHades=kTRUE;
    HLoop* loop = new HLoop(createHades);  // kTRUE : create Hades  (needed to work with standard eventstructure)
    loop.setTreeCacheSize(8000000);//8MB (default is 8MB, values <= 0 will disable the cache)

    TString asciiParFile = "/misc/kempter/projects/plot_dedx/param_31oct11.txt";
    TString rootParFile = "";

    Int_t mdcMods[6][4]={
	{0,0,0,0},
	{0,0,0,0},
	{1,1,1,1},
	{0,0,0,0},
	{1,1,1,1},
	{1,1,1,1} };

    HDst::setupSpectrometer    ("aug11_3sec",mdcMods,"rich,mdc,tof,rpc,shower,wall,tbox,start");
    HDst::setupParameterSources("ascii,oracle",asciiParFile,rootParFile,"now");

    loop->addFile("be1122719211201.hld_dst_aug11.root");

    if(!loop->setInput("")) { exit(1); } // read all categories

    HEventHeader* header = loop->getEventHeader();
    HGeantMedia* media   = loop->getGeantMedia();    // NULL if not in input file ()
    if(media){ // NULL if not in input file
        media->print();
    }


    loop->printCategories();
    loop->printChain();

    HTaskSet *masterTaskSet = gHades->getTaskSet("real");
    masterTaskSet->add(new HMdcPlotDeDx()); // some task derived from HReconstructor

    HCategory* catCand = HCategoryManager::getCategory(catParticleCand);
    if(!catCand) { exit(1); }

    Int_t entries=loop->getEntries();
    for (Int_t i=0; i < entries; i++) {
	Int_t nbytes =  loop->nextEvent(i);            // get next event. categories will be cleared before
	if(nbytes <= 0) { cout<<nbytes<<endl; break; } // last event reached

	if(catCand){
	    HParticleCand* cand=0;
	    for(Int_t j=0; j<catCand->getEntries();j++){
		cand = HCategoryManager::getObject(cand,catCand,j);
                // do something  ....
	    } // end loop cand
	} //catCand

    }// end event loop
    if(gHades)gHades->finalizeTasks();
    if(createHades) delete gHades; // delete Hades or call destructor of HLoop.
}


Function Members (Methods)

public:
HLoop(Bool_t createHades = kFALSE)
HLoop(const HLoop&)
virtual~HLoop()
voidTObject::AbstractMethod(const char* method) const
Bool_taddFile(TString infile)
Bool_taddFiles(TString expression)
Bool_taddFilesList(TString filelist)
Bool_taddMultFiles(TString commaSeparatedList)
virtual voidTObject::AppendPad(Option_t* option = "")
virtual voidTObject::Browse(TBrowser* b)
static TClass*Class()
virtual const char*TObject::ClassName() const
virtual voidTObject::Clear(Option_t* = "")
voidclearCategories()
virtual TObject*TObject::Clone(const char* newname = "") const
virtual Int_tTObject::Compare(const TObject* obj) const
virtual voidTObject::Copy(TObject& object) const
virtual voidTObject::Delete(Option_t* option = "")MENU
virtual Int_tTObject::DistancetoPrimitive(Int_t px, Int_t py)
virtual voidTObject::Draw(Option_t* option = "")
virtual voidTObject::DrawClass() constMENU
virtual TObject*TObject::DrawClone(Option_t* option = "") constMENU
virtual voidTObject::Dump() constMENU
virtual voidTObject::Error(const char* method, const char* msgfmt) const
virtual voidTObject::Execute(const char* method, const char* params, Int_t* error = 0)
virtual voidTObject::Execute(TMethod* method, TObjArray* params, Int_t* error = 0)
virtual voidTObject::ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual voidTObject::Fatal(const char* method, const char* msgfmt) const
virtual TObject*TObject::FindObject(const char* name) const
virtual TObject*TObject::FindObject(const TObject* obj) const
HCategory*getCategory(TString catname, Bool_t silent = kFALSE)
Bool_tgetCategoryStatus(TString catname, Bool_t silent = kFALSE)
TChain*getChain()
virtual Option_t*TObject::GetDrawOption() const
static Long_tTObject::GetDtorOnly()
Long64_tgetEntries()
HEventHeader*getEventHeader()
TObject*getFromInputFile(TString name = "")
HGeantHeader*getGeantHeader(Bool_t silent = kFALSE)
HGeantMedia*getGeantMedia()
virtual const char*TObject::GetIconName() const
virtual const char*TObject::GetName() const
virtual char*TObject::GetObjectInfo(Int_t px, Int_t py) const
static Bool_tTObject::GetObjectStat()
virtual Option_t*TObject::GetOption() const
HPartialEvent*getPartialEvent(TString catname, Bool_t silent = kFALSE)
voidgetSectors(Int_t* sectors)
HSectorSelector&getSectorSelector()
virtual const char*TObject::GetTitle() const
TTree*getTree()
virtual UInt_tTObject::GetUniqueID() const
Bool_tgoodSector(Int_t sector)
virtual Bool_tTObject::HandleTimer(TTimer* timer)
virtual ULong_tTObject::Hash() const
virtual voidTObject::Info(const char* method, const char* msgfmt) const
virtual Bool_tTObject::InheritsFrom(const char* classname) const
virtual Bool_tTObject::InheritsFrom(const TClass* cl) const
virtual voidTObject::Inspect() constMENU
voidTObject::InvertBit(UInt_t f)
virtual TClass*IsA() const
virtual Bool_tTObject::IsEqual(const TObject* obj) const
virtual Bool_tTObject::IsFolder() const
Bool_tisNewFile(TString& name)
Bool_tTObject::IsOnHeap() const
Bool_tisSkippedEvent()
virtual Bool_tTObject::IsSortable() const
Bool_tTObject::IsZombie() const
virtual voidTObject::ls(Option_t* option = "") const
voidTObject::MayNotUse(const char* method) const
Int_tnextEvent(Int_t iev)
virtual Bool_tTObject::Notify()
voidTObject::Obsolete(const char* method, const char* asOfVers, const char* removedFromVers) const
static voidTObject::operator delete(void* ptr)
static voidTObject::operator delete(void* ptr, void* vp)
static voidTObject::operator delete[](void* ptr)
static voidTObject::operator delete[](void* ptr, void* vp)
void*TObject::operator new(size_t sz)
void*TObject::operator new(size_t sz, void* vp)
void*TObject::operator new[](size_t sz)
void*TObject::operator new[](size_t sz, void* vp)
HLoop&operator=(const HLoop&)
virtual voidTObject::Paint(Option_t* option = "")
virtual voidTObject::Pop()
virtual voidTObject::Print(Option_t* option = "") const
voidprintBranchStatus()
voidprintCategories()
voidprintChain()
virtual Int_tTObject::Read(const char* name)
Bool_treadSectorFileList(TString filename, Bool_t defaultVal = kFALSE, Bool_t print = kFALSE)
virtual voidTObject::RecursiveRemove(TObject* obj)
voidTObject::ResetBit(UInt_t f)
virtual voidTObject::SaveAs(const char* filename = "", Option_t* option = "") constMENU
virtual voidTObject::SavePrimitive(ostream& out, Option_t* option = "")
voidTObject::SetBit(UInt_t f)
voidTObject::SetBit(UInt_t f, Bool_t set)
voidsetCurrentLoop()
virtual voidTObject::SetDrawOption(Option_t* option = "")MENU
static voidTObject::SetDtorOnly(void* obj)
Bool_tsetInput(TString readCategories = "")
static voidTObject::SetObjectStat(Bool_t stat)
voidsetRefID(Int_t id)
voidsetTreeCacheSize(Long64_t cs = 8000000)
virtual voidTObject::SetUniqueID(UInt_t uid)
virtual voidShowMembers(TMemberInspector&)
virtual voidStreamer(TBuffer&)
voidStreamerNVirtual(TBuffer& ClassDef_StreamerNVirtual_b)
virtual voidTObject::SysError(const char* method, const char* msgfmt) const
Bool_tTObject::TestBit(UInt_t f) const
Int_tTObject::TestBits(UInt_t f) const
virtual voidTObject::UseCurrentStyle()
virtual voidTObject::Warning(const char* method, const char* msgfmt) const
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0)
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) const
protected:
virtual voidTObject::DoError(int level, const char* location, const char* fmt, va_list va) const
voidTObject::MakeZombie()
private:
Bool_taddCatName(TString catname, Short_t catNum)
Bool_tsetStatus(TString catname, Int_t stat)

Data Members

private:
TChain*fChainchain
Long64_tfCurrentEntrycurrent entry in chain
TStringfCurrentNamecurrent file name
map<TString,HCategory*>fEventmap category name -> HCategory pointer
TFile*fFileCurrentcurrent file pointer
Bool_tfFirstEventtrue if first event called
HGeantMedia*fGeantMediapointer to HGEANT MEDIA (NULL if not avvailable!)
Bool_tfHasCreatedHadesremember if this class has created HADES
HEventHeader*fHeadpointer to HADES event header
Bool_tfIsCacheSetkTRUE if user has set the the cache.
Bool_tfIsNewFile== kTRUE for first entry after a new file is opened
Bool_tfIsSkipped== kTRUE event was skipped by tasklist
Long64_tfMaxEntriestotal number of entries in the chain
map<TString,Short_t>fNameToCatmap category name -> category number
map<TString,HPartialEvent*>fPartialmap partial event name -> HPartialEvent pointer
map<TString,TString>fPartialNmap category name -> partial event name
HRecEvent*fRecEventHADES event under reconstruction
Int_tfRefIDreference ID for init of params
HSectorSelectorfSectorSelectorselection of sectors from filelist
map<TString,Int_t>fStatusmap category name -> status
TTree*fTreecurrent Tree of the chain
Long64_tfTreeCacheDefaultSizedefault 8MB
Long64_tfTreeCacheSize
Bool_tfUseTaskSet== kTRUE if hades tasksets should be executed
Int_tfsectors[6]array of sector status form filelist

Class Charts

Inheritance Inherited Members Includes Libraries
Class Charts

Function documentation

HLoop(Bool_t createHades = kFALSE)
 if createHades == kTRUE (default=kFALSE) Hades will be created and event structure set
                == kFALSE Hades will not be created, but if exists
                   the event structure will be replaced by the one defined in HLoop
 if Hades does not exists and is not created new, the event structure will be
 available only via HLoop and not via gHades
~HLoop()
void setTreeCacheSize(Long64_t cs = 8000000)
 Configure the read of the Root Tree:
 default is 8MB to minimize the seek/read on the file system
 values <= 0 will disable the cache (for comparison)
 THis function has to be called before setInput().
Bool_t addFile(TString infile)
 add a single root file to the chain.
 It will be checked if the file exists.
Bool_t addFiles(TString expression)
Bool_t addFilesList(TString filelist)
 add all files in list filelist. The list should contain
 1 root file per line (including path). empty lines and
 commented lines (starting with "#") will be ignored.
 Return kFALSE if list files does not exist or and error
 occured while reading the file
Bool_t addMultFiles(TString commaSeparatedList)
 add multiple files as comma separated file list : "file1,file2,file3"
Bool_t setInput(TString readCategories = "")
 read in the given file structure. Categories can be
 disabled/enabled by the string readCategories. This
 string should contain a comma separated list. By default
 all categories are enabled. The format should be
 like (example 1) "-*,+HMdcCal1,+HParticleCand"
 (switch off all categories and enable just the to given
 ones. The global disable -* has to be the first in the
 list. Or (example 2) "-HMdcRaw,-HRichHit" (enable all
 categories, but not the give ones).  For simulation
 or real data one has to use the correct corresponding
 names (expample : HParticleCandSim / HParticleCand)
void printCategories()
 print all categories found in input + status
void printChain()
 print all files in the chain
void printBranchStatus()
 print the branch status of the chain
void clearCategories()
  clear all active catgegories of the event
HCategory* getCategory(TString catname, Bool_t silent = kFALSE)
 return the pointer to given category. NULL if not found
Bool_t getCategoryStatus(TString catname, Bool_t silent = kFALSE)
 return the status of a given category. kFALSE if not found
HPartialEvent* getPartialEvent(TString catname, Bool_t silent = kFALSE)
 return the pointer to given partialevent. NULL if not found
HGeantHeader* getGeantHeader(Bool_t silent = kFALSE)
 return the pointer to HGeantHader (subheader of PartialEvent Simul).
 NULL if not found
Bool_t setStatus(TString catname, Int_t stat)
 set the status of a given category. return kFALSE
 if something went wrong. if catname="-*" or "+*"
 all categories of the event are disabled /enabled.
Int_t nextEvent(Int_t iev)
 get next entry form tree. clears all active categories
 before. Returns number of read bytes
 (0 = entry not found , -1 = IO error)
 prints the current file name if a new file
 is entered in the chain
Bool_t addCatName(TString catname, Short_t catNum)
 add agiven category number to the HADES event structure.
 this function has to be called after setInput() !!!!
Bool_t isNewFile(TString& name)
 this function can be called after HLoop::nextEvent(Int_t iev)
 If a new file was opened kTRUE will be returned. The
 current file name will be returned by name
TObject* getFromInputFile(TString name = "")
 returns an object from root input file
 return 0 if not existsing, file not opened
 or anything else strange.
Bool_t getSectors(Int_t* sectors,TString filename)
HLoop(Bool_t createHades = kFALSE)
void setCurrentLoop()
{ gLoop=this;}
Bool_t readSectorFileList(TString filename, Bool_t defaultVal = kFALSE, Bool_t print = kFALSE)
{ fSectorSelector.setDefaultVal(defaultVal); return fSectorSelector.readInput(filename,print); }
HSectorSelector& getSectorSelector()
{ return fSectorSelector;}
Bool_t goodSector(Int_t sector)
{ return ( (sector < 6 && sector >=0 ) ? (fsectors[sector]==1) : kFALSE );}
HEventHeader* getEventHeader()
{ return fHead; }
HGeantMedia* getGeantMedia()
{ return fGeantMedia; }
TChain* getChain()
{ return fChain; }
TTree* getTree()
{ return fTree; }
Long64_t getEntries()
{ return fMaxEntries; }
Bool_t isSkippedEvent()
{ return fIsSkipped; }
void setRefID(Int_t id)
{ fRefID = id;}