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