BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EmcBhaCalibData.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3//
4//
5// Description:
6// Class EmcBhaCalibData - see header
7//
8// Environment:
9// Software developed for the BESIII Detector at the BEPCII.
10//
11// Author List:
12// Chunxiu Liu
13//
14// Copyright Information:
15// Copyright (C) 2005 IHEP
16//
17//------------------------------------------------------------------------
18
19//-----------------------
20// This Class's Header --
21//-----------------------
22#include "EmcBhaCalibData.h"
23
24//-------------
25// C Headers --
26//-------------
27extern "C" {}
28
29//---------------
30// C++ Headers --
31//---------------
32
33#include <cstring>
34
35using namespace std;
36//-------------------------------
37// Collaborating Class Headers --
38//-------------------------------
39
40// ----------------------------------------
41// -- Public Function Member Definitions --
42// ----------------------------------------
43
44//----------------
45// Constructors --
46//----------------
47EmcBhaCalibData::EmcBhaCalibData( int numxtals ) : _nXtals( numxtals ), _nXtalsHit( 0 ) {
48 // _matrixM = new EmcLSSMatrix(_nXtals,600);
49 _matrixM = new EmcLSSMatrix( _nXtals, _nXtals );
50 _vectorR = new double[_nXtals];
51 _xtalInd = new int[_nXtals];
52 _xtalHits = new int[_nXtals];
53 _xtalHitsMax = new int[_nXtals];
54 for ( int i = 0; i < _nXtals; i++ )
55 {
56 _vectorR[i] = 0.;
57 _xtalInd[i] = i;
58 _xtalHits[i] = 0;
59 _xtalHitsMax[i] = 0;
60 }
61 _MsgFlag = 0;
62}
63
64//----------------
65// Constructors --
66//----------------
67EmcBhaCalibData::EmcBhaCalibData( int numxtals, int MsgFlag )
68 : _nXtals( numxtals ), _nXtalsHit( 0 ) {
69 // _matrixM = new EmcLSSMatrix(_nXtals,600);
70 _matrixM = new EmcLSSMatrix( _nXtals, _nXtals, MsgFlag );
71 _vectorR = new double[_nXtals];
72 _xtalInd = new int[_nXtals];
73 _xtalHits = new int[_nXtals];
74 _xtalHitsMax = new int[_nXtals];
75 for ( int i = 0; i < _nXtals; i++ )
76 {
77 _vectorR[i] = 0.;
78 _xtalInd[i] = i;
79 _xtalHits[i] = 0;
80 _xtalHitsMax[i] = 0;
81 }
82
83 _MsgFlag = MsgFlag;
84}
85
86//--------------
87// Destructor --
88//--------------
90 if ( 0 != _matrixM )
91 {
92 delete _matrixM;
93 _matrixM = 0;
94 }
95 if ( 0 != _vectorR )
96 {
97 delete[] _vectorR;
98 _vectorR = 0;
99 }
100 if ( 0 != _xtalInd )
101 {
102 delete[] _xtalInd;
103 _xtalInd = 0;
104 }
105 if ( 0 != _xtalHits )
106 {
107 delete[] _xtalHits;
108 _xtalHits = 0;
109 }
110 if ( 0 != _xtalHitsMax )
111 {
112 delete[] _xtalHitsMax;
113 _xtalHitsMax = 0;
114 }
115}
116//-------------
117// Operators --
118//-------------
119
120//-------------
121// Selectors --
122//-------------
123
124//-------------
125// Modifiers --
126//-------------
127
128void EmcBhaCalibData::writeOut( ostream& OutM, ostream& OutV ) {
129
130 // write only non zero elements to file
131 OutM.setf( ios::scientific, ios::floatfield );
132 OutV.setf( ios::scientific, ios::floatfield );
133 OutV.precision( 12 );
134 OutM.precision( 12 );
135
136 _matrixM->writeOut( OutM );
137
138 _nXtalsHit = 0;
139
140 double* vect_ele = _vectorR;
141 double* vect_end = _vectorR + _nXtals;
142 int* xtal_ind = _xtalInd;
143 int* hits_max = _xtalHitsMax;
144 int* hits = _xtalHits;
145
146 while ( vect_ele < vect_end )
147 {
148 if ( *vect_ele != 0. ) { _nXtalsHit++; }
149 vect_ele++;
150 }
151
152 OutV << _nXtalsHit << " ";
153
154 vect_ele = _vectorR;
155
156 while ( vect_ele < vect_end )
157 {
158 if ( *vect_ele != 0. )
159 { OutV << *xtal_ind << " " << *hits << " " << *hits_max << " " << *vect_ele << " "; }
160 xtal_ind++;
161 vect_ele++;
162 hits_max++;
163 hits++;
164 }
165}
166
167void EmcBhaCalibData::readIn( istream& InM, istream& InV ) {
168
169 _matrixM->readIn( InM );
170
171 _matrixM->print_NonZeros();
172
173 // cout<<"num_filled_rows(48)="<<_matrixM->num_filled_rows(48)<<endl;
174 // cout<<"num_filled_cols(48)="<<_matrixM->num_filled_cols(48)<<endl;
175
176 // cout<<"matrix(47,47)"<<_matrixM->operator()(47,47)<<endl;
177
178 double vect_ele;
179 int nr_ele;
180 int xtal_ind;
181 int hits;
182 int hits_max;
183
184 InV >> nr_ele;
185
186 for ( int i = 0; i < nr_ele; i++ )
187 {
188
189 InV >> xtal_ind >> hits >> hits_max >> vect_ele;
190
191 if ( _vectorR[xtal_ind] == 0. ) { _nXtalsHit++; }
192
193 _vectorR[xtal_ind] += vect_ele;
194 _xtalInd[xtal_ind] = xtal_ind;
195 _xtalHits[xtal_ind] += hits;
196 _xtalHitsMax[xtal_ind] += hits_max;
197 }
198}
199
201
202 bool successful = true;
203
204 // delete all zero elements in matrix and vector R
205 // save only non zero elements (this format is needed by slap),
206 // keep the original xtal index in array xtalInd
207
208 // array to store the new row/column reference for later matrix reduction
209 int* xRef = new int[_nXtals];
210 memset( xRef, -1, ( _nXtals * sizeof( int ) ) );
211
212 _nXtalsHit = 0;
213 for ( int _arrayIndx = 0; _arrayIndx < _nXtals; _arrayIndx++ )
214 {
215
216 if ( _vectorR[_arrayIndx] > 0. )
217 {
218
219 _vectorR[_nXtalsHit] = _vectorR[_arrayIndx];
220 _xtalInd[_nXtalsHit] = _xtalInd[_arrayIndx];
221 _xtalHits[_nXtalsHit] = _xtalHits[_arrayIndx];
222 _xtalHitsMax[_nXtalsHit] = _xtalHitsMax[_arrayIndx];
223 xRef[_arrayIndx] = _nXtalsHit;
224
225 _nXtalsHit++;
226 }
227 }
228
229 successful = _matrixM->reduce_Matrix( xRef );
230
231 delete[] xRef;
232
233 return successful;
234}
235
237 _nXtalsHit = 0;
238 _matrixM->reset();
239
240 for ( int i = 0; i < _nXtals; i++ )
241 {
242 _vectorR[i] = 0.;
243 _xtalInd[i] = i;
244 _xtalHits[i] = 0;
245 _xtalHitsMax[i] = 0;
246 }
247}
248
249void EmcBhaCalibData::printVec( int number ) {
250
251 if ( _MsgFlag <= 3 )
252 {
253 std::cout << "EmcBhaCalibData:: INFO "
254 << "R ( " << number << " ): " << _vectorR[number]
255 << " hits: " << _xtalHits[number] << " direct hits: " << _xtalHitsMax[number]
256 << endl;
257 }
258}
const double hits_max
void printVec(int number)
void writeOut(ostream &OutM, ostream &outV)
EmcBhaCalibData(int numxtals)
void readIn(istream &InM, istream &InV)