1 |
#ifndef trkupgradeanalysis_tools_h
|
2 |
#define trkupgradeanalysis_tools_h
|
3 |
|
4 |
#include <memory> // required for std::auto_ptr
|
5 |
#include <string>
|
6 |
#include <utility> // required for std::pair
|
7 |
#include <map>
|
8 |
|
9 |
// Forward declarations
|
10 |
class TFile;
|
11 |
class TH1F;
|
12 |
class TTree;
|
13 |
class TDirectory;
|
14 |
|
15 |
namespace trkupgradeanalysis
|
16 |
{
|
17 |
namespace tools
|
18 |
{
|
19 |
|
20 |
/** @brief Class to automatically clean up a TFile when it goes out of scope.
|
21 |
*
|
22 |
* Since I'm using exceptions I need something to keep track of the open TFile
|
23 |
* that is exception safe. I can't use auto_ptr class directly because I want
|
24 |
* the "Close" method to be called before deletion.
|
25 |
*
|
26 |
* I'm not sure if inheriting from auto_ptr is a good idea. I'll give it a go
|
27 |
* and see what happens.
|
28 |
*
|
29 |
* @author Mark Grimes (mark.grimes@bristol.ac.uk)
|
30 |
* @date 27/Apr/2012
|
31 |
*/
|
32 |
class TFile_auto_ptr : public std::auto_ptr<TFile>
|
33 |
{
|
34 |
public:
|
35 |
TFile_auto_ptr( const std::string& filename );
|
36 |
~TFile_auto_ptr();
|
37 |
bool operator==( const TFile* pOtherFile );
|
38 |
};
|
39 |
|
40 |
|
41 |
|
42 |
/** @brief Class to simplify getting entries from a TTree.
|
43 |
*
|
44 |
* @author Mark Grimes (mark.grimes@bristol.ac.uk)
|
45 |
* @date 07/Jul/2012
|
46 |
*/
|
47 |
class NTupleRow
|
48 |
{
|
49 |
public:
|
50 |
NTupleRow( TTree* pTree );
|
51 |
const double& getDouble( const std::string& name ) const;
|
52 |
bool nextRow();
|
53 |
void returnToStart();
|
54 |
protected:
|
55 |
std::map<std::string,double> branchAddresses_;
|
56 |
TTree* pTree_;
|
57 |
int maxCandidateNumber_;
|
58 |
int candidateNumber_;
|
59 |
};
|
60 |
|
61 |
|
62 |
|
63 |
/** @brief Uses linear interpolation of two points to find and x value that corresponds to the supplied requiredY.
|
64 |
*
|
65 |
* @param[in] point1 The first point to interpolate between, with x as the first member and y as the second.
|
66 |
* @param[in] point2 The second point to interpolate between, with x as the first member and y as the second.
|
67 |
* @param[in] requiredY The y value for the interpolated point you want to find the x value for.
|
68 |
* @return The x value for the point with y=requiredY on the straight line between point1 and point2
|
69 |
*
|
70 |
* @author Mark Grimes (mark.grimes@bristol.ac.uk)
|
71 |
* @date 30/Apr/2012
|
72 |
*/
|
73 |
float linearInterpolate( std::pair<float,float> point1, std::pair<float,float> point2, float requiredY );
|
74 |
|
75 |
|
76 |
|
77 |
/** @brief Calculates the btag operating point that would give the requested tag efficiency.
|
78 |
*
|
79 |
* Finds the two histogram bins either side of the requested efficiency and then uses linear
|
80 |
* interpolation between the two to get the operating point.
|
81 |
*
|
82 |
* @param[in] pEventsVersusDiscriminatorHistogram The histogram of number of events versus btag discriminator to calculate from.
|
83 |
* @param[in] requiredEfficiency The efficiency that you want an operating point for.
|
84 |
* @param[in] verbose (Defaults to true) Whether to print extra information to standard output.
|
85 |
* @return The discriminator value that would give an efficiency of requiredEfficiency for the supplied histogram.
|
86 |
* @throw std::runtime_error If something goes wrong.
|
87 |
*
|
88 |
* @author Mark Grimes (mark.grimes@bristol.ac.uk)
|
89 |
* @date 30/Apr/2012
|
90 |
*/
|
91 |
float findDiscriminator( const TH1F* pEventsVersusDiscriminatorHistogram, const float requiredEfficiency, const bool verbose=true );
|
92 |
|
93 |
|
94 |
|
95 |
/** @brief Calculates the efficiency for the supplied btag operating point.
|
96 |
*
|
97 |
* Finds the two histogram bins either side of the requested operating point and then uses linear
|
98 |
* interpolation between the two to get the efficiency.
|
99 |
*
|
100 |
* @param[in] pEventsVersusDiscriminatorHistogram The histogram of number of events versus btag discriminator to calculate from.
|
101 |
* @param[in] requiredDiscriminator The operating point that you want to know the efficiency for.
|
102 |
* @param[in] verbose (Defaults to true) Whether to print extra information to standard output.
|
103 |
* @return The efficiency that the supplied discriminator would give for the supplied histogram.
|
104 |
* @throw std::runtime_error If something goes wrong.
|
105 |
*
|
106 |
* @author Mark Grimes (mark.grimes@bristol.ac.uk)
|
107 |
* @date 30/Apr/2012
|
108 |
*/
|
109 |
float findEfficiency( const TH1F* pEventsVersusDiscriminatorHistogram, const float requiredDiscriminator, const bool verbose=true );
|
110 |
|
111 |
|
112 |
/** @brief Creates a directory structure in the root TDirectory, with parent directories separated by slashes also created.
|
113 |
*
|
114 |
* @param[in] fullPath The directory name to be created. Slashes will create a series of directories inside each other.
|
115 |
* @param[in] pParent The already existing directory to create the new directories in.
|
116 |
* @return The TDirectory created.
|
117 |
* @throw std::runtime_error If the pParent is NULL or one of the directories couldn't be created.
|
118 |
*
|
119 |
* @author Mark Grimes (mark.grimes@bristol.ac.uk)
|
120 |
* @date 08/Jul/2012
|
121 |
*/
|
122 |
TDirectory* createDirectory( const std::string& fullPath, TDirectory* pParent );
|
123 |
|
124 |
} // end of namespace tools
|
125 |
|
126 |
} // end of namespace trkupgradeanalysis
|
127 |
|
128 |
|
129 |
#endif // end of "#ifndef trkupgradeanalysis_tools_h"
|