EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
analysis.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file analysis.C
1 
2 #define _NDF_MAX_ 1000
3 
4 void analysis()
5 {
6  // Load basic libraries;
7  gROOT->Macro("$VMCWORKDIR/gconfig/rootlogon.C");
8 
9  // Input simulated & reconstructed files;
10  TFile *ff = new TFile("simulation.root");
11  TTree *cbmsim = ff->Get("cbmsim");
12  cbmsim->AddFriend("cbmsim", "reconstruction.root");
13 
14  // Figure out max and most popular ndf value;
15  TClonesArray *rctrk = new TClonesArray("PndPidCandidate");
16  cbmsim->SetBranchAddress("PidChargedCand",&rctrk);
17  unsigned nEvt = cbmsim->GetEntries(), ndfMax = 0;
18  unsigned arr[1000]; memset(arr, 0x00, sizeof(arr));
19  for (unsigned evt = 0; evt<nEvt; evt++) {
20  cbmsim->GetEntry(evt);
21 
22  if (rctrk->GetEntriesFast()) {
23  PndPidCandidate *rctrack = rctrk->At(0);
24 
25  int ndf = rctrack->GetDegreesOfFreedom();
26  if (ndf > ndfMax) ndfMax = ndf;
27  if (ndf < _NDF_MAX_) arr[ndf]++;
28  }
29  }
30  unsigned ndfMostPopular = 0, ndfMostPopularStat = 0;
31  for(unsigned iq=0; iq<_NDF_MAX_; iq++)
32  if (arr[iq] > ndfMostPopularStat) {
33  ndfMostPopular = iq;
34  ndfMostPopularStat = arr[iq];
35  }
36 
37  // This assumes single-track events of course (a typical case for a particle gun);
38  char *expression = "100.*(PidChargedCand.GetMomentum().Mag()-MCTrack.GetMomentum().Mag())/MCTrack.GetMomentum().Mag()";
39  //char *expression = "10000.*(PidChargedCand.GetMomentum().Theta()-MCTrack.GetMomentum().Theta())";
40  //char *expression = "1000.*(PidChargedCand.GetMomentum().Phi()-MCTrack.GetMomentum().Phi())";
41  char cut[1024];
42  // Allow to lose a couple of degrees of freedom compared to the max (assume standard) case;
43  sprintf(cut, "EicIdealGenTrack.fNDF>=%d&&EicIdealGenTrack.fChiSquareCCDF>.001", ndfMostPopular-2);
44 
45  double par[100]; memset(par, 0x00, sizeof(par));
46 
47  // Fitting is performed in 3 iteration, the last one in a +/-5*sigma range;
48  TH1D *dp1 = new TH1D("dp1", "dp1", 100, -20.0, 20.0);
49  cbmsim->Project("dp1", expression, cut);
50  TF1 *fq1 = new TF1("fq1", "gaus(0)", -20.0, 20.0);
51  // Be aware, that par[2] (sigma) may require some tuning here;
52  par[0] = 100.0; par[1] = 0.0; par[2] = 1.0;
53  fq1->SetParameters(par);
54  dp1->Fit("fq1","R");
55  fq1->GetParameters(par);
56 
57  double sigma2 = fabs(par[2]), min2 = -5*sigma2, max2 = 5*sigma2;
58 
59  TH1D *dp2 = new TH1D("dp2", "dp2", 100, min2, max2);
60  cbmsim->Project("dp2", expression, cut);
61  TF1 *fq2 = new TF1("fq2", "gaus(0)", min2, max2);
62  fq2->SetParameters(par);
63  dp2->Fit("fq2","R");
64  fq2->GetParameters(par);
65 
66  double sigma3 = fabs(par[2]), min3 = -5*sigma3, max3 = 5*sigma3;
67 
68  TH1D *dp3 = new TH1D("dp3", "dp3", 100, min3, max3);
69  cbmsim->Project("dp3", expression, cut);
70  TF1 *fq3 = new TF1("fq3", "gaus(0)", min3, max3);
71  fq3->SetParameters(par);
72  dp3->Fit("fq3","R");
73 } // analysis()