]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSreconstruction.cxx
corrections from Alberto
[u/mrichter/AliRoot.git] / ITS / AliITSreconstruction.cxx
index ae7efa1d9b889880b8a7e60424d3e5592f4444ca..dd4dbd046f2905b5b68f46099fa209abfae6ad0c 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
  
-/*
-$Log$
-*/
-#include <TROOT.h>
-#include <TFile.h>
-#include <TSeqCollection.h>
-#include <TString.h>
-#include <TClonesArray.h>
+/* $Id$ */
+/////////////////////////////////////////////////////////////////////////
+//                                                                     //
+// Class for ITS RecPoint reconstruction                               //
+//                                                                     //
+////////////////////////////////////////////////////////////////////////
 
+#include <TString.h>
 #include "AliRun.h"
-
-#include "AliITS.h"
-#include "AliITSDetType.h"
+#include "AliRunLoader.h"
+#include "AliITSDetTypeRec.h"
+#include "AliITSLoader.h"
 #include "AliITSreconstruction.h"
-#include "AliITSsegmentationSPD.h"
-#include "AliITSsegmentationSDD.h"
-#include "AliITSsegmentationSSD.h"
-#include "AliITSClusterFinderSPD.h"
-#include "AliITSClusterFinderSDD.h"
-#include "AliITSClusterFinderSSD.h"
-#include "AliITSresponseSDD.h"
 #include "AliITSgeom.h"
 
+
 ClassImp(AliITSreconstruction)
 
 //______________________________________________________________________
-AliITSreconstruction::AliITSreconstruction(){
+AliITSreconstruction::AliITSreconstruction():
+ fInit(kFALSE),
+ fEnt(0),
+ fEnt0(0),
+ fDetTypeRec(0x0),
+ fDfArp(kFALSE),
+ fITSgeom(0x0),
+ fLoader(0x0),
+ fRunLoader(0x0)
+{
     // Default constructor.
     // Inputs:
     //  none.
@@ -47,53 +49,95 @@ AliITSreconstruction::AliITSreconstruction(){
     //   none.
     // Return:
     //    A zero-ed constructed AliITSreconstruction class.
-
-    fFilename = "";
-    fFile     = 0;
-    fITS      = 0;
     fDet[0] = fDet[1] = fDet[2] = kTRUE;
-    fInit     = kFALSE;
 }
 //______________________________________________________________________
-AliITSreconstruction::AliITSreconstruction(const char* filename){
+
+AliITSreconstruction::AliITSreconstruction(AliRunLoader *rl):
+ fInit(kFALSE),
+ fEnt(0),
+ fEnt0(0),
+ fDetTypeRec(0x0),
+ fDfArp(kFALSE),
+ fITSgeom(0x0),
+ fLoader(0x0),
+ fRunLoader(rl)
+{
+  fDet[0] = fDet[1] = fDet[2] = kTRUE;
+}
+//______________________________________________________________________
+AliITSreconstruction::AliITSreconstruction(const char* filename):
+ fInit(kFALSE),
+ fEnt(0),
+ fEnt0(0),
+ fDetTypeRec(0x0),
+ fDfArp(kFALSE),
+ fITSgeom(0x0),
+ fLoader(0x0),
+ fRunLoader(0x0)
+{
     // Standard constructor.
     // Inputs:
     //  const char* filename    filename containing the digits to be
-    //                          reconstructed
+    //                          reconstructed. If filename = 0 (nil)
+    //                          then no file is opened but a file is
+    //                          assumed to already be opened. This 
+    //                          already opened file will be used.
     // Outputs:
     //   none.
     // Return:
     //    A standardly constructed AliITSreconstruction class.
 
-    fFilename = filename;
+    fDet[0] = fDet[1] = fDet[2] = kTRUE;
+
+    fRunLoader = AliRunLoader::Open(filename);
+    if (fRunLoader == 0x0)
+     {
+       Error("AliITSreconstruction","Can not load the session",filename);
+       return;
+     }
+    fRunLoader->LoadgAlice();
+    gAlice = fRunLoader->GetAliRun();
 
-    fFile = (TFile*)gROOT->GetListOfFiles()->FindObject(fFilename.Data());
-    if(fFile) fFile->Close();
-    fFile = new TFile(fFilename.Data(),"UPDATE");
-    //
-    if(gAlice) delete gAlice;
-    gAlice = (AliRun*)fFile->Get("gAlice");
     if(!gAlice) {
-       cout << "gAlice not found on file. Aborting." << endl;
-       fInit = kFALSE;
-       return;
-    } // end if !gAlice
+          Error("AliITSreconstruction","gAlice not found on file. Aborting.");
+          fInit = kFALSE;
+          return;
+      } // end if !gAlice
 
-    Init();
 }
+
+//______________________________________________________________________
+AliITSreconstruction::AliITSreconstruction(const AliITSreconstruction &rec):TTask(rec),
+fInit(rec.fInit),
+fEnt(rec.fEnt),
+fEnt0(rec.fEnt0),
+fDetTypeRec(rec.fDetTypeRec),
+fDfArp(rec.fDfArp),
+fITSgeom(rec.fITSgeom),
+fLoader(rec.fLoader),
+fRunLoader(rec.fRunLoader)
+{
+    // Copy constructor. 
+
+  
+}
+
+//______________________________________________________________________
+AliITSreconstruction& AliITSreconstruction::operator=(const AliITSreconstruction& source){
+    // Assignment operator. 
+  this->~AliITSreconstruction();
+  new(this) AliITSreconstruction(source);
+  return *this;
+
+}
+
 //______________________________________________________________________
 AliITSreconstruction::~AliITSreconstruction(){
-    // Default constructor.
-    // Inputs:
-    //  none.
-    // Outputs:
-    //   none.
-    // Return:
     //    A destroyed AliITSreconstruction class.
-
-    if(fFile) fFile->Close();
-    fFile     = 0;
-    fITS      = 0;
+    
+    //fITS      = 0;
+    delete fRunLoader;
     
 }
 //______________________________________________________________________
@@ -105,29 +149,49 @@ Bool_t AliITSreconstruction::Init(){
     //   none.
     // Return:
     //    kTRUE if no errors initilizing this class occurse else kFALSE
-    Int_t nparticles;
-
-    fITS = (AliITS*) gAlice->GetDetector("ITS");
-    if(!fITS){
-       cout << "ITS not found aborting. fITS=" << fITS << endl;
-       fInit = kFALSE;
-       return fInit;
-    } // end if !fITS
-    if(!(fITS->GetITSgeom())){
-       cout << "ITSgeom not found aborting."<< endl;
-       fInit = kFALSE;
-       return fInit;
-    } // end if !GetITSgeom()
+    Info("Init","");
+    if (fRunLoader == 0x0)
+     {
+       Error("Init","Run Loader is NULL");
+       return kFALSE;
+     }
+    fRunLoader->LoadgAlice();
+    fRunLoader->LoadHeader();  
+
+    fLoader = (AliITSLoader*) fRunLoader->GetLoader("ITSLoader");
+    if(!fLoader) {
+      Error("Init","ITS loader not found");
+      fInit = kFALSE;
+    }
+
     // Now ready to init.
+    fRunLoader->CdGAFile();
+    fITSgeom = fLoader->GetITSgeom();
 
+    fDetTypeRec = new AliITSDetTypeRec(fLoader);
+    fDetTypeRec->SetDefaults();
     fDet[0] = fDet[1] = fDet[2] = kTRUE;
     fEnt0 = 0;
-    fEnt  = gAlice->GetEventsPerRun();
-    fITS->MakeTreeC();
-    nparticles = gAlice->GetEvent(fEnt0);
-    
-    // finished init.
+
+    //fEnt  = gAlice->GetEventsPerRun();
+    fEnt = Int_t(fRunLoader->TreeE()->GetEntries());
+
+    fLoader->LoadDigits("read");
+    fLoader->LoadRecPoints("recreate");
+    fLoader->LoadRawClusters("recreate");
+    if (fLoader->TreeR() == 0x0) fLoader->MakeTree("R");
+    if (fLoader->TreeC() == 0x0) fLoader->MakeTree("C");
+    fDetTypeRec->MakeBranchR(0);
+    fDetTypeRec->MakeBranchC();
+    fDetTypeRec->SetTreeAddress();
+    fDetTypeRec->SetTreeAddressR(fLoader->TreeR());
+
     fInit = InitRec();
+
+    Info("Init","  Done\n\n\n");
+
     return fInit;
 }
 //______________________________________________________________________
@@ -139,45 +203,50 @@ Bool_t AliITSreconstruction::InitRec(){
     //      none.
     // Return:
     //      none.
-    AliITSDetType *idt;
-
+  /*
+  //AliITSDetType *idt;
+  fDetTypeRec->SetLoader(fLoader);
     // SPD
-    if(fDet[kSPD]){
-       idt = fITS->DetType(kSPD);
-       AliITSsegmentationSPD *segSPD = (AliITSsegmentationSPD*)
-                                              idt->GetSegmentationModel();
-       TClonesArray *digSPD = fITS->DigitsAddress(kSPD);
-       TClonesArray *recpSPD = fITS->ClustersAddress(kSPD);
-       AliITSClusterFinderSPD *recSPD = new AliITSClusterFinderSPD(segSPD,
-                                                                   digSPD,
-                                                                   recpSPD);
-       fITS->SetReconstructionModel(kSPD,recSPD);
+  if(fDet[kSPD]){
+    Info("InitRec","SPD");
+    //idt = fITS->DetType(kSPD);
+    AliITSsegmentationSPD *segSPD = (AliITSsegmentationSPD*)fDetTypeRec->GetSegmentationModel(0);
+      TClonesArray *digSPD = fDetTypeRec->DigitsAddress(kSPD);
+      TClonesArray *recpSPD = fDetTypeRec->ClustersAddress(kSPD);
+      Info("InitRec","idt = %#x; digSPD = %#x; recpSPD = %#x",fDetTypeRec,digSPD,recpSPD);
+      AliITSClusterFinderSPD *recSPD = new AliITSClusterFinderSPD(segSPD,digSPD,recpSPD);
+      fDetTypeRec->SetReconstructionModel(kSPD,recSPD);
     } // end if fDet[kSPD].
-    // SDD
-    if(fDet[kSDD]){
-       idt = fITS->DetType(kSDD);
-       AliITSsegmentationSDD *segSDD = (AliITSsegmentationSDD*)
-                                          idt->GetSegmentationModel();
-       AliITSresponseSDD *resSDD = (AliITSresponseSDD*)
-                                          idt->GetResponseModel();
-       TClonesArray *digSDD = fITS->DigitsAddress(kSDD);
-       TClonesArray *recpSDD = fITS->ClustersAddress(kSDD);
-       AliITSClusterFinderSDD *recSDD =new AliITSClusterFinderSDD(segSDD,
-                                                                  resSDD,
+  // SDD
+  if(fDet[kSDD]){
+    Info("InitRec","SDD");
+    //    idt = fITS->DetType(kSDD);
+    AliITSsegmentationSDD *segSDD = (AliITSsegmentationSDD*)
+      fDetTypeRec->GetSegmentationModel(1);
+    AliITSresponseSDD *resSDD = (AliITSresponseSDD*)
+      fDetTypeRec->GetCalibrationModel(fDetTypeRec->GetITSgeom()->GetStartSDD()); 
+    TClonesArray *digSDD = fDetTypeRec->DigitsAddress(kSDD);
+    TClonesArray *recpSDD = fDetTypeRec->ClustersAddress(kSDD);
+    AliITSClusterFinderSDD *recSDD =new AliITSClusterFinderSDD(segSDD,
+                                                              resSDD,
                                                               digSDD,recpSDD);
-       fITS->SetReconstructionModel(kSDD,recSDD);
-    } // end if fDet[kSDD]
+    fDetTypeRec->SetReconstructionModel(kSDD,recSDD);
+  } // end if fDet[kSDD]
     // SSD
-    if(fDet[kSSD]){
-       idt = fITS->DetType(kSSD);
-       AliITSsegmentationSSD *segSSD = (AliITSsegmentationSSD*)
-                                        idt->GetSegmentationModel();
-       TClonesArray *digSSD = fITS->DigitsAddress(kSSD);
-       AliITSClusterFinderSSD *recSSD =new AliITSClusterFinderSSD(segSSD,
-                                                                  digSSD);
-       fITS->SetReconstructionModel(kSSD,recSSD);
+  if(fDet[kSSD]){
+    Info("InitRec","SSD");
+    //idt = fITS->DetType(kSSD);
+    AliITSsegmentationSSD *segSSD = (AliITSsegmentationSSD*)
+                                       fDetTypeRec->GetSegmentationModel(2);
+      TClonesArray *digSSD = fDetTypeRec->DigitsAddress(kSSD);
+      AliITSClusterFinderSSD *recSSD =new AliITSClusterFinderSSD(segSSD,
+                                                                digSSD);
+      recSSD->SetITSgeom(fDetTypeRec->GetITSgeom());
+      fDetTypeRec->SetReconstructionModel(kSSD,recSSD);
     } // end if fDet[kSSD]
-
+  */
+  fDetTypeRec->SetDefaultClusterFinders();
+    Info("InitRec","    Done\n");
     return kTRUE;
 }
 //______________________________________________________________________ 
@@ -190,29 +259,53 @@ void AliITSreconstruction::Exec(const Option_t *opt){
     // Return:
     //      none.
     Option_t *lopt;
-    Int_t nparticles,evnt;
+    Int_t evnt;
 
     if(strstr(opt,"All")||strstr(opt,"ALL")||strstr(opt,"ITS")||opt==0){
-       fDet[0] = fDet[1] = fDet[2] = kTRUE;
-       lopt = "All";
+      fDet[0] = fDet[1] = fDet[2] = kTRUE;
+      lopt = "All";
     }else{
-       fDet[0] = fDet[1] = fDet[2] = kFALSE;
-       if(strstr(opt,"SPD")) fDet[kSPD] = kTRUE;
-       if(strstr(opt,"SDD")) fDet[kSDD] = kTRUE;
-       if(strstr(opt,"SSD")) fDet[kSSD] = kTRUE;
-       if(fDet[kSPD] && fDet[kSDD] && fDet[kSSD]) lopt = "All";
-       else lopt = opt;
+      fDet[0] = fDet[1] = fDet[2] = kFALSE;
+      if(strstr(opt,"SPD")) fDet[kSPD] = kTRUE;
+      if(strstr(opt,"SDD")) fDet[kSDD] = kTRUE;
+      if(strstr(opt,"SSD")) fDet[kSSD] = kTRUE;
+      if(fDet[kSPD] && fDet[kSDD] && fDet[kSSD]) lopt = "All";
+      else lopt = opt;
     } // end if strstr(opt,...)
 
     if(!fInit){
-       cout << "Initilization Failed, Can't run Exec." << endl;
-       return;
+      cout << "Initilization Failed, Can't run Exec." << endl;
+      return;
     } // end if !fInit
-    for(evnt=0;evnt<fEnt;evnt++){
-       nparticles = gAlice->GetEvent(evnt);
-       gAlice->SetEvent(evnt);
-       if(!gAlice->TreeR()) gAlice->MakeTree("R");
-       fITS->MakeBranch("R");
-       fITS->DigitsToRecPoints(evnt,0,lopt);
+    for(evnt=0;evnt<fEnt;evnt++)
+     {
+      Info("Exec","");
+      Info("Exec","Processing Event %d",evnt);
+      Info("Exec","");
+
+      fRunLoader->GetEvent(evnt);
+      if (fLoader->TreeR() == 0x0) fLoader->MakeTree("R");
+      fDetTypeRec->MakeBranchR(0);
+      if (fLoader->TreeC() == 0x0){
+       fDetTypeRec->MakeTreeC();
+       fDetTypeRec->MakeBranchC();
+      }
+      fDetTypeRec->SetTreeAddressR(fLoader->TreeR());
+      fDetTypeRec->SetTreeAddressD(fLoader->TreeD());
+      fDetTypeRec->DigitsToRecPoints(evnt,0,lopt);
     } // end for evnt
 }
+//______________________________________________________________________ 
+void AliITSreconstruction::SetOutputFile(TString filename){
+  // Set a new file name for recpoints. 
+  // It must be called before Init()
+  if(!fLoader)fLoader = (AliITSLoader*) fRunLoader->GetLoader("ITSLoader");
+  if(fLoader){
+    Info("SetOutputFile","name for rec points is %s",filename.Data());
+    fLoader->SetRecPointsFileName(filename);
+  }
+  else {
+    Error("SetOutputFile",
+    "ITS loader not available. Not possible to set name: %s",filename.Data());
+  }
+}