Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
CorrFitParamsSetup.cxx
1/*
2 * CorrFitDatabase.cxx
3 *
4 * Created on: 22 sty 2020
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "CorrFitParamsSetup.h"
11
12
13#include <TApplication.h>
14#include <TChain.h>
15#include <TClass.h>
16#include <TFile.h>
17#include <TMath.h>
18#include <TSQLResult.h>
19#include <TSQLRow.h>
20#include <TSQLServer.h>
21#include <TSQLStatement.h>
22#include <TSystem.h>
23#include <fstream>
24#include <iostream>
25
26#include "CorrFitDumpedPairAna.h"
27#include "Cout.h"
28#include "FemtoCorrFuncSimple.h"
29#include "FemtoFreezoutGenerator.h"
30#include "FemtoPairKinematics.h"
31#include "FemtoSourceModel.h"
32#include "FemtoWeightGenerator.h"
33#include "FemtoWeightGeneratorLednicky.h"
34#include "XMLNode.h"
35
36//==================================================
37namespace Hal {
38 CorrFitParamsSetup::CorrFitParamsSetup(Int_t params) : fSize(params) {
39 fMin.MakeBigger(fSize);
40 fMax.MakeBigger(fSize);
41 fNpoints.MakeBigger(fSize);
42 fNames = new TString[fSize];
43 }
44
45 CorrFitParamsSetup::CorrFitParamsSetup(TString xmlFile) {
46 XMLFile file(xmlFile);
47 XMLNode* root = file.GetRootNode();
48 XMLNode* parameters = root->GetChild("Parameters");
49 fSize = parameters->GetNChildren();
50 fMin.MakeBigger(fSize);
51 fMax.MakeBigger(fSize);
52 fNpoints.MakeBigger(fSize);
53 fNames = new TString[fSize];
54 for (int i = 0; i < fSize; i++) {
55 XMLNode* par = parameters->GetChild(i);
56 fMin[i] = par->GetAttrib("min")->GetValue().Atof();
57 fMax[i] = par->GetAttrib("max")->GetValue().Atof();
58 double step = par->GetAttrib("step")->GetValue().Atof();
59 fNpoints[i] = TMath::Ceil((fMax[i] - fMin[i]) / double(step)) + 1;
60 fMax[i] = fMin[i] + double(fNpoints[i] - 1) * step;
61 fNames[i] = par->GetAttrib("name")->GetValue();
62 }
63 }
64
65 Int_t CorrFitParamsSetup::GetNJobs() const {
66 Int_t jobs = 1;
67 for (int i = 0; i < GetNParams(); i++) {
68 jobs = jobs * GetNPoints(i);
69 }
70 return jobs;
71 }
72
73 std::vector<int> CorrFitParamsSetup::GetDimensions() const {
74 std::vector<int> dims(fSize);
75 for (int i = 0; i < fSize; i++) {
76 dims[i] = fNpoints.Get(i);
77 }
78 return dims;
79 }
80
81 void CorrFitParamsSetup::SetParameter(Int_t par_id, Double_t min, Double_t max, Int_t points, TString name) {
82 if (par_id >= fSize) {
83 Int_t old_size = fSize;
84 fSize = par_id + 1;
85 fMin.MakeBigger(fSize);
86 fMax.MakeBigger(fSize);
87 fNpoints.MakeBigger(fSize);
88 TString* temp = fNames;
89 fNames = new TString[fSize];
90 for (int i = 0; i < old_size; i++)
91 fNames[i] = temp[i];
92 delete[] temp;
93 }
94 fMin[par_id] = min;
95 fMax[par_id] = max;
96 fNpoints[par_id] = points;
97 fNames[par_id] = name;
98 }
99
100 CorrFitParamsSetup::CorrFitParamsSetup(const CorrFitParamsSetup& other) :
101 TObject(other), fSize(other.fSize), fMin(other.fMin), fMax(other.fMax), fNpoints(other.fNpoints) {
102 fNames = new TString[fSize];
103 for (int i = 0; i < fSize; i++)
104 fNames[i] = other.fNames[i];
105 }
106
107 CorrFitParamsSetup& CorrFitParamsSetup::operator=(const CorrFitParamsSetup& rhs) {
108 if (&rhs == this) return *this;
109 fSize = rhs.fSize;
110 fMin = rhs.fMin;
111 fMax = rhs.fMax;
112 fNpoints = rhs.fNpoints;
113 if (fNames) delete[] fNames;
114 fNames = new TString[fSize];
115 for (int i = 0; i < fSize; i++) {
116 fNames[i] = rhs.fNames[i];
117 }
118 return *this;
119 }
120
121 Double_t CorrFitParamsSetup::GetStepSize(Int_t par_id) const {
122 Double_t steps = fNpoints.Get(par_id) - 1.0;
123 if (steps == 0) return 0;
124 return (fMax.Get(par_id) - fMin.Get(par_id)) / steps;
125 }
126
127 void CorrFitParamsSetup::Print(Option_t* /*opt*/) const {
128 Cout::Text("CorrFitDbParamsSetup", "L", kWhite);
129 for (int i = 0; i < GetNParams(); i++) {
130 TString name = Form("%s min: %4.2f max: %4.2f steps %i", GetParName(i).Data(), GetMin(i), GetMax(i), GetNSteps(i));
131 Cout::Text(name, "L", kWhite);
132 }
133 }
134
135 Bool_t CorrFitParamsSetup::TestMapFile(Int_t jobId) {
136 TString name = Form("files/corrfit_map_%i.root", jobId);
137 std::ifstream testFile;
138 testFile.open(name);
139 if (!testFile.good()) {
140 testFile.close();
141 return kFALSE;
142 }
143 testFile.close();
144 TFile* f = new TFile(name);
145 if (f->IsZombie()) {
146 delete f;
147 gSystem->Exec(Form("rm %s", name.Data()));
148 return kFALSE;
149 }
150 TTree* t = (TTree*) f->Get("map");
151 if (t == nullptr) {
152 delete f;
153 gSystem->Exec(Form("rm %s", name.Data()));
154 return kFALSE;
155 }
156 delete f;
157 return kTRUE;
158 }
159
160 Int_t CorrFitParamsSetup::GetParId(TString name) const {
161 for (int i = 0; i < fSize; i++) {
162 if (fNames[i] == name) return i;
163 }
164 return -1;
165 }
166
167} // namespace Hal