ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/grimes/L1Menu/interface/l1menu/TriggerRatePlot.h
Revision: 1.9
Committed: Wed Jul 24 11:48:54 2013 UTC (11 years, 9 months ago) by grimes
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +23 -0 lines
Log Message:
Big commit of lots of changes before migrating to Git.

File Contents

# User Rev Content
1 grimes 1.1 #ifndef l1menu_TriggerRatePlot_h
2     #define l1menu_TriggerRatePlot_h
3    
4     #include <memory>
5     #include <string>
6 grimes 1.5 #include <vector>
7 grimes 1.1
8     //
9     // Forward declarations
10     //
11     class TH1;
12     namespace l1menu
13     {
14 grimes 1.6 class IEvent;
15 grimes 1.1 class ITrigger;
16 grimes 1.8 class ICachedTrigger;
17 grimes 1.4 class ISample;
18 grimes 1.1 }
19    
20    
21     namespace l1menu
22     {
23     /** @brief Class that plots trigger rates versus threshold.
24     *
25     * @author Mark Grimes (mark.grimes@bristol.ac.uk)
26     * @date 24/May/2013
27     */
28     class TriggerRatePlot
29     {
30     public:
31     /** @brief Constructor that sets the trigger to plot for, the histogram to plot into, and the trigger parameter to vary.
32     *
33     * Note that the title of the histogram is modified to record the state of the trigger (all other parameters).
34     *
35 grimes 1.5 * @param[in] trigger The trigger that the plot will be created for. The trigger should be set exactly as you want
36     * the plots made for it, e.g. with the correct eta cuts already set. The other thresholds are
37     * not modified so you should set these to zero beforehand if that's what you want. The trigger
38     * is copied so these cannot be changed afterwards.
39     * @param[in] pHistogram The root histogram to fill with the rates. This should be set up with the required binning
40     * beforehand. The title is changed to record the trigger name, version, parameter plotted against
41     * and other parameter values.
42     * @param[in] versusParameter The trigger parameter to plot along the x-axis. Defaults to "threshold1".
43     * @param[in] scaledParameters A list of parameters that should be scaled along with the versusParameter. The ratio between each
44     * parameter and the versusParameter at the time of construction is kept as the versusParameter is
45     * changed. A check is made to ensure the versusParameter is taken out of the list if it is present.
46 grimes 1.1 */
47 grimes 1.5 TriggerRatePlot( const l1menu::ITrigger& trigger, std::unique_ptr<TH1> pHistogram, const std::string& versusParameter="threshold1", const std::vector<std::string> scaledParameters=std::vector<std::string>() );
48 grimes 1.9 /** @brief Constructor that creates the histogram itself.
49     *
50     * Similar to the other constructor, except that instead of taking a previously created histogram takes the information required
51     * to create a histogram itself (number of bins etcetera).
52     */
53     TriggerRatePlot( const l1menu::ITrigger& trigger, const std::string& name, size_t numberOfBins, float lowEdge, float highEdge, const std::string& versusParameter="threshold1", const std::vector<std::string> scaledParameters=std::vector<std::string>() );
54     /** @brief Constructor that takes a histogram previously created by TriggerRatePlot, e.g. to load from disk.
55     *
56     * Tries to tell from the information in the title all of the information required to recreate the TriggerRateObject
57     * instance. If anything goes wrong a runtime_error is thrown. Probably advisable to only use this to load a fully
58     * filled plot from disk for use with other classes (e.g. MenuFitter), rather than adding anything else on to it.
59     *
60     * Note that a copy is made of the histogram.
61     */
62     explicit TriggerRatePlot( const TH1* pPreExisitingHistogram );
63 grimes 1.2 TriggerRatePlot( l1menu::TriggerRatePlot& otherTriggerRatePlot ) = delete;
64     TriggerRatePlot& operator=( l1menu::TriggerRatePlot& otherTriggerRatePlot ) = delete;
65 grimes 1.1
66     /** @brief Explicit rvalue constructor to allow moving of TriggerRatePlot objects. */
67     TriggerRatePlot( l1menu::TriggerRatePlot&& otherTriggerRatePlot ) noexcept;
68     /** @brief Explicit rvalue assignment operator to allow moving of TriggerRatePlot objects. */
69     TriggerRatePlot& operator=( l1menu::TriggerRatePlot&& otherTriggerRatePlot ) noexcept;
70    
71     virtual ~TriggerRatePlot();
72 grimes 1.4
73 grimes 1.6 void addEvent( const l1menu::IEvent& event );
74 grimes 1.4 void addSample( const l1menu::ISample& sample );
75 grimes 1.1
76 grimes 1.3 /** @brief Returns the trigger being used to create the plot. */
77     const l1menu::ITrigger& getTrigger() const;
78    
79 grimes 1.9 /** @brief Returns the threshold that will will provide a given rate.
80     *
81     * Interpolates between the bins using a simple linear fit of the two bins
82     * before and the two bins after the point.
83     */
84     float findThreshold( float targetRate ) const;
85    
86 grimes 1.1 /** @brief Returns the internal pointer to the root histogram. Ownership is retained by TriggerRatePlot. */
87     TH1* getPlot();
88    
89     /** @brief Tells TriggerRatePlot to relinquish ownership of the internal root histogram. A pointer to the
90     * histogram is also returned.
91     *
92     * Note that the pointer is still held so that further operations on this object are still valid,
93     * just that the TH1 won't be deleted when the instance goes out of scope. */
94     TH1* relinquishOwnershipOfPlot();
95     protected:
96 grimes 1.9 void initiate( const l1menu::ITrigger& trigger, const std::vector<std::string>& scaledParameters );
97 grimes 1.1 std::unique_ptr<l1menu::ITrigger> pTrigger_;
98     std::unique_ptr<TH1> pHistogram_;
99     /// The parameter to plot against, usually "threshold1";
100     std::string versusParameter_;
101 grimes 1.2 /// Pointer to the versusParameter_ reference in pTrigger_ to avoid expensive string comparison look ups
102     float* pParameter_;
103 grimes 1.5 /// A vector of pointers of any other parameters that should be scaled, and what the scaling should be.
104     std::vector< std::pair<float*,float> > otherParameterScalings_;
105 grimes 1.1 /// Flag to say whether the histogram should be deleted when this instance goes out of scope.
106     bool histogramOwnedByMe_;
107 grimes 1.8 /// The implementation that the public methods delegate to
108     void addEvent( const l1menu::IEvent& event, const std::unique_ptr<l1menu::ICachedTrigger>& pCachedTrigger, float weightPerEvent );
109 grimes 1.1 };
110     }
111     #endif