40#include "TRestDetectorHitsEvent.h"
44#include "TRestStringHelper.h"
45#include "TRestTools.h"
140 if (compareCondition == 0) {
144 return hit1.z() < hit2.z();
147 std::sort(
fHits->begin(),
fHits->end(), compareCondition);
151void TRestDetectorHitsEvent::Shuffle(
int NLoop) {
152 Int_t nHits =
fHits->GetNumberOfHits();
154 for (
int n = 0; n < NLoop; n++) {
155 Int_t hit1 = (Int_t)(nHits * gRandom->Uniform(0, 1));
156 Int_t hit2 = (Int_t)(nHits * gRandom->Uniform(0, 1));
173 for (
unsigned int i = 0; i < this->GetNumberOfHits(); i++)
174 if (GetType(i) == XZ)
191 for (
unsigned int i = 0; i < this->GetNumberOfHits(); i++)
192 if (GetType(i) == YZ)
208 for (
unsigned int i = 0; i < this->GetNumberOfHits(); i++)
209 if (GetType(i) == XYZ)
211 this->GetTime(i), XYZ);
337 Double_t sizeY, Double_t theta) {
352 Double_t sizeY, Double_t theta) {
368 Double_t rad2 = radius * radius;
369 Double_t hitDistance = rad2;
373 TVector3 axis = x1 - x0;
374 Double_t cylLength = axis.Mag();
377 for (
unsigned int n = 0; n < GetNumberOfHits(); n++) {
379 l = axis.Dot(this->GetPosition(n) - x0) / cylLength;
381 d2 = rad2 - (this->GetPosition(n) - x0).Mag2() + l * l;
383 if (d2 < hitDistance) hitDistance = d2;
389 if (nhits == 0)
return -1;
391 return TMath::Sqrt(hitDistance);
406 TVector3 axis = x1 - x0;
407 Double_t cylLength = axis.Mag();
409 Double_t hitDistance = cylLength;
410 Double_t d = cylLength;
413 for (
unsigned int n = 0; n < GetNumberOfHits(); n++) {
415 d = cylLength - axis.Dot(this->GetPosition(n) - x0) / cylLength;
417 if (d < hitDistance) hitDistance = d;
423 if (nhits == 0)
return -1;
440 TVector3 axis = x1 - x0;
441 Double_t cylLength = axis.Mag();
443 Double_t hitDistance = cylLength;
444 Double_t d = cylLength;
447 for (
unsigned int n = 0; n < GetNumberOfHits(); n++) {
449 d = axis.Dot(this->GetPosition(n) - x0) / cylLength;
451 if (d < hitDistance) hitDistance = d;
457 if (nhits == 0)
return -1;
475 Double_t sizeX, Double_t sizeY,
477 Double_t dX = sizeX / 2;
478 Double_t dY = sizeY / 2;
480 Double_t hitDistance = max(dX, dY);
484 for (
unsigned int n = 0; n < GetNumberOfHits(); n++) {
486 dX = sizeX / 2 - TMath::Abs((this->GetPosition(n) - x0).X());
487 dY = sizeY / 2 - TMath::Abs((this->GetPosition(n) - x0).Y());
491 if (d < hitDistance) hitDistance = d;
497 if (nhits == 0)
return -1;
515 Double_t sizeX, Double_t sizeY,
517 TVector3 axis = x1 - x0;
518 Double_t prismLength = axis.Mag();
520 Double_t hitDistance = prismLength;
524 for (
unsigned int n = 0; n < GetNumberOfHits(); n++) {
526 d = prismLength - axis.Dot(this->GetPosition(n) - x0) / prismLength;
528 if (d < hitDistance) hitDistance = d;
534 if (nhits == 0)
return -1;
552 const TVector3& x1, Double_t sizeX,
553 Double_t sizeY, Double_t theta) {
554 TVector3 axis = x1 - x0;
555 Double_t prismLength = axis.Mag();
557 Double_t hitDistance = prismLength;
561 for (
unsigned int n = 0; n < GetNumberOfHits(); n++) {
563 d = axis.Dot(this->GetPosition(n) - x0) / prismLength;
565 if (d < hitDistance) hitDistance = d;
571 if (nhits == 0)
return -1;
603 for (
unsigned int n = 0; n < optList.size(); n++) {
604 if (optList[n] ==
"print") this->
PrintEvent();
607 optList.erase(std::remove(optList.begin(), optList.end(),
"print"), optList.end());
611 if (optList.size() == 0) optList.push_back(
"hist(Cont1,col)[3]");
613 if (fPad !=
nullptr) {
618 fPad =
new TPad(this->GetName(),
" ", 0, 0, 1, 1);
619 fPad->Divide(3, 2 * optList.size());
623 for (
unsigned int n = 0; n < optList.size(); n++) {
624 string optionStr = (string)optList[n];
625 TString drawEventOption = optList[n];
628 size_t startPos = optionStr.find(
"(");
629 if (startPos != string::npos) drawEventOption = optList[n](0, startPos);
632 string histOption =
"";
633 size_t endPos = optionStr.find(
")");
634 if (endPos != string::npos) {
635 TString histOptionTmp = optList[n](startPos + 1, endPos - startPos - 1);
637 histOption = (string)histOptionTmp;
639 while ((pos = histOption.find(
",", pos)) != string::npos) {
640 histOption.replace(pos, 1,
":");
646 string pitchOption =
"";
648 startPos = optionStr.find(
"[");
649 endPos = optionStr.find(
"]");
651 if (endPos != string::npos) {
652 TString pitchOption = optList[n](startPos + 1, endPos - startPos - 1);
653 pitch = stod((
string)pitchOption);
656 if (drawEventOption ==
"graph") this->
DrawGraphs(column);
658 if (drawEventOption ==
"hist") this->
DrawHistograms(column, histOption, pitch);
685 vector<vector<Double_t>> xz(2, vector<Double_t>(this->GetNumberOfHits()));
686 vector<vector<Double_t>> yz(2, vector<Double_t>(this->GetNumberOfHits()));
687 vector<vector<Double_t>> xy(2, vector<Double_t>(this->GetNumberOfHits()));
694 for (
unsigned int nhit = 0; nhit < this->GetNumberOfHits(); nhit++) {
695 Double_t x =
fHits->GetX(nhit);
696 Double_t y =
fHits->GetY(nhit);
697 Double_t z =
fHits->GetZ(nhit);
698 int type =
fHits->GetType(nhit);
700 if (type % XZ == 0) {
706 if (type % YZ == 0) {
712 if (type % XY == 0) {
719 fXZHitGraph =
new TGraph(nXZ, &xz[0][0], &xz[1][0]);
724 fYZHitGraph =
new TGraph(nYZ, &yz[0][0], &yz[1][0]);
729 fXYHitGraph =
new TGraph(nXY, &xy[0][0], &xy[1][0]);
736 sprintf(title,
"Event ID %d", this->GetID());
739 fPad->cd(1 + 3 * column);
748 fPad->cd(2 + 3 * column);
757 fPad->cd(3 + 3 * column);
783 std::vector<double> fX, fY, fZ;
784 for (
unsigned int i = 0; i < GetNumberOfHits(); i++) {
785 if (GetType(i) % X == 0) fX.emplace_back(
GetX(i));
786 if (GetType(i) % Y == 0) fY.emplace_back(
GetY(i));
787 if (GetType(i) % Z == 0) fZ.emplace_back(
GetZ(i));
790 double maxX, minX, maxY, minY, maxZ, minZ;
791 int nBinsX, nBinsY, nBinsZ;
797 nBinsX = std::round((maxX - minX) / pitch);
798 nBinsY = std::round((maxY - minY) / pitch);
799 nBinsZ = std::round((maxZ - minZ) / pitch);
810 fXYHisto =
new TH2F(
"XY",
"", nBinsX, minX, maxX, nBinsY, minY, maxY);
811 fXZHisto =
new TH2F(
"XZ",
"", nBinsX, minX, maxX, nBinsZ, minZ, maxZ);
812 fYZHisto =
new TH2F(
"YZ",
"", nBinsY, minY, maxY, nBinsZ, minZ, maxZ);
814 fXHisto =
new TH1F(
"X",
"", nBinsX, minX, maxX);
815 fYHisto =
new TH1F(
"Y",
"", nBinsY, minY, maxY);
816 fZHisto =
new TH1F(
"Z",
"", nBinsZ, minZ, maxZ);
826 Int_t nYZ = 0, nXZ = 0, nXY = 0;
827 Int_t nX = 0, nY = 0, nZ = 0;
829 for (
unsigned int nhit = 0; nhit < this->GetNumberOfHits(); nhit++) {
830 Double_t x =
fHits->GetX(nhit);
831 Double_t y =
fHits->GetY(nhit);
832 Double_t z =
fHits->GetZ(nhit);
833 Double_t en =
fHits->GetEnergy(nhit);
834 int type =
fHits->GetType(nhit);
836 if (type % XZ == 0) {
841 if (type % YZ == 0) {
846 if (type % XY == 0) {
871 fPad->cd(1 + 3 * column);
873 fXZHisto->GetXaxis()->SetTitle(
"X-axis (mm)");
874 fXZHisto->GetYaxis()->SetTitle(
"Z-axis (mm)");
875 fXZHisto->GetYaxis()->SetTitleSize(1.4 *
fXZHisto->GetYaxis()->GetTitleSize());
876 fXZHisto->GetXaxis()->SetTitleSize(1.4 *
fXZHisto->GetXaxis()->GetTitleSize());
877 fXZHisto->GetYaxis()->SetLabelSize(1.25 *
fXZHisto->GetYaxis()->GetLabelSize());
878 fXZHisto->GetXaxis()->SetLabelSize(1.25 *
fXZHisto->GetXaxis()->GetLabelSize());
879 fXZHisto->GetYaxis()->SetTitleOffset(1.75);
883 fPad->cd(2 + 3 * column);
885 fYZHisto->GetXaxis()->SetTitle(
"Y-axis (mm)");
886 fYZHisto->GetYaxis()->SetTitle(
"Z-axis (mm)");
887 fYZHisto->GetYaxis()->SetTitleSize(1.4 *
fYZHisto->GetYaxis()->GetTitleSize());
888 fYZHisto->GetXaxis()->SetTitleSize(1.4 *
fYZHisto->GetXaxis()->GetTitleSize());
889 fYZHisto->GetYaxis()->SetLabelSize(1.25 *
fYZHisto->GetYaxis()->GetLabelSize());
890 fYZHisto->GetXaxis()->SetLabelSize(1.25 *
fYZHisto->GetXaxis()->GetLabelSize());
891 fYZHisto->GetYaxis()->SetTitleOffset(1.75);
895 fPad->cd(3 + 3 * column);
897 fXYHisto->GetXaxis()->SetTitle(
"X-axis (mm)");
898 fXYHisto->GetYaxis()->SetTitle(
"Y-axis (mm)");
899 fXYHisto->GetYaxis()->SetTitleSize(1.4 *
fXYHisto->GetYaxis()->GetTitleSize());
900 fXYHisto->GetXaxis()->SetTitleSize(1.4 *
fXYHisto->GetXaxis()->GetTitleSize());
901 fXYHisto->GetYaxis()->SetLabelSize(1.25 *
fXYHisto->GetYaxis()->GetLabelSize());
902 fXYHisto->GetXaxis()->SetLabelSize(1.25 *
fXYHisto->GetXaxis()->GetLabelSize());
903 fXYHisto->GetYaxis()->SetTitleOffset(1.75);
909 fPad->cd(1 + 3 * column);
911 fXHisto->GetXaxis()->SetTitle(
"X-axis (mm)");
912 fXHisto->GetYaxis()->SetTitle(
"Number of events");
913 fXHisto->GetYaxis()->SetTitleSize(1.4 *
fXHisto->GetYaxis()->GetTitleSize());
914 fXHisto->GetXaxis()->SetTitleSize(1.4 *
fXHisto->GetXaxis()->GetTitleSize());
915 fXHisto->GetYaxis()->SetLabelSize(1.25 *
fXHisto->GetYaxis()->GetLabelSize());
916 fXHisto->GetXaxis()->SetLabelSize(1.25 *
fXHisto->GetXaxis()->GetLabelSize());
917 fXHisto->GetYaxis()->SetTitleOffset(1.75);
921 fPad->cd(2 + 3 * column);
923 fYHisto->GetXaxis()->SetTitle(
"Y-axis (mm)");
924 fYHisto->GetYaxis()->SetTitle(
"Number of events");
925 fYHisto->GetYaxis()->SetTitleSize(1.4 *
fYHisto->GetYaxis()->GetTitleSize());
926 fYHisto->GetXaxis()->SetTitleSize(1.4 *
fYHisto->GetXaxis()->GetTitleSize());
927 fYHisto->GetYaxis()->SetLabelSize(1.25 *
fYHisto->GetYaxis()->GetLabelSize());
928 fYHisto->GetXaxis()->SetLabelSize(1.25 *
fYHisto->GetXaxis()->GetLabelSize());
929 fYHisto->GetYaxis()->SetTitleOffset(1.75);
933 fPad->cd(3 + 3 * column);
935 fZHisto->GetXaxis()->SetTitle(
"Z-axis (mm)");
936 fZHisto->GetYaxis()->SetTitle(
"Number of events");
937 fZHisto->GetYaxis()->SetTitleSize(1.4 *
fYHisto->GetYaxis()->GetTitleSize());
938 fZHisto->GetXaxis()->SetTitleSize(1.4 *
fYHisto->GetXaxis()->GetTitleSize());
939 fZHisto->GetYaxis()->SetLabelSize(1.25 *
fYHisto->GetYaxis()->GetLabelSize());
940 fZHisto->GetXaxis()->SetLabelSize(1.25 *
fYHisto->GetXaxis()->GetLabelSize());
941 fZHisto->GetYaxis()->SetTitleOffset(1.75);
950 cout <<
"Total energy : " << GetEnergy() << endl;
951 cout <<
"Mean position : ( " << GetMeanPositionX() <<
" , " << GetMeanPositionY() <<
" , "
952 << GetMeanPositionZ() <<
" ) " << endl;
953 cout <<
"Number of hits : " <<
fHits->GetNumberOfHits() << endl;
955 cout <<
"+++++++++++++++++++++++" << endl;
956 cout <<
"Printing only the first " << nHits <<
" hits" << endl;
TRestHits * GetXYZHits()
This method collects all hits which are compatible with a XYZ hit.
virtual void PrintEvent() const
TVector3 GetMeanPositionInCylinder(TVector3 x0, TVector3 x1, Double_t radius)
This method returns the mean position of the hits found inside the cylinder volume given by argument.
TRestHits * GetXZHits()
This method collects all hits which are compatible with a XZ-projected hit.
Double_t GetClosestHitInsideDistanceToCylinderTop(TVector3 x0, TVector3 x1, Double_t radius)
This method returns the distance to the cylinder top face from the closest hit contained inside the c...
void DrawGraphs(Int_t &column)
This method draw the hits events as a graph.
TH1F * fZHisto
An auxiliary TH1F histogram to visualize hits on Z-projection.
TPad * DrawEvent(const TString &option="")
This method draws the hits event structure into a TPad.
Double_t GetX(int n) const
Returns the X-coordinate of hit entry n in mm.
TH2F * fXYHisto
An auxiliary TH2F histogram to visualize hits on XY-projection.
Double_t GetClosestHitInsideDistanceToPrismBottom(const TVector3 &x0, const TVector3 &x1, Double_t sizeX, Double_t sizeY, Double_t theta)
This method returns the distance to the prism bottom face from the closest hit contained inside the p...
Int_t GetNumberOfHitsInsideCylinder(TVector3 x0, TVector3 x1, Double_t radius)
This method returns the total number hits found inside the cylinder volume given by argument.
Bool_t anyHitInsideCylinder(TVector3 x0, TVector3 x1, Double_t radius)
This method returns true if at least 1 hit is found inside the cylinder volume given by argument.
TH2F * fYZHisto
An auxiliary TH2F histogram to visualize hits on YZ-projection.
Bool_t allHitsInsidePrism(TVector3 x0, TVector3 x1, Double_t sX, Double_t sY, Double_t theta)
This method returns true if all hits are found inside the prism volume given by argument.
void DrawHistograms(Int_t &column, const TString &histOption="", double pitch=0)
This method draw the hits events as an histogram.
Double_t GetEnergyInPrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, Double_t theta)
This method returns the total integrated energy of all hits found inside the prism volume given by ar...
Double_t GetClosestHitInsideDistanceToCylinderWall(TVector3 x0, TVector3 x1, Double_t radius)
This method returns the distance to the cylinder wall from the closest hit contained inside the cylin...
TGraph * fYZHitGraph
An auxiliary TGraph pointer to visualize hits on YZ-projection.
Double_t GetY(int n) const
Returns the Y-coordinate of hit entry n in mm.
Double_t GetZ(int n) const
Returns the Z-coordinate of hit entry n in mm.
TRestHits * fHits
The hits structure that is is saved to disk.
TRestHits * fXZHits
An auxiliary TRestHits structure to register hits on XZ projection.
TH2F * fXZHisto
An auxiliary TH2F histogram to visualize hits on XZ-projection.
TRestDetectorHitsEvent()
TRestDetectorHitsEvent default constructor.
Int_t GetNumberOfHitsInsidePrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, Double_t theta)
This method returns the total number of hits found inside the prism volume given by argument.
Double_t GetClosestHitInsideDistanceToCylinderBottom(TVector3 x0, TVector3 x1, Double_t radius)
This method returns the distance to the cylinder bottom face from the closest hit contained inside th...
TH1F * fYHisto
An auxiliary TH1F histogram to visualize hits on Y-projection.
TRestHits * fXYZHits
An auxiliary TRestHits structure to register hits on XYZ projection.
TVector3 GetMeanPositionInPrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, Double_t theta)
This method returns the mean position of all hits found inside the prism volume given by argument.
Bool_t allHitsInsideCylinder(TVector3 x0, TVector3 x1, Double_t radius)
This method returns true if all hits are contained inside the cylinder volume given by argument.
Double_t GetEnergyInCylinder(TVector3 x0, TVector3 x1, Double_t radius)
This method returns the total integrated energy of all hits found inside the cylinder volume given by...
void AddHit(Double_t x, Double_t y, Double_t z, Double_t en, Double_t t=0, REST_HitType type=XYZ)
Adds a new hit to this event.
TRestHits * GetYZHits()
This method collects all hits which are compatible with a YZ-projected hit.
TGraph * fXZHitGraph
An auxiliary TGraph pointer to visualize hits on XZ-projection.
TH1F * fXHisto
An auxiliary TH1F histogram to visualize hits on X-projection.
Double_t GetClosestHitInsideDistanceToPrismTop(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, Double_t theta)
This method returns the distance to the prism top face from the closest hit contained inside the pris...
Bool_t anyHitInsidePrism(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, Double_t theta)
This method returns true if at least 1 hit is found inside the prism volume given by argument.
virtual void Initialize()
Removes all hits from this event, and clears all auxiliar variables.
TGraph * fXYHitGraph
An auxiliary TGraph pointer to visualize hits on XY-projection.
Double_t GetClosestHitInsideDistanceToPrismWall(TVector3 x0, TVector3 x1, Double_t sizeX, Double_t sizeY, Double_t theta)
This method returns the distance to the prism wall from the closest hit contained inside the prism vo...
~TRestDetectorHitsEvent()
TRestDetectorHitsEvent default destructor.
TRestHits * fYZHits
An auxiliary TRestHits structure to register hits on YZ projection.
virtual void PrintEvent() const
virtual void Initialize()=0
It saves a 3-coordinate position and an energy for each punctual deposition.
Int_t GetNumberOfHitsInsidePrism(const TVector3 &x0, const TVector3 &x1, Double_t sizeX, Double_t sizeY, Double_t theta) const
It determines the total number of hits contained inside a prisma delimited between x0 and y0 vertex,...
virtual void RemoveHits()
It removes all hits inside the class.
TVector3 GetMeanPositionInCylinder(const TVector3 &x0, const TVector3 &x1, Double_t radius) const
It determines the mean position using the hits contained inside a cylinder with a given radius and de...
static void GetBoundaries(std::vector< double > &val, double &max, double &min, int &nBins, double offset=10)
TODO This method is not using any TRestHits member. This probably means that it should be placed some...
Double_t GetEnergyInCylinder(const TVector3 &x0, const TVector3 &x1, Double_t radius) const
It determines the total energy contained inside a cylinder with a given radius and delimited between ...
Bool_t isHitNInsidePrism(Int_t n, const TVector3 &x0, const TVector3 &x1, Double_t sizeX, Double_t sizeY, Double_t theta) const
It determines if hit n is contained inside a prisma delimited between x0 and y0 vertex,...
Double_t GetEnergyInPrism(const TVector3 &x0, const TVector3 &x1, Double_t sizeX, Double_t sizeY, Double_t theta) const
It determines the total hit energy contained inside a prisma delimited between x0 and y0 vertex,...
void AddHit(const TVector3 &position, Double_t energy, Double_t time=0, REST_HitType type=XYZ)
Adds a new hit to the list of hits using a TVector3.
Int_t GetNumberOfHitsInsideCylinder(const TVector3 &x0, const TVector3 &x1, Double_t radius) const
It determines the total number of hits contained inside a cylinder with a given radius and delimited ...
Bool_t isHitNInsideCylinder(Int_t n, const TVector3 &x0, const TVector3 &x1, Double_t radius) const
It determines if hit n is contained inside a cylinder with a given radius and delimited between x0 an...
TVector3 GetMeanPositionInPrism(const TVector3 &x0, const TVector3 &x1, Double_t sizeX, Double_t sizeY, Double_t theta) const
It determines the mean position of hits contained inside a prisma delimited between x0 and x1 vertex,...
virtual void SwapHits(Int_t i, Int_t j)
It exchanges hits n and m affecting to the ordering of the hits inside the list of hits.
virtual void PrintHits(Int_t nHits=-1) const
It prints on screen the first nHits from the list.