FairRoot/PandaRoot
PndRichRecoTask.cxx
Go to the documentation of this file.
1 #include "PndRichRecoTask.h"
2 #include "PndRichReco.h"
3 #include "PndRichBarPoint.h"
4 #include "PndRichResolution.h"
5 
6 // fairroot
7 #include "FairRootManager.h"
8 #include "FairRunAna.h"
9 #include "FairRuntimeDb.h"
10 #include "FairGeanePro.h"
11 #include "FairGeaneUtil.h"
12 #include "FairTrackParP.h"
13 
14 // general
15 #include <iostream>
16 #include <cmath>
17 #include <iomanip>
18 
19 using namespace std;
20 
21 // ----- Default constructor -------------------------------------------
23  FairTask("Rich Reco task") ,
24  fPersistence(kTRUE),
25  fNumberOfEvents(0),
26  fEvent(0),
27  fTrackPositionSecond(0,0,0),
28  fTrackDirectionSecond(0,0,0)
29 {
30  fVerbose=1;
31 }
32 // -------------------------------------------------------------------------
33 
34 // ----- Destructor ----------------------------------------------------
36 }
37 // -------------------------------------------------------------------------
38 
39 // ----- Public method Init --------------------------------------------
40 InitStatus PndRichRecoTask::Init() {
41 
42  FairRootManager *ioman = FairRootManager::Instance();
43 
44  if (!ioman)
45  {
46  cout << "-E- PndRichRecoTask: "
47  << "RootManager not instantised!" << endl;
48  return kFATAL;
49  }
50 
51  fRichReco = new PndRichReco(fGeoVersion); // 13 - one of the flat mirror variant
52  vnhits.reserve(fNumberOfEvents);
53  vmean.reserve(fNumberOfEvents);
54  vsigma.reserve(fNumberOfEvents);
55  fRichBarPoint = dynamic_cast<TClonesArray *> (ioman->GetObject("RichBarPoint"));
56 
58 
59  cout << "-I- PndRichRecoTask: Intialisation successfull " << endl;
60  return kSUCCESS;
61 }
62 // -------------------------------------------------------------------------
63 
64 
65 // ----- Public method Exec --------------------------------------------
66 void PndRichRecoTask::Exec(Option_t*) {
67  if(fVerbose > 0) {
68  //cout << "==================== EVENT " << evt << endl;
69  }
70  fEvent++;
71  //fRichReco->RichFullReconstruction();
72 
73  TVector3 pos = fTrackPosition;
74  TVector3 dir = fTrackDirection.Unit();
75  Double_t mom = 0;
76  Double_t tm = 0;
77  Int_t pdg = 0;
78 
79  PndRichBarPoint *richHit = NULL;
80  Int_t richEntries = fRichBarPoint->GetEntriesFast();
81  if (richEntries) {
82  richHit = (PndRichBarPoint*)fRichBarPoint->At(0);
83  //pos = richHit->GetPosition0();
84  //dir = richHit->GetMomentum0().Unit();
85  //mom = richHit->GetMomentum0().Mag();
86  pos = TVector3(richHit->GetX(),richHit->GetY(),richHit->GetZ());
87  TVector3 p = TVector3(richHit->GetPx(),richHit->GetPy(),richHit->GetPz());
88  dir = p.Unit();
89  mom = p.Mag();
90  tm = richHit->GetTime();
91  pdg = richHit->GetPdgCode();
92  }
93 
94  Int_t richPhot = 0;
95  Float_t richThetaC = -1000, richThetaCErr = 0;
96  Float_t richQuality = 1000000;
97  // first particle
99  richQuality,richThetaC,richThetaCErr,richPhot);
100  std::vector<Double_t> dth = fRichReco->GetDThetas();
101 
102  std::cout << std::setprecision(10) << std::endl;
103  std::cout << "PndRichRecoTask: " << fEvent << " " << richQuality << " " << richThetaC
104  << " " << richThetaCErr << " " << richPhot << " " << 1
105  << " " << mom << " " << dir.Phi() << " " << dir.Theta()
106  << " " << pos.X() << " " << pos.Y() << " " << pdg << std::endl;
107  Double_t mass[5] = {0.000510998961,0.1056583745,0.13957018,0.493667,0.9382720813};
108  Double_t pdf[5];
109  Double_t pdfsum = 0;
110  dbpoint pnt;
111  for(Int_t i=0;i<5;i++)
112  {
113  Float_t richThetaCx = richThetaC;
114  pnt.mass = mass[i];
115  pnt.beta = richThetaCx;
116  pnt.x = pos.X();
117  pnt.y = pos.Y();
118  pnt.theta = dir.Theta();
119  pnt.phi = dir.Phi();
120  pnt.beta += fRichResolution->Shift(pnt);
121  richThetaCx += fRichResolution->Shift(pnt);
122 
123  std::cout << i << " " << fRichResolution->Shift(pnt) << " " << fRichResolution->Sigma(pnt) << " " << mass[i] << " " <<
124  pnt.beta << " " << pnt.x << " " << pnt.y << " " << pnt.theta << " " << pnt.phi << std::endl;
125 
126  Double_t beta = mom / TMath::Sqrt(mom*mom + mass[i]*mass[i]);
127  TF1 *gausPdf = new TF1("gausPdf","gausn",0,1);
128  gausPdf->SetParameter(0,1);
129  gausPdf->SetParameter(1,richThetaCx);
130  gausPdf->SetParameter(2,richThetaCErr);
131  //gausPdf->SetParameter(2,fRichResolution->Sigma(pnt));
132  pdf[i] = gausPdf->Eval(beta);
133  pdfsum += pdf[i];
134  delete gausPdf;
135  }
136  std::cout << "particles PID: ";
137  for(Int_t i=0;i<5;i++)
138  std::cout << pdf[i] << " " << (pdfsum?pdf[i]/pdfsum:0.2) << " " ;
139  std::cout << std::endl;
140 
141  vdth.insert(vdth.end(),dth.begin(),dth.end());
142  vnhits.push_back(dth.size());
143  vmean.push_back(richThetaC);
144  vsigma.push_back(richThetaCErr);
145 
146  std::vector<Double_t> th = fRichReco->GetThetas();
147  std::vector<Double_t> ph = fRichReco->GetPhis();
148  vth.insert(vth.end(),th.begin(),th.end());
149  vph.insert(vph.end(),ph.begin(),ph.end());
150 
151  for(size_t i=0; i<ph.size(); i++)
152  std::cout << "::HitPars() " << fEvent << " " << ph.at(i) << " " <<
153  th.at(i) << " " << dth.at(i) << std::endl;
154 
155  if (fTrackDirectionSecond.Mag()!=0) {
156  // secon particle
158  richQuality,richThetaC,richThetaCErr,richPhot);
159  std::cout << "PndRichRecoTask: " << fEvent << " " << richQuality << " " << richThetaC
160  << " " << richThetaCErr << " " << richPhot << " " << 2 << std::endl;
161  }
162 }
163 
165 {
166 }
167 
169 {
170  std::cout << "::FinishTask() " << vmean.size() << " " << vsigma.size() << std::endl;
171  TF1 * f = GetPeakParameters(vmean,1100,0.95,1.005,0.0003);
172 
173  double chisq=f->GetChisquare();
174  double ndf=f->GetNDF();
175  double chisqdf=chisq/ndf;
176  std::cout << "Chisquare: " << chisq << "/" << ndf << " : " << chisqdf << std::endl;
177 
178  //Double_t amp = f->GetParameter(0); //value of 0th parameter //[R.K. 03/2017] unused variable?
179  //Double_t eamp = f->GetParError(0); //error on 0th parameter //[R.K. 03/2017] unused variable?
180  Double_t mean = f->GetParameter(1); //value of 1st parameter
181  Double_t emean = f->GetParError(1); //error on 1st parameter
182  Double_t sig = f->GetParameter(2); //value of 1st parameter
183  Double_t esig = f->GetParError(2); //error on 1st parameter
184 
185  size_t nhits = 0;
186  for(size_t i=0; i<vmean.size(); i++) {
187  if ( std::fabs(vmean.at(i)-mean) < 3*sig ) nhits++;
188  }
189 
190  std::cout << "::FinishTask() " << mean << " " << sig << std::endl;
191  std::cout << "CalData: " << chisq << std::endl;
192  std::cout << "CalData: " << ndf << std::endl;
193  std::cout << "CalData: " << nhits << std::endl;
194  std::cout << "CalData: " << mean << std::endl;
195  std::cout << "CalData: " << emean << std::endl;
196  std::cout << "CalData: " << sig << std::endl;
197  std::cout << "CalData: " << esig << std::endl;
198 
199  TF1 * f1 = GetPeakParameters(vdth,500,-0.05,0.05,0.003);
200 
201  chisq=f1->GetChisquare();
202  ndf=f1->GetNDF();
203  chisqdf=chisq/ndf;
204  std::cout << "Chisquare: " << chisq << "/" << ndf << " : " << chisqdf << std::endl;
205 
206  //amp = f1->GetParameter(0); //value of 0th parameter //[R.K. 03/2017] unused variable?
207  //eamp = f1->GetParError(0); //error on 0th parameter //[R.K. 03/2017] unused variable?
208  mean = f1->GetParameter(1); //value of 1st parameter
209  emean = f1->GetParError(1); //error on 1st parameter
210  sig = f1->GetParameter(2); //value of 1st parameter
211  esig = f1->GetParError(2); //error on 1st parameter
212 
213  std::cout << "::FinishTask() " << mean << " " << sig << std::endl;
214  std::cout << "CalData: " << chisq << std::endl;
215  std::cout << "CalData: " << ndf << std::endl;
216  std::cout << "CalData: " << mean << std::endl;
217  std::cout << "CalData: " << emean << std::endl;
218  std::cout << "CalData: " << sig << std::endl;
219  std::cout << "CalData: " << esig << std::endl;
220 
221 }
222 
223 TF1* PndRichRecoTask::GetPeakParameters(std::vector<Double_t> v,
224  UInt_t nbins, Double_t xmin, Double_t xmax,
225  Double_t sig)
226 {
227  TH1F * hbetafit = new TH1F("hist", "for gauss fit", nbins, xmin, xmax);
228  for(size_t i=0; i<v.size(); i++)
229  hbetafit->Fill(v.at(i));
230  int ipeak = hbetafit->GetMaximumBin();
231  double amp0 = hbetafit->GetMaximum();
232  double peak = xmin + (ipeak-0.5)*(xmax-xmin)/nbins;
233  TF1 * gfit = new TF1("Gaussian","gaus",xmin,xmax);
234  gfit->SetParameter(0,amp0);
235  gfit->SetParameter(1,peak);
236  gfit->SetParameter(2,sig);
237  for(size_t i=0; i<5; i++) {
238  Double_t meanf = gfit->GetParameter(1);
239  Double_t sigf = gfit->GetParameter(2);
240  double xminf = meanf - 3*sigf;
241  double xmaxf = meanf + 3*sigf;
242  hbetafit->Fit("Gaussian","Q","",xminf,xmaxf);
243  }
244  delete hbetafit;
245  return gfit;
246 }
247 
TVector3 pos
TVector3 fTrackDirectionSecond
int fVerbose
Definition: poormantracks.C:24
std::vector< double > GetDThetas()
Double_t x
Definition: PndRichCalDb.h:25
std::vector< Double_t > vsigma
PndRichResolution * fRichResolution
Int_t i
Definition: run_full.C:25
TF1 * f1
Definition: reco_analys2.C:50
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
std::vector< double > GetThetas()
Double_t xmax
TVector3 fTrackPosition
TClonesArray * pnt
virtual InitStatus Init()
Double_t mom
Definition: plot_dirc.C:14
void RichFullReconstruction(TVector3 pos, TVector3 dir, Float_t ts, Float_t &chi2, Float_t &chTh, Float_t &dChTh, Int_t &nph)
__m128 v
Definition: P4_F32vec4.h:4
std::vector< Double_t > vmean
Double_t p
Definition: anasim.C:58
std::vector< Double_t > vth
TVector3 fTrackDirection
Double_t
TFile * f
Definition: bump_analys.C:12
Double_t mass
Definition: PndRichCalDb.h:23
TF1 * GetPeakParameters(std::vector< Double_t > v, UInt_t nbins, Double_t xmin, Double_t xmax, Double_t sig)
Double_t Shift(dbpoint pnt)
int nbins
Definition: full_core_ntp.C:33
TClonesArray * fRichBarPoint
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
std::vector< Double_t > vdth
std::vector< UInt_t > vnhits
Int_t GetPdgCode() const
TVector3 fTrackPositionSecond
PndRichReco * fRichReco
ClassImp(PndAnaContFact)
std::vector< double > GetPhis()
Double_t theta
Definition: PndRichCalDb.h:27
Pythia8::PDF * pdf
Double_t xmin
Double_t mean[nsteps]
Definition: dedx_bands.C:65
Double_t phi
Definition: PndRichCalDb.h:28
Double_t Sigma(dbpoint pnt)
Double_t beta
Definition: PndRichCalDb.h:24
Double_t y
Definition: PndRichCalDb.h:26
virtual void Exec(Option_t *opt)
std::vector< Double_t > vph