StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StiDetectorVolume.cxx
1 // $Id: StiDetectorVolume.cxx,v 2.10 2018/04/10 11:32:10 smirnovd Exp $
2 // Author: Valeri Fine, Dec 2006
3 
4 #include "StiDetectorVolume.h"
5 
6 #include "TVolumePosition.h"
7 #include "TRotMatrix.h"
8 #include "TTUBS.h"
9 #include "TBRIK.h"
10 #include "TMath.h"
11 #include "TFile.h"
12 #include "TGeometry.h"
13 #include "Sti/StiPlanarShape.h"
14 #include "Sti/StiCylindricalShape.h"
15 #include "Sti/StiGenericDetectorGroup.h"
16 #include "Sti/StiDetector.h"
17 #include "Sti/StiDetectorGroups.h"
18 #include "Sti/StiDetectorBuilder.h"
19 #include "Sti/StiPlacement.h"
20 #include "Sti/StiMaterial.h"
21 #include "Sti/StiToolkit.h"
22 
23 #if 0
24 //_____________________________________________________________________________
25 static Bool_t CompareMatrix(TRotMatrix &a,TRotMatrix &b)
26 {
27  // the code was borrowed from St_geant_Maker
28  double *pa=a.GetMatrix(); double *pb=b.GetMatrix();
29  for (int i=0; i<9; i++) if (pa[i]!=pb[i]) return kFALSE;
30  return kTRUE;
31 }
32 #endif
33 
34 //_____________________________________________________________________________
35 inline static TRotMatrix *GetMatrix(float angle)
36 {
37  // Fill the matrix object with the rotation matrix
38  Double_t m[9] = {
39  TMath::Cos(angle), -TMath::Sin(angle), 0
40  ,TMath::Sin(angle), TMath::Cos(angle), 0
41  , 0 , 0 , 1
42  };
43  //fRotMatrix.SetMatrix(m);
44  TRotMatrix *mat = new TRotMatrix();
45  mat->SetMatrix(m);
46  return mat;
47 }
48 
49 //_____________________________________________________________________________
50 // class TVolume decorator for StiDetector's
51 //
52 //_____________________________________________________________________________
53 
54 // class TVolume decorator for StiDetector's
55 //_____________________________________________________________________________
56 StiDetectorVolume::StiDetectorVolume(StiToolkit &tool, const TString &detectorName, unsigned int select)
57  : TVolume("RnD","Sti",(TShape*)0),fDetector(0)
58 {
59  MakeDetector(tool,detectorName, select);
60 }
61 
62 //_____________________________________________________________________________
63 StiDetectorVolume::StiDetectorVolume(const StiDetectorBuilder &builder, unsigned int select) :
64  TVolume(builder.getName().c_str(),"StiDetectorBuilder",(TShape *)0),fDetector(0)
65 {
66  MakeVolume(builder,select);
67 }
68 
69 //_____________________________________________________________________________
70 StiDetectorVolume::StiDetectorVolume(StiDetector *detector) :
71  TVolume(),fDetector(detector) { }
72 
73 //_____________________________________________________________________________
74 StiDetectorVolume::StiDetectorVolume(StiDetector *detector,const Text_t* name, const Text_t* title, const Text_t* shapename, Option_t* option):
75 TVolume( name, title, shapename, option),fDetector(detector) { }
76 
77 //_____________________________________________________________________________
78 StiDetectorVolume::StiDetectorVolume(StiDetector *detector,const Text_t* name, const Text_t* title, TShape* shape, Option_t* option):
79  TVolume(name,title,shape,option ),fDetector(detector) { }
80 
81 //_____________________________________________________________________________
82 void StiDetectorVolume::Browse(TBrowser *b)
83 {
84  TVolume::Browse(b);
85 }
86 //_____________________________________________________________________________
87 char *StiDetectorVolume::GetObjectInfo(Int_t px, Int_t py) const
88 {
89  return TVolume::GetObjectInfo(px, py);
90 }
91 //_____________________________________________________________________________
92 void StiDetectorVolume::MakeDetector(StiToolkit &tool, const TString &detectorName, unsigned int select)
93 {
94  // Construct the TVolume from the StToolKit
95  StiDetectorGroups *groups=tool.getDetectorGroups();
96  vector<StiGenericDetectorGroup *>::iterator it = groups->begin();
97  for (; it != groups->end(); ++it) {
98  StiGenericDetectorGroup *group = *it;
99  const StiDetectorBuilder &builder = *group->getDetectorBuilder();
100  TString builderName = (const char*)builder.getName().c_str();
101  if ( detectorName.IsNull() || (builderName.BeginsWith(detectorName,TString::kIgnoreCase)) )
102  Add(new StiDetectorVolume(builder,select));
103  else {
104  LOG_INFO << "Skip " << (const char*)builder.getName().c_str() << " detector" << endm;
105  }
106  }
107 }
108 //_____________________________________________________________________________
109 void StiDetectorVolume::MakeVolume(const StiDetectorBuilder &builder, unsigned int select)
110 {
111  // Construct the TVolume from the StDetectorBuilder
112  unsigned int nRows = builder.getNRows();
113  LOG_INFO << "Builder: " << builder.getName().c_str() << " has " << nRows << " rows" << endm;
114  for (unsigned int i=0; i < nRows; i++) {
115  unsigned int nSectors = builder.getNSectors(i);
116  Int_t iColor = 3 + i%6;
117  for (unsigned int j=0;j<nSectors;j++)
118  {
119  StiDetector *next = builder.getDetector(i,j) ;
120  if (!next) {
121  LOG_ERROR << "The is no detector for row " << i <<" sector " << j << endm;
122  continue;
123  }
124  if (select && ( ( select == kActive && !next->isActive())
125  ||
126  ( select == kPassivie && next->isActive() )
127  ) ) continue;
128  const StiShape *stiShape = next->getShape();
129  TShape *shape = MakeShape(stiShape
130  ,(const char*)next->getMaterial()->getName().c_str() );
131  StiPlacement *place = next->getPlacement();
132  TString canonicName = (const char*)next->getName().c_str();
133  canonicName.ReplaceAll("/","_");
134  StiDetectorVolume *nextVolume = new StiDetectorVolume(next,(const char*)canonicName,"StiDetector",shape);
135  nextVolume->SetFillColor(iColor); nextVolume->SetLineColor(iColor);
136  bool planar = (stiShape->getShapeCode() == kPlanar);
137  TVolumePosition *position = 0;
138  if (planar) {
139  if (place->getNormalRefAngle() != 0) {
140  position = new TVolumePosition(0, 0, 0, 0, GetMatrix(place->getNormalRefAngle()));
141  position->SetMatrixOwner();
142  TVolumePosition *translate= new TVolumePosition (0
143  ,place->getNormalYoffset()
144  ,place->getNormalRadius()
145  ,place->getZcenter()
146  );
147  position->Mult(*translate );
148  delete translate;
149  } else {
150  position = new TVolumePosition(0
151  ,place->getNormalYoffset()
152  ,place->getNormalRadius()
153  ,place->getZcenter()
154  ,GetMatrix(place->getNormalRefAngle())
155  );
156  }
157  } else {
158  position = new TVolumePosition(0, 0, 0, place->getZcenter(), GetMatrix(place->getNormalRefAngle()));
159  }
160  position->SetNode(nextVolume);
161  Add(nextVolume,position);
162 #if 1
163  nextVolume->Print();
164  TShape *sh = nextVolume->GetShape();
165  sh->Print();
166  // cout << "Material: " << sh->GetMaterial()->GetName() << " RadL. = " << sh->GetMaterial()->GetRadLength() << endl;
167  if (sh->InheritsFrom("TBRIK")) {
168  TBRIK *brik = (TBRIK *) sh;
169  cout << " dx " << brik->GetDx()
170  << " dy " << brik->GetDy()
171  << " dz " << brik->GetDz() << endl;
172  } else {
173  if (sh->InheritsFrom("TTUBE")) {
174  TTUBE *tube = (TTUBE *) sh;
175  cout << " Rmin " << tube->GetRmin()
176  << " Rmax " << tube->GetRmax()
177  << " dz " << tube->GetDz();
178  }
179  if (sh->InheritsFrom("TTUBS")) {
180  TTUBS *tubs = (TTUBS *) sh;
181  cout << " Phi1 " << tubs->GetPhi1()
182  << " Phi2 " << tubs->GetPhi2();
183  }
184  cout << endl;
185  }
186  position->Print();
187 #endif
188  }
189  }
190 }
191 
192 //_____________________________________________________________________________
193 TShape *StiDetectorVolume::MakeShape(const StiShape *shape, const char*material)
194 {
195  TShape *rootShape=0;
196  if (shape) {
197  switch (shape->getShapeCode()) {
198  case kPlanar:
199  rootShape = MakeShape(*(const StiPlanarShape *)shape,material);
200  break;
201  case kCylindrical:
202  rootShape = MakeShape(*(const StiCylindricalShape *)shape,material);
203  break;
204  default: assert(0);
205  }
206  }
207  return rootShape;
208 }
209 
210 //_____________________________________________________________________________
211 TShape *StiDetectorVolume::MakeShape(const StiPlanarShape &shape,const char*material)
212 {
213  return
214  new TBRIK((const char*)shape.getName().c_str()
215  , "StiPlanarShape"
216  , material
217  , shape.getHalfWidth()
218  , shape.getThickness()/2
219  , shape.getHalfDepth() );
220 }
221 
222 //_____________________________________________________________________________
223 TShape *StiDetectorVolume::MakeShape(const StiCylindricalShape &shape,const char*material)
224 {
225  return (shape.getOpeningAngle() < (TMath::TwoPi()-0.001) ) ?
226  new TTUBS((const char*)shape.getName().c_str()
227  , "StiCylindricalShape"
228  , material
229  , shape.getOuterRadius() - shape.getThickness() // rmin
230  , shape.getOuterRadius() // rmax
231  , shape.getHalfDepth() // Dz
232  , -shape.getOpeningAngle()*TMath::RadToDeg()/2
233  , +shape.getOpeningAngle()*TMath::RadToDeg()/2 )
234  :
235  new TTUBE((const char*)shape.getName().c_str()
236  , "StiCylindricalShape"
237  , material
238  , shape.getOuterRadius() - shape.getThickness() // rmin
239  , shape.getOuterRadius() // rmax
240  , shape.getHalfDepth() // Dz
241  );
242 }
243 
244 
245 
252 void StiDetectorVolume::SaveGeometry(const std::string fileName) const
253 {
254  TFile fileTmp(fileName.c_str(), "RECREATE");
255  this->Write();
256  fileTmp.Close();
257 }
virtual char * GetObjectInfo(Int_t px, Int_t py) const
to be documented
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Definition: TDataSet.cxx:893
virtual void Browse(TBrowser *b)
to be documented
Definition: TVolume.cxx:324
virtual char * GetObjectInfo(Int_t px, Int_t py) const
to be documented
Definition: TVolume.cxx:531
Abstract interface for a STI toolkit.
virtual StiDetectorBuilder * getDetectorBuilder()
Get a detector builder appropriate for this detector group.
virtual void Browse(TBrowser *b)
to be documented
Definition of toolkit.
Definition: StiToolkit.h:55
void SaveGeometry(const std::string fileName="sti2rootgeo.root") const
virtual void Print(Option_t *option="") const
to be documented
virtual UInt_t getNSectors(UInt_t row=0) const
const string & getName() const
Get the name of the object.
Definition: Named.cxx:22