9 #include <EVENT/LCEvent.h> 10 #include <IMPL/LCCollectionVec.h> 11 #include <EVENT/Track.h> 12 #include <EVENT/TrackerHit.h> 13 #include <EVENT/TrackerPulse.h> 15 #include "IMPL/TrackImpl.h" 16 #include "IMPL/LCFlagImpl.h" 17 #include <Exceptions.h> 18 #include <UTIL/BitField64.h> 19 #include <UTIL/ILDConf.h> 21 #include "marlin/Global.h" 25 #include <gear/TPCParameters.h> 26 #include <gear/TPCModule.h> 28 #include <gearimpl/Vector3D.h> 34 #include "GlobalFieldProcessor.h" 35 #include "CLHEP/Vector/ThreeVector.h" 55 gblHelperHit::gblHelperHit(
const EVENT::TrackerHit& aHit,
const simpleHelix& refHelix,
const bool milleOut,
const bool enMID,
56 const int milleCalcMethod,
const double phiSeed) :
57 _isMeas(true), _hitPhi(_calcLocalPhi(aHit, enMID, phiSeed)), _isValid(
58 refHelix.getExpectedPlanePos(aHit.getPosition(), _hitPhi + 0.5 * M_PI, _xyPred, _zPred, _s, _seedPhi, _seedLambda)), _eScaled(
59 _calcEScaled(aHit)), _l2M(_getL2M()), _res(_getRes()), _prec(_getPrec(aHit.getCovMatrix())), _numGlobals(0), _globalLab(), _globalDer() {
72 switch (milleCalcMethod) {
112 TMatrixD projectLocalToMeasurement(2, 2);
115 projectLocalToMeasurement[0][1] = 0.;
117 projectLocalToMeasurement[1][1] = cos(
_seedLambda);
119 projectLocalToMeasurement.Invert();
123 return projectLocalToMeasurement;
131 TMatrixDSym precision(2);
132 const double cosPhi = cos(
_hitPhi);
133 const double sinPhi = sin(
_hitPhi);
134 const double varRad = cosPhi * cosPhi * covMatrix[0] + 2. * sinPhi * cosPhi * covMatrix[1] + sinPhi * sinPhi * covMatrix[2];
135 const double varPhi = sinPhi * sinPhi * covMatrix[0] - 2. * sinPhi * cosPhi * covMatrix[1] + cosPhi * cosPhi * covMatrix[2];
136 const double varZ = covMatrix[5];
140 precision[0][0] = varPhi + varRad * derXY * derXY;
141 precision[0][1] = (varRad > 1.0E-6 * varPhi) ? varRad * derXY * derZS : 0.;
142 precision[1][0] = precision[0][1];
143 precision[1][1] = varZ + varRad * derZS * derZS;
145 const double det = precision[0][0] * precision[1][1] - precision[0][1] * precision[1][0];
147 precision.InvertFast();
150 streamlog_out(ERROR) <<
"Singular covariance matrix" << std::endl;
157 TVectorD residuals(2);
171 FloatVec covMatrix = aHit.getCovMatrix();
176 const double trace = covMatrix[0] + covMatrix[2];
177 const double det = covMatrix[0] * covMatrix[2] - covMatrix[1] * covMatrix[1];
179 if (4.0 * det / (trace * trace) < 0.9999) {
183 if (4.0 * det / (trace * trace) < 0.000001) {
185 phiCov = 0.5 * atan2(-2.0 * covMatrix[1], covMatrix[2] - covMatrix[0]);
188 phiCov = 0.5 * atan2(2.0 * covMatrix[1], covMatrix[0] - covMatrix[2]);
191 UTIL::BitField64 encoder(lcio::ILDCellID0::encoder_string);
192 encoder.setValue(aHit.getCellID0());
193 const gear::TPCModule &module =
195 Global::GEAR->getTPCParameters().getModule(encoder[ILDCellID0::module]) :
196 Global::GEAR->getTPCParameters().getNearestModule(aHit.getPosition()[0], aHit.getPosition()[1]);
198 if (module.getLocalPadLayout().getCoordinateType() == gear::PadRowLayout2D::POLAR) {
199 Vector2D correction = module.getOffset();
200 phi = atan2(aHit.getPosition()[1] - correction[1], aHit.getPosition()[0] - correction[0]);
203 phi = module.getAngle() - 0.5 * M_PI;
206 if (abs(phi - phiCov) > 0.00001)
207 streamlog_out(WARNING) <<
" Inconsistent hit direction, check hit errors, use TPCHit_FixErrors_forTracking " << std::endl;
286 const gear::TPCModule &theModule = Global::GEAR->getTPCParameters().getNearestModule(aHit.getPosition()[0],
287 aHit.getPosition()[1]);
288 const int padIndex = theModule.getNearestPad(aHit.getPosition()[0], aHit.getPosition()[1]);
289 const int nModules = Global::GEAR->getTPCParameters().getNModules();
290 const int moduleNum = theModule.getModuleID();
293 const int rowNum = theModule.getRowNumber(padIndex);
294 const int rowLabel = 100 * moduleNum + rowNum + 1;
301 _globalLab.push_back(rowLabel + 100 * nModules);
314 UTIL::BitField64 encoder(lcio::ILDCellID0::encoder_string);
315 encoder.setValue(aHit.getCellID0());
320 const gear::TPCModule &module = Global::GEAR->getTPCParameters().getNearestModule(aHit.getPosition()[0], aHit.getPosition()[1]);
321 int modNum = module.getModuleID();
322 Vector2D correction = module.getOffset();
323 const double xHit = aHit.getPosition()[0] - correction[0];
324 const double yHit = aHit.getPosition()[1] - correction[1];
325 const double zHit = aHit.getPosition()[2];
326 const double phiHit = atan2(yHit, xHit);
328 const double ex = -sin(phiHit);
329 const double ey = cos(phiHit);
340 double tn = tdir[0] * normal[0] + tdir[1] * normal[1] + tdir[2] * normal[2];
342 for (
unsigned int i = 0; i < 3; i++)
343 for (
unsigned int j = 0; j < 3; j++)
344 drdm[i][j] -= tdir[i] * normal[j] / tn;
359 TMatrixD drldrg(3, 3);
369 TMatrixD drldg = drldrg * drdm * dmdg;
373 for (
unsigned int i = 0; i < 6; i++) {
399 const gear::TPCModule &theModule = Global::GEAR->getTPCParameters().getNearestModule(aHit.getPosition()[0],
400 aHit.getPosition()[1]);
401 const int padIndex = theModule.getNearestPad(aHit.getPosition()[0], aHit.getPosition()[1]);
402 const int nModules = Global::GEAR->getTPCParameters().getNModules();
403 const int moduleNum = theModule.getModuleID();
406 const int rowNum = theModule.getRowNumber(padIndex);
407 const int rowLabel = 100 * moduleNum + rowNum + 1;
410 double hitMaxPulseCharge = 0;
411 for (LCObjectVec::const_iterator pulseIter = aHit.getRawHits().begin(); pulseIter < aHit.getRawHits().end(); ++pulseIter) {
412 TrackerPulse
const * pulse =
dynamic_cast<TrackerPulse
const *
>(*pulseIter);
413 if (pulse->getCharge() > hitMaxPulseCharge) {
414 hitMaxPulseCharge = pulse->getCharge();
417 const double lgQ = log10(hitMaxPulseCharge);
424 bin =
static_cast<int>((lgQ - 2) / 2 * 40) + 1;
426 if (bin < 1) bin = 1;
430 _globalLab.push_back(rowLabel + 100 * nModules);
431 _globalLab.push_back(bin + 2 * 100 * nModules);
432 _globalLab.push_back(bin + 2 * 100 * nModules + 100);
450 UTIL::BitField64 encoder(lcio::ILDCellID0::encoder_string);
451 encoder.setValue(aHit.getCellID0());
452 int rowNum = encoder[ILDCellID0::layer];
468 _selectionFlag(true) {
470 unsigned int minHits = milleMinHits;
480 #endif // conditional compilation if GBL program package is available on the system double _calcEScaled(const EVENT::TrackerHit &)
Calculate scaled Edep.
bool _isValid
hit has valid prediction from track
TMatrixDSym _getPrec(FloatVec)
Get precision ( = inverse variance) in measurement system.
const bool isSelected() const
Get selection flag.
void calcTrackDistortions(const EVENT::TrackerHit &aHit)
Fills the global derivatives and labels for distortions studies as function of the row of the hits...
unsigned int getNumGlobals() const
Get number of global derivatives.
gblHelperHit(const EVENT::TrackerHit &, const simpleHelix &, const bool, const bool, const int, const double)
Construct helper hit from TrackerHit.
double _hitPhi
phi of hit (with respect to module offset)
void calcModuleAlignment(const EVENT::TrackerHit &aHit, const TVectorD &tdir)
Fills the global derivatives and labels for module alignment.
unsigned int getNumGlobals() const
Get number of global derivatives.
std::vector< int > _globalLab
labels for global derivatives
double _calcLocalPhi(const EVENT::TrackerHit &, const bool, const double)
Calculate local phi of hit.
double _seedLambda
lambda (ZS direction) from seed track
TVectorD _getRes()
Get residuals (measurement - prediction) in measurement system.
trackerAlcaCalculator()
Construct user-defined trackerAlcaCalculator.
const TMatrixD & getGlobalDerivatives() const
Get global derivatives.
double _xyPred
XY residual (measurement - prediction)
unsigned int _numDer
number of global derivatives
bool _selectionFlag
selction flag
std::vector< int > getGlobalLabels() const
Get labels for global derivatives.
TMatrixD _globalDer
global derivatives
double _seedPhi
phi (XY direction) from seed track
const bool _isMeas
flag for measurements (else reference point)
TMatrixD _globalDer
global derivatives
std::vector< int > _globalLab
labels for global derivatives
const TMatrixD & getGlobalDerivatives() const
Get global derivatives.
void calcHitCharge(const EVENT::TrackerHit &aHit)
Fills the global derivatives and labels for distortions studies as function of the charge of the hits...
TMatrixD _getL2M()
Get transformation matrix.
void calcDr(const EVENT::TrackerHit &aHit, double phi)
Fills the global derivatives and labels for distortions studies as function of the charge of the hits...
std::vector< int > getGlobalLabels() const
Get labels for global derivatives.
User defined class to calculate global derivatives for Millepede-II.
trackerAlcaSelector(const EVENT::Track &, const int)
Construct user-defined trackerAlcaSelector.
unsigned int _numGlobals
number of global derivatives
double _zPred
Z residual (measurement - prediction)