]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITS.cxx
Raw data simulation, one file per DDL, mini header replaced by data header (T.Kuhr)
[u/mrichter/AliRoot.git] / ITS / AliITS.cxx
index c68fe67284568fa48acef18914dd4a652e572f5e..c63ac6478c3c065f4e8bd987a4f46c58106db257 100644 (file)
@@ -88,9 +88,13 @@ the AliITS class.
 #include "AliITSClusterFinderSSD.h"
 #include "AliITSDetType.h"
 #include "AliITSLoader.h"
-#include "AliITSRawCluster.h"
+#include "AliITSRawClusterSPD.h"
+#include "AliITSRawClusterSDD.h"
+#include "AliITSRawClusterSSD.h"
 #include "AliITSRecPoint.h"
-#include "AliITSdigit.h"
+#include "AliITSdigitSPD.h"
+#include "AliITSdigitSDD.h"
+#include "AliITSdigitSSD.h"
 #include "AliITSgeom.h"
 #include "AliITShit.h"
 #include "AliITSmodule.h"
@@ -104,11 +108,44 @@ the AliITS class.
 #include "AliITSsimulationSDD.h"
 #include "AliITSsimulationSPD.h"
 #include "AliITSsimulationSSD.h"
+#include "AliMC.h"
+#include "AliITSDigitizer.h"
+#include "AliITSDDLRawData.h"
+#include "AliITSclustererV2.h"
+#include "AliITStrackerV2.h"
+#include "AliITStrackerSA.h"
+#include "AliITSpidESD.h"
+#include "AliV0vertexer.h"
+#include "AliITSVertexerPPZ.h"
+#include "AliITSVertexerFast.h"
+#include "AliITSVertexerZ.h"
+#include "AliITSVertexerIons.h"
+#include "AliCascadeVertexer.h"
+#include "AliESD.h"
+#include "AliRun.h"
 
 ClassImp(AliITS)
 
 //______________________________________________________________________
-AliITS::AliITS() : AliDetector() {
+AliITS::AliITS() : AliDetector(),
+    fITSgeom(0),
+    fEuclidOut(0),
+    fITSmodules(0),
+    fOpt("All"),
+    fIdN(0),
+    fIdSens(0),
+    fIdName(0),
+    fNDetTypes(kNTYPES),
+    fDetTypes(0),
+    fSDigits(0),
+    fNSDigits(0),
+    fDtype(0),
+    fNdtype(0),
+    fCtype(0),
+    fNctype(0),
+    fRecPoints(0),
+    fNRecPoints(0),
+    fSelectedVertexer(0){
     // Default initializer for ITS
     //      The default constructor of the AliITS class. In addition to
     // creating the AliITS class it zeros the variables fIshunt (a member
@@ -125,35 +162,30 @@ AliITS::AliITS() : AliDetector() {
     fIshunt     = 0;   // not zeroed in AliDetector.
 
     // AliITS variables.
-    fEuclidOut  = 0;
-    fITSgeom    = 0;
-    fITSmodules = 0;
-    fOpt        = "All";
 //    SetDetectors(); // default to fOpt="All". This variable not written out.
-
-    fIdN        = 0;
-    fIdName     = 0;
-    fIdSens     = 0;
-
-    fNDetTypes  = kNTYPES;
-    fDetTypes   = 0;
-
-    fSDigits    = 0;
-    fNSDigits   = 0;
-
-    fNdtype     = 0;
-    fDtype      = 0;
-
-    fCtype      = 0;
-    fNctype     = 0;
-
-    fRecPoints  = 0;
-    fNRecPoints = 0;
-
     SetMarkerColor(kRed);
+    SelectVertexer(" ");
 }
 //______________________________________________________________________
-AliITS::AliITS(const char *name, const char *title):AliDetector(name,title){
+AliITS::AliITS(const char *name, const char *title):AliDetector(name,title),
+    fITSgeom(0),
+    fEuclidOut(0),
+    fITSmodules(0),
+    fOpt("All"),
+    fIdN(0),
+    fIdSens(0),
+    fIdName(0),
+    fNDetTypes(kNTYPES),
+    fDetTypes(0),
+    fSDigits(0),
+    fNSDigits(0),
+    fDtype(0),
+    fNdtype(0),
+    fCtype(0),
+    fNctype(0),
+    fRecPoints(0),
+    fNRecPoints(0),
+    fSelectedVertexer(0){
     //     The standard Constructor for the ITS class. In addition to 
     // creating the AliITS class, it allocates memory for the TClonesArrays 
     // fHits, fSDigits, fDigits, fITSpoints, and the TObjArray of fCtype 
@@ -175,7 +207,7 @@ AliITS::AliITS(const char *name, const char *title):AliDetector(name,title){
 
     fIshunt     = 0;  // not zeroed in AliDetector
     fHits       = new TClonesArray("AliITShit", 1560);//not done in AliDetector
-    gAlice->AddHitList(fHits);  // Not done in AliDetector.
+    if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);// Not done in AliDetector.
 
     fEuclidOut  = 0;
     fITSgeom    = 0;
@@ -209,7 +241,7 @@ AliITS::AliITS(const char *name, const char *title):AliDetector(name,title){
     } // end for i
 
     SetMarkerColor(kRed);
-
+    SelectVertexer(" ");
 }
 //______________________________________________________________________
 AliITS::~AliITS(){
@@ -341,7 +373,7 @@ void AliITS::Init(){
 
     SetDefaults();
     // Array of TStrings
-    for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
+    if(gMC) for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
 }
 //______________________________________________________________________
 void AliITS::SetDefaults(){
@@ -718,7 +750,7 @@ void AliITS::InitModules(Int_t size,Int_t &nmodules){
 }
 //______________________________________________________________________
 void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t nmodules,
-                         Option_t *option,Text_t *filename){
+                         Option_t *option, const char *filename){
     // fill the modules with the sorted by module hits; add hits from
     // background if option=Add.
     // Inputs:
@@ -946,19 +978,23 @@ void AliITS::Hits2SDigits(){
     //      none.
 
 //    return; // Using Hits in place of the larger sDigits.
+    fLoader->LoadHits("read");
+    fLoader->LoadSDigits("recreate");
     AliRunLoader* rl = fLoader->GetRunLoader(); 
-    AliHeader *header=rl->GetHeader(); // Get event number from this file.
-    if (header == 0x0)
-     {
-       rl->LoadHeader();
-       header=rl->GetHeader();
-       if (header == 0x0) return;
-     }
+
+    for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
     // Do the Hits to Digits operation. Use Standard input values.
     // Event number from file, no background hit merging , use size from
     // AliITSgeom class, option="All", input from this file only.
-    HitsToSDigits(header->GetEvent(),0,-1," ",fOpt," ");
+      rl->GetEvent(iEvent);
+      if (!fLoader->TreeS()) fLoader->MakeTree("S");
+      MakeBranch("S");
+      SetTreeAddress();
+      HitsToSDigits(iEvent,0,-1," ",fOpt," ");
+    }
     
+    fLoader->UnloadHits();
+    fLoader->UnloadSDigits();
 }
 //______________________________________________________________________
 void AliITS::Hits2PreDigits(){
@@ -975,6 +1011,11 @@ void AliITS::Hits2PreDigits(){
     HitsToPreDigits(header->GetEvent(),0,-1," ",fOpt," ");
 }
 //______________________________________________________________________
+AliDigitizer* AliITS::CreateDigitizer(AliRunDigitizer* manager) const
+{
+  return new AliITSDigitizer(manager);
+}
+//______________________________________________________________________
 void AliITS::SDigitsToDigits(Option_t *opt){
     // Standard Summable digits to Digits function.
     // Inputs:
@@ -1012,8 +1053,9 @@ void AliITS::SDigitsToDigits(Option_t *opt){
         iDetType = DetType(id);
         sim      = (AliITSsimulation*)iDetType->GetSimulationModel();
         if (!sim) {
-            Error("SDigit2Digits",
-                  "The simulation class was not instanciated!");
+            Error("SDigit2Digits","The simulation class was not "
+                  "instanciated for module %d type %s!",module,
+                  geom->GetModuleTypeName(module));
             exit(1);
         } // end if !sim
         sim->InitSimulationModule(module,gAlice->GetEvNumber());
@@ -1046,15 +1088,27 @@ void AliITS::Hits2Digits(){
     // Outputs:
     //      none.
 
-    AliHeader *header=fLoader->GetRunLoader()->GetHeader(); // Get event number from this file.
+    fLoader->LoadHits("read");
+    fLoader->LoadDigits("recreate");
+    AliRunLoader* rl = fLoader->GetRunLoader(); 
+
+    for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
     // Do the Hits to Digits operation. Use Standard input values.
     // Event number from file, no background hit merging , use size from
     // AliITSgeom class, option="All", input from this file only.
-    HitsToDigits(header->GetEvent(),0,-1," ",fOpt," ");
+      rl->GetEvent(iEvent);
+      if (!fLoader->TreeD()) fLoader->MakeTree("D");
+      MakeBranch("D");
+      SetTreeAddress();   
+      HitsToDigits(iEvent,0,-1," ",fOpt," ");
+    }
+
+    fLoader->UnloadHits();
+    fLoader->UnloadDigits();
 }
 //______________________________________________________________________
 void AliITS::HitsToSDigits(Int_t evNumber,Int_t bgrev,Int_t size,
-                          Option_t *option, Option_t *opt,Text_t *filename){
+                          Option_t *option, Option_t *opt, const char *filename){
     // keep galice.root for signal and name differently the file for 
     // background when add! otherwise the track info for signal will be lost !
     // the condition below will disappear when the geom class will be
@@ -1079,7 +1133,7 @@ void AliITS::HitsToSDigits(Int_t evNumber,Int_t bgrev,Int_t size,
 }
 //______________________________________________________________________
 void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
-                          Option_t *option, Option_t *opt,Text_t *filename){
+                          Option_t *option, Option_t *opt, const char *filename){
     //   Keep galice.root for signal and name differently the file for 
     // background when add! otherwise the track info for signal will be lost !
     // the condition below will disappear when the geom class will be
@@ -1122,8 +1176,9 @@ void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
         iDetType = DetType(id);
         sim      = (AliITSsimulation*)iDetType->GetSimulationModel();
         if (!sim) {
-            Error("HitsToSDigits",
-                  "The simulation class was not instanciated!");
+            Error("HitsToSDigits","The simulation class was not "
+                  "instanciated for module %d type %s!",module,
+                  geom->GetModuleTypeName(module));
             exit(1);
         } // end if !sim
         mod      = (AliITSmodule *)fITSmodules->At(module);
@@ -1143,7 +1198,7 @@ void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
 }
 //______________________________________________________________________
 void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
-                          Option_t *option, Option_t *opt,Text_t *filename){
+                          Option_t *option, Option_t *opt, const char *filename){
     //   Keep galice.root for signal and name differently the file for 
     // background when add! otherwise the track info for signal will be lost !
     // the condition below will disappear when the geom class will be
@@ -1186,8 +1241,9 @@ void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
         iDetType = DetType(id);
         sim      = (AliITSsimulation*)iDetType->GetSimulationModel();
         if (!sim) {
-            Error("HitsToDigits",
-                  "The simulation class was not instanciated!");
+            Error("HitsToDigits","The simulation class was not "
+                  "instanciated for module %d type %s!",module,
+                  geom->GetModuleTypeName(module));
             exit(1);
         } // end if !sim
         mod      = (AliITSmodule *)fITSmodules->At(module);
@@ -1299,39 +1355,81 @@ void AliITS::AddSimDigit(Int_t id, AliITSdigit *d){
 //______________________________________________________________________
 void AliITS::AddSimDigit(Int_t id,Float_t phys,Int_t *digits,Int_t *tracks,
                          Int_t *hits,Float_t *charges){
-    //   Add a simulated digit to the list.
-    // Inputs:
-    //      Int_t id        Detector type number.
-    //      Float_t phys    Physics indicator. See AliITSdigits.h
-    //      Int_t *digits   Integer array containing the digits info. See 
-    //                      AliITSdigit.h
-    //      Int_t *tracks   Integer array [AliITSdigitS?D::GetNTracks()] 
-    //                      containing the track numbers that contributed to
-    //                      this digit.
-    //      Int_t *hits     Integer array [AliITSdigitS?D::GetNTracks()]
-    //                      containing the hit numbers, from AliITSmodule, that
-    //                      contributed to this digit.
-    //      Float_t *charge Floating point array of the signals contributed
-    //                      to this digit by each track.
-    // Outputs:
-    //      none.
-    // Return:
-    //      none.
+  //   Add a simulated digit to the list.
+  // Inputs:
+  //      Int_t id        Detector type number.
+  //      Float_t phys    Physics indicator. See AliITSdigits.h
+  //      Int_t *digits   Integer array containing the digits info. See 
+  //                      AliITSdigit.h
+  //      Int_t *tracks   Integer array [AliITSdigitS?D::GetNTracks()] 
+  //                      containing the track numbers that contributed to
+  //                      this digit.
+  //      Int_t *hits     Integer array [AliITSdigitS?D::GetNTracks()]
+  //                      containing the hit numbers, from AliITSmodule, that
+  //                      contributed to this digit.
+  //      Float_t *charge Floating point array of the signals contributed
+  //                      to this digit by each track.
+  // Outputs:
+  //      none.
+  // Return:
+  //      none.
 
-    TClonesArray &ldigits = *((TClonesArray*)fDtype->At(id));
-    switch(id){
-    case 0:
-        new(ldigits[fNdtype[id]++]) AliITSdigitSPD(digits,tracks,hits);
-        break;
-    case 1:
-        new(ldigits[fNdtype[id]++]) AliITSdigitSDD(phys,digits,tracks,
-                                                   hits,charges);
-        break;
-    case 2:
-        new(ldigits[fNdtype[id]++]) AliITSdigitSSD(digits,tracks,hits);
-        break;
-    } // end switch id
+  TClonesArray &ldigits = *((TClonesArray*)fDtype->At(id));
+  AliITSresponseSDD *resp = 0;
+  switch(id){
+  case 0:
+    new(ldigits[fNdtype[id]++]) AliITSdigitSPD(digits,tracks,hits);
+    break;
+  case 1:
+    resp = (AliITSresponseSDD*)DetType(1)->GetResponseModel();
+    new(ldigits[fNdtype[id]++]) AliITSdigitSDD(phys,digits,tracks,
+                                              hits,charges,resp);
+    break;
+  case 2:
+    new(ldigits[fNdtype[id]++]) AliITSdigitSSD(digits,tracks,hits);
+    break;
+  } // end switch id
 }
+
+//______________________________________________________________________
+void AliITS::Digits2Raw()
+{
+// convert digits of the current event to raw data
+
+  fLoader->LoadDigits();
+  TTree* digits = fLoader->TreeD();
+  if (!digits) {
+    Error("Digits2Raw", "no digits tree");
+    return;
+  }
+  SetTreeAddressD(digits);
+
+  AliITSDDLRawData rawWriter;
+  //Verbose level
+  // 0: Silent
+  // 1: cout messages
+  // 2: txt files with digits 
+  //BE CAREFUL, verbose level 2 MUST be used only for debugging and
+  //it is highly suggested to use this mode only for debugging digits files
+  //reasonably small, because otherwise the size of the txt files can reach
+  //quickly several MB wasting time and disk space.
+  rawWriter.SetVerbose(0);
+    
+  //SILICON PIXEL DETECTOR
+  Info("Digits2Raw", "Formatting raw data for SPD");
+  rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"));
+    
+  //SILICON DRIFT DETECTOR
+  Info("Digits2Raw", "Formatting raw data for SDD");
+  rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"));
+    
+  //SILICON STRIP DETECTOR
+  Info("Digits2Raw", "Formatting raw data for SSD");
+  rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
+
+  fLoader->UnloadDigits();
+}
+
 //______________________________________________________________________
 void AliITS::MakeTreeC(Option_t *option){
   //   Create a separate tree to store the clusters.
@@ -1570,7 +1668,7 @@ void AliITS::AddRecPoint(const AliITSRecPoint &r){
 }
 //______________________________________________________________________
 void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
-                                  Option_t *opt0,Option_t *opt1,Text_t *flnm){
+                                  Option_t *opt0,Option_t *opt1, const char *flnm){
     // keep galice.root for signal and name differently the file for 
     // background when add! otherwise the track info for signal will be lost !
     // the condition below will disappear when the geom class will be
@@ -1610,15 +1708,16 @@ void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
     
     cout<<"HitsToFastRecPoints: N mod = "<<geom->GetIndexMax()<<endl;
     
-    for(module=0;module<geom->GetIndexMax();module++)
-     {
+    for(module=0;module<geom->GetIndexMax();module++){
         id       = geom->GetModuleType(module);
         if (!all && !det[id]) continue;
         iDetType = DetType(id);
         sim      = (AliITSsimulation*)iDetType->GetSimulationModel();
         if (!sim) 
          {
-           Error("HitsToFastPoints","The simulation class was not instanciated!");
+           Error("HitsToFastPoints","The simulation class was not "
+                 "instanciated for module %d type %x!",module,
+                 geom->GetModuleTypeName(module));
            exit(1);
          } // end if !sim
         mod      = (AliITSmodule *)fITSmodules->At(module);
@@ -1736,3 +1835,110 @@ AliLoader* AliITS::MakeLoader(const char* topfoldername)
 }
 
 
+//_____________________________________________________________________________
+void AliITS::Reconstruct() const
+{
+// reconstruct clusters
+
+  AliLoader* loader = GetLoader();
+  loader->LoadRecPoints("recreate");
+  loader->LoadDigits("read");
+
+  AliITSclustererV2 clusterer(GetITSgeom());
+  AliRunLoader* runLoader = loader->GetRunLoader();
+  Int_t nEvents = runLoader->GetNumberOfEvents();
+  runLoader->LoadKinematics();
+
+  for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
+    runLoader->GetEvent(iEvent);
+
+    TTree* treeClusters = loader->TreeR();
+    if (!treeClusters) {
+      loader->MakeTree("R");
+      treeClusters = loader->TreeR();
+    }
+    TTree* treeDigits = loader->TreeD();
+    if (!treeDigits) {
+      Error("Reconstruct", "Can't get digits tree !");
+      return;
+    }
+
+    clusterer.Digits2Clusters(treeDigits, treeClusters);
+         
+    loader->WriteRecPoints("OVERWRITE");
+  }
+
+  loader->UnloadRecPoints();
+  loader->UnloadDigits();
+}
+
+//_____________________________________________________________________________
+AliTracker* AliITS::CreateTracker() const
+{
+// create an ITS tracker
+
+  return new AliITStrackerSA(GetITSgeom());
+}
+//_____________________________________________________________________________
+AliVertexer* AliITS::CreateVertexer() const
+{
+  // create a ITS vertexer
+
+  if(fSelectedVertexer.Contains("ions") || fSelectedVertexer.Contains("IONS")){
+    Info("CreateVertexer","a AliITSVertexerIons object has been selected\n");
+    return new AliITSVertexerIons("null");
+  }
+  if(fSelectedVertexer.Contains("smear") || fSelectedVertexer.Contains("SMEAR")){
+    Double_t smear[3]={0.005,0.005,0.01};
+    Info("CreateVertexer","a AliITSVertexerFast object has been selected\n"); 
+    return new AliITSVertexerFast(smear);
+  }
+  if(fSelectedVertexer.Contains("ppz") || fSelectedVertexer.Contains("PPZ")){
+    Info("CreateVertexer","a AliITSVertexerPPZ object has been selected\n");
+    return new AliITSVertexerPPZ("null");
+  }
+  // by default an AliITSVertexerZ object is instatiated
+  Info("CreateVertexer","a AliITSVertexerZ object has been selected\n");
+  return new AliITSVertexerZ("null");
+}
+
+//_____________________________________________________________________________
+void AliITS::FillESD(AliESD* esd) const
+{
+// make PID, find V0s and cascades
+
+  Double_t parITS[] = {34., 0.15, 10.};
+  AliITSpidESD itsPID(parITS);
+  itsPID.MakePID(esd);
+
+  // V0 finding
+  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 
+                  0.08,// max. allowed DCA between the daughter tracks
+                  0.99,// max. allowed cosine of V0's pointing angle
+                  0.9,  // min. radius of the fiducial volume
+                  2.9   // max. radius of the fiducial volume
+  };
+  AliV0vertexer vtxer(cuts);
+  Double_t vtx[3], cvtx[6];
+  esd->GetVertex()->GetXYZ(vtx);
+  esd->GetVertex()->GetSigmaXYZ(cvtx);
+  vtxer.SetVertex(vtx);
+  vtxer.Tracks2V0vertices(esd);
+
+  // cascade finding
+  Double_t cts[]={33.,    // max. allowed chi2
+                 0.05,   // min. allowed V0 impact parameter 
+                 0.008,  // window around the Lambda mass 
+                 0.035,  // min. allowed bachelor's impact parameter 
+                 0.10,   // max. allowed DCA between a V0 and a track
+                 0.9985, //max. allowed cosine of the cascade pointing angle
+                 0.9,    // min. radius of the fiducial volume
+                 2.9     // max. radius of the fiducial volume
+  };
+  AliCascadeVertexer cvtxer=AliCascadeVertexer(cts);
+  cvtxer.SetVertex(vtx);
+  cvtxer.V0sTracks2CascadeVertices(esd);
+}
+