16 Bool_t ShiftX = kTRUE;
17 Bool_t ShiftY = kTRUE;
18 Bool_t ShiftZ = kFALSE;
26 std::map<UInt_t, std::pair<TString, TGeoCombiTrans*>> misalignInfo;
29 TString mcEngine =
"TGeant3";
30 TString dir = getenv(
"VMCWORKDIR");
32 TString outDir =
"./data/";
34 TString geoFile =
"makeGeoFile_";
35 geoFile = outDir + geoFile + mcEngine +
"_full.root";
37 TFile* f =
new TFile(geoFile,
"READ");
39 std::cout <<
"Could not open the file" << std::endl;
43 TList* l = f->GetListOfKeys();
48 TGeoManager* geoMan{
nullptr};
50 while ((key = (TKey*)next())) {
51 if (key->ReadObj()->InheritsFrom(
"TGeoManager")) {
52 geoMan =
static_cast<TGeoManager*
>(key->ReadObj());
59 std::cout <<
"Could not find TGeoManager inside the file" << std::endl;
70 TGeoNode* topNode = gGeoManager->GetTopNode();
71 TObjArray* nodes = topNode->GetNodes();
72 for (Int_t iNode = 0; iNode < nodes->GetEntriesFast(); iNode++) {
73 TGeoNode* node =
static_cast<TGeoNode*
>(nodes->At(iNode));
74 if (!TString(node->GetName()).Contains(
"tutorial4"))
76 TGeoNode* station = node;
77 TObjArray* layers = station->GetNodes();
78 for (Int_t iLayer = 0; iLayer < layers->GetEntriesFast(); iLayer++) {
79 TGeoNode* layer =
static_cast<TGeoNode*
>(layers->At(iLayer));
80 TString path = TString(
"/") + topNode->GetName() +
"/" + station->GetName() +
"/" + layer->GetName();
82 UInt_t hash = path.Hash();
84 shiftx = gRandom->Uniform(-1., 1.);
87 shifty = gRandom->Uniform(-1., 1.);
90 shiftz = gRandom->Uniform(-1., 1.);
93 TGeoTranslation* trans{
nullptr};
94 TGeoRotation* rot{
nullptr};
95 if (iLayer > 0 & iLayer < layers->GetEntriesFast() - 1) {
96 trans =
new TGeoTranslation(shiftx, shifty, shiftz);
97 rot =
new TGeoRotation(
"temp", rotx, roty, rotz);
99 trans =
new TGeoTranslation(0., 0., 0.);
100 rot =
new TGeoRotation(
"temp", 0., 0., 0.);
102 TGeoCombiTrans* combi =
new TGeoCombiTrans(*trans, *rot);
104 if (misalignInfo.find(hash) != misalignInfo.end()) {
105 cerr <<
"[ERROR ] Hash collision" << endl;
106 cerr <<
"[ERROR ] Hash value " << hash <<
" already exist." << endl;
107 auto it = misalignInfo.find(hash);
108 cerr <<
"[ERROR ] TGeoNode: " << it->second.first <<
" and " << path <<
" both have hash " << hash
110 cerr <<
"[FATAL ] This should never happen. Stop execution." << endl;
114 misalignInfo[hash] = make_pair(path, combi);
121 cout <<
"There are in total " << misalignInfo.size() <<
" misalligned nodes" << endl;
123 for (
auto& elem : misalignInfo) {
124 cout <<
"Module " << elem.first <<
" " << elem.second.first <<
" " << elem.second.second << endl;
129 myfile.open(
"example.par");
131 myfile <<
"##############################################################################" << endl;
132 myfile <<
"# Class: FairTutorialDetMissallignPar" << endl;
133 myfile <<
"# Context: TestDefaultContext" << endl;
134 myfile <<
"##############################################################################" << endl;
135 myfile <<
"[FairTutorialDetMissallignPar]" << endl;
136 myfile <<
"//----------------------------------------------------------------------------" << endl;
137 myfile <<
"NrOfDetectors: Int_t " << misalignInfo.size() << endl;
141 std::vector<Double_t> r11;
142 std::vector<Double_t> r12;
143 std::vector<Double_t> r13;
144 std::vector<Double_t> r21;
145 std::vector<Double_t> r22;
146 std::vector<Double_t> r23;
147 std::vector<Double_t> r31;
148 std::vector<Double_t> r32;
149 std::vector<Double_t> r33;
150 std::vector<Double_t> tx;
151 std::vector<Double_t> ty;
152 std::vector<Double_t> tz;
153 std::vector<TString> path;
154 std::vector<UInt_t> hash;
158 myfile <<
"DetectorId: UInt_t \\ " << endl;
160 for (
auto& elem : misalignInfo) {
161 const Double_t* rotation = elem.second.second->GetRotationMatrix();
162 const Double_t* translation = elem.second.second->GetTranslation();
163 r11.push_back(rotation[0]);
164 r12.push_back(rotation[1]);
165 r13.push_back(rotation[2]);
166 r21.push_back(rotation[3]);
167 r22.push_back(rotation[4]);
168 r23.push_back(rotation[5]);
169 r31.push_back(rotation[6]);
170 r32.push_back(rotation[7]);
171 r33.push_back(rotation[8]);
172 tx.push_back(translation[0]);
173 ty.push_back(translation[1]);
174 tz.push_back(translation[2]);
175 hash.push_back(elem.first);
176 path.push_back(elem.second.first);
178 if ((8 == counter)) {
179 myfile << elem.first <<
" \\" << endl;
183 myfile << elem.first <<
" ";
197 myfile <<
"R11: Double_t \\ " << endl;
200 myfile <<
"R12: Double_t \\ " << endl;
203 myfile <<
"R13: Double_t \\ " << endl;
207 myfile <<
"R21: Double_t \\ " << endl;
210 myfile <<
"R22: Double_t \\ " << endl;
213 myfile <<
"23: Double_t \\ " << endl;
217 myfile <<
"R31: Double_t \\ " << endl;
220 myfile <<
"R32: Double_t \\ " << endl;
223 myfile <<
"33: Double_t \\ " << endl;
227 myfile <<
"TX: Double_t \\ " << endl;
230 myfile <<
"TY: Double_t \\ " << endl;
233 myfile <<
"TZ: Double_t \\ " << endl;
237 myfile <<
"##############################################################################" << endl;
264 myfile.open(
"misalignment.txt");
265 for (
auto& elem : misalignInfo) {
266 const Double_t* rotation = elem.second.second->GetRotationMatrix();
267 const Double_t* translation = elem.second.second->GetTranslation();
268 myfile <<
"Module " << elem.first <<
" " << elem.second.first <<
" " << rotation[0] <<
" " << rotation[1] <<
" "
269 << rotation[2] <<
" " << rotation[3] <<
" " << rotation[4] <<
" " << rotation[5] <<
" " << rotation[6]
270 <<
" " << rotation[7] <<
" " << rotation[8] <<
" " << translation[0] <<
" " << translation[1] <<
" "
271 << translation[2] << endl;
279 for (
auto& elem : vec) {
280 if ((8 == counter)) {
281 *myfile << elem <<
" \\" << endl;
285 *myfile << elem <<
" ";
void run_tutorial4_createParameterFile()
void writeVectorToFile(std::vector< Double_t > &vec, ofstream *myfile)