From 48ccaa079e94bc856c9736b107e3cf45d0ce211e Mon Sep 17 00:00:00 2001 From: cblume Date: Fri, 29 Aug 2008 08:03:39 +0000 Subject: [PATCH] Update by Sylwester --- TRD/AliTRDqaBlackEvents.cxx | 1997 +++++++++++++++++++---------------- TRD/AliTRDqaBlackEvents.h | 46 +- 2 files changed, 1138 insertions(+), 905 deletions(-) diff --git a/TRD/AliTRDqaBlackEvents.cxx b/TRD/AliTRDqaBlackEvents.cxx index 2e340494cd5..16302498e0a 100644 --- a/TRD/AliTRDqaBlackEvents.cxx +++ b/TRD/AliTRDqaBlackEvents.cxx @@ -1,901 +1,1096 @@ -/************************************************************************** - * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * - * * - * Author: The ALICE Off-line Project. * - * Contributors are mentioned in the code where appropriate. * - * * - * Permission to use, copy, modify and distribute this software and its * - * documentation strictly for non-commercial purposes is hereby granted * - * withount fee, provided that the abov copyright notice appears in all * - * copies and that both the copyright notice and this permission notice * - * appear in the supporting documentation. The authors make no claims * - * about the suitability of this software for any purpose. It is * - * provided "as is without express or implied warranty. * - **************************************************************************/ - -/* $Id: AliTRDqaBlackEvents.cxx 23387 2008-01-17 17:25:16Z cblume $ */ - -//////////////////////////////////////////////////////////////////////////// -// // -// QA of black events // -// // -// Author: // -// Sylwester Radomski (radomski@physi.uni-heidelberg.de) // -// // -//////////////////////////////////////////////////////////////////////////// - -#include "TH1D.h" -#include "TH2D.h" -#include "TH2S.h" -#include "TH3F.h" -#include "TF1.h" -#include "TFile.h" -#include "TCanvas.h" -#include "TPad.h" -#include "TLatex.h" -#include "TStyle.h" -#include "TGraph.h" - -#include "AliLog.h" - -#include "AliTRDgeometry.h" -#include "AliTRDrawStreamTB.h" -#include "AliTRDqaBlackEvents.h" - -ClassImp(AliTRDqaBlackEvents) - -/////////////////////////////////////////////////////////////////////////////////////////////////// - -AliTRDqaBlackEvents::AliTRDqaBlackEvents() - :TObject() - ,fnEvents(0) - ,fCreateFull(0) - ,fThresh(0) - ,fCount(0) - ,fOccupancy(0) - ,fDetRob(0) - ,fTBEvent(0) - ,fRefHistPed(0) - ,fRefHistNoise(0) - ,fErrorHC(0) - ,fErrorMCM(0) - ,fErrorADC(0) - ,fErrorSMHC(0) - ,fErrorSMMCM(0) - ,fErrorSMADC(0) - ,fErrorGraphHC(0) - ,fErrorGraphMCM(0) - ,fErrorGraphADC(0) - ,fGraphMCM(0) - ,fMcmTracks(0) - ,fMapMCM(0) - ,fFracMCM(0) - ,fSMHCped(0) - ,fSMHCerr(0) - ,fNoiseTotal(0) - ,fPP(0) - ,fMinNoise(0.5) - ,fMaxNoise(2) - ,fFitType(0) - // ,fRefFileName("") -{ - // - // Constructor - // to create the histograms call Init() - // - - strcpy(fRefFileName, ""); -} - -/////////////////////////////////////////////////////////////////////////////////////////////////// - -AliTRDqaBlackEvents::AliTRDqaBlackEvents(const AliTRDqaBlackEvents &qa) - :TObject(qa) - ,fnEvents(0) - ,fCreateFull(0) - ,fThresh(0) - ,fCount(0) - ,fOccupancy(0) - ,fDetRob(0) - ,fTBEvent(0) - ,fRefHistPed(0) - ,fRefHistNoise(0) - ,fErrorHC(0) - ,fErrorMCM(0) - ,fErrorADC(0) - ,fErrorSMHC(0) - ,fErrorSMMCM(0) - ,fErrorSMADC(0) - ,fErrorGraphHC(0) - ,fErrorGraphMCM(0) - ,fErrorGraphADC(0) - ,fGraphMCM(0) - ,fMcmTracks(0) - ,fMapMCM(0) - ,fFracMCM(0) - ,fSMHCped(0) - ,fSMHCerr(0) - ,fNoiseTotal(0) - ,fPP(0) - ,fMinNoise(0.5) - ,fMaxNoise(2) - ,fFitType(0) - //,fRefFileName("") -{ - // - // Copy constructor - // to create the histograms call Init() - // - - strcpy(fRefFileName, ""); -} - -/////////////////////////////////////////////////////////////////////////////////////////////////// - -void AliTRDqaBlackEvents::Init() -{ - // - // creates histograms - // - - //TFile *file = new - //Info("Init", "Statring"); - - fnEvents = 0; - - // histograms for chambers - for(Int_t det=0; detGetHistogram()->SetTitle("Error HC;event number;fraction with error (%)"); - fErrorGraphMCM->GetHistogram()->SetTitle("Error MCM;event number;fraction with error (%)"); - fErrorGraphADC->GetHistogram()->SetTitle("Error ADC;event number;fraction with error (%)"); - - - fSMHCped = new TH2D("smHcPed", ";super module;half chamber", 18, -0.5, 17.5, 60, -0.5, 59.5); - //fSMHCerr = 0; - - //Info("Init", "Done"); - - // number of ADC channels fired per SM and in total - for(Int_t sm=0; smReset(); - fChPed[i]->Reset(); - fChNoise[i]->Reset(); - } -} - - -/////////////////////////////////////////////////////////////////////////////////////////////////// - -void AliTRDqaBlackEvents::SetRefFile(const char *filename) { - - strcpy(fRefFileName, filename); -} - -/////////////////////////////////////////////////////////////////////////////////////////////////// - -void AliTRDqaBlackEvents::ReadRefHists(Int_t det) { - - fRefHistPed = 0; - fRefHistNoise = 0; - - TFile *file = 0; - if (fRefFileName) TFile::Open(fRefFileName); - if (!file) return; - - fRefHistPed = (TH2D*)file->Get(Form("ped_%d",det)); - fRefHistNoise = (TH2D*)file->Get(Form("noise_%d", det)); - - if (file) file->Close(); -} - -/////////////////////////////////////////////////////////////////////////////////////////////////// - -Int_t AliTRDqaBlackEvents::AddEvent(AliTRDrawStreamTB *data) -{ - // - // Add an event - // - - // structure to keep track if particular chanel is used - Char_t isUsed[kDET][kCOL][kPAD]; - for(Int_t i=0; iReset(); - fFullCounter[i] = 0; - } - - Int_t nb = 0; - - Int_t lastdet = -1; - Int_t lastside = -1; - Int_t lastmcm = -1; - - Int_t rob_last = -1; - Int_t mcm_last = -1; - - Int_t nGoodHC = 0; - Int_t nGoodMCM = 0; - Int_t nGoodADC = 0; - - Int_t nErrorHC = 0; - Int_t nErrorMCM = 0; - Int_t nErrorADC = 0; - - - //Int_t adc_last = -1; - // Int_t sm_01 = -1; - - // number of ADCs per SM - Int_t nADCinSM[kSM+1]; - for(Int_t sm=0; smNext()) { - - Int_t sm = data->GetSM(); - Int_t layer = data->GetLayer(); - Int_t stack = data->GetStack(); - - Int_t det = data->GetDet(); - Int_t side = data->GetSide(); - - Int_t row = data->GetRow(); - Int_t col = data->GetCol(); - - Int_t rob = data->GetROB(); - Int_t mcm = data->GetMCM(); - Int_t adc = data->GetADC(); - - - Int_t *sig = data->GetSignals(); - nb++; - - nADCinSM[sm]++; - nADCinSM[kSM]++; - - // memory coruption protection - if (det<0 || det>=kDET) continue; - - // check errors - - // tests - //fErrorHC->Fill(data->GetHCErrorCode()); - if (data->GetMCMErrorCode() > 0) fErrorLocMCM[det]->Fill(row, col); - if (data->GetADCErrorCode() > 0) fErrorLocADC[det]->Fill(row, col); - - // new HC found - if ((det + side*kDET) != (lastdet + lastside*kDET)) { - Int_t code = data->GetHCErrorCode(); - // if (code) { - fErrorHC->Fill(code); - - if (code) fErrorSMHC->Fill(sm); - if (code) nErrorHC++; - nGoodHC++; - - //Int_t mask = 1; - //for(Int_t cc = 0; cc < 3; cc++) { - // if (code & mask) fErrorHC->Fill(cc); - // cc *= 2; - // } - //} - } - lastdet = det; - lastside = side; - - // new MCM found - if (mcm != lastmcm){ - Int_t code = data->GetMCMErrorCode(); - fErrorMCM->Fill(code); - - if (code) fErrorSMMCM->Fill(sm); - if (code) nErrorMCM++; - nGoodMCM++; - } - lastmcm = mcm; - - // new ADC channel found - Int_t code = data->GetADCErrorCode(); - fErrorADC->Fill(code); - if (code) fErrorSMADC->Fill(sm); - if (code) nErrorADC++; - nGoodADC++; - - // end of error checking - - // check the ROBs - fDetRob->Fill(det, rob, 1./(kMCM*18)); - isUsed[det][row][col]++; - - // check if mcm signal is continuus - if ((rob_last != rob) || (mcm_last != mcm)) { - rob_last = rob; - mcm_last = mcm; - fnEntriesRM[det]->Fill(rob,mcm); - } - - // number of entries for each channels - fNPoint[det]->Fill(row, col); - - - // create a structure for an MCM if needed - Int_t mcmIndex = det * (kMCM * kROB) + rob * kMCM + mcm; - if (fCreateFull && !fFullSignal[mcmIndex]) - fFullSignal[mcmIndex] = new TH2S(Form("mcm_%d_%d_%d_%d_%d", sm, stack, layer, rob, mcm), - Form("mcm-%d-%d-%d-%d-%d;ADC;time bin", sm, stack, layer, rob, mcm), - 21, -0.5, 20.5, 30, -0.5, 29.5); - - - // loop over Time Bins and fill histograms - Int_t minV = 1024; - Int_t maxV = 0; - - for(Int_t k=0; kGetADCErrorCode() > 0) continue; - - //if (col == 0 || col == 143) - //AliInfo(Form("TB: %d %d %d\n", row, col, sig[k])); - - //if (sig[k] < 1) - //AliInfo(Form("det = %d rob = %d mcm = %d adc = %d k = %d S = %d\n", det, rob, mcm, adc, k, sig[k])); - - fSignal[det]->Fill(sig[k]); - fData[det]->Fill(row, col, sig[k]); - - minV = (minV < sig[k]) ? minV : sig[k]; - maxV = (maxV > sig[k]) ? maxV : sig[k]; - - - // check if data strange enought - if (fCreateFull && fFullSignal[mcmIndex]) { - //if (sm == 17 && ) - //if (det != 29) { - if (sig[k] > fThresh || sig[k] < 1) fFullCounter[mcmIndex]++; - //if (sig[k] < 1) fFullCounter[mcmIndex] = 0; // remove austrian flag - //} - fFullSignal[mcmIndex]->Fill(adc, k, sig[k]); - } - - // noisy chamber - if (det == 29 && col > 7) { - fTBEvent->Fill(fnEvents, k, sig[k]); - } - } - - fPP->Fill(maxV-minV); - fChPP[det]->Fill(maxV-minV); - fSmPP[sm]->Fill(maxV-minV); - } - - // is the dead-alive status changing during the run - for(Int_t i=0; iFill(isUsed[i][j][k]); - } - - // save interesting histos - Int_t mcmTrackCandidate = 0; - for(Int_t i = 0; i < kDET * kROB * kMCM; i++) { - if (fFullCounter[i] && fFullSignal[i] && CheckMCM(i) ) { - - fMcmTracks->AddLast(fFullSignal[i]->Clone(Form("event_%d_%s", fnEvents, fFullSignal[i]->GetName()))); - mcmTrackCandidate++; - - Int_t mcmTrackletDet = i/(kROB * kMCM); - Int_t mcmTrackletMcm = i%(kROB * kMCM); - fMapMCM->Fill(mcmTrackletDet, mcmTrackletMcm); - } - } - - fGraphMCM->SetPoint(fnEvents, fnEvents, mcmTrackCandidate); - AliInfo(Form("Number of MCM track candidates = %d\n", mcmTrackCandidate)); - - - // update fraction of error graphs - Double_t err; - - err = (nGoodHC > 0)? 100.*nErrorHC/nGoodHC : -1; - fErrorGraphHC->SetPoint(fnEvents, fnEvents, err); - - err = (nGoodMCM > 0)? 100.*nErrorMCM/nGoodMCM : -1; - fErrorGraphMCM->SetPoint(fnEvents, fnEvents, err); - - err = (nGoodADC > 0)? 100.*nErrorADC/nGoodADC : -1; - fErrorGraphADC->SetPoint(fnEvents, fnEvents, err); - - // number of fired ADC per SM - for(Int_t sm=0; smSetPoint(fnEvents, fnEvents, nADCinSM[sm]); - - - fnEvents++; - return nb; -} - -/////////////////////////////////////////////////////////////////////////////////////////////////// - -void AliTRDqaBlackEvents::Process(const char *filename) -{ - // - // Process something - // - - char fn[256]; - strcpy(fn, filename); - - //AliInfo(Form("FILENAME = %s (%s)\n", filename, fn)); - - Int_t map[kDET]; - - TH1D *hist = new TH1D("fitSignal", "", 50, -0.5, 49.5); - TF1 *fit = new TF1("fit", "gaus(0)", 0, 20); - fit->SetParameters(1e3, 10, 1); - - for(Int_t det=0; detGetSum() < 10) continue; - map[det] = 1; - - // read reference distributions - ReadRefHists(det); - - for(Int_t row=0; rowGetXaxis()->GetNbins(); row++) { - for(Int_t pad=0; padGetYaxis()->GetNbins(); pad++) { - - // project the histogramm - hist->Reset(); - for(Int_t bb=0; bb<50; bb++) { - Int_t dataBin = fData[det]->FindBin(row, pad, bb); - Double_t v = fData[det]->GetBinContent(dataBin); - hist->SetBinContent(bb+1, v); - } - - Int_t bin = fChPed[det]->FindBin(row, pad); - - if (hist->GetSum() > 1) { - - Double_t ped = 0, noise = 0; - - if (fFitType == 0) { - fit->SetParameters(1e3, 10, 1); - hist->Fit(fit, "q0", "goff", 0, 20); - TF1 *f = hist->GetFunction("fit"); - ped = TMath::Abs(f->GetParameter(1)); - noise = TMath::Abs(f->GetParameter(2)); - fSmNoiseFit[det/30]->Fill(noise); - } else { - ped = hist->GetMean(); - noise = hist->GetRMS(); - fSmNoiseRms[det/30]->Fill(noise); - //if (pad == 0) - // AliInfo(Form("data %f %f %f\n", hist->GetSum(), ped, noise)); - } - - fChPed[det]->SetBinContent(bin, ped); - fChNoise[det]->SetBinContent(bin, noise); - fNoiseTotal->Fill(noise); - - // subtract reference values - Double_t refped = 0; - Double_t refnoise = 0; - - if (fRefHistPed) refped = fRefHistPed->GetBinContent(bin); - if (fRefHistNoise) refnoise = fRefHistPed->GetBinContent(bin); - - fChPedRes[det]->SetBinContent(bin, ped-refped); - fChNoiseRes[det]->SetBinContent(bin, noise-refnoise); - - fPed[det]->Fill(ped); - fNoise[det]->Fill(noise); - - // fill SM-HC plot - Int_t sm = det / 30; - Int_t hc = (pad < kPAD/2) ? 2* (det % 30) : 2* (det % 30) + 1; - if (ped > 9. && ped < 11) fSMHCped->Fill(sm, hc, 1./1152.); // number of pads in HC - - } else { - - // not enought data found - fChPed[det]->SetBinContent(bin, 0); - fChNoise[det]->SetBinContent(bin, 0); - fChPedRes[det]->SetBinContent(bin, 0); - fChNoiseRes[det]->SetBinContent(bin, 0); - } - - //delete hist; - } - } - } - - - //AliInfo(Form("Number of events = %d\n", fnEvents)); - - // normalize number of entries histos - Int_t max = 0; - for(Int_t i=0; iGetXaxis()->GetNbins(); j++) { - for(Int_t k=0; kGetYaxis()->GetNbins(); k++) { - Int_t dataBin = fNPoint[i]->FindBin(j, k); - Double_t v = fNPoint[i]->GetBinContent(dataBin); - if (v > max) max = (Int_t)v; - } - } - } - - char entriesDistName[100]; - - for(Int_t i=0; iGetXaxis()->GetNbins(); j++) { - for(Int_t k=0; kGetYaxis()->GetNbins(); k++) { - Int_t dataBin = fNPoint[i]->FindBin(j, k); - Double_t v = fNPoint[i]->GetBinContent(dataBin); - //if (v > fnEvents) AliInfo(Form("N = %d V = %lf\n", fnEvents, v)); - fNPointDist[i]->Fill(v); - } - } - - fNPoint[i]->Scale(1./fnEvents); - } - - - for(Int_t i=0; iSetMaximum(fnEvents * 1.5); - } - - // save histograms - - //AliInfo(Form("FILENAME 2 = %s (%d)\n", fn, fn)); - TFile *file = new TFile(fn, "recreate"); - for(Int_t det = 0; det < kDET; det++) { - if (!map[det]) continue; - fChPed[det]->Write(); - fChNoise[det]->Write(); - fNPoint[det]->Write(); - fNPointDist[det]->Write(); - fPed[det]->Write(); - fNoise[det]->Write(); - fSignal[det]->Write(); - fnEntriesRM[det]->Write(); - fChPP[det]->Write(); - - fChPedRes[det]->Write(); - fChNoiseRes[det]->Write(); - - // save error hists - fErrorLocMCM[det]->SetMinimum(0); - fErrorLocMCM[det]->SetMaximum(fnEvents); - fErrorLocMCM[det]->Write(); - - fErrorLocADC[det]->SetMinimum(0); - fErrorLocADC[det]->SetMaximum(fnEvents); - fErrorLocADC[det]->Write(); - } - - for(Int_t sm=0; smWrite(); - fSmNoiseFit[sm]->Write(); - fSmPP[sm]->Write(); - } - - - - Int_t nMcm = 0; - for(Int_t i=0; i < kDET * kROB * kMCM; i++) { - if (fFullSignal[i] && fFullCounter[i] > fCount) { - fFullSignal[i]->Write(); - nMcm++; - } - } - - AliInfo(Form("Number of saved MCMs = %d\n", nMcm)); - - fMcmTracks->Write(); - AliInfo(Form("Number of tracks = %d\n", fMcmTracks->GetEntries())); - - // permanently problematic MCMs - for(Int_t det=0; detFindBin(det, mcm); - Double_t frac = 1. * fMapMCM->GetBinContent(bin) / fnEvents; - fFracMCM->Fill(frac); - - if (frac > 0.7) { - AliInfo(Form("{%d, %d, %d, %f}, \n", det, mRob, mMcm, frac)); - } - } - } - - - - fOccupancy->Write(); - fDetRob->Write(); - fTBEvent->Write(); - - // error hists - fErrorHC->Write(); - fErrorMCM->Write(); - fErrorADC->Write(); - - fErrorSMHC->Write(); - fErrorSMMCM->Write(); - fErrorSMADC->Write(); - - // write graphs - fErrorGraphHC->Write("trendErrorHC"); - fErrorGraphMCM->Write("trendErrorMCM"); - fErrorGraphADC->Write("trendErrorADC"); - - fGraphMCM->Write("trendMCM"); - - fMapMCM->SetMaximum(fnEvents); - fMapMCM->Write(); - fFracMCM->Write(); - - fSMHCped->Write(); - - for(Int_t sm=0; smWrite(Form("nADCinSM%d",sm)); - - fNumberADC[kSM]->Write("nADCinEvent"); - - fNoiseTotal->Write(); - fPP->Write(); - - file->Close(); - delete file; -} - -/////////////////////////////////////////////////////////////////////////////////////////////////// - -Int_t AliTRDqaBlackEvents::CheckMCM(Int_t index) { - - return 1; - - static Int_t data[21][3] = { - {1, 0, 1}, - {242, 0, 0}, - {242, 0, 1}, - {242, 0, 2}, - {242, 0, 4}, - {242, 0, 5}, - {242, 0, 6}, - {242, 0, 8}, - {242, 0, 12}, - {251, 7, 7}, - {254, 3, 11}, - {259, 3, 14}, - {260, 1, 9}, - {260, 3, 15}, - {273, 1, 7}, - {273, 1, 15}, - {276, 5, 11}, - {280, 6, 2}, - {299, 6, 4}, - {511, 2, 9}, - {517, 7, 15} - }; - - for(Int_t i=0; i<21; i++) { - Int_t wIndex = data[i][0] * kROB*kMCM + data[i][1] * kMCM + data[i][2]; - if (index == wIndex) return 0; - } - - return 1; -} - -/////////////////////////////////////////////////////////////////////////////////////////////////// - - - - - - - -void AliTRDqaBlackEvents::DrawChamber(const char *filename, Int_t det, Int_t w, Int_t h) -{ - // - // Draw raport for one chamber: - // pedestal map, noise map, distribution of pedestal and noise - // - // input: - // name of the file with histograms (created with Process()) - // detector Id (0 - 539) - // - - // setup global style - gStyle->SetPalette(1); - gStyle->SetOptStat(0); - gStyle->SetPadTopMargin(0.02); - gStyle->SetPadBottomMargin(0.05); - - TFile *file = new TFile(filename, "READ"); - - TCanvas *c = new TCanvas("blackEvents",Form("blackEvents %d",det), w, h); - c->SetVertical(kFALSE); - c->Divide(3,1, 0.01, 0.01); - c->cd(3); - - TPad *mPad = (TPad*) gPad; - mPad->Divide(1,2,0.01,0.01); - - c->cd(1); - TH2D *h2 = (TH2D*)file->Get(Form("ped_%d",det)); - h2->SetMinimum(5); - h2->SetMaximum(15); - h2->SetTitle(";Z direction;#phi direction"); - h2->Draw("colz"); - - c->cd(2); - h2 = (TH2D*)file->Get(Form("noise_%d",det)); - h2->SetMinimum(fMinNoise); - h2->SetMaximum(fMaxNoise); - h2->SetTitle(";Z direction;#phi direction"); - h2->Draw("colz"); - - mPad->cd(1); - //gPad->SetLogy(); - TH1D *h1 = (TH1D*)file->Get(Form("pedDist_%d", det)); - h1->Draw(); - - mPad->cd(2); - gPad->SetLogy(); - h1 = (TH1D*)file->Get(Form("noiseDist_%d", det)); - h1->Draw(); - - h1->Fit("gaus"); - TF1 *f = h1->GetFunction("gaus"); - const char *tt = Form("#mu = %.2f #sigma = %0.2f ", f->GetParameter(1),f->GetParameter(2)); - TLatex *ll = new TLatex(2, 100, tt); - ll->SetTextSize(0.06); - ll->Draw(); -} - -/////////////////////////////////////////////////////////////////////////////////////////////////// - -void AliTRDqaBlackEvents::DrawSm(const char *filename, Int_t sm, Int_t w, Int_t h) -{ - // - // ???????????? - // - - gStyle->SetPalette(1); - gStyle->SetOptStat(0); - - gStyle->SetPadTopMargin(0.02); - //gStyle->SetPadBottomMargin(0.05); - //gStyle->SetPadLeftMargin(0.02); - //gStyle->SetPadRightMargin(0.02); - - TFile *file = new TFile(filename, "READ"); - - TCanvas *c = new TCanvas("blackEventsSM",Form("blackEvents SM %d",sm), w, h); - c->SetVertical(kFALSE); - c->Divide(5, 6, 0.001, 0.01); - - for(Int_t i=0; i<30; i++) { - - TH2D *h2 = (TH2D*)file->Get(Form("noise_%d",i+30*sm)); - if (!h2) continue; - h2->SetMinimum(fMinNoise); - h2->SetMaximum(fMaxNoise); - - // to be replaced by the official calculation - Int_t stack = i/6; - Int_t layer = i%6; - Int_t index = (5-layer)*5 + stack + 1; - //AliInfo(Form("%d %d %d %d\n", i, stack, layer, index)); - c->cd(index); - gPad->SetBottomMargin(0.02); - gPad->SetTopMargin(0.02); - - h2->Draw("col"); - } -} - -/////////////////////////////////////////////////////////////////////////////////////////////////// +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * withount fee, provided thats the abov copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is without express or implied warranty. * + **************************************************************************/ + +/* $Id: AliTRDqaBlackEvents.cxx 23387 2008-01-17 17:25:16Z cblume $ */ + +//////////////////////////////////////////////////////////////////////////// +// // +// QA of black events // +// // +// Author: // +// Sylwester Radomski (radomski@physi.uni-heidelberg.de) // +// // +//////////////////////////////////////////////////////////////////////////// + +#include "TH1D.h" +#include "TH2D.h" +#include "TH2S.h" +#include "TH3F.h" +#include "TF1.h" +#include "TFile.h" +#include "TCanvas.h" +#include "TPad.h" +#include "TLatex.h" +#include "TStyle.h" +#include "TGraph.h" + +#include "AliLog.h" + +#include "AliTRDgeometry.h" +#include "AliTRDrawStreamTB.h" +#include "AliTRDqaBlackEvents.h" + +#include "AliRawReader.h" + + +ClassImp(AliTRDqaBlackEvents) + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +AliTRDqaBlackEvents::AliTRDqaBlackEvents() + :TObject() + ,fnEvents(0) + ,fCreateFull(0) + ,fThresh(0) + ,fCount(0) + ,fRefEv(0) + ,fOccupancy(0) + ,fDetRob(0) + ,fTBEvent(0) + ,fRefHistPed(0) + ,fRefHistNoise(0) + ,fErrorHC(0) + ,fErrorMCM(0) + ,fErrorADC(0) + ,fErrorSMHC(0) + ,fErrorSMMCM(0) + ,fErrorSMADC(0) + ,fErrorGraphHC(0) + ,fErrorGraphMCM(0) + ,fErrorGraphADC(0) + ,fGraphMCM(0) + ,fMcmTracks(0) + ,fMapMCM(0) + ,fFracMCM(0) + ,fSMHCped(0) + ,fSMHCerr(0) + ,fNoiseTotal(0) + ,fPP(0) + ,fMinNoise(0.5) + ,fMaxNoise(2) + ,fFitType(0) + // ,fRefFileName("") +{ + // + // Constructor + // to create the histograms call Init() + // + + strcpy(fRefFileName, ""); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +AliTRDqaBlackEvents::AliTRDqaBlackEvents(const AliTRDqaBlackEvents &qa) + :TObject(qa) + ,fnEvents(0) + ,fCreateFull(0) + ,fThresh(0) + ,fCount(0) + ,fRefEv(0) + ,fOccupancy(0) + ,fDetRob(0) + ,fTBEvent(0) + ,fRefHistPed(0) + ,fRefHistNoise(0) + ,fErrorHC(0) + ,fErrorMCM(0) + ,fErrorADC(0) + ,fErrorSMHC(0) + ,fErrorSMMCM(0) + ,fErrorSMADC(0) + ,fErrorGraphHC(0) + ,fErrorGraphMCM(0) + ,fErrorGraphADC(0) + ,fGraphMCM(0) + ,fMcmTracks(0) + ,fMapMCM(0) + ,fFracMCM(0) + ,fSMHCped(0) + ,fSMHCerr(0) + ,fNoiseTotal(0) + ,fPP(0) + ,fMinNoise(0.5) + ,fMaxNoise(2) + ,fFitType(0) + //,fRefFileName("") +{ + // + // Copy constructor + // to create the histograms call Init() + // + + strcpy(fRefFileName, ""); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +void AliTRDqaBlackEvents::Init() +{ + // + // creates histograms + // + + //TFile *file = new + //Info("Init", "Statring"); + + fnEvents = 0; + + // histograms for chambers + for(Int_t det=0; detGetHistogram()->SetTitle("fraction of events with HC error;event number"); + fErrorGraphMCM->GetHistogram()->SetTitle("fraction of events with MCM error;event number;"); + fErrorGraphADC->GetHistogram()->SetTitle("fraction of events with ADC error;event number;"); + + + fSMHCped = new TH2D("smHcPed", ";super module;half chamber", 18, -0.5, 17.5, 60, -0.5, 59.5); + + // link monitor + const char *linkName[3] = {"smLink", "smBeaf", "smData"}; + const char *linkGrName[3] = {"grSmLink", "grSmBeaf", "grSmData"}; + for(Int_t i=0; i<3; i++) { + fSMLink[i] = new TH2D(linkName[i], ";super module;link", 18, -0.5, 17.5, 60, -0.5, 59.5); + fGrLink[i] = new TGraph(); + fGrLink[i]->SetName(linkGrName[i]); + } + + //fZSsize = new TH1D("zssizeSingle", ";threshold;nADC", 40, -0.5, 39.5); + + + //Info("Init", "Done"); + + // number of ADC channels fired per SM and in total + for(Int_t sm=0; smReset(); + fChPed[i]->Reset(); + fChNoise[i]->Reset(); + } +} + + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +void AliTRDqaBlackEvents::SetRefFile(const char *filename) { + + strcpy(fRefFileName, filename); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +void AliTRDqaBlackEvents::ReadRefHists(Int_t det) { + + fRefHistPed = 0; + fRefHistNoise = 0; + + TFile *file = 0; + if (fRefFileName) TFile::Open(fRefFileName); + if (!file) return; + + fRefHistPed = (TH2D*)file->Get(Form("ped_%d",det)); + fRefHistNoise = (TH2D*)file->Get(Form("noise_%d", det)); + + if (file) file->Close(); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +void AliTRDqaBlackEvents::StartEvent() +{ + // + // start an event + // + + // clear the mcm data + for(Int_t i=0; i < kDET * kROB * kMCM; i++) { + if (fFullSignal[i]) fFullSignal[i]->Reset(); + fFullCounter[i] = 0; + } + + for(Int_t i=0; i<2; i++) { + fnErrorHC[i] = 0; + fnErrorMCM[i] = 0; + fnErrorADC[i] = 0; + } + + + Int_t ppThresh[3] = {10, 20, 40}; + for(Int_t i=0; i<3; i++) { + fppThresh[i] = ppThresh[i]; + fnPP[i] = 0; + fnLink[i] = 0; + } + + for(Int_t sm=0; sm 0) fRefEv++; + fEvNoDist[999]->Reset(); // keep only the last event + +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +void AliTRDqaBlackEvents::AddBuffer(AliTRDrawStreamTB *data, AliRawReader *reader) +{ + + //printf ("try to read data\n"); + Int_t nextBuff = data->NextBuffer(); + //printf("done ...\n"); + + if (nextBuff == 0) return; + + Int_t sm = reader->GetEquipmentId() - 1024; + //printf("reading SM %d\n", sm); + AliInfo(Form("reading SM %d", sm)); + + if (sm < 0 || sm > 18) return; + + // lopp over stacks, links ... + + for (Int_t istack = 0; istack < 5; istack++) { + for (Int_t ilink = 0; ilink < 12; ilink++) { + + //printf("HC = %d %d\n", istack, ilink); + + Int_t det = sm * 30 + istack * 6 + ilink/2; + + // check if data delivered + if (!(data->IsLinkActiveInStack(istack, ilink))) continue; + fSMLink[0]->Fill(sm, istack * 12 + ilink); + fnLink[0]++; + + // check if beaf-beaf + if (data->GetLinkMonitorError(istack, ilink)) { + fSMLink[1]->Fill(sm, istack * 12 + ilink); + fnLink[1]++; + continue; + } + + // fill histogram with HC header errors + Int_t nErrHc = 0; + Int_t nErrHcTot = 0; + + nErrHc = FillBits(fErrorHC, data->GetH0ErrorCode(istack, ilink), 0); + if (!nErrHc) fErrorHC->Fill(-3); + nErrHcTot += nErrHc; + + nErrHc = FillBits(fErrorHC, data->GetH1ErrorCode(istack, ilink), 2); + if (!nErrHc) fErrorHC->Fill(-2); + nErrHcTot += nErrHc; + + nErrHc = FillBits(fErrorHC, data->GetHCErrorCode(istack, ilink), 4); + if (!nErrHc) fErrorHC->Fill(-1); + nErrHcTot += nErrHc; + + // trending + fnErrorHC[0]++; + if (nErrHcTot > 0) { + fnErrorHC[1]++; + fErrorSMHC->Fill(sm); + } + + // data integrity protection + + //if (data->GetHCErrorCode(istack, ilink) > 0) continue; + if (data->GetH0ErrorCode(istack, ilink) > 0) continue; + if (data->GetH1ErrorCode(istack, ilink) > 0) continue; + + fSMLink[2]->Fill(sm, istack * 12 + ilink); + fnLink[2]++; + + + for (Int_t imcm = 0; imcm < data->GetHCMCMmax(istack, ilink); imcm++ ){ + + //printf("mcm = %d %d %d\n", istack, ilink, imcm); + + // fill MCM error code + + Int_t nErrMcm = 0; + Int_t nErrMcmTot = 0; + + nErrMcm = FillBits(fErrorMCM, data->GetMCMhdErrorCode(istack, ilink, imcm), 0); + if (!nErrMcm) fErrorMCM->Fill(-3); + nErrMcmTot += nErrMcm; + + nErrMcm = FillBits(fErrorMCM, data->GetMCMADCMaskErrorCode(istack, ilink, imcm), 5); + if (!nErrMcm) fErrorMCM->Fill(-2); + nErrMcmTot += nErrMcm; + + nErrMcm = FillBits(fErrorMCM, data->GetMCMErrorCode(istack, ilink, imcm), 10); + if (!nErrMcm) fErrorMCM->Fill(-1); + nErrMcmTot += nErrMcm; + + // trending + fnErrorMCM[0]++; + if (nErrMcmTot > 0) { + fnErrorMCM[1]++; + fErrorSMMCM->Fill(sm); + } + + // MCM protection + if ( (data->GetMCMhdErrorCode(istack,ilink,imcm)) & 2 ) continue; + //if ((data->GetMCMADCMaskErrorCode(istack,ilink,imcm))) continue; + //if ((data->GetMCMErrorCode(istack,ilink,imcm))) continue; + + Int_t mcmEvent = data->GetEventNumber(istack, ilink, imcm); + + // set the reference event number + if (fRefEv < 0) { + fRefEv = mcmEvent; + printf("Reference Event Number = %d (%d %d %d)\n", fRefEv, istack, ilink, imcm); + } + + // fill event distribution + if (!(fnEvents%10)) { + fEvNoDist[fnEvents/10]->Fill(mcmEvent - fRefEv); + } + + fEvNoDist[999]->Fill(mcmEvent - fRefEv); + + Int_t mcm = data->GetMCM(istack, ilink, imcm); + Int_t rob = data->GetROB(istack, ilink, imcm); + + // create a structure for an MCM if needed + Int_t mcmIndex = det * (kMCM * kROB) + rob * kMCM + mcm; + if (fCreateFull && !fFullSignal[mcmIndex]) + fFullSignal[mcmIndex] = + new TH2S(Form("mcm_%d_%d_%d_%d_%d", sm, istack, ilink/2, rob, mcm), + Form("mcm-%d-%d-%d-%d-%d;ADC;time bin", sm, istack, ilink/2, rob, mcm), + 21, -0.5, 20.5, 30, -0.5, 29.5); + + + //Int_t zsADC[21][40]; + /* + for(Int_t ina=0; ina<21; ina++) + for(Int_t th=0; th<40; th++) + zsADC[ina][th] = 0; + */ + + // first loop over ADC chanels + + for (Int_t iadc=0; iadc < data->GetADCcount(istack, ilink, imcm); iadc++) { + + //printf("ADC = %d\n", iadc); + + + // fill ADC error bits + Int_t nErrAdc = FillBits(fErrorADC, data->GetADCErrorCode(), 0); + if (!nErrAdc) fErrorADC->Fill(-1); + + fnErrorADC[0]++; + if (nErrAdc > 0) { + fnErrorADC[1]++; + fErrorSMADC->Fill(sm); + } + + // ADC protection + if ((data->GetADCErrorCode(istack,ilink,imcm,iadc))) continue; + + Int_t minV = 1024; + Int_t maxV = 0; + + Int_t *sig = data->GetSignalDirect(istack, ilink, imcm, iadc); + + //Int_t adc = data->GetADCnumber(istack, ilink, imcm, iadc); + Int_t row = data->GetRow(istack, ilink, imcm); + Int_t col = data->GetCol(istack, ilink, imcm, iadc); + + // loop over Time Bins and fill histograms + for(Int_t k=0; k < data->GetNumberOfTimeBins(istack, ilink); k++) { + + //fSignal[det]->Fill(sig[k]); + //fData[det]->Fill(row, col, sig[k]); // slow + + if (sig[k] < kCH) { + fSignalDirect[det][sig[k]]++; + fDataDirect[det][row][col][sig[k]]++; // direct data + } + + // peak-peak + minV = (minV < sig[k]) ? minV : sig[k]; + maxV = (maxV > sig[k]) ? maxV : sig[k]; + + // check for active MCMs + if (fCreateFull && fFullSignal[mcmIndex]) { + if (sig[k] > fThresh || sig[k] < 0) fFullCounter[mcmIndex]++; + //if (sm == 0 && istack == 0 && ilink/2 == 1 && rob == 1 && mcm == 15) fFullCounter[mcmIndex]++; // special + //fFullSignal[mcmIndex]->Fill(adc, k, sig[k]); // slow + } + + // zero suppresion tests + /* + for(Int_t th=0; th<40; th++) { + if (sig[k] > th) { + zsADC[iadc][th] = 1; + if (iadc > 0) zsADC[iadc-1][th] = 1; + if (iadc < 10) zsADC[iadc+1][th] = 1; + } + } + */ + + } // tb + + if (maxV > 0) { + fnADCinSM[sm]++; + fnADCinSM[kSM]++; + } + + Int_t adcPP = maxV - minV; + //if (adcPP == 100) fFullCounter[mcmIndex] += 10; + + fPP->Fill(adcPP); + fChPP[det]->Fill(adcPP); + fSmPP[sm]->Fill(adcPP); + + for(Int_t i=0; i<3; i++) { + if ((adcPP) > fppThresh[i]) fnPP[i]++; + } + + + } // adc + + // fill ZS histos + /* + for(Int_t th=0; th<40; th++) { + Int_t nnADC = 0; + for(Int_t ins=0; ins<21; ins++) + nnADC += zsADC[ins][th]; + fZSsize->Fill(th, nnADC); + } + */ + + // fill active MCMs + + if (fCreateFull && fFullSignal[mcmIndex] && (fFullCounter[mcmIndex] > fCount)) { + + for (Int_t iadc=0; iadc < data->GetADCcount(istack, ilink, imcm); iadc++) { + + // ADC protection + if ((data->GetADCErrorCode(istack,ilink,imcm,iadc))) continue; + + //Int_t row = data->GetRow(istack, ilink, imcm); + //Int_t col = data->GetCol(istack, ilink, imcm, iadc); + Int_t adc = data->GetADCnumber(istack, ilink, imcm, iadc); + + Int_t *sig = data->GetSignalDirect(istack, ilink, imcm, iadc); + + // loop over Time Bins and fill histograms + for(Int_t k=0; k < data->GetNumberOfTimeBins(istack, ilink); k++) { + fFullSignal[mcmIndex]->Fill(adc, k, sig[k]); // slow + } + } // tb + } + + } // mcm + } // link + } // stack + + // printf("end of loops\n"); +} + + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +void AliTRDqaBlackEvents::FinishEvent() +{ + + for(Int_t i=0; i<3; i++) { + fGraphPP[i]->SetPoint(fnEvents, fnEvents, fnPP[i]); + } + + // trend of the number of links + for(Int_t i=0; i<3; i++) { + fGrLink[i]->SetPoint(fnEvents, fnEvents, fnLink[i]); + } + + // save interesting histos + Int_t mcmTrackCandidate = 0; + for(Int_t i = 0; i < kDET * kROB * kMCM; i++) { + if ((fFullCounter[i] > fCount) && fFullSignal[i] && CheckMCM(i) ) { + + fMcmTracks->AddLast(fFullSignal[i]->Clone(Form("event_%d_%s", fnEvents, fFullSignal[i]->GetName()))); + mcmTrackCandidate++; + + Int_t mcmTrackletDet = i/(kROB * kMCM); + Int_t mcmTrackletMcm = i%(kROB * kMCM); + fMapMCM->Fill(mcmTrackletDet, mcmTrackletMcm); + } + } + + fGraphMCM->SetPoint(fnEvents, fnEvents, mcmTrackCandidate); + AliInfo(Form("Number of MCM track candidates = %d\n", mcmTrackCandidate)); + + + // update fraction of error graphs + Double_t err; + + err = (fnErrorHC[0] > 0)? 100.*fnErrorHC[1]/fnErrorHC[0] : -1; + fErrorGraphHC->SetPoint(fnEvents, fnEvents, err); + + err = (fnErrorMCM[0] > 0)? 100.*fnErrorMCM[1]/fnErrorMCM[0] : -1; + fErrorGraphMCM->SetPoint(fnEvents, fnEvents, err); + + err = (fnErrorADC[0] > 0)? 100.*fnErrorADC[1]/fnErrorADC[0] : -1; + fErrorGraphADC->SetPoint(fnEvents, fnEvents, err); + + // number of fired ADC per SM + for(Int_t sm=0; smSetPoint(fnEvents, fnEvents, fnADCinSM[sm]); + + fnEvents++; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +void AliTRDqaBlackEvents::Process(const char *filename) +{ + // + // Process something + // + + char fn[256]; + strcpy(fn, filename); + + //AliInfo(Form("FILENAME = %s (%s)\n", filename, fn)); + + Int_t map[kDET]; + + TH1D *hist = new TH1D("fitSignal", "", 50, -0.5, 49.5); + TF1 *fit = new TF1("fit", "gaus(0)", 0, 20); + fit->SetParameters(1e3, 10, 1); + + for(Int_t det=0; detGetSum() < 10) continue; + //if (fDataDirect[det][10][10][10] < 20) continue; + //map[det] = 1; + + + // rewrite signal-direct + for(Int_t ch=0; chFill(ch, fSignalDirect[det][ch]); + } + + // read reference distributions + ReadRefHists(det); + + //for(Int_t row=0; rowGetXaxis()->GetNbins(); row++) { + //for(Int_t pad=0; padGetYaxis()->GetNbins(); pad++) { + + for(Int_t row=0; rowReset(); + //for(Int_t bb=0; bb<50; bb++) { + for(Int_t bb=0; bbFindBin(row, pad, bb); + //Double_t v = fData[det]->GetBinContent(dataBin); + hist->SetBinContent(bb+1, fDataDirect[det][row][pad][bb]); + } + + Int_t bin = fChPed[det]->FindBin(row, pad); + + if (hist->GetSum() > 1) { + + map[det] = 1; + Double_t ped = 0, noise = 0; + + if (fFitType == 0) { + fit->SetParameters(1e3, 10, 1); + hist->Fit(fit, "q0", "goff", 0, 20); + TF1 *f = hist->GetFunction("fit"); + ped = TMath::Abs(f->GetParameter(1)); + noise = TMath::Abs(f->GetParameter(2)); + fSmNoiseFit[det/30]->Fill(noise); + } else { + ped = hist->GetMean(); + noise = hist->GetRMS(); + fSmNoiseRms[det/30]->Fill(noise); + //if (pad == 0) + // AliInfo(Form("data %f %f %f\n", hist->GetSum(), ped, noise)); + } + + fChPed[det]->SetBinContent(bin, ped); + fChNoise[det]->SetBinContent(bin, noise); + fNoiseTotal->Fill(noise); + + // subtract reference values + Double_t refped = 0; + Double_t refnoise = 0; + + if (fRefHistPed) refped = fRefHistPed->GetBinContent(bin); + if (fRefHistNoise) refnoise = fRefHistPed->GetBinContent(bin); + + fChPedRes[det]->SetBinContent(bin, ped-refped); + fChNoiseRes[det]->SetBinContent(bin, noise-refnoise); + + fPed[det]->Fill(ped); + fNoise[det]->Fill(noise); + + // fill SM-HC plot + Int_t sm = det / 30; + Int_t hc = (pad < kPAD/2) ? 2* (det % 30) : 2* (det % 30) + 1; + if (ped > 9. && ped < 11) fSMHCped->Fill(sm, hc, 1./1152.); // number of pads in HC + + } else { + + // not enought data found + fChPed[det]->SetBinContent(bin, 0); + fChNoise[det]->SetBinContent(bin, 0); + fChPedRes[det]->SetBinContent(bin, 0); + fChNoiseRes[det]->SetBinContent(bin, 0); + } + + //delete hist; + } + } + } + + + //AliInfo(Form("Number of events = %d\n", fnEvents)); + + // normalize number of entries histos + Int_t max = 0; + for(Int_t i=0; iGetXaxis()->GetNbins(); j++) { + for(Int_t k=0; kGetYaxis()->GetNbins(); k++) { + Int_t dataBin = fNPoint[i]->FindBin(j, k); + Double_t v = fNPoint[i]->GetBinContent(dataBin); + if (v > max) max = (Int_t)v; + } + } + } + + char entriesDistName[100]; + + for(Int_t i=0; iGetXaxis()->GetNbins(); j++) { + for(Int_t k=0; kGetYaxis()->GetNbins(); k++) { + Int_t dataBin = fNPoint[i]->FindBin(j, k); + Double_t v = fNPoint[i]->GetBinContent(dataBin); + //if (v > fnEvents) AliInfo(Form("N = %d V = %lf\n", fnEvents, v)); + fNPointDist[i]->Fill(v); + } + } + + fNPoint[i]->Scale(1./fnEvents); + } + + + for(Int_t i=0; iSetMaximum(fnEvents * 1.5); + } + + // save histograms + + //AliInfo(Form("FILENAME 2 = %s (%d)\n", fn, fn)); + TFile *file = new TFile(fn, "recreate"); + for(Int_t det = 0; det < kDET; det++) { + if (!map[det]) continue; + fChPed[det]->Write(); + fChNoise[det]->Write(); + fNPoint[det]->Write(); + fNPointDist[det]->Write(); + fPed[det]->Write(); + fNoise[det]->Write(); + fSignal[det]->Write(); + fnEntriesRM[det]->Write(); + fChPP[det]->Write(); + + fChPedRes[det]->Write(); + fChNoiseRes[det]->Write(); + + // save error hists + fErrorLocMCM[det]->SetMinimum(0); + fErrorLocMCM[det]->SetMaximum(fnEvents); + fErrorLocMCM[det]->Write(); + + fErrorLocADC[det]->SetMinimum(0); + fErrorLocADC[det]->SetMaximum(fnEvents); + fErrorLocADC[det]->Write(); + } + + for(Int_t sm=0; smWrite(); + fSmNoiseFit[sm]->Write(); + fSmPP[sm]->Write(); + } + + + + Int_t nMcm = 0; + for(Int_t i=0; i < kDET * kROB * kMCM; i++) { + if (fFullSignal[i] && fFullCounter[i] > fCount) { + fFullSignal[i]->Write(); + nMcm++; + } + } + + AliInfo(Form("Number of saved MCMs = %d\n", nMcm)); + + fMcmTracks->Write(); + AliInfo(Form("Number of tracks = %d\n", fMcmTracks->GetEntries())); + + // permanently problematic MCMs + for(Int_t det=0; detFindBin(det, mcm); + Double_t frac = 1. * fMapMCM->GetBinContent(bin) / fnEvents; + fFracMCM->Fill(frac); + + if (frac > 0.7) { + AliInfo(Form("{%d, %d, %d, %f}, \n", det, mRob, mMcm, frac)); + } + } + } + + + fOccupancy->Write(); + fDetRob->Write(); + fTBEvent->Write(); + + // error hists + fErrorHC->Write(); + fErrorMCM->Write(); + fErrorADC->Write(); + + fErrorSMHC->Write(); + fErrorSMMCM->Write(); + fErrorSMADC->Write(); + + // write graphs + fErrorGraphHC->Write("trendErrorHC"); + fErrorGraphMCM->Write("trendErrorMCM"); + fErrorGraphADC->Write("trendErrorADC"); + + fGraphMCM->Write("trendMCM"); + + for(Int_t i=0; i<3; i++) { + fGraphPP[i]->Write(Form("fracPP_%d", i)); + } + + //fZSsize->Scale(1./fnEvents); + //fZSsize->Write(); + + fMapMCM->SetMaximum(fnEvents); + fMapMCM->Write(); + fFracMCM->Write(); + + fSMHCped->Write(); + + for(Int_t i=0; i<3; i++ ) { + fSMLink[i]->Write(); + fGrLink[i]->Write(); + } + + for(Int_t sm=0; smWrite(Form("nADCinSM%d",sm)); + + fNumberADC[kSM]->Write("nADCinEvent"); + + fNoiseTotal->Write(); + fPP->Write(); + + for(Int_t i=0; i<1000; i++) { + if (fEvNoDist[i]->GetSum() > 0) fEvNoDist[i]->Write(); + } + + + file->Close(); + delete file; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +Int_t AliTRDqaBlackEvents::CheckMCM(Int_t index) { + + return 1; + + static Int_t data[21][3] = { + {1, 0, 1}, + {242, 0, 0}, + {242, 0, 1}, + {242, 0, 2}, + {242, 0, 4}, + {242, 0, 5}, + {242, 0, 6}, + {242, 0, 8}, + {242, 0, 12}, + {251, 7, 7}, + {254, 3, 11}, + {259, 3, 14}, + {260, 1, 9}, + {260, 3, 15}, + {273, 1, 7}, + {273, 1, 15}, + {276, 5, 11}, + {280, 6, 2}, + {299, 6, 4}, + {511, 2, 9}, + {517, 7, 15} + }; + + for(Int_t i=0; i<21; i++) { + Int_t wIndex = data[i][0] * kROB*kMCM + data[i][1] * kMCM + data[i][2]; + if (index == wIndex) return 0; + } + + return 1; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// + + + + + + + +void AliTRDqaBlackEvents::DrawChamber(const char *filename, Int_t det, Int_t w, Int_t h) +{ + // + // Draw raport for one chamber: + // pedestal map, noise map, distribution of pedestal and noise + // + // input: + // name of the file with histograms (created with Process()) + // detector Id (0 - 539) + // + + // setup global style + gStyle->SetPalette(1); + gStyle->SetOptStat(0); + gStyle->SetPadTopMargin(0.02); + gStyle->SetPadBottomMargin(0.05); + + TFile *file = new TFile(filename, "READ"); + + TCanvas *c = new TCanvas("blackEvents",Form("blackEvents %d",det), w, h); + c->SetVertical(kFALSE); + c->Divide(3,1, 0.01, 0.01); + c->cd(3); + + TPad *mPad = (TPad*) gPad; + mPad->Divide(1,2,0.01,0.01); + + c->cd(1); + TH2D *h2 = (TH2D*)file->Get(Form("ped_%d",det)); + h2->SetMinimum(5); + h2->SetMaximum(15); + h2->SetTitle(";Z direction;#phi direction"); + h2->Draw("colz"); + + c->cd(2); + h2 = (TH2D*)file->Get(Form("noise_%d",det)); + h2->SetMinimum(fMinNoise); + h2->SetMaximum(fMaxNoise); + h2->SetTitle(";Z direction;#phi direction"); + h2->Draw("colz"); + + mPad->cd(1); + //gPad->SetLogy(); + TH1D *h1 = (TH1D*)file->Get(Form("pedDist_%d", det)); + h1->Draw(); + + mPad->cd(2); + gPad->SetLogy(); + h1 = (TH1D*)file->Get(Form("noiseDist_%d", det)); + h1->Draw(); + + h1->Fit("gaus"); + TF1 *f = h1->GetFunction("gaus"); + const char *tt = Form("#mu = %.2f #sigma = %0.2f ", f->GetParameter(1),f->GetParameter(2)); + TLatex *ll = new TLatex(2, 100, tt); + ll->SetTextSize(0.06); + ll->Draw(); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +void AliTRDqaBlackEvents::DrawSm(const char *filename, Int_t sm, Int_t w, Int_t h) +{ + // + // ???????????? + // + + gStyle->SetPalette(1); + gStyle->SetOptStat(0); + + gStyle->SetPadTopMargin(0.02); + //gStyle->SetPadBottomMargin(0.05); + //gStyle->SetPadLeftMargin(0.02); + //gStyle->SetPadRightMargin(0.02); + + TFile *file = new TFile(filename, "READ"); + + TCanvas *c = new TCanvas("blackEventsSM",Form("blackEvents SM %d",sm), w, h); + c->SetVertical(kFALSE); + c->Divide(5, 6, 0.001, 0.01); + + for(Int_t i=0; i<30; i++) { + + TH2D *h2 = (TH2D*)file->Get(Form("noise_%d",i+30*sm)); + if (!h2) continue; + h2->SetMinimum(fMinNoise); + h2->SetMaximum(fMaxNoise); + + // to be replaced by the official calculation + Int_t stack = i/6; + Int_t layer = i%6; + Int_t index = (5-layer)*5 + stack + 1; + //AliInfo(Form("%d %d %d %d\n", i, stack, layer, index)); + c->cd(index); + gPad->SetBottomMargin(0.02); + gPad->SetTopMargin(0.02); + + h2->Draw("col"); + } +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +Int_t AliTRDqaBlackEvents::FillBits(TH1D *hist, Int_t code, Int_t offset) { + + Int_t nb = 0; + UInt_t test = 1; + for(Int_t i=0; i<8; i++) { + if (code & test) { + hist->Fill(i+offset); + nb++; + } + test *= 2; + } + + return nb; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/TRD/AliTRDqaBlackEvents.h b/TRD/AliTRDqaBlackEvents.h index f663ac0b160..91d08b6bc08 100644 --- a/TRD/AliTRDqaBlackEvents.h +++ b/TRD/AliTRDqaBlackEvents.h @@ -23,6 +23,7 @@ class TH3F; class TGraph; class TObjArray; class AliTRDrawStreamTB; +class AliRawReader; class AliTRDqaBlackEvents : public TObject { @@ -35,7 +36,12 @@ class AliTRDqaBlackEvents : public TObject { void Init(); void Reset(); - Int_t AddEvent(AliTRDrawStreamTB *data); + //Int_t AddEvent(AliTRDrawStreamTB *data, AliRawReader *reader); + + void StartEvent(); + void AddBuffer(AliTRDrawStreamTB *data, AliRawReader *reader); + void FinishEvent(); + void Process(const char* filename); //TH2D *GetChamberPedestal(Int_t sm, Int_t layer, Int_t stack) {return 0;} @@ -66,6 +72,8 @@ class AliTRDqaBlackEvents : public TObject { Int_t fThresh; // threshold to analyze MCM data Int_t fCount; // minimum number of entries above threshold + Int_t fRefEv; // reference event number + Char_t fRefFileName[256]; // name of the file with reference distributions @@ -76,9 +84,10 @@ class AliTRDqaBlackEvents : public TObject { kMCM = 16, kADC = 21, kTB = 30, - kCOL = 16, + kROW = 16, kPAD = 144, - kSM = 18 + kSM = 18, + kCH = 50 }; // histograms per detector @@ -100,6 +109,10 @@ class AliTRDqaBlackEvents : public TObject { TH2D *fnEntriesRM[kDET]; // number of entries for ROB - MCM TH1D *fnEntriesRMDist[kDET]; // distribtion of number of entries per ROB-MCM + // direct access to data + Float_t fDataDirect[kDET][kROW][kPAD][kCH]; + Double_t fSignalDirect[kDET][kCH]; + // after reference subtraction TH2D *fChPedRes[kDET]; // histograms after reference subtraction TH2D *fChNoiseRes[kDET]; // histograms after reference subtraction @@ -131,6 +144,8 @@ class AliTRDqaBlackEvents : public TObject { TGraph *fErrorGraphADC; TGraph *fGraphMCM; // number of strange MCMs detected + TGraph *fGraphPP[3]; + // mcm trackles TObjArray *fMcmTracks; @@ -142,7 +157,12 @@ class AliTRDqaBlackEvents : public TObject { // full detector view TH2D *fSMHCped; TH2D *fSMHCerr; - + TH2D *fSMLink[3]; + TGraph *fGrLink[3]; + + //TH1D *fZSsize; + + // number of fired ADC channels in total and per SM TGraph *fNumberADC[kSM+1]; @@ -155,15 +175,33 @@ class AliTRDqaBlackEvents : public TObject { TH1D *fSmNoiseFit[kSM]; TH1D *fSmPP[kSM]; + + TH1D *fEvNoDist[1000]; + // Double_t fMinNoise; // Minimum noise Double_t fMaxNoise; // Maximum noise Int_t fFitType; + // variables keeping info in one event + Int_t fnErrorHC[2]; // 0 good, 1 error + Int_t fnErrorMCM[2]; // + Int_t fnErrorADC[2]; // + + Int_t fppThresh[3]; // thersholds for storing pp + Int_t fnPP[3]; // number of entries above the thershold + Int_t fnLink[3]; // links present, beaf-beaf, good + Int_t fnADCinSM[kSM+1]; // number of ADC channels in a SuperModule + // + + + // private function void ReadRefHists(Int_t det); Int_t CheckMCM(Int_t index); + Int_t FillBits(TH1D *hist, Int_t code, Int_t offset); + ClassDef(AliTRDqaBlackEvents,0) // QA for black events -- 2.39.3