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