BmnRoot 26.10.0-210-gc52d34b0
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnGlobalAlignment.cxx
Go to the documentation of this file.
1// @(#)bmnroot/alignment:$Id$
2// Author: Pavel Batyuk <pavel.batyuk@jinr.ru> 2017-03-31
3
4////////////////////////////////////////////////////////////////////////////////
5// //
6// BmnGlobalAlignment //
7// //
8// Alignment of tracking detectors. //
9// //
10// Uses Volker Blobel and Claus Kleinwort Millepede II //
11// //
12////////////////////////////////////////////////////////////////////////////////
13#include "BmnGlobalAlignment.h"
14
15#include "BmnSiliconHit.h"
16#include "CbmVertex.h"
17#include "GeoSetup.h"
18
19#include <TGraph.h>
20#include <TRandom2.h>
21#include <TStyle.h>
22#include <iconv.h>
23
25
27
29{
30 for (Int_t iStat = 0; iStat < fDetectorGEM->GetNStations(); iStat++)
31 delete[] fixedGemElements[iStat];
32 delete[] fixedGemElements;
33
34 delete[] fDetectorSet;
35 delete fDetectorGEM;
36 delete fDetectorSI;
37 if (Labels) {
38 delete[] Labels;
39 system("cp millepede.res Millepede.res");
40 // Remove useless text files finalizing the code execution
41 system("rm millepede.*");
42 }
43}
44
46 TString inFileName,
47 Int_t period,
48 Int_t run,
49 TString misAlignFile,
50 Bool_t doTest)
52 , fRunPeriod(period)
53 , fRunId(run)
54 , fGemAlignCorr(nullptr)
55 , fGemHits(nullptr)
56 , fGemTracks(nullptr)
57 , fSilTracks(nullptr)
58 , fGlobalTracks(nullptr)
60 , fChi2MaxPerNDF(LDBL_MAX)
62 , fTxMin(-LDBL_MAX)
63 , fTxMax(LDBL_MAX)
64 , fTyMin(-LDBL_MAX)
65 , fTyMax(LDBL_MAX)
68 , fTxLeft(0.)
69 , fTxRight(0.)
70 , fTyLeft(0.)
71 , fTyRight(0.)
72 , fNumOfIterations(500000)
73 , fAccuracy(1e-3)
74 , fPreSigma(1.)
76 , fHugecut(50.)
77 , fEntries(10)
79 , fDwfractioncut(0.0)
80 , fNGL(0)
81 , fNLC(4)
82 , nDetectors(2)
83 , fDebug(true)
84 , Labels(nullptr)
86 , fIsDoTest(doTest)
87 , fMisAlignFile(misAlignFile)
88 , fBmnGemMisalign(nullptr)
89{
90 fNEvents = nEvents;
91 fNTracks = 0;
92 fRecoFileName = inFileName;
93
94 fBranchSiHits = "BmnSiliconHit";
95 fBranchGemHits = "BmnGemStripHit";
96
97 fBranchGemTracks = "BmnGemTrack";
98 fBranchSilTracks = "BmnSiliconTrack";
99 fBranchGlobalTracks = "BmnGlobalTrack";
100
101 fBranchGemAlignCorr = "BmnGemAlignCorrections";
102 fBranchSiAlignCorr = "BmnSiliconAlignCorrections";
103
104 fBranchGemResiduals = "BmnResiduals";
105 fBranchFairEventHeader = "EventHeader.";
106
108 FillMaps();
109}
110
112{
113 cout << " BmnGlobalAlignment::Init() " << endl;
114 cout << "Use detectors: GEM - " << fDetectorSet[0] << " SILICON - " << fDetectorSet[1] << endl;
115
116 TChain* chain = new TChain("bmndata");
117 chain->Add(fRecoFileName.Data());
118 FairEventHeader* evHeader = NULL;
119 chain->SetBranchAddress(fBranchFairEventHeader.Data(), &evHeader);
120 chain->GetEntry(0);
121 delete chain;
122
123 Double_t fieldVolt = 0.;
124 UniRun* runInfo = NULL;
125 if (fRunId != 0) {
126 runInfo = UniRun::GetRun(fRunPeriod, fRunId);
127 if (!runInfo)
128 throw;
129 fieldVolt = *runInfo->GetFieldVoltage();
130 fIsField = (fieldVolt > 10.) ? kTRUE : kFALSE;
131 }
132
133 FairRootManager* ioman = FairRootManager::Instance();
134
135 fSiHits = (TClonesArray*)ioman->GetObject(fBranchSiHits.Data());
136 fGemHits = (TClonesArray*)ioman->GetObject(fBranchGemHits.Data());
137
138 fSilTracks = (TClonesArray*)ioman->GetObject(fBranchSilTracks.Data());
139 fGemTracks = (TClonesArray*)ioman->GetObject(fBranchGemTracks.Data());
140 fGlobalTracks = (TClonesArray*)ioman->GetObject(fBranchGlobalTracks.Data());
141
142 fFairEventHeader = (FairEventHeader*)ioman->GetObject(fBranchFairEventHeader.Data());
143
146
147 ioman->Register(fBranchGemAlignCorr.Data(), "GEM", fGemAlignCorr, kTRUE);
148 ioman->Register(fBranchSiAlignCorr.Data(), "SI", fSiAlignCorr, kTRUE);
149
150 fChain = ioman->GetInChain();
151
152 GeoSetup gSetup;
153 string setupTag = gSetup.GetLastApprovedSetupTag(TString::Format("run%d", fRunPeriod).Data());
154 Int_t res_code = gSetup.LoadSetupToGeoManager(setupTag);
155 if (res_code != 0) {
156 cout << "Geometry '" << setupTag << "' can't be loaded from the Geometry Database" << endl;
157 exit(-1);
158 }
159
160 if (fIsDoTest) {
161 TChain* ch = new TChain("bmndata");
162 ch->Add(fMisAlignFile.Data());
164 ch->GetEntry(0);
165 delete ch;
166 }
167 return kSUCCESS;
168}
169
171{
172 fFairEventHeader->SetMCEntryNumber(fCurrentEvent);
173 fFairEventHeader->SetRunId(fRunId);
175 if (fCurrentEvent % 1000 == 0)
176 cout << "Event# = " << fCurrentEvent << endl;
177
178 if (!fGlobalTracks)
179 return;
180
181 // for (Int_t iGlobTrack = 0; iGlobTrack < fGlobalTracks->GetEntriesFast(); iGlobTrack++) {
182 // BmnGlobalTrack* globTrack = (BmnGlobalTrack*)fGlobalTracks->UncheckedAt(iGlobTrack);
183 // if (fDetectorSet[1] && globTrack->GetSilTrackIndex() == -1)
184 // continue;
185
186 // FairTrackParam* params = globTrack->GetParamFirst();
187
188 // Double_t chi2 = globTrack->GetChi2();
189 // Int_t ndf = globTrack->GetNDF();
190 // Int_t nHits = globTrack->GetNHits();
191 // Double_t Tx = params->GetTx();
192 // Double_t Ty = params->GetTy();
193
194 // // Use track constraints if necessary
195 // if (Tx < fTxMin || Tx > fTxMax || Ty < fTyMin || Ty > fTyMax || nHits < fMinHitsAccepted
196 // || chi2 / ndf > fChi2MaxPerNDF)
197 // continue;
198
199 // // Exclude a range from the selected range of track. params (in order not to take into account tracks with
200 // // almost zero values of track params.)
201 // if (fIsExcludedTx && Tx > fTxLeft && Tx < fTxRight)
202 // continue;
203 // if (fIsExcludedTy && Ty > fTyLeft && Ty < fTyRight)
204 // continue;
205
206 // Int_t* idx = new Int_t[nDetectors];
207 // idx[0] = globTrack->GetGemTrackIndex();
208 // idx[1] = globTrack->GetSilTrackIndex();
209
210 // vector<BmnMilleContainer*> GEM;
211 // vector<BmnMilleContainer*> SILICON;
212
213 // for (Int_t iDet = 0; iDet < nDetectors; iDet++) {
214 // if (!fDetectorSet[iDet] || idx[iDet] == -1 || fIsField) //{
215 // // delete [] idx;
216 // continue;
217 // //}
218 // MilleNoFieldRuns(globTrack, idx[iDet], iDet, GEM, SILICON);
219 // }
220
221 // fCONTAINER[fNTracks] = pair<vector<BmnMilleContainer*>, vector<BmnMilleContainer*>>(SILICON, GEM);
222 // fNTracks++;
223 // delete[] idx;
224 // }
225
226 if (fNEvents == fCurrentEvent) {
227 MakeBinFile();
229 Pede();
230 }
231}
232
234{
236
237 mille->SetStation(hit->GetStation());
238 mille->SetModule(hit->GetModule());
239
240 vector<Double_t> locDerX;
241 vector<Double_t> locDerY;
242 locDerX.push_back(1.);
243 locDerX.push_back(hit->GetZ());
244 locDerX.push_back(0.);
245 locDerX.push_back(0.);
246
247 locDerY.push_back(0.);
248 locDerY.push_back(0.);
249 locDerY.push_back(1.);
250 locDerY.push_back(hit->GetZ());
251
252 vector<Double_t> globDerX;
253 vector<Double_t> globDerY;
254 globDerX.push_back(1.);
255 globDerX.push_back(0.);
256 globDerX.push_back(glTrack->GetParamFirst()->GetTx());
257
258 globDerY.push_back(0.);
259 globDerY.push_back(1.);
260 globDerY.push_back(glTrack->GetParamFirst()->GetTy());
261
262 mille->SetLocDers(locDerX, locDerY);
263 mille->SetGlobDers(globDerX, globDerY);
264
265 mille->SetMeasures(hit->GetX(), hit->GetY());
266 mille->SetDMeasures(fUseRealHitErrors ? 2. * hit->GetDx() : 1., fUseRealHitErrors ? hit->GetDy() : 1.);
267
268 return mille;
269}
270
272 Int_t idx,
273 Int_t iDet,
274 vector<BmnMilleContainer*>& GEM,
275 vector<BmnMilleContainer*>& SILICON)
276{
277 // GEM
278 if (iDet == 0) {
279 BmnTrack* track = (BmnTrack*)fGemTracks->UncheckedAt(idx);
280 for (Int_t iHit = 0; iHit < track->GetNHits(); iHit++) {
281 BmnGemStripHit* hit = (BmnGemStripHit*)fGemHits->UncheckedAt(track->GetHitIndex(iHit));
282 GEM.push_back(FillMilleContainer(glTrack, hit));
283 }
284 }
285
286 // SILICON
287 if (iDet == 1) {
288 BmnTrack* track = (BmnTrack*)fSilTracks->UncheckedAt(idx);
289 for (Int_t iHit = 0; iHit < track->GetNHits(); iHit++) {
290 BmnSiliconHit* hit = (BmnSiliconHit*)fSiHits->UncheckedAt(track->GetHitIndex(iHit));
291 SILICON.push_back(FillMilleContainer(glTrack, hit));
292 }
293 }
294}
295
296void BmnGlobalAlignment::_Mille(Double_t* DerLc, Double_t* DerGl, BmnMille* Mille, Int_t iTrack)
297{
298 fITERATOR = next(fCONTAINER.begin(), iTrack);
299
300 TString* dets = new TString[nDetectors];
301 dets[0] = "GEM";
302 dets[1] = "SILICON";
303
304 for (Int_t iDet = 0; iDet < nDetectors; iDet++) {
305 vector<BmnMilleContainer*> cont;
306 if (dets[iDet].Contains("GEM"))
307 cont = fITERATOR->second.second;
308 else if (dets[iDet].Contains("SILICON"))
309 cont = fITERATOR->second.first;
310 else {
311 cout << "Wrong input data! Exiting ..." << endl;
312 throw;
313 }
314
315 const Int_t nLays = 2;
316 TString lays[nLays] = {"X", "Y"};
317
318 for (size_t iEle = 0; iEle < cont.size(); iEle++) {
319 BmnMilleContainer* _cont = cont[iEle];
320 for (Int_t iLoc = 0; iLoc < fNLC; iLoc++)
321 DerLc[iLoc] = 0.;
322 for (Int_t iGlob = 0; iGlob < fNGL; iGlob++)
323 DerGl[iGlob] = 0.;
324
325 for (Int_t iLay = 0; iLay < nLays; iLay++) {
326 vector<Double_t> locDers = _cont->GetLocDers(lays[iLay]);
327 DerLc[0] = locDers[0];
328 DerLc[1] = locDers[1];
329 DerLc[2] = locDers[2];
330 DerLc[3] = locDers[3];
331
332 Int_t idx = dets[iDet].Contains("GEM") ? GemStatModLabel(_cont->GetStation(), _cont->GetModule())
333 : SiliconStatModLabel(_cont->GetStation(), _cont->GetModule());
334 Int_t idxUp = idx - 1; // Upper label value
335 Int_t idxMed = idxUp - 1;
336 Int_t idxLow = idxMed - 1;
337
338 vector<Double_t> globDers = _cont->GetGlobDers(lays[iLay]);
339 DerGl[idxLow] = globDers[0];
340 DerGl[idxMed] = globDers[1];
341 DerGl[idxUp] = globDers[2];
342
343 Double_t meas = lays[iLay].Contains("X") ? _cont->GetMeasures().X() : _cont->GetMeasures().Y();
344 Double_t dmeas = lays[iLay].Contains("X") ? _cont->GetDMeasures().X() : _cont->GetDMeasures().Y();
345 Mille->mille(fNLC, DerLc, fNGL, DerGl, Labels, meas, dmeas);
346
347 if (fDebug) {
348 cout << dets[iDet] << endl;
349 cout << lays[iLay] << endl;
350 cout << _cont->GetStation() << " " << _cont->GetModule() << endl;
351 cout << "Loc. ders : ";
352 for (Int_t iLoc = 0; iLoc < fNLC; iLoc++)
353 cout << DerLc[iLoc] << " ";
354 cout << endl;
355 cout << "Glob. ders : ";
356 for (Int_t iGlob = 0; iGlob < fNGL; iGlob++)
357 cout << DerGl[iGlob] << " ";
358 cout << endl;
359 cout << "Meas = " << meas << " dMeas = " << dmeas << endl;
360 }
361 }
362 }
363 }
364 delete[] dets;
365}
366
368{
369 const Int_t ngl_per_subdetector = 3; // x, y and z corrs to each det. subsyst. (GEM, SILICON at the moment)
370
371 // GEM
372 for (Int_t iStat = 0; iStat < fDetectorGEM->GetNStations(); iStat++)
373 fNGL += ngl_per_subdetector * fDetectorGEM->GetGemStation(iStat)->GetNModules();
374
375 // SILICON
376 for (Int_t iStat = 0; iStat < fDetectorSI->GetNStations(); iStat++)
377 fNGL += ngl_per_subdetector * fDetectorSI->GetSiliconStation(iStat)->GetNModules();
378
379 // Array with labels
380 Labels = new Int_t[fNGL];
381 for (Int_t iEle = 0; iEle < fNGL; iEle++)
382 Labels[iEle] = 1 + iEle;
383
384 // Read collected tracks
385 // Arrays with loc. and glob. derivatives
386 Int_t nTracks = fCONTAINER.size();
387 Double_t DerLc[fNLC];
388 Double_t DerGl[fNGL];
389
390 BmnMille* Mille = new BmnMille("alignment.bin", kTRUE, kFALSE);
391 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
392 if (fDebug)
393 cout << "Track# " << iTrack << endl;
394 _Mille(DerLc, DerGl, Mille, iTrack);
395 Mille->end();
396 if (iTrack % 1000 == 0 && !fDebug)
397 cout << "Track processed# " << iTrack << endl;
398 }
399
400 delete Mille;
401 return 0;
402}
403
405{
406 // Double_t shiftX = 0., shiftY = 0., shiftZ = 0.;
407 // Double_t*** misAlign = new Double_t**[fDetectorGEM->GetNStations()];
408 // for (Int_t iStat = 0; iStat < fDetectorGEM->GetNStations(); iStat++) {
409 // misAlign[iStat] = new Double_t*[fDetectorGEM->GetGemStation(iStat)->GetNModules()];
410 // for (Int_t iMod = 0; iMod < fDetectorGEM->GetGemStation(iStat)->GetNModules(); iMod++) {
411 // misAlign[iStat][iMod] = new Double_t[3];
412 // for (Int_t iPar = 0; iPar < 3; iPar++)
413 // misAlign[iStat][iMod][iPar] = 0.;
414 // }
415 // }
416
417 // if (fIsDoTest && fBmnGemMisalign) {
418 // for (Int_t iCorr = 0; iCorr < fBmnGemMisalign->GetEntriesFast(); iCorr++) {
419 // BmnGemAlignCorrections* align = (BmnGemAlignCorrections*) fBmnGemMisalign->UncheckedAt(iCorr);
420 // Int_t iStat = align->GetStation();
421 // Int_t iMod = align->GetModule();
422 // TVector3 corrsXYZ = align->GetCorrections();
423 // misAlign[iStat][iMod][0] = corrsXYZ.X();
424 // shiftX += misAlign[iStat][iMod][0];
425 // misAlign[iStat][iMod][1] = corrsXYZ.Y();
426 // shiftY += misAlign[iStat][iMod][1];
427 // misAlign[iStat][iMod][2] = corrsXYZ.Z();
428 // shiftZ += misAlign[iStat][iMod][2];
429 // }
430 // }
431
432 FILE* steer = fopen("steer.txt", "w");
433 TString alignType = "alignment.bin";
434 fprintf(steer, "%s\n", alignType.Data());
435 fprintf(steer, "method inversion %d %f\n", fNumOfIterations, fAccuracy);
437 fprintf(steer, "regularization 1.0\n");
438 fprintf(steer, "hugecut %G\n", fHugecut);
439 if (fChisqcut[0] * fChisqcut[1] != 0)
440 fprintf(steer, "chisqcut %G %G\n", fChisqcut[0], fChisqcut[1]);
441 fprintf(steer, "entries %d\n", fEntries);
442 fprintf(steer, "outlierdownweighting %d\n", fOutlierdownweighting);
443 fprintf(steer, "dwfractioncut %G\n", fDwfractioncut);
444 fprintf(steer, "Parameter\n");
445
446 Int_t parCounterGem = 0;
447 Int_t parCounterSi = 0;
448 const Int_t nParams = 3;
449
450 for (Int_t iStat = 0; iStat < fDetectorGEM->GetNStations(); iStat++)
451 for (Int_t iMod = 0; iMod < fDetectorGEM->GetGemStation(iStat)->GetNModules(); iMod++)
452 parCounterGem++;
453
454 for (Int_t iStat = 0; iStat < fDetectorSI->GetNStations(); iStat++)
455 for (Int_t iMod = 0; iMod < fDetectorSI->GetSiliconStation(iStat)->GetNModules(); iMod++)
456 parCounterSi++;
457
458 Int_t startIdx = 0;
459 for (Int_t iDet = 0; iDet < nDetectors; iDet++) {
460 if (iDet == 0) { // Process GEMs to mark fixed stations if exist
461 for (Int_t iStat = 0; iStat < fDetectorGEM->GetNStations(); iStat++) {
462 for (Int_t iPar = 0; iPar < fDetectorGEM->GetGemStation(iStat)->GetNModules() * nParams; iPar++) {
463 if (!fDetectorSet[0])
464 fprintf(steer, "%d %G %G\n", Labels[startIdx + iPar], 0., -1.);
465 else
466 fprintf(steer, "%d %G %G\n", Labels[startIdx + iPar], 0.,
467 (fixedGemElements[iStat][iPar / nParams]) ? -1. : fPreSigma);
468 }
469 startIdx += fDetectorGEM->GetGemStation(iStat)->GetNModules() * nParams;
470 }
471 } else if (iDet == 1) { // Process SILICON to mark fixed modules if exist
472 for (Int_t iStat = 0; iStat < fDetectorSI->GetNStations(); iStat++) {
473 for (Int_t iPar = 0; iPar < fDetectorSI->GetSiliconStation(iStat)->GetNModules() * nParams; iPar++) {
474 if (!fDetectorSet[1])
475 fprintf(steer, "%d %G %G\n", Labels[startIdx + iPar], 0., -1.);
476 else
477 fprintf(steer, "%d %G %G\n", Labels[startIdx + iPar], 0.,
478 (fixedSiElements[iStat][iPar / nParams]) ? -1.
479 : (fIsDoTest) ? -1.
480 : fPreSigma);
481 }
482 startIdx += fDetectorSI->GetSiliconStation(iStat)->GetNModules() * nParams;
483 }
484 }
485 }
486
487 if (!fUseConstraints) {
488 fclose(steer);
489 return;
490 }
491
492 // Calculate center-of-gravity along Z-axis (GEM and SI)
493 map<pair<Int_t, Int_t>, Double_t> z_GEM;
494 map<pair<Int_t, Int_t>, Double_t> z_SI;
495
496 if (fDetectorSet[0]) {
497 for (Int_t iStat = 0; iStat < fDetectorGEM->GetNStations(); iStat++)
498 for (Int_t iMod = 0; iMod < fDetectorGEM->GetGemStation(iStat)->GetNModules(); iMod++)
499 if (!fixedGemElements[iStat][iMod])
500 z_GEM[pair<Int_t, Int_t>(iStat, iMod)] =
501 fDetectorGEM->GetGemStation(iStat)->GetModule(iMod)->GetZPositionRegistered();
502 }
503
504 if (fDetectorSet[1]) {
505 for (Int_t iStat = 0; iStat < fDetectorSI->GetNStations(); iStat++)
506 for (Int_t iMod = 0; iMod < fDetectorSI->GetSiliconStation(iStat)->GetNModules(); iMod++)
507 if (!fixedSiElements[iStat][iMod])
508 z_SI[pair<Int_t, Int_t>(iStat, iMod)] =
509 fDetectorSI->GetSiliconStation(iStat)->GetModule(iMod)->GetZPositionRegistered();
510 }
511
512 Double_t zSum = 0.;
513 for (auto it : z_GEM)
514 zSum += it.second;
515
516 for (auto it : z_SI)
517 zSum += it.second;
518
519 Double_t zC = zSum / (z_GEM.size() + z_SI.size());
520 cout << zC << " " << z_GEM.size() + z_SI.size() << endl;
521
522 // Calculate dZ = Zpos - Zc (GEM and SI)
523 map<pair<Int_t, Int_t>, Double_t> dZ_GEM;
524 map<pair<Int_t, Int_t>, Double_t> dZ_SI;
525
526 for (auto it : z_GEM)
527 dZ_GEM[it.first] = it.second - zC;
528
529 for (auto it : z_SI)
530 dZ_SI[it.first] = it.second - zC;
531
532 map<Int_t, Double_t> deltas; // Label --> Correct dZ
533
534 for (auto it : dZ_GEM) {
535 Int_t stat = it.first.first;
536 Int_t mod = it.first.second;
537 Int_t labZ = GemStatModLabel(stat, mod);
538 Int_t labY = labZ - 1;
539 Int_t labX = labY - 1;
540 deltas[labX] = it.second;
541 deltas[labY] = it.second;
542 deltas[labZ] = it.second + zC;
543 }
544
545 for (auto it : dZ_SI) {
546 Int_t stat = it.first.first;
547 Int_t mod = it.first.second;
548 Int_t labZ = SiliconStatModLabel(stat, mod);
549 Int_t labY = labZ - 1;
550 Int_t labX = labY - 1;
551 deltas[labX] = it.second;
552 deltas[labY] = it.second;
553 deltas[labZ] = it.second + zC;
554 }
555
556 if (!fDetectorSet[0] && !fDetectorSet[1])
557 return;
558
559 // Apply constraints ...
560 // Wi * a_Xi = 0, (iStep = 0), Wi = 1.
561 // Wi * a_Yi = 0, (iStep = 1), Wi = 1.
562 // Wi * a_Zi = 0, (iStep = 2), Wi = 1.
563 for (Int_t iRemain = 0; iRemain < nParams; iRemain++) {
564 fprintf(steer, "constraint 0.0\n");
565 if (fDetectorSet[0])
566 for (Int_t iPar = 0; iPar < parCounterGem * nParams; iPar++) {
567 Int_t stat = GetGemStatMod(Labels[iPar])[0];
568 Int_t mod = GetGemStatMod(Labels[iPar])[1];
569 if (Labels[iPar] % nParams == iRemain && !fixedGemElements[stat][mod])
570 fprintf(steer, "%d %G\n", Labels[iPar], 1.);
571 }
572
573 if (fDetectorSet[1])
574 for (Int_t iPar = parCounterGem * nParams; iPar < fNGL; iPar++) {
575 Int_t stat = GetSiliconStatMod(Labels[iPar])[0];
576 Int_t mod = GetSiliconStatMod(Labels[iPar])[1];
577 if (Labels[iPar] % nParams == iRemain && !fixedSiElements[stat][mod])
578 fprintf(steer, "%d %G\n", Labels[iPar], 1.);
579 }
580 }
581
582 // Wi * a_Xi = 0, (iStep = 0), Wi = delta_Zi
583 // Wi * a_Yi = 0, (iStep = 1), Wi = delta_Zi
584 // Wi * a_Zi = 0, (iStep = 2), Wi = Zi
585 for (Int_t iRemain = 0; iRemain < nParams; iRemain++) {
586 fprintf(steer, "constraint 0.0\n");
587 for (auto it : deltas) {
588 if (it.first <= parCounterGem * nParams) {
589 Int_t stat = GetGemStatMod(it.first)[0];
590 Int_t mod = GetGemStatMod(it.first)[1];
591 if (it.first % nParams == iRemain && !fixedGemElements[stat][mod])
592 fprintf(steer, "%d %G\n", it.first, it.second);
593 } else {
594 Int_t stat = GetSiliconStatMod(it.first)[0];
595 Int_t mod = GetSiliconStatMod(it.first)[1];
596 if (it.first % nParams == iRemain && !fixedSiElements[stat][mod])
597 fprintf(steer, "%d %G\n", it.first, it.second);
598 }
599 }
600 }
601 fclose(steer);
602}
603
605{
606 system("pede steer.txt");
607 ifstream resFile("millepede.res", ios::in);
608 ReadPedeOutput(resFile);
609 resFile.close();
610}
611
613{
614 if (!resFile) {
615 cout << "BmnGlobalAlignment::ReadPedeOutput" << " No input file found!!" << endl;
616 throw;
617 }
618 resFile.ignore(numeric_limits<streamsize>::max(), '\n');
619
620 const Int_t nParams = 3;
621 Double_t* corrs = new Double_t[nParams];
622
623 // Read GEMs
624 for (Int_t iStat = 0; iStat < fDetectorGEM->GetNStations(); iStat++) {
625 for (Int_t iMod = 0; iMod < fDetectorGEM->GetGemStation(iStat)->GetNModules(); iMod++) {
626 ExtractCorrValues(resFile, corrs);
627 BmnGemAlignCorrections* gemCorrs =
628 new ((*fGemAlignCorr)[fGemAlignCorr->GetEntriesFast()]) BmnGemAlignCorrections();
629 gemCorrs->SetStation(iStat);
630 gemCorrs->SetModule(iMod);
631 gemCorrs->SetCorrections(corrs);
632 }
633 }
634
635 // Read SILICON
636 for (Int_t iStat = 0; iStat < fDetectorSI->GetNStations(); iStat++) {
637 for (Int_t iMod = 0; iMod < fDetectorSI->GetSiliconStation(iStat)->GetNModules(); iMod++) {
638 ExtractCorrValues(resFile, corrs);
640 new ((*fSiAlignCorr)[fSiAlignCorr->GetEntriesFast()]) BmnSiliconAlignCorrections();
641 siCorrs->SetStation(iStat);
642 siCorrs->SetModule(iMod);
643 siCorrs->SetCorrections(corrs);
644 }
645 }
646
647 delete[] corrs;
648}
649
650void BmnGlobalAlignment::ExtractCorrValues(ifstream& resFile, Double_t* corrs)
651{
652 const Int_t nParams = 3;
653 TString parValue = "", dummy = "";
654 string line;
655
656 for (Int_t iCorr = 0; iCorr < nParams; iCorr++)
657 corrs[iCorr] = 0.;
658 for (Int_t iLine = 0; iLine < nParams; iLine++) {
659 getline(resFile, line);
660 stringstream ss(line);
661 Int_t size = ss.str().length();
662 // 40 and 68 symbols are fixed in the Pede-output by a given format
663 if (size == 40)
664 ss >> dummy >> parValue >> dummy;
665 else if (size == 68)
666 ss >> dummy >> parValue >> dummy >> dummy >> dummy;
667 else
668 cout << "Unsupported format given!" << endl;
669
670 Int_t idx = (iLine % nParams == 0) ? 0 : (iLine % nParams == 1) ? 1 : 2;
671 corrs[idx] = -parValue.Atof();
672 }
673}
674
676{
678
679 // Choose appropriate configuration (BM@N or SRC)
680 Bool_t isSRC = (fRunId < 3589) ? kTRUE : kFALSE; // FIXME
681 TString gPathConfig = gSystem->Getenv("VMCWORKDIR");
682 TString confSi = "SiliconRun" + TString(isSRC ? "SRC" : "") + "Spring2018.xml";
683 TString confGem = "GemRun" + TString(isSRC ? "SRC" : "") + "Spring2018.xml";
684
685 /// SI
686 TString gPathSiliconConfig = gPathConfig + "/parameters/silicon/XMLConfigs/";
687 fDetectorSI = new BmnSiliconStationSet(gPathSiliconConfig + confSi);
688
689 // Define fixed elements of SI-detector...
690 fixedSiElements = new Bool_t*[fDetectorSI->GetNStations()];
691 for (Int_t iStat = 0; iStat < fDetectorSI->GetNStations(); iStat++) {
692 fixedSiElements[iStat] = new Bool_t[fDetectorSI->GetSiliconStation(iStat)->GetNModules()];
693 }
694
695 for (Int_t iStat = 0; iStat < fDetectorSI->GetNStations(); iStat++)
696 for (Int_t iMod = 0; iMod < fDetectorSI->GetSiliconStation(iStat)->GetNModules(); iMod++)
697 fixedSiElements[iStat][iMod] = kFALSE;
698
699 /// GEM
700 TString gPathGemConfig = gPathConfig + "/parameters/gem/XMLConfigs/";
701 fDetectorGEM = new BmnGemStripStationSet(gPathGemConfig + confGem);
702
703 // Define fixed elements of GEM-detector...
704 fixedGemElements = new Bool_t*[fDetectorGEM->GetNStations()];
705 for (Int_t iStat = 0; iStat < fDetectorGEM->GetNStations(); iStat++) {
706 fixedGemElements[iStat] = new Bool_t[fDetectorGEM->GetGemStation(iStat)->GetNModules()];
707 }
708
709 for (Int_t iStat = 0; iStat < fDetectorGEM->GetNStations(); iStat++)
710 for (Int_t iMod = 0; iMod < fDetectorGEM->GetGemStation(iStat)->GetNModules(); iMod++)
711 fixedGemElements[iStat][iMod] = kFALSE;
712}
bool Bool_t
int Int_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const char Option_t
R__EXTERN TSystem * gSystem
void SetCorrections(Double_t x, Double_t y, Double_t z)
map< Int_t, pair< vector< BmnMilleContainer * >, vector< BmnMilleContainer * > > > fCONTAINER
void ExtractCorrValues(ifstream &, Double_t *)
TClonesArray * fGlobalTracks
TClonesArray * fSiAlignCorr
TClonesArray * fGemTracks
BmnGemStripStationSet * fDetectorGEM
virtual InitStatus Init()
BmnSiliconStationSet * fDetectorSI
Int_t SiliconStatModLabel(Int_t st, Int_t mod)
void MilleNoFieldRuns(BmnGlobalTrack *, Int_t, Int_t, vector< BmnMilleContainer * > &, vector< BmnMilleContainer * > &)
FairEventHeader * fFairEventHeader
virtual void Exec(Option_t *opt)
map< Int_t, pair< vector< BmnMilleContainer * >, vector< BmnMilleContainer * > > >::iterator fITERATOR
vector< Int_t > GetSiliconStatMod(Int_t label)
TClonesArray * fBmnGemMisalign
void _Mille(Double_t *, Double_t *, BmnMille *, Int_t)
TClonesArray * fGemAlignCorr
TClonesArray * fSilTracks
void ReadPedeOutput(ifstream &)
BmnMilleContainer * FillMilleContainer(BmnGlobalTrack *, BmnHit *)
Int_t GemStatModLabel(Int_t st, Int_t mod)
vector< Int_t > GetGemStatMod(Int_t label)
BmnGlobalTrack.h.
Int_t GetModule()
Definition BmnHit.h:36
Short_t GetStation() const
Definition BmnHit.h:35
void SetModule(Int_t mod)
vector< Double_t > GetGlobDers(TString lay)
void SetMeasures(Double_t measX, Double_t measY)
void SetLocDers(vector< Double_t > vecX, vector< Double_t > vecY)
vector< Double_t > GetLocDers(TString lay)
void SetGlobDers(vector< Double_t > vecX, vector< Double_t > vecY)
void SetDMeasures(Double_t dMeasX, Double_t dMeasY)
void SetStation(Int_t stat)
void end()
Write buffer (set of derivatives with same local parameters) to file.
Definition BmnMille.cxx:150
void mille(Int_t NLC, const Double_t *derLc, Int_t NGL, const Double_t *derGl, const Int_t *label, Double_t rMeas, Double_t sigma)
Add measurement to buffer.
Definition BmnMille.cxx:48
FairTrackParam * GetParamFirst()
Definition BmnTrack.h:63
Int_t GetNHits() const
Accessors.
Definition BmnTrack.h:49
Int_t GetHitIndex(Int_t iHit) const
Definition BmnTrack.h:51
GeoSetup class.
Definition GeoSetup.h:40
int LoadSetupToGeoManager(string_view setup_tag)
Load selected geometry setup from the Local Geometry Database and create gGeoManager instance.
Definition GeoSetup.cxx:512
string GetLastApprovedSetupTag(string_view tag_prefix)
Get tag for the last approved setup corresponding to the pattern.
Definition GeoSetup.cxx:122
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
virtual Int_t Add(const char *name, Long64_t nentries=TTree::kMaxEntries)
Int_t GetEntry(Long64_t entry=0, Int_t getall=0) override
Double_t Atof() const
const char * Data() const
static TString Format(const char *fmt,...)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Double_t Y() const
Double_t X() const
UniRun.h Class for the table: run_.
Definition UniRun.h:21
static UniRun * GetRun(int period_number, int run_number)
get run from the database
Definition UniRun.cxx:161
double * GetFieldVoltage()
get field voltage of the current run
Definition UniRun.h:121