Skip to content
Closed
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
8 changes: 8 additions & 0 deletions DPGAnalysis/HcalNanoAOD/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<use name="DataFormats/Common"/>
<use name="DataFormats/NanoAOD"/>
<use name="DataFormats/HcalDetId"/>
<use name="DQM/HcalCommon"/>
<use name="boost"/>
<export>
<lib name="1"/>
</export>
5 changes: 5 additions & 0 deletions DPGAnalysis/HcalNanoAOD/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### HcalNanoAOD

This package provides modules for saving HCAL raw data to NanoAOD. Specifically, modules are provided for HB/HE/HF/HO digis, RecHits, trigger primitives (TPs), HF pre-RecHits, and calibration metadata. Also see DPGAnalysis/CaloNanoAOD for modules related to HCAL+particle flow.

The digis are saved as a dense array (counting on compression to minimize the space consumed by 0s). The outputs are also sorted by DetId; the sorting is performed by the classes named *SortedTable.
31 changes: 31 additions & 0 deletions DPGAnalysis/HcalNanoAOD/interface/HFPreRecHitSortedTable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef HFPreRecHitSortedTable_h
#define HFPreRecHitSortedTable_h

#include <vector>
#include <map>

#include "CalibFormats/HcalObjects/interface/HcalCoderDb.h"
#include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
#include "CalibFormats/HcalObjects/interface/HcalDbService.h"
#include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
#include "DataFormats/HcalDetId/interface/HcalDetId.h"
#include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
#include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
#include "CondFormats/HcalObjects/interface/HcalElectronicsMap.h"
#include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"

class HFPreRecHitSortedTable {
public:
std::vector<HcalDetId> dids_;
std::map<HcalDetId, unsigned int> did_indexmap_; // Use std::map for efficient lookup, rather than std::find

std::vector<int> charges_;
std::vector<int> chargeAsymmetries_;
std::vector<bool> valids_;

HFPreRecHitSortedTable(const std::vector<HcalDetId>& dids);
void add(const HFPreRecHitCollection::const_iterator itPreRecHit);
void reset();
};
#endif
47 changes: 47 additions & 0 deletions DPGAnalysis/HcalNanoAOD/interface/HODigiSortedTable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#ifndef HODigiSortedTable_h
#define HODigiSortedTable_h

#include <vector>
#include <map>

#include "CalibFormats/HcalObjects/interface/HcalCoderDb.h"
#include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
#include "CalibFormats/HcalObjects/interface/HcalDbService.h"
#include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
#include "DataFormats/HcalDetId/interface/HcalDetId.h"
#include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
#include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
#include "CondFormats/HcalObjects/interface/HcalElectronicsMap.h"
#include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
#include "DQM/HcalCommon/interface/Utilities.h"

class HODigiSortedTable {
public:
std::vector<HcalDetId> dids_;
std::map<HcalDetId, unsigned int> did_indexmap_; // Use std::map for efficient lookup, rather than std::find

std::vector<int> ietas_;
std::vector<int> iphis_;
std::vector<int> subdets_;
std::vector<int> depths_;
std::vector<int> rawIds_;
std::vector<int> fiberIdleOffsets_;
std::vector<int> sois_;
std::vector<bool> valids_;

unsigned int nTS_;
std::vector<std::vector<int>> adcs_;
std::vector<std::vector<float>> fcs_;
std::vector<std::vector<float>> pedestalfcs_;
std::vector<std::vector<int>> capids_;
std::vector<std::vector<int>> fibers_;
std::vector<std::vector<int>> fiberChans_;
std::vector<std::vector<int>> dvs_;
std::vector<std::vector<int>> ers_;

HODigiSortedTable(const std::vector<HcalDetId>& dids, const unsigned int nTS);
void add(const HODataFrame* digi, const edm::ESHandle<HcalDbService>& dbService);
void reset();
};

#endif
49 changes: 49 additions & 0 deletions DPGAnalysis/HcalNanoAOD/interface/QIE10DigiSortedTable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifndef QIE10DigiSortedTable_h
#define QIE10DigiSortedTable_h

#include <vector>
#include <map>

#include "CalibFormats/HcalObjects/interface/HcalCoderDb.h"
#include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
#include "CalibFormats/HcalObjects/interface/HcalDbService.h"
#include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
#include "DataFormats/HcalDetId/interface/HcalDetId.h"
#include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
#include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
#include "CondFormats/HcalObjects/interface/HcalElectronicsMap.h"
#include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
#include "DQM/HcalCommon/interface/Utilities.h"

class QIE10DigiSortedTable {
public:
std::vector<HcalDetId> dids_;
std::map<HcalDetId, unsigned int> did_indexmap_; // Use std::map for efficient lookup, rather than std::find

std::vector<int> ietas_;
std::vector<int> iphis_;
std::vector<int> subdets_;
std::vector<int> depths_;
std::vector<int> rawIds_;
std::vector<bool> linkErrors_;
std::vector<int> flags_;
std::vector<int> sois_;
std::vector<bool> valids_;
//std::vector<uint8_t> sipmTypes_;

unsigned int nTS_;
std::vector<std::vector<int>> adcs_;
std::vector<std::vector<float>> fcs_;
std::vector<std::vector<float>> pedestalfcs_;
std::vector<std::vector<int>> tdcs_;
std::vector<std::vector<int>> capids_;
std::vector<std::vector<bool>> oks_;

QIE10DigiSortedTable(const std::vector<HcalDetId>& dids, const unsigned int nTS);
void add(const QIE10DataFrame* digi, const edm::ESHandle<HcalDbService>& dbService);
void reset();
};

typedef QIE10DigiSortedTable HFDigiSortedTable;

#endif
49 changes: 49 additions & 0 deletions DPGAnalysis/HcalNanoAOD/interface/QIE11DigiSortedTable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifndef QIE11DigiSortedTable_h
#define QIE11DigiSortedTable_h

#include <vector>
#include <map>

#include "CalibFormats/HcalObjects/interface/HcalCoderDb.h"
#include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
#include "CalibFormats/HcalObjects/interface/HcalDbService.h"
#include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
#include "DataFormats/HcalDetId/interface/HcalDetId.h"
#include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
#include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
#include "CondFormats/HcalObjects/interface/HcalElectronicsMap.h"
#include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
#include "DQM/HcalCommon/interface/Utilities.h"

class QIE11DigiSortedTable {
public:
std::vector<HcalDetId> dids_;
std::map<HcalDetId, unsigned int> did_indexmap_; // Use std::map for efficient lookup, rather than std::find

std::vector<int> ietas_;
std::vector<int> iphis_;
std::vector<int> subdets_;
std::vector<int> depths_;
std::vector<int> rawIds_;
std::vector<bool> linkErrors_;
std::vector<bool> capidErrors_;
std::vector<int> flags_;
std::vector<int> sois_;
std::vector<bool> valids_;
std::vector<uint8_t> sipmTypes_;

unsigned int nTS_;
std::vector<std::vector<int>> adcs_;
std::vector<std::vector<float>> fcs_;
std::vector<std::vector<float>> pedestalfcs_;
std::vector<std::vector<int>> tdcs_;
std::vector<std::vector<int>> capids_;

QIE11DigiSortedTable(const std::vector<HcalDetId>& dids, const unsigned int nTS);
void add(const QIE11DataFrame* digi, const edm::ESHandle<HcalDbService>& dbService);
void reset();
};

typedef QIE11DigiSortedTable HBDigiSortedTable;
typedef QIE11DigiSortedTable HEDigiSortedTable;
#endif
25 changes: 25 additions & 0 deletions DPGAnalysis/HcalNanoAOD/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<use name="FWCore/Framework"/>
<use name="FWCore/ParameterSet"/>
<use name="FWCore/ServiceRegistry"/>
<use name="FWCore/Utilities"/>
<use name="DataFormats/Candidate"/>
<use name="DataFormats/PatCandidates"/>
<use name="DataFormats/NanoAOD"/>
<use name="DataFormats/L1TGlobal"/>
<use name="DataFormats/CTPPSDetId"/>
<use name="DataFormats/CTPPSReco"/>
<use name="DataFormats/ProtonReco"/>
<use name="DataFormats/HcalDetId"/>
<use name="PhysicsTools/PatAlgos"/>
<use name="roothistmatrix"/>
<use name="IOPool/Provenance"/>
<use name="CondFormats/L1TObjects"/>
<use name="CondFormats/HcalObjects"/>
<use name="CondFormats/RunInfo"/>
<use name="CondFormats/DataRecord"/>
<use name="DQM/HcalCommon"/>
<use name="CalibFormats/CaloObjects"/>
<use name="DPGAnalysis/HcalNanoAOD"/>
<library file="*.cc" name="DPGAnalysisHcalNanoAOD_plugins">
<flags EDM_PLUGIN="1"/>
</library>
108 changes: 108 additions & 0 deletions DPGAnalysis/HcalNanoAOD/plugins/HcalDetIdTableProducer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#include <memory>

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Utilities/interface/ESInputTag.h"
#include "FWCore/Utilities/interface/Transition.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"

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

#include "CalibFormats/HcalObjects/interface/HcalCoderDb.h"
#include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
#include "CalibFormats/HcalObjects/interface/HcalDbService.h"
#include "CondFormats/HcalObjects/interface/HcalElectronicsMap.h"
#include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
#include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
#include "DataFormats/HcalDetId/interface/HcalDetId.h"
#include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
#include "DataFormats/NanoAOD/interface/FlatTable.h"

class HcalDetIdTableProducer : public edm::global::EDProducer<edm::BeginRunProducer> {
private:
edm::ESGetToken<HcalDbService, HcalDbRecord> tokenHcalDbService_;
edm::EDPutTokenT<std::vector<HcalDetId>> hbDetIdListToken_;
edm::EDPutTokenT<std::vector<HcalDetId>> heDetIdListToken_;
edm::EDPutTokenT<std::vector<HcalDetId>> hfDetIdListToken_;
edm::EDPutTokenT<std::vector<HcalDetId>> hoDetIdListToken_;

public:
explicit HcalDetIdTableProducer(const edm::ParameterSet& iConfig)
: tokenHcalDbService_(esConsumes<HcalDbService, HcalDbRecord, edm::Transition::BeginRun>()) {
hbDetIdListToken_ = produces<std::vector<HcalDetId>, edm::Transition::BeginRun>("HBDetIdList");
heDetIdListToken_ = produces<std::vector<HcalDetId>, edm::Transition::BeginRun>("HEDetIdList");
hfDetIdListToken_ = produces<std::vector<HcalDetId>, edm::Transition::BeginRun>("HFDetIdList");
hoDetIdListToken_ = produces<std::vector<HcalDetId>, edm::Transition::BeginRun>("HODetIdList");

produces<nanoaod::FlatTable, edm::Transition::BeginRun>("HBDetIdList");
produces<nanoaod::FlatTable, edm::Transition::BeginRun>("HEDetIdList");
produces<nanoaod::FlatTable, edm::Transition::BeginRun>("HFDetIdList");
produces<nanoaod::FlatTable, edm::Transition::BeginRun>("HODetIdList");
};

void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
void globalBeginRunProduce(edm::Run& iRun, edm::EventSetup const& iSetup) const override;
};

void HcalDetIdTableProducer::produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const {}

void HcalDetIdTableProducer::globalBeginRunProduce(edm::Run& iRun, edm::EventSetup const& iSetup) const {
// Setup products
const std::vector<HcalSubdetector> subdets = {HcalBarrel, HcalEndcap, HcalForward, HcalOuter};
std::map<HcalSubdetector, std::unique_ptr<std::vector<HcalDetId>>> didLists;
didLists[HcalBarrel] = std::make_unique<std::vector<HcalDetId>>();
didLists[HcalEndcap] = std::make_unique<std::vector<HcalDetId>>();
didLists[HcalForward] = std::make_unique<std::vector<HcalDetId>>();
didLists[HcalOuter] = std::make_unique<std::vector<HcalDetId>>();

// Load channels from emap
edm::ESHandle<HcalDbService> dbService = iSetup.getHandle(tokenHcalDbService_);
HcalElectronicsMap const* emap = dbService->getHcalMapping();

std::vector<HcalGenericDetId> alldids = emap->allPrecisionId();
for (auto it_did = alldids.begin(); it_did != alldids.end(); ++it_did) {
if (!it_did->isHcalDetId()) {
continue;
}
HcalDetId did = HcalDetId(it_did->rawId());
if (!(did.subdet() == HcalBarrel || did.subdet() == HcalEndcap || did.subdet() == HcalForward ||
did.subdet() == HcalOuter)) {
continue;
}

// TODO: Add filtering, for example on FED whitelist

didLists[did.subdet()]->push_back(did);
}

// Sort HcalDetIds
for (auto& it_subdet : subdets) {
std::sort(didLists[it_subdet]->begin(), didLists[it_subdet]->end());
}

// Make NanoAOD tables
std::map<HcalSubdetector, std::string> subdetNames = {
{HcalBarrel, "HB"}, {HcalEndcap, "HE"}, {HcalForward, "HF"}, {HcalOuter, "HO"}};

for (auto& it_subdet : subdets) {
auto didTable =
std::make_unique<nanoaod::FlatTable>(didLists[it_subdet]->size(), subdetNames[it_subdet], false, false);

std::vector<int> vdids;
for (auto& it_did : *(didLists[it_subdet])) {
vdids.push_back(it_did.rawId());
}
didTable->addColumn<int>("did", vdids, "HcalDetId");

iRun.put(std::move(didTable), subdetNames[it_subdet] + "DetIdList");
iRun.put(std::move(didLists[it_subdet]), subdetNames[it_subdet] + "DetIdList");
}
}

#include "FWCore/Framework/interface/MakerMacros.h"
//define this as a plug-in
DEFINE_FWK_MODULE(HcalDetIdTableProducer);
Loading