-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecoMinimize.cc
More file actions
165 lines (142 loc) · 5.61 KB
/
RecoMinimize.cc
File metadata and controls
165 lines (142 loc) · 5.61 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "Utilities/Analyzer.cc"
#include "Utilities/JESTools.cc"
#include "Utilities/GenTools.cc"
#include "Utilities/ROOTMini.cc"
// Delphes
#include "classes/DelphesClasses.h"
#include "external/ExRootAnalysis/ExRootTreeReader.h"
#include <TROOT.h>
#include <TH1.h>
#include <TString.h>
#include <TClonesArray.h>
#include <TLorentzVector.h>
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
void RecoMinimize(int SampleType = 0, int irun = 1, int testmode = 0) {
cout << "start" <<endl;
//SetUpUtilities
Analyzer *a = new Analyzer(SampleType, irun, 30);
TString savepath = "results/";
TString savename = "RecoMinimize";
JESTools *b = new JESTools();
GenTools *g = new GenTools("PFile","GenFile");
TFile* JESFile = new TFile("PFile/JESFile.root");
b->ReadJESPlots(JESFile);
ROOTMini *m = new ROOTMini(b);
// m->SetMinimizer();
a->SetOutput(savepath,savename);
a->DebugMode(testmode);
m->SetDebug(0);
m->SetTempOutput(0);
bool output_ = false;
TH1F* hFLBestProb = new TH1F("FLBestProb","FL Best Probability", 100,0.,1.);
TH1F* hFLRecoWprimeMass = new TH1F("FLRecoWprimeMass", "FL Reconstructed W\' mass",1000,0,1000);
TH2F* hFLPickVsProb = new TH2F("FLPickVsProb","FL Correct Pick Vs Probability; Probability; Parton Index",100,0,1.0,5,-0.5,4.5);
TH1F* hFLSampleFlags = new TH1F("FLSampleFlags","FL Sample Type determined by minimized results",3,-0.5,2.5);
TH1F* hLLBestProb = new TH1F("LLBestProb","LL Best Probability", 100,0.,1.);
TH1F* hLLRecoWprimeMass = new TH1F("LLRecoWprimeMass", "LL Reconstructed W\' mass",1000,0,1000);
TH2F* hLLPickVsProb = new TH2F("LLPickVsProb","LL Correct Pick Vs Probability; Probability; Parton Index",100,0,1.0,5,-0.5,4.5);
TH1F* hLLSampleFlags = new TH1F("LLSampleFlags","LL Sample Type determined by minimized results",3,-0.5,2.5);
for (Int_t entry = a->GetStartEntry(); entry < a->GetEndEntry(); ++entry) {
a->ReadEvent(entry);
// if (a->AssignGenParticles() == -1) continue;
if (a->RecoPass == -1) continue; //lepton != 1, jet < 5 : discard
//Set up inputs
vector<TLorentzVector> Jets = a->LVJets;
vector<bool> BTags = a->BTags;
TLorentzVector Lepton = a->LVLeptons.at(0);
TLorentzVector LVMET = a->LVMET;
m->SetLep(Lepton, LVMET);
vector< vector<int> > perms = b->MakePermutations(Jets.size());
double BestProb = -1;
int BestPerm = 0;
int BestWPB = -1;
int SampleFlag = -1;
vector<TLorentzVector> BestParticles;
BestParticles.clear();
for (unsigned iperm = 0; iperm < perms.size(); ++iperm) {
vector<int> thisperm = perms.at(iperm);
double PBTags = b->CalcPFlavor(thisperm, BTags);
vector<TLorentzVector> PermJets = b->GetPermutationLV(thisperm, Jets);
double PermP = m->MinimizeP(PermJets);
if (PermP == -1) continue;
PermP *= PBTags;
//Start to deal with W'B
vector<TLorentzVector> PermParticles;
m->ReCalcP(PermParticles);
TLorentzVector hadt = PermParticles[0]+PermParticles[1]+PermParticles[2];
TLorentzVector lept = PermParticles[3]+PermParticles[4]+PermParticles[5];
// Probability to be samples by Tops
double pTopFL = 1.;
double pTopLL = 1.;
double pTopBG = 1.; // Background likelihood correction
double topdr = hadt.DeltaR(lept);
pTopFL *= g->CalcP("TopdR",topdr,0);
pTopLL *= g->CalcP("TopdR",topdr,1);
pTopBG *= g->CalcP("TopdR",topdr,2);
double topptdiff = hadt.Pt() - lept.Pt();
pTopFL *= g->CalcP("TopPtDiff",topptdiff,0);
pTopLL *= g->CalcP("TopPtDiff",topptdiff,1);
pTopBG *= g->CalcP("TopPtDiff",topptdiff,2);
pTopFL *= pTopBG;
pTopLL *= pTopBG;
// W'b Searching
vector<int> WPBCand = b->FindWPB(Jets.size(),thisperm);
// Processing variables
double PermPWPB = -1;
int PermFlag = -1;
int PermiWPB = -1;
TLorentzVector LVPermWPB = TLorentzVector();
for (unsigned iwpb = 0; iwpb < WPBCand.size(); ++iwpb) {
double thispwpb;
int thisflag;
TLorentzVector ThisWPB = Jets.at(WPBCand.at(iwpb));
double pWPBTag = b->CalcBTag(iwpb, BTags, true);
double phadwpb = g->CalcP("WPdPhi",ThisWPB.DeltaPhi(hadt),0) * g->CalcP("WPBPt",ThisWPB.Pt(),0);
phadwpb *= pTopFL * pWPBTag;
double plepwpb = g->CalcP("WPdPhi",ThisWPB.DeltaPhi(lept),1) * g->CalcP("WPBPt",ThisWPB.Pt(),1);
plepwpb *= pTopLL * pWPBTag;
if (phadwpb > plepwpb) {
thisflag = 0;
thispwpb = phadwpb;
}
else {
thisflag = 1;
thispwpb = plepwpb;
}
if (thispwpb > PermPWPB) {
PermFlag = thisflag;
PermPWPB = thispwpb;
PermiWPB = WPBCand.at(iwpb);
LVPermWPB = ThisWPB;
}
}
//WPB for this permutation is calculated
PermParticles.push_back(LVPermWPB);
PermP *= PermPWPB;
// PermParticles orders as LFJet1, LFjet2, HadB, LepB, lepton, neutrino, w'b
// if (iperm == 0 ) BestProb = PermP;
if (PermP > BestProb || iperm == 0) {
BestProb = PermP;
BestPerm = iperm;
BestWPB = PermiWPB;
SampleFlag = PermFlag;
BestParticles = PermParticles;
}
}
if (SampleFlag == 0) {
hFLBestProb->Fill(BestProb);
double wpmass = (BestParticles[0]+BestParticles[1]+BestParticles[2]+BestParticles[6]).M();
hFLRecoWprimeMass->Fill(wpmass);
}
else if (SampleFlag == 1) {
hLLBestProb->Fill(BestProb);
double wpmass = (BestParticles[0]+BestParticles[1]+BestParticles[2]+BestParticles[6]).M();
hLLRecoWprimeMass->Fill(wpmass);
}
}
a->SaveOutput();
}