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