@@ -86,13 +86,23 @@ TRestComponent::~TRestComponent() {}
8686void TRestComponent::Initialize () {
8787 // SetSectionName(this->ClassName());
8888
89+ // / Avoiding double initialization
90+ if (!fNodeDensity .empty () && fRandom ) return ;
91+
8992 if (!fRandom ) {
9093 delete fRandom ;
9194 fRandom = nullptr ;
9295 }
9396
9497 fRandom = new TRandom3 (fSeed );
9598 fSeed = fRandom ->TRandom ::GetSeed ();
99+
100+ if (fStepParameterValue > 0 ) {
101+ RegenerateParametricNodes (fFirstParameterValue , fLastParameterValue , fStepParameterValue ,
102+ fExponential );
103+ } else {
104+ if (!fParameterizationNodes .empty ()) FillHistograms ();
105+ }
96106}
97107
98108// ///////////////////////////////////////////
@@ -105,11 +115,33 @@ void TRestComponent::RegenerateHistograms(UInt_t seed) {
105115 fNodeDensity .clear ();
106116
107117 fSeed = seed;
108- TRestComponent::Initialize ();
109-
110118 FillHistograms ();
111119}
112120
121+ // ///////////////////////////////////////////
122+ // / \brief It allows to produce a parameter nodes list providing the initial
123+ // / value, the final value and the step. We might chose the step growing in
124+ // / linear increase steps or exponential. Linear is the default value.
125+ // /
126+ void TRestComponent::RegenerateParametricNodes (Double_t from, Double_t to, Double_t step,
127+ Bool_t expIncrease) {
128+ fStepParameterValue = step;
129+ fFirstParameterValue = from;
130+ fLastParameterValue = to;
131+ fExponential = expIncrease;
132+
133+ fParameterizationNodes .clear ();
134+
135+ if (expIncrease) {
136+ for (double p = from; p < to; p *= step) fParameterizationNodes .push_back (p);
137+ } else {
138+ for (double p = from; p < to; p += step) fParameterizationNodes .push_back (p);
139+ }
140+
141+ if (fParameterizationNodes .empty ()) return ;
142+ RegenerateHistograms (fSeed );
143+ }
144+
113145// /////////////////////////////////////////
114146// / \brief It returns the position of the fVariable element for the variable
115147// / name given by argument.
@@ -232,6 +264,11 @@ Double_t TRestComponent::GetRawRate(std::vector<Double_t> point) {
232264 return 0 ;
233265 }
234266
267+ for (size_t n = 0 ; n < point.size (); n++) {
268+ // The point is outside boundaries
269+ if (point[n] < fRanges [n].X () || point[n] > fRanges [n].Y ()) return 0 ;
270+ }
271+
235272 Int_t centerBin[GetDimensions ()];
236273 Double_t centralDensity = GetDensity ()->GetBinContent (GetDensity ()->GetBin (point.data ()), centerBin);
237274 if (!Interpolation ()) return centralDensity;
@@ -289,17 +326,53 @@ Double_t TRestComponent::GetRawRate(std::vector<Double_t> point) {
289326// /
290327Double_t TRestComponent::GetTotalRate () {
291328 THnD* dHist = GetDensityForActiveNode ();
329+ if (!dHist) return 0 ;
292330
293331 Double_t integral = 0 ;
294- if (dHist != nullptr ) {
295- TH1D* h1 = dHist->Projection (0 );
296- integral = h1->Integral ();
297- delete h1;
332+ for (Int_t n = 0 ; n < dHist->GetNbins (); ++n) {
333+ Int_t centerBin[GetDimensions ()];
334+ std::vector<Double_t> point;
335+
336+ dHist->GetBinContent (n, centerBin);
337+ for (size_t d = 0 ; d < GetDimensions (); ++d) point.push_back (GetBinCenter (d, centerBin[d]));
338+
339+ Bool_t skip = false ;
340+ for (size_t d = 0 ; d < GetDimensions (); ++d) {
341+ if (point[d] < fRanges [d].X () || point[d] > fRanges [d].Y ()) skip = true ;
342+ }
343+ if (!skip) integral += GetRate (point);
298344 }
299345
300346 return integral;
301347}
302348
349+ // /////////////////////////////////////////////
350+ // / \brief This method returns the total rate for the node that has the highest contribution
351+ // / The result will be returned in s-1.
352+ // /
353+ Double_t TRestComponent::GetMaxRate () {
354+ Double_t maxRate = 0 ;
355+ for (size_t n = 0 ; n < fParameterizationNodes .size (); n++) {
356+ SetActiveNode ((Int_t)n);
357+ Double_t rate = GetTotalRate ();
358+ if (rate > maxRate) maxRate = rate;
359+ }
360+ return maxRate;
361+ }
362+
363+ // /////////////////////////////////////////////
364+ // / \brief This method returns the integrated total rate for all the nodes
365+ // / The result will be returned in s-1.
366+ // /
367+ Double_t TRestComponent::GetAllNodesIntegratedRate () {
368+ Double_t rate = 0 ;
369+ for (size_t n = 0 ; n < fParameterizationNodes .size (); n++) {
370+ SetActiveNode ((Int_t)n);
371+ rate += GetTotalRate ();
372+ }
373+ return rate;
374+ }
375+
303376// /////////////////////////////////////////////
304377// / \brief It returns the bin center of the given component dimension.
305378// /
@@ -561,14 +634,26 @@ void TRestComponent::PrintMetadata() {
561634 }
562635 }
563636
564- if (!fParameter .empty ()) {
637+ if (!fParameterizationNodes .empty ()) {
565638 RESTMetadata << " " << RESTendl;
566639 RESTMetadata << " === Parameterization === " << RESTendl;
567640 RESTMetadata << " - Parameter : " << fParameter << RESTendl;
568641
569642 RESTMetadata << " - Number of parametric nodes : " << fParameterizationNodes .size () << RESTendl;
570643 RESTMetadata << " " << RESTendl;
571644 RESTMetadata << " Use : PrintNodes() for additional info" << RESTendl;
645+
646+ if (fStepParameterValue > 0 ) {
647+ RESTMetadata << " " << RESTendl;
648+ RESTMetadata << " Nodes were automatically generated using these parameters" << RESTendl;
649+ RESTMetadata << " - First node : " << fFirstParameterValue << RESTendl;
650+ RESTMetadata << " - Upper limit node : " << fLastParameterValue << RESTendl;
651+ RESTMetadata << " - Increasing step : " << fStepParameterValue << RESTendl;
652+ if (fExponential )
653+ RESTMetadata << " - Increases exponentially" << RESTendl;
654+ else
655+ RESTMetadata << " - Increases linearly" << RESTendl;
656+ }
572657 }
573658
574659 if (fResponse ) {
0 commit comments