BOSS 7.0.7
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 68 of file EmcBhaCalib.cxx.

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

◆ ~EmcBhaCalib()

EmcBhaCalib::~EmcBhaCalib ( )
virtual

Definition at line 115 of file EmcBhaCalib.cxx.

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

Member Function Documentation

◆ execute()

StatusCode EmcBhaCalib::execute ( )

Definition at line 190 of file EmcBhaCalib.cxx.

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

◆ finalize()

StatusCode EmcBhaCalib::finalize ( )

Definition at line 294 of file EmcBhaCalib.cxx.

294 {
295
296 MsgStream log(msgSvc(), name());
297
298
299 log << MSG::INFO << "in endRun()" << endreq;
300
301
302 return StatusCode::SUCCESS;
303}

◆ help()

void EmcBhaCalib::help ( )
virtual

Definition at line 307 of file EmcBhaCalib.cxx.

307 {
308
309 MsgStream log(msgSvc(), name());
310
311 log << MSG::INFO<< "Performs the Chi square fit of the accumulated "
312 << endreq;
313}

◆ initialize()

StatusCode EmcBhaCalib::initialize ( )

Definition at line 140 of file EmcBhaCalib.cxx.

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

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