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

EmcBhaCalib Class Reference

#include <EmcBhaCalib.h>

List of all members.

Public Member Functions

 EmcBhaCalib (const std::string &name, ISvcLocator *pSvcLocator)
 EmcBhaCalib (const std::string &name, ISvcLocator *pSvcLocator)
StatusCode execute ()
StatusCode execute ()
StatusCode finalize ()
StatusCode finalize ()
virtual void help ()
virtual void help ()
StatusCode initialize ()
StatusCode initialize ()
virtual ~EmcBhaCalib ()
virtual ~EmcBhaCalib ()

Private Member Functions

void initCalibConst ()
void initCalibConst ()
void ntupleOut ()
void ntupleOut ()
bool prepareConstants ()
bool prepareConstants ()
void printInfo (std::string xtalHitsDirFile)
void printInfo (std::string xtalHitsDirFile)
bool readInFromDB ()
bool readInFromDB ()
bool readInFromFile ()
bool readInFromFile ()
bool solveEqua ()
bool solveEqua ()
void writeOut ()
void writeOut ()
void writeOutConst ()
void writeOutConst ()

Private Attributes

NTuple::Item< float > calibConst
NTuple::Item< float > calibConst
double DigiCalibConst
NTuple::Item< float > err
NTuple::Item< float > err
NTuple::Item< float > gi0
NTuple::Item< float > gi0
NTuple::Item< long > ixtal
NTuple::Item< long > ixtal
double * m_absoluteConstants
double * m_absoluteConstants
bool m_askForMatrixInversion
double * m_calibConst
double * m_calibConst
double * m_calibConstUnred
double * m_calibConstUnred
bool m_calibrationSuccessful
double m_convCrit
int m_dirHitsCut
IEmcCalibConstSvcm_emcCalibConstSvc
IEmcCalibConstSvcm_emcCalibConstSvc
std::string m_equationSolver
std::string m_fileDir
std::string m_fileExt
bool m_fitPolynom
int m_MsgFlag
EmcBhaCalibDatam_myCalibData
EmcBhaCalibDatam_myCalibData
long int m_nrNonZeros
int m_nrXtalsEnoughHits
double * m_oldConstants
double * m_oldConstants
bool m_readDataFromDB
std::string m_runNumberFile
NTuple::Tuple * m_tuple1
NTuple::Tuple * m_tuple1
bool m_writeToFile
NTuple::Item< long > nhitxtal
NTuple::Item< long > nhitxtal


Detailed Description

class EmcBhaCalib Algorithm - performs calibration of EMC Xtals with Bhabha events and Chi^2 fit, the resulting system of linear equations of the fit is solved with the SLAP Algebra package

The matrix and the vector can either be fetched from file(s). If they are read from files the file names are supposed to have the name CalibVector.dat and calibMatrix.dat with an extension at the beginning. Only these extensions (usually the runnumbers) need to be listed in the read-in-file that is specified with runNumberFile.

Author:
Chunxiu Liu (originator/contributor etc.);


Constructor & Destructor Documentation

EmcBhaCalib::EmcBhaCalib const std::string &  name,
ISvcLocator *  pSvcLocator
 

00062   :Algorithm(name, pSvcLocator),  
00063    m_dirHitsCut(200),
00064    m_convCrit(0.000001),
00065    m_askForMatrixInversion(true),
00066    m_fitPolynom(true),  //no used now
00067    m_writeToFile(true),
00068    m_readDataFromDB(false),
00069    m_equationSolver("GMR"),
00070    m_fileExt(""),
00071    m_fileDir("/ihepbatch/besdata/public/liucx/Calib/"),
00072    m_nrNonZeros(0), 
00073    m_nrXtalsEnoughHits(0),
00074    m_runNumberFile("runnumbers.dat"),
00075    m_MsgFlag(0)
00076 
00077 {
00078 
00079   // Declare the properties  
00080   declareProperty("equationSolver", m_equationSolver);
00081   declareProperty("dirHitsCut", m_dirHitsCut);
00082   declareProperty("writeToFile", m_writeToFile);
00083   declareProperty("fileExt", m_fileExt);
00084   declareProperty("fileDir", m_fileDir);
00085   declareProperty("readDataFromDB", m_readDataFromDB);
00086   declareProperty("askForMatrixInversion", m_askForMatrixInversion);
00087   declareProperty("fitPolynom", m_fitPolynom);
00088   declareProperty("convCrit",  m_convCrit);
00089   declareProperty("runNumberFile", m_runNumberFile);
00090   declareProperty("MsgFlag", m_MsgFlag);
00091 
00092   m_calibConst = new double[6240];
00093   m_calibConstUnred = new double[6240];
00094   m_absoluteConstants = new double[6240];
00095   m_oldConstants = new double[6240];
00096 
00097 
00098   //ntuple
00099   m_tuple1=0;
00100  
00101 
00102 
00103 }

EmcBhaCalib::~EmcBhaCalib  )  [virtual]
 

00108                           {
00109   if ( 0 != m_calibConst) {
00110     delete [] m_calibConst;
00111     m_calibConst = 0;
00112   }
00113   if ( 0 != m_calibConstUnred) {
00114     delete [] m_calibConstUnred;
00115     m_calibConstUnred = 0;
00116   }
00117   if ( 0 != m_absoluteConstants) {
00118     delete [] m_absoluteConstants;
00119     m_absoluteConstants = 0;
00120   }
00121   if ( 0 != m_oldConstants) {
00122     delete [] m_oldConstants;
00123     m_oldConstants = 0;
00124   }
00125   if ( 0 != m_myCalibData) {
00126     delete m_myCalibData;
00127     m_myCalibData = 0;
00128   }
00129 
00130 }

EmcBhaCalib::EmcBhaCalib const std::string &  name,
ISvcLocator *  pSvcLocator
 

virtual EmcBhaCalib::~EmcBhaCalib  )  [virtual]
 


Member Function Documentation

StatusCode EmcBhaCalib::execute  ) 
 

StatusCode EmcBhaCalib::execute  ) 
 

00182                                 {
00183   
00184   MsgStream log(msgSvc(), name());
00185   log << MSG::DEBUG << "in execute()" << endreq;   
00186  
00187   //read in accumulated matrix/matrices
00188   if ( m_readDataFromDB ) {
00189     m_calibrationSuccessful = readInFromDB();
00190 
00191     log << MSG::INFO << "read in accumulated matrix from DB"<<endreq;
00192 
00193   } else {
00194     m_calibrationSuccessful = readInFromFile();
00195 
00196     log << MSG::INFO <<"read in accumulated matrix from file"<<endreq; 
00197 
00198   }
00199   
00200   if ( m_calibrationSuccessful == true ) {
00201     
00202     //ask first if to do a matrix inversion
00203     if (m_askForMatrixInversion==true) {
00204 
00205       m_calibrationSuccessful = false;
00206       log << MSG::INFO << " Well, we have " 
00207           << m_nrXtalsEnoughHits << " crystals whith more "
00208           << "than " <<  m_dirHitsCut 
00209           << " direct hits. Do you want do "
00210           << "a matrix inversion ? [N]" << endreq; 
00211 
00212 
00213       m_calibrationSuccessful = true;
00214 
00215     }
00216    
00217     if ( m_calibrationSuccessful == true ) {
00218       
00219       //write added matrix and vector to files
00220       if ( m_writeToFile == true) {     
00221         writeOut();
00222       }
00223       cout <<"writeout"<<endl;
00224         m_myCalibData->printVec(2);
00225       //reduce to continious array of only non zeros elements for SLAP
00226       if ( m_calibrationSuccessful = m_myCalibData->reduce() ) {
00227 
00228         cout<<"m_calibrationSuccessful="<<m_calibrationSuccessful<<endl;
00229 
00230         if ( m_myCalibData->nXtalsHit() != m_myCalibData->nXtals() ){
00231           log << MSG::INFO << " Reduced number of Xtals for calibration: " 
00232               << m_myCalibData->nXtalsHit() 
00233               << endreq;
00234         }
00235         cout<<"m_myCalibData->nXtalsHit()="<<m_myCalibData->nXtalsHit()
00236             <<"m_myCalibData->nXtals()="<<m_myCalibData->nXtals()<<endl;
00237         m_myCalibData->printVec(2);
00238 
00239         //for ( int i = 0; i< m_myCalibData->nXtals(); i++ ) {
00240         //  cout<<m_calibConst[i]<<endl;
00241         //}  
00242          
00243         //solve matrix equation
00244 
00245         if ( m_calibrationSuccessful = solveEqua() ) {
00246           
00247           // for ( int i = 0; i< m_myCalibData->nXtals(); i++ ) {
00248           //cout<<m_calibConst[i]<<endl;
00249           // }
00250  
00251           for (int i=0; i<m_myCalibData->nXtalsHit(); i++){
00252             //fill an array of constants for storage in database
00253             m_calibConstUnred[m_myCalibData->xtalInd(i)] = m_calibConst[i];
00254           }
00255            
00256           //do validation, fit polynom if necessary, fill CalList         
00257           prepareConstants();
00258           
00259           //if wanted write constants to plain ASCII file 
00260           if ( m_writeToFile==true){ 
00261             writeOutConst();
00262           }
00263 
00264           ntupleOut();
00265 
00266         }
00267         
00268       } else {
00269         log << MSG::WARNING << " Reduction of the Emc Bhabha calibration matrix FAILED !"
00270             << endl
00271             << " Will NOT perform Emc Bhabha calibration !"
00272             << endreq;
00273         return( StatusCode::FAILURE);
00274       }
00275     }
00276   } else {
00277     log << MSG::WARNING << " ERROR in reading in Emc Bhabha calibration data !"
00278         << endl
00279         << " Will NOT perform Emc Bhabha calibration !"
00280         << endreq;
00281     return( StatusCode::FAILURE);
00282   }
00283 
00284    return StatusCode::SUCCESS;
00285 }

StatusCode EmcBhaCalib::finalize  ) 
 

StatusCode EmcBhaCalib::finalize  ) 
 

00288                                  {
00289 
00290   MsgStream log(msgSvc(), name());
00291 
00292 
00293   log << MSG::INFO << "in endRun()" << endreq;
00294 
00295   return StatusCode::SUCCESS;
00296 }

virtual void EmcBhaCalib::help  )  [virtual]
 

void EmcBhaCalib::help  )  [virtual]
 

00299                   {
00300   
00301   MsgStream log(msgSvc(), name());
00302   
00303   log << MSG::INFO<< "Performs the Chi square fit of the accumulated " 
00304       << endreq;
00305 }

void EmcBhaCalib::initCalibConst  )  [private]
 

void EmcBhaCalib::initCalibConst  )  [private]
 

00309                              {
00310 
00311   
00312   MsgStream log(msgSvc(), name());
00313 
00314   for ( int i = 0; i< m_myCalibData->nXtals(); i++ ) {
00315     m_calibConst[i] = 20.;
00316   }  
00317 
00318   ifstream inConst("EmcCalib.Const");  
00319   if ( !inConst ) {
00320     log << MSG::VERBOSE  
00321         << " No starting values for calibration constants found ! "
00322         << "(EmcCalib.Const)" 
00323         << endl
00324         << "Set them to 1.0 ! " << endreq;
00325   } else {
00326     log << MSG::VERBOSE << " Read in starting values of calibration constants !"
00327         << endreq;
00328     
00329     int nConst;
00330     inConst >> nConst;
00331     log << MSG::VERBOSE << " Have starting values for " 
00332         << nConst << " Xtals !" << endl
00333         << "Set the others to 1.0 ! " << endmsg;
00334     
00335     int numberXtal;
00336     for ( int i = 0; i< nConst; i++ ) {
00337       inConst >> numberXtal >> m_calibConst[numberXtal];
00338     }
00339   }
00340   
00341   int nConstEmc;
00342       
00343   nConstEmc= m_emcCalibConstSvc -> getDigiCalibConstNo() ;
00344   log << MSG::VERBOSE << " Have starting values for " 
00345       << nConstEmc << " Xtals !" << endl
00346       << "Set the others to 1.0 ! " << endmsg;
00347   
00348   
00349   int numberXtal;
00350   //cout<<"ind"<<"  "<<"getThetaIndex(ind)"<<"  "
00351   // <<"getPhiIndex(ind)"<<"getEmcID"<<endl;
00352   for ( int i = 0; i< nConstEmc; i++ ) {
00353     numberXtal=i;
00354     m_calibConst[numberXtal]= m_emcCalibConstSvc -> getDigiCalibConst(i);
00355     //cout<<"m_calibConst[numberXtal]"<<numberXtal
00356     //<<"  "<<m_calibConst[numberXtal]<<endl;
00357 
00358     //cout<<numberXtal<<"  "
00359     //<<m_emcCalibConstSvc->getThetaIndex(numberXtal)<<"  "
00360     //<<m_emcCalibConstSvc->getPhiIndex(numberXtal)
00361     //<<"  "<<m_emcCalibConstSvc->getEmcID(numberXtal)<<endl;  
00362   }
00363 
00364   
00365 }

StatusCode EmcBhaCalib::initialize  ) 
 

StatusCode EmcBhaCalib::initialize  ) 
 

00133                                   {
00134   
00135   MsgStream log(msgSvc(), name());
00136   log << MSG::INFO << "in initialize()" << endreq;
00137 
00138      
00139   m_myCalibData = new EmcBhaCalibData(6240, m_MsgFlag);
00140 
00141   m_calibrationSuccessful = false;  
00142   
00143   StatusCode status1;
00144   
00145   NTuplePtr nt1(ntupleSvc(),"FILE302/n1");
00146   if ( nt1 ) m_tuple1 = nt1;
00147   else {
00148     m_tuple1=ntupleSvc()->book("FILE302/n1",CLID_ColumnWiseTuple,"Calib");
00149     if( m_tuple1 ) {
00150       
00151          status1 = m_tuple1->addItem ("ixtal",ixtal); 
00152          status1 = m_tuple1->addItem ("gi0",gi0);
00153          status1 = m_tuple1->addItem ("calibConst",calibConst);
00154          status1 = m_tuple1->addItem ("err",err);
00155          status1 = m_tuple1->addItem ("nhitxtal",nhitxtal);
00156       
00157     }
00158     else    {   // did not manage to book the N tuple....
00159       log << MSG::ERROR <<"Cannot book N-tuple:" << long(m_tuple1) << endmsg;
00160       return StatusCode::FAILURE;
00161     }
00162   }
00163 
00164   // use EmcCalibConstSvc
00165   StatusCode scCalib; 
00166   scCalib = Gaudi::svcLocator() -> service("EmcCalibConstSvc", m_emcCalibConstSvc);
00167   if( scCalib != StatusCode::SUCCESS){
00168     log << MSG::ERROR << "can not use EmcCalibConstSvc" << endreq;
00169   } 
00170   else {
00171     std::cout << "Test EmcCalibConstSvc   DigiCalibConst(0)=  " 
00172               << m_emcCalibConstSvc -> getDigiCalibConst(0) << std::endl;
00173   }
00174   
00175    //init starting values for calibration constants from file or set to 1
00176   initCalibConst();  
00177 
00178   return StatusCode::SUCCESS;
00179 }

void EmcBhaCalib::ntupleOut  )  [private]
 

void EmcBhaCalib::ntupleOut  )  [private]
 

00767                       {
00768 
00769   //readout inputConst from file, only for MC data
00770   std::string InconstFile = m_fileDir;
00771   InconstFile += m_fileExt;
00772   InconstFile += "CalibInput.dat"; 
00773   double inputConst[6240];
00774   ifstream inputConstfile(InconstFile.c_str());
00775   int ind=0;
00776 
00777   while( !inputConstfile.eof() ) {
00778     inputConstfile>>inputConst[ind];
00779     ind++;
00780   }
00781   inputConstfile.close();
00782 
00783   for (int i=0; i < m_myCalibData->nXtalsHit(); i++) {
00784         int xtalIndex=m_myCalibData->xtalInd(i);
00785         gi0 = 1.0/inputConst[xtalIndex];
00786         err = (m_calibConstUnred[xtalIndex]-gi0)/gi0;
00787         calibConst=m_calibConstUnred[xtalIndex];
00788         ixtal=xtalIndex;
00789         nhitxtal=m_myCalibData->xtalHitsDir(xtalIndex);
00790 
00791         m_tuple1->write();   
00792   }
00793     
00794 }

bool EmcBhaCalib::prepareConstants  )  [private]
 

bool EmcBhaCalib::prepareConstants  )  [private]
 

00707                               {
00708 
00709   bool successfull=false;
00710 
00711   //the old constant
00712   //float theCalConst = 1.0;
00713   int chanIndex;
00714   double digiCalibConst[6240];
00715 
00716   for ( int i = 0; i< m_myCalibData->nXtals(); i++ ) {
00717 
00718     chanIndex=m_myCalibData->xtalInd(i);  //xtalInd(i) array of xtal indices
00719    
00720     //the old constant
00721     m_oldConstants[chanIndex]=m_calibConst[chanIndex];
00722 
00723     //---- get the new absolute constant ----
00724     //set it to 0 if we have not enough hits -> we'll keep the old constant
00725     if ( m_myCalibData->xtalHitsDir(chanIndex) < m_dirHitsCut )
00726       m_absoluteConstants[chanIndex] = m_oldConstants[chanIndex];
00727     else 
00728       m_absoluteConstants[chanIndex] =
00729         m_oldConstants[chanIndex] * 
00730         m_calibConstUnred[chanIndex];
00731    
00732   }
00733 
00734   double DigiConst[6240];
00735   for(int ind=0; ind<m_myCalibData->nXtals(); ind++ ) {
00736     digiCalibConst[ind] =m_calibConstUnred[ind] ;
00737     DigiCalibConst=digiCalibConst[ind];
00738 
00739     DigiConst[ind]=m_absoluteConstants[ind];
00740     
00741   }
00742   
00743   //define tree fill the absolute digicalibconsts into the root-file
00744 
00745   TTree* constr= new TTree("DigiCalibConst","DigiCalibConst");
00746     constr->Branch("DigiCalibConst",DigiConst,"DigiConst[6240]/D");
00747   constr->Fill();
00748 
00749   double aa[6240];
00750    constr->SetBranchAddress("DigiCalibConst", aa);
00751    constr->GetEntry(0);
00752 
00753   TFile fconst("EmcCalibConst.root", "recreate");
00754   constr->Write();
00755 
00756    fconst.Close();
00757    delete constr;
00758 
00759    // end tree
00760 
00761    successfull=true;
00762    return successfull;
00763 
00764 }

void EmcBhaCalib::printInfo std::string  xtalHitsDirFile  )  [private]
 

void EmcBhaCalib::printInfo std::string  xtalHitsDirFile  )  [private]
 

00798                                          {
00799 
00800   ofstream xtalHitsDirOut;
00801   std::string xtalHitsDirFile = m_fileDir;
00802   xtalHitsDirFile += m_fileExt;
00803   xtalHitsDirFile += fileName;
00804   xtalHitsDirOut.open(xtalHitsDirFile.c_str());
00805 
00806   //nXtalsHit() is number of xtals hit
00807   for (int i=0; i < m_myCalibData->nXtalsHit(); i++) {
00808     if ( m_myCalibData->xtalHitsDir(i) > m_dirHitsCut ) 
00809       {
00810         int chanindex=m_myCalibData->xtalInd(i);
00811         xtalHitsDirOut<<chanindex<<endl;
00812       }
00813   }
00814   xtalHitsDirOut.close();
00815 
00816 }

bool EmcBhaCalib::readInFromDB  )  [private]
 

bool EmcBhaCalib::readInFromDB  )  [private]
 

00698                           {
00699 
00700   bool success = true;
00701 
00702   return success;
00703 }

bool EmcBhaCalib::readInFromFile  )  [private]
 

bool EmcBhaCalib::readInFromFile  )  [private]
 

00594                             {
00595 
00596   MsgStream log(msgSvc(), name());
00597 
00598   log << MSG::INFO << " Read Bhabha calibration data from files !"
00599                   << endreq;
00600 
00601   std::string runNumberFile = m_fileDir;
00602   runNumberFile += m_fileExt;
00603   runNumberFile += m_runNumberFile;
00604 
00605   bool success = false;
00606   log << MSG::INFO << " Get file names from input file : " 
00607       << runNumberFile
00608       << endreq;
00609   
00610   std::string vectorFile;
00611   std::string matrixFile;
00612 
00613   log << MSG::INFO  << "Runnumber    non-zeros    xtals"
00614       << endreq;   
00615 
00616   ifstream datafile(runNumberFile.c_str());
00617 
00618   //cout<<"datafile="<<runNumberFile.c_str()<<""<<datafile.good()<<endl;
00619 
00620   if (datafile.good() > 0 ) {
00621     
00622     while( !datafile.eof() ) {
00623       
00624       ifstream vectorIn;
00625       ifstream matrixIn;
00626       
00627       std::string num;
00628       datafile >> num;
00629       
00630       if ( num.length() > 0 ) {
00631         
00632         vectorFile = m_fileDir;
00633         vectorFile += m_fileExt;
00634         vectorFile += num;
00635         vectorFile += "CalibVector.dat"; 
00636 
00637         matrixFile = m_fileDir;
00638         matrixFile += m_fileExt;
00639         matrixFile += num;
00640         matrixFile += "CalibMatrix.dat";
00641 
00642         vectorIn.open(vectorFile.c_str());
00643         matrixIn.open(matrixFile.c_str());
00644 
00645         if ( vectorIn.good() > 0 && matrixIn.good() > 0 ) {
00646           
00647           m_myCalibData->readIn(matrixIn,vectorIn);
00648           
00649           log << MSG::INFO << num 
00650               << "          "     
00651               << m_myCalibData->getMatrixM()->num_nonZeros()
00652               << "       "
00653               << m_myCalibData->nXtalsHit() 
00654               << endreq;
00655 
00656           success = true;
00657 
00658         }
00659         else {
00660           if ( !vectorIn )
00661             log << MSG::ERROR << " ERROR: Vector input file "
00662                 << vectorFile
00663                 <<  " doesn't exist !" << endreq;
00664           if ( !matrixIn )
00665             log << MSG::ERROR << " ERROR: Matrix input file "
00666                 << matrixFile
00667                 << " doesn't exist !" << endreq;
00668         }
00669         vectorIn.close();
00670         matrixIn.close();
00671       }
00672     }
00673   }
00674 
00675   if ( success == true) {
00676 
00677     for (int i=0; i < m_myCalibData->nXtals(); i++) {
00678       if ( m_myCalibData->xtalHitsDir(i) > m_dirHitsCut ) 
00679         {
00680           m_nrXtalsEnoughHits++;
00681         }
00682     }
00683     m_nrNonZeros = m_myCalibData->getMatrixM()->num_nonZeros();
00684     log << MSG::INFO<< " Final matrix :  "
00685         << "Number of non zero elements: " << m_nrNonZeros 
00686         << "       "
00687         << m_myCalibData->nXtalsHit()
00688         << endreq;
00689 
00690   }
00691 
00692 
00693   return success;
00694 }

bool EmcBhaCalib::solveEqua  )  [private]
 

bool EmcBhaCalib::solveEqua  )  [private]
 

00370                        {
00371   
00372   MsgStream log(msgSvc(), name());
00373   //-----------------------------------------------------
00374   //  solve system of equations with SLAP package 
00375   //-----------------------------------------------------
00376   log << MSG::VERBOSE << " Solve Matrix equation with method " 
00377       << m_equationSolver
00378       << endl
00379       << "Xtals hit: " << m_myCalibData->nXtalsHit() 
00380       << endl
00381       << "Nr of non Zeros: " << m_nrNonZeros << endreq;
00382   
00383   //input parameters for SLAP
00384   long int isym = 1;     //matrix M is symmetric
00385   long int nsave = 20;
00386   long int itol = 0;     //type of convergence criterion
00387   double convCriterion = m_convCrit;    //convergence crtiterion
00388   long int maxIter = 1000;    //maximum number of iterations
00389   long int errUnit = 6;     //unit on which to write error estimation
00390   // at each iteration  
00391 
00392   //working arrays needed by SLAP
00393   long int lengthDoubleWork;
00394   double* doubleWork;
00395   long int lengthIntWork;
00396   long int* intWork;
00397 
00398   //output parameters of slap
00399   long int iters=0;           //number of iterations required
00400   double errorv=1000;        //error estimate
00401   long int errorFlag;  
00402 
00403   //sparse Ax=b solver.
00404   //uses the generalized minimum residual method 
00405   //The preconditioner  is   diagonal scaling.
00406   if ( m_equationSolver == "GMR" ) {
00407 
00408     cout<<m_equationSolver<<endl;
00409 
00410     //workspaces
00411     lengthDoubleWork = (1 + m_myCalibData->nXtals()*(nsave+7) 
00412                          + nsave*(nsave+3))
00413                          + 50000;
00414     doubleWork = new double[lengthDoubleWork];
00415     lengthIntWork = 50;
00416     intWork = new long int [lengthIntWork];
00417   
00418     dsdgmr_ ( &(m_myCalibData->nXtalsHit()),
00419               m_myCalibData->getVectorR(),
00420               m_calibConst,
00421               &m_nrNonZeros,
00422               m_myCalibData->getMatrixM()->row(),
00423               m_myCalibData->getMatrixM()->column(),
00424               m_myCalibData->getMatrixM()->matrix(),
00425               &isym,
00426               &nsave,
00427               &itol,
00428               &convCriterion,
00429               &maxIter,
00430               &iters,
00431               &errorv,
00432               &errorFlag,
00433               &errUnit,
00434               doubleWork,
00435               &lengthDoubleWork,
00436               intWork,
00437               &lengthIntWork
00438              );
00439           
00440     log << MSG::VERBOSE << " Error flag: " <<  errorFlag << endreq;
00441     if ( errorFlag < 0 ) errorFlag = labs(errorFlag) + 2;
00442     switch ( errorFlag ) {
00443     case 0: log << MSG::VERBOSE << " all went well" 
00444                 << endreq; break;
00445     case 1: log << MSG::ERROR << " insufficient storage allocated for _doubleWork or _intWork" 
00446                 << endreq; break;
00447     case 2: log << MSG::ERROR << " method failed to reduce norm of current residual" 
00448                 << endreq; break;
00449     case 3: log << MSG::ERROR << " insufficient length for _doubleWork" 
00450                 << endreq; break;
00451     case 4: log << MSG::ERROR << " inconsistent _itol and  values" 
00452                 << endreq; break;
00453     default: log << MSG::ERROR << " unknown flag" << endreq; 
00454     }
00455     log << MSG::VERBOSE << " Integer workspace used = " << intWork[8] << endl
00456         << " Double  workspace used = " << intWork[9] << endreq;
00457   }
00458 
00459   //Routine to solve a  symmetric positive definite  linear
00460   //system Ax  =  b  using   the  Preconditioned  Conjugate
00461   //Gradient   method.    The preconditioner  is   diagonal scaling.
00462   if ( m_equationSolver == "PCG" ) {
00463     
00464     cout<<m_equationSolver<<endl;
00465 
00466     itol = 1; 
00467 
00468     //workspaces
00469     lengthDoubleWork = 5 *m_myCalibData->nXtals() + 50000;
00470     doubleWork = new double[lengthDoubleWork];
00471     lengthIntWork = 50;
00472     intWork = new long int [lengthIntWork];
00473        
00474     dsdcg_( &(m_myCalibData->nXtalsHit()),
00475             m_myCalibData->getVectorR(),
00476             m_calibConst,
00477             &m_nrNonZeros,
00478             m_myCalibData->getMatrixM()->row(),
00479             m_myCalibData->getMatrixM()->column(),
00480             m_myCalibData->getMatrixM()->matrix(),
00481             &isym,
00482             &itol,
00483             &convCriterion,
00484             &maxIter,
00485             &iters,
00486             &errorv,
00487             &errorFlag,
00488             &errUnit,
00489             doubleWork,
00490             &lengthDoubleWork,
00491             intWork,
00492             &lengthIntWork
00493             );
00494       
00495     switch ( errorFlag ) {
00496     case 0: log << MSG::VERBOSE << "all went well" << endreq; break;
00497     case 1: log << MSG::ERROR << " insufficient storage allocated for WORK or IWORK" 
00498                 << endreq; break;
00499     case 2: log << MSG::ERROR << " method failed to to converge in maxIter steps." 
00500                 << endreq; break;
00501     case 3:log << MSG::ERROR << " Error in user input.  Check input value of _nXtal,_itol." 
00502                << endreq; break;
00503     case 4:log << MSG::ERROR << " User error tolerance set too tight. "
00504                << "Reset to 500.0*D1MACH(3).  Iteration proceeded." 
00505                << endreq; break;
00506     case 5:log << MSG::ERROR << " Preconditioning matrix, M,  is not Positive Definite. "
00507                << endreq; break;
00508     case 6: log << MSG::ERROR << " Matrix A is not Positive Definite."
00509                 << endreq; break;
00510     default: log << MSG::ERROR << " unknown flag" << endreq; 
00511     }
00512      log << MSG::VERBOSE << " Integer workspace used = " << intWork[9] << endl
00513                     << "Double  workspace used = " << intWork[10] << endreq;
00514   }
00515 
00516    log << MSG::VERBOSE << "------ Calibration fit statistics ------- " << endl
00517                   << "maximum number of iterations =" << maxIter << endl
00518                   << "        number of iterations =" << iters << endl
00519                   << "error estimate of error in final solution =" 
00520                   << errorv << endreq;
00521 
00522   if ( 0 != doubleWork) delete [] doubleWork;     
00523   if ( 0 != intWork) delete [] intWork;
00524 
00525   if ( errorFlag != 0 ) return false;
00526   else return true; 
00527 
00528   return true;
00529 }

void EmcBhaCalib::writeOut  )  [private]
 

void EmcBhaCalib::writeOut  )  [private]
 

00533                       {
00534 
00535   ofstream vectorOut;
00536   std::string vectorFile = m_fileDir;
00537   vectorFile += m_fileExt;
00538   vectorFile += "allCalibVector.dat";
00539   vectorOut.open(vectorFile.c_str());
00540 
00541   ofstream matrixOut;
00542   std::string matrixFile = m_fileDir;
00543   matrixFile += m_fileExt;
00544   matrixFile += "allCalibMatrix.dat";
00545   matrixOut.open(matrixFile.c_str());
00546 
00547   MsgStream log(msgSvc(), name());
00548 
00549   log << MSG::VERBOSE << " Write out files " 
00550       << vectorFile << "   " 
00551       << matrixFile
00552       << endreq;
00553 
00554   m_myCalibData->writeOut(matrixOut,vectorOut);
00555 
00556   vectorOut.close();
00557   matrixOut.close();
00558 
00559 }

void EmcBhaCalib::writeOutConst  )  [private]
 

void EmcBhaCalib::writeOutConst  )  [private]
 

00563                            {
00564   
00565   ofstream constOut;  
00566 
00567   std::string constFile = m_fileDir;
00568   constFile += m_fileExt;
00569   constFile += "CalibConst.dat";
00570 
00571   constOut.open(constFile.c_str());
00572   
00573   constOut << "#crystalIndex relative-constant absolute-constant" << endl;
00574     
00575   //output constants to file
00576   for ( int i=0; i < m_myCalibData->nXtals(); i++) {
00577 
00578     long Xtal_Index = i;
00579   
00580 
00581     if(m_calibConstUnred[Xtal_Index]>0){
00582       constOut << Xtal_Index << " " 
00583                << m_calibConstUnred[Xtal_Index] << " " 
00584                << m_absoluteConstants[Xtal_Index]
00585                << endl; 
00586     }
00587   }
00588   constOut.close();
00589 
00590 }


Member Data Documentation

NTuple::Item<float> EmcBhaCalib::calibConst [private]
 

NTuple::Item<float> EmcBhaCalib::calibConst [private]
 

double EmcBhaCalib::DigiCalibConst [private]
 

NTuple::Item<float> EmcBhaCalib::err [private]
 

NTuple::Item<float> EmcBhaCalib::err [private]
 

NTuple::Item<float> EmcBhaCalib::gi0 [private]
 

NTuple::Item<float> EmcBhaCalib::gi0 [private]
 

NTuple::Item<long> EmcBhaCalib::ixtal [private]
 

NTuple::Item<long> EmcBhaCalib::ixtal [private]
 

double* EmcBhaCalib::m_absoluteConstants [private]
 

double* EmcBhaCalib::m_absoluteConstants [private]
 

bool EmcBhaCalib::m_askForMatrixInversion [private]
 

double* EmcBhaCalib::m_calibConst [private]
 

double* EmcBhaCalib::m_calibConst [private]
 

double* EmcBhaCalib::m_calibConstUnred [private]
 

double* EmcBhaCalib::m_calibConstUnred [private]
 

bool EmcBhaCalib::m_calibrationSuccessful [private]
 

double EmcBhaCalib::m_convCrit [private]
 

int EmcBhaCalib::m_dirHitsCut [private]
 

IEmcCalibConstSvc* EmcBhaCalib::m_emcCalibConstSvc [private]
 

IEmcCalibConstSvc* EmcBhaCalib::m_emcCalibConstSvc [private]
 

std::string EmcBhaCalib::m_equationSolver [private]
 

std::string EmcBhaCalib::m_fileDir [private]
 

std::string EmcBhaCalib::m_fileExt [private]
 

bool EmcBhaCalib::m_fitPolynom [private]
 

int EmcBhaCalib::m_MsgFlag [private]
 

EmcBhaCalibData* EmcBhaCalib::m_myCalibData [private]
 

EmcBhaCalibData* EmcBhaCalib::m_myCalibData [private]
 

long int EmcBhaCalib::m_nrNonZeros [private]
 

int EmcBhaCalib::m_nrXtalsEnoughHits [private]
 

double* EmcBhaCalib::m_oldConstants [private]
 

double* EmcBhaCalib::m_oldConstants [private]
 

bool EmcBhaCalib::m_readDataFromDB [private]
 

std::string EmcBhaCalib::m_runNumberFile [private]
 

NTuple::Tuple* EmcBhaCalib::m_tuple1 [private]
 

NTuple::Tuple* EmcBhaCalib::m_tuple1 [private]
 

bool EmcBhaCalib::m_writeToFile [private]
 

NTuple::Item<long> EmcBhaCalib::nhitxtal [private]
 

NTuple::Item<long> EmcBhaCalib::nhitxtal [private]
 


The documentation for this class was generated from the following files:
Generated on Wed Feb 2 16:01:07 2011 for BOSS6.5.5 by  doxygen 1.3.9.1