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
20#include <TSystem.h>
21#include <fstream>
22#include <sstream>
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 RCU_THROW_MSG ("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 RCU_THROW_MSG ("failed to parse line: " + line);
52
53 std::string mydsid = "." + DSID + ".";
54 for (SampleHandler::iterator sample = sh.begin(),
55 end = sh.end(); sample != end; ++ sample)
56 {
57 if ((*sample)->name().find (mydsid) != std::string::npos)
58 {
59 double oldCrossSection
60 = (*sample)->meta()->castDouble (MetaFields::crossSection);
61 (*sample)->meta()->setDouble (MetaFields::crossSection, oldCrossSection + crossSection);
62 (*sample)->meta()->setDouble (MetaFields::kfactor, kFactor);
63 (*sample)->meta()->setDouble (MetaFields::filterEfficiency, filterEfficiency);
64 (*sample)->meta()->setDouble (MetaFields::crossSectionRelUncertainty, xsUncertainty);
65 }
66 }
67 }
68 }
69 }
70
71 void readSusyMetaDir (const SampleHandler& sh, const std::string& inputDir)
72 {
73 TString mydir = inputDir;
74 gSystem->ExpandPathName (mydir);
75 void *dirp = 0;
76
77 try
78 {
79 dirp = gSystem->OpenDirectory (mydir.Data());
80 const char *file = 0;
81 while ((file = gSystem->GetDirEntry (dirp)))
82 {
83 std::string myfile = inputDir + "/" + file;
84 if (myfile.size() > 4 && myfile.substr (myfile.size()-4) == ".txt")
85 readSusyMeta (sh, myfile);
86 }
87 gSystem->FreeDirectory (dirp);
88 } catch (...)
89 {
90 gSystem->FreeDirectory (dirp);
91 throw;
92 }
93 }
94}
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:58
A class that manages a list of Sample objects.
std::vector< Sample * >::const_iterator iterator
the iterator to use
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:71
static const std::string crossSectionRelUncertainty
the relative uncertainty on the cross section
Definition MetaFields.h:61
static const std::string kfactor
the k-factor of the sample
Definition MetaFields.h:82
static const std::string crossSection
the cross section field
Definition MetaFields.h:58
static const std::string filterEfficiency
the filter efficiency of the sample
Definition MetaFields.h:85
TFile * file