Skip to content

Commit

Permalink
Enable phase2 tracker in phase2 premixing
Browse files Browse the repository at this point in the history
  • Loading branch information
makortel committed May 10, 2018
1 parent fcbee47 commit 2e317ef
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
maxNumberClusters = cms.uint32(0)
)


from Configuration.ProcessModifiers.premix_stage2_cff import premix_stage2
premix_stage2.toModify(siPhase2Clusters, src = "mixData:Tracker")

Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@
MissCalibrate = False,
ElectronPerADCGain = cms.double(600.) # it can be changed to something else (e.g. 135e) if needed
)
from Configuration.ProcessModifiers.premix_stage2_cff import premix_stage2
(premix_stage2 & phase2_tracker).toModify(siPixelClusters,
src = "mixData:Pixel"
)
13 changes: 8 additions & 5 deletions SimGeneral/MixingModule/python/pixelDigitizer_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@

# Customize here instead of SiPixelSimBlock as the latter is imported
# also to DataMixer configuration, and the original version is needed
# there. Customize before phase2_tracker because this customization
# applies only to phase0/1 pixel, and at the moment it is unclear what
# needs to be done for phase2 tracker in premixing stage2.
# there in stage2. Customize before phase2_tracker because this
# customization applies only to phase0/1 pixel.
from Configuration.ProcessModifiers.premix_stage2_cff import premix_stage2
premix_stage2.toModify(pixelDigitizer,
AddPixelInefficiency = False # will be added in DataMixer
)

from SimTracker.SiPhase2Digitizer.phase2TrackerDigitizer_cfi import phase2TrackerDigitizer as _phase2TrackerDigitizer
from SimTracker.SiPhase2Digitizer.phase2TrackerDigitizer_cfi import phase2TrackerDigitizer as _phase2TrackerDigitizer, _premixStage1ModifyDict
from Configuration.Eras.Modifier_phase2_tracker_cff import phase2_tracker
phase2_tracker.toReplaceWith(pixelDigitizer, _phase2TrackerDigitizer)
phase2_tracker.toReplaceWith(pixelDigitizer, _phase2TrackerDigitizer.clone()) # have to clone here in order to not change the original with further customizations

# Customize here instead of phase2TrackerDigitizer as the latter is
# imported also to DataMixer configuration, and the original version
# is needed there in stage2.
(premix_stage2 & phase2_tracker).toModify(pixelDigitizer, **_premixStage1ModifyDict)
15 changes: 13 additions & 2 deletions SimGeneral/PreMixingModule/python/mixOne_premix_on_sim_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from SimCalorimetry.HcalSimProducers.hcalUnsuppressedDigis_cfi import hcalSimBlock
from SimGeneral.MixingModule.SiStripSimParameters_cfi import SiStripSimBlock
from SimGeneral.MixingModule.SiPixelSimParameters_cfi import SiPixelSimBlock
from SimTracker.SiPhase2Digitizer.phase2TrackerDigitizer_cfi import phase2TrackerDigitizer, _premixStage1ModifyDict as _phase2TrackerPremixStage1ModifyDict
from SimGeneral.MixingModule.ecalDigitizer_cfi import ecalDigitizer
from SimCalorimetry.HGCalSimProducers.hgcalDigitizer_cfi import hgceeDigitizer, hgchebackDigitizer, hgchefrontDigitizer

Expand Down Expand Up @@ -266,8 +267,18 @@
# Disable SiStrip
strip = None,
stripSimLink = None,
# Add Phase2 OT digiSimLink
# TODO: Add digis, but needs code first
# Replace pixel with Phase2 tracker
pixel = cms.PSet(
phase2TrackerDigitizer,
#
workerType = cms.string("PreMixingPhase2TrackerWorker"),
#
pixelLabelSig = cms.InputTag("simSiPixelDigis:Pixel"),
pixelPileInputTag = cms.InputTag("simSiPixelDigis:Pixel"),
trackerLabelSig = cms.InputTag("simSiPixelDigis:Tracker"),
trackerPileInputTag = cms.InputTag("simSiPixelDigis:Tracker"),
premixStage1ElectronPerAdc = cms.double(_phase2TrackerPremixStage1ModifyDict["PixelDigitizerAlgorithm"]["ElectronPerAdc"])
),
pixelSimLink = dict(
labelSig = "simSiPixelDigis:Pixel",
pileInputTag = "simSiPixelDigis:Pixel",
Expand Down
3 changes: 2 additions & 1 deletion SimTracker/SiPhase2Digitizer/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<use name="SimTracker/SiPhase2Digitizer"/>
<library file="Phase2TrackerDigitizer.cc PSPDigitizerAlgorithm.cc Phase2TrackerDigitizerAlgorithm.cc PixelDigitizerAlgorithm.cc PSSDigitizerAlgorithm.cc SSDigitizerAlgorithm.cc" name="SimTrackerSiPhase2DigitizerPlugins">
<library file="*.cc" name="SimTrackerSiPhase2DigitizerPlugins">
<use name="SimGeneral/PreMixingModule"/>
<flags EDM_PLUGIN="1"/>
</library>
67 changes: 54 additions & 13 deletions SimTracker/SiPhase2Digitizer/plugins/Phase2TrackerDigitizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,26 @@ namespace cms
hitsProducer_(iConfig.getParameter<std::string>("hitsProducer")),
trackerContainers_(iConfig.getParameter<std::vector<std::string> >("ROUList")),
geometryType_(iConfig.getParameter<std::string>("GeometryType")),
isOuterTrackerReadoutAnalog(iConfig.getParameter<bool>("isOTreadoutAnalog"))
isOuterTrackerReadoutAnalog(iConfig.getParameter<bool>("isOTreadoutAnalog")),
premixStage1_(iConfig.getParameter<bool>("premixStage1"))
{
//edm::LogInfo("Phase2TrackerDigitizer") << "Initialize Digitizer Algorithms";
const std::string alias1("simSiPixelDigis");
mixMod.produces<edm::DetSetVector<PixelDigi> >("Pixel").setBranchAlias(alias1);
mixMod.produces<edm::DetSetVector<PixelDigiSimLink> >("Pixel").setBranchAlias(alias1);

const std::string alias2("simSiTrackerDigis");
mixMod.produces<edm::DetSetVector<Phase2TrackerDigi> >("Tracker").setBranchAlias(alias2);
mixMod.produces<edm::DetSetVector<PixelDigiSimLink> >("Tracker").setBranchAlias(alias2);

if(!iConfig.getParameter<bool>("isOTreadoutAnalog")) {
const std::string alias2("simSiTrackerDigis");
if(premixStage1_) {
// Premixing exploits the ADC field of PixelDigi to store the collected charge
// But we still want everything else to be treated like for Phase2TrackerDigi
mixMod.produces<edm::DetSetVector<PixelDigi> >("Tracker").setBranchAlias(alias2);
}
else {
mixMod.produces<edm::DetSetVector<Phase2TrackerDigi> >("Tracker").setBranchAlias(alias2);
}
mixMod.produces<edm::DetSetVector<PixelDigiSimLink> >("Tracker").setBranchAlias(alias2);
}
// creating algorithm objects and pushing them into the map
algomap_[AlgorithmType::InnerPixel] = std::make_unique<PixelDigitizerAlgorithm>(iConfig);
algomap_[AlgorithmType::PixelinPS] = std::make_unique<PSPDigitizerAlgorithm>(iConfig);
Expand Down Expand Up @@ -206,11 +215,27 @@ namespace cms
if (simHits.isValid()) crossingSimHitIndexOffset_[tag.encode()] += simHits->size();
}
}

// For premixing
void Phase2TrackerDigitizer::loadAccumulator(const std::map<unsigned int, std::map<int, float> >& accumulator) {
for(const auto& detMap: accumulator) {
AlgorithmType algoType = getAlgoType(detMap.first);
auto& algo = *(algomap_.at(algoType));
algo.loadAccumulator(detMap.first, detMap.second);
}
}

void Phase2TrackerDigitizer::finalizeEvent(edm::Event& iEvent, const edm::EventSetup& iSetup) {
//Decide if we want analog readout for Outer Tracker.
addPixelCollection(iEvent, iSetup, isOuterTrackerReadoutAnalog);
if(!isOuterTrackerReadoutAnalog)
addOuterTrackerCollection(iEvent, iSetup);
if(!isOuterTrackerReadoutAnalog) {
if(premixStage1_) {
addOuterTrackerCollection<PixelDigi>(iEvent, iSetup);
}
else {
addOuterTrackerCollection<Phase2TrackerDigi>(iEvent, iSetup);
}
}
}
Phase2TrackerDigitizer::AlgorithmType Phase2TrackerDigitizer::getAlgoType(unsigned int detId_raw) {
DetId detId(detId_raw);
Expand Down Expand Up @@ -294,9 +319,26 @@ namespace cms
iEvent.put(std::move(output), "Pixel");
iEvent.put(std::move(outputlink), "Pixel");
}
}
namespace {
void addToCollector(edm::DetSet<PixelDigi>& collector, const int channel, const DigitizerUtility::DigiSimInfo& info) {
// For premixing stage1 the channel must be decoded with PixelDigi
// so that when the row and column are inserted to PixelDigi the
// coded channel stays the same (so that it can then be decoded
// with Phase2TrackerDigi in stage2).
std::pair<int,int> ip = PixelDigi::channelToPixel(channel);
collector.data.emplace_back(ip.first, ip.second, info.sig_tot);
}
void addToCollector(edm::DetSet<Phase2TrackerDigi>& collector, const int channel, const DigitizerUtility::DigiSimInfo& info) {
std::pair<int,int> ip = Phase2TrackerDigi::channelToPixel(channel);
collector.data.emplace_back(ip.first, ip.second, info.ot_bit);
}
}
namespace cms {
template <typename DigiType>
void Phase2TrackerDigitizer::addOuterTrackerCollection(edm::Event& iEvent, const edm::EventSetup& iSetup) {
const TrackerTopology* tTopo = tTopoHand.product();
std::vector<edm::DetSet<Phase2TrackerDigi> > digiVector;
std::vector<edm::DetSet<DigiType> > digiVector;
std::vector<edm::DetSet<PixelDigiSimLink> > digiLinkVector;
for (auto const & det_u : pDD_->detUnits()) {
DetId detId_raw = DetId(det_u->geographicalId().rawId());
Expand All @@ -307,13 +349,12 @@ namespace cms
std::map<int, DigitizerUtility::DigiSimInfo> digi_map;
algomap_[algotype]->digitize(dynamic_cast<const Phase2TrackerGeomDetUnit*>(det_u),
digi_map, tTopo);
edm::DetSet<Phase2TrackerDigi> collector(det_u->geographicalId().rawId());
edm::DetSet<DigiType> collector(det_u->geographicalId().rawId());
edm::DetSet<PixelDigiSimLink> linkcollector(det_u->geographicalId().rawId());

for (auto const & digi_p : digi_map) {
DigitizerUtility::DigiSimInfo info = digi_p.second;
std::pair<int,int> ip = Phase2TrackerDigi::channelToPixel(digi_p.first);
collector.data.emplace_back(ip.first, ip.second, info.ot_bit);
addToCollector(collector, digi_p.first, info);
for (auto const & sim_p : info.simInfoList) {

linkcollector.data.emplace_back(digi_p.first, sim_p.second->trackId(), sim_p.second->hitIndex(), sim_p.second->tofBin(), sim_p.second->eventId(), sim_p.first);
Expand All @@ -325,8 +366,8 @@ namespace cms
}

// Step C: create collection with the cache vector of DetSet
std::unique_ptr<edm::DetSetVector<Phase2TrackerDigi> >
output(new edm::DetSetVector<Phase2TrackerDigi>(digiVector));
std::unique_ptr<edm::DetSetVector<DigiType> >
output(new edm::DetSetVector<DigiType>(digiVector));
std::unique_ptr<edm::DetSetVector<PixelDigiSimLink> >
outputlink(new edm::DetSetVector<PixelDigiSimLink>(digiLinkVector));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ namespace cms
template <class T>
void accumulate_local(T const& iEvent, edm::EventSetup const& iSetup);


// For premixing
void loadAccumulator(const std::map<unsigned int, std::map<int, float> >& accumulator);
private:
using vstring = std::vector<std::string> ;

Expand All @@ -82,6 +83,9 @@ namespace cms
size_t globalSimHitIndex,
const unsigned int tofBin);
void addPixelCollection(edm::Event& iEvent, const edm::EventSetup& iSetup, const bool ot_analog);

// Templated for premixing
template <typename DigiType>
void addOuterTrackerCollection(edm::Event& iEvent, const edm::EventSetup& iSetup);


Expand All @@ -106,6 +110,7 @@ namespace cms
edm::ESHandle<TrackerTopology> tTopoHand;
edm::ESWatcher<TrackerDigiGeometryRecord> theTkDigiGeomWatcher;
const bool isOuterTrackerReadoutAnalog;
const bool premixStage1_;
// cache for detector types
ModuleTypeCache moduleTypeCache_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,20 @@ void Phase2TrackerDigitizerAlgorithm::module_killing_DB(uint32_t detID) {
}
}
}

// For premixing
void Phase2TrackerDigitizerAlgorithm::loadAccumulator(unsigned int detId, const std::map<int, float>& accumulator) {
auto& theSignal = _signal[detId];
// the input channel is always with PixelDigi definition
// if needed, that has to be converted to Phase2TrackerDigi convention
for(const auto& elem: accumulator) {
auto inserted = theSignal.emplace(elem.first, DigitizerUtility::Amplitude(elem.second, nullptr));
if(!inserted.second) {
throw cms::Exception("LogicError") << "Signal was already set for DetId " << detId;
}
}
}

void Phase2TrackerDigitizerAlgorithm::digitize(const Phase2TrackerGeomDetUnit* pixdet,
std::map<int, DigitizerUtility::DigiSimInfo> & digi_map,
const TrackerTopology* tTopo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class Phase2TrackerDigitizerAlgorithm {
std::map<int, DigitizerUtility::DigiSimInfo>& digi_map,
const TrackerTopology* tTopo);

// For premixing
void loadAccumulator(unsigned int detId, const std::map<int, float>& accumulator);
protected:
// Accessing Lorentz angle from DB:
edm::ESHandle<SiPixelLorentzAngle> SiPixelLorentzAngle_;
Expand Down
104 changes: 104 additions & 0 deletions SimTracker/SiPhase2Digitizer/plugins/PreMixingPhase2TrackerWorker.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/ProducerBase.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DataFormats/Common/interface/Handle.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/Utilities/interface/RandomNumberGenerator.h"
#include "SimGeneral/MixingModule/interface/PileUpEventPrincipal.h"

#include "DataFormats/Common/interface/DetSetVector.h"
#include "DataFormats/Common/interface/DetSet.h"

#include "SimGeneral/PreMixingModule/interface/PreMixingWorker.h"
#include "SimGeneral/PreMixingModule/interface/PreMixingWorkerFactory.h"

#include "Phase2TrackerDigitizer.h"
#include "Phase2TrackerDigitizerAlgorithm.h"

class PreMixingPhase2TrackerWorker: public PreMixingWorker {
public:
PreMixingPhase2TrackerWorker(const edm::ParameterSet& ps, edm::ProducerBase& producer, edm::ConsumesCollector&& iC);
~PreMixingPhase2TrackerWorker() override = default;

void beginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& es) override;

void initializeEvent(edm::Event const& e, edm::EventSetup const& es) override;
void addSignals(edm::Event const& e, edm::EventSetup const& es) override;
void addPileups(PileUpEventPrincipal const& pep, edm::EventSetup const& es) override;
void put(edm::Event &e, edm::EventSetup const& iSetup, std::vector<PileupSummaryInfo> const& ps, int bs) override;

private:
void accumulate(const edm::DetSetVector<PixelDigi>& digis);

cms::Phase2TrackerDigitizer digitizer_;

edm::EDGetTokenT<edm::DetSetVector<PixelDigi> > pixelSignalToken_;
edm::EDGetTokenT<edm::DetSetVector<PixelDigi> > trackerSignalToken_;
edm::InputTag pixelPileupLabel_;
edm::InputTag trackerPileupLabel_;
float electronPerAdc_;

// Maybe map of maps is not that bad for this add once, update once,
// read once workflow?
using SignalMap = std::map<unsigned int, std::map<int, float>>; // (channel, charge)
SignalMap accumulator_;
};


PreMixingPhase2TrackerWorker::PreMixingPhase2TrackerWorker(const edm::ParameterSet& ps, edm::ProducerBase& producer, edm::ConsumesCollector&& iC):
digitizer_(ps, producer, iC),
pixelSignalToken_(iC.consumes<edm::DetSetVector<PixelDigi> >(ps.getParameter<edm::InputTag>("pixelLabelSig"))),
trackerSignalToken_(iC.consumes<edm::DetSetVector<PixelDigi> >(ps.getParameter<edm::InputTag>("trackerLabelSig"))),
pixelPileupLabel_(ps.getParameter<edm::InputTag>("pixelPileInputTag")),
trackerPileupLabel_(ps.getParameter<edm::InputTag>("trackerPileInputTag")),
electronPerAdc_(ps.getParameter<double>("premixStage1ElectronPerAdc"))
{}

void PreMixingPhase2TrackerWorker::beginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& es) {
digitizer_.beginLuminosityBlock(lumi, es);
}

void PreMixingPhase2TrackerWorker::initializeEvent(edm::Event const& e, edm::EventSetup const& es) {
digitizer_.initializeEvent(e, es);
}

void PreMixingPhase2TrackerWorker::addSignals(edm::Event const& e, edm::EventSetup const& es) {
edm::Handle<edm::DetSetVector<PixelDigi> > hdigis;
e.getByToken(pixelSignalToken_, hdigis);
accumulate(*hdigis);

e.getByToken(trackerSignalToken_, hdigis);
accumulate(*hdigis);
}

void PreMixingPhase2TrackerWorker::addPileups(PileUpEventPrincipal const& pep, edm::EventSetup const& es) {
edm::Handle<edm::DetSetVector<PixelDigi> > hdigis;
pep.getByLabel(pixelPileupLabel_, hdigis);
accumulate(*hdigis);

pep.getByLabel(trackerPileupLabel_, hdigis);
accumulate(*hdigis);
}

void PreMixingPhase2TrackerWorker::accumulate(const edm::DetSetVector<PixelDigi>& digis) {
for(const auto& detset: digis) {
auto& accDet = accumulator_[detset.detId()];
for(const auto& digi: detset) {
// note: according to C++ standard operator[] does
// value-initializiation, which for float means initial value of 0
auto& acc = accDet[digi.channel()];
acc += digi.adc()*electronPerAdc_;
}
}
}

void PreMixingPhase2TrackerWorker::put(edm::Event &e, edm::EventSetup const& iSetup, std::vector<PileupSummaryInfo> const& ps, int bs) {
digitizer_.loadAccumulator(accumulator_);
digitizer_.finalizeEvent(e, iSetup);
decltype(accumulator_){}.swap(accumulator_); // release memory
}

DEFINE_EDM_PLUGIN(PreMixingWorkerFactory, PreMixingPhase2TrackerWorker, "PreMixingPhase2TrackerWorker");
Loading

0 comments on commit 2e317ef

Please sign in to comment.