/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Mdc/MdcAlignAlg/MdcAlignAlg-00-01-04/src/MdcAlignAlg.cxx

Go to the documentation of this file.
00001 // MdcAlignAlg
00002 // 2008/03/26   Wu Linghui / Luo Tao   IHEP
00003 
00004 #include "GaudiKernel/MsgStream.h"
00005 #include "GaudiKernel/StatusCode.h"
00006 #include "EventModel/EventHeader.h"
00007 
00008 #include "MdcAlignAlg/MdcAlignAlg.h"
00009 #include "MdcAlignAlg/ResiAlign.h"
00010 #include "MdcAlignAlg/MilleAlign.h"
00011 
00012 #include "TFile.h"
00013 
00014 #include <iostream>
00015 
00016 using namespace std;
00017 // using namespace Event;
00018 
00020 
00021 MdcAlignAlg::MdcAlignAlg(const std::string& name, ISvcLocator* pSvcLocator) :
00022      Algorithm(name, pSvcLocator), m_alignMeth(0), m_flgKalFit(0){
00023 
00024      m_distAlign = false;
00025      m_configFile = "MdcCalibConfig.txt";
00026      m_fixMomLab = "fixMom_lab.txt";
00027      m_nEvt = 0;
00028      m_mag = 1.0;
00029 
00030      //declare properties
00031      declareProperty("DistAlign", m_distAlign);
00032      declareProperty("MdcAlignMeth", m_alignMeth);
00033      declareProperty("UseKalFit", m_flgKalFit);
00034      declareProperty("MagneticField", m_mag);
00035      declareProperty("AlignFile", m_alignFile);
00036      declareProperty("HistFile", m_histname);
00037      declareProperty("ConfigFile", m_configFile);
00038      declareProperty("FixMomLab", m_fixMomLab);
00039      declareProperty("NumEvtDisplay", m_nEvtDisp);           
00040 }
00041 
00042 
00043 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
00044 StatusCode MdcAlignAlg::initialize() {
00045      MsgStream log( msgSvc(), name() );
00046      log << MSG::INFO << "MdcAlignAlg initialze() ..." << endreq;
00047      log << MSG::INFO << "MdcAlignFlg = " << m_alignMeth << endreq;
00048 
00049      StatusCode sc = service("MdcGeomSvc", m_mdcGeomSvc);
00050      if(sc != StatusCode::SUCCESS){
00051           log << MSG::ERROR << "can not use MdcGeomSvc" << endreq;
00052      }
00053 
00054      sc = service("MdcCalibFunSvc", m_mdcFunSvc);
00055      if( sc != StatusCode::SUCCESS ){
00056           log << MSG::FATAL << "can not use MdcCalibFunSvc" << endreq;
00057      }
00058 
00059      // initialize m_param
00060      initParam();
00061 
00062      // read mdc config parameters
00063      int i;
00064      std::string strconfig;
00065      std::string strcomment;
00066      std::string strTes;
00067      int fgTes[50];
00068      for(i=0; i<50; i++) fgTes[i] = -999;
00069      ifstream fconfig( m_configFile.c_str() );
00070      if( ! fconfig.is_open() ){
00071           log << MSG::WARNING << "can not open config file " << m_configFile
00072               << ". Use defalt config parameters" << endreq;
00073      } else {
00074           log << MSG::INFO << "Open config file " << m_configFile << endreq;
00075           while( fconfig >> strconfig ){
00076                if('#' == strconfig[0]){
00077                     getline(fconfig, strcomment);
00078                }  else if("EsTimeFlag" == strconfig){
00079                     getline(fconfig, strTes);
00080                     int n = sscanf(strTes.c_str(), "%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d",
00081                                    fgTes+0, fgTes+1, fgTes+2, fgTes+3, fgTes+4,
00082                                    fgTes+5, fgTes+6, fgTes+7, fgTes+8, fgTes+9,
00083                                    fgTes+10, fgTes+11, fgTes+12, fgTes+13, fgTes+14,
00084                                    fgTes+15, fgTes+16, fgTes+17, fgTes+18, fgTes+19);
00085                     for(i=0; i<n; i++) m_param.esFlag[i] = fgTes[i];
00086                     m_param.nEsFlag = n;
00087                }  else if("TesMin" == strconfig){
00088                     fconfig >> m_param.tesMin;
00089                } else if("TesMax" == strconfig){
00090                     fconfig >> m_param.tesMax;
00091                }  else if("ResidualType" == strconfig){
00092                     fconfig >> m_param.resiType;
00093                } else if("FlagAdjacLayerCut" == strconfig){
00094                     fconfig >> m_param.fgAdjacLayerCut;
00095                } else if("FlagBoundLayerCut" == strconfig){
00096                     fconfig >> m_param.fgBoundLayerCut;
00097                } else if("hitStatCut" == strconfig){
00098                     fconfig >> m_param.hitStatCut;
00099                } else if("nTrkCut" == strconfig){
00100                     fconfig >> m_param.nTrkCut[0] >> m_param.nTrkCut[1];
00101                } else if("nHitLayCut" == strconfig){
00102                     fconfig >> m_param.nHitLayCut;
00103                } else if("nHitCut" == strconfig){
00104                     fconfig >> m_param.nHitCut;
00105                } else if("ptCut" == strconfig){
00106                     fconfig >> m_param.ptCut[0] >> m_param.ptCut[1];
00107                } else if("cosThetaCut" == strconfig){
00108                     fconfig >> m_param.costheCut[0] >> m_param.costheCut[1];
00109                } else if("DrCut" == strconfig){
00110                     fconfig >> m_param.drCut;
00111                } else if("DzCut" == strconfig){
00112                     fconfig >> m_param.dzCut;
00113                } else if("MaximalDocaInner" == strconfig){
00114                     fconfig >> m_param.maxDocaInner;
00115                }else if("MaximalDocaOuter" == strconfig){
00116                     fconfig >> m_param.maxDocaOuter;
00117                }else if("MaximalResidual" == strconfig){
00118                     fconfig >> m_param.maxResi;
00119                }
00120           }
00121           fconfig.close();
00122      }
00123 
00124      // set event type
00125      m_param.particle = m_evtType;
00126 
00127      cout << "EsFlag for Mdc Alignment: ";
00128      for(int iEs=0; iEs<m_param.nEsFlag; iEs++) cout << setw(6) << m_param.esFlag[iEs];
00129      cout << endl;
00130 
00131      if(fabs(m_mag) > 0.01) Alignment::gFlagMag = true;
00132      else Alignment::gFlagMag = false;
00133 
00134      m_alignPar = new MdcAlignPar();
00135      m_alignPar -> rdAlignPar(m_alignFile);
00136 
00137      m_mdcevt = new MdcAliEvent();
00138      m_mdcevt -> setParam(m_param);
00139 
00140      m_hlist  = new TObjArray();
00141 
00142      if( 0 == m_alignMeth ){
00143           m_pAlign = new ResiAlign();
00144      } else if( 1 == m_alignMeth ){
00145           m_pAlign = new MilleAlign();
00146           m_pAlign->fixMomLab = m_fixMomLab;
00147      }
00148      m_pAlign->setParam(m_param);
00149      m_pAlign -> initialize(m_hlist, m_mdcGeomSvc, m_mdcFunSvc);
00150 
00151      return StatusCode::SUCCESS;
00152 }
00153 
00154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
00155 StatusCode MdcAlignAlg::execute() {
00156      MsgStream log(msgSvc(), name());
00157      log << MSG::DEBUG << "MdcAlignAlg execute()" << endreq;
00158 
00159      // display event number for debug
00160      SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
00161      if (!eventHeader) {
00162           log << MSG::FATAL << "Could not find Event Header" << endreq;
00163           return( StatusCode::FAILURE);
00164      }
00165      int iEvt = eventHeader->eventNumber();
00166      if(0 == (m_nEvt % m_nEvtDisp)) std::cout << "Event " << m_nEvt << ",   Event number online " << iEvt << endl;
00167      m_nEvt++;
00168 
00169      // get reconstruction result
00170      if(m_flgKalFit)  m_mdcevt -> setKalEvent();
00171      else             m_mdcevt -> setRecEvent();
00172 
00173      if (!(m_pAlign->fillHist(m_mdcevt))) {
00174           m_mdcevt->clear();
00175           return(StatusCode::SUCCESS);
00176      }
00177      m_mdcevt->clear();
00178 
00179      return StatusCode::SUCCESS;
00180 }
00181 
00182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
00183 StatusCode MdcAlignAlg::finalize() {
00184      MsgStream log(msgSvc(), name());
00185      log << MSG::INFO << "MdcAlignAlg finalize()" << endreq;
00186 
00187      if( ! m_distAlign ){
00188           // execute calibration and write new calibration data file
00189           m_pAlign -> updateConst(m_alignPar);
00190           m_alignPar -> wrtAlignPar();
00191      }
00192 
00193      TFile* fhist = new TFile(m_histname.c_str(), "recreate");
00194      m_hlist -> Write();
00195 
00196      m_pAlign -> clear();
00197      delete m_pAlign;
00198      std::cout << "m_pAlign deleted" << std::endl;
00199 
00200      delete m_alignPar;
00201      std::cout << "m_alignPar deleted" << std::endl;
00202 
00203      delete m_mdcevt;
00204      std::cout << "m_mdcevt deleted" << std::endl;
00205 
00206      delete m_hlist;
00207      std::cout << "m_hlist deleted" << std::endl;
00208 
00209      fhist->Close();
00210      delete fhist;
00211      cout << m_histname << " was written" << endl;
00212 
00213      if( ! m_distAlign ){
00214           std::ofstream fend("endalign.out");
00215           fend << "MdcAlign end." << std::endl;
00216           fend.close();
00217      }
00218 
00219      std::cout << "MdcAlignAlg End." << std::endl;
00220 
00221      return StatusCode::SUCCESS;
00222 }
00223 
00224 void MdcAlignAlg::initParam(){
00225      m_param.particle = 0;
00226      m_param.nEsFlag = 0;
00227      for(int i=0; i<50; i++) m_param.esFlag[i] = -999;
00228      m_param.tesMin = 0.0;
00229      m_param.tesMax = 9999.0;
00230      m_param.resiType = 0;
00231      m_param.fgAdjacLayerCut = 0;
00232      m_param.fgBoundLayerCut = 0;
00233      m_param.hitStatCut = 0;
00234      m_param.nTrkCut[0] = 2;
00235      m_param.nTrkCut[1] = 2;
00236      m_param.nHitLayCut = 35;
00237      m_param.nHitCut = 70;
00238      m_param.ptCut[0] = 0.0;
00239      m_param.ptCut[1] = 100.0;
00240      m_param.costheCut[0] = -1.0;
00241      m_param.costheCut[1] = 1.0;
00242      m_param.drCut = 50.0;      // mm
00243      m_param.dzCut = 300.0;     // mm
00244      m_param.maxDocaInner = 8.0;        // mm
00245      m_param.maxDocaOuter = 12.0;       // mm
00246      m_param.maxResi = 1.0;     // mm
00247 
00248 }

Generated on Tue Nov 29 23:12:48 2016 for BOSS_7.0.2 by  doxygen 1.4.7