12 static const std::vector<std::string> ToRemove {
"GeV",
"MeV",
"[",
"]",
"{",
"}",
"(",
")",
"#",
" " };
13 typedef std::pair<std::string,std::string> stringpair;
14 static const std::vector<stringpair> ToReplace { stringpair(
"-",
"minus"), stringpair(
".",
"p")};
28 ref_tool.addSubtool (*
this);
87 ref_tool.addSubtool (*
this);
92 if (syst_bit_map &
type) {
93 return std::make_shared<CollectionContainer>(ref_tool,
94 Nominal->retrieveContainer(
type).get(),
95 syst, syst_bit_map); }
98 return Nominal->retrieveContainer(
type);
123 return std::shared_ptr<CollectionContainer>();
127 Error(
"EffiCollection()",
"Consistency check for central file failed");
131 Error(
"EffiCollection()",
"Consistency check for calo file failed");
135 Error(
"EffiCollection()",
"Consistency check for forward file failed");
139 Error(
"EffiCollection()",
"Consistency check for low-pt file failed");
143 Error(
"EffiCollection()",
"Consistency check for low-pt calo file failed");
148 Error(
"EffiCollection()",
"Consistency check for LRT central file failed");
152 Error(
"EffiCollection()",
"Consistency check for LRT low-pt file failed");
180 m_syst_set = std::make_unique<CP::SystematicSet>();
181 size_t glob_sys =
m_ref_tool.getPosition(
this);
183 Error(
"EffiCollection()",
"Invalid position in the list of systematics. It seems that I'm not part of the referring ScaleFactorTool.");
194 for (
unsigned int b =
container->nBins() - 1; b > 0 ; --b){
214 const xAOD::TrackParticle* idtrack = mu.getXAODObject().trackParticle(xAOD::Muon::InnerDetectorTrackParticle);
217 Error(
"CollectionContainer",
"No information available to tell if the muon is LRT or standard. Either run MuonLRTMergingAlg to decorate with `isLRT` flag, or supply the patternRecoInfo for the original ID track.");
219 std::bitset<xAOD::NumberOfTrackRecoInfo> patternBitSet(patternAcc(*idtrack));
225 if (std::abs(
etaAcc(mu)) >= 2.5) {
235 }
else if (std::abs(
etaAcc(mu)) < 2.5) {
262 if (Cont !=
nullptr)
return Cont->
retrieve(RunNumber);
263 Warning(
"EffiCollection::retrieveSF()",
"Invalid muon");
267 unsigned int Nbins = 0;
295 if (!Cont)
return false;
312 return "EffiCollection::FileTypeName() - WARNING: Unknown EffiCollection::CollectionType!";
319 for (
const std::string& R : ToRemove) {
322 for (
const stringpair& R : ToReplace) {
327 Warning(
"EffiCollection::GetBinName()",
"Unknown bin %u",
bin);
329 return "UNKNOWN_BIN";
360 std::map<std::string, std::pair<unsigned int, unsigned int>>
map =
findPeriods(ref_tool);
361 for (
auto& period :
map) {
362 m_SF.push_back(std::make_shared<EfficiencyScaleFactor>(ref_tool,
fileName(ref_tool), period.first));
363 m_SF.back()->setFirstLastRun(period.second.first, period.second.second);
371 std::map<std::string, std::pair<unsigned int, unsigned int>>
map =
findPeriods(ref_tool);
372 for (
auto& period :
map) {
373 std::vector< std::shared_ptr<EfficiencyScaleFactor>>
::const_iterator itr = std::find_if( Nominal->m_SF.begin(),
375 [&period](
const std::shared_ptr<EfficiencyScaleFactor>&
a){
376 return a->coversRunNumber(period.second.first);
378 m_SF.push_back(std::make_shared<EfficiencyScaleFactor>(*itr, ref_tool,
fileName(ref_tool), period.first, syst_name, syst_bit_map));
379 m_SF.back()->setFirstLastRun(period.second.first, period.second.second);
384 std::string file_name =
fileName(ref_tool);
385 std::map<std::string, std::pair<unsigned int, unsigned int>>
map;
387 std::unique_ptr<TFile> fin (TFile::Open(file_name.c_str()));
388 if (!fin || !fin->IsOpen()) {
389 Error(
"CollectionContainer",
"Unable to open file %s", file_name.c_str());
393 fin->GetObject(
"LumiData", intree);
397 map[
"All"] = std::pair<unsigned int,unsigned int>(1, 999999);
399 std::string *period = 0;
400 unsigned int firstRun = 0;
401 unsigned int lastRun = 0;
402 intree->SetBranchAddress(
"Period", &period);
403 intree->SetBranchAddress(
"FirstRun", &firstRun);
404 intree->SetBranchAddress(
"LastRun", &lastRun);
405 for (
int t = 0; intree->GetEntry(t); t++) {
406 map[*period] = std::pair<unsigned int, unsigned int>(firstRun, lastRun);
421 Error(
"CollectionContainer",
"Could not retrieve any SFs from the input file");
425 for (std::vector< std::shared_ptr<EfficiencyScaleFactor>>
::const_iterator first_sf =
m_SF.begin() ; first_sf !=
m_SF.end(); ++first_sf) {
426 if (!(*first_sf)->CheckConsistency())
return false;
427 for (std::vector< std::shared_ptr<EfficiencyScaleFactor>>
::const_iterator second_sf =
m_SF.begin(); second_sf != first_sf; ++second_sf) {
428 if ( (*first_sf)->coversRunNumber( (*second_sf)->firstRun()) || (*first_sf)->coversRunNumber((*second_sf)->lastRun()) ||
429 (*second_sf)->coversRunNumber( (*first_sf)->firstRun()) || (*second_sf)->coversRunNumber((*first_sf)->lastRun())){
430 Error(
"CollectionContainer",
"Overlapping periods observed in file type %s. As run %i is in period %i - %i. Please check your SF file!",
437 std::sort(
m_SF.begin(),
m_SF.end(), [](
const std::shared_ptr<EfficiencyScaleFactor>&
a,
const std::shared_ptr<EfficiencyScaleFactor>& b){
438 return a->firstRun() < b->firstRun();});
443 for (
auto& period :
m_SF) {
444 if (period->coversRunNumber(RunNumber)) {
455 return (*
m_SF.begin()).get();
460 for ( std::shared_ptr<EfficiencyScaleFactor>& Period :
m_SF) {
468 return m_SF.empty() ? 0 : (*
m_SF.begin())->nBins();
471 return m_SF.empty() ? 0 : (*
m_SF.begin())->nOverFlowBins();
486 if (
m_SF.empty() )
return -1;
487 int bin = (*
m_SF.begin())->FindBinSF(mu);
497 if (
m_SF.empty())
return false;
498 return (*
m_SF.begin())->sysname(
false).empty();
501 if (
m_SF.empty())
return false;
502 return (*
m_SF.begin())->IsUpVariation();
505 if (
m_SF.empty())
return false;
506 return (*
m_SF.begin())->separateBinSyst();
509 if (
m_SF.empty())
return "UNKNOWN SYST";
510 return (*
m_SF.begin())->sysname(
false);
513 for (
auto& SF :
m_SF)
514 parentTool.addSubtool(*SF);
The collection container manages the time binning of a particular scale-factor map.
bool separateBinSyst() const
std::map< std::string, std::pair< unsigned int, unsigned int > > findPeriods(const MuonEfficiencyScaleFactors &ref_tool) const
unsigned int nOverFlowBins() const
Number of overflow bins in the map.
EffiCollection::CollectionType m_FileType
void addSubtoolsTo(columnar::ColumnarTool<> &parentTool)
std::vector< std::shared_ptr< EfficiencyScaleFactor > > m_SF
bool isBinInMap(unsigned int bin) const
Checks if the global bin number belongs to this map.
bool isOverFlowBin(int b) const
Check whether the bin is overflow or not.
std::string GetBinName(unsigned int Bin) const
Name of the i-th bin.
EffiCollection::CollectionType type() const
File type of the map.
bool isUpVariation() const
std::string fileName(const MuonEfficiencyScaleFactors &ref_tool) const
std::string sysname() const
Returns MUON_EFF_<sysname()>
int FindBinSF(const xAOD::Muon &mu) const
Returns the global bin number corresponding to the muon kinematics.
EfficiencyScaleFactor * m_currentSF
bool LoadPeriod(unsigned int RunNumber)
void SetGlobalOffSet(unsigned int OffSet)
Sets the global offset to align the order in the map into a global numbering scheme.
EfficiencyScaleFactor * retrieve(unsigned int RunNumer)
Retrieve the scale-factor map belonging to that particular run of data-taking.
unsigned int nBins() const
Number of bins of the map itself.
unsigned int m_binOffSet
Offset to translate between the bin-numbers in the bin numbers of each file against the global bin-nu...
unsigned int globalOffSet() const
Global offset of the bin numbers.
CollectionContainer(const MuonEfficiencyScaleFactors &ref_tool, EffiCollection::CollectionType FileType)
Nominal constructor... Only needs to know about it's type and the file to load.
bool SetSystematicBin(unsigned int Bin)
Activate this bin to run in the uncorrelated systematic mode.
bool CheckConsistency()
Consistency check of all scale-factor maps managed by the container instance.
columnar::MuonAccessor< columnar::RetypeColumn< double, float > > etaAcc
columnar::MuonAccessor< columnar::RetypeColumn< xAOD::Muon::MuonType, std::uint16_t > > muonTypeAcc
std::shared_ptr< CollectionContainer > m_forward_eff
bool isAffectedBySystematic(const SystematicVariation &variation) const
Returns whether the given set has variations affecting this Collection.
CollectionContainer * FindContainer(unsigned int bin) const
std::shared_ptr< CollectionContainer > m_central_eff
Make the collection container shared ptr to allow that a systematic EffiCollection can use the same c...
int getUnCorrelatedSystBin(const xAOD::Muon &mu) const
Returns the bin number from which the scale-factor of the muon is going to be retrieved....
CollectionContainer * FindLRTContainer(columnar::MuonId mu) const
bool IsLowPtBin(unsigned int Bin) const
Checks whether the i-th bin belongs to the low-pt map...
std::shared_ptr< CollectionContainer > m_calo_eff
std::shared_ptr< CollectionContainer > m_lrt_central_eff
columnar::MuonAccessor< columnar::RetypeColumn< double, float > > ptAcc
@ Central
The five different scale-factor maps.
bool CheckConsistency()
a consistency check of the scale-factor maps.
columnar::MuonAccessor< char > isLRTmuon
std::string GetBinName(unsigned int bin) const
Returns the global bin name conststucted from the axis titles and the bin borders.
EfficiencyScaleFactor * retrieveSF(const xAOD::Muon &mu, unsigned int RunNumber) const
return the correct SF type to provide, depending on eta and the author
static std::string FileTypeName(EffiCollection::CollectionType T)
bool IsForwardBin(unsigned int Bin) const
Checks whether the i-th bin belongs to the forward map.
std::shared_ptr< CollectionContainer > m_lowpt_central_eff
std::shared_ptr< CollectionContainer > m_lowpt_calo_eff
std::unique_ptr< SystematicSet > m_syst_set
The systematic set is returned back to the MuonEfficiencyScaleFactors instance to register The known ...
bool SetSystematicBin(unsigned int Bin)
If systematic decorrelation is activated then the user needs to loop manually over the syst bins.
unsigned int nBins() const
Get the number of all bins in the scale-factor maps including the overflow & underflow bins.
EffiCollection(MuonEfficiencyScaleFactors &ref_tool)
const MuonEfficiencyScaleFactors & m_ref_tool
std::shared_ptr< CollectionContainer > m_lrt_lowpt_central_eff
std::shared_ptr< CollectionContainer > retrieveContainer(CollectionType Type) const
Method to retrieve a container from the class ordered by a collection type This method is mainly used...
SystematicSet * getSystSet() const
Returns the systematic set affecting this collection.
std::string filename_HighEta() const
High-eta reconstruction scale-factors are not obtained by the means of are not obtained by the means ...
std::string filename_Calo() const
Reconstruction scale-factors have a dedicated map for calo-tag muons around |\eta|<0....
std::string filename_Central() const
The following methods are meant to propagate information from the central tool to the subtool managin...
std::string filename_LowPtCalo() const
CP::MuonEfficiencyType measurement() const
Returns the type of the measurement to be carried out... E.g. Reco/TTVA/Iso.
std::string filename_LowPt() const
Returns the scale-factor maps from a complementary scale-factor measurement using the J/Psi or Upsilo...
Class to wrap a set of SystematicVariations.
static SystematicVariation makeToyVariation(const std::string &basename, unsigned toyIndex, float toyScale)
constructor for toy systematics
SG::Accessor< T, ALLOC > Accessor
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
Select isolated Photons, Electrons and Muons.
std::string ReplaceExpInString(std::string str, const std::string &exp, const std::string &rep)
Replaces all expressions an string by something else.
ObjectId< ContainerId::muon > MuonId
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Muon_v1 Muon
Reference the current persistent version:
@ SiSpacePointsSeedMaker_LargeD0