ATLAS Offline Software
Loading...
Searching...
No Matches
CP::TPileupReweighting Class Reference

#include <TPileupReweighting.h>

Inheritance diagram for CP::TPileupReweighting:

Classes

struct  CompositeTrigger
struct  Period
struct  Run

Public Member Functions

 TPileupReweighting (const char *name="TPileupReweighting")
 Standard constructor.
Int_t UsePeriodConfig (const TString &configName)
 use a hardcoded period configuration
Int_t SetBinning (Int_t nbinsx, Double_t *xbins, Int_t nbinsy=0, Double_t *ybins=0)
 Add a histogram binning config.
Int_t SetUniformBinning (Int_t nbinsx, Double_t xlow, Double_t xup, Int_t nbinsy=0, Double_t ylow=0, Double_t yup=0)
Int_t SetBinning (TH1 *hist)
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.
Int_t GetDefaultChannel (Int_t mcRunNumber=-1)
Double_t GetIntegratedLumi (const TString &trigger="")
 total luminosity loaded and accepted by the tool (in inverse pb)
Double_t GetNumberOfEvents (Int_t channel)
 totalMC maps should also hold the total number of entries for each channel
Double_t GetSumOfEventWeights (Int_t channel)
void RemapPeriod (Int_t periodNumber1, Int_t periodNumber2)
 Combine two period numbers.
Double_t GetIntegratedLumiFraction (Int_t periodNumber, UInt_t start, UInt_t end)
 return fraction of lumi assigned to periodNumber (or mcRunNumber) that is between start and end data run numbers
Double_t GetIntegratedLumiFraction (Int_t periodNumber, Double_t mu, UInt_t start, UInt_t end)
 return fraction of lumi assigned to periodNumber (or mcRunNumber) with given mu, that is between start and end data run numbers
Double_t GetIntegratedLumi (UInt_t start, UInt_t end)
 get the amount of integrated lumi between the two given runs
Double_t GetIntegratedLumi (Int_t periodNumber, UInt_t start, UInt_t end)
 similar to above, but for only the given mcRunNumber/periodNumber
Double_t GetLumiBlockIntegratedLumi (Int_t runNumber, UInt_t lb)
 get integrated lumi for specific run and lumiblock number .
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
void DisableWarnings (Bool_t in)
 Indicate if warnings should be suppressed.
void EnableDebugging (Bool_t in)
 Indicate if additional debugging information should be output.
void PrintInfo (Bool_t in)
 disable info
void SetUnrepresentedDataAction (Int_t action, Double_t tolerance=0.05)
 Set how to handle configurations where some of your data has no corresponding mc to describe it 0=Default (Throw exception), 1=Subtract lumi from normalizations (i.e.
Double_t GetUnrepresentedDataFraction (Int_t periodNumber, Int_t channel)
 return the unrepresented data fraction in a given channel .
Float_t GetUnrepresentedDataWeight (Int_t periodNumber, Int_t channel)
Bool_t IsUnrepresentedData (Int_t runNumber, Float_t x, Float_t y=0.)
void IgnoreConfigFilePeriods (Bool_t in)
 Should the tool ignore period assignments encoded in config file.
Int_t AddPeriod (Int_t periodNumber, UInt_t start, UInt_t end)
 Assign an mc RunNumber to a data period.
Int_t GetFirstFoundPeriodNumber (UInt_t runNumber)
 Get the first period number with the data run number contained - assume all periods are disconnected for this to be useful.
void SetDataScaleFactors (Float_t x, Float_t y=1.)
 Scale the LumiMetaData mu values by this factor.
void SetMCScaleFactors (Float_t x, Float_t y=1.)
Int_t AddConfigFile (const TString &fileName)
Int_t AddLumiCalcFile (const TString &fileName, const TString &trigger="None")
Int_t AddMetaDataFile (const TString &fileName, const TString &channelBranchName="mc_channel_number")
Bool_t RemoveChannel (int chanNum)
 Removes a channel from the inputs ... this is for experts only.
Int_t Initialize ()
 Initialize this class once before the event loop starts If distribution information is provided, it is assumed to be for the standard pileup reweighting.
Float_t GetCombinedWeight (Int_t periodNumber, Int_t channelNumber, Float_t x, Float_t y=0.)
Float_t GetPeriodWeight (Int_t periodNumber, Int_t channelNumber)
Float_t GetPrimaryWeight (Int_t periodNumber, Int_t channelNumber, Float_t x)
Float_t GetSecondaryWeight (Int_t periodNumber, Int_t channelNumber, Float_t x, Float_t y)
Double_t GetMetaData (const TString &metadataName, Int_t channelNumber)
TTree * GetMetaDataTree ()
 combines loaded metadata with channel sumsofweights and entry counts
Int_t GenerateMetaDataFile (const TString &fileName, const TString &channelBranchName="mc_channel_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="")
Int_t WriteToFile (TFile *outFile)
ULong64_t GetPRWHash (Int_t periodNumber, Int_t channelNumber, Float_t x, Float_t y=0.)
Bool_t MakeWeightTree (TString channelNumbers, TString outFile, TString hashBranch="PRWHash", TString weightBranch="PileupWeight")
void SetRandomSeed (int seed)
int GetRandomSeed ()
UInt_t GetRandomRunNumber (Int_t mcRunNumber)
 Gets a random data run number according to the integrated lumi distribution associated to this mcRunNumber.
UInt_t GetRandomRunNumber (Int_t mcRunNumber, Double_t mu)
 Get random run number according to integrated lumi distribution for the given mu value (uses the binning of the mu histogram).
Int_t GetRandomPeriodNumber (Int_t mcRunNumber)
 Get random period number from the sub-periods assigned to this run number.
UInt_t GetRandomLumiBlockNumber (UInt_t runNumber)
 Get a random lumi block from the run number given.
Int_t Merge (TCollection *coll)
std::vector< intGetPeriodNumbers () const
TH1 * GetInputHistogram (Int_t channelNumber, Int_t periodNumber)
TH1 * GetPrimaryDistribution (Int_t channelNumber, Int_t periodNumber)
TH1 * GetPrimaryTriggerDistribution (const TString &trigger, Int_t periodNumber, long triggerBits)
Double_t GetDataWeight (Int_t runNumber, const TString &trigger, Double_t x, bool run_dependent=false)
 Method for weighting data to account for prescales and mu bias.
Double_t GetDataWeight (Int_t runNumber, const TString &trigger)
Double_t GetPrescaleWeight (Int_t runNumber, const TString &trigger, Double_t x, bool run_dependent=false)
 Method for prescaling MC to account for prescales in data.
Double_t GetPrescaleWeight (Int_t runNumber, const TString &trigger)
Bool_t IsInitialized ()
Int_t AddDistribution (TH1 *hist, Int_t runNumber, Int_t channelNumber)
void ResetCountingMode ()
 This method is DEFINITELY EXPERT USE ONLY.
void SetParentTool (TPileupReweighting *tool)
Float_t GetDataScaleFactor () const
void SetTriggerBit (const TString &trigger, bool in=true)
void ResetTriggerBits ()
double GetRunAverageMu (int run)
void PrintPeriods ()
std::map< UInt_t, Run > & GetRunMap ()
void CopyProperties (const TPileupReweighting *in)

Protected Member Functions

virtual bool runLbnOK (Int_t, Int_t)
virtual bool passTriggerBeforePrescale (const TString &trigger) const
Int_t GetNearestGoodBin (Int_t thisMCRunNumber, Int_t bin)
Int_t IsBadBin (Int_t thisMCRunNumber, Int_t bin)
std::unique_ptr< TH1 > CloneEmptyHistogram (Int_t runNumber, Int_t channelNumber)
void normalizeHistogram (TH1 *histo)
 Normalize histograms.
void AddDistributionTree (TTree *tree, TFile *file)
void CalculatePrescaledLuminosityHistograms (const TString &trigger, int run_dependent=0)
std::unique_ptr< CompositeTriggermakeTrigger (const TString &s)
void calculateHistograms (CompositeTrigger *trigger, int run_dependent)

Protected Attributes

std::map< TString, boolm_triggerPassBits
TPileupReweightingm_parentTool
Bool_t m_SetWarnings
Bool_t m_debugging
Bool_t m_printInfo
Bool_t m_countingMode
Int_t m_unrepresentedDataAction
Bool_t m_isInitialized
Bool_t m_lumiVectorIsLoaded
Float_t m_dataScaleFactorX
Float_t m_dataScaleFactorY
Float_t m_mcScaleFactorX
Float_t m_mcScaleFactorY
Int_t m_nextPeriodNumber
Bool_t m_ignoreFilePeriods
TTree * m_metadatatree
Double_t m_unrepDataTolerance
Double_t m_unrepDataWarningThreshold {0.0}
Bool_t m_doGlobalDataWeight
Bool_t m_doPrescaleWeight = false
Int_t m_lumicalcRunNumberOffset
std::map< TString, std::vector< TString > > m_lumicalcFiles
 map storing the lumicalc file locations - used when building DataPileupWeights
std::unique_ptr< TH1 > m_emptyHistogram
 the empty histogram used for this weight... effectively holds the configuration of the binning
std::map< TString, std::map< Int_t, Double_t > > m_metadata
 channel metadata map
std::map< TString, std::unique_ptr< CompositeTrigger > > m_triggerObjs
std::list< Periodm_periodList
 List physically holding (owning) period objects.
std::map< Int_t, Period * > m_periods
std::map< UInt_t, Runm_runs
std::map< Int_t, Double_t > unrepDataByChannel
std::string m_prwFilesPathPrefix
std::unique_ptr< TRandom3 > m_random3
Bool_t m_ignoreBadChannels
Bool_t m_useMultiPeriods = true
int m_autoRunStart = 0
int m_autoRunEnd = 0

Detailed Description

Definition at line 50 of file TPileupReweighting.h.

Constructor & Destructor Documentation

◆ TPileupReweighting()

CP::TPileupReweighting::TPileupReweighting ( const char * name = "TPileupReweighting")

Standard constructor.

Member Function Documentation

◆ AddConfigFile()

Int_t TPileupReweighting::AddConfigFile ( const TString & fileName)

Definition at line 936 of file TPileupReweighting.cxx.

936 {
937
938 //open the file and look for config TTrees
939 //recognised TTrees are: ChannelMetaData, MCPileupReweighting, MCCustomReweighting, DataCustomReweighting
940
941 if(m_isInitialized) {
942 Error("AddConfigFile","You cannot AddConfigFile after initializing the tool. Reorder your code!");
943 throw std::runtime_error("Throwing 5: You cannot AddConfigFile after initializing the tool. Reorder your code!");
944 }
945
946 TDirectory* origDir = gDirectory;
947 // Load the data ROOT file
948 TFile* rootFile = TFile::Open( fileName, "READ" );
949 if ( rootFile->IsZombie() ) {
950 Error("AddConfigFile","Could not open file: %s",fileName.Data());
951 std::string toThrow = "Throwing 6: Could not open file: "; toThrow += fileName.Data();
952 throw std::runtime_error(toThrow);
953 } else {
954 //try to get the the known TTrees
955 TTree *tmp = (TTree*)rootFile->Get( std::string(m_prwFilesPathPrefix+"MCPileupReweighting").c_str() );
956 if(tmp) {
957 //Info("AddConfigFile","Adding MCPileupReweighting...");
958 AddDistributionTree(tmp,rootFile);
959 m_countingMode=false;
960 }
961 tmp = 0;tmp = (TTree*)rootFile->Get( std::string(m_prwFilesPathPrefix+"MCCustomReweighting").c_str() );
962 if(tmp) {
963 //Info("AddConfigFile","Adding MCCustomReweighting...");
964 AddDistributionTree(tmp,rootFile);
965 m_countingMode=false;
966 }
967 tmp = 0;tmp = (TTree*)rootFile->Get( std::string(m_prwFilesPathPrefix+"DataCustomReweighting").c_str() );
968 if(tmp) {
969 //Info("AddConfigFile","Adding DataCustomReweighting...");
970 AddDistributionTree(tmp,rootFile);
971 m_countingMode=false;
972 }
973 tmp=0; tmp = (TTree*)rootFile->Get( std::string(m_prwFilesPathPrefix+"PileupReweighting/MCPileupReweighting").c_str() ); //allow trees in the PileupReweighting dir instead
974 if(tmp) {
975 //Info("AddConfigFile","Adding MCPileupReweighting...");
976 AddDistributionTree(tmp,rootFile);
977 m_countingMode=false;
978 }
979 tmp = 0;tmp = (TTree*)rootFile->Get( std::string(m_prwFilesPathPrefix+"PileupReweighting/MCCustomReweighting").c_str() );
980 if(tmp) {
981 //Info("AddConfigFile","Adding MCCustomReweighting...");
982 AddDistributionTree(tmp,rootFile);
983 m_countingMode=false;
984 }
985 tmp = 0;tmp = (TTree*)rootFile->Get( std::string(m_prwFilesPathPrefix+"PileupReweighting/DataCustomReweighting").c_str() );
986 if(tmp) {
987 //Info("AddConfigFile","Adding DataCustomReweighting...");
988 AddDistributionTree(tmp,rootFile);
989 m_countingMode=false;
990 }
991 }
992
993 delete rootFile;
994
995 // Return to the original ROOT directory
997
998 return 0;
999}
void AddDistributionTree(TTree *tree, TFile *file)
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition Error.h:16

◆ AddDistribution()

Int_t TPileupReweighting::AddDistribution ( TH1 * hist,
Int_t runNumber,
Int_t channelNumber )

Definition at line 728 of file TPileupReweighting.cxx.

728 {
729
730 //NOTE: should probably just ignore histograms with 0 entries
731
732 if(m_isInitialized) {
733 Error("AddDistribution","You cannot AddDistribution after initializing the tool. Reorder your code!");
734 throw std::runtime_error("Throwing 5: You cannot AddLumiCalcFile after initializing the tool. Reorder your code!");
735 }
736
737 if(channelNumber>=0 && !m_periods[runNumber]) {
738 Error("AddDistribution","Unrecognised periodNumber: %d .. please use AddPeriod to define a period",runNumber);
739 throw std::runtime_error("Throwing 6: Unrecognised periodNumber. Please use AddPeriod to define a period");
740 }
741
742 if(!m_useMultiPeriods && runNumber>=0) {
743 //not allowing multi periods in a single channel, so before we go any further, require no periods other than this incoming one to have a hist defined for this channel
744 //the global one can though
745 for(auto& period : m_periods) {
746 if(period.first<0) continue; //global sum period
747 if(period.first==runNumber) continue; //ok to add to this
748 if(period.second->inputHists.find(channelNumber)!=period.second->inputHists.end()) {
749 TString myMsg = TString::Format("Attempt to add distribution for channel %d to period %d, but this channels already has period %d defined.\nThis is indicative of use of incompatible PRW config files, please check your config files for multiple periods/runNumbers for the same channel.",channelNumber,runNumber,period.first);
750 Error("AddDistribution","%s",myMsg.Data());
751 throw std::runtime_error(myMsg.Data());
752 }
753 }
754 }
755
756
757 auto& inputHist = (channelNumber<0) ? m_runs[runNumber].inputHists["None"] : m_periods[runNumber]->inputHists[channelNumber];
758
759 if(!inputHist) {
760 //if no emptyHistogram specified, we will use this histogram as the structure for the empty;
761 if(!m_emptyHistogram) {
762 //check if the input histogram is a TH1D or not. We like TH1D, not yucky TH1F
763 if(strcmp(hist->IsA()->GetName(),"TH1D")==0 || strcmp(hist->IsA()->GetName(),"TH2D")==0) {
764 m_emptyHistogram.reset( dynamic_cast<TH1*>(hist->Clone("default")) );
765 } else {
766 //check dimensionality
767 if(hist->GetDimension()==1) {
768 std::vector<Double_t> binsX;
769 for(int i=0;i<=hist->GetNbinsX();i++) binsX.push_back(hist->GetXaxis()->GetBinLowEdge(i+1));
770 TH1D tmpHist("tmpHist","tmpHist",binsX.size()-1,&binsX[0]);
771 m_emptyHistogram.reset( dynamic_cast<TH1*>(tmpHist.Clone("default")) );
772 } else if(hist->GetDimension()==2) {
773 std::vector<Double_t> binsX;std::vector<Double_t> binsY;
774 for(int i=0;i<=hist->GetNbinsX();i++) binsX.push_back(hist->GetXaxis()->GetBinLowEdge(i+1));
775 for(int i=0;i<=hist->GetNbinsY();i++) binsY.push_back(hist->GetYaxis()->GetBinLowEdge(i+1));
776 TH2D tmpHist("tmpHist","tmpHist",binsX.size()-1,&binsX[0],binsY.size()-1,&binsY[0]);
777 m_emptyHistogram.reset( dynamic_cast<TH1*>(tmpHist.Clone("default")) );
778 } else {
779 Error("AddDistribution","Unknown input histogram dimensionality: %d",hist->GetDimension());
780 throw std::runtime_error("Throwing 98");
781 }
782 }
784 {
785 m_emptyHistogram->Reset();m_emptyHistogram->SetEntries(0);m_emptyHistogram->SetDirectory(0);//clear the histogram
786 }
787 }
788 inputHist = CloneEmptyHistogram(runNumber,channelNumber);
789
790 }
791
792
793 //iterator over bins of histogram, filling the TH1 stored in the data map
794 Double_t numEntries = inputHist->GetEntries();
795
796 std::unique_ptr<TH1> tmpHist;
797 if(channelNumber<0) {
798 m_runs[runNumber].nominalFromHists = true;
799 //for data we will do an interpolation to build the shape and then scale it to the integral ...
800 tmpHist.reset( static_cast<TH1*>(inputHist->Clone("tmpHist")) );
801 tmpHist->Reset();
802 Int_t bin,binx,biny;
803 for(biny=1; biny<=tmpHist->GetNbinsY(); biny++) {
804 for(binx=1; binx<=tmpHist->GetNbinsX(); binx++) {
805 bin = tmpHist->GetBin(binx,biny);
806 Double_t x = tmpHist->GetXaxis()->GetBinCenter(binx)/m_dataScaleFactorX;
807 Double_t y = tmpHist->GetYaxis()->GetBinCenter(biny)/m_dataScaleFactorY;
808 if(tmpHist->GetDimension()==1){
809 tmpHist->SetBinContent(bin, hist->Interpolate(x));
810 } else {
811 tmpHist->SetBinContent(bin, hist->Interpolate(x,y));
812 }
813 }
814 }
815 tmpHist->Scale( hist->Integral() / tmpHist->Integral() );
816 tmpHist->SetEntries( hist->GetEntries() );
817 hist = tmpHist.get();
818 }
819
820 Int_t bin,binx,biny;
821 for(biny=1; biny<=hist->GetNbinsY(); biny++) {
822 for(binx=1; binx<=hist->GetNbinsX(); binx++) {
823 bin = hist->GetBin(binx,biny);
824 Double_t value = hist->GetBinContent(bin);
825 Double_t x = hist->GetXaxis()->GetBinCenter(binx);
826 Double_t y = hist->GetYaxis()->GetBinCenter(biny);
827 //shift x,y,z by the MCScaleFactors as appropriate
828 if(channelNumber>=0) {x *= m_mcScaleFactorX; y *= m_mcScaleFactorY;}
829 //data scale factor now dealt with in above interpolation
830 Int_t inBin = inputHist->FindFixBin(x,y);
831 Double_t inValue = inputHist->GetBinContent(inBin);
832 inputHist->SetBinContent(inBin,inValue+value);
833 }
834 }
835
836 //also keep track of the number of entries
837 //SetBinContent screws with the entry count, so had to record it before the loops above
838 inputHist->SetEntries(numEntries+hist->GetEntries());
839
840
841 m_countingMode=false;
842 return 0;
843
844}
#define y
#define x
std::map< UInt_t, Run > m_runs
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
std::unique_ptr< TH1 > CloneEmptyHistogram(Int_t runNumber, Int_t channelNumber)
tmpHist(what, wmin=-1e10, wmax=+1e10)
Definition fitman.py:146

◆ AddDistributionTree()

void TPileupReweighting::AddDistributionTree ( TTree * tree,
TFile * file )
protected

Definition at line 648 of file TPileupReweighting.cxx.

648 {
649
650 bool isMC=true;
651 //should have the standard structure
652 Int_t channel = 0; UInt_t runNbr = 0;
653 auto pStarts = std::make_unique< std::vector< UInt_t > >();
654 auto pStartsPtr = pStarts.get();
655 auto pEnds = std::make_unique< std::vector< UInt_t > >();
656 auto pEndsPtr = pEnds.get();
657 Char_t histName[150];
658 Char_t customName[150];
659 Bool_t isDefaultForRunNumber(false); bool hasDefaultsBranch=false;
660 if(strcmp(tree->GetName(),"MCPileupReweighting")==0) {strcpy(customName,"pileup");isMC=true;}
661 else {
662 if(tree->SetBranchAddress("CustomName",&customName)!=0) {
663 Error("AddDistributionTree","Could not find CustomName branch in TTree");throw std::runtime_error("Throwing 18");
664 }
665 }
666 if(strcmp(tree->GetName(),"DataCustomReweighting")==0) {channel=-1;isMC=false;}
667 else {
668 if(tree->SetBranchAddress("Channel",&channel)!=0) {
669 Error("AddDistributionTree","Could not find Channel branch in TTree");throw std::runtime_error("Throwing 18");
670 }
671 }
672 if(tree->SetBranchAddress("RunNumber",&runNbr)!=0) {
673 Error("AddDistributionTree","Could not find RunNumber branch in TTree");throw std::runtime_error("Throwing 18");
674 }
675 if(isMC) {
676 if(tree->SetBranchAddress("PeriodStarts",&pStartsPtr)!=0) {
677 Error("AddDistributionTree","Could not find PeriodStarts branch in TTree");throw std::runtime_error("Throwing 18");
678 }
679 if(tree->SetBranchAddress("PeriodEnds",&pEndsPtr)!=0) {
680 Error("AddDistributionTree","Could not find PeriodEnds branch in TTree");throw std::runtime_error("Throwing 18");
681 }
682 if(tree->FindBranch("IsDefaultForRunNumber")!=0) {
683 tree->SetBranchAddress("IsDefaultForRunNumber",&isDefaultForRunNumber);
684 hasDefaultsBranch=true;
685 }
686 }
687
688 if(tree->SetBranchAddress("HistName",&histName)!=0) {
689 Error("AddDistributionTree","Could not find HistName branch in TTree");throw std::runtime_error("Throwing 18");
690 }
691 long n = tree->GetEntries();
692 std::map<TString,bool> loadedHistos; //avoid double-loading from this file
693 for(long i=0;i<n;i++) {
694 tree->GetEntry(i);
695 TString sHistName(histName);
696 TString weightName(customName);
697 const auto &[ptr, inserted] = loadedHistos.try_emplace(sHistName, true);
698
699 if(inserted) {
700 if(( (!m_ignoreFilePeriods) || m_periods.find(runNbr)==m_periods.end()) && isMC) {
701 //if ignoring file periods, will still add the period if it doesnt exist!
702 for(unsigned int j=0;j<pStarts->size();j++) {
703 unsigned int start = pStarts->at(j);
704 unsigned int end = pEnds->at(j);
705 AddPeriod(runNbr,start,end);
706 }
707 }
708 //load the histogram
709 TH1 *histo = (TH1*)file->Get( sHistName );
710 if(!histo) histo = (TH1*)file->Get( TString::Format("%sPileupReweighting/%s",m_prwFilesPathPrefix.c_str(),sHistName.Data()) ); //try from subdir
711 if(!histo) {
712 Error("AddDistributionTree","Unable to find the histogram %s in the File %s",sHistName.Data(),file->GetName());
713 throw std::runtime_error("Throwing 21");
714 }
715 //add it to the histograms
716 AddDistribution(histo, runNbr, channel);
717 //we also add it to the global count, if this isn't data
718 if(channel>=0) AddDistribution(histo,-1,channel);
719 }
720 if(hasDefaultsBranch) {
721 if(isDefaultForRunNumber && m_periods.find(runNbr)!=m_periods.end()) m_periods[runNbr]->defaultChannel=channel;
722 }
723 }
724
725}
Int_t AddPeriod(Int_t periodNumber, UInt_t start, UInt_t end)
Assign an mc RunNumber to a data period.
Int_t AddDistribution(TH1 *hist, Int_t runNumber, Int_t channelNumber)
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)
void * ptr(T *p)
Definition SGImplSvc.cxx:74
TChain * tree
TFile * file

◆ AddLumiCalcFile()

Int_t TPileupReweighting::AddLumiCalcFile ( const TString & fileName,
const TString & trigger = "None" )

Definition at line 847 of file TPileupReweighting.cxx.

847 {
848
849 if(m_isInitialized) {
850 Error("AddLumiCalcFile","You cannot AddLumiCalcFile after initializing the tool. Reorder your code!");
851 throw std::runtime_error("Throwing 5: You cannot AddLumiCalcFile after initializing the tool. Reorder your code!");
852 }
853 TDirectory* origDir = gDirectory;
854 // Load the data ROOT file
855 TFile* rootFile = TFile::Open( fileName, "READ" );
856 if ( rootFile->IsZombie() ) {
857 Error("AddConfigFile","Could not open file: %s",fileName.Data());
858 std::string toThrow = "Throwing 6: Could not open file: "; toThrow += fileName.Data();
859 throw std::runtime_error(toThrow);
860 } else {
861 //try to get the the known TTrees
862 TTree *tmp = (TTree*)rootFile->Get( "LumiMetaData" );
863 if(tmp) {
864 m_lumicalcFiles[trigger].push_back(fileName);
865 if(trigger=="None") {
866 if (m_printInfo) {
867 Info("AddLumiCalcFile","Adding LumiMetaData (scale factor=%f)...",m_dataScaleFactorX);
868 }
869 //structure expected is as given by iLumiCalc:
870 // RunNbr, AvergeInteractionPerXing, IntLumi
871 UInt_t runNbr=0;Float_t intLumi=0;UInt_t lbn=0;TBranch *b_runNbr=0;TBranch *b_intLumi=0;TBranch *b_lbn=0;
872 Float_t mu=0.; TBranch *b_mu=0;
873 if(tmp->SetBranchAddress("RunNbr",&runNbr,&b_runNbr)!=0) {
874 Error("AddLumiCalcFile","Could not find RunNbr branch in Data TTree");throw std::runtime_error("Could not find RunNbr branch in Data TTree");
875 }
876 if(tmp->SetBranchAddress("AvergeInteractionPerXing",&mu,&b_mu)!=0) {
877 Error("AddLumiCalcFile","Could not find AvergeInteractionPerXing branch in Data TTree");throw std::runtime_error("Could not find AvergeInteractionPerXing branch in Data TTree");
878 }
879 if(tmp->SetBranchAddress("IntLumi",&intLumi,&b_intLumi)!=0) {
880 Error("AddLumiCalcFile","Could not find IntLumi branch in Data TTree");throw std::runtime_error("Could not find IntLumi branch in Data TTree");
881 }
882 if(tmp->SetBranchAddress("LBStart",&lbn,&b_lbn)!=0) {
883 Error("AddLumiCalcFile","Could not find LBStart branch in Data TTree");throw std::runtime_error("Could not find LBStart branch in Data TTree");
884 }
885 long nEntries = tmp->GetEntries();
886
887 for(long i=0;i<nEntries;i++) {
888 b_runNbr->GetEntry(i);b_intLumi->GetEntry(i);b_mu->GetEntry(i);
890 //save the lumi by run and lbn
891 b_lbn->GetEntry(i);
892
893 //before going any further, check the runnbr and lbn are ok
894 if(!m_parentTool->runLbnOK(runNbr,lbn)) continue;
895
896 Run& r = m_runs[runNbr];
897 if(trigger=="None") {
898 r.lumiByLbn[lbn].first += intLumi;
899 r.lumiByLbn[lbn].second = mu;
900 if(r.nominalFromHists) continue; //don't fill runs that we already filled from hists ... only happens for the 'None' trigger
901 }
902
903 //rescale the mu value ... do this *after* having stored the mu value in the lumiByLbn map
905 //fill into input data histograms
906 //check if we need to create an empty histogram
907
908 std::unique_ptr<TH1>& histptr = r.inputHists[trigger];
909 if (!histptr) {
910 histptr = CloneEmptyHistogram(runNbr,-1);
911 }
912 histptr->Fill(mu,intLumi);
913 }
914 m_countingMode=false;
916 } else {
917 if (m_printInfo) {
918 Info("AddLumiCalcFile","Adding LumiMetaData for DataWeight (trigger=%s) (scale factor=%f)...",trigger.Data(),m_dataScaleFactorX);
919 }
920 }
921
922 } else {
923 Error("AddLumiCalcFile","No LumiMetaData found in file %s. not a LumiCalcFile?", fileName.Data());
924 throw std::runtime_error("No LumiMetaData found in file, not a LumiCalcFile?");
925 }
926 }
927
928 delete rootFile;
929
930 // Return to the original ROOT directory
932
933 return 0;
934}
TPileupReweighting * m_parentTool
std::map< TString, std::vector< TString > > m_lumicalcFiles
map storing the lumicalc file locations - used when building DataPileupWeights
int r
Definition globals.cxx:22
@ Info
Definition ZDCMsg.h:20

◆ AddMetaDataFile()

Int_t TPileupReweighting::AddMetaDataFile ( const TString & fileName,
const TString & channelBranchName = "mc_channel_number" )

Definition at line 506 of file TPileupReweighting.cxx.

506 {
507 TDirectory* origDir = gDirectory;
508 TTree* tmp = 0;
509 TFile* rootFile = 0;
510 if(fileName.EndsWith(".root")) {
511 //looks for ChannelMetaData ttree
512 // Load the data ROOT file
513 rootFile = TFile::Open( fileName, "READ" );
514 if ( rootFile->IsZombie() ) {
515 Error("AddMetaDataFile","Could not open file: %s",fileName.Data());
516 throw std::runtime_error("Throwing 6");
517 } else {
518 //try to get the the known TTrees
519 tmp = (TTree*)rootFile->Get( "ChannelMetaData" );
520 if(!tmp) {
521 Error("AddMetaDataFile","%s is not a valid metadata file. Should have a ChannelMetaData TTree",fileName.Data());
522 throw std::runtime_error("Throwing 7");
523 }
524 rootFile->Close();
525 }
526 delete rootFile;
527 } else {
528 //try to make the TTree by reading the file
529 tmp = new TTree("ChannelMetaData","ChannelMetaData");
530 tmp->ReadFile(fileName);
531 }
532 Int_t chanNum;
533 std::map<TString, Double_t> data;
534 TObjArray *leaves = tmp->GetListOfLeaves();
535 if(leaves==0) {Error("AddMetaDataFile","No leaves"); return -1; }
536 for(Int_t i=0;i<leaves->GetEntries();++i) {
537 TLeaf *leaf = (TLeaf *)leaves->At(i);
538 if(leaf) {
539 TBranch *branch = leaf->GetBranch();
540 if(strcmp(branch->GetName(),channelBranchName)==0) {
541 //this is the channel branch
542 if(strcmp(leaf->GetTypeName(),"Int_t")!=0) {
543 Error("AddMetaDataFile","Channel Branch must be type Int_t");
544 throw std::runtime_error("Throwing 7");
545 }
546 branch->SetAddress(&chanNum);
547 } else if(strcmp(leaf->GetTypeName(),"Double_t")!=0) {
548 Warning("AddMetaDataFile","Cannot read non-double branch: %s",branch->GetName());
549 } else {
550 branch->SetAddress(&(data[branch->GetName()]));
551 }
552 }
553 }
554 //loop over tree entries and read in the values
555 for(Int_t i=0;i<tmp->GetEntries();++i) {
556 tmp->GetEntry(i);
557 for(std::map<TString, Double_t>::iterator it = data.begin();it!=data.end();++it) {
558 if(m_metadata.find(it->first)!=m_metadata.end()&&m_metadata[it->first].find(chanNum)!=m_metadata[it->first].end() && m_metadata[it->first][chanNum]!=it->second) {
559 Warning("AddMetaDataFile", "Overriding metadata [%s,%d]. %f becomes %f",(it->first).Data(),chanNum,m_metadata[it->first][chanNum],it->second);
560 }
561 m_metadata[it->first][chanNum] = it->second;
562 }
563 }
564
565 delete tmp;
566 if(rootFile) { rootFile->Close();delete rootFile;}
567
568 // Return to the original ROOT directory
570
571 return 0;
572}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
std::map< TString, std::map< Int_t, Double_t > > m_metadata
channel metadata map

◆ AddPeriod()

Int_t TPileupReweighting::AddPeriod ( Int_t periodNumber,
UInt_t start,
UInt_t end )

Assign an mc RunNumber to a data period.

returns a PeriodID. These count up from 1

Definition at line 368 of file TPileupReweighting.cxx.

368 {
369 //you can add more periods only in counting mode, but they must not be with subperiods!
370
372 Error("AddPeriod","You cannot AddPeriod after initializing the tool, except when in config file generating mode. Reorder your code!");
373 throw std::runtime_error("Throwing 1: You cannot AddPeriod after initializing the tool, except when in config file generating mode. Reorder your code!");
374 }
375
376 if(m_periods.find(periodNumber)==m_periods.end()) {
377 m_periodList.emplace_back( periodNumber, start, end,
378 GetDefaultChannel( -1 ) );
379 m_periods[periodNumber] = &( m_periodList.back() );
380 return periodNumber;
381 }
382
383 //if period exists but both start and end are zero, then just assign that
384 Period* p = m_periods[periodNumber];
385
386 if(p->subPeriods.size() == 0 && p->start==0 && p->end==0) { p->start=start; p->end=end; return periodNumber; }
387
388 //check if period already contained (i.e. same period or one of the existing subperiods) ... if it is, do nothing
389 if(p->start==start && p->end==end) return periodNumber;
390 for(auto pp : p->subPeriods) {
391 if(pp->start==start && pp->end==end) return pp->id;
392 }
393
394 //if get here, and in counting mode, this isn't allowed! .. i.e. we can't have subperiods
396 Error("AddPeriod","You cannot have subperiods when in Config File Generating mode");
397 throw std::runtime_error("Throwing 44: In Config File Generating mode, but detected subperiods in the period definition. This is not allowed.");
398 }
399
400 //if period is already defined, we create a new period with start and end, and assign our period to this one
401 //also create a new period for the existing period configuration of this period
402
403 if(p->subPeriods.size()==0) {
405 m_periodList.emplace_back( m_nextPeriodNumber, p->start, p->end,
406 p->defaultChannel );
408 p->subPeriods.push_back(m_periods[m_nextPeriodNumber]);
409 p->start = 0; p->end=0;
410 }
411
413 m_periodList.emplace_back( m_nextPeriodNumber, start, end,
414 p->defaultChannel );
416 p->subPeriods.push_back(m_periods[m_nextPeriodNumber]);
417
418 return m_nextPeriodNumber;
419}
std::list< Period > m_periodList
List physically holding (owning) period objects.
Int_t GetDefaultChannel(Int_t mcRunNumber=-1)

◆ calculateHistograms()

void TPileupReweighting::calculateHistograms ( CompositeTrigger * trigger,
int run_dependent )
protected

Definition at line 2115 of file TPileupReweighting.cxx.

2115 {
2116 TH1* unprescaledLumi = 0;
2117 if(runDependentRun) {
2118 unprescaledLumi = m_triggerObjs["None"]->triggerHists[-runDependentRun][0].get();
2119 }
2120 bool fillUnprescaledLumi = (unprescaledLumi==0); //only fill the unprescaled histogram once ... so if it already exists, it must have already been filled
2121
2122 //now we need the trigger bits for this trigger for this event
2123 long tbits = t->getBits(this);
2124 //1. Open all the lumicalc files
2125 //2. For each entry in the 'None' lumicalc file, lookup the run and lb in the subTriggers, and get the prescales (if not found, assume trigger not in, prescale=infinity)
2126 //3. perform calculation of lumi as: Lumi*(1 - Prod_triggers(1-1/prescale)) .. sum this up into the output histogram
2127 // Note: Put each lumi into the period that contains the run ( use )
2128
2129 TDirectory* origDir = gDirectory;
2130
2131 std::map<TString, std::map<Int_t, std::map<Int_t, Float_t> > > prescaleByRunAndLbn;
2132
2133 //Load the prescales for each lumicalc subTrigger
2134 for(std::vector<TString>::iterator it = t->subTriggers.begin();it!=t->subTriggers.end();++it) {
2135 //Info("aa","subtrigger %s Int lumi is %f", it->Data(), m_triggerPrimaryDistributions[*it][1]->Integral());
2136 for(auto& fileName : m_lumicalcFiles[*it]) {
2137 //if the file is also in the "None" list, then we will now the prescale must be 0
2138 //it seems that in these no-trigger files used for unprescaled lumi the prescales are all set to -1
2139 bool isUnprescaled = (std::find(m_lumicalcFiles["None"].begin(),m_lumicalcFiles["None"].end(),fileName)!=m_lumicalcFiles["None"].end());
2140
2141 TFile* rootFile = TFile::Open( fileName, "READ" );
2142 if ( rootFile->IsZombie() ) {
2143 Error("CalculatePrescaledLuminosityHistograms","Could not open file: %s",fileName.Data());
2144 std::string toThrow = "Throwing 6: Could not open file: "; toThrow += fileName.Data();
2145 throw std::runtime_error(toThrow);
2146 } else {
2147 //try to get the the known TTrees
2148 TTree *tmp = (TTree*)rootFile->Get( "LumiMetaData" );
2149 if(tmp) {
2150 //structure expected is as given by iLumiCalc:
2151 // RunNbr, AvergeInteractionPerXing, IntLumi
2152 UInt_t runNbr=0;Float_t ps1=0;Float_t ps2=0; Float_t ps3=0;UInt_t lbn=0;TBranch *b_runNbr=0;TBranch *b_L1Presc=0;TBranch *b_L2Presc=0;TBranch *b_L3Presc=0;TBranch *b_lbn=0;
2153 if(tmp->SetBranchAddress("RunNbr",&runNbr,&b_runNbr)!=0) {
2154 Error("CalculatePrescaledLuminosityHistograms","Could not find RunNbr branch in Data TTree");throw std::runtime_error("Could not find RunNbr branch in Data TTree");
2155 }
2156 if(tmp->SetBranchAddress("L1Presc",&ps1,&b_L1Presc)!=0) {
2157 Error("CalculatePrescaledLuminosityHistograms","Could not find L1Presc branch in Data TTree");throw std::runtime_error("Could not find L1Presc branch in Data TTree");
2158 }
2159 if(tmp->SetBranchAddress("L2Presc",&ps2,&b_L2Presc)!=0) {
2160 Error("CalculatePrescaledLuminosityHistograms","Could not find L2Presc branch in Data TTree");throw std::runtime_error("Could not find L2Presc branch in Data TTree");
2161 }
2162 if(tmp->SetBranchAddress("L3Presc",&ps3,&b_L3Presc)!=0) {
2163 Error("CalculatePrescaledLuminosityHistograms","Could not find L3Presc branch in Data TTree");throw std::runtime_error("Could not find L3Presc branch in Data TTree");
2164 }
2165 if(tmp->SetBranchAddress("LBStart",&lbn,&b_lbn)!=0) {
2166 Error("CalculatePrescaledLuminosityHistograms","Could not find LBStart branch in Data TTree");throw std::runtime_error("Could not find LBStart branch in Data TTree");
2167 }
2168 long nEntries = tmp->GetEntries();
2169 for(long i=0;i<nEntries;i++) {
2170 b_runNbr->GetEntry(i);b_L1Presc->GetEntry(i);b_L2Presc->GetEntry(i);b_L3Presc->GetEntry(i);b_lbn->GetEntry(i);
2171 runNbr += m_lumicalcRunNumberOffset;
2172 if(runDependentRun && int(runNbr)!=runDependentRun) continue; //only use the given run with doing calculation run-dependently
2173 //save the prescale by run and lbn
2174 //if(runNbr==215643)
2175 if(m_debugging && m_printInfo) Info("...","prescale in [%d,%d] = %f %f %f", runNbr,lbn,ps1,ps2,ps3);
2176 if(ps1>0&&ps2>0&&ps3>0) prescaleByRunAndLbn[*it][runNbr][lbn] = ps1*ps2*ps3;
2177 else if(isUnprescaled) prescaleByRunAndLbn[*it][runNbr][lbn] = 1; //special case where the trigger is an unprescaled one and user is reusing the unprescaled lumicalc
2178 }
2179 }
2180 rootFile->Close();
2181 }
2182 delete rootFile;
2183 } //end of loop over lumicalc files for this trigger
2184 }
2185
2186 for(auto& fileName : m_lumicalcFiles["None"]) {
2187 // Load the data ROOT file for the 'None' lumicalc file
2188 TFile* rootFile = TFile::Open( fileName, "READ" );
2189 if ( rootFile->IsZombie() ) {
2190 Error("CalculatePrescaledLuminosityHistograms","Could not open file: %s",fileName.Data());
2191 std::string toThrow = "Throwing 6: Could not open file: "; toThrow += fileName.Data();
2192 throw std::runtime_error(toThrow);
2193 } else {
2194 //try to get the the known TTrees
2195 TTree *tmp = (TTree*)rootFile->Get( "LumiMetaData" );
2196 if(tmp) {
2197 //structure expected is as given by iLumiCalc:
2198 // RunNbr, AvergeInteractionPerXing, IntLumi
2199 UInt_t runNbr=0;Float_t intLumi=0;UInt_t lbn=0;TBranch *b_runNbr=0;TBranch *b_intLumi=0;TBranch *b_lbn=0;
2200 Float_t mu=0.; TBranch *b_mu=0;
2201 if(tmp->SetBranchAddress("RunNbr",&runNbr,&b_runNbr)!=0) {
2202 Error("CalculatePrescaledLuminosityHistograms","Could not find RunNbr branch in Data TTree");throw std::runtime_error("Could not find RunNbr branch in Data TTree");
2203 }
2204 if(tmp->SetBranchAddress("AvergeInteractionPerXing",&mu,&b_mu)!=0) {
2205 Error("CalculatePrescaledLuminosityHistograms","Could not find AvergeInteractionPerXing branch in Data TTree");throw std::runtime_error("Could not find AvergeInteractionPerXing branch in Data TTree");
2206 }
2207 if(tmp->SetBranchAddress("IntLumi",&intLumi,&b_intLumi)!=0) {
2208 Error("CalculatePrescaledLuminosityHistograms","Could not find IntLumi branch in Data TTree");throw std::runtime_error("Could not find IntLumi branch in Data TTree");
2209 }
2210 if(tmp->SetBranchAddress("LBStart",&lbn,&b_lbn)!=0) {
2211 Error("CalculatePrescaledLuminosityHistograms","Could not find LBStart branch in Data TTree");throw std::runtime_error("Could not find LBStart branch in Data TTree");
2212 }
2213 long nEntries = tmp->GetEntries();
2214 //this loop ends up calling the triggerBeforePrescale method each time, but this should hopefully stop once the loading is done
2215 for(long i=0;i<nEntries;i++) {
2216 b_runNbr->GetEntry(i);b_intLumi->GetEntry(i);b_mu->GetEntry(i);
2217 b_lbn->GetEntry(i);
2218
2219 runNbr += m_lumicalcRunNumberOffset;
2220 if(runDependentRun && int(runNbr)!=runDependentRun) continue; //only use the given run with doing calculation run-dependently
2221 //for each subtrigger, lookup prescale, and calculate pFactor
2222
2223 double pFactor = t->eval(prescaleByRunAndLbn,runNbr,lbn,this);
2224
2225 //Info("...","prescale in [%d,%d] = %f", runNbr,lbn,1./pFactor);
2226
2227 int bin = m_emptyHistogram->FindFixBin(mu*m_dataScaleFactorX);
2228
2229 //add into all periods that contain this runNbr
2230 bool firstFill=false;
2231 for(auto p : m_periods) {
2232 if(p.first != p.second->id) continue; //skips remappings
2233 if(!p.second->contains(runNbr)) continue;
2234 if(runDependentRun && firstFill) continue; //only fill runDependentRun once, since they aren't kept in the period they go in their own run-indexed histogram
2235
2236 int idx = (runDependentRun) ? -runDependentRun : p.second->id; //use negative runNumber to avoid clash with periodID
2237
2238
2239 auto& triggerHists = t->triggerHists[idx];
2240 std::unique_ptr<TH1>& histptr = triggerHists[tbits];
2241 if(!histptr) {
2242 histptr = CloneEmptyHistogram(p.first,-1);
2243 if(m_debugging && m_printInfo) Info("CalculatePrescaledLuminosityHistograms","Created Data Weight Histogram for [%s,%d,%d,%ld]",t->val.Data(),p.first,idx,tbits);
2244 }
2245 //check if we were about to fill a bad bin ... if we are, we either skipp the fill (unrep action=1) or redirect (unrep action=3)
2246 if( (m_unrepresentedDataAction==1) && p.second->inputBinRedirect[bin]!=bin) { } //do nothing
2247 else if( m_unrepresentedDataAction==3 ) {histptr->Fill(triggerHists[tbits]->GetBinCenter(p.second->inputBinRedirect[bin]), intLumi*pFactor);}
2248 else triggerHists[tbits]->Fill(mu*m_dataScaleFactorX,intLumi*pFactor);
2249
2250
2251 if(runDependentRun && fillUnprescaledLumi) {
2252 //need to fill unprescaled lumi histogram for this particular run ...
2253 if(unprescaledLumi==0) {
2254 m_triggerObjs["None"]->triggerHists[-runDependentRun][0] = CloneEmptyHistogram(p.first,-1);
2255 unprescaledLumi = m_triggerObjs["None"]->triggerHists[-runDependentRun][0].get();
2256 }
2257 if( (m_unrepresentedDataAction==1) && p.second->inputBinRedirect[bin]!=bin) { } //do nothing
2258 else if( m_unrepresentedDataAction==3 ) {unprescaledLumi->Fill(unprescaledLumi->GetBinCenter(p.second->inputBinRedirect[bin]), intLumi);}
2259 else unprescaledLumi->Fill(mu*m_dataScaleFactorX,intLumi);
2260 }
2261
2262 firstFill=true;
2263
2264 }
2265 }
2266 rootFile->Close();
2267 }
2268 }
2269 delete rootFile;
2270 } //end loop over unprescaled lumicalc files
2271
2272
2273 //Info("aa","Int lumi is %f", m_triggerPrimaryDistributions[trigger][1]->Integral());
2274
2275
2276
2277 // Return to the original ROOT directory
2279
2280
2281}
std::map< TString, std::unique_ptr< CompositeTrigger > > m_triggerObjs
TrigPassBitsCollection tbits
ps1
rename ourselfs to athena, both the prompt and the process (for top & ps)
Definition athena.py:137

◆ CalculatePrescaledLuminosityHistograms()

void TPileupReweighting::CalculatePrescaledLuminosityHistograms ( const TString & trigger,
int run_dependent = 0 )
protected

Definition at line 2092 of file TPileupReweighting.cxx.

2092 {
2093 //check if this is a composite trigger (user has provided OR of triggers that are passed before prescale)
2094
2095 TString triggerCopy = trigger; triggerCopy.ReplaceAll(" ",""); triggerCopy.ReplaceAll("&&","&");triggerCopy.ReplaceAll("||","|");
2096 auto t = makeTrigger(triggerCopy);
2097 if( ! t ) {
2098 Error("GetDataWeight","Error parsing composite trigger set: %s",trigger.Data());
2099 throw std::runtime_error("Could not parse composite trigger");
2100 }
2101
2102 std::vector<TString> subTriggers;
2103
2104 t->getTriggers(subTriggers); //fills the vector
2105
2106 t->subTriggers = std::move(subTriggers); //cache the vector of triggers
2107
2108 calculateHistograms(t.get(),runDependentRun);
2109
2110 //save trigger object
2111 m_triggerObjs[trigger] = std::move( t );
2112
2113}
std::unique_ptr< CompositeTrigger > makeTrigger(const TString &s)
void calculateHistograms(CompositeTrigger *trigger, int run_dependent)

◆ CloneEmptyHistogram()

std::unique_ptr< TH1 > TPileupReweighting::CloneEmptyHistogram ( Int_t runNumber,
Int_t channelNumber )
protected

Definition at line 435 of file TPileupReweighting.cxx.

435 {
436
437 TString s("pileup");
438 if(channelNumber>=0) {
439 s += "_chan"; s += channelNumber;
440 } else {
441 s += "_data";
442 }
443 s+="_run"; s+= runNumber;
444 //get the empty histogram
445 if(!m_emptyHistogram) {
446 Error("CloneEmptyHistogram","There is no binning info - use SetBinning/SetUniformBinning or load a prw config file (This usually means you need to call AddConfigFile BEFORE AddLumiCalcFile)");
447 throw std::runtime_error("Throwing 47: There is no binning info - use SetBinning/SetUniformBinning or load a prw config file (This usually means you need to call AddConfigFile BEFORE AddLumiCalcFile)");
448 }
449
450 std::unique_ptr< TH1 > out( dynamic_cast<TH1*>(m_emptyHistogram->Clone(s)) );
451 if (out) {
452 out->SetTitle(s);
453 out->SetDirectory(0); //take ownership
454 out->SetEntries(0);
455 }
456 return out;
457
458}

◆ CopyProperties()

void CP::TPileupReweighting::CopyProperties ( const TPileupReweighting * in)
inline

Definition at line 480 of file TPileupReweighting.h.

480 {
481 m_prwFilesPathPrefix = in->m_prwFilesPathPrefix;
482 m_ignoreBadChannels = in->m_ignoreBadChannels;
483 m_unrepresentedDataAction = in->m_unrepresentedDataAction;
484 m_unrepDataTolerance= in->m_unrepDataTolerance;
485 m_unrepDataWarningThreshold = in->m_unrepDataWarningThreshold;
486 }

◆ DisableWarnings()

void CP::TPileupReweighting::DisableWarnings ( Bool_t in)
inline

Indicate if warnings should be suppressed.

Definition at line 116 of file TPileupReweighting.h.

◆ EnableDebugging()

void CP::TPileupReweighting::EnableDebugging ( Bool_t in)
inline

Indicate if additional debugging information should be output.

Definition at line 118 of file TPileupReweighting.h.

118{ m_debugging = in;}

◆ Fill()

Int_t TPileupReweighting::Fill ( Int_t runNumber,
Int_t channelNumber,
Float_t w,
Float_t x,
Float_t y = 0. )

Definition at line 1843 of file TPileupReweighting.cxx.

1843 {
1844 if(!m_isInitialized ) {
1845 if (m_printInfo) Info("Fill","Initializing the subtool..");
1846 Initialize();
1847 }
1848 //should only be given genuine mcRunNumbers if mc (channel>=0). We don't fill periodNumber distributions
1849
1850 TH1* hist = 0;
1851
1852 //get the period if mc, get the data run if data
1853 if(channelNumber>=0) {
1854 if(m_periods.find(runNumber)==m_periods.end()) {
1855 //if assume default binning is true, will add binning from 0 to 100 for this run number
1858 }
1859 if(m_periods.find(runNumber)==m_periods.end()) {
1860 Error("Fill","Unrecognised runNumber: %d. Check your period configuration (AddPeriod or UsePeriodConfig)",runNumber);
1861 throw std::runtime_error("Throwing 1: Unrecognised periodNumber");
1862 }
1863 }
1865 if(!p) {
1866 Error("Fill","Unrecognised runNumber: %d. Check your period configuration (AddPeriod or UsePeriodConfig) ... but should never have got here so please report this!",runNumber);
1867 throw std::runtime_error("Throwing 1: Unrecognised periodNumber");
1868 }
1869 std::unique_ptr<TH1>& histptr = p->inputHists[channelNumber];
1870 if(!histptr) {
1871 //need to create my period histogram
1872 histptr = CloneEmptyHistogram(runNumber,channelNumber);
1873 }
1874 hist = histptr.get();
1875 } else {
1876 Run& r = m_runs[runNumber];
1877 if( ! r.inputHists["None"]) r.inputHists["None"]=CloneEmptyHistogram(runNumber,channelNumber);
1878 hist = r.inputHists["None"].get();
1879 }
1880
1881 if(!hist) {
1882 Error("Fill","Unknown [run,channel] = [%d,%d]",runNumber,channelNumber);
1883 throw std::runtime_error("Throwing 45: Fill:: Unknown [run,channel] ");
1884 }
1885
1886 if(hist->GetDimension()==1) {
1887 return hist->Fill(x,w);
1888 } else if(hist->GetDimension()==2) {
1889 return (static_cast<TH2*>(hist))->Fill(x,y,w);
1890 }
1891 return -1;
1892}
Int_t Initialize()
Initialize this class once before the event loop starts If distribution information is provided,...

◆ GenerateMetaDataFile()

Int_t TPileupReweighting::GenerateMetaDataFile ( const TString & fileName,
const TString & channelBranchName = "mc_channel_number" )

Definition at line 460 of file TPileupReweighting.cxx.

460 {
461
462 TTree inTree("in","in");
463 inTree.ReadFile(fileName);
464 TTree outTree("ChannelMetaData","ChannelMetaData");
465 Int_t chanNum;
466 std::map<TString, Double_t> data;
467 TObjArray *leaves = inTree.GetListOfLeaves();
468 if(leaves==0) {Error("GenerateMetaDataFile","No leaves"); return -1; }
469 for(Int_t i=0;i<leaves->GetEntries();++i) {
470 TLeaf *leaf = (TLeaf *)leaves->At(i);
471 if(leaf) {
472 TBranch *branch = leaf->GetBranch();
473 if(strcmp(branch->GetName(),channelBranchName)==0) {
474 //this is the channel branch
475 if(strcmp(leaf->GetTypeName(),"Int_t")!=0) {
476 Error("GenerateMetaDataFile","Channel Branch must be type Int_t"); return -1;
477 }
478 branch->SetAddress(&chanNum);
479 outTree.Branch(channelBranchName,&chanNum);
480 } else if(strcmp(leaf->GetTypeName(),"Double_t")!=0) {
481 Warning("GenerateMetaDataFile","Cannot read non-double branch: %s",branch->GetName());
482 } else {
483 branch->SetAddress(&(data[branch->GetName()]));
484 outTree.Branch(branch->GetName(),&(data[branch->GetName()]));
485 }
486 }
487 }
488 //loop over tree entries and read in the values according to property type
489 for(Int_t i=0;i<inTree.GetEntries();++i) {
490 inTree.GetEntry(i);
491 outTree.Fill();
492 }
493
494 //remove the file extension and replace with .root
495 TString outName = fileName(0,fileName.Last('.'));
496 outName += ".prw.root";
497 TFile f1(outName,"RECREATE");
498 outTree.Write();
499 f1.Close();
500 if (m_printInfo) {
501 Info("GenerateMetaDataFile","Succesfully Generated File %s",outName.Data());
502 }
503 return 0;
504}

◆ GetCombinedWeight()

Float_t TPileupReweighting::GetCombinedWeight ( Int_t periodNumber,
Int_t channelNumber,
Float_t x,
Float_t y = 0. )

Definition at line 1609 of file TPileupReweighting.cxx.

1609 {
1610 if(!m_isInitialized) {
1611 if (m_printInfo) Info("GetCombinedWeight","Initializing the subtool..");
1612 Initialize();
1613 }
1614 if(m_countingMode) return 0.;
1615
1616 //decide how many dimensions this weight has - use the emptyHistogram to tell...
1617 TH1* hist = m_emptyHistogram.get();
1618 if(!hist) {
1619 Error("GetCombinedWeight","Tool not configured properly ... please report this!");
1620 throw std::runtime_error("Throwing 47: Tool not configured properly ... please report this!");
1621 }
1622
1623 Float_t out = GetPeriodWeight(periodNumber,channelNumber)*GetPrimaryWeight(periodNumber,channelNumber,x);
1624 if(hist->GetDimension()>1) out *= GetSecondaryWeight(periodNumber,channelNumber,x,y);
1625
1626 return out;
1627}
Float_t GetSecondaryWeight(Int_t periodNumber, Int_t channelNumber, Float_t x, Float_t y)
Float_t GetPrimaryWeight(Int_t periodNumber, Int_t channelNumber, Float_t x)
Float_t GetPeriodWeight(Int_t periodNumber, Int_t channelNumber)

◆ GetDataScaleFactor()

Float_t CP::TPileupReweighting::GetDataScaleFactor ( ) const
inline

Definition at line 298 of file TPileupReweighting.h.

298{ return m_dataScaleFactorX; }

◆ GetDataWeight() [1/2]

Double_t TPileupReweighting::GetDataWeight ( Int_t runNumber,
const TString & trigger )

Definition at line 1728 of file TPileupReweighting.cxx.

1728 {
1729 //special mu-independent version of GetDataWeight. Will just use the global luminosity
1731 double out = GetDataWeight(runNumber, trigger, 0);
1733 return out;
1734}
Double_t GetDataWeight(Int_t runNumber, const TString &trigger, Double_t x, bool run_dependent=false)
Method for weighting data to account for prescales and mu bias.

◆ GetDataWeight() [2/2]

Double_t TPileupReweighting::GetDataWeight ( Int_t runNumber,
const TString & trigger,
Double_t x,
bool run_dependent = false )

Method for weighting data to account for prescales and mu bias.

Use by giving the tool multiple lumicalc files, one for each trigger

Definition at line 1736 of file TPileupReweighting.cxx.

1736 {
1737
1738 if(!m_isInitialized ) {
1739 if (m_printInfo) Info("GetDataWeight","Initializing the subtool..");
1740 Initialize();
1741 }
1742 if(m_countingMode) return 0.;
1743
1744 //determine which period this run number is in
1745 Int_t periodNumber = GetFirstFoundPeriodNumber(runNumber);
1746
1747 Period* p = m_periods[periodNumber];
1748 if(!p) {
1749 Error("GetDataWeight","Unrecognised periodNumber: %d",periodNumber);
1750 throw std::runtime_error("Throwing 1: Unrecognised periodNumber");
1751 }
1752
1753 //see if we already made this trigger hist
1754 auto tobj = m_triggerObjs.find(trigger);
1755
1756
1757 if(tobj==m_triggerObjs.end()) {
1758 //try to do a subtrigger calculation we need to reopen all the lumicalc files and do the fiddily prescaled luminosity calculation
1759 //will throw errors if can't
1761 tobj = m_triggerObjs.find(trigger);
1762 }
1763
1764 //check
1765
1766
1767
1768 if(tobj->second->triggerHists.find(p->id) == tobj->second->triggerHists.end()) {
1769 Error("GetDataWeight","Could not find trigger %s in period %d",trigger.Data(),p->id);
1770 throw std::runtime_error("GetDataWeight: Could not find trigger 1");
1771 }
1772
1773
1774 //now we need to evaluate the trigger bits, and if necessary calculate the new trigger hist for the new bits combination
1775 long tbits = tobj->second->getBits(this);
1776
1777 if(tbits==0) return 1; //no trigger passed
1778
1779 int idx = (runDependent) ? -runNumber : p->id;
1780
1781
1782 auto dItr = tobj->second->triggerHists[idx].find(tbits);
1783
1784 TH1* denomHist = 0;
1785 if(dItr == tobj->second->triggerHists[idx].end()) {
1786 //possible that the tbits for this event have not been encountered before, so just redo the calculation ...
1787 calculateHistograms(tobj->second.get(),(runDependent) ? runNumber:0);
1788
1789 denomHist = tobj->second->triggerHists[idx][tbits].get();
1790 if(denomHist==0) {
1791 Error("GetDataWeight","Could not find trigger %s in period %d with bits %ld",trigger.Data(),idx, tbits);
1792 throw std::runtime_error("GetDataWeight: Could not find trigger 2");
1793 }
1794 } else {
1795 denomHist = dItr->second.get();
1796 }
1797
1798
1799 TH1* numerHist = m_triggerObjs["None"]->triggerHists[idx][0].get();
1800 if(numerHist==0) {
1801 Error("GetDataWeight","Could not find unprescaled trigger in period %d",idx);
1802 throw std::runtime_error("GetDataWeight: Could not find unprescaled trigger. Please AddLumiCalc with a 'None' trigger");
1803 }
1804
1805 if(m_doGlobalDataWeight) return numerHist->Integral(0,numerHist->GetNbinsX()+1)/denomHist->Integral(0,denomHist->GetNbinsX()+1);
1806
1807 Int_t bin=(m_doPrescaleWeight) ? numerHist->FindFixBin(x) : //DO NOT SHIFT IF GETTING A PRESCALE WEIGHT - applied to MC, we only shift incoming mu if we are data
1808 numerHist->FindFixBin(x*m_dataScaleFactorX); //if getting a data weight (i.e. running on data) MUST SCALE BY THE DATA SCALE FACTOR! (assume incoming is raw unscaled)
1809
1810 //we also need to redirect the binning if necessary (unrepData=3)
1811 if( (!m_doPrescaleWeight) && m_unrepresentedDataAction==3) bin = p->inputBinRedirect[bin];
1812
1813 if(!denomHist->GetBinContent(bin)) {
1814 if(m_doPrescaleWeight) return -1; //happens if trigger was disabled/unavailable for that mu, even though that mu is in the dataset
1815 Error("GetDataWeight","Unrecognised mu value %f ... are you sure you included all lumicalc files",x);
1816 throw std::runtime_error("GetDataWeight: Unrecognised mu value. Please AddLumiCalc enough lumi with 'None' trigger");
1817 }
1818
1819 return numerHist->GetBinContent(bin)/denomHist->GetBinContent(bin);
1820}
void CalculatePrescaledLuminosityHistograms(const TString &trigger, int run_dependent=0)
Int_t GetFirstFoundPeriodNumber(UInt_t runNumber)
Get the first period number with the data run number contained - assume all periods are disconnected ...

◆ GetDefaultChannel()

Int_t TPileupReweighting::GetDefaultChannel ( Int_t mcRunNumber = -1)

Definition at line 109 of file TPileupReweighting.cxx.

109 {
110 if(m_parentTool != this) return m_parentTool->GetDefaultChannel(mcRunNumber);
111 return m_periods[mcRunNumber]->defaultChannel;
112}

◆ GetFirstFoundPeriodNumber()

Int_t TPileupReweighting::GetFirstFoundPeriodNumber ( UInt_t runNumber)

Get the first period number with the data run number contained - assume all periods are disconnected for this to be useful.

Definition at line 422 of file TPileupReweighting.cxx.

422 {
423 //go through periods, first period that includes this runNumber wins!
424 //otherwise it returns the 'global period number': -1
425 for(auto period : m_periods) {
426 if(period.second->id==-1) continue;
427 if(period.second->contains(runNumber)) return period.second->id;
428 }
429 return -1;
430
431}

◆ GetInputHistogram()

TH1 * CP::TPileupReweighting::GetInputHistogram ( Int_t channelNumber,
Int_t periodNumber )
inline

Definition at line 251 of file TPileupReweighting.h.

251 {
252 if(m_periods.find(periodNumber)==m_periods.end()||
253 m_periods[periodNumber]->inputHists.find(channelNumber)==m_periods[periodNumber]->inputHists.end()) {
254 return 0;
255 }
256 return m_periods[periodNumber]->inputHists[channelNumber].get();
257 }

◆ GetIntegratedLumi() [1/3]

Double_t TPileupReweighting::GetIntegratedLumi ( const TString & trigger = "")

total luminosity loaded and accepted by the tool (in inverse pb)

Definition at line 115 of file TPileupReweighting.cxx.

115 {
116 if(!m_isInitialized) {
117 if (m_printInfo) {
118 Info("GetIntegratedLumi","Initializing the subtool..");
119 }
120 Initialize();
121 }
123 Error("GetIntegratedLumi","No UNPRESCALED (Trigger=None) Lumicalc file loaded, so cannot get integrated lumi, returning 0");
124 return 0;
125 }
126 if(trigger=="" || trigger=="None") return GetSumOfEventWeights(-1)/1E6;
127
128 if(m_triggerObjs.find(trigger)==m_triggerObjs.end()) {
130 }
131
132 auto& h = m_triggerObjs[trigger]->triggerHists[-1][m_triggerObjs[trigger]->getBits(this)];
133
134 return h->Integral(0,h->GetNbinsX()+1)/1E6;
135}
Double_t GetSumOfEventWeights(Int_t channel)

◆ GetIntegratedLumi() [2/3]

Double_t TPileupReweighting::GetIntegratedLumi ( Int_t periodNumber,
UInt_t start,
UInt_t end )

similar to above, but for only the given mcRunNumber/periodNumber

Definition at line 139 of file TPileupReweighting.cxx.

139 {
140 if(!m_isInitialized) {
141 if (m_printInfo) {
142 Info("GetIntegratedLumi","Initializing the subtool..");
143 }
144 Initialize();
145 }
146 //look through dataPeriodRunTotals["pileup"][periodNumber] for runs inside the given period
147 double total = 0;
148 for(auto run : m_periods[periodNumber]->runNumbers) {
149 if(run >= start && run <= end) total += m_runs[run].inputHists["None"]->GetSumOfWeights();
150 }
151 return total*1E-6;
152}
int run(int argc, char *argv[])

◆ GetIntegratedLumi() [3/3]

Double_t CP::TPileupReweighting::GetIntegratedLumi ( UInt_t start,
UInt_t end )
inline

get the amount of integrated lumi between the two given runs

Definition at line 102 of file TPileupReweighting.h.

102{ return GetIntegratedLumi(-1,start,end); }
Double_t GetIntegratedLumi(const TString &trigger="")
total luminosity loaded and accepted by the tool (in inverse pb)

◆ GetIntegratedLumiFraction() [1/2]

Double_t TPileupReweighting::GetIntegratedLumiFraction ( Int_t periodNumber,
Double_t mu,
UInt_t start,
UInt_t end )

return fraction of lumi assigned to periodNumber (or mcRunNumber) with given mu, that is between start and end data run numbers

Definition at line 204 of file TPileupReweighting.cxx.

204 {
205 if(!m_isInitialized) {
206 if (m_printInfo) {
207 Info("GetIntegratedLumiFraction","Initializing the subtool..");
208 }
209 Initialize();
210 }
212 Error("GetIntegratedLumiFraction","No UNPRESCALED (Trigger=None) Lumicalc file loaded, so no lumi fraction possible, returning 0");
213 return 0;
214 }
215 //determine the mubin
216 if(!m_emptyHistogram) { Error("GetIntegratedLumiFraction", "Cannot do this without a lumicalc file!"); return 0; }
217 Int_t muBin = m_emptyHistogram->FindFixBin(mu);
218 //the total mu in this bin in this period is given by the triggerHist = "None" hist
219
220
221
222 double total = m_triggerObjs["None"]->triggerHists[periodNumber][0]->GetBinContent(muBin);
223 //loop over assigned runs, if in range then include in numerator
224 double numer = 0;
225 for(auto run : m_periods[periodNumber]->runNumbers) {
226 if(run >= start && run <= end) numer += m_runs[run].muDist->GetBinContent(muBin);
227 }
228
229 return numer / total;
230}

◆ GetIntegratedLumiFraction() [2/2]

Double_t TPileupReweighting::GetIntegratedLumiFraction ( Int_t periodNumber,
UInt_t start,
UInt_t end )

return fraction of lumi assigned to periodNumber (or mcRunNumber) that is between start and end data run numbers

Definition at line 182 of file TPileupReweighting.cxx.

182 {
183 if(!m_isInitialized) {
184 if (m_printInfo) {
185 Info("GetIntegratedLumiFraction","Initializing the subtool..");
186 }
187 Initialize();
188 }
189
191 Error("GetIntegratedLumiFraction","No UNPRESCALED (Trigger=None) Lumicalc file loaded, so no lumi fraction possible, returning 0");
192 return 0;
193 }
194 //total lumi in period is given by sumOfWeights[-1]
195 double total = m_periods[periodNumber]->sumOfWeights[-1];
196 //go through associated runs, adding up lumi from all within start and end (inclusive)
197 double numer(0);
198 for(auto run : m_periods[periodNumber]->runNumbers) {
199 if(run >= start && run <= end) numer += m_runs[run].inputHists["None"]->GetSumOfWeights();
200 }
201 return numer / total;
202}

◆ GetLumiBlockIntegratedLumi()

Double_t TPileupReweighting::GetLumiBlockIntegratedLumi ( Int_t runNumber,
UInt_t lb )

get integrated lumi for specific run and lumiblock number .

. comes from the 'unprescaled lumi', and is in pb

Definition at line 154 of file TPileupReweighting.cxx.

154 {
155 if(!m_isInitialized) {
156 if (m_printInfo) {
157 Info("GetIntegratedLumi","Initializing the subtool..");
158 }
159 Initialize();
160 }
161 if(m_runs.find(runNumber)==m_runs.end()) return 0.;
162 auto& run = m_runs[runNumber];
163
164 if(run.lumiByLbn.find(lb)==run.lumiByLbn.end()) return 0.;
165 return run.lumiByLbn[lb].first*1E-6;
166}
int lb
Definition globals.cxx:23

◆ GetLumiBlockMu()

Float_t TPileupReweighting::GetLumiBlockMu ( Int_t runNumber,
UInt_t lb )

get the lumiblock mu, useful for 'updating' the mu coming from data to account for new lumitags

Definition at line 168 of file TPileupReweighting.cxx.

168 {
169 if(!m_isInitialized) {
170 if (m_printInfo) {
171 Info("GetLumiBlockMu","Initializing the subtool..");
172 }
173 Initialize();
174 }
175 if(m_runs.find(runNumber)==m_runs.end()) return -1.0;
176 auto& run = m_runs[runNumber];
177
178 if(run.lumiByLbn.find(lb)==run.lumiByLbn.end()) return -1.0;
179 return run.lumiByLbn[lb].second;
180}

◆ GetMetaData()

Double_t CP::TPileupReweighting::GetMetaData ( const TString & metadataName,
Int_t channelNumber )
inline

Definition at line 188 of file TPileupReweighting.h.

188 {
189 if(m_metadata.find(metadataName)==m_metadata.end()) {
190 Error("GetMetaData","Metadata %s not known",metadataName.Data());
191 return 0;
192 }
193 if(m_metadata[metadataName].find(channelNumber)==m_metadata[metadataName].end()) {
194 Error("GetMetaData","Metadata %s not known in channel %d",metadataName.Data(), channelNumber);
195 return 0;
196 }
197 return m_metadata[metadataName][channelNumber];
198 }
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:140

◆ GetMetaDataTree()

TTree * TPileupReweighting::GetMetaDataTree ( )

combines loaded metadata with channel sumsofweights and entry counts

Definition at line 574 of file TPileupReweighting.cxx.

574 {
576 m_metadatatree = new TTree(TString(this->GetName())+"MetaData",TString(this->GetName())+"MetaData");
577 m_metadatatree->SetDirectory(0);
578 Int_t channel=0;
579 m_metadatatree->Branch("mc_channel_number",&channel);
580 std::map<TString,Double_t> data;
581 std::map<Int_t,bool> channels;
582 //create a branch for each metadata item
583 for(std::map<TString,std::map<Int_t,Double_t> >::iterator it=m_metadata.begin();it!=m_metadata.end();++it) {
584 for(std::map<Int_t,Double_t>::iterator it2=(it->second).begin();it2!=(it->second).end();++it2) {
585 channels[it2->first]=true; //records which channels we have metadata for
586 }
587 const auto &[ptr, inserted ] = data.try_emplace(it->first, 0.);
588 if (inserted){
589 m_metadatatree->Branch(it->first,&(data[it->first]));
590 }
591 }
592 //also create branches for the NumberOfEvents and SumOfEventWeights
593 data["NumberOfEvents"]=0.;
594 m_metadatatree->Branch("NumberOfEvents",&(data["NumberOfEvents"]));
595 data["SumOfEventWeights"]=0.;
596 m_metadatatree->Branch("SumOfEventWeights",&(data["SumOfEventWeights"]));
597 //and add to channels list any channels that have events
598 auto& myMap = m_periods[-1]->sumOfWeights;
599 for(std::map<Int_t,Double_t>::iterator it=myMap.begin();it!=myMap.end();++it) {
600 if(it->first>=0 && it->second>0.) channels[it->first]=true;
601 }
602
603 //now loop over the channels and fill the TTree
604 for(std::map<Int_t,bool>::iterator it=channels.begin();it!=channels.end();++it) {
605 channel=it->first;
606 for(std::map<TString,Double_t>::iterator it2=data.begin();it2!=data.end();++it2) {
607 if(it2->first=="NumberOfEvents") {
608 //check for this in globalNumberOfEntries
609 if(myMap.find(channel)==myMap.end()) {
610 data[it2->first]=0.;
611 Warning("GetMetaDataTree","Channel %d does not have MetaData %s",it->first,(it2->first).Data());
612 } else {
613 data[it2->first]=m_periods[-1]->numberOfEntries[channel];
614 }
615 } else if(it2->first=="SumOfEventWeights") {
616 //check for this in globalTotals
617 auto& myMap2 = m_periods[-1]->sumOfWeights;
618 if(myMap2.find(channel)==myMap2.end()) {
619 data[it2->first]=0.;
620 Warning("GetMetaDataTree","Channel %d does not have MetaData %s",it->first,(it2->first).Data());
621 } else {
622 data[it2->first]=m_periods[-1]->sumOfWeights[channel];
623 }
624 } else {
625 auto& myMap2 = m_metadata[it2->first];
626 if(myMap2.find(channel)==myMap2.end()) {
627 //this channel doesn't have this property
628 data[it2->first]=0.;
629 Warning("GetMetaDataTree","Channel %d does not have MetaData %s",it->first,(it2->first).Data());
630 } else {
631 data[it2->first]=myMap2[channel];
632 }
633 }
634 }
635 m_metadatatree->Fill();
636 }
637
638 m_metadatatree->BuildIndex("mc_channel_number");
639 m_metadatatree->ResetBranchAddresses();
640
641 return m_metadatatree;
642}
JetConstituentVector::iterator iterator

◆ GetNearestGoodBin()

Int_t TPileupReweighting::GetNearestGoodBin ( Int_t thisMCRunNumber,
Int_t bin )
protected

Definition at line 1373 of file TPileupReweighting.cxx.

1373 {
1374
1375 int binDistance = 1;
1376 do {
1377 int res1 = IsBadBin(thisMCRunNumber,bin+binDistance);
1378 if(!res1) return bin+binDistance;
1379 int res2 = IsBadBin(thisMCRunNumber,bin-binDistance);
1380 if(!res2) return bin-binDistance;
1381 if(res1==2 && res2==2) { //run out of bins
1382 Error("GetNearestGoodBin", "None of the bins are good!!??");
1383 return -1;
1384 }
1385 binDistance++;
1386 } while(true); //scary!
1387
1388 return -1;
1389
1390}
Int_t IsBadBin(Int_t thisMCRunNumber, Int_t bin)

◆ GetNumberOfEvents()

Double_t CP::TPileupReweighting::GetNumberOfEvents ( Int_t channel)
inline

totalMC maps should also hold the total number of entries for each channel

Definition at line 73 of file TPileupReweighting.h.

73 {
74 Period* global = m_periods[-1];
75 if(!global) return 0;
76 if(global->numberOfEntries.find(channel)==global->numberOfEntries.end()) {
77 Error("GetNumberOfEvents", "Unknown channel: %d",channel);
78 return 0;
79 }
80 return global->numberOfEntries[channel];
81 }

◆ GetPeriodNumbers()

std::vector< int > CP::TPileupReweighting::GetPeriodNumbers ( ) const
inline

Definition at line 242 of file TPileupReweighting.h.

242 {
243 std::vector<int> out;
244 for(auto& p : m_periods) { out.push_back(p.first); }
245 return out;
246 }

◆ GetPeriodWeight()

Float_t TPileupReweighting::GetPeriodWeight ( Int_t periodNumber,
Int_t channelNumber )

Definition at line 1629 of file TPileupReweighting.cxx.

1629 {
1630 //= L_A/L / N_A/N
1631 if(!m_isInitialized) {
1632 if (m_printInfo) Info("GetPeriodWeight","Initializing the subtool..");
1633 Initialize();
1634 }
1635 if(m_countingMode) return 0.;
1636
1637 Period* p = m_periods[periodNumber];
1638 if(!p) {
1639 Error("GetPeriodWeight","Unrecognised periodNumber: %d",periodNumber);
1640 throw std::runtime_error("Throwing 1: Unrecognised periodNumber");
1641 }
1642 if(p->sumOfWeights.find(channelNumber) == p->sumOfWeights.end()) {
1643 channelNumber = GetDefaultChannel(periodNumber);//p->defaultChannel;
1644 if(channelNumber!=0) {
1645 Warning("GetPeriodWeight","You're using a default config file ... you're gonna have a bad time!!");
1646 Warning("GetPeriodWeight","Please generate proper config files!");
1647 }
1648 }
1649
1650 double n_a = p->sumOfWeights[channelNumber];
1651 double n = m_periods[-1]->sumOfWeights[channelNumber];
1652
1653 double l_a = p->sumOfWeights[-1];
1654 double l = m_periods[-1]->sumOfWeights[-1];
1655
1656 return (l_a/l) / (n_a/n);
1657}
l
Printing final latex table to .tex output file.

◆ GetPrescaleWeight() [1/2]

Double_t TPileupReweighting::GetPrescaleWeight ( Int_t runNumber,
const TString & trigger )

Definition at line 1823 of file TPileupReweighting.cxx.

1823 {
1824 //special mu-independent version of GetPrescaleWeight. Will just use the global luminosity
1826 double out = GetPrescaleWeight(runNumber, trigger, 0);
1828 return out;
1829}
Double_t GetPrescaleWeight(Int_t runNumber, const TString &trigger, Double_t x, bool run_dependent=false)
Method for prescaling MC to account for prescales in data.

◆ GetPrescaleWeight() [2/2]

Double_t TPileupReweighting::GetPrescaleWeight ( Int_t runNumber,
const TString & trigger,
Double_t x,
bool run_dependent = false )

Method for prescaling MC to account for prescales in data.

Definition at line 1831 of file TPileupReweighting.cxx.

1831 {
1832
1833 m_doPrescaleWeight = true;
1834 double out = GetDataWeight(runNumber,trigger,x,runDependent);
1835 m_doPrescaleWeight = false;
1836 if(out<=0) return 0; //happens when triggers disabled/unavailable for a given mu ... therefore the prescale weight is 0
1837 return 1./out;
1838
1839}

◆ GetPrimaryDistribution()

TH1 * CP::TPileupReweighting::GetPrimaryDistribution ( Int_t channelNumber,
Int_t periodNumber )
inline

Definition at line 259 of file TPileupReweighting.h.

259 {
260 if(m_periods.find(periodNumber)==m_periods.end()||
261 m_periods[periodNumber]->primaryHists.find(channelNumber)==m_periods[periodNumber]->primaryHists.end()) {
262 return 0;
263 }
264 return m_periods[periodNumber]->primaryHists[channelNumber].get();
265 }

◆ GetPrimaryTriggerDistribution()

TH1 * CP::TPileupReweighting::GetPrimaryTriggerDistribution ( const TString & trigger,
Int_t periodNumber,
long triggerBits )
inline

Definition at line 267 of file TPileupReweighting.h.

267 {
268 if(m_triggerObjs.find(trigger)==m_triggerObjs.end() || m_triggerObjs[trigger]->triggerHists.find(periodNumber) ==m_triggerObjs[trigger]->triggerHists.end() ||
269 m_triggerObjs[trigger]->triggerHists[periodNumber].find(triggerBits) == m_triggerObjs[trigger]->triggerHists[periodNumber].end()) return 0;
270 /*
271 if(m_triggerObjs.find(trigger)==m_triggerObjs.end() || m_triggerObjs.at(trigger).second->triggerHists.find(periodNumber)==m_triggerObjs.at(trigger).second->->triggerHists.end() ||
272 m_triggerObjs.at(trigger).second->triggerHists.at(periodNumber).find(triggerBits) == m_triggerObjs.at(trigger).second.at(periodNumber).end()) return 0;
273 */
274
275 return m_triggerObjs[trigger]->triggerHists[periodNumber][triggerBits].get();
276 }

◆ GetPrimaryWeight()

Float_t TPileupReweighting::GetPrimaryWeight ( Int_t periodNumber,
Int_t channelNumber,
Float_t x )

Definition at line 1659 of file TPileupReweighting.cxx.

1659 {
1660 //= L_i/L_A / N_i/N_A .. primaryHists have already been normalized
1661 if(!m_isInitialized ) {
1662 if (m_printInfo) Info("GetPrimaryWeight","Initializing the subtool..");
1663 Initialize();
1664 }
1665 if(m_countingMode) return 0.;
1666
1667 Period* p = m_periods[periodNumber];
1668 if(!p) {
1669 Error("GetPrimaryWeight","Unrecognised periodNumber: %d",periodNumber);
1670 throw std::runtime_error("Throwing 1: Unrecognised periodNumber");
1671 }
1672 int oChanNumber = channelNumber;
1673 if(p->sumOfWeights.find(channelNumber) == p->sumOfWeights.end()) channelNumber = GetDefaultChannel(periodNumber);//p->defaultChannel;
1674
1675 if(!p->primaryHists[channelNumber]) {
1676 Error("GetPrimaryWeight","Unrecognised channelNumber %d for periodNumber %d",oChanNumber,periodNumber);
1677 throw std::runtime_error("Throwing 2: Unrecognised channelNumber");
1678 }
1679
1680 int bin = p->primaryHists[channelNumber]->FindFixBin(x);
1681
1682 double n = p->primaryHists[channelNumber]->GetBinContent(bin);
1683
1684 // There is a special case that needs some additional protection
1685 // If you have the sum of weights ==0 for a given mu then you will have 0 in the PRW
1686 // profile leading to an exception or FPE later
1687 if (n==0){
1688 Warning("GetPrimaryWeight","No events expected in channelNumber %d for periodNumber %d with x=%g. Incorrect PRW profile or are you very unlucky???",channelNumber,periodNumber,x);
1689 return 1.;
1690 }
1691
1692 if(!p->primaryHists[-1]) {
1693 Error("GetPrimaryWeight","No data loaded for period %d. Did you forget to load a lumicalc file or data config file?",periodNumber);
1694 throw std::runtime_error("Throwing 3: No data loaded. Did you forget to load a lumicalc file or data config file?");
1695 }
1696
1697 double l = p->primaryHists[-1]->GetBinContent(bin);
1698
1699 if (l==0 && n==0){
1700 Error("GetPrimaryWeight","No events expected with this mu. Incorrect PRW profile? Throwing exception ...");
1701 throw std::runtime_error(Form("Incorrect PRW profile detected. x=%g is not in the config file profile for channel %d, period %d", x, channelNumber, periodNumber ));
1702 }
1703
1704 return l/n;
1705}

◆ GetPRWHash()

ULong64_t TPileupReweighting::GetPRWHash ( Int_t periodNumber,
Int_t channelNumber,
Float_t x,
Float_t y = 0. )

Definition at line 1590 of file TPileupReweighting.cxx.

1590 {
1591 if(!m_isInitialized) {
1592 if (m_printInfo) Info("GetPRWHash","Initializing the subtool..");
1593 Initialize();
1594 }
1595 TH1* hist = m_emptyHistogram.get();
1596 if(!hist) {
1597 Error("GetPRWHash","Tool not configured properly ... please report this!");
1598 throw std::runtime_error("Throwing 47: Tool not configured properly ... please report this!");
1599 }
1600
1601 ULong64_t out = hist->FindFixBin(x,y);
1602 out += (unsigned long)(channelNumber)*10000000000;
1603 out += (unsigned long)(periodNumber)*10000;
1604
1605 return out;
1606
1607}

◆ GetRandomLumiBlockNumber()

UInt_t TPileupReweighting::GetRandomLumiBlockNumber ( UInt_t runNumber)

Get a random lumi block from the run number given.

Use GetRandomRunNumber to choose the run number

Definition at line 1475 of file TPileupReweighting.cxx.

1475 {
1476 if(!m_isInitialized) {
1477 if (m_printInfo) {
1478 Info("GetRandomLumiBlockNumber","Initializing the subtool..");
1479 }
1480 Initialize();
1481 }
1482 if(m_countingMode) { return 0; } //do nothing when in counting mode
1483
1484 double lumi = GetIntegratedLumi(runNumber,runNumber) * m_random3->Rndm() * 1E6 /* dont forget the lumi was divided by a million to get to pb */;
1485 double lumisum = 0.;
1486
1487 for(auto& lbn : m_runs[runNumber].lumiByLbn) {
1488 if(m_unrepresentedDataAction==1 && IsUnrepresentedData(runNumber,lbn.second.second)) continue; //skip over bad lumi
1489 lumisum += lbn.second.first;
1490 if(lumisum >= lumi) return lbn.first;
1491 }
1492 Error("GetRandomLumiBlockNumber","overran integrated luminosity for RunNumber=%d (%f vs %f)",runNumber,lumi,lumisum);
1493 throw std::runtime_error("Throwing 46: overran integrated luminosity for runNumber");
1494 return 0;
1495}
std::unique_ptr< TRandom3 > m_random3
Bool_t IsUnrepresentedData(Int_t runNumber, Float_t x, Float_t y=0.)

◆ GetRandomPeriodNumber()

Int_t TPileupReweighting::GetRandomPeriodNumber ( Int_t mcRunNumber)

Get random period number from the sub-periods assigned to this run number.

Definition at line 1498 of file TPileupReweighting.cxx.

1498 {
1499 if(!m_isInitialized) {
1500 if (m_printInfo) Info("GetRandomPeriodNumber","Initializing the subtool..");
1501 Initialize();
1502 }
1503 if(m_countingMode) { return 0; } //do nothing when in counting mode
1504
1505 Period* p = m_periods[periodNumber];
1506 if(!p) {
1507 Error("GetRandomPeriodNumber","Unrecognised periodNumber: %d",periodNumber);
1508 throw std::runtime_error("Throwing 1: Unrecognised periodNumber");
1509 }
1510
1511 //if no subperiods, we just return ourselves
1512 if(p->subPeriods.size()==0) return p->id;
1513
1514 //need the total lumi of this period
1515 double lumi = p->sumOfWeights[-1] * m_random3->Rndm();
1516
1517 //loop over subPeriods ..
1518 double lumiSum=0;
1519 for(auto subp : p->subPeriods) {
1520 lumiSum += subp->sumOfWeights[-1];
1521 if(lumiSum >= lumi) return subp->id;
1522 }
1523
1524 Error("GetRandomPeriodNumber","overran integrated luminosity for periodNumber=%d",periodNumber);
1525 throw std::runtime_error("Throwing 46.1: overran integrated luminosity for GetRandomPeriodNumber");
1526 return 0;
1527
1528}

◆ GetRandomRunNumber() [1/2]

UInt_t TPileupReweighting::GetRandomRunNumber ( Int_t mcRunNumber)

Gets a random data run number according to the integrated lumi distribution associated to this mcRunNumber.

allows use of custom reweighting config files

Definition at line 1418 of file TPileupReweighting.cxx.

1418 {
1419 if(!m_isInitialized) {
1420 if (m_printInfo)Info("GetRandomRunNumber","Initializing the subtool..");
1421 Initialize();
1422 }
1423 if(m_countingMode) { return 0; } //do nothing when in counting mode
1424
1425 Period* p = m_periods[periodNumber];
1426 if(!p || !p->primaryHists[-1]) {
1427 Error("GetRandomRunNumber","Unrecognised periodNumber or no data loaded for: %d",periodNumber);
1428 throw std::runtime_error("Throwing 1: Unrecognised periodNumber");
1429 }
1430
1431 double lumi = p->sumOfWeights[-1] * m_random3->Rndm();
1432
1433 //go through the runs assigned to this period ...
1434 double lumiSum=0;
1435 for(auto runNum : p->runNumbers) {
1436 lumiSum += m_runs[runNum].inputHists["None"]->GetSumOfWeights();
1437 if(lumiSum >= lumi-0.00001) return runNum; //small difference is to catch rounding errors
1438 }
1439 Error("GetRandomRunNumber","overran integrated luminosity for periodNumber=%d (%f vs %f)",periodNumber,lumiSum,lumi);
1440 throw std::runtime_error("Throwing 46.1: overran integrated luminosity for GetRandomRunNumber");
1441 return 0;
1442}

◆ GetRandomRunNumber() [2/2]

UInt_t TPileupReweighting::GetRandomRunNumber ( Int_t mcRunNumber,
Double_t mu )

Get random run number according to integrated lumi distribution for the given mu value (uses the binning of the mu histogram).

Definition at line 1444 of file TPileupReweighting.cxx.

1444 {
1445 if(!m_isInitialized) {
1446 if (m_printInfo) Info("GetRandomRunNumber","Initializing the subtool..");
1447 Initialize();
1448 }
1449 if(m_countingMode) { return 0; } //do nothing when in counting mode
1450
1451 Period* p = m_periods[periodNumber];
1452 if(!p || !p->primaryHists[-1]) {
1453 Error("GetRandomRunNumber","Unrecognised periodNumber or no data loaded for: %d",periodNumber);
1454 throw std::runtime_error("Throwing 1: Unrecognised periodNumber");
1455 }
1456
1457 int bin = m_emptyHistogram->FindFixBin(x);
1458
1459 double lumi = p->primaryHists[-1]->GetBinContent(bin) * p->sumOfWeights[-1] * m_random3->Rndm();
1460
1461 if(!lumi) { return 0; } //no lumi with that mu
1462
1463
1464 //go through the runs assigned to this period ...
1465 double lumiSum=0;
1466 for(auto runNum : p->runNumbers) {
1467 lumiSum += m_runs[runNum].inputHists["None"]->GetBinContent(bin);
1468 if(lumiSum >= lumi-0.00001) return runNum; //small difference is to catch rounding errors
1469 }
1470 Error("GetRandomRunNumber","overran integrated luminosity for periodNumber=%d (%f vs %f)",periodNumber,lumiSum,lumi);
1471 throw std::runtime_error("Throwing 46.1: overran integrated luminosity for GetRandomRunNumber");
1472 return 0;
1473}

◆ GetRandomSeed()

int CP::TPileupReweighting::GetRandomSeed ( )
inline

Definition at line 223 of file TPileupReweighting.h.

223{return m_random3->GetSeed();}

◆ GetRunAverageMu()

double CP::TPileupReweighting::GetRunAverageMu ( int run)
inline

Definition at line 303 of file TPileupReweighting.h.

303{ return m_runs[run].inputHists["None"]->GetMean(); }

◆ GetRunMap()

std::map< UInt_t, Run > & CP::TPileupReweighting::GetRunMap ( )
inline

Definition at line 454 of file TPileupReweighting.h.

454{ return m_runs; }

◆ GetSecondaryWeight()

Float_t TPileupReweighting::GetSecondaryWeight ( Int_t periodNumber,
Int_t channelNumber,
Float_t x,
Float_t y )

Definition at line 1707 of file TPileupReweighting.cxx.

1707 {
1708 //= L_j/L_i / N_j/N_i .. secondary hists have already been normalized
1709 if(!m_isInitialized ) {
1710 if (m_printInfo) Info("GetSecondaryWeight","Initializing the subtool..");
1711 Initialize();
1712 }
1713 if(m_countingMode) return 0.;
1714
1715 Period* p = m_periods[periodNumber];
1716 if(!p) {
1717 Error("GetSecondaryWeight","Unrecognised periodNumber: %d",periodNumber);
1718 throw std::runtime_error("Throwing 1: Unrecognised periodNumber");
1719 }
1720 if(p->sumOfWeights.find(channelNumber) == p->sumOfWeights.end()) channelNumber = GetDefaultChannel(periodNumber);//p->defaultChannel;
1721 int bin = p->secondaryHists[channelNumber]->FindFixBin(x,y);
1722 double n = p->secondaryHists[channelNumber]->GetBinContent(bin);
1723 double l = p->secondaryHists[-1]->GetBinContent(bin);
1724
1725 return l/n;
1726}

◆ GetSumOfEventWeights()

Double_t CP::TPileupReweighting::GetSumOfEventWeights ( Int_t channel)
inline

Definition at line 82 of file TPileupReweighting.h.

82 {
83 Period* global = m_periods[-1];
84 if(!global) return 0;
85 if(global->sumOfWeights.find(channel)==global->sumOfWeights.end()) {
86 Error("GetSumOfEventWeights", "Unknown channel: %d",channel);
87 return 0;
88 }
89 return global->sumOfWeights[channel];
90 }

◆ GetUnrepresentedDataFraction()

Double_t TPileupReweighting::GetUnrepresentedDataFraction ( Int_t periodNumber,
Int_t channel )

return the unrepresented data fraction in a given channel .

. when using action=2, you will want to scale up all MC events by 1/(1-unrepFraction) to account for missed data

Definition at line 1392 of file TPileupReweighting.cxx.

1392 {
1393
1394 //return unrepDataByChannel[channel]/GetSumOfEventWeights(-1); //the denominator is equivalent to asking for the total data!
1395
1396
1397 Period* p = m_periods[periodNumber];
1398 if(!p) {
1399 Error("GetUnrepresentedDataFraction","Unrecognised periodNumber: %d",periodNumber);
1400 throw std::runtime_error("Throwing 1: Unrecognised periodNumber");
1401 }
1402
1403 //look for channel through sumOfWeights - because if the channel has no unrepData, it will have no entry in the unrepData map
1404 if(p->sumOfWeights.find(channel) == p->sumOfWeights.end()) channel = GetDefaultChannel(periodNumber);
1405
1406
1407 if(p->sumOfWeights.find(channel) == p->sumOfWeights.end()) {
1408 Error("GetUnrepresentedDataFraction","Unrecognised channel: %d",channel);
1409 throw std::runtime_error("GetUnrepresentedDataFraction: Unrecognised channel");
1410 }
1411
1412 return p->unrepData[channel]/p->sumOfWeights[-1];
1413
1414}

◆ GetUnrepresentedDataWeight()

Float_t CP::TPileupReweighting::GetUnrepresentedDataWeight ( Int_t periodNumber,
Int_t channel )
inline

Definition at line 134 of file TPileupReweighting.h.

134 {
136 Warning("GetUnrepresentedDataWeight","You should not be applying this weight unless the UnrepresentedDataAction=2");
137 }
138 return 1./(1. - GetUnrepresentedDataFraction(periodNumber,channel));
139 }
Double_t GetUnrepresentedDataFraction(Int_t periodNumber, Int_t channel)
return the unrepresented data fraction in a given channel .

◆ IgnoreConfigFilePeriods()

void CP::TPileupReweighting::IgnoreConfigFilePeriods ( Bool_t in)
inline

Should the tool ignore period assignments encoded in config file.

Definition at line 146 of file TPileupReweighting.h.

◆ Initialize()

Int_t TPileupReweighting::Initialize ( )

Initialize this class once before the event loop starts If distribution information is provided, it is assumed to be for the standard pileup reweighting.

Definition at line 1021 of file TPileupReweighting.cxx.

1021 {
1022
1023 //Need to calculate a period weight for each period
1024 //Need a reweighting histogram for each period
1025 //for merged mc run numbers, we must generate or modify the existing mc distributions
1026
1027 //print out the period assignments if in debug mode
1028 if(m_debugging) {
1029 PrintPeriods();
1030 }
1031
1032 if(m_countingMode) {
1033 if (m_printInfo) {
1034 Info("Initialize","In Config File Generating mode. Remember to call WriteToFile!");
1035 }
1036 //need to check no periods have subperiods, this is not allowed in counting mode
1037 for(auto period : m_periods) {
1038 if(period.second->subPeriods.size()!=0) {
1039 Error("Initialize","You cannot have subperiods when in Config File Generating mode");
1040 throw std::runtime_error("Throwing 44: In Config File Generating mode, but detected subperiods in the period definition. This is not allowed.");
1041 }
1042 }
1043 //histograms are instantiated in the event loop as the channels occur
1044 //can delay period definition here
1045 m_isInitialized=true;
1046 return 0;
1047 }
1048
1049 //find all channels that have too much unrepresented data (more than tolerance). We will remove these channels entirely
1050
1051 std::map<int,std::map<int,bool>> trackWarnings; //map used to avoid reprinting warnings as loop over histogram bins
1052
1053 double totalData(0);
1054 //count up the unrepresented data, indexed by channel
1055 for(auto& run : m_runs) {
1056 if(run.second.inputHists.find("None") == run.second.inputHists.end()) continue;
1057 TH1* hist = run.second.inputHists["None"].get();
1058 Int_t bin,binx,biny;
1059 for(biny=1; biny<=hist->GetNbinsY(); biny++) {
1060 for(binx=1; binx<=hist->GetNbinsX(); binx++) {
1061 bin = hist->GetBin(binx,biny);
1062 Double_t value = hist->GetBinContent(bin);
1063 totalData += value;
1064 if(value==0.) continue;
1065 bool isUnrep(false);
1066 std::map<Int_t, bool> doneChannels;
1067 for(auto& period : m_periods) {
1068 if(period.first != period.second->id) continue; //skip remappings
1069 if(period.first == -1) continue; //don't look at the global period when calculating unrepresented data
1070 if(!period.second->contains(run.first)) continue;
1071 for(auto& inHist : m_periods[-1]->inputHists) { //use global period to iterate over channels
1072 if(inHist.first<0) continue; //skips any data hists (shouldn't happen really)
1073 if(doneChannels[inHist.first]) continue; //dont doublecount the data if the channel was to blame across multiple period
1074 if(period.second->inputHists.find(inHist.first)==period.second->inputHists.end()) {
1075 //all the data is missing ..
1076 isUnrep=true;doneChannels[inHist.first]=true;
1077 unrepDataByChannel[inHist.first] += value;
1078 if(!trackWarnings[inHist.first][period.first]) {
1079 trackWarnings[inHist.first][period.first]=true;
1080 Warning("Initialize","Channel %d has no configuration for period %d -- this is symptomatic of you trying to reweight an MC campaign to data not intended for that campaign (e.g. MC16a with 2017 data)",inHist.first,period.first);
1081 }
1082 } else if(period.second->inputHists[inHist.first]->GetBinContent(bin)==0) {
1083 //hist for this channel in this period exists, but this bin is empty
1084 isUnrep=true;doneChannels[inHist.first]=true;
1085 unrepDataByChannel[inHist.first] += value;
1086 }
1087 }
1088 }
1089 if(isUnrep) unrepDataByChannel[-1] += value; //store total unrep data
1090 }
1091 }
1092 }
1093 if (totalData == 0.){ //should be impossible
1094 Error("Initialize", "totalData is still zero.");
1095 }
1096 if(m_ignoreBadChannels && unrepDataByChannel[-1] && totalData && (unrepDataByChannel[-1]/totalData)>m_unrepDataTolerance) {
1097 Warning("Initialize","There is %f%% unrepresented data and 'IgnoreBadChannels' property is set to true. Will start ignoring channels until this is below the tolerance (%f%%)", 100.*(unrepDataByChannel[-1]/totalData),100.*m_unrepDataTolerance);
1098 //remove channels one-by-one until we are under tolerance
1099 while( (unrepDataByChannel[-1]/totalData)>m_unrepDataTolerance ) {
1100 int worstChannel = -1;
1101 double worstFraction = 0;
1102 for(auto& channel : unrepDataByChannel) {
1103 if(channel.first<0) continue; //ignore the data
1104 if(channel.second/totalData > worstFraction) { worstChannel=channel.first; worstFraction = channel.second/totalData; }
1105 }
1106 if(worstChannel==-1) {
1107 Error("Initialize","Run out of channels to remove. All your channels are bad ... oh dear oh dear oh dear. Please a better PRW config file");
1108 throw std::runtime_error("Throwing exception 333: Run out of channels to remove. All your channels are bad ... oh dear oh dear oh dear. Please a better PRW config file");
1109 }
1110
1111 Warning("Initialize","Ignoring channel %d, which has %f%% unrepresented data (%f%% of the total unrep data)",worstChannel,100.*unrepDataByChannel[worstChannel]/totalData,100.*unrepDataByChannel[worstChannel]/unrepDataByChannel[-1]);
1112 //remove the bad channel
1113 RemoveChannel(worstChannel);
1114 unrepDataByChannel.erase(unrepDataByChannel.find(worstChannel));
1115
1116 //recalculate the total unrep data
1117 unrepDataByChannel[-1] = 0;
1118 for(auto& run : m_runs) {
1119 if(run.second.inputHists.find("None") == run.second.inputHists.end()) continue;
1120 TH1* hist = run.second.inputHists["None"].get();
1121 Int_t bin,binx,biny;
1122 for(biny=1; biny<=hist->GetNbinsY(); biny++) {
1123 for(binx=1; binx<=hist->GetNbinsX(); binx++) {
1124 bin = hist->GetBin(binx,biny);
1125 Double_t value = hist->GetBinContent(bin);
1126 if(value==0.) continue;
1127 for(auto& period : m_periods) {
1128 if(period.first != period.second->id) continue; //skip remappings
1129 if(!period.second->contains(run.first)) continue;
1130 bool done(false);
1131 for(auto& inHist : period.second->inputHists) {
1132 if(inHist.first<0) continue; //skips any data hists (shouldn't happen really)
1133 if((inHist.second)->GetBinContent(bin)==0) {
1134 unrepDataByChannel[-1] += value; done=true; break;
1135 }
1136 }
1137 if(done) break;
1138 }
1139 }
1140 }
1141 }
1142 }
1143 }
1144
1145
1146 //need a CompositeTrigger to hold the unprescaled lumi hists ...
1147 m_triggerObjs["None"] = std::make_unique< CompositeTrigger >();
1148
1149 //go through all periods, use inputHists to populate the primary and secondary dists, and fill sumOfWeights and numberOfEntries
1150 for(auto period : m_periods) {
1151 if(period.first != period.second->id) continue; //skips remappings
1152 for(auto& inputHist : period.second->inputHists) {
1153 int channel = inputHist.first;
1154 TH1* hist = inputHist.second.get();
1155 period.second->sumOfWeights[channel] += hist->GetSumOfWeights();
1156 period.second->numberOfEntries[channel] += hist->GetEntries();
1157 if(hist->GetDimension()==1) {
1158 period.second->primaryHists[channel] = CloneEmptyHistogram(period.first,channel);
1159 period.second->primaryHists[channel]->Add(hist);
1160 }
1161 }
1162 //also add all runs that belong to us ... only do the "None" trigger
1163 for(auto& run : m_runs) {
1164 if(!period.second->contains(run.first)) continue;
1165 if(run.second.inputHists.find("None") == run.second.inputHists.end()) continue;
1166 //add to list of runNumbers for this period
1167 period.second->runNumbers.push_back(run.first);
1168 TH1* hist = run.second.inputHists["None"].get();
1169
1170 //sweep over bins, checking for unrepresented data and acting accordingly
1171 Int_t bin,binx,biny;
1172 for(biny=1; biny<=hist->GetNbinsY(); biny++) {
1173 for(binx=1; binx<=hist->GetNbinsX(); binx++) {
1174 bin = hist->GetBin(binx,biny);
1175 Double_t value = hist->GetBinContent(bin);
1176 if(value==0.) continue;
1177 //loop over channels, check for zero in this bin ... only need to do if we haven't checked ourselves
1178 if(period.second->inputBinRedirect.find(bin) == period.second->inputBinRedirect.end()) {
1179 for(auto& inputHist : period.second->inputHists) {
1180 if(inputHist.first<0) continue; //skips data
1181 Double_t mcValue = (inputHist.second)->GetBinContent(bin);
1182 if(mcValue==0.) {
1184 Info("Initialize","Unrepresented data at coords [%f,%f] caused by periodNumber %d in channel %d",hist->GetXaxis()->GetBinCenter(binx),hist->GetYaxis()->GetBinCenter(biny),period.first,inputHist.first);
1185 }
1186 //if we are doing unrepaction=2, just set to 'not the bin number'. if we are doing action=3, find the nearest good bin
1187 if(m_unrepresentedDataAction==0) {period.second->inputBinRedirect[bin] = bin-1;Error("Initialize","Unrepresented data at coords [%f,%f] caused by periodNumber %d in channel %d",hist->GetXaxis()->GetBinCenter(binx),hist->GetYaxis()->GetBinCenter(biny),period.first,inputHist.first);}
1188 if(m_unrepresentedDataAction==1||m_unrepresentedDataAction==2) period.second->inputBinRedirect[bin] = bin-1;
1189 else if(m_unrepresentedDataAction==3) period.second->inputBinRedirect[bin] = GetNearestGoodBin(period.first, bin);
1190 break;
1191 }
1192 }
1193 if(period.second->inputBinRedirect.find(bin) == period.second->inputBinRedirect.end()) period.second->inputBinRedirect[bin] = bin; //a good bin
1194 }
1195 //if is a bad bin, act accordingly
1196 if(period.second->inputBinRedirect[bin] != bin) {
1197 run.second.badBins[bin]=value;
1199 //remove this data. we have to remember to do this for the trigger data too if this is the pileup weight
1200 hist->SetBinContent(bin,0);
1201 //also modify the m_inputTriggerHistograms ...
1202 for(auto& triggerDists : run.second.inputHists) triggerDists.second->SetBinContent(bin,0);
1203 } else if(m_unrepresentedDataAction==3) {
1204 //reassign the content to that bin
1205 hist->SetBinContent(period.second->inputBinRedirect[bin],hist->GetBinContent(period.second->inputBinRedirect[bin])+hist->GetBinContent(bin));
1206 hist->SetBinContent(bin,0);
1207 //also modify the m_inputTriggerHistograms ...
1208 for(auto& triggerDists : run.second.inputHists) {
1209 triggerDists.second->SetBinContent(period.second->inputBinRedirect[bin],triggerDists.second->GetBinContent(period.second->inputBinRedirect[bin])+triggerDists.second->GetBinContent(bin));
1210 triggerDists.second->SetBinContent(bin,0);
1211 }
1212 }
1213 }
1214 }
1215 }
1216
1217 //ensure hist is normalized correctly, if was read in from the 'actual mu' config files (where the normalization can be slightly wrong)
1218 if(run.second.nominalFromHists) {
1219 //get the total lumi for the run ...
1220 double totLumi(0);
1221 for(auto lb : run.second.lumiByLbn) {
1222 totLumi += lb.second.first;
1223 }
1224 const double integral = hist->Integral();
1225 if (std::abs(integral) > 0.) {
1226 hist->Scale(totLumi / integral);
1227 }
1228
1229 }
1230
1231 //create the period's 'data' hist if necessary
1232 if( hist->GetDimension()==1 ) {
1233 if(!period.second->primaryHists[-1] ) {
1234 period.second->primaryHists[-1] = CloneEmptyHistogram(period.first,-1);
1235
1236 //this will remain unnormalized, unlike the 'primaryHist'
1237 m_triggerObjs["None"]->triggerHists[period.second->id][0] =
1238 CloneEmptyHistogram( period. first, -1 );
1239 }
1240 }
1241 else if( hist->GetDimension()==2 ) {
1242 if(!period.second->secondaryHists[-1] ) {
1243 auto h = CloneEmptyHistogram(period.first,-1);
1244 period.second->secondaryHists[-1].reset( dynamic_cast< TH2* >( h.release() ) );
1245 period.second->primaryHists[-1].reset(
1246 period.second->secondaryHists[-1]->ProjectionX() );
1247 period.second->primaryHists[-1]->SetDirectory(0);
1248 period.second->primaryHists[-1]->Reset();
1249 m_triggerObjs["None"]->triggerHists[period.second->id][0].reset(
1250 static_cast<TH1*>(period.second->primaryHists[-1]->Clone("triggerHist")) );
1251 m_triggerObjs["None"]->triggerHists[period.second->id][0]->SetDirectory(0);
1252 }
1253
1254 }
1255
1256 }
1257
1258 }
1259
1260
1261 //now that all periods and runs have been checked, with redirects set up where necessary, we actually accumulate the data across the runs
1262 //we should also check if there are any data runs that are not covered by the period assignments
1263
1264 double ignoredData(0);
1265 for(auto& run : m_runs) {
1266 bool covered(false);
1267 TH1* hist = run.second.inputHists["None"].get();
1268 for(auto& period : m_periods) {
1269 if(!period.second->contains(run.first)) continue;
1270 if(period.first!=-1) covered=true; //don't count the global period
1271 if(hist->GetDimension()==1) {
1272 period.second->primaryHists[-1]->Add(hist);
1273 m_triggerObjs["None"]->triggerHists[period.second->id][0]->Add(hist);
1274 } else if(hist->GetDimension()==2) {
1275 period.second->secondaryHists[-1]->Add(hist);
1276 TH1* proj = static_cast<TH2*>(hist)->ProjectionX();
1277 period.second->primaryHists[-1]->Add(proj);
1278 m_triggerObjs["None"]->triggerHists[period.second->id][0]->Add(proj);
1279 delete proj;
1280 }
1281 period.second->sumOfWeights[-1] += hist->GetSumOfWeights();
1282 period.second->numberOfEntries[-1] += hist->GetEntries();
1283 }
1284 if(!covered && m_periods.size()>1) {
1285 Warning("Initialize","loaded data in run %d that is not covered by period assignments",run.first);
1286 ignoredData += hist->GetSumOfWeights();
1287 }
1288 }
1289 //double totalData = (m_unrepresentedDataAction==1) ? (m_periods[-1]->sumOfWeights[-1]+unrepDataByChannel[-1]) : m_periods[-1]->sumOfWeights[-1];
1290 if (totalData == 0){
1291 Error("Initialize", "totalData is zero.");
1292 throw std::runtime_error("totalData is zero after summing. This should never happen.");
1293 }
1294 if(ignoredData>0.) Warning("Initialize", "Period Assignments missed %f%% data",100.*ignoredData/totalData);
1295 if(unrepDataByChannel[-1]) {
1296 double frac = unrepDataByChannel[-1]/totalData;
1297 if( frac > m_unrepDataTolerance) {
1298 Error("Initialize", "%f%% unrepresented data, which suggests something is wrong with your prw config. Try EnableDebugging(true) to investigate",100.* (unrepDataByChannel[-1]/totalData));
1299 }
1301 Warning("Initialize","has %f%% unrepresented data. This was removed (UnrepresentedDataAction=1)",100.*frac);
1302 } else if(m_unrepresentedDataAction==2) {
1303 Warning("Initialize","has %f%% unrepresented data. This was kept in (UnrepresentedDataAction=2)",100.*frac);
1304 } else if(m_unrepresentedDataAction==3) {
1305 if(frac >= m_unrepDataWarningThreshold) {
1306 Warning("Initialize","has %f%% unrepresented data."
1307 " This was reassigned (UnrepresentedDataAction=3)",
1308 100.*frac);
1309 }
1310 } else if(m_unrepresentedDataAction==0) {
1311 Error("Initialize","has %f%% unrepresented data:",100.*frac);
1312 //print the report of which channels caused it
1313 for(auto& it : unrepDataByChannel) {
1314 if(it.first<0) continue; //ignore data
1315 Error("Initialize"," Channel %d caused %f%% of the unrepresented data (nEntries=%d)",it.first,100.*it.second/unrepDataByChannel[-1],m_periods[-1]->numberOfEntries[it.first]);
1316 }
1317 Error("Initialize","Exiting. You must decide how to proceed...");
1318 Error("Initialize","1) use AddPeriod or RemapPeriod to redefine the mc periods to include this data. You should not need to regenerate your mc config file");
1319 Error("Initialize","2) use SetUnrepresentedDataAction(1) to remove this data from the weight calculations. You should also veto such data events (using IsUnrepresentedData(..,..) method)");
1320 Error("Initialize","3) use SetUnrepresentedDataAction(2) to leave this data in the calculation. I hope you know what you're doing!!");
1321 Error("Initialize","4) use SetUnrepresentedDataAction(3) to reassign the data to the nearest representable bin");
1322 throw std::runtime_error("Throwing exception 22: Unrepresented data exists. Make a choice how to handle this. See err log for details");
1323 }
1324 //if get here, through the exception if frac is bad
1325 if( frac > m_unrepDataTolerance) {
1326 throw std::runtime_error("Throwing exception 222: Some channel had too much unrepresented data. You should fix your prw file");
1327 }
1328 }
1329
1330
1331 if(m_debugging && m_printInfo) Info("Initialize","Normalizing histograms and cleaning up...");
1332 //now that all the distributions are built. Normalize them all
1333 for(auto period : m_periods) {
1334 if(period.first != period.second->id) continue;
1335 for(auto& pHist : period.second->primaryHists) {
1336 normalizeHistogram(pHist.second.get());
1337 }
1338 for(auto& pHist : period.second->secondaryHists) {
1339 normalizeHistogram(pHist.second.get());
1340 }
1341 period.second->inputHists.clear();
1342 }
1343
1344 //we keep the inputHists for data, because can use that to do random run numbers based on mu
1345
1346 if(m_debugging && m_printInfo) Info("Initialize","...Done");
1347 //if no input histograms were added, we are in counting mode
1348
1349
1350 m_isInitialized=true;
1351
1352 return 0;
1353}
void normalizeHistogram(TH1 *histo)
Normalize histograms.
std::map< Int_t, Double_t > unrepDataByChannel
Int_t GetNearestGoodBin(Int_t thisMCRunNumber, Int_t bin)
Bool_t RemoveChannel(int chanNum)
Removes a channel from the inputs ... this is for experts only.
double integral(TH1 *h)
Definition computils.cxx:59

◆ IsBadBin()

Int_t TPileupReweighting::IsBadBin ( Int_t thisMCRunNumber,
Int_t bin )
protected

Definition at line 1357 of file TPileupReweighting.cxx.

1357 {
1358
1359 if(bin<0) return 2; //out of range
1360
1361 Period* p = m_periods[periodNumber];
1362 for(auto& inHist : p->inputHists) {
1363 int channelNumber = inHist.first;
1364 if(channelNumber<0) continue; //skip data hists
1365 if(bin > (inHist.second->GetNbinsX()+2)*(inHist.second->GetNbinsY()+2)*(inHist.second->GetNbinsZ()+2)) return 2; //definitely out of range by this point!
1366 if(inHist.second->GetBinContent(bin)==0) return 1;
1367 }
1368 return 0;
1369
1370}

◆ IsInitialized()

Bool_t CP::TPileupReweighting::IsInitialized ( )
inline

Definition at line 288 of file TPileupReweighting.h.

288{ return m_isInitialized; }

◆ IsUnrepresentedData()

Bool_t TPileupReweighting::IsUnrepresentedData ( Int_t runNumber,
Float_t x,
Float_t y = 0. )

Definition at line 1530 of file TPileupReweighting.cxx.

1530 {
1531 int bin = m_emptyHistogram->FindFixBin(x,y);
1532 return ( m_runs[runNumber].badBins[bin] );
1533}

◆ makeTrigger()

std::unique_ptr< CP::TPileupReweighting::CompositeTrigger > TPileupReweighting::makeTrigger ( const TString & s)
protected

Definition at line 2284 of file TPileupReweighting.cxx.

2284 {
2285
2286 if( m_debugging && m_printInfo ) {
2287 Info( "makeTrigger", "Doing %s", s.Data() );
2288 }
2289
2290 // Find the first operand
2291 TString oper1;
2292 std::unique_ptr< CompositeTrigger > cOper1;
2293 if( s.BeginsWith( "(" ) ) {
2294 // Find closing bracket
2295 int bCounter=1; int i=1;
2296 while( ( bCounter != 0 ) && ( i <= s.Length() ) ) {
2297 if( s( i ) == '(' ) {
2298 bCounter++;
2299 } else if( s( i ) == ')' ) {
2300 bCounter--;
2301 }
2302 i++;
2303 }
2304 if( bCounter != 0 ) {
2305 Error( "makeTrigger", "Missing closing bracket" );
2306 return std::unique_ptr< CompositeTrigger >();
2307 }
2308 oper1 = s( 1, i - 2 );
2309 if( i == s.Length() + 1 ) {
2310 return makeTrigger( oper1 ); //meainingless brackets, just return evaluation
2311 } else {
2312 cOper1 = makeTrigger( oper1 );
2313 if( ! cOper1 ) {
2314 return 0;
2315 }
2316 }
2317 }
2318
2319 // Find the second operand. Do this by finding the first operation at
2320 // this level. If cannot find, then just set val
2321 int i=0;int bCounter=0; int op=0;
2322 while( i <= s.Length() ) {
2323 if( s( i ) == '(' ) {
2324 bCounter++;
2325 } else if( s( i ) == ')' ) {
2326 bCounter--;
2327 } else if( ( s( i ) == '&' ) && ( bCounter == 0 ) ) {
2328 op = 2;
2329 break;
2330 } else if( ( s( i ) == '|' ) && ( bCounter == 0 ) ) {
2331 op = 1;
2332 break;
2333 }
2334 i++;
2335 }
2336
2337
2338 if( op == 0 ) {
2339 if( m_lumicalcFiles.find( s ) == m_lumicalcFiles.end() ) {
2340 Error( "GetDataWeight", "Could not find subTrigger %s", s.Data() );
2341 return std::unique_ptr< CompositeTrigger >();
2342 }
2343 if( cOper1 ) {
2344 return cOper1;
2345 }
2346 auto out = std::make_unique< CompositeTrigger >();
2347 out->op = op;
2348 out->val = s;
2349 return out; //just a value trigger
2350 }
2351
2352 auto out = std::make_unique< CompositeTrigger >();
2353 out->op = op;
2354
2355 if( op == 1 ) { //an OR
2356 if( cOper1 ) {
2357 out->trig1 = std::move( cOper1 );
2358 } else {
2359 oper1 = s( 0, i );
2360 out->trig1 = makeTrigger( oper1 );
2361 if( ! out->trig1 ) {
2362 return std::unique_ptr< CompositeTrigger >();
2363 }
2364 }
2365 TString oper2 = s( i + 1, s.Length() );
2366 out->trig2 = makeTrigger( oper2 );
2367 if( ! out->trig2 ) {
2368 return std::unique_ptr< CompositeTrigger >();
2369 }
2370 return out;
2371 }
2372
2373 // Got here, must be an AND keep going until we hit an OR at this level,
2374 // then make all that the first operand (delete cOper if necessary)
2375 int j = i;
2376 bCounter = 0;
2377 while( j <= s.Length() ) {
2378 if( s( j ) == '(' ) {
2379 bCounter++;
2380 } else if( s( j )== ')' ) {
2381 bCounter--;
2382 } else if( ( s( j ) == '|' ) && ( bCounter == 0 ) ) {
2383 op=1;
2384 break;
2385 }
2386 j++;
2387 }
2388 if( ( j == s.Length() + 1 ) && ( op == 2 ) ) { //no more OR found, set oper2 to remainder
2389 if( cOper1 ) {
2390 out->trig1 = std::move( cOper1 );
2391 } else {
2392 oper1 = s( 0, i );
2393 out->trig1 = makeTrigger( oper1 );
2394 }
2395 TString oper2 = s( i + 1, s.Length() );
2396 if( m_debugging && m_printInfo ) {
2397 Info( "makeTrigger", "Found & %s %s", oper1.Data(), oper2.Data() );
2398 }
2399 out->trig2 = makeTrigger( oper2 );
2400 if( ! out->trig2 ) {
2401 return std::unique_ptr< CompositeTrigger >();
2402 }
2403 return out;
2404 } else if( op ==1 ) { //found an OR, set oper1 to everything up to this
2405
2406 oper1 = s( 0, j );
2407 TString oper2 = s( j + 1, s.Length() );
2408 if( m_debugging && m_printInfo ) {
2409 Info( "makeTrigger", "Found & then | %s %s", oper1.Data(),
2410 oper2.Data() );
2411 }
2412 out->op = op; //updates to an OR
2413 out->trig1 = makeTrigger( oper1 );
2414 if( ! out->trig1 ) {
2415 return std::unique_ptr< CompositeTrigger >();
2416 }
2417 out->trig2 = makeTrigger( oper2 );
2418 if( ! out->trig2 ) {
2419 return std::unique_ptr< CompositeTrigger >();
2420 }
2421 return out;
2422 }
2423 Error( "makeTrigger", "Should never have got here!, but did with %s",
2424 s.Data() );
2425 return std::unique_ptr< CompositeTrigger >();
2426}

◆ MakeWeightTree()

Bool_t TPileupReweighting::MakeWeightTree ( TString channelNumbers,
TString outFile,
TString hashBranch = "PRWHash",
TString weightBranch = "PileupWeight" )

Definition at line 1536 of file TPileupReweighting.cxx.

1536 {
1537 if(!m_isInitialized ) {
1538 if (m_printInfo) Info("MakeWeightTree","Initializing the subtool..");
1539 Initialize();
1540 }
1541 TH1* hist = m_emptyHistogram.get();
1542 if(!hist) {
1543 Error("MakeWeightTree","Tool not configured properly ... please report this!");
1544 throw std::runtime_error("Throwing 47: Tool not configured properly ... please report this!");
1545 }
1546
1547 //loop over given channels, and loop over all periods (except the global period) and get the pileup weight in each case for each bin
1548 TFile f1(outFile,"RECREATE");
1549
1550 TTree* outTree = new TTree("prwTree","prwTree");
1551 ULong64_t prwHash(0);Float_t weight(0.);
1552 outTree->Branch(hashBranch,&prwHash);
1553 outTree->Branch(weightBranch,&weight);
1554
1555 TObjArray *tx = channelNumbers.Tokenize(",");
1556 for (Int_t i = 0; i < tx->GetEntries(); i++) {
1557 int channelNumber = ((TObjString *)(tx->At(i)))->String().Atoi();
1558 if(channelNumber>999999 || channelNumber<0) {
1559 Error("MakeWeightTree","ChannelNumber can not be bigger than 999999 or less than 0 ... got %d",channelNumber);
1560 f1.Close();
1561 return 0;
1562 }
1563 for(auto& period : m_periods) {
1564 if(period.first==-1) continue;
1565 int periodNumber = period.first;
1566 for(int i=1;i<=hist->GetNbinsX();i++) {
1567 double x = hist->GetXaxis()->GetBinCenter(i);
1568 for(int j=1;j<=hist->GetNbinsY();j++) {
1569 double y = hist->GetYaxis()->GetBinCenter(j);
1570 weight = GetCombinedWeight(periodNumber,channelNumber,x,y);
1571 prwHash = GetPRWHash(periodNumber,channelNumber,x,y);
1572 outTree->Fill();
1573 }
1574 }
1575
1576 }
1577 }
1578
1579 outTree->BuildIndex(hashBranch.Data());
1580 outTree->Write();
1581 f1.Close();
1582
1583 if (m_printInfo) {
1584 Info("MakeWeightTree","Successfully wrote prwTree to %s",outFile.Data());
1585 }
1586
1587 return true;
1588}
Float_t GetCombinedWeight(Int_t periodNumber, Int_t channelNumber, Float_t x, Float_t y=0.)
ULong64_t GetPRWHash(Int_t periodNumber, Int_t channelNumber, Float_t x, Float_t y=0.)
outFile
Comment Out Those You do not wish to run.

◆ Merge()

Int_t TPileupReweighting::Merge ( TCollection * coll)

Definition at line 2045 of file TPileupReweighting.cxx.

2045 {
2046 if(!coll) return 0;
2047 if(coll->IsEmpty()) return 0;
2048
2049 // Iterate over the elements of the collection:
2050 TIter next( coll );
2051 TObject* obj = 0;
2052 while( ( obj = next() ) ) {
2053
2054 // Check that the element is of the right type:
2055 CP::TPileupReweighting* vobj = dynamic_cast< CP::TPileupReweighting* >( obj );
2056 if( ! vobj ) {
2057 Error( "Merge", "Unknown object type encountered: %s",obj->ClassName() );
2058 return 0;
2059 }
2060
2061 //merge the inputHistograms ... all the periods should be identical
2062 for(auto period : vobj->m_periods) {
2063 if(period.first != period.second->id) continue;
2064 for(auto& iHist : period.second->inputHists) {
2065 if(GetInputHistogram(period.first,iHist.first)==0) {
2066 m_periods[period.first]->inputHists[iHist.first].reset(
2067 dynamic_cast<TH1*>(iHist.second->Clone(iHist.second->GetName())) );
2068 m_periods[period.first]->inputHists[iHist.first]->SetDirectory(0);
2069 } else {
2070 GetInputHistogram(period.first,iHist.first)->Add(iHist.second.get());
2071 }
2072 }
2073 }
2074 //also must remember to merge the runs too (where the data is held)
2075 for(auto& run : vobj->m_runs) {
2076 for(auto& iHist : run.second.inputHists) {
2077 if( ! m_runs[run.first].inputHists[iHist.first] ) {
2078 m_runs[run.first].inputHists[iHist.first].reset(
2079 dynamic_cast<TH1*>( iHist.second->Clone(iHist.second->GetName())) );
2080 m_runs[run.first].inputHists[iHist.first]->SetDirectory(0);
2081 } else {
2082 m_runs[run.first].inputHists[iHist.first]->Add(iHist.second.get());
2083 }
2084 }
2085 }
2086 }
2087
2088 return 1;
2089}
TH1 * GetInputHistogram(Int_t channelNumber, Int_t periodNumber)

◆ normalizeHistogram()

void TPileupReweighting::normalizeHistogram ( TH1 * histo)
protected

Normalize histograms.

Definition at line 2002 of file TPileupReweighting.cxx.

2002 {
2003 // normalize the data histogram based on which sort of histogram it is
2004 if(hist){
2005 if(hist->InheritsFrom("TH3")) {
2006 Error("normalizeHistogram","3D reweighting not supported yet");
2007 throw std::runtime_error("Throwing 3: 3D reweighting not supported yet");
2008 }
2009 else if(hist->InheritsFrom("TH2")) {
2010 bool skipNorm=false;
2011 //normalize each bin according to the projection in x
2012 TH1D* proj = static_cast<TH2*>(hist)->ProjectionX();
2013 Int_t bin,binx,biny,binz;
2014 for(binz=1; binz<=hist->GetNbinsZ(); binz++) {
2015 for(biny=1; biny<=hist->GetNbinsY(); biny++) {
2016 for(binx=1; binx<=hist->GetNbinsX(); binx++) {
2017 bin = hist->GetBin(binx,biny,binz);
2018 Double_t value = hist->GetBinContent(bin);
2019 Double_t normalizer = proj->GetBinContent(binx);
2020 if(normalizer!=0.0) {
2021 hist->SetBinContent(bin,value/normalizer);
2022 } else {
2023 skipNorm=true;
2024 }
2025 }
2026 }
2027 }
2028 delete proj;
2029 if(skipNorm && m_debugging) Warning("normalizeHistogram","Skipped normalization in hist %s",hist->GetName());
2030 } else {
2031 //normalize to the sum of weights
2032 if(hist->GetSumOfWeights()!=0.0) {
2033 hist->Scale(1.0/hist->GetSumOfWeights());
2034 } else {
2035 if (m_debugging) Warning("normalizeHistogram","Skipping Normalizing histogram %s to ~zero: %f",hist->GetName(),hist->GetSumOfWeights());
2036 }
2037 }
2038 } else {
2039 Error("normalizeHistogram","Non existent histogram for normalizing");throw std::runtime_error("Throwing 56");
2040 }
2041}

◆ passTriggerBeforePrescale()

virtual bool CP::TPileupReweighting::passTriggerBeforePrescale ( const TString & trigger) const
inlineprotectedvirtual

Reimplemented in CP::PileupReweightingTool.

Definition at line 309 of file TPileupReweighting.h.

309 {
310 if(m_triggerPassBits.size()==0) return true;
311 try {
312 return m_triggerPassBits.at(trigger);
313 } catch(...) { return true; }
314 } //override in the ASG tool
std::map< TString, bool > m_triggerPassBits

◆ PrintInfo()

void CP::TPileupReweighting::PrintInfo ( Bool_t in)
inline

disable info

Definition at line 120 of file TPileupReweighting.h.

120{ m_printInfo = in; }

◆ PrintPeriods()

void CP::TPileupReweighting::PrintPeriods ( )
inline

Definition at line 414 of file TPileupReweighting.h.

414{ for(auto p : m_periods) {std::cout << p.first << " -> "; p.second->print("");} }

◆ RemapPeriod()

void TPileupReweighting::RemapPeriod ( Int_t periodNumber1,
Int_t periodNumber2 )

Combine two period numbers.

Histos are merged and the first number will be redirected to the second (the second is created if it doesn't exist)

Definition at line 63 of file TPileupReweighting.cxx.

63 {
64 //check if periodNumber2 exists
65 if(m_periods.find(periodNumber2)==m_periods.end()) {
66 m_periodList.emplace_back( periodNumber2, 0, 0, GetDefaultChannel(-1) );
67 m_periods[periodNumber2] = &( m_periodList.back() );
68 }
69 m_periods[periodNumber1] = m_periods[periodNumber2];
70}

◆ RemoveChannel()

Bool_t TPileupReweighting::RemoveChannel ( int chanNum)

Removes a channel from the inputs ... this is for experts only.

Definition at line 1001 of file TPileupReweighting.cxx.

1001 {
1002 if(m_isInitialized) {
1003 Error("RemoveChannel","You cannot RemoveChannel after initializing the tool. Reorder your code!");
1004 throw std::runtime_error("Throwing 5: You cannot RemoveChannel after initializing the tool. Reorder your code!");
1005 }
1006
1007 bool found(false);
1008 for(auto& period : m_periods) {
1009 auto itr = period.second->inputHists.begin();
1010 while(itr != period.second->inputHists.end()) {
1011 if(itr->first!=chanNum) ++itr;
1012 else {
1013 found=true;
1014 itr = period.second->inputHists.erase(itr);
1015 }
1016 }
1017 }
1018 return found;
1019}

◆ ResetCountingMode()

void CP::TPileupReweighting::ResetCountingMode ( )
inline

This method is DEFINITELY EXPERT USE ONLY.

Used in the checkPRWConfigFile utitlity

Definition at line 293 of file TPileupReweighting.h.

293{ m_countingMode=true; }

◆ ResetTriggerBits()

void CP::TPileupReweighting::ResetTriggerBits ( )
inline

Definition at line 301 of file TPileupReweighting.h.

301{ m_triggerPassBits.clear(); }

◆ runLbnOK()

virtual bool CP::TPileupReweighting::runLbnOK ( Int_t ,
Int_t  )
inlineprotectedvirtual

Reimplemented in CP::PileupReweightingTool.

Definition at line 308 of file TPileupReweighting.h.

308{ return true; } //override in the ASG tool

◆ SetBinning() [1/2]

Int_t TPileupReweighting::SetBinning ( Int_t nbinsx,
Double_t * xbins,
Int_t nbinsy = 0,
Double_t * ybins = 0 )

Add a histogram binning config.

To modify the pileup histo binning, use "pileup" as name

Definition at line 83 of file TPileupReweighting.cxx.

83 {
84 if( nbinsy > 0 ) {
85 m_emptyHistogram.reset( new TH2D( "default", "default", nbinsx, xbins,
86 nbinsy, ybins ) );
87 } else {
88 m_emptyHistogram.reset( new TH1D( "default", "default", nbinsx, xbins ) );
89 }
90 m_emptyHistogram->SetDirectory(0);
91 return 0;
92}

◆ SetBinning() [2/2]

Int_t TPileupReweighting::SetBinning ( TH1 * hist)

Definition at line 101 of file TPileupReweighting.cxx.

101 {
102 if(!hist) return -1;
103 m_emptyHistogram.reset( dynamic_cast< TH1* >( hist->Clone( "default" ) ) );
105 m_emptyHistogram->SetDirectory(0);
106 return 0;
107}

◆ SetDataScaleFactors()

void CP::TPileupReweighting::SetDataScaleFactors ( Float_t x,
Float_t y = 1. )
inline

Scale the LumiMetaData mu values by this factor.

Definition at line 156 of file TPileupReweighting.h.

◆ SetDefaultChannel()

void TPileupReweighting::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.

default channels can now be assigned for each mc run number .. mcRunNumber=-1 is the global default

Definition at line 72 of file TPileupReweighting.cxx.

72 {
73 //check if periodNumber2 exists
74 if(m_periods.find(periodNumber)==m_periods.end()) {
75 m_periodList.emplace_back( periodNumber, 0, 0, channel );
76 m_periods[periodNumber] = &( m_periodList.back() );
77 } else {
78 m_periods[periodNumber]->SetDefaultChannel(channel);
79 }
80}

◆ SetMCScaleFactors()

void CP::TPileupReweighting::SetMCScaleFactors ( Float_t x,
Float_t y = 1. )
inline

Definition at line 157 of file TPileupReweighting.h.

◆ SetParentTool()

void CP::TPileupReweighting::SetParentTool ( TPileupReweighting * tool)
inline

Definition at line 296 of file TPileupReweighting.h.

◆ SetRandomSeed()

void CP::TPileupReweighting::SetRandomSeed ( int seed)
inline

Definition at line 222 of file TPileupReweighting.h.

222{m_random3->SetSeed(seed);}

◆ SetTriggerBit()

void CP::TPileupReweighting::SetTriggerBit ( const TString & trigger,
bool in = true )
inline

Definition at line 300 of file TPileupReweighting.h.

300{ m_triggerPassBits[trigger]=in; }

◆ SetUniformBinning()

Int_t TPileupReweighting::SetUniformBinning ( Int_t nbinsx,
Double_t xlow,
Double_t xup,
Int_t nbinsy = 0,
Double_t ylow = 0,
Double_t yup = 0 )

Definition at line 93 of file TPileupReweighting.cxx.

93 {
94 std::vector<double> xbins(nbinsx+1);
95 std::vector<double> ybins(nbinsy+1);
96 for(int i=0;i<nbinsx+1;i++) xbins[i] = xlow + i*(xup-xlow)/nbinsx;
97 if (nbinsy > 0)
98 for(int i=0;i<nbinsy+1;i++) ybins[i] = ylow + i*(yup-ylow)/nbinsy;
99 return SetBinning(nbinsx,&xbins[0],nbinsy,&ybins[0]);
100}
Int_t SetBinning(Int_t nbinsx, Double_t *xbins, Int_t nbinsy=0, Double_t *ybins=0)
Add a histogram binning config.

◆ SetUnrepresentedDataAction()

void CP::TPileupReweighting::SetUnrepresentedDataAction ( Int_t action,
Double_t tolerance = 0.05 )
inline

Set how to handle configurations where some of your data has no corresponding mc to describe it 0=Default (Throw exception), 1=Subtract lumi from normalizations (i.e.

discard data), 2=keep lumi and continue

Definition at line 124 of file TPileupReweighting.h.

124 {
125 if(action<0 || action>3) {
126 Fatal("SetUnrepresentedDataAction","Set action=%d - I'm afraid I can't let you do that, Dave",action);
127 throw std::runtime_error("Throwing 2001");
128 }
130 m_unrepDataTolerance=tolerance; //applicable for action=2 mode. Default is 5%
131 }
@ Fatal
Definition ZDCMsg.h:23
constexpr double tolerance

◆ UsePeriodConfig()

Int_t TPileupReweighting::UsePeriodConfig ( const TString & configName)

use a hardcoded period configuration

Definition at line 234 of file TPileupReweighting.cxx.

234 {
235 if(configName=="MC11a") {
236 AddPeriod(180164, 177986,180481); //associates mc runnumber 180164 with data period 177986 to 180481 (period B-D)
237 AddPeriod(183003, 180614,184169); //period E-H
238 AddPeriod(185649, 185353,186934); //period I-K1. For I-K you would change the last number to 187815
239 AddPeriod(185761, 186935,191933); //everything else. Thanks Ellie!
240 SetUniformBinning(100,0,50);
241 if (m_printInfo) {
242 Info("UsePeriodConfig","Using MC11a Period configuration");
243 }
244 return 0;
245 } else if(configName=="MC11b" || configName=="MC11c") {
246 AddPeriod(180164, 177986, 180481);
247 AddPeriod(183003, 180614, 184169);
248 AddPeriod(186169, 185353, 187815);
249 AddPeriod(189751, 188902, 191933);
250 SetUniformBinning(100,0,50);
251 if (m_printInfo) {
252 Info("UsePeriodConfig","Using MC11b/c Period configuration");
253 }
254 return 0;
255 } else if(configName=="MC12a") {
256 AddPeriod(195847,200804,216432);
257 //mc12a binning is in integer values of mu
258
259 if(m_emptyHistogram && (m_emptyHistogram->GetNbinsX()!=50 || fabs(m_emptyHistogram->GetXaxis()->GetBinLowEdge(1)+0.5)>0.01|| fabs(m_emptyHistogram->GetXaxis()->GetBinUpEdge(50)-49.5)>0.01) ) {
260 Error("UsePeriodConfig","Cannot use MC12a, an incompatible config has already been set up");
261 throw std::runtime_error("Throwing 13: Cannot use MC14, an incompatible config has already been set up");
262 return -1;
263 }
264
265 SetUniformBinning(50,-0.5,49.5);
266 if (m_printInfo) {
267 Info("UsePeriodConfig","Using MC12a Period configuration");
268 }
269 return 0;
270 } else if(configName=="MC12b") {
271 AddPeriod(195848,200804,216432);
272 //mc12b binning is in integer values of mu
273
274 if(m_emptyHistogram && (m_emptyHistogram->GetNbinsX()!=50 || fabs(m_emptyHistogram->GetXaxis()->GetBinLowEdge(1)+0.5)>0.01|| fabs(m_emptyHistogram->GetXaxis()->GetBinUpEdge(50)-49.5)>0.01) ) {
275 Error("UsePeriodConfig","Cannot use MC12b, an incompatible config has already been set up");
276 throw std::runtime_error("Throwing 13: Cannot use MC14, an incompatible config has already been set up");
277 return -1;
278 }
279
280 SetUniformBinning(50,-0.5,49.5);
281 if (m_printInfo) {
282 Info("UsePeriodConfig","Using MC12b Period configuration");
283 }
284 return 0;
285 } else if(configName=="MC12ab") {
286 AddPeriod(195847,200804,216432);
287 AddPeriod(195848,200804,216432);
288
289 if(m_emptyHistogram && (m_emptyHistogram->GetNbinsX()!=50 || fabs(m_emptyHistogram->GetXaxis()->GetBinLowEdge(1)+0.5)>0.01|| fabs(m_emptyHistogram->GetXaxis()->GetBinUpEdge(50)-49.5)>0.01) ) {
290 Error("UsePeriodConfig","Cannot use MC12ab, an incompatible config has already been set up");
291 throw std::runtime_error("Throwing 13: Cannot use MC14, an incompatible config has already been set up");
292 return -1;
293 }
294
295 //mc12a/b binning is in integer values of mu
296 SetUniformBinning(50,-0.5,49.5);
297 if (m_printInfo) {
298 Info("UsePeriodConfig","Using MC12ab Period configuration");
299 }
300 return 0;
301 } else if(configName=="MC14_8TeV") {
302 AddPeriod(212272,200804,216432);
303 if(m_emptyHistogram && (m_emptyHistogram->GetNbinsX()!=50 || fabs(m_emptyHistogram->GetXaxis()->GetBinLowEdge(1)+0.5)>0.01 || fabs(m_emptyHistogram->GetXaxis()->GetBinUpEdge(50)-49.5)>0.01) ) {
304 Error("UsePeriodConfig","Cannot use MC14_8TeV, an incompatible config has already been set up");
305 throw std::runtime_error("Throwing 13: Cannot use MC14_8TeV, an incompatible config has already been set up");
306 return -1;
307 }
308 SetUniformBinning(50,-0.5,49.5);
309 if (m_printInfo) {
310 Info("UsePeriodConfig","Using MC14_8TeV Period configuration");
311 }
312 return 0;
313 } else if(configName=="MC14_13TeV") {
314 AddPeriod(222222,222222,999999);
315 if(m_emptyHistogram && (m_emptyHistogram->GetNbinsX()!=100 || fabs(m_emptyHistogram->GetXaxis()->GetBinLowEdge(1)+0.5)>0.01|| fabs(m_emptyHistogram->GetXaxis()->GetBinUpEdge(100)-99.5)>0.01) ) {
316 Error("UsePeriodConfig","Cannot use MC14_13TeV, an incompatible config has already been set up");
317 throw std::runtime_error("Throwing 13: Cannot use MC14_13TeV, an incompatible config has already been set up");
318 return -1;
319 }
320 SetUniformBinning(100,-0.5,99.5);
321 if (m_printInfo) {
322 Info("UsePeriodConfig","Using MC14_13TeV Period configuration");
323 }
324 return 0;
325 } else if(configName=="MC15") {
326 AddPeriod(222510,222222,999999);
327 AddPeriod(222525,222222,999999);
328 AddPeriod(222526,222222,999999);
329 AddPeriod(284500,222222,999999);
330 AddPeriod(295000,222222,999999); //mc15c for pPb data in 2016
331 if(m_emptyHistogram && (m_emptyHistogram->GetNbinsX()!=100 || fabs(m_emptyHistogram->GetXaxis()->GetBinLowEdge(1))>0.01 || fabs(m_emptyHistogram->GetXaxis()->GetBinUpEdge(100)-100.)>0.01) ) {
332 Error("UsePeriodConfig","Cannot use MC15, an incompatible config has already been set up");
333 throw std::runtime_error("Throwing 13: Cannot use MC15, an incompatible config has already been set up");
334 return -1;
335 }
336 SetUniformBinning(100,0,100);
337 if (m_printInfo) {
338 Info("UsePeriodConfig","Using MC15 Period configuration");
339 }
340 return 0;
341 } else if(configName=="Run2") {
342 m_autoRunStart = 222222; m_autoRunEnd = 999999; //periods will be automatically added during Fill
343 if(m_emptyHistogram && (m_emptyHistogram->GetNbinsX()!=100 || fabs(m_emptyHistogram->GetXaxis()->GetBinLowEdge(1))>0.01 || fabs(m_emptyHistogram->GetXaxis()->GetBinUpEdge(100)-100.)>0.01) ) {
344 Error("UsePeriodConfig","Cannot use open Run2, an incompatible config has already been set up");
345 throw std::runtime_error("Throwing 13: Cannot use Run2 config, an incompatible config has already been set up");
346 return -1;
347 }
348 SetUniformBinning(100,0,100);
349 if (m_printInfo) {
350 Info("UsePeriodConfig","Using Run2 Period configuration, which assumes period assignment of 222222 to 999999");
351 }
352 return 0;
353 } else if(configName=="MC16") {
354 /* period configs are now assigned through the parent tool for MC16 */
355
356 SetUniformBinning(100,0,100);
357 if (m_printInfo) {
358 Info("UsePeriodConfig","Using MC16 Period configuration");
359 }
360 return 0;
361 }
362 Error("UsePeriodConfig","Unrecognized period config");
363 return -1;
364}
Int_t SetUniformBinning(Int_t nbinsx, Double_t xlow, Double_t xup, Int_t nbinsy=0, Double_t ylow=0, Double_t yup=0)

◆ WriteToFile() [1/2]

Int_t TPileupReweighting::WriteToFile ( const TString & filename = "")

Definition at line 1894 of file TPileupReweighting.cxx.

1894 {
1895
1896 if(!m_countingMode) {Warning("WriteToFile","Not in counting mode, so no file will be written");return 0;}
1897
1898
1899 //build a TTree with the correct mc structure, and dump the mc histogram info in to it
1900 //also build aggregate histograms across all channels - shouldn't be used as input histograms unless for a single channel
1901 TString filename = fname;
1902 filename += (filename=="") ? TString(this->GetName()) + ".prw.root" : "";
1903
1904 //loop over the weights. "pileup" gets it own MCPileupReweighting ttree. ... since we got rid of weightNames in this version, everything goes in MCPileupReweighting now!
1905 //data goes in to DataCustomReweighting. other goes in to MCCustomReweighting
1906 TFile* outFile = TFile::Open(filename,"RECREATE");
1907 Int_t r = WriteToFile(outFile);
1908 outFile->Close();
1909 return r;
1910}
Int_t WriteToFile(const TString &filename="")

◆ WriteToFile() [2/2]

Int_t TPileupReweighting::WriteToFile ( TFile * outFile)

Definition at line 1913 of file TPileupReweighting.cxx.

1913 {
1914 if(!m_countingMode) {Warning("WriteToFile","Not in counting mode, so no file will be written");return 0;}
1915
1916 TDirectory* origDir = gDirectory;
1917
1918 outFile->cd();
1919
1920 std::unique_ptr< TTree > outTreeMC;
1921 std::unique_ptr< TTree > outTreeData;
1922 Int_t channel = 0; UInt_t runNumber = 0;
1923 auto pStarts = std::make_unique< std::vector< UInt_t > >();
1924 auto pStartsPtr = pStarts.get();
1925 auto pEnds = std::make_unique< std::vector< UInt_t > >();
1926 auto pEndsPtr = pEnds.get();
1927 Char_t histName[150];
1928
1929
1930 //loop over periods ... periods only get entry in table if they have an input histogram
1931 for(auto period : m_periods) {
1932 if(period.first != period.second->id) continue; //skips redirects
1933 if(period.first<0) continue; //avoid the global run number
1934 runNumber = period.first;
1935 pStarts->clear();
1936 pEnds->clear();
1937 if(period.second->subPeriods.size()==0) {
1938 pStarts->push_back(period.second->start); pEnds->push_back(period.second->end);
1939 }
1940 else {
1941 for(auto subp : period.second->subPeriods) {
1942 pStarts->push_back(subp->start); pEnds->push_back(subp->end);
1943 }
1944 }
1945 for(auto& inHist : period.second->inputHists) {
1946 channel = inHist.first;
1947 TH1* hist = inHist.second.get();
1948 strncpy(histName,hist->GetName(),sizeof(histName)-1);
1949 hist->Write();
1950
1951 if(!outTreeMC) {
1952 outTreeMC.reset( new TTree("MCPileupReweighting","MCPileupReweighting") );
1953 outTreeMC->Branch("Channel",&channel);
1954 outTreeMC->Branch("RunNumber",&runNumber);
1955 outTreeMC->Branch("PeriodStarts",&pStartsPtr);
1956 outTreeMC->Branch("PeriodEnds",&pEndsPtr);
1957 outTreeMC->Branch("HistName",&histName,"HistName/C");
1958 }
1959 outTreeMC->Fill();
1960 }
1961 }
1962
1963 //loop over data
1964 for(auto& run : m_runs) {
1965 runNumber = run.first;
1966 if(run.second.inputHists.find("None")==run.second.inputHists.end()) continue;
1967
1968 TH1* hist = run.second.inputHists["None"].get();
1969 strncpy(histName,hist->GetName(),sizeof(histName)-1);
1970 hist->Write();
1971 if(!outTreeData) {
1972 outTreeData.reset( new TTree("DataPileupReweighting","DataPileupReweighting") );
1973 outTreeData->Branch("RunNumber",&runNumber);
1974 outTreeData->Branch("HistName",&histName,"HistName/C");
1975 }
1976 outTreeData->Fill();
1977 }
1978
1979
1980 //write the non-zero ttrees
1981 if( outTreeMC ) {
1982 outTreeMC->Write();
1983 }
1984 if( outTreeData ) {
1985 outTreeData->Write();
1986 }
1987
1988 if (m_printInfo) {
1989 Info("WriteToFile", "Successfully generated config file: %s",outFile->GetName());
1990 Info("WriteToFile", "Happy Reweighting :-)");
1991 }
1992
1994
1995 return 0;
1996}

Member Data Documentation

◆ m_autoRunEnd

int CP::TPileupReweighting::m_autoRunEnd = 0
protected

Definition at line 476 of file TPileupReweighting.h.

◆ m_autoRunStart

int CP::TPileupReweighting::m_autoRunStart = 0
protected

Definition at line 475 of file TPileupReweighting.h.

◆ m_countingMode

Bool_t CP::TPileupReweighting::m_countingMode
protected

Definition at line 335 of file TPileupReweighting.h.

◆ m_dataScaleFactorX

Float_t CP::TPileupReweighting::m_dataScaleFactorX
protected

Definition at line 338 of file TPileupReweighting.h.

◆ m_dataScaleFactorY

Float_t CP::TPileupReweighting::m_dataScaleFactorY
protected

Definition at line 338 of file TPileupReweighting.h.

◆ m_debugging

Bool_t CP::TPileupReweighting::m_debugging
protected

Definition at line 333 of file TPileupReweighting.h.

◆ m_doGlobalDataWeight

Bool_t CP::TPileupReweighting::m_doGlobalDataWeight
protected

Definition at line 345 of file TPileupReweighting.h.

◆ m_doPrescaleWeight

Bool_t CP::TPileupReweighting::m_doPrescaleWeight = false
protected

Definition at line 346 of file TPileupReweighting.h.

◆ m_emptyHistogram

std::unique_ptr< TH1 > CP::TPileupReweighting::m_emptyHistogram
protected

the empty histogram used for this weight... effectively holds the configuration of the binning

Definition at line 359 of file TPileupReweighting.h.

◆ m_ignoreBadChannels

Bool_t CP::TPileupReweighting::m_ignoreBadChannels
protected

Definition at line 471 of file TPileupReweighting.h.

◆ m_ignoreFilePeriods

Bool_t CP::TPileupReweighting::m_ignoreFilePeriods
protected

Definition at line 341 of file TPileupReweighting.h.

◆ m_isInitialized

Bool_t CP::TPileupReweighting::m_isInitialized
protected

Definition at line 337 of file TPileupReweighting.h.

◆ m_lumicalcFiles

std::map<TString,std::vector<TString> > CP::TPileupReweighting::m_lumicalcFiles
protected

map storing the lumicalc file locations - used when building DataPileupWeights

Definition at line 350 of file TPileupReweighting.h.

◆ m_lumicalcRunNumberOffset

Int_t CP::TPileupReweighting::m_lumicalcRunNumberOffset
protected

Definition at line 347 of file TPileupReweighting.h.

◆ m_lumiVectorIsLoaded

Bool_t CP::TPileupReweighting::m_lumiVectorIsLoaded
protected

Definition at line 337 of file TPileupReweighting.h.

◆ m_mcScaleFactorX

Float_t CP::TPileupReweighting::m_mcScaleFactorX
protected

Definition at line 339 of file TPileupReweighting.h.

◆ m_mcScaleFactorY

Float_t CP::TPileupReweighting::m_mcScaleFactorY
protected

Definition at line 339 of file TPileupReweighting.h.

◆ m_metadata

std::map<TString, std::map<Int_t, Double_t> > CP::TPileupReweighting::m_metadata
protected

channel metadata map

Definition at line 364 of file TPileupReweighting.h.

◆ m_metadatatree

TTree* CP::TPileupReweighting::m_metadatatree
protected

Definition at line 342 of file TPileupReweighting.h.

◆ m_nextPeriodNumber

Int_t CP::TPileupReweighting::m_nextPeriodNumber
protected

Definition at line 340 of file TPileupReweighting.h.

◆ m_parentTool

TPileupReweighting* CP::TPileupReweighting::m_parentTool
protected

Definition at line 331 of file TPileupReweighting.h.

◆ m_periodList

std::list< Period > CP::TPileupReweighting::m_periodList
protected

List physically holding (owning) period objects.

Definition at line 457 of file TPileupReweighting.h.

◆ m_periods

std::map<Int_t, Period*> CP::TPileupReweighting::m_periods
protected

Definition at line 458 of file TPileupReweighting.h.

◆ m_printInfo

Bool_t CP::TPileupReweighting::m_printInfo
protected

Definition at line 334 of file TPileupReweighting.h.

◆ m_prwFilesPathPrefix

std::string CP::TPileupReweighting::m_prwFilesPathPrefix
protected

Definition at line 463 of file TPileupReweighting.h.

◆ m_random3

std::unique_ptr< TRandom3 > CP::TPileupReweighting::m_random3
protected

Definition at line 469 of file TPileupReweighting.h.

◆ m_runs

std::map<UInt_t, Run> CP::TPileupReweighting::m_runs
protected

Definition at line 459 of file TPileupReweighting.h.

◆ m_SetWarnings

Bool_t CP::TPileupReweighting::m_SetWarnings
protected

Definition at line 332 of file TPileupReweighting.h.

◆ m_triggerObjs

std::map<TString, std::unique_ptr<CompositeTrigger> > CP::TPileupReweighting::m_triggerObjs
protected

Definition at line 408 of file TPileupReweighting.h.

◆ m_triggerPassBits

std::map<TString, bool> CP::TPileupReweighting::m_triggerPassBits
protected

Definition at line 315 of file TPileupReweighting.h.

◆ m_unrepDataTolerance

Double_t CP::TPileupReweighting::m_unrepDataTolerance
protected

Definition at line 343 of file TPileupReweighting.h.

◆ m_unrepDataWarningThreshold

Double_t CP::TPileupReweighting::m_unrepDataWarningThreshold {0.0}
protected

Definition at line 344 of file TPileupReweighting.h.

344{0.0};

◆ m_unrepresentedDataAction

Int_t CP::TPileupReweighting::m_unrepresentedDataAction
protected

Definition at line 336 of file TPileupReweighting.h.

◆ m_useMultiPeriods

Bool_t CP::TPileupReweighting::m_useMultiPeriods = true
protected

Definition at line 472 of file TPileupReweighting.h.

◆ unrepDataByChannel

std::map<Int_t, Double_t> CP::TPileupReweighting::unrepDataByChannel
protected

Definition at line 461 of file TPileupReweighting.h.


The documentation for this class was generated from the following files: