ATLAS Offline Software
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 
14 #include <RootCoreUtils/Assert.h>
15 #include <RootCoreUtils/ThrowMsg.h>
19 #include <SampleHandler/Sample.h>
20 #include <TSystem.h>
21 #include <fstream>
22 #include <sstream>
23 
24 //
25 // method implementations
26 //
27 
28 namespace 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 }
SH::MetaFields::crossSectionRelUncertainty
static const std::string crossSectionRelUncertainty
the relative uncertainty on the cross section
Definition: MetaFields.h:61
SH::SampleHandler::iterator
std::vector< Sample * >::const_iterator iterator
the iterator to use
Definition: SampleHandler.h:475
checkFileSG.line
line
Definition: checkFileSG.py:75
SH::MetaFields::filterEfficiency
static const std::string filterEfficiency
the filter efficiency of the sample
Definition: MetaFields.h:85
SampleHandler.h
ToolsMeta.h
Assert.h
grl_maker.mydir
mydir
Definition: grl_maker.py:4
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
SH::readSusyMetaDir
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
MetaObject.h
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:113
CaloCondBlobAlgs_fillNoiseFromASCII.inputFile
string inputFile
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:17
SH::MetaFields::crossSection
static const std::string crossSection
the cross section field
Definition: MetaFields.h:58
RCU::Shell
Definition: ShellExec.cxx:28
file
TFile * file
Definition: tile_monitor.h:29
GetAllXsec.kFactor
kFactor
Definition: GetAllXsec.py:95
TestSUSYToolsAlg.inputDir
string inputDir
Definition: TestSUSYToolsAlg.py:74
GetAllXsec.DSID
tuple DSID
Definition: GetAllXsec.py:53
SH::MetaFields::kfactor
static const std::string kfactor
the k-factor of the sample
Definition: MetaFields.h:82
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
SH::readSusyMeta
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
MetaFields.h
ThrowMsg.h
xAOD::crossSection
crossSection
Definition: TruthEvent_v1.cxx:33
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
SH::SampleHandler
A class that manages a list of Sample objects.
Definition: SampleHandler.h:60
str
Definition: BTagTrackIpAccessor.cxx:11
SH
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition: PrunDriver.h:15
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
Sample.h