]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDv1.cxx
updates requested by HLT
[u/mrichter/AliRoot.git] / TRD / AliTRDv1.cxx
index aeed814aa500e04ede46731b57c70dad438fbd44..fcfa91679c88a2186c3ea9fddb7278c9fd71c85a 100644 (file)
-///////////////////////////////////////////////////////////////////////////////
-//                                                                           //
-//  Transition Radiation Detector version 1 -- coarse simulation             //
-//  This version has two detector arms, leaving the space in front of the    //
-//  HMPID and PHOS empty                                                     //
-//                                                                           //
-//Begin_Html
-/*
-<img src="picts/AliTRDv1Class.gif">
-*/
-//End_Html
-//                                                                           //
-//                                                                           //
-///////////////////////////////////////////////////////////////////////////////
-
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/* $Id$ */
+
+////////////////////////////////////////////////////////////////////////////
+//                                                                        //
+//  Transition Radiation Detector version 1 -- slow simulator             //
+//                                                                        //
+////////////////////////////////////////////////////////////////////////////
+
+#include <TLorentzVector.h>
 #include <TMath.h>
 #include <TRandom.h>
-#include <TVector.h>
+#include <TVirtualMC.h>
+#include <TGeoManager.h>
+#include <TGeoMatrix.h>
+#include <TGeoPhysicalNode.h>
 
-#include "AliTRDv1.h"
-#include "AliRun.h"
+#include "AliTrackReference.h"
 #include "AliMC.h"
-#include "AliConst.h"
+#include "AliRun.h"
+#include "AliGeomManager.h"
+
+#include "AliTRDgeometry.h"
+#include "AliTRDCommonParam.h"
+#include "AliTRDsimTR.h"
+#include "AliTRDv1.h"
+
 ClassImp(AliTRDv1)
+//_____________________________________________________________________________
+AliTRDv1::AliTRDv1()
+  :AliTRD()
+  ,fTRon(kFALSE)
+  ,fTR(NULL)
+  ,fStepSize(0)
+  ,fWion(0)
+{
+  //
+  // Default constructor
+  //
+
+}
 
 //_____________________________________________________________________________
 AliTRDv1::AliTRDv1(const char *name, const char *title) 
-         :AliTRD(name, title) 
+  :AliTRD(name,title) 
+  ,fTRon(kTRUE)
+  ,fTR(NULL)
+  ,fStepSize(0.1)
+  ,fWion(0)
 {
   //
-  // Standard constructor for the Transition Radiation Detector version 1
+  // Standard constructor for Transition Radiation Detector version 1
   //
 
-  fIdSens     = 0;
-  fHitsOn     = 0;
+  SetBufferSize(128000);
+
+  if      (AliTRDCommonParam::Instance()->IsXenon()) {
+    fWion = 23.53; // Ionization energy XeCO2 (85/15)
+  }
+  else if (AliTRDCommonParam::Instance()->IsArgon()) {
+    fWion = 27.21; // Ionization energy ArCO2 (82/18)
+  }
+  else {
+    AliFatal("Wrong gas mixture");
+    exit(1);
+  }
+
+}
 
-  fIdSpace1   = 0;
-  fIdSpace2   = 0;
-  fIdSpace3   = 0;
+//_____________________________________________________________________________
+AliTRDv1::~AliTRDv1()
+{
+  //
+  // AliTRDv1 destructor
+  //
 
-  fIdChamber1 = 0;
-  fIdChamber2 = 0;
-  fIdChamber3 = 0;
+  if (fTR) {
+    delete fTR;
+    fTR     = 0;
+  }
 
 }
  
 //_____________________________________________________________________________
-void AliTRDv1::CreateGeometry()
+void AliTRDv1::AddAlignableVolumes() const
 {
   //
-  // Create the GEANT geometry for the Transition Radiation Detector - Version 1
-  // This version covers only part of the azimuth. 
+  // Create entries for alignable volumes associating the symbolic volume
+  // name with the corresponding volume path. Needs to be syncronized with
+  // eventual changes in the geometry.
+  //
+
+  TString volPath;
+  TString symName;
+
+  TString vpStr   = "ALIC_1/B077_1/BSEGMO";
+  TString vpApp1  = "_1/BTRD";
+  TString vpApp2  = "_1";
+  TString vpApp3a = "/UTR1_1/UTS1_1/UTI1_1/UT";
+  TString vpApp3b = "/UTR2_1/UTS2_1/UTI2_1/UT";
+  TString vpApp3c = "/UTR3_1/UTS3_1/UTI3_1/UT";
+
+  TString snStr   = "TRD/sm";
+  TString snApp1  = "/st";
+  TString snApp2  = "/pl";
+
+  //
+  // The super modules
+  // The symbolic names are: TRD/sm00
+  //                           ...
+  //                         TRD/sm17
+  //
+  for (Int_t isector = 0; isector < AliTRDgeometry::Nsector(); isector++) {
+
+    volPath  = vpStr;
+    volPath += isector;
+    volPath += vpApp1;
+    volPath += isector;
+    volPath += vpApp2;
+
+    symName  = snStr;
+    symName += Form("%02d",isector);
+
+    gGeoManager->SetAlignableEntry(symName.Data(),volPath.Data());
+
+  }
+
   //
-  // Author:  Christoph Blume (C.Blume@gsi.de) 20/07/99 
+  // The readout chambers
+  // The symbolic names are: TRD/sm00/st0/pl0
+  //                           ...
+  //                         TRD/sm17/st4/pl5
   //
+  AliGeomManager::ELayerID idTRD1 = AliGeomManager::kTRD1;
+  Int_t layer, modUID;
+  
+  for (Int_t isector = 0; isector < AliTRDgeometry::Nsector(); isector++) {
+
+    if (fGeometry->GetSMstatus(isector) == 0) continue;
+
+    for (Int_t istack = 0; istack < AliTRDgeometry::Nstack(); istack++) {
+      for (Int_t ilayer = 0; ilayer < AliTRDgeometry::Nlayer(); ilayer++) {
+
+       layer = idTRD1 + ilayer;
+       modUID = AliGeomManager::LayerToVolUIDSafe(layer,isector*5+istack);
+
+        Int_t idet = AliTRDgeometry::GetDetectorSec(ilayer,istack);
+
+        volPath  = vpStr;
+        volPath += isector;
+        volPath += vpApp1;
+        volPath += isector;
+        volPath += vpApp2;
+        switch (isector) {
+        case 13:
+        case 14:
+        case 15:
+          if (istack == 2) {
+            continue;
+         }
+          volPath += vpApp3c;
+          break;
+        case 11:
+        case 12:
+          volPath += vpApp3b;
+          break;
+        default:
+          volPath += vpApp3a;
+       };
+        volPath += Form("%02d",idet);
+        volPath += vpApp2;
+
+        symName  = snStr;
+        symName += Form("%02d",isector);
+        symName += snApp1;
+        symName += istack;
+        symName += snApp2;
+        symName += ilayer;
+
+        TGeoPNEntry *alignableEntry = 
+         gGeoManager->SetAlignableEntry(symName.Data(),volPath.Data(),modUID);
+
+       // Add the tracking to local matrix following the TPC example
+       if (alignableEntry) {
+         TGeoHMatrix *globMatrix = alignableEntry->GetGlobalOrig();
+         Double_t sectorAngle = 20.0 * (isector % 18) + 10.0;
+         TGeoHMatrix *t2lMatrix  = new TGeoHMatrix();
+         t2lMatrix->RotateZ(sectorAngle);
+         t2lMatrix->MultiplyLeft(&(globMatrix->Inverse()));
+         alignableEntry->SetMatrix(t2lMatrix);
+       }
+       else {
+         AliError(Form("Alignable entry %s is not valid!",symName.Data()));
+       }
+
+      }
+    }
+  }
 
-  Float_t xpos, ypos, zpos;
+}
+
+//_____________________________________________________________________________
+void AliTRDv1::CreateGeometry()
+{
+  //
+  // Create the GEANT geometry for the Transition Radiation Detector - Version 1
+  // This version covers the full azimuth. 
+  //
 
   // Check that FRAME is there otherwise we have no place where to put the TRD
-  AliModule* FRAME = gAlice->GetModule("FRAME");
-  if (!FRAME) return;
+  AliModule* frame = gAlice->GetModule("FRAME");
+  if (!frame) {
+    AliError("TRD needs FRAME to be present\n");
+    return;
+  }
 
   // Define the chambers
   AliTRD::CreateGeometry();
 
-  // Position the the TRD-sectors only in one TRD-volume in the spaceframe
-  xpos     = 0.;
-  ypos     = 0.;
-  zpos     = 0.;
-  gMC->Gspos("TRD ",1,"BTR1",xpos,ypos,zpos,0,"ONLY");
-
 }
 
 //_____________________________________________________________________________
@@ -83,103 +245,272 @@ void AliTRDv1::CreateMaterials()
 
 }
 
+//_____________________________________________________________________________
+void AliTRDv1::CreateTRhit(Int_t det)
+{
+  //
+  // Creates an electron cluster from a TR photon.
+  // The photon is assumed to be created a the end of the radiator. The 
+  // distance after which it deposits its energy takes into account the 
+  // absorbtion of the entrance window and of the gas mixture in drift
+  // volume.
+  //
+
+  // Maximum number of TR photons per track
+  const Int_t   kNTR         = 50;
+
+  TLorentzVector mom;
+  TLorentzVector pos;
+
+  Float_t eTR[kNTR];
+  Int_t   nTR;
+
+  // Create TR photons
+  gMC->TrackMomentum(mom);
+  Float_t pTot = mom.Rho();
+  fTR->CreatePhotons(11,pTot,nTR,eTR);
+  if (nTR > kNTR) {
+    AliFatal(Form("Boundary error: nTR = %d, kNTR = %d",nTR,kNTR));
+  }
+
+  // Loop through the TR photons
+  for (Int_t iTR = 0; iTR < nTR; iTR++) {
+
+    Float_t energyMeV = eTR[iTR] * 0.001;
+    Float_t energyeV  = eTR[iTR] * 1000.0;
+    Float_t absLength = 0.0;
+    Float_t sigma     = 0.0;
+
+    // Take the absorbtion in the entrance window into account
+    Double_t muMy = fTR->GetMuMy(energyMeV);
+    sigma         = muMy * fFoilDensity;
+    if (sigma > 0.0) {
+      absLength = gRandom->Exp(1.0/sigma);
+      if (absLength < AliTRDgeometry::MyThick()) {
+        continue;
+      }
+    }
+    else {
+      continue;
+    }
+
+    // The absorbtion cross sections in the drift gas
+    // Gas-mixture (Xe/CO2)
+    Double_t muNo = 0.0;
+    if      (AliTRDCommonParam::Instance()->IsXenon()) {
+      muNo = fTR->GetMuXe(energyMeV);
+    }
+    else if (AliTRDCommonParam::Instance()->IsArgon()) {
+      muNo = fTR->GetMuAr(energyMeV);
+    }
+    Double_t muCO = fTR->GetMuCO(energyMeV);
+    sigma = (fGasNobleFraction * muNo + (1.0 - fGasNobleFraction) * muCO) 
+          * fGasDensity 
+          * fTR->GetTemp();
+
+    // The distance after which the energy of the TR photon
+    // is deposited.
+    if (sigma > 0.0) {
+      absLength = gRandom->Exp(1.0/sigma);
+      if (absLength > (AliTRDgeometry::DrThick()
+                     + AliTRDgeometry::AmThick())) {
+        continue;
+      }
+    }
+    else {
+      continue;
+    }
+
+    // The position of the absorbtion
+    Float_t posHit[3];
+    gMC->TrackPosition(pos);
+    posHit[0] = pos[0] + mom[0] / pTot * absLength;
+    posHit[1] = pos[1] + mom[1] / pTot * absLength;
+    posHit[2] = pos[2] + mom[2] / pTot * absLength;
+
+    // Create the charge 
+    Int_t q = ((Int_t) (energyeV / fWion));
+
+    // Add the hit to the array. TR photon hits are marked 
+    // by negative charge
+    AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber()
+          ,det
+          ,posHit
+          ,-q
+          ,gMC->TrackTime()*1.0e06
+          ,kTRUE);
+
+  }
+
+}
+
 //_____________________________________________________________________________
 void AliTRDv1::Init() 
 {
   //
-  // Initialise the Transition Radiation Detector after the geometry is built
+  // Initialise Transition Radiation Detector after geometry has been built.
   //
 
   AliTRD::Init();
 
-  for (Int_t i = 0; i < 80; i++) printf("*");
-  printf("\n");
-  
-  // Identifier of the sensitive volume (amplification region)
-  fIdSens     = gMC->VolId("UL06");
+  AliDebug(1,"Slow simulator\n");
 
-  // Identifier of the TRD-spaceframe volumina
-  fIdSpace1   = gMC->VolId("B028");
-  fIdSpace2   = gMC->VolId("B029");
-  fIdSpace3   = gMC->VolId("B030");
+  // Switch on TR simulation as default
+  if (!fTRon) {
+    AliInfo("TR simulation off");
+  }
+  else {
+    fTR = new AliTRDsimTR();
+  }
 
-  // Identifier of the TRD-driftchambers
-  fIdChamber1 = gMC->VolId("UCIO");
-  fIdChamber2 = gMC->VolId("UCIM");
-  fIdChamber3 = gMC->VolId("UCII");
+  AliDebug(1,"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
 
 }
 
 //_____________________________________________________________________________
-void AliTRDv1::StepManager() 
+void AliTRDv1::StepManager()
 {
   //
-  // Procedure called at every step in the TRD
-  // Fast simulator. If switched on, a hit is produced when a track
-  // crosses the border between amplification region and pad plane.
-  //
-
-  Int_t   vol[3]; 
-  Int_t   iIdSens, icSens; 
-  Int_t   iIdSpace, icSpace;
-  Int_t   iIdChamber, icChamber;
-
-  Int_t   secMap1[10] = {  3,  7,  8,  9, 10, 11,  2,  1, 18, 17 };
-  Int_t   secMap2[ 5] = { 16, 15, 14, 13, 12 };
-  Int_t   secMap3[ 3] = {  5,  6,  4 };
-
-  Float_t hits[4];
-
-  TLorentzVector p;
-  TClonesArray  &lhits = *fHits;
-
-  // Writing out hits enabled?
-  if (!(fHitsOn)) return;
-
-  // Use only charged tracks and count them only once per volume
-  if (gMC->TrackCharge()    && 
-      gMC->IsTrackExiting()) {
-    
-    // Check on sensitive volume
-    iIdSens = gMC->CurrentVolID(icSens);
-    if (iIdSens == fIdSens) { 
-
-      gMC->TrackPosition(p);
-      for (Int_t i = 0; i < 3; i++) hits[i] = p[i];
-      // No charge created
-      hits[3] = 0;
-
-      iIdSpace   = gMC->CurrentVolOffID(4,icSpace  );
-      iIdChamber = gMC->CurrentVolOffID(1,icChamber);
-
-      // The sector number
-      if      (iIdSpace == fIdSpace1) 
-        vol[0] = secMap1[icSpace-1];
-      else if (iIdSpace == fIdSpace2) 
-        vol[0] = secMap2[icSpace-1];
-      else if (iIdSpace == fIdSpace3) 
-        vol[0] = secMap3[icSpace-1];
-
-      // The chamber number 
-      //   1: outer left
-      //   2: middle left
-      //   3: inner
-      //   4: middle right
-      //   5: outer right
-      if      (iIdChamber == fIdChamber1)
-        vol[1] = (hits[2] < 0 ? 1 : 5);
-      else if (iIdChamber == fIdChamber2)       
-        vol[1] = (hits[2] < 0 ? 2 : 4);
-      else if (iIdChamber == fIdChamber3)       
-        vol[1] = 3;
-
-      // The plane number
-      vol[2] = icChamber - TMath::Nint((Float_t) (icChamber / 7)) * 6;
-
-      new(lhits[fNhits++]) AliTRDhit(fIshunt,gAlice->CurrentTrack(),vol,hits);
+  // Slow simulator. Every charged track produces electron cluster as hits 
+  // along its path across the drift volume. The step size is fixed in
+  // this version of the step manager.
+  //
+  // Works for Xe/CO2 as well as Ar/CO2
+  //
 
+  // PDG code electron
+  const Int_t   kPdgElectron = 11;
+
+  Int_t    layer  = 0;
+  Int_t    stack  = 0;
+  Int_t    sector = 0;
+  Int_t    det    = 0;
+  Int_t    qTot;
+
+  Float_t  hits[3];
+  Double_t eDep;
+
+  Bool_t   drRegion = kFALSE;
+  Bool_t   amRegion = kFALSE;
+
+  TString  cIdPath;
+  Char_t   cIdSector[3];
+           cIdSector[2]  = 0;
+
+  TString  cIdCurrent;
+  TString  cIdSensDr = "J";
+  TString  cIdSensAm = "K";
+  Char_t   cIdChamber[3];
+           cIdChamber[2] = 0;
+
+  TLorentzVector pos;
+  TLorentzVector mom;
+
+  const Int_t    kNlayer      = AliTRDgeometry::Nlayer();
+  const Int_t    kNstack      = AliTRDgeometry::Nstack();
+  const Int_t    kNdetsec     = kNlayer * kNstack;
+
+  const Double_t kBig         = 1.0e+12;
+  const Float_t  kEkinMinStep = 1.0e-5;  // Minimum energy for the step size adjustment
+
+  // Set the maximum step size to a very large number for all 
+  // neutral particles and those outside the driftvolume
+  gMC->SetMaxStep(kBig); 
+
+  // If not charged track or already stopped or disappeared, just return.
+  if ((!gMC->TrackCharge()) || 
+        gMC->IsTrackDisappeared()) {
+    return;
+  }
+
+  // Inside a sensitive volume?
+  cIdCurrent = gMC->CurrentVolName();
+
+  if (cIdSensDr == cIdCurrent[1]) {
+    drRegion = kTRUE;
+  }
+  if (cIdSensAm == cIdCurrent[1]) {
+    amRegion = kTRUE;
+  }
+
+  if ((!drRegion) && 
+      (!amRegion)) {
+    return;
+  }
+
+  // The hit coordinates and charge
+  gMC->TrackPosition(pos);
+  hits[0] = pos[0];
+  hits[1] = pos[1];
+  hits[2] = pos[2];
+
+  // The sector number (0 - 17), according to standard coordinate system
+  cIdPath      = gGeoManager->GetPath();
+  cIdSector[0] = cIdPath[21];
+  cIdSector[1] = cIdPath[22];
+  sector = atoi(cIdSector);
+
+  // The plane and chamber number
+  cIdChamber[0]   = cIdCurrent[2];
+  cIdChamber[1]   = cIdCurrent[3];
+  Int_t idChamber = (atoi(cIdChamber) % kNdetsec);
+  stack = ((Int_t) idChamber / kNlayer);
+  layer = ((Int_t) idChamber % kNlayer);
+
+  // The detector number
+  det = fGeometry->GetDetector(layer,stack,sector);
+
+  // 0: InFlight 1:Entering 2:Exiting
+  Int_t trkStat = 0;
+
+  // Special hits only in the drift region
+  if      ((drRegion) &&
+           (gMC->IsTrackEntering())) {
+
+    // Create a track reference at the entrance of each
+    // chamber that contains the momentum components of the particle
+    gMC->TrackMomentum(mom);
+    AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber(), AliTrackReference::kTRD);
+    trkStat = 1;
+
+    // Create the hits from TR photons if electron/positron is
+    // entering the drift volume
+    if ((fTR) && 
+        (TMath::Abs(gMC->TrackPid()) == kPdgElectron)) {
+      CreateTRhit(det);
     }
 
-  }  
+  }
+  else if ((amRegion) && 
+           (gMC->IsTrackExiting())) {
+
+    // Create a track reference at the exit of each
+    // chamber that contains the momentum components of the particle
+    gMC->TrackMomentum(mom);
+    AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber(), AliTrackReference::kTRD);
+    trkStat = 2;
+
+  }
+  
+  // Calculate the charge according to GEANT Edep
+  // Create a new dEdx hit
+  eDep = TMath::Max(gMC->Edep(),0.0) * 1.0e+09;
+  qTot = (Int_t) (eDep / fWion);
+  if ((qTot) ||
+      (trkStat)) {
+    AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber()
+          ,det
+          ,hits
+          ,qTot
+          ,gMC->TrackTime()*1.0e06
+          ,drRegion);
+  }
+
+  // Set Maximum Step Size
+  // Produce only one hit if Ekin is below cutoff
+  if ((gMC->Etot() - gMC->TrackMass()) < kEkinMinStep) {
+    return;
+  }
+  gMC->SetMaxStep(fStepSize);
 
 }