10#include "CorrFitConst.h"
11#include "CorrFitInfo.h"
12#include "CorrFitMapRebin.h"
13#include "CorrFitParamsSetup.h"
18#include "FemtoSerializationInterface.h"
20#include "PackageSql.h"
37void mergeHorizontal();
40void preparetemplate();
43void rebin(TString opt);
44int main(
int argc,
char* argv[]) {
46 Hal::Cout::PrintInfo(
"No arguments! run: hal-corrfit --help to get help", Hal::EInfo::kCriticalError);
49 TString arg1 = argv[1];
50 if (arg1 ==
"--help") {
51 std::cout <<
" Usage:" << std::endl;
52 std::cout <<
"--help print help" << std::endl;
53 std::cout <<
"0 - prepare template files and database" << std::endl;
54 std::cout <<
"1 - merge maps" << std::endl;
55 std::cout <<
"2 - compress maps" << std::endl;
56 std::cout <<
"--print - check/print info about executed jobs " << std::endl;
57 std::cout <<
"--print-bad - check/print info about executed jobs list of bad jobs is set to bad_jobs.txt" << std::endl;
58 std::cout <<
"--rebin=n rebin CF new_map.root fille will be created" << std::endl;
60 }
else if (arg1 ==
"0") {
63 }
else if (arg1 ==
"--print") {
65 }
else if (arg1 ==
"--print-bad") {
67 }
else if (arg1 ==
"1") {
70 }
else if (arg1 ==
"2") {
72 }
else if (arg1.BeginsWith(
"--rebin=")) {
75 std::cout <<
"Unknown parameter type --help" << std::endl;
81Bool_t AllJobsCompleted(Int_t jobs) {
82 for (
int i = 0; i < jobs; i++) {
83 if (Hal::CorrFitParamsSetup::TestMapFile(i) == kFALSE)
return kFALSE;
89 TFile* info_file =
new TFile(
"files/config.root");
91 bool vert = obj->IsVertical();
102 Int_t nJobs = getNFiles();
103 Bool_t all_jobs = AllJobsCompleted(nJobs);
111 for (
int i = 0; i < nJobs; i++) {
112 Bool_t fileOk = Hal::CorrFitParamsSetup::TestMapFile(i);
123 Int_t nJobs = setup.GetNJobs();
124 Bool_t all_jobs = AllJobsCompleted(nJobs);
131 std::ofstream bad_jobs;
132 bad_jobs.open(
"bad_jobs.txt");
133 bad_jobs <<
"LIST_OF_BAD_JOBS" << std::endl;
135 for (
int i = 0; i < nJobs; i++) {
136 Bool_t fileOk = Hal::CorrFitParamsSetup::TestMapFile(i);
139 bad_jobs <<
"BAD_JOB jobs/job_" << i << std::endl;
146void preparetemplate() {
148 std::ofstream xml_file;
149 xml_file.open(
"corrfit_conf.xml");
150 xml_file <<
"<CorrfitConfig>" << std::endl;
151 xml_file <<
"<Parameters>" << std::endl;
152 xml_file <<
"\t<Param name=\"R_{out}\" min=\"1\" max=\"10\" step=\"1\"></Param>" << std::endl;
153 xml_file <<
"\t<Param name=\"R_{side}\" min=\"1\" max=\"10\" step=\"1\"></Param>" << std::endl;
154 xml_file <<
"\t<Param name=\"R_{long}\" min=\"1\" max=\"10\" step=\"1\"></Param>" << std::endl;
155 xml_file <<
"</Parameters>" << std::endl;
156 xml_file <<
"<!-- full path to file with pairs-->" << std::endl;
157 xml_file <<
"<PairFile>zz.root</PairFile>" << std::endl;
158 xml_file <<
"<!-- optional part, use to configure dump pair analysis-->" << std::endl;
159 xml_file <<
"<DumpAnalysisConf>" << std::endl;
160 xml_file <<
"\t<CorrelationFunction>" << std::endl;
161 xml_file <<
"\t\t<Name>CF</Name>" << std::endl;
162 xml_file <<
"\t\t<Frame>EKinematics::kLCMS</Frame>" << std::endl;
163 xml_file <<
"\t\t<Type>Femto3DCF</Type>" << std::endl;
164 xml_file <<
"<!-- optional part, used only for spherical harmonics-->" << std::endl;
165 xml_file <<
"\t\t<L>3</L>" << std::endl;
166 xml_file <<
"\t\t<Xaxis bins=\"100\" min=\"0.0\" max=\"1.0\"></Xaxis>" << std::endl;
167 xml_file <<
"\t\t<Yaxis bins=\"100\" min=\"0.0\" max=\"1.0\"></Yaxis>" << std::endl;
168 xml_file <<
"\t\t<Zaxis bins=\"100\" min=\"0.0\" max=\"1.0\"></Zaxis>" << std::endl;
169 xml_file <<
"\t</CorrelationFunction>" << std::endl;
170 xml_file <<
"\t<FreezoutGenerator>Hal::FemtoFreezoutGeneratorLCMS</FreezoutGenerator>" << std::endl;
171 xml_file <<
"\t<SourceModel>Hal::FemtoSourceModelGauss3D</SourceModel>" << std::endl;
172 xml_file <<
"\t<CalcOptions>" << std::endl;
173 xml_file <<
"\t\t<JobMultiplyFactor>1</JobMultiplyFactor>" << std::endl;
174 xml_file <<
"\t\t<WeightMultiplyFactor>1</WeightMultiplyFactor>" << std::endl;
175 xml_file <<
"\t\t<PreprocessMultiplyFactor>1</PreprocessMultiplyFactor>" << std::endl;
176 xml_file <<
"\t\t<!-- S/B/S+B for S(signal) B (background) B+S (both)-->" << std::endl;
177 xml_file <<
"\t\t<CalcMode>S</CalcMode>" << std::endl;
178 xml_file <<
"\t\t<IgnoreSign>kTRUE</IgnoreSign>" << std::endl;
179 xml_file <<
"\t</CalcOptions>" << std::endl;
180 xml_file <<
"\t<WeightConf>" << std::endl;
181 xml_file <<
"\t\t<Type>Hal::FemtoWeightGeneratorLednicky</Type>" << std::endl;
182 xml_file <<
"\t\t<QuantumOn>kTRUE</QuantumOn>" << std::endl;
183 xml_file <<
"\t\t<StrongOn>kFALSE</StrongOn>" << std::endl;
184 xml_file <<
"\t\t<CoulombOn>kFALSE</CoulombOn>" << std::endl;
185 xml_file <<
"\t\t<PairType>211;211</PairType>" << std::endl;
186 xml_file <<
"\t</WeightConf>" << std::endl;
187 xml_file <<
"</DumpAnalysisConf>" << std::endl;
188 xml_file <<
"</CorrfitConfig>" << std::endl;
193 macro <<
"void ana(){" << std::endl;
194 macro <<
"\tTString jobEnv = gSystem->Getenv(\"JOB_ID_HAL\");" << std::endl;
195 macro <<
"\tInt_t job_index = jobEnv.Atoi();" << std::endl;
196 macro <<
"\tHal::CorrFitDumpedPairAna *task = new Hal::CorrFitDumpedPairAna(job_index);" << std::endl;
197 macro <<
"\tif(task->Init()==kFALSE) return;" << std::endl;
198 macro <<
"\ttask->Run();" << std::endl;
199 macro <<
"\ttask->Finish();" << std::endl;
200 macro <<
"}" << std::endl;
203 gSystem->mkdir(
"jobs");
204 gSystem->mkdir(
"files");
207void rebin(TString rebin) {
209 TString opt = Hal::Std::RemoveString(rebin,
"--rebin=");
210 Int_t Nrebin = opt.Atoi();
212 std::cout <<
"invalid number of bins " << std::endl;
216 rebinner->
Compress(
"merged_rebined_map.root");
220 TFile* info_file =
new TFile(
"files/config.root");
223 int nFiles = setup.GetNJobs();
224 if (obj->IsVertical()) { nFiles = obj->GetMainBins(); }
227void mergeHorizontal() {
228 TFile* info_file =
new TFile(
"files/config.root");
231 int nJobs = setup.GetNJobs();
232 std::cout <<
"Merging vertical CF's" << nJobs << std::endl;
233 if (!AllJobsCompleted(nJobs)) {
238 if (!(ans ==
"y" || ans ==
"Y")) {
return; }
240 TFile* file =
new TFile(
"merged_map.root",
"recreate");
241 TChain* chain =
new TChain(
"map",
"");
243 for (
int i = 0; i < nJobs; i++) {
244 chain->AddFile(Form(
"files/corrfit_map_%i.root", i));
247 TTree* tree =
new TTree(
"map",
"");
250 chain->SetBranchAddress(
"data", &Data_in);
251 tree->Branch(
"data", &Data_out);
252 int entries = chain->GetEntries() / nJobs;
255 int single_size = Data_in->
GetSize();
256 for (
int i = 0; i < nJobs; i++) {
258 for (
int k = 0; k < single_size; k++) {
259 Data_out->
Set(k, Data_in->
Get(k));
269void mergeVertical() {
270 TFile* info_file =
new TFile(
"files/config.root");
272 bool vert = obj->IsVertical();
273 auto CF = obj->GetCf()->Clone();
274 std::cout <<
"CF " << CF->ClassName() << std::endl;
275 auto cfType = Hal::Femto::GetCFType(CF);
276 int nSlices = Hal::Femto::GetNSlices(CF);
280 int n_params = setup.GetNJobs();
281 if (!AllJobsCompleted(nSlices)) {
286 if (!(ans ==
"y" || ans ==
"Y")) {
return; }
289 TFile* file =
new TFile(
"merged_map.root",
"recreate");
290 TChain* chain =
new TChain(
"map",
"");
292 for (
int i = 0; i < nSlices; i++) {
293 chain->AddFile(Form(
"files/corrfit_map_%i.root", i));
295 std::cout <<
"Merging vertical CF's" << nSlices <<
" " << n_params << std::endl;
296 auto* tree =
new TTree(
"map",
"");
299 chain->SetBranchAddress(
"data", &Data_in);
300 tree->Branch(
"data", &Data_out);
302 const int slice_size = Data_in->
GetSize();
303 std::cout <<
"CHECK SIZE " << nSlices * n_params <<
" " << chain->GetEntries() << std::endl;
304 std::cout << nSlices <<
" " << n_params << std::endl;
306 for (
int iPar = 0; iPar < n_params; iPar++) {
307 for (
int iBin = 0; iBin < nSlices; iBin++) {
308 chain->GetEntry(iPar + n_params * iBin);
309 for (
int iS = 0; iS < slice_size; iS++) {
310 Data_out->
Set(iBin * slice_size + iS, Data_in->
Get(iS));
323 TFile* info_file =
new TFile(
"files/config.root");
326 auto cfType = Hal::Femto::GetCFType(CF);
327 TFile* fileIn =
new TFile(
"merged_map.root");
328 TTree* treeIn = (TTree*) fileIn->Get(
"map");
330 TFile* fileOut =
new TFile(
"compressed_map.root",
"recreate");
331 TTree* treeOut =
new TTree(
"map",
"");
334 treeIn->SetBranchAddress(
"data", &Data_in);
335 treeOut->Branch(
"data", &Data_out);
337 std::cout << interfaceFrom << std::endl;
338 std::cout << interfaceFrom->ClassName() << std::endl;
339 interfaceFrom->BindCFs(CF);
340 interfaceFrom->BindArray(Data_in);
341 interfaceFrom->SetOption(Hal::FemtoSerializationInterface::EOption::kFull);
342 interfaceFrom->Init();
344 interfaceTo->BindCFs(CF);
345 interfaceTo->BindArray(Data_out);
346 interfaceTo->SetOption(Hal::FemtoSerializationInterface::EOption::kSimple);
348 const int entries = treeIn->GetEntries();
351 for (
int i = 0; i < entries; i++) {
353 interfaceFrom->Deserialize();
354 if (i == 0) std::cout <<
"ARSIZE " << Data_in->
GetSize() <<
" " << Data_out->
GetSize() << std::endl;
357 sh->RecalculateCF(-1, kTRUE);
368 interfaceTo->Serialize();
374 delete interfaceFrom;
void Set(Int_t index, T val)
void MakeBigger(Int_t new_dim)
Bool_t Compress(TString outFile)
static void Text(TString text, TString option="L", Color_t color=-1)
static void PrintInfo(TString text, Hal::EInfo status)
static void FailSucced(TString value, TString flag, Color_t color)