/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Emc/EmcCalib/EmcBhaCalib/EmcBhaCalib-00-00-34/src/EmcBhaCalibData.cxx

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //     
00004 //
00005 // Description:
00006 //      Class EmcBhaCalibData - see header
00007 //
00008 // Environment:
00009 //      Software developed for the BESIII Detector at the BEPCII.
00010 //
00011 // Author List:
00012 //      Chunxiu Liu
00013 //
00014 // Copyright Information:
00015 //      Copyright (C) 2005           IHEP
00016 //
00017 //------------------------------------------------------------------------
00018 
00019 //-----------------------
00020 // This Class's Header --
00021 //-----------------------
00022 #include "EmcBhaCalib/EmcBhaCalibData.h"
00023 
00024 //-------------
00025 // C Headers --
00026 //-------------
00027 extern "C" {
00028 }
00029 
00030 //---------------
00031 // C++ Headers --
00032 //---------------
00033 
00034 #include <cstring>
00035 
00036 using namespace std;
00037 //-------------------------------
00038 // Collaborating Class Headers --
00039 //-------------------------------
00040 
00041 //              ----------------------------------------
00042 //              -- Public Function Member Definitions --
00043 //              ----------------------------------------
00044 
00045 //----------------
00046 // Constructors --
00047 //----------------
00048 EmcBhaCalibData::EmcBhaCalibData(int numxtals)
00049   : _nXtals(numxtals),
00050     _nXtalsHit(0)
00051 {
00052   //  _matrixM = new EmcLSSMatrix(_nXtals,600);
00053   _matrixM = new EmcLSSMatrix(_nXtals,_nXtals);
00054   _vectorR = new double[_nXtals];
00055   _xtalInd = new int[_nXtals];
00056   _xtalHits = new int[_nXtals];
00057   _xtalHitsMax = new int[_nXtals];
00058   for (int i=0;i<_nXtals;i++) {
00059     _vectorR[i] = 0.;
00060     _xtalInd[i] = i;  
00061     _xtalHits[i] = 0;
00062     _xtalHitsMax[i] = 0;
00063   }
00064   _MsgFlag =0;
00065 }
00066 
00067 //----------------
00068 // Constructors --
00069 //----------------
00070 EmcBhaCalibData::EmcBhaCalibData(int numxtals, int MsgFlag)
00071   : _nXtals(numxtals),
00072     _nXtalsHit(0)
00073 {
00074   //  _matrixM = new EmcLSSMatrix(_nXtals,600);
00075   _matrixM = new EmcLSSMatrix(_nXtals,_nXtals, MsgFlag);
00076   _vectorR = new double[_nXtals];
00077   _xtalInd = new int[_nXtals];
00078   _xtalHits = new int[_nXtals];
00079   _xtalHitsMax = new int[_nXtals];
00080   for (int i=0;i<_nXtals;i++) {
00081     _vectorR[i] = 0.;
00082     _xtalInd[i] = i;
00083     _xtalHits[i] = 0;
00084     _xtalHitsMax[i] = 0;
00085   }
00086 
00087   _MsgFlag = MsgFlag;
00088 }
00089 
00090 //--------------
00091 // Destructor --
00092 //--------------
00093 EmcBhaCalibData::~EmcBhaCalibData() {
00094   if ( 0 != _matrixM) {
00095     delete _matrixM; 
00096     _matrixM = 0;
00097   }
00098   if ( 0 != _vectorR) {
00099     delete[] _vectorR;
00100     _vectorR = 0;
00101   }
00102   if ( 0 != _xtalInd) {
00103     delete[] _xtalInd;
00104     _xtalInd = 0;
00105   }
00106   if ( 0 != _xtalHits) {
00107     delete[] _xtalHits;
00108     _xtalHits = 0;
00109   }
00110   if ( 0 != _xtalHitsMax) {
00111     delete[] _xtalHitsMax;
00112     _xtalHitsMax = 0;
00113   }
00114 }
00115 //-------------
00116 // Operators --
00117 //-------------
00118 
00119     
00120 //-------------
00121 // Selectors --
00122 //-------------
00123 
00124 
00125 //-------------
00126 // Modifiers --
00127 //-------------
00128 
00129 void
00130 EmcBhaCalibData::writeOut( ostream& OutM, ostream& OutV) {
00131 
00132   //write only non zero elements to file
00133   OutM.setf(ios::scientific,ios::floatfield);
00134   OutV.setf(ios::scientific,ios::floatfield);
00135   OutV.precision(12);
00136   OutM.precision(12);
00137 
00138   _matrixM->writeOut( OutM );
00139 
00140   _nXtalsHit = 0;
00141 
00142   double* vect_ele = _vectorR;
00143   double* vect_end = _vectorR + _nXtals;
00144   int* xtal_ind = _xtalInd;
00145   int* hits_max = _xtalHitsMax;
00146   int* hits = _xtalHits;
00147 
00148   while ( vect_ele < vect_end ) {
00149     if ( *vect_ele != 0.  ){
00150       _nXtalsHit++;
00151     }
00152     vect_ele++;
00153   }
00154 
00155   OutV << _nXtalsHit << " ";
00156 
00157   vect_ele = _vectorR;
00158 
00159   while ( vect_ele < vect_end ) {
00160     if ( *vect_ele != 0. ) {
00161       OutV << *xtal_ind << " " << *hits << " " << *hits_max << " " 
00162            << *vect_ele << " ";
00163     }
00164     xtal_ind++;
00165     vect_ele++;
00166     hits_max++;
00167     hits++;
00168   }
00169 
00170 }
00171 
00172 
00173 void
00174 EmcBhaCalibData::readIn( istream& InM, istream& InV) {
00175 
00176   _matrixM->readIn( InM );
00177   
00178   _matrixM->print_NonZeros();
00179 
00180   //cout<<"num_filled_rows(48)="<<_matrixM->num_filled_rows(48)<<endl;
00181   //cout<<"num_filled_cols(48)="<<_matrixM->num_filled_cols(48)<<endl;
00182 
00183   //cout<<"matrix(47,47)"<<_matrixM->operator()(47,47)<<endl;
00184 
00185   double vect_ele;
00186   int nr_ele;
00187   int xtal_ind;
00188   int hits;
00189   int hits_max;
00190 
00191   InV >> nr_ele;
00192 
00193   for (int i=0; i<nr_ele; i++) {
00194 
00195     InV >> xtal_ind >> hits >> hits_max
00196         >> vect_ele ;
00197 
00198     if (_vectorR[xtal_ind] == 0. ) {
00199       _nXtalsHit++;
00200     }
00201     
00202     _vectorR[xtal_ind] += vect_ele ;
00203     _xtalInd[xtal_ind] = xtal_ind;
00204     _xtalHits[xtal_ind] += hits;
00205     _xtalHitsMax[xtal_ind] += hits_max;
00206 
00207  }
00208 
00209 }
00210 
00211 bool
00212 EmcBhaCalibData::reduce() {
00213 
00214   bool successful = true;
00215 
00216   //delete all zero elements in matrix and vector R
00217   //save only non zero elements (this format is needed by slap),
00218   //keep the original xtal index in array xtalInd
00219 
00220   //array to store the new row/column reference for later matrix reduction 
00221   int* xRef = new int[_nXtals];
00222   memset(xRef, -1, (_nXtals*sizeof(int)));
00223 
00224   _nXtalsHit = 0;
00225   for ( int _arrayIndx = 0; 
00226         _arrayIndx < _nXtals; _arrayIndx++) {
00227 
00228     if ( _vectorR[_arrayIndx] > 0. ) {
00229 
00230       _vectorR[_nXtalsHit] = _vectorR[_arrayIndx];
00231       _xtalInd[_nXtalsHit] = _xtalInd[_arrayIndx];
00232       _xtalHits[_nXtalsHit] = _xtalHits[_arrayIndx];
00233       _xtalHitsMax[_nXtalsHit] = _xtalHitsMax[_arrayIndx];
00234       xRef[_arrayIndx] = _nXtalsHit;
00235 
00236       _nXtalsHit++;
00237     }
00238   }
00239 
00240   successful = _matrixM->reduce_Matrix( xRef );
00241 
00242   delete [] xRef;
00243 
00244   return successful;
00245 }
00246 
00247 
00248 void
00249 EmcBhaCalibData::reset() 
00250 {
00251   _nXtalsHit = 0;
00252   _matrixM->reset();
00253 
00254   for (int i=0;i<_nXtals;i++) {
00255     _vectorR[i]= 0.;
00256     _xtalInd[i] = i;
00257     _xtalHits[i] = 0;
00258     _xtalHitsMax[i] = 0;
00259   }
00260 
00261 }
00262 
00263 
00264 void
00265 EmcBhaCalibData::printVec(int number) {
00266 
00267   if (_MsgFlag <= 3) {
00268     std::cout << "EmcBhaCalibData:: INFO "<< "R ( " << number << " ): " << _vectorR[number] 
00269         << "  hits: " << _xtalHits[number] 
00270         << "  direct hits: " << _xtalHitsMax[number]
00271         << endl;
00272   }
00273 }
00274 
00275 
00276 

Generated on Tue Nov 29 22:58:15 2016 for BOSS_7.0.2 by  doxygen 1.4.7