]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONv1.cxx
Removing obsolete files from build system
[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
3d1463c8 18//-----------------------------------------------------------------------------
d19b6003 19// Class AliMUONv1
20// --------------------
21// AliDetector class for MUON subsystem which implements
22// functions for simulation
3d1463c8 23//-----------------------------------------------------------------------------
acc838fd 24
30178c30 25#include "AliMUONv1.h"
88cb7938 26#include "AliMUONConstants.h"
b7ef3c96 27#include "AliMUONResponseFactory.h"
a9e2aefa 28#include "AliMUONHit.h"
d4bb94a1 29#include "AliMUONGeometryBuilder.h"
b7ef3c96 30#include "AliMUONGeometry.h"
31#include "AliMUONGeometryTransformer.h"
e118b27e 32#include "AliMUONGeometryModule.h"
7ecf374b 33#include "AliMUONStringIntMap.h"
e118b27e 34#include "AliMUONGeometryDetElement.h"
7ecf374b 35
273e54a3 36#include "AliMpDEManager.h"
37
7ecf374b 38#include "AliConst.h"
88cb7938 39#include "AliMagF.h"
40#include "AliRun.h"
5d12ce38 41#include "AliMC.h"
d95fe39e 42#include "AliTrackReference.h"
8c343c7c 43#include "AliLog.h"
a9e2aefa 44
7ecf374b 45#include <TRandom.h>
46#include <TF1.h>
47#include <TClonesArray.h>
48#include <TRandom.h>
49#include <TVirtualMC.h>
50#include <TGeoMatrix.h>
51
edee5e63 52#include <string>
53
bb2bab35 54#include "AliMUONVHitStore.h"
55
5398f946 56/// \cond CLASSIMP
a9e2aefa 57ClassImp(AliMUONv1)
5398f946 58/// \endcond
a9e2aefa 59
60//___________________________________________
30178c30 61AliMUONv1::AliMUONv1()
62 : AliMUON(),
d4bb94a1 63 fAngleEffect(kTRUE),
64 fStepMaxInActiveGas(0.6),
65 fStepSum(0x0),
66 fDestepSum(0x0),
67 fTrackMomentum(),
68 fTrackPosition(),
69 fElossRatio(0x0),
70 fAngleEffect10(0x0),
b7ef3c96 71 fAngleEffectNorma(0x0)
a9e2aefa 72{
d19b6003 73/// Default constructor
74
75 AliDebug(1,Form("default (empty) ctor this=%p",this));
1391e633 76}
d4bb94a1 77
a9e2aefa 78//___________________________________________
9bf406e1 79AliMUONv1::AliMUONv1(const char *name, const char* title)
80: AliMUON(name, title),
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
125//___________________________________________
acc838fd 126AliMUONv1::~AliMUONv1()
a9e2aefa 127{
d19b6003 128/// Destructor
129
130 AliDebug(1,Form("dtor this=%p",this));
d4bb94a1 131 delete [] fStepSum;
132 delete [] fDestepSum;
133 delete fElossRatio;
134 delete fAngleEffect10;
8109731a 135 delete fAngleEffectNorma;
acc838fd 136}
b17c0c87 137
acc838fd 138//__________________________________________________
139void AliMUONv1::CreateGeometry()
140{
d19b6003 141/// Construct geometry using geometry builder
a9e2aefa 142
d4bb94a1 143 fGeometryBuilder->CreateGeometry();
acc838fd 144}
a9e2aefa 145
acc838fd 146//________________________________________________________________
a9e2aefa 147void AliMUONv1::CreateMaterials()
148{
d19b6003 149/// Construct materials using geometry builder
acc838fd 150
d4bb94a1 151 fGeometryBuilder->CreateMaterials();
a9e2aefa 152}
153
c28b5041 154//________________________________________________________________
155void AliMUONv1::AddAlignableVolumes() const
156{
157/// Construct materials using geometry builder
158
159 GetGeometryTransformer()->AddAlignableVolumes();
160}
161
162
acc838fd 163//___________________________________________
a9e2aefa 164void AliMUONv1::Init()
a713db22 165{
d19b6003 166/// Initialize geometry
167
edee5e63 168 AliDebug(1,"Start Init for version 1 - CPC chamber type");
002920d1 169
edee5e63 170 fGeometryBuilder->InitGeometry();
171 AliDebug(1,"Finished Init for version 1 - CPC chamber type");
b7ef3c96 172
173
b7ef3c96 174 // Build segmentation
175 // using geometry parametrisation
176 //
b7ef3c96 177 // Build response
edee5e63 178 //
b7ef3c96 179 AliMUONResponseFactory respFactory("default");
180 respFactory.Build(this);
181
a9e2aefa 182}
1391e633 183
d4bb94a1 184//__________________________________________________________________
273e54a3 185Int_t AliMUONv1::GetGeomModuleId(Int_t volId) const
d4bb94a1 186{
d19b6003 187/// Check if the volume with specified volId is a sensitive volume (gas)
5398f946 188/// of some chamber and return the chamber number;
d19b6003 189/// if not sensitive volume - return 0.
d4bb94a1 190
273e54a3 191 for (Int_t i = 0; i < AliMUONConstants::NGeomModules(); i++) {
b7ef3c96 192 if ( GetGeometry()->GetModule(i)->IsSensitiveVolume(volId) )
273e54a3 193 return i;
b7ef3c96 194 }
d4bb94a1 195
273e54a3 196 return -1;
d4bb94a1 197}
333f7cda 198
199//_______________________________________________________________________________
200TString AliMUONv1::CurrentVolumePath() const
201{
d19b6003 202/// Return current volume path
203/// (Could be removed when this function is available via gMC)
333f7cda 204
205 TString path = "";
206 TString name;
207 Int_t copyNo;
208 Int_t imother = 0;
209 do {
210 name = gMC->CurrentVolOffName(imother);
211 gMC->CurrentVolOffID(imother++, copyNo);
212 TString add = "/";
213 add += name;
7ecf374b 214 add += "_";
333f7cda 215 add += copyNo;
216 path.Insert(0,add);
217 }
218 while ( name != TString("ALIC") );
219
220 return path;
221}
222
1391e633 223//_______________________________________________________________________________
c33d9661 224void AliMUONv1::StepManager()
225{
d19b6003 226/// Step manager for the chambers
c33d9661 227
228 // Only charged tracks
d59b2ec3 229 if( !(gMC->TrackCharge()) ) return;
1391e633 230 // Only charged tracks
231
c33d9661 232 // Only gas gap inside chamber
233 // Tag chambers and record hits when track enters
d95fe39e 234 static Int_t idvol=-1, iEnter = 0;
1391e633 235 Int_t copy;
236 const Float_t kBig = 1.e10;
d95fe39e 237 static Double_t xyzEnter[3];
acc838fd 238
239 //
240 // Only gas gap inside chamber
241 // Tag chambers and record hits when track enters
273e54a3 242 Int_t id=gMC->CurrentVolID(copy);
243 Int_t iGeomModule = GetGeomModuleId(id);
244 if (iGeomModule == -1) return;
acc838fd 245
d95fe39e 246 // Detection elements id
247 const AliMUONGeometryModule* kGeometryModule
273e54a3 248 = GetGeometry()->GetModule(iGeomModule);
d95fe39e 249 AliMUONGeometryDetElement* detElement
250 = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
273e54a3 251
252 if (!detElement && iGeomModule < AliMUONConstants::NGeomModules()-2) {
253 iGeomModule++;
254 const AliMUONGeometryModule* kGeometryModule2
255 = GetGeometry()->GetModule(iGeomModule);
256 detElement
257 = kGeometryModule2->FindBySensitiveVolume(CurrentVolumePath());
258 }
374ebd7d 259
d95fe39e 260 Int_t detElemId = 0;
261 if (detElement) detElemId = detElement->GetUniqueID();
333f7cda 262
d95fe39e 263 if (!detElemId) {
273e54a3 264 AliErrorStream()
265 << "Geometry module id: "
266 << setw(3) << iGeomModule << " "
d95fe39e 267 << "Current SV: "
268 << CurrentVolumePath()
269 << " detElemId: "
270 << setw(5) << detElemId
271 << endl;
272 Double_t x, y, z;
273 gMC->TrackPosition(x, y, z);
273e54a3 274 AliErrorStream()
275 << " global position: "
d95fe39e 276 << x << ", " << y << ", " << z
277 << endl;
273e54a3 278 AliErrorStream() << "DetElemId not identified." << endl;
279 }
280
281 Int_t iChamber = AliMpDEManager::GetChamberId(detElemId) + 1;
282 idvol = iChamber -1;
333f7cda 283
d59b2ec3 284 // Filling TrackRefs file for MUON. Our Track references are the active volume of the chambers
d95fe39e 285 if ( (gMC->IsTrackEntering() || gMC->IsTrackExiting() ) ) {
286 AliTrackReference* trackReference
287 = AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
288 trackReference->SetUserId(detElemId);
289 }
d59b2ec3 290
d95fe39e 291 if( gMC->IsTrackEntering() ) {
d59b2ec3 292 Float_t theta = fTrackMomentum.Theta();
293 if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
c5ce4e69 294 iEnter = 1;
295 gMC->TrackPosition(xyzEnter[0], xyzEnter[1], xyzEnter[2]); // save coordinates of entrance point
d59b2ec3 296 }
297
5a0e88a7 298 // AliDebug(1,
299 // Form("Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber,
300 // ( (AliMUONChamber*)(*fChambers)[idvol])->Z())) ;
d59b2ec3 301 // Particule id and mass,
302 Int_t ipart = gMC->TrackPid();
303 Float_t mass = gMC->TrackMass();
304
305 fDestepSum[idvol]+=gMC->Edep();
306 // Get current particle id (ipart), track position (pos) and momentum (mom)
307 if ( fStepSum[idvol]==0.0 ) gMC->TrackMomentum(fTrackMomentum);
308 fStepSum[idvol]+=gMC->TrackStep();
309
5a0e88a7 310 // if (AliDebugLevel()) {
311 // AliDebug(1,Form("Step, iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
312 // iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg,
313 // mass, fStepSum[idvol], gMC->Edep()));
314 // AliDebug(1,Form("Step:Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(),
315 // fTrackMomentum.Z()));
316 // gMC->TrackPosition(fTrackPosition);
317 // AliDebug(1,Form("Step: Track Position %f %f %f",fTrackPosition.X(),
318 // fTrackPosition.Y(),fTrackPosition.Z())) ;
319 //}
d59b2ec3 320
321 // Track left chamber or StepSum larger than fStepMaxInActiveGas
322 if ( gMC->IsTrackExiting() ||
323 gMC->IsTrackStop() ||
324 gMC->IsTrackDisappeared()||
325 (fStepSum[idvol]>fStepMaxInActiveGas) ) {
326
327 if ( gMC->IsTrackExiting() ||
328 gMC->IsTrackStop() ||
329 gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
c5ce4e69 330 if (fDestepSum[idvol] == 0) {
331 // AZ - no energy release
332 fStepSum[idvol] = 0; // Reset for the next event
333 iEnter = 0;
334 return;
335 }
d59b2ec3 336
337 gMC->TrackPosition(fTrackPosition);
338 Float_t theta = fTrackMomentum.Theta();
339 Float_t phi = fTrackMomentum.Phi();
340
795b3f56 341 Int_t merge = 0;
342 Double_t xyz0[3]={0}, xyz1[3]={0}, tmp[3]={0};
c5ce4e69 343 if (gMC->IsTrackExiting() && iEnter != 0) {
344 // AZ - this code is to avoid artificial hit splitting at the
345 // "fake" boundary inside the same chamber. It will still produce
346 // 2 hits but with the same coordinates (at the wire) to allow
347 // their merging at the digitization level.
348
349 // Only for a track going from the entrance to the exit from the volume
350 // Get local coordinates
c5ce4e69 351 gMC->Gmtod(xyzEnter, xyz0, 1); // local coord. at the entrance
352
353 fTrackPosition.Vect().GetXYZ(tmp);
354 gMC->Gmtod(tmp, xyz1, 1); // local coord. at the exit
795b3f56 355 Float_t dx = xyz0[0] - xyz1[0];
356 Float_t dy = xyz0[1] - xyz1[1];
357 Float_t thLoc = TMath::ATan2 (TMath::Sqrt(dx*dx+dy*dy), TMath::Abs(xyz0[2]-xyz1[2]));
358 if (thLoc * TMath::RadToDeg() < 15) merge = 1;
359 }
c5ce4e69 360
795b3f56 361 if (merge) {
c5ce4e69 362 Double_t dz = -0.5;
363 if (xyz1[2] != xyz0[2]) dz = xyz0[2] / (xyz1[2] - xyz0[2]);
364 tmp[0] = xyz0[0] - (xyz1[0] - xyz0[0]) * dz; // local coord. at the wire
365 tmp[1] = xyz0[1] - (xyz1[1] - xyz0[1]) * dz;
366 tmp[2] = xyz0[2] - (xyz1[2] - xyz0[2]) * dz;
367 gMC->Gdtom(tmp, xyz1, 1); // global coord. at the wire
368 fTrackPosition.SetXYZT(xyz1[0], xyz1[1], xyz1[2], fTrackPosition.T());
369 } else {
370 TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
371 fStepSum[idvol]/2.*sin(theta)*sin(phi),
372 fStepSum[idvol]/2.*cos(theta),0.0 );
373 fTrackPosition-=backToWire;
374 //printf(" %d %d %d %f %d \n", gMC->IsTrackExiting(), gMC->IsTrackStop(), gMC->IsTrackDisappeared(), fStepSum[idvol], iEnter);
375 // AliDebug(1,
376 // Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()));
377 // AliDebug(1,
378 // Form("Exit: Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z())) ;
379 }
d59b2ec3 380
381 //-------------- Angle effect
382 // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
383
384 Float_t betaxGamma = fTrackMomentum.P()/mass;// pc/mc2
385 Float_t sigmaEffect10degrees;
386 Float_t sigmaEffectThetadegrees;
387 Float_t eLossParticleELossMip;
388 Float_t yAngleEffect=0.;
389 Float_t thetawires = TMath::Abs( TMath::ASin( TMath::Sin(TMath::Pi()-theta) * TMath::Sin(phi) ) );// We use Pi-theta because z is negative
390
391
392 if (fAngleEffect){
393 if ( (betaxGamma >3.2) && (thetawires*kRaddeg<=15.) ) {
394 betaxGamma=TMath::Log(betaxGamma);
395 eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
396 // 10 degrees is a reference for a model (arbitrary)
397 sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
398 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
399 sigmaEffectThetadegrees = sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg); // For 5mm gap
400 if ( (iChamber==1) || (iChamber==2) )
401 sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
402 yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
403 }
404 }
405
bb2bab35 406 AliMUONHit hit(fIshunt,
d59b2ec3 407 gAlice->GetMCApp()->GetCurrentTrackNumber(),
408 detElemId, ipart,
409 fTrackPosition.X(),
410 fTrackPosition.Y()+yAngleEffect,
411 fTrackPosition.Z(),
412 gMC->TrackTime(),
413 fTrackMomentum.P(),
414 theta,
415 phi,
416 fStepSum[idvol],
417 fDestepSum[idvol],
418 fTrackPosition.X(),
419 fTrackPosition.Y(),
420 fTrackPosition.Z());
421
bb2bab35 422 fHitStore->Add(hit);
5a0e88a7 423
d59b2ec3 424 fStepSum[idvol] =0; // Reset for the next event
425 fDestepSum[idvol]=0; // Reset for the next event
c5ce4e69 426 iEnter = 0;
d59b2ec3 427 }
428}