1 #include "Experiment.hxx" 8 SampleGroup::SampleGroup(
const std::string& name){
16 SampleGroup::SampleGroup(
const std::string& name,
const std::string& dataFile, std::map<std::string, std::string>& mcFiles){
25 SampleGroup::SampleGroup(
const std::string& name,
DataSample* dataSample, std::map<std::string, DataSample*>& mcSamples){
44 _dataSamples.push_back(sample);
58 _mcSamples[name] = sample;
66 std::map< std::string, std::string>::iterator it;
67 for (it = mcFiles.begin(); it != mcFiles.end(); it++) {
68 std::string name = it->first;
69 std::string file = it->second;
78 std::map< std::string, DataSample*>::iterator it;
79 for (it = mcSamples.begin(); it != mcSamples.end(); it++) {
80 std::string name = it->first;
90 if (_mcSamples.find(name)==_mcSamples.end()){
91 std::cout <<
"MC sample '" << name <<
"' does not exists in SampleGroup '" << _name <<
"' !!!" << std::endl;
102 GetPOT(POTdata, POTmc, POTsand);
114 std::map< std::string, DataSample*>::iterator mit;
115 std::map< std::string, DataSample*>& mcSamples =
GetMCSamples();
117 for (mit = mcSamples.begin(); mit != mcSamples.end(); mit++) {
118 if((mit->first).find(
"and") != std::string::npos){
120 Float_t pot = sample->
GetPOT();
121 if(sample->
GetPOT() < 1e17) pot = pot*2.5e17;
126 POTmc += sample->
GetPOT();
135 std::vector<DataSample*>::iterator it;
136 for (it = _dataSamples.begin(); it != _dataSamples.end(); it++) {
137 (*it)->SetCurrentTree(name);
141 std::map< std::string, DataSample*>::iterator mit;
142 for (mit = _mcSamples.begin(); mit != _mcSamples.end(); mit++) {
162 std::map<std::string, std::string> files2;
164 _sampleGroups[
"group"] =
SampleGroup(
"group", file1, files2);
178 std::ifstream infile(configfile.c_str());
182 if (!getline(infile, line))
185 std::istringstream ssline(line);
186 std::vector<std::string> record;
190 if (!getline(ssline, token,
' '))
break;
191 record.push_back(token);
194 if (record.size() < 3) {
195 std::cerr <<
"Invalid format (should be sampleName dataName:dataFile mcName:mcFile [mcName2:mcFile2])" << std::endl;
196 std::cerr <<
"Saw: " << line << std::endl;
200 std::string groupName = record[0];
201 std::string dataFile = record[1].replace(0, record[1].find(
":") + 1,
"");
202 std::cout <<
"Adding group " << groupName <<
" with data file " << dataFile <<
" and MC files ";
204 std::map<std::string, std::string> mcFiles;
205 for (
unsigned int i = 2; i < record.size(); i++) {
206 std::string mcName = record[i];
207 std::string mcFile = record[i];
208 mcName = mcName.replace(mcName.find(
":"), mcName.size(),
"");
209 mcFile = mcFile.replace(0, mcFile.find(
":") + 1,
"");
210 mcFiles[mcName] = mcFile;
211 std::cout << mcFile <<
" ";
214 std::cout << std::endl;
216 _sampleGroups[groupName] =
SampleGroup(groupName, dataFile, mcFiles);
217 _filePath = dataFile;
225 if (_sampleGroups.find(name)==_sampleGroups.end()){
226 std::cout <<
"SampleGroup '" << name <<
"' does not exists in Experiment '" << _name <<
"' !!!" << std::endl;
236 std::map< std::string, DataSample*>& mcSamples = sampleGroup.
GetMCSamples();
237 for (std::map< std::string, DataSample*>::iterator it = mcSamples.begin(); it != mcSamples.end(); it++) {
238 _mcFiles.push_back(it->second->GetFilePath());
241 std::vector<DataSample*>& dataSamples = sampleGroup.
GetDataSamples();
242 for (std::vector<DataSample*>::iterator it2 = dataSamples.begin(); it2 != dataSamples.end(); it2++) {
243 _dataFiles.push_back((*it2)->GetFilePath());
251 AddSampleFilesToVector(sampleGroup);
252 _sampleGroups[name] = sampleGroup;
260 _sampleGroups[name] =
SampleGroup(name, dataFile, mcFiles);
261 AddSampleFilesToVector(_sampleGroups[name]);
262 _filePath = dataFile;
269 _sampleGroups[name] =
SampleGroup(name, dataSample, mcSamples);
270 AddSampleFilesToVector(_sampleGroups[name]);
278 std::map< std::string, SampleGroup >::iterator sit;
279 for (sit = _sampleGroups.begin(); sit != _sampleGroups.end(); sit++) {
293 std::cout <<
"---------------------------------------------" << std::endl;
294 std::cout <<
"-------- POT info for sample pair '"<< name <<
"' ---------" << std::endl;
295 std::cout <<
"---------------------------------------------" << std::endl;
297 std::cout <<
"data sample:" << std::endl;
299 std::cout << std::endl;
302 std::cout <<
"-------- MC samples -------------------------" << std::endl;
303 std::map< std::string, DataSample*>::iterator it;
305 std::map< std::string, DataSample*>& mcSamples = sampleGroup.
GetMCSamples();
306 for (it = mcSamples.begin(); it != mcSamples.end(); it++) {
307 std::string name = it->first;
310 std::cout <<
"MC sample: " << name << std::endl;
313 std::cout <<
"--------------------------------------------" << std::endl;
314 std::cout <<
"--------------------------------------------" << std::endl;
322 std::map< std::string, SampleGroup >::iterator sit;
324 for (sit = _sampleGroups.begin(); sit != _sampleGroups.end(); sit++) {
326 Float_t POTdata, POTmc;
327 sampleGroup.
GetPOT(POTdata, POTmc);
332 std::cout <<
"Warning: MC POT is zero! Setting ratio to 1." << std::endl;
334 }
else if (POTdata == 0) {
335 std::cout <<
"Warning: data POT is zero! Setting ratio to 1." << std::endl;
338 ratio = POTmc / POTdata;
341 std::cout << sit->first <<
": \t" << ratio <<
" \t(" << POTmc <<
" / " << POTdata <<
" )" << std::endl;
348 Float_t totalData = 0;
351 std::map< std::string, SampleGroup >::iterator sit;
353 for (sit = _sampleGroups.begin(); sit != _sampleGroups.end(); sit++) {
355 Float_t POTdata, POTmc;
356 sampleGroup.
GetPOT(POTdata, POTmc);
357 totalData += POTdata;
361 return totalMC / totalData;
369 std::map< std::string, SampleGroup >::iterator sit;
370 for (sit = _sampleGroups.begin(); sit != _sampleGroups.end(); sit++) {
373 std::vector<DataSample*>& dataSamples = sampleGroup.
GetDataSamples();
374 std::vector<DataSample*>::iterator it;
375 for (it = dataSamples.begin(); it != dataSamples.end(); it++) {
380 std::map< std::string, DataSample*>& mcSamples = sampleGroup.
GetMCSamples();
381 std::map< std::string, DataSample*>::iterator it2;
382 for (it2 = mcSamples.begin(); it2 != mcSamples.end(); it2++) {
383 std::string name = it2->first;
bool HasMCSample(const std::string &name)
Check whether the group has a given MC sample.
void DumpPOTRatios()
Dump total good POT for all sample pairs, and the POT ratio for each pair.
void SetCurrentTree(const std::string &name)
Set the current configuration to all samples in the SampleGroup.
std::vector< DataSample * > & GetDataSamples()
Get all MC samples in a group.
Experiment(const std::string &name)
void GetPOT(Float_t &POTdata, Float_t &POTmc)
Get the good data and MC POT for this sample group.
std::map< std::string, DataSample * > & GetMCSamples()
Get all MC samples in a group.
void Dump()
Dump info about the experiment.
void SetCurrentTree(Int_t index)
Sets the current tree provided the index.
void DumpPOT(const std::string &name)
Dump detailed POT information for a given sample pair.
void AddMCSample(const std::string &name, const std::string &file)
Add a new MC Sample to a group specifying its name (spill, sand, etc)
void SetCurrentTree(const std::string &name)
Set the current configuration to all samples in all SampleGroups.
bool HasSampleGroup(const std::string &name)
Checks if the Experiment has a SampleGroup with a given name.
void AddSampleFilesToVector(SampleGroup &sampleGroup)
Method to add file paths to the MC and Data vectors that store them.
void AddMCSamples(std::map< std::string, std::string > &mcFiles)
Add a set of MC Samples to a group specifying their names (spill, sand, etc)
DataSample * GetDataSample()
Get the data sample in a group.
void AddSampleGroup(const std::string &name, SampleGroup &sampleGroup)
void AddDataSample(const std::string &file)
Add a new Data Sample to a group (for the moment only one data sample can be added) ...
Float_t GetOverallPOTRatio()
Get the overall POT ratio.