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