Decouple MpdKalmanFilter from runReco.C
EDIT 2023-12-22: MpdKalmanFilter is so strongly coupled to whole code, it is pretty much impossible to decouple it in one go. Nevertheless, it is possible to partially isolate it by:
- get rid of its Init() method that needs FairRootAna class to read the magnetic field (terrible design) and does not do anything else
- get rid of its FairTask parent, as the class is a library that should be explicitely called by FairTasks which are dependent on it
- at present, it is pretty much impossible to get rid of its singleton nature. However there are actions which (hopefully) will keep it under control: 1. remove duplicate singleton calls from every class using it, by storing it in a member pointer 2. Make the dependency explicit in constructor of each reco.C FairTask using it, by passing *(MpdKalmanFilter::Instance()) as an argument
See #113 (closed)
MpdKalmanFilter should not be initialized as a FairTask itself (as by its nature it is not), it should be loaded as a dependency for FairTask that needs it.
Probable culprit
InitStatus MpdKalmanFilter::Init()
{
cout << "InitStatus MpdKalmanFilter::Init\n\n";
// Check if mag. field was set - if not create the default
fMagField = FairRunAna::Instance()->GetField();
if (!fMagField || TMath::Abs(fMagField->GetBz(0, 0, 0)) < 0.01) {
cout << " -I- Using the default constant magnetic field Bz = 5 kG " << endl;
fMagField = new MpdMultiField();
MpdConstField *field = new MpdConstField();
field->SetField(0., 0., 5.); // values are in kG
field->SetFieldRegion(-230, 230, -230, 230, -375, 375); // cm
((MpdMultiField *)fMagField)->AddField(field);
FairRunAna::Instance()->SetField(fMagField);
fMagField->Init();
cout << " -I- The magnetic field at (0,0,0) = (" << fMagField->GetBx(0, 0, 0) << "," << fMagField->GetBy(0, 0, 0)
<< "," << fMagField->GetBz(0, 0, 0) << ") kG" << endl;
} else {
cout << " -I- The magnetic field at (0,0,0) = (" << fMagField->GetBx(0, 0, 0) << "," << fMagField->GetBy(0, 0, 0)
<< "," << fMagField->GetBz(0, 0, 0) << ") kG" << endl;
cout << "OVERHEAD FIELD INFO: " << ((MpdMultiField *)fMagField)->GetFieldList()->UncheckedAt(0) << " "
<< ((FairField *)((MpdMultiField *)fMagField)->GetFieldList()->UncheckedAt(0))->GetType() << endl;
}
fJacob.ResizeTo(5, 5);
return kSUCCESS;
}
Edited by Slavomir Hnatic