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

New TRestEventRateAnalysisProcess implementation #130

Merged
merged 7 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 2 additions & 5 deletions pipeline/pandaxiii_data/P3AutoChain.rml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
<addProcess type="TRestRawSignalAnalysisProcess" name="sAna" value="ON">

/// We define all observables except MinValue because it is not yet in validation chain
<observable name="SecondsFromStart" value="ON" />
<observable name="HoursFromStart" value="ON" />
<observable name="EventTimeDelay" value="ON" />
<observable name="MeanRate_InHz" value="ON" />
<observable name="BaseLineMean" value="ON" />
<observable name="BaseLineSigmaMean" value="ON" />
<observable name="TimeBinsLength" value="ON" />
Expand All @@ -59,13 +55,14 @@
<observable name="AveragePeakTime" value="ON" />

</addProcess>
<addProcess type="TRestEventRateAnalysisProcess" name="rateAna" value="ON" observable="all"/>
<addProcess type="TRestRawZeroSuppresionProcess" name="zS" value="ON" sampling="0.2us"/> 5MHz sampling

<addProcess type="TRestRealTimeDrawingProcess" name="rD" value="ON" drawInterval="1000" >
<TRestAnalysisPlot name="TriggerRatePlot" previewPlot="false">
<canvas size="(1000,800)" save="TriggerRate.png"/>
<plot name="TriggerRate" title="Trigger Rate" xlabel="Seconds From Start" ylabel="Counts" value="ON" stats="ON">
<variable name="sAna_SecondsFromStart" range="auto" nbins="100" />
<variable name="rateAna_SecondsFromStart" range="auto" nbins="100" />
</plot>
</TRestAnalysisPlot>
</addProcess>
Expand Down
Binary file modified pipeline/pandaxiii_data/validation.root
Binary file not shown.
11 changes: 7 additions & 4 deletions pipeline/trex/01_raw.rml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
<parameter name="readoutEndChannel" value="250" />
</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="rawAna" value="ON"
baseLineRange="(${BL_MIN},${BL_MAX})" integralRange="(${INT_MIN},${INT_MAX})"
pointThreshold="${POINT_TH}" pointsOverThreshold="${NPOINTS}" signalThreshold="${SGNL_TH}"
Expand All @@ -41,10 +48,6 @@
<observable name="baselinesigma_map" type="map<int,double>" value="ON" />
<observable name="max_amplitude_map" type="map<int,double>" value="ON" />
<observable name="thr_integral_map" type="map<int,double>" value="ON" />
<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" />
<observable name="BaseLineMean" type="double" value="ON" />
<observable name="BaseLineSigmaMean" type="double" value="ON" />
<observable name="TimeBinsLength" type="double" value="ON" />
Expand Down
65 changes: 65 additions & 0 deletions source/framework/analysis/inc/TRestEventRateAnalysisProcess.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*************************************************************************
* 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_TRestEventRateAnalysisProcess
#define RestCore_TRestEventRateAnalysisProcess

#include "TRestEventProcess.h"

//! A pure analysis process used to calculate event rates and other time observables
class TRestEventRateAnalysisProcess : public TRestEventProcess {
private:
/// A pointer to the input event
TRestEvent* fEvent; //!

/// It registers the timestamp from the first event to calculate time from start observables
Double_t fFirstEventTime; //!

/// It keeps a historic list of timestamps of the previous N events. Now fixed to N=10 events.
vector<Double_t> fPreviousEventTime; //!

void Initialize();

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

public:
any GetInputEvent() { return fEvent; }
any GetOutputEvent() { return fEvent; }

void InitProcess();
TRestEvent* ProcessEvent(TRestEvent* eventInput);

void PrintMetadata() {
BeginPrintProcess();

EndPrintProcess();
}

TString GetProcessName() { return (TString) "eventRateAnalysis"; }

TRestEventRateAnalysisProcess(); // Constructor
~TRestEventRateAnalysisProcess(); // Destructor

ClassDef(TRestEventRateAnalysisProcess, 1);
};
#endif
168 changes: 168 additions & 0 deletions source/framework/analysis/src/TRestEventRateAnalysisProcess.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/*************************************************************************
* 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. *
*************************************************************************/

//////////////////////////////////////////////////////////////////////////
///
/// This process adds observables related to the event time and measured rate
/// to the analysis tree.
///
/// Inside a TRestProcessRunner chain this process might be added
/// as follows:
///
/// \code
/// <addProcess type="TRestEventRateAnalysisProcess" name="rate" observables="all" />
/// \endcode
///
/// or
///
/// \code
/// <addProcess type="TRestEventRateAnalysisProcess" name="rate">
/// <observable name="MeanRate_InHz" />
/// </addProcess>
/// \endcode
///
///
/// ### Observables
///
///
/// * **SecondsFromStart**: It takes the time of the event and subtracts the
/// time of
/// the first event.
/// * **HoursFromStart**: SecondsFromStart divided by 3600.
/// * **EventTimeDelay**: It counts the time from the previous event to the
/// present one.
/// * **MeanRate_InHz**: It records the mean rate using the last 10 events. It
/// divides 10 by the time in seconds between the first and the last entry.
///
///
/// You may add filters to any observable inside the analysis tree. To add a cut,
/// write "cut" sections in your rml file:
///
/// \code
/// <TRestEventRateAnalysisProcess name="" ... >
/// <cut name="MeanRate_InHz" value="(0,10)" />
/// </TRestEventRateAnalysisProcess>
/// \endcode
///
/// <hr>
///
/// \warning **⚠ REST is under continous development.** This documentation
/// is offered to you by the REST community. Your HELP is needed to keep this
/// code up to date. Your feedback will be worth to support this software, please
/// report any problems/suggestions you may find will using it at [The REST Framework
/// forum](http://ezpc10.unizar.es). You are welcome to contribute fixing typos,
/// updating information or adding/proposing new contributions. See also our
/// <a href="https://github.com/rest-for-physics/framework/blob/master/CONTRIBUTING.md">Contribution
/// Guide</a>.
///
///
///_______________________________________________________________________________
///
/// RESTsoft - Software for Rare Event Searches with TPCs
///
/// History of developments:
///
/// 2022-February: Transfering rate observables from TRestRawSignalAnalysisProcess
///
/// \class TRestEventRateAnalysisProcess
/// \author Javier Galan
///
/// <hr>
///
#include "TRestDataBase.h"

#include "TRestEventRateAnalysisProcess.h"
using namespace std;

ClassImp(TRestEventRateAnalysisProcess);

///////////////////////////////////////////////
/// \brief Default constructor
///
TRestEventRateAnalysisProcess::TRestEventRateAnalysisProcess() { Initialize(); }

///////////////////////////////////////////////
/// \brief Default destructor
///
TRestEventRateAnalysisProcess::~TRestEventRateAnalysisProcess() {}

///////////////////////////////////////////////
/// \brief Function to initialize input/output event members and define the
/// section name
///
void TRestEventRateAnalysisProcess::Initialize() {
SetSectionName(this->ClassName());

fEvent = NULL;

fSingleThreadOnly = true;

fFirstEventTime = -1;
fPreviousEventTime.clear();
}

///////////////////////////////////////////////
/// \brief Process initialization.
///
void TRestEventRateAnalysisProcess::InitProcess() {
if (fRunInfo->GetStartTimestamp() != 0) {
fFirstEventTime = fRunInfo->GetStartTimestamp();
} else {
fFirstEventTime = -1;
}
}

///////////////////////////////////////////////
/// \brief The main processing event function
///
TRestEvent* TRestEventRateAnalysisProcess::ProcessEvent(TRestEvent* evInput) {
fEvent = evInput;

if (fFirstEventTime == -1) fFirstEventTime = fEvent->GetTime();

Double_t secondsFromStart = fEvent->GetTime() - fFirstEventTime;
SetObservableValue("SecondsFromStart", secondsFromStart);
SetObservableValue("HoursFromStart", secondsFromStart / 3600.);

Double_t evTimeDelay = 0;
if (fPreviousEventTime.size() > 0) evTimeDelay = fEvent->GetTime() - fPreviousEventTime.back();
SetObservableValue("EventTimeDelay", evTimeDelay);

Double_t meanRate = 0;
if (fPreviousEventTime.size() == 10) meanRate = 10. / (fEvent->GetTime() - fPreviousEventTime.front());
SetObservableValue("MeanRate_InHz", meanRate);

if (GetVerboseLevel() >= REST_Debug) {
for (auto i : fObservablesDefined) {
fAnalysisTree->PrintObservable(i.second);
}
}

fPreviousEventTime.push_back(fEvent->GetTimeStamp());
if (fPreviousEventTime.size() > 10) fPreviousEventTime.erase(fPreviousEventTime.begin());

// If cut condition matches the event will be not registered.
if (ApplyCut()) return NULL;

return fEvent;
}

2 changes: 1 addition & 1 deletion source/framework/core/src/TRestProcessRunner.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Int_t TRestProcessRunner::ReadConfig(string keydeclare, TiXmlElement* e) {
info << "multi-threading is disabled due to process \"" << p->GetName() << "\"" << endl;
info << "This process is in debug mode or is single thread only" << endl;
for (i = fThreadNumber; i > 1; i--) {
delete (*fThreads.end());
delete (*(fThreads.end() - 1));
fThreads.erase(fThreads.end() - 1);
fThreadNumber--;
}
Expand Down