57 #include "StFgtQaCorrelationPlotMaker.h"
66 #include "StRoot/StFgtPool/StFgtCosmicTestStandGeom/StFgtCosmicTestStandGeom.h"
69 #include "StRoot/StEvent/StFgtCollection.h"
70 #include "StRoot/StEvent/StFgtHitCollection.h"
71 #include "StRoot/StEvent/StFgtHit.h"
74 StFgtQaCorrelationPlotMaker::StFgtQaCorrelationPlotMaker(
const Char_t* name,
77 const Char_t* quadName ) :
79 mComputeCor(1), mCovHist(0), mCorHist(0), mMatrix(0), mSum(0), mN(0) {
86 std::cerr <<
"TODO" << endl;
91 StFgtQaCorrelationPlotMaker::~StFgtQaCorrelationPlotMaker(){
97 for( Int_t i=0; i<mNbins; ++i )
109 std::cerr <<
"TODO" << endl;
113 Int_t StFgtQaCorrelationPlotMaker::Init(){
114 Int_t ierr = StFgtQaMaker::Init();
116 if( mDoVsStrip ==
'r' )
127 for( Int_t i=0; i<mNbins; ++i )
137 std::stringstream ss;
138 ss <<
GetName() <<
"_" << mDiscId <<
"_" << mQuadId <<
"_" << mDoVsStrip << mComputeCor;
146 if( mDoVsStrip ==
'R' || mDoVsStrip ==
'P' ){
153 mNbins = mXbins/mBinFactorX;
154 mCovHist =
new TH2F( name.data(),
"", mNbins, mXmin, mXmax, mNbins, mXmin, mXmax );
156 cout <<
"Size of TH2F is " << mNbins <<
' ' << mXmin <<
' ' << mXmax << endl;
159 getTitle( 0, title );
160 mCovHist->SetTitle( title.data() );
163 mCorHist =
new TH2F( (name +
"_cor").
data(),
"", mNbins, mXmin, mXmax, mNbins, mXmin, mXmax );
164 getTitle( 1, title );
165 mCorHist->SetTitle( title.data() );
168 mN =
new Int_t [mNbins];
169 mSum =
new Float_t [mNbins];
170 mMatrix =
new Float_t* [mNbins];
171 for( Int_t i=0; i<mNbins; ++i ){
174 mMatrix[i] =
new Float_t [mNbins];
175 for( Int_t j=0; j<mNbins; ++j )
187 std::map< Int_t, Float_t > hitMap;
188 std::map< Int_t, Int_t > countMap;
192 stripCollectionPtr = mFgtCollectionPtr->getStripCollection( mDiscId );
195 if( stripCollectionPtr ){
196 const StSPtrVecFgtStrip &stripVec = stripCollectionPtr->getStripVec();
197 StSPtrVecFgtStripConstIterator stripIter;
198 stripWeightMap_t::iterator stripMapIter;
200 for( stripIter = stripVec.begin(); stripIter != stripVec.end(); ++stripIter ){
201 Int_t geoId = (*stripIter)->getGeoId();
202 Short_t adc = (*stripIter)->getAdc( mTimeBin );
205 Short_t disc, quad, strip;
208 StFgtGeom::decodeGeoId( geoId, disc, quad, layer, strip );
210 if( disc == mDiscId && quad == mQuadId ){
214 if( mDoVsStrip ==
'R' || mDoVsStrip ==
'P' ){
215 pass = ( layer == mDoVsStrip );
219 Int_t rdo, arm, apv, channel;
220 StFgtCosmicTestStandGeom::getNaiveElecCoordFromGeoId(geoId,rdo,arm,apv,channel);
221 idx = 128*(apv%12) + channel;
237 if( !hitMap.empty() ){
239 std::map< Int_t, Float_t >::iterator iter1, iter2;
241 for( iter1 = hitMap.begin(); iter1 != hitMap.end(); ++iter1 ){
242 iter1->second /= countMap[ iter1->first ];
245 ++(mN[ iter1->first ]);
249 mSum[ iter1->first ] += iter1->second;
252 mMatrix[ iter1->first ][ iter1->first ] += iter1->second * iter1->second;
255 for( iter2 = hitMap.begin(); iter2 != iter1; ++iter2 ){
256 Int_t idx1 = iter1->first;
257 Int_t idx2 = iter2->first;
263 mMatrix[ idx1 ][ idx2 ] += iter1->second * iter2->second;
278 for( i = 0; i < mNbins && !ierr; ++i )
279 ierr = ( mN[i] != N && mN[i] );
282 cerr <<
"ERROR: number of counts per channel not consistant" << endl;
283 cerr <<
"Bin[0] = " << mN[0] << endl;
284 cerr <<
"Bin[" << i <<
"] = " << mN[i] << endl;
289 for( Int_t i = 0; i < mNbins && !ierr; ++i ){
295 for( Int_t j = 0; j <= i && !ierr; ++j )
300 Float_t nFactor = ( N>1 ? N/((Float_t)(N-1)) : 1 );
303 for( Int_t i = 0; i < mNbins && !ierr; ++i ){
304 for( Int_t j = 0; j <= i && !ierr; ++j ){
306 Float_t cov = mMatrix[i][j] - mSum[i]*mSum[j];
308 mCovHist->SetBinContent( i+1, j+1, cov );
309 mCovHist->SetBinContent( j+1, i+1, cov );
314 for( Int_t i = 0; i < mNbins && !ierr; ++i ){
315 Float_t sigmaSq1 = mCovHist->GetBinContent( i+1, i+1 );
316 for( Int_t j = 0; j <= i && !ierr; ++j ){
317 Float_t sigmaSq2 = mCovHist->GetBinContent( j+1, j+1 );
318 Float_t cov = mCovHist->GetBinContent( i+1, j+1 );
319 Float_t denom = sigmaSq1 * sigmaSq2;
320 denom = (denom > 0 ? sqrt(denom) : 0 );
321 Float_t cor = (denom ? cov/denom : 0);
323 if( cor > 1 || cor < -1 ){
328 cerr <<
"FATAL ERROR: abs. val. of correlation coefficient is greater than 1" << endl;
329 cerr << cor <<
' ' << cov <<
' ' << sigmaSq1 <<
' ' << sigmaSq2 << endl;
330 cerr << mDoVsStrip << endl;
334 mCorHist->SetBinContent( j+1, i+1, cor );
335 mCorHist->SetBinContent( i+1, j+1, cor );
343 void StFgtQaCorrelationPlotMaker::getTitle( Bool_t isCor, std::string& title ){
344 std::stringstream ss;
346 if( mDoVsStrip ==
'R' )
348 else if( mDoVsStrip ==
'P' )
349 ss <<
"#phi-strips: ";
352 ss <<
"Correlation Coefficients ";
356 if( mDoVsStrip ==
'R' || mDoVsStrip ==
'P' )
361 ss <<
", Quad " << mQuadName;
363 if( mDoVsStrip ==
'R' )
364 ss <<
"; r strip id.";
365 else if( mDoVsStrip ==
'P' )
366 ss <<
"; #phi strip id.";
368 ss <<
"; 128x(APV Num) + Channel Id.";
virtual const char * GetName() const
special overload