ARTEMIS-CRIB
 
Loading...
Searching...
No Matches
TMUXDataMappingProcessor.cc
Go to the documentation of this file.
1/**
2 * @file TMUXDataMappingProcessor.cc
3 * @brief Implementation of TMUXDataMappingProcessor for mapping categorized data.
4 * @author Kodai Okawa <okawa@cns.s.u-tokyo.ac.jp>
5 * @date 2022-01-30 09:47:17
6 * @note last modified: 2025-03-05 18:32:52
7 * @details
8 */
9
11#include "../TProcessorUtil.h"
12
13#include "TMUXData.h"
14#include <TCategorizedData.h>
15#include <TRawDataObject.h>
16#include <constant.h>
17
18/// ROOT macro for class implementation
20
21namespace art::crib {
22
23/**
24 * @details
25 * The constructor initializes the processor by setting up input/output
26 * collection names and default parameter values. These values can be
27 * overridden via the steering file or configuration options.
28 */
30 : fCategorizedData(nullptr), fOutData(nullptr) {
31 RegisterInputCollection("CategorizedDataName", "name of the segmented data",
32 fCategorizedDataName, TString("catdata"));
33 RegisterOutputCollection("OutputCollection", "name of the output branch",
34 fOutputColName, TString("mux"));
35
36 RegisterProcessorParameter("CatID", "Category ID", fCatID, -1);
37}
38
39/**
40 * @details
41 * The destructor ensures that dynamically allocated memory for `fOutData`
42 * is properly released to prevent memory leaks.
43 */
48
49/**
50 * @details
51 * During initialization, the processor retrieves the input categorized data
52 * collection from the provided event collection and validates its type.
53 * It also initializes the output data array (`fOutData`) as a TClonesArray
54 * of TMUXData objects.
55 *
56 * If the required input collection or parameters are invalid, an error
57 * state is set, and processing will not proceed.
58 */
59void TMUXDataMappingProcessor::Init(TEventCollection *col) {
60 // Categorized data initialization
62 col, fCategorizedDataName, "art::TCategorizedData");
63
64 if (std::holds_alternative<TString>(result)) {
65 SetStateError(std::get<TString>(result));
66 return;
67 }
68 fCategorizedData = std::get<TCategorizedData **>(result);
69
70 // CatID validation
71 if (fCatID < 0) {
72 SetStateError("CatID must be set in the steering file");
73 return;
74 }
75
76 delete fOutData; // Release memory allocated for fOutData if it exists
77 fOutData = new TClonesArray("art::crib::TMUXData");
78 fOutData->SetName(fOutputColName);
79 col->Add(fOutputColName, fOutData, fOutputIsTransparent);
80 Info("Init", "%s -> %s, CatID = %d",
82}
83
84/**
85 * @details
86 * Processes the categorized data and maps it to TMUXData objects. For each
87 * detector, the method extracts relevant data and creates a TMUXData object
88 * in the output array.
89 *
90 * If the input collection is not initialized or the specified category is
91 * not found, appropriate warnings are logged, and the method exits early.
92 */
94 fOutData->Clear("C");
95 if (!fCategorizedData) {
96 Warning("Process", "No CategorizedData object");
97 return;
98 }
99
100 const auto *cat_array = (*fCategorizedData)->FindCategory(fCatID);
101 if (!cat_array)
102 return;
103
104 const int nDet = cat_array->GetEntriesFast();
105 int counter = 0;
106 for (int iDet = 0; iDet < nDet; ++iDet) {
107 const auto *det_array = static_cast<const TObjArray *>(cat_array->At(iDet));
108 if (!det_array)
109 continue;
110
111 auto *outData = static_cast<TMUXData *>(fOutData->ConstructedAt(counter));
112 counter++;
113 int detID = ProcessDetectorData(det_array, outData);
114 outData->SetID(detID);
115 }
116}
117
118/**
119 * @details
120 * Processes data for a single detector and maps it to a TMUXData object.
121 * This method extracts energy, position, and timing data from the raw
122 * detector arrays and assigns them to the corresponding fields in `mux`.
123 *
124 * Special handling is applied to timing data to aggregate multiple values.
125 */
126int TMUXDataMappingProcessor::ProcessDetectorData(const TObjArray *det_array, TMUXData *mux) {
127 double raw_data[TMUXData::kNRAW] = {kInvalidD, kInvalidD, kInvalidD, kInvalidD, kInvalidD};
128 int detID = kInvalidI;
129 for (int iType = 0; iType < TMUXData::kNRAW; ++iType) {
130 const auto *data_array = static_cast<const TObjArray *>(det_array->At(iType));
131 if (!data_array)
132 continue;
133
134 if (iType < TMUXData::kNRAW - 1) {
135 // index = 0--3 assuming ADC data
136 if (data_array->GetEntriesFast() != 1) {
137 Warning("ProcessDetectorData", "MUX data [%d] size is not 1", iType);
138 continue;
139 }
140 const auto *data = dynamic_cast<const TRawDataObject *>(data_array->At(0));
141 if (data) {
142 raw_data[iType] = data->GetValue();
143 detID = data->GetDetID();
144 }
145 } else { // Timing treatment for MHTDC
146 const int nData = data_array->GetEntriesFast();
147 for (int iData = 0; iData < nData; ++iData) {
148 const auto *data = dynamic_cast<const TRawDataObject *>(data_array->At(iData));
149 if (data) {
150 if (!IsValid(raw_data[iType]))
151 raw_data[iType] = data->GetValue();
152 mux->PushTiming(data->GetValue());
153 detID = data->GetDetID();
154 }
155 }
156 }
157 }
158 mux->SetE1(raw_data[0]);
159 mux->SetE2(raw_data[1]);
160 mux->SetP1(raw_data[2]);
161 mux->SetP2(raw_data[3]);
162 mux->SetTrig(raw_data[4]);
163
164 return detID;
165}
166
167} // namespace art::crib
ClassImp(art::crib::TMUXDataMappingProcessor)
ROOT macro for class implementation.
Declaration of TMUXDataMappingProcessor class for mapping categorized data to TMUXData objects.
Header file for the TMUXData class.
Utility functions for handling input and parameter objects in TEventCollection.
A processor for mapping categorized data to TMUXData objects.
Int_t fCatID
Category ID used for filtering input data.
void Init(TEventCollection *col) override
Initializes the processor with the provided event collection.
TCategorizedData ** fCategorizedData
! Pointer to the categorized data collection.
TString fOutputColName
Name of the output TMUXData collection.
TClonesArray * fOutData
! Pointer to the output TMUXData array.
int ProcessDetectorData(const TObjArray *det_array, TMUXData *mux)
Processes data for a single detector.
void Process() override
Processes the categorized data and maps it to TMUXData.
TString fCategorizedDataName
Name of the input categorized data collection.
Represents data from the MUX module (E1, E2, P1, P2, T).
Definition TMUXData.h:25
static const Int_t kNRAW
Number of raw data elements (E1, E2, P1, P2, Trigger).
Definition TMUXData.h:102
void SetE2(Double_t value)
Set the second energy value.
Definition TMUXData.h:58
void PushTiming(Double_t value)
Add a new timing value.
Definition TMUXData.cc:77
void SetP1(Double_t value)
Set the first position value.
Definition TMUXData.h:64
void SetE1(Double_t value)
Set the first energy value.
Definition TMUXData.h:55
void SetTrig(Double_t value)
Set the timing value.
Definition TMUXData.h:73
void SetP2(Double_t value)
Set the second position value.
Definition TMUXData.h:67
std::enable_if_t< std::is_base_of_v< TObject, T >, std::variant< T **, TString > > GetInputObject(TEventCollection *col, const TString &name, const TString &expectedTypeName, const TString &elementTypeName="TObject")
Retrieve an object from TEventCollection with type validation.
return to the guide