80 static const double dRcut = 1.0e-7;
81 static const double dTcut = 1.0;
87 double stringFirstTheta = 0.0;
88 double stringFirstPhi = 0.0;
90 double persSumE = 0.0;
91 double transSumE = 0.0;
93 unsigned int endTruthID = 0;
94 unsigned int endId = 0;
95 unsigned int endHit = 0;
96 HepGeom::Point3D<double> lastTransEnd(0.0, 0.0, 0.0);
97 HepGeom::Point3D<double> lastPersEnd(0.0, 0.0, 0.0);
103 const int truthId = currentLink->
id();
111 if ( lastTruthId != truthId || lastIndex !=
index || (idx-endTruthID)==USHRT_MAX ) {
112 lastTruthId = truthId;
114 const unsigned short persIndex =
static_cast<unsigned short>(
index);
116 log << MSG::WARNING <<
"Attempting to persistify an eventIndex larger than max unsigned short!" <<
endmsg;
120 persCont->
m_truthID.push_back(
static_cast<unsigned long>(truthId));
124 persCont->
m_nTruthID.push_back(idx - endTruthID);
129 if ( ( (
int)siHit->identify() != lastId ) || (idx-endId)==USHRT_MAX) {
134 lastId = siHit->identify();
135 persCont->
m_id.push_back(lastId);
138 persCont->
m_nId.push_back(idx - endId);
143 HepGeom::Point3D<double> st = siHit->localStartPosition();
144 HepGeom::Point3D<double> en = siHit->localEndPosition();
146 const double dx = st.x() - lastTransEnd.x();
147 const double dy = st.y() - lastTransEnd.y();
148 const double dz = st.z() - lastTransEnd.z();
149 const double t = siHit->meanTime();
151 const double dRLast = sqrt(dx * dx + dy * dy + dz * dz);
152 const double dTLast = fabs(t - lastT);
154 CLHEP::Hep3Vector direction(0.0, 0.0, 0.0);
157 bool startNewString = (dRLast >= dRcut || dTLast >= dTcut || (idx - endHit) == USHRT_MAX);
159 if (!startNewString) {
163 direction = CLHEP::Hep3Vector( en.x() - lastPersEnd.x(), en.y() - lastPersEnd.y(), en.z() - lastPersEnd.z() );
165 theta = direction.theta();
171 if ( dTheta_2b < m_2bMaximum && dTheta_2b >= 0 && dPhi_2b < m_2bMaximum && dPhi_2b >= 0) {
172 persCont->
m_dTheta.push_back(dTheta_2b);
173 persCont->
m_dPhi.push_back(dPhi_2b);
179 startNewString =
true;
183 if (startNewString) {
187 direction = CLHEP::Hep3Vector( en.x() - st.x(), en.y() - st.y(), en.z() - st.z() );
189 theta = direction.theta();
199 lastPersEnd = HepGeom::Point3D<double>(st.x(), st.y(), st.z());
201 stringFirstTheta =
theta;
202 stringFirstPhi =
phi;
205 persCont->
m_nHits.push_back(idx - endHit);
210 lastTransEnd = HepGeom::Point3D<double>(en.x(), en.y(), en.z());
211 transSumE += siHit->energyLoss();
213 const int eneLoss_2b = (int)((transSumE - persSumE) /
m_persEneUnit + 0.5);
216 const int hitLength_2b = (int)(direction.mag() /
m_persLenUnit + 0.5);
219 double eneLoss = 0.0;
222 eneLoss = siHit->energyLoss();
243 CLHEP::Hep3Vector persDir(
length, 0.0, 0.0);
244 persDir.setTheta(
theta);
247 lastPersEnd = (CLHEP::Hep3Vector)lastPersEnd + persDir;
254 persCont->
m_nTruthID.push_back(idx - endTruthID);
255 persCont->
m_nId.push_back(idx - endId);
256 persCont->
m_nHits.push_back(idx - endHit);
257#ifdef ENABLE_SANITY_CHECKS
259 const unsigned int init(0);
260 const unsigned int transContSize = transCont->
size();
261 if (std::accumulate(persCont->
m_nTruthID.begin(), persCont->
m_nTruthID.end(), init)!=transContSize) {
262 log << MSG::ERROR <<
"transToPers: sum of entries of persCont->m_nTruthID (" << std::accumulate(persCont->
m_nTruthID.begin(), persCont->
m_nTruthID.end(), init) <<
") does not match transient container size = " << transContSize <<
endmsg;
264 if (std::accumulate(persCont->
m_nId.begin(), persCont->
m_nId.end(), init)!=transContSize) {
265 log << MSG::ERROR <<
"transToPers: sum of entries of persCont->m_nId (" << std::accumulate(persCont->
m_nId.begin(), persCont->
m_nId.end(), init) <<
") does not match transient container size = " << transContSize <<
endmsg;
267 if (std::accumulate(persCont->
m_nHits.begin(), persCont->
m_nHits.end(), init)!=transContSize) {
268 log << MSG::ERROR <<
"transToPers: sum of entries of persCont->m_nHits (" << std::accumulate(persCont->
m_nHits.begin(), persCont->
m_nHits.end(), init) <<
") does not match transient container size = " << transContSize <<
endmsg;
287 const EventContext& ctx = Gaudi::Hive::currentContext();
288#ifdef ENABLE_SANITY_CHECKS
290 const unsigned int transContSize = persCont->
m_hitEne_2b.size();
291 const unsigned int init(0);
292 if (std::accumulate(persCont->
m_nTruthID.begin(), persCont->
m_nTruthID.end(), init)!=transContSize) {
293 log << MSG::ERROR <<
"persToTrans: sum of entries of persCont->m_nTruthID (" << std::accumulate(persCont->
m_nTruthID.begin(), persCont->
m_nTruthID.end(), init) <<
") does not match transient container size = " << transContSize <<
endmsg;
295 if (std::accumulate(persCont->
m_nId.begin(), persCont->
m_nId.end(), init)!=transContSize) {
296 log << MSG::ERROR <<
"persToTrans: sum of entries of persCont->m_nId (" << std::accumulate(persCont->
m_nId.begin(), persCont->
m_nId.end(), init) <<
") does not match transient container size = " << transContSize <<
endmsg;
298 if (std::accumulate(persCont->
m_nHits.begin(), persCont->
m_nHits.end(), init)!=transContSize) {
299 log << MSG::ERROR <<
"persToTrans: sum of entries of persCont->m_nHits (" << std::accumulate(persCont->
m_nHits.begin(), persCont->
m_nHits.end(), init) <<
") does not match transient container size = " << transContSize <<
endmsg;
303 unsigned int hitCount = 0;
304 unsigned int angleCount = 0;
305 unsigned int idxTruthID = 0;
306 unsigned int idxId = 0;
307 unsigned int idxEne4b = 0;
308 unsigned int idxLen4b = 0;
309 unsigned int endHit = 0;
310 unsigned int endTruthID = 0;
311 unsigned int endId = 0;
313 for (
unsigned int i = 0; i < persCont->
m_nHits.size(); i++) {
317 const unsigned int start = endHit;
318 endHit += persCont->
m_nHits[i];
325 for (
unsigned int j = start; j < endHit; j++) {
327 if (j >= endTruthID + persCont->
m_nTruthID[idxTruthID])
328 endTruthID += persCont->
m_nTruthID[idxTruthID++];
330 if (j >= endId + persCont->
m_nId[idxId])
331 endId += persCont->
m_nId[idxId++];
333 const double eneLoss_2b = persCont->
m_hitEne_2b[hitCount];
342 const double meanTime =
t0;
343 const double theta = theta0 + dTheta;
346 CLHEP::Hep3Vector
r(
length, 0.0, 0.0);
350 HepGeom::Point3D<double> endThis( endLast +
r );
358 transCont->
Emplace( endLast, endThis, eneLoss, meanTime, partLink, persCont->
m_id[idxId] );
360 endLast = std::move(endThis);
363 if (j > start) ++angleCount;
static EBC_SUPPRESSED_TRUTH truthSuppressionTypeFromChar(char suppChar)
Translate truth suppression char ('a'..'b') to an enum.
a link optimized in size for a GenParticle in a McEventCollection
int id() const
Return the id of the target particle.
char getTruthSuppressionTypeAsChar() const
Return whether the truth particle has been suppressed, as a char ('a'..'b').
index_type eventIndex() const
Return the event number of the referenced GenEvent.
static std::vector< index_type > getEventPositionInCollection(index_type index, IProxyDict *sg)
Return a vector of the positions in the McEventCollection of the GenEvent(s) with a given event numbe...
void setTruthSuppressionType(EBC_SUPPRESSED_TRUTH truthSupp)
Return whether the truth particle has been suppressed.
Some out-of-line helpers for ExtendedEventContext.