[c41f48e] | 1 | /*
|
---|
| 2 | Example of using vertex fitter class to fit primary vertex
|
---|
[c24ad79] | 3 | assumed to be generated in (0,0,0).
|
---|
| 4 | To run compiled version:
|
---|
| 5 | root
|
---|
| 6 | root> .L examples/LoadPvtxFit.C+
|
---|
| 7 | root> LoadPVtxFit()
|
---|
| 8 | root> ExamplePVtxFit("infile.root", Nevents)
|
---|
| 9 |
|
---|
| 10 | March 4, 2021
|
---|
| 11 | F. Bedeschi, INFN-Pisa, Italy
|
---|
[c41f48e] | 12 | */
|
---|
| 13 |
|
---|
| 14 | #include "classes/DelphesClasses.h"
|
---|
| 15 | #include "external/ExRootAnalysis/ExRootTreeReader.h"
|
---|
| 16 | #include "modules/TrackCovariance.h"
|
---|
| 17 | #include "external/TrackCovariance/TrkUtil.h"
|
---|
| 18 | #include "external/TrackCovariance/VertexFit.h"
|
---|
| 19 |
|
---|
| 20 | #include <TClonesArray.h>
|
---|
| 21 | #include <TChain.h>
|
---|
| 22 | #include <TVectorD.h>
|
---|
| 23 | #include <TMatrixDSym.h>
|
---|
| 24 | #include <TH1.h>
|
---|
| 25 | #include <TCanvas.h>
|
---|
| 26 | #include <TStyle.h>
|
---|
| 27 |
|
---|
| 28 | //------------------------------------------------------------------------------
|
---|
| 29 |
|
---|
| 30 | void ExamplePVtxFit(const char* inputFile, Int_t Nevent = 5)
|
---|
| 31 | {
|
---|
| 32 | // Create chain of root trees
|
---|
| 33 | TChain chain("Delphes");
|
---|
| 34 | chain.Add(inputFile);
|
---|
| 35 |
|
---|
| 36 | // Create object of class ExRootTreeReader
|
---|
| 37 | ExRootTreeReader* treeReader = new ExRootTreeReader(&chain);
|
---|
| 38 | Long64_t numberOfEntries = treeReader->GetEntries();
|
---|
| 39 |
|
---|
| 40 | // Get pointers to branches used in this analysis
|
---|
| 41 | TClonesArray* branchGenPart = treeReader->UseBranch("Particle");
|
---|
| 42 | TClonesArray* branchTrack = treeReader->UseBranch("Track");
|
---|
| 43 |
|
---|
| 44 | // Book histograms
|
---|
| 45 | Int_t Nbin = 100;
|
---|
| 46 | TH1D* hXpull = new TH1D("hXpull", "Pull X vertex component", Nbin, -10., 10.);
|
---|
| 47 | TH1D* hYpull = new TH1D("hYpull", "Pull Y vertex component", Nbin, -10., 10.);
|
---|
| 48 | TH1D* hZpull = new TH1D("hZpull", "Pull Z vertex component", Nbin, -10., 10.);
|
---|
| 49 | TH1D* hChi2 = new TH1D("hChi2", "Vertex #chi^{2}/N_{dof}", Nbin, 0., 10.);
|
---|
| 50 | //
|
---|
| 51 | // Loop over all events
|
---|
| 52 | Int_t Nev = TMath::Min(Nevent, (Int_t) numberOfEntries);
|
---|
| 53 | for (Int_t entry = 0; entry < Nev; ++entry)
|
---|
| 54 | {
|
---|
| 55 | // Load selected branches with data from specified event
|
---|
| 56 | treeReader->ReadEntry(entry);
|
---|
| 57 | Int_t Ntr = 0; // # of tracks from primary vertex
|
---|
[c24ad79] | 58 | Int_t NtrG = branchTrack->GetEntries(); // Total # of tracks
|
---|
[c41f48e] | 59 | TVectorD** pr = new TVectorD * [NtrG];
|
---|
| 60 | TMatrixDSym** cv = new TMatrixDSym * [NtrG];
|
---|
| 61 | // If event contains at least 1 track
|
---|
| 62 | //
|
---|
| 63 | if (branchTrack->GetEntries() > 0)
|
---|
| 64 | {
|
---|
| 65 | // Loop on tracks
|
---|
| 66 | for (Int_t it = 0; it < branchTrack->GetEntries(); it++)
|
---|
| 67 | {
|
---|
| 68 | Track* trk = (Track*)branchTrack->At(it);
|
---|
| 69 | //
|
---|
| 70 | // Get associated generated particle
|
---|
| 71 | GenParticle* gp = (GenParticle*)trk->Particle.GetObject();
|
---|
| 72 | //
|
---|
[c24ad79] | 73 | // Position of origin (mm)
|
---|
| 74 | Double_t x = gp->X;
|
---|
| 75 | Double_t y = gp->Y;
|
---|
| 76 | Double_t z = gp->Z;
|
---|
[c41f48e] | 77 | //
|
---|
[c24ad79] | 78 | // Select group of tracks originating from the primary vertex
|
---|
[c41f48e] | 79 | if (x == 0.0 && y == 0.0)
|
---|
| 80 | {
|
---|
| 81 | //
|
---|
| 82 | // Reconstructed track parameters
|
---|
| 83 | Double_t obsD0 = trk->D0;
|
---|
| 84 | Double_t obsPhi = trk->Phi;
|
---|
| 85 | Double_t obsC = trk->C;
|
---|
| 86 | Double_t obsZ0 = trk->DZ;
|
---|
| 87 | Double_t obsCtg = trk->CtgTheta;
|
---|
| 88 | Double_t oPar[5] = { obsD0, obsPhi, obsC, obsZ0, obsCtg };
|
---|
| 89 | TVectorD obsPar(5, oPar); // Fill observed parameters
|
---|
| 90 | //
|
---|
| 91 | pr[Ntr] = new TVectorD(obsPar);
|
---|
| 92 | cv[Ntr] = new TMatrixDSym(TrkUtil::CovToMm(trk->CovarianceMatrix()));
|
---|
| 93 | Ntr++;
|
---|
| 94 | }
|
---|
| 95 | } // End loop on tracks
|
---|
| 96 | }
|
---|
| 97 | //
|
---|
| 98 | // Fit primary vertex
|
---|
| 99 | Int_t MinTrk = 2; // Minumum # tracks for vertex fit
|
---|
| 100 | if (Ntr >= MinTrk) {
|
---|
| 101 | VertexFit* Vtx = new VertexFit(Ntr, pr, cv);
|
---|
| 102 | TVectorD xvtx = Vtx->GetVtx();
|
---|
| 103 | TMatrixDSym covX = Vtx->GetVtxCov();
|
---|
| 104 | Double_t Chi2 = Vtx->GetVtxChi2();
|
---|
| 105 | Double_t Ndof = 2 * (Double_t)Ntr - 3;
|
---|
| 106 | Double_t PullX = xvtx(0) / TMath::Sqrt(covX(0, 0));
|
---|
| 107 | Double_t PullY = xvtx(1) / TMath::Sqrt(covX(1, 1));
|
---|
| 108 | Double_t PullZ = xvtx(2) / TMath::Sqrt(covX(2, 2));
|
---|
| 109 | //
|
---|
| 110 | // Fill histograms
|
---|
| 111 | hXpull->Fill(PullX);
|
---|
| 112 | hYpull->Fill(PullY);
|
---|
| 113 | hZpull->Fill(PullZ);
|
---|
| 114 | hChi2->Fill(Chi2 / Ndof);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | //
|
---|
| 118 | // Cleanup
|
---|
| 119 | for (Int_t i = 0; i < Ntr; i++) delete pr[i];
|
---|
| 120 | for (Int_t i = 0; i < Ntr; i++) delete cv[i];
|
---|
| 121 | delete[] pr;
|
---|
| 122 | delete[] cv;
|
---|
| 123 | }
|
---|
| 124 | //
|
---|
| 125 | // Show resulting histograms
|
---|
| 126 | //
|
---|
| 127 | TCanvas* Cnv = new TCanvas("Cnv", "Delphes generated track plots", 50, 50, 900, 500);
|
---|
| 128 | Cnv->Divide(2, 2);
|
---|
| 129 | Cnv->cd(1); gPad->SetLogy(1); gStyle->SetOptFit(1111);
|
---|
| 130 | hXpull->Fit("gaus"); hXpull->Draw();
|
---|
| 131 | Cnv->cd(2); gPad->SetLogy(1); gStyle->SetOptFit(1111);
|
---|
| 132 | hYpull->Fit("gaus"); hYpull->Draw();
|
---|
| 133 | Cnv->cd(3); gPad->SetLogy(1); gStyle->SetOptFit(1111);
|
---|
| 134 | hZpull->Fit("gaus"); hZpull->Draw();
|
---|
| 135 | Cnv->cd(4); hChi2->Draw();
|
---|
| 136 | }
|
---|