BmnRoot 26.10.0-233-gb9bbe585
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnFunctionSet.h
Go to the documentation of this file.
1#ifndef BMNFUNCTIONSET_H
2#define BMNFUNCTIONSET_H 1
3
4// FairRoot
5#include "FairField.h"
6#include "FairPrimaryGenerator.h"
7
8// ROOT
9#include "TDatime.h"
10#include "TString.h"
11#include "TSystem.h"
12#include "TTimeStamp.h"
13
14#include <TFile.h>
15
16// STL
17#include <chrono>
18#include <string>
19#include <vector>
20
21using SysClock = std::chrono::system_clock;
22using SysPoint = std::chrono::time_point<SysClock>;
23
24/** Class with static common functions to simplify experiment code **/
26{
27 public:
28 // check whether path is a directory
29 static bool isDirectory(TString path);
30 // check whether file exists: 1 - exists, 0 - not exists, -1 - exists but cannot access with the mode (default:
31 // kFileExists) fileName: file path; iVerbose: 0 - no output, 1 - print errors; mode: check for 'kFileExists', or
32 // has 'kExecutePermission', 'kWritePermission' or 'kReadPermission'
33 static int CheckFileExist(TString& fileName, int iVerbose = 0, EAccessMode mode = kFileExists);
34 // check whether directory exists: 1 - exists, 0 - not exists, -1 - exists but cannot access with the mode (default:
35 // kFileExists)
36 static int CheckDirectoryExist(TString& fileName, int iVerbose = 0, EAccessMode mode = kFileExists);
37 // create directory tree for the file name if not exists: 1 - exists, 0 - created
38 // error codes: -1 - exists but cannot access with the mode (default: kWritePermission), -2 - cannot be created, -3
39 // - empty file name
40 static int CreateDirectoryTree(TString& fileName, int iVerbose = 0, EAccessMode mode = kWritePermission);
41 // get the list of input ROOT files for the given input file, which can be a ROOT file with data, a ROOT file with
42 // a TChain object or a text file (extension is not '.root') with a list of ROOT files:
43 // inputFileName: path to the input file; fileList: returns the list of ROOT files with expanded paths
44 // return value: number of files in the list, < 0 - error codes
45 static int GetInputFileList(TString inputFileName, std::vector<TString>& fileList);
46
47 // define whether ROOT file contains simulation data: 1 - true, 0 - false (experimental data), <0 - some errors
48 // occured if filename is not set then the function checks the current processing
49 static int isSimulationFile(TString fileName = "");
50 // method_number: 0 - find FairRtdbRun with period number name; 1 - use "FileHeader" (FairFileHeader)
51 static int GetPeriodNumber(TFile* root_file, int method_number = 0);
52
53 // parsing file name to define beam, target and energy of the run
54 // the file name is parsed with the '_' separator, if it does not fit then with the '.' separator
55 // file_name: name of the file to parse
56 // result (beam, target, energy (GeV)) returns via links, energy is < 0 in case of errors
57 // return value: 0 - success, < 0 - error codes
58 static Int_t ParseFileName(const TString& file_name, TString& beam, TString& target, Double_t& energy);
59 // define beam and energy of the run by FairIonGenerator added to the primary generator (e.g. ION generator in
60 // run_sim_bmn.C): the generated ion is considered as the beam
61 // result (beam, energy - kinetic energy per nucleon (GeV)) returns via links, energy is < 0 in case of errors
62 // return value: 0 - success, < 0 - error codes
63 static Int_t GetBeamByIonGenerator(FairPrimaryGenerator* primary_generator, TString& beam, Double_t& energy);
64
65 // get magnetic field value (mV) for the given beam and its energy (e.g. parsed by ParseFileName)
66 // beam: beam particle name; energy: beam energy (GeV)
67 // return value: magnetic field value (mV), < 0 - in case of errors
68 static double GetMagneticFieldByEnergy(const TString& beam, double energy);
69
70 // get the correction factor for the magnetic field map scale calculated as 'field voltage / map voltage'
71 // energy: beam energy (GeV)
72 // return value: correction factor to multiply the field map scale by, 1 - for the energies without correction
73 static double GetFieldScaleCorrection(double energy);
74
75 // set the scale of the magnetic field of any type, so the code does not depend on whether the field
76 // of the run is a field map or a constant field. The zero scale gives the zero field (the magnet is off).
77 // field: the magnetic field; scale: 'field voltage of the run / reference voltage of the field'
78 // return value: true - success, false - no field or the field type is not supported
79 static bool SetFieldScale(FairField* field, double scale);
80
83 static void PrintTimePoint(SysPoint p);
84 static std::string TimePoint2String(SysPoint p);
85 static SysPoint TDatime2GMT(TDatime& tdatime, Int_t timezoneOffsetHours = 0);
86
87 private:
90
91 static TString JoinKeys(const std::vector<std::pair<TString, TString>>& dict);
92 // parsing file name with the given separator (used by ParseFileName)
93 // separator: symbol to split the file name into tokens
94 // return value: 0 - success, < 0 - error codes
95 static Int_t ParseFileNameBySeparator(const TString& file_name,
96 const TString& separator,
97 TString& beam,
98 TString& target,
99 Double_t& energy);
100
102};
103
104#endif
std::chrono::system_clock SysClock
std::chrono::time_point< SysClock > SysPoint
int Int_t
double Double_t
#define ClassDef(name, id)
EAccessMode
kFileExists
kWritePermission
Class with static common functions to simplify experiment code.
static double GetMagneticFieldByEnergy(const TString &beam, double energy)
static void PrintTimePoint(SysPoint p)
static int CreateDirectoryTree(TString &fileName, int iVerbose=0, EAccessMode mode=kWritePermission)
static SysPoint TDatime2GMT(TDatime &tdatime, Int_t timezoneOffsetHours=0)
static int CheckDirectoryExist(TString &fileName, int iVerbose=0, EAccessMode mode=kFileExists)
static double GetFieldScaleCorrection(double energy)
static TString JoinKeys(const std::vector< std::pair< TString, TString > > &dict)
static Int_t ParseFileName(const TString &file_name, TString &beam, TString &target, Double_t &energy)
static std::string TimePoint2String(SysPoint p)
static bool SetFieldScale(FairField *field, double scale)
static int isSimulationFile(TString fileName="")
static Int_t GetBeamByIonGenerator(FairPrimaryGenerator *primary_generator, TString &beam, Double_t &energy)
static SysPoint TimeStamp2TP(TTimeStamp p)
static bool isDirectory(TString path)
static int GetInputFileList(TString inputFileName, std::vector< TString > &fileList)
static TTimeStamp TimePoint2TS(SysPoint p)
static int GetPeriodNumber(TFile *root_file, int method_number=0)
static int CheckFileExist(TString &fileName, int iVerbose=0, EAccessMode mode=kFileExists)
static Int_t ParseFileNameBySeparator(const TString &file_name, const TString &separator, TString &beam, TString &target, Double_t &energy)