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