BmnRoot 26.10.0-19-g6979a6c6
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
update_align_corrections_bmn.C
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2// This macro updates the cumulative mis-alignment parameters; it is only called
3// when the "previous" misalignment file already exists someway: either we use
4// the defaults, or start using this macro only from the second iteration...
5//
6// Anatoly.Solomin@jinr.ru 2017-02-16
7
8void update_align_corrections_bmn(TString preAlignCorrFileName,
9 TString newAlignCorrFileName,
10 TString sumAlignCorrFileName)
11{
12 gROOT->LoadMacro("$VMCWORKDIR/macro/run/bmnloadlibs.C");
13 bmnloadlibs(); // load BmnRoot libraries
14 // get run period
15 TString runPeriod = newAlignCorrFileName; // just to start with
16 TPRegexp("bmn_run([\\d]+)[\\w\\d\\.]+").Substitute(runPeriod, "$1");
17 int run_period = runPeriod.Atoi();
18 cout << "run_period = " << run_period << endl;
19
20 // Define GEM config. to be used: RunWinter2016 or RunSpring2017
21 BmnGemStripStationSet* stationSet;
22 TString GemAlignCorrBranchName;
23 if (run_period == 6) {
25 GemAlignCorrBranchName = "BmnGemAlignCorrections";
26 } else if (run_period == 5) {
28 GemAlignCorrBranchName = "BmnGemAlignCorrections";
29 }
30 TFile* preFile = new TFile(preAlignCorrFileName.Data());
31 TTree* preTree = (TTree*)preFile->Get("cbmsim");
32 cout << "preTree->Print()" << endl;
33 preTree->Print();
34 TClonesArray* preCorrs = new TClonesArray(GemAlignCorrBranchName);
35 TBranch* b_preCorrs = preTree->GetBranch(GemAlignCorrBranchName);
36 b_preCorrs->SetAddress(&preCorrs);
37
38 TFile* newFile = new TFile(newAlignCorrFileName.Data());
39 TTree* newTree = (TTree*)newFile->Get("cbmsim");
40 cout << "newTree->Print()" << endl;
41 newTree->Print();
42 TClonesArray* newCorrs = new TClonesArray(GemAlignCorrBranchName);
43 newTree->SetBranchAddress(GemAlignCorrBranchName, &newCorrs);
44
45 TFile* sumFile = new TFile(sumAlignCorrFileName.Data(), "RECREATE");
46 TTree* sumTree = new TTree("cbmsim", "sum");
47 TClonesArray* sumCorrs = new TClonesArray(GemAlignCorrBranchName);
48 TClonesArray& sumCorrsRef = *sumCorrs;
49 sumTree->Branch(GemAlignCorrBranchName, &sumCorrs);
50 cout << "sumTree->Print()" << endl;
51 sumTree->Print();
52
53 const Int_t nStat = stationSet->GetNStations();
54 const Int_t nParams = 3;
55 Double_t*** corr = new Double_t**[nStat];
56 for (Int_t iStat = 0; iStat < nStat; iStat++) {
57 Int_t nModul = stationSet->GetGemStation(iStat)->GetNModules();
58 corr[iStat] = new Double_t*[nModul];
59 for (Int_t iMod = 0; iMod < nModul; iMod++) {
60 corr[iStat][iMod] = new Double_t[nParams];
61 for (Int_t iPar = 0; iPar < nParams; iPar++) {
62 corr[iStat][iMod][iPar] = 0.;
63 }
64 }
65 }
66 for (Int_t iEntry = 0; iEntry < (Int_t)preTree->GetEntries(); iEntry++) {
67 // cout <<"iEntry = "<<iEntry<< endl;
68 preTree->GetEntry(iEntry);
69 // cout <<"(Int_t)preCorrs->GetEntriesFast() = "<<(Int_t)preCorrs->GetEntriesFast()<< endl;
70 if ((Int_t)preCorrs->GetEntriesFast() > 0)
71 break;
72 }
73 for (Int_t iEntry = 0; iEntry < (Int_t)newTree->GetEntries(); iEntry++) {
74 // cout <<"iEntry = "<<iEntry<< endl;
75 newTree->GetEntry(iEntry);
76 // cout <<"(Int_t)newCorrs->GetEntriesFast() = "<<(Int_t)newCorrs->GetEntriesFast()<< endl;
77 if ((Int_t)newCorrs->GetEntriesFast() > 0)
78 break;
79 }
80 for (Int_t iCorr = 0; iCorr < (Int_t)newCorrs->GetEntriesFast(); iCorr++) {
81 cout << "iCorr = " << iCorr << endl;
82 BmnGemAlignCorrections* preCorr = (BmnGemAlignCorrections*)preCorrs->At(iCorr);
83 Int_t iStat = preCorr->GetStation();
84 Int_t iMod = preCorr->GetModule();
85 BmnGemAlignCorrections* newCorr = (BmnGemAlignCorrections*)newCorrs->At(iCorr);
86 BmnGemAlignCorrections* sumCorr = new (sumCorrsRef[iCorr]) BmnGemAlignCorrections();
87 sumCorr->SetStation(iStat);
88 sumCorr->SetModule(iMod);
89 sumCorr->SetCorrections(preCorr->GetCorrections().X() + newCorr->GetCorrections().X(),
90 preCorr->GetCorrections().Y() + newCorr->GetCorrections().Y(),
91 preCorr->GetCorrections().Z() + newCorr->GetCorrections().Z());
92 cout << "preCorr: Stat " << iStat << " Module " << iMod << " Param. " << 0 << " Value (in cm.) "
93 << TString::Format("% 14.11f", preCorr->GetCorrections().X()) << endl;
94 cout << "newCorr: Stat " << iStat << " Module " << iMod << " Param. " << 0 << " Value (in cm.) "
95 << TString::Format("% 14.11f", newCorr->GetCorrections().X()) << endl;
96 cout << "sumCorr: Stat " << iStat << " Module " << iMod << " Param. " << 0 << " Value (in cm.) "
97 << TString::Format("% 14.11f", sumCorr->GetCorrections().X()) << endl;
98 cout << endl;
99 cout << "preCorr: Stat " << iStat << " Module " << iMod << " Param. " << 1 << " Value (in cm.) "
100 << TString::Format("% 14.11f", preCorr->GetCorrections().Y()) << endl;
101 cout << "newCorr: Stat " << iStat << " Module " << iMod << " Param. " << 1 << " Value (in cm.) "
102 << TString::Format("% 14.11f", newCorr->GetCorrections().Y()) << endl;
103 cout << "sumCorr: Stat " << iStat << " Module " << iMod << " Param. " << 1 << " Value (in cm.) "
104 << TString::Format("% 14.11f", sumCorr->GetCorrections().Y()) << endl;
105 cout << endl;
106 cout << "preCorr: Stat " << iStat << " Module " << iMod << " Param. " << 2 << " Value (in cm.) "
107 << TString::Format("% 14.11f", preCorr->GetCorrections().Z()) << endl;
108 cout << "newCorr: Stat " << iStat << " Module " << iMod << " Param. " << 2 << " Value (in cm.) "
109 << TString::Format("% 14.11f", newCorr->GetCorrections().Z()) << endl;
110 cout << "sumCorr: Stat " << iStat << " Module " << iMod << " Param. " << 2 << " Value (in cm.) "
111 << TString::Format("% 14.11f", sumCorr->GetCorrections().Z()) << endl;
112 cout << endl;
113 corr[iStat][iMod][0] = sumCorr->GetCorrections().X();
114 corr[iStat][iMod][1] = sumCorr->GetCorrections().Y();
115 corr[iStat][iMod][2] = sumCorr->GetCorrections().Z();
116 }
117 sumTree->Fill();
118 sumFile->cd();
119 sumTree->Write("", TObject::kOverwrite);
120 delete preFile;
121 delete newFile;
122 delete sumFile;
123 delete stationSet;
124 delete corr;
125}
int Int_t
double Double_t
#define gROOT
void SetCorrections(Double_t x, Double_t y, Double_t z)
BmnGemStripStation * GetGemStation(Int_t station_num)
virtual void SetAddress(void *add)
Bool_t cd() override
T * Get(const char *namecycle)
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
Int_t Substitute(TString &s, const TString &replace, const TString &mods="", Int_t start=0, Int_t nMatchMax=10)
Int_t Atoi() const
const char * Data() const
static TString Format(const char *fmt,...)
virtual Int_t Fill()
virtual TBranch * GetBranch(const char *name)
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
void Print(Option_t *option="") const override
virtual Long64_t GetEntries() const
Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0) const override
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
virtual Int_t Branch(const char *folder, Int_t bufsize=32000, Int_t splitlevel=99)
Double_t Z() const
Double_t Y() const
Double_t X() const
void update_align_corrections_bmn(TString preAlignCorrFileName, TString newAlignCorrFileName, TString sumAlignCorrFileName)