13 #include "CLHEP/Geometry/Point3D.h"
15 #include "GaudiKernel/MsgStream.h"
77 static const double dRcut = 1.0e-7;
78 static const double dTcut = 1.0;
82 double stringFirstTheta = 0.0;
83 double stringFirstPhi = 0.0;
85 double persSumE = 0.0;
86 double transSumE = 0.0;
88 unsigned int endBC = 0;
89 unsigned int endId = 0;
90 unsigned int endHit = 0;
91 HepGeom::Point3D<double> lastTransEnd(0.0, 0.0, 0.0);
92 HepGeom::Point3D<double> lastPersEnd(0.0, 0.0, 0.0);
101 if ( siHit->particleLink().barcode() != lastBarcode || (
idx-endBC)==USHRT_MAX ) {
105 lastBarcode = siHit->particleLink().barcode();
106 persCont->
m_barcode.push_back(lastBarcode);
109 persCont->
m_nBC.push_back(
idx - endBC);
114 if ( ( (
int)siHit->identify() != lastId ) || (
idx-endId)==USHRT_MAX) {
118 lastId = siHit->identify();
119 persCont->
m_id.push_back(lastId);
122 persCont->
m_nId.push_back(
idx - endId);
127 HepGeom::Point3D<double> st = siHit->localStartPosition();
128 HepGeom::Point3D<double>
en = siHit->localEndPosition();
130 const double dx = st.x() - lastTransEnd.x();
131 const double dy = st.y() - lastTransEnd.y();
132 const double dz = st.z() - lastTransEnd.z();
133 const double t = siHit->meanTime();
135 const double dRLast = sqrt(
dx *
dx +
dy *
dy + dz * dz);
136 const double dTLast = fabs(
t - lastT);
138 CLHEP::Hep3Vector direction(0.0, 0.0, 0.0);
141 bool startNewString = (dRLast >= dRcut || dTLast >= dTcut || (
idx - endHit) == USHRT_MAX);
143 if (!startNewString) {
147 direction = CLHEP::Hep3Vector(
en.x() - lastPersEnd.x(),
en.y() - lastPersEnd.y(),
en.z() - lastPersEnd.z() );
149 theta = direction.theta();
155 if ( dTheta_2b < m_2bMaximum && dTheta_2b >= 0 && dPhi_2b < m_2bMaximum && dPhi_2b >= 0) {
156 persCont->
m_dTheta.push_back(dTheta_2b);
157 persCont->
m_dPhi.push_back(dPhi_2b);
163 startNewString =
true;
167 if (startNewString) {
171 direction = CLHEP::Hep3Vector(
en.x() - st.x(),
en.y() - st.y(),
en.z() - st.z() );
173 theta = direction.theta();
185 stringFirstTheta =
theta;
186 stringFirstPhi =
phi;
195 transSumE += siHit->energyLoss();
203 double eneLoss = 0.0;
206 eneLoss = siHit->energyLoss();
227 CLHEP::Hep3Vector persDir(
length, 0.0, 0.0);
228 persDir.setTheta(
theta);
231 lastPersEnd = (CLHEP::Hep3Vector)lastPersEnd + persDir;
238 persCont->
m_nBC.push_back(
idx - endBC);
239 persCont->
m_nId.push_back(
idx - endId);
241 #ifdef ENABLE_SANITY_CHECKS
243 const unsigned int init(0);
244 const unsigned int transContSize = transCont->
size();
246 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;
249 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;
252 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;
259 std::unique_ptr<SiHitCollection> trans(std::make_unique<SiHitCollection>(
"DefaultCollectionName",persObj->
m_nHits.size()));
261 return(trans.release());
265 #ifdef ENABLE_SANITY_CHECKS
271 #ifdef ENABLE_SANITY_CHECKS
273 const unsigned int transContSize = persCont->
m_hitEne_2b.size();
274 const unsigned int init(0);
276 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;
279 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;
282 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;
286 unsigned int hitCount = 0;
287 unsigned int angleCount = 0;
288 unsigned int idxBC = 0;
289 unsigned int idxId = 0;
290 unsigned int idxEne4b = 0;
291 unsigned int idxLen4b = 0;
292 unsigned int endHit = 0;
293 unsigned int endBC = 0;
294 unsigned int endId = 0;
298 for (
unsigned int i = 0;
i < persCont->
m_nHits.size();
i++) {
302 const unsigned int start = endHit;
310 for (
unsigned int j =
start; j < endHit; j++) {
312 if (j >= endBC + persCont->
m_nBC[idxBC])
313 endBC += persCont->
m_nBC[idxBC++];
315 if (j >= endId + persCont->
m_nId[idxId])
316 endId += persCont->
m_nId[idxId++];
318 const double eneLoss_2b = persCont->
m_hitEne_2b[hitCount];
321 const double eneLoss = (eneLoss_2b < m_2bMaximum) ? eneLoss_2b * m_persEneUnit : persCont->
m_hitEne_4b[idxEne4b++];
322 const double length = (hitLength_2b < m_2bMaximum) ? hitLength_2b * m_persLenUnit : persCont->
m_hitLength_4b[idxLen4b++];
324 const double dTheta = (j >
start) ? ((
double)persCont->
m_dTheta[angleCount] - m_2bHalfMaximum) * m_persAngUnit : 0.0;
325 const double dPhi = (j >
start) ? ((
double)persCont->
m_dPhi[angleCount] - m_2bHalfMaximum) * m_persAngUnit : 0.0;
327 const double meanTime =
t0;
328 const double theta = theta0 + dTheta;
331 CLHEP::Hep3Vector
r(
length, 0.0, 0.0);
335 HepGeom::Point3D<double> endThis( endLast +
r );
341 transCont->
Emplace( endLast, endThis, eneLoss, meanTime, partLink, persCont->
m_id[idxId]);
346 if (j >
start) ++angleCount;