CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
CgemAlignAlg.cxx
Go to the documentation of this file.
1#include "GaudiKernel/MsgStream.h"
2#include "GaudiKernel/StatusCode.h"
3#include "GaudiKernel/SmartDataPtr.h"
4#include "GaudiKernel/ISvcLocator.h"
5#include "GaudiKernel/IDataProviderSvc.h"
6#include "GaudiKernel/PropertyMgr.h"
7
10
13#include "GaudiKernel/DataSvc.h"
17
18#include <iostream>
19#include <fstream>
20#include <cstring>
21
22using namespace Event;
23
24CgemAlignAlg::CgemAlignAlg(const std::string& name, ISvcLocator* pSvcLocator) :
25 Algorithm(name, pSvcLocator){
26
27 m_histname = "NULL";
28 m_initAlignParFlg = false;
29
30 declareProperty("AlignMethod", m_alignMethod);
31 declareProperty("Event", m_evtType);
32 declareProperty("HistOutput", m_histname);
33 declareProperty("ConfigFile", m_configFile);
34 declareProperty("AlignFile", m_alignFile);
35 declareProperty("NumEvtDisplay", m_nEvtDisp);
36 declareProperty("EventStart", EventStart=0);
37 declareProperty("EventEnd", EventEnd=1E10);
38 // declareProperty("CombineCosmic", m_combCosmic = false);
39 }
40
42
43 std::ofstream fend("endAlign.out");
44 fend << "CgemAlign end." << std::endl;
45 fend.close();
46
47 std::cout << "CgemAlignAlg End." << std::endl;
48}
49
51 MsgStream log( msgSvc(), name() );
52
53 std::cout<<" "<<std::endl;
54 std::cout<<" ██████╗ ███████╗███████╗██╗██╗██╗ ██████╗ ██████╗ ███████╗███╗ ███╗ █████╗ ██╗ ██╗ ██████╗ ███╗ ██╗███╗ ███╗███████╗███╗ ██╗████████╗ "<<std::endl;
55 std::cout<<" ██╔══██╗██╔════╝██╔════╝██║██║██║ ██╔════╝██╔════╝ ██╔════╝████╗ ████║ ██╔══██╗██║ ██║██╔════╝ ████╗ ██║████╗ ████║██╔════╝████╗ ██║╚══██╔══╝ "<<std::endl;
56 std::cout<<" ██████╔╝█████╗ ███████╗██║██║██║ ██║ ██║ ███╗█████╗ ██╔████╔██║ ███████║██║ ██║██║ ███╗██╔██╗ ██║██╔████╔██║█████╗ ██╔██╗ ██║ ██║ "<<std::endl;
57 std::cout<<" ██╔══██╗██╔══╝ ╚════██║██║██║██║ ██║ ██║ ██║██╔══╝ ██║╚██╔╝██║ ██╔══██║██║ ██║██║ ██║██║╚██╗██║██║╚██╔╝██║██╔══╝ ██║╚██╗██║ ██║ "<<std::endl;
58 std::cout<<" ██████╔╝███████╗███████║██║██║██║ ╚██████╗╚██████╔╝███████╗██║ ╚═╝ ██║ ██║ ██║███████╗██║╚██████╔╝██║ ╚████║██║ ╚═╝ ██║███████╗██║ ╚████║ ██║ "<<std::endl;
59 std::cout<<" ╚═════╝ ╚══════╝╚══════╝╚═╝╚═╝╚═╝ ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═══╝ ╚═╝ "<<std::endl;
60 std::cout<<" "<<std::endl;
61
62 log << MSG::INFO << "CgemAlignAlg initialze() ..." << endreq;
63
64 if("NULL"==m_histname){
65 log << MSG::ERROR << "not defined histogram file." << endreq;
66 return StatusCode::FAILURE;
67 }
68
69 StatusCode sc = service("CgemGeomSvc", m_cgemGeomSvc);
70 if(sc != StatusCode::SUCCESS){
71 log << MSG::ERROR << "can not use CgemGeomSvc" << endreq;
72 }
73
74 sc = service("CgemCalibFunSvc", m_cgemFunSvc);
75 if( sc != StatusCode::SUCCESS ){
76 log << MSG::FATAL << "can not use CgemCalibFunSvc" << endreq;
77 }
78
79 // initialize m_param
80 initParam();
81
82 // read cgem config parameters
83 int i;
84 std::string strconfig;
85 std::string strcomment;
86 std::string strTes;
87 int fgTes[50];
88 for(i=0; i<50; i++) fgTes[i] = -999;
89 ifstream fconfig( m_configFile.c_str() );
90 if( ! fconfig.is_open() ){
91 log << MSG::WARNING << "can not open config file " << m_configFile
92 << ". Use defalt config parameters" << endreq;
93 } else {
94 log << MSG::INFO << "Open config file " << m_configFile << endreq;
95 while( fconfig >> strconfig ){
96 if('#' == strconfig[0]){
97 getline(fconfig, strcomment);
98 } else if("TesMin" == strconfig){
99 fconfig >> m_param.tesMin;
100 }
101
102 }
103 fconfig.close();
104 }
105
106 // set event type
107 m_param.particle = m_evtType;
108
109 m_alignPar = new CgemAlignPar();
110 m_alignPar -> rdAlignPar(m_alignFile);
111 cout << std::setprecision(4) << std::fixed;
112 cout<<" The parameters are:"<<endl;
113 cout<<" Layer Dx(mm) Dy(mm) Dz(mm) Rx(mrad) Ry(mrad) Rz(mrad) "<<endl;
114 cout<<" =============================================================================================== "<<endl;
115 cout<<" 0 "<<std::setw(15)<<m_alignPar->getDx(0)<<std::setw(15)<<m_alignPar->getDy(0)<<std::setw(15)<<m_alignPar->getDz(0)<<std::setw(15)<<m_alignPar->getRx(0)*1000.<<std::setw(15)<<m_alignPar->getRy(0)*1000.<<std::setw(15)<<m_alignPar->getRz(0)*1000.<<endl;
116 cout<<" 1 "<<std::setw(15)<<m_alignPar->getDx(1)<<std::setw(15)<<m_alignPar->getDy(1)<<std::setw(15)<<m_alignPar->getDz(1)<<std::setw(15)<<m_alignPar->getRx(1)*1000.<<std::setw(15)<<m_alignPar->getRy(1)*1000.<<std::setw(15)<<m_alignPar->getRz(1)*1000.<<endl;
117 cout<<" 2 "<<std::setw(15)<<m_alignPar->getDx(2)<<std::setw(15)<<m_alignPar->getDy(2)<<std::setw(15)<<m_alignPar->getDz(2)<<std::setw(15)<<m_alignPar->getRx(2)*1000.<<std::setw(15)<<m_alignPar->getRy(2)*1000.<<std::setw(15)<<m_alignPar->getRz(2)*1000.<<endl;
118 cout<<" 3 "<<std::setw(15)<<m_alignPar->getDx(3)<<std::setw(15)<<m_alignPar->getDy(3)<<std::setw(15)<<m_alignPar->getDz(3)<<std::setw(15)<<m_alignPar->getRx(3)*1000.<<std::setw(15)<<m_alignPar->getRy(3)*1000.<<std::setw(15)<<m_alignPar->getRz(3)*1000.<<endl;
119 cout<<" 4 "<<std::setw(15)<<m_alignPar->getDx(4)<<std::setw(15)<<m_alignPar->getDy(4)<<std::setw(15)<<m_alignPar->getDz(4)<<std::setw(15)<<m_alignPar->getRx(4)*1000.<<std::setw(15)<<m_alignPar->getRy(4)*1000.<<std::setw(15)<<m_alignPar->getRz(4)*1000.<<endl;
120 cout<<" 5 "<<std::setw(15)<<m_alignPar->getDx(5)<<std::setw(15)<<m_alignPar->getDy(5)<<std::setw(15)<<m_alignPar->getDz(5)<<std::setw(15)<<m_alignPar->getRx(5)*1000.<<std::setw(15)<<m_alignPar->getRy(5)*1000.<<std::setw(15)<<m_alignPar->getRz(5)*1000.<<endl;
121 cout<<" =============================================================================================== "<<endl;
122 cout<<"\n"<<endl;
123
124 m_cgemevt = new CgemAliEvent();
125 m_cgemevt -> setParam(m_param);
126
127 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
128 m_hlist = new TObjArray(0);
129
130 if( 0 == m_alignMethod ){
131 m_align = new CgemMilleAlign();
132 }
133 m_align->setParam(m_param);
134 m_align->initialize(m_hlist, m_cgemGeomSvc, m_cgemFunSvc);
135
136 log << MSG::INFO << "CgemAlignAlg initialze() successfully !!" << endreq;
137
138 m_nEvt = 0;
139
140 return StatusCode::SUCCESS;
141}
142
144 MsgStream log(msgSvc(), name());
145 log << MSG::INFO << "CgemAlignAlg execute()" << endreq;
146
147 // display event number for debug
148 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
149 if (!eventHeader) {
150 log << MSG::FATAL << "Could not find Event Header" << endreq;
151 return( StatusCode::FAILURE);
152 }
153 int iRun = eventHeader->runNumber();
154 int iEvt = eventHeader->eventNumber();
155 if(0 == (m_nEvt % m_nEvtDisp)){
156 std::cout << "Run " << iRun << ", Event " << iEvt << ", Total Event number " << m_nEvt << endl;
157 }
158
159 if(m_nEvt<EventStart||m_nEvt>EventEnd)
160 {
161 cout<<"Skim the event!!"<<endl;
162 m_nEvt++;
163 return StatusCode::SUCCESS;
164 }
165 else
166 {
167
168 if( ! m_initAlignParFlg ){
169 m_initAlignParFlg = true;
170 }
171
172 m_cgemevt -> setRecEvent();
173
174 if (!(m_align->fillHist(m_cgemevt, m_alignPar))) {
175 m_cgemevt->clear();
176 return(StatusCode::SUCCESS);
177 }
178 m_cgemevt->clear();
179
180 m_nEvt++;
181 return StatusCode::SUCCESS;
182 }
183
184}
185
187 MsgStream log(msgSvc(), name());
188 log << MSG::INFO << "CgemAlignAlg finalize()" << endreq;
189
190 m_align->updateAlignPar(m_alignPar);
191 m_alignPar->wrtAlignPar();
192
193 // write histogram file
194 TFile fhist(m_histname.c_str(), "recreate");
195 m_hlist -> Write();
196 fhist.Close();
197 std::cout << m_histname << " was written" << std::endl;
198
199 return StatusCode::SUCCESS;
200}
201
202
203void CgemAlignAlg::initParam(){
204 m_param.particle = 0;
205 m_param.nEsFlag = 0;
206 m_param.tesMin = 0.0;
207 m_param.tesMax = 9999.0;
208 m_param.resiType = 0;
209 m_param.fgAdjacLayerCut = 0;
210 m_param.fgBoundLayerCut = 0;
211 m_param.hitStatCut = 0;
212 m_param.nTrkCut[0] = 2;
213 m_param.nTrkCut[1] = 2;
214 m_param.nHitLayCut = 35;
215 m_param.nHitCut = 70;
216 m_param.ptCut[0] = 0.0;
217 m_param.ptCut[1] = 100.0;
218 m_param.costheCut[0] = -1.0;
219 m_param.costheCut[1] = 1.0;
220 m_param.drCut = 50.0; // mm
221 m_param.dzCut = 300.0; // mm
222 m_param.maxDocaInner = 8.0; // mm
223 m_param.maxDocaOuter = 12.0; // mm
224 m_param.maxResi = 1.0; // mm
225
226}
227
228
229
IMessageSvc * msgSvc()
double maxDocaOuter
double costheCut[2]
double maxDocaInner
double ptCut[2]
StatusCode execute()
CgemAlignAlg(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode finalize()
StatusCode initialize()
virtual bool updateAlignPar(CgemAlignPar *alignPar)=0
virtual bool fillHist(CgemAliEvent *event, CgemAlignPar *alignPar)=0
virtual void setParam(CgemAliParams &param)=0
virtual void initialize(TObjArray *hlist, ICgemGeomSvc *cgemGeomSvc, ICgemCalibFunSvc *cgemFunSvc)=0
double getDz(int iEP)
double getRy(int iEP)
double getDy(int iEP)
double getDx(int iEP)
double getRz(int iEP)
double getRx(int iEP)
Definition Event.h:21