5 #include "TRestDetectorHitsReadoutAnalysisProcess.h"
14 vector<TVector3> hitPosition;
15 vector<double> hitEnergy;
16 double energyInFiducial = 0;
18 for (
size_t hitIndex = 0; hitIndex < fInputHitsEvent->GetNumberOfHits(); hitIndex++) {
19 const auto position = fInputHitsEvent->GetPosition(hitIndex);
20 const auto energy = fInputHitsEvent->GetEnergy(hitIndex);
21 const auto time = fInputHitsEvent->GetTime(hitIndex);
22 const auto type = fInputHitsEvent->GetType(hitIndex);
23 fOutputHitsEvent->AddHit(position, energy, time, type);
27 cerr <<
"TRestDetectorHitsReadoutAnalysisProcess::ProcessEvent() : "
28 <<
"Negative or zero energy found in hit " << hitIndex << endl;
32 const auto daqId = fReadout->GetDaqId(position,
false);
33 const auto channelType = fReadout->GetTypeForChannelDaqId(daqId);
35 if (channelType != fChannelType) {
39 hitPosition.push_back(position);
40 hitEnergy.push_back(energy);
42 if (fFiducialDiameter > 0) {
43 TVector3 relativePosition = position - fFiducialPosition;
44 relativePosition.SetZ(0);
45 const double distance = relativePosition.Mag();
46 if (distance > fFiducialDiameter / 2) {
49 energyInFiducial += energy;
53 const double readoutEnergy = accumulate(hitEnergy.begin(), hitEnergy.end(), 0.0);
55 if (fRemoveZeroEnergyEvents && readoutEnergy <= 0) {
59 TVector3 positionAverage;
60 for (
size_t i = 0; i < hitPosition.size(); i++) {
61 positionAverage += hitPosition[i] * hitEnergy[i];
63 positionAverage *= 1.0 / readoutEnergy;
66 TVector3 positionSigma;
67 for (
size_t i = 0; i < hitPosition.size(); i++) {
68 TVector3 diff2 = hitPosition[i] - positionAverage;
69 diff2.SetX(diff2.X() * diff2.X());
70 diff2.SetY(diff2.Y() * diff2.Y());
71 diff2.SetZ(diff2.Z() * diff2.Z());
72 positionSigma += diff2 * hitEnergy[i];
74 positionSigma *= 1.0 / readoutEnergy;
75 positionSigma.SetX(sqrt(positionSigma.X()));
76 positionSigma.SetY(sqrt(positionSigma.Y()));
77 positionSigma.SetZ(sqrt(positionSigma.Z()));
79 SetObservableValue(
"readoutEnergy", readoutEnergy);
80 SetObservableValue(
"readoutNumberOfHits", hitEnergy.size());
82 SetObservableValue(
"readoutAveragePositionX", positionAverage.X());
83 SetObservableValue(
"readoutAveragePositionY", positionAverage.Y());
84 SetObservableValue(
"readoutAveragePositionZ", positionAverage.Z());
86 SetObservableValue(
"readoutSigmaPositionX", positionSigma.X());
87 SetObservableValue(
"readoutSigmaPositionY", positionSigma.Y());
88 SetObservableValue(
"readoutSigmaPositionZ", positionSigma.Z());
90 SetObservableValue(
"readoutEnergyInFiducial", energyInFiducial);
92 return fOutputHitsEvent;
96 fReadout =
dynamic_cast<TRestDetectorReadout*
>(fRunInfo->GetMetadataClass(
"TRestDetectorReadout"));
98 cerr <<
"TRestDetectorHitsReadoutAnalysisProcess::InitProcess() : "
99 <<
"TRestDetectorReadout not found" << endl;
103 if (fChannelType ==
"") {
104 cerr <<
"TRestDetectorHitsReadoutAnalysisProcess::InitProcess() : "
105 <<
"Channel type not defined" << endl;
115 RESTMetadata <<
"Channel type : " << fChannelType << RESTendl;
116 RESTMetadata <<
"Fiducial position : (" << fFiducialPosition.X() <<
" , " << fFiducialPosition.Y()
117 <<
" , " << fFiducialPosition.Z() <<
")" << RESTendl;
118 RESTMetadata <<
"Fiducial diameter : " << fFiducialDiameter << RESTendl;
124 fRemoveZeroEnergyEvents = StringToBool(GetParameter(
"removeZeroEnergyEvents",
"false"));
125 fChannelType = GetParameter(
"channelType", fChannelType);
126 fFiducialPosition = Get3DVectorParameterWithUnits(
"fiducialPosition", fFiducialPosition);
127 fFiducialDiameter = GetDblParameterWithUnits(
"fiducialDiameter", fFiducialDiameter);
131 SetSectionName(this->ClassName());
132 SetLibraryVersion(LIBRARY_VERSION);
134 fInputHitsEvent =
nullptr;
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
Process one event.
void PrintMetadata() override
Implemented it in the derived metadata class to print out specific metadata information.
void Initialize() override
Making default settings.
void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
void EndProcess() override
To be executed at the end of the run (outside event loop)
A metadata class to generate/store a readout description.
A base class for any REST event.