]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSFindClustersV2.C
Correct formula for phi, in case of current local X <0, in GetLocalXat and GetPhiZat
[u/mrichter/AliRoot.git] / ITS / AliITSFindClustersV2.C
index 0e06e7044ddf8f8c71f9a6d74752bd4c4f729695..e8cba5ad628258c078d989c024b0211e651a8bd1 100644 (file)
-#ifndef __CINT__
-  #include "AliRun.h"
-  #include "AliITS.h"
-  #include "AliITSgeom.h"
-  #include "AliITSRecPoint.h"
-  #include "AliITSclusterV2.h"
-  #include "AliITSsimulationFastPoints.h"
-
-  #include "TFile.h"
-  #include "TTree.h"
-  #include "TParticle.h"
+#if !defined(__CINT__) || defined(__MAKECINT__)
+
+#include <Riostream.h>
+#include <TROOT.h>
+#include <TString.h>
+#include "AliRawReader.h"
+#include "AliRawReaderDate.h"
+#include "AliRawReaderRoot.h"
+#include "AliRun.h"
+#include "AliRunLoader.h"
+#include "AliITSInitGeometry.h"
+#include "AliITSgeom.h"
+#include "AliITSLoader.h"
+#include "AliCDBManager.h"
+#include "AliITSDetTypeRec.h"
+#include "AliGeomManager.h"
+
 #endif
 
-Int_t AliITSFindClustersV2() {
-/****************************************************************
- *  Just something to start with                                *
- ****************************************************************/
-   cerr<<"Looking for clusters...\n";
-
-   if (gAlice) {delete gAlice; gAlice=0;}
-
-   TFile *in=TFile::Open("galice.root","update");
-   if (!in->IsOpen()) {
-      cerr<<"Can't open galice.root !\n"; 
-      return 1;
-   }
-   
-   if (!(gAlice=(AliRun*)in->Get("gAlice"))) {
-      cerr<<"Can't find gAlice !\n";
-      return 2;
-   }
-
-   Int_t ev=0;
-   gAlice->GetEvent(ev);
-
-   AliITS *ITS  = (AliITS*)gAlice->GetModule("ITS");
-   if (!ITS) {
-      cerr<<"Can't find the ITS !\n";
-      return 3;
-   }
-
-   gAlice->MakeTree("R"); ITS->MakeBranch("R",0);
-//////////////// Taken from ITSHitsToFastPoints.C ///////////////////////
-   AliITSsimulationFastPoints *sim = new AliITSsimulationFastPoints();
-   for (Int_t i=0;i<3;i++) { ITS->SetSimulationModel(i,sim); }
-
-   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;
-   }
-   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");
-   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++) {
-       if (!pTree->GetEvent(i)) {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);
-       Int_t ncl=points->GetEntriesFast();
-       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);
-       }
-       cTree->Fill(); clusters->Delete();
-       points->Delete();
-   }
-   cTree->Write();
-
-   cerr<<"Number of clusters: "<<nclusters<<endl;
-
-   delete cTree; delete clusters; delete points;
-
-   delete gAlice; gAlice=0;
-   in->Close();
-   out->Close();
-
-   return 0;
+/*
+$Id$ 
+*/
+/***************************************************************
+ *  This macro performs the ITS local reconstruction           *
+ *  It is intended for special purposes and tests.             *
+ *  The reccomended way to reconstruct ITs is via the          *
+ *  class STEER/AliReconstruction                              *
+ *  Present version: M.Masera - Previous version: J. Belikov   *
+ ***************************************************************/
+
+void Reconstruct(AliRunLoader* runLoader,Option_t *opt);
+void Reconstruct(AliRunLoader* runLoader, AliRawReader *rawreader,Option_t *opt);
+
+Int_t AliITSFindClustersV2(char *inputRawData = NULL,TString filename="galice.root",Option_t *opt="All"){
+  // if kine tree is available MC labels are used for rec points
+  // set opt equal to "SPD" or to "SDD" or to "SSD" do build
+  // rec points for individual subdetectors 
+  if (gAlice) {
+    delete AliRunLoader::Instance();
+    delete gAlice;
+    gAlice = NULL;
+  }
+
+  // Get geometry
+  AliGeomManager::LoadGeometry("geometry.root");
+
+  //Get Run loader and ITS loader - set geometry
+  AliRunLoader* rl = AliRunLoader::Open(filename.Data());
+
+  AliITSInitGeometry initgeom;
+  AliITSgeom *geom = initgeom.CreateAliITSgeom();
+  printf("Geometry name: %s \n",(initgeom.GetGeometryName()).Data());
+  AliITSLoader* loader = static_cast<AliITSLoader*>(rl->GetLoader("ITSLoader"));
+  if (!loader) {
+    Error("Init", "ITS loader not found");
+    return -1;
+  }
+  loader->SetITSgeom(geom);
+
+  // Set OCDB if needed
+  AliCDBManager* man = AliCDBManager::Instance();
+  if (!man->IsDefaultStorageSet()) {
+    printf("Setting a local default storage and run number 0\n");
+    man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
+    man->SetRun(0);
+  }
+  else {
+    printf("Using deafult storage \n");
+  }
+
+  AliRawReader *rawreader = NULL;
+  TString fileRaw(inputRawData);
+  if(!fileRaw.IsNull()){
+    if (fileRaw.EndsWith(".root")) {
+      cout<<"Raw data format - ROOT file \n"; 
+      rawreader = new AliRawReaderRoot(fileRaw); // root format
+    }
+    else {
+      cout<<"Raw data format - DATE file \n";
+      rawreader = new AliRawReaderDate(fileRaw);  // DATE format
+    }
+    //    if (!fEquipIdMap.IsNull() && fRawReader)fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
+    Reconstruct(rl,rawreader,opt);
+  }
+  else {
+    cout<< "Starting from DIGITS \n";
+    Reconstruct(rl,opt);
+  }
+
+  return 0;
 }
 
+//________________________________________________________________________
+void Reconstruct(AliRunLoader* runLoader,Option_t *opt){
+// reconstruct clusters starting from DIGITS
+// MC truth if available is used to label clusters according to the particles
+// originating them
+
+  AliITSLoader* loader = 
+                static_cast<AliITSLoader*>(runLoader->GetLoader("ITSLoader"));
+  if (!loader) {
+    Error("Reconstruct", "ITS loader not found");
+    return;
+  }
+  AliITSDetTypeRec* rec = new AliITSDetTypeRec();
+  rec->SetITSgeom(loader->GetITSgeom());
+  rec->SetDefaults();
+
+  runLoader->LoadKinematics();
+  TTree *trK=(TTree*)runLoader->TreeK();
+  if(trK){
+    cout<<"kine tree found - MC labels will be used in RP \n";
+    if(runLoader->LoadgAlice())gAlice = runLoader->GetAliRun();
+  }
+  else{
+    cout<<"kine tree not found - MC labels will not b used\n";
+  }
+
+  Int_t nEvents = runLoader->GetNumberOfEvents();
+  // loop on the events
+
+  for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
+    runLoader->GetEvent(iEvent);
+    cout<<">>>>>>>   Processing event number "<<iEvent+1<<endl;
+    loader->LoadRecPoints("update");
+    loader->CleanRecPoints();
+    loader->MakeRecPointsContainer();
+    loader->LoadDigits("read");
+    TTree *tR = loader->TreeR();
+    TTree *tD = loader->TreeD();
+    if(!tR){
+      cout<<"Tree R pointer not found - Abort \n";
+      break;
+    }
+    rec->SetTreeAddressD(tD);
+    rec->MakeBranch(tR,"R");
+    rec->SetTreeAddressR(tR);
+    rec->DigitsToRecPoints(tD,tR,0,opt,kTRUE);    
+    loader->WriteRecPoints("OVERWRITE");
+    loader->UnloadRecPoints();
+    loader->UnloadDigits();
+    runLoader->UnloadKinematics();
+  }
 
+}
 
+void Reconstruct(AliRunLoader* runLoader, AliRawReader *rawreader,Option_t *opt){
+// reconstruct clusters starting from raw data (root or DATE format)
+// MC truth if available is used to label clusters according to the particles
+// originating them
+
+  AliITSLoader* loader = static_cast<AliITSLoader*>(runLoader->GetLoader("ITSLoader"));
+  if (!loader) {
+    Error("Reconstruct", "ITS loader not found");
+    return;
+  }
+  AliITSDetTypeRec* rec = new AliITSDetTypeRec();
+  rec->SetITSgeom(loader->GetITSgeom());
+  rec->SetDefaults();
+  // direct clusterfinding starting from raw data is implemented only 
+  // in AliITSClusterFinderV2
+  rec->SetDefaultClusterFindersV2(kTRUE);
+
+  runLoader->LoadKinematics();
+  TTree *trK=(TTree*)runLoader->TreeK();
+  if(trK){
+    cout<<"kine tree found - MC labels will be used in RP \n";
+    if(runLoader->LoadgAlice())gAlice = runLoader->GetAliRun();
+  }
+  Int_t nEvents = runLoader->GetNumberOfEvents();
+  rawreader->RewindEvents();
+  for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
+    rawreader->NextEvent();
+    runLoader->GetEvent(iEvent);
+    cout<<">>>>>>>   Processing event number: "<<iEvent<<endl;
+    loader->LoadRecPoints("update");
+    loader->CleanRecPoints();
+    loader->MakeRecPointsContainer();
+    TTree *tR = loader->TreeR();
+    if(!tR){
+      cout<<"Tree R pointer not found - Abort \n";
+      break;
+    }
+    rec->DigitsToRecPoints(rawreader,tR,opt);
+    rec->ResetRecPoints();
+    rec->ResetClusters();    
+    loader->WriteRecPoints("OVERWRITE");
+    loader->UnloadRecPoints();
+    loader->UnloadDigits();
+    runLoader->UnloadKinematics();
+  }
 
-
-
-
-
-
-
-
-
-
-
+}