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