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 **************************************************************************/
21 // AliDetector class for MUON subsystem
22 // providing simulation data management
24 #include "Riostream.h"
29 #include <TDirectory.h>
31 #include <TGeometry.h>
35 #include <TObjArray.h>
37 #include <TObjectTable.h>
39 #include <TParticle.h>
42 #include <TRotMatrix.h>
47 #include <TVirtualMC.h>
49 //#include "AliHeader.h"
50 #include "AliLoader.h"
51 #include "AliRunDigitizer.h"
55 #include "AliMUONChamberTrigger.h"
56 #include "AliMUONConstants.h"
57 #include "AliMUONHit.h"
58 #include "AliMUONRawCluster.h"
59 #include "AliMUONTransientDigit.h"
60 #include "AliMUONGeometry.h"
61 #include "AliMUONGeometryTransformer.h"
62 #include "AliMUONGeometryBuilder.h"
63 #include "AliMUONCommonGeometryBuilder.h"
64 #include "AliMUONVGeometryBuilder.h"
65 #include "AliMUONGeometrySegmentation.h"
66 #include "AliMUONDigitizerv2.h"
67 #include "AliMUONSDigitizerv1.h"
68 #include "AliMUONRawWriter.h"
69 #include "AliMUONSegmentation.h"
72 #include "AliMUONSDigitizerV2.h"
73 #include "AliMUONDigitizerV3.h"
74 #include "AliMUONDigitMaker.h"
76 #include "AliMUONSt1GeometryBuilderV2.h"
77 #include "AliMUONSt2GeometryBuilderV2.h"
78 #include "AliMUONSlatGeometryBuilder.h"
79 #include "AliMUONTriggerGeometryBuilder.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 //__________________________________________________________________
118 fTriggerScalerEvent(kFALSE),
119 fTriggerResponseV1(kFALSE),
128 /// Default Constructor
130 AliDebug(1,Form("default (empty) ctor this=%p",this));
134 //__________________________________________________________________
135 AliMUON::AliMUON(const char *name, const char *title,
136 const char* sDigitizerClassName,
137 const char* digitizerClassName)
138 : AliDetector(name,title),
139 fNCh(AliMUONConstants::NCh()),
140 fNTrackingCh(AliMUONConstants::NTrackingCh()),
151 fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200
152 fMaxDestepAlu(-1), // in the calculation of the tracking parameters
155 fTriggerScalerEvent(kFALSE),
156 fTriggerResponseV1(kFALSE),
159 fSDigitizerType(sDigitizerClassName),
160 fDigitizerType(digitizerClassName),
162 fDigitMaker(new AliMUONDigitMaker(kFALSE))
164 /// Standard constructor
166 AliDebug(1,Form("ctor this=%p",this));
169 SetMarkerColor(kRed);//
172 fGeometryBuilder = new AliMUONGeometryBuilder(this);
174 // Common geometry definitions
176 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
178 // By default, add also all the needed geometry builders.
179 // If you want to change this from outside, please use ResetGeometryBuilder
180 // method, followed by AddGeometryBuilder ones.
182 AddGeometryBuilder(new AliMUONSt1GeometryBuilderV2(this));
183 AddGeometryBuilder(new AliMUONSt2GeometryBuilderV2(this));
184 AddGeometryBuilder(new AliMUONSlatGeometryBuilder(this));
185 AddGeometryBuilder(new AliMUONTriggerGeometryBuilder(this));
188 // Creating List of Chambers
190 fChambers = new TObjArray(AliMUONConstants::NCh());
192 // Loop over stations
193 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
194 // Loop over 2 chambers in the station
195 for (Int_t stCH = 0; stCH < 2; stCH++) {
198 // Default Parameters for Muon Tracking Stations
200 if (ch < AliMUONConstants::NTrackingCh()) {
201 fChambers->AddAt(new AliMUONChamber(ch),ch);
203 fChambers->AddAt(new AliMUONChamberTrigger(ch, GetGeometryTransformer()),ch);
205 } // Chamber stCH (0, 1) in
206 } // Station st (0...)
210 //____________________________________________________________________
215 AliDebug(1,Form("dtor this=%p",this));
224 delete fGeometryBuilder;
225 delete fSegmentation;
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 //__________________________________________________________________
276 void AliMUON::SetTreeAddress()
278 /// Set Hits tree address
280 GetMUONData()->SetLoader(fLoader);
281 // GetMUONData()->MakeBranch("D,S,RC");
282 // GetMUONData()->SetTreeAddress("H,D,S,RC");
283 GetMUONData()->SetTreeAddress("H");
284 if (fHits != GetMUONData()->Hits()) {
285 if ( gAlice->GetMCApp() )
286 if ( gAlice->GetMCApp()->GetHitLists() ) {
287 fHits = GetMUONData()->Hits();
288 gAlice->GetMCApp()->AddHitList(fHits); // For purifyKine, only necessary when Hit list is created in AliMUONData
291 fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector
294 //_________________________________________________________________
295 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
297 /// Set the inverse charge slope for chamber id
299 Int_t i=2*(id-1); //PH ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
300 //PH ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
301 ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
302 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
304 //__________________________________________________________________
305 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
307 /// Set sigma of charge spread for chamber id
310 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
311 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
313 //___________________________________________________________________
314 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
316 /// Set integration limits for charge spread
318 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
319 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
322 //__________________________________________________________________
323 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
325 /// Set maximum number for ADCcounts (saturation)
328 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
329 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
332 //__________________________________________________________________
333 void AliMUON::SetMaxStepGas(Float_t p1)
335 /// Set stepsize in gas
339 //__________________________________________________________________
340 void AliMUON::SetMaxStepAlu(Float_t p1)
342 /// Set step size in Alu
346 //__________________________________________________________________
347 void AliMUON::SetMaxDestepGas(Float_t p1)
349 /// Set maximum step size in Gas
353 //__________________________________________________________________
354 void AliMUON::SetMaxDestepAlu(Float_t p1)
356 /// Set maximum step size in Alu
361 //____________________________________________________________________
362 Float_t AliMUON::GetMaxStepGas() const
364 /// Return stepsize in gas
369 //____________________________________________________________________
370 Float_t AliMUON::GetMaxStepAlu() const
372 /// Return step size in Alu
377 //____________________________________________________________________
378 Float_t AliMUON::GetMaxDestepGas() const
380 /// Return maximum step size in Gas
382 return fMaxDestepGas;
385 //____________________________________________________________________
386 Float_t AliMUON::GetMaxDestepAlu() const
388 /// Return maximum step size in Gas
390 return fMaxDestepAlu;
393 //____________________________________________________________________
394 void AliMUON::SetAlign(Bool_t align)
396 /// Set option for alignement to geometry builder
398 fGeometryBuilder->SetAlign(align);
401 //____________________________________________________________________
402 void AliMUON::SetAlign(const TString& fileName, Bool_t align)
404 /// Set option for alignement to geometry builder
406 fGeometryBuilder->SetAlign(fileName, align);
409 //____________________________________________________________________
410 void AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
412 /// Set the response for chamber id
413 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
416 //____________________________________________________________________
417 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
419 /// FIXME: the selection of the class should be done through a factory
420 /// mechanism. (see also Hits2SDigits()).
422 AliDebug(1, Form("Digitizer used : %s",fDigitizerType.Data()));
424 if ( fDigitizerType == "digitizer:default" ) // NewDigitizerNewTrigger
426 return new AliMUONDigitizerV3(manager,kTRUE);
428 else if ( fDigitizerType == "digitizer:NewDigitizerWONoiseNewTrigger" )
430 return new AliMUONDigitizerV3(manager,kFALSE);
434 AliFatal(Form("Unknown digitizer type : %s",fDigitizerType.Data()));
439 //_____________________________________________________________________
441 AliMUON::SDigitizerType() const
443 /// Return digitizer type
445 return fSDigitizerType;
448 //_____________________________________________________________________
449 void AliMUON::SDigits2Digits()
451 /// Write TreeD here only
454 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
455 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
456 fLoader->TreeD()->Reset();
459 //_____________________________________________________________________
460 void AliMUON::Hits2SDigits()
462 /// FIXME: the selection of the sdigitizer should be done through a
463 /// factory mechanism.
465 AliDebug(1, Form("SDigitizer used : %s",fSDigitizerType.Data()));
467 if ( fSDigitizerType == "sdigitizer:default" )
469 // Adaption of AliMUONSDigitizerv1 to be excuted by the AliSimulation framework
470 AliRunLoader* runLoader = fLoader->GetRunLoader();
471 AliRunDigitizer * manager = new AliRunDigitizer(1,1);
472 manager->SetInputStream(0,runLoader->GetFileName(),AliConfig::GetDefaultEventFolderName());
473 AliMUONDigitizer * dMUON = new AliMUONSDigitizerv1(manager);
474 fLoader->LoadHits("READ");
475 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
476 runLoader->GetEvent(iEvent);
479 fLoader->UnloadHits();
481 else if ( fSDigitizerType == "sdigitizer:AliMUONSDigitizerV2" )
483 TTask* sdigitizer = new AliMUONSDigitizerV2;
484 sdigitizer->ExecuteTask();
488 AliFatal(Form("Unknown sdigitizer classname : %s",fSDigitizerType.Data()));
492 //_____________________________________________________________________
494 AliMUON::DigitizerType() const
496 /// Return digitizer type
498 return fDigitizerType;
501 //_____________________________________________________________________
502 void AliMUON::Digits2Raw()
504 /// Convert digits of the current event to raw data
508 fRawWriter = new AliMUONRawWriter(fMUONData);
509 if (fTriggerScalerEvent == kTRUE)
511 fRawWriter->SetScalersNumbers();
515 if (!fRawWriter->Digits2Raw())
517 AliError("pb writting raw data");
521 //_____________________________________________________________________
522 Bool_t AliMUON::Raw2SDigits(AliRawReader* rawReader)
524 /// Convert raw data to SDigit
525 /// Only for tracking for the moment (ChF)
527 //fLoader->LoadDigits("READ");
528 if (!fLoader->TreeS()) fLoader->MakeSDigitsContainer();
530 fMUONData->MakeBranch("S");
531 fMUONData->SetTreeAddress("S");
532 fDigitMaker->Raw2Digits(rawReader);
533 fMUONData->Fill("S");
535 fLoader->WriteSDigits("OVERWRITE");
536 fMUONData->ResetSDigits();
537 fLoader->UnloadSDigits();
543 //_______________________________________________________________________
544 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
546 /// Build standard getter (AliLoader type);
547 /// if detector wants to use castomized getter, it must overload this method
549 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
550 GetName(),topfoldername));
551 fLoader = new AliLoader(GetName(),topfoldername);
552 fMUONData = new AliMUONData(fLoader,GetName(),GetName());
553 fMUONData->SetSplitLevel(fSplitLevel);
555 fDigitMaker->SetMUONData(fMUONData);
559 //_______________________________________________________________________
561 AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
563 /// Return rawcluster (icluster) for chamber ichamber and cathode icathod
566 TClonesArray *muonRawCluster = GetMUONData()->RawClusters(ichamber);
568 TTree *treeR = fLoader->TreeR();
569 Int_t nent=(Int_t)treeR->GetEntries();
570 treeR->GetEvent(nent-2+icathod-1);
571 //treeR->GetEvent(icathod);
572 //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
574 AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
575 //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
580 //________________________________________________________________________
582 AliMUON::ResetGeometryBuilder()
584 /// Only to be used by "experts" wanting to change the geometry builders
586 /// As the ctor of AliMUON now defines a default geometrybuilder, this
587 /// ResetGeometryBuilder() must be called prior to call the
588 /// AddGeometryBuilder()
590 delete fGeometryBuilder;
591 fGeometryBuilder = new AliMUONGeometryBuilder(this);
593 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
596 //____________________________________________________________________
597 Bool_t AliMUON::GetTriggerResponseV1() const
600 /// Returns fTriggerResponseV1
602 return fTriggerResponseV1;
606 //____________________________________________________________________
607 Int_t AliMUON::GetTriggerCoinc44() const
610 /// Returns fTriggerCoinc44
612 return fTriggerCoinc44;
616 //____________________________________________________________________
617 Bool_t AliMUON::GetTriggerEffCells() const
620 /// Returns fTriggerEffCells
622 return fTriggerEffCells;