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");
59 "Suppress the unrepresented-data WARNING when the"
60 " unrepresented fraction is below this value."
61 " Default 0 means always warn (preserving the"
62 " existing behaviour).");
63 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");
68 declareProperty(
"DataScaleFactorUP",
m_upVariation=1./0.99,
"Set to a value representing the 'up' fluctuation - will report a PRW_DATASF uncertainty to Systematic Registry");
69 declareProperty(
"DataScaleFactorDOWN",
m_downVariation=1./1.07,
"Set to a value representing the 'down' fluctuation - will report a PRW_DATASF uncertainty to Systematic Registry");
70 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");
71 declareProperty(
"PeriodAssignments",
m_customPeriods={284500,222222,324300,300000,324300,344495,310000,344496,367384,410000,422633,440613,450000,450360,461002,470000,473235,486706,495000,497924,999999},
"Specify period number assignments to run numbers ranges - this is usually an expert option");
72 declareProperty(
"GRLTool",
m_grlTool,
"If you provide a GoodRunsListSelectionTool, any information from lumicalc files will be automatically filtered" );
73 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)");
77 "The tool to compute the weight in the sumOfWeights" );
80 "The tool to compute the weight in the sumOfWeights" );
83#ifndef XAOD_STANDALONE
85 auto props = getProperties();
86 for( Gaudi::Details::PropertyBase* prop : props ) {
87 if( prop->name() !=
"OutputLevel" ) {
96#ifndef XAOD_STANDALONE
138 ATH_MSG_ERROR(
"Errr... what the!? You're trying to do both PRW_DATASF directions at the same time!!!??");
139 return StatusCode::FAILURE;
142 if(!
m_upTool) {
ATH_MSG_ERROR(
"Requested up variation of PRW_DATASF, but not configured to do this :-(");
return StatusCode::FAILURE; }
146 if(!
m_downTool) {
ATH_MSG_ERROR(
"Requested down variation of PRW_DATASF, but not configured to do this :-(");
return StatusCode::FAILURE; }
150 return StatusCode::SUCCESS;
159 if(out<0)
return out;
160 return out * ( (includeDataScaleFactor) ?
m_activeTool->GetDataScaleFactor() : 1.);
167 return actualInteractions;
170 if(correctedMu<0)
return correctedMu;
172 result = actualInteractions * (correctedMu/avg) * ( (includeDataScaleFactor) ?
m_activeTool->GetDataScaleFactor() : 1.);
187 std::vector<std::vector<int>> customPeriods;
189 if(customPeriods.size()==0 || customPeriods.back().size()==3) customPeriods.resize(customPeriods.size()+1);
190 customPeriods.back().push_back(num);
193 for(
auto& period : customPeriods) {
194 if(period.size()!=3) {
195 ATH_MSG_FATAL(
"Recevied period with " << period.size() <<
" numbers. Period configuration requires 3 numbers: periodNumber, startNumber, endNumber");
196 return StatusCode::FAILURE;
198 AddPeriod(period[0],period[1],period[2]);
208 for(
auto& period : customPeriods)
m_upTool->AddPeriod(period[0],period[1],period[2]);
216 for(
auto& period : customPeriods)
m_downTool->AddPeriod(period[0],period[1],period[2]);
229#ifndef XAOD_STANDALONE
232 CHECK( histSvc.retrieve() );
246 for(
unsigned int j=0;j<
m_prwFiles.size();j++) {
259 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!");
278 TString myTrigger = (myFile.Contains(
':')) ? TString(myFile(myFile.Last(
':')+1,myFile.Length()-myFile.Last(
':'))) : TString(
"None");
279 myFile = (myFile.Contains(
':')) ? TString(myFile(0,myFile.Last(
':'))) : myFile;
282 if(
file==
"") {
ATH_MSG_ERROR(
"Unable to find the Lumicalc file: " << myFile);
return StatusCode::FAILURE; }
291 if( registry.
registerSystematics( *
this ) != StatusCode::SUCCESS )
return StatusCode::FAILURE;
298 if (
sc != StatusCode::SUCCESS) {
307 return StatusCode::SUCCESS;
312#ifndef XAOD_STANDALONE
315 std::string nameWithoutParent = this->
name().substr(this->
name().
find(
".")+1);
316 TString fileName = TString::Format(
"%s.prw.root", nameWithoutParent.c_str());
322 CHECK( histSvc.retrieve() );
325 TTree *outTreeData=0;
326 Int_t channel = 0;UInt_t runNumber = 0;
327 std::vector<UInt_t> pStarts;
328 std::vector<UInt_t> pEnds;
329 std::vector<UInt_t>* pStartsPtr = &pStarts;
330 std::vector<UInt_t>* pEndsPtr = &pEnds;
331 Char_t histName[150];
336 if(!period.second)
continue;
337 if(period.first<0)
continue;
338 if(period.first != period.second->id)
continue;
339 runNumber = period.first;
342 if(period.second->subPeriods.size()==0) {
343 pStarts.push_back(period.second->start); pEnds.push_back(period.second->end);
346 for(
auto subp : period.second->subPeriods) {
347 pStarts.push_back(subp->start); pEnds.push_back(subp->end);
350 for(
auto& inHist : period.second->inputHists) {
351 channel = inHist.first;
352 TH1* hist = inHist.second.release();
353 strncpy(histName,hist->GetName(),
sizeof(histName)-1);
354 CHECK( histSvc->regHist(TString::Format(
"/%s/PileupReweighting/%s",
m_configStream.c_str(),hist->GetName()).Data(),hist) );
356 outTreeMC =
new TTree(
"MCPileupReweighting",
"MCPileupReweighting");
357 outTreeMC->Branch(
"Channel",&channel);
358 outTreeMC->Branch(
"RunNumber",&runNumber);
359 outTreeMC->Branch(
"PeriodStarts",&pStartsPtr);
360 outTreeMC->Branch(
"PeriodEnds",&pEndsPtr);
361 outTreeMC->Branch(
"HistName",&histName,
"HistName/C");
362 CHECK( histSvc->regTree(TString::Format(
"/%s/PileupReweighting/%s",
m_configStream.c_str(),outTreeMC->GetName()).Data(),outTreeMC) );
370 runNumber =
run.first;
371 if(
run.second.inputHists.find(
"None")==
run.second.inputHists.end())
continue;
373 TH1* hist =
run.second.inputHists[
"None"].release();
374 strncpy(histName,hist->GetName(),
sizeof(histName)-1);
375 CHECK( histSvc->regHist(TString::Format(
"/%s/PileupReweighting/%s",
m_configStream.c_str(),hist->GetName()).Data(),hist) );
377 outTreeData =
new TTree(
"DataPileupReweighting",
"DataPileupReweighting");
378 outTreeData->Branch(
"RunNumber",&runNumber);
379 outTreeData->Branch(
"HistName",&histName,
"HistName/C");
380 CHECK( histSvc->regTree(TString::Format(
"/%s/PileupReweighting/%s",
m_configStream.c_str(),outTreeData->GetName()).Data(),outTreeData) );
385 Info(
"WriteToFile",
"Successfully generated config file to stream: %s",
m_configStream.c_str());
386 Info(
"WriteToFile",
"Happy Reweighting :-)");
392 std::string nameWithoutParent = this->
name().substr(this->
name().
find(
".")+1);
393 TString fileName = TString::Format(
"%s.prw.root", nameWithoutParent.c_str());
400 return StatusCode::SUCCESS;
433 else return tool->GetRandomRunNumber( eventInfo.
runNumber() );
451 case 222510:
case 222525:
case 222526:
case 284500:
UsePeriodConfig(
"MC15");
break;
466 return StatusCode::SUCCESS;
471 if(!corrAvgIntPerXingDec.isAvailable(eventInfo))
473 return StatusCode::SUCCESS;
477 if(!corrAvgIntPerXingDec.isAvailable(eventInfo))
483 if(!rrnDec.isAvailable(eventInfo)){
489 if(!rlbnDec.isAvailable(eventInfo))
492 if(!prwHashDec.isAvailable(eventInfo))
493 prwHashDec(eventInfo) =
getPRWHash( eventInfo );
501 ATH_MSG_VERBOSE(
"PileupWeight = " << puWeightAcc(eventInfo) <<
" RandomRunNumber = " << rrnAcc(eventInfo) <<
" RandomLumiBlockNumber = " << rlbnAcc(eventInfo));
503 return StatusCode::SUCCESS;
509 ATH_MSG_WARNING(
"Requesting Data Weight is not intended for simulated events. Returning 1.");
517 ATH_MSG_ERROR(
"Unrecognised run+lumiblock number (" << eventInfo.
runNumber() <<
"," << eventInfo.
lumiBlock() <<
") ... please ensure your lumicalc files are complete! Returning 1.");
528 unsigned int randomRunNum = rrnAcc.
withDefault (eventInfo, 0);
529 if (randomRunNum == 0) {
532 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_unrepDataWarningThreshold
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.
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.
SG::Decorator< T, ALLOC > Decorator
Helper class to provide type-safe access to aux data, specialized for JaggedVecElt.
static const unsigned int allowResurrectedDecision
static const unsigned int Physics
EventInfo_v1 EventInfo
Definition of the latest event info version.
int run(int argc, char *argv[])