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

TestAcc.cc File Reference

#include <iostream>
#include <fstream>
#include <vector>
#include <string.h>
#include <stdio.h>
#include "TVector3.h"
#include "TNtuple.h"
#include "TFile.h"
#include "MessageService/MsgService.h"
#include "BField/BfldValidate.h"
#include "BField/BfldLoanPool.h"
#include "BField/BField.h"
#include "TestConstants.h"

Go to the source code of this file.

Functions

 CVSID ("$Id: TestAcc.cc,v 1.2 2001/08/15 18:57:27 agoldst Exp $")
void BenchmarkAccuracy (const char *outFileName, const char *rectMapFileName, const char *vorMapFileName, const char *vorMeshFileName, const char *vorBFldFileName, const char *rectAccTestPtsFileName, const char *vorAccTestPtsFileName)
bool GetAccTestPts (vector< TVector3 > &pts, vector< TVector3 > &bfld, const char *fileName)
void AccTest (const vector< TVector3 > &pts, const vector< TVector3 > &trueB, BField *field, TNtuple *outData, int algorithm)
int GetNumPointsRect (const char *fileName)
int GetNumPointsVor (const char *fileName)
BFieldNewBFieldRect (const char *mapFileName)
BFieldNewBFieldVor (const char *vorMapFileName, const char *meshFileName, const char *vorBFieldFileName)

Variables

const int kDefaultNumAccTestPts = 3012
const char kRectDataName [] = "rectData"
const char kVorDataName [] = "vorData"


Function Documentation

void AccTest const vector< TVector3 > &  pts,
const vector< TVector3 > &  trueB,
BField field,
TNtuple *  outData,
int  algorithm
 

Definition at line 133 of file TestAcc.cc.

References BField::GetBField(), MSG, and BField::SetInterpMethod().

Referenced by BenchmarkAccuracy().

00134                                                            {
00135   if(algorithm == kAlgRect) {
00136     MSG("Bfldtest",Msg::kDebug)
00137       << "Running accuracy test for rect2d algorithm..." << endl;
00138   }
00139   else {
00140     MSG("Bfldtest",Msg::kDebug)
00141       << "Running accuracy test for Voronoi algorithm..." << endl;
00142   }
00143 
00144   int i,j;
00145   TVector3 r,bt,brc,brb,brp,brv,bvc,bvp;
00146   float *row;
00147 
00148   //***Is BField smart enough to handle a change in interpolation
00149   //methods in mid-run?
00150   //I suspect not...in principle, though, it ought to work.
00151 
00152   //Write out the data into the ntuple, in the ugliest possible way.
00153 
00154   for(i = 0;i < pts.size();i++) {
00155     r = pts[i];
00156     bt = trueB[i];
00157 
00158     j = 0;
00159     if(algorithm == kAlgRect) {
00160       row = new float[18];
00161     }
00162     else {
00163       row = new float[12];
00164     }
00165 
00166     row[j] = r.X(); ++j;
00167     row[j] = r.Y(); ++j;
00168     row[j] = r.Z(); ++j;
00169     
00170     row[j] = bt.X(); ++j;
00171     row[j] = bt.Y(); ++j;
00172     row[j] = bt.Z(); ++j;
00173 
00174 
00175     if(algorithm == kAlgRect) {
00176       field->SetInterpMethod(BfldInterpMethod::kClosest);
00177       brc = field->GetBField(r);
00178       field->SetInterpMethod(BfldInterpMethod::kBilinear);
00179       brb = field->GetBField(r);
00180       field->SetInterpMethod(BfldInterpMethod::kPlanar);
00181       brp = field->GetBField(r);
00182       field->SetInterpMethod(BfldInterpMethod::kPlanarVec);
00183       brv = field->GetBField(r);
00184    
00185       row[j] = brc.X(); ++j;
00186       row[j] = brc.Y(); ++j;
00187       row[j] = brc.Z(); ++j;
00188       
00189       row[j] = brb.X(); ++j;
00190       row[j] = brb.Y(); ++j;
00191       row[j] = brb.Z(); ++j;
00192       
00193       row[j] = brp.X(); ++j;
00194       row[j] = brp.Y(); ++j;
00195       row[j] = brp.Z(); ++j;
00196       
00197       row[j] = brv.X(); ++j;
00198       row[j] = brv.Y(); ++j;
00199       row[j] = brv.Z();
00200     
00201 
00202 #ifdef WRITE_OUT_BIG_ERR_PTS
00203       double err = (brb-bt).Mag() / bt.Mag();
00204       if(err > kSmallestBigErr) {
00205         *gBigErrPtsFile << "r " << r.X() << " " << r.Y()
00206                         << " " << err << endl;
00207       }
00208 #endif
00209 
00210     }
00211     else { //so algorithm == kAlgVor
00212       field->SetInterpMethod(BfldInterpMethod::kClosest);
00213       bvc = field->GetBField(r);
00214       field->SetInterpMethod(BfldInterpMethod::kPlanar);
00215       bvp = field->GetBField(r);
00216     
00217       row[j] = bvc.X(); ++j;
00218       row[j] = bvc.Y(); ++j;
00219       row[j] = bvc.Z(); ++j;
00220 
00221       row[j] = bvp.X(); ++j;
00222       row[j] = bvp.Y(); ++j;
00223       row[j] = bvp.Z();
00224 
00225 #ifdef WRITE_OUT_BIG_ERR_PTS
00226       double err = (bvp-bt).Mag() / bt.Mag();
00227       if(err > kSmallestBigErr) {
00228         *gBigErrPtsFile << "v " << r.X() << " " << r.Y()
00229                         << " " << err << endl;
00230       }
00231 #endif
00232     } 
00233 
00234     outData->Fill(row);
00235     delete row;
00236   }
00237 }

void BenchmarkAccuracy const char *  outFileName,
const char *  rectMapFileName,
const char *  vorMapFileName,
const char *  vorMeshFileName,
const char *  vorBFldFileName,
const char *  rectAccTestPtsFileName,
const char *  vorAccTestPtsFileName
 

Referenced by main().

CVSID "$Id: TestAcc.  cc,
v 1.2 2001/08/15 18:57:27 agoldst Exp $" 
 

bool GetAccTestPts vector< TVector3 > &  pts,
vector< TVector3 > &  bfld,
const char *  fileName
 

Definition at line 239 of file TestAcc.cc.

References MSG.

Referenced by BenchmarkAccuracy().

00240                                          {
00241   //Read the data from fileName into pts and bfld
00242   //For now, assume the data will have the form of an ANSYS output file,
00243   //to wit, a series of lines of the form
00244   //id  x  y  z bx  by  bz
00245   //where all variables (including id) are floats
00246 
00247   MSG("Bfldtest",Msg::kDebug)
00248     << "Reading in test points file " << fileName << endl;
00249 
00250   ifstream inFile(fileName,ios::in);
00251   if(!inFile.good()) {
00252     MSG("Bfldtest",Msg::kWarning)
00253       << "Error opening test points file " << fileName << endl;
00254     return false;
00255   }
00256 
00257   if(pts.size() > bfld.size()) //Make sure the arrays match in size.
00258     bfld.resize(pts.size());
00259   else
00260     pts.resize(bfld.size());
00261   int n = pts.size();
00262 
00263   float id_ignored,x,y,z,bx,by,bz;
00264   int i = 0;
00265 
00266   while(!inFile.eof()) {
00267     inFile >> id_ignored >> x >> y >> z >> bx >> by >> bz;
00268     if(i >= n) { //The poor man's dynamically resizing array.
00269       n *= 2;
00270       pts.resize(n);
00271       bfld.resize(n);
00272     }
00273 
00274     pts[i].SetXYZ(x,y,z);
00275     bfld[i].SetXYZ(bx,by,bz);
00276     i++;
00277   }
00278 
00279   pts.resize(i); //Truncate the arrays to exactly the number
00280   bfld.resize(i); //of points read in.
00281 
00282   MSG("Bfldtest",Msg::kDebug)
00283     << "Read in " << i << " test points and B values." << endl;
00284   return true;
00285 }

int GetNumPointsRect const char *  fileName  ) 
 

Definition at line 20 of file Utils.cc.

00021 {
00022   //Provide an estimate of the space used by the rect2d interpolator.
00023 
00024   //Currently not implemented. But see my documentation for estimates
00025   //of this.
00026   return 0;
00027 }

int GetNumPointsVor const char *  fileName  ) 
 

Definition at line 29 of file Utils.cc.

00030 {
00031   //Provide an estimate of the size used by the Voronoi interpolator.
00032 
00033   //Currently not implemented. But see my documentation for estimates
00034   //of this.
00035   return 0;
00036 }

BField * NewBFieldRect const char *  mapFileName  ) 
 

Definition at line 44 of file Utils.cc.

References kFakeMapNum, and BField::SetInterpMethod().

00044                                                {
00045   BField *theField;
00046 
00047   //***Finish this function!
00048   //At the moment, just uses the standard $BMAPPATH/bfld_142.dat,
00049   //which should be all right. The only way to get rect2d
00050   //to use an arbitrary file is to rewrite the class a bit.
00051 
00052   VldContext theContext(Detector::kNear,SimFlag::kReroot,VldTimeStamp());
00053   theField = new BField(theContext,-1,kFakeMapNum);
00054   theField->SetInterpMethod(BfldInterpMethod::kDefault);
00055 
00056   return theField;
00057 }

BField * NewBFieldVor const char *  vorMapFileName,
const char *  meshFileName,
const char *  vorBFieldFileName
 

Definition at line 65 of file Utils.cc.

References kVorCoarseness, and BField::SetInterpMethod().

00066                                                     {
00067   //***How do I convince the BField wrapper to use arbitrary data files?
00068   //Again, it would seem that a rewrite of BField is in order.
00069   //In any case, eventually BField will have to get its data from the
00070   //database...
00071   //***Finish this function!
00072 
00073   VldContext theContext(Detector::kNear,SimFlag::kReroot,VldTimeStamp());
00074 
00075   BField *theField = new BField(theContext,kVorCoarseness,true);
00076   theField->SetInterpMethod(BfldInterpMethod::kDefault);
00077 
00078   return theField;
00079 }


Variable Documentation

const int kDefaultNumAccTestPts = 3012
 

Definition at line 20 of file TestAcc.cc.

Referenced by BenchmarkAccuracy().

const char kRectDataName[] = "rectData"
 

Definition at line 22 of file TestAcc.cc.

Referenced by BenchmarkAccuracy().

const char kVorDataName[] = "vorData"
 

Definition at line 23 of file TestAcc.cc.

Referenced by BenchmarkAccuracy().


Generated on Mon Jun 16 14:59:50 2008 for loon by  doxygen 1.3.9.1