39 system(
"cp millepede.res Millepede.res");
41 system(
"rm millepede.*");
113 cout <<
" BmnGlobalAlignment::Init() " << endl;
133 FairRootManager* ioman = FairRootManager::Instance();
150 fChain = ioman->GetInChain();
156 cout <<
"Geometry '" << setupTag <<
"' can't be loaded from the Geometry Database" << endl;
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.);
247 locDerY.push_back(0.);
248 locDerY.push_back(0.);
249 locDerY.push_back(1.);
250 locDerY.push_back(hit->GetZ());
252 vector<Double_t> globDerX;
253 vector<Double_t> globDerY;
254 globDerX.push_back(1.);
255 globDerX.push_back(0.);
258 globDerY.push_back(0.);
259 globDerY.push_back(1.);
274 vector<BmnMilleContainer*>&
GEM,
275 vector<BmnMilleContainer*>& SILICON)
305 vector<BmnMilleContainer*> cont;
306 if (dets[iDet].Contains(
"GEM"))
308 else if (dets[iDet].Contains(
"SILICON"))
311 cout <<
"Wrong input data! Exiting ..." << endl;
315 const Int_t nLays = 2;
316 TString lays[nLays] = {
"X",
"Y"};
318 for (
size_t iEle = 0; iEle < cont.size(); iEle++) {
320 for (
Int_t iLoc = 0; iLoc <
fNLC; iLoc++)
322 for (
Int_t iGlob = 0; iGlob <
fNGL; iGlob++)
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];
334 Int_t idxUp = idx - 1;
335 Int_t idxMed = idxUp - 1;
336 Int_t idxLow = idxMed - 1;
338 vector<Double_t> globDers = _cont->
GetGlobDers(lays[iLay]);
339 DerGl[idxLow] = globDers[0];
340 DerGl[idxMed] = globDers[1];
341 DerGl[idxUp] = globDers[2];
348 cout << dets[iDet] << endl;
349 cout << lays[iLay] << endl;
351 cout <<
"Loc. ders : ";
352 for (
Int_t iLoc = 0; iLoc <
fNLC; iLoc++)
353 cout << DerLc[iLoc] <<
" ";
355 cout <<
"Glob. ders : ";
356 for (
Int_t iGlob = 0; iGlob <
fNGL; iGlob++)
357 cout << DerGl[iGlob] <<
" ";
359 cout <<
"Meas = " << meas <<
" dMeas = " << dmeas << endl;
369 const Int_t ngl_per_subdetector = 3;
373 fNGL += ngl_per_subdetector *
fDetectorGEM->GetGemStation(iStat)->GetNModules();
377 fNGL += ngl_per_subdetector *
fDetectorSI->GetSiliconStation(iStat)->GetNModules();
381 for (
Int_t iEle = 0; iEle <
fNGL; iEle++)
391 for (
Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
393 cout <<
"Track# " << iTrack << endl;
394 _Mille(DerLc, DerGl, Mille, iTrack);
396 if (iTrack % 1000 == 0 && !
fDebug)
397 cout <<
"Track processed# " << iTrack << endl;
432 FILE* steer = fopen(
"steer.txt",
"w");
433 TString alignType =
"alignment.bin";
434 fprintf(steer,
"%s\n", alignType.
Data());
437 fprintf(steer,
"regularization 1.0\n");
438 fprintf(steer,
"hugecut %G\n",
fHugecut);
441 fprintf(steer,
"entries %d\n",
fEntries);
444 fprintf(steer,
"Parameter\n");
446 Int_t parCounterGem = 0;
447 Int_t parCounterSi = 0;
448 const Int_t nParams = 3;
451 for (
Int_t iMod = 0; iMod <
fDetectorGEM->GetGemStation(iStat)->GetNModules(); iMod++)
455 for (
Int_t iMod = 0; iMod <
fDetectorSI->GetSiliconStation(iStat)->GetNModules(); iMod++)
462 for (
Int_t iPar = 0; iPar <
fDetectorGEM->GetGemStation(iStat)->GetNModules() * nParams; iPar++) {
464 fprintf(steer,
"%d %G %G\n",
Labels[startIdx + iPar], 0., -1.);
466 fprintf(steer,
"%d %G %G\n",
Labels[startIdx + iPar], 0.,
469 startIdx +=
fDetectorGEM->GetGemStation(iStat)->GetNModules() * nParams;
471 }
else if (iDet == 1) {
473 for (
Int_t iPar = 0; iPar <
fDetectorSI->GetSiliconStation(iStat)->GetNModules() * nParams; iPar++) {
475 fprintf(steer,
"%d %G %G\n",
Labels[startIdx + iPar], 0., -1.);
477 fprintf(steer,
"%d %G %G\n",
Labels[startIdx + iPar], 0.,
482 startIdx +=
fDetectorSI->GetSiliconStation(iStat)->GetNModules() * nParams;
493 map<pair<Int_t, Int_t>,
Double_t> z_GEM;
494 map<pair<Int_t, Int_t>,
Double_t> z_SI;
498 for (
Int_t iMod = 0; iMod <
fDetectorGEM->GetGemStation(iStat)->GetNModules(); iMod++)
500 z_GEM[pair<Int_t, Int_t>(iStat, iMod)] =
501 fDetectorGEM->GetGemStation(iStat)->GetModule(iMod)->GetZPositionRegistered();
506 for (
Int_t iMod = 0; iMod <
fDetectorSI->GetSiliconStation(iStat)->GetNModules(); iMod++)
508 z_SI[pair<Int_t, Int_t>(iStat, iMod)] =
509 fDetectorSI->GetSiliconStation(iStat)->GetModule(iMod)->GetZPositionRegistered();
513 for (
auto it : z_GEM)
519 Double_t zC = zSum / (z_GEM.size() + z_SI.size());
520 cout << zC <<
" " << z_GEM.size() + z_SI.size() << endl;
523 map<pair<Int_t, Int_t>,
Double_t> dZ_GEM;
524 map<pair<Int_t, Int_t>,
Double_t> dZ_SI;
526 for (
auto it : z_GEM)
527 dZ_GEM[it.first] = it.second - zC;
530 dZ_SI[it.first] = it.second - zC;
532 map<Int_t, Double_t> deltas;
534 for (
auto it : dZ_GEM) {
535 Int_t stat = it.first.first;
536 Int_t mod = it.first.second;
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;
545 for (
auto it : dZ_SI) {
546 Int_t stat = it.first.first;
547 Int_t mod = it.first.second;
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;
563 for (
Int_t iRemain = 0; iRemain < nParams; iRemain++) {
564 fprintf(steer,
"constraint 0.0\n");
566 for (
Int_t iPar = 0; iPar < parCounterGem * nParams; iPar++) {
570 fprintf(steer,
"%d %G\n",
Labels[iPar], 1.);
574 for (
Int_t iPar = parCounterGem * nParams; iPar <
fNGL; iPar++) {
578 fprintf(steer,
"%d %G\n",
Labels[iPar], 1.);
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) {
592 fprintf(steer,
"%d %G\n", it.first, it.second);
597 fprintf(steer,
"%d %G\n", it.first, it.second);
606 system(
"pede steer.txt");
607 ifstream resFile(
"millepede.res", ios::in);
615 cout <<
"BmnGlobalAlignment::ReadPedeOutput" <<
" No input file found!!" << endl;
618 resFile.ignore(numeric_limits<streamsize>::max(),
'\n');
620 const Int_t nParams = 3;
625 for (
Int_t iMod = 0; iMod <
fDetectorGEM->GetGemStation(iStat)->GetNModules(); iMod++) {
637 for (
Int_t iMod = 0; iMod <
fDetectorSI->GetSiliconStation(iStat)->GetNModules(); iMod++) {
652 const Int_t nParams = 3;
653 TString parValue =
"", dummy =
"";
656 for (
Int_t iCorr = 0; iCorr < nParams; iCorr++)
658 for (
Int_t iLine = 0; iLine < nParams; iLine++) {
659 getline(resFile, line);
660 stringstream ss(line);
661 Int_t size = ss.str().length();
664 ss >> dummy >> parValue >> dummy;
666 ss >> dummy >> parValue >> dummy >> dummy >> dummy;
668 cout <<
"Unsupported format given!" << endl;
670 Int_t idx = (iLine % nParams == 0) ? 0 : (iLine % nParams == 1) ? 1 : 2;
671 corrs[idx] = -parValue.
Atof();
682 TString confSi =
"SiliconRun" +
TString(isSRC ?
"SRC" :
"") +
"Spring2018.xml";
683 TString confGem =
"GemRun" +
TString(isSRC ?
"SRC" :
"") +
"Spring2018.xml";
686 TString gPathSiliconConfig = gPathConfig +
"/parameters/silicon/XMLConfigs/";
696 for (
Int_t iMod = 0; iMod <
fDetectorSI->GetSiliconStation(iStat)->GetNModules(); iMod++)
700 TString gPathGemConfig = gPathConfig +
"/parameters/gem/XMLConfigs/";
710 for (
Int_t iMod = 0; iMod <
fDetectorGEM->GetGemStation(iStat)->GetNModules(); iMod++)
R__EXTERN TSystem * gSystem
void SetCorrections(Double_t x, Double_t y, Double_t z)
void SetModule(Int_t num)
void SetStation(Int_t num)
map< Int_t, pair< vector< BmnMilleContainer * >, vector< BmnMilleContainer * > > > fCONTAINER
virtual ~BmnGlobalAlignment()
void ExtractCorrValues(ifstream &, Double_t *)
Bool_t ** fixedGemElements
TClonesArray * fGlobalTracks
TClonesArray * fSiAlignCorr
static Int_t fCurrentEvent
TClonesArray * fGemTracks
BmnGemStripStationSet * fDetectorGEM
virtual InitStatus Init()
TString fBranchSiAlignCorr
Bool_t ** fixedSiElements
TString fBranchFairEventHeader
Double_t fMinHitsAccepted
BmnSiliconStationSet * fDetectorSI
Bool_t fUseRegularization
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
Int_t fOutlierdownweighting
TString fBranchGemAlignCorr
vector< Int_t > GetSiliconStatMod(Int_t label)
TClonesArray * fBmnGemMisalign
void _Mille(Double_t *, Double_t *, BmnMille *, Int_t)
TClonesArray * fGemAlignCorr
void CreateDetectorGeometries()
TClonesArray * fSilTracks
void ReadPedeOutput(ifstream &)
const Int_t MakeBinFile()
BmnMilleContainer * FillMilleContainer(BmnGlobalTrack *, BmnHit *)
TString fBranchGlobalTracks
Int_t GemStatModLabel(Int_t st, Int_t mod)
TString fBranchGemResiduals
vector< Int_t > GetGemStatMod(Int_t label)
Short_t GetStation() const
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.
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.
void SetModule(Int_t num)
void SetStation(Int_t num)
FairTrackParam * GetParamFirst()
Int_t GetNHits() const
Accessors.
Int_t GetHitIndex(Int_t iHit) const
int LoadSetupToGeoManager(string_view setup_tag)
Load selected geometry setup from the Local Geometry Database and create gGeoManager instance.
string GetLastApprovedSetupTag(string_view tag_prefix)
Get tag for the last approved setup corresponding to the pattern.
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
const char * Data() const
static TString Format(const char *fmt,...)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
UniRun.h Class for the table: run_.
static UniRun * GetRun(int period_number, int run_number)
get run from the database
double * GetFieldVoltage()
get field voltage of the current run