Introduction of the new SSD geometry in simulation (AliITSv11Hybrid) and suppression...
[u/mrichter/AliRoot.git] / MUON / AliMUON.cxx
CommitLineData
4c039060 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 purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
4c039060 15
88cb7938 16/* $Id$ */
17
d19b6003 18// ------------------
19// Class AliMUON
20// ------------------
21// AliDetector class for MUON subsystem
22// providing simulation data management
fe4da5cc 23
88cb7938 24#include "Riostream.h"
25
26#include <AliPDG.h>
a897a37a 27#include <TBRIK.h>
88cb7938 28#include <TCanvas.h>
29#include <TDirectory.h>
30#include <TFile.h>
94de3818 31#include <TGeometry.h>
88cb7938 32#include <TMinuit.h>
fe4da5cc 33#include <TNode.h>
88cb7938 34#include <TNtuple.h>
fe4da5cc 35#include <TObjArray.h>
88cb7938 36#include <TObject.h>
37#include <TObjectTable.h>
38#include <TPad.h>
a897a37a 39#include <TParticle.h>
40#include <TROOT.h>
88cb7938 41#include <TRandom.h>
42#include <TRotMatrix.h>
43#include <TTUBE.h>
a9e2aefa 44#include <TTUBE.h>
88cb7938 45#include <TTree.h>
46#include <TVector.h>
47#include <TVirtualMC.h>
fe4da5cc 48
d4bb94a1 49//#include "AliHeader.h"
88cb7938 50#include "AliLoader.h"
dbb4e169 51#include "AliRunDigitizer.h"
307d9d04 52#include "AliMC.h"
fac3a970 53#include "AliRun.h"
fe4da5cc 54#include "AliMUON.h"
88cb7938 55#include "AliMUONChamberTrigger.h"
88cb7938 56#include "AliMUONConstants.h"
ffd9faa2 57#include "AliMUONHit.h"
504d0837 58#include "AliMUONGeometry.h"
59#include "AliMUONGeometryTransformer.h"
d4bb94a1 60#include "AliMUONGeometryBuilder.h"
e118b27e 61#include "AliMUONCommonGeometryBuilder.h"
d1cd2474 62#include "AliMUONVGeometryBuilder.h"
a19e2543 63#include "AliMUONRawWriter.h"
8c343c7c 64#include "AliLog.h"
a9e2aefa 65
68585390 66#include "AliMUONSDigitizerV2.h"
67#include "AliMUONDigitizerV3.h"
241560c2 68#include "AliMUONDigitMaker.h"
68585390 69
d5609cfc 70#include "AliMUONSt1GeometryBuilderV2.h"
71#include "AliMUONSt2GeometryBuilderV2.h"
72#include "AliMUONSlatGeometryBuilder.h"
73#include "AliMUONTriggerGeometryBuilder.h"
74
7435e1f8 75#include "AliMUONDigitStoreV1.h"
76#include "AliMUONVTriggerStore.h"
77#include "AliMUONHitStoreV1.h"
78
a9e2aefa 79// Defaults parameters for Z positions of chambers
80// taken from values for "stations" in AliMUON::AliMUON
81// const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
82// and from array "dstation" in AliMUONv1::CreateGeometry
83// Float_t dstation[5]={20., 20., 20, 20., 20.};
84// for tracking chambers,
85// according to (Z1 = zch - dstation) and (Z2 = zch + dstation)
86// for the first and second chambers in the station, respectively,
87// and from "DTPLANES" in AliMUONv1::CreateGeometry
88// const Float_t DTPLANES = 15.;
89// for trigger chambers,
90// according to (Z1 = zch) and (Z2 = zch + DTPLANES)
91// for the first and second chambers in the station, respectively
fe4da5cc 92
13985652 93/// \cond CLASSIMP
94ClassImp(AliMUON)
95/// \endcond
30178c30 96
ce3f5e87 97//__________________________________________________________________
fe4da5cc 98AliMUON::AliMUON()
30178c30 99 : AliDetector(),
100 fNCh(0),
101 fNTrackingCh(0),
30178c30 102 fSplitLevel(0),
103 fChambers(0),
d4bb94a1 104 fGeometryBuilder(0),
30178c30 105 fAccCut(kFALSE),
106 fAccMin(0.),
107 fAccMax(0.),
108 fMaxStepGas(0.),
109 fMaxStepAlu(0.),
110 fMaxDestepGas(0.),
111 fMaxDestepAlu(0.),
112 fMaxIterPad(0),
ced309a5 113 fCurIterPad(0),
68585390 114 fTriggerScalerEvent(kFALSE),
e93b11d0 115 fTriggerResponseV1(kFALSE),
116 fTriggerCoinc44(0),
afb3ccf0 117 fTriggerEffCells(0),
a3249004 118 fDigitizerWithNoise(kTRUE),
241560c2 119 fRawWriter(0x0),
7435e1f8 120 fDigitMaker(0x0),
121 fHitStore(0x0)
fe4da5cc 122{
d19b6003 123/// Default Constructor
124
125 AliDebug(1,Form("default (empty) ctor this=%p",this));
1bd26093 126 fIshunt = 0;
fe4da5cc 127}
30178c30 128
ce3f5e87 129//__________________________________________________________________
9bf406e1 130AliMUON::AliMUON(const char *name, const char* title)
131 : AliDetector(name, title),
30178c30 132 fNCh(AliMUONConstants::NCh()),
133 fNTrackingCh(AliMUONConstants::NTrackingCh()),
30178c30 134 fSplitLevel(0),
135 fChambers(0),
d4bb94a1 136 fGeometryBuilder(0),
30178c30 137 fAccCut(kFALSE),
138 fAccMin(0.),
139 fAccMax(0.),
140 fMaxStepGas(0.1),
141 fMaxStepAlu(0.1),
142 fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200
143 fMaxDestepAlu(-1), // in the calculation of the tracking parameters
144 fMaxIterPad(0),
ced309a5 145 fCurIterPad(0),
e93b11d0 146 fTriggerScalerEvent(kFALSE),
147 fTriggerResponseV1(kFALSE),
148 fTriggerCoinc44(0),
afb3ccf0 149 fTriggerEffCells(0),
a3249004 150 fDigitizerWithNoise(kTRUE),
241560c2 151 fRawWriter(0x0),
7435e1f8 152 fDigitMaker(new AliMUONDigitMaker),
153 fHitStore(0x0)
fe4da5cc 154{
d19b6003 155/// Standard constructor
156
157 AliDebug(1,Form("ctor this=%p",this));
30178c30 158 fIshunt = 0;
a897a37a 159
e939a978 160 //PH SetMarkerColor(kRed);//
e118b27e 161
162 // Geometry builder
163 fGeometryBuilder = new AliMUONGeometryBuilder(this);
164
165 // Common geometry definitions
166 fGeometryBuilder
167 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
168
d5609cfc 169 // By default, add also all the needed geometry builders.
170 // If you want to change this from outside, please use ResetGeometryBuilder
171 // method, followed by AddGeometryBuilder ones.
172
173 AddGeometryBuilder(new AliMUONSt1GeometryBuilderV2(this));
174 AddGeometryBuilder(new AliMUONSt2GeometryBuilderV2(this));
175 AddGeometryBuilder(new AliMUONSlatGeometryBuilder(this));
176 AddGeometryBuilder(new AliMUONTriggerGeometryBuilder(this));
177
178 //
179 // Creating List of Chambers
a9e2aefa 180 Int_t ch;
f665c1ea 181 fChambers = new TObjArray(AliMUONConstants::NCh());
7435e1f8 182 fChambers->SetOwner(kTRUE);
183
a9e2aefa 184 // Loop over stations
f665c1ea 185 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
a9e2aefa 186 // Loop over 2 chambers in the station
ce3f5e87 187 for (Int_t stCH = 0; stCH < 2; stCH++) {
188 //
189 //
190 // Default Parameters for Muon Tracking Stations
191 ch = 2 * st + stCH;
192 if (ch < AliMUONConstants::NTrackingCh()) {
193 fChambers->AddAt(new AliMUONChamber(ch),ch);
194 } else {
504d0837 195 fChambers->AddAt(new AliMUONChamberTrigger(ch, GetGeometryTransformer()),ch);
ce3f5e87 196 }
ce3f5e87 197 } // Chamber stCH (0, 1) in
a9e2aefa 198 } // Station st (0...)
e478a3f2 199
fe4da5cc 200}
30178c30 201
ce3f5e87 202//____________________________________________________________________
fe4da5cc 203AliMUON::~AliMUON()
204{
d19b6003 205/// Destructor
206
edee5e63 207 AliDebug(1,Form("dtor this=%p",this));
7435e1f8 208 delete fChambers;
d4bb94a1 209 delete fGeometryBuilder;
d5609cfc 210 delete fRawWriter;
241560c2 211 delete fDigitMaker;
7435e1f8 212 delete fHitStore;
d1cd2474 213}
30178c30 214
d1cd2474 215//_____________________________________________________________________________
216void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
217{
d19b6003 218/// Add the geometry builder to the list
d1cd2474 219
d4bb94a1 220 fGeometryBuilder->AddBuilder(geomBuilder);
a897a37a 221}
c9d10ab5 222
ce3f5e87 223//____________________________________________________________________
fe4da5cc 224void AliMUON::BuildGeometry()
225{
d19b6003 226/// Geometry for event display
c9d10ab5 227
002920d1 228
ae89d471 229// for (Int_t i = 0; i < AliMUONConstants::NCh(); i++)
230// this->Chamber(i).SegmentationModel2(1)->Draw("eventdisplay");// to be check !
231
002920d1 232
fe4da5cc 233}
c9d10ab5 234
504d0837 235//____________________________________________________________________
236const AliMUONGeometry* AliMUON::GetGeometry() const
237{
d19b6003 238/// Return geometry parametrisation
504d0837 239
240 if ( !fGeometryBuilder) {
241 AliWarningStream() << "GeometryBuilder not defined." << std::endl;
242 return 0;
243 }
244
245 return fGeometryBuilder->GetGeometry();
246}
247
248//____________________________________________________________________
249const AliMUONGeometryTransformer* AliMUON::GetGeometryTransformer() const
250{
d19b6003 251/// Return geometry parametrisation
504d0837 252
253 const AliMUONGeometry* kGeometry = GetGeometry();
254
255 if ( !kGeometry) return 0;
256
257 return kGeometry->GetTransformer();
258}
259
ce3f5e87 260//__________________________________________________________________
7435e1f8 261void
262AliMUON::MakeBranch(Option_t* opt)
a897a37a 263{
7435e1f8 264 /// Create branche(s) to hold MUON hits
265 AliDebug(1,"");
266
267 TString sopt(opt);
268 if ( sopt != "H" ) return;
269
270 if (!fHitStore)
271 {
272 fHitStore = new AliMUONHitStoreV1;
ae31c826 273 if ( gAlice->GetMCApp() )
7435e1f8 274 {
275 if ( gAlice->GetMCApp()->GetHitLists() )
276 {
277 // AliStack::PurifyKine needs to be able to loop on our hits
278 // to remap the track numbers.
279 gAlice->GetMCApp()->AddHitList(fHitStore->Collection());
6d2f7cbd 280 }
7435e1f8 281 }
282 }
283
284 TTree* treeH = fLoader->TreeH();
285
286 if (!treeH)
287 {
288 AliFatal("No TreeH");
307d9d04 289 }
7435e1f8 290
291 fHitStore->Connect(*treeH);
292}
293
294//__________________________________________________________________
295void
296AliMUON::SetTreeAddress()
297{
298 /// Set Hits tree address
299
300// if ( gAlice->GetMCApp() && fHitStore )
301// {
302// TList* l = gAlice->GetMCApp()->GetHitLists();
303// if ( l )
304// {
305// TObject* o = l->First();
306// if (o!=fHitStore->HitCollection())
307// {
308// AliError(Form("Something is strange hitcollection=%x",fHitStore->HitCollection()));
309// l->Print();
310// }
311// }
312// }
313}
314
315//_________________________________________________________________
316void
317AliMUON::ResetHits()
318{
319 /// Reset hits
320
321 AliDebug(1,"");
322 if (fHitStore) fHitStore->Clear();
a9e2aefa 323}
324
ce3f5e87 325//_________________________________________________________________
a897a37a 326void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
fe4da5cc 327{
d19b6003 328/// Set the inverse charge slope for chamber id
329
ce3f5e87 330 Int_t i=2*(id-1); //PH ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
331 //PH ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
2682e810 332 ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
333 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
fe4da5cc 334}
ce3f5e87 335//__________________________________________________________________
a897a37a 336void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
fe4da5cc 337{
d19b6003 338/// Set sigma of charge spread for chamber id
339
fe4da5cc 340 Int_t i=2*(id-1);
2682e810 341 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
342 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
fe4da5cc 343}
ce3f5e87 344//___________________________________________________________________
a897a37a 345void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
fe4da5cc 346{
d19b6003 347/// Set integration limits for charge spread
fe4da5cc 348 Int_t i=2*(id-1);
2682e810 349 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
350 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
fe4da5cc 351}
352
ce3f5e87 353//__________________________________________________________________
d09fafb0 354void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
fe4da5cc 355{
d19b6003 356/// Set maximum number for ADCcounts (saturation)
357
fe4da5cc 358 Int_t i=2*(id-1);
2682e810 359 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
360 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
fe4da5cc 361}
d4bb94a1 362
ce3f5e87 363//__________________________________________________________________
a897a37a 364void AliMUON::SetMaxStepGas(Float_t p1)
fe4da5cc 365{
d19b6003 366/// Set stepsize in gas
367
ce3f5e87 368 fMaxStepGas=p1;
fe4da5cc 369}
ce3f5e87 370//__________________________________________________________________
a897a37a 371void AliMUON::SetMaxStepAlu(Float_t p1)
fe4da5cc 372{
d19b6003 373/// Set step size in Alu
374
fe4da5cc 375 fMaxStepAlu=p1;
376}
ce3f5e87 377//__________________________________________________________________
a897a37a 378void AliMUON::SetMaxDestepGas(Float_t p1)
fe4da5cc 379{
d19b6003 380/// Set maximum step size in Gas
381
fe4da5cc 382 fMaxDestepGas=p1;
383}
ce3f5e87 384//__________________________________________________________________
a897a37a 385void AliMUON::SetMaxDestepAlu(Float_t p1)
fe4da5cc 386{
d19b6003 387/// Set maximum step size in Alu
388
ce3f5e87 389 fMaxDestepAlu=p1;
fe4da5cc 390}
d4bb94a1 391
d1cd2474 392//____________________________________________________________________
393Float_t AliMUON::GetMaxStepGas() const
394{
d19b6003 395/// Return stepsize in gas
d1cd2474 396
397 return fMaxStepGas;
398}
399
400//____________________________________________________________________
401Float_t AliMUON::GetMaxStepAlu() const
402{
d19b6003 403/// Return step size in Alu
d1cd2474 404
405 return fMaxStepAlu;
406}
407
408//____________________________________________________________________
409Float_t AliMUON::GetMaxDestepGas() const
410{
d19b6003 411/// Return maximum step size in Gas
d1cd2474 412
413 return fMaxDestepGas;
414}
415
416//____________________________________________________________________
417Float_t AliMUON::GetMaxDestepAlu() const
418{
d19b6003 419/// Return maximum step size in Gas
d1cd2474 420
421 return fMaxDestepAlu;
422}
d4bb94a1 423
ce3f5e87 424//____________________________________________________________________
883746f3 425 void AliMUON::SetAlign(Bool_t align)
a713db22 426{
d19b6003 427/// Set option for alignement to geometry builder
883746f3 428
429 fGeometryBuilder->SetAlign(align);
430}
fe4da5cc 431
ce3f5e87 432//____________________________________________________________________
82d1ac0a 433 void AliMUON::SetAlign(const TString& fileName, Bool_t align)
434{
d19b6003 435/// Set option for alignement to geometry builder
82d1ac0a 436
437 fGeometryBuilder->SetAlign(fileName, align);
438}
439
440//____________________________________________________________________
7435e1f8 441void AliMUON::SetResponseModel(Int_t id, const AliMUONResponse& response)
fe4da5cc 442{
d19b6003 443/// Set the response for chamber id
2682e810 444 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
fe4da5cc 445}
d19b6003 446
ce3f5e87 447//____________________________________________________________________
c92eb8ad 448AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
85a5290f 449{
a3249004 450/// Return digitizer
68585390 451
a3249004 452 return new AliMUONDigitizerV3(manager, fDigitizerWithNoise);
85a5290f 453}
68585390 454
ce3f5e87 455//_____________________________________________________________________
2ab0c725 456void AliMUON::SDigits2Digits()
457{
d19b6003 458/// Write TreeD here only
d963c261 459
d963c261 460 char hname[30];
88cb7938 461 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
462 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
463 fLoader->TreeD()->Reset();
2ab0c725 464}
a9e2aefa 465
d1775029 466//_____________________________________________________________________
467void AliMUON::Hits2SDigits()
468{
a3249004 469/// Perform Hits2Digits using SDigitizerV2
68585390 470
7435e1f8 471 AliMUONSDigitizerV2 sdigitizer;
472 sdigitizer.ExecuteTask();
d1775029 473}
68585390 474
39e39255 475//_____________________________________________________________________
476void AliMUON::Digits2Raw()
477{
d19b6003 478/// Convert digits of the current event to raw data
479
d5609cfc 480 if (!fRawWriter)
481 {
7435e1f8 482 fRawWriter = new AliMUONRawWriter;
483 AliDebug(1,Form("Creating %s",fRawWriter->ClassName()));
d5609cfc 484 if (fTriggerScalerEvent == kTRUE)
485 {
84ceeb06 486 fRawWriter->SetScalersNumbers();
d5609cfc 487 }
488 }
489
7435e1f8 490 fLoader->LoadDigits("READ");
491
492 TTree* treeD = fLoader->TreeD();
493
494 if (!treeD)
495 {
496 AliError("Could not get TreeD");
497 return;
498 }
499
500 AliMUONVTriggerStore* triggerStore = AliMUONVTriggerStore::Create(*treeD);
501 AliMUONVDigitStore* digitStore = AliMUONVDigitStore::Create(*treeD);
502
503 triggerStore->Connect(*treeD,kFALSE);
504 digitStore->Connect(*treeD,kFALSE);
505
506 treeD->GetEvent(0);
507
508 if (!fRawWriter->Digits2Raw(digitStore,triggerStore))
d5609cfc 509 {
510 AliError("pb writting raw data");
511 }
7435e1f8 512
513 delete triggerStore;
514 delete digitStore;
515
516 fLoader->UnloadDigits();
39e39255 517}
68585390 518
241560c2 519//_____________________________________________________________________
520Bool_t AliMUON::Raw2SDigits(AliRawReader* rawReader)
521{
522/// Convert raw data to SDigit
523/// Only for tracking for the moment (ChF)
524
7435e1f8 525 fLoader->LoadDigits("READ");
241560c2 526 if (!fLoader->TreeS()) fLoader->MakeSDigitsContainer();
527
7435e1f8 528 TTree* treeS = fLoader->TreeS();
529
530 AliMUONVDigitStore* sDigitStore = new AliMUONDigitStoreV1;
531 sDigitStore->Connect(*treeS);
532
533 fDigitMaker->Raw2Digits(rawReader,sDigitStore,0x0);
241560c2 534
535 fLoader->WriteSDigits("OVERWRITE");
7435e1f8 536
241560c2 537 fLoader->UnloadSDigits();
538
7435e1f8 539 delete sDigitStore;
540
241560c2 541 return kTRUE;
241560c2 542}
543
ce3f5e87 544//_______________________________________________________________________
3fa6cfdd 545AliLoader* AliMUON::MakeLoader(const char* topfoldername)
546{
d19b6003 547/// Build standard getter (AliLoader type);
548/// if detector wants to use castomized getter, it must overload this method
8c343c7c 549
550 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
551 GetName(),topfoldername));
128843d9 552 fLoader = new AliLoader(GetName(),topfoldername);
241560c2 553
3fa6cfdd 554 return fLoader;
555}
ffd9faa2 556
d5609cfc 557//________________________________________________________________________
558void
559AliMUON::ResetGeometryBuilder()
560{
d19b6003 561/// Only to be used by "experts" wanting to change the geometry builders
562/// to be used.
563/// As the ctor of AliMUON now defines a default geometrybuilder, this
564/// ResetGeometryBuilder() must be called prior to call the
565/// AddGeometryBuilder()
566
d5609cfc 567 delete fGeometryBuilder;
568 fGeometryBuilder = new AliMUONGeometryBuilder(this);
569 fGeometryBuilder
570 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
571}
44b96781 572
573//____________________________________________________________________
574Bool_t AliMUON::GetTriggerResponseV1() const
575{
576///
577/// Returns fTriggerResponseV1
578///
579 return fTriggerResponseV1;
580
581}
582
e93b11d0 583//____________________________________________________________________
584Int_t AliMUON::GetTriggerCoinc44() const
585{
586///
587/// Returns fTriggerCoinc44
588///
589 return fTriggerCoinc44;
590
afb3ccf0 591}
592
593//____________________________________________________________________
88570609 594Bool_t AliMUON::GetTriggerEffCells() const
afb3ccf0 595{
596///
597/// Returns fTriggerEffCells
598///
599 return fTriggerEffCells;
600
e93b11d0 601}
602
a3249004 603//____________________________________________________________________
604Bool_t AliMUON::GetDigitizerWithNoise() const
605{
606///
607/// Returns fDigitizerWithNoise
608///
609 return fDigitizerWithNoise;
610
611}
612