19#include "FairRootManager.h"
20#include "FairRunAna.h"
24#include "fairlogger/Logger.h"
33 for (
auto& [isec, h2] : station)
36 for (
auto& [isec, h2] : station)
42 FairRootManager* ioman = FairRootManager::Instance();
44 LOG(error) <<
" <!> BmnAlignerApply::Init : FairRootManager not found";
50 LOG(error) <<
" <!> BmnAlignerApply::Init : Failed to get StsHit array";
58 LOG(error) <<
" <!> BmnAlignerApply::Init : Failed init alignment hierarchy";
63 LOG(error) <<
" <!> BmnAlignerApply::Init : Failed to load alignment solution from file " <<
fAlignFilePath;
69 }
catch (std::exception& e) {
70 LOG(error) <<
" <!> BmnAlignerApply::Init : " << e.what();
74 LOG(error) <<
" <!> BmnAlignerApply::Init : Unknown exception";
79 LOG(info) <<
"BmnAlignerApply::Init : detector alignment model '" <<
fpDetModel->Description() <<
"'";
81 <<
"BmnAlignerApply::Init : this model is incomplete - some hits will be left as is";
88 SetActive(statusL == kSUCCESS);
103 FairField* mField = FairRunAna::Instance()->GetField();
113 FairRootManager* ioman = FairRootManager::Instance();
114 auto digiRunHeader =
static_cast<DigiRunHeader*
>(ioman->GetInFile()->Get(
"DigiRunHeader"));
115 uint64_t period{digiRunHeader ? digiRunHeader->GetPeriodId() : 0};
118 gPathConfig +
"/parameters/silicon/XMLConfigs/" + (period > 8 ?
"SiliconRun9.xml" :
"SiliconRun8.xml"))};
119 std::unique_ptr<BmnVSPStationSet> VspStationSet;
121 VspStationSet.reset(
new BmnVSPStationSet(gPathConfig +
"/parameters/vsp/XMLConfigs/VSP_Run9.xml"));
123 UInt_t irun{((
DstEventHeader*)ioman->GetObject(
"DstEventHeader."))->GetRunId()};
125 LOG(error) <<
" <!> BmnAlignerApply::Init : no run number to select Lorentz corrections";
134 fileName +=
"/parameters/reco/LorentzCorr.histo.root";
137 if (histFile ==
nullptr) {
140 LOG(error) <<
" <!> BmnAlignerApply::Init : Lorentz correction file " << fileName <<
" not found";
151 TKey *key =
nullptr, *key1 =
nullptr;
153 while ((obj = next())) {
159 while ((key1 = (
TKey*)nextHist())) {
161 runs[0].insert(stoi(key->
GetName()));
163 runs[1].insert(stoi(key->
GetName()));
168 for (
int igem = 0; igem < 2; ++igem) {
169 auto iter = runs[igem].upper_bound(irun);
170 if (iter != runs[igem].begin())
172 cout <<
" ---> Using corrections for run " << *iter <<
" " << igem << endl;
178 while ((key = (
TKey*)nextHist())) {
180 if (igem == 0 && !hName.
Contains(
"hSil"))
182 if (igem == 1 && !hName.
Contains(
"hGem"))
186 int ipos = hName.
First(
"_");
188 int ista = stat.
Atoi() - 1;
195 Fatal(
"FillLorentzHistost",
"!!! Different ymin and ymax %f %f ", ymin, ymax);
198 Double_t dx = (xmax - xmin) / nx, dy = (ymax - ymin) / ny;
199 cout <<
" Bin size: " << dx <<
"x" << dy <<
" cm" << endl;
205 for (
int iupl = 0; iupl < 2; ++iupl) {
208 hName12.
Insert(ipos - 1, upl);
209 TH2D* hnew =
new TH2D(hName12,
"", nx, xmin, xmax, ny12, 0, ymax);
215 int iyb = ny12 + 1, iye = ny;
222 for (
int iy = iyb; iy <= iye; ++iy) {
223 for (
int ix = 1; ix <= nx; ++ix) {
225 int iy1 = (iupl == 0) ? iy - ny12 : ny12 - iy + 1;
232 int nsec = 2, nxsi = 0;
234 if (ista == 0 && VspStationSet)
235 nsec = VspStationSet->GetStation(ista)->GetNModules();
240 nsec = SilStationSet->GetStation(ista1)->GetNModules();
242 nxsi = nx / (nsec / 2);
243 rangex = (xmax - xmin) / (nsec / 2);
246 for (
int isec = 0; isec < nsec; ++isec) {
249 hName12.
Insert(ipos, sec);
250 if (isec == nsec / 2)
251 xend = xmax + rangex;
253 TH2D* hnew =
new TH2D(hName12,
"", nxsi, xend - rangex, xend, ny12, 0, ymax);
256 hLorCor[isec] = hnew;
261 for (
int iy = ny; iy > 0; --iy) {
262 int iy1 = (iy > ny12) ? iy - ny12 : ny12 - iy + 1;
264 for (
int ix = 1; ix <= nx; ++ix) {
265 int isec = (ix - 1) / nxsi;
266 isec = nsec / 2 - isec - 1;
269 int ix1 = (ix - 1) % nxsi + 1;
292 for (
Int_t i = 0;
i < totalHits;
i++) {
296 Int_t hitDetID = hit->GetDetectorID();
304 LOG(error) <<
" <!> BmnAlignerApply::Exec : unknown detector ID " << hitDetID <<
" ("
316 LOG(error) <<
" <!> BmnAlignerApply::Exec : hit alignment skipped due to rotation matrix inversion failure";
350 Double_t ymin = ay->GetXmin(), ymax = ay->GetXmax();
360 hit->SetX(xh - dx * scale);
379 Double_t ymin = ay->GetXmin(), ymax = ay->GetXmax();
389 hit->SetX(xh - dx * scale);
393 int iupd = isec / (nsec / 2);
411 LOG(info) <<
"BmnAlignerApply: " << alignedHits <<
" hits aligned, " << totalHits - alignedHits <<
" hits ignored";
412 LOG_IF(warning, failedHits) <<
" <!> BmnAlignerApply: " << failedHits <<
" hits failed to be aligned";
417 LOG(info) <<
" BmnAlignerApply::Finish : " <<
fHitsAligned <<
" hits aligned";
418 LOG(info) <<
" BmnAlignerApply::Finish : " <<
fHitsIgnored <<
" hits ignored";
419 LOG_IF(warning,
fHitsFailed) <<
" <!> BmnAlignerApply::Finish : " <<
fHitsFailed <<
" hits failed to be aligned";
RM::SVector< Double_t, BMN_GLOBAL_PARAMS_PD > SVectGL
void Fatal(const char *location, const char *msgfmt,...)
R__EXTERN TSystem * gSystem
static Bool_t ReadSolution(const char *jsonPath, const BmnAlignHierarchy &hierarchy, Solution &solution)
const BmnMeasureModel * fpMeasureModel
std::map< int, TH2D * > fhLorCorX[17]
const char * fAlignFilePath
TClonesArray * fpStsHitsArray
std::map< int, TH2D * > fhLorCorY[17]
virtual void Exec(Option_t *opt)
const BmnDetectorModel * fpDetModel
VecSVectGL_t fCorrections
BmnAlignHierarchy fHierarchy
const Bool_t fLorentzCorrectionApply
virtual InitStatus Init()
InitStatus LorentzCorrectionInit()
virtual ~BmnAlignerApply()
virtual Int_t GetStationNr() const
Int_t GetSectorNr() const
Int_t GetSystemId() const
Accessors.
T * Get(const char *namecycle)
TList * GetListOfKeys() const override
virtual TList * GetListOfKeys() const
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
virtual void SetDirectory(TDirectory *dir)
virtual Int_t GetNbinsY() const
virtual Int_t GetNbinsX() const
void SetBinContent(Int_t bin, Double_t content) override
Double_t Interpolate(Double_t x, Double_t y) const override
virtual Double_t GetBinContent(Int_t bin) const
Bool_t IsFolder() const override
virtual TObject * ReadObj()
const char * GetName() const override
TString & Insert(Ssiz_t pos, const char *s)
Ssiz_t First(char c) const
static TString Itoa(Int_t value, Int_t base)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
std::vector< NodeValues > leaves