ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/grimes/VHbbAnalysisCode/src/tools.cpp
(Generate patch)

Comparing UserCode/grimes/VHbbAnalysisCode/src/tools.cpp (file contents):
Revision 1.1 by grimes, Wed May 2 15:59:19 2012 UTC vs.
Revision 1.2 by grimes, Wed Aug 15 22:37:47 2012 UTC

# Line 5 | Line 5
5  
6   #include <TFile.h>
7   #include <TH1F.h>
8 + #include <TTree.h>
9 + #include <TDirectory.h>
10  
11   trkupgradeanalysis::tools::TFile_auto_ptr::TFile_auto_ptr( const std::string& filename )
12   {
# Line 26 | Line 28 | bool trkupgradeanalysis::tools::TFile_au
28  
29  
30  
31 + trkupgradeanalysis::tools::NTupleRow::NTupleRow( TTree* pTree )
32 +        : pTree_(pTree)
33 + {
34 +        TObjArray* pLeafList=pTree->GetListOfBranches();
35 +
36 +        for( int a=0; a<pLeafList->GetEntries(); ++a )
37 +        {
38 +                TBranch* pBranch=(TBranch*)(*pLeafList)[a];
39 +                std::string name=pBranch->GetName();
40 +                std::string title=pBranch->GetTitle();
41 +                std::string typeString=title.substr( name.size() );
42 +
43 +                if( typeString=="/D" ) branchAddresses_[name]=0; // Put an entry in the map for this name
44 +        }
45 +
46 +        // Now loop over the map names and set the branch addresses. I didn't want to do this earlier
47 +        // because there's the possibility adding new entries to the map might change the addresses.
48 +        for( std::map<std::string,double>::iterator iEntry=branchAddresses_.begin(); iEntry!=branchAddresses_.end(); ++iEntry )
49 +        {
50 +                pTree->SetBranchAddress( iEntry->first.c_str(), &(iEntry->second) );
51 +        }
52 +
53 +        maxCandidateNumber_=pTree_->GetEntries();
54 +        candidateNumber_=-1; // Set to minus one, so that the first call to nextCandidate() sets it to the first (0) entry
55 +        pTree_->GetEntry(0); // Load in the first candidate so that the memory contents isn't random. Note the first call to nextCandidate() will keep it on the 0th entry.
56 + }
57 +
58 + const double& trkupgradeanalysis::tools::NTupleRow::getDouble( const std::string& name ) const
59 + {
60 +        std::map<std::string,double>::const_iterator iFindResult=branchAddresses_.find(name);
61 +        if( iFindResult!=branchAddresses_.end() ) return iFindResult->second;
62 +        else throw std::runtime_error( "trkupgradeanalysis::tools::NTupleRow::getDouble(..) - TTree doesn't have a branch called "+name );
63 + }
64 +
65 + bool trkupgradeanalysis::tools::NTupleRow::nextRow()
66 + {
67 +        ++candidateNumber_;
68 +        if( candidateNumber_>=maxCandidateNumber_ ) return false;
69 +
70 +        pTree_->GetEntry(candidateNumber_);
71 +        return true;
72 + }
73 +
74 + void trkupgradeanalysis::tools::NTupleRow::returnToStart()
75 + {
76 +        candidateNumber_=-1; // Set to minus one, so that the first call to nextCandidate() sets it to the first (0) entry
77 + }
78 +
79 +
80 +
81 +
82 +
83  
84   float trkupgradeanalysis::tools::linearInterpolate( std::pair<float,float> point1, std::pair<float,float> point2, float requiredY )
85   {
# Line 135 | Line 189 | float trkupgradeanalysis::tools::findEff
189          throw std::runtime_error("findEfficiency was unable to find an operating point");
190  
191   } // end of function findEfficiency
192 +
193 +
194 +
195 + TDirectory* trkupgradeanalysis::tools::createDirectory( const std::string& fullPath, TDirectory* pParent )
196 + {
197 +        if( pParent==NULL ) throw std::runtime_error( "The parent directory is a Null pointer" );
198 +
199 +        TDirectory* pSubDirectory=pParent;
200 +        size_t currentPosition=0;
201 +        size_t nextSlash;
202 +        do
203 +        {
204 +                nextSlash=fullPath.find_first_of('/', currentPosition );
205 +                std::string directoryName=fullPath.substr(currentPosition,nextSlash-currentPosition);
206 +                currentPosition=nextSlash+1;
207 +
208 +                TDirectory* pNextSubDirectory=pSubDirectory->GetDirectory( directoryName.c_str() );
209 +                if( pNextSubDirectory==NULL ) pNextSubDirectory=pSubDirectory->mkdir( directoryName.c_str() );
210 +                if( pNextSubDirectory==NULL ) throw std::runtime_error( "Couldn't create the root directory \""+directoryName+"\"" );
211 +                pSubDirectory=pNextSubDirectory;
212 +
213 +        } while( nextSlash!=std::string::npos );
214 +
215 +        return pSubDirectory;
216 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines