FairRoot/PandaRoot
PndSttMapCreator.cxx
Go to the documentation of this file.
1 // PndSttMapCreator
3 //
4 // Class to create the STT map:
5 // usage: add to your task Init function:
6 // PndSttMapCreator *mapper = new PndSttMapCreator(fSttParameters);
7 // fTubeArray = mapper->FillTubeArray();
8 // with fSttParameters = PndGeoSttPar from params.root file
9 //
10 // authors: Lia Lavezzi - INFN Pavia
11 // [changed to TGeoManager (2013)]
13 
14 #include "PndSttMapCreator.h"
15 #include "PndSttTubeParameters.h"
16 #include "PndSttTube.h"
17 #include "PndGeoSttPar.h"
18 #include "PndSttGeometryMap.h"
19 #include "PndGeoHandling.h"
20 
21 #include "FairGeoNode.h"
22 #include "FairGeoTransform.h"
23 #include "FairGeoVector.h"
24 #include "FairGeoRotation.h"
25 #include "FairGeoTube.h"
26 #include "FairRun.h"
27 
28 #include "TGeoTube.h"
29 #include "TVector3.h"
30 #include "TObjArray.h"
31 #include "TString.h"
32 #include "TGeoVolume.h"
33 #include "TGeoTube.h"
34 #include "TClonesArray.h"
35 #include "TGeoManager.h"
36 #include "TGeoMatrix.h"
37 #include "TGeoVolume.h"
38 #include "TList.h"
39 
40 #include <iostream>
41 
42 using namespace std;
43 
44 PndSttMapCreator::PndSttMapCreator() : fGeoType(-1), fSttParameters(new PndGeoSttPar()), fTubeInRad(0), fTubeOutRad(0), copy_map(), fSttTube(0), fMap(0) {
45  //copy_map.clear();
46 }
47 
48 // to use in PndStt
49 PndSttMapCreator::PndSttMapCreator(Int_t geoType) : fGeoType(geoType), fSttParameters(new PndGeoSttPar()), fTubeInRad(0), fTubeOutRad(0), copy_map(), fSttTube(0), fMap(0) {
50  //copy_map.clear();
51 
52  if(fGeoType > 2) cout << "-E- PndSttMapCreator: geometry not supported by map" << endl; // CHECK
53 
54  if(!gGeoManager) cout << "-E- PndSttMapCreator: no geo manager " << endl; // CHECK
55  // set general par
57 
58 }
59 
60 // crete geometry from parameters file
61 PndSttMapCreator::PndSttMapCreator(PndGeoSttPar *sttPar): fGeoType(-1), fSttParameters(sttPar), fTubeInRad(0), fTubeOutRad(0), fSttTube(0) {
62 
63  if(!gGeoManager) cout << "-E- PndSttMapCreator: no geo manager " << endl; // CHECK
64 
65  // choose geometry type
66  fGeoType = sttPar->GetGeometryType(); // classic, optimized, average, detailed, CAD
67 
68  if(fGeoType > 2) cout << "-E- PndSttMapCreator: geometry not supported by map" << endl; // CHECK
69  // set general par
71 }
72 
74  if (fMap != NULL) delete(fMap);
75 }
76 
77 void PndSttMapCreator::SetGeneralParameters() { // CHECK whether it depends on geometry or not
78  if(fGeoType == 1) {
79  fTubeInRad = 0.5; // tube inner radius cm
80  fTubeOutRad = 0.001; // tube outer radius cm CHECK why not: fTubeInRad + 0.001
81  } else if (fGeoType == 2) {
82  fTubeInRad = 0.5;
83  fTubeOutRad = 0.001; // copy of values from fGeoType 1. I have no clue why fTubeOutRad is 0.001 but it is used nowhere
84  }
85  else {
86  fTubeInRad = -1;
87  fTubeOutRad = -1;
88  }
89 }
90 
91 // during simulation
93  if(fGeoType == 1) return GetTubeIDFromPathGeoType1(path);
94  return -999;
95 }
96 
97 // during parameters reading
99  if(fGeoType == 1) return GetTubeIDFromNameGeoType1(name);
100  return -999;
101 }
102 
103 // retrieve parameters from tube ID
105  if(fGeoType == 1) return GetTubeFromTubeIDGeoType1(tubeid);
106  return NULL;
107 }
108 
110  if(fGeoType == 1) return GetNameFromPathGeoType1(path);
111  return "";
112 }
113 
115  if(fGeoType == 1) return GetPathFromTubeIDGeoType1(tubeid, isCopy);
116  return "";
117 }
118 
119 
121  if(fGeoType == 1) return GetTubeFromParametersToFillGeoType1(parms);
122  return NULL;
123 }
124 
125 
126 
127 // fill the tube map at the beginning of the run
129  if(fGeoType == 1) return FillTubeArrayGeoType1();
130  else if (fGeoType == 2) return FillTubeArrayGeoType2();
131 
132  return NULL;
133 }
134 
135 // fill the tube map at the beginning of the run
137  if(fGeoType == 1) return FillSttTubeParametersGeoType1(par, volList);
138  return -1;
139 }
140 
142  if(fGeoType == 1) return CreateTubeParametersGeoType1(pnode);
143  else if (fGeoType == 2) return CreateTubeParametersGeoType2(pnode);
144 
145  return NULL;
146 }
147 // ------------------- simulation ----------------------------------------------------
148 // during simulation
150  TString tmpstring = GetNameFromPathGeoType1(path);
151  return GetTubeIDFromNameGeoType1(tmpstring);
152 }
153 
154 // OK
155 // name as in geo file: from path "_" to name "#"
157  // two possibilities:
158  // copy : /cave_1/stt01assembly_0/stt01tube_XXX/stt01gas_1 --> stt01tube#XXX
159  // solo : /cave_1/stt01assembly_0/stt01tubeXXX_0/stt01gasXXX_0 --> stt01tubeXXX
160 
161  TString tmpstring = path;
162 
163  // cut /cave_1/stt01assembly_0/
164  TString cavename;
165  cavename = "/cave_1/stt01assembly_0/";
166  tmpstring = tmpstring(cavename.Sizeof() - 1, tmpstring.Sizeof());
167 
168  // cut /stt01gas...
169  int index = tmpstring.Index("/");
170  tmpstring = tmpstring(0, index);
171 
172  // replace _ with #
173  if(tmpstring.Contains("_0")) {
174  tmpstring.Chop(); // cut "0"
175  tmpstring.Chop(); // cut "_"
176  }
177  else{
178  tmpstring.Replace(9, 1, "#");
179  }
180 
181  return tmpstring;
182 }
183 
184 // OK
186  // two possibilities: we DON' T CARE and just take the XXX part
187  // copy : stt01tube#XXX --> XXX
188  // solo : stt01tubeXXX --> XXX
189 
190  TString tmpstring = name;
191 
192  if(tmpstring.Contains("#")) {
193  int start = tmpstring.Index("#") + 1;
194  tmpstring = tmpstring(start, tmpstring.Sizeof());
195  }
196  else{
197  int start = tmpstring.Index("e") + 1;
198  tmpstring = tmpstring(start, tmpstring.Sizeof());
199  }
200  return tmpstring.Atoi();
201 }
202 
205 
209 
210 
211  // store geo parameter
212  TObjArray *pararray = fSttParameters->GetTubeParameters();
213 
214  TListIter iter(volList);
215 
216  FairGeoNode* node = NULL;
217  //FairGeoVolume *aVol=NULL; //[R.K. 01/2017] unused variable?
218  int tubecounter = 0;
220  pararray->AddLast(parms); // add this to have correspondence index <-> tubeid
221  while( (node = (FairGeoNode*) iter.Next()) ) {
222  if ( node->isSensitive() ) continue;
223  TString nodename = node->GetName();
224  if(!nodename.Contains("stt01tube")) continue;
225  tubecounter++;
226 
227  parms = CreateTubeParameters(node);
228  pararray->AddLast(parms);
229  }
230 
231  return tubecounter;
232 }
233 
235  TString nodename = pnode->getName();
236  Int_t tubeID = GetTubeIDFromNameGeoType1(nodename);
237 
238  FairGeoTransform *lab = pnode->getLabTransform();
239  FairGeoVector tra = lab->getTransVector();
240  FairGeoRotation rot = lab->getRotMatrix();
241  TGeoVolume* rootvol = pnode->getRootVolume();
242  TGeoTube *gtube = (TGeoTube*) rootvol->GetShape();
243  Double_t halflength = gtube->GetDz(); // in cm
244 
245  PndSttTubeParameters *parms = new PndSttTubeParameters(tubeID, halflength);
246  return parms;
247 
248 }
249 
250 // --------------------------------------------------------------------------------
252  TObjArray *pararray = fSttParameters->GetTubeParameters();
253 
254  fTubeArray = new TClonesArray("PndSttTube");
255  //fTubeArray->Delete();
256 
257  for(int i = 1; i < pararray->GetEntries(); i++) {
258  PndSttTubeParameters *parms = (PndSttTubeParameters*) pararray->At(i);
259  int tubeID = parms->GetTubeID();
260 
262  if(!fSttTube) continue;
263  // correspondance position in TCA <-> tubeID
264  new((*fTubeArray)[tubeID]) PndSttTube(*fSttTube);
265 
266  delete (fSttTube);
267  }
268 
271  return fTubeArray;
272 }
273 
275 
276  Int_t tubeid = parms->GetTubeID();
277  if(tubeid == -1) {
278  cout << "PndSttMapCreator::GetTubeFromParametersToFillGeoType1 (tubeid): tube " << tubeid << " not found (nor as a copy)" << endl;
279  return NULL;
280  }
281 
282  gGeoManager->cd("/cave_1/stt01assembly_0");
283  TGeoNode *assembly_node = gGeoManager->GetCurrentNode();
284  double local[3] = {0., 0., 0.}, master[3];
285  assembly_node->LocalToMaster(local, master);
286  TVector3 assembly_position(master[0], master[1], master[2]);
287 
288 
289  Bool_t isCopy = kTRUE;
290 
291  // try as if it was a copy stt01tube#XXX
292  TString path = GetPathFromTubeIDGeoType1(tubeid, isCopy);
293 
294  bool ispath = gGeoManager->CheckPath(path);
295  if(ispath == kFALSE) { // try as if it was a solo stt01tubeXXX
296  isCopy = kFALSE;
297  path = GetPathFromTubeIDGeoType1(tubeid, isCopy);
298  ispath = gGeoManager->CheckPath(path);
299  }
300  if(ispath == kFALSE) {
301  cout << "PndSttMapCreator::GetTubeFromParametersToFillGeoType1 (ispath): tube " << tubeid << " not found (nor as a copy)" << endl;
302  return NULL;
303  }
304 
305  gGeoManager->cd(path);
306  TGeoNode* tube_node = gGeoManager->GetCurrentNode();
307  tube_node->LocalToMaster(local, master);
308  TVector3 tube_position(master[0], master[1], master[2]);
309  tube_position += assembly_position;
310 
311  // tube_position.Print();
312 
313 
314  // geometrical info
315  double x = tube_position.X();
316  double y = tube_position.Y();
317  double z = tube_position.Z();
318 
319  TGeoMatrix *mat = tube_node->GetMatrix();
320  Double_t const *rotation = mat->GetRotationMatrix();
321 
322  double r[3][3];
323  int irot = 0, i = 0, j = 0;
324  for(i = 0; i < 3; i++) {
325  for(j = 0; j < 3; j++) {
326  r[i][j] = rotation[irot];
327  irot++;
328  }
329  }
330 
331  // sets up the correspondence int (tubeID) <--> int (1 = copy/0 = solo)
332  // copy_map[key] = alloc
333  copy_map[tubeid] = isCopy;
334 
335  return new PndSttTube(parms,
336  (float)x,(float)y,(float)z,
337  r[0][0],r[0][1],r[0][2],
338  r[1][0],r[1][1],r[1][2],
339  r[2][0],r[2][1],r[2][2],
341 
342 }
343 
345 
346  Bool_t isCopy = copy_map[tubeid];
347 
348 
349  gGeoManager->cd("/cave_1/stt01assembly_0");
350  TGeoNode *assembly_node = gGeoManager->GetCurrentNode();
351  double local[3] = {0., 0., 0.}, master[3];
352  assembly_node->LocalToMaster(local, master);
353  TVector3 assembly_position(master[0], master[1], master[2]);
354 
355 
356  // try as if it was a copy stt01tube#XXX
357  TString path = GetPathFromTubeIDGeoType1(tubeid, isCopy);
358 
359  bool ispath = gGeoManager->CheckPath(path);
360 
361  if(ispath == kFALSE) {
362  cout << "PndSttMapCreator::GetTubeFromTubeIDGeoType1 (ispath): tube " << tubeid << " not found (nor as a copy)" << endl;
363  return NULL;
364  }
365 
366  gGeoManager->cd(path);
367  TGeoNode* tube_node = gGeoManager->GetCurrentNode();
368  tube_node->LocalToMaster(local, master);
369  TVector3 tube_position(master[0], master[1], master[2]);
370  tube_position += assembly_position;
371 
372  // tube_position.Print();
373 
374 
375  // geometrical info
376  double x = tube_position.X();
377  double y = tube_position.Y();
378  double z = tube_position.Z();
379 
380  TGeoMatrix *mat = tube_node->GetMatrix();
381  Double_t const *rotation = mat->GetRotationMatrix();
382 
383  double r[3][3];
384  int irot = 0, i = 0, j = 0;
385  for(i = 0; i < 3; i++) {
386  for(j = 0; j < 3; j++) {
387  r[i][j] = rotation[irot];
388  irot++;
389  }
390  }
391 
392  TObjArray *parmsarray = fSttParameters->GetTubeParameters();
393  PndSttTubeParameters *parms = (PndSttTubeParameters*) parmsarray->At(tubeid); // CHECK
394 
395 
396  return new PndSttTube(parms,
397  (float)x,(float)y,(float)z,
398  r[0][0],r[0][1],r[0][2],
399  r[1][0],r[1][1],r[1][2],
400  r[2][0],r[2][1],r[2][2],
402 
403 }
404 
405 
406 // name as in geo file: from path "_" to name "#"
408 
409  // two possibilities:
410  // stt01tube#XXX --> copy : /cave_1/stt01assembly_0/stt01tube_XXX/stt01gas_1 --> stt01tube#XXX
411  // stt01tubeXXX --> solo : /cave_1/stt01assembly_0/stt01tubeXXX_0/stt01gasXXX_0 --> stt01tubeXXX
412 
413  TString tmpstring;
414  tmpstring += tubeid ;
415 
416  if(isCopy == kTRUE) tmpstring.Prepend("_");
417  else tmpstring.Append("_0");
418  tmpstring.Prepend("stt01tube");
419 
420  TString cavename;
421  cavename = "/cave_1/stt01assembly_0/";
422  tmpstring.Prepend(cavename);
423 
424 
425  return tmpstring;
426 }
427 
429 {
430  TString nodename = pnode->getName();
431  Int_t tubeID = PndGeoHandling::Instance()->GetShortID(nodename);
432 
433  FairGeoTransform *lab = pnode->getLabTransform();
434  FairGeoVector tra = lab->getTransVector();
435  FairGeoRotation rot = lab->getRotMatrix();
436  TGeoVolume* rootvol = pnode->getRootVolume();
437  TGeoTube *gtube = (TGeoTube*) rootvol->GetShape();
438  Double_t halflength = gtube->GetDz(); // in cm
439 
440  PndSttTubeParameters *parms = new PndSttTubeParameters(tubeID, halflength);
441  return parms;
442 }
443 
445 {
446 }
447 
449 
451 
455 //
456 //
457 // // store geo parameter
458  TObjArray *sensorNames = PndGeoHandling::Instance()->GetSensorNames();
459  TIter iter = sensorNames->MakeIterator();
460 
461  TObjArray *pararray = fSttParameters->GetTubeParameters();
462 // std::cout << "SensorNames.GetEntries() " << sensorNames->GetEntries() << std::endl;
463  int tubecounter = 0;
464  TObjString* sensorName;
465  while( (sensorName = (TObjString*)iter.Next()) ) {
466  TString stringName = sensorName->GetString();
467  if (stringName.Contains("ArCO2Sensitive")){
468  gGeoManager->cd(stringName.Data());
469  TGeoNode* node = gGeoManager->GetCurrentNode();
470  TGeoTube* tube = (TGeoTube*)node->GetVolume()->GetShape();
471  PndSttTubeParameters *parms = new PndSttTubeParameters(PndGeoHandling::Instance()->GetShortID(stringName), tube->GetDZ());
472 // std::cout << "-I- PndSttMapCreator::FillSttTubeParameeresType2 " << stringName.Data() << " ID: " << PndGeoHandling::Instance()->GetShortID(stringName) << " z/2 " << tube->GetDZ() << std::endl;
473  pararray->AddLast(parms);
474  tubecounter++;
475  }
476  }
477 
478  return tubecounter;
479 }
480 
482  TObjArray *pararray = fSttParameters->GetTubeParameters();
483 
484  fTubeArray = new TClonesArray("PndSttTube");
485  //fTubeArray->Delete();
486 
487  for(int i = 1; i < pararray->GetEntries(); i++) {
488  PndSttTubeParameters *parms = (PndSttTubeParameters*) pararray->At(i);
489  int tubeID = parms->GetTubeID();
490 
492  if(!fSttTube) continue;
493  // correspondance position in TCA <-> tubeID
494  new((*fTubeArray)[tubeID]) PndSttTube(*fSttTube);
495 
496  delete (fSttTube);
497  }
498 
501  return fTubeArray;
502 }
503 
505 
506  Int_t tubeid = parms->GetTubeID();
507  if(tubeid == -1) {
508  cout << "PndSttMapCreator::GetTubeFromParametersToFillGeoType2 (tubeid): tube " << tubeid << " not found (nor as a copy)" << endl;
509  return NULL;
510  }
511  TVector3 local(0.,0.,0.);
512  TVector3 localToMaster = PndGeoHandling::Instance()->LocalToMasterShortId(local, tubeid);
513  TGeoHMatrix* mat = PndGeoHandling::Instance()->GetMatrixShortId(tubeid);
514  Double_t const *rotation = mat->GetRotationMatrix();
515 
516  double r[3][3];
517  int irot = 0, i = 0, j = 0;
518  for(i = 0; i < 3; i++) {
519  for(j = 0; j < 3; j++) {
520  r[i][j] = rotation[irot];
521  irot++;
522  }
523  }
524 
525  return new PndSttTube(parms,
526  localToMaster.X(), localToMaster.Y(),localToMaster.Z(),
527  r[0][0],r[0][1],r[0][2],
528  r[1][0],r[1][1],r[1][2],
529  r[2][0],r[2][1],r[2][2],
531 
532 }
533 
PndSttTube * GetTubeFromParametersToFillGeoType1(PndSttTubeParameters *parms)
Int_t GetTubeIDFromPathGeoType1(TString path)
Int_t FillSttTubeParametersType2(PndGeoSttPar *par)
TClonesArray * FillTubeArrayGeoType2()
TString GetPathFromTubeIDGeoType1(Int_t tubeid, Bool_t isCopy)
double r
Definition: RiemannTest.C:14
PndSttGeometryMap * fMap
Int_t i
Definition: run_full.C:25
PndSttTube * fSttTube
std::map< int, int > copy_map
TString GetNameFromPathGeoType1(TString path)
TClonesArray * fTubeArray
TGeoRotation rotation
Double_t par[3]
void SetTubeInRad(Double_t inrad)
Definition: PndGeoSttPar.h:26
TGeoManager * gGeoManager
ClassImp(PndSttMapCreator)
Int_t GetGeometryType()
Definition: PndGeoSttPar.h:28
Int_t FillSttTubeParameters(PndGeoSttPar *par, TList *volList)
TGeoHMatrix * GetMatrixShortId(Int_t shortId)
Int_t GetTubeIDFromPath(TString path)
PndSttTube * GetTubeFromTubeID(Int_t tubeid)
Double_t GetTubeOutRad()
Definition: PndGeoSttPar.h:30
Int_t GetTubeIDFromNameGeoType2(TString name)
PndGeoSttPar * fSttParameters
Double_t
PndSttTube * GetTubeFromParametersToFillGeoType2(PndSttTubeParameters *parms)
TClonesArray * FillTubeArray()
Double_t z
PndSttTubeParameters * CreateTubeParametersGeoType1(FairGeoNode *pnode)
TObjArray * GetSensorNames()
Int_t GetShortID(TString path)
for a given path the (unique) position of the sensor path in the fSensorNamePar-List is given...
static PndGeoHandling * Instance()
void SetTubeOutRad(Double_t outrad)
Definition: PndGeoSttPar.h:27
TString name
TObjArray * GetTubeParameters()
Definition: PndGeoSttPar.h:22
TClonesArray * FillTubeArrayGeoType1()
Double_t GetTubeInRad()
Definition: PndGeoSttPar.h:29
Double_t x
PndSttTubeParameters * CreateTubeParameters(FairGeoNode *pnode)
TVector3 LocalToMasterShortId(const TVector3 &local, const Int_t &shortId)
Int_t GetTubeIDFromName(TString name)
Int_t FillSttTubeParametersGeoType1(PndGeoSttPar *par, TList *volList)
TGeoRotation rot
Double_t y
void SetGeometryType(Int_t geoType)
Definition: PndGeoSttPar.h:25
PndSttTubeParameters * CreateTubeParametersGeoType2(FairGeoNode *pnode)
PndSttTube * GetTubeFromParametersToFill(PndSttTubeParameters *parms)
TString GetPathFromTubeID(Int_t tubeid, Bool_t isCopy)
TString GetNameFromPath(TString path)
Int_t GetTubeIDFromNameGeoType1(TString name)
PndSttTube * GetTubeFromTubeIDGeoType1(Int_t tubeid)