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

Adding IAXO sensitivity examples and updating sensitivity classes when necessary #521

Merged
merged 22 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
43834ea
TRestComponent::GetActiveNodeValue. Adding protection
jgalan May 23, 2024
6dc59b5
TRestExperiment::InitFromConfigFile. Now a component does not need to…
jgalan May 23, 2024
506f931
TRestComponentFormula::FillHistograms adding protection
jgalan May 23, 2024
c5a85ad
TRestComponent::GetRawRate. Adding protection in case point is outsid…
jgalan May 23, 2024
36fb433
TRestComponentFormula. Fixing variable name
jgalan May 23, 2024
7c7cd94
TRestComponent::GetTotalRate now takes into account the response
jgalan May 23, 2024
31c8c45
TRestComponent::RegenerateParametricNodes method added
jgalan May 23, 2024
af25e19
TRestComponent. Fixing pipeline issues
jgalan May 23, 2024
8f84763
TRestComponent. Adding members to automatize parameter list initializ…
jgalan May 24, 2024
66e30ee
TRestComponent. Increasing class version
jgalan May 24, 2024
5308886
TRetComponent::RegenateHistograms avoid double histogram fill
jgalan May 24, 2024
fa4c04e
TRestComponent. Avoid recursive method call
jgalan May 24, 2024
4660a81
TRestSensitivity::GenerateCurves quarantined
jgalan May 27, 2024
1c9bb68
TRestComponent adding metadata members explicitily for IO streamer
jgalan May 28, 2024
9758d64
TRestSensitivity::ImportCurve method added
jgalan May 28, 2024
0a7aab9
TRestComponent. Fixing few initialization issues
jgalan May 28, 2024
83b1926
TRestSensitivity. Adding warnings
jgalan May 28, 2024
52b34f8
TRestComponent::GetMaxRate/GetAllNodesIntegratedRate methods added
jgalan May 29, 2024
86bebc5
TRestExperiment::fUseAverage added to allow using always the average …
jgalan May 29, 2024
804651f
TRestExperimentList::fUseAverage added so that experiments mock data …
jgalan May 29, 2024
a8d7645
TRestExperimentList. Fixing compilation issues
jgalan May 29, 2024
513988e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 29, 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
24 changes: 22 additions & 2 deletions source/framework/sensitivity/inc/TRestComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ class TRestComponent : public TRestMetadata {
/// It defines the nodes of the parameterization (Initialized by the dataset)
std::vector<Double_t> fParameterizationNodes; //<

/// It defines the first parametric node value in case of automatic parameter generation
Double_t fFirstParameterValue = 0; //<

/// It defines the upper limit for the automatic parametric node values generation
Double_t fLastParameterValue = 0; //<

/// It defines the increasing step for automatic parameter list generation
Double_t fStepParameterValue = 0; //<

/// It true the parametric values automatically generated will grow exponentially
Bool_t fExponential = false; //<

/// It is used to define the node that will be accessed for rate retrieval
Int_t fActiveNode = -1; //<

Expand Down Expand Up @@ -101,6 +113,8 @@ class TRestComponent : public TRestMetadata {
void Initialize() override;
void RegenerateHistograms(UInt_t seed = 0);

void RegenerateParametricNodes(Double_t from, Double_t to, Double_t step, Bool_t expIncrease = false);

/// It returns true if any nodes have been defined.
Bool_t HasNodes() { return !fParameterizationNodes.empty(); }

Expand All @@ -112,7 +126,11 @@ class TRestComponent : public TRestMetadata {
size_t GetDimensions() { return fVariables.size(); }
Int_t GetSamples() { return fSamples; }
Int_t GetActiveNode() { return fActiveNode; }
Double_t GetActiveNodeValue() { return fParameterizationNodes[fActiveNode]; }
Double_t GetActiveNodeValue() {
if (fActiveNode >= 0 && fActiveNode < (Int_t)fParameterizationNodes.size())
return fParameterizationNodes[fActiveNode];
return 0;
}
std::vector<Double_t> GetParameterizationNodes() { return fParameterizationNodes; }

std::vector<std::string> GetVariables() const { return fVariables; }
Expand All @@ -121,6 +139,8 @@ class TRestComponent : public TRestMetadata {

Double_t GetRawRate(std::vector<Double_t> point);
Double_t GetTotalRate();
Double_t GetMaxRate();
Double_t GetAllNodesIntegratedRate();
Double_t GetNormalizedRate(std::vector<Double_t> point);
Double_t GetRate(std::vector<Double_t> point);

Expand Down Expand Up @@ -171,6 +191,6 @@ class TRestComponent : public TRestMetadata {
TRestComponent();
~TRestComponent();

ClassDefOverride(TRestComponent, 5);
ClassDefOverride(TRestComponent, 6);
};
#endif
2 changes: 1 addition & 1 deletion source/framework/sensitivity/inc/TRestComponentFormula.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TRestComponentFormula : public TRestComponent {
std::vector<TFormula> fFormulas;

/// The formulas should be expressed in the following units
std::string fUnits = "cm^-2*keV^-1"; //<
std::string fFormulaUnits = "cm^-2*keV^-1"; //<

protected:
void InitFromConfigFile() override;
Expand Down
7 changes: 5 additions & 2 deletions source/framework/sensitivity/inc/TRestExperiment.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class TRestExperiment : public TRestMetadata {
/// Only if it is true we will be able to calculate the LogLikelihood
Bool_t fDataReady = false; //<

/// The mock dataset will be generated using the mean counts instead of a real MonteCarlo
Bool_t fUseAverage = false; //<

/// It keeps track on the number of counts inside the dataset
Int_t fExperimentalCounts = 0; //<

Expand All @@ -66,7 +69,7 @@ class TRestExperiment : public TRestMetadata {
void InitFromConfigFile() override;

public:
void GenerateMockDataSet();
void GenerateMockDataSet(Bool_t useAverage = false);
Int_t GetExperimentalCounts() const { return fExperimentalCounts; }

Bool_t IsMockData() const { return fMockData; }
Expand Down Expand Up @@ -94,6 +97,6 @@ class TRestExperiment : public TRestMetadata {
TRestExperiment();
~TRestExperiment();

ClassDefOverride(TRestExperiment, 1);
ClassDefOverride(TRestExperiment, 2);
};
#endif
12 changes: 9 additions & 3 deletions source/framework/sensitivity/inc/TRestExperimentList.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,17 @@ class TRestExperimentList : public TRestMetadata {
/// The fusioned list of parameterization nodes found at each experiment signal
std::vector<Double_t> fParameterizationNodes; //<

/// The mock dataset will be generated using the mean counts instead of a real MonteCarlo
Bool_t fUseAverage = false; //<

/// If not zero this will be the common exposure time in micro-seconds (standard REST units)
Double_t fExposureTime = 0;

/// In case an exposure time is given it defines how to assign time to each experiment (unique/ksvz).
std::string fExposureStrategy = "unique";
/// In case an exposure time is given it defines how to assign time to each experiment (equal/ksvz).
std::string fExposureStrategy = "equal";

/// The factor used on the exponential exposure time as a function of the experiment number
Double_t fExposureFactor = 0;

/// If not null this will be the common signal used in each experiment
TRestComponent* fSignal = nullptr; //<
Expand Down Expand Up @@ -98,6 +104,6 @@ class TRestExperimentList : public TRestMetadata {
TRestExperimentList();
~TRestExperimentList();

ClassDefOverride(TRestExperimentList, 1);
ClassDefOverride(TRestExperimentList, 2);
};
#endif
1 change: 1 addition & 0 deletions source/framework/sensitivity/inc/TRestSensitivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class TRestSensitivity : public TRestMetadata {

Double_t GetCoupling(Double_t node, Double_t sigma = 2, Double_t precision = 0.01);
void AddCurve(const std::vector<Double_t>& curve) { fCurves.push_back(curve); }
void ImportCurve(const std::vector<Double_t>& curve) { AddCurve(curve); }
void GenerateCurve();
void GenerateCurves(Int_t N);

Expand Down
99 changes: 92 additions & 7 deletions source/framework/sensitivity/src/TRestComponent.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,23 @@ TRestComponent::~TRestComponent() {}
void TRestComponent::Initialize() {
// SetSectionName(this->ClassName());

/// Avoiding double initialization
if (!fNodeDensity.empty() && fRandom) return;

if (!fRandom) {
delete fRandom;
fRandom = nullptr;
}

fRandom = new TRandom3(fSeed);
fSeed = fRandom->TRandom::GetSeed();

if (fStepParameterValue > 0) {
RegenerateParametricNodes(fFirstParameterValue, fLastParameterValue, fStepParameterValue,
fExponential);
} else {
if (!fParameterizationNodes.empty()) FillHistograms();
}
}

/////////////////////////////////////////////
Expand All @@ -105,11 +115,33 @@ void TRestComponent::RegenerateHistograms(UInt_t seed) {
fNodeDensity.clear();

fSeed = seed;
TRestComponent::Initialize();

FillHistograms();
}

/////////////////////////////////////////////
/// \brief It allows to produce a parameter nodes list providing the initial
/// value, the final value and the step. We might chose the step growing in
/// linear increase steps or exponential. Linear is the default value.
///
void TRestComponent::RegenerateParametricNodes(Double_t from, Double_t to, Double_t step,
Bool_t expIncrease) {
fStepParameterValue = step;
fFirstParameterValue = from;
fLastParameterValue = to;
fExponential = expIncrease;

fParameterizationNodes.clear();

if (expIncrease) {
for (double p = from; p < to; p *= step) fParameterizationNodes.push_back(p);
} else {
for (double p = from; p < to; p += step) fParameterizationNodes.push_back(p);
}

if (fParameterizationNodes.empty()) return;
RegenerateHistograms(fSeed);
}

///////////////////////////////////////////
/// \brief It returns the position of the fVariable element for the variable
/// name given by argument.
Expand Down Expand Up @@ -232,6 +264,11 @@ Double_t TRestComponent::GetRawRate(std::vector<Double_t> point) {
return 0;
}

for (size_t n = 0; n < point.size(); n++) {
// The point is outside boundaries
if (point[n] < fRanges[n].X() || point[n] > fRanges[n].Y()) return 0;
}

Int_t centerBin[GetDimensions()];
Double_t centralDensity = GetDensity()->GetBinContent(GetDensity()->GetBin(point.data()), centerBin);
if (!Interpolation()) return centralDensity;
Expand Down Expand Up @@ -289,17 +326,53 @@ Double_t TRestComponent::GetRawRate(std::vector<Double_t> point) {
///
Double_t TRestComponent::GetTotalRate() {
THnD* dHist = GetDensityForActiveNode();
if (!dHist) return 0;

Double_t integral = 0;
if (dHist != nullptr) {
TH1D* h1 = dHist->Projection(0);
integral = h1->Integral();
delete h1;
for (Int_t n = 0; n < dHist->GetNbins(); ++n) {
Int_t centerBin[GetDimensions()];
std::vector<Double_t> point;

dHist->GetBinContent(n, centerBin);
for (size_t d = 0; d < GetDimensions(); ++d) point.push_back(GetBinCenter(d, centerBin[d]));

Bool_t skip = false;
for (size_t d = 0; d < GetDimensions(); ++d) {
if (point[d] < fRanges[d].X() || point[d] > fRanges[d].Y()) skip = true;
}
if (!skip) integral += GetRate(point);
}

return integral;
}

///////////////////////////////////////////////
/// \brief This method returns the total rate for the node that has the highest contribution
/// The result will be returned in s-1.
///
Double_t TRestComponent::GetMaxRate() {
Double_t maxRate = 0;
for (size_t n = 0; n < fParameterizationNodes.size(); n++) {
SetActiveNode((Int_t)n);
Double_t rate = GetTotalRate();
if (rate > maxRate) maxRate = rate;
}
return maxRate;
}

///////////////////////////////////////////////
/// \brief This method returns the integrated total rate for all the nodes
/// The result will be returned in s-1.
///
Double_t TRestComponent::GetAllNodesIntegratedRate() {
Double_t rate = 0;
for (size_t n = 0; n < fParameterizationNodes.size(); n++) {
SetActiveNode((Int_t)n);
rate += GetTotalRate();
}
return rate;
}

///////////////////////////////////////////////
/// \brief It returns the bin center of the given component dimension.
///
Expand Down Expand Up @@ -561,14 +634,26 @@ void TRestComponent::PrintMetadata() {
}
}

if (!fParameter.empty()) {
if (!fParameterizationNodes.empty()) {
RESTMetadata << " " << RESTendl;
RESTMetadata << " === Parameterization === " << RESTendl;
RESTMetadata << "- Parameter : " << fParameter << RESTendl;

RESTMetadata << " - Number of parametric nodes : " << fParameterizationNodes.size() << RESTendl;
RESTMetadata << " " << RESTendl;
RESTMetadata << " Use : PrintNodes() for additional info" << RESTendl;

if (fStepParameterValue > 0) {
RESTMetadata << " " << RESTendl;
RESTMetadata << " Nodes were automatically generated using these parameters" << RESTendl;
RESTMetadata << " - First node : " << fFirstParameterValue << RESTendl;
RESTMetadata << " - Upper limit node : " << fLastParameterValue << RESTendl;
RESTMetadata << " - Increasing step : " << fStepParameterValue << RESTendl;
if (fExponential)
RESTMetadata << " - Increases exponentially" << RESTendl;
else
RESTMetadata << " - Increases linearly" << RESTendl;
}
}

if (fResponse) {
Expand Down
13 changes: 11 additions & 2 deletions source/framework/sensitivity/src/TRestComponentFormula.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Double_t TRestComponentFormula::GetFormulaRate(std::vector<Double_t> point) {
normFactor *= (fRanges[n].Y() - fRanges[n].X()) / fNbins[n];
}

return normFactor * result / units(fUnits);
return normFactor * result / units(fFormulaUnits);
}

/////////////////////////////////////////////
Expand All @@ -149,6 +149,12 @@ Double_t TRestComponentFormula::GetFormulaRate(std::vector<Double_t> point) {
void TRestComponentFormula::FillHistograms() {
if (fFormulas.empty()) return;

if (GetDimensions() == 0) {
RESTError << "TRestComponentFormula::FillHistograms. No variables defined!" << RESTendl;
RESTError << "Did you add a <cVariable entry?" << RESTendl;
return;
}

RESTInfo << "Generating N-dim histogram for " << GetName() << RESTendl;

TString hName = "formula";
Expand Down Expand Up @@ -208,7 +214,7 @@ void TRestComponentFormula::PrintMetadata() {
TRestComponent::PrintMetadata();

RESTMetadata << " " << RESTendl;
RESTMetadata << "Formula units: " << fUnits << RESTendl;
RESTMetadata << "Formula units: " << fFormulaUnits << RESTendl;

if (!fFormulas.empty()) {
RESTMetadata << " " << RESTendl;
Expand All @@ -231,6 +237,9 @@ void TRestComponentFormula::InitFromConfigFile() {

if (!fFormulas.empty()) return;

/// For some reason I need to do this manually. Dont understand why!
fFormulaUnits = GetParameter("formulaUnits");
Copy link
Member Author

@jgalan jgalan May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nkx111 may be you know why I needed to use this? This line seemed to solve my problems with formulaUnits initialization from config file. However, it seems to be working properly (I don't need to implement that line) for all members inside TRestAxionHelioscopeSignal that also inherits from TRestComponent.


auto ele = GetElement("formula");
while (ele != nullptr) {
std::string name = GetParameter("name", ele, "");
Expand Down
Loading
Loading