diff --git a/.github/pr-badge.yml b/.github/pr-badge.yml index f6508d325..1eaab6569 100644 --- a/.github/pr-badge.yml +++ b/.github/pr-badge.yml @@ -2,15 +2,15 @@ message: "$payload.pull_request.user.login" color: "blue" - label: "PR Size" - message: "Large" + message: "Large: $additions" color: "red" when: "$additions > 200" - label: "PR Size" - message: "Medium" + message: "Medium: $additions" color: "orange" - when: "$additions > 100" + when: "$additions > 100 and $additions < 201" - label: "PR Size" - message: "Ok" + message: "Ok: $additions" color: "green" when: "$additions < 100" - imageUrl: "https://gitlab.cern.ch/rest-for-physics/framework/badges/$branchName/pipeline.svg" diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6b159fcfd..b1fa2b6de 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -76,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} @@ -93,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} @@ -110,7 +110,7 @@ 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 @@ -118,13 +118,13 @@ Load REST Libraries: - 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/ @@ -137,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 @@ -149,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/ @@ -159,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/ @@ -169,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/ @@ -187,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/ @@ -198,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 @@ -209,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 @@ -228,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 @@ -242,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 @@ -256,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 @@ -269,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 @@ -283,14 +283,14 @@ 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/ @@ -298,7 +298,7 @@ AnalysisPlot2: - restRoot -b -q ValidateClassify.C Deploy: - type: deploy + stage: deploy only: - tags script: diff --git a/pipeline/MakeBasicTree.C b/pipeline/MakeBasicTree.C index d1ea9ceca..b5729b1e5 100644 --- a/pipeline/MakeBasicTree.C +++ b/pipeline/MakeBasicTree.C @@ -1,37 +1,67 @@ // This macro will extract the double observables and will fill a tree with std::vector -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 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(m) << endl; + cout << "index: " << obsValues.size() + << ", obsName: " << analysisTree->GetObservableName(m) + << " value: " << analysisTree->GetObservableValue(m) << endl; } - obsValues.push_back(aTree->GetObservableValue(m)); + obsValues.push_back(analysisTree->GetObservableValue(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("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; } diff --git a/pipeline/ValidateTrees.C b/pipeline/ValidateTrees.C index 32380d7eb..d07bc5a4c 100644 --- a/pipeline/ValidateTrees.C +++ b/pipeline/ValidateTrees.C @@ -1,52 +1,60 @@ #include #include + #include #include -Int_t ValidateTrees(TString validationFile) { - TFile* f = new TFile("results.root"); - TTree* tr = (TTree*)f->Get("bTree"); - std::vector* vr = 0; - tr->SetBranchAddress("doubleObservables", &vr); - - TFile* fV = new TFile(validationFile); - TTree* tV = (TTree*)fV->Get("bTree"); - std::vector* 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("bTree"); + std::vector* inputObservableVector = 0; + inputTree->SetBranchAddress("doubleObservables", &inputObservableVector); + + TFile validationFile(validationFilename); + TTree* validationTree = validationFile.Get("bTree"); + std::vector* 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; @@ -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; } diff --git a/source/framework/core/inc/TRestEvent.h b/source/framework/core/inc/TRestEvent.h index 8ce892f1b..ff5b7fd9e 100644 --- a/source/framework/core/inc/TRestEvent.h +++ b/source/framework/core/inc/TRestEvent.h @@ -55,45 +55,45 @@ class TRestEvent : public TObject { public: // Setters - void SetRunOrigin(Int_t run_origin) { fRunOrigin = run_origin; } - void SetSubRunOrigin(Int_t sub_run_origin) { fSubRunOrigin = sub_run_origin; } + inline void SetRunOrigin(Int_t run_origin) { fRunOrigin = run_origin; } + inline void SetSubRunOrigin(Int_t sub_run_origin) { fSubRunOrigin = sub_run_origin; } - void SetID(Int_t id) { fEventID = id; } - void SetSubID(Int_t id) { fSubEventID = id; } - void SetSubEventTag(TString tag) { fSubEventTag = tag; } + inline void SetID(Int_t id) { fEventID = id; } + inline void SetSubID(Int_t id) { fSubEventID = id; } + inline void SetSubEventTag(const TString& tag) { fSubEventTag = tag; } void SetTime(Double_t time); void SetTime(Double_t seconds, Double_t nanoseconds); - void SetTimeStamp(TTimeStamp time) { fEventTime = time; } + inline void SetTimeStamp(const TTimeStamp& time) { fEventTime = time; } - void SetState(Bool_t state) { fOk = state; } - void SetOK(Bool_t state) { fOk = state; } + inline void SetState(Bool_t state) { fOk = state; } + inline void SetOK(Bool_t state) { fOk = state; } void SetEventInfo(TRestEvent* eve); // Getters - Int_t GetID() { return fEventID; } - Int_t GetSubID() { return fSubEventID; } - TString GetSubEventTag() { return fSubEventTag; } + inline Int_t GetID() const { return fEventID; } + inline Int_t GetSubID() const { return fSubEventID; } + inline TString GetSubEventTag() const { return fSubEventTag; } - Int_t GetRunOrigin() { return fRunOrigin; } - Int_t GetSubRunOrigin() { return fSubRunOrigin; } + inline Int_t GetRunOrigin() const { return fRunOrigin; } + inline Int_t GetSubRunOrigin() const { return fSubRunOrigin; } - Double_t GetTime() { return fEventTime.AsDouble(); } - TTimeStamp GetTimeStamp() { return fEventTime; } + inline Double_t GetTime() const { return fEventTime.AsDouble(); } + inline TTimeStamp GetTimeStamp() const { return fEventTime; } - Bool_t isOk() { return fOk; } + inline Bool_t isOk() const { return fOk; } virtual void Initialize() = 0; virtual void InitializeWithMetadata(TRestRun* r); - virtual void PrintEvent(); + virtual void PrintEvent() const; ////////////////////////////////////////////////////////////////////////// /// \brief Draw the event /// /// To be implemented in the derived class - virtual TPad* DrawEvent(TString option = "") { + virtual TPad* DrawEvent(const TString& option = "") { UNUSED(option); return new TPad(); } @@ -105,6 +105,6 @@ class TRestEvent : public TObject { // Destructor virtual ~TRestEvent(); - ClassDef(TRestEvent, 1); // REST event superclass + ClassDef(TRestEvent, 1); }; -#endif \ No newline at end of file +#endif diff --git a/source/framework/core/inc/TRestHits.h b/source/framework/core/inc/TRestHits.h index 453c0975c..3e7784577 100644 --- a/source/framework/core/inc/TRestHits.h +++ b/source/framework/core/inc/TRestHits.h @@ -21,11 +21,11 @@ #ifndef TRestSoft_TRestHits #define TRestSoft_TRestHits +#include #include +#include #include #include -#include -#include #include @@ -62,145 +62,146 @@ class TRestHits : public TObject { void Translate(Int_t n, Double_t x, Double_t y, Double_t z); /// Event is rotated in XYZ. void RotateIn3D(Int_t n, Double_t alpha, Double_t beta, Double_t gamma, - TVector3 vMean); // vMean is the mean position of the event - // from GetMeanPosition() + const TVector3& vMean); // vMean is the mean position of the event from GetMeanPosition() /// Rotation around an arbitrary axis vAxis - void Rotate(Int_t n, Double_t alpha, TVector3 vAxis, - TVector3 vMean); // vMean is the mean position of the event from - // GetMeanPosition() + void Rotate(Int_t n, Double_t alpha, const TVector3& vAxis, + const TVector3& vMean); // vMean is the mean position of the event from GetMeanPosition() void AddHit(Double_t x, Double_t y, Double_t z, Double_t en, Double_t t = 0, REST_HitType type = XYZ); - void AddHit(TVector3 pos, Double_t en, Double_t t = 0, REST_HitType type = XYZ); + void AddHit(const TVector3& pos, Double_t en, Double_t t = 0, REST_HitType type = XYZ); void AddHit(TRestHits& hits, Int_t n); void RemoveHits(); - Int_t GetMostEnergeticHitInRange(Int_t n, Int_t m); + Int_t GetMostEnergeticHitInRange(Int_t n, Int_t m) const; - Double_t GetMaximumHitDistance(); - Double_t GetMaximumHitDistance2(); + Double_t GetMaximumHitDistance() const; + Double_t GetMaximumHitDistance2() const; virtual void MergeHits(int n, int m); virtual void SwapHits(Int_t i, Int_t j); virtual void RemoveHit(int n); - virtual Bool_t areXY(); - virtual Bool_t areXZ(); - virtual Bool_t areYZ(); - virtual Bool_t areXYZ(); + virtual Bool_t areXY() const; + virtual Bool_t areXZ() const; + virtual Bool_t areYZ() const; + virtual Bool_t areXYZ() const; - Bool_t isNaN(Int_t n); + Bool_t isNaN(Int_t n) const; - void GetXArray(Float_t* x); - void GetYArray(Float_t* y); - void GetZArray(Float_t* z); + void GetXArray(Float_t* x) const; + void GetYArray(Float_t* y) const; + void GetZArray(Float_t* z) const; void InitializeXArray(Float_t x = 0); void InitializeYArray(Float_t y = 0); void InitializeZArray(Float_t z = 0); - Double_t GetDistanceToNode(Int_t n); + Double_t GetDistanceToNode(Int_t n) const; - Bool_t isSortedByEnergy(); + Bool_t isSortedByEnergy() const; - Int_t GetNumberOfHits() { return fNHits; } + inline Int_t GetNumberOfHits() const { return fNHits; } - Double_t GetX(int n) { return ((Double_t)fX[n]); } // return value in mm - Double_t GetY(int n) { return ((Double_t)fY[n]); } // return value in mm - Double_t GetZ(int n) { return ((Double_t)fZ[n]); } // return value in mm - Double_t GetTime(int n) { return ((Double_t)fT[n]); } // return value in us - REST_HitType GetType(int n) { return fType[n]; } + inline Double_t GetX(int n) const { return ((Double_t)fX[n]); } // return value in mm + inline Double_t GetY(int n) const { return ((Double_t)fY[n]); } // return value in mm + inline Double_t GetZ(int n) const { return ((Double_t)fZ[n]); } // return value in mm + inline Double_t GetTime(int n) const { return ((Double_t)fT[n]); } // return value in us + inline REST_HitType GetType(int n) const { return fType[n]; } - TVector3 GetPosition(int n); - TVector3 GetVector(int i, int j); + TVector3 GetPosition(int n) const; + TVector3 GetVector(int i, int j) const; - Int_t GetNumberOfHitsX(); - Int_t GetNumberOfHitsY(); + Int_t GetNumberOfHitsX() const; + Int_t GetNumberOfHitsY() const; - Double_t GetMeanPositionX(); - Double_t GetMeanPositionY(); - Double_t GetMeanPositionZ(); - TVector3 GetMeanPosition(); + Double_t GetMeanPositionX() const; + Double_t GetMeanPositionY() const; + Double_t GetMeanPositionZ() const; + TVector3 GetMeanPosition() const; - Double_t GetSigmaXY2(); - Double_t GetSigmaX(); - Double_t GetSigmaY(); - Double_t GetSigmaZ2(); - Double_t GetSkewXY(); - Double_t GetSkewZ(); + Double_t GetSigmaXY2() const; + Double_t GetSigmaX() const; + Double_t GetSigmaY() const; + Double_t GetSigmaZ2() const; + Double_t GetSkewXY() const; + Double_t GetSkewZ() const; Double_t GetGaussSigmaX(); Double_t GetGaussSigmaY(); Double_t GetGaussSigmaZ(); - Double_t GetEnergyX(); - Double_t GetEnergyY(); + Double_t GetEnergyX() const; + Double_t GetEnergyY() const; - Double_t GetEnergy(int n) { return ((Double_t)fEnergy[n]); } // return value in keV + inline Double_t GetEnergy(int n) const { return ((Double_t)fEnergy[n]); } // return value in keV - Bool_t isHitNInsidePrism(Int_t n, TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, - Double_t theta); - Int_t GetNumberOfHitsInsidePrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, - Double_t theta); - Double_t GetEnergyInPrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, Double_t theta); - Double_t GetMeanPositionXInPrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, - Double_t theta); - Double_t GetMeanPositionYInPrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, - Double_t theta); - Double_t GetMeanPositionZInPrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, - Double_t theta); - TVector3 GetMeanPositionInPrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, Double_t theta); + Bool_t isHitNInsidePrism(Int_t n, const TVector3& x0, const TVector3& x1, Double_t sizeX, Double_t sizeY, + Double_t theta) const; + Int_t GetNumberOfHitsInsidePrism(const TVector3& x0, const TVector3& x1, Double_t sizeX, Double_t sizeY, + Double_t theta) const; + Double_t GetEnergyInPrism(const TVector3& x0, const TVector3& x1, Double_t sizeX, Double_t sizeY, + Double_t theta) const; + Double_t GetMeanPositionXInPrism(const TVector3& x0, const TVector3& x1, Double_t sizeX, Double_t sizeY, + Double_t theta) const; + Double_t GetMeanPositionYInPrism(const TVector3& x0, const TVector3& x1, Double_t sizeX, Double_t sizeY, + Double_t theta) const; + Double_t GetMeanPositionZInPrism(const TVector3& x0, const TVector3& x1, Double_t sizeX, Double_t sizeY, + Double_t theta) const; + TVector3 GetMeanPositionInPrism(const TVector3& x0, const TVector3& x1, Double_t sizeX, Double_t sizeY, + Double_t theta) const; - Bool_t isHitNInsideCylinder(Int_t n, TVector3 x0, TVector3 x1, Double_t radius); + Bool_t isHitNInsideCylinder(Int_t n, const TVector3& x0, const TVector3& x1, Double_t radius) const; - Int_t GetNumberOfHitsInsideCylinder(TVector3 x0, TVector3 x1, Double_t radius); - Int_t GetNumberOfHitsInsideCylinder(Int_t i, Int_t j, Double_t radius); + Int_t GetNumberOfHitsInsideCylinder(const TVector3& x0, const TVector3& x1, Double_t radius) const; + Int_t GetNumberOfHitsInsideCylinder(Int_t i, Int_t j, Double_t radius) const; - Double_t GetEnergyInCylinder(TVector3 x0, TVector3 x1, Double_t radius); - Double_t GetEnergyInCylinder(Int_t i, Int_t j, Double_t radius); - Double_t GetMeanPositionXInCylinder(TVector3 x0, TVector3 x1, Double_t radius); - Double_t GetMeanPositionYInCylinder(TVector3 x0, TVector3 x1, Double_t radius); - Double_t GetMeanPositionZInCylinder(TVector3 x0, TVector3 x1, Double_t radius); - TVector3 GetMeanPositionInCylinder(TVector3 x0, TVector3 x1, Double_t radius); + Double_t GetEnergyInCylinder(const TVector3& x0, const TVector3& x1, Double_t radius) const; + Double_t GetEnergyInCylinder(Int_t i, Int_t j, Double_t radius) const; + Double_t GetMeanPositionXInCylinder(const TVector3& x0, const TVector3& x1, Double_t radius) const; + Double_t GetMeanPositionYInCylinder(const TVector3& x0, const TVector3& x1, Double_t radius) const; + Double_t GetMeanPositionZInCylinder(const TVector3& x0, const TVector3& x1, Double_t radius) const; + TVector3 GetMeanPositionInCylinder(const TVector3& x0, const TVector3& x1, Double_t radius) const; - Bool_t isHitNInsideSphere(Int_t n, TVector3 pos0, Double_t radius); - Bool_t isHitNInsideSphere(Int_t n, Double_t x0, Double_t y0, Double_t z0, Double_t radius); + Bool_t isHitNInsideSphere(Int_t n, const TVector3& pos0, Double_t radius) const; + Bool_t isHitNInsideSphere(Int_t n, Double_t x0, Double_t y0, Double_t z0, Double_t radius) const; - Double_t GetEnergyInSphere(TVector3 pos0, Double_t radius); - Double_t GetEnergyInSphere(Double_t x, Double_t y, Double_t z, Double_t radius); + Double_t GetEnergyInSphere(const TVector3& pos0, Double_t radius) const; + Double_t GetEnergyInSphere(Double_t x, Double_t y, Double_t z, Double_t radius) const; - Double_t GetMaximumHitEnergy(); - Double_t GetMinimumHitEnergy(); - Double_t GetMeanHitEnergy(); + Double_t GetMaximumHitEnergy() const; + Double_t GetMinimumHitEnergy() const; + Double_t GetMeanHitEnergy() const; - Double_t GetEnergyIntegral(); - Double_t GetTotalDepositedEnergy() { return fTotEnergy; } - Double_t GetTotalEnergy() { return fTotEnergy; } - Double_t GetEnergy() { return fTotEnergy; } - Double_t GetDistance2(int n, int m); - Double_t GetDistance(int N, int M) { return TMath::Sqrt(GetDistance2(N, M)); } - Double_t GetTotalDistance(); + Double_t GetEnergyIntegral() const; + inline Double_t GetTotalDepositedEnergy() const { return fTotEnergy; } + inline Double_t GetTotalEnergy() const { return fTotEnergy; } + inline Double_t GetEnergy() const { return fTotEnergy; } + Double_t GetDistance2(int n, int m) const; + inline Double_t GetDistance(int N, int M) const { return TMath::Sqrt(GetDistance2(N, M)); } + Double_t GetTotalDistance() const; - Double_t GetHitsPathLength(Int_t n = 0, Int_t m = 0); + Double_t GetHitsPathLength(Int_t n = 0, Int_t m = 0) const; - Double_t GetHitsTwist(Int_t n, Int_t m); - Double_t GetHitsTwistWeighted(Int_t n, Int_t m); + Double_t GetHitsTwist(Int_t n, Int_t m) const; + Double_t GetHitsTwistWeighted(Int_t n, Int_t m) const; - Int_t GetClosestHit(TVector3 position); + Int_t GetClosestHit(const TVector3& position) const; - TVector2 GetProjection(Int_t n, Int_t m, TVector3 position); + TVector2 GetProjection(Int_t n, Int_t m, const TVector3& position) const; - Double_t GetTransversalProjection(TVector3 p0, TVector3 direction, TVector3 position); + Double_t GetTransversalProjection(const TVector3& p0, const TVector3& direction, + const TVector3& position) const; void WriteHitsToTextFile(TString filename); - virtual void PrintHits(Int_t nHits = -1); + virtual void PrintHits(Int_t nHits = -1) const; class TRestHits_Iterator : public std::iterator { private: int maxindex = 0; int index = 0; - TRestHits* fHits = 0; + TRestHits* fHits = nullptr; bool isaccessor = false; float _x; float _y; @@ -249,7 +250,7 @@ class TRestHits : public TObject { return i1.index > i2.index; } friend bool operator>=(const TRestHits_Iterator& i1, const TRestHits_Iterator& i2) { - // default comparsion logic + // default comparison logic return i1.index >= i2.index; } friend bool operator<(const TRestHits_Iterator& i1, const TRestHits_Iterator& i2) { @@ -266,11 +267,11 @@ class TRestHits : public TObject { TRestHits_Iterator(TRestHits* h, int _index); }; - TRestHits_Iterator begin() { return TRestHits_Iterator(this, 0); } - TRestHits_Iterator end() { return TRestHits_Iterator(this, fNHits); } + inline TRestHits_Iterator begin() { return TRestHits_Iterator(this, 0); } + inline TRestHits_Iterator end() { return TRestHits_Iterator(this, fNHits); } typedef TRestHits_Iterator iterator; - // Construtor + // Constructor TRestHits(); // Destructor ~TRestHits(); diff --git a/source/framework/core/inc/TRestVolumeHits.h b/source/framework/core/inc/TRestVolumeHits.h index 821bbeb85..f82e71d4e 100644 --- a/source/framework/core/inc/TRestVolumeHits.h +++ b/source/framework/core/inc/TRestVolumeHits.h @@ -35,9 +35,9 @@ class TRestVolumeHits : public TRestHits { public: void AddHit(Double_t x, Double_t y, Double_t z, Double_t en, Double_t time, REST_HitType type, - Double_t sigmax, Double_t sigmay, Double_t sigmaz); - void AddHit(TVector3 pos, Double_t en, Double_t time, REST_HitType type, TVector3 sigma); - void AddHit(TRestVolumeHits& hits, Int_t n); + Double_t sigmaX, Double_t sigmaY, Double_t sigmaZ); + void AddHit(const TVector3& pos, Double_t en, Double_t time, REST_HitType type, const TVector3& sigma); + void AddHit(const TRestVolumeHits& hits, Int_t n); void RemoveHits(); void MergeHits(Int_t n, Int_t m); @@ -46,26 +46,28 @@ class TRestVolumeHits : public TRestHits { void SortByEnergy(); void SwapHits(Int_t i, Int_t j); - Bool_t areXY(); - Bool_t areXZ(); - Bool_t areYZ(); - Bool_t areXYZ(); + Bool_t areXY() const override; + Bool_t areXZ() const override; + Bool_t areYZ() const override; + Bool_t areXYZ() const override; // Setters // Getters - Double_t GetSigmaX(int n) { return fSigmaX[n]; } // return value in mm - Double_t GetSigmaY(int n) { return fSigmaY[n]; } // return value in mm - Double_t GetSigmaZ(int n) { return fSigmaZ[n]; } // return value in mm + inline Double_t GetSigmaX(int n) const { return fSigmaX[n]; } // return value in mm + inline Double_t GetSigmaY(int n) const { return fSigmaY[n]; } // return value in mm + inline Double_t GetSigmaZ(int n) const { return fSigmaZ[n]; } // return value in mm - TVector3 GetSigma(int n); + TVector3 GetSigma(int n) const; - void PrintHits(); + void PrintHits() const; - Double_t GetClusterSize(int n) { + inline Double_t GetClusterSize(int n) const { return TMath::Sqrt(fSigmaX[n] * fSigmaX[n] + fSigmaY[n] * fSigmaY[n] + fSigmaZ[n] * fSigmaZ[n]); } - Double_t GetXYSize(int n) { return TMath::Sqrt(fSigmaX[n] * fSigmaX[n] + fSigmaY[n] * fSigmaY[n]); } + inline Double_t GetXYSize(int n) const { + return TMath::Sqrt(fSigmaX[n] * fSigmaX[n] + fSigmaY[n] * fSigmaY[n]); + } // Constructor & Destructor TRestVolumeHits(); diff --git a/source/framework/core/src/TRestEvent.cxx b/source/framework/core/src/TRestEvent.cxx index 6f7ead21e..89f28c896 100644 --- a/source/framework/core/src/TRestEvent.cxx +++ b/source/framework/core/src/TRestEvent.cxx @@ -73,7 +73,6 @@ void TRestEvent::Initialize() { fSubEventID = 0; fSubEventTag = ""; fOk = true; - fPad = nullptr; } @@ -81,18 +80,18 @@ void TRestEvent::Initialize() { /// Set the time of the event /// void TRestEvent::SetTime(Double_t time) { - Int_t sec = (Int_t)time; - Int_t nsec = (Int_t)((time - sec) * 1E9); + auto seconds = (Int_t)time; + auto nanoseconds = (Int_t)((time - seconds) * 1E9); - fEventTime.SetSec(sec); - fEventTime.SetNanoSec(nsec); + fEventTime.SetSec(seconds); + fEventTime.SetNanoSec(nanoseconds); } ////////////////////////////////////////////////////////////////////////// /// \brief Clone the content of this TRestEvent object to another /// /// This method uses default root streamer to do the copying. The efficiency is -/// low. Override recommanded. +/// low. Override recommended. void TRestEvent::CloneTo(TRestEvent* target) { if (this->ClassName() != target->ClassName()) { cout << "In TRestEvent::CloneTo() : Event type doesn't match! (This :" << this->ClassName() @@ -125,12 +124,12 @@ void TRestEvent::CloneTo(TRestEvent* target) { /// Set the time of the event /// void TRestEvent::SetTime(Double_t seconds, Double_t nanoseconds) { - fEventTime.SetSec(seconds); - fEventTime.SetNanoSec(nanoseconds); + fEventTime.SetSec((Int_t)seconds); + fEventTime.SetNanoSec((Int_t)nanoseconds); } ////////////////////////////////////////////////////////////////////////// -/// Copy the six univeral information in TRestEvent from another TRestEvent +/// Copy the six universal information in TRestEvent from another TRestEvent /// void TRestEvent::SetEventInfo(TRestEvent* eve) { if (eve != nullptr) { @@ -176,7 +175,7 @@ void TRestEvent::InitializeWithMetadata(TRestRun* r) { Initialize(); } /// You may want to call the base class inside the re-implemented one, /// by calling TRestEvent::PrintEvent(); /// -void TRestEvent::PrintEvent() { +void TRestEvent::PrintEvent() const { cout << "*******************************************************" << endl; cout << " EVENT ID : " << GetID() << endl; cout << " TIME : " << GetTimeStamp().AsString() << endl; diff --git a/source/framework/core/src/TRestHits.cxx b/source/framework/core/src/TRestHits.cxx index 255fbd1e6..e9641bac7 100644 --- a/source/framework/core/src/TRestHits.cxx +++ b/source/framework/core/src/TRestHits.cxx @@ -19,7 +19,9 @@ ///_______________________________________________________________________________ #include "TRestHits.h" + #include "TROOT.h" + using namespace std; using namespace TMath; @@ -32,7 +34,7 @@ TRestHits::TRestHits() { TRestHits::~TRestHits() {} -Bool_t TRestHits::areXY() { +Bool_t TRestHits::areXY() const { for (int i = 0; i < GetNumberOfHits(); i++) { if (fType[i] != XY) { // all hits should fit this condition to be considered XY @@ -44,7 +46,7 @@ Bool_t TRestHits::areXY() { return false; } -Bool_t TRestHits::areXZ() { +Bool_t TRestHits::areXZ() const { for (int i = 0; i < GetNumberOfHits(); i++) { if (fType[i] != XZ) { // all hits should fit this condition to be considered XY @@ -56,7 +58,7 @@ Bool_t TRestHits::areXZ() { return false; } -Bool_t TRestHits::areYZ() { +Bool_t TRestHits::areYZ() const { for (int i = 0; i < GetNumberOfHits(); i++) { if (fType[i] != YZ) { // all hits should fit this condition to be considered XY @@ -68,7 +70,7 @@ Bool_t TRestHits::areYZ() { return false; } -Bool_t TRestHits::areXYZ() { +Bool_t TRestHits::areXYZ() const { for (int i = 0; i < GetNumberOfHits(); i++) { if (fType[i] != XYZ) { // all hits should fit this condition to be considered XY @@ -80,12 +82,12 @@ Bool_t TRestHits::areXYZ() { return false; } -Bool_t TRestHits::isNaN(Int_t n) { +Bool_t TRestHits::isNaN(Int_t n) const { if (IsNaN(GetX(n)) && IsNaN(GetY(n)) && IsNaN(GetZ(n))) return true; return false; } -void TRestHits::GetXArray(Float_t* x) { +void TRestHits::GetXArray(Float_t* x) const { if (areYZ()) { for (int i = 0; i < GetNumberOfHits(); i++) x[i] = 0; } else { @@ -93,19 +95,7 @@ void TRestHits::GetXArray(Float_t* x) { } } -void TRestHits::InitializeXArray(Float_t x) { - for (int i = 0; i < GetNumberOfHits(); i++) fX[i] = x; -} - -void TRestHits::InitializeYArray(Float_t y) { - for (int i = 0; i < GetNumberOfHits(); i++) fY[i] = y; -} - -void TRestHits::InitializeZArray(Float_t z) { - for (int i = 0; i < GetNumberOfHits(); i++) fZ[i] = z; -} - -void TRestHits::GetYArray(Float_t* y) { +void TRestHits::GetYArray(Float_t* y) const { if (areXZ()) { for (int i = 0; i < GetNumberOfHits(); i++) y[i] = 0; } else { @@ -113,7 +103,7 @@ void TRestHits::GetYArray(Float_t* y) { } } -void TRestHits::GetZArray(Float_t* z) { +void TRestHits::GetZArray(Float_t* z) const { if (areXY()) { for (int i = 0; i < GetNumberOfHits(); i++) z[i] = 0; } else { @@ -121,14 +111,26 @@ void TRestHits::GetZArray(Float_t* z) { } } -Double_t TRestHits::GetEnergyIntegral() { +void TRestHits::InitializeXArray(Float_t x) { + for (int i = 0; i < GetNumberOfHits(); i++) fX[i] = x; +} + +void TRestHits::InitializeYArray(Float_t y) { + for (int i = 0; i < GetNumberOfHits(); i++) fY[i] = y; +} + +void TRestHits::InitializeZArray(Float_t z) { + for (int i = 0; i < GetNumberOfHits(); i++) fZ[i] = z; +} + +Double_t TRestHits::GetEnergyIntegral() const { Double_t sum = 0; for (int i = 0; i < GetNumberOfHits(); i++) sum += GetEnergy(i); return sum; } -Bool_t TRestHits::isHitNInsidePrism(Int_t n, TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, - Double_t theta) { +Bool_t TRestHits::isHitNInsidePrism(Int_t n, const TVector3& x0, const TVector3& x1, Double_t sizeX, + Double_t sizeY, Double_t theta) const { TVector3 axis = x1 - x0; Double_t prismLength = axis.Mag(); @@ -143,8 +145,8 @@ Bool_t TRestHits::isHitNInsidePrism(Int_t n, TVector3 x0, TVector3 x1, Double_t return false; } -Double_t TRestHits::GetEnergyInPrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, - Double_t theta) { +Double_t TRestHits::GetEnergyInPrism(const TVector3& x0, const TVector3& x1, Double_t sizeX, Double_t sizeY, + Double_t theta) const { Double_t energy = 0.; for (int n = 0; n < GetNumberOfHits(); n++) @@ -153,8 +155,8 @@ Double_t TRestHits::GetEnergyInPrism(TVector3 x0, TVector3 x1, Double_t sizeX, D return energy; } -Int_t TRestHits::GetNumberOfHitsInsidePrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, - Double_t theta) { +Int_t TRestHits::GetNumberOfHitsInsidePrism(const TVector3& x0, const TVector3& x1, Double_t sizeX, + Double_t sizeY, Double_t theta) const { Int_t hits = 0; for (int n = 0; n < GetNumberOfHits(); n++) @@ -163,7 +165,8 @@ Int_t TRestHits::GetNumberOfHitsInsidePrism(TVector3 x0, TVector3 x1, Double_t s return hits; } -Bool_t TRestHits::isHitNInsideCylinder(Int_t n, TVector3 x0, TVector3 x1, Double_t radius) { +Bool_t TRestHits::isHitNInsideCylinder(Int_t n, const TVector3& x0, const TVector3& x1, + Double_t radius) const { /* cout << "TRestHits::isHitNInsideCylinder has not been validated." << endl; cout << "After validation this output should be removed" << endl;*/ @@ -197,11 +200,11 @@ Bool_t TRestHits::isHitNInsideCylinder(Int_t n, TVector3 x0, TVector3 x1, Double return false; } -Double_t TRestHits::GetEnergyInCylinder(Int_t i, Int_t j, Double_t radius) { +Double_t TRestHits::GetEnergyInCylinder(Int_t i, Int_t j, Double_t radius) const { return GetEnergyInCylinder(this->GetPosition(i), this->GetPosition(j), radius); } -Double_t TRestHits::GetEnergyInCylinder(TVector3 x0, TVector3 x1, Double_t radius) { +Double_t TRestHits::GetEnergyInCylinder(const TVector3& x0, const TVector3& x1, Double_t radius) const { Double_t energy = 0.; for (int n = 0; n < GetNumberOfHits(); n++) { if (isHitNInsideCylinder(n, x0, x1, radius)) energy += this->GetEnergy(n); @@ -210,11 +213,12 @@ Double_t TRestHits::GetEnergyInCylinder(TVector3 x0, TVector3 x1, Double_t radiu return energy; } -Int_t TRestHits::GetNumberOfHitsInsideCylinder(Int_t i, Int_t j, Double_t radius) { +Int_t TRestHits::GetNumberOfHitsInsideCylinder(Int_t i, Int_t j, Double_t radius) const { return GetNumberOfHitsInsideCylinder(this->GetPosition(i), this->GetPosition(j), radius); } -Int_t TRestHits::GetNumberOfHitsInsideCylinder(TVector3 x0, TVector3 x1, Double_t radius) { +Int_t TRestHits::GetNumberOfHitsInsideCylinder(const TVector3& x0, const TVector3& x1, + Double_t radius) const { Int_t hits = 0; for (int n = 0; n < GetNumberOfHits(); n++) if (isHitNInsideCylinder(n, x0, x1, radius)) hits++; @@ -222,11 +226,11 @@ Int_t TRestHits::GetNumberOfHitsInsideCylinder(TVector3 x0, TVector3 x1, Double_ return hits; } -Double_t TRestHits::GetEnergyInSphere(TVector3 pos0, Double_t radius) { +Double_t TRestHits::GetEnergyInSphere(const TVector3& pos0, Double_t radius) const { return GetEnergyInSphere(pos0.X(), pos0.Y(), pos0.Z(), radius); } -Double_t TRestHits::GetEnergyInSphere(Double_t x0, Double_t y0, Double_t z0, Double_t radius) { +Double_t TRestHits::GetEnergyInSphere(Double_t x0, Double_t y0, Double_t z0, Double_t radius) const { Double_t sum = 0; for (int i = 0; i < GetNumberOfHits(); i++) { Double_t x = this->GetPosition(i).X(); @@ -240,11 +244,11 @@ Double_t TRestHits::GetEnergyInSphere(Double_t x0, Double_t y0, Double_t z0, Dou return sum; } -Bool_t TRestHits::isHitNInsideSphere(Int_t n, TVector3 pos0, Double_t radius) { +Bool_t TRestHits::isHitNInsideSphere(Int_t n, const TVector3& pos0, Double_t radius) const { return isHitNInsideSphere(n, pos0.X(), pos0.Y(), pos0.Z(), radius); } -Bool_t TRestHits::isHitNInsideSphere(Int_t n, Double_t x0, Double_t y0, Double_t z0, Double_t radius) { +Bool_t TRestHits::isHitNInsideSphere(Int_t n, Double_t x0, Double_t y0, Double_t z0, Double_t radius) const { Double_t x = this->GetPosition(n).X(); Double_t y = this->GetPosition(n).Y(); Double_t z = this->GetPosition(n).Z(); @@ -268,7 +272,7 @@ void TRestHits::AddHit(Double_t x, Double_t y, Double_t z, Double_t en, Double_t fTotEnergy += en; } -void TRestHits::AddHit(TVector3 pos, Double_t en, Double_t t, REST_HitType type) { +void TRestHits::AddHit(const TVector3& pos, Double_t en, Double_t t, REST_HitType type) { fNHits++; fX.push_back((Float_t)(pos.X())); @@ -309,7 +313,7 @@ void TRestHits::Translate(Int_t n, double x, double y, double z) { fZ[n] += z; } -void TRestHits::RotateIn3D(Int_t n, Double_t alpha, Double_t beta, Double_t gamma, TVector3 vMean) { +void TRestHits::RotateIn3D(Int_t n, Double_t alpha, Double_t beta, Double_t gamma, const TVector3& vMean) { TVector3 position = GetPosition(n); TVector3 vHit = position - vMean; @@ -322,7 +326,7 @@ void TRestHits::RotateIn3D(Int_t n, Double_t alpha, Double_t beta, Double_t gamm fZ[n] = vHit[2] + vMean[2]; } -void TRestHits::Rotate(Int_t n, Double_t alpha, TVector3 vAxis, TVector3 vMean) { +void TRestHits::Rotate(Int_t n, Double_t alpha, const TVector3& vAxis, const TVector3& vMean) { TVector3 vHit; vHit[0] = fX[n] - vMean[0]; @@ -336,21 +340,21 @@ void TRestHits::Rotate(Int_t n, Double_t alpha, TVector3 vAxis, TVector3 vMean) fZ[n] = vHit[2] + vMean[2]; } -Double_t TRestHits::GetMaximumHitEnergy() { +Double_t TRestHits::GetMaximumHitEnergy() const { Double_t energy = 0; for (int i = 0; i < GetNumberOfHits(); i++) if (GetEnergy(i) > energy) energy = GetEnergy(i); return energy; } -Double_t TRestHits::GetMinimumHitEnergy() { +Double_t TRestHits::GetMinimumHitEnergy() const { Double_t energy = GetMaximumHitEnergy(); for (int i = 0; i < GetNumberOfHits(); i++) if (GetEnergy(i) < energy) energy = GetEnergy(i); return energy; } -Double_t TRestHits::GetMeanHitEnergy() { return GetTotalEnergy() / GetNumberOfHits(); } +Double_t TRestHits::GetMeanHitEnergy() const { return GetTotalEnergy() / GetNumberOfHits(); } void TRestHits::MergeHits(int n, int m) { Double_t totalEnergy = fEnergy[n] + fEnergy[m]; @@ -378,7 +382,7 @@ void TRestHits::SwapHits(Int_t i, Int_t j) { iter_swap(fT.begin() + i, fT.begin() + j); } -Bool_t TRestHits::isSortedByEnergy() { +Bool_t TRestHits::isSortedByEnergy() const { for (int i = 0; i < GetNumberOfHits() - 1; i++) if (GetEnergy(i + 1) > GetEnergy(i)) return false; @@ -396,22 +400,22 @@ void TRestHits::RemoveHit(int n) { fNHits--; } -TVector3 TRestHits::GetPosition(int n) { - if ((fType.size() == 0 ? !IsNaN(fX[n]) : fType[n] == XY)) - return TVector3(((Double_t)fX[n]), ((Double_t)fY[n]), 0); - if ((fType.size() == 0 ? !IsNaN(fX[n]) : fType[n] == XZ)) - return TVector3(((Double_t)fX[n]), 0, ((Double_t)fZ[n])); - if ((fType.size() == 0 ? !IsNaN(fX[n]) : fType[n] == YZ)) - return TVector3(0, ((Double_t)fY[n]), ((Double_t)fZ[n])); - return TVector3(((Double_t)fX[n]), ((Double_t)fY[n]), ((Double_t)fZ[n])); +TVector3 TRestHits::GetPosition(int n) const { + if ((fType.size() == 0 ? !IsNaN(fX[n]) : fType[n] == XY)) { + return {(Double_t)fX[n], (Double_t)fY[n], 0}; + } + if ((fType.size() == 0 ? !IsNaN(fX[n]) : fType[n] == XZ)) { + return {(Double_t)fX[n], 0, (Double_t)fZ[n]}; + } + if ((fType.size() == 0 ? !IsNaN(fX[n]) : fType[n] == YZ)) { + return {0, (Double_t)fY[n], (Double_t)fZ[n]}; + } + return {(Double_t)fX[n], (Double_t)fY[n], (Double_t)fZ[n]}; } -TVector3 TRestHits::GetVector(int i, int j) { - TVector3 vector = GetPosition(i) - GetPosition(j); - return vector; -} +TVector3 TRestHits::GetVector(int i, int j) const { return GetPosition(i) - GetPosition(j); } -Int_t TRestHits::GetNumberOfHitsX() { +Int_t TRestHits::GetNumberOfHitsX() const { Int_t nHitsX = 0; for (int n = 0; n < GetNumberOfHits(); n++) @@ -420,7 +424,7 @@ Int_t TRestHits::GetNumberOfHitsX() { return nHitsX; } -Int_t TRestHits::GetNumberOfHitsY() { +Int_t TRestHits::GetNumberOfHitsY() const { Int_t nHitsY = 0; for (int n = 0; n < GetNumberOfHits(); n++) @@ -429,7 +433,7 @@ Int_t TRestHits::GetNumberOfHitsY() { return nHitsY; } -Double_t TRestHits::GetEnergyX() { +Double_t TRestHits::GetEnergyX() const { Double_t totalEnergy = 0; for (int n = 0; n < GetNumberOfHits(); n++) { if ((fType.size() == 0 ? !IsNaN(fX[n]) : fType[n] % X == 0)) { @@ -440,7 +444,7 @@ Double_t TRestHits::GetEnergyX() { return totalEnergy; } -Double_t TRestHits::GetEnergyY() { +Double_t TRestHits::GetEnergyY() const { Double_t totalEnergy = 0; for (int n = 0; n < GetNumberOfHits(); n++) { if ((fType.size() == 0 ? !IsNaN(fY[n]) : fType[n] % Y == 0)) { @@ -450,7 +454,7 @@ Double_t TRestHits::GetEnergyY() { return totalEnergy; } -Double_t TRestHits::GetMeanPositionX() { +Double_t TRestHits::GetMeanPositionX() const { Double_t meanX = 0; Double_t totalEnergy = 0; for (int n = 0; n < GetNumberOfHits(); n++) { @@ -466,7 +470,7 @@ Double_t TRestHits::GetMeanPositionX() { return meanX; } -Double_t TRestHits::GetMeanPositionY() { +Double_t TRestHits::GetMeanPositionY() const { Double_t meanY = 0; Double_t totalEnergy = 0; for (int n = 0; n < GetNumberOfHits(); n++) { @@ -482,7 +486,7 @@ Double_t TRestHits::GetMeanPositionY() { return meanY; } -Double_t TRestHits::GetMeanPositionZ() { +Double_t TRestHits::GetMeanPositionZ() const { Double_t meanZ = 0; Double_t totalEnergy = 0; for (int n = 0; n < GetNumberOfHits(); n++) { @@ -498,12 +502,12 @@ Double_t TRestHits::GetMeanPositionZ() { return meanZ; } -TVector3 TRestHits::GetMeanPosition() { +TVector3 TRestHits::GetMeanPosition() const { TVector3 mean(GetMeanPositionX(), GetMeanPositionY(), GetMeanPositionZ()); return mean; } -Double_t TRestHits::GetSigmaXY2() { +Double_t TRestHits::GetSigmaXY2() const { Double_t sigmaXY2 = 0; Double_t totalEnergy = this->GetTotalEnergy(); Double_t meanX = this->GetMeanPositionX(); @@ -517,7 +521,7 @@ Double_t TRestHits::GetSigmaXY2() { return sigmaXY2 /= totalEnergy; } -Double_t TRestHits::GetSigmaX() { +Double_t TRestHits::GetSigmaX() const { Double_t sigmaX2 = 0; Double_t sigmaX = 0; Double_t totalEnergy = this->GetTotalEnergy(); @@ -532,7 +536,7 @@ Double_t TRestHits::GetSigmaX() { return sigmaX = TMath::Sqrt(sigmaX2); } -Double_t TRestHits::GetSigmaY() { +Double_t TRestHits::GetSigmaY() const { Double_t sigmaY2 = 0; Double_t sigmaY = 0; Double_t totalEnergy = this->GetTotalEnergy(); @@ -552,113 +556,115 @@ void TRestHits::WriteHitsToTextFile(TString filename) { for (int i = 0; i < GetNumberOfHits(); i++) { if ((fType.size() == 0 ? !IsNaN(fX[i]) : fType[i] % X == 0)) fprintf(fff, "%d\t%e\t%s\t%e\t%e\n", i, fX[i], "NaN", fZ[i], fEnergy[i]); - if ((fType.size() == 0 ? !IsNaN(fY[i]) : fType[i] % Y == 0)) + if ((fType.size() == 0 ? !IsNaN(fY[i]) : fType[i] % Y == 0)) fprintf(fff, "%d\t%s\t%e\t%e\t%e\n", i, "NaN", fY[i], fZ[i], fEnergy[i]); } fclose(fff); } Double_t TRestHits::GetGaussSigmaX() { - Double_t gausSigmaX = 0; - Int_t nHits = GetNumberOfHits(); - Double_t x[nHits], y[nHits], ex[nHits], ey[nHits]; - if (nHits <= 3) { - gausSigmaX = 0; - } else { - for (int n = 0; n < GetNumberOfHits(); n++) { - x[n] = fX[n]; - y[n] = fEnergy[n]; - ex[n] = 0; - if (y[n] != 0) { - ey[n] = 10*sqrt(y[n]); - } else { - ey[n] = 0; - } - } - TGraphErrors *grX = new TGraphErrors(nHits,x,y,ex,ey); - Double_t maxY = MaxElement(nHits,grX->GetY()); - Double_t maxX = grX->GetX()[LocMax(nHits,grX->GetY())]; - - TF1 *fit = new TF1("","gaus"); - fit->SetParameter(0,maxY); - fit->SetParameter(1,maxX); - fit->SetParameter(2, 2.0); - grX->Fit(fit, "QNB"); // Q = quiet, no info in screen; N = no plot; B = no automatic start parmaeters; R = Use the Range specified in the function range - - gausSigmaX = fit->GetParameter(2); - - } - - return gausSigmaX; + Double_t gausSigmaX = 0; + Int_t nHits = GetNumberOfHits(); + Double_t x[nHits], y[nHits], ex[nHits], ey[nHits]; + if (nHits <= 3) { + gausSigmaX = 0; + } else { + for (int n = 0; n < GetNumberOfHits(); n++) { + x[n] = fX[n]; + y[n] = fEnergy[n]; + ex[n] = 0; + if (y[n] != 0) { + ey[n] = 10 * sqrt(y[n]); + } else { + ey[n] = 0; + } + } + TGraphErrors* grX = new TGraphErrors(nHits, x, y, ex, ey); + Double_t maxY = MaxElement(nHits, grX->GetY()); + Double_t maxX = grX->GetX()[LocMax(nHits, grX->GetY())]; + + TF1* fit = new TF1("", "gaus"); + fit->SetParameter(0, maxY); + fit->SetParameter(1, maxX); + fit->SetParameter(2, 2.0); + grX->Fit(fit, "QNB"); // Q = quiet, no info in screen; N = no plot; B = no automatic start + // parmaeters; R = Use the Range specified in the function range + + gausSigmaX = fit->GetParameter(2); + } + + return gausSigmaX; } Double_t TRestHits::GetGaussSigmaY() { - Double_t gausSigmaY = 0; - Int_t nHits = GetNumberOfHits(); - - Double_t x[nHits], y[nHits], ex[nHits], ey[nHits]; - if (nHits <= 3) { - gausSigmaY = 0; - } else { - for (int n = 0; n < GetNumberOfHits(); n++) { - x[n] = fY[n]; - y[n] = fEnergy[n]; - ex[n] = 0; - if (y[n] != 0) { - ey[n] = 10*sqrt(y[n]); - } else { - ey[n] = 0; - } - } - TGraphErrors *grY = new TGraphErrors(nHits,x,y,ex,ey); - Double_t maxY = MaxElement(nHits,grY->GetY()); - Double_t maxX = grY->GetX()[LocMax(nHits,grY->GetY())]; - - TF1 *fit = new TF1("","gaus"); - fit->SetParameter(0,maxY); - fit->SetParameter(1,maxX); - fit->SetParameter(2, 2.0); - grY->Fit(fit, "QNB"); // Q = quiet, no info in screen; N = no plot; B = no automatic start parmaeters; R = Use the Range specified in the function range - - gausSigmaY = fit->GetParameter(2); - } - return gausSigmaY; + Double_t gausSigmaY = 0; + Int_t nHits = GetNumberOfHits(); + + Double_t x[nHits], y[nHits], ex[nHits], ey[nHits]; + if (nHits <= 3) { + gausSigmaY = 0; + } else { + for (int n = 0; n < GetNumberOfHits(); n++) { + x[n] = fY[n]; + y[n] = fEnergy[n]; + ex[n] = 0; + if (y[n] != 0) { + ey[n] = 10 * sqrt(y[n]); + } else { + ey[n] = 0; + } + } + TGraphErrors* grY = new TGraphErrors(nHits, x, y, ex, ey); + Double_t maxY = MaxElement(nHits, grY->GetY()); + Double_t maxX = grY->GetX()[LocMax(nHits, grY->GetY())]; + + TF1* fit = new TF1("", "gaus"); + fit->SetParameter(0, maxY); + fit->SetParameter(1, maxX); + fit->SetParameter(2, 2.0); + grY->Fit(fit, "QNB"); // Q = quiet, no info in screen; N = no plot; B = no automatic start + // parmaeters; R = Use the Range specified in the function range + + gausSigmaY = fit->GetParameter(2); + } + return gausSigmaY; } Double_t TRestHits::GetGaussSigmaZ() { - Double_t gausSigmaZ = 0; - Int_t nHits = GetNumberOfHits(); - - Double_t x[nHits], y[nHits], ex[nHits], ey[nHits]; - if (nHits <= 3) { - gausSigmaZ = 0; - } else { - for (int n = 0; n < GetNumberOfHits(); n++) { - x[n] = fZ[n]; - y[n] = fEnergy[n]; - ex[n] = 0; - if (y[n] != 0) { - ey[n] = 10*sqrt(y[n]); - } else { - ey[n] = 0; - } - } - TGraphErrors *grZ = new TGraphErrors(nHits,x,y,ex,ey); - Double_t maxY = MaxElement(nHits,grZ->GetY()); - Double_t maxX = grZ->GetX()[LocMax(nHits,grZ->GetY())]; - - TF1 *fit = new TF1("","gaus",maxX-5,maxX+5); - fit->SetParameter(0,maxY); - fit->SetParameter(1,maxX); - fit->SetParameter(2, 2.0); - grZ->Fit(fit, "QNB"); // Q = quiet, no info in screen; N = no plot; B = no automatic start parmaeters; R = Use the Range specified in the function range - - gausSigmaZ = fit->GetParameter(2); - } - return gausSigmaZ; -} - -Double_t TRestHits::GetSkewXY() { + Double_t gausSigmaZ = 0; + Int_t nHits = GetNumberOfHits(); + + Double_t x[nHits], y[nHits], ex[nHits], ey[nHits]; + if (nHits <= 3) { + gausSigmaZ = 0; + } else { + for (int n = 0; n < GetNumberOfHits(); n++) { + x[n] = fZ[n]; + y[n] = fEnergy[n]; + ex[n] = 0; + if (y[n] != 0) { + ey[n] = 10 * sqrt(y[n]); + } else { + ey[n] = 0; + } + } + TGraphErrors* grZ = new TGraphErrors(nHits, x, y, ex, ey); + Double_t maxY = MaxElement(nHits, grZ->GetY()); + Double_t maxX = grZ->GetX()[LocMax(nHits, grZ->GetY())]; + + TF1* fit = new TF1("", "gaus", maxX - 5, maxX + 5); + fit->SetParameter(0, maxY); + fit->SetParameter(1, maxX); + fit->SetParameter(2, 2.0); + grZ->Fit(fit, "QNB"); // Q = quiet, no info in screen; N = no plot; B = no automatic start + // parmaeters; R = Use the Range specified in the function range + + gausSigmaZ = fit->GetParameter(2); + } + return gausSigmaZ; +} + +Double_t TRestHits::GetSkewXY() const { Double_t skewXY = 0; Double_t totalEnergy = this->GetTotalEnergy(); Double_t sigmaXY = TMath::Sqrt(this->GetSigmaXY2()); @@ -673,7 +679,7 @@ Double_t TRestHits::GetSkewXY() { return skewXY /= (totalEnergy * sigmaXY * sigmaXY * sigmaXY); } -Double_t TRestHits::GetSigmaZ2() { +Double_t TRestHits::GetSigmaZ2() const { Double_t sigmaZ2 = 0; Double_t totalEnergy = this->GetTotalEnergy(); Double_t meanZ = this->GetMeanPositionZ(); @@ -684,7 +690,7 @@ Double_t TRestHits::GetSigmaZ2() { return sigmaZ2 /= totalEnergy; } -Double_t TRestHits::GetSkewZ() { +Double_t TRestHits::GetSkewZ() const { Double_t skewZ = 0; Double_t totalEnergy = this->GetTotalEnergy(); Double_t sigmaZ = TMath::Sqrt(this->GetSigmaZ2()); @@ -696,8 +702,8 @@ Double_t TRestHits::GetSkewZ() { return skewZ /= (totalEnergy * sigmaZ * sigmaZ * sigmaZ); } -Double_t TRestHits::GetMeanPositionXInPrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, - Double_t theta) { +Double_t TRestHits::GetMeanPositionXInPrism(const TVector3& x0, const TVector3& x1, Double_t sizeX, + Double_t sizeY, Double_t theta) const { Double_t meanX = 0; Double_t totalEnergy = 0; for (int n = 0; n < GetNumberOfHits(); n++) { @@ -713,8 +719,8 @@ Double_t TRestHits::GetMeanPositionXInPrism(TVector3 x0, TVector3 x1, Double_t s return meanX; } -Double_t TRestHits::GetMeanPositionYInPrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, - Double_t theta) { +Double_t TRestHits::GetMeanPositionYInPrism(const TVector3& x0, const TVector3& x1, Double_t sizeX, + Double_t sizeY, Double_t theta) const { Double_t meanY = 0; Double_t totalEnergy = 0; for (int n = 0; n < GetNumberOfHits(); n++) { @@ -729,8 +735,8 @@ Double_t TRestHits::GetMeanPositionYInPrism(TVector3 x0, TVector3 x1, Double_t s return meanY; } -Double_t TRestHits::GetMeanPositionZInPrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, - Double_t theta) { +Double_t TRestHits::GetMeanPositionZInPrism(const TVector3& x0, const TVector3& x1, Double_t sizeX, + Double_t sizeY, Double_t theta) const { Double_t meanZ = 0; Double_t totalEnergy = 0; for (int n = 0; n < GetNumberOfHits(); n++) { @@ -745,15 +751,16 @@ Double_t TRestHits::GetMeanPositionZInPrism(TVector3 x0, TVector3 x1, Double_t s return meanZ; } -TVector3 TRestHits::GetMeanPositionInPrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, - Double_t theta) { +TVector3 TRestHits::GetMeanPositionInPrism(const TVector3& x0, const TVector3& x1, Double_t sizeX, + Double_t sizeY, Double_t theta) const { TVector3 mean(GetMeanPositionXInPrism(x0, x1, sizeX, sizeY, theta), GetMeanPositionYInPrism(x0, x1, sizeX, sizeY, theta), GetMeanPositionZInPrism(x0, x1, sizeX, sizeY, theta)); return mean; } -Double_t TRestHits::GetMeanPositionXInCylinder(TVector3 x0, TVector3 x1, Double_t radius) { +Double_t TRestHits::GetMeanPositionXInCylinder(const TVector3& x0, const TVector3& x1, + Double_t radius) const { Double_t meanX = 0; Double_t totalEnergy = 0; for (int n = 0; n < GetNumberOfHits(); n++) { @@ -769,7 +776,8 @@ Double_t TRestHits::GetMeanPositionXInCylinder(TVector3 x0, TVector3 x1, Double_ return meanX; } -Double_t TRestHits::GetMeanPositionYInCylinder(TVector3 x0, TVector3 x1, Double_t radius) { +Double_t TRestHits::GetMeanPositionYInCylinder(const TVector3& x0, const TVector3& x1, + Double_t radius) const { Double_t meanY = 0; Double_t totalEnergy = 0; for (int n = 0; n < GetNumberOfHits(); n++) { @@ -785,7 +793,8 @@ Double_t TRestHits::GetMeanPositionYInCylinder(TVector3 x0, TVector3 x1, Double_ return meanY; } -Double_t TRestHits::GetMeanPositionZInCylinder(TVector3 x0, TVector3 x1, Double_t radius) { +Double_t TRestHits::GetMeanPositionZInCylinder(const TVector3& x0, const TVector3& x1, + Double_t radius) const { Double_t meanZ = 0; Double_t totalEnergy = 0; for (int n = 0; n < GetNumberOfHits(); n++) { @@ -800,13 +809,13 @@ Double_t TRestHits::GetMeanPositionZInCylinder(TVector3 x0, TVector3 x1, Double_ return meanZ; } -TVector3 TRestHits::GetMeanPositionInCylinder(TVector3 x0, TVector3 x1, Double_t radius) { +TVector3 TRestHits::GetMeanPositionInCylinder(const TVector3& x0, const TVector3& x1, Double_t radius) const { TVector3 mean(GetMeanPositionXInCylinder(x0, x1, radius), GetMeanPositionYInCylinder(x0, x1, radius), GetMeanPositionZInCylinder(x0, x1, radius)); return mean; } -Double_t TRestHits::GetHitsPathLength(Int_t n, Int_t m) { +Double_t TRestHits::GetHitsPathLength(Int_t n, Int_t m) const { if (n < 0) n = 0; if (m > GetNumberOfHits() - 1) m = GetNumberOfHits() - 1; @@ -815,13 +824,13 @@ Double_t TRestHits::GetHitsPathLength(Int_t n, Int_t m) { return distance; } -Double_t TRestHits::GetTotalDistance() { +Double_t TRestHits::GetTotalDistance() const { Double_t distance = 0; for (int i = 0; i < GetNumberOfHits() - 1; i++) distance += TMath::Sqrt(GetDistance2(i, i + 1)); return distance; } -Double_t TRestHits::GetDistance2(int n, int m) { +Double_t TRestHits::GetDistance2(int n, int m) const { Double_t dx = GetX(n) - GetX(m); Double_t dy = GetY(n) - GetY(m); Double_t dz = GetZ(n) - GetZ(m); @@ -833,7 +842,7 @@ Double_t TRestHits::GetDistance2(int n, int m) { return dx * dx + dy * dy + dz * dz; } -Double_t TRestHits::GetDistanceToNode(Int_t n) { +Double_t TRestHits::GetDistanceToNode(Int_t n) const { Double_t distance = 0; if (n > GetNumberOfHits() - 1) n = GetNumberOfHits() - 1; @@ -842,20 +851,19 @@ Double_t TRestHits::GetDistanceToNode(Int_t n) { return distance; } -Int_t TRestHits::GetMostEnergeticHitInRange(Int_t n, Int_t m) { - Int_t maxEn = 0; +Int_t TRestHits::GetMostEnergeticHitInRange(Int_t n, Int_t m) const { + Int_t maxEnergy = 0; Int_t hit = -1; for (int i = n; i < m; i++) { - if (this->GetEnergy(i) > maxEn) { - maxEn = this->GetEnergy(i); + if (GetEnergy(i) > maxEnergy) { + maxEnergy = GetEnergy(i); hit = i; } } - // if (hit == -1) cout << "REST warning : No largest hit found! No hits?" << endl; return hit; } -Int_t TRestHits::GetClosestHit(TVector3 position) { +Int_t TRestHits::GetClosestHit(const TVector3& position) const { Int_t closestHit = 0; Double_t minDistance = 1.e30; @@ -872,22 +880,23 @@ Int_t TRestHits::GetClosestHit(TVector3 position) { return closestHit; } -TVector2 TRestHits::GetProjection(Int_t n, Int_t m, TVector3 position) { +TVector2 TRestHits::GetProjection(Int_t n, Int_t m, const TVector3& position) const { TVector3 nodesSegment = this->GetVector(n, m); TVector3 origin = position - this->GetPosition(m); - if (origin == TVector3(0, 0, 0)) return TVector2(0, 0); + if (origin == TVector3(0, 0, 0)) return {0, 0}; Double_t longitudinal = nodesSegment.Unit().Dot(origin); - if (origin == nodesSegment) return TVector2(longitudinal, 0); + if (origin == nodesSegment) return {longitudinal, 0}; Double_t transversal = TMath::Sqrt(origin.Mag2() - longitudinal * longitudinal); - return TVector2(longitudinal, transversal); + return {longitudinal, transversal}; } -Double_t TRestHits::GetTransversalProjection(TVector3 p0, TVector3 direction, TVector3 position) { +Double_t TRestHits::GetTransversalProjection(const TVector3& p0, const TVector3& direction, + const TVector3& position) const { TVector3 oX = position - p0; if (oX == TVector3(0, 0, 0)) return 0; @@ -897,7 +906,7 @@ Double_t TRestHits::GetTransversalProjection(TVector3 p0, TVector3 direction, TV return TMath::Sqrt(oX.Mag2() - longitudinal * longitudinal); } -Double_t TRestHits::GetHitsTwist(Int_t n, Int_t m) { +Double_t TRestHits::GetHitsTwist(Int_t n, Int_t m) const { if (n < 0) n = 0; if (m == 0) m = this->GetNumberOfHits(); @@ -918,7 +927,7 @@ Double_t TRestHits::GetHitsTwist(Int_t n, Int_t m) { return sum / cont; } -Double_t TRestHits::GetHitsTwistWeighted(Int_t n, Int_t m) { +Double_t TRestHits::GetHitsTwistWeighted(Int_t n, Int_t m) const { if (n < 0) n = 0; if (m == 0) m = this->GetNumberOfHits(); @@ -942,7 +951,7 @@ Double_t TRestHits::GetHitsTwistWeighted(Int_t n, Int_t m) { return sum / cont; } -Double_t TRestHits::GetMaximumHitDistance() { +Double_t TRestHits::GetMaximumHitDistance() const { Double_t maxDistance = 0; for (int n = 0; n < this->GetNumberOfHits(); n++) for (int m = n + 1; m < this->GetNumberOfHits(); m++) { @@ -953,7 +962,7 @@ Double_t TRestHits::GetMaximumHitDistance() { return maxDistance; } -Double_t TRestHits::GetMaximumHitDistance2() { +Double_t TRestHits::GetMaximumHitDistance2() const { Double_t maxDistance = 0; for (int n = 0; n < this->GetNumberOfHits(); n++) for (int m = n + 1; m < this->GetNumberOfHits(); m++) { @@ -964,7 +973,7 @@ Double_t TRestHits::GetMaximumHitDistance2() { return maxDistance; } -void TRestHits::PrintHits(Int_t nHits) { +void TRestHits::PrintHits(Int_t nHits) const { Int_t N = nHits; if (N == -1) N = GetNumberOfHits(); diff --git a/source/framework/core/src/TRestVolumeHits.cxx b/source/framework/core/src/TRestVolumeHits.cxx index f4c7ff306..7b5df4ef8 100644 --- a/source/framework/core/src/TRestVolumeHits.cxx +++ b/source/framework/core/src/TRestVolumeHits.cxx @@ -17,33 +17,34 @@ ///_______________________________________________________________________________ #include "TRestVolumeHits.h" + using namespace std; -ClassImp(TRestVolumeHits) - //______________________________________________________________________________ - TRestVolumeHits::TRestVolumeHits() { +ClassImp(TRestVolumeHits); + +TRestVolumeHits::TRestVolumeHits() { // TRestVolumeHits default constructor } -//______________________________________________________________________________ TRestVolumeHits::~TRestVolumeHits() { // TRestVolumeHits destructor } void TRestVolumeHits::AddHit(Double_t x, Double_t y, Double_t z, Double_t en, Double_t time, - REST_HitType type, Double_t sigmax, Double_t sigmay, Double_t sigmaz) { + REST_HitType type, Double_t sigmaX, Double_t sigmaY, Double_t sigmaZ) { if (fType.size() > 0 && type != fType[0]) { cout << "Error! Cannot add different typed hits into TRestVolumeHits!" << endl; return; } TRestHits::AddHit(x, y, z, en, time, type); - fSigmaX.push_back((Float_t)sigmax); - fSigmaY.push_back((Float_t)sigmay); - fSigmaZ.push_back((Float_t)sigmaz); + fSigmaX.push_back((Float_t)sigmaX); + fSigmaY.push_back((Float_t)sigmaY); + fSigmaZ.push_back((Float_t)sigmaZ); } -void TRestVolumeHits::AddHit(TVector3 pos, Double_t en, Double_t time, REST_HitType type, TVector3 sigma) { +void TRestVolumeHits::AddHit(const TVector3& pos, Double_t en, Double_t time, REST_HitType type, + const TVector3& sigma) { if (fType.size() > 0 && type != fType[0]) { cout << "Error! Cannot add different typed hits into TRestVolumeHits!" << endl; return; @@ -55,7 +56,7 @@ void TRestVolumeHits::AddHit(TVector3 pos, Double_t en, Double_t time, REST_HitT fSigmaZ.push_back((Float_t)sigma.Z()); } -void TRestVolumeHits::AddHit(TRestVolumeHits& hits, Int_t n) { +void TRestVolumeHits::AddHit(const TRestVolumeHits& hits, Int_t n) { Double_t x = hits.GetX(n); Double_t y = hits.GetY(n); Double_t z = hits.GetZ(n); @@ -83,25 +84,25 @@ void TRestVolumeHits::RemoveHits() { fSigmaZ.clear(); } -Bool_t TRestVolumeHits::areXY() { +Bool_t TRestVolumeHits::areXY() const { if (fType.size() == 0) return TMath::IsNaN(fZ[0]) && !TMath::IsNaN(fX[0]) && !TMath::IsNaN(fY[0]); else return fType[0] == XY; } -Bool_t TRestVolumeHits::areXZ() { +Bool_t TRestVolumeHits::areXZ() const { if (fType.size() == 0) return !TMath::IsNaN(fZ[0]) && !TMath::IsNaN(fX[0]) && TMath::IsNaN(fY[0]); else return fType[0] == XZ; } -Bool_t TRestVolumeHits::areYZ() { +Bool_t TRestVolumeHits::areYZ() const { if (fType.size() == 0) return !TMath::IsNaN(fZ[0]) && TMath::IsNaN(fX[0]) && !TMath::IsNaN(fY[0]); else return fType[0] == YZ; } -Bool_t TRestVolumeHits::areXYZ() { +Bool_t TRestVolumeHits::areXYZ() const { if (fType.size() == 0) return !TMath::IsNaN(fZ[0]) && !TMath::IsNaN(fX[0]) && !TMath::IsNaN(fY[0]); else @@ -127,11 +128,8 @@ void TRestVolumeHits::RemoveHit(int n) { TRestHits::RemoveHit(n); fSigmaX.erase(fSigmaX.begin() + n); - ; fSigmaY.erase(fSigmaY.begin() + n); - ; fSigmaZ.erase(fSigmaZ.begin() + n); - ; } void TRestVolumeHits::SortByEnergy() { @@ -152,11 +150,11 @@ void TRestVolumeHits::SwapHits(Int_t i, Int_t j) { TRestHits::SwapHits(i, j); } -TVector3 TRestVolumeHits::GetSigma(int n) { +TVector3 TRestVolumeHits::GetSigma(int n) const { return TVector3(((Double_t)fSigmaX[n]), ((Double_t)fSigmaY[n]), ((Double_t)fSigmaZ[n])); } -void TRestVolumeHits::PrintHits() { +void TRestVolumeHits::PrintHits() const { for (int n = 0; n < GetNumberOfHits(); n++) { cout << "Hit " << n << " X: " << GetX(n) << " Y: " << GetY(n) << " Z: " << GetZ(n) << " sX: " << GetSigmaX(n) << " sY: " << GetSigmaY(n) << " sZ: " << GetSigmaZ(n)