ATLAS Offline Software
Classes | Macros | Functions | Variables
fbtTestBasics.cxx File Reference
#include <fstream>
#include <map>
#include <memory>
#include <getopt.h>
#include <TSystem.h>
#include <TError.h>
#include <TFile.h>
#include <TH1F.h>
#include "POOLRootAccess/TEvent.h"
#include "AsgTools/AnaToolHandle.h"
#include "xAODEventInfo/EventInfo.h"
#include "xAODEventInfo/EventAuxInfo.h"
#include "xAODEgamma/Electron.h"
#include "xAODMuon/Muon.h"
#include "AthContainers/Accessor.h"
#include "AsgMessaging/MessageCheck.h"
#include "AsgAnalysisInterfaces/IFakeBkgTool.h"
#include "AsgAnalysisInterfaces/ILinearFakeBkgTool.h"

Go to the source code of this file.

Classes

struct  Result
 

Macros

#define FBT_CHECK1(x, FAIL)
 
#define FBT_CHECK(x)   FBT_CHECK1(x, false)
 

Functions

bool successful (bool arg)
 
bool successful (int arg)
 
bool successful (const StatusCode &arg)
 
bool allTests ATLAS_NOT_THREAD_SAFE ()
 Install fatal handler with default options. More...
 
bool minimalTest ATLAS_NOT_THREAD_SAFE (const std::string &type, Result &result)
 
bool parallelJob ATLAS_NOT_THREAD_SAFE (const std::string &type, const std::string &saveAs)
 
template<class Interface = CP::IFakeBkgTool>
bool setup ATLAS_NOT_THREAD_SAFE (asg::AnaToolHandle< Interface > &tool, const std::string &type)
 mostly useful for athena, which will otherwise re-use the previous tool More...
 
template<class Interface = CP::IFakeBkgTool>
bool eventLoop ATLAS_NOT_THREAD_SAFE (asg::AnaToolHandle< Interface > &tool, Result &result)
 
bool addEventWeight ATLAS_NOT_THREAD_SAFE (asg::AnaToolHandle< CP::ILinearFakeBkgTool > &tool, Result &result)
 
bool addEventWeight ATLAS_NOT_THREAD_SAFE (asg::AnaToolHandle< CP::IFakeBkgTool > &tool, Result &result)
 
template<class Interface = CP::IFakeBkgTool>
bool fillResult ATLAS_NOT_THREAD_SAFE (asg::AnaToolHandle< Interface > &tool, Result &result)
 
int main ATLAS_NOT_THREAD_SAFE (int argc, char *argv[])
 

Variables

StoreGateSvcstore = nullptr
 
std::vector< std::string > config
 
std::string selection = ">=1T"
 
std::string process = ">=1F[T]"
 
bool readCPVariations = true
 
int eventOffset = 0
 
int nEvents = 48
 
std::string progressFile = ""
 
bool verbose = false
 

Macro Definition Documentation

◆ FBT_CHECK

#define FBT_CHECK (   x)    FBT_CHECK1(x, false)

Definition at line 47 of file fbtTestBasics.cxx.

◆ FBT_CHECK1

#define FBT_CHECK1 (   x,
  FAIL 
)
Value:
do { \
if(!successful(x)) { \
Error("fbtTestBasics", "failure encounted on l.%d", __LINE__); \
return FAIL; \
} \
} while(false)

Definition at line 40 of file fbtTestBasics.cxx.

Function Documentation

◆ ATLAS_NOT_THREAD_SAFE() [1/9]

bool allTests ATLAS_NOT_THREAD_SAFE ( )
inline

Install fatal handler with default options.

This is meant to be easy to call from python via ctypes.

Install fatal handler with default options.

getLorentzAngle() Read LorentzAngle from HIST and write out into local DB

getBSErrors() Read BSErrors from Monitoring HIST and write out into local DB

getEfficiency() Read Efficiency from Monitoring HIST and write out into local DB

getRawOccupancy() Read RawOccupancy from Monitoring HIST and write out into local DB

getNoiseOccupancy() Read NoiseOccupancy from HIST and write out into local DB

getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats

note: the declarations must be placed in the "good" order, otherwise the definitions of the SystematicVariations will be different than those obtained with readFromROOT()

Definition at line 112 of file fbtTestBasics.cxx.

113 {
114 
115  Result result0, result1, result2, result3, result4, result5;
116 
117  if(verbose) std::cout <<"\nWill do minimal test with CP::ApplyFakeFactor\n";
118  FBT_CHECK( readFromROOT() );
119  FBT_CHECK( minimalTest("CP::ApplyFakeFactor", result0) );
120 
121  if(verbose) std::cout <<"\nWill do minimal test with CP::AsymptMatrixTool\n";
122  FBT_CHECK( minimalTest("CP::AsymptMatrixTool", result1) );
123 
124  if(verbose) std::cout <<"\nWill do minimal test with CP::LhoodMM_tools\n";
125  FBT_CHECK( minimalTest("CP::LhoodMM_tools", result2) );
126 
127  if(verbose) std::cout <<"\nWill test loading efficiencies from XML\n";
128  FBT_CHECK( readFromXML() );
129  FBT_CHECK( minimalTest("CP::AsymptMatrixTool", result3) );
130  FBT_CHECK( readFromROOT() );
131  FBT_CHECK( result1 == result3 );
132 
133  if(verbose) std::cout <<"\nWill test getEventWeight()\n";
134  {
136  FBT_CHECK( setup(tool, "CP::AsymptMatrixTool") );
137  FBT_CHECK( eventLoop(tool, result4) );
138  if(verbose) result3.Print();
139  }
140  FBT_CHECK( result1 == result4 );
141 
142  if(verbose) std::cout <<"\nWill test parallel jobs and merging\n";
143  eventOffset = 0;
144  nEvents = 16;
145  FBT_CHECK( parallelJob("CP::LhoodMM_tools", "fbt_job1.root") );
146  eventOffset = 16;
147  FBT_CHECK( parallelJob("CP::LhoodMM_tools", "fbt_job2.root") );
148  eventOffset = 32;
149  FBT_CHECK( parallelJob("CP::LhoodMM_tools", "fbt_job3.root") );
150  eventOffset = 0;
151  FBT_CHECK( gSystem->Exec("hadd -f fbt_merged.root fbt_job*.root") == 0 );
152  {
154  progressFile = "fbt_merged.root";
155  FBT_CHECK( setup(tool, "CP::LhoodMM_tools") );
156  progressFile.clear();
157  FBT_CHECK( fillResult(tool, result5) );
158  }
159  FBT_CHECK(result2 == result5 );
160 
161  return true;
162 }

◆ ATLAS_NOT_THREAD_SAFE() [2/9]

bool addEventWeight ATLAS_NOT_THREAD_SAFE ( asg::AnaToolHandle< CP::IFakeBkgTool > &  tool,
Result result 
)

Definition at line 263 of file fbtTestBasics.cxx.

264 {
265  return true;
266 }

◆ ATLAS_NOT_THREAD_SAFE() [3/9]

bool addEventWeight ATLAS_NOT_THREAD_SAFE ( asg::AnaToolHandle< CP::ILinearFakeBkgTool > &  tool,
Result result 
)

Definition at line 246 of file fbtTestBasics.cxx.

247 {
248  FBT_CHECK( tool->applySystematicVariation({}) );
249  float y;
250  FBT_CHECK( tool->getEventWeight(y, selection, process) );
251  result.value += y;
252  result.statUp = sqrt(pow(result.statUp, 2) + y*y);
253  result.statDown = sqrt(pow(result.statDown, 2) + y*y);
254  for(auto& sysvar : tool->affectingSystematics())
255  {
256  FBT_CHECK( tool->applySystematicVariation({sysvar}) );
257  FBT_CHECK( tool->getEventWeight(y, selection, process) );
258  result.variations[sysvar] += y;
259  }
260  return true;
261 }

◆ ATLAS_NOT_THREAD_SAFE() [4/9]

template<class Interface = CP::IFakeBkgTool>
bool setup ATLAS_NOT_THREAD_SAFE ( asg::AnaToolHandle< Interface > &  tool,
const std::string &  type 
)

mostly useful for athena, which will otherwise re-use the previous tool

Definition at line 195 of file fbtTestBasics.cxx.

196 {
198  FBT_CHECK( tool.setProperty("InputFiles", config) );
199  FBT_CHECK( tool.setProperty("EnergyUnit", "GeV") );
200  FBT_CHECK( tool.setProperty("ConvertWhenMissing", true) );
201  FBT_CHECK( tool.setProperty("Selection", selection) );
202  FBT_CHECK( tool.setProperty("Process", process) );
203  if(progressFile.size())
204  {
205  FBT_CHECK( tool.setProperty("ProgressFileName", progressFile) );
206  FBT_CHECK( tool.setProperty("ProgressFileDirectory", "fakes") );
207  }
208  FBT_CHECK( tool.initialize() );
209  return true;
210 
211 }

◆ ATLAS_NOT_THREAD_SAFE() [5/9]

template<class Interface = CP::IFakeBkgTool>
bool eventLoop ATLAS_NOT_THREAD_SAFE ( asg::AnaToolHandle< Interface > &  tool,
Result result 
)

Definition at line 214 of file fbtTestBasics.cxx.

215 {
216  auto eventInfo = std::make_unique<xAOD::EventInfo>();
217  auto eventAuxInfo = std::make_unique<xAOD::EventAuxInfo>();
218  eventInfo->setStore(eventAuxInfo.get());
219  static const SG::Accessor<int> flagAcc("flag");
220  flagAcc(*eventInfo) = 1;
221  FBT_CHECK( store->record(std::move(eventInfo), "EventInfo") );
222  FBT_CHECK( store->record(std::move(eventAuxInfo), "EventInfoAux.") );
223 
225  auto e = std::make_unique<xAOD::Electron>();
226  e->makePrivateStore();
227  e->setCharge(1);
228  particles.push_back(static_cast<xAOD::IParticle*>(&*e));
229  static const SG::Accessor<char> TightAcc("Tight");
230  for(int i=eventOffset;i<nEvents+eventOffset;++i)
231  {
232  e->setP4((1 + (i%3))*1e4, 0., 0. ,0.511);
233  TightAcc(*e) = (i%4)? 0 : 1;
234  FBT_CHECK( tool->addEvent(particles) );
235  FBT_CHECK( addEventWeight(tool, result) );
236  }
237 
238 #ifdef XAOD_STANDALONE
239  store->clear();
240 #else
241  FBT_CHECK( store->clearStore(true) );
242 #endif
243  return true;
244 }

◆ ATLAS_NOT_THREAD_SAFE() [6/9]

template<class Interface = CP::IFakeBkgTool>
bool fillResult ATLAS_NOT_THREAD_SAFE ( asg::AnaToolHandle< Interface > &  tool,
Result result 
)

Definition at line 269 of file fbtTestBasics.cxx.

270 {
271  result.variations.clear();
272  FBT_CHECK( tool->getTotalYield(result.value, result.statUp, result.statDown) );
273  if(readCPVariations)
274  {
275  for(auto& sysvar : tool->affectingSystematics())
276  {
277  FBT_CHECK( tool->applySystematicVariation({sysvar}) );
278  float unused;
279  FBT_CHECK( tool->getTotalYield(result.variations[sysvar], unused, unused) );
280  }
281  }
282  if(verbose) result.Print();
283  return true;
284 }

◆ ATLAS_NOT_THREAD_SAFE() [7/9]

bool parallelJob ATLAS_NOT_THREAD_SAFE ( const std::string &  type,
const std::string &  saveAs 
)

Definition at line 173 of file fbtTestBasics.cxx.

174 {
176  FBT_CHECK( setup(tool, type) );
177  Result result;
178  FBT_CHECK( eventLoop(tool, result) );
179  std::unique_ptr<TFile> f(TFile::Open(saveAs.c_str(), "RECREATE"));
180  FBT_CHECK( !!f );
181  FBT_CHECK( tool->saveProgress(f->mkdir("fakes")) );
182  f->Close();
183  if(verbose)
184  {
185  float value, up, down;
186  FBT_CHECK( tool->getTotalYield(value, up, down) );
187  std::cout << "Parallel job stored intermediate yield " << value << " +" << up << " -" << down << std::endl;
188  }
189  return true;
190 }

◆ ATLAS_NOT_THREAD_SAFE() [8/9]

bool minimalTest ATLAS_NOT_THREAD_SAFE ( const std::string &  type,
Result result 
)

Definition at line 164 of file fbtTestBasics.cxx.

165 {
167  FBT_CHECK( setup(tool, type) );
168  FBT_CHECK( eventLoop(tool, result) );
169  FBT_CHECK( fillResult(tool, result) );
170  return true;
171 }

◆ ATLAS_NOT_THREAD_SAFE() [9/9]

int main ATLAS_NOT_THREAD_SAFE ( int  argc,
char *  argv[] 
)

Definition at line 84 of file fbtTestBasics.cxx.

85 {
86  for(int i=1;i<argc;++i)
87  {
88  std::string option = argv[i];
89  if(option=="-v" || option=="--verbose") verbose = true;
90  }
91 
92 #ifdef XAOD_STANDALONE
93  xAOD::Init("fbtTestBasics").ignore();
95  store = std::make_unique<xAOD::TStore>();
96  StatusCode::enableFailure();
97 #else
98  IAppMgrUI* app = POOL::Init();
100  FBT_CHECK1( event.evtStore().retrieve(), 1 );
101  store = event.evtStore().get();
102 #endif
103 
104  int returnCode = allTests() ? 0 : 1;
105 
106 #ifndef XAOD_STANDALONE
107  FBT_CHECK1( app->finalize(), 1 );
108 #endif
109  return returnCode;
110 }

◆ successful() [1/3]

bool successful ( bool  arg)

Definition at line 35 of file fbtTestBasics.cxx.

35 { return arg; }

◆ successful() [2/3]

bool successful ( const StatusCode &  arg)

Definition at line 37 of file fbtTestBasics.cxx.

37 { return arg == StatusCode::SUCCESS; }

◆ successful() [3/3]

bool successful ( int  arg)

Variable Documentation

◆ config

std::vector<std::string> config

Definition at line 74 of file fbtTestBasics.cxx.

◆ eventOffset

int eventOffset = 0

Definition at line 78 of file fbtTestBasics.cxx.

◆ nEvents

int nEvents = 48

Definition at line 79 of file fbtTestBasics.cxx.

◆ process

std::string process = ">=1F[T]"

Definition at line 76 of file fbtTestBasics.cxx.

◆ progressFile

std::string progressFile = ""

Definition at line 80 of file fbtTestBasics.cxx.

◆ readCPVariations

bool readCPVariations = true

Definition at line 77 of file fbtTestBasics.cxx.

◆ selection

std::string selection = ">=1T"

Definition at line 75 of file fbtTestBasics.cxx.

◆ store

StoreGateSvc* store = nullptr

Definition at line 71 of file fbtTestBasics.cxx.

◆ verbose

bool verbose = false

Definition at line 82 of file fbtTestBasics.cxx.

StoreGateSvc::record
StatusCode record(T *p2BRegistered, const TKEY &key)
Record an object with a key.
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:71
asg::AnaToolHandle
a modified tool handle that allows its owner to configure new tools from the C++ side
Definition: AnaToolHandle.h:34
get_generator_info.result
result
Definition: get_generator_info.py:21
Result::Print
void Print() const
Definition: fbtTestBasics.cxx:310
SG::Accessor< int >
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
systematicsTool.readFromROOT
def readFromROOT(filename, regexFilter=None, regexVeto=None)
Definition: systematicsTool.py:834
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
athena.value
value
Definition: athena.py:124
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:100
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
x
#define x
FBT_CHECK1
#define FBT_CHECK1(x, FAIL)
Definition: fbtTestBasics.cxx:39
successful
bool successful(bool arg)
Definition: fbtTestBasics.cxx:35
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
POOL::Init
IAppMgrUI * Init(const char *options="POOLRootAccess/basic.opts")
Bootstraps (creates and configures) the Gaudi Application with the provided options file.
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:29
FBT_CHECK
#define FBT_CHECK(x)
Definition: fbtTestBasics.cxx:46
POOL::TEvent::kClassAccess
@ kClassAccess
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:46
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
lumiFormat.i
int i
Definition: lumiFormat.py:85
PixelAthClusterMonAlgCfg.e4
e4
Definition: PixelAthClusterMonAlgCfg.py:332
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
readCPVariations
bool readCPVariations
Definition: fbtTestBasics.cxx:77
process
std::string process
Definition: fbtTestBasics.cxx:76
CalibCoolCompareRT.up
up
Definition: CalibCoolCompareRT.py:109
nEvents
int nEvents
Definition: fbtTestBasics.cxx:79
hist_file_dump.f
f
Definition: hist_file_dump.py:135
progressFile
std::string progressFile
Definition: fbtTestBasics.cxx:80
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
StoreGateSvc::clearStore
virtual StatusCode clearStore(bool forceRemove=false) override final
clear DataStore contents: called by the event loop mgrs
Definition: StoreGateSvc.cxx:450
selection
std::string selection
Definition: fbtTestBasics.cxx:75
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
verbose
bool verbose
Definition: fbtTestBasics.cxx:82
create_dcsc_inputs_sqlite.arg
list arg
Definition: create_dcsc_inputs_sqlite.py:48
python.InDetPriVxFinderConfig.setup
setup
Definition: InDetPriVxFinderConfig.py:124
POOL::TEvent
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:40
Result
Definition: fbtTestBasics.cxx:49
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
eventOffset
int eventOffset
Definition: fbtTestBasics.cxx:78
POOL::TEvent::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:60
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
unused
void unused(Args &&...)
Definition: VP1ExpertSettings.cxx:39
y
#define y
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:84
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31