ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/NonMCBackground/src/SelectionEMU.cc
Revision: 1.8
Committed: Thu Jun 21 21:25:38 2012 UTC (12 years, 10 months ago) by dkralph
Content type: text/plain
Branch: MAIN
Changes since 1.7: +11 -14 lines
Log Message:
switch to new denom defs

File Contents

# User Rev Content
1 dkralph 1.4 //***************************************************************************************************
2     //
3     // selection sync'ed with https://twiki.cern.ch/twiki/bin/viewauth/CMS/HiggsZZ4l2012SummerSync
4     //
5     //***************************************************************************************************
6    
7     // system headers
8     #include <map>
9     #include <utility>
10    
11     // mit headers
12     #include "Vertex.h"
13    
14     // 4L stuff
15 khahn 1.1 #include "SelectionStatus.h"
16     #include "EventData.h"
17     #include "SimpleLepton.h"
18     #include "EfficiencyWeightsInterface.h"
19 dkralph 1.4 #include "ElectronSelection.h"
20     #include "MuonSelection.h"
21 khahn 1.1 #include "IsolationSelection.h"
22     #include "SelectionEMU.h"
23 dkralph 1.4 #include "ReferenceSelection.h"
24     #include "Selection.h"
25     #include "CommonDefs.h"
26 khahn 1.1 #include "SelectionDefs.h"
27 dkralph 1.4 #include "FSR.h"
28 dkralph 1.5 #include "SelectionFuncs.h"
29 khahn 1.1
30    
31 dkralph 1.4 extern vector<SimpleLepton> failingLeptons;
32     extern vector<SimpleLepton> passingLeptons;
33 khahn 1.1
34 dkralph 1.4 //--------------------------------------------------------------------------------------------------
35     EventData apply_HZZ4L_EMU_selection(ControlFlags &ctrl, // input control
36     const mithep::EventHeader *info, // input event info
37     const mithep::Array<mithep::Vertex> * vtxArr ,
38     const mithep::Array<mithep::PFCandidate> *pfCandidates,
39     const mithep::Array<mithep::PileupEnergyDensity> *puEnergyDensity,
40     const mithep::Array<mithep::Electron> *electronArr, // input electrons
41     SelectionStatus (*ElectronPreSelector)( ControlFlags &,
42     const mithep::Electron*,
43     const mithep::Vertex *),
44     SelectionStatus (*ElectronIDSelector)( ControlFlags &,
45     const mithep::Electron*,
46     const mithep::Vertex *),
47     SelectionStatus (*ElectronIsoSelector)( ControlFlags &,
48     const mithep::Electron*,
49     const mithep::Vertex *,
50     const mithep::Array<mithep::PFCandidate> *,
51     const mithep::Array<mithep::PileupEnergyDensity> *,
52     mithep::ElectronTools::EElectronEffectiveAreaTarget,
53     vector<const mithep::PFCandidate*>),
54     const mithep::Array<mithep::Muon> *muonArr, // input muons
55     SelectionStatus (*MuonPreSelector)( ControlFlags &,
56     const mithep::Muon*,
57     const mithep::Vertex *,
58     const mithep::Array<mithep::PFCandidate> *),
59     SelectionStatus (*MuonIDSelector)( ControlFlags &,
60     const mithep::Muon*,
61     // const mithep::Vertex &),
62     const mithep::Vertex *,
63     const mithep::Array<mithep::PFCandidate> *),
64     SelectionStatus (*MuonIsoSelector)( ControlFlags &,
65     const mithep::Muon*,
66     const mithep::Vertex *,
67     const mithep::Array<mithep::PFCandidate> *,
68     const mithep::Array<mithep::PileupEnergyDensity> *,
69     mithep::MuonTools::EMuonEffectiveAreaTarget,
70     vector<const mithep::PFCandidate*>)
71     )
72     //--------------------------------------------------------------------------------------------------
73 khahn 1.1 {
74    
75     EventData ret;
76     unsigned evtfail = 0x0;
77     TRandom3 r;
78    
79 dkralph 1.4 failingLeptons.clear();
80     passingLeptons.clear();
81    
82     mithep::MuonTools::EMuonEffectiveAreaTarget eraMu;
83     mithep::ElectronTools::EElectronEffectiveAreaTarget eraEle;
84     getEATargets(ctrl,eraMu,eraEle);
85    
86     const mithep::Vertex * vtx;
87     bool goodVertex = setPV( ctrl, vtxArr, vtx );
88     if(goodVertex) {
89     ret.status.selectionBits.flip(PASS_SKIM2);
90     } else {
91     if(ctrl.debug) cout << "found bad vertex" << endl;
92     ret.status.setStatus(SelectionStatus::FAIL);
93     return ret;
94 khahn 1.1 }
95    
96 dkralph 1.4 //***********************************************************
97     // Lepton Selection
98     //***********************************************************
99 khahn 1.1 vector<SimpleLepton> lepvec;
100 dkralph 1.4 vector<const mithep::PFCandidate*> photonsToVeto;
101    
102 khahn 1.1
103     if( ctrl.debug ) cout << "\tnMuons: " << muonArr->GetEntries() << endl;
104     //----------------------------------------------------
105 dkralph 1.4 for(int i=0; i<muonArr->GetEntries(); i++)
106 khahn 1.1 {
107 dkralph 1.4 const mithep::Muon *mu = (mithep::Muon*)((*muonArr)[i]);
108 khahn 1.1
109 dkralph 1.8
110     SelectionStatus denomSel;
111     denomSel |= muonDenominatorSelection(ctrl,mu,vtx,pfCandidates);
112     if( !(denomSel.getStatus() & SelectionStatus::PRESELECTION) ) continue;
113    
114 khahn 1.1 SelectionStatus musel;
115 dkralph 1.4 musel |= (*MuonPreSelector)(ctrl,mu,vtx,pfCandidates);
116     musel |= (*MuonIDSelector)(ctrl,mu,vtx,pfCandidates );
117 dkralph 1.8 musel |= (*MuonIsoSelector)(ctrl,mu,vtx,pfCandidates,puEnergyDensity,eraMu,photonsToVeto);
118 dkralph 1.4
119     SimpleLepton tmplep;
120     float pt = mu->Pt();
121     tmplep.vec.SetPtEtaPhiM(pt,
122     mu->Eta(),
123     mu->Phi(),
124     MUON_MASS);
125 khahn 1.1
126 dkralph 1.4 tmplep.type = 13;
127     tmplep.index = i;
128     tmplep.charge = mu->Charge();
129     tmplep.isoTrk = mu->IsoR03SumPt();
130     tmplep.isoEcal = mu->IsoR03EmEt();
131     tmplep.isoHcal = mu->IsoR03HadEt();
132     tmplep.isoPF04 = musel.isoPF04;
133     tmplep.chisoPF04 = musel.chisoPF04;
134     tmplep.gaisoPF04 = musel.gaisoPF04;
135     tmplep.neisoPF04 = musel.neisoPF04;
136     // tmplep.isoPF03 = computePFMuonIso(mu,vtx,pfCandidates,0.3);
137     // tmplep.isoPF04 = computePFMuonIso(mu,vtx,pfCandidates,0.4);
138     tmplep.ip3dSig = mu->Ip3dPVSignificance();
139     tmplep.is4l = false;
140     tmplep.isEB = (fabs(mu->Eta()) < 1.479 ? 1 : 0 );
141     tmplep.isoMVA = musel.isoMVA;
142     tmplep.isTight = musel.tight();
143     tmplep.isLoose = musel.loose();
144     tmplep.status = musel;
145     tmplep.fsrRecoveryAttempted = false;
146 dkralph 1.6 SelectionStatus tmpstat = PassWwMuonSel(mu,vtx,pfCandidates);
147     tmplep.tightCutsApplied = tmpstat.tight();
148 dkralph 1.4 lepvec.push_back(tmplep);
149     if( ctrl.debug ) cout << endl;
150     }
151    
152     if( ctrl.debug ) { cout << "\tnElectron: " << electronArr->GetEntries() << endl; }
153     // --------------------------------------------------------------------------------
154     for(int i=0; i<electronArr->GetEntries(); i++)
155     {
156     const mithep::Electron *ele = (mithep::Electron*)((*electronArr)[i]);
157 khahn 1.1
158 dkralph 1.8 SelectionStatus denomSel;
159     denomSel |= electronDenominatorSelection(ctrl,ele,vtx);
160     if( !(denomSel.getStatus() & SelectionStatus::PRESELECTION) ) continue;
161    
162 dkralph 1.4 SelectionStatus elesel;
163     elesel |= (*ElectronPreSelector)(ctrl,ele,vtx);
164     elesel |= (*ElectronIDSelector)(ctrl,ele,vtx);
165 dkralph 1.8 elesel |= (*ElectronIsoSelector)(ctrl,ele,vtx,pfCandidates,puEnergyDensity,eraEle,photonsToVeto);
166 khahn 1.1
167 dkralph 1.4 SimpleLepton tmplep;
168     float pt = ele->Pt();
169     tmplep.vec.SetPtEtaPhiM( pt,
170     ele->Eta(),
171     ele->Phi(),
172     ELECTRON_MASS );
173 khahn 1.1
174 dkralph 1.4 tmplep.type = 11;
175 khahn 1.1 tmplep.index = i;
176 dkralph 1.4 tmplep.charge = ele->Charge();
177     tmplep.isoTrk = ele->TrackIsolationDr03();
178     tmplep.isoEcal = ele->EcalRecHitIsoDr03();
179     tmplep.isoHcal = ele->HcalTowerSumEtDr03();
180     tmplep.isoPF04 = elesel.isoPF04;
181     tmplep.chisoPF04 = elesel.chisoPF04;
182     tmplep.gaisoPF04 = elesel.gaisoPF04;
183     tmplep.neisoPF04 = elesel.neisoPF04;
184     // tmplep.isoPF03 = computePFEleIso(ele,vtx,pfCandidates,0.3);
185     // tmplep.isoPF04 = computePFEleIso(ele,vtx,pfCandidates,0.4);
186     tmplep.ip3dSig = ele->Ip3dPVSignificance();
187 khahn 1.1 tmplep.is4l = false;
188 dkralph 1.4 tmplep.isEB = ele->IsEB();
189     tmplep.scID = ele->SCluster()->GetUniqueID();
190     tmplep.isTight = elesel.tight();
191     tmplep.isLoose = elesel.loose();
192     tmplep.status = elesel;
193     tmplep.idMVA = elesel.idMVA;
194     tmplep.isoMVA = elesel.isoMVA;
195     tmplep.fsrRecoveryAttempted = false;
196     SelectionStatus tmpstat = electronTagSelection(ele,vtx,pfCandidates);
197     tmplep.tightCutsApplied = tmpstat.tight();
198 khahn 1.1 lepvec.push_back(tmplep);
199 dkralph 1.4 if( ctrl.debug ) cout << endl;
200 khahn 1.1 }
201 khahn 1.3
202 dkralph 1.4 sort( lepvec.begin(), lepvec.end(), SimpleLepton::lep_pt_sort );
203    
204     //********************************************************
205     // Step 2: Lepton Cleaning
206     //********************************************************
207     vector<vector<SimpleLepton>::iterator> electrons_to_erase;
208     for (vector<SimpleLepton>::iterator it1=lepvec.begin(); it1 != lepvec.end(); it1++ ) {
209     if ( abs(it1->type) != 11 ) continue;
210     TVector3 evec = it1->vec.Vect();
211    
212     bool erase_this_electron=false;
213     for (vector<SimpleLepton>::iterator it2=lepvec.begin(); it2 != lepvec.end(); it2++ ) {
214     if ( it2 == it1 ) continue;
215     if ( abs(it2->type) != 13 ) continue;
216 dkralph 1.7 // if( !(it2->status.looseIDAndPre()) ) continue;
217 dkralph 1.4 TVector3 mvec = it2->vec.Vect();
218 khahn 1.1
219 dkralph 1.4 if ( evec.DrEtaPhi(mvec) < 0.05 ) {
220     erase_this_electron=true;
221     break;
222 khahn 1.1 }
223 dkralph 1.4 }
224     if( erase_this_electron )
225     electrons_to_erase.push_back(it1);
226     }
227     for( int i=0; i<electrons_to_erase.size(); i++ ) {
228     lepvec.erase(electrons_to_erase[i]);
229     }
230 khahn 1.1
231     //********************************************************
232 dkralph 1.4 // Step 3: Good Leptons
233 khahn 1.1 //********************************************************
234 dkralph 1.4 vector<double> pt_of_leptons_to_erase;
235     for (int i=0; i<lepvec.size(); i++ ) {
236     bool already_pushed=false;
237     if( !(lepvec[i].status.loose()) ) {
238     pt_of_leptons_to_erase.push_back(lepvec[i].vec.Pt());
239     already_pushed = true;
240     failingLeptons.push_back(lepvec[i]); // these should pass preselection
241     } else {
242     passingLeptons.push_back(lepvec[i]);
243     }
244     #ifndef SYNC
245     if( !already_pushed && fabs(lepvec[i].ip3dSig)>4 )
246     pt_of_leptons_to_erase.push_back(lepvec[i].vec.Pt());
247     #endif
248 khahn 1.1 }
249 dkralph 1.4 for( int i=0; i<pt_of_leptons_to_erase.size(); i++ ) {
250     for( vector<SimpleLepton>::iterator it=lepvec.begin(); it != lepvec.end(); it++ ) {
251     SimpleLepton flep = *it;
252     if( flep.vec.Pt() != pt_of_leptons_to_erase[i] ) continue;
253     lepvec.erase(it);
254     break;
255     }
256 khahn 1.1 }
257 dkralph 1.4
258 khahn 1.1 //******************************************************************************
259 dkralph 1.4 // W + (OF SS lepton) Selection
260 khahn 1.1 //******************************************************************************
261 dkralph 1.7 if(has_ssof_lepton(ctrl)) {
262     ret.status.setStatus(SelectionStatus::EVTPASS);
263     ret.Z1leptons.push_back(passingLeptons[0]);
264     ret.Z1leptons.push_back(passingLeptons[0]);
265     ret.Z2leptons.push_back(passingLeptons[0]);
266     ret.Z2leptons.push_back(passingLeptons[0]);
267     } else {
268     ret.status.setStatus(SelectionStatus::FAIL);
269 khahn 1.1 }
270 dkralph 1.7 return ret;
271 dkralph 1.4 }
272     //----------------------------------------------------------------------------------------
273     bool has_ssof_lepton(ControlFlags &ctrl)
274     {
275     bool has_ssof=false;
276     for(unsigned iw=0; iw<passingLeptons.size(); iw++) {
277     SimpleLepton w_lep = passingLeptons[iw];
278     //????????????????????????????????????????????????????????????????????????????????????????
279     // this is applied in skim (skim also applies ww muon id)
280     // if(abs(w_lep.type) == 11) {
281     // if( !(w_lep.tightCutsApplied) )
282     // continue;
283     // }
284     //????????????????????????????????????????????????????????????????????????????????????????
285     for(unsigned ifake=0; ifake<failingLeptons.size(); ifake++) {
286     SimpleLepton fake_lep = failingLeptons[ifake];
287     if(abs(fake_lep.type) == abs(w_lep.type)) continue;
288     if(fake_lep.charge != w_lep.charge) continue;
289     has_ssof = true;
290     }
291     for(unsigned ipass=0; ipass<passingLeptons.size(); ipass++) {
292     if(ipass == iw) continue;
293     SimpleLepton pass_lep = passingLeptons[ipass];
294     if(abs(pass_lep.type) == abs(w_lep.type)) continue;
295     if(pass_lep.charge != w_lep.charge) continue;
296     has_ssof = true;
297 khahn 1.1 }
298 dkralph 1.4 }
299 khahn 1.1
300 dkralph 1.4 return has_ssof;
301 khahn 1.1 }