Skip to content

Instantly share code, notes, and snippets.

@pgjones
Created March 13, 2013 19:40
Show Gist options
  • Save pgjones/5155396 to your computer and use it in GitHub Desktop.
Save pgjones/5155396 to your computer and use it in GitHub Desktop.
Plot the occupancy by lcn from a rat ds root file
#include <RAT/DS/Root.hh>
#include <RAT/DS/EV.hh>
#include <RAT/DS/Run.hh>
#include <TH1D.h>
#include <TTree.h>
#include <TFile.h>
#include <time.h>
using namespace std;
void
LoadRootFile( const char* lpFile,
TTree **tree,
RAT::DS::Root **rDS,
RAT::DS::Run **rRun );
void
PlotOccupancy( const char* inFile )
{
// Load the root file first RAT::DS::Root* rDS;
RAT::DS::Run* rRun;
TTree *tree;
LoadRootFile( inFile, &tree, &rDS, &rRun );
time_t codeStart = time( NULL );
TH1D* occupancyPlot = new TH1D( "occupancy", "occupancy", 10000, -0.5, 9999.5 );
for( int iEvent = 0; iEvent < tree->GetEntries(); iEvent++ )
{
if( iEvent % 100 == 0 )
cout << iEvent << " finished at " << time( NULL ) - codeStart << endl;
tree->GetEntry( iEvent );
for( int iEV = 0; iEV < rDS->GetEVCount(); iEV++ )
for( int iPMT = 0; iPMT < rDS->GetEV( iEV )->GetPMTCalCount(); iPMT++ )
occupancyPlot->Fill( rDS->GetEV( iEV )->GetPMTCal( iPMT )->GetID() );
}
occupancyPlot->Draw();
}
void
LoadRootFile( const char* lpFile,
TTree **tree,
RAT::DS::Root **rDS,
RAT::DS::Run **rRun )
{
TFile *file = new TFile( lpFile );
(*tree) = (TTree*)file->Get( "T" );
TTree *runTree = (TTree*)file->Get( "runT" );
*rDS = new RAT::DS::Root();
(*tree)->SetBranchAddress( "ds", &(*rDS) );
*rRun = new RAT::DS::Run();
runTree->SetBranchAddress( "run", &(*rRun) );
runTree->GetEntry();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment