BOSS 7.1.2
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 69 of file EmcBhaCalib.cxx.

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

◆ ~EmcBhaCalib()

EmcBhaCalib::~EmcBhaCalib ( )
virtual

Definition at line 116 of file EmcBhaCalib.cxx.

116 {
117 if ( 0 != m_calibConst) {
118 delete [] m_calibConst;
119 m_calibConst = 0;
120 }
121 if ( 0 != m_calibConstUnred) {
122 delete [] m_calibConstUnred;
123 m_calibConstUnred = 0;
124 }
125 if ( 0 != m_absoluteConstants) {
126 delete [] m_absoluteConstants;
127 m_absoluteConstants = 0;
128 }
129 if ( 0 != m_oldConstants) {
130 delete [] m_oldConstants;
131 m_oldConstants = 0;
132 }
133 if ( 0 != m_myCalibData) {
134 delete m_myCalibData;
135 m_myCalibData = 0;
136 }
137
138}

Member Function Documentation

◆ execute()

StatusCode EmcBhaCalib::execute ( )

Definition at line 195 of file EmcBhaCalib.cxx.

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

◆ finalize()

StatusCode EmcBhaCalib::finalize ( )

Definition at line 299 of file EmcBhaCalib.cxx.

299 {
300
301 MsgStream log(msgSvc(), name());
302
303
304 log << MSG::INFO << "in endRun()" << endreq;
305
306
307 return StatusCode::SUCCESS;
308}

◆ help()

void EmcBhaCalib::help ( )
virtual

Definition at line 312 of file EmcBhaCalib.cxx.

312 {
313
314 MsgStream log(msgSvc(), name());
315
316 log << MSG::INFO<< "Performs the Chi square fit of the accumulated "
317 << endreq;
318}

◆ initialize()

StatusCode EmcBhaCalib::initialize ( )

Definition at line 141 of file EmcBhaCalib.cxx.

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

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