Skip to content

Commit d6d6db0

Browse files
Add feminos-daq input run tree information to TRestRun (#155)
* Add input run tree info to TRestRun info * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add flag to use or not this feminos-daq run info * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add brief documentation --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 12d3311 commit d6d6db0

File tree

2 files changed

+89
-4
lines changed

2 files changed

+89
-4
lines changed

inc/TRestRawFeminosRootToSignalProcess.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,29 @@ class TRestRawFeminosRootToSignalProcess : public TRestEventProcess {
4545
ULong64_t fInputEventTreeTimestamp = 0; //!
4646
std::vector<unsigned short>* fInputEventTreeSignalIds = nullptr; //!
4747
std::vector<unsigned short>* fInputEventTreeSignalValues = nullptr; //!
48+
ULong64_t fStartTimestamp = -1; //!
49+
ULong64_t fEndTimestamp = 0; //!
50+
Bool_t fUseFeminosDaqRunInfo = true; //<
4851

4952
public:
5053
RESTValue GetInputEvent() const override { return RESTValue((TRestEvent*)nullptr); }
5154
RESTValue GetOutputEvent() const override { return fSignalEvent; }
5255

5356
void InitProcess() override;
5457
void Initialize() override;
58+
void EndProcess() override;
5559

5660
TRestEvent* ProcessEvent(TRestEvent* inputEvent) override;
5761
const char* GetProcessName() const override { return "FeminosRootToSignal"; }
5862

63+
/// It prints out the process parameters stored in the metadata structure
64+
inline void PrintMetadata() override {
65+
BeginPrintProcess();
66+
std::string useFemDaqRunInfoStr = fUseFeminosDaqRunInfo ? "true" : "false";
67+
RESTMetadata << "Use feminos-daq run information: " << useFemDaqRunInfoStr << RESTendl;
68+
69+
EndPrintProcess();
70+
}
5971
// Constructor
6072
TRestRawFeminosRootToSignalProcess();
6173
TRestRawFeminosRootToSignalProcess(const char* configFilename);
@@ -64,7 +76,7 @@ class TRestRawFeminosRootToSignalProcess : public TRestEventProcess {
6476
~TRestRawFeminosRootToSignalProcess();
6577

6678
ClassDefOverride(TRestRawFeminosRootToSignalProcess,
67-
1); // Template for a REST "event process" class inherited from
79+
2); // Template for a REST "event process" class inherited from
6880
// TRestEventProcess
6981
};
7082
#endif

src/TRestRawFeminosRootToSignalProcess.cxx

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,20 @@
2121
*************************************************************************/
2222

2323
//////////////////////////////////////////////////////////////////////////
24-
/// The TRestRawFeminosRootToSignalProcess ...
24+
/// The TRestRawFeminosRootToSignalProcess converts the events acquired by
25+
/// the Feminos DAQ into TRestRawSignalEvent objects.
2526
///
26-
/// DOCUMENTATION TO BE WRITTEN (main description, methods, data members)
27+
/// ### Parameters
28+
/// - **fUseFeminosDaqRunInfo**: Flag to determine if Feminos DAQ run info is transferred
29+
/// to the TRestRun object. If `true` (default), the run info such as start time,
30+
/// run number, tag, and description are set from the Feminos DAQ run info (stored
31+
/// in the run tree of the .root file). If `false`, this behavior is disabled and the
32+
/// start time is set from the first processed event timestamp. *Note: if you are using
33+
/// inputFormat in TRestRun to extract the run information (run number and tag usually),
34+
/// be aware that this happens before TRestRawFeminosRootToSignalProcess. The process,
35+
/// with fUseFeminosDaqRunInfo set to true, will overwrite the run info so the final
36+
/// values in the TRestRun will come from the .root file generated by feminos-daq,
37+
/// not the filename.*
2738
///
2839
/// \warning This process might be obsolete today. It may need additional
2940
/// revision, validation, and documentation. Use it under your own risk. If you
@@ -56,6 +67,9 @@
5667
/// 2024-Aug: First implementation
5768
/// Luis Obis
5869
///
70+
/// 2025-May: Extract Feminos DAQ run info
71+
/// Álvaro Ezquerro
72+
///
5973
/// \class TRestRawFeminosRootToSignalProcess
6074
/// \author Luis Obis
6175
///
@@ -109,7 +123,47 @@ void TRestRawFeminosRootToSignalProcess::InitProcess() {
109123
exit(1);
110124
}
111125

112-
fRunInfo->SetFeminosDaqTotalEvents(fInputEventTree->GetEntries());
126+
if (fUseFeminosDaqRunInfo) {
127+
ULong64_t startTimeStampMilliseconds = 0;
128+
ULong64_t runNumber = 0;
129+
std::string* runTag = new std::string();
130+
std::string* runDescription = new std::string();
131+
fInputRunTree->SetBranchAddress("timestamp", &startTimeStampMilliseconds);
132+
fInputRunTree->SetBranchAddress("number", &runNumber);
133+
fInputRunTree->SetBranchAddress("tag", &runTag);
134+
fInputRunTree->SetBranchAddress("comments", &runDescription);
135+
136+
/* // Unused because they cannot be set in the run info
137+
std::string* runComment = new std::string();
138+
fInputRunTree->SetBranchAddress("comments", &runComment);
139+
std::string* runDetector = new std::string();
140+
fInputRunTree->SetBranchAddress("detector", &runDetector);
141+
Float_t driftField = 0;
142+
fInputRunTree->SetBranchAddress("drift_field_V_cm_bar", &driftField);
143+
Float_t meshVoltage = 0;
144+
fInputRunTree->SetBranchAddress("mesh_voltage_V", &meshVoltage);
145+
Float_t detectorPressure = 0;
146+
fInputRunTree->SetBranchAddress("detector_pressure_bar", &detectorPressure);
147+
*/
148+
149+
// retrieve row 0
150+
fInputRunTree->GetEntry(0);
151+
152+
// set run info
153+
Double_t startTimeStamp = startTimeStampMilliseconds / 1000.0; // convert ms to seconds
154+
fRunInfo->SetStartTimeStamp(startTimeStamp);
155+
fRunInfo->SetRunNumber(runNumber);
156+
// mclient sets the run tag and description to "\n" if they are empty
157+
if (*runTag == "\n") {
158+
runTag->clear();
159+
}
160+
if (*runDescription == "\n") {
161+
runDescription->clear();
162+
}
163+
fRunInfo->SetRunTag(*runTag);
164+
fRunInfo->SetRunDescription(*runDescription);
165+
fRunInfo->SetFeminosDaqTotalEvents(fInputEventTree->GetEntries());
166+
}
113167

114168
fInputEventTree->SetBranchAddress("timestamp", &fInputEventTreeTimestamp);
115169
fInputEventTree->SetBranchAddress("signal_ids", &fInputEventTreeSignalIds);
@@ -126,6 +180,16 @@ TRestEvent* TRestRawFeminosRootToSignalProcess::ProcessEvent(TRestEvent* inputEv
126180
// fInputEventTreeTimestamp is in milliseconds and TRestEvent::SetTime(seconds, nanoseconds)
127181
fSignalEvent->SetTime(fInputEventTreeTimestamp / 1000, fInputEventTreeTimestamp % 1000 * 1000000);
128182

183+
// get the first event timestamp (if we are not using FeminosDaq run info where this is set from the run
184+
// tree)
185+
if (!fUseFeminosDaqRunInfo && fInputEventTreeTimestamp < fStartTimestamp) {
186+
fStartTimestamp = fInputEventTreeTimestamp;
187+
}
188+
// get the last event timestamp
189+
if (fInputEventTreeTimestamp > fEndTimestamp) {
190+
fEndTimestamp = fInputEventTreeTimestamp;
191+
}
192+
129193
for (size_t i = 0; i < fInputEventTreeSignalIds->size(); i++) {
130194
auto signal = TRestRawSignal();
131195
signal.Initialize();
@@ -148,3 +212,12 @@ TRestEvent* TRestRawFeminosRootToSignalProcess::ProcessEvent(TRestEvent* inputEv
148212

149213
return fSignalEvent;
150214
}
215+
216+
void TRestRawFeminosRootToSignalProcess::EndProcess() {
217+
// use first event timestamp as start of run if we are not using FeminosDaq run info
218+
if (!fUseFeminosDaqRunInfo) {
219+
fRunInfo->SetStartTimeStamp(fStartTimestamp / 1000.0); // convert from ms to s
220+
}
221+
// use last event timestamp as end of run
222+
fRunInfo->SetEndTimeStamp(fEndTimestamp / 1000.0); // convert from ms to s
223+
}

0 commit comments

Comments
 (0)