Macros moved from oldmacros on the standard ITS directory
authorbarbera <barbera@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 3 Jul 2002 11:52:51 +0000 (11:52 +0000)
committerbarbera <barbera@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 3 Jul 2002 11:52:51 +0000 (11:52 +0000)
ITS/AliCascadeComparison.C [new file with mode: 0644]
ITS/AliCascadeFindVertices.C [new file with mode: 0644]
ITS/AliV0Comparison.C [new file with mode: 0644]
ITS/AliV0FindVertices.C [new file with mode: 0644]

diff --git a/ITS/AliCascadeComparison.C b/ITS/AliCascadeComparison.C
new file mode 100644 (file)
index 0000000..bffb293
--- /dev/null
@@ -0,0 +1,384 @@
+/****************************************************************************
+ *           Very important, delicate and rather obscure macro.             *
+ *                                                                          *
+ *               Creates list of "findable" cascades,                       *
+ *             calculates efficiency, resolutions etc.                      *
+ *                                                                          *
+ *  Origin: Christian Kuhn, IReS, Strasbourg, christian.kuhn@ires.in2p3.fr  *
+ ****************************************************************************/
+
+#ifndef __CINT__
+  #include <iostream.h>
+  #include <fstream.h>
+
+  #include "TH1.h"
+  #include "TFile.h"
+  #include "TTree.h"
+  #include "TObjArray.h"
+  #include "TStyle.h"
+  #include "TCanvas.h"
+  #include "TLine.h"
+  #include "TText.h"
+  #include "TParticle.h"
+  #include "TStopwatch.h"
+
+  #include "AliRun.h"
+  #include "AliPDG.h"
+  #include "AliCascadeVertex.h"
+#endif
+
+struct GoodCascade {
+  Int_t nlab,plab;   // V0's daughter labels
+  Int_t blab;        // Bachelor label
+  Int_t code;
+  Float_t px,py,pz;
+  Float_t x,y,z;
+};
+Int_t good_cascades(GoodCascade *gt, Int_t max);
+
+Int_t AliCascadeComparison(Int_t code=3312) {
+  //code= 3312; //kXiMinus 
+  //code=-3312; //kXiPlusBar
+  //code= 3334; //kOmegaMinus
+  //code=-3334; //kOmegaPlusBar
+
+   cerr<<"Doing comparison...\n";
+
+   const Double_t cascadeWindow=0.05, cascadeWidth=0.015; 
+   Double_t cascadeMass=0.5;
+   switch (code) {
+   case kXiMinus:
+   case kXiPlusBar:    cascadeMass=1.32131; break;
+   case kOmegaMinus: 
+   case kOmegaPlusBar: cascadeMass=1.67245; break;
+   default: cerr<<"Invalid PDG code !\n"; return 1;
+   }
+
+   TStopwatch timer;
+
+   /*** Load reconstructed cascades ***/
+   TFile *cf=TFile::Open("AliCascadeVertices.root");
+   if (!cf->IsOpen()){cerr<<"Can't open AliCascadeVertices.root !\n";return 2;}
+   TObjArray carray(1000);
+   TTree *cTree=(TTree*)cf->Get("TreeCasc");
+   TBranch *branch=cTree->GetBranch("cascades");
+   Int_t nentr=(Int_t)cTree->GetEntries();
+   for (Int_t i=0; i<nentr; i++) {
+       AliCascadeVertex *iovertex=new AliCascadeVertex; 
+       branch->SetAddress(&iovertex);
+       cTree->GetEvent(i);
+       carray.AddLast(iovertex);
+   }
+   delete cTree;
+   cf->Close();
+
+   /*** Check if the file with the "good" cascades exists ***/
+   GoodCascade gc[100];
+   Int_t ngood=0;
+   ifstream in("good_cascades");
+   if (in) {
+      cerr<<"Reading good cascades...\n";
+      while (in>>gc[ngood].nlab>>gc[ngood].plab>>
+                gc[ngood].blab>>gc[ngood].code>>
+                 gc[ngood].px>>gc[ngood].py>>gc[ngood].pz>>
+                 gc[ngood].x >>gc[ngood].y >>gc[ngood].z) {
+         ngood++;
+         cerr<<ngood<<'\r';
+         if (ngood==100) {
+            cerr<<"Too many good cascades !\n";
+            break;
+         }
+      }
+      if (!in.eof()) cerr<<"Read error (good_cascades) !\n";
+   } else {
+     /*** generate a file with the "good" cascades ***/
+      cerr<<"Marking good cascades (this will take a while)...\n";
+      ngood=good_cascades(gc,100);
+      ofstream out("good_cascades");
+      if (out) {
+         for (Int_t ngd=0; ngd<ngood; ngd++)            
+            out<<gc[ngd].nlab<<' '<<gc[ngd].plab<<' '<<
+                gc[ngd].blab<<' '<<gc[ngd].code<<' '<<
+                 gc[ngd].px<<' '<<gc[ngd].py<<' '<<gc[ngd].pz<<' '<<
+                 gc[ngd].x <<' '<<gc[ngd].y <<' '<<gc[ngd].z <<endl;
+      } else cerr<<"Can not open file (good_cascades) !\n";
+      out.close();
+   }
+
+   /*** create some histograms ***/
+   TH1F *hp=new TH1F("hp","Angular Resolution",30,-30.,30.); //phi resolution 
+   hp->SetXTitle("(mrad)"); hp->SetFillColor(2);
+   TH1F *hl=new TH1F("hl","Lambda Resolution",30,-30,30);
+   hl->SetXTitle("(mrad)"); hl->SetFillColor(1); hl->SetFillStyle(3013); 
+   TH1F *hpt=new TH1F("hpt","Relative Pt Resolution",30,-10.,10.); 
+   hpt->SetXTitle("(%)"); hpt->SetFillColor(2); 
+
+   TH1F *hx=new TH1F("hx","Position Resolution (X,Y)",30,-3.,3.); //x res. 
+   hx->SetXTitle("(mm)"); hx->SetFillColor(6);
+   TH1F *hy=new TH1F("hy","Position Resolution (Y)",30,-3.,3.);   //y res
+   hy->SetXTitle("(mm)"); hy->SetFillColor(1); hy->SetFillStyle(3013);
+   TH1F *hz=new TH1F("hz","Position Resolution (Z)",30,-3.,3.);   //z res. 
+   hz->SetXTitle("(mm)"); hz->SetFillColor(6);
+
+   Double_t pmin=0.2, pmax=4.2; Int_t nchan=20;
+   TH1F *hgood=new TH1F("hgood","Good Cascades",nchan,pmin,pmax);    
+   TH1F *hfound=new TH1F("hfound","Found Cascades",nchan,pmin,pmax);
+   TH1F *hfake=new TH1F("hfake","Fake Cascades",nchan,pmin,pmax);
+   TH1F *hg=new TH1F("hg","Efficiency for Good Cascades",nchan,pmin,pmax);
+   hg->SetLineColor(4); hg->SetLineWidth(2);
+   TH1F *hf=new TH1F("hf","Probability of Fake Cascades",nchan,pmin,pmax);
+   hf->SetFillColor(1); hf->SetFillStyle(3013); hf->SetLineWidth(2);
+
+   Double_t mmin=cascadeMass-cascadeWindow, mmax=cascadeMass+cascadeWindow;
+   TH1F *cs =new TH1F("cs","Cascade Effective Mass",40, mmin, mmax);
+   cs->SetXTitle("(GeV)"); cs->SetFillColor(6);
+
+   Double_t pxg=0.,pyg=0.,ptg=0.;
+   Int_t nlab=-1, plab=-1, blab=-1;
+   Int_t i;
+   for (i=0; i<nentr; i++) {
+       AliCascadeVertex *cascade=(AliCascadeVertex*)carray.UncheckedAt(i);
+       cascade->GetV0labels(nlab,plab); 
+       nlab=TMath::Abs(nlab); plab=TMath::Abs(plab);
+       blab=TMath::Abs(cascade->GetBachelorLabel());
+
+       cascade->ChangeMassHypothesis(code);
+
+       Double_t mass=cascade->GetEffMass();
+       cs->Fill(mass);
+
+       if (TMath::Abs(mass-cascadeMass)>cascadeWidth) continue;
+
+       Int_t j;
+       for (j=0; j<ngood; j++) {
+          if (gc[j].code != cascade->GetPdgCode()) continue;
+          if (gc[j].nlab == nlab)
+          if (gc[j].plab == plab)
+          if (gc[j].blab == blab) break;
+       }
+
+       Double_t px,py,pz; cascade->GetPxPyPz(px,py,pz);
+       Double_t pt=TMath::Sqrt(px*px+py*py);
+
+       if (j==ngood) {
+          hfake->Fill(pt);
+          cerr<<"Fake cascade: ("<<nlab<<","<<plab<<","<<blab<<")\n";
+          continue;
+       }
+
+       pxg=gc[j].px; pyg=gc[j].py; ptg=TMath::Sqrt(pxg*pxg+pyg*pyg);
+       Double_t phig=TMath::ATan2(pyg,pxg), phi=TMath::ATan2(py,px);
+       Double_t lamg=TMath::ATan2(gc[j].pz,ptg), lam=TMath::ATan2(pz,pt);
+       hp->Fill((phi - phig)*1000.);
+       hl->Fill((lam - lamg)*1000.);
+       hpt->Fill((1/pt - 1/ptg)/(1/ptg)*100.);
+
+       Double_t x,y,z; cascade->GetXYZ(x,y,z);
+       hx->Fill((x-gc[j].x)*10);
+       hy->Fill((y-gc[j].y)*10);
+       hz->Fill((z-gc[j].z)*10);
+
+       hfound->Fill(ptg);
+       gc[j].nlab=-1;
+
+   }
+   for (i=0; i<ngood; i++) {
+      if (gc[i].code != code) continue;
+      pxg=gc[i].px; pyg=gc[i].py; ptg=TMath::Sqrt(pxg*pxg+pyg*pyg);
+      hgood->Fill(ptg);
+      nlab=gc[i].nlab; plab=gc[i].plab; blab=gc[i].blab;
+      if (nlab < 0) continue;
+     cerr<<"Cascade ("<<nlab<<','<<plab<<","<<blab<<") has not been found !\n";
+   }
+
+   carray.Delete();
+
+   Stat_t ng=hgood->GetEntries();
+   Stat_t nf=hfound->GetEntries();
+
+   cerr<<"Number of found cascades: "<<nentr<<" ("<<nf<<" in the peak)\n";
+   cerr<<"Number of good cascades: "<<ng<<endl;
+
+   if (ng!=0) 
+      cerr<<"Integral efficiency is about "<<nf/ng*100.<<" %\n";
+
+   gStyle->SetOptStat(111110);
+   gStyle->SetOptFit(1);
+
+   TCanvas *c1=new TCanvas("c1","",0,0,580,610);
+   c1->Divide(2,2);
+
+   c1->cd(1);
+   gPad->SetFillColor(42); gPad->SetFrameFillColor(10); 
+   //hp->Fit("gaus");
+   hp->Draw();
+   hl->Draw("same"); c1->cd();
+
+   c1->cd(2);
+   gPad->SetFillColor(42); gPad->SetFrameFillColor(10);
+   //hpt->Fit("gaus"); c1->cd();
+   hpt->Draw(); c1->cd();
+
+   c1->cd(3);
+   gPad->SetFillColor(42); gPad->SetFrameFillColor(10); 
+   //hx->Fit("gaus"); 
+   hx->Draw(); 
+   hy->Draw("same"); c1->cd();
+
+   c1->cd(4);
+   gPad->SetFillColor(42); gPad->SetFrameFillColor(10);
+   //hz->Fit("gaus");
+   hz->Draw();
+
+
+   TCanvas *c2=new TCanvas("c2","",600,0,580,610);
+   c2->Divide(1,2);
+
+   c2->cd(1);
+   gPad->SetFillColor(42); gPad->SetFrameFillColor(10);
+   hfound->Sumw2(); hgood->Sumw2(); hfake->Sumw2();
+   hg->Divide(hfound,hgood,1,1.,"b");
+   hf->Divide(hfake,hgood,1,1.,"b");
+   hg->SetMaximum(1.4);
+   hg->SetYTitle("Cascade reconstruction efficiency");
+   hg->SetXTitle("Pt (GeV/c)");
+   hg->Draw();
+
+   TLine *line1 = new TLine(pmin,1.0,pmax,1.0); line1->SetLineStyle(4);
+   line1->Draw("same");
+   TLine *line2 = new TLine(pmin,0.9,pmax,0.9); line2->SetLineStyle(4);
+   line2->Draw("same");
+
+   hf->SetFillColor(1);
+   hf->SetFillStyle(3013);
+   hf->SetLineColor(2);
+   hf->SetLineWidth(2);
+   hf->Draw("histsame");
+   TText *text = new TText(0.461176,0.248448,"Fake cascades");
+   text->SetTextSize(0.05);
+   text->Draw();
+   text = new TText(0.453919,1.11408,"Good cascades");
+   text->SetTextSize(0.05);
+   text->Draw();
+
+
+   c2->cd(2);
+   gPad->SetFillColor(42); gPad->SetFrameFillColor(10);
+   cs->SetXTitle("(GeV/c)"); 
+   //cs->Fit("gaus","","",cascadeMass-cascadeWidth,cascadeMass+cascadeWidth);
+   cs->Draw();
+   Double_t max=cs->GetMaximum();
+   TLine *line3 = 
+      new TLine(cascadeMass-cascadeWidth,0.,cascadeMass-cascadeWidth,max);
+   line3->Draw("same");
+   TLine *line4 = 
+      new TLine(cascadeMass+cascadeWidth,0.,cascadeMass+cascadeWidth,max);
+   line4->Draw("same");
+
+   timer.Stop(); timer.Print();
+
+   return 0;
+}
+
+
+
+Int_t good_cascades(GoodCascade *gc, Int_t max) {
+   Int_t nc=0;
+   /*** Get information about the cuts ***/
+   Double_t r2min=0.9*0.9;
+   Double_t r2max=2.9*2.9;
+
+   /*** Get labels of the "good" tracks ***/
+   Double_t dd; Int_t id, label[15000], ngt=0;
+   ifstream in("good_tracks_its");
+   if (!in) {
+     cerr<<"Can't open the file good_tracks_its \n";
+     return nc;
+   }
+   while (in>>label[ngt]>>id>>dd>>dd>>dd>>dd>>dd>>dd) {
+     ngt++;
+     if (ngt>=15000) {
+       cerr<<"Too many good ITS tracks !\n";
+       return nc;
+     }
+   }   
+   if (!in.eof()) {
+      cerr<<"Read error (good_tracks_its) !\n";
+      return nc;
+   }
+
+   /*** Get an access to the kinematics ***/
+   if (gAlice) {delete gAlice; gAlice=0;}
+
+   TFile *file=TFile::Open("galice.root");
+   if (!file->IsOpen()) {cerr<<"Can't open galice.root !\n"; exit(4);}
+   if (!(gAlice=(AliRun*)file->Get("gAlice"))) {
+     cerr<<"gAlice has not been found on galice.root !\n";
+     exit(5);
+   }
+
+   Int_t np=gAlice->GetEvent(0);
+   while (np--) {
+      cerr<<np<<'\r';
+      TParticle *cp=gAlice->Particle(np);
+
+      /*** only these cascades are "good" ***/
+      Int_t code=cp->GetPdgCode();
+      if (code!=kXiMinus)    if (code!=kXiPlusBar)
+      if (code!=kOmegaMinus) if (code!=kOmegaPlusBar) continue; 
+
+      /*** daughter tracks must be "good" ***/
+      Int_t v0lab=cp->GetFirstDaughter(), blab=cp->GetLastDaughter();
+      if (v0lab==blab) continue;
+      if (v0lab<0) continue;
+      if (blab<0) continue;
+
+      TParticle *p0=gAlice->Particle(v0lab);
+      TParticle *bp=gAlice->Particle(blab);
+      if ((p0->GetPdgCode()!=kLambda0) && (p0->GetPdgCode()!=kLambda0Bar)) {
+         TParticle *p=p0; p0=bp; bp=p;
+         Int_t i=v0lab; v0lab=blab; blab=i;         
+         if ((p0->GetPdgCode()!=kLambda0) && (p0->GetPdgCode()!=kLambda0Bar))
+                                                                   continue;
+      }
+
+      /** is the bachelor "good" ? **/
+      Int_t i;
+      for (i=0; i<ngt; i++) if (label[i]==blab) break;
+      if (i==ngt) continue; 
+
+      /** is the V0 "good" ? **/
+      Int_t plab=p0->GetFirstDaughter(), nlab=p0->GetLastDaughter();
+      if (nlab==plab) continue;
+      if (nlab<0) continue;
+      if (plab<0) continue;
+
+      for (i=0; i<ngt; i++) if (label[i]==nlab) break;
+      if (i==ngt) continue;
+      for (i=0; i<ngt; i++) if (label[i]==plab) break;
+      if (i==ngt) continue;
+
+      /*** fiducial volume ***/
+      Double_t x=bp->Vx(), y=bp->Vy(), r2=x*x+y*y; //bachelor
+      if (r2<r2min) continue;
+      if (r2>r2max) continue;
+      TParticle *pp=gAlice->Particle(plab);
+      x=pp->Vx(); y=pp->Vy(); r2=x*x+y*y;                      //V0
+      if (r2<r2min) continue;
+      if (r2>r2max) continue;
+
+      if (gAlice->Particle(plab)->GetPDG()->Charge() < 0.) {
+         i=plab; plab=nlab; nlab=i;
+      }
+
+      gc[nc].code=code;
+      gc[nc].plab=plab;   gc[nc].nlab=nlab; gc[nc].blab=blab;
+      gc[nc].px=cp->Px(); gc[nc].py=cp->Py(); gc[nc].pz=cp->Pz();
+      gc[nc].x=bp->Vx(); gc[nc].y=bp->Vy(); gc[nc].z=bp->Vz();
+      nc++;
+
+   }
+
+
+   return nc;
+}
diff --git a/ITS/AliCascadeFindVertices.C b/ITS/AliCascadeFindVertices.C
new file mode 100644 (file)
index 0000000..44eb584
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef __CINT__
+  #include <iostream.h>
+  #include "AliCascadeVertexer.h"
+  #include "TFile.h"
+  #include "TStopwatch.h"
+#endif
+
+Int_t AliCascadeFindVertices() {
+   cerr<<"Looking for cascade vertices...\n";
+
+   TFile *out=TFile::Open("AliCascadeVertices.root","new");
+   if (!out->IsOpen()) {
+      cerr<<"Delete old AliCascadeVertices.root !\n"; return 1;
+   }
+   TFile *in=TFile::Open("AliITStracksV2.root");
+   if (!in->IsOpen()) {cerr<<"Can't open AliITStracksV2.root !\n"; return 2;}
+
+   TFile *file=TFile::Open("AliV0vertices.root");
+   if (!file->IsOpen()) {
+      cerr<<"Can't open AliV0vertices.root !\n";return 3;
+   }
+   Double_t cuts[]={33.,  // max. allowed chi2
+                    0.015,// min. allowed V0 impact parameter 
+                    0.05, // window around the Lambda mass 
+                    0.015,// min. allowed track impact parameter 
+                    0.060,// max. allowed DCA between a V0 and a track
+                    0.997,// max. allowed cosine of the cascade pointing angle
+                    0.9,  // min. radius of the fiducial volume
+                    2.9   // max. radius of the fiducial volume
+                   };
+   TStopwatch timer;
+   AliCascadeVertexer *vertexer=new AliCascadeVertexer(cuts);
+   Int_t rc=vertexer->V0sTracks2CascadeVertices(in,out);
+   delete vertexer;
+   timer.Stop(); timer.Print();
+    
+   file->Close();
+   in->Close();
+   out->Close();
+
+   return rc;
+}
diff --git a/ITS/AliV0Comparison.C b/ITS/AliV0Comparison.C
new file mode 100644 (file)
index 0000000..92bdc39
--- /dev/null
@@ -0,0 +1,349 @@
+/****************************************************************************
+ *           Very important, delicate and rather obscure macro.             *
+ *                                                                          *
+ *                  Creates list of "findable" V0s,                         *
+ *             calculates efficiency, resolutions etc.                      *
+ *                                                                          *
+ *   Origin: I.Belikov, IReS, Strasbourg, Jouri.Belikov@cern.ch             *
+ ****************************************************************************/
+
+#ifndef __CINT__
+  #include <iostream.h>
+  #include <fstream.h>
+
+  #include "TH1.h"
+  #include "TFile.h"
+  #include "TTree.h"
+  #include "TObjArray.h"
+  #include "TStyle.h"
+  #include "TCanvas.h"
+  #include "TLine.h"
+  #include "TText.h"
+  #include "TParticle.h"
+  #include "TStopwatch.h"
+
+  #include "AliRun.h"
+  #include "AliPDG.h"
+  #include "AliV0vertex.h"
+#endif
+
+struct GoodVertex {
+  Int_t nlab,plab;
+  Int_t code;
+  Float_t px,py,pz;
+  Float_t x,y,z;
+};
+Int_t good_vertices(GoodVertex *gt, Int_t max);
+
+Int_t AliV0Comparison(Int_t code=310) { //Lambda=3122, LambdaBar=-3122
+   cerr<<"Doing comparison...\n";
+
+   const Double_t V0window=0.05, V0width=0.015; 
+   Double_t V0mass=0.5;
+   switch (code) {
+   case kK0Short:    V0mass=0.497672; break;
+   case kLambda0:    V0mass=1.115683; break;
+   case kLambda0Bar: V0mass=1.115683; break;
+   default: cerr<<"Invalid PDG code !\n"; return 1;
+   }
+
+   TStopwatch timer;
+
+   /*** Load reconstructed vertices ***/
+   TFile *vf=TFile::Open("AliV0vertices.root");
+   if (!vf->IsOpen()) {cerr<<"Can't open AliV0vertices.root !\n"; return 2;}
+   TObjArray varray(1000);
+   TTree *vTree=(TTree*)vf->Get("TreeV");
+   TBranch *branch=vTree->GetBranch("vertices");
+   Int_t nentr=(Int_t)vTree->GetEntries();
+   for (Int_t i=0; i<nentr; i++) {
+       AliV0vertex *iovertex=new AliV0vertex; branch->SetAddress(&iovertex);
+       vTree->GetEvent(i);
+       varray.AddLast(iovertex);
+   }
+
+   /*** Check if the file with the "good" vertices exists ***/
+   GoodVertex gv[1000];
+   Int_t ngood=0;
+   ifstream in("good_vertices");
+   if (in) {
+      cerr<<"Reading good vertices...\n";
+      while (in>>gv[ngood].nlab>>gv[ngood].plab>>gv[ngood].code>>
+                 gv[ngood].px>>gv[ngood].py>>gv[ngood].pz>>
+                 gv[ngood].x >>gv[ngood].y >>gv[ngood].z) {
+         ngood++;
+         cerr<<ngood<<'\r';
+         if (ngood==1000) {
+            cerr<<"Too many good vertices !\n";
+            break;
+         }
+      }
+      if (!in.eof()) cerr<<"Read error (good_vertices) !\n";
+   } else {
+     /*** generate a file with the "good" vertices ***/
+      cerr<<"Marking good vertices (this will take a while)...\n";
+      ngood=good_vertices(gv,1000);
+      ofstream out("good_vertices");
+      if (out) {
+         for (Int_t ngd=0; ngd<ngood; ngd++)            
+           out<<gv[ngd].nlab<<' '<<gv[ngd].plab<<' '<<gv[ngd].code<<' '<<
+                 gv[ngd].px<<' '<<gv[ngd].py<<' '<<gv[ngd].pz<<' '<<
+                 gv[ngd].x <<' '<<gv[ngd].y <<' '<<gv[ngd].z <<endl;
+      } else cerr<<"Can not open file (good_vertices) !\n";
+      out.close();
+   }
+
+   vf->Close();
+
+
+   TH1F *hp=new TH1F("hp","Angular Resolution",30,-30.,30.); //phi resolution 
+   hp->SetXTitle("(mrad)"); hp->SetFillColor(2);
+   TH1F *hl=new TH1F("hl","Lambda Resolution",30,-30,30);
+   hl->SetXTitle("(mrad)"); hl->SetFillColor(1); hl->SetFillStyle(3013); 
+   TH1F *hpt=new TH1F("hpt","Relative Pt Resolution",30,-10.,10.); 
+   hpt->SetXTitle("(%)"); hpt->SetFillColor(2); 
+
+   TH1F *hx=new TH1F("hx","Position Resolution (X,Y)",30,-3.,3.); //x res. 
+   hx->SetXTitle("(mm)"); hx->SetFillColor(6);
+   TH1F *hy=new TH1F("hy","Position Resolution (Y)",30,-3.,3.);   //y res
+   hy->SetXTitle("(mm)"); hy->SetFillColor(1); hy->SetFillStyle(3013);
+   TH1F *hz=new TH1F("hz","Position Resolution (Z)",30,-3.,3.);   //z res. 
+   hz->SetXTitle("(mm)"); hz->SetFillColor(6);
+
+
+   Double_t pmin=0.2, pmax=4.2; Int_t nchan=20;
+   TH1F *hgood=new TH1F("hgood","Good Vertices",nchan,pmin,pmax);    
+   TH1F *hfound=new TH1F("hfound","Found Vertices",nchan,pmin,pmax);
+   TH1F *hfake=new TH1F("hfake","Fake Vertices",nchan,pmin,pmax);
+   TH1F *hg=new TH1F("hg","Efficiency for Good Vertices",nchan,pmin,pmax);
+   hg->SetLineColor(4); hg->SetLineWidth(2);
+   TH1F *hf=new TH1F("hf","Probability of Fake Vertices",nchan,pmin,pmax);
+   hf->SetFillColor(1); hf->SetFillStyle(3013); hf->SetLineWidth(2);
+
+   Double_t mmin=V0mass-V0window, mmax=V0mass+V0window;
+   TH1F *v0s =new TH1F("v0s","V0s Effective Mass",40, mmin, mmax);
+   v0s->SetXTitle("(GeV)"); v0s->SetFillColor(6);
+
+
+   Double_t pxg=0.,pyg=0.,ptg=0.;
+   Int_t nlab=-1, plab=-1;
+   Int_t i;
+   for (i=0; i<nentr; i++) {
+       AliV0vertex *vertex=(AliV0vertex*)varray.UncheckedAt(i);
+       nlab=TMath::Abs(vertex->GetNlabel());
+       plab=TMath::Abs(vertex->GetPlabel());
+
+       vertex->ChangeMassHypothesis(code);
+
+       Double_t mass=vertex->GetEffMass();
+       v0s->Fill(mass);
+
+       Int_t j;
+       for (j=0; j<ngood; j++) {
+          if (gv[j].code != vertex->GetPdgCode()) continue;
+          if (gv[j].nlab == nlab)
+          if (gv[j].plab == plab) break;
+       }
+
+       if (TMath::Abs(mass-V0mass)>V0width) continue;
+
+       Double_t px,py,pz; vertex->GetPxPyPz(px,py,pz);
+       Double_t pt=TMath::Sqrt(px*px+py*py);
+
+       if (j==ngood) {
+          hfake->Fill(pt);
+          cerr<<"Fake vertex: ("<<nlab<<","<<plab<<")\n";
+          continue;
+       }
+
+       pxg=gv[j].px; pyg=gv[j].py; ptg=TMath::Sqrt(pxg*pxg+pyg*pyg);
+       Double_t phig=TMath::ATan2(pyg,pxg), phi=TMath::ATan2(py,px);
+       Double_t lamg=TMath::ATan2(gv[j].pz,ptg), lam=TMath::ATan2(pz,pt);
+       hp->Fill((phi - phig)*1000.);
+       hl->Fill((lam - lamg)*1000.);
+       hpt->Fill((1/pt - 1/ptg)/(1/ptg)*100.);
+
+       Double_t x,y,z; vertex->GetXYZ(x,y,z);
+       hx->Fill((x-gv[j].x)*10);
+       hy->Fill((y-gv[j].y)*10);
+       hz->Fill((z-gv[j].z)*10);
+
+       hfound->Fill(ptg);
+       gv[j].nlab=-1;
+
+   }
+   for (i=0; i<ngood; i++) {
+      if (gv[i].code != code) continue;
+      pxg=gv[i].px; pyg=gv[i].py; ptg=TMath::Sqrt(pxg*pxg+pyg*pyg);
+      hgood->Fill(ptg);
+      nlab=gv[i].nlab; plab=gv[i].plab;
+      if (nlab < 0) continue;
+      cerr<<"Vertex ("<<nlab<<','<<plab<<") has not been found !\n";
+   }
+
+   varray.Delete();
+
+   Stat_t ng=hgood->GetEntries();
+   Stat_t nf=hfound->GetEntries();
+
+   cerr<<"Number of found vertices: "<<nentr<<" ("<<nf<<" in the peak)\n";
+   cerr<<"Number of good vertices: "<<ng<<endl;
+
+   if (ng!=0) 
+      cerr<<"Integral efficiency is about "<<nf/ng*100.<<" %\n";
+
+   gStyle->SetOptStat(111110);
+   gStyle->SetOptFit(1);
+
+   TCanvas *c1=new TCanvas("c1","",0,0,580,610);
+   c1->Divide(2,2);
+
+   c1->cd(1);
+   gPad->SetFillColor(42); gPad->SetFrameFillColor(10); 
+   //hp->Fit("gaus");
+   hp->Draw();
+   hl->Draw("same"); c1->cd();
+
+   c1->cd(2);
+   gPad->SetFillColor(42); gPad->SetFrameFillColor(10);
+   //hpt->Fit("gaus"); c1->cd();
+   hpt->Draw(); c1->cd();
+
+   c1->cd(3);
+   gPad->SetFillColor(42); gPad->SetFrameFillColor(10); 
+   //hx->Fit("gaus"); 
+   hx->Draw(); 
+   hy->Draw("same"); c1->cd();
+
+   c1->cd(4);
+   gPad->SetFillColor(42); gPad->SetFrameFillColor(10);
+   //hz->Fit("gaus");
+   hz->Draw();
+
+
+   TCanvas *c2=new TCanvas("c2","",600,0,580,610);
+   c2->Divide(1,2);
+
+   c2->cd(1);
+   gPad->SetFillColor(42); gPad->SetFrameFillColor(10);
+   hfound->Sumw2(); hgood->Sumw2(); hfake->Sumw2();
+   hg->Divide(hfound,hgood,1,1.,"b");
+   hf->Divide(hfake,hgood,1,1.,"b");
+   hg->SetMaximum(1.4);
+   hg->SetYTitle("V0 reconstruction efficiency");
+   hg->SetXTitle("Pt (GeV/c)");
+   hg->Draw();
+
+   TLine *line1 = new TLine(pmin,1.0,pmax,1.0); line1->SetLineStyle(4);
+   line1->Draw("same");
+   TLine *line2 = new TLine(pmin,0.9,pmax,0.9); line2->SetLineStyle(4);
+   line2->Draw("same");
+
+   hf->SetFillColor(1);
+   hf->SetFillStyle(3013);
+   hf->SetLineColor(2);
+   hf->SetLineWidth(2);
+   hf->Draw("histsame");
+   TText *text = new TText(0.461176,0.248448,"Fake vertices");
+   text->SetTextSize(0.05);
+   text->Draw();
+   text = new TText(0.453919,1.11408,"Good vertices");
+   text->SetTextSize(0.05);
+   text->Draw();
+
+
+   c2->cd(2);
+   gPad->SetFillColor(42); gPad->SetFrameFillColor(10);
+   v0s->SetXTitle("(GeV/c)"); 
+   v0s->Fit("gaus","","",V0mass-V0width,V0mass+V0width);
+   Double_t max=v0s->GetMaximum();
+   TLine *line3 = new TLine(V0mass-V0width,0.,V0mass-V0width,max);
+   line3->Draw("same");
+   TLine *line4 = new TLine(V0mass+V0width,0.,V0mass+V0width,max);
+   line4->Draw("same");
+
+   timer.Stop(); timer.Print();
+
+   return 0;
+}
+
+Int_t good_vertices(GoodVertex *gv, Int_t max) {
+   Int_t nv=0;
+   /*** Get information about the cuts ***/
+   Double_t r2min=0.9*0.9;
+   Double_t r2max=2.9*2.9;
+
+   /*** Get labels of the "good" tracks ***/
+   Double_t dd; Int_t id, label[15000], ngt=0;
+   ifstream in("good_tracks_its");
+   if (!in) {
+     cerr<<"Can't open the file good_tracks_its \n";
+     return nv;
+   }
+   while (in>>label[ngt]>>id>>dd>>dd>>dd>>dd>>dd>>dd) {
+     ngt++;
+     if (ngt>=15000) {
+       cerr<<"Too many good ITS tracks !\n";
+       return nv;
+     }
+   }   
+   if (!in.eof()) {
+      cerr<<"Read error (good_tracks_its) !\n";
+      return nv;
+   }
+
+   /*** Get an access to the kinematics ***/
+   if (gAlice) {delete gAlice; gAlice=0;}
+
+   TFile *file=TFile::Open("galice.root");
+   if (!file->IsOpen()) {cerr<<"Can't open galice.root !\n"; exit(4);}
+   if (!(gAlice=(AliRun*)file->Get("gAlice"))) {
+     cerr<<"gAlice has not been found on galice.root !\n";
+     exit(5);
+   }
+
+   Int_t np=gAlice->GetEvent(0);
+   while (np--) {
+      cerr<<np<<'\r';
+      TParticle *p0=gAlice->Particle(np);
+
+      /*** only these V0s are "good" ***/
+      Int_t code=p0->GetPdgCode();
+      if (code!=kK0Short)
+      if (code!=kLambda0)
+      if (code!=kLambda0Bar) continue; 
+
+      /*** daughter tracks should be "good" ***/
+      Int_t plab=p0->GetFirstDaughter(), nlab=p0->GetLastDaughter();
+      if (nlab==plab) continue;
+      if (nlab<0) continue;
+      if (plab<0) continue;
+      Int_t i;
+      for (i=0; i<ngt; i++) if (label[i]==nlab) break;
+      if (i==ngt) continue;
+      for (i=0; i<ngt; i++) if (label[i]==plab) break;
+      if (i==ngt) continue;
+
+      /*** fiducial volume ***/
+      TParticle *p=gAlice->Particle(nlab);
+      Double_t x=p->Vx(), y=p->Vy(), z=p->Vz(), r2=x*x+y*y;
+      if (r2<r2min) continue;
+      if (r2>r2max) continue;
+       
+      if (gAlice->Particle(plab)->GetPDG()->Charge() < 0.) {
+         i=plab; plab=nlab; nlab=i;
+      }
+      
+      gv[nv].code=code;
+      gv[nv].plab=plab; gv[nv].nlab=nlab;
+      gv[nv].px=p0->Px(); gv[nv].py=p0->Py(); gv[nv].pz=p0->Pz();
+      gv[nv].x=x; gv[nv].y=y; gv[nv].z=z;
+      nv++;
+   }
+   delete gAlice; gAlice=0;
+
+   file->Close();  
+
+   return nv;
+}
diff --git a/ITS/AliV0FindVertices.C b/ITS/AliV0FindVertices.C
new file mode 100644 (file)
index 0000000..b2e1cb5
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef __CINT__
+  #include <iostream.h>
+  #include "AliV0vertexer.h"
+  #include "TFile.h"
+  #include "TStopwatch.h"
+#endif
+
+Int_t AliV0FindVertices() {
+   cerr<<"Looking for V0 vertices...\n";
+
+   TFile *out=TFile::Open("AliV0vertices.root","new");
+   if (!out->IsOpen()) {cerr<<"Delete old AliV0vertices.root !\n"; return 1;}
+
+   TFile *in=TFile::Open("AliITStracksV2.root");
+   if (!in->IsOpen()) {cerr<<"Can't open AliITStracksV2.root !\n"; return 2;}
+
+   Double_t cuts[]={33,  // max. allowed chi2
+                    0.12,// min. allowed negative daughter's impact parameter 
+                    0.06,// min. allowed positive daughter's impact parameter 
+                    0.080,// max. allowed DCA between the daughter tracks
+                    0.998,// max. allowed cosine of V0's pointing angle
+                    0.9,  // min. radius of the fiducial volume
+                    2.9   // max. radius of the fiducial volume
+                   };
+   TStopwatch timer;
+   AliV0vertexer *vertexer=new AliV0vertexer(cuts);
+   Int_t rc=vertexer->Tracks2V0vertices(in,out);
+   delete vertexer;
+   timer.Stop(); timer.Print();
+    
+   in->Close();
+   out->Close();
+
+   return rc;
+}