void check_readout() { // TString sInputName = "/mnt/nas-herrmann2/cern-feb15/ratesMbs/unpack_rate_all.out.root"; TString sInputName = "/lustre/nyx/cbm/prod/beamtime/2015/02/cern/mbs_rates/unpack_rate_all.out.root"; Double_t dReadoutInterval = 0.67108864; /* // Mar041923 Double_t dStartTime = 1425493623; Double_t dStopTime = 1425496149; */ // Mar050041 Double_t dStartTime = 1425512400; Double_t dStopTime = 1425517500; const Int_t kiNBinsPerSecond = 10; const Int_t kiNCounters = 2; const Int_t kiScalerIndex[kiNCounters] = {6, 6}; const Int_t kiScalerBlockIndex[kiNCounters] = {1, 1}; const Int_t kiScalerBlockChannelIndex[kiNCounters] = {0, 1}; const TString ktCounterName[kiNCounters] = {"2-0-0", "2-1-0"}; const Double_t kdCounterArea[kiNCounters] = {16., 44.}; /* const Int_t kiNCounters = 2; const Int_t kiScalerIndex[kiNCounters] = {6, 6}; const Int_t kiScalerBlockIndex[kiNCounters] = {1, 1}; const Int_t kiScalerBlockChannelIndex[kiNCounters] = {2, 3}; const TString ktCounterName[kiNCounters] = {"2-2-0", "2-3-0"}; const Double_t kdCounterArea[kiNCounters] = {8., 8.}; */ const Int_t kiNbScalerBlocks = 3; const Int_t kiNbScalerBlockChannels = 64; const Int_t kiScaler = 1; const Bool_t kbCounterMode = kFALSE; // FIXME gStyle->SetOptStat(0); TFile * fInput = new TFile( sInputName, "READ"); TTree* tTree = (TTree*)fInput->Get("cbmsim"); if(!tTree) { cout<<"Output tree could not be retrieved from file. Abort macro execution."<GetBranch("TofTriglog"); if(!tBranchTrlo) { cout<<"Branch 'TofTriglog' not found in output tree. Abort macro execution."<GetBranch("TofCalibScaler"); if(!tBranch) { cout<<"Branch 'TofCalibScaler' not found in output tree. Abort macro execution."<SetAddress(&tArrayTrlo); TClonesArray* tArray = new TClonesArray("TTofCalibScaler"); tBranch->SetAddress(&tArray); TTofTriglogBoard* tTriglogBoard; TTofCalibScaler* tCalibScaler; TH1D* tScalerBlockRate[kiNbScalerBlocks][kiNbScalerBlockChannels]; TH1D* tCounterRate[kiNCounters]; TH1D* tCounterFlux[kiNCounters]; if(kbCounterMode) { for(Int_t iCounter = 0; iCounter < kiNCounters; iCounter++) { tCounterRate[iCounter] = new TH1D(Form("tCounterRate_%02d", iCounter), Form("%s; time in run [s]; counter rate [Hz]", ktCounterName[iCounter].Data()), kiNBinsPerSecond*static_cast(dStopTime - dStartTime), 0., dStopTime - dStartTime); tCounterFlux[iCounter] = new TH1D(Form("tCounterFlux_%02d", iCounter), Form("%s; time in run [s]; counter flux [Hz/cm^{2}]", ktCounterName[iCounter].Data()), kiNBinsPerSecond*static_cast(dStopTime - dStartTime), 0., dStopTime - dStartTime); } } else { for(Int_t iScalerBlock = 0; iScalerBlock < kiNbScalerBlocks; iScalerBlock++) { for(Int_t iScalerBlockChannel = 0; iScalerBlockChannel < kiNbScalerBlockChannels; iScalerBlockChannel++) { tScalerBlockRate[iScalerBlock][iScalerBlockChannel] = new TH1D(Form("tScalerBlockRate_%02d_%02d", iScalerBlock, iScalerBlockChannel), "; time in run [s]; channel rate [Hz]", kiNBinsPerSecond*static_cast(dStopTime - dStartTime), 0., dStopTime - dStartTime); } } } Long64_t lBranchEntries = tBranchTrlo->GetEntries(); for(Long64_t lBranchEntry = 0; lBranchEntry < lBranchEntries; lBranchEntry++) { if(0 == lBranchEntry%10000 && 0 < lBranchEntry) cout<<"Event "<Clear("C"); tArray->Clear("C"); tBranchTrlo->GetEntry(lBranchEntry); tBranch->GetEntry(lBranchEntry); tTriglogBoard = (TTofTriglogBoard*)tArrayTrlo->At(0); Double_t dCurrentReadoutTime = tTriglogBoard->GetMbsTimeSec()*1. + tTriglogBoard->GetMbsTimeMilliSec()/1000. - dStartTime; Double_t dPreviousReadoutTime = dCurrentReadoutTime - dReadoutInterval; if(kbCounterMode) { Int_t iFirstTimeBin = tCounterRate[0]->FindBin(dPreviousReadoutTime); Int_t iLastTimeBin = tCounterRate[0]->FindBin(dCurrentReadoutTime); Double_t dFirstTimeBinShare = (tCounterRate[0]->GetXaxis()->GetBinUpEdge(iFirstTimeBin) - dPreviousReadoutTime)/dReadoutInterval; Double_t dLastTimeBinShare = (dCurrentReadoutTime - tCounterRate[0]->GetXaxis()->GetBinLowEdge(iLastTimeBin))/dReadoutInterval; Double_t dMiddleTimeBinShare = tCounterRate[0]->GetBinWidth(1)/dReadoutInterval; for(Int_t iCounter = 0; iCounter < kiNCounters; iCounter++) { tCalibScaler = (TTofCalibScaler*)tArray->At(kiScalerIndex[iCounter]); // multiplication with 'fdTimeSinceLast' to get absolute numbers, not an instantaneous rate! Double_t dScalerValue = tCalibScaler->GetScalerValue(kiScalerBlockChannelIndex[iCounter], kiScalerBlockIndex[iCounter])*tCalibScaler->GetTimeToLast(); for(Int_t iTimeBin = iFirstTimeBin; iTimeBin <= iLastTimeBin; iTimeBin++) { Double_t dBinShare(0.); if(iTimeBin == iFirstTimeBin) { dBinShare = dFirstTimeBinShare; } else if(iTimeBin == iLastTimeBin) { dBinShare = dLastTimeBinShare; } else { dBinShare = dMiddleTimeBinShare; } tCounterRate[iCounter]->AddBinContent(iTimeBin, dBinShare*dScalerValue); tCounterFlux[iCounter]->AddBinContent(iTimeBin, dBinShare*dScalerValue); } } } else { Int_t iFirstTimeBin = tScalerBlockRate[0][0]->FindBin(dPreviousReadoutTime); Int_t iLastTimeBin = tScalerBlockRate[0][0]->FindBin(dCurrentReadoutTime); Double_t dFirstTimeBinShare = (tScalerBlockRate[0][0]->GetXaxis()->GetBinUpEdge(iFirstTimeBin) - dPreviousReadoutTime)/dReadoutInterval; Double_t dLastTimeBinShare = (dCurrentReadoutTime - tScalerBlockRate[0][0]->GetXaxis()->GetBinLowEdge(iLastTimeBin))/dReadoutInterval; Double_t dMiddleTimeBinShare = tScalerBlockRate[0][0]->GetBinWidth(1)/dReadoutInterval; tCalibScaler = (TTofCalibScaler*)tArray->At(kiScaler); for(Int_t iScalerBlock = 0; iScalerBlock < kiNbScalerBlocks; iScalerBlock++) { for(Int_t iScalerBlockChannel = 0; iScalerBlockChannel < kiNbScalerBlockChannels; iScalerBlockChannel++) { // multiplication with 'fdTimeSinceLast' to get absolute numbers, not an instantaneous rate! Double_t dScalerValue = tCalibScaler->GetScalerValue(iScalerBlockChannel, iScalerBlock)*tCalibScaler->GetTimeToLast(); for(Int_t iTimeBin = iFirstTimeBin; iTimeBin <= iLastTimeBin; iTimeBin++) { Double_t dBinShare(0.); if(iTimeBin == iFirstTimeBin) { dBinShare = dFirstTimeBinShare; } else if(iTimeBin == iLastTimeBin) { dBinShare = dLastTimeBinShare; } else { dBinShare = dMiddleTimeBinShare; } tScalerBlockRate[iScalerBlock][iScalerBlockChannel]->AddBinContent(iTimeBin, dBinShare*dScalerValue); } } } } } if(kbCounterMode) { TCanvas* tCanvasRate = new TCanvas("tCanvasRate", "", 0., 0., 2100., 500.); tCanvasRate->Divide(3, 1); for(Int_t iCounter = 0; iCounter < kiNCounters; iCounter++) { tCanvasRate->cd(iCounter + 1); gPad->SetLogy(); tCounterRate[iCounter]->Scale(1.*kiNBinsPerSecond); tCounterRate[iCounter]->Draw("HIST"); } TCanvas* tCanvasFlux = new TCanvas("tCanvasFlux", "", 0., 480., 2100., 500.); tCanvasFlux->Divide(3, 1); for(Int_t iCounter = 0; iCounter < kiNCounters; iCounter++) { tCanvasFlux->cd(iCounter + 1); gPad->SetLogy(); tCounterFlux[iCounter]->Scale(1.*kiNBinsPerSecond); tCounterFlux[iCounter]->Scale(1./kdCounterArea[iCounter]); tCounterFlux[iCounter]->Draw("HIST"); } } else { TCanvas* tCanvasRate[kiNbScalerBlocks]; for(Int_t iScalerBlock = 0; iScalerBlock < kiNbScalerBlocks; iScalerBlock++) { tCanvasRate[iScalerBlock] = new TCanvas(Form("tCanvasRate_%02d", iScalerBlock), "", 0., 0., 1400., 1000.); tCanvasRate[iScalerBlock]->Divide(8, 8); for(Int_t iScalerBlockChannel = 0; iScalerBlockChannel < kiNbScalerBlockChannels; iScalerBlockChannel++) { tCanvasRate[iScalerBlock]->cd(iScalerBlockChannel + 1); gPad->SetLogy(); tScalerBlockRate[iScalerBlock][iScalerBlockChannel]->Draw("HIST"); } } } }