HighLAND
Experiment.hxx
1 #ifndef Experiment_h
2 #define Experiment_h
3 
4 #include "DataSample.hxx"
5 
6 /// Experiment class
7 /// This class handles multiple data samples in groups (SampleGroup). For example, one generally
8 /// wants to compare a sample of run 1 data to run 1 MC, and a sample of run 2
9 /// data to a sample of run 2 MC. This class allows you to add groups of data/MC
10 /// samples, then interact with them.
11 
12 
13 /// SampleGroup class
14 /// Contains a single data sample and a map of MC samples with their names as key. For example we can associate
15 /// spill MC and sand muon MC to a given data run
16 
18 public:
19 
20  SampleGroup(){}
21  SampleGroup(const std::string& name);
22  SampleGroup(const std::string& name, DataSample* dataSample, std::map<std::string, DataSample*>& mcSamples);
23  SampleGroup(const std::string& name, const std::string& dataFile, std::map<std::string, std::string>& mcFiles);
24 
25  /// Add a new Data Sample to a group (for the moment only one data sample can be added)
26  void AddDataSample(const std::string& file);
27  void AddDataSample(DataSample* sample);
28 
29  /// Add a new MC Sample to a group specifying its name (spill, sand, etc)
30  void AddMCSample(const std::string& name, const std::string& file);
31  void AddMCSample(const std::string& name, DataSample* sample);
32 
33  /// Add a set of MC Samples to a group specifying their names (spill, sand, etc)
34  void AddMCSamples(std::map<std::string, std::string>& mcFiles);
35  void AddMCSamples(std::map<std::string, DataSample*>& mcSamples);
36 
37  /// Get the data sample in a group
39  if (_dataSamples.size()>0) return _dataSamples[0];
40  else return NULL;
41  }
42 
43  /// Get a single MC sample in a group by name
44  DataSample* GetMCSample(const std::string& name){return _mcSamples[name];}
45 
46  /// Get all MC samples in a group
47  std::vector<DataSample*>& GetDataSamples(){return _dataSamples;}
48 
49  /// Get all MC samples in a group
50  std::map<std::string, DataSample*>& GetMCSamples(){return _mcSamples;}
51 
52  /// Check whether the group has a given MC sample
53  bool HasMCSample(const std::string& name);
54 
55  /// Get the good data and MC POT for this sample group.
56  void GetPOT(Float_t& POTdata, Float_t& POTmc);
57 
58  /// Get the good data and MC POT for this sample group, including sand POT.
59  void GetPOT(Float_t& POTdata, Float_t& POTmc, Float_t& POTsand);
60 
61  /// Set the current configuration to all samples in the SampleGroup
62  void SetCurrentTree(const std::string& name);
63 
64 protected:
65 
66  std::string _name;
67  std::vector<DataSample*> _dataSamples;
68  std::map<std::string, DataSample*> _mcSamples;
69 };
70 
71 
72 
73 class Experiment{
74  public :
75 
76  /// Default constructor - just set the name of the experiment. You can add sample
77  /// groups using AddSampleGroup functions.
78  Experiment(const std::string& name);
79 
80  /// Automatically add sampleGroups to the experiment, based on the contents of a
81  /// configuration file.
82  ///
83  /// Each line in this file should relate to one SampleGroup. The first entry on each line is the group
84  /// name.
85  /// The samples are then specified in "sampleName:fileName" pairs. The first pair on each line
86  /// corresponds to the data, the others to MC.
87  ///
88  /// NOTE THAT YOU CANNOT HAVE SPACES IN EITHER THE GROUP NAME OR SAMPLE NAMES.
89  ///
90  /// Example:
91  /// Run1 Data:run1_data.root MC:run1_mc.root Sand:run1_sand.root
92  /// Run2 Data:run2_data.root MC:run2_mc.root
93  Experiment(const std::string& name, const std::string& configfile);
94 
95  /// Create an experiment provided a data and a MC files
96  Experiment(const std::string& name, const std::string& file1, const std::string& file2);
97 
98  virtual ~Experiment(){}
99 
100  /// Checks if the Experiment has a SampleGroup with a given name
101  bool HasSampleGroup(const std::string& name);
102 
103  /// Add a group of samples (normally data and MC). A DataSample object
104  /// will be generated internally for each.
105  void AddSampleGroup(const std::string& name, SampleGroup& sampleGroup);
106 
107  /// Add a group of samples (normally data and MC). A DataSample object
108  /// will be generated internally for each.
109  void AddSampleGroup(const std::string& name, const std::string& dataFile, std::map<std::string, std::string>& mcFiles);
110 
111  /// Add group of samples (normally data and MC).
112  void AddSampleGroup(const std::string& name, DataSample* dataFile, std::map<std::string, DataSample*>& mcSamples);
113 
114  /// Returns all sample groups
115  std::map< std::string, SampleGroup>& GetSampleGroups(){return _sampleGroups;}
116 
117  /// Get a single sample group by name
118  SampleGroup& GetSampleGroup(const std::string& name){HasSampleGroup(name); return _sampleGroups[name];}
119 
120  /// Returns the data sample in group
121  DataSample* GetDataSample(const std::string& name){if (!HasSampleGroup(name)) return NULL; return GetSampleGroup(name).GetDataSample();}
122 
123  /// Returns the by name a MC sample in agroup
124  DataSample* GetMCSample(const std::string& name, const std::string& name2){if (!HasSampleGroup(name)) return NULL; return GetSampleGroup(name).GetMCSample(name2);}
125 
126  /// Returns all MC samples in a group
127  std::map<std::string, DataSample*>& GetMCSamples(const std::string& name){HasSampleGroup(name); return GetSampleGroup(name).GetMCSamples();}
128 
129  /// Dump detailed POT information for a given sample pair.
130  void DumpPOT(const std::string& name);
131 
132  /// Dump total good POT for all sample pairs, and the POT ratio for each pair.
133  void DumpPOTRatios();
134 
135  /// Get the overall POT ratio.
136  Float_t GetOverallPOTRatio();
137 
138  /// If the Experiment was created by passing file paths in (rather than DataSample objects)
139  /// then return the path to one of those files. This is mainly used in automated scripts where the
140  /// Experiment(name, configfile) constructor was used and you later need an explicit file path to
141  /// construct some other object.
142  std::string GetFilePath() { return _filePath; }
143 
144  /// Set the current configuration to all samples in all SampleGroups
145  void SetCurrentTree(const std::string& name);
146 
147  /// Get the current configuration
148  const std::string& GetCurrentTree() const {return _tree;}
149 
150  /// Dump info about the experiment
151  void Dump();
152 
153  /// Return pointer to vector of mc files
154  std::vector<std::string> GetMCFileVector(){return _mcFiles;}
155 
156  /// Return pointer to vector of data files
157  std::vector<std::string> GetDataFileVector(){return _dataFiles;}
158 
159  /// Method to add file paths to the MC and Data vectors that store them
160  void AddSampleFilesToVector(SampleGroup& sampleGroup);
161 
162  protected:
163 
164  /// What the user called this Experiment.
165  std::string _name;
166 
167  /// Configurations that have been added. Structure is
168  /// name ==> [ sample1, sample2 ]
169  std::map< std::string, SampleGroup > _sampleGroups;
170 
171  /// we keep a record of one of the input files the user specified, so that they
172  /// can access it later (for example, if they want to instantiate a DrawingTools
173  /// object using an Experiment rather than specifying a file path directly).
174  std::string _filePath;
175 
176  /// The current tree from the tree manager
177  std::string _tree;
178 
179  /// Vector holding all MC file paths associated with this experiment
180  std::vector<std::string> _mcFiles;
181  /// Vector holding all data file paths associated with this experiment
182  std::vector<std::string> _dataFiles;
183 
184 
185 
186 };
187 
188 #endif
189 
190 
std::vector< std::string > _mcFiles
Vector holding all MC file paths associated with this experiment.
Definition: Experiment.hxx:180
bool HasMCSample(const std::string &name)
Check whether the group has a given MC sample.
Definition: Experiment.cxx:87
void SetCurrentTree(const std::string &name)
Set the current configuration to all samples in the SampleGroup.
Definition: Experiment.cxx:132
std::string _tree
The current tree from the tree manager.
Definition: Experiment.hxx:177
std::string _name
What the user called this Experiment.
Definition: Experiment.hxx:165
DataSample * GetDataSample(const std::string &name)
Returns the data sample in group.
Definition: Experiment.hxx:121
std::vector< DataSample * > & GetDataSamples()
Get all MC samples in a group.
Definition: Experiment.hxx:47
void GetPOT(Float_t &POTdata, Float_t &POTmc)
Get the good data and MC POT for this sample group.
Definition: Experiment.cxx:98
DataSample * GetMCSample(const std::string &name, const std::string &name2)
Returns the by name a MC sample in agroup.
Definition: Experiment.hxx:124
std::map< std::string, DataSample * > & GetMCSamples(const std::string &name)
Returns all MC samples in a group.
Definition: Experiment.hxx:127
std::map< std::string, SampleGroup > _sampleGroups
Definition: Experiment.hxx:169
SampleGroup & GetSampleGroup(const std::string &name)
Get a single sample group by name.
Definition: Experiment.hxx:118
std::map< std::string, DataSample * > & GetMCSamples()
Get all MC samples in a group.
Definition: Experiment.hxx:50
std::string _filePath
Definition: Experiment.hxx:174
std::vector< std::string > GetDataFileVector()
Return pointer to vector of data files.
Definition: Experiment.hxx:157
void AddMCSample(const std::string &name, const std::string &file)
Add a new MC Sample to a group specifying its name (spill, sand, etc)
Definition: Experiment.cxx:48
std::string GetFilePath()
Definition: Experiment.hxx:142
void AddMCSamples(std::map< std::string, std::string > &mcFiles)
Add a set of MC Samples to a group specifying their names (spill, sand, etc)
Definition: Experiment.cxx:63
DataSample * GetDataSample()
Get the data sample in a group.
Definition: Experiment.hxx:38
void AddDataSample(const std::string &file)
Add a new Data Sample to a group (for the moment only one data sample can be added) ...
Definition: Experiment.cxx:34
DataSample * GetMCSample(const std::string &name)
Get a single MC sample in a group by name.
Definition: Experiment.hxx:44
std::vector< std::string > _dataFiles
Vector holding all data file paths associated with this experiment.
Definition: Experiment.hxx:182
std::vector< std::string > GetMCFileVector()
Return pointer to vector of mc files.
Definition: Experiment.hxx:154
const std::string & GetCurrentTree() const
Get the current configuration.
Definition: Experiment.hxx:148
std::map< std::string, SampleGroup > & GetSampleGroups()
Returns all sample groups.
Definition: Experiment.hxx:115