#include "StructDef.h" //#include "$SIMPATH/unpack/tof/calib/scaler/TTofCalibScaler.h" Bool_t hvScalUseExample( Int_t iFirstRPC = 0, Int_t iSecondRpc = 2, Int_t iScalerIndex = 3, Double_t dScalerArea = -1 ) { const Int_t kiNbRpc = 11; TString sChNameRpc[kiNbRpc] = { "HD_Big", "HD_Sm", "HD_Ref", "USTC", "TS_PAD", "TS_Strip", "BUC_Ref", "BUC_2010", "BUC_2012", "BUC_2013", "TRD_BUC"}; if( kiNbRpc <= iFirstRPC || kiNbRpc <= iSecondRpc ) { cout<<" One of the RPC indices is out of bound, values should be between 0 and "<IsOpen() ) { cout<< Form("Input file %s cannot be opened.", sInputFilenameHv.Data())<Get("CaenHV"); if(!tInputTreeHv) { cout<<"No Hv tree inside the input file for CAEN HV."<GetEntries(); Rpc_HV tRpcHvEvtA; Rpc_HV tRpcHvEvtB; TBranch* tBranchEventRpcA = tInputTreeHv->GetBranch( sChNameRpc[iFirstRPC] ); if(!tBranchEventRpcA) { cout<<"No branch "<SetAddress(&(tRpcHvEvtA.iTimeSec)); TBranch* tBranchEventRpcB = tInputTreeHv->GetBranch( sChNameRpc[iSecondRpc] ); if(!tBranchEventRpcB) { cout<<"No branch "<SetAddress(&(tRpcHvEvtB.iTimeSec)); // Scalers TString sInputFilenameScal = "unpack.out.root"; // TString sInputFilenameScal = "MbsTrbSun2325_unpack.out.root"; // TString sInputFilenameScal = "../unpack_MbsTrbMon0153.out.root"; TFile * fInputFileScal = TFile::Open( sInputFilenameScal, "READ"); if(!fInputFileScal || kFALSE == fInputFileScal->IsOpen() ) { cout<< Form("Input file %s cannot be opened.", sInputFilenameScal.Data())<Get("cbmsim"); if(!tInputTreeScal) { cout<<"No CbmSim tree inside the input file for scalers."<GetEntries(); TClonesArray* tArrayTriglog(NULL); TClonesArray* tArrayScal(NULL); TBranch* tBranchEventTriglog = tInputTreeScal->GetBranch( "TofTriglog" ); if(!tBranchEventTriglog) { cout<<"No branch TofTriglog in input tree."<SetAddress(&tArrayTriglog); TBranch* tBranchEventScal = tInputTreeScal->GetBranch( "TofCalibScaler" ); if(!tBranchEventScal) { cout<<"No branch TofCalibScaler in input tree."<SetAddress(&tArrayScal); // Switch back current directory to gROOT so that new object are created in memory, not in file gROOT->cd(); // TTofCalibScaler* tEventScal(0); cout<GetEntry(iFirstGoodMbsEvent); fTriglogBoard = (TTofTriglogBoard*) tArrayTriglog->ConstructedAt(0); // Always only 1 TRIGLOG board! if( 0 < fTriglogBoard->GetMbsTimeSec() ) break; } // for( iFirstGoodMbsEvent = 0; iFirstGoodMbsEvent < uNTreeEntriesScal; iFirstGoodMbsEvent ++) tInputTreeScal->GetEntry(iFirstGoodMbsEvent); fTriglogBoard = (TTofTriglogBoard*) tArrayTriglog->ConstructedAt(0); // Always only 1 TRIGLOG board! fCalTrloBoard = (TTofCalibScaler*) tArrayScal->ConstructedAt(0); // TRIGLOG board always first! TTimeStamp tTimeFirstMbsEvent; tTimeFirstMbsEvent.SetSec( fTriglogBoard->GetMbsTimeSec() ); tTimeFirstMbsEvent.SetNanoSec( fTriglogBoard->GetMbsTimeMilliSec() * 1000000 ); // Get time for MBS ending point tInputTreeScal->GetEntry(uNTreeEntriesScal-1); fTriglogBoard = (TTofTriglogBoard*) tArrayTriglog->ConstructedAt(0); // Always only 1 TRIGLOG board! fCalTrloBoard = (TTofCalibScaler*) tArrayScal->ConstructedAt(0); // TRIGLOG board always first! TTimeStamp tTimeLastMbsEvent; tTimeLastMbsEvent.SetSec( fTriglogBoard->GetMbsTimeSec() ); tTimeLastMbsEvent.SetNanoSec( fTriglogBoard->GetMbsTimeMilliSec() * 1000000 ); cout<<"Time first MBS event: "<SetLineColor(kBlue); TH1 * hCurrentEvoPosA = new TH1D( "hCurrentEvoPosA", Form("Current evolution for the Positive HV of %s; Time [s]; Current [uA]", sChNameRpc[iFirstRPC].Data()), 2*iTimeIntervalsec, 0, iTimeIntervalsec ); hCurrentEvoPosA->SetLineColor(kRed); TH1 * hCurrentEvoNegB = new TH1D( "hCurrentEvoNegB", Form("Current evolution for the Negative HV of %s; Time [s]; Current [uA]", sChNameRpc[iSecondRpc].Data()), 2*iTimeIntervalsec, 0, iTimeIntervalsec ); hCurrentEvoNegB->SetLineColor(kBlue); TH1 * hCurrentEvoPosB = new TH1D( "hCurrentEvoPosB", Form("Current evolution for the Positive HV of %s; Time [s]; Current [uA]", sChNameRpc[iSecondRpc].Data()), 2*iTimeIntervalsec, 0, iTimeIntervalsec ); hCurrentEvoPosB->SetLineColor(kRed); TH1 * hRateEvoScal = new TH1D( "hRateEvoScal", Form("Scaler rate evolution for the input scaler #%d in TRIGLOG; Time [s]; Rate [kHz/cm2]", iScalerIndex), 2*iTimeIntervalsec, 0, iTimeIntervalsec ); hRateEvoScal->SetLineColor(kGreen); /* TProfile * hCurrentEvoNegB = new TProfile( "hCurrentEvoNegB", Form("Current evolution for the Negative HV of %s; Time [s]; Current [uA]", sChNameRpc[iSecondRpc].Data()), iTimeIntervalsec, 0, iTimeIntervalsec ); hCurrentEvoNegB->SetLineColor(kBlue); TProfile * hCurrentEvoPosB = new TProfile( "hCurrentEvoPosB", Form("Current evolution for the Positive HV of %s; Time [s]; Current [uA]", sChNameRpc[iSecondRpc].Data()), iTimeIntervalsec, 0, iTimeIntervalsec ); hCurrentEvoPosB->SetLineColor(kRed); TProfile * hRateEvoScal = new TProfile( "hRateEvoScal", Form("Scaler rate evolution for the input scaler #%d in TRIGLOG; Time [s]; Rate [kHz/cm2]", iScalerIndex), iTimeIntervalsec, 0, iTimeIntervalsec ); hRateEvoScal->SetLineColor(kGreen); */ TH2 * hRateCurrCompA = new TH2D( "hRateCurrCompA", Form("Comparison of scaler #%d rate and RPC %s current; Rate [kHz/cm2]; Total current [uA]", iScalerIndex, sChNameRpc[iFirstRPC].Data()), 1000, 0, 5, 300, 0, 3 ); TH2 * hRateCurrCompB = new TH2D( "hRateCurrCompB", Form("Comparison of scaler #%d rate and RPC %s current; Rate [kHz/cm2]; Total current [uA]", iScalerIndex, sChNameRpc[iSecondRpc].Data()), 1000, 0, 5, 300, 0, 3 ); // Loop until the HV point matching best the first MBS event is found Double_t dTimeDistMbsPrevA = -1e10; Double_t dTimeDistMbsPrevB = -1e10; Double_t dTimeDistMbsLastA = -1e10; Double_t dTimeDistMbsLastB = -1e10; UInt_t uHvStartPoint = 0; for( uHvStartPoint = 0; uHvStartPoint < uNTreeEntriesHv; uHvStartPoint++) { tInputTreeHv->GetEntry(uHvStartPoint); dTimeDistMbsPrevA = dTimeDistMbsLastA; dTimeDistMbsPrevB = dTimeDistMbsLastB; dTimeDistMbsLastA = (Double_t)tRpcHvEvtA.iTimeSec + (Double_t)tRpcHvEvtA.iTimeMilliSec/1000.0 - (Double_t)(tTimeFirstMbsEvent.GetSec()) - (Double_t)(tTimeFirstMbsEvent.GetNanoSec())/1e9; dTimeDistMbsLastB = (Double_t)tRpcHvEvtB.iTimeSec + (Double_t)tRpcHvEvtB.iTimeMilliSec/1000.0 - (Double_t)(tTimeFirstMbsEvent.GetSec()) - (Double_t)(tTimeFirstMbsEvent.GetNanoSec())/1e9; if( 0 < dTimeDistMbsLastA && 0 < dTimeDistMbsLastB ) break; } // for( UInt_t uHvPoint = 0; uHvPoint < uNTreeEntriesHv; uHvPoint++) if( TMath::Abs( dTimeDistMbsPrevA ) < TMath::Abs( dTimeDistMbsLastA ) && TMath::Abs( dTimeDistMbsPrevB ) < TMath::Abs( dTimeDistMbsLastB ) ) uHvStartPoint --; cout<<" Best Match in time with first MBS event found for HV point #"<GetEntries()<<" " <GetEntries()<GetEntries()<<" " <GetEntries()<GetEntries()<GetEntries()<<" " <GetEntries()<SetFillColor(0); tCanvasA->SetGridx(0); tCanvasA->SetGridy(0); tCanvasA->SetTopMargin(0); tCanvasA->SetRightMargin(0); tCanvasA->SetBottomMargin(0); tCanvasA->SetLeftMargin(0); tCanvasA->Divide(2,2,0,0); tCanvasA->cd(1); gPad->SetTopMargin(0.15); gPad->SetRightMargin(0.15); gPad->SetBottomMargin(0.15); gPad->SetLeftMargin(0.15); hRateEvoScal->Draw(); hCurrentEvoPosA->Draw("SAME"); hCurrentEvoNegA->Draw("SAME"); tCanvasA->cd(2); gPad->SetTopMargin(0.15); gPad->SetRightMargin(0.15); gPad->SetBottomMargin(0.15); gPad->SetLeftMargin(0.15); hRateEvoScal->Draw(); hCurrentEvoPosB->Draw("SAME"); hCurrentEvoNegB->Draw("SAME"); tCanvasA->cd(3); gPad->SetTopMargin(0.15); gPad->SetRightMargin(0.15); gPad->SetBottomMargin(0.15); gPad->SetLeftMargin(0.15); hRateEvoScal->Draw(); tCanvasA->cd(4); gPad->SetTopMargin(0.15); gPad->SetRightMargin(0.15); gPad->SetBottomMargin(0.15); gPad->SetLeftMargin(0.15); hRateEvoScal->Draw(); TCanvas* tCanvasB = new TCanvas("tCanvasB","Currents VS rate",0,0,2000,1000); tCanvasB->SetFillColor(0); tCanvasB->SetGridx(0); tCanvasB->SetGridy(0); tCanvasB->SetTopMargin(0); tCanvasB->SetRightMargin(0); tCanvasB->SetBottomMargin(0); tCanvasB->SetLeftMargin(0); tCanvasB->Divide(2,1,0,0); tCanvasB->cd(1); gPad->SetTopMargin(0.15); gPad->SetRightMargin(0.15); gPad->SetBottomMargin(0.15); gPad->SetLeftMargin(0.15); hRateCurrCompA->Draw("COLZ"); tCanvasB->cd(2); gPad->SetTopMargin(0.15); gPad->SetRightMargin(0.15); gPad->SetBottomMargin(0.15); gPad->SetLeftMargin(0.15); hRateCurrCompB->Draw("COLZ"); fInputFileHv->Close(); fInputFileScal->Close(); return kTRUE; }