-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from rest-for-physics/lobis-add-const-to-getters
Made some methods const
- Loading branch information
Showing
10 changed files
with
464 additions
and
417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,67 @@ | ||
// This macro will extract the double observables and will fill a tree with std::vector<double> | ||
Int_t MakeBasicTree(string fname) { | ||
TRestRun* run = new TRestRun(fname); | ||
Int_t MakeBasicTree(const char* inputFilename, const char* outputFilename = "results.root", | ||
Bool_t check = true) { | ||
TRestRun run(inputFilename); | ||
|
||
TRestAnalysisTree* aTree = run->GetAnalysisTree(); | ||
TRestAnalysisTree* analysisTree = run.GetAnalysisTree(); | ||
|
||
std::vector<double> obsValues; | ||
for (int n = 0; n < aTree->GetNumberOfObservables(); n++) { | ||
if (aTree->GetObservableType(n) == "double") obsValues.push_back(0); | ||
for (int n = 0; n < analysisTree->GetNumberOfObservables(); n++) { | ||
if (analysisTree->GetObservableType(n) == "double") obsValues.push_back(0); | ||
} | ||
|
||
TFile* outFile = new TFile("results.root", "RECREATE"); | ||
TTree* myTree = new TTree("bTree", "basicTree"); | ||
TFile* outFile = new TFile(outputFilename, "RECREATE"); | ||
TTree* outTree = new TTree("bTree", "basicTree"); | ||
|
||
myTree->Branch("doubleObservables", &obsValues); | ||
outTree->Branch("doubleObservables", &obsValues); | ||
|
||
for (int n = 0; n < run->GetEntries(); n++) { | ||
run->GetEntry(n); | ||
for (int n = 0; n < run.GetEntries(); n++) { | ||
run.GetEntry(n); | ||
// cout << "Entry : " << n << endl; | ||
|
||
obsValues.clear(); | ||
for (int m = 0; m < aTree->GetNumberOfObservables(); m++) { | ||
if (aTree->GetObservableType(m) == "double") { | ||
for (int m = 0; m < analysisTree->GetNumberOfObservables(); m++) { | ||
if (analysisTree->GetObservableType(m) == "double") { | ||
if (n == 0) { | ||
cout << "index: " << obsValues.size() << ", obsName: " << aTree->GetObservableName(m) | ||
<< " value: " << aTree->GetObservableValue<Double_t>(m) << endl; | ||
cout << "index: " << obsValues.size() | ||
<< ", obsName: " << analysisTree->GetObservableName(m) | ||
<< " value: " << analysisTree->GetObservableValue<Double_t>(m) << endl; | ||
} | ||
obsValues.push_back(aTree->GetObservableValue<Double_t>(m)); | ||
obsValues.push_back(analysisTree->GetObservableValue<Double_t>(m)); | ||
} | ||
} | ||
myTree->Fill(); | ||
outTree->Fill(); | ||
} | ||
|
||
myTree->Write(); | ||
// check all trees have the same number of elements | ||
if (run.GetEntries() != analysisTree->GetEntries() || run.GetEntries() != outTree->GetEntries()) { | ||
cout << "ERROR: mismatch in number of tree entries" << endl; | ||
return 1; | ||
} | ||
outTree->Write(); | ||
outFile->Close(); | ||
|
||
// check output file tree has the correct number of entries | ||
if (check) { | ||
TFile outFileCheck(outputFilename, "READ"); | ||
TTree* outTreeCheck = outFileCheck.Get<TTree>("bTree"); | ||
if (outTreeCheck == nullptr) { | ||
cout << "ERROR: tree was not correctly written into file" << endl; | ||
return 1; | ||
} | ||
|
||
if (outTreeCheck->GetEntries() != run.GetEntries()) { | ||
cout << "ERROR: output file check - mismatch in number of tree entries" << endl; | ||
return 1; | ||
} | ||
} | ||
|
||
if (run.GetEntries() == 0) { | ||
cout << "ERROR: Macro finished without issues but number of final entries is 0" << endl; | ||
return 1; | ||
} | ||
|
||
cout << "Finished `MakeBasicTree.C` macro. Number of entries: " << run.GetEntries() << endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.