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

Minor updates #263

Merged
merged 10 commits into from
Jul 12, 2022
85 changes: 38 additions & 47 deletions source/framework/core/inc/TRestHits.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,32 @@
#ifndef TRestSoft_TRestHits
#define TRestSoft_TRestHits

#include <TArrayD.h>
#include <TArrayI.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TGraphErrors.h>
#include <TH1.h>
#include <TMath.h>
#include <TMatrixD.h>
#include <TVector3.h>

#include <iostream>

#include "TArrayD.h"
#include "TArrayI.h"
#include "TCanvas.h"
#include "TMath.h"
#include "TMatrixD.h"
#include "TObject.h"

enum REST_HitType { unknown = -1, X = 2, Y = 3, Z = 5, XY = 6, XZ = 10, YZ = 15, XYZ = 30 };
//! It let save an event as a set of punctual deposition.
//! Allows saving an event as a set of punctual deposition.
//! It saves a 3-coordinate position and an energy for each punctual deposition.
class TRestHits : public TObject {
lobis marked this conversation as resolved.
Show resolved Hide resolved
public:
Int_t fNHits; ///< Number of punctual energy depositions, it is the length
///< for all the array
Double_t fTotEnergy; ///< Event total energy

std::vector<Float_t> fX; // [fNHits] Position on X axis for each punctual
// deposition (units mm)
std::vector<Float_t> fY; // [fNHits] Position on Y axis for each punctual
// deposition (units mm)
std::vector<Float_t> fZ; // [fNHits] Position on Z axis for each punctual
// deposition (units mm)
class TRestHits {
protected:
size_t fNHits = 0; ///< Number of punctual energy depositions, it is the length for all the arrays
Double_t fTotalEnergy = 0; ///< Event total energy

std::vector<Float_t> fX; // [fNHits] Position on X axis for each punctual deposition (units mm)
std::vector<Float_t> fY; // [fNHits] Position on Y axis for each punctual deposition (units mm)
std::vector<Float_t> fZ; // [fNHits] Position on Z axis for each punctual deposition (units mm)
std::vector<Float_t> fT; // [fNHits] Absolute time information for each punctual deposition
// (units us, 0 is time of decay)
std::vector<Float_t> fEnergy; // [fNHits] Energy deposited at each
// 3-coordinate position (units keV)
std::vector<Float_t> fEnergy; // [fNHits] Energy deposited at each 3-coordinate position (units keV)
std::vector<REST_HitType> fType; //

public:
Expand All @@ -71,13 +63,12 @@ class TRestHits : public TObject {
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) const;

Double_t GetMaximumHitDistance() const;
Double_t GetMaximumHitDistance2() const;

virtual void RemoveHits();
virtual void MergeHits(int n, int m);
virtual void SwapHits(Int_t i, Int_t j);
virtual void RemoveHit(int n);
Expand All @@ -101,7 +92,7 @@ class TRestHits : public TObject {

Bool_t isSortedByEnergy() const;

inline Int_t GetNumberOfHits() const { return fNHits; }
inline size_t GetNumberOfHits() const { return fNHits; }

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
Expand Down Expand Up @@ -174,9 +165,9 @@ class TRestHits : public TObject {
Double_t GetMeanHitEnergy() const;

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; }
inline Double_t GetTotalDepositedEnergy() const { return fTotalEnergy; }
inline Double_t GetTotalEnergy() const { return fTotalEnergy; }
inline Double_t GetEnergy() const { return fTotalEnergy; }
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;
Expand All @@ -202,10 +193,10 @@ class TRestHits : public TObject {

class TRestHits_Iterator : public std::iterator<std::random_access_iterator_tag, TRestHits_Iterator> {
private:
int maxindex = 0;
int maxIndex = 0;
int index = 0;
TRestHits* fHits = nullptr;
bool isaccessor = false;
bool isAccessor = false;
float _x;
float _y;
float _z;
Expand All @@ -214,19 +205,19 @@ class TRestHits : public TObject {
REST_HitType _type;

public:
float& x() { return isaccessor ? _x : fHits->fX[index]; }
float& y() { return isaccessor ? _y : fHits->fY[index]; }
float& z() { return isaccessor ? _z : fHits->fZ[index]; }
float& t() { return isaccessor ? _t : fHits->fT[index]; }
float& e() { return isaccessor ? _e : fHits->fEnergy[index]; }
REST_HitType& type() { return isaccessor ? _type : fHits->fType[index]; }

float x() const { return isaccessor ? _x : fHits->fX[index]; }
float y() const { return isaccessor ? _y : fHits->fY[index]; }
float z() const { return isaccessor ? _z : fHits->fZ[index]; }
float t() const { return isaccessor ? _t : fHits->fT[index]; }
float e() const { return isaccessor ? _e : fHits->fEnergy[index]; }
REST_HitType type() const { return isaccessor ? _type : fHits->fType[index]; }
float& x() { return isAccessor ? _x : fHits->fX[index]; }
float& y() { return isAccessor ? _y : fHits->fY[index]; }
float& z() { return isAccessor ? _z : fHits->fZ[index]; }
float& t() { return isAccessor ? _t : fHits->fT[index]; }
float& e() { return isAccessor ? _e : fHits->fEnergy[index]; }
REST_HitType& type() { return isAccessor ? _type : fHits->fType[index]; }

float x() const { return isAccessor ? _x : fHits->fX[index]; }
float y() const { return isAccessor ? _y : fHits->fY[index]; }
float z() const { return isAccessor ? _z : fHits->fZ[index]; }
float t() const { return isAccessor ? _t : fHits->fT[index]; }
float e() const { return isAccessor ? _e : fHits->fEnergy[index]; }
REST_HitType type() const { return isAccessor ? _type : fHits->fType[index]; }

// accessor: hit data is copied to self. The class acts like "TRestHit"
void toaccessor();
Expand All @@ -250,7 +241,7 @@ class TRestHits : public TObject {
return i1.fHits != i2.fHits || 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) {
Expand All @@ -271,16 +262,16 @@ class TRestHits : public TObject {

TRestHits_Iterator(TRestHits* h, int _index);
};
inline TRestHits_Iterator begin() { return TRestHits_Iterator(this, 0); }
inline TRestHits_Iterator end() { return TRestHits_Iterator(this, fNHits); }
inline TRestHits_Iterator begin() { return {this, 0}; }
inline TRestHits_Iterator end() { return {this, static_cast<int>(fNHits)}; }
typedef TRestHits_Iterator iterator;

// Constructor
TRestHits();
// Destructor
~TRestHits();

ClassDef(TRestHits, 5);
ClassDef(TRestHits, 6);
};

#endif
33 changes: 15 additions & 18 deletions source/framework/core/src/TRestHits.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ using namespace TMath;

ClassImp(TRestHits);

TRestHits::TRestHits() {
fNHits = 0;
fTotEnergy = 0;
}
TRestHits::TRestHits() = default;

TRestHits::~TRestHits() {}
TRestHits::~TRestHits() = default;

Bool_t TRestHits::areXY() const {
for (int i = 0; i < GetNumberOfHits(); i++) {
Expand Down Expand Up @@ -269,7 +266,7 @@ void TRestHits::AddHit(Double_t x, Double_t y, Double_t z, Double_t en, Double_t
fEnergy.push_back((Float_t)(en));
fType.push_back(type);

fTotEnergy += en;
fTotalEnergy += en;
}

void TRestHits::AddHit(const TVector3& pos, Double_t en, Double_t t, REST_HitType type) {
Expand All @@ -282,7 +279,7 @@ void TRestHits::AddHit(const TVector3& pos, Double_t en, Double_t t, REST_HitTyp
fEnergy.push_back((Float_t)(en));
fType.push_back(type);

fTotEnergy += en;
fTotalEnergy += en;
}

void TRestHits::AddHit(TRestHits& hits, Int_t n) {
Expand All @@ -304,7 +301,7 @@ void TRestHits::RemoveHits() {
fT.clear();
fEnergy.clear();
fType.clear();
fTotEnergy = 0;
fTotalEnergy = 0;
}

void TRestHits::Translate(Int_t n, double x, double y, double z) {
Expand Down Expand Up @@ -390,7 +387,7 @@ Bool_t TRestHits::isSortedByEnergy() const {
}

void TRestHits::RemoveHit(int n) {
fTotEnergy -= GetEnergy(n);
fTotalEnergy -= GetEnergy(n);
fX.erase(fX.begin() + n);
fY.erase(fY.begin() + n);
fZ.erase(fZ.begin() + n);
Expand Down Expand Up @@ -1011,9 +1008,9 @@ void TRestHits::PrintHits(Int_t nHits) const {
TRestHits::TRestHits_Iterator::TRestHits_Iterator(TRestHits* h, int _index) {
fHits = h;
index = _index;
maxindex = fHits->GetNumberOfHits();
maxIndex = fHits->GetNumberOfHits();
if (index < 0) index = 0;
if (index >= maxindex) index = maxindex;
if (index >= maxIndex) index = maxIndex;
}

void TRestHits::TRestHits_Iterator::toaccessor() {
Expand All @@ -1023,7 +1020,7 @@ void TRestHits::TRestHits_Iterator::toaccessor() {
_t = t();
_e = e();
_type = type();
isaccessor = true;
isAccessor = true;
}

TRestHits::TRestHits_Iterator TRestHits::TRestHits_Iterator::operator*() const {
Expand All @@ -1034,22 +1031,22 @@ TRestHits::TRestHits_Iterator TRestHits::TRestHits_Iterator::operator*() const {

TRestHits::TRestHits_Iterator& TRestHits::TRestHits_Iterator::operator++() {
index++;
if (index >= maxindex) index = maxindex;
if (index >= maxIndex) index = maxIndex;
return *this;
}

TRestHits::TRestHits_Iterator& TRestHits::TRestHits_Iterator::operator+=(const int& n) {
if (index + n >= maxindex) {
index = maxindex;
if (index + n >= maxIndex) {
index = maxIndex;
} else {
index += n;
}
return *this;
}

TRestHits::TRestHits_Iterator TRestHits::TRestHits_Iterator::operator+(const int& n) {
if (index + n >= maxindex) {
return TRestHits_Iterator(fHits, maxindex);
if (index + n >= maxIndex) {
return TRestHits_Iterator(fHits, maxIndex);
} else {
return TRestHits_Iterator(fHits, index + n);
}
Expand Down Expand Up @@ -1079,7 +1076,7 @@ TRestHits::TRestHits_Iterator TRestHits::TRestHits_Iterator::operator-(const int
}

TRestHits::TRestHits_Iterator& TRestHits::TRestHits_Iterator::operator=(const TRestHits_Iterator& iter) {
if (isaccessor) {
if (isAccessor) {
(fHits ? fHits->fX[index] : x()) = iter.x();
(fHits ? fHits->fY[index] : y()) = iter.y();
(fHits ? fHits->fZ[index] : z()) = iter.z();
Expand Down
28 changes: 10 additions & 18 deletions source/framework/core/src/TRestRun.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
#include <windows.h>
#undef GetClassName
#else
#include "unistd.h"
#include <sys/stat.h>
#include <unistd.h>
#endif // !WIN32

#include <filesystem>

#include "TRestDataBase.h"
#include "TRestEventProcess.h"
#include "TRestManager.h"
Expand All @@ -61,17 +63,7 @@ TRestRun::TRestRun(const string& filename) {
}
}

TRestRun::~TRestRun() {
// if (fEventTree != nullptr) {
// delete fEventTree;
//}

// if (fAnalysisTree != nullptr) {
// delete fAnalysisTree;
//}

CloseFile();
}
TRestRun::~TRestRun() { CloseFile(); }

///////////////////////////////////////////////
/// \brief Set variables by default during initialization.
Expand Down Expand Up @@ -116,8 +108,6 @@ void TRestRun::Initialize() {
fEventBranchLoc = -1;
fFileProcess = nullptr;
fSaveHistoricData = true;

return;
}

///////////////////////////////////////////////
Expand Down Expand Up @@ -1021,17 +1011,19 @@ TFile* TRestRun::MergeToOutputFile(vector<string> filenames, string outputfilena
}

///////////////////////////////////////////////
/// \brief Create a new TFile as REST output file. Writing metadata objects into
/// it.
/// \brief Create a new TFile as REST output file. Writing metadata objects into it.
///
TFile* TRestRun::FormOutputFile() {
CloseFile();

fOutputFileName = FormFormat(fOutputFileName);
// remove unwanted "./" etc. from the path while resolving them
fOutputFileName = std::filesystem::weakly_canonical(fOutputFileName.Data());

fOutputFile = new TFile(fOutputFileName, "recreate");
fAnalysisTree = new TRestAnalysisTree("AnalysisTree", "AnalysisTree");
fEventTree = new TTree("EventTree", "EventTree");
// fAnalysisTree->CreateBranches();
lobis marked this conversation as resolved.
Show resolved Hide resolved
// fEventTree->CreateEventBranches();

fAnalysisTree->Write();
fEventTree->Write();
this->WriteWithDataBase();
Expand Down