JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
MQwHistograms.h
Go to the documentation of this file.
1/*!
2 * \file MQwHistograms.h
3 * \brief Mix-in class for histogram management functionality
4 */
5
6#pragma once
7
8// System headers
9#include <vector>
10
11// Root headers
12#include "TH1.h"
13
14// Qweak headers
15#include "QwLog.h"
16
17/**
18 * \class MQwHistograms
19 * \ingroup QwAnalysis
20 * \brief Mix-in class providing histogram management functionality
21 *
22 * Provides a common interface for data elements that need to create
23 * and fill ROOT histograms. Manages histogram pointers and provides
24 * utilities for histogram registration and sharing between objects.
25 */
27
28 /// Regular pointers for the histograms
29 typedef TH1* TH1_ptr;
30 // Shared pointers (std::shared_ptr) are not advisable
31 // because ROOT keep ownership of all histograms. They
32 // are automatically deleted when ROOT closes the file.
33 // If we put them in a shared_ptr here, they would be
34 // deleted by the time the shared_ptr goes out of scope.
35
36 protected:
37 /// Default constructor
39 /// Copy constructor
41 : fHistograms(source.fHistograms) { }
42 /// Virtual destructor
43 virtual ~MQwHistograms() { }
44
45 /// Arithmetic assignment operator: Should only copy event-based data.
46 /// In this particular class, there is no event-based data.
48 if (this != &value) {
49 // No event-based data to copy in this class
50 }
51 return *this;
52 }
53
54 inline void Fill_Pointer(TH1_ptr hist_ptr, Double_t value){
55 if (hist_ptr != nullptr){
56 hist_ptr->Fill(value);
57 }
58 }
59
60 protected:
61 /// Histograms associated with this data element
62 std::vector<TH1_ptr> fHistograms;
63
64 protected:
65 /// Register a histogram
66 void AddHistogram(TH1* h) {
67 fHistograms.push_back(TH1_ptr(h));
68 fHistograms.back()->SetBuffer(1000);
69 }
70
71 public:
72 /// Share histogram pointers between objects
73 void ShareHistograms(const MQwHistograms* source) {
74 if (source) fHistograms = source->fHistograms;
75 }
76
77}; // class MQwHistograms
78
A logfile class, based on an identical class in the Hermes analyzer.
MQwHistograms(const MQwHistograms &source)
Copy constructor.
void Fill_Pointer(TH1_ptr hist_ptr, Double_t value)
void ShareHistograms(const MQwHistograms *source)
Share histogram pointers between objects.
void AddHistogram(TH1 *h)
Register a histogram.
MQwHistograms & operator=(const MQwHistograms &value)
virtual ~MQwHistograms()
Virtual destructor.
TH1 * TH1_ptr
Regular pointers for the histograms.
std::vector< TH1_ptr > fHistograms
Histograms associated with this data element.
MQwHistograms()
Default constructor.