00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "EmcBhaCalib/EmcCalibTagDeadOrHot.h"
00021
00022 #include <iostream>
00023 #include <fstream>
00024 #include <cmath>
00025 #include <cassert>
00026 #include <cstdlib>
00027
00028
00029
00030
00031 #include "GaudiKernel/MsgStream.h"
00032 #include "GaudiKernel/AlgFactory.h"
00033 #include "GaudiKernel/ISvcLocator.h"
00034 #include "GaudiKernel/SmartDataPtr.h"
00035 #include "GaudiKernel/IDataProviderSvc.h"
00036 #include "GaudiKernel/PropertyMgr.h"
00037 #include "GaudiKernel/DataObject.h"
00038
00039 #include "CLHEP/Vector/ThreeVector.h"
00040 using namespace std;
00041
00042 using CLHEP::Hep3Vector;
00043
00044
00045 #include "GaudiKernel/MsgStream.h"
00046
00047
00048 #include "TROOT.h"
00049 #include "TFile.h"
00050 #include "TTree.h"
00051 #include "TH1F.h"
00052 #include "TObjArray.h"
00053
00054
00055
00056
00057
00058
00059 EmcCalibTagDeadOrHot::EmcCalibTagDeadOrHot(const std::string& name, ISvcLocator* pSvcLocator)
00060 :Algorithm(name, pSvcLocator),
00061 m_fileExt(""),
00062 m_fileDir("/ihepbatch/besdata/public/liucx/Calib/"),
00063 m_deadIxtal(-999),
00064 m_hotIxtal(-999)
00065 {
00066
00067
00068 declareProperty("fileExt", m_fileExt);
00069 declareProperty("fileDir", m_fileDir);
00070 declareProperty("deadIxtal", m_deadIxtal);
00071 declareProperty("hotIxtal", m_hotIxtal);
00072
00073 m_oldConstants = new double[6240];
00074 m_IxtalNumber= new int[6240];
00075 }
00076
00077
00078
00079
00080 EmcCalibTagDeadOrHot::~EmcCalibTagDeadOrHot() {
00081
00082 if ( 0 != m_oldConstants) {
00083 delete [] m_oldConstants;
00084 m_oldConstants = 0;
00085 }
00086 if ( 0 != m_IxtalNumber) {
00087 delete [] m_IxtalNumber;
00088 m_IxtalNumber = 0;
00089 }
00090 }
00091
00092
00093 StatusCode EmcCalibTagDeadOrHot::initialize(){
00094
00095 MsgStream log(msgSvc(), name());
00096 log << MSG::INFO << "in initialize()" << endreq;
00097
00098
00099 StatusCode scCalib;
00100 scCalib = Gaudi::svcLocator() -> service("EmcCalibConstSvc", m_emcCalibConstSvc);
00101 if( scCalib != StatusCode::SUCCESS){
00102 log << MSG::ERROR << "can not use EmcCalibConstSvc" << endreq;
00103 }
00104 else {
00105 std::cout << "Test EmcCalibConstSvc DigiCalibConst(0)= "
00106 << m_emcCalibConstSvc -> getDigiCalibConst(0) << std::endl;
00107 }
00108
00109
00110
00111 initCalibConst();
00112
00113 SetDeadOrHotChannel();
00114
00115 return StatusCode::SUCCESS;
00116 }
00117
00118
00119 StatusCode EmcCalibTagDeadOrHot::execute() {
00120
00121 MsgStream log(msgSvc(), name());
00122 log << MSG::DEBUG << "in execute()" << endreq;
00123
00124 return StatusCode::SUCCESS;
00125 }
00126
00127
00128 StatusCode EmcCalibTagDeadOrHot::finalize() {
00129
00130 MsgStream log(msgSvc(), name());
00131
00132
00133 log << MSG::INFO << "in endRun()" << endreq;
00134
00135
00136 return StatusCode::SUCCESS;
00137 }
00138
00139
00140
00141
00142 void
00143 EmcCalibTagDeadOrHot::initCalibConst( ) {
00144
00145
00146 MsgStream log(msgSvc(), name());
00147
00148 int nConstEmc;
00149
00150 nConstEmc= m_emcCalibConstSvc -> getDigiCalibConstNo() ;
00151
00152 if ( nConstEmc!=6240) cout<<"number of calibconst="<< nConstEmc<<endl;
00153
00154 for ( int i = 0; i< nConstEmc; i++ ) {
00155
00156 m_oldConstants[i]=m_emcCalibConstSvc -> getDigiCalibConst(i);
00157 m_IxtalNumber[i]=m_emcCalibConstSvc -> getIxtalNumber(i);
00158
00159 }
00160
00161 ifstream In;
00162 In.open("/ihepbatch/bes/liucx/GrelConstIxtal2013.txt");
00163 ofstream out;
00164 out.open("thephi.dat");
00165 int ixtal,ithe,iphi;
00166 double rel;
00167 while( !In.eof() ) {
00168
00169 In >> ixtal>>rel;
00170 ithe= m_emcCalibConstSvc -> getThetaIndex(ixtal);
00171 iphi= m_emcCalibConstSvc -> getPhiIndex(ixtal);
00172 out<<ixtal<<"\t"<<ithe<<"\t"<<iphi<<"\t"<<rel<<endl;
00173 }
00174 In.close();
00175
00176 out.close();
00177
00178 cout<<"1,10,101"<<"\t"<<m_emcCalibConstSvc -> getIndex(1,10,101)<<endl;
00179 cout<<"1,30,105"<<"\t"<<m_emcCalibConstSvc -> getIndex(1,30,105)<<endl;
00180 cout<<"1,35,40"<<"\t"<<m_emcCalibConstSvc -> getIndex(1,35,40)<<endl;
00181 cout<<"0,2,40"<<"\t"<<m_emcCalibConstSvc -> getIndex(0,2,40)<<endl;
00182 cout<<"2,2,40"<<"\t"<<m_emcCalibConstSvc -> getIndex(2,2,40)<<endl;
00183
00184 }
00185
00186
00187
00188 void
00189 EmcCalibTagDeadOrHot::SetDeadOrHotChannel() {
00190
00191 int Nxtals=6240;
00192
00193 double DigiConst[6240];
00194 int IxtalNumber[6240];
00195
00196 for(int ind=0; ind < Nxtals; ind++ ) {
00197
00198 DigiConst[ind]=m_oldConstants[ind];
00199 IxtalNumber[ind]=m_IxtalNumber[ind];
00200 if (ind==m_deadIxtal) IxtalNumber[ind]=-9;
00201 if (ind==m_hotIxtal) IxtalNumber[ind]=-99;
00202
00203 }
00204
00205
00206 TFile fconst("EmcCalibConst_DeadOrHot.root", "recreate");
00207
00208
00209 TTree* constr= new TTree("DigiCalibConst","DigiCalibConst");
00210 constr->Branch("DigiCalibConst",DigiConst,"DigiConst[6240]/D");
00211 constr->Branch("IxtalNumber",IxtalNumber,"IxtalNumber[6240]/I");
00212
00213 constr->Fill();
00214
00215
00216 constr->Write();
00217
00218 delete constr;
00219
00220 fconst.Close();
00221
00222
00223
00224
00225
00226
00227
00228 }
00229
00230
00231