Getting the max and min value from an EventList

Hi All,
I am trying to get the Maximum and Minimum value from an EventList, the EventList was populated with cutted events; after setup the EventList i got the max and min values as i had not the cut. How can i get those values from my EventList?

Best regards from Mexico

Cederik

[quote=“cederik”]Hi All,
I am trying to get the Maximum and Minimum value from an EventList, the EventList was populated with cutted events; after setup the EventList i got the max and min values as i had not the cut. How can i get those values from my EventList?

Best regards from Mexico

Cederik[/quote]

Hello.

What is this EventList? Is it some type of container ROOT provides? It would be nice if you can give us a code sample and/or .root file to reproduce the problem you have.

Thanks.

Hi, many thanks,
here is the extract from the code, as an example…

.
.
MyTree          = new TChain("events");
 
TCut            *MyCut         = new TCut((TString)CutString);
TEventList      *MyEventList   = new TEventList("ListofEvents");
 
MyTree->SetEventList(0);
MyTree->Draw((TString)(">>")+(TString)MyEventList->GetName(), *MyCut);
MyTree->SetEventList(MyEventList);
 
Max=MyTree->GetMaximum(SelectedBranch);
Min=MyTree->GetMinimum(SelectedBranch);

.
.
.

but

Min and Max, allways return the values as if no cut applied

Regards!

Hello cederik.

I think, what you need is an ‘entry list’, not an event list. And also, after a tree/chain creates this entry list in its Draw, you have to apply the selection:

[code]void evlist()
{
TTree tree(“tree”, “tree”);

Double_t x = 0;
tree.Branch(“x”, &x, “x/D”);
const unsigned nPoints = 1000;
const Double_t xMin = -10., xMax = 10., xStep = (xMax - xMin) / (nPoints - 1);
for (unsigned i = 0; i < nPoints; ++i) {
x = xMin + i * xStep;
tree.Fill();
}

std::cout<<"min == "<<tree.GetMinimum(“x”)<<std::endl;
std::cout<<"max == "<<tree.GetMaximum(“x”)<<std::endl;

tree.Draw(">>eList", “x>0”, “entrylist”);//Note: “entrylist” is a special option!

//Actually, it’s better to check the real type of object,
//but dynamic_cast does not work with CINT.
TEntryList * const eList = (TEntryList*)gDirectory->Get(“eList”);
if (eList) {
tree.SetEntryList(eList);
std::cout<<“After cut applied:\n”;
std::cout<<"min == "<<tree.GetMinimum(“x”)<<std::endl;
std::cout<<"max == "<<tree.GetMaximum(“x”)<<std::endl;
}
}
[/code]

As I’ve never worked with TTree/TChain, I can be wrong and may there is another way to use this ‘selection’ mechanics, but give it a try.

Best regards,
Timur.

Hi Timur,

I tried the code and the results are quite the same; maybe the issue it’s related with the TChain, the histograms draws fine and reproduces the cuts imposed. But the max and min are always related to the entire data collection.

Regards

[quote=“tpochep”]Hello cederik.

I think, what you need is an ‘entry list’, not an event list. And also, after a tree/chain creates this entry list in its Draw, you have to apply the selection:

[code]void evlist()
{
TTree tree(“tree”, “tree”);

Double_t x = 0;
tree.Branch(“x”, &x, “x/D”);
const unsigned nPoints = 1000;
const Double_t xMin = -10., xMax = 10., xStep = (xMax - xMin) / (nPoints - 1);
for (unsigned i = 0; i < nPoints; ++i) {
x = xMin + i * xStep;
tree.Fill();
}

std::cout<<"min == "<<tree.GetMinimum(“x”)<<std::endl;
std::cout<<"max == "<<tree.GetMaximum(“x”)<<std::endl;

tree.Draw(">>eList", “x>0”, “entrylist”);//Note: “entrylist” is a special option!

//Actually, it’s better to check the real type of object,
//but dynamic_cast does not work with CINT.
TEntryList * const eList = (TEntryList*)gDirectory->Get(“eList”);
if (eList) {
tree.SetEntryList(eList);
std::cout<<“After cut applied:\n”;
std::cout<<"min == "<<tree.GetMinimum(“x”)<<std::endl;
std::cout<<"max == "<<tree.GetMaximum(“x”)<<std::endl;
}
}
[/code]

As I’ve never worked with TTree/TChain, I can be wrong and may there is another way to use this ‘selection’ mechanics, but give it a try.

Best regards,
Timur.[/quote]

Show the code.

TEntryList * RootFileFormat::SetCuts(std::string CutString)
{
  log_debug("Access to Cuts");
 
  MyCut         = new TCut((TString)CutString);

 //MyTree has a global scope and indeed it is a TChain Type not  a TTree type 

  MyTree->SetEntryList(0);
  MyTree->Draw(">>eList",*MyCut,"entrylist");
  eList = (TEntryList*)gDirectory->Get("eList");
  MyTree->SetEntryList(eList);
  delete MyCut;
  return eList;
}

void histogram::FillHist(TChain *MChain,int cur_event, int nbins)
{
    double MinVal;
    double MaxVal;

    MinVal=MChain->GetMinimum((TString)VarToPlot.str());
    MaxVal=MChain->GetMaximum((TString)VarToPlot.str());

    log_debug("Min Val:" << MinVal << " " <<"Max Val: "<< MaxVal);
.
.
.

}

and I call them in this way:

 anEntryList=SetCuts("event.nTank<10");
 DefaultHisto->FillHist(MyTree,eData->gpsNanosecond,eData->nHit);

Hmm, can you, please, call Print on this resulting list? ‘eList->Print();’ after you’ve extracted it from the gDirectory.

After calling :

...
MyTree->SetEntryList(0);
  MyTree->Draw(">>eList",*MyCut,"entrylist");
  eList = (TEntryList*)gDirectory->Get("eList");
  MyTree->SetEntryList(eList);
  eList->Print("all");
...

We got:

The sum of these entries - is it equal to the total number of entries in your TChain?

[quote=“tpochep”][quote]
events /home/cederik/HEP/HAWC/data/2013Test/04/run000392/trig_00001.root 11
49075
223044
477808
924488
955955
993559
1024863
1107633
1214652
1214653
1214654
[/quote]

The sum of these entries - is it equal to the total number of entries in your TChain?[/quote]

No, my TChain, in this case, have more or less 2 million of entries.