15#define XXX std::cout << " I am here: " << __FILE__ << ":" << __LINE__ << std::endl;
36#include <TObjString.h>
48 TNamed(name,
"notitle"), m_parentTool(this),
49 m_SetWarnings(true),m_debugging(false),m_printInfo(true),
50 m_countingMode(true),m_unrepresentedDataAction(0),m_isInitialized(false),m_lumiVectorIsLoaded(false),
51 m_dataScaleFactorX(1.),m_dataScaleFactorY(1.),
52 m_mcScaleFactorX(1.),m_mcScaleFactorY(1.),
53 m_nextPeriodNumber(1),m_ignoreFilePeriods(false),m_metadatatree(0),m_unrepDataTolerance(0.05),m_doGlobalDataWeight(false),m_lumicalcRunNumberOffset(0), m_emptyHistogram(), m_random3(), m_ignoreBadChannels(false)
55 m_random3.reset(
new TRandom3(0) );
56 m_random3->SetSeed(1);
59 m_periodList.emplace_back( -1,0,9999999,0 );
60 m_periods[ -1 ] = &( m_periodList.back() );
75 m_periodList.emplace_back( periodNumber, 0, 0, channel );
78 m_periods[periodNumber]->SetDefaultChannel(channel);
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;
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]);
111 return m_periods[mcRunNumber]->defaultChannel;
118 Info(
"GetIntegratedLumi",
"Initializing the subtool..");
123 Error(
"GetIntegratedLumi",
"No UNPRESCALED (Trigger=None) Lumicalc file loaded, so cannot get integrated lumi, returning 0");
134 return h->Integral(0,
h->GetNbinsX()+1)/1E6;
142 Info(
"GetIntegratedLumi",
"Initializing the subtool..");
149 if(
run >= start &&
run <= end) total +=
m_runs[
run].inputHists[
"None"]->GetSumOfWeights();
157 Info(
"GetIntegratedLumi",
"Initializing the subtool..");
164 if(
run.lumiByLbn.find(
lb)==
run.lumiByLbn.end())
return 0.;
165 return run.lumiByLbn[
lb].first*1E-6;
171 Info(
"GetLumiBlockMu",
"Initializing the subtool..");
178 if(
run.lumiByLbn.find(
lb)==
run.lumiByLbn.end())
return -1.0;
179 return run.lumiByLbn[
lb].second;
185 Info(
"GetIntegratedLumiFraction",
"Initializing the subtool..");
191 Error(
"GetIntegratedLumiFraction",
"No UNPRESCALED (Trigger=None) Lumicalc file loaded, so no lumi fraction possible, returning 0");
195 double total =
m_periods[periodNumber]->sumOfWeights[-1];
199 if(
run >= start &&
run <= end) numer +=
m_runs[
run].inputHists[
"None"]->GetSumOfWeights();
201 return numer / total;
207 Info(
"GetIntegratedLumiFraction",
"Initializing the subtool..");
212 Error(
"GetIntegratedLumiFraction",
"No UNPRESCALED (Trigger=None) Lumicalc file loaded, so no lumi fraction possible, returning 0");
216 if(!
m_emptyHistogram) { Error(
"GetIntegratedLumiFraction",
"Cannot do this without a lumicalc file!");
return 0; }
222 double total =
m_triggerObjs[
"None"]->triggerHists[periodNumber][0]->GetBinContent(muBin);
226 if(
run >= start &&
run <= end) numer +=
m_runs[
run].muDist->GetBinContent(muBin);
229 return numer / total;
235 if(configName==
"MC11a") {
242 Info(
"UsePeriodConfig",
"Using MC11a Period configuration");
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);
252 Info(
"UsePeriodConfig",
"Using MC11b/c Period configuration");
255 }
else if(configName==
"MC12a") {
256 AddPeriod(195847,200804,216432);
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");
265 SetUniformBinning(50,-0.5,49.5);
267 Info(
"UsePeriodConfig",
"Using MC12a Period configuration");
270 }
else if(configName==
"MC12b") {
271 AddPeriod(195848,200804,216432);
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");
280 SetUniformBinning(50,-0.5,49.5);
282 Info(
"UsePeriodConfig",
"Using MC12b Period configuration");
285 }
else if(configName==
"MC12ab") {
286 AddPeriod(195847,200804,216432);
287 AddPeriod(195848,200804,216432);
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");
296 SetUniformBinning(50,-0.5,49.5);
298 Info(
"UsePeriodConfig",
"Using MC12ab Period configuration");
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");
308 SetUniformBinning(50,-0.5,49.5);
310 Info(
"UsePeriodConfig",
"Using MC14_8TeV Period configuration");
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");
320 SetUniformBinning(100,-0.5,99.5);
322 Info(
"UsePeriodConfig",
"Using MC14_13TeV Period configuration");
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);
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");
336 SetUniformBinning(100,0,100);
338 Info(
"UsePeriodConfig",
"Using MC15 Period configuration");
341 }
else if(configName==
"Run2") {
342 m_autoRunStart = 222222; m_autoRunEnd = 999999;
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");
348 SetUniformBinning(100,0,100);
350 Info(
"UsePeriodConfig",
"Using Run2 Period configuration, which assumes period assignment of 222222 to 999999");
353 }
else if(configName==
"MC16") {
356 SetUniformBinning(100,0,100);
358 Info(
"UsePeriodConfig",
"Using MC16 Period configuration");
362 Error(
"UsePeriodConfig",
"Unrecognized period config");
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!");
386 if(p->subPeriods.size() == 0 && p->start==0 && p->end==0) { p->start=start; p->end=end;
return periodNumber; }
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;
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.");
403 if(p->subPeriods.size()==0) {
409 p->start = 0; p->end=0;
426 if(period.second->id==-1)
continue;
427 if(period.second->contains(runNumber))
return period.second->id;
434std::unique_ptr< TH1 >
438 if(channelNumber>=0) {
439 s +=
"_chan"; s += channelNumber;
443 s+=
"_run"; s+= runNumber;
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)");
450 std::unique_ptr< TH1 > out(
dynamic_cast<TH1*
>(
m_emptyHistogram->Clone(s)) );
453 out->SetDirectory(0);
462 TTree inTree(
"in",
"in");
463 inTree.ReadFile(fileName);
464 TTree outTree(
"ChannelMetaData",
"ChannelMetaData");
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);
472 TBranch *branch = leaf->GetBranch();
473 if(strcmp(branch->GetName(),channelBranchName)==0) {
475 if(strcmp(leaf->GetTypeName(),
"Int_t")!=0) {
476 Error(
"GenerateMetaDataFile",
"Channel Branch must be type Int_t");
return -1;
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());
483 branch->SetAddress(&(
data[branch->GetName()]));
484 outTree.Branch(branch->GetName(),&(
data[branch->GetName()]));
489 for(Int_t i=0;i<inTree.GetEntries();++i) {
495 TString outName = fileName(0,fileName.Last(
'.'));
496 outName +=
".prw.root";
497 TFile f1(outName,
"RECREATE");
501 Info(
"GenerateMetaDataFile",
"Succesfully Generated File %s",outName.Data());
507 TDirectory* origDir = gDirectory;
510 if(fileName.EndsWith(
".root")) {
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");
519 tmp = (TTree*)rootFile->Get(
"ChannelMetaData" );
521 Error(
"AddMetaDataFile",
"%s is not a valid metadata file. Should have a ChannelMetaData TTree",fileName.Data());
522 throw std::runtime_error(
"Throwing 7");
529 tmp =
new TTree(
"ChannelMetaData",
"ChannelMetaData");
530 tmp->ReadFile(fileName);
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);
539 TBranch *branch = leaf->GetBranch();
540 if(strcmp(branch->GetName(),channelBranchName)==0) {
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");
546 branch->SetAddress(&chanNum);
547 }
else if(strcmp(leaf->GetTypeName(),
"Double_t")!=0) {
548 Warning(
"AddMetaDataFile",
"Cannot read non-double branch: %s",branch->GetName());
550 branch->SetAddress(&(
data[branch->GetName()]));
555 for(Int_t i=0;i<tmp->GetEntries();++i) {
557 for(std::map<TString, Double_t>::iterator it =
data.begin();it!=
data.end();++it) {
559 Warning(
"AddMetaDataFile",
"Overriding metadata [%s,%d]. %f becomes %f",(it->first).Data(),chanNum,
m_metadata[it->first][chanNum],it->second);
566 if(rootFile) { rootFile->Close();
delete rootFile;}
569 gDirectory = origDir;
576 m_metadatatree =
new TTree(TString(this->GetName())+
"MetaData",TString(this->GetName())+
"MetaData");
580 std::map<TString,Double_t>
data;
581 std::map<Int_t,bool> channels;
584 for(std::map<Int_t,Double_t>::iterator it2=(it->second).begin();it2!=(it->second).end();++it2) {
585 channels[it2->first]=
true;
587 const auto &[ptr, inserted ] =
data.try_emplace(it->first, 0.);
593 data[
"NumberOfEvents"]=0.;
595 data[
"SumOfEventWeights"]=0.;
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;
604 for(std::map<Int_t,bool>::iterator it=channels.begin();it!=channels.end();++it) {
606 for(std::map<TString,Double_t>::iterator it2=
data.begin();it2!=
data.end();++it2) {
607 if(it2->first==
"NumberOfEvents") {
609 if(myMap.find(channel)==myMap.end()) {
611 Warning(
"GetMetaDataTree",
"Channel %d does not have MetaData %s",it->first,(it2->first).Data());
615 }
else if(it2->first==
"SumOfEventWeights") {
617 auto& myMap2 =
m_periods[-1]->sumOfWeights;
618 if(myMap2.find(channel)==myMap2.end()) {
620 Warning(
"GetMetaDataTree",
"Channel %d does not have MetaData %s",it->first,(it2->first).Data());
626 if(myMap2.find(channel)==myMap2.end()) {
629 Warning(
"GetMetaDataTree",
"Channel %d does not have MetaData %s",it->first,(it2->first).Data());
631 data[it2->first]=myMap2[channel];
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;}
662 if(
tree->SetBranchAddress(
"CustomName",&customName)!=0) {
663 Error(
"AddDistributionTree",
"Could not find CustomName branch in TTree");
throw std::runtime_error(
"Throwing 18");
666 if(strcmp(
tree->GetName(),
"DataCustomReweighting")==0) {channel=-1;isMC=
false;}
668 if(
tree->SetBranchAddress(
"Channel",&channel)!=0) {
669 Error(
"AddDistributionTree",
"Could not find Channel branch in TTree");
throw std::runtime_error(
"Throwing 18");
672 if(
tree->SetBranchAddress(
"RunNumber",&runNbr)!=0) {
673 Error(
"AddDistributionTree",
"Could not find RunNumber branch in TTree");
throw std::runtime_error(
"Throwing 18");
676 if(
tree->SetBranchAddress(
"PeriodStarts",&pStartsPtr)!=0) {
677 Error(
"AddDistributionTree",
"Could not find PeriodStarts branch in TTree");
throw std::runtime_error(
"Throwing 18");
679 if(
tree->SetBranchAddress(
"PeriodEnds",&pEndsPtr)!=0) {
680 Error(
"AddDistributionTree",
"Could not find PeriodEnds branch in TTree");
throw std::runtime_error(
"Throwing 18");
682 if(
tree->FindBranch(
"IsDefaultForRunNumber")!=0) {
683 tree->SetBranchAddress(
"IsDefaultForRunNumber",&isDefaultForRunNumber);
684 hasDefaultsBranch=
true;
688 if(
tree->SetBranchAddress(
"HistName",&histName)!=0) {
689 Error(
"AddDistributionTree",
"Could not find HistName branch in TTree");
throw std::runtime_error(
"Throwing 18");
691 long n =
tree->GetEntries();
692 std::map<TString,bool> loadedHistos;
693 for(
long i=0;i<n;i++) {
695 TString sHistName(histName);
696 TString weightName(customName);
697 const auto &[ptr, inserted] = loadedHistos.try_emplace(sHistName,
true);
702 for(
unsigned int j=0;j<pStarts->size();j++) {
703 unsigned int start = pStarts->at(j);
704 unsigned int end = pEnds->at(j);
709 TH1 *histo = (TH1*)
file->Get( sHistName );
710 if(!histo) histo = (TH1*)
file->Get( TString::Format(
"%sPileupReweighting/%s",
m_prwFilesPathPrefix.c_str(),sHistName.Data()) );
712 Error(
"AddDistributionTree",
"Unable to find the histogram %s in the File %s",sHistName.Data(),
file->GetName());
713 throw std::runtime_error(
"Throwing 21");
720 if(hasDefaultsBranch) {
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!");
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");
746 if(period.first<0)
continue;
747 if(period.first==runNumber)
continue;
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());
757 auto& inputHist = (channelNumber<0) ?
m_runs[runNumber].inputHists[
"None"] :
m_periods[runNumber]->inputHists[channelNumber];
763 if(strcmp(hist->IsA()->GetName(),
"TH1D")==0 || strcmp(hist->IsA()->GetName(),
"TH2D")==0) {
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]);
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]);
779 Error(
"AddDistribution",
"Unknown input histogram dimensionality: %d",hist->GetDimension());
780 throw std::runtime_error(
"Throwing 98");
794 Double_t numEntries = inputHist->GetEntries();
796 std::unique_ptr<TH1> tmpHist;
797 if(channelNumber<0) {
798 m_runs[runNumber].nominalFromHists =
true;
800 tmpHist.reset(
static_cast<TH1*
>(inputHist->Clone(
"tmpHist")) );
803 for(biny=1; biny<=tmpHist->GetNbinsY(); biny++) {
804 for(binx=1; binx<=tmpHist->GetNbinsX(); binx++) {
805 bin = tmpHist->GetBin(binx,biny);
808 if(tmpHist->GetDimension()==1){
809 tmpHist->SetBinContent(
bin, hist->Interpolate(
x));
811 tmpHist->SetBinContent(
bin, hist->Interpolate(
x,
y));
815 tmpHist->Scale( hist->Integral() / tmpHist->Integral() );
816 tmpHist->SetEntries( hist->GetEntries() );
817 hist = tmpHist.get();
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);
830 Int_t inBin = inputHist->FindFixBin(
x,
y);
831 Double_t inValue = inputHist->GetBinContent(inBin);
832 inputHist->SetBinContent(inBin,inValue+value);
838 inputHist->SetEntries(numEntries+hist->GetEntries());
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!");
853 TDirectory* origDir = gDirectory;
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);
862 TTree *tmp = (TTree*)rootFile->Get(
"LumiMetaData" );
865 if(trigger==
"None") {
867 Info(
"AddLumiCalcFile",
"Adding LumiMetaData (scale factor=%f)...",
m_dataScaleFactorX);
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");
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");
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");
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");
885 long nEntries = tmp->GetEntries();
887 for(
long i=0;i<nEntries;i++) {
888 b_runNbr->GetEntry(i);b_intLumi->GetEntry(i);b_mu->GetEntry(i);
897 if(trigger==
"None") {
898 r.lumiByLbn[lbn].first += intLumi;
899 r.lumiByLbn[lbn].second = mu;
900 if(
r.nominalFromHists)
continue;
908 std::unique_ptr<TH1>& histptr =
r.inputHists[trigger];
912 histptr->Fill(mu,intLumi);
918 Info(
"AddLumiCalcFile",
"Adding LumiMetaData for DataWeight (trigger=%s) (scale factor=%f)...",trigger.Data(),
m_dataScaleFactorX);
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?");
931 gDirectory = origDir;
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!");
946 TDirectory* origDir = gDirectory;
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);
955 TTree *tmp = (TTree*)rootFile->Get( std::string(
m_prwFilesPathPrefix+
"MCPileupReweighting").c_str() );
961 tmp = 0;tmp = (TTree*)rootFile->Get( std::string(
m_prwFilesPathPrefix+
"MCCustomReweighting").c_str() );
967 tmp = 0;tmp = (TTree*)rootFile->Get( std::string(
m_prwFilesPathPrefix+
"DataCustomReweighting").c_str() );
973 tmp=0; tmp = (TTree*)rootFile->Get( std::string(
m_prwFilesPathPrefix+
"PileupReweighting/MCPileupReweighting").c_str() );
979 tmp = 0;tmp = (TTree*)rootFile->Get( std::string(
m_prwFilesPathPrefix+
"PileupReweighting/MCCustomReweighting").c_str() );
985 tmp = 0;tmp = (TTree*)rootFile->Get( std::string(
m_prwFilesPathPrefix+
"PileupReweighting/DataCustomReweighting").c_str() );
996 gDirectory = origDir;
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!");
1009 auto itr = period.second->inputHists.begin();
1010 while(itr != period.second->inputHists.end()) {
1011 if(itr->first!=chanNum) ++itr;
1014 itr = period.second->inputHists.erase(itr);
1034 Info(
"Initialize",
"In Config File Generating mode. Remember to call WriteToFile!");
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.");
1051 std::map<int,std::map<int,bool>> trackWarnings;
1053 double totalData(0);
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);
1064 if(value==0.)
continue;
1065 bool isUnrep(
false);
1066 std::map<Int_t, bool> doneChannels;
1068 if(period.first != period.second->id)
continue;
1069 if(period.first == -1)
continue;
1070 if(!period.second->contains(
run.first))
continue;
1071 for(
auto& inHist :
m_periods[-1]->inputHists) {
1072 if(inHist.first<0)
continue;
1073 if(doneChannels[inHist.first])
continue;
1074 if(period.second->inputHists.find(inHist.first)==period.second->inputHists.end()) {
1076 isUnrep=
true;doneChannels[inHist.first]=
true;
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);
1082 }
else if(period.second->inputHists[inHist.first]->GetBinContent(
bin)==0) {
1084 isUnrep=
true;doneChannels[inHist.first]=
true;
1095 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 int worstChannel = -1;
1099 double worstFraction = 0;
1101 if(channel.first<0)
continue;
1102 if(channel.second/totalData > worstFraction) { worstChannel=channel.first; worstFraction = channel.second/totalData; }
1104 if(worstChannel==-1) {
1105 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");
1106 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");
1117 if(
run.second.inputHists.find(
"None") ==
run.second.inputHists.end())
continue;
1118 TH1* hist =
run.second.inputHists[
"None"].get();
1119 Int_t
bin,binx,biny;
1120 for(biny=1; biny<=hist->GetNbinsY(); biny++) {
1121 for(binx=1; binx<=hist->GetNbinsX(); binx++) {
1122 bin = hist->GetBin(binx,biny);
1123 Double_t value = hist->GetBinContent(
bin);
1124 if(value==0.)
continue;
1126 if(period.first != period.second->id)
continue;
1127 if(!period.second->contains(
run.first))
continue;
1129 for(
auto& inHist : period.second->inputHists) {
1130 if(inHist.first<0)
continue;
1131 if((inHist.second)->GetBinContent(
bin)==0) {
1145 m_triggerObjs[
"None"] = std::make_unique< CompositeTrigger >();
1149 if(period.first != period.second->id)
continue;
1150 for(
auto& inputHist : period.second->inputHists) {
1151 int channel = inputHist.first;
1152 TH1* hist = inputHist.second.get();
1153 period.second->sumOfWeights[channel] += hist->GetSumOfWeights();
1154 period.second->numberOfEntries[channel] += hist->GetEntries();
1155 if(hist->GetDimension()==1) {
1157 period.second->primaryHists[channel]->Add(hist);
1162 if(!period.second->contains(
run.first))
continue;
1163 if(
run.second.inputHists.find(
"None") ==
run.second.inputHists.end())
continue;
1165 period.second->runNumbers.push_back(
run.first);
1166 TH1* hist =
run.second.inputHists[
"None"].get();
1169 Int_t
bin,binx,biny;
1170 for(biny=1; biny<=hist->GetNbinsY(); biny++) {
1171 for(binx=1; binx<=hist->GetNbinsX(); binx++) {
1172 bin = hist->GetBin(binx,biny);
1173 Double_t value = hist->GetBinContent(
bin);
1174 if(value==0.)
continue;
1176 if(period.second->inputBinRedirect.find(
bin) == period.second->inputBinRedirect.end()) {
1177 for(
auto& inputHist : period.second->inputHists) {
1178 if(inputHist.first<0)
continue;
1179 Double_t mcValue = (inputHist.second)->GetBinContent(
bin);
1182 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 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);}
1191 if(period.second->inputBinRedirect.find(
bin) == period.second->inputBinRedirect.end()) period.second->inputBinRedirect[
bin] =
bin;
1194 if(period.second->inputBinRedirect[
bin] !=
bin) {
1195 run.second.badBins[
bin]=value;
1198 hist->SetBinContent(
bin,0);
1200 for(
auto& triggerDists :
run.second.inputHists) triggerDists.second->SetBinContent(
bin,0);
1203 hist->SetBinContent(period.second->inputBinRedirect[
bin],hist->GetBinContent(period.second->inputBinRedirect[
bin])+hist->GetBinContent(
bin));
1204 hist->SetBinContent(
bin,0);
1206 for(
auto& triggerDists :
run.second.inputHists) {
1207 triggerDists.second->SetBinContent(period.second->inputBinRedirect[
bin],triggerDists.second->GetBinContent(period.second->inputBinRedirect[
bin])+triggerDists.second->GetBinContent(
bin));
1208 triggerDists.second->SetBinContent(
bin,0);
1216 if(
run.second.nominalFromHists) {
1219 for(
auto lb :
run.second.lumiByLbn) {
1220 totLumi +=
lb.second.first;
1222 const double integral = hist->Integral();
1230 if( hist->GetDimension()==1 ) {
1231 if(!period.second->primaryHists[-1] ) {
1239 else if( hist->GetDimension()==2 ) {
1240 if(!period.second->secondaryHists[-1] ) {
1242 period.second->secondaryHists[-1].reset(
dynamic_cast< TH2*
>(
h.release() ) );
1243 period.second->primaryHists[-1].reset(
1244 period.second->secondaryHists[-1]->ProjectionX() );
1245 period.second->primaryHists[-1]->SetDirectory(0);
1246 period.second->primaryHists[-1]->Reset();
1247 m_triggerObjs[
"None"]->triggerHists[period.second->id][0].reset(
1248 static_cast<TH1*
>(period.second->primaryHists[-1]->Clone(
"triggerHist")) );
1249 m_triggerObjs[
"None"]->triggerHists[period.second->id][0]->SetDirectory(0);
1262 double ignoredData(0);
1264 bool covered(
false);
1265 TH1* hist =
run.second.inputHists[
"None"].get();
1267 if(!period.second->contains(
run.first))
continue;
1268 if(period.first!=-1) covered=
true;
1269 if(hist->GetDimension()==1) {
1270 period.second->primaryHists[-1]->Add(hist);
1271 m_triggerObjs[
"None"]->triggerHists[period.second->id][0]->Add(hist);
1272 }
else if(hist->GetDimension()==2) {
1273 period.second->secondaryHists[-1]->Add(hist);
1274 TH1* proj =
static_cast<TH2*
>(hist)->ProjectionX();
1275 period.second->primaryHists[-1]->Add(proj);
1276 m_triggerObjs[
"None"]->triggerHists[period.second->id][0]->Add(proj);
1279 period.second->sumOfWeights[-1] += hist->GetSumOfWeights();
1280 period.second->numberOfEntries[-1] += hist->GetEntries();
1283 Warning(
"Initialize",
"loaded data in run %d that is not covered by period assignments",
run.first);
1284 ignoredData += hist->GetSumOfWeights();
1289 if(ignoredData>0.) Warning(
"Initialize",
"Period Assignments missed %f%% data",100.*ignoredData/totalData);
1296 Error(
"Initialize",
"%f%% unrepresented data, which suggests something is wrong with your prw config. Try EnableDebugging(true) to investigate",100.* (
unrepDataByChannel[-1]/totalData));
1299 Warning(
"Initialize",
"has %f%% unrepresented data. This was removed (UnrepresentedDataAction=1)",100.*frac);
1301 Warning(
"Initialize",
"has %f%% unrepresented data. This was kept in (UnrepresentedDataAction=2)",100.*frac);
1303 Warning(
"Initialize",
"has %f%% unrepresented data. This was reassigned (UnrepresentedDataAction=3)",100.*frac);
1305 Error(
"Initialize",
"has %f%% unrepresented data:",100.*frac);
1308 if(it.first<0)
continue;
1309 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]);
1311 Error(
"Initialize",
"Exiting. You must decide how to proceed...");
1312 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");
1313 Error(
"Initialize",
"2) use SetUnrepresentedDataAction(1) to remove this data from the weight calculations. You should also veto such data events (using IsUnrepresentedData(..,..) method)");
1314 Error(
"Initialize",
"3) use SetUnrepresentedDataAction(2) to leave this data in the calculation. I hope you know what you're doing!!");
1315 Error(
"Initialize",
"4) use SetUnrepresentedDataAction(3) to reassign the data to the nearest representable bin");
1316 throw std::runtime_error(
"Throwing exception 22: Unrepresented data exists. Make a choice how to handle this. See err log for details");
1320 throw std::runtime_error(
"Throwing exception 222: Some channel had too much unrepresented data. You should fix your prw file");
1328 if(period.first != period.second->id)
continue;
1329 for(
auto& pHist : period.second->primaryHists) {
1332 for(
auto& pHist : period.second->secondaryHists) {
1335 period.second->inputHists.clear();
1356 for(
auto& inHist : p->inputHists) {
1357 int channelNumber = inHist.first;
1358 if(channelNumber<0)
continue;
1359 if(
bin > (inHist.second->GetNbinsX()+2)*(inHist.second->GetNbinsY()+2)*(inHist.second->GetNbinsZ()+2))
return 2;
1360 if(inHist.second->GetBinContent(
bin)==0)
return 1;
1369 int binDistance = 1;
1371 int res1 =
IsBadBin(thisMCRunNumber,
bin+binDistance);
1372 if(!res1)
return bin+binDistance;
1373 int res2 =
IsBadBin(thisMCRunNumber,
bin-binDistance);
1374 if(!res2)
return bin-binDistance;
1375 if(res1==2 && res2==2) {
1376 Error(
"GetNearestGoodBin",
"None of the bins are good!!??");
1393 Error(
"GetUnrepresentedDataFraction",
"Unrecognised periodNumber: %d",periodNumber);
1394 throw std::runtime_error(
"Throwing 1: Unrecognised periodNumber");
1398 if(p->sumOfWeights.find(channel) == p->sumOfWeights.end()) channel =
GetDefaultChannel(periodNumber);
1401 if(p->sumOfWeights.find(channel) == p->sumOfWeights.end()) {
1402 Error(
"GetUnrepresentedDataFraction",
"Unrecognised channel: %d",channel);
1403 throw std::runtime_error(
"GetUnrepresentedDataFraction: Unrecognised channel");
1406 return p->unrepData[channel]/p->sumOfWeights[-1];
1414 if (
m_printInfo)Info(
"GetRandomRunNumber",
"Initializing the subtool..");
1420 if(!p || !p->primaryHists[-1]) {
1421 Error(
"GetRandomRunNumber",
"Unrecognised periodNumber or no data loaded for: %d",periodNumber);
1422 throw std::runtime_error(
"Throwing 1: Unrecognised periodNumber");
1425 double lumi = p->sumOfWeights[-1] *
m_random3->Rndm();
1429 for(
auto runNum : p->runNumbers) {
1430 lumiSum +=
m_runs[runNum].inputHists[
"None"]->GetSumOfWeights();
1431 if(lumiSum >= lumi-0.00001)
return runNum;
1433 Error(
"GetRandomRunNumber",
"overran integrated luminosity for periodNumber=%d (%f vs %f)",periodNumber,lumiSum,lumi);
1434 throw std::runtime_error(
"Throwing 46.1: overran integrated luminosity for GetRandomRunNumber");
1440 if (
m_printInfo) Info(
"GetRandomRunNumber",
"Initializing the subtool..");
1446 if(!p || !p->primaryHists[-1]) {
1447 Error(
"GetRandomRunNumber",
"Unrecognised periodNumber or no data loaded for: %d",periodNumber);
1448 throw std::runtime_error(
"Throwing 1: Unrecognised periodNumber");
1453 double lumi = p->primaryHists[-1]->GetBinContent(
bin) * p->sumOfWeights[-1] *
m_random3->Rndm();
1455 if(!lumi) {
return 0; }
1460 for(
auto runNum : p->runNumbers) {
1461 lumiSum +=
m_runs[runNum].inputHists[
"None"]->GetBinContent(
bin);
1462 if(lumiSum >= lumi-0.00001)
return runNum;
1464 Error(
"GetRandomRunNumber",
"overran integrated luminosity for periodNumber=%d (%f vs %f)",periodNumber,lumiSum,lumi);
1465 throw std::runtime_error(
"Throwing 46.1: overran integrated luminosity for GetRandomRunNumber");
1472 Info(
"GetRandomLumiBlockNumber",
"Initializing the subtool..");
1479 double lumisum = 0.;
1481 for(
auto& lbn :
m_runs[runNumber].lumiByLbn) {
1483 lumisum += lbn.second.first;
1484 if(lumisum >= lumi)
return lbn.first;
1486 Error(
"GetRandomLumiBlockNumber",
"overran integrated luminosity for RunNumber=%d (%f vs %f)",runNumber,lumi,lumisum);
1487 throw std::runtime_error(
"Throwing 46: overran integrated luminosity for runNumber");
1494 if (
m_printInfo) Info(
"GetRandomPeriodNumber",
"Initializing the subtool..");
1501 Error(
"GetRandomPeriodNumber",
"Unrecognised periodNumber: %d",periodNumber);
1502 throw std::runtime_error(
"Throwing 1: Unrecognised periodNumber");
1506 if(p->subPeriods.size()==0)
return p->id;
1509 double lumi = p->sumOfWeights[-1] *
m_random3->Rndm();
1513 for(
auto subp : p->subPeriods) {
1514 lumiSum += subp->sumOfWeights[-1];
1515 if(lumiSum >= lumi)
return subp->id;
1518 Error(
"GetRandomPeriodNumber",
"overran integrated luminosity for periodNumber=%d",periodNumber);
1519 throw std::runtime_error(
"Throwing 46.1: overran integrated luminosity for GetRandomPeriodNumber");
1526 return (
m_runs[runNumber].badBins[
bin] );
1532 if (
m_printInfo) Info(
"MakeWeightTree",
"Initializing the subtool..");
1537 Error(
"MakeWeightTree",
"Tool not configured properly ... please report this!");
1538 throw std::runtime_error(
"Throwing 47: Tool not configured properly ... please report this!");
1542 TFile f1(outFile,
"RECREATE");
1544 TTree* outTree =
new TTree(
"prwTree",
"prwTree");
1545 ULong64_t prwHash(0);Float_t weight(0.);
1546 outTree->Branch(hashBranch,&prwHash);
1547 outTree->Branch(weightBranch,&weight);
1549 TObjArray *tx = channelNumbers.Tokenize(
",");
1550 for (Int_t i = 0; i < tx->GetEntries(); i++) {
1551 int channelNumber = ((TObjString *)(tx->At(i)))->String().Atoi();
1552 if(channelNumber>999999 || channelNumber<0) {
1553 Error(
"MakeWeightTree",
"ChannelNumber can not be bigger than 999999 or less than 0 ... got %d",channelNumber);
1558 if(period.first==-1)
continue;
1559 int periodNumber = period.first;
1560 for(
int i=1;i<=hist->GetNbinsX();i++) {
1561 double x = hist->GetXaxis()->GetBinCenter(i);
1562 for(
int j=1;j<=hist->GetNbinsY();j++) {
1563 double y = hist->GetYaxis()->GetBinCenter(j);
1573 outTree->BuildIndex(hashBranch.Data());
1578 Info(
"MakeWeightTree",
"Successfully wrote prwTree to %s",outFile.Data());
1586 if (
m_printInfo) Info(
"GetPRWHash",
"Initializing the subtool..");
1591 Error(
"GetPRWHash",
"Tool not configured properly ... please report this!");
1592 throw std::runtime_error(
"Throwing 47: Tool not configured properly ... please report this!");
1595 ULong64_t out = hist->FindFixBin(
x,
y);
1596 out += (
unsigned long)(channelNumber)*10000000000;
1597 out += (
unsigned long)(periodNumber)*10000;
1605 if (
m_printInfo) Info(
"GetCombinedWeight",
"Initializing the subtool..");
1613 Error(
"GetCombinedWeight",
"Tool not configured properly ... please report this!");
1614 throw std::runtime_error(
"Throwing 47: Tool not configured properly ... please report this!");
1626 if (
m_printInfo) Info(
"GetPeriodWeight",
"Initializing the subtool..");
1633 Error(
"GetPeriodWeight",
"Unrecognised periodNumber: %d",periodNumber);
1634 throw std::runtime_error(
"Throwing 1: Unrecognised periodNumber");
1636 if(p->sumOfWeights.find(channelNumber) == p->sumOfWeights.end()) {
1638 if(channelNumber!=0) {
1639 Warning(
"GetPeriodWeight",
"You're using a default config file ... you're gonna have a bad time!!");
1640 Warning(
"GetPeriodWeight",
"Please generate proper config files!");
1644 double n_a = p->sumOfWeights[channelNumber];
1645 double n =
m_periods[-1]->sumOfWeights[channelNumber];
1647 double l_a = p->sumOfWeights[-1];
1648 double l =
m_periods[-1]->sumOfWeights[-1];
1650 return (l_a/l) / (n_a/n);
1656 if (
m_printInfo) Info(
"GetPrimaryWeight",
"Initializing the subtool..");
1663 Error(
"GetPrimaryWeight",
"Unrecognised periodNumber: %d",periodNumber);
1664 throw std::runtime_error(
"Throwing 1: Unrecognised periodNumber");
1666 int oChanNumber = channelNumber;
1667 if(p->sumOfWeights.find(channelNumber) == p->sumOfWeights.end()) channelNumber =
GetDefaultChannel(periodNumber);
1669 if(!p->primaryHists[channelNumber]) {
1670 Error(
"GetPrimaryWeight",
"Unrecognised channelNumber %d for periodNumber %d",oChanNumber,periodNumber);
1671 throw std::runtime_error(
"Throwing 2: Unrecognised channelNumber");
1674 int bin = p->primaryHists[channelNumber]->FindFixBin(
x);
1676 double n = p->primaryHists[channelNumber]->GetBinContent(
bin);
1682 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);
1686 if(!p->primaryHists[-1]) {
1687 Error(
"GetPrimaryWeight",
"No data loaded for period %d. Did you forget to load a lumicalc file or data config file?",periodNumber);
1688 throw std::runtime_error(
"Throwing 3: No data loaded. Did you forget to load a lumicalc file or data config file?");
1691 double l = p->primaryHists[-1]->GetBinContent(
bin);
1694 Error(
"GetPrimaryWeight",
"No events expected with this mu. Incorrect PRW profile? Throwing exception ...");
1695 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 ));
1704 if (
m_printInfo) Info(
"GetSecondaryWeight",
"Initializing the subtool..");
1711 Error(
"GetSecondaryWeight",
"Unrecognised periodNumber: %d",periodNumber);
1712 throw std::runtime_error(
"Throwing 1: Unrecognised periodNumber");
1714 if(p->sumOfWeights.find(channelNumber) == p->sumOfWeights.end()) channelNumber =
GetDefaultChannel(periodNumber);
1715 int bin = p->secondaryHists[channelNumber]->FindFixBin(
x,
y);
1716 double n = p->secondaryHists[channelNumber]->GetBinContent(
bin);
1717 double l = p->secondaryHists[-1]->GetBinContent(
bin);
1733 if (
m_printInfo) Info(
"GetDataWeight",
"Initializing the subtool..");
1743 Error(
"GetDataWeight",
"Unrecognised periodNumber: %d",periodNumber);
1744 throw std::runtime_error(
"Throwing 1: Unrecognised periodNumber");
1762 if(tobj->second->triggerHists.find(p->id) == tobj->second->triggerHists.end()) {
1763 Error(
"GetDataWeight",
"Could not find trigger %s in period %d",trigger.Data(),p->id);
1764 throw std::runtime_error(
"GetDataWeight: Could not find trigger 1");
1769 long tbits = tobj->second->getBits(
this);
1771 if(tbits==0)
return 1;
1773 int idx = (runDependent) ? -runNumber : p->id;
1776 auto dItr = tobj->second->triggerHists[idx].find(tbits);
1779 if(dItr == tobj->second->triggerHists[idx].end()) {
1783 denomHist = tobj->second->triggerHists[idx][tbits].get();
1785 Error(
"GetDataWeight",
"Could not find trigger %s in period %d with bits %ld",trigger.Data(),idx, tbits);
1786 throw std::runtime_error(
"GetDataWeight: Could not find trigger 2");
1789 denomHist = dItr->second.get();
1793 TH1* numerHist =
m_triggerObjs[
"None"]->triggerHists[idx][0].get();
1795 Error(
"GetDataWeight",
"Could not find unprescaled trigger in period %d",idx);
1796 throw std::runtime_error(
"GetDataWeight: Could not find unprescaled trigger. Please AddLumiCalc with a 'None' trigger");
1799 if(
m_doGlobalDataWeight)
return numerHist->Integral(0,numerHist->GetNbinsX()+1)/denomHist->Integral(0,denomHist->GetNbinsX()+1);
1807 if(!denomHist->GetBinContent(
bin)) {
1809 Error(
"GetDataWeight",
"Unrecognised mu value %f ... are you sure you included all lumicalc files",
x);
1810 throw std::runtime_error(
"GetDataWeight: Unrecognised mu value. Please AddLumiCalc enough lumi with 'None' trigger");
1813 return numerHist->GetBinContent(
bin)/denomHist->GetBinContent(
bin);
1830 if(out<=0)
return 0;
1839 if (
m_printInfo) Info(
"Fill",
"Initializing the subtool..");
1847 if(channelNumber>=0) {
1854 Error(
"Fill",
"Unrecognised runNumber: %d. Check your period configuration (AddPeriod or UsePeriodConfig)",runNumber);
1855 throw std::runtime_error(
"Throwing 1: Unrecognised periodNumber");
1860 Error(
"Fill",
"Unrecognised runNumber: %d. Check your period configuration (AddPeriod or UsePeriodConfig) ... but should never have got here so please report this!",runNumber);
1861 throw std::runtime_error(
"Throwing 1: Unrecognised periodNumber");
1863 std::unique_ptr<TH1>& histptr = p->inputHists[channelNumber];
1868 hist = histptr.get();
1872 hist =
r.inputHists[
"None"].get();
1876 Error(
"Fill",
"Unknown [run,channel] = [%d,%d]",runNumber,channelNumber);
1877 throw std::runtime_error(
"Throwing 45: Fill:: Unknown [run,channel] ");
1880 if(hist->GetDimension()==1) {
1881 return hist->Fill(
x,w);
1882 }
else if(hist->GetDimension()==2) {
1883 return (
static_cast<TH2*
>(hist))->Fill(
x,
y,w);
1890 if(!
m_countingMode) {Warning(
"WriteToFile",
"Not in counting mode, so no file will be written");
return 0;}
1895 TString filename = fname;
1896 filename += (filename==
"") ? TString(this->GetName()) +
".prw.root" :
"";
1900 TFile* outFile = TFile::Open(filename,
"RECREATE");
1908 if(!
m_countingMode) {Warning(
"WriteToFile",
"Not in counting mode, so no file will be written");
return 0;}
1910 TDirectory* origDir = gDirectory;
1914 std::unique_ptr< TTree > outTreeMC;
1915 std::unique_ptr< TTree > outTreeData;
1916 Int_t channel = 0; UInt_t runNumber = 0;
1917 auto pStarts = std::make_unique< std::vector< UInt_t > >();
1918 auto pStartsPtr = pStarts.get();
1919 auto pEnds = std::make_unique< std::vector< UInt_t > >();
1920 auto pEndsPtr = pEnds.get();
1921 Char_t histName[150];
1926 if(period.first != period.second->id)
continue;
1927 if(period.first<0)
continue;
1928 runNumber = period.first;
1931 if(period.second->subPeriods.size()==0) {
1932 pStarts->push_back(period.second->start); pEnds->push_back(period.second->end);
1935 for(
auto subp : period.second->subPeriods) {
1936 pStarts->push_back(subp->start); pEnds->push_back(subp->end);
1939 for(
auto& inHist : period.second->inputHists) {
1940 channel = inHist.first;
1941 TH1* hist = inHist.second.get();
1942 strncpy(histName,hist->GetName(),
sizeof(histName)-1);
1946 outTreeMC.reset(
new TTree(
"MCPileupReweighting",
"MCPileupReweighting") );
1947 outTreeMC->Branch(
"Channel",&channel);
1948 outTreeMC->Branch(
"RunNumber",&runNumber);
1949 outTreeMC->Branch(
"PeriodStarts",&pStartsPtr);
1950 outTreeMC->Branch(
"PeriodEnds",&pEndsPtr);
1951 outTreeMC->Branch(
"HistName",&histName,
"HistName/C");
1959 runNumber =
run.first;
1960 if(
run.second.inputHists.find(
"None")==
run.second.inputHists.end())
continue;
1962 TH1* hist =
run.second.inputHists[
"None"].get();
1963 strncpy(histName,hist->GetName(),
sizeof(histName)-1);
1966 outTreeData.reset(
new TTree(
"DataPileupReweighting",
"DataPileupReweighting") );
1967 outTreeData->Branch(
"RunNumber",&runNumber);
1968 outTreeData->Branch(
"HistName",&histName,
"HistName/C");
1970 outTreeData->Fill();
1979 outTreeData->Write();
1983 Info(
"WriteToFile",
"Successfully generated config file: %s",outFile->GetName());
1984 Info(
"WriteToFile",
"Happy Reweighting :-)");
1987 gDirectory = origDir;
1999 if(hist->InheritsFrom(
"TH3")) {
2000 Error(
"normalizeHistogram",
"3D reweighting not supported yet");
2001 throw std::runtime_error(
"Throwing 3: 3D reweighting not supported yet");
2003 else if(hist->InheritsFrom(
"TH2")) {
2004 bool skipNorm=
false;
2006 TH1D* proj =
static_cast<TH2*
>(hist)->ProjectionX();
2007 Int_t
bin,binx,biny,binz;
2008 for(binz=1; binz<=hist->GetNbinsZ(); binz++) {
2009 for(biny=1; biny<=hist->GetNbinsY(); biny++) {
2010 for(binx=1; binx<=hist->GetNbinsX(); binx++) {
2011 bin = hist->GetBin(binx,biny,binz);
2012 Double_t value = hist->GetBinContent(
bin);
2013 Double_t normalizer = proj->GetBinContent(binx);
2014 if(normalizer!=0.0) {
2015 hist->SetBinContent(
bin,value/normalizer);
2023 if(skipNorm &&
m_debugging) Warning(
"normalizeHistogram",
"Skipped normalization in hist %s",hist->GetName());
2026 if(hist->GetSumOfWeights()!=0.0) {
2027 hist->Scale(1.0/hist->GetSumOfWeights());
2029 if (
m_debugging) Warning(
"normalizeHistogram",
"Skipping Normalizing histogram %s to ~zero: %f",hist->GetName(),hist->GetSumOfWeights());
2033 Error(
"normalizeHistogram",
"Non existent histogram for normalizing");
throw std::runtime_error(
"Throwing 56");
2041 if(coll->IsEmpty())
return 0;
2046 while( ( obj = next() ) ) {
2051 Error(
"Merge",
"Unknown object type encountered: %s",obj->ClassName() );
2057 if(period.first != period.second->id)
continue;
2058 for(
auto& iHist : period.second->inputHists) {
2060 m_periods[period.first]->inputHists[iHist.first].reset(
2061 dynamic_cast<TH1*
>(iHist.second->Clone(iHist.second->GetName())) );
2062 m_periods[period.first]->inputHists[iHist.first]->SetDirectory(0);
2070 for(
auto& iHist :
run.second.inputHists) {
2071 if( !
m_runs[
run.first].inputHists[iHist.first] ) {
2072 m_runs[
run.first].inputHists[iHist.first].reset(
2073 dynamic_cast<TH1*
>( iHist.second->Clone(iHist.second->GetName())) );
2074 m_runs[
run.first].inputHists[iHist.first]->SetDirectory(0);
2076 m_runs[
run.first].inputHists[iHist.first]->Add(iHist.second.get());
2089 TString triggerCopy = trigger; triggerCopy.ReplaceAll(
" ",
""); triggerCopy.ReplaceAll(
"&&",
"&");triggerCopy.ReplaceAll(
"||",
"|");
2092 Error(
"GetDataWeight",
"Error parsing composite trigger set: %s",trigger.Data());
2093 throw std::runtime_error(
"Could not parse composite trigger");
2096 std::vector<TString> subTriggers;
2098 t->getTriggers(subTriggers);
2100 t->subTriggers = std::move(subTriggers);
2110 TH1* unprescaledLumi = 0;
2111 if(runDependentRun) {
2112 unprescaledLumi =
m_triggerObjs[
"None"]->triggerHists[-runDependentRun][0].get();
2114 bool fillUnprescaledLumi = (unprescaledLumi==0);
2117 long tbits = t->getBits(
this);
2123 TDirectory* origDir = gDirectory;
2125 std::map<TString, std::map<Int_t, std::map<Int_t, Float_t> > > prescaleByRunAndLbn;
2128 for(std::vector<TString>::iterator it = t->subTriggers.begin();it!=t->subTriggers.end();++it) {
2135 TFile* rootFile = TFile::Open( fileName,
"READ" );
2136 if ( rootFile->IsZombie() ) {
2137 Error(
"CalculatePrescaledLuminosityHistograms",
"Could not open file: %s",fileName.Data());
2138 std::string toThrow =
"Throwing 6: Could not open file: "; toThrow += fileName.Data();
2139 throw std::runtime_error(toThrow);
2142 TTree *tmp = (TTree*)rootFile->Get(
"LumiMetaData" );
2146 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;
2147 if(tmp->SetBranchAddress(
"RunNbr",&runNbr,&b_runNbr)!=0) {
2148 Error(
"CalculatePrescaledLuminosityHistograms",
"Could not find RunNbr branch in Data TTree");
throw std::runtime_error(
"Could not find RunNbr branch in Data TTree");
2150 if(tmp->SetBranchAddress(
"L1Presc",&ps1,&b_L1Presc)!=0) {
2151 Error(
"CalculatePrescaledLuminosityHistograms",
"Could not find L1Presc branch in Data TTree");
throw std::runtime_error(
"Could not find L1Presc branch in Data TTree");
2153 if(tmp->SetBranchAddress(
"L2Presc",&ps2,&b_L2Presc)!=0) {
2154 Error(
"CalculatePrescaledLuminosityHistograms",
"Could not find L2Presc branch in Data TTree");
throw std::runtime_error(
"Could not find L2Presc branch in Data TTree");
2156 if(tmp->SetBranchAddress(
"L3Presc",&ps3,&b_L3Presc)!=0) {
2157 Error(
"CalculatePrescaledLuminosityHistograms",
"Could not find L3Presc branch in Data TTree");
throw std::runtime_error(
"Could not find L3Presc branch in Data TTree");
2159 if(tmp->SetBranchAddress(
"LBStart",&lbn,&b_lbn)!=0) {
2160 Error(
"CalculatePrescaledLuminosityHistograms",
"Could not find LBStart branch in Data TTree");
throw std::runtime_error(
"Could not find LBStart branch in Data TTree");
2162 long nEntries = tmp->GetEntries();
2163 for(
long i=0;i<nEntries;i++) {
2164 b_runNbr->GetEntry(i);b_L1Presc->GetEntry(i);b_L2Presc->GetEntry(i);b_L3Presc->GetEntry(i);b_lbn->GetEntry(i);
2166 if(runDependentRun &&
int(runNbr)!=runDependentRun)
continue;
2170 if(ps1>0&&ps2>0&&ps3>0) prescaleByRunAndLbn[*it][runNbr][lbn] = ps1*ps2*ps3;
2171 else if(isUnprescaled) prescaleByRunAndLbn[*it][runNbr][lbn] = 1;
2182 TFile* rootFile = TFile::Open( fileName,
"READ" );
2183 if ( rootFile->IsZombie() ) {
2184 Error(
"CalculatePrescaledLuminosityHistograms",
"Could not open file: %s",fileName.Data());
2185 std::string toThrow =
"Throwing 6: Could not open file: "; toThrow += fileName.Data();
2186 throw std::runtime_error(toThrow);
2189 TTree *tmp = (TTree*)rootFile->Get(
"LumiMetaData" );
2193 UInt_t runNbr=0;Float_t intLumi=0;UInt_t lbn=0;TBranch *b_runNbr=0;TBranch *b_intLumi=0;TBranch *b_lbn=0;
2194 Float_t mu=0.; TBranch *b_mu=0;
2195 if(tmp->SetBranchAddress(
"RunNbr",&runNbr,&b_runNbr)!=0) {
2196 Error(
"CalculatePrescaledLuminosityHistograms",
"Could not find RunNbr branch in Data TTree");
throw std::runtime_error(
"Could not find RunNbr branch in Data TTree");
2198 if(tmp->SetBranchAddress(
"AvergeInteractionPerXing",&mu,&b_mu)!=0) {
2199 Error(
"CalculatePrescaledLuminosityHistograms",
"Could not find AvergeInteractionPerXing branch in Data TTree");
throw std::runtime_error(
"Could not find AvergeInteractionPerXing branch in Data TTree");
2201 if(tmp->SetBranchAddress(
"IntLumi",&intLumi,&b_intLumi)!=0) {
2202 Error(
"CalculatePrescaledLuminosityHistograms",
"Could not find IntLumi branch in Data TTree");
throw std::runtime_error(
"Could not find IntLumi branch in Data TTree");
2204 if(tmp->SetBranchAddress(
"LBStart",&lbn,&b_lbn)!=0) {
2205 Error(
"CalculatePrescaledLuminosityHistograms",
"Could not find LBStart branch in Data TTree");
throw std::runtime_error(
"Could not find LBStart branch in Data TTree");
2207 long nEntries = tmp->GetEntries();
2209 for(
long i=0;i<nEntries;i++) {
2210 b_runNbr->GetEntry(i);b_intLumi->GetEntry(i);b_mu->GetEntry(i);
2214 if(runDependentRun &&
int(runNbr)!=runDependentRun)
continue;
2217 double pFactor = t->eval(prescaleByRunAndLbn,runNbr,lbn,
this);
2224 bool firstFill=
false;
2226 if(p.first != p.second->id)
continue;
2227 if(!p.second->contains(runNbr))
continue;
2228 if(runDependentRun && firstFill)
continue;
2230 int idx = (runDependentRun) ? -runDependentRun : p.second->id;
2233 auto& triggerHists = t->triggerHists[idx];
2234 std::unique_ptr<TH1>& histptr = triggerHists[tbits];
2237 if(
m_debugging &&
m_printInfo) Info(
"CalculatePrescaledLuminosityHistograms",
"Created Data Weight Histogram for [%s,%d,%d,%ld]",t->val.Data(),p.first,idx,tbits);
2241 else if(
m_unrepresentedDataAction==3 ) {histptr->Fill(triggerHists[tbits]->GetBinCenter(p.second->inputBinRedirect[
bin]), intLumi*pFactor);}
2245 if(runDependentRun && fillUnprescaledLumi) {
2247 if(unprescaledLumi==0) {
2249 unprescaledLumi =
m_triggerObjs[
"None"]->triggerHists[-runDependentRun][0].get();
2252 else if(
m_unrepresentedDataAction==3 ) {unprescaledLumi->Fill(unprescaledLumi->GetBinCenter(p.second->inputBinRedirect[
bin]), intLumi);}
2272 gDirectory = origDir;
2277std::unique_ptr<CP::TPileupReweighting::CompositeTrigger>
2281 Info(
"makeTrigger",
"Doing %s", s.Data() );
2286 std::unique_ptr< CompositeTrigger > cOper1;
2287 if( s.BeginsWith(
"(" ) ) {
2289 int bCounter=1;
int i=1;
2290 while( ( bCounter != 0 ) && ( i <= s.Length() ) ) {
2291 if( s( i ) ==
'(' ) {
2293 }
else if( s( i ) ==
')' ) {
2298 if( bCounter != 0 ) {
2299 Error(
"makeTrigger",
"Missing closing bracket" );
2300 return std::unique_ptr< CompositeTrigger >();
2302 oper1 = s( 1, i - 2 );
2303 if( i == s.Length() + 1 ) {
2315 int i=0;
int bCounter=0;
int op=0;
2316 while( i <= s.Length() ) {
2317 if( s( i ) ==
'(' ) {
2319 }
else if( s( i ) ==
')' ) {
2321 }
else if( ( s( i ) ==
'&' ) && ( bCounter == 0 ) ) {
2324 }
else if( ( s( i ) ==
'|' ) && ( bCounter == 0 ) ) {
2334 Error(
"GetDataWeight",
"Could not find subTrigger %s", s.Data() );
2335 return std::unique_ptr< CompositeTrigger >();
2340 auto out = std::make_unique< CompositeTrigger >();
2346 auto out = std::make_unique< CompositeTrigger >();
2351 out->trig1 = std::move( cOper1 );
2355 if( ! out->trig1 ) {
2356 return std::unique_ptr< CompositeTrigger >();
2359 TString oper2 = s( i + 1, s.Length() );
2361 if( ! out->trig2 ) {
2362 return std::unique_ptr< CompositeTrigger >();
2371 while( j <= s.Length() ) {
2372 if( s( j ) ==
'(' ) {
2374 }
else if( s( j )==
')' ) {
2376 }
else if( ( s( j ) ==
'|' ) && ( bCounter == 0 ) ) {
2382 if( ( j == s.Length() + 1 ) && ( op == 2 ) ) {
2384 out->trig1 = std::move( cOper1 );
2389 TString oper2 = s( i + 1, s.Length() );
2391 Info(
"makeTrigger",
"Found & %s %s", oper1.Data(), oper2.Data() );
2394 if( ! out->trig2 ) {
2395 return std::unique_ptr< CompositeTrigger >();
2398 }
else if( op ==1 ) {
2401 TString oper2 = s( j + 1, s.Length() );
2403 Info(
"makeTrigger",
"Found & then | %s %s", oper1.Data(),
2408 if( ! out->trig1 ) {
2409 return std::unique_ptr< CompositeTrigger >();
2412 if( ! out->trig2 ) {
2413 return std::unique_ptr< CompositeTrigger >();
2417 Error(
"makeTrigger",
"Should never have got here!, but did with %s",
2419 return std::unique_ptr< CompositeTrigger >();
char data[hepevt_bytes_allocation_ATLAS]
ClassImp(CP::TPileupReweighting) CP
Header file for AthHistogramAlgorithm.
void normalizeHistogram(TH1 *histo)
Normalize histograms.
Double_t GetLumiBlockIntegratedLumi(Int_t runNumber, UInt_t lb)
get integrated lumi for specific run and lumiblock number .
Int_t Fill(Int_t runNumber, Int_t channelNumber, Float_t w, Float_t x, Float_t y=0.)
void RemapPeriod(Int_t periodNumber1, Int_t periodNumber2)
Combine two period numbers.
Int_t WriteToFile(const TString &filename="")
std::map< Int_t, Double_t > unrepDataByChannel
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 ...
Int_t Merge(TCollection *coll)
std::map< TString, std::map< Int_t, Double_t > > m_metadata
channel metadata map
TH1 * GetInputHistogram(Int_t channelNumber, Int_t periodNumber)
Float_t GetSecondaryWeight(Int_t periodNumber, Int_t channelNumber, Float_t x, Float_t y)
std::map< UInt_t, Run > m_runs
Int_t Initialize()
Initialize this class once before the event loop starts If distribution information is provided,...
Bool_t m_doPrescaleWeight
Int_t GetRandomPeriodNumber(Int_t mcRunNumber)
Get random period number from the sub-periods assigned to this run number.
Int_t AddPeriod(Int_t periodNumber, UInt_t start, UInt_t end)
Assign an mc RunNumber to a data period.
std::unique_ptr< TRandom3 > m_random3
Int_t GetNearestGoodBin(Int_t thisMCRunNumber, Int_t bin)
Bool_t m_lumiVectorIsLoaded
std::list< Period > m_periodList
List physically holding (owning) period objects.
Float_t GetCombinedWeight(Int_t periodNumber, Int_t channelNumber, Float_t x, Float_t y=0.)
Int_t UsePeriodConfig(const TString &configName)
use a hardcoded period configuration
void SetDefaultChannel(Int_t channel, Int_t mcRunNumber=-1)
Set which channel should be used as a default when specific mc channel distributions cannot be found.
Bool_t m_ignoreFilePeriods
std::unique_ptr< CompositeTrigger > makeTrigger(const TString &s)
Bool_t IsUnrepresentedData(Int_t runNumber, Float_t x, Float_t y=0.)
void CalculatePrescaledLuminosityHistograms(const TString &trigger, int run_dependent=0)
Double_t GetIntegratedLumi(const TString &trigger="")
total luminosity loaded and accepted by the tool (in inverse pb)
Int_t SetUniformBinning(Int_t nbinsx, Double_t xlow, Double_t xup, Int_t nbinsy=0, Double_t ylow=0, Double_t yup=0)
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.
std::map< Int_t, Period * > m_periods
Int_t AddMetaDataFile(const TString &fileName, const TString &channelBranchName="mc_channel_number")
std::unique_ptr< TH1 > m_emptyHistogram
the empty histogram used for this weight... effectively holds the configuration of the binning
Bool_t RemoveChannel(int chanNum)
Removes a channel from the inputs ... this is for experts only.
UInt_t GetRandomRunNumber(Int_t mcRunNumber)
Gets a random data run number according to the integrated lumi distribution associated to this mcRunN...
Float_t GetPrimaryWeight(Int_t periodNumber, Int_t channelNumber, Float_t x)
Int_t GenerateMetaDataFile(const TString &fileName, const TString &channelBranchName="mc_channel_number")
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.
Int_t AddLumiCalcFile(const TString &fileName, const TString &trigger="None")
Int_t GetFirstFoundPeriodNumber(UInt_t runNumber)
Get the first period number with the data run number contained - assume all periods are disconnected ...
void calculateHistograms(CompositeTrigger *trigger, int run_dependent)
Float_t m_dataScaleFactorX
Int_t AddConfigFile(const TString &fileName)
Float_t m_dataScaleFactorY
UInt_t GetRandomLumiBlockNumber(UInt_t runNumber)
Get a random lumi block from the run number given.
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
Int_t GetDefaultChannel(Int_t mcRunNumber=-1)
void AddDistributionTree(TTree *tree, TFile *file)
Int_t SetBinning(Int_t nbinsx, Double_t *xbins, Int_t nbinsy=0, Double_t *ybins=0)
Add a histogram binning config.
std::map< TString, std::unique_ptr< CompositeTrigger > > m_triggerObjs
Bool_t m_doGlobalDataWeight
Double_t GetUnrepresentedDataFraction(Int_t periodNumber, Int_t channel)
return the unrepresented data fraction in a given channel .
TTree * GetMetaDataTree()
combines loaded metadata with channel sumsofweights and entry counts
TPileupReweighting(const char *name="TPileupReweighting")
Standard constructor.
Bool_t m_ignoreBadChannels
ULong64_t GetPRWHash(Int_t periodNumber, Int_t channelNumber, Float_t x, Float_t y=0.)
std::string m_prwFilesPathPrefix
Int_t IsBadBin(Int_t thisMCRunNumber, Int_t bin)
TPileupReweighting * m_parentTool
Float_t GetPeriodWeight(Int_t periodNumber, Int_t channelNumber)
std::unique_ptr< TH1 > CloneEmptyHistogram(Int_t runNumber, Int_t channelNumber)
std::map< TString, std::vector< TString > > m_lumicalcFiles
map storing the lumicalc file locations - used when building DataPileupWeights
Int_t AddDistribution(TH1 *hist, Int_t runNumber, Int_t channelNumber)
Double_t m_unrepDataTolerance
Int_t m_lumicalcRunNumberOffset
Double_t GetSumOfEventWeights(Int_t channel)
Bool_t MakeWeightTree(TString channelNumbers, TString outFile, TString hashBranch="PRWHash", TString weightBranch="PileupWeight")
Int_t m_unrepresentedDataAction
Error
The different types of error that can be flagged in the L1TopoRDO.
JetConstituentVector::iterator iterator