Created
July 26, 2013 11:11
-
-
Save pgjones/6088094 to your computer and use it in GitHub Desktop.
Simple classification extraction example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////////////////////////// | |
/// My preferred method to load a root file in root. | |
/// Must load in root as .L Load.cc+ | |
/// | |
/// 11/10/2012 : New 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 | |
DoSomething( 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 ); | |
for( int iEvent = 0; iEvent < tree->GetEntries(); iEvent++ ) | |
{ | |
if( iEvent % 100 == 0 ) | |
cout << iEvent << " finished at " << time( NULL ) - codeStart << endl; | |
tree->GetEntry( iEvent ); | |
// Do something here | |
for( int iEV = 0; iEV < rDS->GetEVCount(); iEV++ ) | |
{ | |
RAT::DS::EV* rEV = rDS->GetEV( iEV ); | |
try | |
{ | |
double numPeaks = rEV->GetClassifierResult( "timingPeaks:scintFitter" ).GetClassification( "timingPeaks" ); | |
} | |
catch( RAT::DS::ClassifierResult::NoClassificationError& e ) { cout << "NoClassification" << endl; continue; } | |
} | |
} | |
} | |
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