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

#4716 with merge conflicts resolved and Phase2 digitiser updated #4738

Merged
merged 4 commits into from Jul 22, 2014
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
15 changes: 15 additions & 0 deletions SimDataFormats/TrackerDigiSimLink/interface/PixelDigiSimLink.h
Expand Up @@ -7,20 +7,33 @@
//typedef std::pair<unsigned int ,unsigned int > PixelDigiSimLink;
class PixelDigiSimLink {
public:
enum {LowTof, HighTof};

PixelDigiSimLink(unsigned int ch, unsigned int tkId, unsigned int counter, unsigned int tofBin, EncodedEventId e, float a ){
chan=ch;
simTkId=tkId;
CFpos = tofBin == LowTof ? counter & 0x7FFFFFFF : (counter & 0x7FFFFFFF) | 0x80000000;
fract=a;
eId=e;
};
PixelDigiSimLink(unsigned int ch, unsigned int tkId, EncodedEventId e, float a ){
chan=ch;
simTkId=tkId;
CFpos = 0;
fract=a;
eId=e;
};
PixelDigiSimLink():eId(0){
chan=0;
simTkId=0;
CFpos = 0;
fract=0;
};
~PixelDigiSimLink(){};
unsigned int channel() const{return chan;};
unsigned int SimTrackId() const{return simTkId;};
unsigned int CFposition() const {return CFpos & 0x7FFFFFFF;}
unsigned int TofBin() const {return (CFpos & 0x80000000) == 0 ? LowTof : HighTof;}
EncodedEventId eventId() const{return eId;}
float fraction() const{return fract;};

Expand All @@ -30,6 +43,8 @@ class PixelDigiSimLink {
private:
unsigned int chan;
unsigned int simTkId;
uint32_t CFpos; // position of the PSimHit in the CrossingFrame vector
// for the subdetector collection; bit 31 set if from the HighTof collection
EncodedEventId eId;
float fract;
};
Expand Down
3 changes: 2 additions & 1 deletion SimDataFormats/TrackerDigiSimLink/src/classes_def.xml
@@ -1,7 +1,8 @@
<lcgdict>

<class name="PixelDigiSimLink" ClassVersion="10">
<class name="PixelDigiSimLink" ClassVersion="11">
<version ClassVersion="10" checksum="408436386"/>
<version ClassVersion="11" checksum="3298015919"/>
</class>
<class name="edm::DetSet<PixelDigiSimLink>"/>
<class name="std::vector<PixelDigiSimLink>"/>
Expand Down
6 changes: 5 additions & 1 deletion SimTracker/Common/interface/SimHitInfoForLinks.h
Expand Up @@ -6,11 +6,15 @@

// A stripped down version of PSimHit used to save memory.
// Contains only the information needed to be make DigiSimLinks.
// Include the simHit's index in the source collection, collection name suffix index.

struct SimHitInfoForLinks {
explicit SimHitInfoForLinks(PSimHit const* hitp) : eventId_(hitp->eventId()), trackIds_(1, hitp->trackId()) {
explicit SimHitInfoForLinks(PSimHit const* hitp, size_t hitindex, unsigned int tofbin) :
eventId_(hitp->eventId()), trackIds_(1, hitp->trackId()), hitIndex_(hitindex), tofBin_(tofbin) {
}
EncodedEventId eventId_;
std::vector<unsigned int> trackIds_;
size_t hitIndex_;
unsigned int tofBin_;
};
#endif
32 changes: 27 additions & 5 deletions SimTracker/SiPhase2Digitizer/plugins/SiPhase2Digitizer.cc
Expand Up @@ -113,11 +113,13 @@ namespace cms
//

void
SiPhase2Digitizer::accumulatePixelHits(edm::Handle<std::vector<PSimHit> > hSimHits) {
SiPhase2Digitizer::accumulatePixelHits(edm::Handle<std::vector<PSimHit> > hSimHits,
size_t globalSimHitIndex,
const unsigned int tofBin) {
if(hSimHits.isValid()) {
std::set<unsigned int> detIds;
std::vector<PSimHit> const& simHits = *hSimHits.product();
for(std::vector<PSimHit>::const_iterator it = simHits.begin(), itEnd = simHits.end(); it != itEnd; ++it) {
for(std::vector<PSimHit>::const_iterator it = simHits.begin(), itEnd = simHits.end(); it != itEnd; ++it, ++globalSimHitIndex) {
unsigned int detId = (*it).detUnitId();
if(detIds.insert(detId).second) {
// The insert succeeded, so this detector element has not yet been processed.
Expand All @@ -128,7 +130,7 @@ namespace cms
GlobalVector bfield = pSetup->inTesla(pixdet->surface().position());
LogDebug ("PixelDigitizer ") << "B-field(T) at " << pixdet->surface().position() << "(cm): "
<< pSetup->inTesla(pixdet->surface().position());
_pixeldigialgo->accumulateSimHits(it, itEnd, pixdet, bfield);
_pixeldigialgo->accumulateSimHits(it, itEnd, globalSimHitIndex, tofBin, pixdet, bfield);
}
}
}
Expand All @@ -141,6 +143,12 @@ namespace cms
_pixeldigialgo->init(iSetup);
first = false;
}
// Make sure that the first crossing processed starts indexing the sim hits from zero.
// This variable is used so that the sim hits from all crossing frames have sequential
// indices used to create the digi-sim link (if configured to do so) rather than starting
// from zero for each crossing.
crossingSimHitIndexOffset_.clear();

_pixeldigialgo->initializeEvent();
iSetup.get<TrackerDigiGeometryRecord>().get(geometryType, pDD);
iSetup.get<IdealMagneticFieldRecord>().get(pSetup);
Expand Down Expand Up @@ -169,7 +177,14 @@ namespace cms
edm::InputTag tag(hitsProducer, *i);

iEvent.getByLabel(tag, simHits);
accumulatePixelHits(simHits);
unsigned int tofBin = PixelDigiSimLink::LowTof;
if ((*i).find(std::string("HighTof")) != std::string::npos) tofBin = PixelDigiSimLink::HighTof;
accumulatePixelHits(simHits, crossingSimHitIndexOffset_[tag.encode()], tofBin);
// Now that the hits have been processed, I'll add the amount of hits in this crossing on to
// the global counter. Next time accumulateStripHits() is called it will count the sim hits
// as though they were on the end of this collection.
// Note that this is only used for creating digi-sim links (if configured to do so).
if( simHits.isValid() ) crossingSimHitIndexOffset_[tag.encode()]+=simHits->size();
}
}

Expand All @@ -181,7 +196,14 @@ namespace cms
edm::InputTag tag(hitsProducer, *i);

iEvent.getByLabel(tag, simHits);
accumulatePixelHits(simHits);
unsigned int tofBin = PixelDigiSimLink::LowTof;
if ((*i).find(std::string("HighTof")) != std::string::npos) tofBin = PixelDigiSimLink::HighTof;
accumulatePixelHits(simHits, crossingSimHitIndexOffset_[tag.encode()], tofBin);
// Now that the hits have been processed, I'll add the amount of hits in this crossing on to
// the global counter. Next time accumulateStripHits() is called it will count the sim hits
// as though they were on the end of this collection.
// Note that this is only used for creating digi-sim links (if configured to do so).
if( simHits.isValid() ) crossingSimHitIndexOffset_[tag.encode()]+=simHits->size();
}
}

Expand Down
14 changes: 13 additions & 1 deletion SimTracker/SiPhase2Digitizer/plugins/SiPhase2Digitizer.h
Expand Up @@ -55,9 +55,21 @@ namespace cms {

virtual void beginJob() {}
private:
void accumulatePixelHits(edm::Handle<std::vector<PSimHit> >);
void accumulatePixelHits(edm::Handle<std::vector<PSimHit> >,
size_t globalSimHitIndex,
const unsigned int tofBin);
bool first;
std::unique_ptr<SiPhase2DigitizerAlgorithm> _pixeldigialgo;
/** @brief Offset to add to the index of each sim hit to account for which crossing it's in.
*
* I need to know what each sim hit index will be when the hits from all crossing frames are merged into
* one collection (assuming the MixingModule is configured to create the crossing frame for all sim hits).
* To do this I'll record how many hits were in each crossing, and then add that on to the index for a given
* hit in a given crossing. This assumes that the crossings are processed in the same order here as they are
* put into the crossing frame, which I'm pretty sure is true.<br/>
* The key is the name of the sim hit collection. */
std::map<std::string,size_t> crossingSimHitIndexOffset_;

typedef std::vector<std::string> vstring;
const std::string hitsProducer;
const vstring trackerContainers;
Expand Down
Expand Up @@ -441,13 +441,16 @@ SiPhase2DigitizerAlgorithm::PixelEfficiencies::PixelEfficiencies(const edm::Para
//=========================================================================
void SiPhase2DigitizerAlgorithm::accumulateSimHits(std::vector<PSimHit>::const_iterator inputBegin,
std::vector<PSimHit>::const_iterator inputEnd,
const size_t inputBeginGlobalIndex,
const unsigned int tofBin,
const PixelGeomDetUnit* pixdet,
const GlobalVector& bfield) {
// produce SignalPoint's for all SimHit's in detector
// Loop over hits

uint32_t detId = pixdet->geographicalId().rawId();
for (std::vector<PSimHit>::const_iterator ssbegin = inputBegin; ssbegin != inputEnd; ++ssbegin) {
size_t simHitGlobalIndex=inputBeginGlobalIndex; // This needs to stored to create the digi-sim link later
for (std::vector<PSimHit>::const_iterator ssbegin = inputBegin; ssbegin != inputEnd; ++ssbegin, ++simHitGlobalIndex) {
// skip hits not in this detector.
if((*ssbegin).detUnitId() != detId) {
continue;
Expand All @@ -473,7 +476,7 @@ void SiPhase2DigitizerAlgorithm::accumulateSimHits(std::vector<PSimHit>::const_i
primary_ionization(*ssbegin, ionization_points); // fills _ionization_points
drift (*ssbegin, pixdet, bfield, ionization_points, collection_points); // transforms _ionization_points to collection_points
// compute induced signal on readout elements and add to _signal
induce_signal(*ssbegin, pixdet, collection_points); // *ihit needed only for SimHit<-->Digi link
induce_signal(*ssbegin, simHitGlobalIndex, tofBin, pixdet, collection_points); // *ihit needed only for SimHit<-->Digi link
} // end if
} // end for

Expand Down Expand Up @@ -837,6 +840,8 @@ void SiPhase2DigitizerAlgorithm::drift(const PSimHit& hit,
//*************************************************************************
// Induce the signal on the collection plane of the active sensor area.
void SiPhase2DigitizerAlgorithm::induce_signal(const PSimHit& hit,
const size_t hitIndex,
const unsigned int tofBin,
const PixelGeomDetUnit* pixdet,
const std::vector<SignalPoint>& collection_points) {

Expand Down Expand Up @@ -1051,7 +1056,7 @@ void SiPhase2DigitizerAlgorithm::induce_signal(const PSimHit& hit,
for ( hit_map_type::const_iterator im = hit_signal.begin();
im != hit_signal.end(); ++im) {
int chan = (*im).first;
theSignal[chan] += (makeDigiSimLinks_ ? Amplitude( (*im).second, &hit, (*im).second) : Amplitude( (*im).second, (*im).second) ) ;
theSignal[chan] += (makeDigiSimLinks_ ? Amplitude( (*im).second, &hit, hitIndex, tofBin, (*im).second) : Amplitude( (*im).second, (*im).second) ) ;

#ifdef TP_DEBUG
std::pair<int,int> ip = PixelDigi::channelToPixel(chan);
Expand Down Expand Up @@ -1161,7 +1166,7 @@ void SiPhase2DigitizerAlgorithm::make_digis(float thePixelThresholdInE,
}
float fraction=sum_samechannel/(*i).second;
if(fraction>1.) fraction=1.;
simlinks.emplace_back((*i).first, (*simiiter).first, (*i).second.eventId(), fraction);
simlinks.emplace_back((*i).first, (*simiiter).first, (*i).second.hitIndex(), (*i).second.tofBin(), (*i).second.eventId(), fraction);
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions SimTracker/SiPhase2Digitizer/plugins/SiPhase2DigitizerAlgorithm.h
Expand Up @@ -56,6 +56,8 @@ class SiPhase2DigitizerAlgorithm {
//run the algorithm to digitize a single det
void accumulateSimHits(const std::vector<PSimHit>::const_iterator inputBegin,
const std::vector<PSimHit>::const_iterator inputEnd,
const size_t inputBeginGlobalIndex,
const unsigned int tofBin,
const PixelGeomDetUnit *pixdet,
const GlobalVector& bfield);
void digitize(const PixelGeomDetUnit *pixdet,
Expand Down Expand Up @@ -91,8 +93,8 @@ class SiPhase2DigitizerAlgorithm {
}
}

Amplitude( float amp, const PSimHit* hitp, float frac) :
_amp(amp), _frac(1, frac), _hitInfo(new SimHitInfoForLinks(hitp)) {
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
Expand Down Expand Up @@ -131,6 +133,12 @@ class SiPhase2DigitizerAlgorithm {
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 Down Expand Up @@ -356,6 +364,8 @@ class SiPhase2DigitizerAlgorithm {
const std::vector<EnergyDepositUnit>& ionization_points,
std::vector<SignalPoint>& collection_points) const;
void induce_signal(const PSimHit& hit,
const size_t hitIndex,
const unsigned int tofBin,
const PixelGeomDetUnit *pixdet,
const std::vector<SignalPoint>& collection_points);
void fluctuateEloss(int particleId, float momentum, float eloss,
Expand Down
34 changes: 28 additions & 6 deletions SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizer.cc
Expand Up @@ -122,11 +122,14 @@ namespace cms
//

void
SiPixelDigitizer::accumulatePixelHits(edm::Handle<std::vector<PSimHit> > hSimHits, const TrackerTopology *tTopo) {
SiPixelDigitizer::accumulatePixelHits(edm::Handle<std::vector<PSimHit> > hSimHits,
size_t globalSimHitIndex,
const unsigned int tofBin,
const TrackerTopology *tTopo) {
if(hSimHits.isValid()) {
std::set<unsigned int> detIds;
std::vector<PSimHit> const& simHits = *hSimHits.product();
for(std::vector<PSimHit>::const_iterator it = simHits.begin(), itEnd = simHits.end(); it != itEnd; ++it) {
for(std::vector<PSimHit>::const_iterator it = simHits.begin(), itEnd = simHits.end(); it != itEnd; ++it, ++globalSimHitIndex) {
unsigned int detId = (*it).detUnitId();
if(detIds.insert(detId).second) {
// The insert succeeded, so this detector element has not yet been processed.
Expand All @@ -137,8 +140,7 @@ namespace cms
GlobalVector bfield = pSetup->inTesla(pixdet->surface().position());
LogDebug ("PixelDigitizer ") << "B-field(T) at " << pixdet->surface().position() << "(cm): "
<< pSetup->inTesla(pixdet->surface().position());

_pixeldigialgo->accumulateSimHits(it, itEnd, pixdet, bfield, tTopo);
_pixeldigialgo->accumulateSimHits(it, itEnd, globalSimHitIndex, tofBin, pixdet, bfield, tTopo);
}
}
}
Expand All @@ -151,6 +153,12 @@ namespace cms
_pixeldigialgo->init(iSetup);
first = false;
}
// Make sure that the first crossing processed starts indexing the sim hits from zero.
// This variable is used so that the sim hits from all crossing frames have sequential
// indices used to create the digi-sim link (if configured to do so) rather than starting
// from zero for each crossing.
crossingSimHitIndexOffset_.clear();

_pixeldigialgo->initializeEvent();
iSetup.get<TrackerDigiGeometryRecord>().get(geometryType, pDD);
iSetup.get<IdealMagneticFieldRecord>().get(pSetup);
Expand Down Expand Up @@ -189,7 +197,14 @@ namespace cms
// the next (i.e. original) line should be uncommented and the one after removed. Forever.
//iEvent.getByLabel(tag, simHits);
detIdRemapService_->getByLabel( iEvent, tag, simHits );
accumulatePixelHits(simHits, tTopo);
unsigned int tofBin = PixelDigiSimLink::LowTof;
if ((*i).find(std::string("HighTof")) != std::string::npos) tofBin = PixelDigiSimLink::HighTof;
accumulatePixelHits(simHits, crossingSimHitIndexOffset_[tag.encode()], tofBin, tTopo);
// Now that the hits have been processed, I'll add the amount of hits in this crossing on to
// the global counter. Next time accumulateStripHits() is called it will count the sim hits
// as though they were on the end of this collection.
// Note that this is only used for creating digi-sim links (if configured to do so).
if( simHits.isValid() ) crossingSimHitIndexOffset_[tag.encode()]+=simHits->size();
}
}

Expand All @@ -210,7 +225,14 @@ namespace cms
// the next (i.e. original) line should be uncommented and the one after removed. Forever.
//iEvent.getByLabel(tag, simHits);
detIdRemapService_->getByLabel( iEvent, tag, simHits );
accumulatePixelHits(simHits,tTopo);
unsigned int tofBin = PixelDigiSimLink::LowTof;
if ((*i).find(std::string("HighTof")) != std::string::npos) tofBin = PixelDigiSimLink::HighTof;
accumulatePixelHits(simHits, crossingSimHitIndexOffset_[tag.encode()], tofBin, tTopo);
// Now that the hits have been processed, I'll add the amount of hits in this crossing on to
// the global counter. Next time accumulateStripHits() is called it will count the sim hits
// as though they were on the end of this collection.
// Note that this is only used for creating digi-sim links (if configured to do so).
if( simHits.isValid() ) crossingSimHitIndexOffset_[tag.encode()]+=simHits->size();
}
}

Expand Down
15 changes: 14 additions & 1 deletion SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizer.h
Expand Up @@ -59,9 +59,22 @@ namespace cms {

virtual void beginJob() {}
private:
void accumulatePixelHits(edm::Handle<std::vector<PSimHit> >,const TrackerTopology *tTopo);
void accumulatePixelHits(edm::Handle<std::vector<PSimHit> >,
size_t globalSimHitIndex,
const unsigned int tofBin,
const TrackerTopology *tTopo);
bool first;
std::unique_ptr<SiPixelDigitizerAlgorithm> _pixeldigialgo;
/** @brief Offset to add to the index of each sim hit to account for which crossing it's in.
*
* I need to know what each sim hit index will be when the hits from all crossing frames are merged into
* one collection (assuming the MixingModule is configured to create the crossing frame for all sim hits).
* To do this I'll record how many hits were in each crossing, and then add that on to the index for a given
* hit in a given crossing. This assumes that the crossings are processed in the same order here as they are
* put into the crossing frame, which I'm pretty sure is true.<br/>
* The key is the name of the sim hit collection. */
std::map<std::string,size_t> crossingSimHitIndexOffset_;

typedef std::vector<std::string> vstring;
const std::string hitsProducer;
const vstring trackerContainers;
Expand Down