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"
29 #include <TDirectory.h>
33 #include <TObjArray.h>
35 #include <TObjectTable.h>
37 #include <TParticle.h>
40 #include <TRotMatrix.h>
43 #include <TVirtualMC.h>
45 //#include "AliHeader.h"
46 #include "AliLoader.h"
47 #include "AliCDBManager.h"
48 #include "AliRunDigitizer.h"
51 #include "AliRawDataHeaderSim.h"
53 #include "AliMUONChamberTrigger.h"
54 #include "AliMUONConstants.h"
55 #include "AliMUONHit.h"
56 #include "AliMUONGeometry.h"
57 #include "AliMUONGeometryTransformer.h"
58 #include "AliMUONGeometryBuilder.h"
59 #include "AliMUONCommonGeometryBuilder.h"
60 #include "AliMUONVGeometryBuilder.h"
61 #include "AliMUONRawWriter.h"
64 #include "AliMUONSDigitizerV2.h"
65 #include "AliMUONDigitizerV3.h"
66 #include "AliMUONDigitMaker.h"
67 #include "AliMUONCalibrationData.h"
69 #include "AliMUONSt1GeometryBuilderV2.h"
70 #include "AliMUONSt2GeometryBuilderV2.h"
71 #include "AliMUONSlatGeometryBuilder.h"
72 #include "AliMUONTriggerGeometryBuilder.h"
74 #include "AliMUONDigitStoreV1.h"
75 #include "AliMUONVTriggerStore.h"
76 #include "AliMUONHitStoreV1.h"
78 // Defaults parameters for Z positions of chambers
79 // taken from values for "stations" in AliMUON::AliMUON
80 // const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
81 // and from array "dstation" in AliMUONv1::CreateGeometry
82 // Float_t dstation[5]={20., 20., 20, 20., 20.};
83 // for tracking chambers,
84 // according to (Z1 = zch - dstation) and (Z2 = zch + dstation)
85 // for the first and second chambers in the station, respectively,
86 // and from "DTPLANES" in AliMUONv1::CreateGeometry
87 // const Float_t DTPLANES = 15.;
88 // for trigger chambers,
89 // according to (Z1 = zch) and (Z2 = zch + DTPLANES)
90 // for the first and second chambers in the station, respectively
96 //__________________________________________________________________
113 fTriggerScalerEvent(kFALSE),
114 fTriggerResponseV1(kFALSE),
117 fDigitizerWithNoise(1),
118 fIsTailEffect(kTRUE),
122 fDigitStoreConcreteClassName(),
123 fCalibrationData(0x0)
125 /// Default Constructor
127 AliDebug(1,Form("default (empty) ctor this=%p",this));
131 //__________________________________________________________________
132 AliMUON::AliMUON(const char *name, const char* title)
133 : AliDetector(name, title),
134 fNCh(AliMUONConstants::NCh()),
135 fNTrackingCh(AliMUONConstants::NTrackingCh()),
144 fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200
145 fMaxDestepAlu(-1), // in the calculation of the tracking parameters
148 fTriggerScalerEvent(kFALSE),
149 fTriggerResponseV1(kFALSE),
152 fDigitizerWithNoise(1),
153 fIsTailEffect(kTRUE),
155 fDigitMaker(new AliMUONDigitMaker),
157 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...)
206 Int_t runnumber = AliCDBManager::Instance()->GetRun();
208 fCalibrationData = new AliMUONCalibrationData(runnumber);
211 //____________________________________________________________________
216 AliDebug(1,Form("dtor this=%p",this));
218 delete fGeometryBuilder;
222 delete fCalibrationData;
225 //_____________________________________________________________________________
226 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
228 /// Add the geometry builder to the list
230 fGeometryBuilder->AddBuilder(geomBuilder);
233 //____________________________________________________________________
234 const AliMUONGeometry* AliMUON::GetGeometry() const
236 /// Return geometry parametrisation
238 if ( !fGeometryBuilder) {
239 AliWarningStream() << "GeometryBuilder not defined." << std::endl;
243 return fGeometryBuilder->GetGeometry();
246 //____________________________________________________________________
247 const AliMUONGeometryTransformer* AliMUON::GetGeometryTransformer() const
249 /// Return geometry parametrisation
251 const AliMUONGeometry* kGeometry = GetGeometry();
253 if ( !kGeometry) return 0;
255 return kGeometry->GetTransformer();
258 //__________________________________________________________________
260 AliMUON::MakeBranch(Option_t* opt)
262 /// Create branche(s) to hold MUON hits
266 if ( sopt != "H" ) return;
270 fHitStore = new AliMUONHitStoreV1;
271 if ( gAlice->GetMCApp() )
273 if ( gAlice->GetMCApp()->GetHitLists() )
275 // AliStack::PurifyKine needs to be able to loop on our hits
276 // to remap the track numbers.
277 gAlice->GetMCApp()->AddHitList(fHitStore->Collection());
282 TTree* treeH = fLoader->TreeH();
286 AliFatal("No TreeH");
289 fHitStore->Connect(*treeH);
292 //__________________________________________________________________
294 AliMUON::SetTreeAddress()
296 /// Set Hits tree address
298 // if ( gAlice->GetMCApp() && fHitStore )
300 // TList* l = gAlice->GetMCApp()->GetHitLists();
303 // TObject* o = l->First();
304 // if (o!=fHitStore->HitCollection())
306 // AliError(Form("Something is strange hitcollection=%x",fHitStore->HitCollection()));
313 //_________________________________________________________________
320 if (fHitStore) fHitStore->Clear();
323 //_________________________________________________________________
324 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
326 /// Set the inverse charge slope for chamber id
328 Int_t i=2*(id-1); //PH ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
329 //PH ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
330 ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
331 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
333 //__________________________________________________________________
334 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
336 /// Set sigma of charge spread for chamber id
339 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
340 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
342 //___________________________________________________________________
343 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
345 /// Set integration limits for charge spread
347 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
348 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
351 //__________________________________________________________________
352 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
354 /// Set maximum number for ADCcounts (saturation)
357 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
358 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
361 //__________________________________________________________________
362 void AliMUON::SetMaxStepGas(Float_t p1)
364 /// Set stepsize in gas
368 //__________________________________________________________________
369 void AliMUON::SetMaxStepAlu(Float_t p1)
371 /// Set step size in Alu
375 //__________________________________________________________________
376 void AliMUON::SetMaxDestepGas(Float_t p1)
378 /// Set maximum step size in Gas
382 //__________________________________________________________________
383 void AliMUON::SetMaxDestepAlu(Float_t p1)
385 /// Set maximum step size in Alu
390 //____________________________________________________________________
391 Float_t AliMUON::GetMaxStepGas() const
393 /// Return stepsize in gas
398 //____________________________________________________________________
399 Float_t AliMUON::GetMaxStepAlu() const
401 /// Return step size in Alu
406 //____________________________________________________________________
407 Float_t AliMUON::GetMaxDestepGas() const
409 /// Return maximum step size in Gas
411 return fMaxDestepGas;
414 //____________________________________________________________________
415 Float_t AliMUON::GetMaxDestepAlu() const
417 /// Return maximum step size in Gas
419 return fMaxDestepAlu;
422 //____________________________________________________________________
423 void AliMUON::SetAlign(Bool_t align)
425 /// Set option for alignement to geometry builder
427 fGeometryBuilder->SetAlign(align);
430 //____________________________________________________________________
431 void AliMUON::SetAlign(const TString& fileName, Bool_t align)
433 /// Set option for alignement to geometry builder
435 fGeometryBuilder->SetAlign(fileName, align);
438 //____________________________________________________________________
439 void AliMUON::SetResponseModel(Int_t id, const AliMUONResponse& response)
441 /// Set the response for chamber id
442 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
445 //____________________________________________________________________
446 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
450 AliMUONDigitizerV3* digitizer = new AliMUONDigitizerV3(manager, fDigitizerWithNoise);
451 digitizer->SetCalibrationData(fCalibrationData);
455 //_____________________________________________________________________
456 void AliMUON::SDigits2Digits()
458 /// Write TreeD here only
461 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
462 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
463 fLoader->TreeD()->Reset();
466 //_____________________________________________________________________
467 void AliMUON::Hits2SDigits()
469 /// Perform Hits2Digits using SDigitizerV2
471 AliMUONSDigitizerV2 sdigitizer;
472 sdigitizer.ExecuteTask();
475 //_____________________________________________________________________
476 void AliMUON::Digits2Raw()
478 /// Convert digits of the current event to raw data
480 AliRawDataHeaderSim header;
484 fRawWriter = new AliMUONRawWriter;
485 AliDebug(1,Form("Creating %s",fRawWriter->ClassName()));
486 if (fTriggerScalerEvent == kTRUE)
488 fRawWriter->SetScalersNumbers();
492 fLoader->LoadDigits("READ");
494 TTree* treeD = fLoader->TreeD();
498 AliError("Could not get TreeD");
502 AliMUONVTriggerStore* triggerStore = AliMUONVTriggerStore::Create(*treeD);
503 AliMUONVDigitStore* digitStore = AliMUONVDigitStore::Create(*treeD);
505 triggerStore->Connect(*treeD,kFALSE);
506 digitStore->Connect(*treeD,kFALSE);
510 fRawWriter->SetHeader(header);
511 if (!fRawWriter->Digits2Raw(digitStore,triggerStore))
513 AliError("pb writting raw data");
519 fLoader->UnloadDigits();
522 //_____________________________________________________________________
523 Bool_t AliMUON::Raw2SDigits(AliRawReader* rawReader)
525 /// Convert raw data to SDigit
527 fLoader->LoadDigits("READ");
528 if (!fLoader->TreeS()) fLoader->MakeSDigitsContainer();
530 TTree* treeS = fLoader->TreeS();
532 AliMUONVDigitStore* sDigitStore = new AliMUONDigitStoreV1;
533 sDigitStore->Connect(*treeS);
535 fDigitMaker->Raw2Digits(rawReader,sDigitStore,0x0);
537 fLoader->WriteSDigits("OVERWRITE");
539 fLoader->UnloadSDigits();
546 //_______________________________________________________________________
547 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
549 /// Build standard getter (AliLoader type);
550 /// if detector wants to use castomized getter, it must overload this method
552 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
553 GetName(),topfoldername));
554 fLoader = new AliLoader(GetName(),topfoldername);
559 //________________________________________________________________________
561 AliMUON::ResetGeometryBuilder()
563 /// Only to be used by "experts" wanting to change the geometry builders
565 /// As the ctor of AliMUON now defines a default geometrybuilder, this
566 /// ResetGeometryBuilder() must be called prior to call the
567 /// AddGeometryBuilder()
569 delete fGeometryBuilder;
570 fGeometryBuilder = new AliMUONGeometryBuilder(this);
572 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
575 //____________________________________________________________________
576 Bool_t AliMUON::GetTriggerResponseV1() const
579 /// Returns fTriggerResponseV1
581 return fTriggerResponseV1;
585 //____________________________________________________________________
586 Int_t AliMUON::GetTriggerCoinc44() const
589 /// Returns fTriggerCoinc44
591 return fTriggerCoinc44;
595 //____________________________________________________________________
596 Bool_t AliMUON::GetTriggerEffCells() const
599 /// Returns fTriggerEffCells
601 return fTriggerEffCells;
605 //____________________________________________________________________
606 Int_t AliMUON::GetDigitizerWithNoise() const
609 /// Returns fDigitizerWithNoise
611 return fDigitizerWithNoise;
615 //____________________________________________________________________
616 Bool_t AliMUON::UsingFastTrackerDecoder() const
618 /// Checks to see if we are using the fast decoder for tracker DDL streams.
620 if ( ! fDigitMaker ) {
621 AliError("Digit maker is not instantiated.");
625 return fDigitMaker->UsingFastTrackerDecoder();
628 //____________________________________________________________________
629 Bool_t AliMUON::UsingFastTriggerDecoder() const
631 /// Checks to see if we are using the fast decoder for trigger DDL streams.
633 if ( ! fDigitMaker ) {
634 AliError("Digit maker is not instantiated.");
638 return fDigitMaker->UsingFastTriggerDecoder();
641 //____________________________________________________________________
642 void AliMUON::SetFastTrackerDecoder(Bool_t useFastDecoder)
644 /// Set fast raw data decoder
646 if ( ! fDigitMaker ) {
647 AliError("Digit maker is not instantiated.");
651 fDigitMaker->SetFastTrackerDecoder(useFastDecoder);
654 //____________________________________________________________________
655 void AliMUON::SetFastTriggerDecoder(Bool_t useFastDecoder)
657 /// Set fast raw data decoder
659 if ( ! fDigitMaker ) {
660 AliError("Digit maker is not instantiated.");
664 fDigitMaker->SetFastTriggerDecoder(useFastDecoder);