]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSFindClustersV2.C
Example macro for the creation of tags (P.Christakoglou)
[u/mrichter/AliRoot.git] / ITS / AliITSFindClustersV2.C
index bc82fa92ded1cf8ba936c00d4008bf3ee347d0a9..d9728602dd3411eda1219b828c0fac68e5159772 100644 (file)
-#ifndef __CINT__
-  #include <iostream.h>
+/****************************************************************************
+ *           Origin: I.Belikov, CERN, Jouri.Belikov@cern.ch                 *
+ ****************************************************************************/
+
+#if !defined(__CINT__) || defined(__MAKECINT__)
+  #include <Riostream.h>
 
   #include "AliRun.h"
+  #include "AliRunLoader.h"
+  #include "AliITSLoader.h"
   #include "AliITS.h"
   #include "AliITSgeom.h"
-  #include "AliITSRecPoint.h"
-  #include "AliITSclusterV2.h"
-  #include "AliITSsimulationFastPoints.h"
+  #include "AliITSclustererV2.h"
 
-  #include "TFile.h"
   #include "TTree.h"
-  #include "TParticle.h"
+  #include "TStopwatch.h"
 #endif
 
-Int_t AliITSFindClustersV2() {
-/****************************************************************
- *  Just something to start with                                *
- ****************************************************************/
-   cerr<<"Looking for clusters...\n";
+extern AliRun *gAlice;
 
-   if (gAlice) {delete gAlice; gAlice=0;}
+Int_t AliITSFindClustersV2(Int_t nev=5, Char_t SlowOrFast='s') {
 
-   TFile *in=TFile::Open("galice.root","update");
-   if (!in->IsOpen()) {
-      cerr<<"Can't open galice.root !\n"; 
+   cerr<<"Looking for clusters...\n";
+
+   if (gAlice) {
+      delete gAlice->GetRunLoader();
+      delete gAlice; 
+      gAlice=0;
+   }
+   AliRunLoader *rl = AliRunLoader::Open("galice.root");
+   if (rl == 0x0) {
+      cerr<<"AliITSFindClustersV2.C : Can not open session RL=NULL"<< endl;
       return 1;
    }
-   
-   if (!(gAlice=(AliRun*)in->Get("gAlice"))) {
-      cerr<<"Can't find gAlice !\n";
+     
+   AliITSLoader *itsl = (AliITSLoader*)rl->GetLoader("ITSLoader");
+   if (itsl == 0x0) {
+      cerr<<"AliITSFindClustersV2.C : can not get ITS loader"<< endl;
       return 2;
    }
 
-   Int_t ev=0;
-   gAlice->GetEvent(ev);
+   rl->LoadKinematics();
 
-   AliITS *ITS  = (AliITS*)gAlice->GetModule("ITS");
-   if (!ITS) {
-      cerr<<"Can't find the ITS !\n";
+   Int_t retval = rl->LoadgAlice();
+   if (retval) {
+      cerr<<"AliITSFindClustersV2.C : LoadgAlice returned error"<< endl;
+      delete rl;
       return 3;
    }
 
-   gAlice->MakeTree("R"); ITS->MakeBranch("R",0);
-//////////////// Taken from ITSHitsToFastPoints.C ///////////////////////
-   ITS->SetSimulationModel(0,new AliITSsimulationFastPoints());
-   ITS->SetSimulationModel(1,new AliITSsimulationFastPoints());
-   ITS->SetSimulationModel(2,new AliITSsimulationFastPoints());
-   Int_t nsignal=25;
-   Int_t size=-1;
-   Int_t bgr_ev=Int_t(ev/nsignal);
-   ITS->HitsToFastRecPoints(ev,bgr_ev,size," ","All"," ");
-//////////////////////////////////////////////////////////////////////////
-
-   delete gAlice; gAlice=0;
-   in->Close();
-
-///////////////// Conversion AliITSRecPoint -> AliITSclusterV2 //////////////
-   /*TFile */in=TFile::Open("galice.root");
-
-   if (gAlice) {delete gAlice; gAlice=0;}
-
-   if (!(gAlice=(AliRun*)in->Get("gAlice"))) {
-      cerr<<"Can't find gAlice !\n";
-      return 4;
-   }
-
-   gAlice->GetEvent(0);
-
-   /*AliITS */ITS  = (AliITS*)gAlice->GetModule("ITS");
-   if (!ITS) {
-      cerr<<"Can't find the ITS !\n";
-      return 5;
-   }
+   gAlice=rl->GetAliRun();
+   AliITS *ITS  = (AliITS*)gAlice->GetModule("ITS");
+   if (!ITS) { cerr<<"Can't find the ITS !\n"; delete rl; return 3; }
    AliITSgeom *geom=ITS->GetITSgeom();
-   TFile *out=TFile::Open("AliITSclustersV2.root","new");
-   if (!out->IsOpen()) {
-      cerr<<"Delete old AliITSclustersV2.root !\n"; 
-      return 6;
-   }
-   geom->Write();
-
-   TClonesArray *clusters=new TClonesArray("AliITSclusterV2",10000);
-   //TTree *cTree=new TTree("cTree","ITS clusters");
-   TTree *cTree=new TTree("TreeC_ITS_0","ITS clusters");
-   cTree->Branch("Clusters",&clusters);
 
-   TTree *pTree=gAlice->TreeR();
-   if (!pTree) {
-      cerr<<"Can't get TreeR !\n";
-      return 7;
-   }
-   TBranch *branch=pTree->GetBranch("ITSRecPoints");
-   if (!branch) { 
-      cerr<<"Can't get ITSRecPoints branch !\n";
-      return 8;
-   }
-   TClonesArray *points=new TClonesArray("AliITSRecPoint",10000);
-   branch->SetAddress(&points);
-
-   TClonesArray &cl=*clusters;
-   Int_t nclusters=0;
-   Int_t nentr=(Int_t)pTree->GetEntries();
-
-   cerr<<"Number of entries: "<<nentr<<endl;
-
-   for (Int_t i=0; i<nentr; i++) {
-       points->Clear();
-       pTree->GetEvent(i);
-       Int_t ncl=points->GetEntriesFast(); if (ncl==0){cTree->Fill();continue;}
-       Int_t lay,lad,det; geom->GetModuleId(i,lay,lad,det);
-       Float_t x,y,zshift; geom->GetTrans(lay,lad,det,x,y,zshift); 
-       Double_t rot[9];    geom->GetRotMatrix(lay,lad,det,rot);
-       Double_t yshift = x*rot[0] + y*rot[1];
-       Int_t ndet=(lad-1)*geom->GetNdetectors(lay) + (det-1);
-       nclusters+=ncl;
-       for (Int_t j=0; j<ncl; j++) {
-          AliITSRecPoint *p=(AliITSRecPoint*)points->UncheckedAt(j);
-          Float_t lp[5];
-          lp[0]=-p->GetX()-yshift; if (lay==1) lp[0]=-lp[0];
-          lp[1]=p->GetZ()+zshift;
-          lp[2]=p->GetSigmaX2();
-          lp[3]=p->GetSigmaZ2();
-          lp[4]=p->GetQ();
-          Int_t lab[6]; 
-          lab[0]=p->GetLabel(0);lab[1]=p->GetLabel(1);lab[2]=p->GetLabel(2);
-          lab[3]=ndet;
-
-          Int_t label=lab[0];
-          TParticle *part=(TParticle*)gAlice->Particle(label);
-          label=-3;
-          while (part->P() < 0.005) {
-             Int_t m=part->GetFirstMother();
-             if (m<0) {cerr<<"Primary momentum: "<<part->P()<<endl; break;}
-             label=m;
-             part=(TParticle*)gAlice->Particle(label);
-          }
-          if      (lab[1]<0) lab[1]=label;
-          else if (lab[2]<0) lab[2]=label;
-          else cerr<<"No empty labels !\n";
-
-          new(cl[j]) AliITSclusterV2(lab,lp);
+   itsl->LoadRecPoints("recreate");
+   if (SlowOrFast=='s') itsl->LoadDigits("read");
+   else itsl->LoadHits("read");
+   
+   if(SlowOrFast=='s'){
+     AliITSclustererV2 clusterer(geom);
+
+     TStopwatch timer;
+     if (nev>rl->GetNumberOfEvents()) nev=rl->GetNumberOfEvents();
+     for (Int_t i=0; i<nev; i++) {
+       cerr<<"Processing event number: "<<i<<endl;
+       rl->GetEvent(i);
+       
+       TTree *out=itsl->TreeR();
+       if (!out) {
+        itsl->MakeTree("R");
+        out=itsl->TreeR();
        }
-       cTree->Fill(); clusters->Delete();
-       points->Delete();
+       
+       TTree *in=itsl->TreeD();
+       if (!in) {
+        cerr<<"Can't get digits tree !\n";
+        return 4;
+       }
+       clusterer.Digits2Clusters(in,out);       
+       itsl->WriteRecPoints("OVERWRITE");
+       timer.Stop(); timer.Print();
+     }
+
+   } else{
+     
+     for(Int_t i=0;i<3;i++){
+       ITS->SetSimulationModel(i,new AliITSsimulationFastPoints());
+     }
+
+     TStopwatch timer;
+     for (Int_t i=0; i<nev; i++) {
+       rl->GetEvent(i);
+       if(itsl->TreeR()== 0x0) itsl->MakeTree("R");
+       TTree* in = (TTree*)itsl->TreeH();
+       TTree* out= (TTree*)itsl->TreeR();
+       timer.Start();
+       ITS->Hits2Clusters(in,out);
+       timer.Stop(); timer.Print();
+       itsl->WriteRecPoints("OVERWRITE");
+     }
    }
-   cTree->Write();
-
-   cerr<<"Number of clusters: "<<nclusters<<endl;
 
-   delete cTree; delete clusters; delete points;
-
-   delete gAlice; gAlice=0;
-
-   in->Close();
-   out->Close();
+   delete rl;
 
    return 0;
-
 }
 
 
 
-
-
-
-
-
-
-
-
-
-
-