Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made some methods const #174

Merged
merged 21 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bb8a120
TRestEvent - made methods consts, used const references, increased cl…
lobis Apr 1, 2022
634364a
TRestHits - made some methods const
lobis Apr 1, 2022
52ec934
TRestHits - made all possible methods const
lobis Apr 1, 2022
e6da8d7
TRestHits - GetMostEnergeticHitInRange fixed bug
lobis Apr 1, 2022
aa5b537
TRestHits - made all function argument `TVector3` passed by const ref…
lobis Apr 1, 2022
6bad675
Geant4Lib - made most compatible methods const and fixed errors
lobis Apr 1, 2022
7d23903
TRestHits.cxx - added back bug to see if pipeline is fixed
lobis Apr 1, 2022
4073148
TRestEvent.h - reverted increase of class version
lobis Apr 1, 2022
2b138ed
pipeline - updated `MakeBasicTree.C` macro with more checks
lobis Apr 3, 2022
7e1732c
pipeline - updated `ValidateTrees.C` macro, more readable variable names
lobis Apr 3, 2022
092d4da
pipeline - renamed some variables in `MakeBasicTree.C` macro, more pr…
lobis Apr 3, 2022
1d06419
pipeline - fixed typo https://github.com/rest-for-physics/framework/p…
lobis Apr 4, 2022
80d87e3
pipeline/MakeBasicTree.C - added error on empty tree
lobis Apr 4, 2022
cede9bc
.gitlab-ci.yml - updated pipeline
lobis Apr 4, 2022
cdcb061
Adding const methods to TRestVolumeHits
juanangp Apr 5, 2022
4cdfdb1
Merge remote-tracking branch 'origin/master' into lobis-add-const-to-…
lobis Apr 5, 2022
4f45a62
TRestVolumeHits - made a few more methods const
lobis Apr 5, 2022
047d268
Merge branch 'master' into lobis-add-const-to-getters
jgalan Apr 5, 2022
d1f56b0
Merge branch 'master' into lobis-add-const-to-getters
jgalan Apr 5, 2022
99c0aea
Updating PR badge
jgalan Apr 5, 2022
7531f6d
Merge branch 'lobis-add-const-to-getters' of github.com:rest-for-phys…
jgalan Apr 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
image: ghcr.io/lobis/root-geant4-garfield:cpp17_ROOT-v6-26-00_Geant4-v10.4.3_Garfield-af4a1451
#image: nkx1231/root6-geant4-garfield:0.6
image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics

variables:
# GIT_SUBMODULE_STRATEGY: recursive
Expand Down Expand Up @@ -77,7 +76,7 @@ Validate Code:
- python3 pipeline/validateProcesses.py source/libraries/

Build and Test:
type: test
stage: test
script:
- cd ${CI_PROJECT_DIR}
- python3 pull-submodules.py --force --dontask --latest:${CI_COMMIT_BRANCH}
Expand All @@ -94,7 +93,7 @@ Build and Test:
expire_in: 1 day

Build and Install:
type: build
stage: build
script:
- cd ${CI_PROJECT_DIR}
- python3 pull-submodules.py --force --dontask --latest:${CI_COMMIT_BRANCH}
Expand All @@ -111,21 +110,21 @@ Build and Install:
expire_in: 1 day

Load REST Libraries:
type: install
stage: install
script:
- echo ${CI_PROJECT_DIR}/install/thisREST.sh
- cat ${CI_PROJECT_DIR}/install/thisREST.sh
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- restRoot -b -q

List REST Macros:
type: install
stage: install
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- restManager ListMacros

01_NLDBD:
type: restG4
stage: restG4
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/install/examples/restG4/01.NLDBD/
Expand All @@ -138,7 +137,7 @@ List REST Macros:
expire_in: 1 day

02_PandaXiiiMC:
type: restG4
stage: restG4
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/pandaxiii_MC
Expand All @@ -150,7 +149,7 @@ List REST Macros:
expire_in: 1 day

Load Gas:
type: metadata
stage: metadata
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/metadata/gas/
Expand All @@ -160,7 +159,7 @@ Load Gas:
- $CI_SERVER_HOST == "lfna.unizar.es"

Generate Gas:
type: metadata
stage: metadata
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/metadata/gas/
Expand All @@ -170,14 +169,14 @@ Generate Gas:
- $CI_SERVER_HOST == "lfna.unizar.es"

AnalysisTree:
type: core
stage: core
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/analysistree/
- restRoot -b -q simpleTree.cpp

Generate Readout:
type: metadata
stage: metadata
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/metadata/readout/
Expand All @@ -188,7 +187,7 @@ Generate Readout:
# - diff validation.txt print.txt

Basic Readout:
type: metadata
stage: metadata
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/projects/basic-readouts/
Expand All @@ -199,7 +198,7 @@ Basic Readout:
- restRoot -b -q BasicValidation.C'("basic.root", "pixelDecoding")'

Test Metadata:
type: restManager_generate
stage: restManager_generate
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/install/examples
Expand All @@ -210,7 +209,7 @@ Test Metadata:
expire_in: 1 day

TREX-DM Latest Data:
type: restManager_process
stage: restManager_process
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/trex
Expand All @@ -229,7 +228,7 @@ TREX-DM Latest Data:
expire_in: 1 day

PandaXIII Topological:
type: restManager_process
stage: restManager_process
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/pandaxiii_MC
Expand All @@ -243,7 +242,7 @@ PandaXIII Topological:
expire_in: 1 week

PandaXIII Topological from Geant4:
type: restManager_process
stage: restManager_process
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/pandaxiii_MC
Expand All @@ -257,7 +256,7 @@ PandaXIII Topological from Geant4:
expire_in: 1 week

PandaXIII Data:
type: restManager_process
stage: restManager_process
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/pandaxiii_data
Expand All @@ -270,7 +269,7 @@ PandaXIII Data:
expire_in: 1 week

Event Selection:
type: restManager_process
stage: restManager_process
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/selection
Expand All @@ -284,22 +283,22 @@ Event Selection:
expire_in: 1 week

AnalysisPlot:
type: postProcessing
stage: postProcessing
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/analysisPlot/
- restManager --c summary.rml --f ${CI_PROJECT_DIR}/pipeline/trex/Hits_01928.root

AnalysisPlot2:
type: postProcessing
stage: postProcessing
script:
- source ${CI_PROJECT_DIR}/install/thisREST.sh
- cd ${CI_PROJECT_DIR}/pipeline/analysisPlot/
- restManager --batch --c classify.rml
- restRoot -b -q ValidateClassify.C

Deploy:
type: deploy
stage: deploy
only:
- tags
script:
Expand Down
64 changes: 47 additions & 17 deletions pipeline/MakeBasicTree.C
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;
}
62 changes: 35 additions & 27 deletions pipeline/ValidateTrees.C
Original file line number Diff line number Diff line change
@@ -1,52 +1,60 @@
#include <TFile.h>
#include <TTree.h>

#include <iostream>
#include <vector>
Int_t ValidateTrees(TString validationFile) {
TFile* f = new TFile("results.root");
TTree* tr = (TTree*)f->Get("bTree");
std::vector<double>* vr = 0;
tr->SetBranchAddress("doubleObservables", &vr);

TFile* fV = new TFile(validationFile);
TTree* tV = (TTree*)fV->Get("bTree");
std::vector<double>* vV = 0;
tV->SetBranchAddress("doubleObservables", &vV);

if (tr->GetEntries() != tV->GetEntries()) {

Int_t ValidateTrees(const char* validationFilename, const char* inputFilename = "results.root") {
TFile inputFile(inputFilename);
TTree* inputTree = inputFile.Get<TTree>("bTree");
std::vector<double>* inputObservableVector = 0;
inputTree->SetBranchAddress("doubleObservables", &inputObservableVector);

TFile validationFile(validationFilename);
TTree* validationTree = validationFile.Get<TTree>("bTree");
std::vector<double>* validationObservableVector = 0;
validationTree->SetBranchAddress("doubleObservables", &validationObservableVector);

if (inputTree->GetEntries() != validationTree->GetEntries()) {
cout << "Number of entries is not the same!" << endl;
cout << "result: " << tr->GetEntries() << endl;
cout << "anticipated: " << tV->GetEntries() << endl;
cout << "result: " << inputTree->GetEntries() << endl;
cout << "anticipated: " << validationTree->GetEntries() << endl;
return 1;
}

bool obsValErr = false;
for (int n = 0; n < tr->GetEntries(); n++) {
tr->GetEntry(n);
tV->GetEntry(n);
for (int n = 0; n < inputTree->GetEntries(); n++) {
inputTree->GetEntry(n);
validationTree->GetEntry(n);

if ((*vr).size() != (*vV).size()) {
if ((*inputObservableVector).size() != (*validationObservableVector).size()) {
cout << "Vectors are different size at entry " << n << "!!" << endl;
cout << "results.root vector size : " << (*vr).size() << endl;
cout << "validation.root vector size : " << (*vV).size() << endl;
cout << "results.root vector size : " << (*inputObservableVector).size() << endl;
cout << "validation.root vector size : " << (*validationObservableVector).size() << endl;

cout << "Validation vector contents: " << endl;
for (int m = 0; m < (*vV).size(); m++) cout << (*vV)[m] << "\t";
for (int m = 0; m < (*validationObservableVector).size(); m++)
cout << (*validationObservableVector)[m] << "\t";
cout << endl;

cout << "Results vector contents: " << endl;
for (int m = 0; m < (*vr).size(); m++) cout << (*vr)[m] << "\t";
for (int m = 0; m < (*inputObservableVector).size(); m++)
cout << (*inputObservableVector)[m] << "\t";
cout << endl;
return 2;
}

for (int m = 0; m < (*vr).size(); m++) {
if ((Int_t)(1000. * (*vr)[m]) != (Int_t)(1000. * (*vV)[m])) {
for (int m = 0; m < (*inputObservableVector).size(); m++) {
if ((Int_t)(1000. * (*inputObservableVector)[m]) !=
(Int_t)(1000. * (*validationObservableVector)[m])) {
cout << "Double Observable with index " << m << " in entry " << n
<< " is not the same value!!" << endl;
printf(" value: %.15f, should be: %.15f\n", (*vr)[m], (*vV)[m]);
printf(" value: %.15f, should be: %.15f\n", (*inputObservableVector)[m],
(*validationObservableVector)[m]);

if (!TMath::IsNaN((*vr)[m] - (*vV)[m]) && abs(((*vr)[m] - (*vV)[m]) / (*vr)[m]) < 1e-15) {
if (!TMath::IsNaN((*inputObservableVector)[m] - (*validationObservableVector)[m]) &&
abs(((*inputObservableVector)[m] - (*validationObservableVector)[m]) /
(*inputObservableVector)[m]) < 1e-15) {
cout << " (ignored)" << endl;
} else {
obsValErr = true;
Expand All @@ -56,6 +64,6 @@ Int_t ValidateTrees(TString validationFile) {
}
if (obsValErr) return 3;

cout << "Tree validation sucess!" << endl;
cout << "Tree validation success!" << endl;
return 0;
}
Loading