14 #include "CLHEP/Geometry/Point3D.h"
16 #include "GaudiKernel/MsgStream.h"
17 #include "GaudiKernel/ThreadLocalContext.h"
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));
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;
211 lastTransEnd = HepGeom::Point3D<double>(
en.x(),
en.y(),
en.z());
212 transSumE += siHit->energyLoss();
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;
256 persCont->
m_nId.push_back(
idx - endId);
258 #ifdef ENABLE_SANITY_CHECKS
260 const unsigned int init(0);
261 const unsigned int transContSize = transCont->
size();
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;
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;
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;
276 std::unique_ptr<SiHitCollection> trans(std::make_unique<SiHitCollection>(
"DefaultCollectionName",persObj->
m_nHits.size()));
278 return(trans.release());
282 #ifdef ENABLE_SANITY_CHECKS
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);
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;
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;
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;
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];
337 const double eneLoss = (eneLoss_2b < m_2bMaximum) ? eneLoss_2b * m_persEneUnit : persCont->
m_hitEne_4b[idxEne4b++];
338 const double length = (hitLength_2b < m_2bMaximum) ? hitLength_2b * m_persLenUnit : persCont->
m_hitLength_4b[idxLen4b++];
340 const double dTheta = (j >
start) ? ((
double)persCont->
m_dTheta[angleCount] - m_2bHalfMaximum) * m_persAngUnit : 0.0;
341 const double dPhi = (j >
start) ? ((
double)persCont->
m_dPhi[angleCount] - m_2bHalfMaximum) * m_persAngUnit : 0.0;
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] );
364 if (j >
start) ++angleCount;