23 #ifndef RestCore_TRestAnalysisTree
24 #define RestCore_TRestAnalysisTree
31 #include "TRestEvent.h"
32 #include "TRestReflector.h"
40 TString* fSubEventTag;
46 Int_t fSetObservableCalls = 0;
47 Int_t fSetObservableIndex = 0;
48 Bool_t fQuickSetObservableValue =
true;
49 std::vector<RESTValue> fObservables;
50 std::map<std::string, int> fObservableIdMap;
51 std::map<std::string, int> fObservableIdSearchMap;
56 std::vector<TString> fObservableNames;
57 std::vector<TString> fObservableDescriptions;
58 std::vector<TString> fObservableTypes;
64 void InitObservables();
66 void ReadLeafValueToObservable(TLeaf* lf,
RESTValue& obs);
67 bool BranchesExist() {
return GetListOfBranches()->GetEntriesFast() > 0; }
104 inline int GetStatus()
const {
return fStatus; }
110 Int_t GetSubEventID() {
113 Double_t GetTimeStamp() {
116 TString GetSubEventTag() {
121 Int_t GetRunOrigin() {
return fRunOrigin; }
122 Int_t GetSubRunOrigin() {
return fSubRunOrigin; }
126 RESTValue GetObservable(
const std::string& obsName);
141 std::cout <<
"Error! TRestAnalysisTree::GetObservableValue(): index outside limits!" << std::endl;
142 return std::numeric_limits<T>::quiet_NaN();
147 return fObservables[n].GetValue<T>();
164 return std::numeric_limits<T>::quiet_NaN();
167 return GetObservableValue<T>(
id);
176 std::cout <<
"Error! TRestAnalysisTree::SetObservableValue(): index outside limits!" << std::endl;
180 std::cout <<
"Error! cannot set observable! AnalysisTree is in chain state" << std::endl;
183 fObservables[id].SetValue(value);
225 if (fQuickSetObservableValue && fStatus == Filled && fSetObservableCalls ==
fNObservables) {
227 fSetObservableIndex++;
235 AddObservable<T>(name);
239 fSetObservableCalls++;
247 void PrintObservables();
248 void PrintObservable(
int N);
250 void SetRunOrigin(Int_t run_origin) { fRunOrigin = run_origin; }
251 void SetSubRunOrigin(Int_t sub_run_origin) { fSubRunOrigin = sub_run_origin; }
257 RESTValue AddObservable(
const TString& observableName,
const TString& observableType =
"double",
258 const TString& description =
"");
259 template <
typename T>
260 T& AddObservable(TString observableName, TString description =
"") {
261 return *(T*)AddObservable(observableName, REST_Reflection::GetTypeName<T>(), description);
264 Int_t GetEntry(Long64_t entry = 0, Int_t getall = 0);
282 Double_t GetIntegral(
const TString& obsName, Double_t xLow = -1, Double_t xHigh = -1) {
286 Double_t GetAverage(
const TString& obsName, Double_t xLow = -1, Double_t xHigh = -1) {
290 Double_t GetRMS(
const TString& obsName, Double_t xLow = -1, Double_t xHigh = -1) {
294 Double_t GetMinimum(
const TString& obsName, Double_t xLow = -1, Double_t xHigh = -1) {
298 Double_t GetMaximum(
const TString& obsName, Double_t xLow = -1, Double_t xHigh = -1) {
302 Double_t GetContour(
const TString& obsName,
const TString& obsIndexer, Double_t level = 0.5,
303 Int_t nBins = -1, Double_t xLow = -1, Double_t xHigh = -1) {
311 Double_t
GetObservableRMS(
const TString& obsName, Double_t xLow = -1, Double_t xHigh = -1);
316 Double_t
GetObservableContour(
const TString& obsName,
const TString& obsIndexer, Double_t level = 0.5,
317 Int_t nBins = -1, Double_t xLow = -1, Double_t xHigh = -1);
319 Int_t
WriteAsTTree(
const char* name = 0, Int_t option = 0, Int_t bufsize = 0);
325 TChain* GetChain() {
return fChain; }
329 Long64_t GetEntries()
const;
331 Long64_t GetEntries(
const char* sel);
333 void Browse(TBrowser* b) {
fChain ?
fChain->Browse(b) : TTree::Browse(b); }
334 Long64_t Draw(
const char* varexp,
const TCut& selection, Option_t* option =
"",
335 Long64_t nentries = kMaxEntries, Long64_t firstentry = 0) {
336 return fChain ?
fChain->Draw(varexp, selection, option, nentries, firstentry)
337 : TTree::Draw(varexp, selection, option, nentries, firstentry);
339 Long64_t Draw(
const char* varexp,
const char* selection, Option_t* option =
"",
340 Long64_t nentries = kMaxEntries, Long64_t firstentry = 0) {
341 return fChain ?
fChain->Draw(varexp, selection, option, nentries, firstentry)
342 : TTree::Draw(varexp, selection, option, nentries, firstentry);
344 void Draw(Option_t* opt) {
fChain ?
fChain->Draw(opt) : TTree::Draw(opt); }
345 TBranch* FindBranch(
const char* name) {
346 return fChain ?
fChain->FindBranch(name) : TTree::FindBranch(name);
348 TLeaf* FindLeaf(
const char* name) {
return fChain ?
fChain->FindLeaf(name) : TTree::FindLeaf(name); }
349 TBranch* GetBranch(
const char* name) {
return fChain ?
fChain->GetBranch(name) : TTree::GetBranch(name); }
350 Bool_t GetBranchStatus(
const char* branchname)
const {
351 return fChain ?
fChain->GetBranchStatus(branchname) : TTree::GetBranchStatus(branchname);
353 Long64_t GetCacheSize()
const {
return fChain ?
fChain->GetCacheSize() : TTree::GetCacheSize(); }
354 Long64_t GetChainEntryNumber(Long64_t entry)
const {
355 return fChain ?
fChain->GetChainEntryNumber(entry) : TTree::GetChainEntryNumber(entry);
357 Long64_t GetEntryNumber(Long64_t entry)
const {
358 return fChain ?
fChain->GetEntryNumber(entry) : TTree::GetEntryNumber(entry);
360 Long64_t GetReadEntry()
const {
return fChain ?
fChain->GetReadEntry() : TTree::GetReadEntry(); }
362 TH1* GetHistogram() {
return fChain ?
fChain->GetHistogram() : TTree::GetHistogram(); }
363 TLeaf* GetLeaf(
const char* branchname,
const char* leafname) {
364 return fChain ?
fChain->GetLeaf(branchname, leafname) : TTree::GetLeaf(branchname, leafname);
366 TLeaf* GetLeaf(
const char* name) {
return fChain ?
fChain->GetLeaf(name) : TTree::GetLeaf(name); }
367 TObjArray* GetListOfBranches() {
368 return fChain ?
fChain->GetListOfBranches() : TTree::GetListOfBranches();
370 TObjArray* GetListOfLeaves() {
return fChain ?
fChain->GetListOfLeaves() : TTree::GetListOfLeaves(); }
371 Long64_t Process(
const char* filename, Option_t* option =
"", Long64_t nentries = kMaxEntries,
372 Long64_t firstentry = 0) {
373 return fChain ?
fChain->Process(filename, option, nentries, firstentry)
374 : TTree::Process(filename, option, nentries, firstentry);
376 Long64_t Process(TSelector* selector, Option_t* option =
"", Long64_t nentries = kMaxEntries,
377 Long64_t firstentry = 0) {
378 return fChain ?
fChain->Process(selector, option, nentries, firstentry)
379 : TTree::Process(selector, option, nentries, firstentry);
381 Long64_t Scan(
const char* varexp =
"",
const char* selection =
"", Option_t* option =
"",
382 Long64_t nentries = kMaxEntries, Long64_t firstentry = 0) {
383 return fChain ?
fChain->Scan(varexp, selection, option, nentries, firstentry)
384 : TTree::Scan(varexp, selection, option, nentries, firstentry);
386 Int_t SetBranchAddress(
const char* bname,
void* add, TBranch** ptr = 0) {
387 return fChain ?
fChain->SetBranchAddress(bname, add, ptr) : TTree::SetBranchAddress(bname, add, ptr);
389 Int_t SetBranchAddress(
const char* bname,
void* add, TBranch** ptr, TClass* realClass, EDataType datatype,
391 return fChain ?
fChain->SetBranchAddress(bname, add, ptr, realClass, datatype, isptr)
392 : TTree::SetBranchAddress(bname, add, ptr, realClass, datatype, isptr);
394 Int_t SetBranchAddress(
const char* bname,
void* add, TClass* realClass, EDataType datatype,
396 return fChain ?
fChain->SetBranchAddress(bname, add, realClass, datatype, isptr)
397 : TTree::SetBranchAddress(bname, add, realClass, datatype, isptr);
399 void SetBranchStatus(
const char* bname, Bool_t status = 1, UInt_t* found = 0) {
400 fChain ?
fChain->SetBranchStatus(bname, status, found) : TTree::SetBranchStatus(bname, status, found);
402 void SetDirectory(TDirectory* dir) {
fChain ?
fChain->SetDirectory(dir) : TTree::SetDirectory(dir); }
404 void ResetBranchAddress(TBranch* br) {
405 fChain ?
fChain->ResetBranchAddress(br) : TTree::ResetBranchAddress(br);
407 void ResetBranchAddresses() {
fChain ?
fChain->ResetBranchAddresses() : TTree::ResetBranchAddresses(); }
REST core data-saving helper based on TTree.
void SetObservableValue(const std::string &name, const T &value)
Set the value of observable. May not check the name.
TString GetObservableDescription(Int_t n)
Get the observable description according to id.
T GetObservableValue(Int_t n)
Get observable in a given type, according to its id.
void DisableQuickObservableValueSetting()
It will disable quick observable value setting.
std::vector< std::string > GetCutObservables(const std::string &cut_str)
It will return a list with the names found in a string with conditions, as given in methods as Evalua...
void UpdateObservables()
Update observables stored in the tree.
Double_t GetObservableContour(const TString &obsName, const TString &obsIndexer, Double_t level=0.5, Int_t nBins=-1, Double_t xLow=-1, Double_t xHigh=-1)
This method generates a histogram of the the observable obsName given in the argument weighting it wi...
void EnableAllBranches()
It will enable all branches in the tree.
void EnableQuickObservableValueSetting()
It will enable quick observable value setting.
Long64_t LoadTree(Long64_t entry)
Overrides TTree::LoadTree(), to set current tree according to the given entry number,...
Bool_t AddChainFile(const std::string &file)
Add a series output file like TChain.
TString GetObservableName(Int_t n)
Get the observable name according to id.
void UpdateBranches()
Update branches in the tree.
Double_t GetObservableIntegral(const TString &obsName, Double_t xLow=-1, Double_t xHigh=-1)
It returns the integral of the observable considering the given range. If no range is given the full ...
TChain * fChain
used for quick search of certain observables
Bool_t EvaluateCuts(const std::string &expression)
This method will receive a string with several analysis observables/cuts in the same fashion as used ...
TTree * GetTree() const
Overrides TTree::GetTree(), to get the actual tree used in case of chain operation(fCurrentTree !...
Double_t GetObservableMaximum(const TString &obsName, Double_t xLow=-1, Double_t xHigh=-1)
It returns the maximum value of obsName considering the given range. If no range is given the full hi...
Int_t GetObservableID(const std::string &obsName)
Get the index of the specified observable.
void MakeObservableIdMap()
Update the map of observable name to observable id.
Int_t GetMatchedObservableID(const std::string &obsName)
Get the index of the observable, erasing the prefix if exists.
Double_t GetObservableAverage(const TString &obsName, Double_t xLow=-1, Double_t xHigh=-1)
It returns the average of the observable considering the given range. If no range is given the full h...
void DisableBranches(std::vector< std::string > obsNames)
It will disable the branches given by argument.
Double_t GetObservableRMS(const TString &obsName, Double_t xLow=-1, Double_t xHigh=-1)
It returns the RMS of the observable considering the given range. If no range is given the full histo...
Double_t GetDblObservableValue(const std::string &obsName)
Get double value of the observable, according to the name.
TString GetObservableType(Int_t n)
Get the observable type according to id.
void SetObservableValue(const Int_t &id, const T &value)
Set the value of observable whose index is id.
T GetObservableValue(std::string obsName)
Get observable in a given type, according to its name.
std::vector< std::string > GetObservableNames()
It returns a vector with strings containing all the observables that exist in the analysis tree.
void DisableAllBranches()
It will disable all branches in the tree.
Double_t GetObservableMinimum(const TString &obsName, Double_t xLow=-1, Double_t xHigh=-1)
It returns the minimum value of obsName considering the given range. If no range is given the full hi...
int EvaluateStatus()
Evaluate the Status of this tree.
Bool_t ObservableExists(const std::string &obsName)
Get if the specified observable exists.
Int_t fNObservables
in case multiple files for reading
void EnableBranches(std::vector< std::string > obsNames)
It will enable the branches given by argument.
Bool_t EvaluateCut(const std::string &expression)
This method will evaluate a condition on one analysis observable constructed as "observable>value"....
void SetObservable(Int_t id, RESTValue obs)
Set the value of observable whose id is as specified.
Int_t WriteAsTTree(const char *name=0, Int_t option=0, Int_t bufsize=0)
It writes TRestAnalysisTree as TTree, in order to migrate files to pure ROOT users.
A base class for any REST event.