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

MTD validation update #27607

Merged
merged 3 commits into from Jul 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions SimGeneral/MixingModule/python/fullMixCustomize_cff.py
Expand Up @@ -60,5 +60,11 @@ def setCrossingFrameOn(process):
crossingFrames = process.mix.mixObjects.mixSH.crossingFrames + [ 'MuonME0Hits' ]
)
)
from Configuration.Eras.Modifier_phase2_timing_layer_bar_cff import phase2_timing_layer_bar
phase2_timing_layer_bar.toModify( process.mix.mixObjects,
mixSH = dict(
crossingFrames = process.mix.mixObjects.mixSH.crossingFrames + [ 'FastTimerHitsBarrel', 'FastTimerHitsEndcap' ]
)
)

return(process)
75 changes: 74 additions & 1 deletion Validation/MtdValidation/plugins/BtlRecHitsValidation.cc
Expand Up @@ -22,9 +22,14 @@
#include "DQMServices/Core/interface/DQMStore.h"

#include "DataFormats/Common/interface/ValidHandle.h"
#include "DataFormats/Math/interface/GeantUnits.h"
#include "DataFormats/ForwardDetId/interface/BTLDetId.h"
#include "DataFormats/FTLRecHit/interface/FTLRecHitCollections.h"

#include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
#include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
#include "SimDataFormats/TrackingHit/interface/PSimHit.h"

#include "Geometry/Records/interface/MTDDigiGeometryRecord.h"
#include "Geometry/Records/interface/MTDTopologyRcd.h"
#include "Geometry/MTDGeometryBuilder/interface/MTDGeometry.h"
Expand All @@ -33,6 +38,14 @@
#include "Geometry/MTDGeometryBuilder/interface/ProxyMTDTopology.h"
#include "Geometry/MTDGeometryBuilder/interface/RectangularMTDTopology.h"

struct MTDHit {
float energy;
float time;
float x_local;
float y_local;
float z_local;
};

class BtlRecHitsValidation : public DQMEDAnalyzer {
public:
explicit BtlRecHitsValidation(const edm::ParameterSet&);
Expand All @@ -48,8 +61,10 @@ class BtlRecHitsValidation : public DQMEDAnalyzer {
// ------------ member data ------------

const std::string folder_;
const float hitMinEnergy_;

edm::EDGetTokenT<FTLRecHitCollection> btlRecHitsToken_;
edm::EDGetTokenT<CrossingFrame<PSimHit> > btlSimHitsToken_;

// --- histograms declaration

Expand All @@ -73,19 +88,27 @@ class BtlRecHitsValidation : public DQMEDAnalyzer {
MonitorElement* meHitTvsPhi_;
MonitorElement* meHitTvsEta_;
MonitorElement* meHitTvsZ_;

MonitorElement* meTimeRes_;
MonitorElement* meEnergyRes_;
MonitorElement* meTresvsE_;
MonitorElement* meEresvsE_;
};

// ------------ constructor and destructor --------------
BtlRecHitsValidation::BtlRecHitsValidation(const edm::ParameterSet& iConfig)
: folder_(iConfig.getParameter<std::string>("folder")) {
: folder_(iConfig.getParameter<std::string>("folder")),
hitMinEnergy_(iConfig.getParameter<double>("hitMinimumEnergy")) {
btlRecHitsToken_ = consumes<FTLRecHitCollection>(iConfig.getParameter<edm::InputTag>("inputTag"));
btlSimHitsToken_ = consumes<CrossingFrame<PSimHit> >(iConfig.getParameter<edm::InputTag>("simHitsTag"));
}

BtlRecHitsValidation::~BtlRecHitsValidation() {}

// ------------ method called for each event ------------
void BtlRecHitsValidation::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
using namespace edm;
using namespace geant_units::operators;

edm::ESHandle<MTDGeometry> geometryHandle;
iSetup.get<MTDDigiGeometryRecord>().get(geometryHandle);
Expand All @@ -96,6 +119,34 @@ void BtlRecHitsValidation::analyze(const edm::Event& iEvent, const edm::EventSet
const MTDTopology* topology = topologyHandle.product();

auto btlRecHitsHandle = makeValid(iEvent.getHandle(btlRecHitsToken_));
auto btlSimHitsHandle = makeValid(iEvent.getHandle(btlSimHitsToken_));
MixCollection<PSimHit> btlSimHits(btlSimHitsHandle.product());

// --- Loop over the BLT SIM hits
std::unordered_map<uint32_t, MTDHit> m_btlSimHits;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@casarsa this energy accumulation is equivalent to that used in the digi - rechit construction, am I correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are. In both cases I'm starting from the SimHits and am accumulating the energy released in the same BTL crystal.

for (auto const& simHit : btlSimHits) {
// --- Use only hits compatible with the in-time bunch-crossing
if (simHit.tof() < 0 || simHit.tof() > 25.)
continue;

DetId id = simHit.detUnitId();

auto simHitIt = m_btlSimHits.emplace(id.rawId(), MTDHit()).first;

// --- Accumulate the energy (in MeV) of SIM hits in the same detector cell
(simHitIt->second).energy += convertUnitsTo(0.001_MeV, simHit.energyLoss());

// --- Get the time of the first SIM hit in the cell
if ((simHitIt->second).time == 0 || simHit.tof() < (simHitIt->second).time) {
(simHitIt->second).time = simHit.tof();

auto hit_pos = simHit.entryPoint();
(simHitIt->second).x_local = hit_pos.x();
(simHitIt->second).y_local = hit_pos.y();
(simHitIt->second).z_local = hit_pos.z();
}

} // simHit loop

// --- Loop over the BLT RECO hits

Expand Down Expand Up @@ -134,6 +185,18 @@ void BtlRecHitsValidation::analyze(const edm::Event& iEvent, const edm::EventSet
meHitTvsEta_->Fill(global_point.eta(), recHit.time());
meHitTvsZ_->Fill(global_point.z(), recHit.time());

// Resolution histograms
if (m_btlSimHits.count(detId.rawId()) == 1 && m_btlSimHits[detId.rawId()].energy > hitMinEnergy_) {
float time_res = recHit.time() - m_btlSimHits[detId.rawId()].time;
float energy_res = recHit.energy() - m_btlSimHits[detId.rawId()].energy;

meTimeRes_->Fill(time_res);
meEnergyRes_->Fill(energy_res);

meTresvsE_->Fill(m_btlSimHits[detId.rawId()].energy, time_res);
meEresvsE_->Fill(m_btlSimHits[detId.rawId()].energy, energy_res);
}

n_reco_btl++;

} // recHit loop
Expand Down Expand Up @@ -177,6 +240,14 @@ void BtlRecHitsValidation::bookHistograms(DQMStore::IBooker& ibook,
ibook.bookProfile("BtlHitTvsEta", "BTL RECO ToA vs #eta;#eta_{RECO};ToA_{RECO} [ns]", 50, -1.6, 1.6, 0., 100.);
meHitTvsZ_ =
ibook.bookProfile("BtlHitTvsZ", "BTL RECO ToA vs Z;Z_{RECO} [cm];ToA_{RECO} [ns]", 50, -260., 260., 0., 100.);

meTimeRes_ = ibook.book1D("BtlTimeRes", "BTL time resolution;T_{RECO} - T_{SIM} [ns]", 100, -0.5, 0.5);
meEnergyRes_ = ibook.book1D("BtlEnergyRes", "BTL energy resolution;E_{RECO} - E_{SIM} [MeV]", 100, -0.5, 0.5);

meTresvsE_ = ibook.bookProfile(
"BtlTresvsE", "BTL time resolution vs E;E_{SIM} [MeV];T_{RECO}-T_{SIM} [ns]", 50, 0., 20., 0., 100.);
meEresvsE_ = ibook.bookProfile(
"BtlEresvsE", "BTL energy resolution vs E;E_{SIM} [MeV];E_{RECO}-E_{SIM} [MeV]", 50, 0., 20., 0., 100.);
}

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
Expand All @@ -185,6 +256,8 @@ void BtlRecHitsValidation::fillDescriptions(edm::ConfigurationDescriptions& desc

desc.add<std::string>("folder", "MTD/BTL/RecHits");
desc.add<edm::InputTag>("inputTag", edm::InputTag("mtdRecHits", "FTLBarrel"));
desc.add<edm::InputTag>("simHitsTag", edm::InputTag("mix", "g4SimHitsFastTimerHitsBarrel"));
desc.add<double>("hitMinimumEnergy", 1.); // [MeV]

descriptions.add("btlRecHits", desc);
}
Expand Down
52 changes: 44 additions & 8 deletions Validation/MtdValidation/plugins/BtlSimHitsValidation.cc
Expand Up @@ -26,7 +26,9 @@
#include "DataFormats/Math/interface/GeantUnits.h"
#include "DataFormats/ForwardDetId/interface/BTLDetId.h"

#include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
#include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
#include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
#include "SimDataFormats/TrackingHit/interface/PSimHit.h"

#include "Geometry/Records/interface/MTDDigiGeometryRecord.h"
#include "Geometry/Records/interface/MTDTopologyRcd.h"
Expand Down Expand Up @@ -56,20 +58,27 @@ class BtlSimHitsValidation : public DQMEDAnalyzer {

void analyze(const edm::Event&, const edm::EventSetup&) override;

void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;

// ------------ member data ------------

const std::string folder_;
int eventCounter_;
TH1D* hEnergyFullRange_;

const std::string folder_;
const float hitMinEnergy_;

edm::EDGetTokenT<edm::PSimHitContainer> btlSimHitsToken_;
edm::EDGetTokenT<CrossingFrame<PSimHit> > btlSimHitsToken_;

// --- histograms declaration

MonitorElement* meNhits_;
MonitorElement* meNtrkPerCell_;

MonitorElement* meHitOccupancy_;

MonitorElement* meHitEnergy_;
MonitorElement* meHitLogEnergy_;
MonitorElement* meHitTime_;

MonitorElement* meHitXlocal_;
Expand All @@ -95,12 +104,14 @@ class BtlSimHitsValidation : public DQMEDAnalyzer {

// ------------ constructor and destructor --------------
BtlSimHitsValidation::BtlSimHitsValidation(const edm::ParameterSet& iConfig)
: folder_(iConfig.getParameter<std::string>("folder")),
: eventCounter_(0),
folder_(iConfig.getParameter<std::string>("folder")),
hitMinEnergy_(iConfig.getParameter<double>("hitMinimumEnergy")) {
btlSimHitsToken_ = consumes<edm::PSimHitContainer>(iConfig.getParameter<edm::InputTag>("inputTag"));
hEnergyFullRange_ = new TH1D("hEnergyFullRange", "", 1000, 0.01, 20.);
btlSimHitsToken_ = consumes<CrossingFrame<PSimHit> >(iConfig.getParameter<edm::InputTag>("inputTag"));
}

BtlSimHitsValidation::~BtlSimHitsValidation() {}
BtlSimHitsValidation::~BtlSimHitsValidation() { delete hEnergyFullRange_; }

// ------------ method called for each event ------------
void BtlSimHitsValidation::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
Expand All @@ -116,12 +127,13 @@ void BtlSimHitsValidation::analyze(const edm::Event& iEvent, const edm::EventSet
const MTDTopology* topology = topologyHandle.product();

auto btlSimHitsHandle = makeValid(iEvent.getHandle(btlSimHitsToken_));
MixCollection<PSimHit> btlSimHits(btlSimHitsHandle.product());

std::unordered_map<uint32_t, MTDHit> m_btlHits;
std::unordered_map<uint32_t, std::set<int> > m_btlTrkPerCell;

// --- Loop over the BLT SIM hits
for (auto const& simHit : *btlSimHitsHandle) {
for (auto const& simHit : btlSimHits) {
// --- Use only hits compatible with the in-time bunch-crossing
if (simHit.tof() < 0 || simHit.tof() > 25.)
continue;
Expand Down Expand Up @@ -157,6 +169,9 @@ void BtlSimHitsValidation::analyze(const edm::Event& iEvent, const edm::EventSet
meNtrkPerCell_->Fill((hit.second).size());

for (auto const& hit : m_btlHits) {
meHitLogEnergy_->Fill(log10((hit.second).energy));
hEnergyFullRange_->Fill((hit.second).energy);

if ((hit.second).energy < hitMinEnergy_)
continue;

Expand Down Expand Up @@ -201,8 +216,25 @@ void BtlSimHitsValidation::analyze(const edm::Event& iEvent, const edm::EventSet
meHitTvsZ_->Fill(global_point.z(), (hit.second).time);

} // hit loop

eventCounter_++;
}

// ------------ method called at run end -----------------
void BtlSimHitsValidation::endLuminosityBlock(edm::LuminosityBlock const& iLumBlock, edm::EventSetup const& iSetup) {
const float NBtlCrystals = BTLDetId::kCrystalsPerRODBarPhiFlat * BTLDetId::MAX_ROD;
const float scale = (eventCounter_ > 0 ? 1. / (eventCounter_ * NBtlCrystals) : 1.);

double bin_sum = hEnergyFullRange_->GetBinContent(hEnergyFullRange_->GetNbinsX() + 1);
for (int ibin = hEnergyFullRange_->GetNbinsX(); ibin > 0; --ibin) {
bin_sum += hEnergyFullRange_->GetBinContent(ibin);
meHitOccupancy_->setBinContent(ibin, scale * bin_sum);
}

eventCounter_ = 0;
hEnergyFullRange_->Reset();
};

// ------------ method for histogram booking ------------
void BtlSimHitsValidation::bookHistograms(DQMStore::IBooker& ibook,
edm::Run const& run,
Expand All @@ -214,7 +246,11 @@ void BtlSimHitsValidation::bookHistograms(DQMStore::IBooker& ibook,
meNhits_ = ibook.book1D("BtlNhits", "Number of BTL cells with SIM hits;N_{BTL cells}", 100, 0., 5000.);
meNtrkPerCell_ = ibook.book1D("BtlNtrkPerCell", "Number of tracks per BTL cell;N_{trk}", 10, 0., 10.);

meHitOccupancy_ = ibook.book1D(
"BtlHitOccupancy", "BTL cell occupancy vs hit energy;E_{SIM} [MeV]; Occupancy per event", 1000, 0.01, 20.);

meHitEnergy_ = ibook.book1D("BtlHitEnergy", "BTL SIM hits energy;E_{SIM} [MeV]", 100, 0., 20.);
meHitLogEnergy_ = ibook.book1D("BtlHitLogEnergy", "BTL SIM hits energy;log_{10}(E_{SIM} [MeV])", 100, -6., 3.);
meHitTime_ = ibook.book1D("BtlHitTime", "BTL SIM hits ToA;ToA_{SIM} [ns]", 100, 0., 25.);

meHitXlocal_ = ibook.book1D("BtlHitXlocal", "BTL SIM local X;X_{SIM}^{LOC} [mm]", 100, -30., 30.);
Expand Down Expand Up @@ -251,7 +287,7 @@ void BtlSimHitsValidation::fillDescriptions(edm::ConfigurationDescriptions& desc
edm::ParameterSetDescription desc;

desc.add<std::string>("folder", "MTD/BTL/SimHits");
desc.add<edm::InputTag>("inputTag", edm::InputTag("g4SimHits", "FastTimerHitsBarrel"));
desc.add<edm::InputTag>("inputTag", edm::InputTag("mix", "g4SimHitsFastTimerHitsBarrel"));
desc.add<double>("hitMinimumEnergy", 1.); // [MeV]

descriptions.add("btlSimHits", desc);
Expand Down
1 change: 1 addition & 0 deletions Validation/MtdValidation/plugins/BuildFile.xml
Expand Up @@ -4,4 +4,5 @@
<use name="Geometry/Records"/>
<use name="Geometry/MTDGeometryBuilder"/>
<use name="DQMServices/Core"/>
<use name="hepmc"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@casarsa why this dependence?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That surprised me too. It seems it's required by SimDataFormats/CrossingFrame/interface/CrossingFrame.h, that includes HepMCProduct.h.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By quick look it looks like the include of HepMCProduct.h could easily be removed from SimDataFormats/CrossingFrame/interface/CrossingFrame.h.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regardless of the possible cleanup of SimDataFormats/CrossingFrame/interface/CrossingFrame.h, the proper dependence to be added here is SimDataFormats/CrossingFrame. That should make the explicit dependence in hepmc uneecessary (as SimDataFormats/CrossingFrame depends on that).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@makortel let's open a separate issue for that

<flags EDM_PLUGIN="1"/>
14 changes: 8 additions & 6 deletions Validation/MtdValidation/plugins/EtlSimHitsValidation.cc
Expand Up @@ -25,7 +25,9 @@
#include "DataFormats/Math/interface/GeantUnits.h"
#include "DataFormats/ForwardDetId/interface/ETLDetId.h"

#include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
#include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
#include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
#include "SimDataFormats/TrackingHit/interface/PSimHit.h"

#include "Geometry/Records/interface/MTDDigiGeometryRecord.h"
#include "Geometry/MTDGeometryBuilder/interface/MTDGeometry.h"
Expand Down Expand Up @@ -53,10 +55,9 @@ class EtlSimHitsValidation : public DQMEDAnalyzer {
// ------------ member data ------------

const std::string folder_;

const float hitMinEnergy_;

edm::EDGetTokenT<edm::PSimHitContainer> etlSimHitsToken_;
edm::EDGetTokenT<CrossingFrame<PSimHit> > etlSimHitsToken_;

// --- histograms declaration

Expand Down Expand Up @@ -89,7 +90,7 @@ class EtlSimHitsValidation : public DQMEDAnalyzer {
EtlSimHitsValidation::EtlSimHitsValidation(const edm::ParameterSet& iConfig)
: folder_(iConfig.getParameter<std::string>("folder")),
hitMinEnergy_(iConfig.getParameter<double>("hitMinimumEnergy")) {
etlSimHitsToken_ = consumes<edm::PSimHitContainer>(iConfig.getParameter<edm::InputTag>("inputTag"));
etlSimHitsToken_ = consumes<CrossingFrame<PSimHit> >(iConfig.getParameter<edm::InputTag>("inputTag"));
}

EtlSimHitsValidation::~EtlSimHitsValidation() {}
Expand All @@ -104,12 +105,13 @@ void EtlSimHitsValidation::analyze(const edm::Event& iEvent, const edm::EventSet
const MTDGeometry* geom = geometryHandle.product();

auto etlSimHitsHandle = makeValid(iEvent.getHandle(etlSimHitsToken_));
MixCollection<PSimHit> etlSimHits(etlSimHitsHandle.product());

std::unordered_map<uint32_t, MTDHit> m_etlHits[2];
std::unordered_map<uint32_t, std::set<int> > m_etlTrkPerCell[2];

// --- Loop over the BLT SIM hits
for (auto const& simHit : *etlSimHitsHandle) {
for (auto const& simHit : etlSimHits) {
// --- Use only hits compatible with the in-time bunch-crossing
if (simHit.tof() < 0 || simHit.tof() > 25.)
continue;
Expand Down Expand Up @@ -261,7 +263,7 @@ void EtlSimHitsValidation::fillDescriptions(edm::ConfigurationDescriptions& desc
edm::ParameterSetDescription desc;

desc.add<std::string>("folder", "MTD/ETL/SimHits");
desc.add<edm::InputTag>("inputTag", edm::InputTag("g4SimHits", "FastTimerHitsEndcap"));
desc.add<edm::InputTag>("inputTag", edm::InputTag("mix", "g4SimHitsFastTimerHitsEndcap"));
desc.add<double>("hitMinimumEnergy", 0.1); // [MeV]

descriptions.add("etlSimHits", desc);
Expand Down