Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

BfldHandlerVoronoi.cxx

Go to the documentation of this file.
00001 
00002 // $Id: BfldHandlerVoronoi.cxx,v 1.10 2005/02/03 22:35:49 rhatcher Exp $
00003 // 
00004 // BfldHandlerVoronoi 
00005 // 
00006 // BfldHandlerVoronoi searches and interpolates BfldMeshVoronoi grids
00007 //
00008 // Author:  R. Hatcher 2000.06.20
00009 //
00011 
00012 #include "BField/BfldHandlerVoronoi.h"
00013 
00014 #include "Conventions/Munits.h"
00015 #include "BField/BfldMapVoronoi.h"
00016 #include "BField/BfldMeshVoronoi.h"
00017 
00018 #include "BField/BFLCache.h"
00019 
00020 #include "MessageService/MsgService.h"
00021 #include "MessageService/MsgFormat.h"
00022 CVSID("$Id: BfldHandlerVoronoi.cxx,v 1.10 2005/02/03 22:35:49 rhatcher Exp $");
00023 
00024 ClassImp(BfldHandlerVoronoi)
00025 
00026 //_____________________________________________________________________________
00027 BfldHandlerVoronoi::BfldHandlerVoronoi()
00028    : BfldHandler(), fCostasHandler(0)
00029 {
00030    MSG("Bfld",Msg::kWarning) 
00031       << "BfldHandlerVoronoi::ctor" << endl;
00032 }
00033 
00034 //_____________________________________________________________________________
00035 BfldHandlerVoronoi::~BfldHandlerVoronoi()
00036 {
00037 
00038    if (fCostasHandler) delete fCostasHandler;
00039 }
00040 
00041 //_____________________________________________________________________________
00042 void BfldHandlerVoronoi::SetInterpMethod(const BfldInterpMethod::InterpMethod_t method) 
00043 {
00044    // set the interpolation method for this handler
00045    // the Voronoi specialization translates "kDefault" to "kNatural"
00046    // 
00047    // and should also disallow illegal choices
00048 
00049    static Int_t nwarn = 10;
00050 
00051    BfldInterpMethod::InterpMethod_t chosen = method;
00052 
00053    switch (chosen) {
00054    case BfldInterpMethod::kBilinear:  // not yet!
00055      break;
00056    case BfldInterpMethod::kPlanar:
00057    case BfldInterpMethod::kPlanarVec:
00058       // can't do these methods
00059       if (nwarn > 0) {
00060          nwarn--;
00061          MSG("Bfld",Msg::kWarning)
00062             << "BfldHandlerRect2d::SetInterpMethod '"
00063             << BfldInterpMethod::AsString(chosen) 
00064             << "' not supported"<< endl;
00065       }
00066       // fall through to our choice of default
00067    case BfldInterpMethod::kDefault:
00068       // pick a default method
00069       chosen = BfldInterpMethod::kNatural;
00070       break;
00071    default:
00072       // no need to adjust anything for most methods
00073       break;
00074    }
00075    
00076    BfldHandler::SetInterpMethod(chosen); // do the normal thing
00077 
00078    SetCostasInterpMethod();  // make sure Costas handler is notified
00079    
00080 }
00081 
00082 //_____________________________________________________________________________
00083 void BfldHandlerVoronoi::SetMap(BfldMap* bmap)
00084 {
00085   BfldHandler::SetMap(bmap); // do the normal thing
00086   SetCostasHandler(bmap->GetGrid());  // make sure Costas handler is attached
00087 }
00088 
00089 //_____________________________________________________________________________
00090 void BfldHandlerVoronoi::SetMesh(BfldMesh* mesh)
00091 {
00092   BfldHandler::SetMesh(mesh); // do the normal thing
00093   SetCostasHandler(mesh->GetGrid());  // make sure Costas handler is attached
00094 }
00095 
00096 //_____________________________________________________________________________
00097 void BfldHandlerVoronoi::SetCostasHandler(BfldGrid::Grid_t grid)
00098 {
00099 
00100   // this isn't really the right way to do this ...but a hack
00101   if ( ! fCostasHandler ) {
00102 
00103      MSG("Bfld",Msg::kDebug) 
00104         << "BfldHandlerVoronoi::SetCostasHandler create BFLHander" << endl;
00105 
00106     switch (grid) {
00107     case BfldGrid::kNearCoarseV: fCostasHandler = new BFLHandler(0);
00108       break;
00109     case BfldGrid::kFarCoarseV:  fCostasHandler = new BFLHandler(1);
00110       break;
00111     default:
00112       MSG("Bfld",Msg::kFatal) 
00113         << "BfldHandlerVoronoi::SetCostasHandler couldn't attach BFLHandler for " 
00114         << BfldGrid::AsString(grid) << " grid " << endl;
00115       break;
00116     }
00117     
00118     SetCostasInterpMethod();
00119 
00120     //fCostasHandler->SetLastPolygAsSeed();
00121 
00122     //  BFLHandler creates a BFLInterpolation which creates a BFLCache
00123     //  no need to explicitly do so -- it is a memory leak
00124     //BFLCache *mycached = new BFLCache;
00125     //fCostasHandler->SetCache(mycached);
00126     
00127   }
00128 
00129 }
00130 
00131 //_____________________________________________________________________________
00132 void BfldHandlerVoronoi::SetCostasInterpMethod()
00133 {
00134    // inform fCostasHandler about the interpolation approach requested
00135 
00136 //   if (fCostasHandler) fCostasHandler->SetInterpolant((int)fInterpMethod);
00137    if (fCostasHandler) fCostasHandler->SetInterpolant(fInterpMethod);
00138 }
00139 
00140 //_____________________________________________________________________________
00141 TVector3 BfldHandlerVoronoi::GetBFieldMeshCoord(const TVector3 &xyz)
00142 {
00143    // search for the right location
00144    // and then interpolate
00145 
00146    // Costas expects position in mm ...
00147    // Costas currently returns in Tesla ... 
00148 
00149    // convert position to "mm"
00150    TVector3 xyz_mm = xyz * (1./Munits::mm);
00151    // return field in "Tesla"
00152    return fCostasHandler->GetBField(xyz_mm,kTRUE) * Munits::tesla;
00153 }
00154 
00155 //_____________________________________________________________________________

Generated on Mon Feb 15 11:06:25 2010 for loon by  doxygen 1.3.9.1