2 #include <alignment/calibration/MillepedeAlgorithm.h>
4 #include <alignment/dataobjects/MilleData.h>
5 #include <alignment/dataobjects/PedeSteering.h>
6 #include <alignment/GlobalLabel.h>
7 #include <alignment/GlobalParam.h>
8 #include <alignment/GlobalTimeLine.h>
9 #include <alignment/Manager.h>
10 #include <alignment/PedeApplication.h>
11 #include <alignment/PedeResult.h>
12 #include <framework/database/EventDependency.h>
19 using namespace alignment;
28 auto chisqHist = getObjectPtr<TH1F>(
"chi2_per_ndf");
29 B2INFO(
" Mean of Chi2 / NDF of tracks before calibration: " << chisqHist->GetMean());
32 B2INFO(
"Less than " <<
m_minEntries <<
" collected: " << chisqHist->GetEntries() <<
". Return c_NotEnoughData.");
38 auto mille = getObjectPtr<MilleData>(
"mille");
39 for (
auto file : mille->getFiles())
51 B2INFO(
"No parameters to store. Failure.");
71 int undeterminedParams = 0;
72 double maxCorrectionPull = 0.;
73 int maxCorrectionPullLabel = 0;
75 double paramChi2 = 0.;
82 GlobalCalibrationManager::initGlobalVector(
result);
83 GlobalCalibrationManager::initGlobalVector(errors);
84 GlobalCalibrationManager::initGlobalVector(corrections);
87 std::vector<std::tuple<unsigned short, unsigned short, unsigned short, double>> resultTuple;
89 for (
auto& exprun : expRuns) {
93 corrections.construct();
108 ++undeterminedParams;
116 double pull = correction / error;
119 paramChi2 += pull * pull;
121 if (fabs(pull) > fabs(maxCorrectionPull)) {
122 maxCorrectionPull = pull;
123 maxCorrectionPullLabel = label.label();
128 result.updateGlobalParam(correction, label.getUniqueId(), label.getElementId(), label.getParameterId());
129 errors.setGlobalParam(error, label.getUniqueId(), label.getElementId(), label.getParameterId());
130 corrections.setGlobalParam(correction, label.getUniqueId(), label.getElementId(), label.getParameterId());
132 resultTuple.push_back({label.getUniqueId(), label.getElementId(), label.getParameterId(), correction});
136 result.postReadFromResult(resultTuple);
138 for (
auto object :
result.releaseObjects()) {
141 for (
auto object : errors.releaseObjects()) {
144 for (
auto object : corrections.releaseObjects()) {
150 GlobalCalibrationManager::initGlobalVector(gpv);
164 ++undeterminedParams;
172 double pull = correction / error;
175 paramChi2 += pull * pull;
177 if (fabs(pull) > fabs(maxCorrectionPull)) {
178 maxCorrectionPull = pull;
179 maxCorrectionPullLabel = label.label();
192 for (
auto iov_obj : objects) {
201 if (iov_obj.second)
delete iov_obj.second;
206 for (
auto iov_obj : objects_errors) {
216 if (iov_obj.second)
delete iov_obj.second;
221 for (
auto iov_obj : objects_corrections) {
231 if (iov_obj.second)
delete iov_obj.second;
237 if (undeterminedParams) {
238 B2WARNING(
"There are " << undeterminedParams <<
" undetermined parameters.");
240 B2WARNING(
"Not enough data for calibration.");
247 if (paramChi2 / nParams > 1. || fabs(maxCorrectionPull) > 10.) {
248 B2INFO(
"Largest correction/error is " << maxCorrectionPull <<
" for parameter with label " << maxCorrectionPullLabel);
249 B2INFO(
"Parameter corrections Chi2/NDF, e.g. sum[(correction/error)^2]/#params = " << paramChi2 / nParams
250 <<
" = " << paramChi2 <<
" / " << nParams <<
" > 1.");
252 B2INFO(
"Requesting iteration.");
265 const std::string milleFileName(
"gbl-data.mille");
268 auto gblDataTree = getObjectPtr<TTree>(
"GblDataTree");
270 B2WARNING(
"No GBL data tree object in collected data.");
272 }
else if (!gblDataTree->GetEntries()) {
273 B2WARNING(
"No trajectories in GBL data tree.");
283 std::vector<unsigned int>* indLocal;
284 std::vector<double>* derLocal;
285 std::vector<int>* labGlobal;
286 std::vector<double>* derGlobal;
289 std::vector<gbl::GblData>* currentGblData =
new std::vector<gbl::GblData>();
290 gblDataTree->SetBranchAddress(
"GblData", ¤tGblData);
292 B2INFO(
"Writing Millepede binary files...");
293 for (
unsigned int iRecord = 0; iRecord < gblDataTree->GetEntries(); ++iRecord) {
294 gblDataTree->GetEntry(iRecord);
300 theData.getAllData(aValue, aErr, indLocal, derLocal, labGlobal,
302 milleBinary->addData(aValue, aErr, *indLocal, *derLocal, *labGlobal,
305 milleBinary->writeRecord();
309 B2INFO(
"Millepede binary files written.");