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