00001 // @(#)root/geom:$Id: TVirtualMagField.cxx 27244 2009-01-26 17:07:51Z rdm $ 00002 00003 /************************************************************************* 00004 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * 00005 * All rights reserved. * 00006 * * 00007 * For the licensing terms see $ROOTSYS/LICENSE. * 00008 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00009 *************************************************************************/ 00010 00011 #include "TGeoGlobalMagField.h" 00012 #include "TVirtualMagField.h" 00013 00014 //______________________________________________________________________________ 00015 // TVirtualMagField - ABC for magnetic field. Derived classes are encouraged to 00016 // use the TVirtualMagField named constructor and must implement the method: 00017 // Field(const Double_t *x, Double_t *B) 00018 // 00019 // A field object can be made global via: 00020 // TGlobalMagField::Instance()->SetField(field) [1] 00021 // A field which is made global is owned by the field manager. The used is not 00022 // allowed to delete it directly anymore (otherwise a Fatal() is issued). Global 00023 // field can be deleted by calling [1] with a different argument (which can be 00024 // NULL). Otherwise the global field is deleted together with the field manager. 00025 // 00026 //______________________________________________________________________________ 00027 00028 ClassImp(TVirtualMagField) 00029 00030 //______________________________________________________________________________ 00031 TVirtualMagField::~TVirtualMagField() 00032 { 00033 // Destructor. Unregisters the field. 00034 TVirtualMagField *global_field = TGeoGlobalMagField::Instance()->GetField(); 00035 if (global_field == this) 00036 Fatal("~TVirtualMagField", "Not allowed to delete a field once set global. \ 00037 \n To delete the field call: TGeoGlobalMagField::Instance()->SetField(NULL)"); 00038 } 00039 00040 //______________________________________________________________________________ 00041 // TGeoUniformMagField - Implementation for uniform magnetic field. 00042 //______________________________________________________________________________ 00043 00044 ClassImp(TGeoUniformMagField) 00045 00046 //______________________________________________________________________________ 00047 TGeoUniformMagField::TGeoUniformMagField() 00048 :TVirtualMagField() 00049 { 00050 // Default constructor; 00051 fB[0] = 0.; 00052 fB[1] = 0.; 00053 fB[2] = 0.; 00054 } 00055 00056 //______________________________________________________________________________ 00057 TGeoUniformMagField::TGeoUniformMagField(Double_t Bx, Double_t By, Double_t Bz) 00058 :TVirtualMagField("Uniform magnetic field") 00059 { 00060 // Default constructor; 00061 fB[0] = Bx; 00062 fB[1] = By; 00063 fB[2] = Bz; 00064 }