]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSReconstructioner.cxx
Write header with vertex position.
[u/mrichter/AliRoot.git] / PHOS / AliPHOSReconstructioner.cxx
index b532e092a03aaf654c96af88df91a43a0a077004..8624d3df5a9e020c3dcd1154cb38efbcca4095e4 100644 (file)
 /* $Id$ */
 
 //_________________________________________________________________________
-//  Algorithm class for the reconstruction: clusterizer
-//                                          track segment maker
-//                                          particle identifier   
-//                  
-//*-- Author: Gines Martinez & Yves Schutz (SUBATECH)
-
+//*--
+//*-- Author: Gines Martinez & Yves Schutz (SUBATECH) 
+//*-- Compleetely redesigned by Dmitri Peressounko (SUBATECH & RRC KI) March 2001
+/////////////////////////////////////////////////////////////////////////////////////
+//  Wrapping class for reconstruction. Allows to produce reconstruction from 
+//  different steps: from previously produced hits,sdigits, etc. Each new reconstruction
+//  flow (e.g. digits, made from them RecPoints, subsequently made TrackSegments, 
+//  subsequently made RecParticles) are distinguished by the title of created branches. One can 
+//  use this title as a comment, see use case below. 
+//  Thanks to getters, one can set 
+//  parameters to reconstruction briks. The full set of parameters is saved in the 
+//  corresponding branch: e.g. parameters of clusterizer are stored in branch 
+//  TreeR::AliPHOSClusterizer with the same title as the branch containing the RecPoints. //  TTree does not support overwriting, therefore one can not produce several 
+//  branches with the same names and titles - use different titles.
+//
+//  Use case: 
+//
+//  root [0] AliPHOSReconstructioner * r = new AliPHOSReconstructioner("galice.root")
+//              //  Set the header file
+//  root [1] r->ExecuteTask() 
+//              //  Make full chain of reconstruction
+//
+//              // One can specify the title for each branch 
+//  root [2] r->SetBranchFileName("RecPoints","RecPoints1") ;
+//      
+//             // One can change parameters of reconstruction algorithms
+//  root [3] r->GetClusterizer()->SetEmcLocalMaxCut(0.02)
+//
+//             // One can specify the starting point of the reconstruction and title of all 
+//             // branches produced in this pass
+//  root [4] r->StartFrom("AliPHOSClusterizer","Local max cut 0.02") 
+//             // means that will use already generated Digits and produce only RecPoints, 
+//             // TS and RecParticles 
+//
+//             // And finally one can call ExecuteTask() with the following options
+//  root [5] r->ExecuteTask("debug all timing")
+//            // deb     - prints the numbers of RecPoints, TrackSegments, RecParticles 
+//            // deb all - prints in addition list of RecPoints, TrackSegments, RecParticles  
+//            // timing  - prints benchmarking results
+///////////////////////////////////////////////////////////////////////////////////////////////////
 
 // --- ROOT system ---
 
-#include "TClonesArray.h"
-
 // --- Standard library ---
 
-#include <iomanip>
-
 // --- AliRoot header files ---
-
+#include "AliESD.h"
+#include "AliESDCaloTrack.h"
 #include "AliPHOSReconstructioner.h"
-#include "AliPHOSClusterizer.h"
+#include "AliPHOSClusterizerv1.h"
+#include "AliPHOSTrackSegmentMakerv1.h"
+#include "AliPHOSPIDv1.h"
+#include "AliPHOSGetter.h"
+
 
 ClassImp(AliPHOSReconstructioner)
 
 //____________________________________________________________________________
-AliPHOSReconstructioner::AliPHOSReconstructioner(AliPHOSClusterizer * Clusterizer, 
-                                                AliPHOSTrackSegmentMaker * Tracker,
-                                                AliPHOSPID * Pid)
+  AliPHOSReconstructioner::AliPHOSReconstructioner():TTask("AliPHOSReconstructioner","")
 {
   // ctor
-  
-  fClusterizer        = Clusterizer ;
-  fTrackSegmentMaker  = Tracker ;
-  fPID                = Pid ; 
-  fDebugReconstruction = kFALSE ;
-} 
+  fClusterizer = 0 ;
+  fTSMaker     = 0 ;
+  fPID         = 0 ; 
+  fFirstEvent  = 0 ; 
+  fLastEvent   = -1 ; 
+  fIsInitialized = kFALSE ;
 
-
-//____________________________________________________________________________
- void AliPHOSReconstructioner::Init(AliPHOSClusterizer * Clusterizer, 
-                                                AliPHOSTrackSegmentMaker * Tracker,
-                                                AliPHOSPID * Pid)
-{
-  fClusterizer        = Clusterizer ;
-  fTrackSegmentMaker  = Tracker ;
-  fPID                = Pid ; 
-  fDebugReconstruction = kFALSE ;
 } 
 
 //____________________________________________________________________________
- void AliPHOSReconstructioner::Make(DigitsList * dl, RecPointsList * emccl, RecPointsList * ppsdl, 
-                                    TrackSegmentsList * trsl, RecParticlesList * rpl)
+AliPHOSReconstructioner::AliPHOSReconstructioner(const char* evFoldName,const char * branchName):
+TTask("AliPHOSReconstructioner",evFoldName)
 {
-  // Launches the Reconstruction process in the sequence: Make the reconstructed poins (clusterize)
-  //                                                      Make the track segments 
-  //                                                      Make the reconstructed particles
-  Int_t index ; 
-  // Digit Debuging
-  if  (fDebugReconstruction)     {
-    cout << ">>>>>>>>>>>>>>>>>>>>>> DebugReconstruction  <<<<<<<<<<<<<<<<<<<<<<<<<<"  << endl ;
-    cout << "DebugReconstruction>>> Digit list entries is " <<    dl->GetEntries() << endl ;
-    AliPHOSDigit * digit;
-    Bool_t calorimeter ;
-    Float_t factor;
-    cout << "DebugReconstruction>>>    Vol Id " << 
-      " Ene(MeV, KeV) "             <<                         
-      " Index "                    << 
-      " Nprim "                     << 
-      " Prim1 "                      << 
-      " Prim2 "                      << 
-      " Prim3 "                      <<  endl;      
-    for (index = 0 ; index < dl->GetEntries() ; index++) {
-      digit = (AliPHOSDigit * )  dl->At(index) ;
-      calorimeter = fClusterizer->IsInEmc(digit);
-      if (calorimeter) factor =1000. ; else factor=1000000.;
-      cout << "DebugReconstruction>>>  " << 
-       setw(8)  <<  digit->GetId() << " "  <<
-       setw(3)  <<  calorimeter <<  
-       setw(10) <<  factor*fClusterizer->Calibrate(digit->GetAmp()) <<       "  "  <<                   
-       setw(6)  <<  digit->GetIndexInList() << "  "  << 
-       setw(5)  <<  digit->GetNprimary() <<"  "  << 
-       setw(5)  <<  digit->GetPrimary(1) <<"  "  << 
-       setw(5)  <<  digit->GetPrimary(2) <<"  "  << 
-       setw(5)  <<  digit->GetPrimary(3) << endl;       
-    }
-    
-  }
-
-
+  // ctor
 
-  // Making Clusters
-  if  (fDebugReconstruction)  cout << "DebugReconstruction>>> Start making reconstructed points (clusterizing)" << endl;
-  fClusterizer->MakeClusters(dl, emccl, ppsdl);
+  AliPHOSGetter::Instance(evFoldName) ; 
 
-  // mark the position of the RecPoints in the array
-  AliPHOSEmcRecPoint * emcrp ; 
-  for (index = 0 ; index < emccl->GetEntries() ; index++) {
-    emcrp = (AliPHOSEmcRecPoint * )emccl->At(index) ; 
-    emcrp->SetIndexInList(index) ; 
-  }
-  AliPHOSPpsdRecPoint * ppsdrp ; 
-  for (index = 0 ; index < ppsdl->GetEntries() ; index++) {
-    ppsdrp = (AliPHOSPpsdRecPoint * )ppsdl->At(index) ; 
-    ppsdrp->SetIndexInList(index) ; 
-  }
+  fRecPointBranch=branchName ; 
+  fClusterizer = new AliPHOSClusterizerv1(evFoldName, GetTitle());
+  Add(fClusterizer);
   
-  if  (fDebugReconstruction) 
-    {
-      cout << "DebugReconstruction>>> Cluster emc list entries is " <<    emccl->GetEntries() << endl ;
-      AliPHOSEmcRecPoint * recpoint;
-      cout << "DebugReconstruction>>> Module "  << 
-       "Ene(MeV) "             <<                         
-       "Index "                    << 
-       "Multi "                    << 
-       "   X     "                      << 
-       "   Y     "                      << 
-       "   Z    "                      << 
-       " Lambda 1   "                     <<  
-       " Lambda 2   "                     <<
-       "MaxEnergy(MeV) "                 <<
-       "Nprim "                 <<
-       "Prim1 "                 <<
-       "Prim2 "                 <<
-       "Prim3 "                 << endl;  
-      for (index = 0 ; index < emccl->GetEntries() ; index++) {
-       recpoint = (AliPHOSEmcRecPoint * )emccl->At(index) ; 
-       TVector3  locpos;  recpoint->GetLocalPosition(locpos);
-       Float_t lambda[2]; recpoint->GetElipsAxis(lambda);
-       Int_t * primaries; 
-       Int_t nprimaries;
-       primaries = recpoint->GetPrimaries(nprimaries);
-       cout << "DebugReconstruction>>>  " << 
-         setw(2) <<recpoint->GetPHOSMod() << " "  << 
-         setw(9) << 1000.*recpoint->GetTotalEnergy() <<       " "  <<                   
-         setw(6) <<  recpoint->GetIndexInList() << " "  << 
-         setw(5) <<  recpoint->GetMultiplicity() <<" "  << 
-         setw(8) <<  locpos.X() <<" "  << 
-         setw(8) <<  locpos.Y() <<" "  << 
-         setw(8) <<  locpos.Z() << " " <<
-         setw(10) << lambda[0] << "  " <<
-         setw(10) << lambda[1] << "  " <<
-         setw(9) << 1000*recpoint->GetMaximalEnergy() << "  " << 
-         setw(9) << nprimaries << "  "  <<
-         setw(4) << primaries[0] << "  "  <<
-         setw(4) << primaries[1] << "  "  <<
-         setw(4) << primaries[2] << "  "  << endl;              
-      }
-      
-      cout << "DebugReconstruction>>> Cluster ppsd list entries is " <<    ppsdl->GetEntries() << endl ;
-      AliPHOSPpsdRecPoint * ppsdrecpoint;
-      Text_t detector[4];
-      cout << "DebugReconstruction>>> Module "  << 
-       "Det     "             <<      
-       "Ene(KeV) "             <<                         
-       "Index "                    << 
-       "Multi "                    << 
-       "   X     "                      << 
-       "   Y     "                      << 
-       "   Z         "                      << 
-       "Nprim "                 <<
-       "Prim1 "                 <<
-       "Prim2 "                 <<
-       "Prim3 "                 << endl;  
-      for (index = 0 ; index < ppsdl->GetEntries() ; index++) {
-       ppsdrecpoint = (AliPHOSPpsdRecPoint * ) ppsdl->At(index) ; 
-       TVector3  locpos; ppsdrecpoint->GetLocalPosition(locpos);
-       Int_t * primaries; 
-       Int_t nprimaries;
-        if (ppsdrecpoint->GetUp()) detector="CPV"; else detector="PC ";
-       primaries = ppsdrecpoint->GetPrimaries(nprimaries);
-       cout << "DebugReconstruction>>> " << 
-         setw(4) << ppsdrecpoint->GetPHOSMod() << "  "  << 
-         setw(4)  << detector << " "      <<
-         setw(9) << 1000000.*ppsdrecpoint->GetTotalEnergy() <<       " "  <<             
-         setw(6) <<  ppsdrecpoint->GetIndexInList() << " "  << 
-         setw(5) <<  ppsdrecpoint->GetMultiplicity() <<" "  << 
-         setw(8) <<  locpos.X() <<" "  << 
-         setw(8) <<  locpos.Y() <<" "  << 
-         setw(8) <<  locpos.Z() << " " <<
-         setw(9) << nprimaries << "  "  <<
-         setw(4) << primaries[0] << "  "  <<
-         setw(4) << primaries[1] << "  "  <<
-         setw(4) << primaries[2] << "  "  << endl;              
-      }
-    }  
+  fTSBranch=branchName ; 
+  fTSMaker     = new AliPHOSTrackSegmentMakerv1(evFoldName, GetTitle());
+  Add(fTSMaker) ;
   
+  fRecPartBranch=branchName ; 
+  fPID         = new AliPHOSPIDv1(evFoldName, GetTitle());
+  Add(fPID);
   
-  if  (fDebugReconstruction)  cout << "DebugReconstruction>>>> Start making track segments(unfolding+tracksegments)" << endl;
-  fTrackSegmentMaker->MakeTrackSegments(dl, emccl, ppsdl, trsl) ;   
+  fIsInitialized = kTRUE ;
+} 
+//____________________________________________________________________________
+void AliPHOSReconstructioner::Exec(Option_t *opt)
+{
+  //check, if the names of branches, which should be made coincide with already
+  //existing
+  if (!opt) 
+    return ; 
+  if(!fIsInitialized)
+    Init() ;
+}
+//____________________________________________________________________________
+void AliPHOSReconstructioner:: Clusters2Tracks(Int_t ievent, AliESD *event)
+{
+  // Convert PHOS reconstructed particles into ESD object for event# ievent.
+  // ESD object is returned as an argument event
+
+  if(!fIsInitialized) Init() ;
+
+  fClusterizer->SetEventRange(ievent,ievent);
+  fClusterizer->ExecuteTask();
+
+  fTSMaker    ->SetEventRange(ievent,ievent);
+  fTSMaker    ->ExecuteTask();
   
-  // mark the position of the TrackSegments in the array
-  AliPHOSTrackSegment * trs ; 
-  for (index = 0 ; index < trsl->GetEntries() ; index++) {
-    trs = (AliPHOSTrackSegment * )trsl->At(index) ; 
-    trs->SetIndexInList(index) ; 
+  fPID        ->SetEventRange(ievent,ievent);
+  fPID        ->ExecuteTask();
+
+  AliPHOSGetter *gime = AliPHOSGetter::Instance();
+  TClonesArray *recParticles = gime->RecParticles();
+  Int_t nOfRecParticles = recParticles->GetEntries();
+  for (Int_t recpart=0; recpart<nOfRecParticles; recpart++) {
+    AliESDCaloTrack *ct = new AliESDCaloTrack((AliPHOSRecParticle*)recParticles->At(recpart));
+    event->AddCaloTrack(ct);
   }
-  if  (fDebugReconstruction){
-    cout << "DebugReconstruction>>> Track segment list entries is " <<    trsl->GetEntries() << endl ;
-    cout << "DebugReconstruction>>> Module "  << 
-      "Ene(KeV) "             <<                         
-      "Index "                    << 
-      "   X      "                      << 
-      "   Y      "                      << 
-      "   Z       "                      <<
-      " rX        "                      << 
-      " rY        "                      << 
-      " rZ      "                               << 
-      "Nprim "                 <<
-      "Prim1 "                 <<
-      "Prim2 "                 <<
-      "Prim3 "                 << endl;  
+  
+}
+//____________________________________________________________________________
+ void AliPHOSReconstructioner::Init()
+{
+  // initiliaze Reconstructioner if necessary: we can not do this in default constructor
+
+  if(!fIsInitialized){
     
-    for (index = 0 ; index < trsl->GetEntries() ; index++) {
-      trs = (AliPHOSTrackSegment * )trsl->At(index) ; 
-      TVector3 locpos; trs->GetPosition(locpos);
-      Int_t * primaries; 
-      Int_t nprimaries;
-      primaries = trs->GetPrimariesEmc(nprimaries);
-      cout << "DebugReconstruction>>> " << 
-       setw(4) << trs->GetPHOSMod() << "  "  << 
-       setw(9) << 1000.*trs->GetEnergy() <<       " "  <<             
-       setw(3) <<  trs->GetIndexInList() << " "  <<  
-       setw(9) <<  locpos.X() <<" "  << 
-       setw(9) <<  locpos.Y() <<" "  << 
-       setw(9) <<  locpos.Z() << " " <<
-       setw(10) <<  (trs->GetMomentumDirection()).X() << " " <<
-       setw(10) <<  (trs->GetMomentumDirection()).Y() << " " <<
-       setw(10) <<  (trs->GetMomentumDirection()).Z() << " " <<
-       setw(4) << nprimaries << "  "  <<
-       setw(4) << primaries[0] << "  "  <<
-       setw(4) << primaries[1] << "  "  <<
-       setw(4) << primaries[2] << "  "  << endl;
-    }
+    fRecPointBranch="Default" ; 
+    fClusterizer = new AliPHOSClusterizerv1(GetTitle(),fRecPointBranch.Data());
+    Add(fClusterizer) ;
+
+    fTSBranch="Default" ; 
+    fTSMaker     = new AliPHOSTrackSegmentMakerv1(GetTitle(),fTSBranch.Data());
+    Add(fTSMaker) ;
+
+
+    fRecPartBranch="Default"; 
+    fPID         = new AliPHOSPIDv1(GetTitle(),fRecPartBranch.Data()) ;
+    Add(fPID) ;
+    
+    fIsInitialized = kTRUE ;
     
   }
-  if  (fDebugReconstruction)  cout << "DebugReconstruction>>>> Start making reconstructed particles" << endl;
-  
-  fPID->MakeParticles(trsl, rpl) ; 
-  
-  // mark the position of the RecParticles in the array
-  AliPHOSRecParticle * rp ; 
-  for (index = 0 ; index < rpl->GetEntries() ; index++) {
-    rp = (AliPHOSRecParticle * )rpl->At(index) ; 
-    rp->SetIndexInList(index) ; 
+} 
+//____________________________________________________________________________
+AliPHOSReconstructioner::~AliPHOSReconstructioner()
+{
+  // Delete data members if any
+} 
+
+void AliPHOSReconstructioner::Print()const {
+  // Print reconstructioner data  
+
+  TString message ; 
+  message  = "-----------------AliPHOSReconstructioner---------------\n" ;
+  message += " Reconstruction of the header file %s\n" ;
+  message += " with the following modules:\n" ;
+
+  if(fClusterizer->IsActive()){
+    message += "   (+)   %s to branch %s\n" ;
   }
-  //Debugger of RecParticles
- if  (fDebugReconstruction){
-    cout << "DebugReconstruction>>>  Reconstructed particle list entries is " <<    rpl->GetEntries() << endl ;
-    cout << "DebugReconstruction>>> Module "  << 
-      "    PARTICLE     "   <<
-      "Ene(KeV) "             <<                         
-      "Index "                    << 
-      "   X      "                      << 
-      "   Y      "                      << 
-      "   Z       "                      <<
-      "Nprim "                 <<
-      "Prim1 "                 <<
-      "Prim2 "                 <<
-      "Prim3 "                 << endl;  
-    for (index = 0 ; index < rpl->GetEntries() ; index++) {
-      rp = (AliPHOSRecParticle * ) rpl->At(index) ;       
-      TVector3 locpos; (rp->GetPHOSTrackSegment())->GetPosition(locpos);
-      Int_t * primaries; 
-      Int_t nprimaries;
-      Text_t particle[11];
-      primaries = (rp->GetPHOSTrackSegment())->GetPrimariesEmc(nprimaries);
-      switch(rp->GetType())
-       {
-       case kNEUTRAL_EM:
-         particle = "NEUTRAL_EM";
-         break;
-       case kNEUTRAL_HA:
-         particle = "NEUTRAL_HA";
-         break;
-       case kGAMMA:
-         particle = "GAMMA     ";
-         break ;
-       case kGAMMA_HA: 
-         particle = "GAMMA_HA  ";
-         break ;
-       case kABSURD_EM:
-         particle = "ABSURD_EM " ;
-         break ;
-       case kABSURD_HA:
-         particle = "ABSURD_HA " ;
-         break ;       
-       case kELECTRON:
-         particle = "ELECTRON  " ;
-         break ;
-       case kCHARGED_HA:
-         particle = "CHARGED_HA" ;
-         break ; 
-       }
-      
-      cout << "DebugReconstruction>>> " << 
-       setw(4) << (rp->GetPHOSTrackSegment())->GetPHOSMod() << "  "  <<
-       setw(15) << particle << "  " <<
-       setw(9) << 1000.*(rp->GetPHOSTrackSegment())->GetEnergy() <<       " "  <<             
-       setw(3) <<  rp->GetIndexInList() << " "  <<  
-       setw(9) <<  locpos.X() <<" "  << 
-       setw(9) <<  locpos.Y() <<" "  << 
-       setw(9) <<  locpos.Z() << " " <<
-       setw(4) << nprimaries << "  "  <<
-       setw(4) << primaries[0] << "  "  <<
-       setw(4) << primaries[1] << "  "  <<
-       setw(4) << primaries[2] << "  "  << endl;
-    }
-    
+
+  if(fTSMaker->IsActive()){
+    message += "   (+)   %s to branch %s\n" ; 
   }
 
+  if(fPID->IsActive()){
+    message += "   (+)   %s to branch %s\n" ;  
+  }
+  Info("Print", message.Data(), 
+       GetTitle(), 
+       fClusterizer->GetName(), fRecPointBranch.Data(), 
+       fTSMaker->GetName(), fTSBranch.Data() , 
+       fPID->GetName(), fRecPartBranch.Data() ) ; 
+}
 
+//____________________________________________________________________________
+void AliPHOSReconstructioner::SetEventRange(Int_t first, Int_t last)
+{
+  // Set the event range to process
+  fFirstEvent=first; 
+  fLastEvent=last; 
+  fClusterizer->SetEventRange(fFirstEvent, fLastEvent) ; 
+  fTSMaker->SetEventRange(fFirstEvent, fLastEvent) ;
+  fPID->SetEventRange(fFirstEvent, fLastEvent) ;
 }