5 #include <ConstField.h>
7 #include <FieldManager.h>
8 #include <KalmanFitterRefTrack.h>
9 #include <StateOnPlane.h>
11 #include <TrackPoint.h>
13 #include <MaterialEffects.h>
14 #include <RKTrackRep.h>
15 #include <TGeoMaterialInterface.h>
17 #include <EventDisplay.h>
19 #include <HelixTrackModel.h>
20 #include <MeasurementCreator.h>
22 #include <TDatabasePDG.h>
23 #include <TEveManager.h>
24 #include <TGeoManager.h>
29 #include "TDatabasePDG.h"
35 #define FILENAME "/tmp/streamerTest.root"
37 constexpr
bool verbose =
false;
41 TFile *f = TFile::Open(FILENAME,
"RECREATE");
45 t->checkConsistency();
55 f = TFile::Open(FILENAME,
"READ");
60 t->checkConsistency();
72 if (!emptyTrackTest()) {
73 std::cout <<
"emptyTrackTest failed." << std::endl;
85 TFile* fOut =
new TFile(FILENAME,
"RECREATE");
87 TTree* tResults =
new TTree(
"tResults",
"results from track fit");
89 tResults->Branch(
"gfTrack",
"genfit::Track", &fitTrack, 32000, -1);
90 tResults->Branch(
"stateFinal", &stateFinal);
91 tResults->Branch(
"covFinal", &covFinal, 32000, -1);
92 tResults->Branch(
"planeFinal", &planeFinal, 32000, -1);
105 new TGeoManager(
"Geometry",
"Geane geometry");
106 TGeoManager::Import(
"genfitGeom.root");
114 unsigned int nEvents(100);
117 for (
unsigned int iEvent=0; iEvent<nEvents; ++iEvent){
120 TVector3 pos(0, 0, 0);
121 TVector3 mom(1.,0,0);
122 mom.SetPhi(gRandom->Uniform(0.,2*TMath::Pi()));
123 mom.SetTheta(gRandom->Uniform(0.4*TMath::Pi(),0.6*TMath::Pi()));
124 mom.SetMag(gRandom->Uniform(0.2, 1.));
129 const double charge = TDatabasePDG::Instance()->GetParticle(pdg)->Charge()/(3.);
134 unsigned int nMeasurements = gRandom->Uniform(5, 15);
138 const bool smearPosMom =
true;
139 const double posSmear = 0.1;
140 const double momSmear = 3. /180.*TMath::Pi();
141 const double momMagSmear = 0.1;
146 posM.SetX(gRandom->Gaus(posM.X(),posSmear));
147 posM.SetY(gRandom->Gaus(posM.Y(),posSmear));
148 posM.SetZ(gRandom->Gaus(posM.Z(),posSmear));
150 momM.SetPhi(gRandom->Gaus(mom.Phi(),momSmear));
151 momM.SetTheta(gRandom->Gaus(mom.Theta(),momSmear));
152 momM.SetMag(gRandom->Gaus(mom.Mag(), momMagSmear*mom.Mag()));
156 double resolution = 0.01;
157 for (
int i = 0; i < 3; ++i)
158 covM(i,i) = resolution*resolution;
159 for (
int i = 3; i < 6; ++i)
160 covM(i,i) = pow(resolution / nMeasurements /
sqrt(3), 2);
172 TVectorD seedState(6);
173 TMatrixDSym seedCov(6);
179 std::vector<genfit::eMeasurementType> measurementTypes;
180 for (
unsigned int i = 0; i < nMeasurements; ++i)
181 measurementTypes.push_back(genfit::eMeasurementType(gRandom->Uniform(8)));
186 for (
unsigned int i=0; i<measurementTypes.size(); ++i){
187 std::vector<genfit::AbsMeasurement*> measurements = measurementCreator.create(measurementTypes[i], i*5.);
192 tp->setScatterer(sc);
198 std::cerr<<
"Exception, next track"<<std::endl;
199 std::cerr << e.what();
205 fitTrack->checkConsistency();
208 fitter->processTrack(fitTrack);
210 fitTrack->checkConsistency();
219 switch (iEvent % 5) {
223 fitTrack->
prune(
"FL");
226 fitTrack->
prune(
"W");
229 fitTrack->
prune(
"RC");
232 fitTrack->
prune(
"U");
253 fOut = TFile::Open(FILENAME,
"READ");
254 fOut->GetObject(
"tResults", tResults);
255 TVectorD* pState = 0;
256 tResults->SetBranchAddress(
"stateFinal", &pState);
257 TMatrixDSym* pMatrix = 0;
258 tResults->SetBranchAddress(
"covFinal", &pMatrix);
260 tResults->SetBranchAddress(
"planeFinal", &plane);
261 tResults->SetBranchAddress(
"gfTrack", &fitTrack);
265 for (Long_t nEntry = 0; nEntry < tResults->GetEntries(); ++nEntry) {
266 tResults->GetEntry(nEntry);
269 fitTrack->checkConsistency();
271 std::cout << e.getExcString() << std::endl;
283 std::cout <<
"stored track not equal, small differences can occur if some info has been pruned." << std::endl;
297 std::cerr << e.what();
302 std::cout << nEvents - fail <<
" stored tracks are identical to fitted tracks, as far as tested." << std::endl;
303 std::cout << fail <<
" tracks were not identical to fitted tracks, as far as tested." << std::endl;
305 std::cout <<
"deleteing didn't segfault" << std::endl;
Abstract base class for Kalman fitter and derived fitting algorithms.
Abstract base class for a track representation.
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.
Exception class for error handling in GENFIT (provides storage for diagnostic information)
static FieldManager * getInstance()
Get singleton instance.
void init(AbsBField *b)
set the magnetic field here. Magnetic field classes must be derived from AbsBField.
Helix track model for testing purposes.
Kalman filter implementation with linearization around a reference track.
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 setTrackModel(const HelixTrackModel *model)
Takes ownership!
AbsTrackRep with 5D track parameterization in plane coordinates: (q/p, u', v', u, v)
AbsMaterialInterface implementation for use with ROOT's TGeoManager.
Object containing AbsMeasurement and AbsFitterInfo objects.
Collection of TrackPoint objects, AbsTrackRep objects and FitStatus objects.
void insertPoint(TrackPoint *point, int id=-1)
Insert TrackPoint BEFORE TrackPoint with position id, if id >= 0.
const MeasuredStateOnPlane & getFittedState(int id=0, const AbsTrackRep *rep=nullptr, bool biased=true) const
Shortcut to get FittedStates.
void prune(const Option_t *="CFLWRMIU")
Delete unneeded information from the Track.
double sqrt(double a)
sqrt for double
double charge(int pdgCode)
Returns electric charge of a particle with given pdg code.
std::shared_ptr< genfit::DetPlane > SharedPlanePtr
Shared Pointer to a DetPlane.
int main(int argc, char **argv)
Run all tests.