Skip to content

Commit 64bc2fc

Browse files
authored
Merge pull request #355 from rest-for-physics/jgalan_sensitivity
Implementation of experimental sensitivity classes
2 parents f53257d + 4ed69d3 commit 64bc2fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3739
-102
lines changed

CMakeLists.txt

+21
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,27 @@ else ()
188188
set(REST_MPFR OFF)
189189
endif (${REST_MPFR} MATCHES "ON")
190190

191+
if (((${REST_ALL_LIBS} MATCHES "ON") AND (NOT DEFINED RESTLIB_AXION))
192+
OR (${RESTLIB_AXION} MATCHES "ON"))
193+
# GSL #### Find GSL
194+
find_package(GSL REQUIRED)
195+
196+
# Include GSL directories
197+
set(external_include_dirs ${external_include_dirs} ${GSL_INCLUDE_DIRS})
198+
199+
# Link GSL libraries
200+
set(external_libs ${external_libs};${GSL_LIBRARIES})
201+
202+
message(STATUS "Found GSL libraries : ${GSL_LIBRARIES}")
203+
message(STATUS "GSL headers : ${GSL_INCLUDE_DIRS}")
204+
205+
set(REST_GSL ON)
206+
else ()
207+
set(REST_GSL OFF)
208+
message(STATUS "GSL libraries not required")
209+
endif (((${REST_ALL_LIBS} MATCHES "ON") AND (NOT DEFINED RESTLIB_AXION))
210+
OR (${RESTLIB_AXION} MATCHES "ON"))
211+
191212
# CURL #####
192213
find_library(CURL_LIB curl)
193214
if (NOT ${CURL_LIB} STREQUAL "CURL_LIB-NOTFOUND")
273 KB
Loading
182 KB
Loading

macros/REST_AddComponentDataSet.C

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "TRestComponent.h"
2+
#include "TRestTask.h"
3+
4+
#ifndef RestTask_AddComponent
5+
#define RestTask_AddComponent
6+
7+
//*******************************************************************************************************
8+
//*** Description: This macro will load from an RML the component chosen in the arguments and it
9+
//*** will write it inside the file given as outputFile
10+
//***
11+
//*** --------------
12+
//*** Usage: restManager AddComponentDataSet components.rml sectionName [outputFile] [componentName] [update]
13+
//***
14+
//*** Arguments description:
15+
//***
16+
//*** - cfgFile: The RML configuration file where the component definition can be found.
17+
//*** - sectionName: The section name used to select a component inside the RML file.
18+
//*** - outputFile: The file where the component is written, by default is components.root.
19+
//*** - componentName: This argument allows to change the component name stored in the output file.
20+
//*** By default it will take the same value as section name.
21+
//*** - update: If disabled it will create a new file erasing any other previously added components.
22+
//*** It is enabled by default.
23+
//***
24+
//*******************************************************************************************************
25+
26+
Int_t REST_AddComponentDataSet(std::string cfgFile, std::string sectionName,
27+
std::string outputFile = "components.root", std::string componentName = "",
28+
Bool_t update = true) {
29+
TRestComponentDataSet comp(cfgFile.c_str(), sectionName.c_str());
30+
comp.Initialize();
31+
32+
TFile* f;
33+
if (update)
34+
f = TFile::Open(outputFile.c_str(), "UPDATE");
35+
else
36+
f = TFile::Open(outputFile.c_str(), "RECREATE");
37+
38+
if (componentName == "") componentName = sectionName;
39+
40+
comp.Write(componentName.c_str());
41+
42+
f->Close();
43+
44+
return 0;
45+
}
46+
#endif

macros/REST_AddComponentFormula.C

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "TRestComponent.h"
2+
#include "TRestTask.h"
3+
4+
#ifndef RestTask_AddComponentFormula
5+
#define RestTask_AddComponentFormula
6+
7+
//*******************************************************************************************************
8+
//*** Description: This macro will load from an RML the component chosen in the arguments and it
9+
//*** will write it inside the file given as outputFile
10+
//***
11+
//*** --------------
12+
//*** Usage: restManager AddComponentFormula components.rml sectionName [outputFile] [componentName] [update]
13+
//***
14+
//*** Arguments description:
15+
//***
16+
//*** - cfgFile: The RML configuration file where the component definition can be found.
17+
//*** - sectionName: The section name used to select a component inside the RML file.
18+
//*** - outputFile: The file where the component is written, by default is components.root.
19+
//*** - componentName: This argument allows to change the component name stored in the output file.
20+
//*** By default it will take the same value as section name.
21+
//*** - update: If disabled it will create a new file erasing any other previously added components.
22+
//*** It is enabled by default.
23+
//***
24+
//*******************************************************************************************************
25+
26+
Int_t REST_AddComponentFormula(std::string cfgFile, std::string sectionName,
27+
std::string outputFile = "components.root", std::string componentName = "",
28+
Bool_t update = true) {
29+
TRestComponentFormula comp(cfgFile.c_str(), sectionName.c_str());
30+
comp.Initialize();
31+
32+
TFile* f;
33+
if (update)
34+
f = TFile::Open(outputFile.c_str(), "UPDATE");
35+
else
36+
f = TFile::Open(outputFile.c_str(), "RECREATE");
37+
38+
if (componentName == "") componentName = sectionName;
39+
40+
comp.Write(componentName.c_str());
41+
42+
f->Close();
43+
44+
return 0;
45+
}
46+
#endif

macros/REST_CheckValidRuns.C

+6-7
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,14 @@ namespace fs = std::filesystem;
3737
//*** CAUTION: Be aware that any non-REST file in the list will be removed if you use purge=1
3838
//***
3939
//*******************************************************************************************************
40-
Int_t REST_CheckValidRuns(TString namePattern, Bool_t purge = false) {
40+
Int_t REST_CheckValidRuns(std::string namePattern, Bool_t purge = false) {
4141
TGeoManager::SetVerboseLevel(0);
4242

4343
vector<std::string> filesNotWellClosed;
4444

4545
TRestStringOutput RESTLog;
4646

47-
string a = TRestTools::Execute((string)("ls -d -1 " + namePattern));
48-
vector<string> b = Split(a, "\n");
47+
std::vector<std::string> b = TRestTools::GetFilesMatchingPattern(namePattern, true);
4948

5049
Double_t totalTime = 0;
5150
int cont = 0;
@@ -76,11 +75,12 @@ Int_t REST_CheckValidRuns(TString namePattern, Bool_t purge = false) {
7675
}
7776

7877
RESTLog << "Run time (hours) : " << run->GetRunLength() / 3600. << RESTendl;
79-
if (run->GetRunLength() > 0) totalTime += run->GetRunLength() / 3600.;
78+
RESTLog << "Entries : " << run->GetEntries() << RESTendl;
8079

81-
if (run->GetEndTimestamp() == 0 || run->GetRunLength() < 0) {
80+
if (run->GetEndTimestamp() == 0 || run->GetRunLength() < 0 || run->GetEntries() == 0) {
8281
filesNotWellClosed.push_back(filename);
83-
}
82+
} else if (run->GetRunLength() > 0)
83+
totalTime += run->GetRunLength() / 3600.;
8484

8585
delete run;
8686

@@ -100,7 +100,6 @@ Int_t REST_CheckValidRuns(TString namePattern, Bool_t purge = false) {
100100
if (purge) {
101101
RESTLog << "---------------------------" << RESTendl;
102102
RESTLog << "The files have been removed" << RESTendl;
103-
RESTLog << "---------------------------" << RESTendl;
104103
}
105104
}
106105

macros/REST_OpenInputFile.C

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ void REST_OpenInputFile(const std::string& fileName) {
4646
printf("\n%s\n", " - dSet->PrintMetadata()");
4747
printf("%s\n", " - dSet->GetDataFrame().GetColumnNames()");
4848
printf("%s\n\n", " - dSet->GetTree()->GetEntries()");
49+
printf("%s\n", " - dSet->GetDataFrame().Display(\"\")->Print()");
4950
printf("%s\n\n", " - dSet->GetDataFrame().Display({\"colName1,colName2\"})->Print()");
5051
if (dSet) delete dSet;
5152
dSet = new TRestDataSet();

pipeline/panda-x/P3AutoChain.rml

+6-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
2-
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
32
<!--In this example, when launching the analysis, we are doing following operations inside TRestManager:
43
1. Initialize TRestRun
54
1.1 set input and output file for TRestRun(here input and output is in "globals")
@@ -13,25 +12,17 @@
1312
2.4.1 add additional observables in the process
1413
3. Add a task to call TRestProcessRunner to run
1514
-->
16-
1715
<TRestManager name="CoBoDataAnalysis" title="Example" verboseLevel="info">
18-
19-
<TRestRun name="SJTU_Proto">
20-
<parameter name="runNumber" value="auto"/>//change this value to "auto" to enable database
21-
<parameter name="inputFileName" value="auto"/>
22-
</TRestRun>
23-
16+
<TRestRun name="SJTU_Proto"><parameter name="runNumber" value="auto"/>//change this value to "auto" to enable database
17+
<parameter name="inputFileName" value="auto"/></TRestRun>
2418
<TRestProcessRunner name="Processor" verboseLevel="info">
2519
<parameter name="eventsToProcess" value="0"/>
2620
<parameter name="threadNumber" value="2"/>
27-
2821
<parameter name="inputAnalysisStorage" value="on"/>
2922
<parameter name="inputEventStorage" value="off"/>
3023
<parameter name="outputEventStorage" value="on"/>
31-
3224
<addProcess type="TRestRawMultiCoBoAsAdToSignalProcess" name="virtualDAQ" value="ON"/>
33-
<addProcess type="TRestRawSignalAnalysisProcess" name="sAna" value="ON">
34-
<parameter name="pointsOverThreshold" value="3"/>
25+
<addProcess type="TRestRawSignalAnalysisProcess" name="sAna" value="ON"><parameter name="pointsOverThreshold" value="3"/>
3526
/// We define all observables except MinValue because it is not yet in validation chain
3627
<observable name="BaseLineMean" value="ON"/>
3728
<observable name="BaseLineSigmaMean" value="ON"/>
@@ -61,31 +52,20 @@
6152
<parameter name="zeroSuppression" value="true"/>
6253
<parameter name="nPointsOverThreshold" value="3"/>
6354
</addProcess>
64-
6555
<addProcess type="TRestRealTimeDrawingProcess" name="rD" value="ON" drawInterval="1000">
6656
<TRestAnalysisPlot name="TriggerRatePlot" previewPlot="false">
6757
<canvas size="(1000,800)" save="TriggerRate.png"/>
68-
<plot name="TriggerRate" title="Trigger Rate" xlabel="Seconds From Start" ylabel="Counts" value="ON"
69-
stats="ON">
58+
<plot name="TriggerRate" title="Trigger Rate" xlabel="Seconds From Start" ylabel="Counts" value="ON" stats="ON">
7059
<variable name="rateAna_SecondsFromStart" range="auto" nbins="100"/>
7160
</plot>
7261
</TRestAnalysisPlot>
7362
</addProcess>
74-
75-
7663
</TRestProcessRunner>
77-
7864
<addTask type="processEvents" value="ON"/>
79-
80-
8165
<globals>
8266
<searchPath value="$ENV{REST_INPUTDATA}/definitions/"/>
8367
<parameter name="mainDataPath" value=""/>
84-
8568
<parameter name="pointThreshold" value="3"/>
8669
</globals>
87-
8870
</TRestManager>
89-
90-
91-
<!--parameter here is accessible to all the classes-->
71+
<!--parameter here is accessible to all the classes-->

source/bin/restRoot.cxx

+13-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int main(int argc, char* argv[]) {
6161
printf("\n");
6262
printf(" restRoot --m [0,1]\n");
6363
printf("\n");
64-
printf(" Option 0 will disable macro loading. Option 1 is the default.\n");
64+
printf(" Option 0 will disable macro loading. Option 0 is the default.\n");
6565
printf("\n");
6666
exit(0);
6767
}
@@ -81,7 +81,18 @@ int main(int argc, char* argv[]) {
8181
gROOT->ProcessLine("#include <TRestPhysics.h>");
8282
gROOT->ProcessLine("#include <TRestSystemOfUnits.h>");
8383
if (loadMacros) {
84-
if (!silent) printf("= Loading macros ...\n");
84+
if (!silent) {
85+
printf("= Loading macros ...\n");
86+
printf(
87+
"= HINT. Loading all macros may require a long time till you get access to the interactive "
88+
"shell\n");
89+
printf("= HINT. You may use `restListMacros` outside `restRoot` to check the available macros\n");
90+
printf(
91+
"= HINT. Then, you may execute the macro externally by using: `restManager MacroName "
92+
"[ARGUMENTS]\n");
93+
printf("= HINT. `MacroName` is the name of the macro after removing the macro name header\n");
94+
printf("= HINT. E.g. REST_Detector_XYZ(arg1,arg2) may be called as: restManager XYZ arg1 arg2\n");
95+
}
8596
vector<string> macroFiles;
8697
const vector<string> patterns = {
8798
REST_PATH + "/macros/REST_*.C", // framework

source/framework/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ link_libraries("-fPIC")
44

55
add_subdirectory(external)
66

7-
set(contents external/tinyxml tools core analysis masks)
7+
set(contents external/tinyxml tools core analysis masks sensitivity)
88

99
file(GLOB_RECURSE addon_src "tiny*cpp" "startup.cpp")
1010

source/framework/core/inc/TRestDataSet.h

+27-11
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class TRestDataSet : public TRestMetadata {
8282
std::map<std::string, RelevantQuantity> fQuantity; //<
8383

8484
/// Parameter cuts over the selected dataset
85-
TRestCut* fCut = nullptr;
85+
TRestCut* fCut = nullptr; //<
8686

8787
/// The total integrated run time of selected files
8888
Double_t fTotalDuration = 0; //<
@@ -103,12 +103,14 @@ class TRestDataSet : public TRestMetadata {
103103
std::vector<std::string> fImportedFiles; //<
104104

105105
/// A list of new columns together with its corresponding expressions added to the dataset
106-
std::vector<std::pair<std::string, std::string>> fColumnNameExpressions;
106+
std::vector<std::pair<std::string, std::string>> fColumnNameExpressions; //<
107107

108108
/// A flag to enable Multithreading during dataframe generation
109109
Bool_t fMT = false; //<
110110

111-
inline auto GetAddedColumns() const { return fColumnNameExpressions; }
111+
// If the dataframe was defined externally it will be true
112+
Bool_t fExternal = false; //<
113+
112114
/// The resulting RDF::RNode object after initialization
113115
ROOT::RDF::RNode fDataSet = ROOT::RDataFrame(0); //!
114116

@@ -123,20 +125,28 @@ class TRestDataSet : public TRestMetadata {
123125
public:
124126
/// Gives access to the RDataFrame
125127
ROOT::RDF::RNode GetDataFrame() const {
126-
if (fTree == nullptr) RESTWarning << "DataFrame has not been yet initialized" << RESTendl;
128+
if (!fExternal && fTree == nullptr)
129+
RESTWarning << "DataFrame has not been yet initialized" << RESTendl;
127130
return fDataSet;
128131
}
129132

130-
void SetDataFrame(const ROOT::RDF::RNode& dS) { fDataSet = dS; }
131-
132133
void EnableMultiThreading(Bool_t enable = true) { fMT = enable; }
133134

134135
/// Gives access to the tree
135136
TTree* GetTree() const {
137+
if (fTree == nullptr && fExternal) {
138+
RESTInfo << "The tree is not accessible. Only GetDataFrame can be used in an externally "
139+
"generated dataset"
140+
<< RESTendl;
141+
RESTInfo << "You may write a tree using GetDataFrame()->Snapshot(\"MyTree\", \"output.root\");"
142+
<< RESTendl;
143+
return fTree;
144+
}
145+
136146
if (fTree == nullptr) {
137147
RESTError << "Tree has not been yet initialized" << RESTendl;
138-
RESTError << "You should invoke TRestDataSet::GenerateDataSet() before trying to access the tree"
139-
<< RESTendl;
148+
RESTError << "You should invoke TRestDataSet::GenerateDataSet() or " << RESTendl;
149+
RESTError << "TRestDataSet::Import( fname ) before trying to access the tree" << RESTendl;
140150
}
141151
return fTree;
142152
}
@@ -167,21 +177,27 @@ class TRestDataSet : public TRestMetadata {
167177
inline auto GetFilterLowerThan() const { return fFilterLowerThan; }
168178
inline auto GetFilterEqualsTo() const { return fFilterEqualsTo; }
169179
inline auto GetQuantity() const { return fQuantity; }
180+
inline auto GetAddedColumns() const { return fColumnNameExpressions; }
170181
inline auto GetCut() const { return fCut; }
171182
inline auto IsMergedDataSet() const { return fMergedDataset; }
172183

173184
inline void SetObservablesList(const std::vector<std::string>& obsList) { fObservablesList = obsList; }
174185
inline void SetFilePattern(const std::string& pattern) { fFilePattern = pattern; }
175186
inline void SetQuantity(const std::map<std::string, RelevantQuantity>& quantity) { fQuantity = quantity; }
176187

188+
void SetTotalTimeInSeconds(Double_t seconds) { fTotalDuration = seconds; }
189+
void SetDataFrame(const ROOT::RDF::RNode& dS) {
190+
fDataSet = dS;
191+
fExternal = true;
192+
}
193+
177194
TRestDataSet& operator=(TRestDataSet& dS);
178195
Bool_t Merge(const TRestDataSet& dS);
179196
void Import(const std::string& fileName);
180197
void Import(std::vector<std::string> fileNames);
181-
void Export(const std::string& filename);
198+
void Export(const std::string& filename, std::vector<std::string> excludeColumns = {});
182199

183200
ROOT::RDF::RNode MakeCut(const TRestCut* cut);
184-
185201
ROOT::RDF::RNode DefineColumn(const std::string& columnName, const std::string& formula);
186202

187203
void PrintMetadata() override;
@@ -193,6 +209,6 @@ class TRestDataSet : public TRestMetadata {
193209
TRestDataSet(const char* cfgFileName, const std::string& name = "");
194210
~TRestDataSet();
195211

196-
ClassDefOverride(TRestDataSet, 5);
212+
ClassDefOverride(TRestDataSet, 7);
197213
};
198214
#endif

source/framework/core/inc/TRestMetadata.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ class TRestMetadata : public TNamed {
332332
~TRestMetadata();
333333

334334
// Making class constructors protected to keep this class abstract
335-
TRestMetadata& operator=(const TRestMetadata&) = delete;
336-
TRestMetadata(const TRestMetadata&) = delete;
335+
TRestMetadata& operator=(const TRestMetadata&);
336+
TRestMetadata(const TRestMetadata&);
337337

338338
/// Call CINT to generate streamers for this class
339339
ClassDef(TRestMetadata, 9);

0 commit comments

Comments
 (0)