10#include "CorrFitDumpedPairAna.h"
13#include <TApplication.h>
16#include <TClonesArray.h>
17#include <TCollection.h>
18#include <TDirectory.h>
19#include <TDirectoryFile.h>
32#include "CorrFitInfo.h"
33#include "CorrFitParamsSetup.h"
37#include "FemtoConst.h"
38#include "FemtoCorrFunc.h"
39#include "FemtoCorrFuncSimple.h"
40#include "FemtoDumpPairAna.h"
41#include "FemtoFreezoutGenerator.h"
42#include "FemtoMiniPair.h"
45#include "FemtoSerializationInterface.h"
46#include "FemtoSourceModel.h"
47#include "FemtoWeightGenerator.h"
48#include "FemtoWeightGeneratorLednicky.h"
52 CorrFitDumpedPairAna::CorrFitDumpedPairAna(Int_t jobid, Int_t maps_perAna) :
53 TObject(), fPairFile(
""), fJobId(jobid), fMultiplyJobs(maps_perAna), fMode(eDumpCalcMode::kSignalPairs) {}
56 if (fTempCF)
delete fTempCF;
61 if (fWeight)
delete fWeight;
65 Bool_t CorrFitDumpedPairAna::Init() {
66 if (!ConfigureFromXML()) {
70 Bool_t fileOk = CorrFitParamsSetup::TestMapFile(fJobId * fMultiplyJobs);
76 if (!ConfigureInput()) {
88 if (fTempCF->GetEntries() > 1) {
100 DividedHisto1D* dummy = fTempCF->GetCF(0);
101 Femto::EKinematics kinem = Femto::EKinematics::kLCMS;
102 if (dummy->GetLabelsNo() > 0) {
103 TString label = dummy->GetLabel(0);
104 kinem = Femto::LabelToKinematics(label);
106 fPair = Femto::MakePair(kinem, fImgMom);
109 if (dummy->InheritsFrom(
"Hal::FemtoSHCF")) {
110 Cout::PrintInfo(
"Cannot ignore sign with SH correlation function!", EInfo::kError);
118 void CorrFitDumpedPairAna::Run(Int_t events) {
123 nEvents = fTree->GetEntries();
126 case eDumpCalcMode::kSignalBackgroundPairs: {
127 Int_t step = nEvents / 100;
128 for (
int iEvent = 0; iEvent < nEvents; iEvent++) {
129 fTree->GetEntry(iEvent);
130 if (iEvent % step == 0) { Cout::ProgressBar(iEvent, nEvents); }
131 RunSignalBackgroundPair();
132 if (fPairThreshold > 0 && fPairThreshold < fPairsProcessed)
break;
136 case eDumpCalcMode::kSignalPairs: {
138 Int_t step = nEvents / 100;
139 for (
int iEvent = 0; iEvent < nEvents; iEvent++) {
140 fTree->GetEntry(iEvent);
141 if (iEvent % step == 0) { Cout::ProgressBar(iEvent, nEvents); }
143 if (fPairThreshold > 0 && fPairThreshold < fPairsProcessed)
break;
146 case eDumpCalcMode::kBackgroundPairsOnly: {
147 Int_t step = nEvents / 100;
148 for (
int iEvent = 0; iEvent < nEvents; iEvent++) {
149 fTree->GetEntry(iEvent);
150 if (iEvent % step == 0) { Cout::ProgressBar(iEvent, nEvents); }
152 if (fPairThreshold > 0 && fPairThreshold < fPairsProcessed)
break;
158 Bool_t CorrFitDumpedPairAna::SaveAsRawArray(TObject* cf, Int_t step) {
159 TFile* file =
new TFile(Form(
"files/corrfit_map_%i.root", GetSimStepNo() + step),
"recreate");
162 serialization->BindCFs(cf);
164 serialization->BindArray(Data);
165 serialization->Init();
166 serialization->Serialize();
167 if (!Data)
return kFALSE;
168 TTree* tree =
new TTree(
"map",
"map");
169 tree->Branch(
"data", &Data);
173 delete serialization;
177 Bool_t CorrFitDumpedPairAna::ConfigureInput() {
178 if (fPairFile.EndsWith(
".root")) {
179 return ConfigureRootInput();
181 ConfigureListInput();
186 Bool_t CorrFitDumpedPairAna::ConfigureFromXML() {
187 auto printErr = [](TString str) {
191 XMLFile file(
"corrfit_conf.xml");
192 CorrFitParamsSetup setup(
"corrfit_conf.xml");
193 fTotalNumberOfPoints = 1;
194 int parNo = setup.GetNParams();
195 for (
int i = 0; i < parNo; i++) {
196 fTotalNumberOfPoints = fTotalNumberOfPoints * setup.GetNPoints(i);
198 XMLNode* root = file.GetRootNode();
199 fPairFile = root->GetChild(
"PairFile")->GetValue();
200 XMLNode* parameters = root->GetChild(
"Parameters");
201 XMLNode* dumpAna = root->GetChild(
"DumpAnalysisConf");
202 if (!dumpAna)
return printErr(
"DumpAnalysisConf");
204 if (!parameters)
return printErr(
"Parameters");
206 XMLNode* freezXml = dumpAna->GetChild(
"FreezoutGenerator");
207 XMLNode* sourceXml = dumpAna->GetChild(
"SourceModel");
208 if (!freezXml)
return printErr(
"FreezoutGenerator");
210 if (!sourceXml)
return printErr(
"SourceModel");
211 TClass* freezoutClass = TClass::GetClass(freezXml->GetValue(), 1, 0);
212 TClass* sourceClass = TClass::GetClass(sourceXml->GetValue(), 1, 0);
213 FemtoFreezoutGenerator* generator =
static_cast<FemtoFreezoutGenerator*
>(freezoutClass->New());
214 FemtoSourceModel* source =
static_cast<FemtoSourceModel*
>(sourceClass->New());
215 if (source && generator) {
216 generator->SetSourceModel(*source);
217 SetGenerator(*generator);
222 if (source)
delete source;
223 if (generator)
delete generator;
224 XMLNode* calcOpts = dumpAna->GetChild(
"CalcOptions");
226 XMLNode* pairCut = calcOpts->GetChild(
"NoPairCut");
227 if (pairCut) { fPairThreshold = pairCut->GetValue().Atoi(); }
230 XMLNode* multiJobs = calcOpts->GetChild(
"JobMultiplyFactor");
232 if (multiJobs->GetValue().Length() > 0 && fMultiplyJobs <= 0) { fMultiplyJobs = multiJobs->GetValue().Atoi(); }
234 if (fMultiplyJobs <= 0) fMultiplyJobs = 1;
235 std::vector<int> dims = setup.GetDimensions();
236 if (!InitGenerators(dims, parameters, setup)) {
237 Cout::PrintInfo(
"Cannot init generators !", EInfo::kError);
241 XMLNode* multiplyXmlWeight = calcOpts->GetChild(
"WeightMultiplyFactor");
242 if (multiplyXmlWeight) SetMultiplyFactorWeight(multiplyXmlWeight->GetValue().Atoi());
244 XMLNode* multiplyXmlPreproc = calcOpts->GetChild(
"PreprocessMultiplyFactor");
245 if (multiplyXmlPreproc) SetMultiplyFactorPreprocess(multiplyXmlPreproc->GetValue().Atoi());
247 XMLNode* calcXml = calcOpts->GetChild(
"CalcMode");
249 TString opt = calcXml->GetValue();
250 if (opt ==
"S") fMode = eDumpCalcMode::kSignalPairs;
251 if (opt ==
"S+B") fMode = eDumpCalcMode::kSignalBackgroundPairs;
252 if (opt ==
"B") fMode = eDumpCalcMode::kBackgroundPairsOnly;
254 XMLNode* ignore = calcOpts->GetChild(
"IgnoreSign");
256 if (ignore->GetValue() ==
"kTRUE") this->IgnoreSign();
260 XMLNode* weight = dumpAna->GetChild(
"WeightConf");
262 auto w = Hal::Femto::GetWeightGeneratorFromXLM(weight);
264 Cout::PrintInfo(
"Problem with weight configuration !", EInfo::kError);
267 this->SetWeightGenerator(*w);
270 XMLNode* cfXml = dumpAna->GetChild(
"CorrelationFunction");
271 DividedHisto1D* cf = Femto::GetHistoFromXML(cfXml);
273 FemtoCorrFuncSimple corrFunc(*cf);
275 this->SetCorrFunc(corrFunc);
276 if (!InitCFs()) { Cout::PrintInfo(
"Cannot init CF !", EInfo::kError); }
278 Cout::PrintInfo(
"Cannot find CF in XML !", EInfo::kError);
284 CorrFitDumpedPairAna::~CorrFitDumpedPairAna() {
285 if (fTempCF)
delete fTempCF;
286 if (fTempGenerator)
delete fTempGenerator;
287 for (
auto i : fGenerator) {
292 void CorrFitDumpedPairAna::Print(Option_t* )
const {
293 Cout::Text(
"CorrFitDumpedPairAna Info",
"M");
294 Cout::Text(Form(
"JobID: %i", fJobId),
"L");
295 Cout::Text(Form(
"Multiply factor jobs: %i", fMultiplyJobs),
"L");
296 Cout::Text(Form(
"Multiply factor weight: %i", fMultiplyWeight),
"L");
297 Cout::Text(Form(
"Multiply factor preprocess: %i", fMultiplyPreprocess),
"L");
298 Cout::Text(Form(
"IgnoreSign: %i", fIgnoreSing),
"L");
299 Cout::Text(Form(
"Pair file: %s", fPairFile.Data()),
"L");
301 case eDumpCalcMode::kBackgroundPairsOnly: {
302 Cout::Text(
"Use only background branch",
"L");
304 case eDumpCalcMode::kSignalBackgroundPairs: {
305 Cout::Text(
"Use signal & background branches",
"L");
307 case eDumpCalcMode::kSignalPairs: {
308 Cout::Text(
"Use only signal branch",
"L");
311 Cout::Text(
"CF Info",
"M");
312 if (fTempCF) fTempCF->Print();
313 Cout::Text(
"Generator Info",
"M");
315 for (
auto& gen : fGenerator) {
316 if (gen) gen->Print();
318 Cout::Text(
"Weight Info",
"M");
319 if (fWeight) fWeight->Print();
322 void CorrFitDumpedPairAna::ConnectToSignal(
const std::vector<TString>& branches) {
323 for (
auto name : branches) {
324 fUsedBranches.push_back(name);
325 TClonesArray* array =
new TClonesArray(
"Hal::FemtoMicroPair");
326 fTree->SetBranchAddress(name, &array);
327 fSignalClones.push_back(array);
331 void CorrFitDumpedPairAna::ConnectToBackground(
const std::vector<TString>& branches) {
332 for (
auto name : branches) {
333 fUsedBranches.push_back(name);
334 TClonesArray* array =
new TClonesArray(
"Hal::FemtoMicroPair");
335 fTree->SetBranchAddress(name, &array);
336 fBackgroundClones.push_back(array);
340 void CorrFitDumpedPairAna::LockUnusedBranches() {
341 auto list = fTree->GetListOfBranches();
342 for (
int i = 0; i < list->GetEntries(); i++) {
343 auto branch = (TBranch*) list->At(i);
345 TString brName = branch->GetName();
346 for (
auto name : fUsedBranches)
347 if (name == brName) {
351 if (lock) fTree->SetBranchStatus(brName, 0);
355 Bool_t CorrFitDumpedPairAna::ConfigureRootInput() {
356 fFile =
new TFile(fPairFile);
357 fGrouping =
dynamic_cast<CorrFitMapGroupConfig*
>(fFile->Get(
"HalInfo/CorrFitMapGroup"));
362 TString treeName = FindTreeName(fPairFile);
363 fTree =
new TChain(treeName);
364 fTree->AddFile(fPairFile);
366 if (treeName.Length() == 0)
return kFALSE;
367 Bool_t res = ConnectToData();
368 LockUnusedBranches();
372 Bool_t CorrFitDumpedPairAna::ConfigureListInput() {
373 std::vector<TString> filelist;
374 if (fPairFile.EndsWith(
"/")) {
375 filelist = Hal::Std::GetListOfFiles(fPairFile,
"root", kTRUE, kFALSE);
377 filelist = Hal::Std::GetLinesFromFile(fPairFile, kTRUE);
379 if (filelist.size() < 1)
return kFALSE;
380 fFile =
new TFile(filelist[0]);
381 fGrouping =
dynamic_cast<CorrFitMapGroupConfig*
>(fFile->Get(
"HalInfo/CorrFitMapGroup"));
386 TString treeName = FindTreeName(filelist[0]);
387 fTree =
new TChain(treeName);
388 for (
auto file : filelist) {
389 fTree->AddFile(file);
394 TString CorrFitDumpedPairAna::FindTreeName(TString name)
const {
395 TFile* f =
new TFile(name);
396 TList* keys = f->GetListOfKeys();
398 for (
int i = 0; i < keys->GetEntries(); i++) {
399 TKey* key = (TKey*) keys->At(i);
400 TObject* obj = f->Get(key->GetName());
401 if (obj->InheritsFrom(
"TTree")) {
402 treeName = key->GetName();
static void PrintInfo(TString text, Hal::EInfo status)
virtual FemtoWeightGenerator * MakeCopy() const