]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDv1.cxx
added libraries to AddTask in order to include flow package
[u/mrichter/AliRoot.git] / TRD / AliTRDv1.cxx
CommitLineData
4c039060 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
88cb7938 16/* $Id$ */
4c039060 17
030b4415 18////////////////////////////////////////////////////////////////////////////
19// //
20// Transition Radiation Detector version 1 -- slow simulator //
21// //
22////////////////////////////////////////////////////////////////////////////
fe4da5cc 23
1819f4bb 24#include <TLorentzVector.h>
88cb7938 25#include <TMath.h>
26#include <TRandom.h>
88cb7938 27#include <TVirtualMC.h>
f57bb418 28#include <TGeoManager.h>
268f57b1 29#include <TGeoMatrix.h>
170c35f1 30#include <TGeoPhysicalNode.h>
fe4da5cc 31
e6add757 32#include "AliTrackReference.h"
45160b1f 33#include "AliMC.h"
88cb7938 34#include "AliRun.h"
02cb65d6 35#include "AliGeomManager.h"
030b4415 36
88cb7938 37#include "AliTRDgeometry.h"
a076fc2f 38#include "AliTRDCommonParam.h"
cb2f9e9b 39#include "AliTRDsimTR.h"
88cb7938 40#include "AliTRDv1.h"
851d3db9 41
fe4da5cc 42ClassImp(AliTRDv1)
8230f242 43
44//_____________________________________________________________________________
030b4415 45AliTRDv1::AliTRDv1()
46 :AliTRD()
1315812e 47 ,fTRon(kTRUE)
030b4415 48 ,fTR(NULL)
030b4415 49 ,fStepSize(0)
f2979d08 50 ,fWion(0)
8230f242 51{
52 //
53 // Default constructor
54 //
55
8230f242 56}
57
fe4da5cc 58//_____________________________________________________________________________
59AliTRDv1::AliTRDv1(const char *name, const char *title)
030b4415 60 :AliTRD(name,title)
61 ,fTRon(kTRUE)
62 ,fTR(NULL)
030b4415 63 ,fStepSize(0.1)
f2979d08 64 ,fWion(0)
fe4da5cc 65{
66 //
851d3db9 67 // Standard constructor for Transition Radiation Detector version 1
fe4da5cc 68 //
82bbf98a 69
5c7f4665 70 SetBufferSize(128000);
71
a076fc2f 72 if (AliTRDCommonParam::Instance()->IsXenon()) {
f2979d08 73 fWion = 23.53; // Ionization energy XeCO2 (85/15)
74 }
a076fc2f 75 else if (AliTRDCommonParam::Instance()->IsArgon()) {
f2979d08 76 fWion = 27.21; // Ionization energy ArCO2 (82/18)
77 }
78 else {
79 AliFatal("Wrong gas mixture");
80 exit(1);
81 }
82
5c7f4665 83}
84
85//_____________________________________________________________________________
86AliTRDv1::~AliTRDv1()
87{
dd9a6ee3 88 //
89 // AliTRDv1 destructor
90 //
82bbf98a 91
030b4415 92 if (fTR) {
93 delete fTR;
94 fTR = 0;
95 }
82bbf98a 96
fe4da5cc 97}
98
f57bb418 99//_____________________________________________________________________________
100void AliTRDv1::AddAlignableVolumes() const
101{
102 //
103 // Create entries for alignable volumes associating the symbolic volume
104 // name with the corresponding volume path. Needs to be syncronized with
105 // eventual changes in the geometry.
106 //
107
108 TString volPath;
109 TString symName;
110
92cd97ad 111 TString vpStr = "ALIC_1/B077_1/BSEGMO";
112 TString vpApp1 = "_1/BTRD";
113 TString vpApp2 = "_1";
114 TString vpApp3a = "/UTR1_1/UTS1_1/UTI1_1/UT";
115 TString vpApp3b = "/UTR2_1/UTS2_1/UTI2_1/UT";
116 TString vpApp3c = "/UTR3_1/UTS3_1/UTI3_1/UT";
2c595ef5 117 TString vpApp3d = "/UTR4_1/UTS4_1/UTI4_1/UT";
f57bb418 118
92cd97ad 119 TString snStr = "TRD/sm";
120 TString snApp1 = "/st";
121 TString snApp2 = "/pl";
f57bb418 122
123 //
124 // The super modules
125 // The symbolic names are: TRD/sm00
126 // ...
127 // TRD/sm17
128 //
053767a4 129 for (Int_t isector = 0; isector < AliTRDgeometry::Nsector(); isector++) {
f57bb418 130
131 volPath = vpStr;
053767a4 132 volPath += isector;
f57bb418 133 volPath += vpApp1;
053767a4 134 volPath += isector;
f57bb418 135 volPath += vpApp2;
136
137 symName = snStr;
053767a4 138 symName += Form("%02d",isector);
f57bb418 139
140 gGeoManager->SetAlignableEntry(symName.Data(),volPath.Data());
141
142 }
143
144 //
145 // The readout chambers
146 // The symbolic names are: TRD/sm00/st0/pl0
147 // ...
148 // TRD/sm17/st4/pl5
149 //
02cb65d6 150 AliGeomManager::ELayerID idTRD1 = AliGeomManager::kTRD1;
151 Int_t layer, modUID;
152
053767a4 153 for (Int_t isector = 0; isector < AliTRDgeometry::Nsector(); isector++) {
8bf0cd64 154
053767a4 155 if (fGeometry->GetSMstatus(isector) == 0) continue;
8bf0cd64 156
053767a4 157 for (Int_t istack = 0; istack < AliTRDgeometry::Nstack(); istack++) {
158 for (Int_t ilayer = 0; ilayer < AliTRDgeometry::Nlayer(); ilayer++) {
f57bb418 159
053767a4 160 layer = idTRD1 + ilayer;
161 modUID = AliGeomManager::LayerToVolUIDSafe(layer,isector*5+istack);
162
163 Int_t idet = AliTRDgeometry::GetDetectorSec(ilayer,istack);
f57bb418 164
165 volPath = vpStr;
053767a4 166 volPath += isector;
f57bb418 167 volPath += vpApp1;
053767a4 168 volPath += isector;
f57bb418 169 volPath += vpApp2;
053767a4 170 switch (isector) {
2c595ef5 171 case 17:
172 if ((istack == 4) && (ilayer == 4)) {
173 continue;
174 }
175 volPath += vpApp3d;
176 break;
92cd97ad 177 case 13:
178 case 14:
179 case 15:
053767a4 180 if (istack == 2) {
92cd97ad 181 continue;
182 }
183 volPath += vpApp3c;
184 break;
185 case 11:
186 case 12:
187 volPath += vpApp3b;
188 break;
189 default:
190 volPath += vpApp3a;
191 };
f57bb418 192 volPath += Form("%02d",idet);
193 volPath += vpApp2;
194
195 symName = snStr;
053767a4 196 symName += Form("%02d",isector);
f57bb418 197 symName += snApp1;
053767a4 198 symName += istack;
f57bb418 199 symName += snApp2;
053767a4 200 symName += ilayer;
f57bb418 201
51a5f1d0 202 TGeoPNEntry *alignableEntry =
02cb65d6 203 gGeoManager->SetAlignableEntry(symName.Data(),volPath.Data(),modUID);
f57bb418 204
170c35f1 205 // Add the tracking to local matrix following the TPC example
51a5f1d0 206 if (alignableEntry) {
02cb65d6 207 TGeoHMatrix *globMatrix = alignableEntry->GetGlobalOrig();
053767a4 208 Double_t sectorAngle = 20.0 * (isector % 18) + 10.0;
51a5f1d0 209 TGeoHMatrix *t2lMatrix = new TGeoHMatrix();
210 t2lMatrix->RotateZ(sectorAngle);
211 t2lMatrix->MultiplyLeft(&(globMatrix->Inverse()));
212 alignableEntry->SetMatrix(t2lMatrix);
213 }
214 else {
215 AliError(Form("Alignable entry %s is not valid!",symName.Data()));
216 }
8bf0cd64 217
f57bb418 218 }
219 }
220 }
221
222}
223
fe4da5cc 224//_____________________________________________________________________________
225void AliTRDv1::CreateGeometry()
226{
227 //
851d3db9 228 // Create the GEANT geometry for the Transition Radiation Detector - Version 1
5c7f4665 229 // This version covers the full azimuth.
d3f347ff 230 //
231
82bbf98a 232 // Check that FRAME is there otherwise we have no place where to put the TRD
8230f242 233 AliModule* frame = gAlice->GetModule("FRAME");
030b4415 234 if (!frame) {
235 AliError("TRD needs FRAME to be present\n");
236 return;
237 }
d3f347ff 238
82bbf98a 239 // Define the chambers
240 AliTRD::CreateGeometry();
d3f347ff 241
fe4da5cc 242}
243
244//_____________________________________________________________________________
245void AliTRDv1::CreateMaterials()
246{
247 //
851d3db9 248 // Create materials for the Transition Radiation Detector version 1
fe4da5cc 249 //
82bbf98a 250
d3f347ff 251 AliTRD::CreateMaterials();
82bbf98a 252
fe4da5cc 253}
254
793ff80c 255//_____________________________________________________________________________
256void AliTRDv1::CreateTRhit(Int_t det)
257{
258 //
259 // Creates an electron cluster from a TR photon.
260 // The photon is assumed to be created a the end of the radiator. The
261 // distance after which it deposits its energy takes into account the
262 // absorbtion of the entrance window and of the gas mixture in drift
263 // volume.
264 //
265
793ff80c 266 // Maximum number of TR photons per track
267 const Int_t kNTR = 50;
268
030b4415 269 TLorentzVector mom;
270 TLorentzVector pos;
793ff80c 271
ce0d6231 272 Float_t eTR[kNTR];
273 Int_t nTR;
793ff80c 274
ce0d6231 275 // Create TR photons
2942f542 276 TVirtualMC::GetMC()->TrackMomentum(mom);
ce0d6231 277 Float_t pTot = mom.Rho();
278 fTR->CreatePhotons(11,pTot,nTR,eTR);
279 if (nTR > kNTR) {
280 AliFatal(Form("Boundary error: nTR = %d, kNTR = %d",nTR,kNTR));
281 }
f73816f5 282
ce0d6231 283 // Loop through the TR photons
284 for (Int_t iTR = 0; iTR < nTR; iTR++) {
793ff80c 285
ce0d6231 286 Float_t energyMeV = eTR[iTR] * 0.001;
287 Float_t energyeV = eTR[iTR] * 1000.0;
288 Float_t absLength = 0.0;
289 Float_t sigma = 0.0;
793ff80c 290
ce0d6231 291 // Take the absorbtion in the entrance window into account
292 Double_t muMy = fTR->GetMuMy(energyMeV);
293 sigma = muMy * fFoilDensity;
294 if (sigma > 0.0) {
295 absLength = gRandom->Exp(1.0/sigma);
296 if (absLength < AliTRDgeometry::MyThick()) {
842287f2 297 continue;
298 }
ce0d6231 299 }
300 else {
301 continue;
302 }
793ff80c 303
ce0d6231 304 // The absorbtion cross sections in the drift gas
305 // Gas-mixture (Xe/CO2)
f2979d08 306 Double_t muNo = 0.0;
a076fc2f 307 if (AliTRDCommonParam::Instance()->IsXenon()) {
f2979d08 308 muNo = fTR->GetMuXe(energyMeV);
309 }
a076fc2f 310 else if (AliTRDCommonParam::Instance()->IsArgon()) {
f2979d08 311 muNo = fTR->GetMuAr(energyMeV);
312 }
ce0d6231 313 Double_t muCO = fTR->GetMuCO(energyMeV);
f2979d08 314 sigma = (fGasNobleFraction * muNo + (1.0 - fGasNobleFraction) * muCO)
315 * fGasDensity
316 * fTR->GetTemp();
ce0d6231 317
318 // The distance after which the energy of the TR photon
319 // is deposited.
320 if (sigma > 0.0) {
321 absLength = gRandom->Exp(1.0/sigma);
322 if (absLength > (AliTRDgeometry::DrThick()
323 + AliTRDgeometry::AmThick())) {
842287f2 324 continue;
325 }
ce0d6231 326 }
327 else {
328 continue;
329 }
793ff80c 330
ce0d6231 331 // The position of the absorbtion
332 Float_t posHit[3];
2942f542 333 TVirtualMC::GetMC()->TrackPosition(pos);
ce0d6231 334 posHit[0] = pos[0] + mom[0] / pTot * absLength;
335 posHit[1] = pos[1] + mom[1] / pTot * absLength;
336 posHit[2] = pos[2] + mom[2] / pTot * absLength;
793ff80c 337
ce0d6231 338 // Create the charge
f2979d08 339 Int_t q = ((Int_t) (energyeV / fWion));
793ff80c 340
ce0d6231 341 // Add the hit to the array. TR photon hits are marked
342 // by negative charge
343 AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber()
344 ,det
345 ,posHit
346 ,-q
2942f542 347 ,TVirtualMC::GetMC()->TrackTime()*1.0e06
d4c6453d 348 ,kTRUE);
793ff80c 349
350 }
351
352}
353
5c7f4665 354//_____________________________________________________________________________
355void AliTRDv1::Init()
356{
357 //
358 // Initialise Transition Radiation Detector after geometry has been built.
5c7f4665 359 //
360
361 AliTRD::Init();
362
45160b1f 363 AliDebug(1,"Slow simulator\n");
bd0f8685 364
365 // Switch on TR simulation as default
366 if (!fTRon) {
45160b1f 367 AliInfo("TR simulation off");
bd0f8685 368 }
369 else {
cb2f9e9b 370 fTR = new AliTRDsimTR();
bd0f8685 371 }
5c7f4665 372
45160b1f 373 AliDebug(1,"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
5c7f4665 374
fe4da5cc 375}
376
5c7f4665 377//_____________________________________________________________________________
378void AliTRDv1::StepManager()
a328fff9 379{
380 //
381 // Slow simulator. Every charged track produces electron cluster as hits
382 // along its path across the drift volume. The step size is fixed in
383 // this version of the step manager.
384 //
f2979d08 385 // Works for Xe/CO2 as well as Ar/CO2
386 //
a328fff9 387
ce0d6231 388 // PDG code electron
389 const Int_t kPdgElectron = 11;
390
053767a4 391 Int_t layer = 0;
392 Int_t stack = 0;
393 Int_t sector = 0;
394 Int_t det = 0;
a328fff9 395 Int_t qTot;
396
397 Float_t hits[3];
398 Double_t eDep;
399
400 Bool_t drRegion = kFALSE;
401 Bool_t amRegion = kFALSE;
402
2c8bf4aa 403 TString cIdPath;
404 Char_t cIdSector[3];
405 cIdSector[2] = 0;
406
a328fff9 407 TString cIdCurrent;
408 TString cIdSensDr = "J";
409 TString cIdSensAm = "K";
410 Char_t cIdChamber[3];
2c8bf4aa 411 cIdChamber[2] = 0;
a328fff9 412
030b4415 413 TLorentzVector pos;
414 TLorentzVector mom;
a328fff9 415
053767a4 416 const Int_t kNlayer = AliTRDgeometry::Nlayer();
417 const Int_t kNstack = AliTRDgeometry::Nstack();
418 const Int_t kNdetsec = kNlayer * kNstack;
a328fff9 419
030b4415 420 const Double_t kBig = 1.0e+12;
a328fff9 421 const Float_t kEkinMinStep = 1.0e-5; // Minimum energy for the step size adjustment
422
423 // Set the maximum step size to a very large number for all
424 // neutral particles and those outside the driftvolume
2942f542 425 if (!fPrimaryIonisation) TVirtualMC::GetMC()->SetMaxStep(kBig);
a328fff9 426
427 // If not charged track or already stopped or disappeared, just return.
2942f542 428 if ((!TVirtualMC::GetMC()->TrackCharge()) ||
429 TVirtualMC::GetMC()->IsTrackDisappeared()) {
ce0d6231 430 return;
431 }
a328fff9 432
433 // Inside a sensitive volume?
2942f542 434 cIdCurrent = TVirtualMC::GetMC()->CurrentVolName();
a328fff9 435
ce0d6231 436 if (cIdSensDr == cIdCurrent[1]) {
437 drRegion = kTRUE;
438 }
439 if (cIdSensAm == cIdCurrent[1]) {
440 amRegion = kTRUE;
441 }
a328fff9 442
030b4415 443 if ((!drRegion) &&
444 (!amRegion)) {
445 return;
446 }
a328fff9 447
448 // The hit coordinates and charge
2942f542 449 TVirtualMC::GetMC()->TrackPosition(pos);
a328fff9 450 hits[0] = pos[0];
451 hits[1] = pos[1];
452 hits[2] = pos[2];
453
2c8bf4aa 454 // The sector number (0 - 17), according to standard coordinate system
455 cIdPath = gGeoManager->GetPath();
456 cIdSector[0] = cIdPath[21];
457 cIdSector[1] = cIdPath[22];
053767a4 458 sector = atoi(cIdSector);
a328fff9 459
460 // The plane and chamber number
030b4415 461 cIdChamber[0] = cIdCurrent[2];
462 cIdChamber[1] = cIdCurrent[3];
a328fff9 463 Int_t idChamber = (atoi(cIdChamber) % kNdetsec);
053767a4 464 stack = ((Int_t) idChamber / kNlayer);
465 layer = ((Int_t) idChamber % kNlayer);
e0d47c25 466
030b4415 467 // The detector number
053767a4 468 det = fGeometry->GetDetector(layer,stack,sector);
030b4415 469
25ca55ce 470 // 0: InFlight 1:Entering 2:Exiting
030b4415 471 Int_t trkStat = 0;
a328fff9 472
473 // Special hits only in the drift region
ce0d6231 474 if ((drRegion) &&
2942f542 475 (TVirtualMC::GetMC()->IsTrackEntering())) {
a328fff9 476
ce0d6231 477 // Create a track reference at the entrance of each
478 // chamber that contains the momentum components of the particle
2942f542 479 TVirtualMC::GetMC()->TrackMomentum(mom);
e6add757 480 AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber(), AliTrackReference::kTRD);
ce0d6231 481 trkStat = 1;
a328fff9 482
ce0d6231 483 // Create the hits from TR photons if electron/positron is
484 // entering the drift volume
1315812e 485 if ((fTR) &&
486 (fTRon) &&
2942f542 487 (TMath::Abs(TVirtualMC::GetMC()->TrackPid()) == kPdgElectron)) {
f2979d08 488 CreateTRhit(det);
030b4415 489 }
a328fff9 490
ce0d6231 491 }
492 else if ((amRegion) &&
2942f542 493 (TVirtualMC::GetMC()->IsTrackExiting())) {
ce0d6231 494
495 // Create a track reference at the exit of each
496 // chamber that contains the momentum components of the particle
2942f542 497 TVirtualMC::GetMC()->TrackMomentum(mom);
e6add757 498 AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber(), AliTrackReference::kTRD);
ce0d6231 499 trkStat = 2;
500
a328fff9 501 }
502
503 // Calculate the charge according to GEANT Edep
504 // Create a new dEdx hit
2942f542 505 eDep = TMath::Max(TVirtualMC::GetMC()->Edep(),0.0) * 1.0e+09;
f2979d08 506 qTot = (Int_t) (eDep / fWion);
ce0d6231 507 if ((qTot) ||
508 (trkStat)) {
509 AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber()
510 ,det
511 ,hits
512 ,qTot
2942f542 513 ,TVirtualMC::GetMC()->TrackTime()*1.0e06
ce0d6231 514 ,drRegion);
515 }
a328fff9 516
517 // Set Maximum Step Size
518 // Produce only one hit if Ekin is below cutoff
2942f542 519 if ((TVirtualMC::GetMC()->Etot() - TVirtualMC::GetMC()->TrackMass()) < kEkinMinStep) {
030b4415 520 return;
521 }
2942f542 522 if (!fPrimaryIonisation) TVirtualMC::GetMC()->SetMaxStep(fStepSize);
a328fff9 523
524}