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