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