-
Notifications
You must be signed in to change notification settings - Fork 0
/
avgDistMax.C
88 lines (80 loc) · 2.15 KB
/
avgDistMax.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//File: allErrSummaries.C
//Info: Quick macro to make initial pmu sideband/signal region plots.
//Author: David Last [email protected]/[email protected]
//C++ includes
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <unordered_map>
#include <bitset>
#include <time.h>
#include <sys/stat.h>
//ROOT includes
#include "TInterpreter.h"
#include "TROOT.h"
#include "TH1F.h"
#include "TH2F.h"
#include "THStack.h"
#include "TFile.h"
#include "TTree.h"
#include "TKey.h"
#include "TDirectory.h"
#include "TSystemDirectory.h"
#include "TCanvas.h"
#include "TStyle.h"
#include "TString.h"
#include "TLorentzVector.h"
#include "TVector3.h"
#include "TLegend.h"
#include "TMath.h"
#include "TColor.h"
#include "TParameter.h"
//PlotUtils includes??? Trying anything at this point...
#include "PlotUtils/MnvH1D.h"
#include "PlotUtils/MnvPlotter.h"
using namespace std;
using namespace PlotUtils;
double DistAvg(vector<double> vals) {
vector<double> weights;
double weightSum=0.0;
for (auto val:vals){
double distSum=0.0;
for (auto val2:vals){
distSum += fabs(val-val2);
}
double weight = (distSum) ? 100.0/distSum : -1.0;
weights.push_back(weight);
weightSum += weight;
}
double avg = 0.0;
for (int i=0; i<vals.size(); ++i){
avg += vals.at(i)*weights.at(i)/weightSum;
}
return avg;
}
TH1D* avgDistMax(vector<TFile*> files, TString name, string band){
vector<MnvH1D*> mnvs;
vector<TH1D*> syst;
vector<double> POTs;
double POTsum=0.0;
for (auto file:files){
mnvs.push_back((MnvH1D*)file->Get(name));
syst.push_back(mnvs.back()->GetVertErrorBand(band)->GetHist(0));
TParameter<double>* POT = (TParameter<double>*)file->Get("POTUsed");
POTsum += POT->GetVal();
POTs.push_back(POT->GetVal());
}
TH1D* hOut = new TH1D(mnvs.at(0)->GetCVHistoWithStatError());
for (int i=0; i <= hOut->GetNbinsX(); ++i){
vector<double> vals;
for (int j=0; j<syst.size(); ++j) vals.push_back(syst.at(j)->GetBinContent(i)*POTsum/POTs.at(j));
hOut->SetBinContent(i, DistAvg(vals));
}
return hOut;
}