]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliV0FindVertices.C
Additional protection
[u/mrichter/AliRoot.git] / ITS / AliV0FindVertices.C
index 61a423d2c022f3651a04665dcdf50fd7d5322f63..338ae94c2f3202bc92c8f6c34d576e82d2b2bf1d 100644 (file)
@@ -1,19 +1,48 @@
-#ifndef __CINT__
+/****************************************************************************
+ *           Origin: I.Belikov, CERN, Jouri.Belikov@cern.ch                 *
+ ****************************************************************************/
+
+#if !defined(__CINT__) || defined(__MAKECINT__)
   #include "Riostream.h"
   #include "AliV0vertexer.h"
   #include "TFile.h"
+  #include "TKey.h"
   #include "TStopwatch.h"
+
+  #include "AliRun.h"
+  #include "AliKalmanTrack.h"
+  #include "AliMagF.h"
+  #include "AliESD.h"
+  #include "AliRunLoader.h"
 #endif
 
-Int_t AliV0FindVertices(Int_t nev=1) {
+extern AliRun *gAlice;
+
+Int_t AliV0FindVertices(Int_t nev=5) {
    cerr<<"Looking for V0 vertices...\n";
 
-   TFile *out=TFile::Open("AliV0vertices.root","new");
-   if (!out->IsOpen()) {cerr<<"Delete old AliV0vertices.root !\n"; return 1;}
+   if (gAlice) {
+      delete gAlice->GetRunLoader();
+      delete gAlice; 
+      gAlice=0;
+   } 
 
-   TFile *in=TFile::Open("AliITStracksV2.root");
-   if (!in->IsOpen()) {cerr<<"Can't open AliITStracksV2.root !\n"; return 2;}
+   AliRunLoader* rl = AliRunLoader::Open("galice.root");
+   if (rl == 0x0) {
+      cerr<<"AliV0FindVertices.C : Can not open session RL=NULL"<< endl;
+      return 1;
+   }
 
+   if (rl->LoadgAlice()) {
+      cerr<<"AliV0FindVertices.C : LoadgAlice returned error"<<endl;
+      delete rl;
+      return 3;
+   }
+
+   AliKalmanTrack::SetConvConst(
+      1000/0.299792458/rl->GetAliRun()->Field()->SolenoidField()
+   );
+       
    Double_t cuts[]={33,  // max. allowed chi2
                     0.16,// min. allowed negative daughter's impact parameter 
                     0.05,// min. allowed positive daughter's impact parameter 
@@ -25,15 +54,45 @@ Int_t AliV0FindVertices(Int_t nev=1) {
    TStopwatch timer;
    AliV0vertexer vtxer(cuts);
    Int_t rc=0;
+   if (nev>rl->GetNumberOfEvents()) nev=rl->GetNumberOfEvents();
+
+   TFile *v0f=TFile::Open("AliESDv0.root","RECREATE");
+   if ((!v0f)||(!v0f->IsOpen())) {
+      cerr<<"Can't AliESDv0.root !\n"; return 1;
+   }
+   TFile *itsf=TFile::Open("AliESDits.root");
+   if ((!itsf)||(!itsf->IsOpen())) {
+      cerr<<"Can't AliESDits.root !\n"; return 1;
+   }
+   TKey *key=0;
+   TIter next(itsf->GetListOfKeys());
    for (Int_t i=0; i<nev; i++) {
+     itsf->cd();
+     if ((key=(TKey*)next())==0) break;
+     cerr<<"Processing event number: "<<i<<endl;
+     AliESD *event=(AliESD*)key->ReadObj();
+
      //Double_t vtx[3]={0.,0.,0.}; vtxer.SetVertex(vtx); // primary vertex (cm)
-     vtxer.SetEvent(i);
-     rc=vtxer.Tracks2V0vertices(in,out);
+
+     rc=vtxer.Tracks2V0vertices(event);
+
+     if (rc==0) {
+        Char_t ename[100]; 
+        sprintf(ename,"%d",i);
+        v0f->cd();
+        if (!event->Write(ename)) rc++;
+     } 
+     if (rc) {
+        cerr<<"Something bad happened...\n";
+     }
+     delete event;
    }
    timer.Stop(); timer.Print();
     
-   in->Close();
-   out->Close();
+   itsf->Close();
+   v0f->Close();
+
+   delete rl;
 
    return rc;
 }