/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Tof/tofcalgsec/tofcalgsec-00-02-21/src/TofCalibration.cxx

Go to the documentation of this file.
00001 #include "tofcalgsec/TofCalibration.h"
00002 #include "TDirectory.h"
00003 #include "TFile.h"
00004 #include "TStyle.h"
00005 #include <iostream>
00006 #include <ios>
00007 #include <fstream>
00008 
00009 using namespace CLHEP;
00010 
00011 TofCalibration::TofCalibration( const int npar ):Npar(npar) {
00012   X = HepVector(Npar,0);
00013   m_name = string("calibration");
00014 }
00015 
00016 TofCalibration::~TofCalibration() {
00017   std::vector<TH1F*>::iterator iter = histograms.begin();
00018   for( ; iter != histograms.end(); iter++ ) {
00019     delete (*iter);
00020   }
00021   histograms.clear();
00022   m_result.clear();
00023 }
00024 
00025 
00026 void TofCalibration::calculate( RecordSet*& data, unsigned int icounter ) {
00027 
00028   std::cout << setiosflags(ios::left) << setw(10) << icounter << setw(8) << data->size() << setw(30) << name() << std::endl;
00029 
00030   if( data->size() <= 0 ) {
00031     for( int i=0; i<X.num_row(); i++ ) {
00032       X[i] = 1.0;
00033     }
00034   }
00035   else {
00036     std::vector<Record*>::iterator iter = data->begin();
00037     for( ; iter!=data->end(); iter++ ) {
00038       calculate_record( (*iter), icounter );
00039     }
00040 
00041     calculate_result( icounter );
00042   }
00043 
00044   return;
00045 }
00046 
00047 
00048 void TofCalibration::fillTxt( const char* file ) {
00049   std::ofstream out(file,ios::out);
00050   if( out ) {
00051     std::vector<HepVector>::iterator it;
00052     for( it=m_result.begin(); it!=m_result.end(); it++ ) {
00053       //      for( unsigned int i=0; i<(*it).num_row(); i++ ) {
00054       for( unsigned int i=0; i<Npar2; i++ ) {
00055         out << (*it)[i] << " ";
00056       }
00057       out << std::endl;
00058     }
00059     out.close();
00060   }
00061   else{
00062     cerr << "error when open file " << file << " for write in " << name() << "::fillTxt()" << std::endl;
00063     cout << "print all parameters to srceen: in total " << m_result.size() << " items" << std::endl;
00064     std::vector<HepVector>::iterator it;
00065     for( it=m_result.begin(); it!=m_result.end(); it++ ) {
00066       //      for( unsigned int i=0; i<(*it).num_row(); i++ ) {
00067       for( unsigned int i=0; i<Npar2; i++ ) {
00068         cout << (*it)[i] << " ";
00069       }
00070       cout << std::endl;
00071     }
00072   }
00073 
00074   return;
00075 }
00076 
00077 
00078 void TofCalibration::fillRoot( const char* file, bool isbarrel ) {
00079 
00080   unsigned int ncounter = 1;
00081   if( isbarrel ) {
00082     ncounter = NBarrel;
00083   }
00084   else {
00085     ncounter = NEndcap;
00086   }
00087 
00088   unsigned int nhist = histograms.size();
00089   if( nhist != (ncounter*nHistPerCounter + nHistogram) ) {
00090     std::cout<<" tofcalgsec::TofCalibration: the number of histograms is NOT integral number of times of counter number!"<<std::endl;
00091     exit(0);
00092   }
00093   unsigned int ngraph = graphs.size();
00094   if( ngraph != (ncounter*nGraphPerCounter + nGraph) ) {
00095     std::cout<<" tofcalgsec::TofCalibration: the number of histograms is NOT integral number of times of counter number!"<<std::endl;
00096     exit(0);
00097   }
00098 
00099   TFile f(file,"RECREATE");
00100 
00101   gStyle->SetOptFit(1111);
00102   gStyle->SetOptStat(1111);
00103   gStyle->SetLabelSize(0.03,"x");
00104   gStyle->SetLabelSize(0.03,"y");
00105 
00106   char dirname[256];
00107   if( nHistPerCounter>1 ) {
00108     std::vector<TH1F*>::iterator iter = histograms.begin();
00109     for( unsigned int i=0; i<ncounter; i++ ) {
00110       sprintf( dirname, "tofid%i", i );
00111       TDirectory* cdresult = f.mkdir( dirname );
00112       cdresult->cd();
00113       
00114       for( unsigned int i=0; i<nHistPerCounter; i++ ) {
00115         (*(iter+i))->Write();
00116       }
00117       iter = iter + nHistPerCounter;
00118     }
00119   }
00120   else {
00121     sprintf( dirname, "tofid" );
00122     TDirectory* cdresult = f.mkdir( dirname );
00123     cdresult->cd();
00124     
00125     std::vector<TH1F*>::iterator iter = histograms.begin();
00126     for( ; iter != histograms.end(); iter++ ) {
00127       (*iter)->Write();
00128     }
00129   }
00130   
00131   f.Close();
00132 
00133   return;
00134 }
00135 

Generated on Tue Nov 29 23:14:36 2016 for BOSS_7.0.2 by  doxygen 1.4.7