133 {
134 std::cout<<"main"<<std::endl;
135 gRandom->SetSeed(14);
136
137
138 const unsigned int nEvents = 100;
139 const unsigned int nMeasurements = 56;
140 const double BField = 15.;
142 const double theta = 120;
143 const double thetaDetPlane = 90;
144 const double phiDetPlane = 0;
145 const double pointDist = 5;
146 const double resolution = 0.02;
147
148 const double resolutionWire = 5*resolution;
149 const TVector3 wireDir(0,0,1);
150 const double skewAngle(5);
151 const bool useSkew = true;
152 const int nSuperLayer = 10;
153 const double minDrift = 0.;
154 const double maxDrift = 2;
155 const bool idealLRResolution = false;
156
157 const double outlierProb = -0.1;
158 const double outlierRange = 2;
159
160 const double hitSwitchProb = -0.1;
161
162 const int splitTrack = -5;
163 const bool fullMeasurement = false;
164
166
167
168
169
170
171
172
173
174
176
177
178 const int nIter = 20;
179 const double dPVal = 1.E-3;
180
181 const bool resort = true;
182 const bool prefit = false;
183 const bool refit = false;
184
185 const bool twoReps = false;
186
188
189 const bool smearPosMom = true;
190 const double chargeSwitchProb = -0.1;
191 const double posSmear = 10*resolution;
192 const double momSmear = 5. /180.*TMath::Pi();
193 const double momMagSmear = 0.2;
194 const double zSmearFac = 2;
195
196
197 const bool matFX = false;
198
199 const bool debug =
false;
200 const bool onlyDisplayFailed = true;
201
202 std::vector<genfit::eMeasurementType> measurementTypes;
209 for (
unsigned int i = 0;
i<50; ++
i)
211
212
214
215
217 switch (fitterId) {
220 fitter->setMultipleMeasurementHandling(mmHandling);
221 break;
222
225 fitter->setMultipleMeasurementHandling(mmHandling);
226 break;
227
230 break;
233 break;
234 }
235 fitter->setMaxIterations(nIter);
236 if (debug)
238
239
240
241
242
243
244
245
246
247
248
264
265
266
267 new TGeoManager("Geometry", "Geane geometry");
268 TGeoManager::Import("genfitGeom.root");
272
273 const double charge = TDatabasePDG::Instance()->GetParticle(pdg)->Charge()/(3.);
274
275
276#ifndef VALGRIND
279#endif
280
281
282#ifndef VALGRIND
283
284 gROOT->SetStyle("Plain");
285 gStyle->SetPalette(1);
286 gStyle->SetOptFit(1111);
287
288 TH1D *hmomRes = new TH1D("hmomRes","mom res",500,-10*resolution*momentum/nMeasurements,10*resolution*momentum/nMeasurements);
289 TH1D *hupRes = new TH1D("hupRes","u' res",500,-5*resolution/nMeasurements, 5*resolution/nMeasurements);
290 TH1D *hvpRes = new TH1D("hvpRes","v' res",500,-5*resolution/nMeasurements, 5*resolution/nMeasurements);
291 TH1D *huRes = new TH1D("huRes","u res",500,-5*resolution, 5*resolution);
292 TH1D *hvRes = new TH1D("hvRes","v res",500,-5*resolution, 5*resolution);
293
294 TH1D *hqopPu = new TH1D("hqopPu","q/p pull",200,-6.,6.);
295 TH1D *pVal = new TH1D("pVal","p-value",100,0.,1.00000001);
296 pVal->SetMinimum(0);
297 TH1D *hupPu = new TH1D("hupPu","u' pull",200,-6.,6.);
298 TH1D *hvpPu = new TH1D("hvpPu","v' pull",200,-6.,6.);
299 TH1D *huPu = new TH1D("huPu","u pull",200,-6.,6.);
300 TH1D *hvPu = new TH1D("hvPu","v pull",200,-6.,6.);
301
302 TH1D *weights = new TH1D("weights","Daf vs true weights",500,-1.01,1.01);
303
304 TH1D *trackLenRes = new TH1D("trackLenRes","(trueLen - FittedLen) / trueLen",500,-0.01,0.01);
305#endif
306
307 double maxWeight(0);
308 unsigned int nTotalIterConverged(0);
309 unsigned int nTotalIterNotConverged(0);
310 unsigned int nTotalIterSecondConverged(0);
311 unsigned int nTotalIterSecondNotConverged(0);
312 unsigned int nConvergedFits(0);
313 unsigned int nUNConvergedFits(0);
314 unsigned int nConvergedFitsSecond(0);
315 unsigned int nUNConvergedFitsSecond(0);
316
317
319
322
323
325
326
327
328
329
330
331 if (debug || (iEvent)%10==0)
332 std::cout <<
"Event Nr. " <<
iEvent <<
" ";
333 else std::cout << ". ";
334 if (debug || (iEvent+1)%10==0)
335 std::cout << "\n";
336
337
338
341 delete secondTrack;
342 secondTrack = NULL;
343
344
345
346 TVector3
pos(0, 0, 0);
347 TVector3
mom(1.,0,0);
348 mom.SetPhi(gRandom->Uniform(0.,2*TMath::Pi()));
349
350 mom.SetTheta(theta*TMath::Pi()/180);
351 mom.SetMag(momentum);
352 TMatrixDSym covM(6);
353 for (
int i = 0;
i < 3; ++
i)
354 covM(i,i) = resolution*resolution;
355 for (
int i = 3;
i < 6; ++
i)
356 covM(i,i) = pow(resolution / nMeasurements / sqrt(3), 2);
357
358 if (debug) {
359 std::cout << "start values \n";
362 }
363
364
367
368
369 TVector3 posM(pos);
370 TVector3 momM(mom);
371 if (smearPosMom) {
372 posM.SetX(gRandom->Gaus(posM.X(),posSmear));
373 posM.SetY(gRandom->Gaus(posM.Y(),posSmear));
374 posM.SetZ(gRandom->Gaus(posM.Z(),zSmearFac*posSmear));
375
376 momM.SetPhi(gRandom->Gaus(
mom.Phi(),momSmear));
377 momM.SetTheta(gRandom->Gaus(
mom.Theta(),momSmear));
378 momM.SetMag(gRandom->Gaus(
mom.Mag(), momMagSmear*
mom.Mag()));
379 }
380
381
382
383 double sign(1.);
384 if (chargeSwitchProb > gRandom->Uniform(1.))
385 sign = -1.;
387 sign = 1.;
388 if (chargeSwitchProb > gRandom->Uniform(1.))
389 sign = -1.;
393
394
397
398
399
401
402
404
405
406 std::vector< std::vector<genfit::AbsMeasurement*> > measurements;
407
408 std::vector<bool> outlierTrue;
409 bool outlier;
410
411 std::vector<int> leftRightTrue;
412 int lr;
413
414 double trueLen;
415
416 try{
417 for (
unsigned int i=0;
i<measurementTypes.size(); ++
i){
418 trueLen =
i*pointDist;
419
420 measurements.push_back(measurementCreator.
create(measurementTypes[i], trueLen, outlier, lr));
421 outlierTrue.push_back(outlier);
422 leftRightTrue.push_back(lr);
423 }
424 assert(measurementTypes.size() == leftRightTrue.size());
425 assert(measurementTypes.size() == outlierTrue.size());
426 }
428 std::cerr<<"Exception, next track"<<std::endl;
429 std::cerr << e.
what();
430 continue;
431 }
432
433 if (debug) std::cout << "... done creating measurements \n";
434
435
436
437
438 TVectorD seedState(6);
439 TMatrixDSym seedCov(6);
443 if (twoReps) {
445 secondTrack->addTrackRep(secondRep->
clone());
446 }
447 else
448 delete secondRep;
449
450
451 assert(
fitTrack->checkConsistency());
452
453
454
455 for(
unsigned int i=0;
i<measurements.size(); ++
i){
456 if (splitTrack > 0 && (int)i >= splitTrack)
457 break;
458 if (i>0 && hitSwitchProb > gRandom->Uniform(1.))
460 else
462
463 assert(
fitTrack->checkConsistency());
464
465 }
466
467 if (splitTrack > 0) {
468 for(
unsigned int i=splitTrack;
i<measurements.size(); ++
i){
469 if (i>0 && hitSwitchProb > gRandom->Uniform(1.))
471 else
473
474
475 }
476 }
477
478 assert(
fitTrack->checkConsistency());
479 assert(secondTrack->checkConsistency());
480
481
482
483
484 try{
485 if (debug) std::cout<<"Starting the fitter"<<std::endl;
486
487 if (prefit) {
490 prefitter.processTrackWithRep(fitTrack,
fitTrack->getCardinalRep());
491 }
492
493 fitter->processTrack(fitTrack, resort);
494 if (splitTrack > 0)
495 fitter->processTrack(secondTrack, resort);
496
497 if (debug) std::cout<<"fitter is finished!"<<std::endl;
498 }
500 std::cerr << e.
what();
501 std::cerr << "Exception, next track" << std::endl;
502 continue;
503 }
504
505 if (splitTrack > 0) {
507 if (debug) secondTrack->Print("C");
508
509 if (fullMeasurement) {
512 }
513 else
515
517
518 try{
519 if (debug) std::cout<<"Starting the fitter"<<std::endl;
520 fitter->processTrack(fitTrack, resort);
521 if (debug) std::cout<<"fitter is finished!"<<std::endl;
522 }
524 std::cerr << e.
what();
525 std::cerr << "Exception, next track" << std::endl;
526 continue;
527 }
528 }
529
530
531 if (refit && !
fitTrack->getFitStatus(rep)->isFitConverged()) {
532 std::cout<<"Trying to fit again "<<std::endl;
533 fitter->processTrack(fitTrack, resort);
534 }
535
536
537
538 if (debug) {
540 fitTrack->getFitStatus(rep)->Print();
541 }
542
543 assert(
fitTrack->checkConsistency());
544 assert(secondTrack->checkConsistency());
545
546#ifndef VALGRIND
547 if (!onlyDisplayFailed && iEvent < 1000)
549 else if (onlyDisplayFailed &&
550 (!
fitTrack->getFitStatus(rep)->isFitConverged() ||
551 fitTrack->getFitStatus(rep)->getPVal() < 0.01)) {
552
554 }
555#endif
556
557
558 if (
fitTrack->getFitStatus(rep)->isFitConverged()) {
560 nConvergedFits += 1;
561 }
562 else {
564 nUNConvergedFits += 1;
565 }
566
567 if (twoReps) {
568 if (
fitTrack->getFitStatus(secondRep)->isFitConverged()) {
570 nConvergedFitsSecond += 1;
571 }
572 else {
574 nUNConvergedFitsSecond += 1;
575 }
576 }
577
578
579
580 if (!
fitTrack->getFitStatus(rep)->isFitConverged()) {
581 std::cout << "Track could not be fitted successfully! Fit is not converged! \n";
582 continue;
583 }
584
585
587 if (tp == NULL) {
588 std::cout << "Track has no TrackPoint with fitterInfo! \n";
589 continue;
590 }
592 if (debug) {
593 std::cout << "state before extrapolating back to reference plane \n";
594 kfsop.Print();
595 }
596
597
598 try{
600 }
602 std::cerr<<"Exception, next track"<<std::endl;
603 std::cerr << e.
what();
604 continue;
605 }
606
607#ifndef VALGRIND
608
609 const TVectorD& referenceState = stateRefOrig.getState();
610
611 const TVectorD& state = kfsop.getState();
612 const TMatrixDSym& cov = kfsop.getCov();
613
614 double pval =
fitter->getPVal(fitTrack, rep);
616
617 hmomRes->Fill( (charge/state[0]-momentum));
618 hupRes->Fill( (state[1]-referenceState[1]));
619 hvpRes->Fill( (state[2]-referenceState[2]));
620 huRes->Fill( (state[3]-referenceState[3]));
621 hvRes->Fill( (state[4]-referenceState[4]));
622
623 hqopPu->Fill( (state[0]-referenceState[0]) / sqrt(cov[0][0]) );
624 pVal->Fill( pval);
625 hupPu->Fill( (state[1]-referenceState[1]) / sqrt(cov[1][1]) );
626 hvpPu->Fill( (state[2]-referenceState[2]) / sqrt(cov[2][2]) );
627 huPu->Fill( (state[3]-referenceState[3]) / sqrt(cov[3][3]) );
628 hvPu->Fill( (state[4]-referenceState[4]) / sqrt(cov[4][4]) );
629
630
631 try {
632 trackLenRes->Fill( (trueLen -
fitTrack->getTrackLen(rep)) / trueLen );
633
634 if (debug) {
635 std::cout <<
"true track length = " << trueLen <<
"; fitted length = " <<
fitTrack->getTrackLen(rep) <<
"\n";
636 std::cout <<
"fitted tof = " <<
fitTrack->getTOF(rep) <<
" ns\n";
637 }
638 }
640 std::cerr << e.
what();
641 std::cout << "could not get TrackLen or TOF! \n";
642 }
643
644
645
647 for (
unsigned int i=0;
i<
fitTrack->getNumPointsWithMeasurement(); ++
i){
648
649 if (!
fitTrack->getPointWithMeasurement(i)->hasFitterInfo(rep))
650 continue;
651
652 if (debug) {
654 std::cout <<
"hit " <<
i;
655 if (outlierTrue[i]) std::cout << " is an OUTLIER";
656 std::cout << " weights: ";
657 for (
unsigned int j=0;
j<dafWeights.size(); ++
j){
658 std::cout << dafWeights[
j] <<
" ";
659 }
660 std::cout <<
" l/r: " << leftRightTrue[
i];
661 std::cout << "\n";
662 }
663 int trueSide = leftRightTrue[
i];
664 if (trueSide == 0) continue;
665 if (outlierTrue[i]) continue;
667 if(dafWeightLR.size() != 2)
668 continue;
669
670 double weightCorrectSide, weightWrongSide;
671
672 if (trueSide < 0) {
673 weightCorrectSide = dafWeightLR[0];
674 weightWrongSide = dafWeightLR[1];
675 }
676 else {
677 weightCorrectSide = dafWeightLR[1];
678 weightWrongSide = dafWeightLR[0];
679 }
680 weightWrongSide -= 1.;
681
682 weights->Fill(weightCorrectSide);
683 weights->Fill(weightWrongSide);
684
685 if (weightCorrectSide>maxWeight) maxWeight = weightCorrectSide;
686 }
687
688 for (
unsigned int i=0;
i<
fitTrack->getNumPointsWithMeasurement(); ++
i){
689 if (!
fitTrack->getPointWithMeasurement(i)->hasFitterInfo(rep))
690 continue;
691
693
694 if (outlierTrue[i]) {
695 for (
unsigned int j=0;
j<dafWeights.size(); ++
j){
696 weights->Fill(dafWeights[j]-1);
697 }
698 }
699 else if (leftRightTrue[i] == 0) {
700 for (
unsigned int j=0;
j<dafWeights.size(); ++
j){
701 weights->Fill(dafWeights[j]);
702 }
703 }
704 }
705
706 }
707
708
710 if (debug) {
711 std::cout<<" pruned track: ";
713 }
714
715#endif
716
717
718 }
719
721 delete secondTrack;
723
726
727 std::cout<<"maxWeight = " << maxWeight << std::endl;
728 std::cout<<
"avg nr iterations = " << (
double)(nTotalIterConverged + nTotalIterNotConverged)/(
double)(nConvergedFits + nUNConvergedFits) << std::endl;
729 std::cout<<
"avg nr iterations of converged fits = " << (
double)(nTotalIterConverged)/(
double)(nConvergedFits) << std::endl;
730 std::cout<<
"avg nr iterations of UNconverged fits = " << (
double)(nTotalIterNotConverged)/(
double)(nUNConvergedFits) << std::endl;
731 std::cout<<
"fit efficiency = " << (
double)nConvergedFits/nEvents << std::endl;
732
733 if (twoReps) {
734 std::cout<<
"second rep: \navg nr iterations = " << (
double)(nTotalIterSecondConverged + nTotalIterSecondNotConverged)/(
double)(nConvergedFitsSecond + nUNConvergedFitsSecond) << std::endl;
735 std::cout<<
"avg nr iterations of converged fits = " << (
double)(nTotalIterSecondConverged)/(
double)(nConvergedFitsSecond) << std::endl;
736 std::cout<<
"avg nr iterations of UNconverged fits = " << (
double)(nTotalIterSecondNotConverged)/(
double)(nUNConvergedFitsSecond) << std::endl;
737 std::cout<<
"fit efficiency = " << (
double)nConvergedFitsSecond/nEvents << std::endl;
738 }
739
740
741
742
743
744
745#ifndef VALGRIND
746
747 if (debug) std::cout<<"Draw histograms ...";
748
749 TCanvas*
c1 =
new TCanvas();
751
753 hmomRes->Fit("gaus");
754 hmomRes->Draw();
755
757 weights->Draw();
758
760 hupRes->Fit("gaus");
761 hupRes->Draw();
762
764 hvpRes->Fit("gaus");
765 hvpRes->Draw();
766
768 huRes->Fit("gaus");
769 huRes->Draw();
770
772 hvRes->Fit("gaus");
773 hvRes->Draw();
774
776
777 TCanvas*
c2 =
new TCanvas();
779
781 hqopPu->Fit("gaus");
782 hqopPu->Draw();
783
785 pVal->Fit("pol1");
786 pVal->Draw();
788 hupPu->Fit("gaus");
789 hupPu->Draw();
790
792 hvpPu->Fit("gaus");
793 hvpPu->Draw();
794
796 huPu->Fit("gaus");
797 huPu->Draw();
798
800 hvPu->Fit("gaus");
801 hvPu->Draw();
802
804
805
806
807 TCanvas*
c3 =
new TCanvas();
808
809
811 trackLenRes->Fit("gaus");
812 trackLenRes->Draw();
813
815
816 if (debug) std::cout<<"... done"<<std::endl;
817
818
822
823
824#endif
825
826
827}
Abstract base class for Kalman fitter and derived fitting algorithms.
Abstract base class for a track representation.
virtual double extrapolateToPlane(StateOnPlane &state, const genfit::SharedPlanePtr &plane, bool stopAtBoundary=false, bool calcJacobianNoise=false) const =0
Extrapolates the state to plane, and returns the extrapolation length and, via reference,...
virtual void setPosMomCov(MeasuredStateOnPlane &state, const TVector3 &pos, const TVector3 &mom, const TMatrixDSym &cov6x6) const =0
Set position, momentum and covariance of state.
virtual void get6DStateCov(const MeasuredStateOnPlane &state, TVectorD &stateVec, TMatrixDSym &cov) const
Translates MeasuredStateOnPlane into 6D state vector (x, y, z, p_x, p_y, p_z) and 6x6 covariance.
virtual AbsTrackRep * clone() const =0
Clone the trackRep.
Determinstic Annealing Filter (DAF) implementation.
Event display designed to run with Genfit.
void addEvent(std::vector< genfit::Track * > &tracks)
Add new event.
void reset()
Drop all events.
static EventDisplay * getInstance()
void setOptions(std::string opts)
Set the display options.
void open()
Open the event display.
Exception class for error handling in GENFIT (provides storage for diagnostic information)
virtual const char * what() const
Standard error message handling for exceptions. use like "std::cerr << e.what();".
void init(AbsBField *b)
set the magnetic field here. Magnetic field classes must be derived from AbsBField.
static FieldManager * getInstance()
Get singleton instance.
void useCache(bool opt=true, unsigned int nBuckets=8)
Cache last lookup positions, and use stored field values if a lookup at (almost) the same position is...
Measurement class implementing a measurement of all track parameters.
Helix track model for testing purposes.
FitStatus for use with AbsKalmanFitter implementations.
double getBackwardPVal() const
MeasuredStateOnPlane with additional info produced by a Kalman filter or DAF.
Collects information needed and produced by a AbsKalmanFitter implementations and is specific to one ...
KalmanFittedStateOnPlane * getBackwardUpdate() const
Kalman filter implementation with linearization around a reference track.
Simple Kalman filter implementation.
void setNoEffects(bool opt=true)
static MaterialEffects * getInstance()
void init(AbsMaterialInterface *matIfc)
set the material interface here. Material interface classes must be derived from AbsMaterialInterface...
StateOnPlane with additional covariance matrix.
Create different measurement types along a HelixTrackModel for testing purposes.
void setMaxDrift(double maxDrift)
void setDebug(bool debug)
void setSkewAngle(double skewAngle)
void setPhiDetPlane(double phiDetPlane)
void setResolutionWire(double resolutionWire)
void setOutlierRange(double outlierRange)
void setMinDrift(double minDrift)
void setWireDir(const TVector3 wireDir)
void setResolution(double resolution)
std::vector< genfit::AbsMeasurement * > create(eMeasurementType, double tracklength, bool &outlier, int &lr)
void setNSuperLayer(int nSuperLayer)
void setUseSkew(bool useSkew)
void setOutlierProb(double outlierProb)
void setTrackModel(const HelixTrackModel *model)
Takes ownership!
void setThetaDetPlane(double thetaDetPlane)
void setIdealLRResolution(bool idealLRResolution)
AbsTrackRep with 5D track parameterization in plane coordinates: (q/p, u', v', u, v)
A state with arbitrary dimension defined in a DetPlane.
AbsMaterialInterface implementation for use with ROOT's TGeoManager.
Object containing AbsMeasurement and AbsFitterInfo objects.
Collection of TrackPoint objects, AbsTrackRep objects and FitStatus objects.
#define CALLGRIND_START_INSTRUMENTATION
#define CALLGRIND_DUMP_STATS
#define CALLGRIND_STOP_INSTRUMENTATION
fitTrack(hitlist, Pstart=3.)
eMultipleMeasurementHandling
@ weightedClosestToPrediction
@ unweightedClosestToPredictionWire
integer, parameter double