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 "AliCDBManager.h"
53 #include "AliRunDigitizer.h"
56 #include "AliRawDataHeaderSim.h"
58 #include "AliMUONChamberTrigger.h"
59 #include "AliMUONConstants.h"
60 #include "AliMUONHit.h"
61 #include "AliMUONGeometry.h"
62 #include "AliMUONGeometryTransformer.h"
63 #include "AliMUONGeometryBuilder.h"
64 #include "AliMUONCommonGeometryBuilder.h"
65 #include "AliMUONVGeometryBuilder.h"
66 #include "AliMUONRawWriter.h"
69 #include "AliMUONSDigitizerV2.h"
70 #include "AliMUONDigitizerV3.h"
71 #include "AliMUONDigitMaker.h"
72 #include "AliMUONCalibrationData.h"
74 #include "AliMUONSt1GeometryBuilderV2.h"
75 #include "AliMUONSt2GeometryBuilderV2.h"
76 #include "AliMUONSlatGeometryBuilder.h"
77 #include "AliMUONTriggerGeometryBuilder.h"
79 #include "AliMUONDigitStoreV1.h"
80 #include "AliMUONVTriggerStore.h"
81 #include "AliMUONHitStoreV1.h"
83 // Defaults parameters for Z positions of chambers
84 // taken from values for "stations" in AliMUON::AliMUON
85 // const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
86 // and from array "dstation" in AliMUONv1::CreateGeometry
87 // Float_t dstation[5]={20., 20., 20, 20., 20.};
88 // for tracking chambers,
89 // according to (Z1 = zch - dstation) and (Z2 = zch + dstation)
90 // for the first and second chambers in the station, respectively,
91 // and from "DTPLANES" in AliMUONv1::CreateGeometry
92 // const Float_t DTPLANES = 15.;
93 // for trigger chambers,
94 // according to (Z1 = zch) and (Z2 = zch + DTPLANES)
95 // for the first and second chambers in the station, respectively
101 //__________________________________________________________________
118 fTriggerScalerEvent(kFALSE),
119 fTriggerResponseV1(kFALSE),
122 fDigitizerWithNoise(1),
123 fIsTailEffect(kTRUE),
127 fDigitStoreConcreteClassName(),
128 fCalibrationData(0x0)
130 /// Default Constructor
132 AliDebug(1,Form("default (empty) ctor this=%p",this));
136 //__________________________________________________________________
137 AliMUON::AliMUON(const char *name, const char* title)
138 : AliDetector(name, title),
139 fNCh(AliMUONConstants::NCh()),
140 fNTrackingCh(AliMUONConstants::NTrackingCh()),
149 fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200
150 fMaxDestepAlu(-1), // in the calculation of the tracking parameters
153 fTriggerScalerEvent(kFALSE),
154 fTriggerResponseV1(kFALSE),
157 fDigitizerWithNoise(1),
158 fIsTailEffect(kTRUE),
160 fDigitMaker(new AliMUONDigitMaker),
162 fDigitStoreConcreteClassName("AliMUONDigitStoreV2S"),
166 /// Standard constructor
168 AliDebug(1,Form("ctor this=%p",this));
171 //PH SetMarkerColor(kRed);//
174 fGeometryBuilder = new AliMUONGeometryBuilder(this);
176 // Common geometry definitions
178 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
180 // By default, add also all the needed geometry builders.
181 // If you want to change this from outside, please use ResetGeometryBuilder
182 // method, followed by AddGeometryBuilder ones.
184 AddGeometryBuilder(new AliMUONSt1GeometryBuilderV2(this));
185 AddGeometryBuilder(new AliMUONSt2GeometryBuilderV2(this));
186 AddGeometryBuilder(new AliMUONSlatGeometryBuilder(this));
187 AddGeometryBuilder(new AliMUONTriggerGeometryBuilder(this));
190 // Creating List of Chambers
192 fChambers = new TObjArray(AliMUONConstants::NCh());
193 fChambers->SetOwner(kTRUE);
195 // Loop over stations
196 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
197 // Loop over 2 chambers in the station
198 for (Int_t stCH = 0; stCH < 2; stCH++) {
201 // Default Parameters for Muon Tracking Stations
203 if (ch < AliMUONConstants::NTrackingCh()) {
204 fChambers->AddAt(new AliMUONChamber(ch),ch);
206 fChambers->AddAt(new AliMUONChamberTrigger(ch, GetGeometryTransformer()),ch);
208 } // Chamber stCH (0, 1) in
209 } // Station st (0...)
211 Int_t runnumber = AliCDBManager::Instance()->GetRun();
213 fCalibrationData = new AliMUONCalibrationData(runnumber);
216 //____________________________________________________________________
221 AliDebug(1,Form("dtor this=%p",this));
223 delete fGeometryBuilder;
227 delete fCalibrationData;
230 //_____________________________________________________________________________
231 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
233 /// Add the geometry builder to the list
235 fGeometryBuilder->AddBuilder(geomBuilder);
238 //____________________________________________________________________
239 void AliMUON::BuildGeometry()
241 /// Geometry for event display
244 // for (Int_t i = 0; i < AliMUONConstants::NCh(); i++)
245 // this->Chamber(i).SegmentationModel2(1)->Draw("eventdisplay");// to be check !
250 //____________________________________________________________________
251 const AliMUONGeometry* AliMUON::GetGeometry() const
253 /// Return geometry parametrisation
255 if ( !fGeometryBuilder) {
256 AliWarningStream() << "GeometryBuilder not defined." << std::endl;
260 return fGeometryBuilder->GetGeometry();
263 //____________________________________________________________________
264 const AliMUONGeometryTransformer* AliMUON::GetGeometryTransformer() const
266 /// Return geometry parametrisation
268 const AliMUONGeometry* kGeometry = GetGeometry();
270 if ( !kGeometry) return 0;
272 return kGeometry->GetTransformer();
275 //__________________________________________________________________
277 AliMUON::MakeBranch(Option_t* opt)
279 /// Create branche(s) to hold MUON hits
283 if ( sopt != "H" ) return;
287 fHitStore = new AliMUONHitStoreV1;
288 if ( gAlice->GetMCApp() )
290 if ( gAlice->GetMCApp()->GetHitLists() )
292 // AliStack::PurifyKine needs to be able to loop on our hits
293 // to remap the track numbers.
294 gAlice->GetMCApp()->AddHitList(fHitStore->Collection());
299 TTree* treeH = fLoader->TreeH();
303 AliFatal("No TreeH");
306 fHitStore->Connect(*treeH);
309 //__________________________________________________________________
311 AliMUON::SetTreeAddress()
313 /// Set Hits tree address
315 // if ( gAlice->GetMCApp() && fHitStore )
317 // TList* l = gAlice->GetMCApp()->GetHitLists();
320 // TObject* o = l->First();
321 // if (o!=fHitStore->HitCollection())
323 // AliError(Form("Something is strange hitcollection=%x",fHitStore->HitCollection()));
330 //_________________________________________________________________
337 if (fHitStore) fHitStore->Clear();
340 //_________________________________________________________________
341 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
343 /// Set the inverse charge slope for chamber id
345 Int_t i=2*(id-1); //PH ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
346 //PH ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
347 ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
348 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
350 //__________________________________________________________________
351 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
353 /// Set sigma of charge spread for chamber id
356 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
357 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
359 //___________________________________________________________________
360 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
362 /// Set integration limits for charge spread
364 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
365 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
368 //__________________________________________________________________
369 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
371 /// Set maximum number for ADCcounts (saturation)
374 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
375 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
378 //__________________________________________________________________
379 void AliMUON::SetMaxStepGas(Float_t p1)
381 /// Set stepsize in gas
385 //__________________________________________________________________
386 void AliMUON::SetMaxStepAlu(Float_t p1)
388 /// Set step size in Alu
392 //__________________________________________________________________
393 void AliMUON::SetMaxDestepGas(Float_t p1)
395 /// Set maximum step size in Gas
399 //__________________________________________________________________
400 void AliMUON::SetMaxDestepAlu(Float_t p1)
402 /// Set maximum step size in Alu
407 //____________________________________________________________________
408 Float_t AliMUON::GetMaxStepGas() const
410 /// Return stepsize in gas
415 //____________________________________________________________________
416 Float_t AliMUON::GetMaxStepAlu() const
418 /// Return step size in Alu
423 //____________________________________________________________________
424 Float_t AliMUON::GetMaxDestepGas() const
426 /// Return maximum step size in Gas
428 return fMaxDestepGas;
431 //____________________________________________________________________
432 Float_t AliMUON::GetMaxDestepAlu() const
434 /// Return maximum step size in Gas
436 return fMaxDestepAlu;
439 //____________________________________________________________________
440 void AliMUON::SetAlign(Bool_t align)
442 /// Set option for alignement to geometry builder
444 fGeometryBuilder->SetAlign(align);
447 //____________________________________________________________________
448 void AliMUON::SetAlign(const TString& fileName, Bool_t align)
450 /// Set option for alignement to geometry builder
452 fGeometryBuilder->SetAlign(fileName, align);
455 //____________________________________________________________________
456 void AliMUON::SetResponseModel(Int_t id, const AliMUONResponse& response)
458 /// Set the response for chamber id
459 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
462 //____________________________________________________________________
463 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
467 AliMUONDigitizerV3* digitizer = new AliMUONDigitizerV3(manager, fDigitizerWithNoise);
468 digitizer->SetCalibrationData(fCalibrationData);
472 //_____________________________________________________________________
473 void AliMUON::SDigits2Digits()
475 /// Write TreeD here only
478 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
479 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
480 fLoader->TreeD()->Reset();
483 //_____________________________________________________________________
484 void AliMUON::Hits2SDigits()
486 /// Perform Hits2Digits using SDigitizerV2
488 AliMUONSDigitizerV2 sdigitizer;
489 sdigitizer.ExecuteTask();
492 //_____________________________________________________________________
493 void AliMUON::Digits2Raw()
495 /// Convert digits of the current event to raw data
497 AliRawDataHeaderSim header;
501 fRawWriter = new AliMUONRawWriter;
502 AliDebug(1,Form("Creating %s",fRawWriter->ClassName()));
503 if (fTriggerScalerEvent == kTRUE)
505 fRawWriter->SetScalersNumbers();
509 fLoader->LoadDigits("READ");
511 TTree* treeD = fLoader->TreeD();
515 AliError("Could not get TreeD");
519 AliMUONVTriggerStore* triggerStore = AliMUONVTriggerStore::Create(*treeD);
520 AliMUONVDigitStore* digitStore = AliMUONVDigitStore::Create(*treeD);
522 triggerStore->Connect(*treeD,kFALSE);
523 digitStore->Connect(*treeD,kFALSE);
527 fRawWriter->SetHeader(header);
528 if (!fRawWriter->Digits2Raw(digitStore,triggerStore))
530 AliError("pb writting raw data");
536 fLoader->UnloadDigits();
539 //_____________________________________________________________________
540 Bool_t AliMUON::Raw2SDigits(AliRawReader* rawReader)
542 /// Convert raw data to SDigit
544 fLoader->LoadDigits("READ");
545 if (!fLoader->TreeS()) fLoader->MakeSDigitsContainer();
547 TTree* treeS = fLoader->TreeS();
549 AliMUONVDigitStore* sDigitStore = new AliMUONDigitStoreV1;
550 sDigitStore->Connect(*treeS);
552 fDigitMaker->Raw2Digits(rawReader,sDigitStore,0x0);
554 fLoader->WriteSDigits("OVERWRITE");
556 fLoader->UnloadSDigits();
563 //_______________________________________________________________________
564 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
566 /// Build standard getter (AliLoader type);
567 /// if detector wants to use castomized getter, it must overload this method
569 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
570 GetName(),topfoldername));
571 fLoader = new AliLoader(GetName(),topfoldername);
576 //________________________________________________________________________
578 AliMUON::ResetGeometryBuilder()
580 /// Only to be used by "experts" wanting to change the geometry builders
582 /// As the ctor of AliMUON now defines a default geometrybuilder, this
583 /// ResetGeometryBuilder() must be called prior to call the
584 /// AddGeometryBuilder()
586 delete fGeometryBuilder;
587 fGeometryBuilder = new AliMUONGeometryBuilder(this);
589 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
592 //____________________________________________________________________
593 Bool_t AliMUON::GetTriggerResponseV1() const
596 /// Returns fTriggerResponseV1
598 return fTriggerResponseV1;
602 //____________________________________________________________________
603 Int_t AliMUON::GetTriggerCoinc44() const
606 /// Returns fTriggerCoinc44
608 return fTriggerCoinc44;
612 //____________________________________________________________________
613 Bool_t AliMUON::GetTriggerEffCells() const
616 /// Returns fTriggerEffCells
618 return fTriggerEffCells;
622 //____________________________________________________________________
623 Int_t AliMUON::GetDigitizerWithNoise() const
626 /// Returns fDigitizerWithNoise
628 return fDigitizerWithNoise;
632 //____________________________________________________________________
633 Bool_t AliMUON::UsingFastTrackerDecoder() const
635 /// Checks to see if we are using the fast decoder for tracker DDL streams.
637 if ( ! fDigitMaker ) {
638 AliError("Digit maker is not instantiated.");
642 return fDigitMaker->UsingFastTrackerDecoder();
645 //____________________________________________________________________
646 Bool_t AliMUON::UsingFastTriggerDecoder() const
648 /// Checks to see if we are using the fast decoder for trigger DDL streams.
650 if ( ! fDigitMaker ) {
651 AliError("Digit maker is not instantiated.");
655 return fDigitMaker->UsingFastTriggerDecoder();
658 //____________________________________________________________________
659 void AliMUON::SetFastTrackerDecoder(Bool_t useFastDecoder)
661 /// Set fast raw data decoder
663 if ( ! fDigitMaker ) {
664 AliError("Digit maker is not instantiated.");
668 fDigitMaker->SetFastTrackerDecoder(useFastDecoder);
671 //____________________________________________________________________
672 void AliMUON::SetFastTriggerDecoder(Bool_t useFastDecoder)
674 /// Set fast raw data decoder
676 if ( ! fDigitMaker ) {
677 AliError("Digit maker is not instantiated.");
681 fDigitMaker->SetFastTriggerDecoder(useFastDecoder);