]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONv1.cxx
Geometry builder classes moved from base to sim.
[u/mrichter/AliRoot.git] / MUON / AliMUONv1.cxx
CommitLineData
a9e2aefa 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
0c527060 3 * *
a9e2aefa 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 *
2c799aa2 12 * about the suitability of this software for any purpeateose. It is *
a9e2aefa 13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
88cb7938 16/* $Id$ */
a9e2aefa 17
d19b6003 18// --------------------
19// Class AliMUONv1
20// --------------------
21// AliDetector class for MUON subsystem which implements
22// functions for simulation
acc838fd 23
30178c30 24#include "AliMUONv1.h"
88cb7938 25#include "AliMUONConstants.h"
40afd6cd 26#include "AliMUONSegFactory.h"
b7ef3c96 27#include "AliMUONResponseFactory.h"
28#include "AliMUONSegmentation.h"
a9e2aefa 29#include "AliMUONHit.h"
8c449e83 30#include "AliMUONTriggerCircuit.h"
0c527060 31#include "AliMUONTriggerCircuitNew.h"
32#include "AliMUONTriggerCrateStore.h"
d4bb94a1 33#include "AliMUONGeometryBuilder.h"
b7ef3c96 34#include "AliMUONGeometry.h"
35#include "AliMUONGeometryTransformer.h"
e118b27e 36#include "AliMUONGeometryModule.h"
7ecf374b 37#include "AliMUONStringIntMap.h"
e118b27e 38#include "AliMUONGeometryDetElement.h"
7ecf374b 39
40#include "AliConst.h"
88cb7938 41#include "AliMagF.h"
42#include "AliRun.h"
5d12ce38 43#include "AliMC.h"
d95fe39e 44#include "AliTrackReference.h"
8c343c7c 45#include "AliLog.h"
a9e2aefa 46
7ecf374b 47#include <TRandom.h>
48#include <TF1.h>
49#include <TClonesArray.h>
50#include <TRandom.h>
51#include <TVirtualMC.h>
52#include <TGeoMatrix.h>
53
edee5e63 54#include <string>
55
a9e2aefa 56ClassImp(AliMUONv1)
57
58//___________________________________________
30178c30 59AliMUONv1::AliMUONv1()
60 : AliMUON(),
d4bb94a1 61 fAngleEffect(kTRUE),
62 fStepMaxInActiveGas(0.6),
63 fStepSum(0x0),
64 fDestepSum(0x0),
65 fTrackMomentum(),
66 fTrackPosition(),
67 fElossRatio(0x0),
68 fAngleEffect10(0x0),
b7ef3c96 69 fAngleEffectNorma(0x0)
a9e2aefa 70{
d19b6003 71/// Default constructor
72
73 AliDebug(1,Form("default (empty) ctor this=%p",this));
1391e633 74}
d4bb94a1 75
a9e2aefa 76//___________________________________________
b05d84a5 77AliMUONv1::AliMUONv1(const char *name, const char *title,
78 const char* sDigitizerClassName,
79 const char* digitizerClassName)
80: AliMUON(name,title,sDigitizerClassName,digitizerClassName),
d4bb94a1 81 fAngleEffect(kTRUE),
82 fStepMaxInActiveGas(0.6),
83 fStepSum(0x0),
84 fDestepSum(0x0),
85 fTrackMomentum(),
86 fTrackPosition(),
87 fElossRatio(0x0),
88 fAngleEffect10(0x0),
b7ef3c96 89 fAngleEffectNorma(0x0)
a9e2aefa 90{
d19b6003 91/// Standard onstructor
d4bb94a1 92
d19b6003 93 AliDebug(1,Form("ctor this=%p",this));
edee5e63 94
ba030c0e 95 // By default include all stations
c33d9661 96
1391e633 97 fStepSum = new Float_t [AliMUONConstants::NCh()];
98 fDestepSum = new Float_t [AliMUONConstants::NCh()];
99 for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
100 fStepSum[i] =0.0;
101 fDestepSum[i]=0.0;
102 }
103 // Ratio of particle mean eloss with respect MIP's Khalil Boudjemline, sep 2003, PhD.Thesis and Particle Data Book
104 fElossRatio = new TF1("ElossRatio","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",0.5,5.);
105 fElossRatio->SetParameter(0,1.02138);
106 fElossRatio->SetParameter(1,-9.54149e-02);
107 fElossRatio->SetParameter(2,+7.83433e-02);
108 fElossRatio->SetParameter(3,-9.98208e-03);
109 fElossRatio->SetParameter(4,+3.83279e-04);
110
111 // Angle effect in tracking chambers at theta =10 degres as a function of ElossRatio (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis) (in micrometers)
112 fAngleEffect10 = new TF1("AngleEffect10","[0]+[1]*x+[2]*x*x",0.5,3.0);
113 fAngleEffect10->SetParameter(0, 1.90691e+02);
114 fAngleEffect10->SetParameter(1,-6.62258e+01);
115 fAngleEffect10->SetParameter(2,+1.28247e+01);
116 // Angle effect: Normalisation form theta=10 degres to theta between 0 and 10 (Khalil BOUDJEMLINE sep 2003 Ph.D Thesis)
117 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
118 fAngleEffectNorma = new TF1("AngleEffectNorma","[0]+[1]*x+[2]*x*x+[3]*x*x*x",0.0,10.0);
119 fAngleEffectNorma->SetParameter(0,4.148);
120 fAngleEffectNorma->SetParameter(1,-6.809e-01);
121 fAngleEffectNorma->SetParameter(2,5.151e-02);
122 fAngleEffectNorma->SetParameter(3,-1.490e-03);
a9e2aefa 123}
124
fb1bf5c0 125//_____________________________________________________________________________
126AliMUONv1::AliMUONv1(const AliMUONv1& right)
127 : AliMUON(right)
128{
d19b6003 129/// Copy constructor (not implemented)
fb1bf5c0 130
8c343c7c 131 AliFatal("Copy constructor not provided.");
fb1bf5c0 132}
133
a9e2aefa 134//___________________________________________
acc838fd 135AliMUONv1::~AliMUONv1()
a9e2aefa 136{
d19b6003 137/// Destructor
138
139 AliDebug(1,Form("dtor this=%p",this));
d4bb94a1 140 delete [] fStepSum;
141 delete [] fDestepSum;
142 delete fElossRatio;
143 delete fAngleEffect10;
8109731a 144 delete fAngleEffectNorma;
acc838fd 145}
b17c0c87 146
fb1bf5c0 147//_____________________________________________________________________________
148AliMUONv1& AliMUONv1::operator=(const AliMUONv1& right)
149{
d19b6003 150/// Assignement operator (not implemented)
fb1bf5c0 151
152 // check assignement to self
153 if (this == &right) return *this;
154
8c343c7c 155 AliFatal("Assignement operator not provided.");
fb1bf5c0 156
157 return *this;
158}
159
acc838fd 160//__________________________________________________
161void AliMUONv1::CreateGeometry()
162{
d19b6003 163/// Construct geometry using geometry builder
a9e2aefa 164
d4bb94a1 165 fGeometryBuilder->CreateGeometry();
acc838fd 166}
a9e2aefa 167
acc838fd 168//________________________________________________________________
a9e2aefa 169void AliMUONv1::CreateMaterials()
170{
d19b6003 171/// Construct materials using geometry builder
acc838fd 172
d4bb94a1 173 fGeometryBuilder->CreateMaterials();
a9e2aefa 174}
175
acc838fd 176//___________________________________________
a9e2aefa 177void AliMUONv1::Init()
a713db22 178{
d19b6003 179/// Initialize geometry
180
edee5e63 181 AliDebug(1,"Start Init for version 1 - CPC chamber type");
002920d1 182
edee5e63 183 fGeometryBuilder->InitGeometry();
184 AliDebug(1,"Finished Init for version 1 - CPC chamber type");
b7ef3c96 185
186
edee5e63 187 std::string ftype(GetTitle());
b7ef3c96 188
189 // Build segmentation
190 // using geometry parametrisation
191 //
40afd6cd 192 AliMUONSegFactory segFactory(GetGeometryTransformer());
193 fSegmentation = segFactory.CreateSegmentation(ftype);
194
195 if (!fSegmentation) {
196 AliFatal(Form("Wrong factory type : %s",ftype.c_str()));
197 }
b7ef3c96 198
199 // Build response
edee5e63 200 //
b7ef3c96 201 AliMUONResponseFactory respFactory("default");
202 respFactory.Build(this);
203
204
edee5e63 205 // Initialize segmentation
206 //
b7ef3c96 207 fSegmentation->Init();
208
209 // Initialize trigger circuits
210 //
211 for (Int_t i=0; i<AliMUONConstants::NTriggerCircuit(); i++) {
e1d9a0df 212 AliMUONTriggerCircuit* c = (AliMUONTriggerCircuit*)(fTriggerCircuits->At(i));
213 c->Init(i);
0c527060 214 }
215
216 AliMUONTriggerCrateStore store;
217 store.ReadFromFile();
218 for (Int_t i=0; i<AliMUONConstants::NTriggerCircuit(); i++)
219 {
220 AliMUONTriggerCircuitNew* c = (AliMUONTriggerCircuitNew*)(fTriggerCircuitsNew->At(i));
221 c->Init(i,store);
e1d9a0df 222 }
edee5e63 223
a9e2aefa 224}
1391e633 225
d4bb94a1 226//__________________________________________________________________
227Int_t AliMUONv1::GetChamberId(Int_t volId) const
228{
d19b6003 229/// Check if the volume with specified volId is a sensitive volume (gas)
230/// of some chamber and returns the chamber number;
231/// if not sensitive volume - return 0.
d4bb94a1 232
b7ef3c96 233 for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {
234 if ( GetGeometry()->GetModule(i)->IsSensitiveVolume(volId) )
235 return i+1;
236 }
d4bb94a1 237
238 return 0;
239}
333f7cda 240
241//_______________________________________________________________________________
242TString AliMUONv1::CurrentVolumePath() const
243{
d19b6003 244/// Return current volume path
245/// (Could be removed when this function is available via gMC)
333f7cda 246
247 TString path = "";
248 TString name;
249 Int_t copyNo;
250 Int_t imother = 0;
251 do {
252 name = gMC->CurrentVolOffName(imother);
253 gMC->CurrentVolOffID(imother++, copyNo);
254 TString add = "/";
255 add += name;
7ecf374b 256 add += "_";
333f7cda 257 add += copyNo;
258 path.Insert(0,add);
259 }
260 while ( name != TString("ALIC") );
261
262 return path;
263}
264
1391e633 265//_______________________________________________________________________________
c33d9661 266void AliMUONv1::StepManager()
267{
d19b6003 268/// Step manager for the chambers
c33d9661 269
270 // Only charged tracks
d59b2ec3 271 if( !(gMC->TrackCharge()) ) return;
1391e633 272 // Only charged tracks
273
c33d9661 274 // Only gas gap inside chamber
275 // Tag chambers and record hits when track enters
d95fe39e 276 static Int_t idvol=-1, iEnter = 0;
1391e633 277 Int_t iChamber=0;
278 Int_t id=0;
279 Int_t copy;
280 const Float_t kBig = 1.e10;
d95fe39e 281 static Double_t xyzEnter[3];
acc838fd 282
283 //
284 // Only gas gap inside chamber
285 // Tag chambers and record hits when track enters
c33d9661 286 id=gMC->CurrentVolID(copy);
acc838fd 287 iChamber = GetChamberId(id);
288 idvol = iChamber -1;
289
290 if (idvol == -1) return;
abaf7c9d 291
d95fe39e 292 // Detection elements id
293 const AliMUONGeometryModule* kGeometryModule
294 = GetGeometry()->GetModule(iChamber-1);
d7c4fbc4 295
d95fe39e 296 AliMUONGeometryDetElement* detElement
297 = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
374ebd7d 298
d95fe39e 299 Int_t detElemId = 0;
300 if (detElement) detElemId = detElement->GetUniqueID();
333f7cda 301
d95fe39e 302 if (!detElemId) {
303 cerr << "Chamber id: "
304 << setw(3) << iChamber << " "
305 << "Current SV: "
306 << CurrentVolumePath()
307 << " detElemId: "
308 << setw(5) << detElemId
309 << endl;
310 Double_t x, y, z;
311 gMC->TrackPosition(x, y, z);
312 cerr << " global position: "
313 << x << ", " << y << ", " << z
314 << endl;
315 AliError("DetElemId not identified.");
316 }
333f7cda 317
d59b2ec3 318 // Filling TrackRefs file for MUON. Our Track references are the active volume of the chambers
d95fe39e 319 if ( (gMC->IsTrackEntering() || gMC->IsTrackExiting() ) ) {
320 AliTrackReference* trackReference
321 = AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
322 trackReference->SetUserId(detElemId);
323 }
d59b2ec3 324
d95fe39e 325 if( gMC->IsTrackEntering() ) {
d59b2ec3 326 Float_t theta = fTrackMomentum.Theta();
327 if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
c5ce4e69 328 iEnter = 1;
329 gMC->TrackPosition(xyzEnter[0], xyzEnter[1], xyzEnter[2]); // save coordinates of entrance point
d59b2ec3 330 }
331
5a0e88a7 332 // AliDebug(1,
333 // Form("Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber,
334 // ( (AliMUONChamber*)(*fChambers)[idvol])->Z())) ;
d59b2ec3 335 // Particule id and mass,
336 Int_t ipart = gMC->TrackPid();
337 Float_t mass = gMC->TrackMass();
338
339 fDestepSum[idvol]+=gMC->Edep();
340 // Get current particle id (ipart), track position (pos) and momentum (mom)
341 if ( fStepSum[idvol]==0.0 ) gMC->TrackMomentum(fTrackMomentum);
342 fStepSum[idvol]+=gMC->TrackStep();
343
5a0e88a7 344 // if (AliDebugLevel()) {
345 // AliDebug(1,Form("Step, iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
346 // iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg,
347 // mass, fStepSum[idvol], gMC->Edep()));
348 // AliDebug(1,Form("Step:Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(),
349 // fTrackMomentum.Z()));
350 // gMC->TrackPosition(fTrackPosition);
351 // AliDebug(1,Form("Step: Track Position %f %f %f",fTrackPosition.X(),
352 // fTrackPosition.Y(),fTrackPosition.Z())) ;
353 //}
d59b2ec3 354
355 // Track left chamber or StepSum larger than fStepMaxInActiveGas
356 if ( gMC->IsTrackExiting() ||
357 gMC->IsTrackStop() ||
358 gMC->IsTrackDisappeared()||
359 (fStepSum[idvol]>fStepMaxInActiveGas) ) {
360
361 if ( gMC->IsTrackExiting() ||
362 gMC->IsTrackStop() ||
363 gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
c5ce4e69 364 if (fDestepSum[idvol] == 0) {
365 // AZ - no energy release
366 fStepSum[idvol] = 0; // Reset for the next event
367 iEnter = 0;
368 return;
369 }
d59b2ec3 370
371 gMC->TrackPosition(fTrackPosition);
372 Float_t theta = fTrackMomentum.Theta();
373 Float_t phi = fTrackMomentum.Phi();
374
795b3f56 375 Int_t merge = 0;
376 Double_t xyz0[3]={0}, xyz1[3]={0}, tmp[3]={0};
c5ce4e69 377 if (gMC->IsTrackExiting() && iEnter != 0) {
378 // AZ - this code is to avoid artificial hit splitting at the
379 // "fake" boundary inside the same chamber. It will still produce
380 // 2 hits but with the same coordinates (at the wire) to allow
381 // their merging at the digitization level.
382
383 // Only for a track going from the entrance to the exit from the volume
384 // Get local coordinates
c5ce4e69 385 gMC->Gmtod(xyzEnter, xyz0, 1); // local coord. at the entrance
386
387 fTrackPosition.Vect().GetXYZ(tmp);
388 gMC->Gmtod(tmp, xyz1, 1); // local coord. at the exit
795b3f56 389 Float_t dx = xyz0[0] - xyz1[0];
390 Float_t dy = xyz0[1] - xyz1[1];
391 Float_t thLoc = TMath::ATan2 (TMath::Sqrt(dx*dx+dy*dy), TMath::Abs(xyz0[2]-xyz1[2]));
392 if (thLoc * TMath::RadToDeg() < 15) merge = 1;
393 }
c5ce4e69 394
795b3f56 395 if (merge) {
c5ce4e69 396 Double_t dz = -0.5;
397 if (xyz1[2] != xyz0[2]) dz = xyz0[2] / (xyz1[2] - xyz0[2]);
398 tmp[0] = xyz0[0] - (xyz1[0] - xyz0[0]) * dz; // local coord. at the wire
399 tmp[1] = xyz0[1] - (xyz1[1] - xyz0[1]) * dz;
400 tmp[2] = xyz0[2] - (xyz1[2] - xyz0[2]) * dz;
401 gMC->Gdtom(tmp, xyz1, 1); // global coord. at the wire
402 fTrackPosition.SetXYZT(xyz1[0], xyz1[1], xyz1[2], fTrackPosition.T());
403 } else {
404 TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
405 fStepSum[idvol]/2.*sin(theta)*sin(phi),
406 fStepSum[idvol]/2.*cos(theta),0.0 );
407 fTrackPosition-=backToWire;
408 //printf(" %d %d %d %f %d \n", gMC->IsTrackExiting(), gMC->IsTrackStop(), gMC->IsTrackDisappeared(), fStepSum[idvol], iEnter);
409 // AliDebug(1,
410 // Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()));
411 // AliDebug(1,
412 // Form("Exit: Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z())) ;
413 }
d59b2ec3 414
415 //-------------- Angle effect
416 // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
417
418 Float_t betaxGamma = fTrackMomentum.P()/mass;// pc/mc2
419 Float_t sigmaEffect10degrees;
420 Float_t sigmaEffectThetadegrees;
421 Float_t eLossParticleELossMip;
422 Float_t yAngleEffect=0.;
423 Float_t thetawires = TMath::Abs( TMath::ASin( TMath::Sin(TMath::Pi()-theta) * TMath::Sin(phi) ) );// We use Pi-theta because z is negative
424
425
426 if (fAngleEffect){
427 if ( (betaxGamma >3.2) && (thetawires*kRaddeg<=15.) ) {
428 betaxGamma=TMath::Log(betaxGamma);
429 eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
430 // 10 degrees is a reference for a model (arbitrary)
431 sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
432 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
433 sigmaEffectThetadegrees = sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg); // For 5mm gap
434 if ( (iChamber==1) || (iChamber==2) )
435 sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
436 yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
437 }
438 }
439
d59b2ec3 440 // One hit per chamber
8690a0a6 441 GetMUONData()->AddHit2(fIshunt,
d59b2ec3 442 gAlice->GetMCApp()->GetCurrentTrackNumber(),
443 detElemId, ipart,
444 fTrackPosition.X(),
445 fTrackPosition.Y()+yAngleEffect,
446 fTrackPosition.Z(),
447 gMC->TrackTime(),
448 fTrackMomentum.P(),
449 theta,
450 phi,
451 fStepSum[idvol],
452 fDestepSum[idvol],
453 fTrackPosition.X(),
454 fTrackPosition.Y(),
455 fTrackPosition.Z());
456
5a0e88a7 457 // AliDebug(1,Form("Exit: Particle exiting from chamber %d",iChamber));
458 // AliDebug(1,Form("Exit: StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]));
459 // AliDebug(1,Form("Exit: Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
460
d59b2ec3 461 fStepSum[idvol] =0; // Reset for the next event
462 fDestepSum[idvol]=0; // Reset for the next event
c5ce4e69 463 iEnter = 0;
d59b2ec3 464 }
465}