BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
create_stsdigipar_gem.C
Go to the documentation of this file.
1/******************************************************************************
2 ** Creation of STS digitisation parameter file in ASCII format.
3 **
4 ** @file create_stsdigipar_v12.C
5 ** @author Volker Friese <v.friese@gsi.de>
6 ** @since 21 June 2012
7 ** @date 21.06.2012
8 ** @Modified by Alexander Zinchenko for BM@N GEM STS
9 ** @date 21.12.2013
10 **
11 ** This macro is compatible with geometries created with create_geometry_v12.C
12 **
13 ** The digitisation properties are the same for all sensors.
14 ** The numbering of modules (sectors) is consecutively in each station,
15 ** in the order given by the geometry. This has to be the same in
16 ** CbmStsDigiScheme::Init().
17 *****************************************************************************/
18
19#include "TString.h"
20
21#include <cstdio>
22#include <iostream>
23
24using namespace std;
25
26// ------------- Steering variables -----------------------------------
27
28// ---> Sensor digitisation type.
29// ---> 1 = pixel sensor, 2 = double-sided strip sensor,
30// ---> 3 = double-sided strip sensor with double metal layer
32
33// ---> Size of guard ring. It defines an inactive border on each side of the
34// ---> sensor. MCPoints in this area will not be processed.
36
37// ---> Strip pitch on front and back side
40// Double_t gkStripPitchFront = 0.0058;
41// Double_t gkStripPitchBack = 0.0058;
42
43// ---> Strip stereo angle on front and back side
46
47// ---> Geometry and digitisation tags
50// ----------------------------------------------------------------------------
51
52// ------------- Other global variables -----------------------------------
53// ---> TGeoManager (too lazy to write out 'Manager' all the time
54TGeoManager* geoMan = NULL; // will be set later
55// ----------------------------------------------------------------------------
56
57// ============================================================================
58// ====== Main function =====
59// ============================================================================
60void create_stsdigipar_gem(const char* geoTag = gkGeoTag, const char* digiTag = gkDigiTag)
61{
62
63 // ---> Open parameter file
64 TString parFileName = "sts_";
65 parFileName = parFileName + geoTag + "_" + digiTag + ".digi.par";
66 FILE* parFile;
67 parFile = fopen(parFileName.Data(), "w");
68 if (!parFile) {
69 cout << "-E- Could not open parameter " << parFileName << endl;
70 exit(0);
71 }
72 fprintf(parFile, "%s\n", "[CbmStsDigiPar]");
73
74 // ---> Read geometry from file
75 TString geoPath = getenv("VMCWORKDIR");
76 // TString geoFileName = geoPath + "/geometry/sts/sts_";
77 // geoFileName = geoFileName + geoTag + ".geo.root";
78 TString geoFileName = "data/geofile_full.root";
79 Bool_t init = CreateGeoFromFile(geoFileName.Data());
80 if (!init) {
81 cout << "-E- Could not read STS geometry!" << endl;
82 exit(0);
83 }
85
86 // ---> Top node
87 geoMan->CdTop();
88 TGeoNode* cave = geoMan->GetCurrentNode();
89 cout << "Top node: " << cave->GetName() << ", daughters: " << cave->GetNdaughters() << endl;
90
91 // ---> STS
92 if (!geoMan->cd("STS1_0")) {
93 cout << "-E- Mother volume sts1 not found " << endl;
94 exit(0);
95 }
96
97 TGeoNode* sts = geoMan->GetCurrentNode();
98 if (!TString(sts->GetName()).Contains("STS")) {
99 cout << "-E- Illegal STS node name " << sts->GetName() << endl;
100 exit(0);
101 }
102 cout << "STS node: " << sts->GetName() << ", daughters: " << sts->GetNdaughters()
103 << ", stations: " << GetNofDaughters(sts, "Station") << endl;
104
105 // ---> Stations
106 Int_t statNr = 0; // AZ
107 for (Int_t iCaveD = 0; iCaveD < sts->GetNdaughters(); iCaveD++) {
108 geoMan->CdDown(iCaveD);
109 TGeoNode* station = geoMan->GetCurrentNode();
110 if (!TString(station->GetName()).Contains("Station")) {
111 geoMan->CdUp();
112 continue;
113 }
114 // AZ Int_t statNr = station->GetNumber();
115 ++statNr;
116 if (statNr > 4)
117 gkStripPitchFront = gkStripPitchBack = 0.08; // 800 um
118 Int_t nModules = GetNofModules(station);
119 cout << "Station Nr. " << statNr << ", node " << station->GetName() << ", modules: " << nModules << endl;
120 fprintf(parFile, "%d %d %d\n", statNr, 0, nModules);
121 Int_t moduleNr = 0; // Running module number
122 TGeoMatrix* matrixSt = geoMan->GetCurrentMatrix();
123 Double_t* rot = matrixSt->GetRotationMatrix();
124 Double_t phiStat = -TMath::ASin(rot[1]) * TMath::RadToDeg();
125 gkStereoBack *= -1;
126
127 // ---> Ladders
128 for (Int_t iStatD = 0; iStatD < station->GetNdaughters(); iStatD++) {
129 geoMan->CdDown(iStatD);
130 TGeoNode* ladder = geoMan->GetCurrentNode();
131
132 // ---> Halfladders
133 for (Int_t iLadD = 0; iLadD < ladder->GetNdaughters(); iLadD++) {
134 geoMan->CdDown(iLadD);
135 TGeoNode* hLadder = geoMan->GetCurrentNode();
136
137 // ---> Modules
138 for (Int_t iHladD = 0; iHladD < hLadder->GetNdaughters(); iHladD++) {
139 geoMan->CdDown(iHladD);
140 TGeoNode* module = geoMan->GetCurrentNode();
141 if (!TString(module->GetName()).Contains("Module")) {
142 geoMan->CdUp();
143 continue;
144 }
145 moduleNr++;
146 fprintf(parFile, "%4d %4d\n", moduleNr, GetNofDaughters(module, "Sensor"));
147
148 // ---> Sensors
149 for (Int_t iModD = 0; iModD < module->GetNdaughters(); iModD++) {
150 geoMan->CdDown(iModD);
151 TGeoNode* sensor = geoMan->GetCurrentNode();
152 if (!TString(sensor->GetName()).Contains("Sensor")) {
153 geoMan->CdUp();
154 continue;
155 }
156
157 // ---> Sensor number
158 Int_t sensNr = 1; // sensor->GetNumber();
159
160 // ---> Get sensor position
161 TGeoMatrix* matrix = geoMan->GetCurrentMatrix();
162 Double_t* xTrans = matrix->GetTranslation();
163
164 // ---> Get sensor angle.
165 // Sensors in lower half of station will be read out to bottom.
166 Int_t phi = 0.;
167 if (xTrans[1] < 0.)
168 phi = 180;
169
170 // ---> Get sensor size
171 TGeoBBox* shape = (TGeoBBox*)sensor->GetVolume()->GetShape();
172 Double_t dx = 2. * shape->GetDX();
173 Double_t dy = 2. * shape->GetDY();
174 Double_t dz = 2. * shape->GetDZ();
175 // AZ
176 Double_t* rot = matrix->GetRotationMatrix();
177 // if (TMath::Abs(rot[1]) > 0.9) {
178 if (iStatD % 2) {
179 // Rotation by 90 deg
180 Double_t dy = 2. * shape->GetDX();
181 Double_t dx = 2. * shape->GetDY();
182 }
183 // AZ
184
185 // ---> Subtract guard rings
186 // dx -= 2 * gkGuardRingWidth;
187 // dy -= 2 * gkGuardRingWidth;
188
189 // ---> Write sensor information
190 fprintf(parFile,
191 //"%6d %6d %9.3f %9.3f %9.3f %8d %8.2f %8.2f %8.2f %8.4f %8.4f %8.2f %8.2f\n",
192 "%6d %6d %9.3f %9.3f %9.3f %8.2f %8.2f %8.2f %8.2f %8.4f %8.4f %8.2f %8.2f\n",
193 // AZ sensNr, gkSensorType, xTrans[0], xTrans[1], xTrans[2], phi,
194 sensNr, gkSensorType, xTrans[0], xTrans[1], xTrans[2], phiStat, dx, dy, dz,
196
197 geoMan->CdUp(); // back to module
198 } // sensor loop
199 geoMan->CdUp(); // back to halfladder
200 } // module loop
201 geoMan->CdUp(); // back to ladder
202 } // halfladder loop
203 geoMan->CdUp(); // back to station
204 } // ladder loop
205 geoMan->CdUp(); // back to sts
206 } // station loop
207
208 delete geoMan;
209 fclose(parFile);
210 cout << "-I- Parameters successfully written to " << parFileName << endl;
211}
212// ============================================================================
213// ====== End of main function =====
214// ============================================================================
215
216/** ===========================================================================
217 ** CreateGeoFromFile
218 **
219 ** Create geometry, read STS node from file and add it to geometry.
220 **/
221Bool_t CreateGeoFromFile(const char* fileName)
222{
223
224 // ---> Create TGeoManager and top node (cave)
225 geoMan = new TGeoManager("CBM STS", "STS Geometry");
226 TGeoVolume* cave = geoMan->MakeBox("Cave", NULL, 2000., 2000., 2000.);
227 geoMan->SetTopVolume(cave);
228
229 // ---> Open geometry file
230 cout << "Reading geometry from file " << fileName << endl;
231 TFile* geoFile = new TFile(fileName, "READ");
232 if (!geoFile->IsOpen()) {
233 cout << "-E- Could not open file!" << endl;
234 return kFALSE;
235 }
236
237 // ---> Get STS node from file
238 TList* keyList = geoFile->GetListOfKeys();
239 TIter next(keyList);
240 TKey* key = NULL;
241 TGeoVolume* top = NULL;
242 while ((key = (TKey*)next())) {
243 TString className(key->GetClassName());
244 if (className.BeginsWith("TGeoVolume")) {
245 top = dynamic_cast<TGeoVolume*>(key->ReadObj());
246 std::cout << "Found volume " << top->GetName() << endl;
247 break;
248 }
249 // AZ
250 if (className.BeginsWith("TGeoManager")) {
251 // File with full geometry
252 // geoMan = dynamic_cast<TGeoManager*> (key->ReadObj() );
253 key->ReadObj();
254 std::cout << "Found GeoManager " << gGeoManager->GetName() << endl;
255 return kTRUE;
256 }
257 // AZ
258 }
259 if (!top) {
260 cout << "-E- Could not find volume object in file" << endl;
261 return kFALSE;
262 }
263 TGeoVolume* sts = top->GetNode(0)->GetVolume();
264 TString stsName = sts->GetName();
265 if (!stsName.BeginsWith("STS")) {
266 cout << "-E- No STS volume found on second level" << endl;
267 return kFALSE;
268 }
269 TString stsVersion = stsName;
270 stsVersion.Remove(0, 4);
271 cout << "Geometry version " << stsVersion << endl;
272 top->GetNode(0)->InspectNode();
273
274 // ---> Add STS node to cave
275 TGeoMatrix* stsmatrix = top->GetNode(0)->GetMatrix();
276 cave->AddNode(sts, 0, stsmatrix);
277
278 // ---> Finish geometry and close geometry file
279 geoMan->CloseGeometry();
280 geoFile->Close();
281
282 return kTRUE;
283}
284/** ======================================================================= **/
285
287{
288
289 Int_t nModules = 0;
290
291 // --- Ladder
292 Int_t nLadders = station->GetNdaughters();
293 for (Int_t iLadder = 0; iLadder < nLadders; iLadder++) {
294 TGeoNode* ladder = station->GetDaughter(iLadder);
295
296 // --- Halfladder
297 Int_t nHladders = ladder->GetNdaughters();
298 for (Int_t iHladder = 0; iHladder < nHladders; iHladder++) {
299 TGeoNode* hladder = ladder->GetDaughter(iHladder);
300
301 // --- Modules
302 for (Int_t iModule = 0; iModule < hladder->GetNdaughters(); iModule++) {
303 TGeoNode* module = hladder->GetDaughter(iModule);
304 if (TString(module->GetName()).Contains("Module"))
305 nModules++;
306 }
307 }
308 }
309
310 return nModules;
311}
312
313Int_t GetNofDaughters(TGeoNode* node, const char* name)
314{
315 Int_t nDaughters = 0;
316 for (Int_t iNode = 0; iNode < node->GetNdaughters(); iNode++)
317 if (TString(node->GetDaughter(iNode)->GetName()).Contains(name))
318 nDaughters++;
319 return nDaughters;
320}
bool Bool_t
int Int_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
R__EXTERN TGeoManager * gGeoManager
TList * GetListOfKeys() const override
virtual Bool_t IsOpen() const
void Close(Option_t *option="") override
virtual Double_t GetDX() const
virtual Double_t GetDZ() const
virtual Double_t GetDY() const
virtual const Double_t * GetTranslation() const=0
virtual const Double_t * GetRotationMatrix() const=0
TGeoVolume * GetVolume() const
Int_t GetNdaughters() const
TGeoNode * GetDaughter(Int_t ind) const
virtual TGeoMatrix * GetMatrix() const=0
void InspectNode() const
virtual TGeoNode * AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=nullptr, Option_t *option="")
TGeoNode * GetNode(const char *name) const
TGeoShape * GetShape() const
const char * GetName() const override
const char * Data() const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
TString & Remove(EStripType s, char c)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Int_t GetNofDaughters(TGeoNode *node, const char *name)
Double_t gkStripPitchBack
TString gkDigiTag
Int_t GetNofModules(TGeoNode *station)
=======================================================================
Bool_t CreateGeoFromFile(const char *fileName)
=========================================================================== CreateGeoFromFile
Double_t gkStereoBack
TString gkGeoTag
Double_t gkStripPitchFront
Double_t gkGuardRingWidth
void create_stsdigipar_gem(const char *geoTag=gkGeoTag, const char *digiTag=gkDigiTag)
TGeoManager * geoMan
Int_t gkSensorType
Double_t gkStereoFront
Double_t ASin(Double_t)
constexpr Double_t RadToDeg()
Definition json.hpp:4446