00001 //-------------------------------------------------------------------------- 00002 // Environment: 00003 // This software was developed for the BESIII collaboration. If you 00004 // use all or part of it, please give an appropriate acknowledgement. 00005 // 00006 // Copyright Information: 00007 // Copyright (C) 2005 IHEP 00008 // 00009 //------------------------------------------------------------------------ 00010 00011 #ifndef EMCBHACALIB_H 00012 #define EMCBHACALIB_H 00013 00014 //------------- 00015 // C Headers -- 00016 //------------- 00017 #include <ctime> 00018 00019 #include <cstring> 00020 00021 00022 #include "GaudiKernel/Algorithm.h" 00023 00024 #include "EmcBhaCalib/EmcLSSMatrix.h" 00025 #include "EmcBhaCalib/EmcBhaCalibData.h" 00026 00027 #include "EmcCalibConstSvc/IEmcCalibConstSvc.h" 00028 #include "EmcCalibConstSvc/EmcCalibConstSvc.h" 00029 #include "GaudiKernel/Bootstrap.h" 00030 #include "GaudiKernel/ISvcLocator.h" 00031 00032 //Ntuple 00033 #include "GaudiKernel/NTuple.h" 00034 00035 using namespace std; 00036 00037 //------------------------------------ 00038 // Collaborating Class Declarations -- 00039 //------------------------------------ 00040 00041 // --------------------- 00042 // -- Class Interface -- 00043 // --------------------- 00058 class EmcBhaCalib:public Algorithm{ 00059 00060 00061 public: 00062 00063 EmcBhaCalib(const std::string& name, ISvcLocator* pSvcLocator); 00064 00065 00066 //-------------- 00067 // Destructor 00068 //-------------- 00069 virtual ~EmcBhaCalib(); 00070 00071 StatusCode initialize(); 00072 StatusCode execute(); 00073 StatusCode finalize(); 00074 00075 virtual void help( ); 00076 00077 //------------------ 00078 // Helper functions 00079 //------------------ 00080 00081 private: 00082 00083 00084 // read in calibration constants from file or initialize them to 1 00085 void initCalibConst(); 00086 00087 // solve system of linear equations with SLAP package 00088 bool solveEqua(); 00089 00090 //output constants to file 00091 void writeOutConst(); 00092 00093 //output matrix and vector to file 00094 void writeOut(); 00095 00096 //read in matrix and vector from file 00097 bool readInFromFile(); 00098 00099 //read in matrix and vector from the database 00100 bool readInFromDB(); 00101 00102 //make the absolute constants and fit constants vs theta to get values 00103 //where we did not find some 00104 bool prepareConstants(); 00105 00106 // fill nutuple 00107 void ntupleOut(); 00108 00109 //print data information and only used in testing 00110 void printInfo(std::string xtalHitsDirFile); 00111 // 00112 00113 void digiConstCor(); 00114 //-------------- 00115 // Data 00116 //-------------- 00117 00118 private: 00119 00120 double m_peakCor[6240]; 00121 00122 //cut on minimum number of direct hits needed per xtal 00123 int m_dirHitsCut; 00124 00125 //convergence criterion 00126 double m_convCrit; 00127 00128 //ask before doing the matrix inversion 00129 bool m_askForMatrixInversion; 00130 00131 //fit a polynom second order to the constants theta distribution 00132 //to get constants where we did not find one 00133 bool m_fitPolynom; // now not been used 00134 00135 //write the whole matrix, the vector and the constants to file ? 00136 bool m_writeToFile; 00137 00138 //read calibration data (matrix) from the database (or from files) 00139 bool m_readDataFromDB; 00140 00141 //which method for solving the matrix equation 00142 std::string m_equationSolver; 00143 00144 //file name extensions for different output files 00145 std::string m_fileExt; 00146 00147 //file directory 00148 std::string m_fileDir; 00149 00150 // collected calibration data 00151 EmcBhaCalibData* m_myCalibData; 00152 00153 //was calibration successful ? 00154 bool m_calibrationSuccessful; 00155 00156 //array of relative calibration constants, will be reduced to only 00157 //living xtals for the matrix inversion (no zero hit entries) 00158 double* m_calibConst; 00159 00160 //relative calibration constants, full list including zero entries 00161 double* m_calibConstUnred; 00162 00163 //absolute calibration constants (new relative * old constants) 00164 double* m_absoluteConstants; 00165 00166 //the old absolute constants the new once are relative to 00167 double* m_oldConstants; 00168 00169 //number of non zeros in matrix M 00170 long int m_nrNonZeros; 00171 00172 //number of xtals with minimum required direct hits 00173 int m_nrXtalsEnoughHits; 00174 00175 //file with a list of runnumbers to read in for which runs matrix file 00176 // to load (Default: ./runnumber.dat) 00177 std::string m_runNumberFile; 00178 00179 //message output in the tool classes 00180 int m_MsgFlag; 00181 00182 // ntuple for analysis 00183 NTuple::Tuple* m_tuple1; 00184 NTuple::Item<long> ixtal; 00185 NTuple::Item<float> gi0; 00186 NTuple::Item<float> calibConst; 00187 NTuple::Item<float> err; 00188 NTuple::Item<long> nhitxtal; 00189 00190 double DigiCalibConst; 00191 00192 IEmcCalibConstSvc* m_emcCalibConstSvc; 00193 00194 }; 00195 00196 #endif // EMCBHACALIB_H 00197 00198 00199 00200 00201 00202 00203 00204 00205 00206 00207 00208 00209 00210 00211 00212 00213 00214 00215