71 #include "StFgtPedStatQA.h"
72 #include "StRoot/StFgtUtil/geometry/StFgtGeom.h"
73 #include "StRoot/StFgtPool/StFgtCosmicTestStandGeom/StFgtCosmicTestStandGeom.h"
74 #include "StRoot/StFgtPool/StFgtPedMaker/StFgtPedMaker.h"
75 #include "StRoot/StFgtPool/StFgtPedMaker/StFgtPedMaker.h"
76 #include "StRoot/StFgtPool/StFgtStatusMaker/StFgtStatusMaker.h"
77 #include "StRoot/StFgtPool/StFgtStatusMaker/StFgtStatusMaker.h"
78 #include "StRoot/StFgtDbMaker/StFgtDb.h"
79 #include "StRoot/StFgtDbMaker/StFgtDbMaker.h"
80 #include "StRoot/StFgtUtil/StFgtConsts.h"
85 #include <TPaveText.h>
86 #include <TPaveStats.h>
95 StFgtPedStatQA::StFgtPedStatQA(
const Char_t* name,
96 const Char_t* pedMkrName,
97 const Char_t* statMkrName ) :
98 StMaker( name ), mPedMkrName( pedMkrName ), mPedMkr(0), mStatMkrName( statMkrName ), mStatMkr(0), mTimeBin(2),
99 maxAdcPed( 27.5 ), maxAdcRMS( 47.5 ), maxAdcFrac( 47.5 ) {
101 mFilenameArr[0] = &mFilenameTxt;
102 mFilenameArr[1] = &mFilenameRoot;
103 mFilenameArr[2] = &mFilenamePdf;
107 StFgtPedStatQA::~StFgtPedStatQA(){
112 Int_t StFgtPedStatQA::Init(){
117 for( Int_t i=0; i<3 && !ierr; ++i ){
118 if( !mFilenameArr[i]->empty() ){
119 std::ofstream fout( mFilenameArr[i]->
data() );
121 LOG_FATAL <<
"Error opening file '" << mFilenameArr[i] <<
"'" << endm;
128 mPedMkr =
static_cast< StFgtPedMaker*
>( GetMaker( mPedMkrName.data() ) );
130 LOG_FATAL <<
"Cannot find StFgtPedMaker" << endm;
136 if( !mPedMkr->mTimeBinMask & (1<<mTimeBin) ){
137 LOG_WARN <<
"StFgtPedMaker is not set to compute the time bin needed for StFgtPedStatQA" << endm;
138 mPedMkr->mTimeBinMask |= (1<<mTimeBin);
139 LOG_WARN <<
"StFgtPedMaker::mTimeBinMask set to 0x" << std::hex << mPedMkr->mTimeBinMask << std::dec << endm;
144 mStatMkr =
static_cast< StFgtStatusMaker*
>( GetMaker( mStatMkrName.data() ) );
146 LOG_FATAL <<
"Cannot find StFgtStatusMaker" << endm;
157 if( !mStatMkr->mHasFinished )
158 ierr = mStatMkr->
Finish();
160 cout <<
"StFgtPedStatQA::Finish()" << endl;
164 enum { kNumApv = kFgtApvsPerQuad*kFgtNumDiscs*kFgtNumQuads,
165 kNumUsedApv = kNumApv, kMaxADC = 1500, kMaxRMS = 205, kBins = 100, kMaxAliveYaxis = 132 };
167 Bool_t doMakeHists = !mFilenamePdf.empty() || !mFilenameRoot.empty();
168 Bool_t doMakeTxt = !mFilenameTxt.empty();
170 std::ofstream *foutPtr;
173 foutPtr =
new std::ofstream( mFilenameTxt.data(), std::ios_base::out & std::ios_base::trunc );
175 LOG_FATAL <<
"Error opening file '" << mFilenameTxt.data() <<
"'" << endm;
183 TH1F *hPed[kNumApv], *hRMS[kNumApv], *hFrac[kNumApv];
189 Int_t canWidth = 850, canHeight = 1100;
190 std::stringstream ss;
192 if( !ierr && doMakeHists ){
193 gROOT->SetStyle(
"Plain" );
194 gStyle->SetPalette(1);
195 gStyle->SetOptStat(111110);
196 gStyle->SetPaperSize(TStyle::kUSLetter);
198 if( !mFilenameRoot.empty() )
199 tfilePtr =
new TFile ( mFilenameRoot.data(),
"RECREATE",
"FGT Ped QA" );
201 for( Int_t i=0; i<kNumApv; ++i ){
206 hPed[i] =
new TH1F( (std::string(
"hPed_") + ss.str() ).
data(),
"", kBins/3, 0, kMaxADC );
207 hRMS[i] =
new TH1F( (std::string(
"hRMS_") + ss.str() ).
data(),
"", kBins/3, 0, kMaxRMS );
208 hFrac[i] =
new TH1F( (std::string(
"hFrac_") + ss.str() ).
data(),
"", kBins/3, 0, 1 );
211 hPed2D =
new TH2F(
"hPed2D",
"", kNumUsedApv, 0, kNumUsedApv, kBins, 0, kMaxADC );
212 hRMS2D =
new TH2F(
"hRMS2D",
"", kNumUsedApv, 0, kNumUsedApv, kBins, 0, kMaxRMS );
213 hFrac2D =
new TH2F(
"hFrac2D",
"", kNumUsedApv, 0, kNumUsedApv, kBins, 0, 1 );
214 hAlive =
new TH1F(
"hAlive",
"", kNumUsedApv, 0, kNumUsedApv );
217 StFgtPedMaker::pedDataVec_t& pedVec = mPedMkr->mDataVec;
218 StFgtPedMaker::pedDataVec_t::iterator pedVecIter;
221 if( !mPedMkr->mDbMkrName.empty() ){
222 if( !mPedMkr->mFgtDbMkr ){
223 LOG_FATAL <<
"Pointer to Fgt DB Maker is null" << endm;
227 fgtTables = mPedMkr->mFgtDbMkr->getDbTables();
230 LOG_FATAL <<
"Pointer to Fgt DB Tables is null" << endm;
236 Int_t numnonzero = 0;
239 for( pedVecIter = pedVec.begin(); pedVecIter != pedVec.end() && !ierr; ++pedVecIter, ++pedIdx ){
243 Int_t timebin = pedIdx % kFgtNumTimeBins;
245 Int_t elecId = pedIdx / kFgtNumTimeBins;
246 UChar_t status = mStatMkr->mStatus[ elecId ];
248 UChar_t invalidID = (1<<mStatMkr->INVALID_ID);
249 if( status != invalidID ){
250 Int_t rdo, arm, apv, channel;
251 StFgtGeom::getElecCoordFromElectId( elecId, rdo, arm, apv, channel );
258 Int_t rdo2, arm2, apv2, channel2;
260 Int_t geoId = fgtTables->getGeoIdFromElecCoord( rdo, arm, apv, channel );
262 fgtTables->getElecCoordFromGeoId(geoId, rdo2, arm2, apv2, channel2 );
263 Int_t elecId2 = StFgtGeom::getElectIdFromElecCoord( rdo2, arm2, apv2, channel2 );
265 if( elecId2 != elecId && geoId > -1 ){
266 cout <<
"ERROR: " << elecId <<
" -> " << rdo <<
' ' << arm <<
' ' << apv <<
' ' << channel;
267 cout <<
" -> " << geoId <<
" -> " << rdo2 <<
' ' << arm2 <<
' ' << apv2 <<
' ' << channel2;
268 cout <<
" -> " << elecId2 << endl;
274 geoId = fgtTables->getGeoIdFromElecCoord( rdo, arm, apv, channel );
277 LOG_ERROR <<
"Error: not supported for use without the DB" << endm;
279 Short_t disc, quad, strip;
281 StFgtGeom::decodeGeoId( geoId, disc, quad, layer, strip );
287 Int_t histIdx = (apv%12) + 10*( quad + 4*disc );
290 (*foutPtr) << elecId <<
' ' << rdo <<
' ' << arm <<
' ' << apv <<
' ' << channel <<
" | ";
291 (*foutPtr) << geoId <<
' ' << disc <<
' ' << quad <<
' ' << layer <<
' ' << strip <<
" | ";
292 (*foutPtr) << timebin <<
' ' << pedVecIter ->ped <<
' ' << pedVecIter->RMS <<
' ' << pedVecIter->fracClose <<
" | ";
293 (*foutPtr) <<
"0x" << std::hex << (UInt_t)(status) << std::dec <<
" | " << histIdx << endl;
296 if( timebin == mTimeBin && doMakeHists ){
297 hPed[histIdx]->Fill( pedVecIter->ped );
298 hRMS[histIdx]->Fill( pedVecIter->RMS );
299 hFrac[histIdx]->Fill( pedVecIter->fracClose );
301 hPed2D->Fill( histIdx, pedVecIter->ped );
302 hRMS2D->Fill( histIdx, pedVecIter->RMS );
303 hFrac2D->Fill( histIdx, pedVecIter->fracClose );
305 if( hAlive->GetBinContent( histIdx+1 ) < 1 ){
307 hAlive->SetBinContent( histIdx+1, kFgtNumChannels-data.numDead );
308 if( ( apv >= kFgtApvsPerAssembly ? apv-kFgtApvGap : apv ) % kFgtApvsPerOct == kFgtApvsPerOct/2 ){
311 ss << disc+1 << (Char_t)(quad+
'A') << StFgtGeom::getOctant( apv );
313 hAlive->GetXaxis()->SetBinLabel( histIdx+1, ss.str().data() );
314 hPed2D->GetXaxis()->SetBinLabel( histIdx+1, ss.str().data() );
315 hRMS2D->GetXaxis()->SetBinLabel( histIdx+1, ss.str().data() );
316 hFrac2D->GetXaxis()->SetBinLabel( histIdx+1, ss.str().data() );
325 LOG_INFO <<
"---> PedVec has " << numnonzero <<
" of " << pedVec.size() <<
" nonzero entries" << endm;
332 if( !ierr && doMakeHists ){
333 for( Int_t histIdx = 0; histIdx < kNumApv; ++histIdx ){
339 Int_t apvMod = i % 12;
345 Bool_t octIsShort = ( StFgtGeom::getOctant( apvMod ) ==
'S' );
346 Int_t geoId = StFgtGeom::encodeGeoId( disc, quad,
'P', octIsShort*700 );
349 Int_t rdo, arm, apv, channel;
352 fgtTables->getElecCoordFromGeoId( geoId, rdo, arm, apv, channel );
356 ss <<
"Rdo. " << rdo <<
", Arm " << arm <<
", APV%12 " << apvMod <<
", Octant ";
357 ss << disc+1 << (Char_t)(quad+
'A') << (octIsShort ?
'S' :
'L');
363 hPed[histIdx]->SetTitle( ( ss.str() +
"; Ped Value [ADC]; Counts" ).
data() );
364 hRMS[histIdx]->SetTitle( ( ss.str() +
"; Ped St. Dev. [ADC]; Counts" ).
data() );
365 hFrac[histIdx]->SetTitle( ( ss.str() +
"; Frac. of Integral Near Ped.; Counts" ).
data() );
367 hPed[histIdx]->SetTitle(
"" );
368 hRMS[histIdx]->SetTitle(
"" );
369 hFrac[histIdx]->SetTitle(
"" );
372 hPed2D->SetTitle(
"Pedestals per APV; ; ADC");
373 hRMS2D->SetTitle(
"Pedestal RMS per APV; ; ADC");
374 hFrac2D->SetTitle(
"Fraction of Integral Near Pedestal per APV; ; Fraction");
375 hAlive->SetTitle(
"Number Good Strips per APV; ; Number");
377 if( !mFilenameRoot.empty() ){
382 for( Int_t i=0; i<kNumApv; ++i ){
383 if( !std::string(hPed[i]->GetTitle()).empty() ){
391 hAlive->SetFillColor(kYellow-9);
392 hAlive->SetLineColor(kBlue);
394 if( !mFilenamePdf.empty() ){
396 TCanvas *can1 =
new TCanvas(
"fgtCan1",
"fgt Ped QA", canWidth, canHeight );
397 TCanvas *can2 =
new TCanvas(
"fgtCan2",
"fgt Ped QA", canWidth, canHeight );
399 hPed2D->SetMaximum( maxAdcPed );
400 hRMS2D->SetMaximum( maxAdcRMS );
401 hFrac2D->SetMaximum( maxAdcFrac );
402 hAlive->SetMaximum( kMaxAliveYaxis );
404 can1->Divide( 1, 4 );
406 TH1 *h2D[] = { hAlive, hPed2D, hRMS2D, hFrac2D };
407 Float_t highCut[]={ kFgtNumChannels, mStatMkr->mMaxPed, mStatMkr->mMaxRMS, mStatMkr->mMaxFrac };
408 Float_t fMaxDead = kFgtNumChannels-mStatMkr->mMaxDead;
409 Float_t lowCut[] ={ fMaxDead, mStatMkr->mMinPed, mStatMkr->mMinRMS, mStatMkr->mMinFrac };
411 for( Int_t i=0; i<4; ++i ){
413 gPad->SetLeftMargin( 0.06 );
414 gPad->SetRightMargin( 0.05 );
415 gPad->SetBottomMargin( 0.11 );
421 h2D[i]->Draw( i ?
"COLZ" :
"" );
422 h2D[i]->GetXaxis()->SetTitleOffset(0.9);
423 h2D[i]->GetXaxis()->SetTitleSize(0.06);
424 h2D[i]->GetXaxis()->SetLabelSize(0.06);
425 h2D[i]->GetYaxis()->SetTitleOffset(1.2);
426 h2D[i]->GetYaxis()->SetTitleSize(0.06);
427 h2D[i]->GetYaxis()->SetLabelSize(0.06);
429 TLine *lineA =
new TLine ( 0, highCut[i], kNumUsedApv, highCut[i] );
430 lineA->SetLineColor(kRed);
433 TLine *lineB =
new TLine ( 0, lowCut[i], kNumUsedApv, lowCut[i] );
434 lineB->SetLineColor(kRed);
440 TPaveText *title = (TPaveText*)(gPad->GetPrimitive(
"title"));
442 title->SetX1NDC( 0.045 );
443 title->SetX2NDC( 0.55 );
444 title->SetY1NDC( 0.91 ) ;
445 title->SetY2NDC( 0.999 );
446 title->SetBorderSize(0);
447 title->SetTextAlign( 12 );
448 title->SetTextColor(kBlue);
452 TPave *palette = (TPave*)(gPad->GetPrimitive(
"palette"));
454 palette->SetX1NDC( 0.955 );
455 palette->SetX2NDC( 0.985 );
460 can1->Print( (mFilenamePdf +
"[").
data() );
461 can1->Print( mFilenamePdf.data() );
463 can2->Divide( 3, 5 );
464 for( Int_t i=0; i<kNumApv; ++i ){
465 for( Int_t j=0; j<3; ++j ){
466 can2->cd( (i%5)*3+1+j );
480 hist->SetMaximum( max );
482 gPad->SetBottomMargin(0.15);
483 hist->GetXaxis()->SetTitleSize(0.06);
484 hist->GetXaxis()->SetLabelSize(0.06);
485 hist->GetYaxis()->SetTitleOffset(0.85);
486 hist->GetYaxis()->SetTitleSize(0.06);
487 hist->GetYaxis()->SetLabelSize(0.06);
488 hist->SetLineColor(kBlue);
493 TPaveText *title = (TPaveText*)(gPad->GetPrimitive(
"title"));
495 title->SetX1NDC( 0 );
496 title->SetX2NDC( 0.55 );
497 title->SetY1NDC( 0.91 ) ;
498 title->SetY2NDC( 0.999 );
499 title->SetBorderSize(0);
500 title->SetTextAlign( 12 );
501 title->SetTextColor(kRed);
505 TPaveStats *stats = (TPaveStats*)(gPad->GetPrimitive(
"stats"));
507 stats->SetX1NDC( 0.68 );
508 stats->SetX2NDC( 0.99 );
509 stats->SetY1NDC( 0.68 ) ;
510 stats->SetY2NDC( 0.99 );
515 if( (i+1) % 5 == 0 && !std::string(hPed[i]->GetTitle()).empty() ){
516 can2->Print( mFilenamePdf.data() );
520 can2->Print( ( mFilenamePdf +
"]").
data() );
523 if( !mFilenameRoot.empty() )