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