144 {
146
147
148
150
152 m_tree=
new TTree(
"globalChi2Deriv",
"globalChi2Deriv");
164
179 }
180
181
182
183 bool fullVertex = false;
184 AlignVertex * ptrVertex = alignTrack->getVtx();
187 const std::vector<AlignModuleVertexDerivatives> * ptrX = nullptr;
189 if( ptrVertex ) {
190 fullVertex = true;
191 ptrPosition = ptrVertex->position();
192 ptrCovariance = ptrVertex->covariance();
193 ptrX = ptrVertex->derivatives();
194 vtxType = ptrVertex->type();
195
196
198 msg(MSG::ERROR)<<
"something missing from alignVertex!"<<
endmsg;
199 if (!ptrPosition)
msg(MSG::ERROR)<<
"no fitted position!"<<
endmsg;
200 if (!ptrCovariance)
msg(MSG::ERROR)<<
"no covariance!"<<
endmsg;
201 if (!ptrX)
msg(MSG::ERROR)<<
"no link to the X object!"<<
endmsg;
203 return false;
204 }
205 }
206
207
208
209
212
213
215 const Amg::SymMatrixX * ptrWeightsFD = alignTrack->weightMatrixFirstDeriv();
216 const Amg::VectorX * ptrResiduals = alignTrack->residualVector();
217 const std::vector<AlignModuleDerivatives> * ptrDerivs = alignTrack->derivatives();
218
219
220 if (!ptrWeights || !ptrWeightsFD || !ptrResiduals || !ptrDerivs) {
221 msg(MSG::ERROR)<<
"something missing from alignTrack!"<<
endmsg;
222 if (!ptrWeights)
msg(MSG::ERROR)<<
"no weights!"<<
endmsg;
223 if (!ptrWeightsFD)
msg(MSG::ERROR)<<
"no weights for first deriv!"<<
endmsg;
224 if (!ptrResiduals)
msg(MSG::ERROR)<<
"no residuals!"<<
endmsg;
225 if (!ptrDerivs)
msg(MSG::ERROR)<<
"no derivatives!"<<
endmsg;
226 return false;
227 }
228
229
234
235
237 std::vector<AlignModuleDerivatives> derivatives = *ptrDerivs;
238 const std::vector<AlignModuleDerivatives>* derivativeErr = alignTrack->derivativeErr();
239 const std::vector<std::pair<AlignModule*,std::vector<double> > >* secDerivs = alignTrack->actualSecondDerivatives();
240
241
242
243 std::vector<AlignPar*> allAlignPars;
244 std::vector<Amg::VectorX*> allDerivatives;
245 std::vector<const Amg::VectorX*> allDerivativeErr;
246 std::vector<double> allActualSecDeriv;
247 int WSize(weights.cols());
249 matrix_F.setZero();
250
251
252 msg(MSG::DEBUG) <<
"accumulate: The derivative vector size is " << derivatives.size() <<
endmsg;
253 std::vector<AlignModuleDerivatives>::iterator derivIt = derivatives.begin();
254 std::vector<AlignModuleDerivatives>::iterator derivIt_end = derivatives.end();
255
256 std::vector<AlignModuleDerivatives>::const_iterator derivErrIt;
257 std::vector<std::pair<AlignModule*,std::vector<double> > >::const_iterator secDerivIt;
258 if (derivativeErr) derivErrIt=derivativeErr->begin();
259 if (secDerivs) secDerivIt=secDerivs->begin();
260 for ( ; derivIt!=derivIt_end ; ++derivIt) {
261
262
263 AlignModule*
module=derivIt->first;
264
265
266 module->addTrack();
267 ATH_MSG_DEBUG(
"add track to module "<<
module->identify().get_identifier32().get_compact());
268 module->addNDoF(alignTrack->fitQuality()->numberDoF());
269 module->addTrackChi2(alignTrack->fitQuality()->chiSquared());
270
271
275 }
277
278
279 std::vector<Amg::VectorX>& deriv_vec = derivIt->second;
280 ATH_MSG_DEBUG(
"accumulate: The deriv_vec size is " << deriv_vec.size() );
282 int nModPars = alignPars->
size();
283 if (nModPars != (int)deriv_vec.size() && (nModPars+3) != (int)deriv_vec.size()) {
285 return false;
286 }
287 for (
int i=0;
i<3;
i++) {
288 for (int j=0;j<WSize;j++) {
289 matrix_F(i,j) += deriv_vec[nModPars+
i][j];
290 }
291 }
292
293
294 for (
int i=0;
i<nModPars;
i++) {
296 allAlignPars.push_back((*alignPars)[i]);
297 allDerivatives.push_back(&deriv_vec[i]);
298 if (derivativeErr)
299 allDerivativeErr.push_back(&(derivErrIt->second)[i]);
300 if (secDerivs)
301 allActualSecDeriv.push_back((secDerivIt->second)[i]);
302 }
303 if (derivativeErr) ++derivErrIt;
304 if (secDerivs) ++secDerivIt;
305 }
306
307
310 for (; iatsos != iatsos_last; ++iatsos)
311 if ((*iatsos)->module())
312 (*iatsos)->module()->addHit();
313
314
315 int nAllPars = allAlignPars.size();
317 for (int ipar=0;ipar<nAllPars;ipar++) {
318
319
320 Amg::MatrixX derivativesT = (*allDerivatives[ipar]).transpose();
321 ATH_MSG_DEBUG(
"derivativesT (size "<<derivativesT.cols()<<
"): "<<derivativesT);
322
325
326
327 int index1 = allAlignPars[ipar]->index();
328
331 if (firstderivM(0,0)==0.) {
332 ATH_MSG_DEBUG(
"firstderivM[0][0] is zero : "<<firstderivM(0,0));
333 continue;
334 }
335
336
337
338
343 ATH_MSG_DEBUG(
"alActualSecDeriv size: "<<allActualSecDeriv.size());
345 }
347 }
348
349
350 int imodule1 = allAlignPars[ipar]->alignModule()->identifyHash();
351
352
353 bool goodSecondDeriv = true;
354 for (int jpar=ipar;jpar<nAllPars;jpar++) {
355
356
357 int index2=allAlignPars[jpar]->index();
358
359
360 int imodule2 = allAlignPars[jpar]->alignModule()->identifyHash();
361
362
363
365 if (imodule1 != imodule2)
366 continue;
367
370
371
372
373 if (jpar==ipar && secondderivM(0,0)<0.) {
375 }
379 goodSecondDeriv = false;
380 break;
381 }
382
385
386
389 }
390
391
392
393 if (goodSecondDeriv) {
396 }
397 else
399 }
400
401
402
403
404 if( fullVertex ) {
405
406
407 ATH_MSG_DEBUG(
"accumulate: Contribution from the fullVTX will be added " );
408
409 Amg::MatrixX RHM = (*ptrCovariance) * (matrix_F) * (weightsFirstDeriv * residuals);
410
411 std::vector<AlignPar*> vtxAlignPars;
412 std::vector<const Amg::VectorX*> vtxDerivatives;
413
414
415 msg(MSG::DEBUG) <<
"accumulate: The Vertex derivative vector size is " << ptrX->size() <<
endmsg;
416 std::vector<AlignModuleVertexDerivatives>::const_iterator XIt = ptrX->begin();
417 std::vector<AlignModuleVertexDerivatives>::const_iterator XIt_end = ptrX->end();
418
419 for ( ; XIt!=XIt_end ; ++XIt) {
420
421
422 const AlignModule*
module=XIt->first;
423
424
425 const std::vector<Amg::VectorX>& X_vec = XIt->second;
426 msg(MSG::DEBUG) <<
"accumulate: The X_vec size is " << X_vec.size() <<
endmsg;
428 int nModPars = alignPars->
size();
429 if (nModPars != (int)X_vec.size()) {
431 return false;
432 }
433
434
435 for (
int i=0;
i<nModPars;
i++) {
437 vtxAlignPars.push_back((*alignPars)[i]);
438 vtxDerivatives.push_back(&X_vec[i]);
439 }
440
441 }
442
443
444 int ierr(0);
446 Qinv.setZero();
448 vtemp.setZero();
449 if( vtxType==AlignVertex::Refitted && ptrVertex->Constrained() && ptrVertex->Qmatrix()->determinant() > 1.0e-24 ) {
450
451 bool invertible;
452 double determinant;
453 ptrVertex->Qmatrix()->computeInverseAndDetWithCheck(Qinv,determinant,invertible);
454
455 if(!invertible) {
456 std::cout <<"accumulate: Q inversion failed. CLHEP status flag = "<<ierr<< std::endl;
457 return false;
458 }
459 vtemp(0) = -ptrVertex->originalPosition()->x()+(*(ptrVertex->Vvector()))(0);
460 vtemp(1) = -ptrVertex->originalPosition()->y()+(*(ptrVertex->Vvector()))(1);
461 vtemp(2) = -ptrVertex->originalPosition()->z()+(*(ptrVertex->Vvector()))(2);
462 }
463
464
465
466 int nvtxPars = vtxAlignPars.size();
467 for (int ipar=0;ipar<nvtxPars;ipar++) {
468
469
470 Amg::MatrixX derivativesT = (*vtxDerivatives[ipar]).transpose();
472
473
474 if( vtxType==
AlignVertex::Refitted && ptrVertex->Constrained() && ptrVertex->Qmatrix()->determinant() > 1.0e-24 ) {
475 firstderivM += 2.* derivativesT * ((*ptrCovariance) * Qinv) * vtemp;
476 }
477
478
479 int index1 = vtxAlignPars[ipar]->index();
480
482
483
485 ATH_MSG_DEBUG(
"accumulate: Filling second derivative for this vertex... ");
486 for (int jpar=0;jpar<nvtxPars;jpar++) {
487
488
489 Amg::MatrixX secondderivM = -1.* derivativesT * (*ptrCovariance) * (*vtxDerivatives[jpar]);
490
491
492 if( ptrVertex->Constrained() && ptrVertex->Qmatrix()->determinant() > 1.0e-24 ) {
493 secondderivM += 2.* derivativesT * ((*ptrCovariance) * Qinv * (*ptrCovariance)) * (*vtxDerivatives[jpar]);
494 }
495
496
497 int index2=vtxAlignPars[jpar]->index();
498
502 }
503
504 }
506 }
507
509
510 }
511
512 }
513
514
515
516
517
518
520
521
524 if (
sc==StatusCode::SUCCESS) {
527 }
528 else {
531 }
532
535
536 double pT=alignTrack->originalTrack()->perigeeParameters()->pT();
537 double eta=alignTrack->originalTrack()->perigeeParameters()->eta();
540 m_phi=alignTrack->originalTrack()->perigeeParameters()->momentum().phi();
541
542 Amg::Vector3D pos=alignTrack->originalTrack()->perigeeParameters()->position();
546
547 const TrackInfo
info=alignTrack->originalTrack()->info();
555
558 }
559
560
562 m_nmeas += alignTrack->nAlignTSOSMeas();
563 m_nhits += alignTrack->alignTSOSCollection()->size();
564 m_chi2 += alignTrack->fitQuality()->chiSquared();
565 m_nDoF += alignTrack->fitQuality()->numberDoF();
566
569
570 return true;
571 }
Scalar eta() const
pseudorapidity method
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define AmgSymMatrix(dim)
ServiceHandle< StoreGateSvc > & evtStore()
DataModel_detail::iterator< DataVector > iterator
size_type size() const noexcept
Returns the number of elements in the collection.
@ Refitted
normally refitted, without adding any pseudo-measurement
@ Accumulated
accumulated by the GX algorithm.
@ BremFit
A brem fit was performed on this track.
@ StraightTrack
A straight track.
@ HardScatterOrKink
A track with a kink or a hard scatter.
@ LowPtTrack
A LowPt track.
@ BremFitSuccessful
A brem fit was performed on this track and this fit was successful.
@ SlimmedTrack
A slimmed track.
uint32_t runNumber() const
The current event's run number.
uint64_t eventNumber() const
The current event's event number.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > SymMatrixX
Eigen::Matrix< double, 3, 1 > Vector3D
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorX
Dynamic Vector - dynamic allocation.
::StatusCode StatusCode
StatusCode definition for legacy code.
EventInfo_v1 EventInfo
Definition of the latest event info version.
const Identifier & identify(const UncalibratedMeasurement *meas)
Returns the associated identifier from the muon measurement.