00001
00002
00003
00004
00005
00006
00007
00008
00009
00011 #include <cassert>
00012
00013 #include <TGeoManager.h>
00014 #include <TGeoVolume.h>
00015 #include <TGeoMatrix.h>
00016
00017 #include "GeoGeometry/GeoNode.h"
00018 #include "MessageService/MsgService.h"
00019
00020 ClassImp(GeoNode)
00021
00022 CVSID("$Id: GeoNode.cxx,v 1.8 2009/02/28 21:46:13 gmieg Exp $");
00023
00024
00025 GeoNode::GeoNode(GeoGeometry* geom, TGeoVolume* vol, TGeoMatrix* matrix,
00026 TGeoVolume* parVol,std::string globalpath,
00027 std::string nodename) :
00028 TGeoNodeMatrix(vol,matrix), fGeoGeometry(geom),
00029 fGlobalPath(globalpath),fGlobalMatrix(0) {
00030
00031
00032
00033 UpdateGlobalManager();
00034 this -> SetName(nodename.c_str());
00035 this -> SetParent(parVol);
00036
00037 matrix -> RegisterYourself();
00038
00039 }
00040
00041
00042
00043 GeoNode::~GeoNode() {
00044
00045
00046 UpdateGlobalManager();
00047
00048 if ( CountRef() ) {
00049 MSG("Geo",Msg::kWarning)
00050 << "GeoNode destructor " << CountRef()
00051 << " outstanding references " << endl;
00052 }
00053
00054 if ( fGlobalMatrix ) delete fGlobalMatrix; fGlobalMatrix = 0;
00055
00056 }
00057
00058
00059 void GeoNode::IncrementRef() {
00060
00061
00062 UpdateGlobalManager();
00063
00064 fRef++;
00065 fGeoGeometry->IncrementRef();
00066 SetVisibility(1);
00067
00068 }
00069
00070
00071 void GeoNode::DecrementRef() {
00072
00073
00074 UpdateGlobalManager();
00075
00076 fRef--;
00077 fGeoGeometry->DecrementRef();
00078 if (!CountRef() )SetVisibility(0);
00079 }
00080
00081
00082 void GeoNode::SetParent(TGeoVolume* parentvol) {
00083
00084
00085
00086
00087 UpdateGlobalManager();
00088
00089 if ( !parentvol ) {
00090 MSG("Geo",Msg::kWarning) << "Null parent volume arg"
00091 << "\n No action taken" << endl;
00092 return;
00093 }
00094
00095 this -> SetMotherVolume(parentvol);
00096 TObjArray* listofnodes = parentvol->GetNodes();
00097
00098 if (!listofnodes) {
00099 listofnodes = new TObjArray();
00100 parentvol -> SetNodes(listofnodes);
00101 ((TObject*)parentvol) ->
00102 ResetBit(TGeoVolume::kVolumeImportNodes);
00103 }
00104
00105 listofnodes -> Add(this);
00106 this -> SetNumber(1);
00107
00108 return;
00109
00110 }
00111
00112
00113 void GeoNode::UpdateGlobalMatrix() {
00114
00115
00116
00117
00118 UpdateGlobalManager();
00119
00120 if ( fGlobalMatrix ) {
00121
00122 MSG("Geo",Msg::kWarning) << "UpdateGlobalMatrix deleting previous matrix\n"
00123 << " for node " << this->GetName() << "." << endl;
00124 delete fGlobalMatrix;
00125 fGlobalMatrix = 0;
00126 }
00127
00128 if ( fGlobalPath.empty() ) {
00129 MSG("Geo",Msg::kFatal)
00130 << "UpdateGlobalMatrix called with empty path. Abort." << endl;
00131 abort();
00132 }
00133
00134 if ( !gGeoManager->cd(fGlobalPath.c_str()) ) {
00135 MSG("Geo",Msg::kFatal)
00136 << "UpdateGlobalMatrix unable to cd to global path\n"
00137 << fGlobalPath.c_str() << ". Abort." << endl;
00138 abort();
00139 }
00140
00141 TGeoHMatrix* currentmatrix = gGeoManager->GetCurrentMatrix();
00142 if ( currentmatrix ) {
00143
00144
00145
00146 fGlobalMatrix = new TGeoCombiTrans(*currentmatrix);
00147 }
00148 else {
00149
00150 MSG("Geo",Msg::kFatal)
00151 << "UpdateGlobalMatrix retrieved null matrix ptr from TGeoManager."
00152 << " Abort." << endl;
00153 abort();
00154 }
00155
00156 return;
00157
00158 }
00159
00160
00161 TVector3 GeoNode::LocalToGlobal(const TVector3& local) const {
00162
00163
00164 UpdateGlobalManager();
00165
00166 Double_t lxyz[3] = {local.X(),local.Y(),local.Z()};
00167 Double_t gxyz[3] = {0};
00168
00169 LocalToGlobal(lxyz,gxyz);
00170
00171 return TVector3(gxyz[0],gxyz[1],gxyz[2]);
00172
00173 }
00174
00175
00176 TVector3 GeoNode::GlobalToLocal(const TVector3& global) const {
00177
00178
00179 UpdateGlobalManager();
00180
00181 Double_t gxyz[3] = {global.X(),global.Y(),global.Z()};
00182 Double_t lxyz[3] = {0};
00183
00184 GlobalToLocal(gxyz,lxyz);
00185
00186 return TVector3(lxyz[0],lxyz[1],lxyz[2]);
00187
00188 }
00189
00190
00191 void GeoNode::LocalToGlobal(Double_t* lxyz, Double_t* gxyz) const {
00192
00193 UpdateGlobalManager();
00194
00195 if ( !fGlobalMatrix ) {
00196 MSG("Geo",Msg::kFatal) << "LocalToGlobal for node "
00197 << this->GetName() << " has null fGlobalMatrix ptr."
00198 << endl;
00199 abort();
00200 }
00201
00202 fGlobalMatrix -> LocalToMaster(lxyz,gxyz);
00203
00204
00205 }
00206
00207
00208 void GeoNode::GlobalToLocal(Double_t* gxyz, Double_t* lxyz) const {
00209
00210 UpdateGlobalManager();
00211
00212 if ( !fGlobalMatrix ) {
00213 MSG("Geo",Msg::kFatal) << "GlobalToLocal for node "
00214 << this->GetName() << " has null fGlobalMatrix ptr."
00215 << endl;
00216 abort();
00217 }
00218
00219 fGlobalMatrix -> MasterToLocal(gxyz,lxyz);
00220
00221 }
00222
00223
00224 TVector3 GeoNode::LocalToGlobalVect(const TVector3& local) const {
00225
00226
00227 UpdateGlobalManager();
00228
00229 Double_t lxyz[3] = {local.X(),local.Y(),local.Z()};
00230 Double_t gxyz[3] = {0};
00231
00232 LocalToGlobalVect(lxyz,gxyz);
00233
00234 return TVector3(gxyz[0],gxyz[1],gxyz[2]);
00235
00236 }
00237
00238
00239 TVector3 GeoNode::GlobalToLocalVect(const TVector3& global) const {
00240
00241
00242 UpdateGlobalManager();
00243
00244 Double_t gxyz[3] = {global.X(),global.Y(),global.Z()};
00245 Double_t lxyz[3] = {0};
00246
00247 GlobalToLocalVect(gxyz,lxyz);
00248
00249 return TVector3(lxyz[0],lxyz[1],lxyz[2]);
00250
00251 }
00252
00253
00254 void GeoNode::LocalToGlobalVect(Double_t* lxyz, Double_t* gxyz) const {
00255
00256 UpdateGlobalManager();
00257
00258 if ( !fGlobalMatrix ) {
00259 MSG("Geo",Msg::kFatal) << "LocalToGlobalVect for node "
00260 << this->GetName() << " has null fGlobalMatrix ptr."
00261 << endl;
00262 abort();
00263 }
00264
00265 fGlobalMatrix -> LocalToMasterVect(lxyz,gxyz);
00266
00267 }
00268
00269
00270 void GeoNode::GlobalToLocalVect(Double_t* gxyz, Double_t* lxyz) const {
00271
00272 UpdateGlobalManager();
00273
00274 if ( !fGlobalMatrix ) {
00275 MSG("Geo",Msg::kFatal) << "GlobalToLocalVect for node "
00276 << this->GetName() << " has null fGlobalMatrix ptr."
00277 << endl;
00278 abort();
00279 }
00280
00281 fGlobalMatrix -> MasterToLocalVect(gxyz,lxyz);
00282
00283 }
00284
00285