Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rest daq #35

Draft
wants to merge 43 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
7c4fb67
Changes for novel restDAQ package
juanangp Jul 13, 2021
37cb816
Adding enum and maps for different acquisition and electronics
juanangp Jul 29, 2021
d50587d
Fixing baseIP retreival from metadata, now baseIP uses double colon s…
juanangp Jul 30, 2021
01defff
Removing inline since docker image is not c++17 compatible
juanangp Aug 17, 2021
b14812e
Adding fields for FEMINOS
juanangp Aug 23, 2021
22a8a39
Bug fix
juanangp Aug 24, 2021
f72ca05
New containers for FEC and ASIC metadata
juanangp Aug 25, 2021
36b178c
Adding new metadata for single FECs and ASICs
juanangp Aug 25, 2021
ef31d77
Removal of ASICMetadata, not asic parameters are implemented inside F…
juanangp May 30, 2022
8c8f667
Merge branch 'master' of github.com:rest-for-physics/rawlib into rest…
juanangp May 30, 2022
aa7f05a
Merge branch 'master' of github.com:rest-for-physics/rawlib into rest…
juanangp May 31, 2022
27791ad
TRESTDAQMetadata updating documentation
juanangp Jun 2, 2022
42ba207
New method added for a fast retreival of the pulse amplitude after ba…
juanangp Jun 2, 2022
3720f67
Adding documentation to new function GetAmplitudeFast
juanangp Jun 2, 2022
ec74eb6
used new name for number of events `nEvents` instead of `Nevents`
lobis Oct 27, 2022
7d4d6d1
Merge branch 'master' of https://github.com/rest-for-physics/rawlib i…
juanangp Oct 27, 2022
5426df9
Merge branch 'master' into rest_daq
juanangp May 31, 2023
118a294
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 31, 2023
eb2f3be
Removal of FECMetadata class, implementing struct inside TRestRawDAQM…
juanangp May 31, 2023
6bede40
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 31, 2023
7e1c3eb
Adding copy operator to FECMetadata struct
Jun 2, 2023
8656c48
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 2, 2023
1415759
Changing to a more generic FEC metadata structure, adding new variabl…
juanangp Jun 4, 2023
c066761
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 4, 2023
fa8c95d
Bug fix
juanangp Jun 5, 2023
947fb3b
Merge branch 'master' into rest_daq
juanangp Jun 16, 2023
a49af8a
Adding new DAQ metadata maximum file size
juanangp Jun 23, 2023
24d9512
Added new method to remove baseline from zero suppression data
juanangp Jun 23, 2023
a0fba18
New process TRestRawZeroSupressionToRawProcess to remove the baseline…
juanangp Jun 23, 2023
cb43de3
Merge branch 'rest_daq' of github.com:rest-for-physics/rawlib into re…
juanangp Jun 23, 2023
c5f644d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 23, 2023
e46a544
Adding RML example to TRestRawZeroSupressionToRawProcess
juanangp Jun 23, 2023
aa071be
Merge branch 'master' into rest_daq
juanangp Sep 8, 2023
64cb318
Fixing compilation error after recent changes in master
juanangp Sep 8, 2023
36d7e9a
Merge branch 'master' into rest_daq
juanangp Dec 15, 2023
6528512
Adding ARC electronics as electronic type
juanangp Apr 29, 2024
0f330d4
Merge branch 'master' into rest_daq
juanangp Apr 29, 2024
bcab3e4
Adding ARC electronics type to map
Apr 29, 2024
e56761e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 29, 2024
cb54bfb
Fixing typo
May 30, 2024
10bf1c4
Merge branch 'rest_daq' of github.com:rest-for-physics/rawlib into re…
May 30, 2024
fa69e3f
Adding new macro to cmpute noise and RMS
May 31, 2024
a4662f0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 111 additions & 19 deletions inc/TRestRawDAQMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,136 @@
#include "TRestMetadata.h"
#include "TString.h"

namespace daq_metadata_types {

enum class acqTypes : int { BACKGROUND = 0, CALIBRATION, PEDESTAL };

enum class electronicsTypes : int { DUMMY = 0, DCC, FEMINOS, ARC };

enum class chipTypes : int { AFTER = 0, AGET };

enum class triggerTypes : int { INTERNAL = 0, EXTERNAL, AUTO, TCM };

enum class compressModeTypes : int { ALLCHANNELS = 0, TRIGGEREDCHANNELS, ZEROSUPPRESSION };

const std::map<std::string, acqTypes> acqTypes_map = {{"background", acqTypes::BACKGROUND},
{"calibration", acqTypes::CALIBRATION},
{"pedestal", acqTypes::PEDESTAL}};

const std::map<std::string, electronicsTypes> electronicsTypes_map = {{"DUMMY", electronicsTypes::DUMMY},
{"DCC", electronicsTypes::DCC},
{"FEMINOS", electronicsTypes::FEMINOS},
{"ARC", electronicsTypes::ARC}};

const std::map<std::string, chipTypes> chipTypes_map = {{"after", chipTypes::AFTER},
{"aget", chipTypes::AGET}};

const std::map<std::string, triggerTypes> triggerTypes_map = {{"internal", triggerTypes::INTERNAL},
{"external", triggerTypes::EXTERNAL},
{"auto", triggerTypes::AUTO},
{"tcm", triggerTypes::TCM}};

const std::map<std::string, compressModeTypes> compressMode_map = {
{"allchannels", compressModeTypes::ALLCHANNELS},
{"triggeredchannels", compressModeTypes::TRIGGEREDCHANNELS},
{"zerosuppression", compressModeTypes::ZEROSUPPRESSION},
};

} // namespace daq_metadata_types

//! A metadata class to store DAQ information.
class TRestRawDAQMetadata : public TRestMetadata {
public:
static constexpr int nAsics = 4;
static constexpr int nChannels = 79;

struct FECMetadata {
Int_t id;
Int_t ip[nAsics];
UShort_t clockDiv;
TString chipType;
UShort_t triggerDelay = 0;
std::array<UShort_t, nAsics> asic_polarity;
std::array<UShort_t, nAsics> asic_pedCenter;
std::array<Float_t, nAsics> asic_pedThr;
std::array<UShort_t, nAsics> asic_gain;
std::array<UShort_t, nAsics> asic_shappingTime;
std::array<UShort_t, nAsics> asic_channelStart;
std::array<UShort_t, nAsics> asic_channelEnd;
std::array<Bool_t, nAsics> asic_isActive;
std::array<UShort_t, nAsics> asic_coarseThr;
std::array<UShort_t, nAsics> asic_fineThr;
std::array<UShort_t, nAsics> asic_multThr;
std::array<UShort_t, nAsics> asic_multLimit;
std::array<std::array<Bool_t, nAsics>, nChannels> asic_channelActive;

bool operator<(const FECMetadata& fM) const { return id < fM.id; }
void operator=(const FECMetadata& fM) {
id = fM.id;
clockDiv = fM.clockDiv;
chipType = fM.chipType;
for (int i = 0; i < nAsics; i++) {
ip[i] = fM.ip[i];
asic_polarity[i] = fM.asic_polarity[i];
asic_pedCenter[i] = fM.asic_pedCenter[i];
asic_pedThr[i] = fM.asic_pedThr[i];
asic_gain[i] = fM.asic_gain[i];
asic_shappingTime[i] = fM.asic_shappingTime[i];
asic_channelStart[i] = fM.asic_channelStart[i];
asic_channelEnd[i] = fM.asic_channelEnd[i];
asic_isActive[i] = fM.asic_isActive[i];
asic_coarseThr[i] = fM.asic_coarseThr[i];
asic_fineThr[i] = fM.asic_fineThr[i];
asic_multThr[i] = fM.asic_multThr[i];
asic_multLimit[i] = fM.asic_multLimit[i];
for (int j = 0; j < nChannels; j++) {
asic_channelActive[i][j] = fM.asic_channelActive[i][j];
}
}
}
};

private:
void InitFromConfigFile() override;

void Initialize() override;

protected:
TString fOutBinFileName;
TString fElectronicsType;
std::vector<TString> fPedBuffer; // Pedestal script
std::vector<TString> fRunBuffer; // Run script
TString fNamePedScript; // Name of the run script e.g. /home/user/scripts/run
TString fNameRunScript; // Name of the pedestal script e.g.
// /home/user/scripts/ped
UInt_t fGain; // Value of the gain in the script you have to convert it to fC
UInt_t fShappingTime; // Value of the shapping time in the script you have to
// convert it to nS
TString fElectronicsType; // DCC, FEMINOS, ARC, ...
TString fTriggerType; // external, internal, auto or tcm
TString fAcquisitionType; // pedestal, calibration or background
TString fCompressMode; // allchannels, triggeredchannels, zerosuppression
Int_t fNEvents = 0; // 0 --> Infinite
Int_t fNPedestalEvents = 100; // Number of pedestal events to be acquired
std::vector<FECMetadata> fFEC; // Vector of FECMETADATA
TString fDecodingFile = ""; // Location of the decoding file
Int_t fMaxFileSize = 1000000000; // Maximum file size in bytes

public:
void PrintMetadata() override;
void PrintRunScript();
void PrintPedScript();

// Constructor
TRestRawDAQMetadata();
TRestRawDAQMetadata(const char* configFilename);
// Destructor
virtual ~TRestRawDAQMetadata();

void SetScriptsBuffer();
void SetParFromPedBuffer(); // Set gain and shaping time from a given buffer
void SetOutBinFileName(TString fName) { fOutBinFileName = fName; }
inline auto GetTriggerType() const { return fTriggerType; }
inline auto GetAcquisitionType() const { return fAcquisitionType; }
inline auto GetElectronicsType() const { return fElectronicsType; }
inline auto GetNEvents() const { return fNEvents; }
inline auto GetNPedestalEvents() const { return fNPedestalEvents; }
inline auto GetCompressMode() const { return fCompressMode; }
inline auto GetDecodingFile() const { return fDecodingFile; }
inline auto GetFECs() const { return fFEC; }
inline auto GetMaxFileSize() const { return fMaxFileSize; }

void SetAcquisitionType(const std::string& typ) { fAcquisitionType = typ; }
void SetNEvents(const Int_t& nEv) { fNEvents = nEv; }

inline UInt_t GetGain() const { return fGain; }
inline UInt_t GetShappingTime() const { return fShappingTime; }
UInt_t GetValFromString(TString var, TString line);
void ReadFEC();
void DumpFEC(const FECMetadata& fec);

ClassDefOverride(TRestRawDAQMetadata, 1); // REST run class
ClassDefOverride(TRestRawDAQMetadata, 3); // REST run class
};
#endif
5 changes: 5 additions & 0 deletions inc/TRestRawSignal.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ class TRestRawSignal {

void InitializePointsOverThreshold(const TVector2& thrPar, Int_t nPointsOver, Int_t nPointsFlat = 512);

void ZeroSuppressionToRaw();

UInt_t GetSeed() const { return fSeed; }

Double_t GetIntegral();
Expand Down Expand Up @@ -208,6 +210,8 @@ class TRestRawSignal {

void Scale(Double_t value);

double GetAmplitudeFast(const TVector2& baselineRange, double signalThreshold);

void WriteSignalToTextFile(const TString& filename);

void Print() const;
Expand All @@ -223,6 +227,7 @@ class TRestRawSignal {

TRestRawSignal();
TRestRawSignal(Int_t nBins);
TRestRawSignal(Int_t sID, std::vector<Short_t>& sData);
~TRestRawSignal();

ClassDef(TRestRawSignal, 2);
Expand Down
62 changes: 62 additions & 0 deletions inc/TRestRawZeroSupressionToRawProcess.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*************************************************************************
* 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 RESTProc_TRestRawZeroSupressionToRawProcess
#define RESTProc_TRestRawZeroSupressionToRawProcess

#include "TRestEvent.h"
#include "TRestEventProcess.h"
#include "TRestRawSignalEvent.h"

/// This process remove the offset on a zerosuppression acquired event
class TRestRawZeroSupressionToRawProcess : public TRestEventProcess {
private:
/// Pointer to TRestRawSignalEvent input event
TRestRawSignalEvent* fEvent; //!

void Initialize() override;

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

void InitProcess() override;

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

TRestEvent* ProcessEvent(TRestEvent* eventInput) override;

void EndProcess() override;

/// It prints out the process parameters stored in the metadata structure
void PrintMetadata() override {
BeginPrintProcess();

EndPrintProcess();
}

TRestRawZeroSupressionToRawProcess();
~TRestRawZeroSupressionToRawProcess();

ClassDefOverride(TRestRawZeroSupressionToRawProcess, 1);
};
#endif
49 changes: 49 additions & 0 deletions macros/REST_Raw_NoiseRMS.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@


void REST_Raw_NoiseRMS(const std::string& fileName, int nEvents = 10) {
TRestRun run(fileName);

TRestRawSignalEvent* rawEvent = (TRestRawSignalEvent*)run.GetInputEvent();

std::map<int, double> channelMapMean;
std::map<int, double> channelMapStd;
std::map<int, int> channelMapCount;

int entries = run.GetEntries();

nEvents = std::min(nEvents, entries);

for (int i = 0; i < nEvents; i++) {
run.GetEntry(i);
int chId;
double mean = 0, rms = 0;
for (int s = 0; s < rawEvent->GetNumberOfSignals(); s++) {
TRestRawSignal* rawSignal = rawEvent->GetSignal(s);
const int daqChannel = rawSignal->GetSignalID();
for (int p = 0; p < rawSignal->GetNumberOfPoints(); p++) {
short data = rawSignal->GetRawData(p);
channelMapMean[daqChannel] += data;
channelMapStd[daqChannel] += data * data;
channelMapCount[daqChannel]++;
}
}
}

auto grE = new TGraphErrors();

int c = 0;
for (const auto& [channel, count] : channelMapCount) {
if (count > 0) {
double mean = channelMapMean[channel] / count;
double std = sqrt(channelMapStd[channel] / count - mean * mean);
std::cout << "Channel " << channel << " Mean " << mean << " Std " << std << endl;
grE->SetPoint(c, channel, mean);
grE->SetPointError(c, 0, std);
c++;
}
}

std::cout << "Total number of events processed " << nEvents << endl;

grE->Draw("AP");
}
Loading
Loading