Skip to content

Commit

Permalink
Merge pull request #106 from rest-for-physics/jgalan_bipo
Browse files Browse the repository at this point in the history
Implementing BiPo event data processing in REST
  • Loading branch information
jgalan committed Jul 7, 2023
2 parents fe3b462 + f312b2e commit 5da09a6
Show file tree
Hide file tree
Showing 14 changed files with 1,105 additions and 1 deletion.
24 changes: 24 additions & 0 deletions .github/workflows/validation.yml
Expand Up @@ -144,3 +144,27 @@ jobs:
cd ${{ env.RAW_LIB_PATH }}/pipeline/external/dream
restManager --c dream.rml --f dummyDreamData.fdf
restRoot -b -q dream.C
BiPoData:
name: Process BiPo data
runs-on: ubuntu-latest
container:
image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics
needs: [ build-rawlib ]
steps:
- uses: rest-for-physics/framework/.github/actions/checkout@master
with:
branch: ${{ env.BRANCH_NAME }}
repository: rest-for-physics/rawlib
path: ${{ env.RAW_LIB_PATH }}
- name: Restore cache
uses: actions/cache@v3
id: rawlib-install-cache
with:
key: ${{ env.BRANCH_NAME }}-${{ github.sha }}
path: ${{ env.REST_PATH }}
- name: BiPo data
run: |
source ${{ env.REST_PATH }}/thisREST.sh
cd ${{ env.RAW_LIB_PATH }}/pipeline/external/BiPo
restManager --c BiPoToRawSignal.rml --f BiPo3Mod2_run_2600.data
restRoot -b -q Validate.C
73 changes: 73 additions & 0 deletions examples/01.BiPo/BiPoToRawSignal.rml
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>

<TRestManager>

<include file="globals.xml" />

<globals>
<variable name="RUN_TYPE" value="RawData" overwrite="false" />
<variable name="FORMAT" value="[fRunTag]_run_[fRunNumber].data" overwrite="false" />
</globals>

<TRestRun file="run.xml"/>

<TRestProcessRunner name="RawSignals" title="Raw processing and analysis" verboseLevel="silent">

<parameter name="eventsToProcess" value="0" />

<addProcess type="TRestRawBiPoToSignalProcess" name="BiPo" value="ON" verboseLevel="silent">
<parameter name="electronicsType" value="MATACQ" />
<parameter name="minPoints" value="0" />
</addProcess>

<addProcess type="TRestEventRateAnalysisProcess" name="rate" observable="all" value="ON" verboseLevel="info" >
<observable name="SecondsFromStart" type="double" value="ON" />
<observable name="HoursFromStart" type="double" value="ON" />
<observable name="EventTimeDelay" type="double" value="ON" />
<observable name="MeanRate_InHz" type="double" value="ON" />
</addProcess>

<addProcess type="TRestRawSignalAnalysisProcess" name="front" value="ON"
baseLineRange="(800,1000)" integralRange="(0,1000)"
pointThreshold="${POINT_TH}" pointsOverThreshold="${NPOINTS}" signalThreshold="${SGNL_TH}"
verboseLevel="silent" >
<observable name="max_amplitude_map" type="map<int,double>" value="ON" />
<observable name="thr_integral_map" type="map<int,double>" value="ON" />
<observable name="BaseLineMean" type="double" value="ON" />
<observable name="BaseLineSigmaMean" type="double" value="ON" />
<observable name="NumberOfSignals" type="int" value="ON" />
<observable name="NumberOfGoodSignals" type="int" value="ON" />
<observable name="ThresholdIntegral" type="double" value="ON" />
<observable name="TripleMaxIntegral" type="double" value="ON" />
<observable name="AmplitudeRatio" type="double" value="ON" />
<observable name="MaxPeakTime" type="double" value="ON" />
<observable name="AveragePeakTime" type="double" value="ON" />

<cut name="NumberOfGoodSignals" value="(1,1000)" />
<parameter name="cutsEnabled" value="true" />
</addProcess>

<addProcess type="TRestRawSignalAnalysisProcess" name="back" value="ON"
baseLineRange="(2200,2400)" integralRange="(1000,2200)"
pointThreshold="${POINT_TH}" pointsOverThreshold="${NPOINTS}" signalThreshold="${SGNL_TH}"
verboseLevel="silent" >
<observable name="max_amplitude_map" type="map<int,double>" value="ON" />
<observable name="thr_integral_map" type="map<int,double>" value="ON" />
<observable name="BaseLineMean" type="double" value="ON" />
<observable name="BaseLineSigmaMean" type="double" value="ON" />
<observable name="NumberOfSignals" type="int" value="ON" />
<observable name="NumberOfGoodSignals" type="int" value="ON" />
<observable name="ThresholdIntegral" type="double" value="ON" />
<observable name="TripleMaxIntegral" type="double" value="ON" />
<observable name="AmplitudeRatio" type="double" value="ON" />
<observable name="MaxPeakTime" type="double" value="ON" />
<observable name="AveragePeakTime" type="double" value="ON" />

<cut name="NumberOfGoodSignals" value="(1,1000)" />
<parameter name="cutsEnabled" value="true" />
</addProcess>
</TRestProcessRunner>

<addTask type="processEvents" value="ON" />

</TRestManager>
17 changes: 17 additions & 0 deletions examples/01.BiPo/panel.xml
@@ -0,0 +1,17 @@

<panel font_size="0.06">
<label value="Run number : [TRestRun::fRunNumber]" x="0.25" y="0.9" />
<label value="Run tag : [TRestRun::fRunTag]" x="0.25" y="0.82" />
<label value="Run starts : [[startTime]]" x="0.25" y="0.74" />
<label value="Run ends : [[endTime]]" x="0.25" y="0.66" />
<label value="Entries : [[entries]]" x="0.25" y="0.58" />
<label value="Run duration : [[runLength]] hours" x="0.25" y="0.50" />
<label value="Mean rate : [[meanRate]] Hz" x="0.25" y="0.42" />

<!--
<label value="Detector pressure : [TRestDetector::fPressure] bar" x="0.25" y="0.30" />
<label value="Mesh voltage : [TRestDetector::fAmplificationVoltage] V" x="0.25" y="0.22" />
<label value="Drift voltage : [TRestDetector::fDriftField] V/cm/bar" x="0.25" y="0.14" />
<label value="Electronics gain : [TRestDetector::fElectronicsGain]" x="0.25" y="0.06" />
-->
</panel>
75 changes: 75 additions & 0 deletions examples/01.BiPo/plots.rml
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<TRestManager name="SpecPlot" title="Example" verboseLevel="info">
<TRestAnalysisPlot name="restplot" title="Basic Plots" previewPlot="false" verboseLevel="silent">
<canvas size="(1800,1200)" divide="(3,3)" save="R[fRunNumber]_[fRunTag]_Raw.png"/>
<include file="panel.xml"/>
<plot name="MeanRateEvolution" title="Mean Rate evolution" xlabel="Threshold Integral [#]" ylabel="Counts" legend="ON" logscale="false" value="ON" xOffset="6" timeDisplay="ON">
<histo name="RateEvolution">
<variable name="timeStamp" nbins="1000" range=""/>
<variable name="rate_MeanRate_InHz" nbins="100" range="(0,300)"/>
<parameter name="lineColor" value="1"/>
</histo>
</plot>
<plot name="NoiseEvolution" title="Noise evolution" xlabel="Threshold Integral [#]" ylabel="Counts" legend="ON" logscale="false" value="ON" xOffset="6" timeDisplay="ON">
<histo name="Front_BaseLineSigma">
<variable name="timeStamp" nbins="1000" range=""/>
<variable name="front_BaseLineSigmaMean" range="(0,20)" nbins="100"/>
<parameter name="lineColor" value="1"/>
</histo>
<histo name="Back_BaseLineSigma">
<variable name="timeStamp" nbins="1000"/>
<variable name="back_BaseLineSigmaMean" nbins="100"/>
<parameter name="lineColor" value="1"/>
</histo>
</plot>
<plot name="ThresholdIntegral" title="ThresholdIntegrals" xlabel="Threshold Integral [#]" ylabel="Counts" legend="ON" logscale="false" value="ON" xOffset="6">
<histo name="Front_Integral">
<variable name="front_ThresholdIntegral" range="(0,30000)" nbins="1000"/>
<parameter name="lineColor" value="1"/>
</histo>
<histo name="Back_Integral">
<variable name="back_ThresholdIntegral" range="(0,30000)" nbins="1000"/>
<parameter name="lineColor" value="2"/>
</histo>
</plot>
<plot name="TripleMaxIntegral" title="TripleMaxIntegrals" xlabel="TripleMax Integral [#]" ylabel="Counts" legend="ON" logscale="false" value="ON" xOffset="6">
<histo name="Front_TripleIntegral">
<variable name="front_TripleMaxIntegral" range="(0,5000)" nbins="1000"/>
<parameter name="lineColor" value="1"/>
</histo>
<histo name="Back_TripleIntegral">
<variable name="back_TripleMaxIntegral" range="(0,5000)" nbins="1000"/>
<parameter name="lineColor" value="2"/>
</histo>
</plot>
<plot name="MaxPeakTime" title="MaxPeakTimes" xlabel="TripleMax Integral [#]" ylabel="Counts" legend="ON" logscale="false" value="ON" xOffset="6">
<histo name="Front_MaxPeakTime">
<variable name="front_MaxPeakTime" range="(0,2000)" nbins="200"/>
<parameter name="lineColor" value="1"/>
</histo>
<histo name="Back_MaxPeakTime">
<variable name="back_MaxPeakTime" range="(0,2000)" nbins="200"/>
<parameter name="lineColor" value="2"/>
</histo>
</plot>
<plot name="GoodSignals" title="GoodSignals" xlabel="Good signals [#]" ylabel="Counts" legend="ON" logscale="false" value="ON" xOffset="6">
<histo name="Front_NumberOfGoodSignals">
<variable name="front_NumberOfGoodSignals" range="(0,5)" nbins="5"/>
<parameter name="lineColor" value="1"/>
</histo>
<histo name="Back_NumberOfGoodSignals">
<variable name="back_NumberOfGoodSignals" range="(0,5)" nbins="5"/>
<parameter name="lineColor" value="2"/>
</histo>
</plot>
<plot name="FrontVersusBackIntegral" title="FrontVersusBackIntegral" xlabel="Front Integral [#]" ylabel="Back Integral" legend="ON" logscale="false" value="ON" xOffset="6">
<variable name="front_ThresholdIntegral" range="(0,30000)" nbins="100"/>
<variable name="back_ThresholdIntegral" range="(0,5000)" nbins="100"/>
</plot>
<plot name="FrontVersusBackMaxPeakTime" title="FrontVersusBackMaxPeakTime" xlabel="Front MaxPeakTime [#]" ylabel="Back MaxPeakTime" legend="ON" logscale="false" value="ON" xOffset="6">
<variable name="front_MaxPeakTime" range="(0,200)" nbins="100"/>
<variable name="back_MaxPeakTime" range="(1000,1800)" nbins="100"/>
</plot>
</TRestAnalysisPlot>
<addTask command="restplot-&gt;PlotCombinedCanvas()" value="ON"/>
</TRestManager>
Binary file added images/BiPo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
127 changes: 127 additions & 0 deletions inc/TRestRawBiPoToSignalProcess.h
@@ -0,0 +1,127 @@
/*************************************************************************
* This file is part of the REST software framework. *
* *
* Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
* For more information see http://gifna.unizar.es/trex *
* *
* REST is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* REST is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have a copy of the GNU General Public License along with *
* REST in $REST_PATH/LICENSE. *
* If not, see http://www.gnu.org/licenses/. *
* For the list of contributors see $REST_PATH/CREDITS. *
*************************************************************************/

#ifndef RestCore_TRestBiPoToSignalProcess
#define RestCore_TRestBiPoToSignalProcess

#include "TRestRawSignalEvent.h"
#include "TRestRawToSignalProcess.h"

constexpr size_t CTAG_SZ = 4;

constexpr int MATACQ_N_CH = 4; // Number of channels
constexpr int MATACQ_MAX_DATA_SAMP = 10240; // Max number of samples for
constexpr int MATACQ_BIPO_TIMEOUT = 0; // BiPo mode timeout

constexpr uint32_t MATACQ_UNDERFLOW = 0x0000;
constexpr uint32_t MATACQ_ZERO = 0x8000;
constexpr uint32_t MATACQ_OVERFLOW = 0xFFFF;

constexpr char TAG_RUN_START[] = "STA";
constexpr char TAG_RUN_BIPO[] = "ST2";
constexpr char TAG_RUN_STOP[] = "STO";
constexpr char TAG_ACQ[] = "ACQ";
constexpr char TAG_ACQ_2[] = "AC2";

//! An process to read binary data from BiPo electronics
class TRestRawBiPoToSignalProcess : public TRestRawToSignalProcess {
public:
/// A structure to store the configuration settings of Matacq board
struct MatacqBoard {
/// The base memory address of the Matacq board
int32_t address;

std::array<int32_t, MATACQ_N_CH> en_ch;
std::array<int32_t, MATACQ_N_CH> trg_ch;

int32_t Trig_Type;
int32_t Threshold;
int32_t Nb_Acq;
int32_t Posttrig;
int32_t Time_Tag_On;
int32_t Sampling_GHz;

std::array<int32_t, MATACQ_N_CH> ch_shifts;
int32_t nChannels;
};

/// A structure to store the BiPo settings
struct BiPoSettings {
int32_t trigger_address;

int32_t Win1_Posttrig;
int32_t Timeout_200KHz;

std::array<int32_t, MATACQ_N_CH> Trig_Chan;
std::array<int32_t, MATACQ_N_CH> Level1_mV;
std::array<int32_t, MATACQ_N_CH> Level2_mV;

int32_t t1_window;
int32_t t2_window;
int32_t t1_t2_timeout;
};

protected:
/// The number of Matacq boards present on the setup
Int_t fNBoards = 0; ///<

/// A vector of Matacq boards that contain the information of each card
std::vector<MatacqBoard> fMatacqBoard; //<

/// A vector of BiPo settings
std::vector<BiPoSettings> fBiPoSettings; //<

/// A temporary counter used to define the event id
Int_t fEventCounter = 0; //!

void ReadHeader();
void ReadFooter();
void ReadBoard();
void ReadBiPoSetup();
Int_t ReadBiPoEventData(std::vector<uint16_t>& mdata);

UInt_t GetBoardIndex(Int_t address);
Int_t GetBin(Int_t boardIndex, Int_t channel, Int_t bin);

public:
void InitProcess() override;
void Initialize() override;
TRestEvent* ProcessEvent(TRestEvent* inputEvent) override;

/// Returs a given process name
const char* GetProcessName() const override { return "BiPoToSignal"; }

void PrintMetadata() override;

/// It gives access to a Matacq board confituration
MatacqBoard GetMatacqBoard(Int_t n) { return n > fNBoards ? (MatacqBoard){} : fMatacqBoard[n]; }

/// It gives access to confituration of BiPo settings
BiPoSettings GetBiPoSettings(Int_t n) { return n > fNBoards ? (BiPoSettings){} : fBiPoSettings[n]; }

TRestRawBiPoToSignalProcess();
~TRestRawBiPoToSignalProcess();

ClassDefOverride(TRestRawBiPoToSignalProcess, 1);
};

#endif
2 changes: 1 addition & 1 deletion inc/TRestRawToSignalProcess.h
Expand Up @@ -66,7 +66,7 @@ class TRestRawToSignalProcess : public TRestEventProcess {
fSubRunOrigin = fRunInfo->GetSubRunNumber();
}

void PrintMetadata() override;
virtual void PrintMetadata() override;
void Initialize() override;
TRestMetadata* GetProcessMetadata() const { return nullptr; }

Expand Down
Binary file added pipeline/external/BiPo/BiPo3Mod2_run_2600.data
Binary file not shown.

0 comments on commit 5da09a6

Please sign in to comment.