Skip to content

Commit

Permalink
Merge pull request #118 from rest-for-physics/lobis-working-on-veto-r…
Browse files Browse the repository at this point in the history
…eadout

Add class to hold readout metadata info
  • Loading branch information
lobis authored Sep 28, 2023
2 parents 23ff62b + 67de558 commit 320dffd
Show file tree
Hide file tree
Showing 15 changed files with 589 additions and 144 deletions.
51 changes: 51 additions & 0 deletions inc/TRestRawPeaksFinderProcess.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// Created by lobis on 24-Aug-23.
//

#ifndef REST_TRESTRAWPEAKSFINDERPROCESS_H
#define REST_TRESTRAWPEAKSFINDERPROCESS_H

#include <TRestEventProcess.h>

#include "TRestRawReadoutMetadata.h"
#include "TRestRawSignalEvent.h"

class TRestRawPeaksFinderProcess : public TRestEventProcess {
private:
TRestRawSignalEvent* fSignalEvent = nullptr; //!
TRestRawReadoutMetadata* fReadoutMetadata = nullptr; //!

/// \brief threshold over baseline to consider a peak
Double_t fThresholdOverBaseline = 2.0;
/// \brief range of samples to calculate baseline for peak finding
TVector2 fBaselineRange = {0, 10};
/// \brief distance between two peaks to consider them as different
UShort_t fDistance = 10;
/// \brief window size to calculate the peak amplitude
UShort_t fWindow = 10;

std::set<std::string> fChannelTypes = {}; // this process will only be applied to selected channel types

public:
RESTValue GetInputEvent() const override { return fSignalEvent; }
RESTValue GetOutputEvent() const override { return fSignalEvent; }

void PrintMetadata() override;

void InitProcess() override;
TRestEvent* ProcessEvent(TRestEvent* inputEvent) override;
void EndProcess() override {}

const char* GetProcessName() const override { return "peaksFinder"; }

explicit TRestRawPeaksFinderProcess(const char* configFilename){};

void InitFromConfigFile() override;

TRestRawPeaksFinderProcess() = default;
~TRestRawPeaksFinderProcess() = default;

ClassDefOverride(TRestRawPeaksFinderProcess, 3);
};

#endif // REST_TRESTRAWPEAKSFINDERPROCESS_H
41 changes: 41 additions & 0 deletions inc/TRestRawReadoutMetadata.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Created by lobis on 24-Aug-23.
//

#ifndef REST_TRESTRAWREADOUTMETADATA_H
#define REST_TRESTRAWREADOUTMETADATA_H

#include <TRestMetadata.h>

class TRestDetectorReadout;

class TRestRawReadoutMetadata : public TRestMetadata {
public:
struct ChannelInfo {
std::string type;
std::string name;
UShort_t channelId;
// other members
};
// maps daq id to channel info
std::map<UShort_t, ChannelInfo> fChannelInfo;

void InitializeFromReadout(TRestDetectorReadout* readout);

public:
std::string GetTypeForChannelDaqId(UShort_t channel) const;
std::string GetNameForChannelDaqId(UShort_t channel) const;

Int_t GetChannelIdForChannelDaqId(UShort_t channel) const;

std::vector<UShort_t> GetChannelDaqIDsForType(const std::string& type) const;

void PrintMetadata() const;

TRestRawReadoutMetadata() = default;
~TRestRawReadoutMetadata() = default;

ClassDef(TRestRawReadoutMetadata, 1)
};

#endif // REST_TRESTRAWREADOUTMETADATA_H
5 changes: 5 additions & 0 deletions inc/TRestRawSignal.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ class TRestRawSignal {

TGraph* GetGraph(Int_t color = 1);

/// Returns the (time, amplitude) of the peaks in the signal.
/// Peaks are defined as the points that are above the threshold and are separated by a minimum distance
/// in time bin units. The threshold must be set in absolute value (regardless of the baseline)
std::vector<std::pair<UShort_t, double>> GetPeaks(double threshold, UShort_t distance = 5) const;

TRestRawSignal();
TRestRawSignal(Int_t nBins);
~TRestRawSignal();
Expand Down
21 changes: 17 additions & 4 deletions inc/TRestRawSignalAnalysisProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,43 @@ class TRestRawSignalAnalysisProcess : public TRestEventProcess {
TVector2 fIntegralRange = TVector2(10, 500);

/// Option for calculation of baseline parameters, can be set to "ROBUST"
std::string fBaseLineOption = ""; //<
std::string fBaseLineOption; //<

/// The number of sigmas over baseline fluctuations to identify a point overthreshold
/// The number of sigmas over baseline fluctuations to identify a point over threshold
Double_t fPointThreshold = 2;

/// A parameter to define a minimum signal fluctuation. Measured in sigmas.
Double_t fSignalThreshold = 5;

/// avoid error when loading parameters (not used)
std::string fChannelType; //!

/// The minimum number of points over threshold to identify a signal as such
Int_t fPointsOverThreshold = 5;

/// It defines the signals id range where analysis is applied
TVector2 fSignalsRange = TVector2(-1, -1); //<

TRestRawReadoutMetadata* fReadoutMetadata = nullptr;

void Initialize() override;

std::set<std::string> fChannelTypes = {}; // this process will only be applied to selected channel types

protected:
// add here the members of your event process

public:
RESTValue GetInputEvent() const override { return fSignalEvent; }

RESTValue GetOutputEvent() const override { return fSignalEvent; }

void InitProcess() override;

TRestEvent* ProcessEvent(TRestEvent* inputEvent) override;

void InitFromConfigFile() override;

void PrintMetadata() override {
BeginPrintProcess();

Expand All @@ -87,9 +98,11 @@ class TRestRawSignalAnalysisProcess : public TRestEventProcess {

const char* GetProcessName() const override { return "rawSignalAnalysis"; }

TRestRawSignalAnalysisProcess(); // Constructor
~TRestRawSignalAnalysisProcess(); // Destructor
TRestRawSignalAnalysisProcess();

~TRestRawSignalAnalysisProcess();

ClassDefOverride(TRestRawSignalAnalysisProcess, 5);
};

#endif
15 changes: 10 additions & 5 deletions inc/TRestRawSignalEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
#ifndef RestDAQ_TRestRawSignalEvent
#define RestDAQ_TRestRawSignalEvent

#include <TArrayD.h>
#include <TAxis.h>
#include <TGraph.h>
#include <TObject.h>
#include <TPad.h>
#include <TRestEvent.h>
#include <TRestRawReadoutMetadata.h>
#include <TRestRun.h>
#include <TVector2.h>

#include <iostream>
Expand Down Expand Up @@ -111,8 +111,7 @@ class TRestRawSignalEvent : public TRestEvent {
}

Bool_t isBaseLineInitialized() {
// If one signal is initialized we assume initialization happened for any
// signal
// If one signal is initialized we assume initialization happened for any signal
for (int n = 0; n < GetNumberOfSignals(); n++)
if (fSignal[n].isBaseLineInitialized()) return true;
return false;
Expand All @@ -125,6 +124,10 @@ class TRestRawSignalEvent : public TRestEvent {
return &fSignal[index];
}

TRestRawSignalEvent GetSignalEventForType(const std::string& type) const;
TRestRawSignalEvent GetSignalEventForTypes(
const std::set<std::string>& types, const TRestRawReadoutMetadata* readoutMetadata = nullptr) const;

TRestRawSignal* GetMaxSignal();

Int_t GetLowestWidth(Double_t minPeakAmplitude = 0);
Expand Down Expand Up @@ -155,7 +158,9 @@ class TRestRawSignalEvent : public TRestEvent {

TPad* DrawEvent(const TString& option = "");
void DrawSignals(TPad* pad, const std::vector<Int_t>& signals);
TPad* DrawSignal(Int_t signalID, TString option = "");
TPad* DrawSignal(Int_t signalID, const TString& option = "");

TRestRawReadoutMetadata* GetReadoutMetadata() const;

// Constructor
TRestRawSignalEvent();
Expand Down
7 changes: 5 additions & 2 deletions inc/TRestRawSignalRangeReductionProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class TRestRawSignalRangeReductionProcess : public TRestEventProcess {
TVector2 fDigitizationInputRange =
TVector2(std::numeric_limits<Short_t>::min(), std::numeric_limits<Short_t>::max());

TVector2 fDigitizationOutputRange; //!
TVector2 fDigitizationOutputRange;

public:
void Initialize() override;
Expand All @@ -61,6 +61,9 @@ class TRestRawSignalRangeReductionProcess : public TRestEventProcess {

void LoadConfig(const std::string& configFilename, const std::string& name = "");

Double_t ConvertFromStartingRangeToTargetRange(Double_t value) const;
Double_t ConvertFromTargetRangeToStartingRange(Double_t value) const;

inline void PrintMetadata() override {
BeginPrintProcess();

Expand All @@ -81,6 +84,6 @@ class TRestRawSignalRangeReductionProcess : public TRestEventProcess {
// Destructor
~TRestRawSignalRangeReductionProcess();

ClassDefOverride(TRestRawSignalRangeReductionProcess, 1);
ClassDefOverride(TRestRawSignalRangeReductionProcess, 2);
};
#endif // RestCore_TRestRawSignalRangeReductionProcess
19 changes: 10 additions & 9 deletions pipeline/processes/analysis/globals.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<globals>
<parameter name="mainDataPath" value="." />
<parameter name="verboseLevel" value="silent" /> %options are : silent, warning, info, silent
<parameter name="mainDataPath" value="."/>
<parameter name="verboseLevel" value="silent"/>
%options are : silent, warning, info, silent

<variable name="BL_MIN" value="20" overwrite="false" />
<variable name="BL_MAX" value="150" overwrite="false" />
<variable name="BL_MIN" value="20" overwrite="false"/>
<variable name="BL_MAX" value="150" overwrite="false"/>

<variable name="INT_MIN" value="150" overwrite="false" />
<variable name="INT_MAX" value="450" overwrite="false" />
<variable name="INT_MIN" value="150" overwrite="false"/>
<variable name="INT_MAX" value="450" overwrite="false"/>

<variable name="NPOINTS" value="7" overwrite="false" />
<variable name="POINT_TH" value="3.5" overwrite="false" />
<variable name="SGNL_TH" value="3.5" overwrite="false" />
<variable name="NPOINTS" value="7" overwrite="false"/>
<variable name="POINT_TH" value="3.5" overwrite="false"/>
<variable name="SGNL_TH" value="3.5" overwrite="false"/>
</globals>
2 changes: 1 addition & 1 deletion pipeline/processes/analysis/validate.C
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Int_t validate() {
average /= elems;

if (elems != 14) {
cout << "Number of veto signals identified is not 14!" << endl;
cout << "Number of veto signals identified is not 14! Computed value: " << elems << endl;
return 2;
}

Expand Down
Loading

0 comments on commit 320dffd

Please sign in to comment.