Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed May 29, 2024
1 parent a8d7645 commit 513988e
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 158 deletions.
40 changes: 20 additions & 20 deletions source/framework/sensitivity/inc/TRestComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +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 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 @@ -113,7 +113,7 @@ 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);
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 @@ -126,11 +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() {
if( fActiveNode >= 0 && fActiveNode < (Int_t) fParameterizationNodes.size() )
return fParameterizationNodes[fActiveNode];
return 0;
}
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 @@ -139,8 +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 GetMaxRate();
Double_t GetAllNodesIntegratedRate();
Double_t GetNormalizedRate(std::vector<Double_t> point);
Double_t GetRate(std::vector<Double_t> point);

Expand Down
4 changes: 2 additions & 2 deletions source/framework/sensitivity/inc/TRestExperiment.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ 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; //<

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

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

Bool_t IsMockData() const { return fMockData; }
Expand Down
2 changes: 1 addition & 1 deletion source/framework/sensitivity/inc/TRestExperimentList.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class TRestExperimentList : public TRestMetadata {
/// 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
/// 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
Expand Down
152 changes: 68 additions & 84 deletions source/framework/sensitivity/src/TRestComponent.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ TRestComponent::~TRestComponent() {}
void TRestComponent::Initialize() {
// SetSectionName(this->ClassName());

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

if (!fRandom) {
delete fRandom;
Expand All @@ -97,14 +97,12 @@ void TRestComponent::Initialize() {
fRandom = new TRandom3(fSeed);
fSeed = fRandom->TRandom::GetSeed();

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

/////////////////////////////////////////////
Expand All @@ -117,35 +115,31 @@ void TRestComponent::RegenerateHistograms(UInt_t seed) {
fNodeDensity.clear();

fSeed = seed;
FillHistograms();
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 );
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);
}

///////////////////////////////////////////
Expand Down Expand Up @@ -270,12 +264,10 @@ 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;
}
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);
Expand Down Expand Up @@ -303,7 +295,7 @@ Double_t TRestComponent::GetRawRate(std::vector<Double_t> point) {
// In 3-dimensions we got 8 points to interpolate
// In 4-dimensions we would get 16 points to interpolate
// ...
Int_t nPoints = (Int_t)TMath::Power(2, (Int_t) GetDimensions());
Int_t nPoints = (Int_t)TMath::Power(2, (Int_t)GetDimensions());

Double_t sum = 0;
for (int n = 0; n < nPoints; n++) {
Expand Down Expand Up @@ -334,27 +326,22 @@ Double_t TRestComponent::GetRawRate(std::vector<Double_t> point) {
///
Double_t TRestComponent::GetTotalRate() {
THnD* dHist = GetDensityForActiveNode();
if ( !dHist) return 0;
if (!dHist) return 0;

Double_t integral = 0;
for (Int_t n = 0; n < dHist->GetNbins(); ++n) {

Int_t centerBin[GetDimensions()];
std::vector <Double_t> point;
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] ) );
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 );
}
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;
}
Expand All @@ -364,28 +351,26 @@ Double_t TRestComponent::GetTotalRate() {
/// 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;
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
/// \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;
Double_t rate = 0;
for (size_t n = 0; n < fParameterizationNodes.size(); n++) {
SetActiveNode((Int_t)n);
rate += GetTotalRate();
}
return rate;
}

///////////////////////////////////////////////
Expand Down Expand Up @@ -658,18 +643,17 @@ void TRestComponent::PrintMetadata() {
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 (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
15 changes: 7 additions & 8 deletions source/framework/sensitivity/src/TRestComponentFormula.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,11 @@ 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;
}
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;

Expand Down Expand Up @@ -238,8 +237,8 @@ void TRestComponentFormula::InitFromConfigFile() {

if (!fFormulas.empty()) return;

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

auto ele = GetElement("formula");
while (ele != nullptr) {
Expand Down
Loading

0 comments on commit 513988e

Please sign in to comment.