@@ -19,20 +19,22 @@ void DiLepton::initializeAnalyzer() {
1919 } else {
2020 systHelper = std::make_unique<SystematicHelper>(SKNANO_HOME + " /AnalyzerTools/DiLeptonSystematic.yaml" , MCSample, DataEra);
2121 }
22-
23- // Setup weight function map for SystematicHelper
24- // if (!IsDATA && run_syst) {
25- // setupWeightFunctions();
26- // }
2722}
2823
2924void DiLepton::executeEvent () {
3025 Event ev = GetEvent ();
26+
27+ // Initial cutflow entry
28+ float initialWeight = IsDATA ? 1.0 : MCweight () * ev.GetTriggerLumi (" Full" );
29+ fillCutflow (CutStage::Initial, Channel::NONE, initialWeight, " Central" );
30+
3131 RVec<Jet> rawJets = GetAllJets ();
3232 if (!PassNoiseFilter (rawJets, ev)) return ;
33+ fillCutflow (CutStage::NoiseFilter, Channel::NONE, initialWeight, " Central" );
3334
3435 RVec<Muon> rawMuons = GetAllMuons ();
35- if (!RunNoVetoMap && !PassVetoMap (rawJets, rawMuons, " jetvetomap" )) return ; // For Run3, reject events if any jet is within the veto map
36+ if (!(RunNoVetoMap || PassVetoMap (rawJets, rawMuons, " jetvetomap" ))) return ; // For Run3, reject events if any jet is within the veto map
37+ fillCutflow (CutStage::VetoMap, Channel::NONE, initialWeight, " Central" );
3638
3739 RVec<Electron> rawElectrons = GetAllElectrons ();
3840 Particle METv = ev.GetMETVector (Event::MET_Type::PUPPI);
@@ -43,9 +45,12 @@ void DiLepton::executeEvent() {
4345 if (!IsDATA && run_syst && systHelper) {
4446 // Step 1: Process Central objects and weight-only systematics
4547 RecoObjects centralObjects = defineObjects (ev, rawMuons, rawElectrons, rawJets, genJets, METv, " Central" );
46- Channel selectedChannel = selectEvent (ev, centralObjects);
48+ fillCutflow (CutStage::LeptonSelection, Channel::NONE, initialWeight, " Central" );
49+
50+ Channel selectedChannel = selectEvent (ev, centralObjects, " Central" );
4751
4852 if (selectedChannel != Channel::NONE) {
53+ fillCutflow (CutStage::Final, selectedChannel, initialWeight, " Central" );
4954 // Fill Central with nominal weights
5055 WeightInfo centralWeights = getWeights (selectedChannel, ev, centralObjects, genParts, " Central" );
5156 fillObjects (selectedChannel, centralObjects, centralWeights, " Central" );
@@ -62,7 +67,7 @@ void DiLepton::executeEvent() {
6267
6368 // Define objects with systematic variation
6469 RecoObjects recoObjects = defineObjects (ev, rawMuons, rawElectrons, rawJets, genJets, METv, systName);
65- Channel systChannel = selectEvent (ev, recoObjects);
70+ Channel systChannel = selectEvent (ev, recoObjects, systName );
6671
6772 if (systChannel != Channel::NONE) {
6873 WeightInfo weights = getWeights (systChannel, ev, recoObjects, genParts, systName);
@@ -73,9 +78,12 @@ void DiLepton::executeEvent() {
7378 } else {
7479 // Process only Central for DATA or when systematics are off
7580 RecoObjects recoObjects = defineObjects (ev, rawMuons, rawElectrons, rawJets, genJets, METv, " Central" );
76- Channel selectedChannel = selectEvent (ev, recoObjects);
81+ fillCutflow (CutStage::LeptonSelection, Channel::NONE, initialWeight, " Central" );
82+
83+ Channel selectedChannel = selectEvent (ev, recoObjects, " Central" );
7784
7885 if (selectedChannel != Channel::NONE) {
86+ fillCutflow (CutStage::Final, selectedChannel, initialWeight, " Central" );
7987 WeightInfo weights = getWeights (selectedChannel, ev, recoObjects, genParts, " Central" );
8088 fillObjects (selectedChannel, recoObjects, weights, " Central" );
8189 }
@@ -162,48 +170,62 @@ DiLepton::RecoObjects DiLepton::defineObjects(Event& ev,
162170 return objects;
163171}
164172
165- DiLepton::Channel DiLepton::selectEvent (Event& ev, const RecoObjects& recoObjects) {
173+ DiLepton::Channel DiLepton::selectEvent (Event& ev, const RecoObjects& recoObjects, const TString& syst ) {
166174 const RVec<Muon>& looseMuons = recoObjects.looseMuons ;
167175 const RVec<Muon>& tightMuons = recoObjects.tightMuons ;
168176 const RVec<Electron>& looseElectrons = recoObjects.looseElectrons ;
169177 const RVec<Electron>& tightElectrons = recoObjects.tightElectrons ;
170178 const RVec<Jet>& jets = recoObjects.tightJets_vetoLep ;
171179 const RVec<Jet>& bjets = recoObjects.bjets ;
172180
181+ float weight = IsDATA ? 1.0 : MCweight () * ev.GetTriggerLumi (" Full" );
173182 bool isDiMu = (tightMuons.size () == 2 && looseMuons.size () == 2 &&
174183 tightElectrons.size () == 0 && looseElectrons.size () == 0 );
175184 bool isEMu = (tightMuons.size () == 1 && looseMuons.size () == 1 &&
176185 tightElectrons.size () == 1 && looseElectrons.size () == 1 );
177186
178187 if (channel == Channel::DIMU) {
179188 if (!isDiMu) return Channel::NONE;
189+ fillCutflow (CutStage::LeptonSelection, Channel::DIMU, weight, syst);
180190 }
181191 if (channel == Channel::EMU) {
182192 if (!isEMu) return Channel::NONE;
193+ fillCutflow (CutStage::LeptonSelection, Channel::EMU, weight, syst);
183194 }
184195
185196 // DiMu selection
186197 if (channel == Channel::DIMU) {
187198 if (!ev.PassTrigger (DblMuTriggers)) return Channel::NONE;
199+ fillCutflow (CutStage::Trigger, Channel::DIMU, weight, syst);
200+
188201 const Muon& mu1 = tightMuons[0 ];
189202 const Muon& mu2 = tightMuons[1 ];
190203 if (mu1.Pt () <= 20 .) return Channel::NONE;
191204 if (mu2.Pt () <= 10 .) return Channel::NONE;
192205 if (mu1.Charge () + mu2.Charge () != 0 ) return Channel::NONE;
193206 Particle pair = mu1 + mu2;
194207 if (pair.M () <= 50 .) return Channel::NONE;
208+ fillCutflow (CutStage::KinematicCuts, Channel::DIMU, weight, syst);
195209 return Channel::DIMU;
196210 }
197211 // EMu selection
198212 else if (channel == Channel::EMU) {
199213 if (!ev.PassTrigger (EMuTriggers)) return Channel::NONE;
214+ fillCutflow (CutStage::Trigger, Channel::EMU, weight, syst);
215+
200216 const Muon& mu = tightMuons[0 ];
201217 const Electron& ele = tightElectrons[0 ];
202218 if (!((mu.Pt () > 20 . && ele.Pt () > 15 .) || (mu.Pt () > 10 . && ele.Pt () > 25 .))) return Channel::NONE;
203219 if (mu.Charge () + ele.Charge () != 0 ) return Channel::NONE;
204220 if (mu.DeltaR (ele) <= 0.4 ) return Channel::NONE;
221+ fillCutflow (CutStage::KinematicCuts, Channel::EMU, weight, syst);
222+
205223 if (jets.size () < 2 ) return Channel::NONE;
224+ fillCutflow (CutStage::JetRequirements, Channel::EMU, weight, syst);
225+
206226 if (bjets.size () < 1 ) return Channel::NONE;
227+ fillCutflow (CutStage::BjetRequirements, Channel::EMU, weight, syst);
228+
207229 return Channel::EMU;
208230 }
209231
@@ -458,3 +480,12 @@ void DiLepton::fillObjects(const DiLepton::Channel& channel, const RecoObjects&
458480 FillHist (Form (" %s/%s/pair/mass" , channelStr.Data (), syst.Data ()), pair.M (), weight, 300 , 0 ., 300 .);
459481 }
460482}
483+
484+ void DiLepton::fillCutflow (CutStage stage, const Channel& channel, float weight, const TString& syst) {
485+ if (syst != " Central" ) return ;
486+ TString channelStr = channelToString (channel);
487+ if (channelStr == " NONE" ) channelStr = " ALL" ;
488+
489+ int cutIndex = static_cast <int >(stage);
490+ FillHist (Form (" %s/%s/cutflow" , channelStr.Data (), syst.Data ()), cutIndex, weight, 9 , 0 ., 9 .);
491+ }
0 commit comments