Fork me on GitHub

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • examples/ExamplePVtxFitEC.C

    rb750b0a r46d3442  
    11/*
    22Example of using vertex fitter class to fit primary vertex
    3 assumed to be generated with Pythia8/ee_zh_smr-shf.cmn
     3assumed to be generated in (0,0,0)
    44*/
    55
     
    2121void ExamplePVtxFitEC(const char* inputFile, Int_t Nevent = 5)
    2222{
    23         //
    24         // Beam constraint
    25         // (consistent with generation with ee_zh_smr-shf.cmnd)
    26         //
    27         // Mean beam position
    28         TVectorD xpvc(3);
    29         xpvc(0) = 1.0;
    30         xpvc(1) = -2.0;
    31         xpvc(2) = 10.0;
    32         // Interaction region covariance
    33         TMatrixDSym covpvc(3); covpvc.Zero();
    34         covpvc(0, 0) = 0.0097 * 0.0097;
    35         covpvc(1, 1) = 2.55e-05 * 2.55e-05;
    36         covpvc(2, 2) = 0.64 * 0.64;
    37 
    38         //
    3923        // Create chain of root trees
    4024        TChain chain("Delphes");
     
    5135        // Book histograms
    5236        Int_t Nbin = 100;
    53         // Vertex fit pulls
    5437        TH1D* hXpull = new TH1D("hXpull", "Pull X vertex component", Nbin, -10., 10.);
    5538        TH1D* hYpull = new TH1D("hYpull", "Pull Y vertex component", Nbin, -10., 10.);
    5639        TH1D* hZpull = new TH1D("hZpull", "Pull Z vertex component", Nbin, -10., 10.);
    5740        TH1D* hChi2 = new TH1D("hChi2", "Vertex #chi^{2}/N_{dof}", Nbin, 0., 10.);
    58         // Generation check
    59         TH1D* hXvpull = new TH1D("hXvpull", "Pull X generated vertex", Nbin, -10., 10.);
    60         TH1D* hYvpull = new TH1D("hYvpull", "Pull Y generated vertex", Nbin, -10., 10.);
    61         TH1D* hZvpull = new TH1D("hZvpull", "Pull Z generated vertex", Nbin, -10., 10.);
    62 
    6341        //
    6442        // Loop over all events
     
    8765                                // Get associated generated particle
    8866                                GenParticle* gp = (GenParticle*)trk->Particle.GetObject();
    89                                 TVector3 xg(1.e-3*gp->X,1.e-3*gp->Y,1.e-3*gp->Z);       // mm -> meters
     67                                TVector3 xg(1.e-3*gp->X,1.e-3*gp->Y,1.e-3*gp->Z);
    9068                                TVector3 pg(gp->Px,gp->Py,gp->Pz);
    9169                                Double_t Q = (Double_t)gp->Charge;
    9270                                Double_t Bz = 2.0;
    9371                                TVectorD genParM =TrkUtil:: XPtoPar(xg, pg, Q, Bz);
    94                                 TVectorD genPar = TrkUtil::ParToMm(genParM);            // -> back to mm
    95 
    96                                 //
    97                                 // Check if original track is from primary vertex
     72                                TVectorD genPar = TrkUtil::ParToMm(genParM);
    9873                                //
    9974                                // Position of origin in mm
     
    10479                                Int_t mp = gp->M1;      // Mother
    10580                                while(mp>0){
    106                                         GenParticle* gm = (GenParticle*)branchGenPart->At(mp);
     81                                        GenParticle* gm =
     82                                        (GenParticle*)branchGenPart->At(mp);
    10783                                        Double_t xm = gm->X;
    10884                                        Double_t ym = gm->Y;
    10985                                        Double_t zm = gm->Z;
    11086                                        if(x!=xm || y!=ym || z!=zm){
    111                                                 prim = kFALSE;  // Not primary
     87                                                prim = kFALSE;
    11288                                                break;
    11389                                        }else mp = gm->M1;
    11490                                }
    115 
    11691                                //
    11792                                // group tracks originating from the primary vertex
    11893                                if (prim)
    11994                                {
    120                                         //
    121                                         // Store true primary vertex for this event
     95                                        //std::cout<<"Event: "<<entry<<", track: "<<it;
     96                                        //std::cout<<", x = "<<x<<", y = "<<y<<", z = "<<z<<std::endl;
    12297                                        xpv = x;
    12398                                        ypv = y;
     
    129104                                        Double_t obsC = trk->C;
    130105                                        Double_t obsZ0 = trk->DZ;
     106                                        //std::cout<<"Z0 track = "<< obsZ0
     107                                        //<<", gen Z0 = "<<genPar(3)
     108                                        //<<", gen cot = "<<genPar(4)<<std::endl;
    131109                                        Double_t obsCtg = trk->CtgTheta;
    132110                                        Double_t oPar[5] = { obsD0, obsPhi, obsC, obsZ0, obsCtg };
     
    134112                                        //
    135113                                        pr[Ntr] = new TVectorD(obsPar);
     114                                        //std::cout<<"Cov Matrix:"<<std::endl;
     115                                        //trk->CovarianceMatrix().Print();
    136116                                        cv[Ntr] = new TMatrixDSym(trk->CovarianceMatrix());
    137117                                        Ntr++;
     
    142122                // Fit primary vertex with beam constraint
    143123                //
    144                 Int_t MinTrk = 3;       // Minumum # tracks for vertex fit
     124                //Beam constraint
     125                TVectorD xpvc(3);
     126                xpvc(0) = 1.0;
     127                xpvc(1) = -2.0;
     128                xpvc(2) = 10.0;
     129                TMatrixDSym covpvc(3); covpvc.Zero();
     130                covpvc(0, 0) = 0.0097 * 0.0097;
     131                covpvc(1, 1) = 2.55e-05 * 2.55e-05;
     132                covpvc(2, 2) = 0.64 * 0.64;
     133                Int_t MinTrk = 2;       // Minumum # tracks for vertex fit
    145134                if (Ntr >= MinTrk) {
    146135                        VertexFit* Vtx = new VertexFit(Ntr, pr, cv);
     
    150139                        Double_t Chi2 = Vtx->GetVtxChi2();
    151140                        Double_t Ndof = 2 * (Double_t)Ntr;
    152                         delete Vtx;
    153                         //
    154141                        Double_t PullX = (xvtx(0)-xpv) / TMath::Sqrt(covX(0, 0));
    155142                        Double_t PullY = (xvtx(1)-ypv) / TMath::Sqrt(covX(1, 1));
    156143                        Double_t PullZ = (xvtx(2)-zpv) / TMath::Sqrt(covX(2, 2));
    157                         //
    158                         Double_t PullXv = (xpvc(0)-xpv) / TMath::Sqrt(covpvc(0, 0));
    159                         Double_t PullYv = (xpvc(1)-ypv) / TMath::Sqrt(covpvc(1, 1));
    160                         Double_t PullZv = (xpvc(2)-zpv) / TMath::Sqrt(covpvc(2, 2));
    161                         //
     144                        //std::cout<<"**** True  vertex (x, y, z) "<<xpv<<", "
     145                        //<<ypv<<", "<<zpv<<std::endl;
     146                        //std::cout<<"**** Found vertex (x, y, z) "<<xvtx(0)<<", "
     147                        //<<xvtx(1)<<", "<<xvtx(2)<<std::endl;
    162148                        //
    163149                        // Fill histograms
     
    166152                        hZpull->Fill(PullZ);
    167153                        hChi2->Fill(Chi2 / Ndof);
    168                         //
    169                         hXvpull->Fill(PullXv);
    170                         hYvpull->Fill(PullYv);
    171                         hZvpull->Fill(PullZv);
    172154                }
    173155
     156                //std::cout << "Vertex chi2/Ndof = " << Chi2 / Ndof << std::endl;
    174157                //
    175158                // Cleanup
     
    179162                delete[] cv;
    180163        }
    181 
    182164        //
    183165        // Show resulting histograms
     
    192174        hZpull->Fit("gaus"); hZpull->Draw();
    193175        Cnv->cd(4); hChi2->Draw();
    194         //
    195         TCanvas* Cnv1 = new TCanvas("Cnv1", "Generated primary vertex pulls", 100, 100, 900, 500);
    196         Cnv1->Divide(3, 1);
    197         Cnv1->cd(1); gPad->SetLogy(1); gStyle->SetOptFit(1111);
    198         hXvpull->Fit("gaus"); hXvpull->Draw();
    199         Cnv1->cd(2); gPad->SetLogy(1); gStyle->SetOptFit(1111);
    200         hYvpull->Fit("gaus"); hYvpull->Draw();
    201         Cnv1->cd(3); gPad->SetLogy(1); gStyle->SetOptFit(1111);
    202         hZvpull->Fit("gaus"); hZvpull->Draw();
    203176}
Note: See TracChangeset for help on using the changeset viewer.