20#ifndef XAOD_STANDALONE
21#include "GaudiKernel/ITHistSvc.h"
47#ifndef XAOD_STANDALONE
48 declareProperty(
"ConfigOutputStream",
m_configStream=
"",
"When creating PRW config files, this is the THistSvc stream it goes into. If blank, it wont write this way");
54 declareProperty(
"Prefix",
m_prefix=
"",
"Prefix to attach to all decorations ... only used in the 'apply' method");
57 declareProperty(
"UseMultiPeriods",
m_useMultiPeriods=
true,
"If true, will try to treat each mc runNumber in a single mc dataset (channel) as a modelling a distinct period of data taking");
62 declareProperty(
"DataScaleFactorUP",
m_upVariation=1./0.99,
"Set to a value representing the 'up' fluctuation - will report a PRW_DATASF uncertainty to Systematic Registry");
63 declareProperty(
"DataScaleFactorDOWN",
m_downVariation=1./1.07,
"Set to a value representing the 'down' fluctuation - will report a PRW_DATASF uncertainty to Systematic Registry");
64 declareProperty(
"VaryRandomRunNumber",
m_varyRunNumber=
false,
"If true, then when doing systematic variations, RandomRunNumber will fluctuate as well. Off by default as believed to lead to overestimated uncertainties");
65 declareProperty(
"PeriodAssignments",
m_customPeriods={284500,222222,324300,300000,324300,344495,310000,344496,367384,410000,422633,440613,450000,450360,461002,470000,472553,999999},
"Specify period number assignments to run numbers ranges - this is usually an expert option");
66 declareProperty(
"GRLTool",
m_grlTool,
"If you provide a GoodRunsListSelectionTool, any information from lumicalc files will be automatically filtered" );
67 declareProperty(
"TrigDecisionTool",
m_tdt,
"When using the getDataWeight method, the TDT will be used to check decisions before prescale. Alternatively do expert()->SetTriggerBit('trigger',0) to flag which triggers are not fired before prescale (assumed triggers are fired if not specified)");
71 "The tool to compute the weight in the sumOfWeights" );
74 "The tool to compute the weight in the sumOfWeights" );
77#ifndef XAOD_STANDALONE
79 auto props = getProperties();
80 for( Gaudi::Details::PropertyBase* prop : props ) {
81 if( prop->name() !=
"OutputLevel" ) {
90#ifndef XAOD_STANDALONE
132 ATH_MSG_ERROR(
"Errr... what the!? You're trying to do both PRW_DATASF directions at the same time!!!??");
133 return StatusCode::FAILURE;
136 if(!
m_upTool) {
ATH_MSG_ERROR(
"Requested up variation of PRW_DATASF, but not configured to do this :-(");
return StatusCode::FAILURE; }
140 if(!
m_downTool) {
ATH_MSG_ERROR(
"Requested down variation of PRW_DATASF, but not configured to do this :-(");
return StatusCode::FAILURE; }
144 return StatusCode::SUCCESS;
153 if(out<0)
return out;
154 return out * ( (includeDataScaleFactor) ?
m_activeTool->GetDataScaleFactor() : 1.);
162 if(correctedMu<0)
return correctedMu;
176 std::vector<std::vector<int>> customPeriods;
178 if(customPeriods.size()==0 || customPeriods.back().size()==3) customPeriods.resize(customPeriods.size()+1);
179 customPeriods.back().push_back(num);
182 for(
auto& period : customPeriods) {
183 if(period.size()!=3) {
184 ATH_MSG_FATAL(
"Recevied period with " << period.size() <<
" numbers. Period configuration requires 3 numbers: periodNumber, startNumber, endNumber");
185 return StatusCode::FAILURE;
187 AddPeriod(period[0],period[1],period[2]);
197 for(
auto& period : customPeriods)
m_upTool->AddPeriod(period[0],period[1],period[2]);
205 for(
auto& period : customPeriods)
m_downTool->AddPeriod(period[0],period[1],period[2]);
218#ifndef XAOD_STANDALONE
221 CHECK( histSvc.retrieve() );
235 for(
unsigned int j=0;j<
m_prwFiles.size();j++) {
248 ATH_MSG_INFO(
"Setting up without a PRW config file, but with period config " <<
m_usePeriodConfig <<
". You will only be able to use random run number and data weight functionality... no reweighting!");
267 TString myTrigger = (myFile.Contains(
':')) ? TString(myFile(myFile.Last(
':')+1,myFile.Length()-myFile.Last(
':'))) : TString(
"None");
268 myFile = (myFile.Contains(
':')) ? TString(myFile(0,myFile.Last(
':'))) : myFile;
271 if(
file==
"") {
ATH_MSG_ERROR(
"Unable to find the Lumicalc file: " << myFile);
return StatusCode::FAILURE; }
280 if( registry.
registerSystematics( *
this ) != StatusCode::SUCCESS )
return StatusCode::FAILURE;
287 if (
sc != StatusCode::SUCCESS) {
296 return StatusCode::SUCCESS;
301#ifndef XAOD_STANDALONE
304 std::string nameWithoutParent = this->
name().substr(this->
name().
find(
".")+1);
305 TString fileName = TString::Format(
"%s.prw.root", nameWithoutParent.c_str());
311 CHECK( histSvc.retrieve() );
314 TTree *outTreeData=0;
315 Int_t channel = 0;UInt_t runNumber = 0;
316 std::vector<UInt_t> pStarts;
317 std::vector<UInt_t> pEnds;
318 std::vector<UInt_t>* pStartsPtr = &pStarts;
319 std::vector<UInt_t>* pEndsPtr = &pEnds;
320 Char_t histName[150];
325 if(!period.second)
continue;
326 if(period.first<0)
continue;
327 if(period.first != period.second->id)
continue;
328 runNumber = period.first;
331 if(period.second->subPeriods.size()==0) {
332 pStarts.push_back(period.second->start); pEnds.push_back(period.second->end);
335 for(
auto subp : period.second->subPeriods) {
336 pStarts.push_back(subp->start); pEnds.push_back(subp->end);
339 for(
auto& inHist : period.second->inputHists) {
340 channel = inHist.first;
341 TH1* hist = inHist.second.release();
342 strncpy(histName,hist->GetName(),
sizeof(histName)-1);
343 CHECK( histSvc->regHist(TString::Format(
"/%s/PileupReweighting/%s",
m_configStream.c_str(),hist->GetName()).Data(),hist) );
345 outTreeMC =
new TTree(
"MCPileupReweighting",
"MCPileupReweighting");
346 outTreeMC->Branch(
"Channel",&channel);
347 outTreeMC->Branch(
"RunNumber",&runNumber);
348 outTreeMC->Branch(
"PeriodStarts",&pStartsPtr);
349 outTreeMC->Branch(
"PeriodEnds",&pEndsPtr);
350 outTreeMC->Branch(
"HistName",&histName,
"HistName/C");
351 CHECK( histSvc->regTree(TString::Format(
"/%s/PileupReweighting/%s",
m_configStream.c_str(),outTreeMC->GetName()).Data(),outTreeMC) );
359 runNumber =
run.first;
360 if(
run.second.inputHists.find(
"None")==
run.second.inputHists.end())
continue;
362 TH1* hist =
run.second.inputHists[
"None"].release();
363 strncpy(histName,hist->GetName(),
sizeof(histName)-1);
364 CHECK( histSvc->regHist(TString::Format(
"/%s/PileupReweighting/%s",
m_configStream.c_str(),hist->GetName()).Data(),hist) );
366 outTreeData =
new TTree(
"DataPileupReweighting",
"DataPileupReweighting");
367 outTreeData->Branch(
"RunNumber",&runNumber);
368 outTreeData->Branch(
"HistName",&histName,
"HistName/C");
369 CHECK( histSvc->regTree(TString::Format(
"/%s/PileupReweighting/%s",
m_configStream.c_str(),outTreeData->GetName()).Data(),outTreeData) );
374 Info(
"WriteToFile",
"Successfully generated config file to stream: %s",
m_configStream.c_str());
375 Info(
"WriteToFile",
"Happy Reweighting :-)");
381 std::string nameWithoutParent = this->
name().substr(this->
name().
find(
".")+1);
382 TString fileName = TString::Format(
"%s.prw.root", nameWithoutParent.c_str());
389 return StatusCode::SUCCESS;
422 else return tool->GetRandomRunNumber( eventInfo.
runNumber() );
440 case 222510:
case 222525:
case 222526:
case 284500:
UsePeriodConfig(
"MC15");
break;
455 return StatusCode::SUCCESS;
462 return StatusCode::SUCCESS;
482 prwHashDec(eventInfo) =
getPRWHash( eventInfo );
490 ATH_MSG_VERBOSE(
"PileupWeight = " << puWeightAcc(eventInfo) <<
" RandomRunNumber = " << rrnAcc(eventInfo) <<
" RandomLumiBlockNumber = " << rlbnAcc(eventInfo));
492 return StatusCode::SUCCESS;
498 ATH_MSG_WARNING(
"Requesting Data Weight is not intended for simulated events. Returning 1.");
506 ATH_MSG_ERROR(
"Unrecognised run+lumiblock number (" << eventInfo.
runNumber() <<
"," << eventInfo.
lumiBlock() <<
") ... please ensure your lumicalc files are complete! Returning 1.");
517 unsigned int randomRunNum = rrnAcc.
withDefault (eventInfo, 0);
518 if (randomRunNum == 0) {
521 if(!mu_dependent)
return m_activeTool->GetPrescaleWeight(randomRunNum, trigger);
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
Helper class to provide constant type-safe access to aux data.
#define CHECK(...)
Evaluate an expression and check for errors.
Helper class to provide type-safe access to aux data.
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
bool msgLvl(const MSG::Level lvl) const
This module implements the central registry for handling systematic uncertainties with CP tools.
static SystematicRegistry & getInstance()
Get the singleton instance of the registry for the curren thread.
StatusCode registerSystematics(const IReentrantSystematicsTool &tool)
effects: register all the systematics from the tool
Class to wrap a set of SystematicVariations.
const_iterator end() const
description: const iterator to the end of the set
iterator find(const SystematicVariation &sys) const
description: find an element in the set
Double_t GetLumiBlockIntegratedLumi(Int_t runNumber, UInt_t lb)
get integrated lumi for specific run and lumiblock number .
Int_t Fill(Int_t runNumber, Int_t channelNumber, Float_t w, Float_t x, Float_t y=0.)
Int_t WriteToFile(const TString &filename="")
virtual bool passTriggerBeforePrescale(const TString &trigger) const
std::map< UInt_t, Run > m_runs
void EnableDebugging(Bool_t in)
Indicate if additional debugging information should be output.
Int_t UsePeriodConfig(const TString &configName)
use a hardcoded period configuration
void SetDefaultChannel(Int_t channel, Int_t mcRunNumber=-1)
Set which channel should be used as a default when specific mc channel distributions cannot be found.
std::map< Int_t, Period * > m_periods
std::unique_ptr< TH1 > m_emptyHistogram
the empty histogram used for this weight... effectively holds the configuration of the binning
void PrintInfo(Bool_t in)
disable info
Int_t AddLumiCalcFile(const TString &fileName, const TString &trigger="None")
Float_t m_dataScaleFactorX
Int_t AddConfigFile(const TString &fileName)
Float_t GetLumiBlockMu(Int_t runNumber, UInt_t lb)
get the lumiblock mu, useful for 'updating' the mu coming from data to account for new lumitags
TPileupReweighting(const char *name="TPileupReweighting")
Standard constructor.
Bool_t m_ignoreBadChannels
std::string m_prwFilesPathPrefix
void IgnoreConfigFilePeriods(Bool_t in)
Should the tool ignore period assignments encoded in config file.
Double_t m_unrepDataTolerance
Int_t m_unrepresentedDataAction
Helper class to provide constant type-safe access to aux data.
const_reference_type withDefault(const ELT &e, const T &deflt) const
Fetch the variable for one element, as a const reference, with a default.
Helper class to provide type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
SG::auxid_t auxid() const
Return the aux id for this variable.
uint32_t lumiBlock() const
The current event's luminosity block number.
bool eventType(EventType type) const
Check for one particular bitmask value.
float averageInteractionsPerCrossing() const
Average interactions per crossing for all BCIDs - for out-of-time pile-up.
float actualInteractionsPerCrossing() const
Average interactions per crossing for the current BCID - for in-time pile-up.
@ IS_SIMULATION
true: simulation, false: data
uint32_t runNumber() const
The current event's run number.
uint32_t mcChannelNumber() const
The MC generator's channel number.
uint64_t eventNumber() const
The current event's event number.
std::string find(const std::string &s)
return a remapped string
Select isolated Photons, Electrons and Muons.
static const unsigned int allowResurrectedDecision
static const unsigned int Physics
EventInfo_v1 EventInfo
Definition of the latest event info version.