An example of histogramming, with a fit and a spectrum
{
// This example plots a vector and accumulates a histogram of the values// of this vector. It also plots a spectrum of the interesting part.// Only the part of the vector that corresponds to the interesting part// are plotted (a peak at the beginning of the frames)// The histogram is accumulated for nframmax frames// To see the result of this macro, click here
gROOT->Reset();
gBenchmark->Start("scroll2spectrum");
FrameH* fr; // not mandatory to declare in a script
// Max number of frames displayedInt_t nframmax = 14;
// Open a new window (canvas) and divide it in 3// Add some fancy enhancements
c1 = new TCanvas("c1","c1",1);
c1->Divide(2,1);
c1_1->SetFillColor(44);
c1_1->SetFrameFillColor(41);
// Divide the second pad by 2 so as to obtain a 3 pads canvas
c1_2->Divide(1,2);
c1_2->cd(1); // Go to the first subpad of the second (c1_2) pad
// gPad is always the current selected pad
gPad->SetFillColor(44);
gPad->SetFrameFillColor(41);
gPad->SetLogy();
gPad->SetGridx();
gPad->SetGridy();
c1_2->cd(2); // Go to the second subpad of the second (c1_2) pad
// gPad is always the current selected pad
gPad->SetFillColor(44);
gPad->SetFrameFillColor(41);
gPad->SetGridx();
gPad->SetGridy();
// Open a frame channel
fc = new VFrameChannel("demoDB.root");
// Start timeDouble_t time = fc->GetStart();
// Histogram to constrain the limits
hisfr = new TH1F("hisfr","Histogram of MYGO_ADC1 values",100,0.,3000.);
hisfr->SetMarkerColor(4);
hisfr->SetMarkerStyle(8);
hisfr->SetMarkerSize(0.7);
// Get the first frame with absolute time
fr = fc->GetFrame(time);
Int_t nfram = 0;
while ( (fr!=0) && (nfram<nframmax) ) {
nfram++;
printf("nfram = %dn",nfram);
// Draws the vector (only in the signal region)// Do not need to extract a vector to do that,// the draw method will do it for you if you specify "adc.name"
c1->cd(1);
gVM->Draw(fr,"adc.MYGO_ADC1",0.13,0.07);
// Get the corresponding VSPlot and set the color to blueVSPlot* vfp = gVM->GetLastPlot();
vfp->SetLineColor(4);
vfp->GetXaxis()->SetTimeDisplay(1); // axis labels displayed as time
// Fill the histogram (accumulates it) and draw it// the + option in front of the name of the histogram// means that it's content is not erased before each fill
c1_2->cd(1);
gVM->DrawHist(fr,"adc.MYGO_ADC1",0.13,0.07,"+hisfr","e1");
// Extracts the vector and alculates it's spectrum
vect = VGetVect(fr,"adc.MYGO_ADC1");
fft = FrvRFFTFor(0,vect);
// Now plots it. Log scales are set by default (type of vector=spectrum)
c1_2->cd(2);
gVM->Draw(fft->amplitude);
// Get the corresponding VSPlot and set the color to dark redVSPlot* vfp = gVM->GetLastPlot();
vfp->SetLineColor(50);
// Update the canvas
c1->Update();
// Clean up the allocated variables
FrvRFFTFree(fft);
FrameFree(fr);
fr = fc->GetNextFrame(); // Get the next frame
}
// Fits the histogram and draws the fit result
c1_2->cd(1);
hisfr->Fit("gaus");
hisfr->SetMarkerColor(4);
hisfr->SetMarkerStyle(8);
hisfr->SetMarkerSize(0.7);
hisfr->Draw("e1");
gBenchmark->Show("scroll2spectrum");
}
- ROOT page - VEGA page - Class index - Top of the page This page has been automatically generated. If you have any comments or suggestions
about the page layout send a mail to
, or
contact
with any questions or problems regarding ROOT or VEGA.