Skip to content

Commit d31c89d

Browse files
authored
Merge pull request #508 from rest-for-physics/jgalan_sensitivity
Sensitivity classes updated, axionlib upgrade, new version header will be generated 2.4.3
2 parents e0bd44c + b310063 commit d31c89d

13 files changed

+625
-59
lines changed

macros/REST_OpenInputFile.C

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void REST_OpenInputFile(const std::string& fileName) {
4747
printf("%s\n", " - dSet->GetDataFrame().GetColumnNames()");
4848
printf("%s\n\n", " - dSet->GetTree()->GetEntries()");
4949
printf("%s\n", " - dSet->GetDataFrame().Display(\"\")->Print()");
50-
printf("%s\n\n", " - dSet->GetDataFrame().Display({\"colName1,colName2\"})->Print()");
50+
printf("%s\n\n", " - dSet->GetDataFrame().Display({\"colName1\", \"colName2\"})->Print()");
5151
if (dSet) delete dSet;
5252
dSet = new TRestDataSet();
5353
dSet->EnableMultiThreading(false);

scripts/generateVersionHeader.py

+23-23
Original file line numberDiff line numberDiff line change
@@ -159,29 +159,29 @@
159159
)
160160
print("\n")
161161
print(
162-
"Once your PR has been accepted and merged, you should generate a new Git tag at the master branch.\n"
163-
)
164-
print(
165-
"-----> git tag -a v"
166-
+ str(a)
167-
+ "."
168-
+ str(b)
169-
+ "."
170-
+ str(c)
171-
+ ' -m "Update to version v'
172-
+ str(a)
173-
+ "."
174-
+ str(b)
175-
+ "."
176-
+ str(c)
177-
+ '"\n'
178-
)
179-
print(
180-
"And push the changes to repository. You should also push your branch to GitHub if you have not already.\n"
181-
)
182-
print("-----> git push origin v" + str(a) + "." + str(b) + "." + str(c) + "\n")
183-
print(
184-
"IMPORTANT. Summarize the changes in the tag generated at the Gitlab repository website.\n"
162+
"Once your PR has been accepted and merged, you should generate a new Git tag and RELEASE at the master branch.\n"
185163
)
164+
# print(
165+
# "-----> git tag -a v"
166+
# + str(a)
167+
# + "."
168+
# + str(b)
169+
# + "."
170+
# + str(c)
171+
# + ' -m "Update to version v'
172+
# + str(a)
173+
# + "."
174+
# + str(b)
175+
# + "."
176+
# + str(c)
177+
# + '"\n'
178+
# )
179+
# print(
180+
# "And push the changes to repository. You should also push your branch to GitHub if you have not already.\n"
181+
# )
182+
# print("-----> git push origin v" + str(a) + "." + str(b) + "." + str(c) + "\n")
183+
# print(
184+
# "IMPORTANT. Summarize the changes in the tag generated at the Gitlab repository website.\n"
185+
# )
186186

187187
exit(0)

source/framework/core/inc/TRestVersion.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
* #endif
1313
*
1414
*/
15-
#define REST_RELEASE "2.4.2"
16-
#define REST_RELEASE_DATE "Mon Feb 12"
17-
#define REST_RELEASE_TIME "22:23:31 CET 2024"
18-
#define REST_RELEASE_NAME "Henry Primakoff"
19-
#define REST_GIT_COMMIT "d8ec95be"
20-
#define REST_VERSION_CODE 132098
15+
#define REST_RELEASE "2.4.3"
16+
#define REST_RELEASE_DATE "Fri May 3"
17+
#define REST_RELEASE_TIME "17:36:10 CEST 2024"
18+
#define REST_RELEASE_NAME "Steven Weinberg"
19+
#define REST_GIT_COMMIT "bc42645d"
20+
#define REST_VERSION_CODE 132099
2121
#define REST_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c))
2222
#define REST_SCHEMA_EVOLUTION "ON"
2323
#endif

source/framework/core/src/TRestDataSet.cxx

+36-1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,26 @@
169169
/// [2] d.GetTree()->GetEntries()
170170
/// \endcode
171171
///
172+
/// Example 3 Automatically importing a dataset using restRoot
173+
///
174+
/// \code
175+
/// restRoot Dataset_FinalBabyIAXO_XMM_mM_P14.root
176+
///
177+
/// REST dataset file identified. It contains a valid TRestDataSet.
178+
///
179+
/// Importing dataset /nfs/dust/iaxo/user/jgalan//Dataset_FinalBabyIAXO_XMM_mM_P14.root as `dSet`
180+
///
181+
/// The dataset is ready. You may now access the dataset using:
182+
///
183+
/// - dSet->PrintMetadata()
184+
/// - dSet->GetDataFrame().GetColumnNames()
185+
/// - dSet->GetTree()->GetEntries()
186+
///
187+
/// - dSet->GetDataFrame().Display("")->Print()
188+
/// - dSet->GetDataFrame().Display({"colName1,colName2"})->Print()
189+
/// [0]
190+
/// \endcode
191+
///
172192
/// ### Relevant quantities
173193
///
174194
/// Sometimes we will be willing that our dataset contains few variables
@@ -241,6 +261,21 @@
241261
/// where `SolarFlux`,`GeneratorArea` and `Nsim` are the given names of
242262
/// the relevant quantities inside the dataset.
243263
///
264+
/// ### Adding cuts
265+
///
266+
/// It is also possible to add cuts used to filter the data that will
267+
/// be stored inside the dataset. We can do that including a TRestCut
268+
/// definition inside the TRestDataSet.
269+
///
270+
/// For example, the following cut definition would discard entries
271+
/// with unexpected values inside the specified column, `process_status`.
272+
///
273+
/// \code
274+
/// <TRestCut>
275+
/// <cut name="goodData" value="!TMath::IsNaN(process_status)"/>
276+
/// </TRestCut>
277+
/// \endcode
278+
///
244279
///----------------------------------------------------------------------
245280
///
246281
/// REST-for-Physics - Software for Rare Event Searches Toolkit
@@ -483,7 +518,7 @@ std::vector<std::string> TRestDataSet::FileSelection() {
483518
}
484519

485520
///////////////////////////////////////////////
486-
/// \brief This function apply a TRestCut to the dataframe
521+
/// \brief This function applies a TRestCut to the dataframe
487522
/// and returns a dataframe with the applied cuts. Note that
488523
/// the cuts are not applied directly to the dataframe on
489524
/// TRestDataSet, to do so you should do fDataSet = MakeCut(fCut);

source/framework/sensitivity/inc/TRestComponent.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ class TRestComponent : public TRestMetadata {
8282
/// A canvas for drawing the active node component
8383
TCanvas* fCanvas = nullptr; //!
8484

85-
/// It returns true if any nodes have been defined.
86-
Bool_t HasNodes() { return !fParameterizationNodes.empty(); }
87-
8885
Bool_t HasDensity() { return !fNodeDensity.empty(); }
8986

9087
/// It returns true if the node has been properly identified
@@ -104,6 +101,9 @@ class TRestComponent : public TRestMetadata {
104101
void Initialize() override;
105102
void RegenerateHistograms(UInt_t seed = 0);
106103

104+
/// It returns true if any nodes have been defined.
105+
Bool_t HasNodes() { return !fParameterizationNodes.empty(); }
106+
107107
virtual void RegenerateActiveNodeDensity() {}
108108

109109
std::string GetNature() const { return fNature; }
@@ -113,6 +113,7 @@ class TRestComponent : public TRestMetadata {
113113
Int_t GetSamples() { return fSamples; }
114114
Int_t GetActiveNode() { return fActiveNode; }
115115
Double_t GetActiveNodeValue() { return fParameterizationNodes[fActiveNode]; }
116+
std::vector<Double_t> GetParameterizationNodes() { return fParameterizationNodes; }
116117

117118
std::vector<std::string> GetVariables() const { return fVariables; }
118119
std::vector<TVector2> GetRanges() const { return fRanges; }
@@ -127,6 +128,7 @@ class TRestComponent : public TRestMetadata {
127128

128129
void SetPrecision(const Float_t& pr) { fPrecision = pr; }
129130

131+
Int_t FindActiveNode(Double_t node);
130132
Int_t SetActiveNode(Double_t node);
131133
Int_t SetActiveNode(Int_t n) {
132134
fActiveNode = n;

source/framework/sensitivity/inc/TRestExperiment.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class TRestExperiment : public TRestMetadata {
4242
TRestComponent* fSignal = nullptr; //<
4343

4444
/// It defines the filename used to load the dataset
45-
std::string fExperimentalDataSet = "";
45+
std::string fExperimentalDataSet = ""; //<
4646

4747
/// It contains the experimental data (should contain same columns as the components)
4848
TRestDataSet fExperimentalData; //<
@@ -53,6 +53,9 @@ class TRestExperiment : public TRestMetadata {
5353
/// Only if it is true we will be able to calculate the LogLikelihood
5454
Bool_t fDataReady = false; //<
5555

56+
/// It keeps track on the number of counts inside the dataset
57+
Int_t fExperimentalCounts = 0; //<
58+
5659
/// Internal process random generator
5760
TRandom3* fRandom = nullptr; //!
5861

@@ -64,6 +67,7 @@ class TRestExperiment : public TRestMetadata {
6467

6568
public:
6669
void GenerateMockDataSet();
70+
Int_t GetExperimentalCounts() const { return fExperimentalCounts; }
6771

6872
Bool_t IsMockData() const { return fMockData; }
6973
Bool_t IsDataReady() const { return fDataReady; }

source/framework/sensitivity/inc/TRestExperimentList.h

+10
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,15 @@ class TRestExperimentList : public TRestMetadata {
5050
/// A vector with a list of experiments includes the background components in this model
5151
std::vector<TRestExperiment*> fExperiments; //<
5252

53+
/// The fusioned list of parameterization nodes found at each experiment signal
54+
std::vector<Double_t> fParameterizationNodes; //<
55+
5356
/// If not zero this will be the common exposure time in micro-seconds (standard REST units)
5457
Double_t fExposureTime = 0;
5558

59+
/// In case an exposure time is given it defines how to assign time to each experiment (unique/ksvz).
60+
std::string fExposureStrategy = "unique";
61+
5662
/// If not null this will be the common signal used in each experiment
5763
TRestComponent* fSignal = nullptr; //<
5864

@@ -71,6 +77,10 @@ class TRestExperimentList : public TRestMetadata {
7177
void SetSignal(TRestComponent* comp) { fSignal = comp; }
7278
void SetBackground(TRestComponent* comp) { fBackground = comp; }
7379

80+
void ExtractExperimentParameterizationNodes();
81+
std::vector<Double_t> GetParameterizationNodes() { return fParameterizationNodes; }
82+
void PrintParameterizationNodes();
83+
7484
std::vector<TRestExperiment*> GetExperiments() { return fExperiments; }
7585
TRestExperiment* GetExperiment(const size_t& n) {
7686
if (n >= GetNumberOfExperiments())

source/framework/sensitivity/inc/TRestSensitivity.h

+40-6
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,51 @@
2929
class TRestSensitivity : public TRestMetadata {
3030
private:
3131
/// A list of experimental conditions included to get a final sensitivity plot
32-
std::vector<TRestExperiment*> fExperiments; //<
32+
std::vector<TRestExperiment*> fExperiments; //!
3333

34+
/// The fusioned list of parameterization nodes found at each experiment signal
35+
std::vector<Double_t> fParameterizationNodes; //<
36+
37+
/// A vector of calculated sensitivity curves defined as a funtion of the parametric node
38+
std::vector<std::vector<Double_t>> fCurves; //<
39+
40+
/// A flag that will frozen adding more experiments in the future.
41+
Bool_t fFrozen = false; //< Only needed if we add experiments by other means than RML
42+
43+
/// It is used to generate a histogram with the signal distribution produced with different signal samples
3444
TH1D* fSignalTest = nullptr;
3545

46+
/// A canvas to draw
47+
TCanvas* fCanvas = nullptr; //!
48+
3649
protected:
3750
void InitFromConfigFile() override;
3851

39-
Double_t UnbinnedLogLikelihood(const TRestExperiment* experiment, Double_t g4 = 0);
40-
Double_t ApproachByFactor(Double_t g4, Double_t chi0, Double_t target, Double_t factor);
52+
Double_t UnbinnedLogLikelihood(const TRestExperiment* experiment, Double_t node, Double_t g4 = 0);
53+
Double_t ApproachByFactor(Double_t node, Double_t g4, Double_t chi0, Double_t target, Double_t factor);
4154

4255
public:
4356
void Initialize() override;
4457

45-
Double_t GetCoupling(Double_t sigma = 2, Double_t precision = 0.01);
58+
void ExtractExperimentParameterizationNodes(Bool_t rescan = false);
59+
std::vector<Double_t> GetParameterizationNodes() { return fParameterizationNodes; }
60+
void PrintParameterizationNodes();
61+
62+
Double_t GetCoupling(Double_t node, Double_t sigma = 2, Double_t precision = 0.01);
63+
void AddCurve(const std::vector<Double_t>& curve) { fCurves.push_back(curve); }
64+
void GenerateCurve();
65+
void GenerateCurves(Int_t N);
4666

47-
TH1D* SignalStatisticalTest(Int_t N);
67+
std::vector<Double_t> GetCurve(size_t n = 0);
68+
std::vector<Double_t> GetAveragedCurve();
69+
std::vector<std::vector<Double_t>> GetLevelCurves(const std::vector<Double_t>& levels);
70+
71+
void ExportCurve(std::string fname, int n);
72+
void ExportAveragedCurve(std::string fname);
73+
74+
TH1D* SignalStatisticalTest(Double_t node, Int_t N);
75+
76+
void Freeze() { fFrozen = true; }
4877

4978
std::vector<TRestExperiment*> GetExperiments() { return fExperiments; }
5079
TRestExperiment* GetExperiment(const size_t& n) {
@@ -55,13 +84,18 @@ class TRestSensitivity : public TRestMetadata {
5584
}
5685

5786
size_t GetNumberOfExperiments() { return fExperiments.size(); }
87+
size_t GetNumberOfCurves() { return fCurves.size(); }
88+
size_t GetNumberOfNodes() { return fParameterizationNodes.size(); }
5889

5990
void PrintMetadata() override;
6091

92+
TCanvas* DrawCurves();
93+
TCanvas* DrawLevelCurves();
94+
6195
TRestSensitivity(const char* cfgFileName, const std::string& name = "");
6296
TRestSensitivity();
6397
~TRestSensitivity();
6498

65-
ClassDefOverride(TRestSensitivity, 1);
99+
ClassDefOverride(TRestSensitivity, 2);
66100
};
67101
#endif

source/framework/sensitivity/src/TRestComponent.cxx

+19
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,25 @@ void TRestComponent::InitFromConfigFile() {
627627
if (fResponse) fResponse->LoadResponse();
628628
}
629629

630+
/////////////////////////////////////////////
631+
/// \brief It returns the position of the fParameterizationNodes
632+
/// element for the variable name given by argument.
633+
///
634+
Int_t TRestComponent::FindActiveNode(Double_t node) {
635+
int n = 0;
636+
for (const auto& v : fParameterizationNodes) {
637+
Double_t pUp = node * (1 + fPrecision / 2);
638+
Double_t pDown = node * (1 - fPrecision / 2);
639+
if (v > pDown && v < pUp) {
640+
fActiveNode = n;
641+
return fActiveNode;
642+
}
643+
n++;
644+
}
645+
646+
return -1;
647+
}
648+
630649
/////////////////////////////////////////////
631650
/// \brief It returns the position of the fParameterizationNodes
632651
/// element for the variable name given by argument.

source/framework/sensitivity/src/TRestExperiment.cxx

+5-1
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,15 @@ void TRestExperiment::GenerateMockDataSet() {
102102
Double_t meanCounts = GetBackground()->GetTotalRate() * fExposureTime * units("s");
103103

104104
Int_t N = fRandom->Poisson(meanCounts);
105+
RESTInfo << "Experiment: " << GetName() << " Generating mock dataset. Counts: " << N << RESTendl;
105106

106107
ROOT::RDF::RNode df = fBackground->GetMonteCarloDataFrame(N);
107108

108109
fExperimentalData.SetDataFrame(df);
109110
fExperimentalData.SetTotalTimeInSeconds(fExposureTime * units("s"));
110111

112+
fExperimentalCounts = *fExperimentalData.GetDataFrame().Count();
113+
111114
fMockData = true;
112115
fDataReady = true;
113116
}
@@ -118,6 +121,7 @@ void TRestExperiment::SetExperimentalDataSet(const std::string& filename) {
118121

119122
/// fExposureTime is in standard REST units : us
120123
fExposureTime = fExperimentalData.GetTotalTimeInSeconds() / units("s");
124+
fExperimentalCounts = *fExperimentalData.GetDataFrame().Count();
121125

122126
fMockData = false;
123127
fDataReady = true;
@@ -283,7 +287,7 @@ void TRestExperiment::PrintMetadata() {
283287
}
284288
}
285289

286-
RESTMetadata << " - Experimental counts : " << *fExperimentalData.GetDataFrame().Count() << RESTendl;
290+
RESTMetadata << " - Experimental counts : " << fExperimentalCounts << RESTendl;
287291

288292
RESTMetadata << "----" << RESTendl;
289293
}

0 commit comments

Comments
 (0)