1 |
#include "ZeeTreeWriterMod.h"
|
2 |
#include "SelectionFuncs.h"
|
3 |
#include "TDataMember.h"
|
4 |
#include "TriggerUtils.h"
|
5 |
#include "ElectronTools.h"
|
6 |
|
7 |
const Float_t g_electron_mass = 0.51099892e-3;
|
8 |
const Float_t g_muon_mass = 105.658369e-3;
|
9 |
|
10 |
vector<bool> PFnoPUflag;
|
11 |
|
12 |
//these externs are used in SelectionFuncs.h
|
13 |
TH1D* hpu_2011;
|
14 |
TH1D* hpu_2012;
|
15 |
|
16 |
void mithep::ZeeTreeWriterMod::SlaveBegin()
|
17 |
{
|
18 |
initElectronIDMVAV1();
|
19 |
|
20 |
|
21 |
if(use_gen)
|
22 |
ReqBranch(mithep::Names::gkMCPartBrn, fParticles);
|
23 |
ReqBranch(mithep::Names::gkElectronBrn, fElectrons);
|
24 |
ReqBranch(mithep::Names::gkPVBrn, fPrimVerts);
|
25 |
ReqBranch(mithep::Names::gkPileupEnergyDensityBrn, fPileupEnergyDensity);
|
26 |
ReqBranch(mithep::Names::gkPFCandidatesBrn, fPFCandidates);
|
27 |
ReqBranch(mithep::Names::gkMvfConversionBrn, fConversions);
|
28 |
ReqBranch(mithep::Names::gkHltBitBrn, fTrigMask);
|
29 |
|
30 |
|
31 |
|
32 |
fOutputFile = new TFile(fOutputName, "RECREATE");
|
33 |
fOutputTree = new TTree("ElectronEnergyRegressionTree","ElectronEnergyRegressionTree");
|
34 |
|
35 |
fOutputTree->Branch("nvertices",&nvertices,"nvertices/i");
|
36 |
fOutputTree->Branch("rho",&rho,"rho/F");
|
37 |
fOutputTree->Branch("evt_num",&evt_num,"evt_num/i");
|
38 |
fOutputTree->Branch("lumi_sec",&lumi_sec,"lumi_sec/i");
|
39 |
fOutputTree->Branch("run_num",&run_num,"run_num/i");
|
40 |
fOutputTree->Branch("Z_reco_mass",&Z_reco_mass,"Z_reco_mass/F");
|
41 |
if(use_gen)
|
42 |
fOutputTree->Branch("Z_gen_mass",&Z_gen_mass,"Z_gen_mass/F");
|
43 |
|
44 |
|
45 |
//fOutputTree->Branch("electron1_gene",&electron1_gene,"electron1_gene/F");
|
46 |
|
47 |
//make flattish tree from classes so we don't have to rely on dictionaries for reading later
|
48 |
TClass *eclass = TClass::GetClass("mithep::ElectronEnergyRegressionData");
|
49 |
TList *elist = eclass->GetListOfDataMembers();
|
50 |
|
51 |
//create branches for electron1
|
52 |
for (int i=0; i<elist->GetEntries(); ++i) {
|
53 |
const TDataMember *tdm = static_cast<const TDataMember*>(elist->At(i));
|
54 |
if (!(tdm->IsBasic() && tdm->IsPersistent())) continue;
|
55 |
TString typestring;
|
56 |
if (TString(tdm->GetTypeName()).BeginsWith("Char_t")) typestring = "B";
|
57 |
else if (TString(tdm->GetTypeName()).BeginsWith("UChar_t")) typestring = "b";
|
58 |
else if (TString(tdm->GetTypeName()).BeginsWith("Short_t")) typestring = "S";
|
59 |
else if (TString(tdm->GetTypeName()).BeginsWith("UShort_t")) typestring = "s";
|
60 |
else if (TString(tdm->GetTypeName()).BeginsWith("Int_t")) typestring = "I";
|
61 |
else if (TString(tdm->GetTypeName()).BeginsWith("UInt_t")) typestring = "i";
|
62 |
else if (TString(tdm->GetTypeName()).BeginsWith("Float_t")) typestring = "F";
|
63 |
else if (TString(tdm->GetTypeName()).BeginsWith("Double_t")) typestring = "D";
|
64 |
else if (TString(tdm->GetTypeName()).BeginsWith("Long64_t")) typestring = "L";
|
65 |
else if (TString(tdm->GetTypeName()).BeginsWith("ULong64_t")) typestring = "l";
|
66 |
else if (TString(tdm->GetTypeName()).BeginsWith("Bool_t")) typestring = "O";
|
67 |
else continue;
|
68 |
Char_t *addr = (Char_t*)&electron1;
|
69 |
assert(sizeof(Char_t)==1);
|
70 |
fOutputTree->Branch(string("electron1." + string(tdm->GetName())).c_str(),addr + tdm->GetOffset(),TString::Format("electron1.%s/%s",tdm->GetName(),typestring.Data()));
|
71 |
}
|
72 |
|
73 |
//create branches for electron 2
|
74 |
for (int i=0; i<elist->GetEntries(); ++i) {
|
75 |
const TDataMember *tdm = static_cast<const TDataMember*>(elist->At(i));
|
76 |
if (!(tdm->IsBasic() && tdm->IsPersistent())) continue;
|
77 |
TString typestring;
|
78 |
if (TString(tdm->GetTypeName()).BeginsWith("Char_t")) typestring = "B";
|
79 |
else if (TString(tdm->GetTypeName()).BeginsWith("UChar_t")) typestring = "b";
|
80 |
else if (TString(tdm->GetTypeName()).BeginsWith("Short_t")) typestring = "S";
|
81 |
else if (TString(tdm->GetTypeName()).BeginsWith("UShort_t")) typestring = "s";
|
82 |
else if (TString(tdm->GetTypeName()).BeginsWith("Int_t")) typestring = "I";
|
83 |
else if (TString(tdm->GetTypeName()).BeginsWith("UInt_t")) typestring = "i";
|
84 |
else if (TString(tdm->GetTypeName()).BeginsWith("Float_t")) typestring = "F";
|
85 |
else if (TString(tdm->GetTypeName()).BeginsWith("Double_t")) typestring = "D";
|
86 |
else if (TString(tdm->GetTypeName()).BeginsWith("Long64_t")) typestring = "L";
|
87 |
else if (TString(tdm->GetTypeName()).BeginsWith("ULong64_t")) typestring = "l";
|
88 |
else if (TString(tdm->GetTypeName()).BeginsWith("Bool_t")) typestring = "O";
|
89 |
else continue;
|
90 |
Char_t *addr = (Char_t*)&electron2;
|
91 |
assert(sizeof(Char_t)==1);
|
92 |
fOutputTree->Branch(string("electron2." + string(tdm->GetName())).c_str(),addr + tdm->GetOffset(),TString::Format("electron2.%s/%s",tdm->GetName(),typestring.Data()));
|
93 |
}
|
94 |
|
95 |
|
96 |
//fOutputTree->Branch("electron2_gene",&electron_gene,"electron2_gene/F");
|
97 |
if(use_JSON)
|
98 |
rlrm.AddJSONFile(json_file);
|
99 |
|
100 |
|
101 |
}
|
102 |
|
103 |
void mithep::ZeeTreeWriterMod::SlaveTerminate()
|
104 |
{
|
105 |
fOutputFile->cd();
|
106 |
fOutputTree->Print();
|
107 |
fOutputFile->Write();
|
108 |
fOutputFile->Close();
|
109 |
|
110 |
}
|
111 |
|
112 |
|
113 |
void mithep::ZeeTreeWriterMod::Process()
|
114 |
{
|
115 |
|
116 |
gDebugMask = mithep::Debug::kAnalysis; // debug message category
|
117 |
gDebugLevel = 1; // higher level allows more messages to print
|
118 |
|
119 |
if(use_gen)
|
120 |
LoadBranch(mithep::Names::gkMCPartBrn);
|
121 |
LoadBranch(mithep::Names::gkElectronBrn);
|
122 |
LoadBranch(mithep::Names::gkPVBrn);
|
123 |
LoadBranch(mithep::Names::gkPileupEnergyDensityBrn);
|
124 |
LoadBranch(mithep::Names::gkMvfConversionBrn);
|
125 |
LoadBranch(mithep::Names::gkPFCandidatesBrn);
|
126 |
LoadBranch(mithep::Names::gkHltBitBrn);
|
127 |
|
128 |
mithep::RunLumiRangeMap::RunLumiPairType rl(GetEventHeader()->RunNum(), GetEventHeader()->LumiSec());
|
129 |
if(use_JSON && !rlrm.HasRunLumi(rl)) return;
|
130 |
|
131 |
fillTriggerBits( GetHLTTable(), fTrigMask, fTriggerBits );
|
132 |
|
133 |
if(apply_trigger && !fTriggerBits.test(trigger))
|
134 |
return;
|
135 |
|
136 |
PFnoPUflag.clear();
|
137 |
makePFnoPUArray(fPFCandidates, PFnoPUflag, fPrimVerts );
|
138 |
|
139 |
nvertices = fPrimVerts->GetEntries();
|
140 |
if(rho_version == e_rho_kt_6_pf_jets)
|
141 |
rho = fPileupEnergyDensity->At(0)->RhoKt6PFJets();
|
142 |
else if (rho_version == e_rho)
|
143 |
rho = fPileupEnergyDensity->At(0)->Rho();
|
144 |
else
|
145 |
assert(0);
|
146 |
run_num = GetEventHeader()->RunNum();
|
147 |
lumi_sec = GetEventHeader()->LumiSec();
|
148 |
evt_num = GetEventHeader()->EvtNum();
|
149 |
|
150 |
const MCParticle * Z_electron1 = NULL;
|
151 |
const MCParticle * Z_electron2 = NULL;
|
152 |
|
153 |
if(use_gen){
|
154 |
for(UInt_t i = 0; i < fParticles->GetEntries(); i++){
|
155 |
if(fParticles->At(i)->Is(MCParticle::kZ) && fParticles->At(i)->HasDaughter(MCParticle::kEl)){
|
156 |
Z_electron1 = fParticles->At(i)->Daughter(0);
|
157 |
Z_electron2 = fParticles->At(i)->Daughter(1);
|
158 |
}
|
159 |
}
|
160 |
if(!Z_electron1 || !Z_electron2) return;
|
161 |
}
|
162 |
|
163 |
const Electron * ele1 = NULL;
|
164 |
const Electron * ele2 = NULL;
|
165 |
|
166 |
for(UInt_t i=0; i<fElectrons->GetEntries(); ++i) {
|
167 |
for(UInt_t j=i+1; j<fElectrons->GetEntries(); ++j) {
|
168 |
|
169 |
const Electron *ele1 = fElectrons->At(i);
|
170 |
const Electron *ele2 = fElectrons->At(j);
|
171 |
|
172 |
if(ele1->Pt() < 27) continue;
|
173 |
if(fabs(ele1->Eta()) > 2.5) continue;
|
174 |
if(ele2->Pt() < 7) continue;
|
175 |
if(fabs(ele2->Eta()) > 2.5) continue;
|
176 |
|
177 |
if(ele1->Charge() == ele2->Charge()) continue;
|
178 |
|
179 |
if(use_gen && MathUtils::DeltaR(Z_electron1->Phi(),Z_electron1->Eta(),ele1->Phi(),ele1->Eta()) > 0.1
|
180 |
&& MathUtils::DeltaR(Z_electron2->Phi(),Z_electron2->Eta(),ele1->Phi(),ele1->Eta()) > 0.1) continue;
|
181 |
if(use_gen && MathUtils::DeltaR(Z_electron1->Phi(),Z_electron1->Eta(),ele2->Phi(),ele2->Eta()) > 0.1
|
182 |
&& MathUtils::DeltaR(Z_electron2->Phi(),Z_electron2->Eta(),ele2->Phi(),ele2->Eta()) > 0.1) continue;
|
183 |
|
184 |
Float_t electron_id_rho;
|
185 |
mithep::ElectronTools::EElectronEffectiveAreaTarget eff_area_version_leading;
|
186 |
mithep::ElectronTools::EElectronEffectiveAreaTarget eff_area_version_trailing;
|
187 |
|
188 |
//a tight cut on the tag based on the egamma pog
|
189 |
if(electron_id_version == e_2011_electron_id){
|
190 |
electron_id_rho = fPileupEnergyDensity->At(0)->RhoLowEta();
|
191 |
eff_area_version_leading = mithep::ElectronTools::kEleEAData2011;
|
192 |
eff_area_version_trailing = mithep::ElectronTools::kEleEAData2011;
|
193 |
}
|
194 |
else if (electron_id_version == e_2012_electron_id){
|
195 |
electron_id_rho = fPileupEnergyDensity->At(0)->RhoLowEta();
|
196 |
eff_area_version_leading = mithep::ElectronTools::kEleEAData2011;
|
197 |
eff_area_version_trailing = mithep::ElectronTools::kEleEAData2012;
|
198 |
}
|
199 |
else
|
200 |
assert(0);
|
201 |
|
202 |
ControlFlags ctrl;
|
203 |
|
204 |
//this is similar to WP 80 according to https://twiki.cern.ch/twiki/bin/view/CMS/EgammaCutBasedIdentification
|
205 |
if(!electronPOG2012CutBasedIDMedium(ele1, fPrimVerts->At(0), fPFCandidates, fConversions, electron_id_rho, eff_area_version_leading)) continue;
|
206 |
|
207 |
vector<const mithep::PFCandidate*> photonsToVeto;
|
208 |
|
209 |
if(!electronReferencePreSelection(ctrl, ele2, fPrimVerts->At(0)).passPre()) continue;
|
210 |
if(fabs(ele2->Ip3dPVSignificance()) > 4) continue;
|
211 |
if(!electronReferenceIDMVASelectionV1(ctrl, ele2, fPrimVerts->At(0)).looseID()) continue;
|
212 |
if(!electronReferenceIsoSelection(ctrl,ele2,fPrimVerts->At(0),fPFCandidates,fPileupEnergyDensity,eff_area_version_trailing,photonsToVeto).passLooseIso()) continue;
|
213 |
|
214 |
TLorentzVector vele1,vele2;
|
215 |
|
216 |
vele1.SetPtEtaPhiM(ele1->Pt(), ele1->Eta(), ele1->Phi(), g_electron_mass);
|
217 |
vele2.SetPtEtaPhiM(ele2->Pt(), ele2->Eta(), ele2->Phi(), g_electron_mass);
|
218 |
|
219 |
TLorentzVector vdielectron = vele1 + vele2;
|
220 |
|
221 |
if((vdielectron.M()<massLo) || (vdielectron.M()>massHi)) continue;
|
222 |
|
223 |
electron1.SetVars(ele1);
|
224 |
electron2.SetVars(ele2);
|
225 |
|
226 |
Z_reco_mass = (ele1->Mom() + ele2->Mom()).M();
|
227 |
if(use_gen)
|
228 |
Z_gen_mass = (Z_electron1->Mom() + Z_electron2->Mom()).M();
|
229 |
|
230 |
fOutputTree->Fill();
|
231 |
|
232 |
}
|
233 |
}
|
234 |
}
|