80 static const double dRcut = 1.0e-7;
81 static const double dTcut = 1.0;
83 const EventContext& ctx = Gaudi::Hive::currentContext();
88 double stringFirstTheta = 0.0;
89 double stringFirstPhi = 0.0;
91 double persSumE = 0.0;
92 double transSumE = 0.0;
94 unsigned int endTruthID = 0;
95 unsigned int endId = 0;
96 unsigned int endHit = 0;
97 HepGeom::Point3D<double> lastTransEnd(0.0, 0.0, 0.0);
98 HepGeom::Point3D<double> lastPersEnd(0.0, 0.0, 0.0);
104 const int truthId = currentLink->
id();
112 if ( lastTruthId != truthId || lastIndex !=
index || (idx-endTruthID)==USHRT_MAX ) {
113 lastTruthId = truthId;
115 const unsigned short persIndex =
static_cast<unsigned short>(
index);
117 log << MSG::WARNING <<
"Attempting to persistify an eventIndex larger than max unsigned short!" <<
endmsg;
121 persCont->
m_truthID.push_back(
static_cast<unsigned long>(truthId));
125 persCont->
m_nTruthID.push_back(idx - endTruthID);
130 if ( ( (
int)siHit->identify() != lastId ) || (idx-endId)==USHRT_MAX) {
135 lastId = siHit->identify();
136 persCont->
m_id.push_back(lastId);
139 persCont->
m_nId.push_back(idx - endId);
144 HepGeom::Point3D<double> st = siHit->localStartPosition();
145 HepGeom::Point3D<double> en = siHit->localEndPosition();
147 const double dx = st.x() - lastTransEnd.x();
148 const double dy = st.y() - lastTransEnd.y();
149 const double dz = st.z() - lastTransEnd.z();
150 const double t = siHit->meanTime();
152 const double dRLast = sqrt(dx * dx + dy * dy + dz * dz);
153 const double dTLast = fabs(t - lastT);
155 CLHEP::Hep3Vector direction(0.0, 0.0, 0.0);
158 bool startNewString = (dRLast >= dRcut || dTLast >= dTcut || (idx - endHit) == USHRT_MAX);
160 if (!startNewString) {
164 direction = CLHEP::Hep3Vector( en.x() - lastPersEnd.x(), en.y() - lastPersEnd.y(), en.z() - lastPersEnd.z() );
166 theta = direction.theta();
172 if ( dTheta_2b < m_2bMaximum && dTheta_2b >= 0 && dPhi_2b < m_2bMaximum && dPhi_2b >= 0) {
173 persCont->
m_dTheta.push_back(dTheta_2b);
174 persCont->
m_dPhi.push_back(dPhi_2b);
180 startNewString =
true;
184 if (startNewString) {
188 direction = CLHEP::Hep3Vector( en.x() - st.x(), en.y() - st.y(), en.z() - st.z() );
190 theta = direction.theta();
200 lastPersEnd = HepGeom::Point3D<double>(st.x(), st.y(), st.z());
202 stringFirstTheta =
theta;
203 stringFirstPhi =
phi;
206 persCont->
m_nHits.push_back(idx - endHit);
211 lastTransEnd = HepGeom::Point3D<double>(en.x(), en.y(), en.z());
212 transSumE += siHit->energyLoss();
214 const int eneLoss_2b = (int)((transSumE - persSumE) /
m_persEneUnit + 0.5);
217 const int hitLength_2b = (int)(direction.mag() /
m_persLenUnit + 0.5);
220 double eneLoss = 0.0;
223 eneLoss = siHit->energyLoss();
244 CLHEP::Hep3Vector persDir(
length, 0.0, 0.0);
245 persDir.setTheta(
theta);
248 lastPersEnd = (CLHEP::Hep3Vector)lastPersEnd + persDir;
255 persCont->
m_nTruthID.push_back(idx - endTruthID);
256 persCont->
m_nId.push_back(idx - endId);
257 persCont->
m_nHits.push_back(idx - endHit);
258#ifdef ENABLE_SANITY_CHECKS
260 const unsigned int init(0);
261 const unsigned int transContSize = transCont->
size();
262 if (std::accumulate(persCont->
m_nTruthID.begin(), persCont->
m_nTruthID.end(), init)!=transContSize) {
263 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;
265 if (std::accumulate(persCont->
m_nId.begin(), persCont->
m_nId.end(), init)!=transContSize) {
266 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;
268 if (std::accumulate(persCont->
m_nHits.begin(), persCont->
m_nHits.end(), init)!=transContSize) {
269 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;
288 const EventContext& ctx = Gaudi::Hive::currentContext();
289#ifdef ENABLE_SANITY_CHECKS
291 const unsigned int transContSize = persCont->
m_hitEne_2b.size();
292 const unsigned int init(0);
293 if (std::accumulate(persCont->
m_nTruthID.begin(), persCont->
m_nTruthID.end(), init)!=transContSize) {
294 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;
296 if (std::accumulate(persCont->
m_nId.begin(), persCont->
m_nId.end(), init)!=transContSize) {
297 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;
299 if (std::accumulate(persCont->
m_nHits.begin(), persCont->
m_nHits.end(), init)!=transContSize) {
300 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;
304 unsigned int hitCount = 0;
305 unsigned int angleCount = 0;
306 unsigned int idxTruthID = 0;
307 unsigned int idxId = 0;
308 unsigned int idxEne4b = 0;
309 unsigned int idxLen4b = 0;
310 unsigned int endHit = 0;
311 unsigned int endTruthID = 0;
312 unsigned int endId = 0;
314 for (
unsigned int i = 0; i < persCont->
m_nHits.size(); i++) {
318 const unsigned int start = endHit;
319 endHit += persCont->
m_nHits[i];
326 for (
unsigned int j = start; j < endHit; j++) {
328 if (j >= endTruthID + persCont->
m_nTruthID[idxTruthID])
329 endTruthID += persCont->
m_nTruthID[idxTruthID++];
331 if (j >= endId + persCont->
m_nId[idxId])
332 endId += persCont->
m_nId[idxId++];
334 const double eneLoss_2b = persCont->
m_hitEne_2b[hitCount];
343 const double meanTime =
t0;
344 const double theta = theta0 + dTheta;
347 CLHEP::Hep3Vector
r(
length, 0.0, 0.0);
351 HepGeom::Point3D<double> endThis( endLast +
r );
359 transCont->
Emplace( endLast, endThis, eneLoss, meanTime, partLink, persCont->
m_id[idxId] );
361 endLast = std::move(endThis);
364 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.
static std::vector< index_type > getEventPositionInCollection(index_type index, const IProxyDict *sg)
Return a vector of the positions in the McEventCollection of the GenEvent(s) with a given event numbe...
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.
void setTruthSuppressionType(EBC_SUPPRESSED_TRUTH truthSupp)
Return whether the truth particle has been suppressed.