StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
MuPrmVtx.C
1 /*
2  Reconstruction of primary vertices from MuDst.
3  In directory where you have *MuDst.root files run
4  root.exe lMuDstK.C MuPrmVtx.C+
5  $Id: MuPrmVtx.C,v 2.3 2013/04/10 22:14:20 fisyak Exp $
6  */
7 #define DEBUG
8 #define __IDTRUTH__
9 
10 #define DRAW_RECO_HISTOS // draw histos which are used for reconstruction
11 //#define EVENT_DISPLAY // show tracks and vertices in each event on the screen
12 
13 #if !defined(__CINT__) || defined(__MAKECINT__)
14 #include "Riostream.h"
15 #include <stdio.h>
16 #include "TSystem.h"
17 #include "TMath.h"
18 #include "TH1.h"
19 #include "TH2.h"
20 #include "TProfile.h"
21 #include "TStyle.h"
22 #include "TF1.h"
23 #include "TTree.h"
24 #include "TChain.h"
25 #include "TFile.h"
26 #include "TCanvas.h"
27 #include "TVector3.h"
28 #include "TLorentzVector.h"
29 #include "TDirIter.h"
30 #include "TTreeIter.h"
31 #include "StDcaGeometry.h"
32 #include "KFVertex.h"
33 #include "MTrack.h"
34 #include "VVertex.h"
35 #include "TH1K.h"
36 #include "TSpectrum.h"
37 #include "TVirtualFitter.h"
38 #include "TPolyMarker.h"
39 #include "TRVector.h"
40 #include "TRSymMatrix.h"
41 #include "Math/Functor.h"
42 #include "Math/GSLMinimizer1D.h"
43 #include "TROOT.h"
44 #include "TVector3.h"
45 #include "TArrayF.h"
46 #include "TClonesArray.h"
47 #include "StKFVertex/StAnneling.h"
48 #include "StKFVertex/StKFEvent.h"
49 #include "StKFVertex/StKFTrack.h"
50 #include "StKFVertex/StKFVertex.h"
51 #include "StKFVertex/StKFVerticesCollection.h"
52 #include "StKFVertex/StMuDstVtxT.h"
53 #include "StKFVertex/StVertexP.h"
54 #include "StKFVertex/StVertexT.h"
55 #include "StKFVertex/StKFVertexFinder.h"
56 #ifdef EVENT_DISPLAY
57 #include "StDraw3D.h"
58 static StDraw3D *eventD = 0;
59 #endif
60 #endif
61 #if 0
62 static Int_t beamLine = 0;
63 static KFParticle beam;
64 static Double_t pZ = 1000;
65 #endif
66 Bool_t Ask() {
67  static Bool_t fAsk = kTRUE;
68  char symbol;
69  if (fAsk){
70  std::cout << "ask (enter - next, s - save, r - don't ask, q - quit) >";
71  do{
72  std::cin.get(symbol);
73  if (symbol == 'r')
74  fAsk = kFALSE;
75  if (symbol == 'q')
76  return kTRUE;
77  } while (symbol != '\n');
78  std::cout << endl;
79  }
80  return kFALSE;
81 }
82 //________________________________________________________________________________
83 void MuPrmVtx(Int_t first, Int_t last, const Char_t *files, const Char_t* Out="") {
84  TDirIter Dir(files);
85  TString Files(files);
86 #if 0
87  // if (Files.Contains("pp500") && ! Files.Contains("sim")) beamLine = 1;
88  /* beam line
89  SELECT * FROM Calibrations_rhic.vertexSeed v where beginTime > "2009-03-01" and beginTime < "2009-04-01";
90  | beginTime | x0 | dxdz | y0 | dydz | err_x0 | err_dxdz | err_y0 | err_dydz
91  +----------------------+------------+------------+------------+-------------+------------+------------+------------+------------
92  | 2009-03-26 04:10:21 | 0.42600000 | 0.00118000 | 0.00800000 | 0.00024000 | 0.00900000 | 0.00003000 | 0.00900000 | 0.00003000
93  | 2009-03-26 21:40:24 | 0.42600000 | 0.00136000 | 0.01600000 | -0.00005000 | 0.00900000 | 0.00003000 | 0.00900000 | 0.00003000
94  | 2010-03-20 01:00:00 | 0.27000001 | 0.00000000 |-0.03000000 | 0.00000000 | 0.15000001 | 0.00000000 | 0.15000001 | 0.00000000
95  | 2010-04-09 07:15:15 | 0.27664959 | 0.00127356 |-0.07965557 | -0.00001392 | 0.00289759 | 0.00007723 | 0.00288955 | 0.00008473
96  */
97  struct vertexSeed_t {Double_t x0, dxdz, y0, dydz, err_x0, err_dxdz, err_y0, err_dydz;};
98  vertexSeed_t b = { 0.42600000, 0.00118000, 0.00800000, 0.00024000, 0.00900000, 0.00003000, 0.00900000, 0.00003000};
99 #endif
100  Char_t *file = 0;
101  Int_t NFiles = 0;
102  TTreeIter iter;
103  while ((file = (Char_t *) Dir.NextFile())) {iter.AddFile(file); NFiles++;}
104  if (! NFiles) return;
105  TString output(Out);
106  if (output == "") {
107  if (! iter.Chain()) return;
108  if (! iter.Chain()->GetListOfFiles()) return;
109  const Char_t *file1 = iter.Chain()->GetListOfFiles()->At(0)->GetTitle();
110  TString dir = gSystem->BaseName(file1);
111  dir.ReplaceAll(".MuDst","");
112  output += dir;
113  }
114  TFile *fOut = new TFile(output,"recreate");
115  TTree *ftree = new TTree("StVertexT","Vertex tree");
116  ftree->SetAutoSave(1000000000); // autosave when 1 Gbyte written
117  Int_t bufsize = 64000;
118  Int_t split = 99;
119  if (split) bufsize /= 4;
120  StKFEvent *fStKFEvent = new StKFEvent();
121  TTree::SetBranchStyle(1); //new style by default
122  TBranch *branch = ftree->Branch("StKFEvent", "StKFEvent", &fStKFEvent, bufsize,split);
123  branch->SetAutoDelete(kFALSE);
124 
125  const Int_t*& MuEvent_mEventInfo_mRunId = iter("MuEvent.mEventInfo.mRunId");
126  const Int_t*& MuEvent_mEventInfo_mId = iter("MuEvent.mEventInfo.mId");
127  const Int_t& NoPrimaryVertices = iter("PrimaryVertices");
128  // const Float_t*& MuEvent_mRunInfo_mTpcDriftVelocity = iter("MuEvent.mRunInfo.mTpcDriftVelocity[2]");
129  const Float_t*& PrimaryVertices_mPosition_mX1 = iter("PrimaryVertices.mPosition.mX1");
130  const Float_t*& PrimaryVertices_mPosition_mX2 = iter("PrimaryVertices.mPosition.mX2");
131  const Float_t*& PrimaryVertices_mPosition_mX3 = iter("PrimaryVertices.mPosition.mX3");
132  const Float_t*& PrimaryVertices_mPosError_mX1 = iter("PrimaryVertices.mPosError.mX1");
133  const Float_t*& PrimaryVertices_mPosError_mX2 = iter("PrimaryVertices.mPosError.mX2");
134  const Float_t*& PrimaryVertices_mPosError_mX3 = iter("PrimaryVertices.mPosError.mX3");
135  const Float_t*& PrimaryVertices_mRanking = iter("PrimaryVertices.mRanking");
136  const UShort_t*& PrimaryVertices_mNTracksUsed = iter("PrimaryVertices.mNTracksUsed");
137 #ifdef __IDTRUTH__
138  const UShort_t*& PrimaryVertices_mIdTruth = iter("PrimaryVertices.mIdTruth");
139  const UShort_t*& PrimaryVertices_mQuality = iter("PrimaryVertices.mQuality");
140  const Int_t*& PrimaryVertices_mIdParent = iter("PrimaryVertices.mIdParent"); // >>
141 #endif
142  const Int_t*& PrimaryTracks_mVertexIndex = iter("PrimaryTracks.mVertexIndex");
143  const Int_t& NoPrimaryTracks = iter("PrimaryTracks");
144  const Int_t*& PrimaryTracks_mIndex2Global = iter("PrimaryTracks.mIndex2Global");
145  const Float_t*& PrimaryTracks_mChiSqZ = iter("PrimaryTracks.mChiSqZ");
146 #ifdef __IDTRUTH__0
147  const UShort_t*& PrimaryTracks_mIdTruth = iter("PrimaryTracks.mIdTruth");
148  const UShort_t*& PrimaryTracks_mQuality = iter("PrimaryTracks.mQuality");
149  const Int_t*& PrimaryTracks_mIdParentVx = iter("PrimaryTracks.mIdParentVx");
150 #endif
151  const Int_t& NoGlobalTracks = iter("GlobalTracks");
152  const Short_t*& GlobalTracks_mFlag = iter("GlobalTracks.mFlag");
153  const Float_t*& GlobalTracks_mEta = iter("GlobalTracks.mEta");
154  const Float_t*& GlobalTracks_mFirstPoint_mX3 = iter("GlobalTracks.mFirstPoint.mX3");
155 #ifdef __IDTRUTH__
156  const UShort_t*& GlobalTracks_mIdTruth = iter("GlobalTracks.mIdTruth");
157  const UShort_t*& GlobalTracks_mQuality = iter("GlobalTracks.mQuality");
158  const Int_t*& GlobalTracks_mIdParentVx = iter("GlobalTracks.mIdParentVx");
159 #endif
160  // const UChar_t*& GlobalTracks_mNHitsFit = iter("GlobalTracks.mNHitsFit");
161  // const Float_t*& GlobalTracks_mChiSqXY = iter("GlobalTracks.mChiSqXY");
162  const Int_t*& GlobalTracks_mIndex2Cov = iter("GlobalTracks.mIndex2Cov");
163  const Int_t& NoCovGlobTrack = iter("CovGlobTrack");
164  const Float_t*& CovGlobTrack_mImp = iter("CovGlobTrack.mImp");
165  const Float_t*& CovGlobTrack_mZ = iter("CovGlobTrack.mZ");
166  const Float_t*& CovGlobTrack_mPsi = iter("CovGlobTrack.mPsi");
167  const Float_t*& CovGlobTrack_mPti = iter("CovGlobTrack.mPti");
168  const Float_t*& CovGlobTrack_mTan = iter("CovGlobTrack.mTan");
169  const Float_t*& CovGlobTrack_mCurv = iter("CovGlobTrack.mCurv");
170  const Float_t*& CovGlobTrack_mImpImp = iter("CovGlobTrack.mImpImp");
171  const Float_t*& CovGlobTrack_mZImp = iter("CovGlobTrack.mZImp");
172  const Float_t*& CovGlobTrack_mZZ = iter("CovGlobTrack.mZZ");
173  const Float_t*& CovGlobTrack_mPsiImp = iter("CovGlobTrack.mPsiImp");
174  const Float_t*& CovGlobTrack_mPsiZ = iter("CovGlobTrack.mPsiZ");
175  const Float_t*& CovGlobTrack_mPsiPsi = iter("CovGlobTrack.mPsiPsi");
176  const Float_t*& CovGlobTrack_mPtiImp = iter("CovGlobTrack.mPtiImp");
177  const Float_t*& CovGlobTrack_mPtiZ = iter("CovGlobTrack.mPtiZ");
178  const Float_t*& CovGlobTrack_mPtiPsi = iter("CovGlobTrack.mPtiPsi");
179  const Float_t*& CovGlobTrack_mPtiPti = iter("CovGlobTrack.mPtiPti");
180  const Float_t*& CovGlobTrack_mTanImp = iter("CovGlobTrack.mTanImp");
181  const Float_t*& CovGlobTrack_mTanZ = iter("CovGlobTrack.mTanZ");
182  const Float_t*& CovGlobTrack_mTanPsi = iter("CovGlobTrack.mTanPsi");
183  const Float_t*& CovGlobTrack_mTanPti = iter("CovGlobTrack.mTanPti");
184  const Float_t*& CovGlobTrack_mTanTan = iter("CovGlobTrack.mTanTan");
185  // const Float_t*& Event_mMagneticField = iter("Event.mMagneticField");
186  const Double_t*& Event_mMagneticField = iter("MuEvent.mRunInfo.mMagneticFieldZ");
187 #ifdef __IDTRUTH__
188  const Int_t& NoMuMcVertex = iter("StMuMcVertex");
189 #if 0
190  const Int_t*& StMuMcVertex_Id = iter("StMuMcVertex.mId");
191 #endif
192  const Int_t*& StMuMcVertex_NoDaughters = iter("StMuMcVertex.mNoDaughters");
193  const Int_t*& StMuMcVertex_IdParTrk = iter("StMuMcVertex.mIdParTrk");
194  const Float_t*& StMuMcVertex_time = iter("StMuMcVertex.mTime");
195  const Float_t*& StMuMcVertex_xyzV_mX1 = iter("StMuMcVertex.mXyzV.mX1");
196  const Float_t*& StMuMcVertex_xyzV_mX2 = iter("StMuMcVertex.mXyzV.mX2");
197  const Float_t*& StMuMcVertex_xyzV_mX3 = iter("StMuMcVertex.mXyzV.mX3");
198  const Int_t& NoMuMcTrack = iter("StMuMcTrack");
199 #if 0
200  const Int_t*& StMuMcTrack_Id = iter("StMuMcTrack.mId");
201 #endif
202  const Int_t*& StMuMcTrack_gePid = iter("StMuMcTrack.mGePid");
203 #if 0
204  const Int_t*& StMuMcTrack_IdVx = iter("StMuMcTrack.mIdVx");
205  const Int_t*& StMuMcTrack_IdVxEnd = iter("StMuMcTrack.mIdVxEnd");
206  const Float_t*& StMuMcTrack_pxyz_mX1 = iter("StMuMcTrack.mPxyz.mX1");
207  const Float_t*& StMuMcTrack_pxyz_mX2 = iter("StMuMcTrack.mPxyz.mX2");
208  const Float_t*& StMuMcTrack_pxyz_mX3 = iter("StMuMcTrack.mPxyz.mX3");
209 #endif
210 #endif
211  StKFVertexFinder fitter;
212 #ifdef DRAW_RECO_HISTOS
213  if (! gROOT->IsBatch()) {TCanvas *c1 = new TCanvas("c1z","c1z",1400,600); fitter.SetCanvas(c1);}
214 #endif // DRAW_RECO_HISTOS
215 
216  // Now iterations
217  Int_t nev = 0;
218  while (iter.Next()) { // events loop
219  nev++;
220  if (nev < first) continue;
221  if (nev > last) break;
222 #ifdef EVENT_DISPLAY
223  if (! eventD) eventD = new StDraw3D(); // + Geometry // StDraw3D *eventD = new StDraw3D(0);// View with no detector geometry decoration
224  else eventD->Clear();
225 #endif // EVENT_DISPLAY
226  fStKFEvent->Clear();
227  KFParticle::SetField(Event_mMagneticField[0]);
228 #ifdef DEBUG
229  cout << "#" << nev << "\tRun " << MuEvent_mEventInfo_mRunId[0] << "\tEvent " << MuEvent_mEventInfo_mId[0] << endl;
230  cout << "NoTracks\t" << (int) NoGlobalTracks << " global\t" << (int) NoPrimaryTracks << " primary" << endl;
231 #endif
232  fitter.Reset();
233 #if 0
234  TObjArray tracks;
235  tracks.SetOwner(kTRUE);
236  TObjArray particles;
237  particles.SetOwner(kTRUE);
238 #endif
239  // Add measured multiplicities
240  Double_t ymax = fitter.Vtx()->GetMaximum();
241  for (Int_t l = 0; l < NoPrimaryVertices; l++) {
242  Int_t mult = 0;
243  Int_t multP = 0;
244  Int_t mWest = 0;
245  Int_t mEast = 0;
246  Int_t Q = 0;
247  for (Int_t k = 0; k <NoPrimaryTracks; k++) {
248  if (PrimaryTracks_mVertexIndex[k] != l) continue;
249  Int_t kg = PrimaryTracks_mIndex2Global[k];
250  if (kg < 0 || kg >= NoGlobalTracks) continue;
251  if (GlobalTracks_mFlag[kg] < 0) continue; // Bad fit
252  if (GlobalTracks_mFlag[kg] > 700) continue; // FTPC
253  if (GlobalTracks_mFlag[kg]%100 == 11) continue; // Short track pointing to EEMC
254  Int_t kgc = GlobalTracks_mIndex2Cov[kg];
255  if (kgc < 0 || kgc > NoCovGlobTrack) continue;
256  mult++;
257  if (CovGlobTrack_mPti[kgc] < 0) Q -= 1;
258  else Q += 1;
259  if (PrimaryTracks_mChiSqZ[k] < StAnneling::Chi2Cut()) multP++;
260  if (GlobalTracks_mEta[kg] > 0 && GlobalTracks_mFirstPoint_mX3[kg] > 0) mWest++;
261  if (GlobalTracks_mEta[kg] < 0 && GlobalTracks_mFirstPoint_mX3[kg] < 0) mEast++;
262  }
263  StMuDstVtxT V(PrimaryVertices_mPosition_mX1[l],PrimaryVertices_mPosition_mX2[l],PrimaryVertices_mPosition_mX3[l],
264  PrimaryVertices_mPosError_mX1[l],PrimaryVertices_mPosError_mX2[l],PrimaryVertices_mPosError_mX3[l],
265  PrimaryVertices_mNTracksUsed[l],mult,multP,mWest,mEast,Q,PrimaryVertices_mRanking[l],
266  PrimaryVertices_mIdTruth[l],PrimaryVertices_mQuality[l],PrimaryVertices_mIdParent[l]);
267 #ifdef __IDTRUTH__
268  if (V.QaTruth() > 0) {
269  V.SetMc(NoMuMcVertex,NoMuMcTrack,StMuMcVertex_time,
270  StMuMcVertex_xyzV_mX1,StMuMcVertex_xyzV_mX2,StMuMcVertex_xyzV_mX3,
271  StMuMcVertex_NoDaughters,StMuMcVertex_IdParTrk,StMuMcTrack_gePid);
272  }
273 #endif
274  cout << Form("MuDst Primary Vertex: %3i with ",l) << V << endl;
275  fStKFEvent->AddMuVtx(V);
276  Double_t X = PrimaryVertices_mPosition_mX3[l];
277  Double_t Y = mult;
278  if (1.1*Y > ymax) ymax = 1.1*Y;
279  TPolyMarker * pm = new TPolyMarker(1, &X, &Y);
280  fitter.VtxM()->GetListOfFunctions()->Add(pm);
281  pm->SetMarkerStyle(20);
282  pm->SetMarkerColor(l+2);
283  pm->SetMarkerSize(2);
284  Y = multP;
285  pm = new TPolyMarker(1, &X, &Y);
286  fitter.VtxM()->GetListOfFunctions()->Add(pm);
287  pm->SetMarkerStyle(21);
288  pm->SetMarkerColor(l+2);
289  pm->SetMarkerSize(2);
290  };
291  fitter.Vtx()->SetMaximum(ymax);
292  Int_t NGoodGlobals = 0;
293  for (Int_t kg = 0; kg < NoGlobalTracks; kg++) {
294 #if 0
295  tracks.AddAtAndExpand (0,kg);
296  particles.AddAtAndExpand (0,kg);
297 #endif
298  if (GlobalTracks_mFlag[kg] < 0) continue; // Bad fit
299  if (GlobalTracks_mFlag[kg] > 700) continue; // FTPC
300  if (GlobalTracks_mFlag[kg]%100 == 11) continue; // Short track pointing to EEMC
301  // if (TMath::Abs(GlobalTracks_mEta[kg]) > 5) continue;
302  Int_t kgc = GlobalTracks_mIndex2Cov[kg];
303  if (kgc < 0 || kgc > NoCovGlobTrack) continue;
304  // if (TMath::Abs(CovGlobTrack_mImp[kgc]) > 10) continue;
305  // if (TMath::Abs(CovGlobTrack_mZ[kgc]) > zmax) continue;
306 
307  Double_t parsT[6] = {
308  CovGlobTrack_mImp[kgc],CovGlobTrack_mZ[kgc],CovGlobTrack_mPsi[kgc],
309  CovGlobTrack_mPti[kgc],CovGlobTrack_mTan[kgc],CovGlobTrack_mCurv[kgc]};
310  Double_t errsT[15] = {
311  CovGlobTrack_mImpImp[kgc],
312  CovGlobTrack_mZImp[kgc], CovGlobTrack_mZZ[kgc],
313  CovGlobTrack_mPsiImp[kgc],CovGlobTrack_mPsiZ[kgc],CovGlobTrack_mPsiPsi[kgc],
314  CovGlobTrack_mPtiImp[kgc],CovGlobTrack_mPtiZ[kgc],CovGlobTrack_mPtiPsi[kgc],CovGlobTrack_mPtiPti[kgc],
315  CovGlobTrack_mTanImp[kgc],CovGlobTrack_mTanZ[kgc],CovGlobTrack_mTanPsi[kgc],CovGlobTrack_mTanPti[kgc],
316  CovGlobTrack_mTanTan[kgc]};
317  StDcaGeometry *dca = new StDcaGeometry();
318  dca->set(parsT, errsT);
319  KFParticle *particle = fitter.AddTrackAt(dca,kg);
320  delete dca;
321  Int_t iWE = 0;
322  if (GlobalTracks_mEta[kg] > 0 && GlobalTracks_mFirstPoint_mX3[kg] > 0) iWE = 1;
323  if (GlobalTracks_mEta[kg] < 0 && GlobalTracks_mFirstPoint_mX3[kg] < 0) iWE = 2;
324  particle->SetID(10000*iWE + kg+1);
325  particle->SetIdTruth(GlobalTracks_mIdTruth[kg],GlobalTracks_mQuality[kg]);
326  particle->SetIdParentVx(GlobalTracks_mIdParentVx[kg]);
327 #ifdef DEBUG2
328  cout << "particle: " << *particle << endl;
329 #endif
330  // tracks.AddAt(dca,kg);
331  NGoodGlobals++;
332  }
333 
334  if (NGoodGlobals < 2) continue;
335  fitter.Fit();
336  if (! fitter.Vertices()) continue;
337  fitter.Vertices()->SetMc(NoMuMcVertex,NoMuMcTrack,StMuMcVertex_time,
338  StMuMcVertex_xyzV_mX1,StMuMcVertex_xyzV_mX2,StMuMcVertex_xyzV_mX3,
339  StMuMcVertex_NoDaughters,StMuMcVertex_IdParTrk,StMuMcTrack_gePid);
340  fitter.Vertices()->Print();
341 
342  Int_t Nvtx = fitter.Vertices()->NoVertices();
343  for (Int_t l = 0; l < Nvtx; l++) {
344  StKFVertex *V = fitter.Vertices()->Vertex(l);
345  if (V) {
346  fStKFEvent->AddKFVtx(*V);
347  }
348  }
349 
350 
351  // Matching Dst => KFVertex 3D chi2
352  Int_t NoMuDstVtx = fStKFEvent->NoMuDstVtx();
353  Int_t NoKFVtx = fStKFEvent->NoKFVtx();
354  for (Int_t i = 0; i < NoMuDstVtx; i++) {
355  StVertexT *VI = (StVertexT *) (*(fStKFEvent->MuDstVtx()))[i];
356  for (Int_t j = 0; j < NoKFVtx; j++) {
357  StVertexT *VJ = (StVertexT *) (*(fStKFEvent->KFVtx()))[j];
358  TVector3 diff = VI->Xyz() - VJ->Xyz();
359  Double_t chi2 =
360  diff.x()*diff.x()/(VI->SigmaXyz().x()*VI->SigmaXyz().x() + VJ->SigmaXyz().x()*VJ->SigmaXyz().x()) +
361  diff.y()*diff.y()/(VI->SigmaXyz().y()*VI->SigmaXyz().y() + VJ->SigmaXyz().y()*VJ->SigmaXyz().y()) +
362  diff.z()*diff.z()/(VI->SigmaXyz().z()*VI->SigmaXyz().z() + VJ->SigmaXyz().z()*VJ->SigmaXyz().z());
363  if (chi2 < 1e3) {
364  fStKFEvent->AddDKFPair(i,j,*VI,*VJ,chi2);
365  }
366  }
367  }
368  for (Int_t i = 1; i < NoKFVtx; i++) {
369  StVertexT *VI = (StVertexT *) (*(fStKFEvent->KFVtx()))[i];
370  for (Int_t j = 0; j < i; j++) {
371  StVertexT *VJ = (StVertexT *) (*(fStKFEvent->KFVtx()))[j];
372  TVector3 diff = VI->Xyz() - VJ->Xyz();
373  Double_t chi2 =
374  diff.x()*diff.x()/(VI->SigmaXyz().x()*VI->SigmaXyz().x() + VJ->SigmaXyz().x()*VJ->SigmaXyz().x()) +
375  diff.y()*diff.y()/(VI->SigmaXyz().y()*VI->SigmaXyz().y() + VJ->SigmaXyz().y()*VJ->SigmaXyz().y());
376  if (chi2 < 1e3) {
377  fStKFEvent->AddKFKFPair(i,j,*VI,*VJ,chi2);
378  }
379  }
380  }
381  ftree->Fill();
382 #ifdef EVENT_DISPLAY
383  // fill
384  TArrayF xyzMcVxT(3*NoMuMcVertex); // from trigger event
385  TArrayF xyzMcVxP(3*NoMuMcVertex); // from pile up
386  Int_t NT = 0;
387  Int_t NP = 0;
388  for( int i = 0; i < NoMuMcVertex; ++i ) {
389  if (TMath::Abs(StMuMcVertex_time[i]) < 100e-9) {
390  xyzMcVxT[3*NT ] = StMuMcVertex_xyzV_mX1[i];
391  xyzMcVxT[3*NT+1] = StMuMcVertex_xyzV_mX2[i];
392  xyzMcVxT[3*NT+2] = StMuMcVertex_xyzV_mX3[i];
393  NT++;
394  } else {
395  xyzMcVxP[3*NP ] = StMuMcVertex_xyzV_mX1[i];
396  xyzMcVxP[3*NP+1] = StMuMcVertex_xyzV_mX2[i];
397  xyzMcVxP[3*NP+2] = StMuMcVertex_xyzV_mX3[i];
398  NP++;
399  }
400  }
401  TArrayF xyzRcVx(3*Nvtx);
402  Int_t NR = 0;
403  for (Int_t l = 0; l < Nvtx; l++) {
404  StKFVertex *V = fitter.Vertices()->Vertex(l);
405  if (V) {
406  xyzRcVx[3*NR ] = V->Vertex().GetX();
407  xyzRcVx[3*NR+1] = V->Vertex().GetY();
408  xyzRcVx[3*NR+2] = V->Vertex().GetZ();
409  NR++;
410  }
411  }
412  eventD->Points(NR, xyzRcVx.GetArray(), kVtx); eventD->SetComment("Rc Vtx and Geometry");
413  eventD->Points(NT, xyzMcVxT.GetArray(),kUsedHit); eventD->SetComment("Mc Vtx triggered and Geometry");
414  eventD->Points(NP, xyzMcVxP.GetArray(),kUnusedHit); eventD->SetComment("Mc Vtx pile-up and Geometry");
415  eventD->UpdateModified();
416  while(!gSystem->ProcessEvents()){};
417 #endif // EVENT_DISPLAY
418 #if defined(DRAW_RECO_HISTOS) || defined(EVENT_DISPLAY)
419  if (! gROOT->IsBatch() && Ask()) break;
420 #endif
421  } // loop ove events
422 
423  fOut->Write();
424 }
425 //________________________________________________________________________________
426 void Analysis(const Char_t *files="./y*.root") {
427  TDirIter Dir(files);
428  Char_t *file = 0;
429  TFile *fOut = new TFile("MuDst_KFV.root","recreate");
430  TH2D *multDK = new TH2D("multDK","log_{2} (Multiplicity_{MuDst}) versus log_{2} (Multiplicity_{KFVertex})",
431  120,-1.0,11.0, 120,-1.0,11.0);
432  TH2D *multDKQ = new TH2D("multDKQ","log_{2} (MultiplicityQ_{MuDst}) versus log_{2} (MultiplicityQ_{KFVertex})",
433  120,-1.0,11.0, 120,-1.0,11.0);
434  TH2D *dXD = new TH2D("dXD","dX MuDst - MC versus log_{2} (Multiplicity_{MuDst})",120,-1.0,11.0,100,-5,5);
435  TH2D *dYD = new TH2D("dYD","dY MuDst - MC versus log_{2} (Multiplicity_{MuDst})",120,-1.0,11.0,100,-5,5);
436  TH2D *dZD = new TH2D("dZD","dZ MuDst - MC versus log_{2} (Multiplicity_{MuDst})",120,-1.0,11.0,100,-5,5);
437 
438  TH2D *dXK = new TH2D("dXK","dX KFVertex - MC versus log_{2} (Multiplicity_{KFVertex})",120,-1.0,11.0,100,-5,5);
439  TH2D *dYK = new TH2D("dYK","dY KFVertex - MC versus log_{2} (Multiplicity_{KFVertex})",120,-1.0,11.0,100,-5,5);
440  TH2D *dZK = new TH2D("dZK","dZ KFVertex - MC versus log_{2} (Multiplicity_{KFVertex})",120,-1.0,11.0,100,-5,5);
441  cout << "|Simulation Production | Total no. | MuDst Efficiency | <Multiplicity> | KFVertex Efficiency | <Multiplicity>|" << endl;
442  while ((file = (Char_t *) Dir.NextFile())) {
443  TString File(file);
444  if (File.Contains("event") || File.Contains("geant") ||
445  File.Contains("hist") || File.Contains("tags") || File.Contains("runco") ||
446  File.Contains("minimc") || File.Contains("event") ||
447  File.Contains("MuDst")) continue;
448  TFile *f = new TFile (File);
449  if (! f) continue;
450  TTree *tree = (TTree *) f->Get("StVertexT");
451  if (! tree ) {delete f; continue;}
452  TString Name(gSystem->BaseName(f->GetName()));
453  Name.ReplaceAll(".root","");
454  TString Title(Name);
455  Title.ReplaceAll("_"," ");
456  fOut->cd();
457 
458  TH1D *DM = new TH1D(Form("DM%s",Name.Data()),Form("MuDst Multiplicity for %s",Title.Data()),3000,0,3000);
459  TH1D *DMQ = new TH1D(Form("DMQ%s",Name.Data()),Form("MuDst Multiplicity*QA for %s",Title.Data()),3000,0,3000);
460  TH1D *KM = new TH1D(Form("KM%s",Name.Data()),Form("KFVer Multiplicity for %s",Title.Data()),3000,0,3000);
461  TH1D *KMQ = new TH1D(Form("KMQ%s",Name.Data()),Form("KFVer Multiplicity*QA for %s",Title.Data()),3000,0,3000);
462  StKFEvent *fStKFEvent = new StKFEvent();
463  TBranch *branch = tree->GetBranch("StKFEvent");
464  if (! branch) continue;
465  // tree->SetMakeClass(1);
466  branch->SetAddress(&fStKFEvent);
467  Int_t nbytes = 0, nb = 0;// ierr = 0, nevt = 0;
468  Long64_t nentries = tree->GetEntries();
469  for (Long64_t jentry=0; jentry<nentries;jentry++) {
470  //in case of a TTree, ientry is the entry number in the current file
471  if (tree->LoadTree(jentry) < 0) break;
472  nb = tree->GetEntry(jentry); nbytes += nb;
473  Int_t NoMuDst = fStKFEvent->NoMuDstVtx();
474  Int_t NoKFVtx = fStKFEvent->NoKFVtx();
475  // cout << "Event. \t" << jentry << "\tNo Dst " << NoMuDst << "\tKFV " << NoKFVtx << endl;
476  // find IdTruth = 1 vertices and plot them
477  TClonesArray *MuDst = fStKFEvent->MuDstVtx();
478  Int_t MultMx = -1;
479  Int_t kd = -1;
480  Double_t MultD = 0.5;
481  Double_t MultDQ = 0.5;
482  TVector3 dXyz;
483  for (Int_t l = 0; l < NoMuDst; l++) {
484  StMuDstVtxT *md = (StMuDstVtxT *) MuDst->UncheckedAt(l);
485  if (md->IdTruth() != 1) continue;
486  Int_t Mult = md->Mult();
487  if (Mult > MultMx) {MultMx = Mult; kd = l;}
488  }
489  if (kd >= 0) {
490  StMuDstVtxT *md = (StMuDstVtxT *) MuDst->UncheckedAt(kd);
491  MultD = md->Mult();
492  DM->Fill(MultD);
493  MultDQ = TMath::Nint(MultD*md->QaTruth()/100.);
494  DMQ->Fill(MultDQ);
495  dXyz = md->Xyz() - md->XyzMc();
496  dXD->Fill(TMath::Log2(MultD),dXyz.x());
497  dYD->Fill(TMath::Log2(MultD),dXyz.y());
498  dZD->Fill(TMath::Log2(MultD),dXyz.z());
499  }
500  TClonesArray *KF = fStKFEvent->KFVtx();
501  MultMx = -1;
502  Int_t kf = -1;
503  for (Int_t l = 0; l < NoKFVtx; l++) {
504  StVertexT *mk = (StVertexT *) KF->UncheckedAt(l);
505  if (mk->IdTruth() != 1) continue;
506  Int_t Mult = mk->Mult();
507  if (Mult > MultMx) {MultMx = Mult; kf = l;}
508  }
509  Double_t MultK = 0.5;
510  Double_t MultKQ = 0.5;
511  if (kf >= 0) {
512  StVertexT *mk = (StVertexT *) KF->UncheckedAt(kf);
513  MultK = mk->Mult();
514  KM->Fill(MultK);
515  MultKQ = TMath::Nint(MultK*mk->QaTruth()/100.);
516  KMQ->Fill(MultKQ);
517  dXyz = mk->Xyz() - mk->XyzMc();
518  dXK->Fill(TMath::Log2(MultK),dXyz.x());
519  dYK->Fill(TMath::Log2(MultK),dXyz.y());
520  dZK->Fill(TMath::Log2(MultK),dXyz.z());
521  }
522  multDK->Fill(TMath::Log2(MultK), TMath::Log2(MultD));
523  multDKQ->Fill(TMath::Log2(MultKQ), TMath::Log2(MultDQ));
524  }
525  cout << "Process \t" << f->GetName() << "\tread " << nentries << " entries and " << nbytes << " Bytes" << endl;
526  delete f;
527  TH1D *hists[4] = {DM, DMQ, KM, KMQ};
528  cout << "|" << DM->GetTitle() << "|\t" << nentries;
529  for (Int_t i = 0; i < 4; i++) {
530 #if 0
531  cout << hists[i]->GetName() << "\t" << hists[i]->GetTitle()
532  << "\tEntries = " << hists[i]->GetEntries()
533  << "\tMean = " << hists[i]->GetMean() << endl;
534 #else
535  cout << "|\t" << 100*hists[i]->GetEntries()/nentries << "\t|\t" << hists[i]->GetMean();
536 #endif
537  }
538  cout << "\t|" << endl;
539  // compress multiplicity histograms
540  TH1D *DMr = 0, *DMQr = 0, *KMr = 0, *KMQr = 0;
541  Int_t nx = DM->GetNbinsX();
542  for (Int_t i = nx; i > 0; i--) {
543  if (! DMr) {
544  if (DM->GetBinContent(i) <= 0 && KM->GetBinContent(i) <= 0) continue;
545  DMr = new TH1D(Form("DMr%s",Name.Data()),Form("MuDst Multiplicity for %s",Title.Data()),100,0,DM->GetXaxis()->GetBinUpEdge(i));
546  DMQr = new TH1D(Form("DMQr%s",Name.Data()),Form("MuDst Multiplicity*QA for %s",Title.Data()),100,0,DM->GetXaxis()->GetBinUpEdge(i));
547  KMr = new TH1D(Form("KMr%s",Name.Data()),Form("KFVer Multiplicity for %s",Title.Data()),100,0,DM->GetXaxis()->GetBinUpEdge(i));
548  KMQr = new TH1D(Form("KMQr%s",Name.Data()),Form("KFVer Multiplicity*QA for %s",Title.Data()),100,0,DM->GetXaxis()->GetBinUpEdge(i));
549  }
550  DMr->Fill(DM->GetBinCenter(i),DM->GetBinContent(i));
551  DMQr->Fill(DMQ->GetBinCenter(i),DMQ->GetBinContent(i));
552  KMr->Fill(KM->GetBinCenter(i),KM->GetBinContent(i));
553  KMQr->Fill(KMQ->GetBinCenter(i),KMQ->GetBinContent(i));
554  }
555  delete DM; delete DMQ; delete KM; delete KMQ;
556  }
557  fOut->Write();
558 }
559 //________________________________________________________________________________
560 void MuPrmVtx(Int_t last, const Char_t *files = "./*MuDst.root", const Char_t *Out="") {
561  MuPrmVtx(0,last,files,Out);
562 }
563 //________________________________________________________________________________
564 void MuPrmVtx(const Char_t *files = "./*MuDst.root", const Char_t *Out="") {
565  MuPrmVtx(0,99999,files,Out);
566 }
567 //________________________________________________________________________________
568 // $Log: MuPrmVtx.C,v $
569 // Revision 2.3 2013/04/10 22:14:20 fisyak
570 // Roll back to version 04/04/2013
571 //
572 // Revision 2.1 2012/05/07 14:56:14 fisyak
573 // Add StKFVertexMaker
574 //
575 // Revision 1.13 2012/02/18 23:20:52 fisyak
576 // Rename StKFVertexFitter => StKFVertexFinder
577 //
578 // Revision 1.12 2012/02/07 19:38:26 fisyak
579 // Repackage
580 //
Class StDraw3D - to draw the 3D primitives like 3D points and 3D lines decorated with the STAR detect...
Definition: StDraw3D.h:165
virtual TObject * Points(int n, const float *xyz, EDraw3DStyle sty)
This is an overloaded member function, provided for convenience.
Definition: StDraw3D.cxx:596
Definition: beam.h:43
static void SetField(Double_t Bz)
Definition: KFParticle.h:335
virtual void Clear(Option_t *opt="update")
Remove all objects from the list and update the screen if opt is &quot;update&quot;.
Definition: StDraw3D.cxx:398