ATLAS Offline Software
Loading...
Searching...
No Matches
ToolsMeta.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8//
9// includes
10//
11
13
19#include <TSystem.h>
20#include <fstream>
21#include <sstream>
22#include <stdexcept>
23
24//
25// method implementations
26//
27
28namespace SH
29{
30 void readSusyMeta (const SampleHandler& sh, const std::string& inputFile)
31 {
32 TString myfile = inputFile;
33 gSystem->ExpandPathName (myfile);
34 std::ifstream file (myfile.Data());
35 std::string line;
36
37 if (!file)
38 throw std::runtime_error ("failed to read file: " + inputFile);
39
40 while (std::getline (file, line))
41 {
42 if (line[0] >= '0' && line[0] <= '9')
43 {
44 std::istringstream str (line);
45 std::string DSID, name;
46 float crossSection = 0, kFactor = 0, filterEfficiency = 0,
47 xsUncertainty = 0;
48
49 if (!(str >> DSID >> name >> crossSection >> kFactor >> filterEfficiency
50 >> xsUncertainty))
51 throw std::runtime_error ("readSusyMeta: failed to parse line: " + line);
52
53 std::string mydsid = "." + DSID + ".";
54 for (auto *sample : sh)
55 {
56 if (sample->name().find (mydsid) != std::string::npos)
57 {
58 double oldCrossSection
59 = sample->meta()->castDouble (MetaFields::crossSection);
60 sample->meta()->setDouble (MetaFields::crossSection, oldCrossSection + crossSection);
61 sample->meta()->setDouble (MetaFields::kfactor, kFactor);
62 sample->meta()->setDouble (MetaFields::filterEfficiency, filterEfficiency);
63 sample->meta()->setDouble (MetaFields::crossSectionRelUncertainty, xsUncertainty);
64 }
65 }
66 }
67 }
68 }
69
70 void readSusyMetaDir (const SampleHandler& sh, const std::string& inputDir)
71 {
72 TString mydir = inputDir;
73 gSystem->ExpandPathName (mydir);
74 void *dirp = 0;
75
76 try
77 {
78 dirp = gSystem->OpenDirectory (mydir.Data());
79 // rationale: OpenDirectory returns null for a missing/mistyped
80 // directory, and GetDirEntry/FreeDirectory tolerate a null
81 // handle, so this would otherwise silently read nothing; throw
82 // for consistency with readSusyMeta on a missing file.
83 if (dirp == nullptr)
84 throw std::runtime_error ("could not open directory: " + inputDir);
85 const char *file = 0;
86 while ((file = gSystem->GetDirEntry (dirp)))
87 {
88 std::string myfile = inputDir + "/" + file;
89 if (myfile.size() > 4 && myfile.substr (myfile.size()-4) == ".txt")
90 readSusyMeta (sh, myfile);
91 }
92 gSystem->FreeDirectory (dirp);
93 } catch (...)
94 {
95 gSystem->FreeDirectory (dirp);
96 throw;
97 }
98 }
99}
A class that manages a list of Sample objects.
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition PrunDriver.h:15
void readSusyMeta(const SampleHandler &sh, const std::string &inputFile)
effects: read the susy-meta-data file and add its information to the samples from the given sample ha...
Definition ToolsMeta.cxx:30
void readSusyMetaDir(const SampleHandler &sh, const std::string &inputDir)
effects: read an entire directory of susy-meta-data files and add their information to the samples fr...
Definition ToolsMeta.cxx:70
static const std::string crossSectionRelUncertainty
the relative uncertainty on the cross section
Definition MetaFields.h:53
static const std::string kfactor
the k-factor of the sample
Definition MetaFields.h:74
static const std::string crossSection
the cross section field
Definition MetaFields.h:50
static const std::string filterEfficiency
the filter efficiency of the sample
Definition MetaFields.h:77
TFile * file