Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to new PFCluster format and add decoded calo info #77

Open
wants to merge 1 commit into
base: 14_2_X
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions NtupleProducer/plugins/L1HGC3DclTableProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,15 @@ L1HGC3DclTableProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetu
for (unsigned int i = 0; i < ncands; ++i) {
auto cl3d = *selected[i];

l1t::PFCluster cluster;
bool passEmVsPU = false;
bool passPFEmVsPion = false;
if (!emVsPUID_.method().empty()) {
passEmVsPU = emVsPUID_.passID(cl3d, cluster);
passEmVsPU = emVsPUID_.passID(cl3d, vals_puid[i]);
}
if (!emVsPionID_.method().empty()) {
passPFEmVsPion = emVsPionID_.passID(cl3d, cluster);
passPFEmVsPion = emVsPionID_.passID(cl3d, vals_pfemid[i]);
}

vals_puid[i] = cluster.egVsPUMVAOut();
vals_pfemid[i] = cluster.egVsPionMVAOut();
vals_egemid[i] = id_->value(cl3d);
pass_puid[i] = passEmVsPU;
pass_pfemid[i] = passPFEmVsPion;
Expand Down
135 changes: 135 additions & 0 deletions NtupleProducer/plugins/L1PFDecodedCaloTableProducer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/global/EDProducer.h"

#include "FWCore/Framework/interface/Event.h"
#include "DataFormats/Common/interface/Handle.h"

#include "DataFormats/L1TParticleFlow/interface/PFCluster.h"
#include "DataFormats/L1TCalorimeterPhase2/interface/CaloCrystalCluster.h"


#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"

#include "DataFormats/NanoAOD/interface/FlatTable.h"

#include "CommonTools/Utils/interface/StringCutObjectSelector.h"
#include "CommonTools/Utils/interface/StringObjectFunction.h"


#include <algorithm>

class L1PFDecodedCaloTableProducer : public edm::global::EDProducer<> {
public:
explicit L1PFDecodedCaloTableProducer(const edm::ParameterSet&);
~L1PFDecodedCaloTableProducer();

private:
virtual void produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;


std::string name_;
edm::EDGetTokenT<l1t::PFClusterCollection> clusters_;
StringCutObjectSelector<l1t::PFCluster> sel_;

};

L1PFDecodedCaloTableProducer::L1PFDecodedCaloTableProducer(const edm::ParameterSet& iConfig) :
name_(iConfig.getParameter<std::string>("name")),
clusters_(consumes<l1t::PFClusterCollection>(iConfig.getParameter<edm::InputTag>("src"))),
sel_(iConfig.getParameter<std::string>("cut"), true)
{
produces<nanoaod::FlatTable>();

}

L1PFDecodedCaloTableProducer::~L1PFDecodedCaloTableProducer() { }

// ------------ method called for each event ------------
void
L1PFDecodedCaloTableProducer::produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const
{
edm::Handle<l1t::PFClusterCollection> clusters;
iEvent.getByToken(clusters_, clusters);

std::vector<const l1t::PFCluster *> selected;


for (const l1t::PFCluster &cl : *clusters)
if(sel_(cl)) selected.push_back(&cl);


// create the table
unsigned int ncands = selected.size();
auto out = std::make_unique<nanoaod::FlatTable>(ncands, name_, false, true);

std::vector<float> vals_empt, vals_srrTot, vals_hwSrrTot, vals_meanz, vals_hwMeanZ, vals_hoe, vals_piIdProb, vals_PuIdProb, vals_EmIdProb, vals_caloIso, vals_showerShape;
vals_empt.resize(ncands);
vals_srrTot.resize(ncands);
vals_hwSrrTot.resize(ncands);
vals_meanz.resize(ncands);
vals_hwMeanZ.resize(ncands);
vals_hoe.resize(ncands);
vals_piIdProb.resize(ncands);
vals_PuIdProb.resize(ncands);
vals_EmIdProb.resize(ncands);
vals_caloIso.resize(ncands);
vals_showerShape.resize(ncands);

for (unsigned int i = 0; i < ncands; ++i) {
const auto cand = selected[i];
auto obj = cand->caloDigiObj();

if(auto digi = std::get_if<l1ct::EmCaloObj>(&obj)){
vals_srrTot[i] = digi->floatSrrTot();
vals_hwSrrTot[i] = digi->hwSrrTot.to_float();
vals_meanz[i] = digi->floatMeanZ();
vals_hwMeanZ[i] = digi->hwMeanZ.to_float();
vals_hoe[i] = digi->floatHoe();
vals_piIdProb[i] = digi->floatPiProb();
vals_PuIdProb[i] = digi->floatPuProb();
vals_EmIdProb[i] = digi->floatEmProb();

const l1tp2::CaloCrystalCluster *crycl = dynamic_cast<const l1tp2::CaloCrystalCluster *>(cand->constituentsAndFractions().front().first.get());
if(crycl) {
vals_caloIso[i] = crycl->isolation();
vals_showerShape[i] = crycl->e2x5() / crycl->e5x5();
}
} else if(auto digi = std::get_if<l1ct::HadCaloObj>(&obj)){
vals_empt[i] = digi->floatEmPt();

vals_srrTot[i] = digi->floatSrrTot();
vals_hwSrrTot[i] = digi->hwSrrTot.to_float();
vals_meanz[i] = digi->floatMeanZ();
vals_hwMeanZ[i] = digi->hwMeanZ.to_float();
vals_hoe[i] = digi->floatHoe();
vals_piIdProb[i] = digi->floatPiProb();
vals_PuIdProb[i] = digi->floatPuProb();
vals_EmIdProb[i] = digi->floatEmProb();

}
}


out->addColumn<float>("empt", vals_empt, "");
out->addColumn<float>("srrTot", vals_srrTot, "");
out->addColumn<float>("hwSrrTot", vals_hwSrrTot, "");
out->addColumn<float>("meanz", vals_meanz, "");
out->addColumn<float>("hwMeanZ", vals_hwMeanZ, "");
out->addColumn<float>("hoe", vals_hoe, "");
out->addColumn<float>("piIdProb", vals_piIdProb, "");
out->addColumn<float>("PuIdProb", vals_PuIdProb, "");
out->addColumn<float>("EmIdProb", vals_EmIdProb, "");
out->addColumn<float>("caloIso", vals_caloIso, "");
out->addColumn<float>("showerShape", vals_showerShape, "");

// save to the event branches
iEvent.put(std::move(out));


}

//define this as a plug-in
#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(L1PFDecodedCaloTableProducer);
6 changes: 4 additions & 2 deletions NtupleProducer/python/runInputs140X.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring(
# 'file:/data/cerminar/Phase2Spring23DIGIRECOMiniAOD/DoubleElectron_FlatPt-1To100-gun/GEN-SIM-DIGI-RAW-MINIAOD/PU200_Trk1GeV_131X_mcRun4_realistic_v5-v1/c699a773-9875-40c9-83b7-5a3c27f90bfd.root',
'/store/mc/Phase2Spring24DIGIRECOMiniAOD/TTToSemileptonic_TuneCP5_14TeV-powheg-pythia8/GEN-SIM-DIGI-RAW-MINIAOD/PU200_Trk1GeV_140X_mcRun4_realistic_v4-v2/2820000/5b6178a7-19bf-4f7f-af63-5bab03393e54.root',
# '/store/mc/Phase2Spring24DIGIRECOMiniAOD/TTToSemileptonic_TuneCP5_14TeV-powheg-pythia8/GEN-SIM-DIGI-RAW-MINIAOD/PU200_Trk1GeV_140X_mcRun4_realistic_v4-v2/2820000/5b6178a7-19bf-4f7f-af63-5bab03393e54.root',
# '/store/mc/Phase2Spring23DIGIRECOMiniAOD/MinBias_TuneCP5_14TeV-pythia8/GEN-SIM-DIGI-RAW-MINIAOD/PU200_Trk1GeV_131X_mcRun4_realistic_v5-v1/30002/3b44d52d-1807-4a4f-9b9b-19466303a741.root',
'/store/mc/Phase2Spring24DIGIRECOMiniAOD/SingleElectron_Pt-2To200-gun/GEN-SIM-DIGI-RAW-MINIAOD/PU200_Trk1GeV_140X_mcRun4_realistic_v4-v1/2560000/c598c5a7-d4d8-489d-bbc7-43fe9aa6b350.root'
),

inputCommands = cms.untracked.vstring(
Expand All @@ -35,7 +36,8 @@
# 'drop l1tPFTaus_*_*_*',
# 'drop l1tTrackerMuons_*_*_*',
'drop *_hlt*_*_HLT',
'drop triggerTriggerFilterObjectWithRefs_*_*_HLT'
'drop triggerTriggerFilterObjectWithRefs_*_*_HLT',
'drop *_l1tLayer*_*_HLT',
),
)
process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(20))
Expand Down
30 changes: 30 additions & 0 deletions NtupleProducer/python/runPerformanceNTuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,36 @@ def getCrystalClustersTable(nameSrcDict : dict[str, str]) -> cms.EDProducer:
setattr(process, f"{nameSrcDict['name']}Table", flatTable)
process.extraPFStuff.add(flatTable)

def addDecodedCalo(types=['Had', 'Em'], regs=['HGCal','Barrel']):
for tp in types:
for reg in regs:
decCaloTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
name = cms.string(f"Dec{tp}Calo{reg}"),
src = cms.InputTag("l1tLayer1"+reg, f'Decoded{tp}Clusters'),
cut = cms.string(""),
doc = cms.string(""),
singleton = cms.bool(False), # the number of entries is variable
extension = cms.bool(False), # this is the main table
variables = cms.PSet(
pt = Var("pt", float,precision=8),
phi = Var("phi", float,precision=8),
eta = Var("eta", float,precision=8),
hwQual = LazyVar("hwQual", int, doc="id"),
hwEta = LazyVar("hwEta", int, doc="hwEta"),
hwPhi = LazyVar("hwPhi", int, doc="hwPhi"),
)
)

decCaloTableExt = cms.EDProducer("L1PFDecodedCaloTableProducer",
src = cms.InputTag("l1tLayer1"+reg, f'Decoded{tp}Clusters'),
name = cms.string(""),
cut = cms.string(""),)

setattr(process, f"dec{tp}Calo{reg}Table", decCaloTable)
setattr(process, f"dec{tp}Calo{reg}ExtTable", decCaloTableExt)
decCaloTableExt.name = decCaloTable.name
process.extraPFStuff.add(decCaloTable, decCaloTableExt)


def addAllLeps():
addGenLep()
Expand Down