00001
00002
00003
00004 #include "StiDetectorVolume.h"
00005
00006 #include "TVolumePosition.h"
00007 #include "TRotMatrix.h"
00008 #include "TTUBS.h"
00009 #include "TBRIK.h"
00010 #include "TMath.h"
00011 #include "TGeometry.h"
00012 #include "Sti/StiPlanarShape.h"
00013 #include "Sti/StiCylindricalShape.h"
00014 #include "Sti/StiGenericDetectorGroup.h"
00015 #include "Sti/StiDetector.h"
00016 #include "Sti/StiDetectorGroups.h"
00017 #include "Sti/StiDetectorBuilder.h"
00018 #include "Sti/StiPlacement.h"
00019 #include "Sti/StiMaterial.h"
00020 #include "Sti/StiToolkit.h"
00021
00022 #if 0
00023
00024 static Bool_t CompareMatrix(TRotMatrix &a,TRotMatrix &b)
00025 {
00026
00027 double *pa=a.GetMatrix(); double *pb=b.GetMatrix();
00028 for (int i=0; i<9; i++) if (pa[i]!=pb[i]) return kFALSE;
00029 return kTRUE;
00030 }
00031 #endif
00032
00033
00034 inline static TRotMatrix *GetMatrix(float angle)
00035 {
00036
00037 Double_t m[9] = {
00038 TMath::Cos(angle), -TMath::Sin(angle), 0
00039 ,TMath::Sin(angle), TMath::Cos(angle), 0
00040 , 0 , 0 , 1
00041 };
00042
00043 TRotMatrix *mat = new TRotMatrix();
00044 mat->SetMatrix(m);
00045 return mat;
00046 }
00047
00048
00049
00050
00051 ClassImp(StiDetectorVolume)
00052
00053
00054
00055
00056
00057 StiDetectorVolume::StiDetectorVolume(StiToolkit &tool, const TString &detectorName, unsigned int select)
00058 : TVolume("RnD","Sti",(TShape*)0),fDetector(0)
00059 {
00060 MakeDetector(tool,detectorName, select);
00061 }
00062
00063
00064 StiDetectorVolume::StiDetectorVolume(const StiDetectorBuilder &builder, unsigned int select) :
00065 TVolume(builder.getName().c_str(),"StiDetectorBuilder",(TShape *)0),fDetector(0)
00066 {
00067 MakeVolume(builder,select);
00068 }
00069
00070
00071 StiDetectorVolume::StiDetectorVolume(StiDetector *detector) :
00072 TVolume(),fDetector(detector) { }
00073
00074
00075 StiDetectorVolume::StiDetectorVolume(StiDetector *detector,const Text_t* name, const Text_t* title, const Text_t* shapename, Option_t* option):
00076 TVolume( name, title, shapename, option),fDetector(detector) { }
00077
00078
00079 StiDetectorVolume::StiDetectorVolume(StiDetector *detector,const Text_t* name, const Text_t* title, TShape* shape, Option_t* option):
00080 TVolume(name,title,shape,option ),fDetector(detector) { }
00081
00082
00083 void StiDetectorVolume::Browse(TBrowser *b)
00084 {
00085 TVolume::Browse(b);
00086 }
00087
00088 char *StiDetectorVolume::GetObjectInfo(Int_t px, Int_t py) const
00089 {
00090 return TVolume::GetObjectInfo(px, py);
00091 }
00092
00093 void StiDetectorVolume::MakeDetector(StiToolkit &tool, const TString &detectorName, unsigned int select)
00094 {
00095
00096 StiDetectorGroups *groups=tool.getDetectorGroups();
00097 vector<StiGenericDetectorGroup *>::iterator it = groups->begin();
00098 for (; it != groups->end(); ++it) {
00099 StiGenericDetectorGroup *group = *it;
00100 const StiDetectorBuilder &builder = *group->getDetectorBuilder();
00101 TString builderName = (const char*)builder.getName().c_str();
00102 if ( detectorName.IsNull() || (builderName.BeginsWith(detectorName,TString::kIgnoreCase)) )
00103 Add(new StiDetectorVolume(builder,select));
00104 else {
00105 LOG_INFO << "Skip " << (const char*)builder.getName().c_str() << " detector" << endm;
00106 }
00107 }
00108 }
00109
00110 void StiDetectorVolume::MakeVolume(const StiDetectorBuilder &builder, unsigned int select)
00111 {
00112
00113 unsigned int nRows = builder.getNRows();
00114 LOG_INFO << "Builder: " << builder.getName().c_str() << " has " << nRows << " rows" << endm;
00115 for (unsigned int i=0; i < nRows; i++) {
00116 unsigned int nSectors = builder.getNSectors(i);
00117 Int_t iColor = 3 + i%6;
00118 for (unsigned int j=0;j<nSectors;j++)
00119 {
00120 StiDetector *next = builder.getDetector(i,j) ;
00121 if (!next) {
00122 LOG_ERROR << "The is no detector for row " << i <<" sector " << j << endm;
00123 continue;
00124 }
00125 if (select && ( ( select == kActive && !next->isActive())
00126 ||
00127 ( select == kPassivie && next->isActive() )
00128 ) ) continue;
00129 const StiShape *stiShape = next->getShape();
00130 TShape *shape = MakeShape(stiShape
00131 ,(const char*)next->getMaterial()->getName().c_str() );
00132 StiPlacement *place = next->getPlacement();
00133 TString canonicName = (const char*)next->getName().c_str();
00134 canonicName.ReplaceAll("/","_");
00135 StiDetectorVolume *nextVolume = new StiDetectorVolume(next,(const char*)canonicName,"StiDetector",shape);
00136 nextVolume->SetFillColor(iColor); nextVolume->SetLineColor(iColor);
00137 bool planar = (stiShape->getShapeCode() == kPlanar);
00138 TVolumePosition *position = 0;
00139 if (planar) {
00140 if (place->getNormalRefAngle() != 0) {
00141 position = new TVolumePosition(0, 0, 0, 0, GetMatrix(place->getNormalRefAngle()));
00142 position->SetMatrixOwner();
00143 TVolumePosition *translate= new TVolumePosition (0
00144 ,place->getNormalYoffset()
00145 ,place->getNormalRadius()
00146 ,place->getZcenter()
00147 );
00148 position->Mult(*translate );
00149 delete translate;
00150 } else {
00151 position = new TVolumePosition(0
00152 ,place->getNormalYoffset()
00153 ,place->getNormalRadius()
00154 ,place->getZcenter()
00155 ,GetMatrix(place->getNormalRefAngle())
00156 );
00157 }
00158 } else {
00159 position = new TVolumePosition(0, 0, 0, place->getZcenter());
00160 }
00161 position->SetNode(nextVolume);
00162 Add(nextVolume,position);
00163 #if 1
00164 nextVolume->Print();
00165 TShape *sh = nextVolume->GetShape();
00166 sh->Print();
00167
00168 if (sh->InheritsFrom("TBRIK")) {
00169 TBRIK *brik = (TBRIK *) sh;
00170 cout << " dx " << brik->GetDx()
00171 << " dy " << brik->GetDy()
00172 << " dz " << brik->GetDz() << endl;
00173 } else {
00174 if (sh->InheritsFrom("TTUBE")) {
00175 TTUBE *tube = (TTUBE *) sh;
00176 cout << " Rmin " << tube->GetRmin()
00177 << " Rmax " << tube->GetRmax()
00178 << " dz " << tube->GetDz();
00179 }
00180 if (sh->InheritsFrom("TTUBS")) {
00181 TTUBS *tubs = (TTUBS *) sh;
00182 cout << " Phi1 " << tubs->GetPhi1()
00183 << " Phi2 " << tubs->GetPhi2();
00184 }
00185 cout << endl;
00186 }
00187 position->Print();
00188 #endif
00189 }
00190 }
00191 }
00192
00193
00194 TShape *StiDetectorVolume::MakeShape(const StiShape *shape, const char*material)
00195 {
00196 TShape *rootShape=0;
00197 if (shape) {
00198 switch (shape->getShapeCode()) {
00199 case kPlanar:
00200 rootShape = MakeShape(*(const StiPlanarShape *)shape,material);
00201 break;
00202 case kCylindrical:
00203 rootShape = MakeShape(*(const StiCylindricalShape *)shape,material);
00204 break;
00205 default: assert(0);
00206 }
00207 }
00208 return rootShape;
00209 }
00210
00211
00212 TShape *StiDetectorVolume::MakeShape(const StiPlanarShape &shape,const char*material)
00213 {
00214 return
00215 new TBRIK((const char*)shape.getName().c_str()
00216 , "StiPlanarShape"
00217 , material
00218 , shape.getHalfWidth()
00219 , shape.getThickness()/2
00220 , shape.getHalfDepth() );
00221 }
00222
00223
00224 TShape *StiDetectorVolume::MakeShape(const StiCylindricalShape &shape,const char*material)
00225 {
00226 return (shape.getOpeningAngle() < (TMath::TwoPi()-0.001) ) ?
00227 new TTUBS((const char*)shape.getName().c_str()
00228 , "StiCylindricalShape"
00229 , material
00230 , shape.getOuterRadius() - shape.getThickness()
00231 , shape.getOuterRadius()
00232 , shape.getHalfDepth()
00233 , -shape.getOpeningAngle()/2
00234 , +shape.getOpeningAngle()/2 )
00235 :
00236 new TTUBE((const char*)shape.getName().c_str()
00237 , "StiCylindricalShape"
00238 , material
00239 , shape.getOuterRadius() - shape.getThickness()
00240 , shape.getOuterRadius()
00241 , shape.getHalfDepth()
00242 );
00243 }