BOSS 6.6.4.p01
BESIII Offline Software System
Loading...
Searching...
No Matches
EmcBhaCalib Class Reference

#include <EmcBhaCalib.h>

+ Inheritance diagram for EmcBhaCalib:

Public Member Functions

 EmcBhaCalib (const std::string &name, ISvcLocator *pSvcLocator)
 
virtual ~EmcBhaCalib ()
 
StatusCode initialize ()
 
StatusCode execute ()
 
StatusCode finalize ()
 
virtual void help ()
 

Detailed Description

class EmcBhaCalib Algorithm - performs calibration of EMC Xtals with Bhabha events and Chi^2 fit, the resulting system of linear equations of the fit is solved with the SLAP Algebra package

The matrix and the vector can either be fetched from file(s). If they are read from files the file names are supposed to have the name CalibVector.dat and calibMatrix.dat with an extension at the beginning. Only these extensions (usually the runnumbers) need to be listed in the read-in-file that is specified with runNumberFile.

Author
Chunxiu Liu (originator/contributor etc.);

Definition at line 58 of file EmcBhaCalib.h.

Constructor & Destructor Documentation

◆ EmcBhaCalib()

EmcBhaCalib::EmcBhaCalib ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

Definition at line 62 of file EmcBhaCalib.cxx.

63 :Algorithm(name, pSvcLocator),
64 m_dirHitsCut(200),
65 m_convCrit(0.000001),
66 m_askForMatrixInversion(true),
67 m_fitPolynom(true), //no used now
68 m_writeToFile(false),
69 m_readDataFromDB(false),
70 m_equationSolver("GMR"),
71 m_fileExt(""),
72 m_fileDir("/ihepbatch/besdata/public/liucx/Calib/"),
73 m_nrNonZeros(0),
74 m_nrXtalsEnoughHits(0),
75 m_runNumberFile("runnumbers.dat"),
76 m_MsgFlag(0)
77
78{
79
80 // Declare the properties
81 declareProperty("equationSolver", m_equationSolver);
82 declareProperty("dirHitsCut", m_dirHitsCut);
83 declareProperty("writeToFile", m_writeToFile);
84 declareProperty("fileExt", m_fileExt);
85 declareProperty("fileDir", m_fileDir);
86 declareProperty("readDataFromDB", m_readDataFromDB);
87 declareProperty("askForMatrixInversion", m_askForMatrixInversion);
88 declareProperty("fitPolynom", m_fitPolynom);
89 declareProperty("convCrit", m_convCrit);
90 declareProperty("runNumberFile", m_runNumberFile);
91 declareProperty("MsgFlag", m_MsgFlag);
92
93 m_calibConst = new double[6240];
94 m_calibConstUnred = new double[6240];
95 m_absoluteConstants = new double[6240];
96 m_oldConstants = new double[6240];
97
98
99 //ntuple
100 m_tuple1=0;
101
102
103
104}

◆ ~EmcBhaCalib()

EmcBhaCalib::~EmcBhaCalib ( )
virtual

Definition at line 109 of file EmcBhaCalib.cxx.

109 {
110 if ( 0 != m_calibConst) {
111 delete [] m_calibConst;
112 m_calibConst = 0;
113 }
114 if ( 0 != m_calibConstUnred) {
115 delete [] m_calibConstUnred;
116 m_calibConstUnred = 0;
117 }
118 if ( 0 != m_absoluteConstants) {
119 delete [] m_absoluteConstants;
120 m_absoluteConstants = 0;
121 }
122 if ( 0 != m_oldConstants) {
123 delete [] m_oldConstants;
124 m_oldConstants = 0;
125 }
126 if ( 0 != m_myCalibData) {
127 delete m_myCalibData;
128 m_myCalibData = 0;
129 }
130
131}

Member Function Documentation

◆ execute()

StatusCode EmcBhaCalib::execute ( )

Definition at line 184 of file EmcBhaCalib.cxx.

184 {
185
186 MsgStream log(msgSvc(), name());
187 log << MSG::DEBUG << "in execute()" << endreq;
188 //read in accumulated matrix/matrices
189 if ( m_readDataFromDB ) {
190 m_calibrationSuccessful = readInFromDB();
191
192 log << MSG::INFO << "read in accumulated matrix from DB"<<endreq;
193
194 } else {
195 m_calibrationSuccessful = readInFromFile();
196
197 log << MSG::INFO <<"read in accumulated matrix from file"<<endreq;
198
199 }
200
201 if ( m_calibrationSuccessful == true ) {
202
203 //ask first if to do a matrix inversion
204 if (m_askForMatrixInversion==true) {
205
206 m_calibrationSuccessful = false;
207 log << MSG::INFO << " Well, we have "
208 << m_nrXtalsEnoughHits << " crystals whith more "
209 << "than " << m_dirHitsCut
210 << " direct hits. Do you want do "
211 << "a matrix inversion ? [N]" << endreq;
212
213
214 m_calibrationSuccessful = true;
215
216 }
217
218 if ( m_calibrationSuccessful == true ) {
219
220 //write added matrix and vector to files
221 if ( m_writeToFile == true) {
222 writeOut();
223 }
224 //cout <<"writeout"<<endl;
225 m_myCalibData->printVec(2);
226
227 //reduce to continious array of only non zeros elements for SLAP
228 if ( m_calibrationSuccessful = m_myCalibData->reduce() ) {
229
230 cout<<"m_calibrationSuccessful="<<m_calibrationSuccessful<<endl;
231
232 if ( m_myCalibData->nXtalsHit() != m_myCalibData->nXtals() ){
233 log << MSG::INFO << " Reduced number of Xtals for calibration: "
234 << m_myCalibData->nXtalsHit()
235 << endreq;
236 }
237 cout<<"m_myCalibData->nXtalsHit()="<<m_myCalibData->nXtalsHit()
238 <<"m_myCalibData->nXtals()="<<m_myCalibData->nXtals()<<endl;
239 m_myCalibData->printVec(10);
240
241 //solve matrix equation
242 if ( m_calibrationSuccessful = solveEqua() ) {
243
244 for (int i=0; i<m_myCalibData->nXtalsHit(); i++){
245 //fill an array of constants for storage in database
246 m_calibConstUnred[m_myCalibData->xtalInd(i)]
247 = m_calibConst[i];
248
249 // if (m_myCalibData->xtalHitsDir(i)>10)
250 // cout<<"Index,calibconst="<<" "<<i <<" "<<m_myCalibData->xtalInd(i)
251 // <<" "<<m_calibConstUnred[m_myCalibData->xtalInd(i)]
252 // <<" "<<m_calibConstUnred[m_myCalibData->xtalInd(i)]*
253 // m_oldConstants[m_myCalibData->xtalInd(i)]<<endl;
254
255 }
256 //do validation, fit polynom if necessary, fill CalList
257 prepareConstants();
258
259 //if wanted write constants to plain ASCII file
260 if ( m_writeToFile==true){
261 writeOutConst();
262 }
263
264 ntupleOut();
265
266 }
267
268 } else {
269 log << MSG::WARNING << " Reduction of the Emc Bhabha calibration matrix FAILED !"
270 << endl
271 << " Will NOT perform Emc Bhabha calibration !"
272 << endreq;
273 return( StatusCode::FAILURE);
274 }
275 }
276 } else {
277 log << MSG::WARNING << " ERROR in reading in Emc Bhabha calibration data !"
278 << endl
279 << " Will NOT perform Emc Bhabha calibration !"
280 << endreq;
281 return( StatusCode::FAILURE);
282 }
283
284 return StatusCode::SUCCESS;
285}
IMessageSvc * msgSvc()
void printVec(int number)
int xtalInd(int ind)

◆ finalize()

StatusCode EmcBhaCalib::finalize ( )

Definition at line 288 of file EmcBhaCalib.cxx.

288 {
289
290 MsgStream log(msgSvc(), name());
291
292
293 log << MSG::INFO << "in endRun()" << endreq;
294
295
296 return StatusCode::SUCCESS;
297}

◆ help()

void EmcBhaCalib::help ( )
virtual

Definition at line 301 of file EmcBhaCalib.cxx.

301 {
302
303 MsgStream log(msgSvc(), name());
304
305 log << MSG::INFO<< "Performs the Chi square fit of the accumulated "
306 << endreq;
307}

◆ initialize()

StatusCode EmcBhaCalib::initialize ( )

Definition at line 134 of file EmcBhaCalib.cxx.

134 {
135
136 MsgStream log(msgSvc(), name());
137 log << MSG::INFO << "in initialize()" << endreq;
138
139 m_myCalibData = new EmcBhaCalibData(6240, m_MsgFlag);
140
141 m_calibrationSuccessful = false;
142
143 StatusCode status1;
144
145 NTuplePtr nt1(ntupleSvc(),"FILE302/n1");
146 if ( nt1 ) m_tuple1 = nt1;
147 else {
148 m_tuple1=ntupleSvc()->book("FILE302/n1",CLID_ColumnWiseTuple,"Calib");
149 if( m_tuple1 ) {
150
151 status1 = m_tuple1->addItem ("ixtal",ixtal);
152 status1 = m_tuple1->addItem ("gi0",gi0);
153 status1 = m_tuple1->addItem ("calibConst",calibConst);
154 status1 = m_tuple1->addItem ("err",err);
155 status1 = m_tuple1->addItem ("nhitxtal",nhitxtal);
156
157 }
158 else { // did not manage to book the N tuple....
159 log << MSG::ERROR <<"Cannot book N-tuple:" << long(m_tuple1) << endmsg;
160 return StatusCode::FAILURE;
161 }
162 }
163
164 // use EmcCalibConstSvc
165 StatusCode scCalib;
166 scCalib = Gaudi::svcLocator() -> service("EmcCalibConstSvc", m_emcCalibConstSvc);
167 if( scCalib != StatusCode::SUCCESS){
168 log << MSG::ERROR << "can not use EmcCalibConstSvc" << endreq;
169 }
170 else {
171 std::cout << "Test EmcCalibConstSvc DigiCalibConst(0)= "
172 << m_emcCalibConstSvc -> getDigiCalibConst(0) << std::endl;
173 }
174
175 //init starting values for calibration constants from file or set to 1
176 initCalibConst();
177
178 //digiConstCor();
179
180 return StatusCode::SUCCESS;
181}
INTupleSvc * ntupleSvc()

The documentation for this class was generated from the following files: