BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcAlignAlg.cxx
Go to the documentation of this file.
1// MdcAlignAlg
2// 2008/03/26 Wu Linghui / Luo Tao IHEP
3
4#include "EventModel/EventHeader.h"
5#include "GaudiKernel/MsgStream.h"
6#include "GaudiKernel/StatusCode.h"
7
11
12#include "TFile.h"
13
14#include <iostream>
15
16using namespace std;
17// using namespace Event;
18
19/////////////////////////////////////////////////////////////////////////////
21MdcAlignAlg::MdcAlignAlg( const std::string& name, ISvcLocator* pSvcLocator )
22 : Algorithm( name, pSvcLocator ), m_alignMeth( 0 ), m_flgKalFit( 0 ) {
23
24 m_distAlign = false;
25 m_configFile = "MdcCalibConfig.txt";
26 m_fixMomLab = "fixMom_lab.txt";
27 m_nEvt = 0;
28 m_mag = 1.0;
29
30 // declare properties
31 declareProperty( "DistAlign", m_distAlign );
32 declareProperty( "MdcAlignMeth", m_alignMeth );
33 declareProperty( "UseKalFit", m_flgKalFit );
34 declareProperty( "MagneticField", m_mag );
35 declareProperty( "AlignFile", m_alignFile );
36 declareProperty( "HistFile", m_histname );
37 declareProperty( "ConfigFile", m_configFile );
38 declareProperty( "FixMomLab", m_fixMomLab );
39 declareProperty( "NumEvtDisplay", m_nEvtDisp );
40}
41
42// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
44 MsgStream log( msgSvc(), name() );
45 log << MSG::INFO << "MdcAlignAlg initialze() ..." << endmsg;
46 log << MSG::INFO << "MdcAlignFlg = " << m_alignMeth << endmsg;
47
48 StatusCode sc = service( "MdcGeomSvc", m_mdcGeomSvc );
49 if ( sc != StatusCode::SUCCESS ) { log << MSG::ERROR << "can not use MdcGeomSvc" << endmsg; }
50
51 sc = service( "MdcCalibFunSvc", m_mdcFunSvc );
52 if ( sc != StatusCode::SUCCESS )
53 { log << MSG::FATAL << "can not use MdcCalibFunSvc" << endmsg; }
54
55 sc = service( "MdcUtilitySvc", m_mdcUtilitySvc );
56 if ( sc != StatusCode::SUCCESS )
57 { log << MSG::FATAL << "can not use MdcUtilitySvc" << endmsg; }
58
59 // initialize m_param
60 initParam();
61
62 // read mdc config parameters
63 int i;
64 std::string strconfig;
65 std::string strcomment;
66 std::string strTes;
67 int fgTes[50];
68 for ( i = 0; i < 50; i++ ) fgTes[i] = -999;
69 ifstream fconfig( m_configFile.c_str() );
70 if ( !fconfig.is_open() )
71 {
72 log << MSG::WARNING << "can not open config file " << m_configFile
73 << ". Use defalt config parameters" << endmsg;
74 }
75 else
76 {
77 log << MSG::INFO << "Open config file " << m_configFile << endmsg;
78 while ( fconfig >> strconfig )
79 {
80 if ( '#' == strconfig[0] ) { getline( fconfig, strcomment ); }
81 else if ( "EsTimeFlag" == strconfig )
82 {
83 getline( fconfig, strTes );
84 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", fgTes + 0,
85 fgTes + 1, fgTes + 2, fgTes + 3, fgTes + 4, fgTes + 5, fgTes + 6,
86 fgTes + 7, fgTes + 8, fgTes + 9, fgTes + 10, fgTes + 11, fgTes + 12,
87 fgTes + 13, fgTes + 14, fgTes + 15, fgTes + 16, fgTes + 17, fgTes + 18,
88 fgTes + 19 );
89 for ( i = 0; i < n; i++ ) m_param.esFlag[i] = fgTes[i];
90 m_param.nEsFlag = n;
91 }
92 else if ( "TesMin" == strconfig ) { fconfig >> m_param.tesMin; }
93 else if ( "TesMax" == strconfig ) { fconfig >> m_param.tesMax; }
94 else if ( "ResidualType" == strconfig ) { fconfig >> m_param.resiType; }
95 else if ( "FlagAdjacLayerCut" == strconfig ) { fconfig >> m_param.fgAdjacLayerCut; }
96 else if ( "FlagBoundLayerCut" == strconfig ) { fconfig >> m_param.fgBoundLayerCut; }
97 else if ( "hitStatCut" == strconfig ) { fconfig >> m_param.hitStatCut; }
98 else if ( "nTrkCut" == strconfig )
99 { fconfig >> m_param.nTrkCut[0] >> m_param.nTrkCut[1]; }
100 else if ( "nHitLayCut" == strconfig ) { fconfig >> m_param.nHitLayCut; }
101 else if ( "nHitCut" == strconfig ) { fconfig >> m_param.nHitCut; }
102 else if ( "ptCut" == strconfig ) { fconfig >> m_param.ptCut[0] >> m_param.ptCut[1]; }
103 else if ( "cosThetaCut" == strconfig )
104 { fconfig >> m_param.costheCut[0] >> m_param.costheCut[1]; }
105 else if ( "DrCut" == strconfig ) { fconfig >> m_param.drCut; }
106 else if ( "DzCut" == strconfig ) { fconfig >> m_param.dzCut; }
107 else if ( "MaximalDocaInner" == strconfig ) { fconfig >> m_param.maxDocaInner; }
108 else if ( "MaximalDocaOuter" == strconfig ) { fconfig >> m_param.maxDocaOuter; }
109 else if ( "MaximalResidual" == strconfig ) { fconfig >> m_param.maxResi; }
110 }
111 fconfig.close();
112 }
113
114 // set event type
115 m_param.particle = m_evtType;
116
117 cout << "EsFlag for Mdc Alignment: ";
118 for ( int iEs = 0; iEs < m_param.nEsFlag; iEs++ ) cout << setw( 6 ) << m_param.esFlag[iEs];
119 cout << endl;
120
121 if ( fabs( m_mag ) > 0.01 ) Alignment::gFlagMag = true;
122 else Alignment::gFlagMag = false;
123
124 m_alignPar = new MdcAlignPar();
125 m_alignPar->rdAlignPar( m_alignFile );
126
127 m_mdcevt = new MdcAliEvent();
128 m_mdcevt->setParam( m_param );
129
130 m_hlist = new TObjArray();
131
132 if ( 0 == m_alignMeth ) { m_pAlign = new ResiAlign(); }
133 else if ( 1 == m_alignMeth )
134 {
135 m_pAlign = new MilleAlign();
136 m_pAlign->fixMomLab = m_fixMomLab;
137 }
138 m_pAlign->setParam( m_param );
139 m_pAlign->initialize( m_hlist, m_mdcGeomSvc, m_mdcFunSvc, m_mdcUtilitySvc );
140
141 return StatusCode::SUCCESS;
142}
143
144// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
146 MsgStream log( msgSvc(), name() );
147 log << MSG::DEBUG << "MdcAlignAlg execute()" << endmsg;
148
149 // display event number for debug
150 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(), "/Event/EventHeader" );
151 if ( !eventHeader )
152 {
153 log << MSG::FATAL << "Could not find Event Header" << endmsg;
154 return ( StatusCode::FAILURE );
155 }
156 int iEvt = eventHeader->eventNumber();
157 if ( 0 == ( m_nEvt % m_nEvtDisp ) )
158 std::cout << "Event " << m_nEvt << ", Event number online " << iEvt << endl;
159 m_nEvt++;
160
161 // get reconstruction result
162 if ( m_flgKalFit ) m_mdcevt->setKalEvent();
163 else m_mdcevt->setRecEvent();
164
165 if ( !( m_pAlign->fillHist( m_mdcevt ) ) )
166 {
167 m_mdcevt->clear();
168 return ( StatusCode::SUCCESS );
169 }
170 m_mdcevt->clear();
171
172 return StatusCode::SUCCESS;
173}
174
175// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
177 MsgStream log( msgSvc(), name() );
178 log << MSG::INFO << "MdcAlignAlg finalize()" << endmsg;
179
180 if ( !m_distAlign )
181 {
182 // execute calibration and write new calibration data file
183 m_pAlign->updateConst( m_alignPar );
184 m_alignPar->wrtAlignPar();
185 }
186
187 TFile* fhist = new TFile( m_histname.c_str(), "recreate" );
188 m_hlist->Write();
189
190 m_pAlign->clear();
191 delete m_pAlign;
192 std::cout << "m_pAlign deleted" << std::endl;
193
194 delete m_alignPar;
195 std::cout << "m_alignPar deleted" << std::endl;
196
197 delete m_mdcevt;
198 std::cout << "m_mdcevt deleted" << std::endl;
199
200 delete m_hlist;
201 std::cout << "m_hlist deleted" << std::endl;
202
203 fhist->Close();
204 delete fhist;
205 cout << m_histname << " was written" << endl;
206
207 if ( !m_distAlign )
208 {
209 std::ofstream fend( "endalign.out" );
210 fend << "MdcAlign end." << std::endl;
211 fend.close();
212 }
213
214 std::cout << "MdcAlignAlg End." << std::endl;
215
216 return StatusCode::SUCCESS;
217}
218
219void MdcAlignAlg::initParam() {
220 m_param.particle = 0;
221 m_param.nEsFlag = 0;
222 for ( int i = 0; i < 50; i++ ) m_param.esFlag[i] = -999;
223 m_param.tesMin = 0.0;
224 m_param.tesMax = 9999.0;
225 m_param.resiType = 0;
226 m_param.fgAdjacLayerCut = 0;
227 m_param.fgBoundLayerCut = 0;
228 m_param.hitStatCut = 0;
229 m_param.nTrkCut[0] = 2;
230 m_param.nTrkCut[1] = 2;
231 m_param.nHitLayCut = 35;
232 m_param.nHitCut = 70;
233 m_param.ptCut[0] = 0.0;
234 m_param.ptCut[1] = 100.0;
235 m_param.costheCut[0] = -1.0;
236 m_param.costheCut[1] = 1.0;
237 m_param.drCut = 50.0; // mm
238 m_param.dzCut = 300.0; // mm
239 m_param.maxDocaInner = 8.0; // mm
240 m_param.maxDocaOuter = 12.0; // mm
241 m_param.maxResi = 1.0; // mm
242}
DECLARE_COMPONENT(BesBdkRc)
const Int_t n
IMessageSvc * msgSvc()
double maxDocaOuter
double costheCut[2]
int esFlag[50]
double ptCut[2]
double maxDocaInner
MdcAlignAlg(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode execute()
StatusCode initialize()
StatusCode finalize()
bool gFlagMag
Definition Alignment.cxx:15