14 #include "CLHEP/Geometry/Point3D.h"
16 #include "GaudiKernel/MsgStream.h"
17 #include "GaudiKernel/ThreadLocalContext.h"
81 static const double dRcut = 1.0e-7;
82 static const double dTcut = 1.0;
84 const EventContext& ctx = Gaudi::Hive::currentContext();
89 double stringFirstTheta = 0.0;
90 double stringFirstPhi = 0.0;
92 double persSumE = 0.0;
93 double transSumE = 0.0;
95 unsigned int endBC = 0;
96 unsigned int endId = 0;
97 unsigned int endHit = 0;
98 HepGeom::Point3D<double> lastTransEnd(0.0, 0.0, 0.0);
99 HepGeom::Point3D<double> lastPersEnd(0.0, 0.0, 0.0);
112 if ( lastBarcode !=
barcode || lastIndex !=
index || (
idx-endBC)==USHRT_MAX ) {
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_barcode.push_back(
static_cast<unsigned long>(lastBarcode));
126 persCont->
m_nBC.push_back(
idx - endBC);
131 if ( ( (
int)siHit->identify() != lastId ) || (
idx-endId)==USHRT_MAX) {
136 lastId = siHit->identify();
137 persCont->
m_id.push_back(lastId);
140 persCont->
m_nId.push_back(
idx - endId);
145 HepGeom::Point3D<double> st = siHit->localStartPosition();
146 HepGeom::Point3D<double>
en = siHit->localEndPosition();
148 const double dx = st.x() - lastTransEnd.x();
149 const double dy = st.y() - lastTransEnd.y();
150 const double dz = st.z() - lastTransEnd.z();
151 const double t = siHit->meanTime();
153 const double dRLast = sqrt(
dx *
dx +
dy *
dy + dz * dz);
154 const double dTLast = fabs(
t - lastT);
156 CLHEP::Hep3Vector direction(0.0, 0.0, 0.0);
159 bool startNewString = (dRLast >= dRcut || dTLast >= dTcut || (
idx - endHit) == USHRT_MAX);
161 if (!startNewString) {
165 direction = CLHEP::Hep3Vector(
en.x() - lastPersEnd.x(),
en.y() - lastPersEnd.y(),
en.z() - lastPersEnd.z() );
167 theta = direction.theta();
173 if ( dTheta_2b < m_2bMaximum && dTheta_2b >= 0 && dPhi_2b < m_2bMaximum && dPhi_2b >= 0) {
174 persCont->
m_dTheta.push_back(dTheta_2b);
175 persCont->
m_dPhi.push_back(dPhi_2b);
181 startNewString =
true;
185 if (startNewString) {
189 direction = CLHEP::Hep3Vector(
en.x() - st.x(),
en.y() - st.y(),
en.z() - st.z() );
191 theta = direction.theta();
201 lastPersEnd = HepGeom::Point3D<double>(st.x(), st.y(), st.z());
203 stringFirstTheta =
theta;
204 stringFirstPhi =
phi;
212 lastTransEnd = HepGeom::Point3D<double>(
en.x(),
en.y(),
en.z());
213 transSumE += siHit->energyLoss();
221 double eneLoss = 0.0;
224 eneLoss = siHit->energyLoss();
245 CLHEP::Hep3Vector persDir(
length, 0.0, 0.0);
246 persDir.setTheta(
theta);
249 lastPersEnd = (CLHEP::Hep3Vector)lastPersEnd + persDir;
256 persCont->
m_nBC.push_back(
idx - endBC);
257 persCont->
m_nId.push_back(
idx - endId);
259 #ifdef ENABLE_SANITY_CHECKS
261 const unsigned int init(0);
262 const unsigned int transContSize = transCont->
size();
264 log << MSG::ERROR <<
"transToPers: sum of entries of persCont->m_nBC (" <<
std::accumulate(persCont->
m_nBC.begin(), persCont->
m_nBC.end(),
init) <<
") does not match transient container size = " << transContSize <<
endmsg;
267 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;
270 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;
277 std::unique_ptr<SiHitCollection> trans(std::make_unique<SiHitCollection>(
"DefaultCollectionName",persObj->
m_nHits.size()));
279 return(trans.release());
283 #ifdef ENABLE_SANITY_CHECKS
289 const EventContext& ctx = Gaudi::Hive::currentContext();
290 #ifdef ENABLE_SANITY_CHECKS
292 const unsigned int transContSize = persCont->
m_hitEne_2b.size();
293 const unsigned int init(0);
295 log << MSG::ERROR <<
"persToTrans: sum of entries of persCont->m_nBC (" <<
std::accumulate(persCont->
m_nBC.begin(), persCont->
m_nBC.end(),
init) <<
") does not match transient container size = " << transContSize <<
endmsg;
298 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;
301 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;
305 unsigned int hitCount = 0;
306 unsigned int angleCount = 0;
307 unsigned int idxBC = 0;
308 unsigned int idxId = 0;
309 unsigned int idxEne4b = 0;
310 unsigned int idxLen4b = 0;
311 unsigned int endHit = 0;
312 unsigned int endBC = 0;
313 unsigned int endId = 0;
315 for (
unsigned int i = 0;
i < persCont->
m_nHits.size();
i++) {
319 const unsigned int start = endHit;
327 for (
unsigned int j =
start; j < endHit; j++) {
329 if (j >= endBC + persCont->
m_nBC[idxBC])
330 endBC += persCont->
m_nBC[idxBC++];
332 if (j >= endId + persCont->
m_nId[idxId])
333 endId += persCont->
m_nId[idxId++];
335 const double eneLoss_2b = persCont->
m_hitEne_2b[hitCount];
338 const double eneLoss = (eneLoss_2b < m_2bMaximum) ? eneLoss_2b * m_persEneUnit : persCont->
m_hitEne_4b[idxEne4b++];
339 const double length = (hitLength_2b < m_2bMaximum) ? hitLength_2b * m_persLenUnit : persCont->
m_hitLength_4b[idxLen4b++];
341 const double dTheta = (j >
start) ? ((
double)persCont->
m_dTheta[angleCount] - m_2bHalfMaximum) * m_persAngUnit : 0.0;
342 const double dPhi = (j >
start) ? ((
double)persCont->
m_dPhi[angleCount] - m_2bHalfMaximum) * m_persAngUnit : 0.0;
344 const double meanTime =
t0;
345 const double theta = theta0 + dTheta;
348 CLHEP::Hep3Vector
r(
length, 0.0, 0.0);
352 HepGeom::Point3D<double> endThis( endLast +
r );
362 transCont->
Emplace( endLast, endThis, eneLoss, meanTime, partLink, persCont->
m_id[idxId]);
367 if (j >
start) ++angleCount;