Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
CorrFitFunctor.cxx
1/*
2 * CorrFitFunctor.cxx
3 *
4 * Created on: 18 maj 2020
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "CorrFitFunctor.h"
11
12#include "CorrFitInfo.h"
13#include "Cout.h"
14
15#include <Rtypes.h>
16#include <RtypesCore.h>
17#include <TFile.h>
18#include <TTree.h>
19
20#include <iostream>
21
22namespace Hal {
23 CorrFitFunctor::CorrFitFunctor(TString map_file) :
24 fMapFile(map_file), fInfo(nullptr), fSetup(), fChain(nullptr), fFile(nullptr), fParams(0), fData(nullptr) {
25 fFile = new TFile(fMapFile);
26 fChain = (TTree*) fFile->Get("map");
27 fInfo = (CorrFitInfo*) fFile->Get("Info");
28 fChain->SetBranchAddress("data", &fData);
29 fSetup = fInfo->GetSetup();
30 fParams = fSetup.GetNParams();
31 fDimsArray = fSetup.GetDimensions();
32 fPosArray.resize(fSetup.GetNParams());
33 }
34
35 Bool_t CorrFitFunctor::GetParameterConfig(TString name, Double_t& min, Double_t& max, Int_t& point) const {
36 int paramId = -1;
37 for (int i = 0; i < fSetup.GetNParams(); i++) {
38 if (fSetup.GetParName(i) == name) {
39 paramId = i;
40 break;
41 }
42 }
43 if (paramId == -1) return kFALSE;
44 min = fSetup.GetMin(paramId);
45 max = fSetup.GetMax(paramId);
46 name = fSetup.GetParName(paramId);
47 point = fSetup.GetNPoints(paramId);
48 return kTRUE;
49 }
50
51 Int_t CorrFitFunctor::GetNParams() const { return fInfo->GetSetup().GetNParams(); }
52
53 void CorrFitFunctor::PrintInfo() {
54 Cout::Text("CorrFitFunctor", "M", kWhite);
55 fInfo->GetCf()->Print();
56 Cout::Text("Params conf", "L", kWhite);
57 Cout::Database({"Name", "Steps", "Nmin", "Nmax"});
58 for (int i = 0; i < fSetup.GetNParams(); i++) {
59 TString steps = Form("%i", fSetup.GetNSteps(i));
60 TString min = Form("%4.3f", fSetup.GetMin(i));
61 TString max = Form("%4.3f", fSetup.GetMax(i));
62 Cout::Database({fSetup.GetParName(i), steps, min, max});
63 }
64 }
65
66 Array_1<Float_t>* CorrFitFunctor::GetData(Double_t* params) {
67 Int_t entry_val = 0;
68 // Int_t prestep = 1;
69 for (int i = 0; i < fSetup.GetNParams(); i++) {
70 Double_t par = params[i];
71 Double_t dif = par - fSetup.GetMin(i);
72 Double_t stepSize = fSetup.GetStepSize(i);
73 Int_t bin = dif / stepSize;
74 if (stepSize == 0) bin = 0;
75 fPosArray[i] = bin;
76 /*Int_t step_val = bin * prestep;
77 entry_val += step_val;
78 prestep *= fSetup.GetNPoints(i);*/
79 }
80 entry_val = Hal::Std::MultiToOneDimIndex(fDimsArray, fPosArray);
81 fChain->GetEntry(entry_val);
82 return fData;
83 }
84
85 CorrFitFunctor::~CorrFitFunctor() {
86 if (fFile) { fFile->Close(); }
87 }
88} // namespace Hal