1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-----------------------------------------------------------------------------
21 // AliDetector class for MUON subsystem
22 // providing simulation data management
23 //-----------------------------------------------------------------------------
25 #include "Riostream.h"
30 #include <TDirectory.h>
32 #include <TGeometry.h>
36 #include <TObjArray.h>
38 #include <TObjectTable.h>
40 #include <TParticle.h>
43 #include <TRotMatrix.h>
48 #include <TVirtualMC.h>
50 //#include "AliHeader.h"
51 #include "AliLoader.h"
52 #include "AliRunDigitizer.h"
55 #include "AliRawDataHeaderSim.h"
57 #include "AliMUONChamberTrigger.h"
58 #include "AliMUONConstants.h"
59 #include "AliMUONHit.h"
60 #include "AliMUONGeometry.h"
61 #include "AliMUONGeometryTransformer.h"
62 #include "AliMUONGeometryBuilder.h"
63 #include "AliMUONCommonGeometryBuilder.h"
64 #include "AliMUONVGeometryBuilder.h"
65 #include "AliMUONRawWriter.h"
68 #include "AliMUONSDigitizerV2.h"
69 #include "AliMUONDigitizerV3.h"
70 #include "AliMUONDigitMaker.h"
72 #include "AliMUONSt1GeometryBuilderV2.h"
73 #include "AliMUONSt2GeometryBuilderV2.h"
74 #include "AliMUONSlatGeometryBuilder.h"
75 #include "AliMUONTriggerGeometryBuilder.h"
77 #include "AliMUONDigitStoreV1.h"
78 #include "AliMUONVTriggerStore.h"
79 #include "AliMUONHitStoreV1.h"
81 // Defaults parameters for Z positions of chambers
82 // taken from values for "stations" in AliMUON::AliMUON
83 // const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
84 // and from array "dstation" in AliMUONv1::CreateGeometry
85 // Float_t dstation[5]={20., 20., 20, 20., 20.};
86 // for tracking chambers,
87 // according to (Z1 = zch - dstation) and (Z2 = zch + dstation)
88 // for the first and second chambers in the station, respectively,
89 // and from "DTPLANES" in AliMUONv1::CreateGeometry
90 // const Float_t DTPLANES = 15.;
91 // for trigger chambers,
92 // according to (Z1 = zch) and (Z2 = zch + DTPLANES)
93 // for the first and second chambers in the station, respectively
99 //__________________________________________________________________
116 fTriggerScalerEvent(kFALSE),
117 fTriggerResponseV1(kFALSE),
120 fDigitizerWithNoise(1),
121 fIsTailEffect(kTRUE),
125 fDigitStoreConcreteClassName()
127 /// Default Constructor
129 AliDebug(1,Form("default (empty) ctor this=%p",this));
133 //__________________________________________________________________
134 AliMUON::AliMUON(const char *name, const char* title)
135 : AliDetector(name, title),
136 fNCh(AliMUONConstants::NCh()),
137 fNTrackingCh(AliMUONConstants::NTrackingCh()),
146 fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200
147 fMaxDestepAlu(-1), // in the calculation of the tracking parameters
150 fTriggerScalerEvent(kFALSE),
151 fTriggerResponseV1(kFALSE),
154 fDigitizerWithNoise(1),
155 fIsTailEffect(kTRUE),
157 fDigitMaker(new AliMUONDigitMaker),
159 fDigitStoreConcreteClassName("AliMUONDigitStoreV2S")
161 /// Standard constructor
163 AliDebug(1,Form("ctor this=%p",this));
166 //PH SetMarkerColor(kRed);//
169 fGeometryBuilder = new AliMUONGeometryBuilder(this);
171 // Common geometry definitions
173 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
175 // By default, add also all the needed geometry builders.
176 // If you want to change this from outside, please use ResetGeometryBuilder
177 // method, followed by AddGeometryBuilder ones.
179 AddGeometryBuilder(new AliMUONSt1GeometryBuilderV2(this));
180 AddGeometryBuilder(new AliMUONSt2GeometryBuilderV2(this));
181 AddGeometryBuilder(new AliMUONSlatGeometryBuilder(this));
182 AddGeometryBuilder(new AliMUONTriggerGeometryBuilder(this));
185 // Creating List of Chambers
187 fChambers = new TObjArray(AliMUONConstants::NCh());
188 fChambers->SetOwner(kTRUE);
190 // Loop over stations
191 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
192 // Loop over 2 chambers in the station
193 for (Int_t stCH = 0; stCH < 2; stCH++) {
196 // Default Parameters for Muon Tracking Stations
198 if (ch < AliMUONConstants::NTrackingCh()) {
199 fChambers->AddAt(new AliMUONChamber(ch),ch);
201 fChambers->AddAt(new AliMUONChamberTrigger(ch, GetGeometryTransformer()),ch);
203 } // Chamber stCH (0, 1) in
204 } // Station st (0...)
208 //____________________________________________________________________
213 AliDebug(1,Form("dtor this=%p",this));
215 delete fGeometryBuilder;
221 //_____________________________________________________________________________
222 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
224 /// Add the geometry builder to the list
226 fGeometryBuilder->AddBuilder(geomBuilder);
229 //____________________________________________________________________
230 void AliMUON::BuildGeometry()
232 /// Geometry for event display
235 // for (Int_t i = 0; i < AliMUONConstants::NCh(); i++)
236 // this->Chamber(i).SegmentationModel2(1)->Draw("eventdisplay");// to be check !
241 //____________________________________________________________________
242 const AliMUONGeometry* AliMUON::GetGeometry() const
244 /// Return geometry parametrisation
246 if ( !fGeometryBuilder) {
247 AliWarningStream() << "GeometryBuilder not defined." << std::endl;
251 return fGeometryBuilder->GetGeometry();
254 //____________________________________________________________________
255 const AliMUONGeometryTransformer* AliMUON::GetGeometryTransformer() const
257 /// Return geometry parametrisation
259 const AliMUONGeometry* kGeometry = GetGeometry();
261 if ( !kGeometry) return 0;
263 return kGeometry->GetTransformer();
266 //__________________________________________________________________
268 AliMUON::MakeBranch(Option_t* opt)
270 /// Create branche(s) to hold MUON hits
274 if ( sopt != "H" ) return;
278 fHitStore = new AliMUONHitStoreV1;
279 if ( gAlice->GetMCApp() )
281 if ( gAlice->GetMCApp()->GetHitLists() )
283 // AliStack::PurifyKine needs to be able to loop on our hits
284 // to remap the track numbers.
285 gAlice->GetMCApp()->AddHitList(fHitStore->Collection());
290 TTree* treeH = fLoader->TreeH();
294 AliFatal("No TreeH");
297 fHitStore->Connect(*treeH);
300 //__________________________________________________________________
302 AliMUON::SetTreeAddress()
304 /// Set Hits tree address
306 // if ( gAlice->GetMCApp() && fHitStore )
308 // TList* l = gAlice->GetMCApp()->GetHitLists();
311 // TObject* o = l->First();
312 // if (o!=fHitStore->HitCollection())
314 // AliError(Form("Something is strange hitcollection=%x",fHitStore->HitCollection()));
321 //_________________________________________________________________
328 if (fHitStore) fHitStore->Clear();
331 //_________________________________________________________________
332 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
334 /// Set the inverse charge slope for chamber id
336 Int_t i=2*(id-1); //PH ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
337 //PH ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
338 ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
339 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
341 //__________________________________________________________________
342 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
344 /// Set sigma of charge spread for chamber id
347 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
348 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
350 //___________________________________________________________________
351 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
353 /// Set integration limits for charge spread
355 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
356 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
359 //__________________________________________________________________
360 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
362 /// Set maximum number for ADCcounts (saturation)
365 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
366 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
369 //__________________________________________________________________
370 void AliMUON::SetMaxStepGas(Float_t p1)
372 /// Set stepsize in gas
376 //__________________________________________________________________
377 void AliMUON::SetMaxStepAlu(Float_t p1)
379 /// Set step size in Alu
383 //__________________________________________________________________
384 void AliMUON::SetMaxDestepGas(Float_t p1)
386 /// Set maximum step size in Gas
390 //__________________________________________________________________
391 void AliMUON::SetMaxDestepAlu(Float_t p1)
393 /// Set maximum step size in Alu
398 //____________________________________________________________________
399 Float_t AliMUON::GetMaxStepGas() const
401 /// Return stepsize in gas
406 //____________________________________________________________________
407 Float_t AliMUON::GetMaxStepAlu() const
409 /// Return step size in Alu
414 //____________________________________________________________________
415 Float_t AliMUON::GetMaxDestepGas() const
417 /// Return maximum step size in Gas
419 return fMaxDestepGas;
422 //____________________________________________________________________
423 Float_t AliMUON::GetMaxDestepAlu() const
425 /// Return maximum step size in Gas
427 return fMaxDestepAlu;
430 //____________________________________________________________________
431 void AliMUON::SetAlign(Bool_t align)
433 /// Set option for alignement to geometry builder
435 fGeometryBuilder->SetAlign(align);
438 //____________________________________________________________________
439 void AliMUON::SetAlign(const TString& fileName, Bool_t align)
441 /// Set option for alignement to geometry builder
443 fGeometryBuilder->SetAlign(fileName, align);
446 //____________________________________________________________________
447 void AliMUON::SetResponseModel(Int_t id, const AliMUONResponse& response)
449 /// Set the response for chamber id
450 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
453 //____________________________________________________________________
454 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
458 return new AliMUONDigitizerV3(manager, fDigitizerWithNoise);
461 //_____________________________________________________________________
462 void AliMUON::SDigits2Digits()
464 /// Write TreeD here only
467 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
468 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
469 fLoader->TreeD()->Reset();
472 //_____________________________________________________________________
473 void AliMUON::Hits2SDigits()
475 /// Perform Hits2Digits using SDigitizerV2
477 AliMUONSDigitizerV2 sdigitizer;
478 sdigitizer.ExecuteTask();
481 //_____________________________________________________________________
482 void AliMUON::Digits2Raw()
484 /// Convert digits of the current event to raw data
486 AliRawDataHeaderSim header;
490 fRawWriter = new AliMUONRawWriter;
491 AliDebug(1,Form("Creating %s",fRawWriter->ClassName()));
492 if (fTriggerScalerEvent == kTRUE)
494 fRawWriter->SetScalersNumbers();
498 fLoader->LoadDigits("READ");
500 TTree* treeD = fLoader->TreeD();
504 AliError("Could not get TreeD");
508 AliMUONVTriggerStore* triggerStore = AliMUONVTriggerStore::Create(*treeD);
509 AliMUONVDigitStore* digitStore = AliMUONVDigitStore::Create(*treeD);
511 triggerStore->Connect(*treeD,kFALSE);
512 digitStore->Connect(*treeD,kFALSE);
516 fRawWriter->SetHeader(header);
517 if (!fRawWriter->Digits2Raw(digitStore,triggerStore))
519 AliError("pb writting raw data");
525 fLoader->UnloadDigits();
528 //_____________________________________________________________________
529 Bool_t AliMUON::Raw2SDigits(AliRawReader* rawReader)
531 /// Convert raw data to SDigit
532 /// Only for tracking for the moment (ChF)
534 fLoader->LoadDigits("READ");
535 if (!fLoader->TreeS()) fLoader->MakeSDigitsContainer();
537 TTree* treeS = fLoader->TreeS();
539 AliMUONVDigitStore* sDigitStore = new AliMUONDigitStoreV1;
540 sDigitStore->Connect(*treeS);
542 fDigitMaker->Raw2Digits(rawReader,sDigitStore,0x0);
544 fLoader->WriteSDigits("OVERWRITE");
546 fLoader->UnloadSDigits();
553 //_______________________________________________________________________
554 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
556 /// Build standard getter (AliLoader type);
557 /// if detector wants to use castomized getter, it must overload this method
559 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
560 GetName(),topfoldername));
561 fLoader = new AliLoader(GetName(),topfoldername);
566 //________________________________________________________________________
568 AliMUON::ResetGeometryBuilder()
570 /// Only to be used by "experts" wanting to change the geometry builders
572 /// As the ctor of AliMUON now defines a default geometrybuilder, this
573 /// ResetGeometryBuilder() must be called prior to call the
574 /// AddGeometryBuilder()
576 delete fGeometryBuilder;
577 fGeometryBuilder = new AliMUONGeometryBuilder(this);
579 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
582 //____________________________________________________________________
583 Bool_t AliMUON::GetTriggerResponseV1() const
586 /// Returns fTriggerResponseV1
588 return fTriggerResponseV1;
592 //____________________________________________________________________
593 Int_t AliMUON::GetTriggerCoinc44() const
596 /// Returns fTriggerCoinc44
598 return fTriggerCoinc44;
602 //____________________________________________________________________
603 Bool_t AliMUON::GetTriggerEffCells() const
606 /// Returns fTriggerEffCells
608 return fTriggerEffCells;
612 //____________________________________________________________________
613 Int_t AliMUON::GetDigitizerWithNoise() const
616 /// Returns fDigitizerWithNoise
618 return fDigitizerWithNoise;
622 //____________________________________________________________________
623 Bool_t AliMUON::UsingFastTrackerDecoder() const
625 /// Checks to see if we are using the fast decoder for tracker DDL streams.
627 if ( ! fDigitMaker ) {
628 AliError("Digit maker is not instantiated.");
632 return fDigitMaker->UsingFastTrackerDecoder();
635 //____________________________________________________________________
636 Bool_t AliMUON::UsingFastTriggerDecoder() const
638 /// Checks to see if we are using the fast decoder for trigger DDL streams.
640 if ( ! fDigitMaker ) {
641 AliError("Digit maker is not instantiated.");
645 return fDigitMaker->UsingFastTriggerDecoder();
648 //____________________________________________________________________
649 void AliMUON::SetFastTrackerDecoder(Bool_t useFastDecoder)
651 /// Set fast raw data decoder
653 if ( ! fDigitMaker ) {
654 AliError("Digit maker is not instantiated.");
658 fDigitMaker->SetFastTrackerDecoder(useFastDecoder);
661 //____________________________________________________________________
662 void AliMUON::SetFastTriggerDecoder(Bool_t useFastDecoder)
664 /// Set fast raw data decoder
666 if ( ! fDigitMaker ) {
667 AliError("Digit maker is not instantiated.");
671 fDigitMaker->SetFastTriggerDecoder(useFastDecoder);