Skip to content

Commit

Permalink
Add first version of muon DPG ntuples to be run on ZMu skim
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlo Battilana committed Jun 3, 2022
1 parent a54d721 commit 9512dd1
Show file tree
Hide file tree
Showing 33 changed files with 3,870 additions and 0 deletions.
32 changes: 32 additions & 0 deletions DPGAnalysis/MuonTools/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<use name="FWCore/Framework"/>
<use name="FWCore/PluginManager"/>
<use name="FWCore/ServiceRegistry"/>
<use name="FWCore/ParameterSet"/>
<use name="CommonTools/Utils"/>
<use name="CommonTools/UtilAlgos"/>
<use name="DataFormats/NanoAOD"/>
<use name="CalibMuon/DTDigiSync"/>
<use name="Geometry/Records"/>
<use name="TrackingTools/GeomPropagators"/>
<use name="DataFormats/Common"/>
<use name="DataFormats/DTDigi"/>
<use name="DataFormats/DTRecHit"/>
<use name="DataFormats/L1DTTrackFinder"/>
<use name="Geometry/GEMGeometry"/>
<use name="Geometry/RPCGeometry"/>
<use name="DataFormats/GEMDigi"/>
<use name="DataFormats/GEMRecHit"/>
<use name="DataFormats/CSCRecHit"/>
<use name="DataFormats/CSCDigi"/>
<use name="HLTrigger/HLTcore"/>
<use name="DataFormats/MuonReco"/>
<use name="TrackingTools/TransientTrack"/>
<use name="TrackingTools/Records"/>
<use name="RecoMuon/TrackingTools"/>
<use name="DataFormats/RPCDigi"/>
<use name="DataFormats/RPCRecHit"/>

<export>
<lib name="1"/>
</export>

18 changes: 18 additions & 0 deletions DPGAnalysis/MuonTools/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<use name="FWCore/Framework"/>
<use name="FWCore/PluginManager"/>
<use name="FWCore/ParameterSet"/>
<use name="Geometry/Records"/>
<use name="Geometry/RPCGeometry"/>
<use name="CommonTools/Utils"/>
<use name="CommonTools/UtilAlgos"/>


<library name="DPGAnalysisMuonToolsPlugin" file="*.cc">
<use name="DPGAnalysis/MuonTools"/>
<use name="root"/>
<use name="rootminuit"/>
<use name="clhep"/>
<use name="rootrflx"/>
<use name="rootmath"/>
<flags EDM_PLUGIN="1"/>
</library>
175 changes: 175 additions & 0 deletions DPGAnalysis/MuonTools/plugins/MuNtupleBmtfFiller.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/** \class MuNtupleBmtfFiller MuNtupleBmtfFiller.cc DPGAnalysis/MuonTools/plugins/MuNtupleBmtfFiller.cc
*
* Helper class : the BMTF filler
*
* \author L. Borgonovi (INFN BO)
*
*
*/

#include "DPGAnalysis/MuonTools/plugins/MuNtupleBmtfFiller.h"

#include <vector>

MuNtupleBmtfFiller::MuNtupleBmtfFiller(const edm::ParameterSet& config)
: MuNtupleBaseFiller(config),
m_tpgPhiToken{config, consumesCollector(), "dtTpTag"},
m_bmtfToken{config, consumesCollector(), "bmtfTag"} {
produces<nanoaod::FlatTable>();
}

void MuNtupleBmtfFiller::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;

desc.add<std::string>("label", "l1tBmtfOut");
desc.add<edm::InputTag>("dtTpTag", edm::InputTag{"bmtfDigis"});
desc.add<edm::InputTag>("bmtfTag", edm::InputTag{"bmtfDigis"});

descriptions.addWithDefaultLabel(desc);
}

void MuNtupleBmtfFiller::fill(edm::Event& ev) {
unsigned int nBmtfCands{0};

std::vector<int8_t> wheel;
std::vector<int8_t> sector;

std::vector<float> pt;
std::vector<float> phi;
std::vector<float> eta;
std::vector<int8_t> bx;
std::vector<int> dxy;
std::vector<int8_t> qual;
std::vector<int8_t> etaFine;

std::vector<uint8_t> matchedTpIdxMB1;
std::vector<uint8_t> matchedTpIdxMB2;
std::vector<uint8_t> matchedTpIdxMB3;
std::vector<uint8_t> matchedTpIdxMB4;

auto bmtfColl = m_bmtfToken.conditionalGet(ev);
auto tpColl = m_tpgPhiToken.conditionalGet(ev);

if (bmtfColl.isValid()) {
auto bmtfCandBX = bmtfColl->getFirstBX();
auto bmtfCandLastBX = bmtfColl->getLastBX();

for (; bmtfCandBX <= bmtfCandLastBX; ++bmtfCandBX) {
auto bmtfCand = bmtfColl->begin(bmtfCandBX);
auto bmtfCandLast = bmtfColl->end(bmtfCandBX);

for (; bmtfCand != bmtfCandLast; ++bmtfCand) {
std::map<int, int> mapTA = bmtfCand->trackAddress();

int wsign = mapTA[0] == 0 ? 1 : -1;
int wh = wsign * mapTA[1];
int sec = bmtfCand->processor();

wheel.push_back(wh);
sector.push_back(sec);

std::array<int, 4> ts_mb{{DEFAULT_INT_VAL, DEFAULT_INT_VAL, DEFAULT_INT_VAL, DEFAULT_INT_VAL}};
std::array<int, 4> w_mb{{DEFAULT_INT_VAL, DEFAULT_INT_VAL, DEFAULT_INT_VAL, DEFAULT_INT_VAL}};
std::array<int, 4> s_mb{{DEFAULT_INT_VAL, DEFAULT_INT_VAL, DEFAULT_INT_VAL, DEFAULT_INT_VAL}};

std::array<uint8_t, 4> triggerIndex{{0, 0, 0, 0}};

if (mapTA[2] != 3) {
w_mb[0] = wh;
s_mb[0] = sec;
ts_mb[0] = (mapTA[2] & 1) ? 1 : 0;
}

for (int iSt = 1; iSt <= N_STAT; ++iSt) {
if (mapTA[iSt + 2] != 15) {
ts_mb[iSt] = (mapTA[iSt + 2] & 1) ? 1 : 0; // 0 for ts1 , 1 for ts2
w_mb[iSt] =
(mapTA[iSt + 2] & 8)
? wh
: wh +
wsign; // own wheel if true, nex wheel if false (depends on sign of the wheel -> case 0+, +1: +1, case 0-, -1: -1)
int tmpMapValue = mapTA[iSt + 2] >> 1; // temp value to remove less significant bit
if (tmpMapValue & 1)
s_mb[iSt] =
sec != 0 ? sec - 1 : 11; // if last two remained bit == 01 -> sector-1 (N+1 column of ref table)
else if (tmpMapValue & 2)
s_mb[iSt] =
sec != 11 ? sec + 1 : 0; // if last two remained bit == 10 -> sector+1 (N-1 column of ref table)
else
s_mb[iSt] = sec; // if last two remained bit == 00 -> sector (N column of ref table)
}
}

int tmpIdx = 0;

for (int iSt = 0; iSt < N_STAT; ++iSt) {
int iTP = 0;

if (tpColl.isValid()) {
const auto trigs = tpColl->getContainer();

for (const auto& trig : (*trigs)) {
if (trig.code() != 7) {
if (bmtfCandBX == trig.bxNum()) {
if ((w_mb[iSt] == trig.whNum()) && (ts_mb[iSt] == trig.Ts2Tag()) && (s_mb[iSt] == trig.scNum()) &&
(iSt + 1 == trig.stNum())) {
triggerIndex[tmpIdx] = iTP;
tmpIdx++;
}
}
}

iTP++;
}
}
}

int iPhi = bmtfCand->hwPhi() + bmtfCand->processor() * 48 - 15;
if (iPhi < 0)
iPhi += 576;

bx.push_back(bmtfCandBX);
pt.push_back((bmtfCand->hwPt()) * PT_SCALE);
phi.push_back(iPhi * PHI_SCALE); //no conversion yet
eta.push_back((bmtfCand->hwEta()) * ETA_SCALE);
dxy.push_back(bmtfCand->hwDXY());
qual.push_back(bmtfCand->hwQual());
etaFine.push_back(bmtfCand->hwHF());

matchedTpIdxMB1.push_back(triggerIndex[0]);
matchedTpIdxMB2.push_back(triggerIndex[1]);
matchedTpIdxMB3.push_back(triggerIndex[2]);
matchedTpIdxMB4.push_back(triggerIndex[3]);

++nBmtfCands;
}
}
}

auto table = std::make_unique<nanoaod::FlatTable>(nBmtfCands, m_label, false, false);

table->setDoc("BMTF information");

addColumn(table, "pt", pt, "BMTF cand pt - GeV/c ");
addColumn(table, "phi", phi, "BMTF cand phi - rad");
addColumn(table, "eta", eta, "BMTF cand eta");

addColumn(table, "wheel", pt, "BMTF cand wheel");
addColumn(table, "sector ", pt, "BMTF cand sector");

addColumn(table, "dxy", dxy, "BMTF cand dxy - units?");
addColumn(table, "qual", qual, "BMTF cand quality");
addColumn(table, "etaFine", etaFine, "BMTF cand fine eta bit");

addColumn(table, "matchedTpIdxMB1", matchedTpIdxMB1, "BMTF link to TP index (MB1)");
addColumn(table, "matchedTpIdxMB2", matchedTpIdxMB2, "BMTF link to TP index (MB2)");
addColumn(table, "matchedTpIdxMB3", matchedTpIdxMB3, "BMTF link to TP index (MB3)");
addColumn(table, "matchedTpIdxMB4", matchedTpIdxMB4, "BMTF link to TP index (MB4)");

ev.put(std::move(table));
}

#include "FWCore/PluginManager/interface/ModuleDef.h"
#include "FWCore/Framework/interface/MakerMacros.h"

DEFINE_FWK_MODULE(MuNtupleBmtfFiller);
51 changes: 51 additions & 0 deletions DPGAnalysis/MuonTools/plugins/MuNtupleBmtfFiller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef MuNtuple_MuNtupleBmtfFiller_h
#define MuNtuple_MuNtupleBmtfFiller_h

/** \class MuNtupleBmtfFiller MuNtupleBmtfFiller.h DPGAnalysis/MuonTools/plugins/MuNtupleBmtfFiller.h
*
* Helper class : the BMTF filler
*
* \author L. Borgonovi (INFN BO)
*
*
*/

#include "DPGAnalysis/MuonTools/src/MuNtupleBaseFiller.h"

#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"

#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhContainer.h"
#include "DataFormats/L1TMuon/interface/RegionalMuonCand.h"

class MuNtupleBmtfFiller : public MuNtupleBaseFiller {
public:
/// Constructor
MuNtupleBmtfFiller(const edm::ParameterSet &);

/// Fill descriptors
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);

protected:
/// Fill tree branches for a given events
void fill(edm::Event &ev) final;

private:
/// Scale to convert HW pt to GeV
static constexpr double PT_SCALE = 0.5;

/// Scale to convert HW eta to phisical value
static constexpr double ETA_SCALE = 0.010875;

/// Scale to convert HW eta to rad
static constexpr double PHI_SCALE = 0.010908308; // 2 * pi / 576

/// Number of DT stations
static constexpr int N_STAT = 4;

/// The trigger tokens
nano_mu::EDTokenHandle<L1MuDTChambPhContainer> m_tpgPhiToken;
nano_mu::EDTokenHandle<l1t::RegionalMuonCandBxCollection> m_bmtfToken;
};

#endif
98 changes: 98 additions & 0 deletions DPGAnalysis/MuonTools/plugins/MuNtupleDTDigiFiller.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/** \class MuNtupleDigiFiller MuNtupleDigiFiller.cc DPGAnalysis/MuonTools/src/MuNtupleDTDigiFiller.cc
*
* Helper class : the digi filler for Phase-1 / Phase2 DT digis (the DataFormat is the same)
*
* \author C. Battilana (INFN BO)
*
*
*/

#include "DPGAnalysis/MuonTools/plugins/MuNtupleDTDigiFiller.h"

#include <vector>

MuNtupleDTDigiFiller::MuNtupleDTDigiFiller(const edm::ParameterSet& config)
: MuNtupleBaseFiller{config}, m_token{config, consumesCollector(), "dtDigiTag"} {
produces<nanoaod::FlatTable>();
}

void MuNtupleDTDigiFiller::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;

desc.add<std::string>("label", "dtDigis");
desc.add<edm::InputTag>("dtDigiTag", edm::InputTag{"muonDTDigis"});

descriptions.addWithDefaultLabel(desc);
}

void MuNtupleDTDigiFiller::fill(edm::Event& ev) {
unsigned int nDigis{0};

std::vector<int8_t> wheel;
std::vector<int8_t> sector;
std::vector<int8_t> station;

std::vector<int8_t> superLayer;
std::vector<int8_t> layer;
std::vector<int8_t> wire;

std::vector<float> time;

auto dtDigis = m_token.conditionalGet(ev);

if (dtDigis.isValid()) {
auto dtLayerIdIt = dtDigis->begin();
auto dtLayerIdEnd = dtDigis->end();

for (; dtLayerIdIt != dtLayerIdEnd; ++dtLayerIdIt) {
const auto& [dtLayerId, range] = (*dtLayerIdIt);

for (auto digiIt = range.first; digiIt != range.second; ++digiIt) {
wheel.push_back(dtLayerId.wheel());
sector.push_back(dtLayerId.sector());
station.push_back(dtLayerId.station());

superLayer.push_back(dtLayerId.superLayer());
layer.push_back(dtLayerId.layer());
wire.push_back(digiIt->wire());

time.push_back(digiIt->time());

++nDigis;
}
}
}

auto table = std::make_unique<nanoaod::FlatTable>(nDigis, m_label, false, false);

table->setDoc("DT digi information");

addColumn(table, "wheel", wheel, "wheel - [-2:2] range");
addColumn(table,
"sector",
sector,
"sector - [1:14] range"
"<br />sector 13 used for the second MB4 of sector 4"
"<br />sector 14 used for the second MB4 of sector 10");
addColumn(table, "station", station, "station - [1:4] range");
addColumn(table,
"superLayer",
superLayer,
"superlayer - [1:3] range"
"<br />SL 1 and 3 are phi SLs"
"<br />SL 2 is theta SL");
addColumn(table, "layer", layer, "station - [1:4] range");
addColumn(table,
"wire",
wire,
"wire - [1:X] range"
"<br />X varies for different chambers SLs and layers");
addColumn(table, "time", time, "digi time in ns (no pedestal subtraction)");

ev.put(std::move(table));
}

#include "FWCore/PluginManager/interface/ModuleDef.h"
#include "FWCore/Framework/interface/MakerMacros.h"

DEFINE_FWK_MODULE(MuNtupleDTDigiFiller);
Loading

0 comments on commit 9512dd1

Please sign in to comment.