BOSS 8.0.0
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 56 of file EmcBhaCalib.h.

Constructor & Destructor Documentation

◆ EmcBhaCalib()

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

Definition at line 65 of file EmcBhaCalib.cxx.

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

Referenced by EmcBhaCalib().

◆ ~EmcBhaCalib()

EmcBhaCalib::~EmcBhaCalib ( )
virtual

Definition at line 110 of file EmcBhaCalib.cxx.

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

Member Function Documentation

◆ execute()

StatusCode EmcBhaCalib::execute ( )

Definition at line 193 of file EmcBhaCalib.cxx.

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

◆ finalize()

StatusCode EmcBhaCalib::finalize ( )

Definition at line 294 of file EmcBhaCalib.cxx.

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

◆ help()

void EmcBhaCalib::help ( )
virtual

Definition at line 303 of file EmcBhaCalib.cxx.

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

◆ initialize()

StatusCode EmcBhaCalib::initialize ( )

Definition at line 139 of file EmcBhaCalib.cxx.

139 {
140
141 MsgStream log( msgSvc(), name() );
142 log << MSG::INFO << "in initialize()" << endmsg;
143
144 m_myCalibData = new EmcBhaCalibData( 6240, m_MsgFlag );
145
146 m_calibrationSuccessful = false;
147
148 StatusCode status1;
149
150 NTuplePtr nt1( ntupleSvc(), "FILE302/n1" );
151 if ( nt1 ) m_tuple1 = nt1;
152 else
153 {
154 m_tuple1 = ntupleSvc()->book( "FILE302/n1", CLID_ColumnWiseTuple, "Calib" );
155 if ( m_tuple1 )
156 {
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 else
165 { // 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" << endmsg; }
176 else
177 {
178 std::cout << "Test EmcCalibConstSvc DigiCalibConst(0)= "
179 << m_emcCalibConstSvc->getDigiCalibConst( 0 ) << std::endl;
180 }
181
182 // std::cout<<6239<<"\t"<< m_emcCalibConstSvc->getCrystalEmaxData(6239) <<endl;
183
184 // init starting values for calibration constants from file or set to 1
185 initCalibConst();
186
187 // digiConstCor();
188
189 return StatusCode::SUCCESS;
190}
INTupleSvc * ntupleSvc()

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