FairRoot/PandaRoot
PndFtsMapCreator2.cxx
Go to the documentation of this file.
1 // Mapper for TFT
3 // chamberID layerID tubeIDtot
4 //
5 // author: Isabella Garzia
7 
8 
9 #include "PndFtsMapCreator2.h"
10 #include "PndFtsTube.h"
11 #include "PndGeoFtsPar.h"
12 
13 #include "FairGeoNode.h"
14 #include "FairGeoVolume.h"
15 #include "FairGeoTransform.h"
16 #include "FairGeoVector.h"
17 #include "FairGeoRotation.h"
18 #include "FairGeoTube.h"
19 
20 #include "TGeoTube.h"
21 #include "TVector3.h"
22 #include "TObjArray.h"
23 #include "TString.h"
24 #include "TGeoVolume.h"
25 #include "TGeoTube.h"
26 #include "TClonesArray.h"
27 #include "FairRootManager.h"
28 
29 #include <iostream>
30 #include <fstream>
31 
32 using namespace std;
33 
35  : fGeoType(0), fFtsParameters(new PndGeoFtsPar()), fTubeInRad(0), fTubeOutRad(0), copy_map()
36 {
37  copy_map.clear();
38  // Geometry loading
39  FairRootManager* ioman = FairRootManager::Instance();
40  TFile *infile = ioman->GetInFile();
41 }
42 
43 
44 
45 //PndFtsMapCreator2::PndFtsMapCreator2(){}
46  // to use in PndFts
48  : fGeoType(geoType), fFtsParameters(new PndGeoFtsPar()), fTubeInRad(0), fTubeOutRad(0) , copy_map()
49 {
50  copy_map.clear();
51  if(fGeoType != 1) Info("PndFtsMapCreator2","Geometry %i not supported by map", fGeoType); // CHECK
52 }
53 
54 // crete geometry from parameters file
56  : fGeoType(0), fFtsParameters(ftsPar), fTubeInRad(0), fTubeOutRad(0), copy_map()
57 {
58  copy_map.clear();
59  // set general par
61  // choose geometry type
62  fGeoType = ftsPar->GetGeometryType(); // classic, optimized, average, detailed, CAD
63 
64  if(fGeoType != 1) Info("PndFtsMapCreator2","Geometry %i not supported by map", fGeoType); // CHECK
65 }
66 
68 
69 void PndFtsMapCreator2::SetGeneralParameters() { // CHECK whether it depends on geometry or not
70  fTubeInRad = fFtsParameters->GetTubeInRad(); // tube inner radius
71  fTubeOutRad = fFtsParameters->GetTubeOutRad(); // tube outer radius
72 }
73 
74 // during simulation (for tubeID)
76  if(fGeoType == 1) return GetTubeIDFromPathGeoType1(path);
77  return -999;
78 }
79 
80 
81 // ===== GEO TYPE 1 =====
82  // sensitive volume is gas
83  // when reading the parameters we use fts01tube to retrieve geometrical information
84  // OK
85  // during simulation
86 
88  TString tmpstring = GetNameFromPathGeoType1(path);
89  return GetTubeIDFromNameGeoType1(tmpstring);
90 }
91 
93  if(fGeoType == 1) return GetTubeFromTubeIDToFillGeoType1(tubeid);
94  return NULL;
95 }
96 
97 
99  TString pathstring=name;
100  if(pathstring.Contains("fts01")){
101  //std::cout<<"chamber 1"<<std::endl;
102  return 1;
103  }
104  if(pathstring.Contains("fts02")){
105  //std::cout<<"chamber 2"<<std::endl;
106  return 2;
107  }
108  if(pathstring.Contains("fts31")||pathstring.Contains("fts32")||pathstring.Contains("fts33")||pathstring.Contains("fts34")){
109  //std::cout<<"chamber 3"<<std::endl;
110  return 3;
111  }
112  if(pathstring.Contains("fts35")||pathstring.Contains("fts36")||pathstring.Contains("fts37")||pathstring.Contains("fts38")){
113  //std::cout<<"chamber 4"<<std::endl;
114  return 4;
115  }
116  if(pathstring.Contains("fts05tube")){
117  //std::cout<<"chamber 5"<<std::endl;
118  return 5;
119  }
120  if(pathstring.Contains("fts06tube")){
121  //std::cout<<"chamber 6"<<std::endl;
122  return 6;
123  }
124 
125 }
126 
128  TString pathstring=path;
129  if(pathstring.Contains("fts01tube")){
130  //std::cout<<"chamber 1"<<std::endl;
131  return 1;
132  }
133  if(pathstring.Contains("fts02tube")){
134  //std::cout<<"chamber 2"<<std::endl;
135  return 2;
136  }
137  if(pathstring.Contains("fts31tube")||pathstring.Contains("fts32tube")||pathstring.Contains("fts33tube")||pathstring.Contains("fts34tube")){
138  //std::cout<<"chamber 3"<<std::endl;
139  return 3;
140  }
141  if(pathstring.Contains("fts35tube")||pathstring.Contains("fts36tube")||pathstring.Contains("fts37tube")||pathstring.Contains("fts38tube")){
142  //std::cout<<"chamber 4"<<std::endl;
143  return 4;
144  }
145 if(pathstring.Contains("fts05tube")){
146  //std::cout<<"chamber 5"<<std::endl;
147  return 5;
148  }
149 if(pathstring.Contains("fts06tube")){
150  //std::cout<<"chamber 6"<<std::endl;
151  return 6;
152  }
153 
154 }
155 
156 
158 
159  TString tmpstring = name;
160 
161  if(tmpstring.Contains("#")) {
162  int start = tmpstring.Index("#") + 1;
163  tmpstring = tmpstring(start, tmpstring.Sizeof());
164  }
165  else{
166  int start = tmpstring.Index("e") + 1;
167  tmpstring = tmpstring(start, tmpstring.Sizeof());
168  }
169 
170  return tmpstring.Atoi();
171 }
172 
173 // name as in geo file: from path "_" to name "#"
175  TString tmpstring = path;
176 
177  //std::cout<<"tmpstring original###### = "<<tmpstring<<std::endl;
178 
179 // cut /cave_1/fts01assembly_0/
180  TString cavename;
181  cavename = "/cave_1/ftsXXassembly_X/";
182  tmpstring = tmpstring(cavename.Sizeof() - 1, tmpstring.Sizeof());
183 
184  // cut /fts01gas...
185  int index = tmpstring.Index("/");
186  tmpstring = tmpstring(0, index);
187 
188  // replace _ with #
189  // if(tmpstring.Contains("_0")) {
190  // tmpstring.Chop(); // cut "0"
191  // tmpstring.Chop(); // cut "_"
192  // }
193 
194  if(tmpstring.Contains("down")){
195  tmpstring.Replace(13, 1, "#");
196  //std::cout<<"tmpstring = "<<tmpstring<<std::endl;
197  }
198  if(tmpstring.Contains("up")){
199  tmpstring.Replace(11, 1, "#");
200  //std::cout<<"tmpstring = "<<tmpstring<<std::endl;
201  }
202  if(!tmpstring.Contains("up") && !tmpstring.Contains("down")){
203  tmpstring.Replace(9, 1, "#");
204  //std::cout<<"tmpstring = "<<tmpstring<<std::endl;
205  }
206 
207 
208  return tmpstring;
209 }
210 
211 Int_t PndFtsMapCreator2::GetLayerID(Int_t chamberid, Int_t tudeid,TString path ){
212 
213  Int_t tube=tudeid;
214  Int_t chamber=chamberid;
215  TString tmpstring = path;
216 
217  Int_t i=1;
218  if(chamberid==1 || chamberid==2){
219  if(chamberid==2){i=i+8;}
220  while(tube>128){
221  tube=tube-128;
222  i++;
223  }
224  }
225  if(chamberid==3 || chamberid==4){
226  if(chamberid==3){i=i+16;}
227  else{i=i+24;}
228  if(tmpstring.Contains("fts32")){tube=tube+384;}
229  if(tmpstring.Contains("fts33")){tube=tube+768;}
230  if(tmpstring.Contains("fts34")){tube=tube+1152;}
231  //if(tmpstring.Contains("fts35")){tube=tube+}
232  if(tmpstring.Contains("fts36")){tube=tube+384;}
233  if(tmpstring.Contains("fts37")){tube=tube+768;}
234  if(tmpstring.Contains("fts38")){tube=tube+1152;}
235  while(tube>192){
236  tube=tube-192;
237  i++;
238  }
239  }
240  if(chamberid==5){
241  i=i+32;
242  while(tube>400){
243  tube=tube-400;
244  i++;
245  }
246  }
247  if(chamberid==6){
248  i=i+40;
249  while(tube>592){
250  tube=tube-592;
251  i++;
252  }
253  }
254  return i;
255 
256 }
257 
258 Int_t PndFtsMapCreator2::GetTubeIDTot(Int_t chamberid, Int_t layerid, Int_t tubeid,TString path )
259 {
260  Int_t chamber=chamberid;
261  Int_t layer=layerid;
262  Int_t tubeID=tubeid;
263  TString tmpstring=path;
264  Int_t tube=0;
265  Int_t totTubeID=0;
266 
267  if(chamberid==1){tube=tubeID;}
268  if(chamberid==2){tube=tubeID+1024;}
269  if(chamberid==3){
270  if(layer==17||layer==18){tube=tubeID+(128*(16));}
271  if(layer==19||layer==20){tube=tubeID+(128*16)+(192*2)+(12*2);} //2648
272  if(layer==21||layer==22){tube=tubeID+(128*16)+(192*4)+(12*4);} //3056
273  if(layer==23||layer==24){tube=tubeID+(128*16)+(192*6)+(12*6);} //3464
274  }
275  if(chamberid==4){
276  if(layer==25||layer==26){tube=tubeID+(128*(16)+192*8);} //3872
277  if(layer==27||layer==28){tube=tubeID+(128*(16)+192*10)+12*2;} //4280
278  if(layer==29||layer==30){tube=tubeID+(128*(16)+192*12)+12*4;} //4688
279  if(layer==31||layer==32){tube=tubeID+(128*(16)+192*14)+12*6;} //5096
280  }
281  if(chamberid==5){tube=tubeID+(128*16)+(192*16);}
282  if(chamberid==6){tube=tubeID+(128*16)+(192*16)+(400*8);}
283 
284  //up and down short tubes have different name but the same ID number
285  //I shift the tube ID to give a different ID number to each tube
286  // tubeid chamber 1,2: between 1-128*8, hole:12 tubes
287  //tubeid chamber 3,4: between 1-192*2 for each double layer, hole: 12 tubes
288  //tubeid chamber 5: between 1-400*8, hole: 18 tubes
289  //tubeid chamber 6: between 1-592*8, hole: 18 tubes
290 
291  //chamber 1 and chamber 2
292  if(chamber==1){
293  int shift=0;
294  if(!tmpstring.Contains("down") && !tmpstring.Contains("up")){
295  if(tubeid<=58){totTubeID=tube+shift;}
296  else{
297  if(abs(tubeid-(128*(layer)))<=58){
298  totTubeID=tube+12*(layer)+shift;
299  }
300  else{
301  totTubeID=tube+12*(layer-1)+shift;
302  }
303  }
304  }
305  if(tmpstring.Contains("up")){
306  totTubeID=tube+12*(layer-1)+shift;
307  }
308  if(tmpstring.Contains("down")){
309  totTubeID=tube+12*(layer)+shift;
310  }
311  }
312  //chamber 2
313  if(chamber==2){
314  int shift=12*8;
315  if(!tmpstring.Contains("down") && !tmpstring.Contains("up")){
316  if(tubeid<=58){totTubeID=tube+shift;}
317  else{
318  if(abs(tubeid-(128*(layer-8)))<=58){
319  totTubeID=tube+12*(layer-8)+shift;
320  }
321  else{
322  totTubeID=tube+12*(layer-9)+shift;
323  }
324  }
325  }
326  if(tmpstring.Contains("up")){
327  totTubeID=tube+12*(layer-9)+shift;
328  }
329  if(tmpstring.Contains("down")){
330  totTubeID=tube+12*(layer-8)+shift;
331  }
332  }
333  //chamber 3
334  if(chamber==3 || chamber==4){
335  int shift=0;
336  if(chamber==3){
337  shift=12*(2*8); int numTL=192;
338  }
339  else{shift=12*(3*8);}
340  if(!tmpstring.Contains("down") && !tmpstring.Contains("up")){
341  if(tubeid<=90){totTubeID=tube+shift;}
342  else{
343  if(layer%2!=0){ // odd layers
344  if(abs(tubeid-(192))<=90){
345  totTubeID=tube+shift+12;
346  }
347  else{totTubeID=tube+shift;}
348  }
349  else{
350  if(abs(tubeid-(192*2))<=90){
351  totTubeID=tube+shift+12*2;
352  }
353  else{totTubeID=tube+shift+12;}
354  }
355  }
356  }
357  if(tmpstring.Contains("down")){
358  if(layer%2!=0){totTubeID=tube+12+shift;} //odd layer
359  else{totTubeID=tube+12*2+shift;}
360  }
361  if(tmpstring.Contains("up")){
362  if(layer%2!=0){totTubeID=tube+shift;} //odd layer
363  else{totTubeID=tube+12+shift;}
364  }
365  }
366  //chamber 5
367  //12*32 are the tubes shifted in the previous chambers
368  if(chamber==5){
369  int shift=12*32;
370  if(!tmpstring.Contains("down") && !tmpstring.Contains("up")){
371  if(tubeid<=191){totTubeID=tube+shift;}
372  else{
373  if(abs(tubeid-(400*(layer-32)))<=191){
374  totTubeID=tube+18*(layer-32)+shift;
375  }
376  else{
377  totTubeID=tube+18*(layer-33)+shift;
378  }
379  }
380  }
381  if(tmpstring.Contains("up")){
382  totTubeID=tube+18*(layer-33)+shift;
383  }
384  if(tmpstring.Contains("down")){
385  totTubeID=tube+18*(layer-32)+shift;
386  }
387  }
388 
389  //chamber 6
390  if(chamber==6){
391  int shift=12*32+18*8;
392  if(!tmpstring.Contains("down") && !tmpstring.Contains("up")){
393  if(tubeid<=287){totTubeID=tube+shift;}
394  else{
395  if(abs(tubeid-(592*(layer-40)))<=287){
396  totTubeID=tube+18*(layer-40)+shift;
397  }
398  else{
399  totTubeID=tube+18*(layer-41)+shift;
400  }
401  }
402  }
403  if(tmpstring.Contains("up")){
404  totTubeID=tube+18*(layer-41)+shift;
405  }
406  if(tmpstring.Contains("down")){
407  totTubeID=tube+18*(layer-40)+shift;
408  }
409  }
410 
411  return totTubeID;
412 
413 }
414 
415 
419 
420 
421 // fill the tube map at the beginning of the run
423 
424  std::cout<<"#####Mapper:filltubearray######"<<std::endl;
425  std::cout<<"fGeoType="<<fGeoType<<std::endl;
426  if(fGeoType == 1) return FillTubeArrayGeoType1();
427  return NULL;
428 }
429 
430 
431 
433 
434  // two possibilities:
435  // copy : XXX --> fts01tube#XXX
436  // solo : XXX --> fts01tubeXXX
437 
438  TString tmpstring;
439  TString chstring;
440 
441  tmpstring += tubeid ;
442 
443  //to be virfied
444  if(isCopy == kTRUE) {
445  tmpstring.Prepend("ftsXXtube#");
446  //tmpstring.Prepend("fts01tube#");
447  }
448  else {
449  tmpstring.Prepend("ftsXXtube");
450  }
451  return tmpstring;
452 
453 }
454 
455 
457 
458  TObjArray *geoPassNodes = fFtsParameters->GetGeoPassiveNodes();
459  Bool_t isCopy = kTRUE;
460  // try as if it was a copy stt01tube#XXX
461  TString tubename = GetNameFromTubeIDGeoType1(tubeid, isCopy);
462  FairGeoNode *pnode = (FairGeoNode*) geoPassNodes->FindObject(tubename);
463  if(!pnode) { // try as if it was a solo stt01tubeXXX
464  isCopy = kFALSE;
465  tubename = GetNameFromTubeIDGeoType1(tubeid, isCopy);
466  pnode = (FairGeoNode*) geoPassNodes->FindObject(tubename);
467  }
468 
469  if(!pnode) {
470  //cout << "PndFtsMapCreator2::GetTubeFromTubeIDToFillGeoType1: tube " << tubename << " not f\ound (nor as a copy)" << endl;
471  return NULL;
472  }
473 
474  FairGeoTransform *lab = pnode->getLabTransform();
475  FairGeoVector tra = lab->getTransVector();
476  FairGeoRotation rot = lab->getRotMatrix();
477 
478  // geometrical info
479  double x = tra.getX()/10.; // in cm
480  double y = tra.getY()/10.; // in cm
481  double z = tra.getZ()/10.; // in cm
482  double r[3][3];
483  for(int i = 0; i < 3; i++)for(int j = 0; j < 3; j++) r[i][j] = rot.getElement(i,j);
484 
485  TGeoVolume* rootvol = pnode->getRootVolume();
486  TGeoTube *tube = (TGeoTube*) rootvol->GetShape();
487  Double_t halflength = tube->GetDz(); // in cm
488  // sets up the correspondence int (tubeID) <--> int (1 = copy/0 = solo)
489  // copy_map[key] = alloc
490  copy_map[tubeid] = isCopy;
491 
492  return new PndFtsTube((float)x,(float)y,(float)z,
493  r[0][0],r[0][1],r[0][2],
494  r[1][0],r[1][1],r[1][2],
495  r[2][0],r[2][1],r[2][2],
496  fTubeInRad, fTubeOutRad, halflength);
497 }
498 
500 
501  Int_t tubeid = GetTubeIDFromNameGeoType1(tubename);
502 
503  TObjArray *geoPassNodes = fFtsParameters->GetGeoPassiveNodes();
504  Bool_t isCopy = kTRUE;
505  // try as if it was a copy stt01tube#XXX
506 
507  FairGeoNode *pnode = (FairGeoNode*) geoPassNodes->FindObject(tubename);
508  if(!pnode) { // try as if it was a solo stt01tubeXXX
509  isCopy = kFALSE;
510  //tubename = GetNameFromTubeIDGeoType1(tubeid, isCopy);
511  //pnode = (FairGeoNode*) geoPassNodes->FindObject(tubename);
512  }
513 
514  if(!pnode) {
515  cout << "PndFtsMapCreator2::GetTubeFromNameToFillGeoType1: tube " << tubename << " not found (nor as a copy)" << endl;
516  return NULL;
517  }
518 
519  FairGeoTransform *lab = pnode->getLabTransform();
520  FairGeoVector tra = lab->getTransVector();
521  FairGeoRotation rot = lab->getRotMatrix();
522 
523  // geometrical info
524  double x = tra.getX()/10.; // in cm
525  double y = tra.getY()/10.; // in cm
526  double z = tra.getZ()/10.; // in cm
527  double r[3][3];
528  for(int i = 0; i < 3; i++)for(int j = 0; j < 3; j++) r[i][j] = rot.getElement(i,j);
529 
530  TGeoVolume* rootvol = pnode->getRootVolume();
531  TGeoTube *tube = (TGeoTube*) rootvol->GetShape();
532  Double_t halflength = tube->GetDz(); // in cm
533  // sets up the correspondence int (tubeID) <--> int (1 = copy/0 = solo)
534  // copy_map[key] = alloc
535  copy_map[tubeid] = isCopy;
536 
537  return new PndFtsTube((float)x,(float)y,(float)z,
538  r[0][0],r[0][1],r[0][2],
539  r[1][0],r[1][1],r[1][2],
540  r[2][0],r[2][1],r[2][2],
541  fTubeInRad, fTubeOutRad, halflength);
542 }
543 
544 
545 
547 
548  TObjArray *geoPassNodes = fFtsParameters->GetGeoPassiveNodes();
549  TClonesArray *tubeArray = new TClonesArray("PndFtsTube");
550  tubeArray->Delete();
551  int mytest=0;
552  //std::cout << "TA: entries: " << geoPassNodes->GetEntriesFast() << std::endl;
553  for(int i = 0; i < geoPassNodes->GetEntriesFast(); i++) {
554  FairGeoNode *pnode = (FairGeoNode*) geoPassNodes->At(i);
555  if(!pnode)
556  {
557  std::cout<<"PndFtsMapCreator2::FillTubeArrayGeoType1 : tubename="<< pnode->GetName() << " not existing!!!" << std::endl;
558  continue;
559  }
560  TString tubename = pnode->GetName();
561 
562 
563  //std::cout<<"PndFtsMapCreator2::FillTubeArrayGeoType1 : tubename="<<tubename<< std::endl;
564  if( (!tubename.Contains("tube")) || (!tubename.Contains("fts")) )
565  {
566  //myfile<<"PndFtsMapCreator2::FillTubeArrayGeoType1 : skipping tubename="<<tubename<<endl;
567  continue;
568  }
569 
570  Int_t tempChamber = GetChamberIDFromName(tubename);
571  Int_t tubeID = GetTubeIDFromNameGeoType1(tubename);
572  Int_t tempLayer = GetLayerID(tempChamber, tubeID, tubename);
573  Int_t totTubeID = GetTubeIDTot(tempChamber, tempLayer, tubeID, tubename );
574  //PndFtsTube *ftstube = GetTubeFromTubeIDToFillGeoType1(tubeID);
575  PndFtsTube *ftstube = GetTubeFromNameToFillGeoType1(tubename);
576  new((*tubeArray)[totTubeID]) PndFtsTube(*ftstube);
577 
578 
579  }
580  //std:cout << "end: " << tubeArray->GetEntriesFast() << std::endl;
581  return tubeArray;
582 }
583 
TString GetNameFromPathGeoType1(TString path)
Int_t GetLayerID(Int_t chamberid, Int_t tubeid, TString path)
std::map< int, int > copy_map
double r
Definition: RiemannTest.C:14
Int_t i
Definition: run_full.C:25
TString GetNameFromTubeIDGeoType1(Int_t tubeid, Bool_t isCopy)
Int_t GetGeometryType()
Definition: PndGeoFtsPar.h:37
Double_t GetTubeOutRad()
Definition: PndGeoFtsPar.h:39
PndGeoFtsPar * fFtsParameters
Int_t GetChamberIDFromPath(TString path)
PndFtsTube * GetTubeFromNameToFillGeoType1(TString tubename)
Int_t GetChamberIDFromName(TString name)
Double_t
PndFtsTube * GetTubeFromTubeIDToFillGeoType1(Int_t tubeid)
Double_t z
Int_t GetTubeIDFromPathGeoType1(TString path)
Int_t GetTubeIDFromPath(TString path)
TString name
Int_t GetTubeIDTot(Int_t chamberid, Int_t layerid, Int_t tubeid, TString path)
PndFtsTube * GetTubeFromTubeID(Int_t tubeid)
TObjArray * GetGeoPassiveNodes()
Definition: PndGeoFtsPar.h:31
Double_t x
ClassImp(PndAnaContFact)
TGeoRotation rot
TClonesArray * FillTubeArray()
this function will be used in PndFtsHitProducesRealFast
TClonesArray * FillTubeArrayGeoType1()
Double_t y
Int_t GetTubeIDFromNameGeoType1(TString name)
TFile infile("dedx_out.root","READ")
Double_t GetTubeInRad()
Definition: PndGeoFtsPar.h:38