38 #include "RtypesCore.h" 43 #include "TDirectory.h" 44 #include "TGraphErrors.h" 60 std::pair<std::string, std::string> rsplit
63 auto iSep = s.rfind(sep);
64 if (iSep == std::string::npos)
68 { s.substr(0, iSep), s.substr(iSep + sep.length(), s.length()) };
81 std::string::size_type iSuffix = std::string::npos;
83 iSuffix = path.rfind(suffix, iSuffix);
84 if (iSuffix == std::string::npos)
return nullptr;
87 auto iAfter = iSuffix + suffix.length();
88 if ((iAfter < path.length())
89 && (path[iAfter] !=
'/')
90 && (path[iAfter] !=
':')
93 if (iSuffix == 0)
return nullptr;
98 filePath = path.substr(0U, iAfter);
99 if (iAfter < path.length())
100 rootDirPath = path.substr(iAfter + 1, path.length());
107 std::tie(fileDir, fileName) = rsplit(filePath,
"/");
109 std::cout <<
"Writing to output file: '" << filePath <<
"'";
110 if (!rootDirPath.empty())
111 std::cout <<
" (directory: '" << rootDirPath <<
"')";
117 if (!fileDir.empty()) gSystem->mkdir(fileDir.c_str(),
true);
121 auto pFile = std::make_unique<TFile>(filePath.c_str(),
"UPDATE");
123 if (pFile->IsZombie() || !pFile->IsOpen())
return nullptr;
124 if (rootDirPath.empty())
return pFile.release();
126 if (!pFile->mkdir(rootDirPath.c_str()))
return nullptr;
128 TDirectory* pOutputDir = pFile->GetDirectory(rootDirPath.c_str());
129 if (!pOutputDir)
return nullptr;
138 void WriteCalibrationObject
141 if (!pObj)
throw std::runtime_error(
"Can't write " +
title);
143 auto written = pObj->Write();
145 throw std::runtime_error(
"Writing of " +
title +
" " 146 + pObj->IsA()->GetName() +
"[\"" + pObj->GetName() +
"\"] failed!");
148 std::cout <<
"Written " <<
title <<
" \"" << pObj->GetName()
149 <<
"\" (" << pObj->IsA()->GetName() <<
") [" << written <<
" bytes]" 157 constexpr Int_t NPoints = 21;
158 constexpr Double_t MinE = 0.0;
159 constexpr Double_t MaxE = 2.0;
161 constexpr Double_t ERange = MaxE - MinE;
162 constexpr Double_t BinWidth = ERange / (NPoints - 1);
165 TGraphErrors* pGCorr =
new TGraphErrors(NPoints);
166 pGCorr->SetNameTitle(
168 "#pi^{0} energy calibration" 169 ";reconstructed energy [ GeV ]" 173 for (Int_t i = 0; i < NPoints; ++i) {
174 Double_t
const E = MinE + BinWidth * i;
177 = 1.1 - 0.2 * std::sin((E - MinE) / ERange * TMath::Pi() * 2.);
179 pGCorr->SetPoint(i, E, f);
181 pGCorr->SetPointError(i, BinWidth / 2., f * 0.1);
192 constexpr Int_t NPoints = 21;
193 constexpr Double_t MinE = 0.0;
194 constexpr Double_t MaxE = 2.0;
196 constexpr Double_t ERange = MaxE - MinE;
197 constexpr Double_t BinWidth = ERange / (NPoints - 1);
200 TGraphErrors* pGCorr =
new TGraphErrors(NPoints);
201 pGCorr->SetNameTitle(
203 "#gamma energy calibration" 204 ";reconstructed energy [ GeV ]" 208 for (Int_t i = 0; i < NPoints; ++i) {
209 Double_t
const E = MinE + BinWidth * i;
212 = 1.1 + 0.1 * std::sin((E - MinE) / ERange * TMath::Pi() / 2.);
214 pGCorr->SetPoint(i, E, f);
216 pGCorr->SetPointError(i, BinWidth / 2., f * 0.1);
227 constexpr Int_t NPoints = 21;
228 constexpr Double_t MinE = 0.0;
229 constexpr Double_t MaxE = 2.0;
231 constexpr Double_t ERange = MaxE - MinE;
232 constexpr Double_t BinWidth = ERange / (NPoints - 1);
235 TGraphErrors* pGCorr =
new TGraphErrors(NPoints);
236 pGCorr->SetNameTitle(
238 "e^{#pm} energy calibration" 239 ";reconstructed energy [ GeV ]" 243 for (Int_t i = 0; i < NPoints; ++i) {
244 Double_t
const E = MinE + BinWidth * i;
247 = 1.15 + 0.1 * std::sin((E - MinE) / ERange * TMath::Pi());
249 pGCorr->SetPoint(i, E, f);
251 pGCorr->SetPointError(i, BinWidth / 2., f * 0.1);
262 constexpr Int_t NPoints = 21;
263 constexpr Double_t MinE = 0.0;
264 constexpr Double_t MaxE = 2.0;
266 constexpr Double_t ERange = MaxE - MinE;
267 constexpr Double_t BinWidth = ERange / (NPoints - 1);
270 TGraphErrors* pGCorr =
new TGraphErrors(NPoints);
271 pGCorr->SetNameTitle(
273 "#mu^{#pm} energy calibration" 274 ";reconstructed energy [ GeV ]" 278 for (Int_t i = 0; i < NPoints; ++i) {
279 Double_t
const E = MinE + BinWidth * i;
282 = 1.05 + 0.02 * std::sin((E - MinE) / ERange * TMath::Pi() * 1.5);
284 pGCorr->SetPoint(i, E, f);
286 pGCorr->SetPointError(i, BinWidth / 2., f * 0.1);
297 constexpr Double_t MinE = 0.0;
298 constexpr Double_t MaxE = 2.2;
300 constexpr Double_t ERange = MaxE - MinE;
302 TGraphErrors* pGCorr =
new TGraphErrors(1);
303 pGCorr->SetNameTitle(
305 "Generic energy calibration" 306 ";reconstructed energy [ GeV ]" 311 Double_t
const E = MinE + ERange / 2.;
312 Double_t
const f = 1.10;
314 pGCorr->SetPoint(0, E, f);
316 pGCorr->SetPointError(0, ERange / 2., f * 0.1);
334 TDirectory* pOutputDir = CreateROOTdir(outputPath);
336 std::cerr <<
"Can't create ROOT directory '" << outputPath <<
"'" 340 TFile* pOutputFile = pOutputDir->GetFile();
347 WriteCalibrationObject
348 (CreateNeutralPionCalibration(),
"pion calibration");
349 WriteCalibrationObject(CreatePhotonCalibration(),
"photon calibration");
350 WriteCalibrationObject
351 (CreateElectronCalibration(),
"electron calibration");
352 WriteCalibrationObject(CreateMuonCalibration(),
"muon calibration");
353 WriteCalibrationObject(CreateGeneralCalibration(),
"generic calibration");
355 catch (std::runtime_error
const&
e) {
356 std::cerr <<
"An error occurred: " << e.what() <<
std::endl;
364 pOutputFile->Write();
int CreateTestShowerCalibrationFromPID(std::string outputPath)
Creates a test calibration file for ShowerCalibrationGaloreFromPID.
Creates a test calibration file for ShowerCalibrationGaloreFromPID.
QTextStream & endl(QTextStream &s)