More information on this package is here.
#include "TFilter.h"
//BEGIN_HTML <!--
/* -->
</pre><H1> TFilter </H1>
<p>This Class is the base class for writing data filters. I highly recommend that you use it by
<emph>deriving</emph> your own class from this one. All you then need to do is override the
default SelectEvent() fuction, which decides whether to keep the event or not. (The default
version keeps all events.) </p>
<p>Another good practice that I <b>strongly encourage</b> is that you keep a list of counters (TCounterCol) and
a list of histograms that <b>show all your cuts and percentage passed</b> and stick these results
right in the output file. This can save you a headache later trying to figure out what was in the files.</p>
<p><b>Notice:</b> This class only works with data read by the TDSTReader (i.e. written by Write_Root_DST).</p>
<pre>
<!-- */
// --> End_Html
ClassImp(TFilter)
;
TFilter::TFilter(){
cout << "TFilter initializer \n";
Interrupt = new TInterrupt();
gSystem->AddSignalHandler(Interrupt);
Time = new TStopwatch();
H= new TObjArray();
SetFixEC();
}
void TFilter::InitHistos(void){
cout << "WARNING: TFilter::InitHistos() called, should be overridden.\n";
C_Good_Event_Out = Cuts.AddCounter("Good Event written out.");
}
Int_t TFilter::SelectEvent(){
return 1;
}
void TFilter::DeleteHistos(void){
H->Delete();
}
void TFilter::ClearHistos(void){
TIter next(H);
TH1 *hist;
while( (hist= (TH1 *)next()) ){
hist->Reset();
}
}
void TFilter::Write(void){
TIter next(H);
TH1 *hist;
Cuts.Write("Cuts",TObject::kSingleKey);
TDirectory *dir=new TDirectory("Histograms","Filter Histograms");
dir->cd();
while( (hist= (TH1 *)next()) ){
hist->Write();
}
dir->cd("..");
}
TTree *TFilter::Create_Out_Tree(TDSTReader *dstread){
tree=new TTree("CLASEVENT","CLAS Event Tree filtered");
tree->SetAutoSave(1024*1024*1024);
TTree *chain=dstread->GetTree();
#define __BUFSIZE__ 16384
int bufsize = __BUFSIZE__;
int split = 1;
#define AUTO_CONSTRUCT_TREE
#ifdef AUTO_CONSTRUCT_TREE
TObjArray *branches=chain->GetListOfBranches();
TBranch *thisbranch;
TIter nextbr(branches);
while((thisbranch=(TBranch *)nextbr())){
cout << "Adding " << thisbranch->GetName() << " of type " << thisbranch->GetClassName() <<endl;
tree->Branch(thisbranch->GetName(),thisbranch->GetClassName(),(void **)thisbranch->GetAddress(),bufsize,split);
}
#else
tree->Branch("HEADER","THEADERClass",&dstread->fEvntHeader,bufsize,split);
tree->Branch("EVNT",&dstread->fcaEVNTStore,bufsize,split);
tree->Branch("ECPB",&dstread->fcaECPBStore,bufsize,split);
tree->Branch("SCPB",&dstread->fcaSCPBStore,bufsize,split);
tree->Branch("DCPB",&dstread->fcaDCPBStore,bufsize,split);
tree->Branch("CCPB",&dstread->fcaCCPBStore,bufsize,split);
tree->Branch("LCPB",&dstread->fcaLCPBStore,bufsize,split);
#ifdef WRITE_TGBI
tree->Branch("TGBI",&dstread->fcaTGBIStore,bufsize,split);
#endif
tree->Branch("MCHD",&dstread->fcaMCHDStore,bufsize,split);
#ifdef WRITE_PHOTON
tree->Branch("STPB",&dstread->fcaSTPBStore,bufsize,split);
tree->Branch("TGPB",&dstread->fcaTGPBStore,bufsize,split);
tree->Branch("TAGR",&dstread->fcaTAGRStore,bufsize,split);
#endif
#ifdef WRITE_VERTEX
tree->Branch("VERT",&dstread->fcaVERTStore,bufsize,split);
tree->Branch("MVRT",&dstread->fcaMVRTStore,bufsize,split);
#endif
#ifdef WRITE_TBER
tree->Branch("TBER",&dstread->fcaTBERStore,bufsize,split);
#endif
#ifdef WRITE_MCHD
tree->Branch("MCHD",&dstread->fcaMCHDStore);
#endif
#ifdef WRITE_GSIM
tree->Branch("GSIM",&dstread->fcaGSIMStore,bufsize,split);
#endif
#endif
tree->SetBranchStatus("*",1);
tree->SetMaxTreeSize(21474836480ULL);
return(tree);
}
Int_t TFilter::Run(Int_t Max_evt){
Int_t ntree=-1;
chain=GetTree();
TDSTReader *dstread = (TDSTReader *)GetReader();
tree = Create_Out_Tree(dstread);
cout << "Running ...." << endl;
Time->Start(kTRUE);
for(iEvent=0;iEvent<Max_evt && Next()==0; iEvent++){
if(iEvent % 100000 == 0 ){
printf("Analyzed %09d events, now at %09d, written %09d events.\n",iEvent,GetHEADER()->GetNEvent(),((TCounter *)Cuts[C_Good_Event_Out])->GetTrues());
}
if(ntree != chain->GetTreeNumber()){
ntree = chain->GetTreeNumber();
TIter next(chain->GetListOfBranches());
TBranch *branch;
while ((branch = (TBranch*)next())) {
void *add = branch->GetAddress();
if (add) tree->SetBranchAddress(branch->GetName(),add);
else{
cerr<<"ERROR- Can not reset the branches of output tree !\n";
return(-1);
}
}
}
if(Cuts.Test( SelectEvent() , C_Good_Event_Out)){
tree->Fill();
}
if(Interrupt->IsInterrupted()){
break;
}
}
Time->Stop();
printf("Processed %d events in %6.2f sec, %6.2f CPU sec. \n",iEvent,Time->RealTime(),Time->CpuTime());
printf("Rate is %7.1f events/sec, %7.1f events/CPUsec \n",iEvent/Time->RealTime(),iEvent/Time->CpuTime());
return(iEvent);
}
Author: Maurik Holtrop
Last update: ClasTool/TFilter.cc:$Name: $:$Id: TFilter.cc,v 1.3 2007/04/05 20:36:43 holtrop Exp $
CopyLeft - This code is freely available.
ROOT Home page - ClasTool Class index - Class Hierarchy - Top of the page