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

Update of Phase2Digitizer package #16884

Merged
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
62 changes: 12 additions & 50 deletions SimTracker/SiPhase2Digitizer/plugins/DigitizerUtility.h
Expand Up @@ -14,61 +14,27 @@
namespace DigitizerUtility {
class Amplitude {
public:
Amplitude() : _amp(0.0)
{}
Amplitude(float amp, float frac) :
_amp(amp), _frac(1, frac), _hitInfo()
{
// in case of digi from noisypixels
// the MC information are removed
if (_frac[0] < -0.5)
_frac.pop_back();
}

Amplitude( float amp, const PSimHit* hitp, size_t hitIndex, unsigned int tofBin, float frac) :
_amp(amp), _frac(1, frac), _hitInfo(new SimHitInfoForLinks(hitp, hitIndex, tofBin)) {
// in case of digi from noisypixels
// the MC information are removed
if (_frac[0] < -0.5) {
_frac.pop_back();
_hitInfo->trackIds().pop_back();
Amplitude() : _amp(0.0) {}
Amplitude( float amp, const PSimHit* hitp, float frac=0, size_t hitIndex=0, unsigned int tofBin=0) :
_amp(amp) {
if (frac > 0) {
if (hitp != nullptr) _simInfoList.push_back({frac,new SimHitInfoForLinks(hitp,hitIndex,tofBin)});
else _simInfoList.push_back({frac,0});
}
}

// can be used as a float by convers.
operator float() const {return _amp;}
float ampl() const {return _amp;}
const std::vector<float>& individualampl() const {return _frac;}
const std::vector<unsigned int>& trackIds() const {return _hitInfo->trackIds();}
const std::shared_ptr<SimHitInfoForLinks>& hitInfo() const {return _hitInfo;}
const std::vector<std::pair<float,SimHitInfoForLinks*> >& simInfoList() const {return _simInfoList;}

void operator+= (const Amplitude& other) {
_amp += other._amp;

// in case of contribution of noise to the digi
// the MC information are removed
if (other._frac.size() > 0 && other._frac[0] > -0.5) {
if (other._hitInfo) {
const std::vector<unsigned int>& otherTrackIds = other._hitInfo->trackIds();
if (_hitInfo) {
std::vector<unsigned int>& trackIds = _hitInfo->trackIds();
trackIds.insert(trackIds.end(), otherTrackIds.begin(), otherTrackIds.end());
}
else
_hitInfo.reset(new SimHitInfoForLinks(*other._hitInfo));
}
_frac.insert(_frac.end(), other._frac.begin(), other._frac.end());
// in case of digi from the noise, the MC information need not be there
for (auto const & ic : other.simInfoList()) {
if (ic.first > -0.5) _simInfoList.push_back({ic.first, ic.second});
}
}
const EncodedEventId& eventId() const {
return _hitInfo->eventId();
}
const unsigned int hitIndex() const {
return _hitInfo->hitIndex();
}
const unsigned int tofBin() const {
return _hitInfo->tofBin();
}
void operator+= (const float& amp) {
_amp += amp;
}
Expand All @@ -81,8 +47,7 @@ namespace DigitizerUtility {

private:
float _amp;
std::vector<float> _frac;
std::shared_ptr<SimHitInfoForLinks> _hitInfo;
std::vector<std::pair<float,SimHitInfoForLinks*> > _simInfoList;
};

//*********************************************************
Expand Down Expand Up @@ -142,10 +107,7 @@ namespace DigitizerUtility {
struct DigiSimInfo {
int sig_tot;
bool ot_bit;
std::map<unsigned int, float> track_map;
unsigned int hit_counter;
unsigned int tof_bin;
EncodedEventId event_id;
std::vector<std::pair<float, SimHitInfoForLinks*> > simInfoList;
};
}
#endif
21 changes: 12 additions & 9 deletions SimTracker/SiPhase2Digitizer/plugins/Phase2TrackerDigitizer.cc
Expand Up @@ -141,9 +141,10 @@ namespace cms
void
Phase2TrackerDigitizer::accumulatePixelHits(edm::Handle<std::vector<PSimHit> > hSimHits,
size_t globalSimHitIndex,const unsigned int tofBin) {
if (hSimHits.isValid()) {
if (hSimHits.isValid()) {
std::set<unsigned int> detIds;
std::vector<PSimHit> const& simHits = *hSimHits.product();
int indx = 0;
for (auto it = simHits.begin(), itEnd = simHits.end(); it != itEnd; ++it, ++globalSimHitIndex) {
unsigned int detId_raw = (*it).detUnitId();
if (detectorUnits_.find(detId_raw) == detectorUnits_.end()) continue;
Expand All @@ -155,11 +156,12 @@ namespace cms
GlobalVector bfield = pSetup_->inTesla(phase2det->surface().position());
LogDebug("PixelDigitizer") << "B-field(T) at " << phase2det->surface().position() << "(cm): "
<< pSetup_->inTesla(phase2det->surface().position());
if (algomap_.find(algotype) != algomap_.end())
if (algomap_.find(algotype) != algomap_.end()) {
algomap_[algotype]->accumulateSimHits(it, itEnd, globalSimHitIndex, tofBin, phase2det, bfield);
else
} else
edm::LogInfo("Phase2TrackerDigitizer") << "Unsupported algorithm: ";
}
indx++;
}
}
}
Expand Down Expand Up @@ -280,8 +282,8 @@ namespace cms
DigitizerUtility::DigiSimInfo info = digi_p.second;
std::pair<int,int> ip = PixelDigi::channelToPixel(digi_p.first);
collector.data.emplace_back(ip.first, ip.second, info.sig_tot);
for (auto const & tk_p : info.track_map) {
linkcollector.data.emplace_back(digi_p.first, tk_p.first, info.hit_counter, info.tof_bin, info.event_id, tk_p.second);
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);
}
}
if (collector.data.size() > 0) digiVector.push_back(std::move(collector));
Expand Down Expand Up @@ -313,15 +315,16 @@ namespace cms
digi_map, tTopo);
edm::DetSet<Phase2TrackerDigi> 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);
for (auto const & track_p : info.track_map) {
linkcollector.data.emplace_back(digi_p.first, track_p.first, info.hit_counter, info.tof_bin, info.event_id, track_p.second);
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);
}
}
}

if (collector.data.size() > 0) digiVector.push_back(std::move(collector));
if (linkcollector.data.size() > 0) digiLinkVector.push_back(std::move(linkcollector));
Expand Down
Expand Up @@ -584,7 +584,8 @@ void Phase2TrackerDigitizerAlgorithm::induce_signal(const PSimHit& hit,
// Fill the global map with all hit pixels from this event
for (auto const & hit_s : hit_signal) {
int chan = hit_s.first;
theSignal[chan] += (makeDigiSimLinks_ ? DigitizerUtility::Amplitude( hit_s.second, &hit, hitIndex, tofBin, hit_s.second) : DigitizerUtility::Amplitude( hit_s.second, hit_s.second) ) ;
theSignal[chan] += (makeDigiSimLinks_ ? DigitizerUtility::Amplitude( hit_s.second, &hit, hit_s.second, hitIndex, tofBin)
: DigitizerUtility::Amplitude( hit_s.second, nullptr, hit_s.second) ) ;
}
}
// ======================================================================
Expand Down Expand Up @@ -624,22 +625,23 @@ void Phase2TrackerDigitizerAlgorithm::add_noise(const Phase2TrackerGeomDetUnit*
std::pair<int,int> XtalkPrev = std::pair<int,int>(hitChan.first-1, hitChan.second);
int chanXtalkPrev = (pixelFlag) ? PixelDigi::pixelToChannel(XtalkPrev.first, XtalkPrev.second)
: Phase2TrackerDigi::pixelToChannel(XtalkPrev.first, XtalkPrev.second);
signalNew.insert(std::pair<int,DigitizerUtility::Amplitude>(chanXtalkPrev, DigitizerUtility::Amplitude(signalInElectrons_Xtalk, -1.0)));
signalNew.insert(std::pair<int,DigitizerUtility::Amplitude>(chanXtalkPrev, DigitizerUtility::Amplitude(signalInElectrons_Xtalk, nullptr, -1.0)));
}
if (hitChan.first < (numRows-1)) {
std::pair<int,int> XtalkNext = std::pair<int,int>(hitChan.first+1, hitChan.second);
int chanXtalkNext = (pixelFlag) ? PixelDigi::pixelToChannel(XtalkNext.first, XtalkNext.second)
: Phase2TrackerDigi::pixelToChannel(XtalkNext.first, XtalkNext.second);
signalNew.insert(std::pair<int,DigitizerUtility::Amplitude>(chanXtalkNext, DigitizerUtility::Amplitude(signalInElectrons_Xtalk, -1.0)));
signalNew.insert(std::pair<int,DigitizerUtility::Amplitude>(chanXtalkNext, DigitizerUtility::Amplitude(signalInElectrons_Xtalk, nullptr, -1.0)));
}
}
for (auto const & l : signalNew) {
int chan = l.first;
auto iter = theSignal.find(chan);
if (iter != theSignal.end())
if (iter != theSignal.end()) {
theSignal[chan] += l.second.ampl();
else
theSignal.insert(std::pair<int,DigitizerUtility::Amplitude>(chan, DigitizerUtility::Amplitude(l.second.ampl(),-1.0)));
} else {
theSignal.insert(std::pair<int,DigitizerUtility::Amplitude>(chan, DigitizerUtility::Amplitude(l.second.ampl(), nullptr, -1.0)));
}
}
}
if (!addNoisyPixels) // Option to skip noise in non-hit pixels
Expand Down Expand Up @@ -682,7 +684,7 @@ void Phase2TrackerDigitizerAlgorithm::add_noise(const Phase2TrackerGeomDetUnit*

if (theSignal[chan] == 0) {
int noise = int((*mapI).second);
theSignal[chan] = DigitizerUtility::Amplitude (noise, -1.);
theSignal[chan] = DigitizerUtility::Amplitude (noise, nullptr, -1.);
}
}
}
Expand Down Expand Up @@ -909,7 +911,7 @@ void Phase2TrackerDigitizerAlgorithm::digitize(const Phase2TrackerGeomDetUnit* p
auto it = _signal.find(detID);
if (it == _signal.end()) return;

const signal_map_type& theSignal = _signal[detID]; // ** please check detID exists!!!
const signal_map_type& theSignal = _signal[detID];


unsigned int Sub_detid = DetId(detID).subdetId();
Expand All @@ -927,9 +929,8 @@ void Phase2TrackerDigitizerAlgorithm::digitize(const Phase2TrackerGeomDetUnit* p
theHIPThresholdInE = theHIPThresholdInE_Endcap;
}


if (addNoise) add_noise(pixdet, theThresholdInE/theNoiseInElectrons); // generate noise

// Do only if needed
if (AddPixelInefficiency && theSignal.size() > 0) {
if (use_ineff_from_db_)
Expand All @@ -944,27 +945,23 @@ void Phase2TrackerDigitizerAlgorithm::digitize(const Phase2TrackerGeomDetUnit* p
module_killing_conf(detID);
}

// DDigitize if the signal is greater than threshold
// Digitize if the signal is greater than threshold
for (auto const & s : theSignal) {
DigitizerUtility::Amplitude sig_data = s.second;
float signalInElectrons = sig_data.ampl();
int adc;
if (signalInElectrons >= theThresholdInE) { // check threshold

if (doDigitalReadout) adc = theAdcFullScale;
else adc = std::min( int(signalInElectrons / theElectronPerADC), theAdcFullScale );

DigitizerUtility::DigiSimInfo info;
info.sig_tot = adc;
info.ot_bit = ( signalInElectrons > theHIPThresholdInE ? true : false);
if (makeDigiSimLinks_ && sig_data.hitInfo() != 0) {
info.hit_counter = sig_data.hitIndex();
info.tof_bin = sig_data.tofBin();
info.event_id = sig_data.eventId();
for (unsigned int j = 0; j != sig_data.trackIds().size(); ++j) {
unsigned int tkid = sig_data.trackIds()[j];
float charge_frac = sig_data.individualampl()[j]/adc;
info.track_map.insert({tkid, charge_frac});
if (makeDigiSimLinks_ ) {
int j = 0;
for (auto l : sig_data.simInfoList()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the typical length of this loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mostly a couple of elements

j++;
float charge_frac = l.first/signalInElectrons;
if (l.first > -5.0) info.simInfoList.push_back({charge_frac,l.second});
}
}
digi_map.insert({s.first, info});
Expand Down
Expand Up @@ -5,6 +5,27 @@
pixDigiMon = digiMon.clone()
pixDigiMon.PixelPlotFillingFlag = cms.bool(True)
pixDigiMon.TopFolderName = cms.string("Ph2TkPixelDigi")
pixDigiMon.PositionOfDigisH = cms.PSet(
Nxbins = cms.int32(1350),
xmin = cms.double(0.5),
xmax = cms.double(1350.5),
Nybins = cms.int32(450),
ymin = cms.double(0.5),
ymax = cms.double(450.5))
pixDigiMon.XYPositionMapH = cms.PSet(
Nxbins = cms.int32(340),
xmin = cms.double(-170.),
xmax = cms.double(170.),
Nybins = cms.int32(340),
ymin = cms.double(-170.),
ymax = cms.double(170.))
pixDigiMon.RZPositionMapH = cms.PSet(
Nxbins = cms.int32(3000),
xmin = cms.double(-3000.0),
xmax = cms.double(3000.),
Nybins = cms.int32(280),
ymin = cms.double(0.),
ymax = cms.double(280.))

otDigiMon = digiMon.clone()
otDigiMon.PixelPlotFillingFlag = cms.bool(False)
Expand Down
56 changes: 33 additions & 23 deletions SimTracker/SiPhase2Digitizer/python/Phase2TrackerMonitorDigi_cfi.py
Expand Up @@ -23,18 +23,28 @@
xmax = cms.double(0.005)
),
PositionOfDigisH = cms.PSet(
Nxbins = cms.int32(260),
Nxbins = cms.int32(1016),
xmin = cms.double(0.5),
xmax = cms.double(260.5),
Nybins = cms.int32(2),
xmax = cms.double(1016.5),
Nybins = cms.int32(10),
ymin = cms.double(0.5),
ymax = cms.double(2.5)
ymax = cms.double(10.5)
),
DigiChargeH = cms.PSet(
Nbins = cms.int32(261),
xmin = cms.double(0.5),
xmax = cms.double(260.5)
),
TotalNumberOfDigisPerLayerH = cms.PSet(
Nbins = cms.int32(1000),
xmin = cms.double(-0.5),
xmax = cms.double(999.5)
),
NumberOfHitDetsPerLayerH = cms.PSet(
Nbins = cms.int32(200),
xmin = cms.double(-0.5),
xmax = cms.double(199.5)
),
NumberOfClustersH = cms.PSet(
Nbins = cms.int32(51),
xmin = cms.double(-0.5),
Expand All @@ -46,29 +56,29 @@
xmax = cms.double(15.5),
),
ClusterChargeH = cms.PSet(
Nbins = cms.int32(1024),
xmin = cms.double(0.5),
xmax = cms.double(1024.5)
Nbins = cms.int32(1024),
xmin = cms.double(0.5),
xmax = cms.double(1024.5)
),
ClusterPositionH = cms.PSet(
Nbins = cms.int32(1016),
xmin = cms.double(0.5),
xmax = cms.double(1016.5)
Nbins = cms.int32(1016),
xmin = cms.double(0.5),
xmax = cms.double(1016.5)
),
XYPositionMapH = cms.PSet(
Nxbins = cms.int32(1200),
xmin = cms.double(-120.),
xmax = cms.double(120.),
Nybins = cms.int32(1200),
ymin = cms.double(-120.),
ymax = cms.double(120.)
),
Nxbins = cms.int32(1250),
xmin = cms.double(-1250.),
xmax = cms.double(1250.),
Nybins = cms.int32(1250),
ymin = cms.double(-1250.),
ymax = cms.double(1250.)
),
RZPositionMapH = cms.PSet(
Nxbins = cms.int32(3000),
xmin = cms.double(-300.),
xmax = cms.double(300.),
Nybins = cms.int32(3000),
ymin = cms.double(0.),
ymax = cms.double(120.)
Nxbins = cms.int32(3000),
xmin = cms.double(-3000.),
xmax = cms.double(3000.),
Nybins = cms.int32(1250),
ymin = cms.double(0.),
ymax = cms.double(1250.)
)
)
Expand Up @@ -5,6 +5,20 @@
pixDigiValid = digiValid.clone()
pixDigiValid.PixelPlotFillingFlag = cms.bool(True)
pixDigiValid.TopFolderName = cms.string("Ph2TkPixelDigi")
pixDigiValid.XYPositionMapH = cms.PSet(
Nxbins = cms.int32(340),
xmin = cms.double(-170.),
xmax = cms.double(170.),
Nybins = cms.int32(340),
ymin = cms.double(-170.),
ymax = cms.double(170.))
pixDigiValid.RZPositionMapH = cms.PSet(
Nxbins = cms.int32(3000),
xmin = cms.double(-3000.0),
xmax = cms.double(3000.),
Nybins = cms.int32(280),
ymin = cms.double(0.),
ymax = cms.double(280.))

otDigiValid = digiValid.clone()
otDigiValid.PixelPlotFillingFlag = cms.bool(False)
Expand Down