]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - MUON/AliMUONv1.cxx
Introduced new DE names unique to each det element;
[u/mrichter/AliRoot.git] / MUON / AliMUONv1.cxx
... / ...
CommitLineData
1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
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 *
12 * about the suitability of this software for any purpeateose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
17
18// --------------------
19// Class AliMUONv1
20// --------------------
21// AliDetector class for MUON subsystem which implements
22// functions for simulation
23
24#include "AliMUONv1.h"
25#include "AliMUONConstants.h"
26#include "AliMUONSegFactory.h"
27#include "AliMUONResponseFactory.h"
28#include "AliMUONSegmentation.h"
29#include "AliMUONHit.h"
30#include "AliMUONGeometryBuilder.h"
31#include "AliMUONGeometry.h"
32#include "AliMUONGeometryTransformer.h"
33#include "AliMUONGeometryModule.h"
34#include "AliMUONStringIntMap.h"
35#include "AliMUONGeometryDetElement.h"
36
37#include "AliMpDEManager.h"
38
39#include "AliConst.h"
40#include "AliMagF.h"
41#include "AliRun.h"
42#include "AliMC.h"
43#include "AliTrackReference.h"
44#include "AliLog.h"
45
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
53#include <string>
54
55/// \cond CLASSIMP
56ClassImp(AliMUONv1)
57/// \endcond
58
59//___________________________________________
60AliMUONv1::AliMUONv1()
61 : AliMUON(),
62 fAngleEffect(kTRUE),
63 fStepMaxInActiveGas(0.6),
64 fStepSum(0x0),
65 fDestepSum(0x0),
66 fTrackMomentum(),
67 fTrackPosition(),
68 fElossRatio(0x0),
69 fAngleEffect10(0x0),
70 fAngleEffectNorma(0x0)
71{
72/// Default constructor
73
74 AliDebug(1,Form("default (empty) ctor this=%p",this));
75}
76
77//___________________________________________
78AliMUONv1::AliMUONv1(const char *name, const char* title)
79: AliMUON(name, title),
80 fAngleEffect(kTRUE),
81 fStepMaxInActiveGas(0.6),
82 fStepSum(0x0),
83 fDestepSum(0x0),
84 fTrackMomentum(),
85 fTrackPosition(),
86 fElossRatio(0x0),
87 fAngleEffect10(0x0),
88 fAngleEffectNorma(0x0)
89{
90/// Standard onstructor
91
92 AliDebug(1,Form("ctor this=%p",this));
93
94 // By default include all stations
95
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);
122}
123
124//___________________________________________
125AliMUONv1::~AliMUONv1()
126{
127/// Destructor
128
129 AliDebug(1,Form("dtor this=%p",this));
130 delete [] fStepSum;
131 delete [] fDestepSum;
132 delete fElossRatio;
133 delete fAngleEffect10;
134 delete fAngleEffectNorma;
135}
136
137//__________________________________________________
138void AliMUONv1::CreateGeometry()
139{
140/// Construct geometry using geometry builder
141
142 fGeometryBuilder->CreateGeometry();
143}
144
145//________________________________________________________________
146void AliMUONv1::CreateMaterials()
147{
148/// Construct materials using geometry builder
149
150 fGeometryBuilder->CreateMaterials();
151}
152
153//________________________________________________________________
154void AliMUONv1::AddAlignableVolumes() const
155{
156/// Construct materials using geometry builder
157
158 GetGeometryTransformer()->AddAlignableVolumes();
159}
160
161
162//___________________________________________
163void AliMUONv1::Init()
164{
165/// Initialize geometry
166
167 AliDebug(1,"Start Init for version 1 - CPC chamber type");
168
169 fGeometryBuilder->InitGeometry();
170 AliDebug(1,"Finished Init for version 1 - CPC chamber type");
171
172
173 // Build segmentation
174 // using geometry parametrisation
175 //
176 AliMUONSegFactory segFactory(GetGeometryTransformer());
177 fSegmentation = segFactory.CreateSegmentation();
178
179 // Build response
180 //
181 AliMUONResponseFactory respFactory("default");
182 respFactory.Build(this);
183
184
185 // Initialize segmentation
186 //
187 fSegmentation->Init();
188
189}
190
191//__________________________________________________________________
192Int_t AliMUONv1::GetGeomModuleId(Int_t volId) const
193{
194/// Check if the volume with specified volId is a sensitive volume (gas)
195/// of some chamber and return the chamber number;
196/// if not sensitive volume - return 0.
197
198 for (Int_t i = 0; i < AliMUONConstants::NGeomModules(); i++) {
199 if ( GetGeometry()->GetModule(i)->IsSensitiveVolume(volId) )
200 return i;
201 }
202
203 return -1;
204}
205
206//_______________________________________________________________________________
207TString AliMUONv1::CurrentVolumePath() const
208{
209/// Return current volume path
210/// (Could be removed when this function is available via gMC)
211
212 TString path = "";
213 TString name;
214 Int_t copyNo;
215 Int_t imother = 0;
216 do {
217 name = gMC->CurrentVolOffName(imother);
218 gMC->CurrentVolOffID(imother++, copyNo);
219 TString add = "/";
220 add += name;
221 add += "_";
222 add += copyNo;
223 path.Insert(0,add);
224 }
225 while ( name != TString("ALIC") );
226
227 return path;
228}
229
230//_______________________________________________________________________________
231void AliMUONv1::StepManager()
232{
233/// Step manager for the chambers
234
235 // Only charged tracks
236 if( !(gMC->TrackCharge()) ) return;
237 // Only charged tracks
238
239 // Only gas gap inside chamber
240 // Tag chambers and record hits when track enters
241 static Int_t idvol=-1, iEnter = 0;
242 Int_t copy;
243 const Float_t kBig = 1.e10;
244 static Double_t xyzEnter[3];
245
246 //
247 // Only gas gap inside chamber
248 // Tag chambers and record hits when track enters
249 Int_t id=gMC->CurrentVolID(copy);
250 Int_t iGeomModule = GetGeomModuleId(id);
251 if (iGeomModule == -1) return;
252
253 // Detection elements id
254 const AliMUONGeometryModule* kGeometryModule
255 = GetGeometry()->GetModule(iGeomModule);
256 AliMUONGeometryDetElement* detElement
257 = kGeometryModule->FindBySensitiveVolume(CurrentVolumePath());
258
259 if (!detElement && iGeomModule < AliMUONConstants::NGeomModules()-2) {
260 iGeomModule++;
261 const AliMUONGeometryModule* kGeometryModule2
262 = GetGeometry()->GetModule(iGeomModule);
263 detElement
264 = kGeometryModule2->FindBySensitiveVolume(CurrentVolumePath());
265 }
266
267 Int_t detElemId = 0;
268 if (detElement) detElemId = detElement->GetUniqueID();
269
270 if (!detElemId) {
271 AliErrorStream()
272 << "Geometry module id: "
273 << setw(3) << iGeomModule << " "
274 << "Current SV: "
275 << CurrentVolumePath()
276 << " detElemId: "
277 << setw(5) << detElemId
278 << endl;
279 Double_t x, y, z;
280 gMC->TrackPosition(x, y, z);
281 AliErrorStream()
282 << " global position: "
283 << x << ", " << y << ", " << z
284 << endl;
285 AliErrorStream() << "DetElemId not identified." << endl;
286 }
287
288 Int_t iChamber = AliMpDEManager::GetChamberId(detElemId) + 1;
289 idvol = iChamber -1;
290
291 // Filling TrackRefs file for MUON. Our Track references are the active volume of the chambers
292 if ( (gMC->IsTrackEntering() || gMC->IsTrackExiting() ) ) {
293 AliTrackReference* trackReference
294 = AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
295 trackReference->SetUserId(detElemId);
296 }
297
298 if( gMC->IsTrackEntering() ) {
299 Float_t theta = fTrackMomentum.Theta();
300 if ((TMath::Pi()-theta)*kRaddeg>=15.) gMC->SetMaxStep(fStepMaxInActiveGas); // We use Pi-theta because z is negative
301 iEnter = 1;
302 gMC->TrackPosition(xyzEnter[0], xyzEnter[1], xyzEnter[2]); // save coordinates of entrance point
303 }
304
305 // AliDebug(1,
306 // Form("Active volume found %d chamber %d Z chamber is %f ",idvol,iChamber,
307 // ( (AliMUONChamber*)(*fChambers)[idvol])->Z())) ;
308 // Particule id and mass,
309 Int_t ipart = gMC->TrackPid();
310 Float_t mass = gMC->TrackMass();
311
312 fDestepSum[idvol]+=gMC->Edep();
313 // Get current particle id (ipart), track position (pos) and momentum (mom)
314 if ( fStepSum[idvol]==0.0 ) gMC->TrackMomentum(fTrackMomentum);
315 fStepSum[idvol]+=gMC->TrackStep();
316
317 // if (AliDebugLevel()) {
318 // AliDebug(1,Form("Step, iChamber %d, Particle %d, theta %f phi %f mass %f StepSum %f eloss %g",
319 // iChamber,ipart, fTrackMomentum.Theta()*kRaddeg, fTrackMomentum.Phi()*kRaddeg,
320 // mass, fStepSum[idvol], gMC->Edep()));
321 // AliDebug(1,Form("Step:Track Momentum %f %f %f", fTrackMomentum.X(), fTrackMomentum.Y(),
322 // fTrackMomentum.Z()));
323 // gMC->TrackPosition(fTrackPosition);
324 // AliDebug(1,Form("Step: Track Position %f %f %f",fTrackPosition.X(),
325 // fTrackPosition.Y(),fTrackPosition.Z())) ;
326 //}
327
328 // Track left chamber or StepSum larger than fStepMaxInActiveGas
329 if ( gMC->IsTrackExiting() ||
330 gMC->IsTrackStop() ||
331 gMC->IsTrackDisappeared()||
332 (fStepSum[idvol]>fStepMaxInActiveGas) ) {
333
334 if ( gMC->IsTrackExiting() ||
335 gMC->IsTrackStop() ||
336 gMC->IsTrackDisappeared() ) gMC->SetMaxStep(kBig);
337 if (fDestepSum[idvol] == 0) {
338 // AZ - no energy release
339 fStepSum[idvol] = 0; // Reset for the next event
340 iEnter = 0;
341 return;
342 }
343
344 gMC->TrackPosition(fTrackPosition);
345 Float_t theta = fTrackMomentum.Theta();
346 Float_t phi = fTrackMomentum.Phi();
347
348 Int_t merge = 0;
349 Double_t xyz0[3]={0}, xyz1[3]={0}, tmp[3]={0};
350 if (gMC->IsTrackExiting() && iEnter != 0) {
351 // AZ - this code is to avoid artificial hit splitting at the
352 // "fake" boundary inside the same chamber. It will still produce
353 // 2 hits but with the same coordinates (at the wire) to allow
354 // their merging at the digitization level.
355
356 // Only for a track going from the entrance to the exit from the volume
357 // Get local coordinates
358 gMC->Gmtod(xyzEnter, xyz0, 1); // local coord. at the entrance
359
360 fTrackPosition.Vect().GetXYZ(tmp);
361 gMC->Gmtod(tmp, xyz1, 1); // local coord. at the exit
362 Float_t dx = xyz0[0] - xyz1[0];
363 Float_t dy = xyz0[1] - xyz1[1];
364 Float_t thLoc = TMath::ATan2 (TMath::Sqrt(dx*dx+dy*dy), TMath::Abs(xyz0[2]-xyz1[2]));
365 if (thLoc * TMath::RadToDeg() < 15) merge = 1;
366 }
367
368 if (merge) {
369 Double_t dz = -0.5;
370 if (xyz1[2] != xyz0[2]) dz = xyz0[2] / (xyz1[2] - xyz0[2]);
371 tmp[0] = xyz0[0] - (xyz1[0] - xyz0[0]) * dz; // local coord. at the wire
372 tmp[1] = xyz0[1] - (xyz1[1] - xyz0[1]) * dz;
373 tmp[2] = xyz0[2] - (xyz1[2] - xyz0[2]) * dz;
374 gMC->Gdtom(tmp, xyz1, 1); // global coord. at the wire
375 fTrackPosition.SetXYZT(xyz1[0], xyz1[1], xyz1[2], fTrackPosition.T());
376 } else {
377 TLorentzVector backToWire( fStepSum[idvol]/2.*sin(theta)*cos(phi),
378 fStepSum[idvol]/2.*sin(theta)*sin(phi),
379 fStepSum[idvol]/2.*cos(theta),0.0 );
380 fTrackPosition-=backToWire;
381 //printf(" %d %d %d %f %d \n", gMC->IsTrackExiting(), gMC->IsTrackStop(), gMC->IsTrackDisappeared(), fStepSum[idvol], iEnter);
382 // AliDebug(1,
383 // Form("Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()));
384 // AliDebug(1,
385 // Form("Exit: Track backToWire %f %f %f",backToWire.X(),backToWire.Y(),backToWire.Z())) ;
386 }
387
388 //-------------- Angle effect
389 // Ratio between energy loss of particle and Mip as a function of BetaGamma of particle (Energy/Mass)
390
391 Float_t betaxGamma = fTrackMomentum.P()/mass;// pc/mc2
392 Float_t sigmaEffect10degrees;
393 Float_t sigmaEffectThetadegrees;
394 Float_t eLossParticleELossMip;
395 Float_t yAngleEffect=0.;
396 Float_t thetawires = TMath::Abs( TMath::ASin( TMath::Sin(TMath::Pi()-theta) * TMath::Sin(phi) ) );// We use Pi-theta because z is negative
397
398
399 if (fAngleEffect){
400 if ( (betaxGamma >3.2) && (thetawires*kRaddeg<=15.) ) {
401 betaxGamma=TMath::Log(betaxGamma);
402 eLossParticleELossMip = fElossRatio->Eval(betaxGamma);
403 // 10 degrees is a reference for a model (arbitrary)
404 sigmaEffect10degrees=fAngleEffect10->Eval(eLossParticleELossMip);// in micrometers
405 // Angle with respect to the wires assuming that chambers are perpendicular to the z axis.
406 sigmaEffectThetadegrees = sigmaEffect10degrees/fAngleEffectNorma->Eval(thetawires*kRaddeg); // For 5mm gap
407 if ( (iChamber==1) || (iChamber==2) )
408 sigmaEffectThetadegrees/=(1.09833e+00+1.70000e-02*(thetawires*kRaddeg)); // The gap is different (4mm)
409 yAngleEffect=1.e-04*gRandom->Gaus(0,sigmaEffectThetadegrees); // Error due to the angle effect in cm
410 }
411 }
412
413 // One hit per chamber
414 GetMUONData()->AddHit(fIshunt,
415 gAlice->GetMCApp()->GetCurrentTrackNumber(),
416 detElemId, ipart,
417 fTrackPosition.X(),
418 fTrackPosition.Y()+yAngleEffect,
419 fTrackPosition.Z(),
420 gMC->TrackTime(),
421 fTrackMomentum.P(),
422 theta,
423 phi,
424 fStepSum[idvol],
425 fDestepSum[idvol],
426 fTrackPosition.X(),
427 fTrackPosition.Y(),
428 fTrackPosition.Z());
429
430 // AliDebug(1,Form("Exit: Particle exiting from chamber %d",iChamber));
431 // AliDebug(1,Form("Exit: StepSum %f eloss geant %g ",fStepSum[idvol],fDestepSum[idvol]));
432 // AliDebug(1,Form("Exit: Track Position %f %f %f",fTrackPosition.X(),fTrackPosition.Y(),fTrackPosition.Z()) ;
433
434 fStepSum[idvol] =0; // Reset for the next event
435 fDestepSum[idvol]=0; // Reset for the next event
436 iEnter = 0;
437 }
438}