00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "EmcBhaCalib/EmcBhaCalib.h"
00024
00025
00026
00027
00028 extern "C" {
00029 #include "slap/dlap.h"
00030 }
00031 #include <iostream>
00032 #include <fstream>
00033 #include <cmath>
00034 #include <cassert>
00035 #include <cstdlib>
00036
00037
00038
00039
00040 #include "GaudiKernel/MsgStream.h"
00041 #include "GaudiKernel/AlgFactory.h"
00042 #include "GaudiKernel/ISvcLocator.h"
00043 #include "GaudiKernel/SmartDataPtr.h"
00044 #include "GaudiKernel/IDataProviderSvc.h"
00045 #include "GaudiKernel/PropertyMgr.h"
00046 #include "GaudiKernel/DataObject.h"
00047
00048 #include "CLHEP/Vector/ThreeVector.h"
00049 using namespace std;
00050
00051 using CLHEP::Hep3Vector;
00052
00053
00054 #include "GaudiKernel/MsgStream.h"
00055
00056
00057 #include "TROOT.h"
00058 #include "TFile.h"
00059 #include "TTree.h"
00060 #include "TH1F.h"
00061 #include "TObjArray.h"
00062
00063
00064
00065
00066
00067
00068 EmcBhaCalib::EmcBhaCalib(const std::string& name, ISvcLocator* pSvcLocator)
00069 :Algorithm(name, pSvcLocator),
00070 m_dirHitsCut(200),
00071 m_convCrit(0.000001),
00072 m_askForMatrixInversion(true),
00073 m_fitPolynom(true),
00074 m_writeToFile(false),
00075 m_readDataFromDB(false),
00076 m_equationSolver("GMR"),
00077 m_fileExt(""),
00078 m_fileDir("/ihepbatch/besdata/public/liucx/Calib/"),
00079 m_nrNonZeros(0),
00080 m_nrXtalsEnoughHits(0),
00081 m_runNumberFile("runnumbers.dat"),
00082 m_MsgFlag(0)
00083
00084 {
00085
00086
00087 declareProperty("equationSolver", m_equationSolver);
00088 declareProperty("dirHitsCut", m_dirHitsCut);
00089 declareProperty("writeToFile", m_writeToFile);
00090 declareProperty("fileExt", m_fileExt);
00091 declareProperty("fileDir", m_fileDir);
00092 declareProperty("readDataFromDB", m_readDataFromDB);
00093 declareProperty("askForMatrixInversion", m_askForMatrixInversion);
00094 declareProperty("fitPolynom", m_fitPolynom);
00095 declareProperty("convCrit", m_convCrit);
00096 declareProperty("runNumberFile", m_runNumberFile);
00097 declareProperty("MsgFlag", m_MsgFlag);
00098
00099 m_calibConst = new double[6240];
00100 m_calibConstUnred = new double[6240];
00101 m_absoluteConstants = new double[6240];
00102 m_oldConstants = new double[6240];
00103
00104
00105
00106 m_tuple1=0;
00107
00108
00109
00110 }
00111
00112
00113
00114
00115 EmcBhaCalib::~EmcBhaCalib() {
00116 if ( 0 != m_calibConst) {
00117 delete [] m_calibConst;
00118 m_calibConst = 0;
00119 }
00120 if ( 0 != m_calibConstUnred) {
00121 delete [] m_calibConstUnred;
00122 m_calibConstUnred = 0;
00123 }
00124 if ( 0 != m_absoluteConstants) {
00125 delete [] m_absoluteConstants;
00126 m_absoluteConstants = 0;
00127 }
00128 if ( 0 != m_oldConstants) {
00129 delete [] m_oldConstants;
00130 m_oldConstants = 0;
00131 }
00132 if ( 0 != m_myCalibData) {
00133 delete m_myCalibData;
00134 m_myCalibData = 0;
00135 }
00136
00137 }
00138
00139
00140 StatusCode EmcBhaCalib::initialize(){
00141
00142 MsgStream log(msgSvc(), name());
00143 log << MSG::INFO << "in initialize()" << endreq;
00144
00145 m_myCalibData = new EmcBhaCalibData(6240, m_MsgFlag);
00146
00147 m_calibrationSuccessful = false;
00148
00149 StatusCode status1;
00150
00151 NTuplePtr nt1(ntupleSvc(),"FILE302/n1");
00152 if ( nt1 ) m_tuple1 = nt1;
00153 else {
00154 m_tuple1=ntupleSvc()->book("FILE302/n1",CLID_ColumnWiseTuple,"Calib");
00155 if( m_tuple1 ) {
00156
00157 status1 = m_tuple1->addItem ("ixtal",ixtal);
00158 status1 = m_tuple1->addItem ("gi0",gi0);
00159 status1 = m_tuple1->addItem ("calibConst",calibConst);
00160 status1 = m_tuple1->addItem ("err",err);
00161 status1 = m_tuple1->addItem ("nhitxtal",nhitxtal);
00162
00163 }
00164 else {
00165 log << MSG::ERROR <<"Cannot book N-tuple:" << long(m_tuple1) << endmsg;
00166 return StatusCode::FAILURE;
00167 }
00168 }
00169
00170
00171 StatusCode scCalib;
00172 scCalib = Gaudi::svcLocator() -> service("EmcCalibConstSvc", m_emcCalibConstSvc);
00173 if( scCalib != StatusCode::SUCCESS){
00174 log << MSG::ERROR << "can not use EmcCalibConstSvc" << endreq;
00175 }
00176 else {
00177 std::cout << "Test EmcCalibConstSvc DigiCalibConst(0)= "
00178 << m_emcCalibConstSvc -> getDigiCalibConst(0) << std::endl;
00179 }
00180
00181
00182 initCalibConst();
00183
00184
00185
00186 return StatusCode::SUCCESS;
00187 }
00188
00189
00190 StatusCode EmcBhaCalib::execute() {
00191
00192 MsgStream log(msgSvc(), name());
00193 log << MSG::DEBUG << "in execute()" << endreq;
00194
00195 if ( m_readDataFromDB ) {
00196 m_calibrationSuccessful = readInFromDB();
00197
00198 log << MSG::INFO << "read in accumulated matrix from DB"<<endreq;
00199
00200 } else {
00201 m_calibrationSuccessful = readInFromFile();
00202
00203 log << MSG::INFO <<"read in accumulated matrix from file"<<endreq;
00204
00205 }
00206
00207 if ( m_calibrationSuccessful == true ) {
00208
00209
00210 if (m_askForMatrixInversion==true) {
00211
00212 m_calibrationSuccessful = false;
00213 log << MSG::INFO << " Well, we have "
00214 << m_nrXtalsEnoughHits << " crystals whith more "
00215 << "than " << m_dirHitsCut
00216 << " direct hits. Do you want do "
00217 << "a matrix inversion ? [N]" << endreq;
00218
00219
00220 m_calibrationSuccessful = true;
00221
00222 }
00223
00224 if ( m_calibrationSuccessful == true ) {
00225
00226
00227 if ( m_writeToFile == true) {
00228 writeOut();
00229 }
00230
00231 m_myCalibData->printVec(2);
00232
00233
00234 if ( m_calibrationSuccessful = m_myCalibData->reduce() ) {
00235
00236 cout<<"m_calibrationSuccessful="<<m_calibrationSuccessful<<endl;
00237
00238 if ( m_myCalibData->nXtalsHit() != m_myCalibData->nXtals() ){
00239 log << MSG::INFO << " Reduced number of Xtals for calibration: "
00240 << m_myCalibData->nXtalsHit()
00241 << endreq;
00242 }
00243 cout<<"m_myCalibData->nXtalsHit()="<<m_myCalibData->nXtalsHit()
00244 <<"m_myCalibData->nXtals()="<<m_myCalibData->nXtals()<<endl;
00245 m_myCalibData->printVec(10);
00246
00247
00248 if ( m_calibrationSuccessful = solveEqua() ) {
00249
00250 for (int i=0; i<m_myCalibData->nXtalsHit(); i++){
00251
00252 m_calibConstUnred[m_myCalibData->xtalInd(i)]
00253 = m_calibConst[i];
00254
00255
00256
00257
00258
00259
00260
00261 }
00262
00263 prepareConstants();
00264
00265
00266 if ( m_writeToFile==true){
00267 writeOutConst();
00268 }
00269
00270 ntupleOut();
00271
00272 }
00273
00274 } else {
00275 log << MSG::WARNING << " Reduction of the Emc Bhabha calibration matrix FAILED !"
00276 << endl
00277 << " Will NOT perform Emc Bhabha calibration !"
00278 << endreq;
00279 return( StatusCode::FAILURE);
00280 }
00281 }
00282 } else {
00283 log << MSG::WARNING << " ERROR in reading in Emc Bhabha calibration data !"
00284 << endl
00285 << " Will NOT perform Emc Bhabha calibration !"
00286 << endreq;
00287 return( StatusCode::FAILURE);
00288 }
00289
00290 return StatusCode::SUCCESS;
00291 }
00292
00293
00294 StatusCode EmcBhaCalib::finalize() {
00295
00296 MsgStream log(msgSvc(), name());
00297
00298
00299 log << MSG::INFO << "in endRun()" << endreq;
00300
00301
00302 return StatusCode::SUCCESS;
00303 }
00304
00305
00306 void
00307 EmcBhaCalib::help() {
00308
00309 MsgStream log(msgSvc(), name());
00310
00311 log << MSG::INFO<< "Performs the Chi square fit of the accumulated "
00312 << endreq;
00313 }
00314
00315
00316 void
00317 EmcBhaCalib::initCalibConst( ) {
00318
00319
00320 MsgStream log(msgSvc(), name());
00321
00322 for ( int i = 0; i< m_myCalibData->nXtals(); i++ ) {
00323 m_calibConst[i] = 1.;
00324 }
00325
00326 ifstream inConst("EmcCalib.Const");
00327 if ( !inConst ) {
00328 log << MSG::VERBOSE
00329 << " No starting values for calibration constants found ! "
00330 << "(EmcCalib.Const)"
00331 << endl
00332 << "Set them to 1.0 ! " << endreq;
00333 } else {
00334 log << MSG::VERBOSE << " Read in starting values of calibration constants !"
00335 << endreq;
00336
00337 int nConst;
00338 inConst >> nConst;
00339 log << MSG::VERBOSE << " Have starting values for "
00340 << nConst << " Xtals !" << endl
00341 << "Set the others to 1.0 ! " << endmsg;
00342
00343 int numberXtal;
00344 for ( int i = 0; i< nConst; i++ ) {
00345 inConst >> numberXtal >> m_calibConst[numberXtal];
00346 }
00347 }
00348
00349 int nConstEmc;
00350
00351 nConstEmc= m_emcCalibConstSvc -> getDigiCalibConstNo() ;
00352
00353 if ( nConstEmc!=6240) cout<<"number of calibconst="<< nConstEmc<<endl;
00354
00355
00356
00357
00358
00359 for ( int i = 0; i< nConstEmc; i++ ) {
00360
00361
00362
00363
00364 m_calibConst[i] = m_emcCalibConstSvc -> getDigiCalibConst(i);
00365
00366 m_oldConstants[i]=m_emcCalibConstSvc -> getDigiCalibConst(i);
00367
00368
00369
00370 m_absoluteConstants[i] =1.0;
00371
00372 m_calibConstUnred[i] =1.0;
00373 }
00374
00375
00376 }
00377
00378
00379
00380 bool
00381 EmcBhaCalib::solveEqua() {
00382
00383 MsgStream log(msgSvc(), name());
00384
00385
00386
00387 log << MSG::VERBOSE << " Solve Matrix equation with method "
00388 << m_equationSolver
00389 << endl
00390 << "Xtals hit: " << m_myCalibData->nXtalsHit()
00391 << endl
00392 << "Nr of non Zeros: " << m_nrNonZeros << endreq;
00393
00394
00395 long int isym = 1;
00396 long int nsave = 20;
00397 long int itol = 0;
00398 double convCriterion = m_convCrit;
00399 long int maxIter = 1000;
00400 long int errUnit = 6;
00401
00402
00403
00404 long int lengthDoubleWork;
00405 double* doubleWork;
00406 long int lengthIntWork;
00407 long int* intWork;
00408
00409
00410 long int iters=0;
00411 double errorv=1000;
00412 long int errorFlag=9999;
00413
00414
00415
00416
00417 if ( m_equationSolver == "GMR" ) {
00418
00419 cout<<m_equationSolver<<endl;
00420
00421 cout<<"errorFlag="<<errorFlag<<endl;
00422
00423
00424 lengthDoubleWork = (1 + m_myCalibData->nXtals()*(nsave+7)
00425 + nsave*(nsave+3))
00426 + 50000;
00427 doubleWork = new double[lengthDoubleWork];
00428 lengthIntWork = 50;
00429 intWork = new long int [lengthIntWork];
00430
00431 dsdgmr_ ( &(m_myCalibData->nXtalsHit()),
00432 m_myCalibData->getVectorR(),
00433 m_calibConst,
00434 &m_nrNonZeros,
00435 m_myCalibData->getMatrixM()->row(),
00436 m_myCalibData->getMatrixM()->column(),
00437 m_myCalibData->getMatrixM()->matrix(),
00438 &isym,
00439 &nsave,
00440 &itol,
00441 &convCriterion,
00442 &maxIter,
00443 &iters,
00444 &errorv,
00445 &errorFlag,
00446 &errUnit,
00447 doubleWork,
00448 &lengthDoubleWork,
00449 intWork,
00450 &lengthIntWork
00451 );
00452 cout<<"errorFlag="<<errorFlag<<endl;
00453
00454
00455 log << MSG::VERBOSE << " Error flag: " << errorFlag << endreq;
00456 if ( errorFlag < 0 ) errorFlag = labs(errorFlag) + 2;
00457 switch ( errorFlag ) {
00458 case 0: log << MSG::VERBOSE << " all went well"
00459 << endreq; break;
00460 case 1: log << MSG::ERROR << " insufficient storage allocated for _doubleWork or _intWork"
00461 << endreq; break;
00462 case 2: log << MSG::ERROR << " method failed to reduce norm of current residual"
00463 << endreq; break;
00464 case 3: log << MSG::ERROR << " insufficient length for _doubleWork"
00465 << endreq; break;
00466 case 4: log << MSG::ERROR << " inconsistent _itol and values"
00467 << endreq; break;
00468 default: log << MSG::ERROR << " unknown flag" << endreq;
00469 }
00470 log << MSG::VERBOSE << " Integer workspace used = " << intWork[8] << endl
00471 << " Double workspace used = " << intWork[9] << endreq;
00472 }
00473
00474
00475
00476
00477 if ( m_equationSolver == "PCG" ) {
00478
00479 cout<<m_equationSolver<<endl;
00480
00481 itol = 1;
00482
00483
00484 lengthDoubleWork = 5 *m_myCalibData->nXtals() + 50000;
00485 doubleWork = new double[lengthDoubleWork];
00486 lengthIntWork = 50;
00487 intWork = new long int [lengthIntWork];
00488
00489 dsdcg_( &(m_myCalibData->nXtalsHit()),
00490 m_myCalibData->getVectorR(),
00491 m_calibConst,
00492 &m_nrNonZeros,
00493 m_myCalibData->getMatrixM()->row(),
00494 m_myCalibData->getMatrixM()->column(),
00495 m_myCalibData->getMatrixM()->matrix(),
00496 &isym,
00497 &itol,
00498 &convCriterion,
00499 &maxIter,
00500 &iters,
00501 &errorv,
00502 &errorFlag,
00503 &errUnit,
00504 doubleWork,
00505 &lengthDoubleWork,
00506 intWork,
00507 &lengthIntWork
00508 );
00509
00510 switch ( errorFlag ) {
00511 case 0: log << MSG::VERBOSE << "all went well" << endreq; break;
00512 case 1: log << MSG::ERROR << " insufficient storage allocated for WORK or IWORK"
00513 << endreq; break;
00514 case 2: log << MSG::ERROR << " method failed to to converge in maxIter steps."
00515 << endreq; break;
00516 case 3:log << MSG::ERROR << " Error in user input. Check input value of _nXtal,_itol."
00517 << endreq; break;
00518 case 4:log << MSG::ERROR << " User error tolerance set too tight. "
00519 << "Reset to 500.0*D1MACH(3). Iteration proceeded."
00520 << endreq; break;
00521 case 5:log << MSG::ERROR << " Preconditioning matrix, M, is not Positive Definite. "
00522 << endreq; break;
00523 case 6: log << MSG::ERROR << " Matrix A is not Positive Definite."
00524 << endreq; break;
00525 default: log << MSG::ERROR << " unknown flag" << endreq;
00526 }
00527 log << MSG::VERBOSE << " Integer workspace used = " << intWork[9] << endl
00528 << "Double workspace used = " << intWork[10] << endreq;
00529 }
00530
00531 log << MSG::VERBOSE << "------ Calibration fit statistics ------- " << endl
00532 << "maximum number of iterations =" << maxIter << endl
00533 << " number of iterations =" << iters << endl
00534 << "error estimate of error in final solution ="
00535 << errorv << endreq;
00536
00537 if ( 0 != doubleWork) delete [] doubleWork;
00538 if ( 0 != intWork) delete [] intWork;
00539
00540 if ( errorFlag != 0 ) return false;
00541 else return true;
00542
00543 return true;
00544 }
00545
00546
00547 void
00548 EmcBhaCalib::writeOut() {
00549
00550 ofstream vectorOut;
00551 std::string vectorFile = m_fileDir;
00552 vectorFile += m_fileExt;
00553 vectorFile += "allCalibVector.dat";
00554 vectorOut.open(vectorFile.c_str());
00555
00556 ofstream matrixOut;
00557 std::string matrixFile = m_fileDir;
00558 matrixFile += m_fileExt;
00559 matrixFile += "allCalibMatrix.dat";
00560 matrixOut.open(matrixFile.c_str());
00561
00562 MsgStream log(msgSvc(), name());
00563
00564 log << MSG::VERBOSE << " Write out files "
00565 << vectorFile << " "
00566 << matrixFile
00567 << endreq;
00568
00569 m_myCalibData->writeOut(matrixOut,vectorOut);
00570
00571 vectorOut.close();
00572 matrixOut.close();
00573
00574 }
00575
00576
00577 void
00578 EmcBhaCalib::writeOutConst() {
00579
00580 ofstream constOut;
00581
00582 std::string constFile = m_fileDir;
00583 constFile += m_fileExt;
00584 constFile += "CalibConst.dat";
00585
00586 constOut.open(constFile.c_str());
00587
00588 constOut << "#crystalIndex relative-constant absolute-constant" << endl;
00589
00590 int chanIndex;
00591
00592
00593 for ( int i=0; i < m_myCalibData->nXtalsHit(); i++) {
00594
00595 chanIndex=m_myCalibData->xtalInd(i);
00596
00597
00598
00599 if ( m_myCalibData->xtalHitsDir(i) < m_dirHitsCut )
00600 m_absoluteConstants[chanIndex] = m_oldConstants[chanIndex];
00601 else
00602 m_absoluteConstants[chanIndex] =
00603 m_oldConstants[chanIndex] * m_calibConstUnred[chanIndex];
00604
00605 }
00606
00607
00608 for ( int i=0; i < m_myCalibData->nXtals(); i++) {
00609
00610 long Xtal_Index = i;
00611 if(m_calibConstUnred[Xtal_Index]>0){
00612 constOut << Xtal_Index << " "
00613 << m_calibConstUnred[Xtal_Index] << " "
00614 << m_oldConstants[Xtal_Index] << " "
00615 << m_absoluteConstants[Xtal_Index]
00616 << endl;
00617
00618
00619 }
00620 }
00621 constOut.close();
00622
00623 }
00624
00625
00626 bool
00627 EmcBhaCalib::readInFromFile() {
00628
00629 MsgStream log(msgSvc(), name());
00630
00631 log << MSG::INFO << " Read Bhabha calibration data from files !"
00632 << endreq;
00633
00634 std::string runNumberFile = m_fileDir;
00635 runNumberFile += m_fileExt;
00636 runNumberFile += m_runNumberFile;
00637
00638 bool success = false;
00639 log << MSG::INFO << " Get file names from input file : "
00640 << runNumberFile
00641 << endreq;
00642
00643 std::string vectorFile;
00644 std::string matrixFile;
00645
00646 log << MSG::INFO << "Runnumber non-zeros xtals"
00647 << endreq;
00648
00649 ifstream datafile(runNumberFile.c_str());
00650
00651
00652
00653 if (datafile.good() > 0 ) {
00654
00655 while( !datafile.eof() ) {
00656
00657 ifstream vectorIn;
00658 ifstream matrixIn;
00659
00660 std::string num;
00661 datafile >> num;
00662
00663 if ( num.length() > 0 ) {
00664
00665 vectorFile = m_fileDir;
00666 vectorFile += m_fileExt;
00667 vectorFile += num;
00668 vectorFile += "CalibVector.dat";
00669
00670 matrixFile = m_fileDir;
00671 matrixFile += m_fileExt;
00672 matrixFile += num;
00673 matrixFile += "CalibMatrix.dat";
00674
00675 vectorIn.open(vectorFile.c_str());
00676 matrixIn.open(matrixFile.c_str());
00677
00678 if ( vectorIn.good() > 0 && matrixIn.good() > 0 ) {
00679
00680 m_myCalibData->readIn(matrixIn,vectorIn);
00681
00682 log << MSG::INFO << num
00683 << " "
00684 << m_myCalibData->getMatrixM()->num_nonZeros()
00685 << " "
00686 << m_myCalibData->nXtalsHit()
00687 << endreq;
00688
00689 success = true;
00690
00691 }
00692 else {
00693 if ( !vectorIn )
00694 log << MSG::ERROR << " ERROR: Vector input file "
00695 << vectorFile
00696 << " doesn't exist !" << endreq;
00697 if ( !matrixIn )
00698 log << MSG::ERROR << " ERROR: Matrix input file "
00699 << matrixFile
00700 << " doesn't exist !" << endreq;
00701 }
00702 vectorIn.close();
00703 matrixIn.close();
00704 }
00705 }
00706 }
00707
00708 if ( success == true) {
00709
00710 for (int i=0; i < m_myCalibData->nXtals(); i++) {
00711
00712 if ( m_myCalibData->xtalHitsDir(i) > m_dirHitsCut )
00713 {
00714 m_nrXtalsEnoughHits++;
00715 }
00716 }
00717 m_nrNonZeros = m_myCalibData->getMatrixM()->num_nonZeros();
00718 log << MSG::INFO<< " Final matrix : "
00719 << "Number of non zero elements: " << m_nrNonZeros
00720 << " "
00721 << m_myCalibData->nXtalsHit()
00722 << endreq;
00723
00724 }
00725
00726
00727 return success;
00728 }
00729
00730
00731 bool
00732 EmcBhaCalib::readInFromDB() {
00733
00734 bool success = true;
00735
00736 return success;
00737 }
00738
00739
00740 bool
00741 EmcBhaCalib::prepareConstants() {
00742
00743 bool successfull=false;
00744
00745
00746
00747 int chanIndex;
00748
00749 for ( int i = 0; i< m_myCalibData->nXtalsHit(); i++ ) {
00750
00751 chanIndex=m_myCalibData->xtalInd(i);
00752
00754
00755
00756
00757
00758
00759
00760 if ( m_myCalibData->xtalHitsDir(i) < m_dirHitsCut )
00761 m_absoluteConstants[chanIndex] = m_oldConstants[chanIndex];
00762 else
00763 m_absoluteConstants[chanIndex] =
00764 m_oldConstants[chanIndex] * m_calibConstUnred[chanIndex];
00765 }
00766
00767
00768 double DigiConst[6240];
00769 int IxtalNumber[6240];
00770
00771 for(int ind=0; ind<m_myCalibData->nXtals(); ind++ ) {
00772
00773 DigiConst[ind]=m_absoluteConstants[ind];
00774
00775 }
00776
00777 int ixtal1,ixtal2,ixtal3;
00778 ixtal1=m_emcCalibConstSvc->getIndex(1,20,26);
00779 ixtal2=m_emcCalibConstSvc->getIndex(1,23,26);
00780 ixtal3=m_emcCalibConstSvc->getIndex(1,24,26);
00781
00782 for(int ind=0; ind<m_myCalibData->nXtals(); ind++ ) {
00783
00784 IxtalNumber[ind]=-1;
00785
00786
00787
00788
00789
00790 }
00791
00792 TFile fconst("EmcCalibConst.root", "recreate");
00793
00794
00795 TTree* constr= new TTree("DigiCalibConst","DigiCalibConst");
00796 constr->Branch("DigiCalibConst",DigiConst,"DigiConst[6240]/D");
00797 constr->Branch("IxtalNumber",IxtalNumber,"IxtalNumber[6240]/I");
00798
00799 constr->Fill();
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814 constr->Write();
00815
00816 delete constr;
00817
00818 fconst.Close();
00819
00820
00821
00822 successfull=true;
00823 return successfull;
00824
00825 }
00826
00827 void
00828 EmcBhaCalib::ntupleOut(){
00829
00830
00831 for (int i=0; i < m_myCalibData->nXtalsHit(); i++) {
00832 int xtalIndex=m_myCalibData->xtalInd(i);
00833
00834 gi0 = m_oldConstants[xtalIndex];
00835
00836 if (gi0<0) cout<<"gi0="<<gi0<<endl;
00837 err = (m_calibConstUnred[xtalIndex]-gi0)/gi0;
00838 calibConst=m_calibConstUnred[xtalIndex];
00839 ixtal=xtalIndex;
00840 nhitxtal=m_myCalibData->xtalHitsDir(i);
00841 m_tuple1->write();
00842 }
00843
00844 }
00845
00846
00847 void
00848 EmcBhaCalib::printInfo(std::string fileName) {
00849
00850 ofstream xtalHitsDirOut;
00851 std::string xtalHitsDirFile = m_fileDir;
00852 xtalHitsDirFile += m_fileExt;
00853 xtalHitsDirFile += fileName;
00854 xtalHitsDirOut.open(xtalHitsDirFile.c_str());
00855
00856
00857 for (int i=0; i < m_myCalibData->nXtalsHit(); i++) {
00858 if ( m_myCalibData->xtalHitsDir(i) > m_dirHitsCut )
00859 {
00860 int chanindex=m_myCalibData->xtalInd(i);
00861 xtalHitsDirOut<<chanindex<<endl;
00862 }
00863 }
00864 xtalHitsDirOut.close();
00865
00866 }
00867
00868 void
00869 EmcBhaCalib::digiConstCor(){
00870
00871
00872
00873
00874
00875
00876
00877 double digiConst[6240];
00878
00879 for(int ind=0; ind<m_myCalibData->nXtals(); ind++ ) {
00880
00881 digiConst[ind]=m_oldConstants[ind];
00882
00883 }
00884
00885
00886
00887 ifstream ExpEneIn;
00888 std::string ExpEneFile;
00889 ExpEneFile = "cor.conf";
00890 ExpEneIn.open(ExpEneFile.c_str());
00891
00892 double ExpEne[56];
00893 double Exp_barrel[44],Exp_east[6],Exp_west[6];
00894
00895 for(int i=0;i<56;i++) {
00896
00897 ExpEneIn>>ExpEne[i];
00898 ExpEne[i]=ExpEne[i]*1.843;
00899 if (i<6) Exp_east[i]=ExpEne[i];
00900 if (i>=6&&i<50) Exp_barrel[i-6]=ExpEne[i];
00901 if (i>=50) Exp_west[55-i]=ExpEne[i];
00902
00903
00904 }
00905 ExpEneIn.close();
00906
00907 ifstream EDepEneIn;
00908 std::string EDepEneFile = "allxtal.dat";
00909 EDepEneIn.open(EDepEneFile.c_str());
00910
00911 double CorDigiConst[6240];
00912 int ipart,ithe,iphi;
00913 double peak,sigma;
00914 double coeff;
00915
00916 for(int i=0;i<6240;i++) {
00917
00918 EDepEneIn>>ipart>>ithe>>iphi>>peak>>sigma;
00919 int ix=m_emcCalibConstSvc->getIndex(ipart,ithe,iphi);
00920
00921 if (ipart==0) coeff=peak/Exp_east[ithe];
00922 if (ipart==1) coeff=peak/Exp_barrel[ithe];
00923 if (ipart==2) coeff=peak/Exp_west[ithe];
00924 cout<<coeff<<endl;
00925
00926 CorDigiConst[ix]=coeff;
00927 }
00928 EDepEneIn.close();
00929
00930
00931
00932
00933 TTree* constr= new TTree("DigiCalibConst","DigiCalibConst");
00934 constr->Branch("DigiCalibConst",CorDigiConst,"CorDigiConst[6240]/D");
00935 constr->Fill();
00936
00937 double aa[6240];
00938 constr->SetBranchAddress("DigiCalibConst", aa);
00939 constr->GetEntry(0);
00940
00941 TFile fconst("EmcCalibConstCor.root", "recreate");
00942 constr->Write();
00943
00944 fconst.Close();
00945 delete constr;
00946
00947
00948 }