BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
create_stsdigipar_GEMS.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_GEMS(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 // ---> GEM STS
92 if (!geoMan->cd("GEMS_0")) {
93 cout << "-E- Mother volume GEMS not found " << endl;
94 exit(0);
95 }
96
97 TGeoNode* sts = geoMan->GetCurrentNode();
98 if (!TString(sts->GetName()).Contains("GEMS")) {
99 cout << "-E- Illegal GEMS 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 * 2);
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 // ---> Modules
128 for (Int_t iStatD = 0; iStatD < nModules; iStatD++) {
129 geoMan->CdDown(iStatD);
130
131 TGeoNode* module = geoMan->GetCurrentNode();
132 if (!TString(module->GetName()).Contains("Module")) {
133 geoMan->CdUp();
134 continue;
135 }
136 // moduleNr++;
137 // fprintf(parFile, "%4d %4d\n", moduleNr, GetNofDaughters(module, "Senso"));
138
139 // ---> Sensors
140 for (Int_t iModD = 0; iModD < module->GetNdaughters(); iModD++) {
141 geoMan->CdDown(iModD);
142 TGeoNode* sensor = geoMan->GetCurrentNode();
143 // if ( ! TString(sensor->GetName()).Contains("Sensor") ) {
144 if (!TString(sensor->GetName()).Contains("Senso")) {
145 geoMan->CdUp();
146 continue;
147 }
148
149 moduleNr++;
150 fprintf(parFile, "%4d %4d\n", moduleNr, 1);
151 // ---> Sensor number
152 Int_t sensNr = 1;
153 // Int_t sensNr = sensor->GetNumber();
154
155 // ---> Get sensor position
156 TGeoMatrix* matrix = geoMan->GetCurrentMatrix();
157 Double_t* xTrans = matrix->GetTranslation();
158
159 // ---> Get sensor angle.
160 // Sensors in lower half of station will be read out to bottom.
161 Int_t phi = 0.;
162 if (xTrans[1] < 0.)
163 phi = 180;
164
165 // ---> Get sensor size
166 TGeoBBox* shape = (TGeoBBox*)sensor->GetVolume()->GetShape();
167 Double_t dx = 2. * shape->GetDX();
168 Double_t dy = 2. * shape->GetDY();
169 Double_t dz = 2. * shape->GetDZ();
170 // AZ
171 Double_t* rot = matrix->GetRotationMatrix();
172 // if (TMath::Abs(rot[1]) > 0.9) {
173 if (iStatD % 2) {
174 // Rotation by 90 deg
175 // Double_t dy = 2. * shape->GetDX();
176 // Double_t dx = 2. * shape->GetDY();
177 }
178 // AZ
179
180 // ---> Subtract guard rings
181 // dx -= 2 * gkGuardRingWidth;
182 // dy -= 2 * gkGuardRingWidth;
183
184 // ---> Write sensor information
185 fprintf(parFile,
186 //"%6d %6d %9.3f %9.3f %9.3f %8d %8.2f %8.2f %8.2f %8.4f %8.4f %8.2f %8.2f\n",
187 "%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",
188 // AZ sensNr, gkSensorType, xTrans[0], xTrans[1], xTrans[2], phi,
189 sensNr, gkSensorType, xTrans[0], xTrans[1], xTrans[2], phiStat, dx, dy, dz, gkStripPitchFront,
191
192 geoMan->CdUp(); // back to module
193 } // sensor loop
194 geoMan->CdUp(); // back to module
195 } // module loop
196 geoMan->CdUp(); // back to sts
197 } // station loop
198
199 delete geoMan;
200 fclose(parFile);
201 cout << "-I- Parameters successfully written to " << parFileName << endl;
202}
203// ============================================================================
204// ====== End of main function =====
205// ============================================================================
206
207/** ===========================================================================
208 ** CreateGeoFromFile
209 **
210 ** Create geometry, read STS node from file and add it to geometry.
211 **/
212Bool_t CreateGeoFromFile(const char* fileName)
213{
214
215 // ---> Create TGeoManager and top node (cave)
216 geoMan = new TGeoManager("CBM STS", "STS Geometry");
217 TGeoVolume* cave = geoMan->MakeBox("Cave", NULL, 2000., 2000., 2000.);
218 geoMan->SetTopVolume(cave);
219
220 // ---> Open geometry file
221 cout << "Reading geometry from file " << fileName << endl;
222 TFile* geoFile = new TFile(fileName, "READ");
223 if (!geoFile->IsOpen()) {
224 cout << "-E- Could not open file!" << endl;
225 return kFALSE;
226 }
227
228 // ---> Get STS node from file
229 TList* keyList = geoFile->GetListOfKeys();
230 TIter next(keyList);
231 TKey* key = NULL;
232 TGeoVolume* top = NULL;
233 while ((key = (TKey*)next())) {
234 TString className(key->GetClassName());
235 if (className.BeginsWith("TGeoVolume")) {
236 top = dynamic_cast<TGeoVolume*>(key->ReadObj());
237 std::cout << "Found volume " << top->GetName() << endl;
238 break;
239 }
240 // AZ
241 if (className.BeginsWith("TGeoManager")) {
242 // File with full geometry
243 // geoMan = dynamic_cast<TGeoManager*> (key->ReadObj() );
244 key->ReadObj();
245 std::cout << "Found GeoManager " << gGeoManager->GetName() << endl;
246 return kTRUE;
247 }
248 // AZ
249 }
250 if (!top) {
251 cout << "-E- Could not find volume object in file" << endl;
252 return kFALSE;
253 }
254 TGeoVolume* sts = top->GetNode(0)->GetVolume();
255 TString stsName = sts->GetName();
256 if (!stsName.BeginsWith("STS")) {
257 cout << "-E- No STS volume found on second level" << endl;
258 return kFALSE;
259 }
260 TString stsVersion = stsName;
261 stsVersion.Remove(0, 4);
262 cout << "Geometry version " << stsVersion << endl;
263 top->GetNode(0)->InspectNode();
264
265 // ---> Add STS node to cave
266 TGeoMatrix* stsmatrix = top->GetNode(0)->GetMatrix();
267 cave->AddNode(sts, 0, stsmatrix);
268
269 // ---> Finish geometry and close geometry file
270 geoMan->CloseGeometry();
271 geoFile->Close();
272
273 return kTRUE;
274}
275/** ======================================================================= **/
276
278{
279
280 Int_t nModules = station->GetNdaughters();
281
282 // --- Modules
283 /*
284 for (Int_t iModule = 0; iModule < station->GetNdaughters(); iModule++) {
285 TGeoNode* module = station->GetDaughter(iModule);
286 if ( TString(module->GetName()).Contains("Module") ) nModules++;
287 }
288 */
289
290 return nModules;
291}
292
293Int_t GetNofDaughters(TGeoNode* node, const char* name)
294{
295 Int_t nDaughters = 0;
296 for (Int_t iNode = 0; iNode < node->GetNdaughters(); iNode++)
297 if (TString(node->GetDaughter(iNode)->GetName()).Contains(name))
298 nDaughters++;
299 return nDaughters;
300}
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)
Int_t GetNofModules(TGeoNode *station)
=======================================================================
void create_stsdigipar_GEMS(const char *geoTag=gkGeoTag, const char *digiTag=gkDigiTag)
Bool_t CreateGeoFromFile(const char *fileName)
=========================================================================== CreateGeoFromFile
Double_t gkStripPitchBack
TString gkDigiTag
Double_t gkStereoBack
TString gkGeoTag
Double_t gkStripPitchFront
Double_t gkGuardRingWidth
TGeoManager * geoMan
Int_t gkSensorType
Double_t gkStereoFront
Double_t ASin(Double_t)
constexpr Double_t RadToDeg()
Definition json.hpp:4446