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 "AliMUONTriggerCircuitNew.h"
61 #include "AliMUONGeometry.h"
62 #include "AliMUONGeometryTransformer.h"
63 #include "AliMUONGeometryBuilder.h"
64 #include "AliMUONCommonGeometryBuilder.h"
65 #include "AliMUONVGeometryBuilder.h"
66 #include "AliMUONGeometrySegmentation.h"
67 #include "AliMUONDigitizerv2.h"
68 #include "AliMUONSDigitizerv1.h"
69 #include "AliMUONRawWriter.h"
70 #include "AliMUONSegmentation.h"
73 #include "AliMUONSDigitizerV2.h"
74 #include "AliMUONDigitizerV3.h"
75 #include "AliMUONDigitMaker.h"
77 #include "AliMUONSt1GeometryBuilderV2.h"
78 #include "AliMUONSt2GeometryBuilderV2.h"
79 #include "AliMUONSlatGeometryBuilder.h"
80 #include "AliMUONTriggerGeometryBuilder.h"
82 // Defaults parameters for Z positions of chambers
83 // taken from values for "stations" in AliMUON::AliMUON
84 // const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
85 // and from array "dstation" in AliMUONv1::CreateGeometry
86 // Float_t dstation[5]={20., 20., 20, 20., 20.};
87 // for tracking chambers,
88 // according to (Z1 = zch - dstation) and (Z2 = zch + dstation)
89 // for the first and second chambers in the station, respectively,
90 // and from "DTPLANES" in AliMUONv1::CreateGeometry
91 // const Float_t DTPLANES = 15.;
92 // for trigger chambers,
93 // according to (Z1 = zch) and (Z2 = zch + DTPLANES)
94 // for the first and second chambers in the station, respectively
100 //__________________________________________________________________
108 fTriggerCircuitsNew(0),
120 fTriggerScalerEvent(kFALSE),
121 fTriggerResponseV1(kFALSE),
130 /// Default Constructor
132 AliDebug(1,Form("default (empty) ctor this=%p",this));
136 //__________________________________________________________________
137 AliMUON::AliMUON(const char *name, const char *title,
138 const char* sDigitizerClassName,
139 const char* digitizerClassName)
140 : AliDetector(name,title),
141 fNCh(AliMUONConstants::NCh()),
142 fNTrackingCh(AliMUONConstants::NTrackingCh()),
146 fTriggerCircuitsNew(0),
154 fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200
155 fMaxDestepAlu(-1), // in the calculation of the tracking parameters
158 fTriggerScalerEvent(kFALSE),
159 fTriggerResponseV1(kFALSE),
162 fSDigitizerType(sDigitizerClassName),
163 fDigitizerType(digitizerClassName),
165 fDigitMaker(new AliMUONDigitMaker(kFALSE))
167 /// Standard constructor
169 AliDebug(1,Form("ctor this=%p",this));
172 SetMarkerColor(kRed);//
175 fGeometryBuilder = new AliMUONGeometryBuilder(this);
177 // Common geometry definitions
179 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
181 // By default, add also all the needed geometry builders.
182 // If you want to change this from outside, please use ResetGeometryBuilder
183 // method, followed by AddGeometryBuilder ones.
185 AddGeometryBuilder(new AliMUONSt1GeometryBuilderV2(this));
186 AddGeometryBuilder(new AliMUONSt2GeometryBuilderV2(this));
187 AddGeometryBuilder(new AliMUONSlatGeometryBuilder(this));
188 AddGeometryBuilder(new AliMUONTriggerGeometryBuilder(this));
191 // Creating List of Chambers
193 fChambers = new TObjArray(AliMUONConstants::NCh());
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...)
212 fTriggerCircuitsNew = new TObjArray(AliMUONConstants::NTriggerCircuit());
213 for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
214 fTriggerCircuitsNew->AddAt(new AliMUONTriggerCircuitNew(),circ);
218 //____________________________________________________________________
223 AliDebug(1,Form("dtor this=%p",this));
230 if (fTriggerCircuitsNew){
231 fTriggerCircuitsNew->Delete();
232 delete fTriggerCircuitsNew;
236 delete fGeometryBuilder;
237 delete fSegmentation;
242 //_____________________________________________________________________________
243 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
245 /// Add the geometry builder to the list
247 fGeometryBuilder->AddBuilder(geomBuilder);
250 //____________________________________________________________________
251 void AliMUON::BuildGeometry()
253 /// Geometry for event display
256 // for (Int_t i = 0; i < AliMUONConstants::NCh(); i++)
257 // this->Chamber(i).SegmentationModel2(1)->Draw("eventdisplay");// to be check !
262 //____________________________________________________________________
263 const AliMUONGeometry* AliMUON::GetGeometry() const
265 /// Return geometry parametrisation
267 if ( !fGeometryBuilder) {
268 AliWarningStream() << "GeometryBuilder not defined." << std::endl;
272 return fGeometryBuilder->GetGeometry();
275 //____________________________________________________________________
276 const AliMUONGeometryTransformer* AliMUON::GetGeometryTransformer() const
278 /// Return geometry parametrisation
280 const AliMUONGeometry* kGeometry = GetGeometry();
282 if ( !kGeometry) return 0;
284 return kGeometry->GetTransformer();
287 //__________________________________________________________________
288 void AliMUON::SetTreeAddress()
290 /// Set Hits tree address
292 GetMUONData()->SetLoader(fLoader);
293 // GetMUONData()->MakeBranch("D,S,RC");
294 // GetMUONData()->SetTreeAddress("H,D,S,RC");
295 GetMUONData()->SetTreeAddress("H");
296 if (fHits != GetMUONData()->Hits()) {
297 if ( gAlice->GetMCApp() )
298 if ( gAlice->GetMCApp()->GetHitLists() ) {
299 fHits = GetMUONData()->Hits();
300 gAlice->GetMCApp()->AddHitList(fHits); // For purifyKine, only necessary when Hit list is created in AliMUONData
303 fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector
306 //_________________________________________________________________
307 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
309 /// Set the inverse charge slope for chamber id
311 Int_t i=2*(id-1); //PH ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
312 //PH ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
313 ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
314 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
316 //__________________________________________________________________
317 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
319 /// Set sigma of charge spread for chamber id
322 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
323 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
325 //___________________________________________________________________
326 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
328 /// Set integration limits for charge spread
330 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
331 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
334 //__________________________________________________________________
335 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
337 /// Set maximum number for ADCcounts (saturation)
340 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
341 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
344 //__________________________________________________________________
345 void AliMUON::SetMaxStepGas(Float_t p1)
347 /// Set stepsize in gas
351 //__________________________________________________________________
352 void AliMUON::SetMaxStepAlu(Float_t p1)
354 /// Set step size in Alu
358 //__________________________________________________________________
359 void AliMUON::SetMaxDestepGas(Float_t p1)
361 /// Set maximum step size in Gas
365 //__________________________________________________________________
366 void AliMUON::SetMaxDestepAlu(Float_t p1)
368 /// Set maximum step size in Alu
373 //____________________________________________________________________
374 Float_t AliMUON::GetMaxStepGas() const
376 /// Return stepsize in gas
381 //____________________________________________________________________
382 Float_t AliMUON::GetMaxStepAlu() const
384 /// Return step size in Alu
389 //____________________________________________________________________
390 Float_t AliMUON::GetMaxDestepGas() const
392 /// Return maximum step size in Gas
394 return fMaxDestepGas;
397 //____________________________________________________________________
398 Float_t AliMUON::GetMaxDestepAlu() const
400 /// Return maximum step size in Gas
402 return fMaxDestepAlu;
405 //____________________________________________________________________
406 void AliMUON::SetAlign(Bool_t align)
408 /// Set option for alignement to geometry builder
410 fGeometryBuilder->SetAlign(align);
413 //____________________________________________________________________
414 void AliMUON::SetAlign(const TString& fileName, Bool_t align)
416 /// Set option for alignement to geometry builder
418 fGeometryBuilder->SetAlign(fileName, align);
421 //____________________________________________________________________
422 void AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
424 /// Set the response for chamber id
425 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
428 //____________________________________________________________________
429 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
431 /// FIXME: the selection of the class should be done through a factory
432 /// mechanism. (see also Hits2SDigits()).
434 AliInfo(Form("Digitizer used : %s",fDigitizerType.Data()));
436 if ( fDigitizerType == "digitizer:default" ) // NewDigitizerNewTrigger
438 return new AliMUONDigitizerV3(manager,kTRUE);
440 else if ( fDigitizerType == "digitizer:NewDigitizerWONoiseNewTrigger" )
442 return new AliMUONDigitizerV3(manager,kFALSE);
446 AliFatal(Form("Unknown digitizer type : %s",fDigitizerType.Data()));
451 //_____________________________________________________________________
453 AliMUON::SDigitizerType() const
455 /// Return digitizer type
457 return fSDigitizerType;
460 //_____________________________________________________________________
461 void AliMUON::SDigits2Digits()
463 /// Write TreeD here only
466 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
467 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
468 fLoader->TreeD()->Reset();
471 //_____________________________________________________________________
472 void AliMUON::Hits2SDigits()
474 /// FIXME: the selection of the sdigitizer should be done through a
475 /// factory mechanism.
477 AliInfo(Form("SDigitizer used : %s",fSDigitizerType.Data()));
479 if ( fSDigitizerType == "sdigitizer:default" )
481 // Adaption of AliMUONSDigitizerv1 to be excuted by the AliSimulation framework
482 AliRunLoader* runLoader = fLoader->GetRunLoader();
483 AliRunDigitizer * manager = new AliRunDigitizer(1,1);
484 manager->SetInputStream(0,runLoader->GetFileName(),AliConfig::GetDefaultEventFolderName());
485 AliMUONDigitizer * dMUON = new AliMUONSDigitizerv1(manager);
486 fLoader->LoadHits("READ");
487 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
488 runLoader->GetEvent(iEvent);
491 fLoader->UnloadHits();
493 else if ( fSDigitizerType == "sdigitizer:AliMUONSDigitizerV2" )
495 TTask* sdigitizer = new AliMUONSDigitizerV2;
496 sdigitizer->ExecuteTask();
500 AliFatal(Form("Unknown sdigitizer classname : %s",fSDigitizerType.Data()));
504 //_____________________________________________________________________
506 AliMUON::DigitizerType() const
508 /// Return digitizer type
510 return fDigitizerType;
513 //_____________________________________________________________________
514 void AliMUON::Digits2Raw()
516 /// Convert digits of the current event to raw data
520 fRawWriter = new AliMUONRawWriter(fMUONData);
521 if (fTriggerScalerEvent == kTRUE)
523 fRawWriter->SetScalersNumbers();
527 if (!fRawWriter->Digits2Raw())
529 AliError("pb writting raw data");
533 //_____________________________________________________________________
534 Bool_t AliMUON::Raw2SDigits(AliRawReader* rawReader)
536 /// Convert raw data to SDigit
537 /// Only for tracking for the moment (ChF)
539 //fLoader->LoadDigits("READ");
540 if (!fLoader->TreeS()) fLoader->MakeSDigitsContainer();
542 fMUONData->MakeBranch("S");
543 fMUONData->SetTreeAddress("S");
544 fDigitMaker->Raw2Digits(rawReader);
545 fMUONData->Fill("S");
547 fLoader->WriteSDigits("OVERWRITE");
548 fMUONData->ResetSDigits();
549 fLoader->UnloadSDigits();
555 //_______________________________________________________________________
556 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
558 /// Build standard getter (AliLoader type);
559 /// if detector wants to use castomized getter, it must overload this method
561 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
562 GetName(),topfoldername));
563 fLoader = new AliLoader(GetName(),topfoldername);
564 fMUONData = new AliMUONData(fLoader,GetName(),GetName());
565 fMUONData->SetSplitLevel(fSplitLevel);
567 fDigitMaker->SetMUONData(fMUONData);
571 //_______________________________________________________________________
573 AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
575 /// Return rawcluster (icluster) for chamber ichamber and cathode icathod
578 TClonesArray *muonRawCluster = GetMUONData()->RawClusters(ichamber);
580 TTree *treeR = fLoader->TreeR();
581 Int_t nent=(Int_t)treeR->GetEntries();
582 treeR->GetEvent(nent-2+icathod-1);
583 //treeR->GetEvent(icathod);
584 //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
586 AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
587 //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
592 //________________________________________________________________________
594 AliMUON::ResetGeometryBuilder()
596 /// Only to be used by "experts" wanting to change the geometry builders
598 /// As the ctor of AliMUON now defines a default geometrybuilder, this
599 /// ResetGeometryBuilder() must be called prior to call the
600 /// AddGeometryBuilder()
602 delete fGeometryBuilder;
603 fGeometryBuilder = new AliMUONGeometryBuilder(this);
605 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
608 //____________________________________________________________________
609 Bool_t AliMUON::GetTriggerResponseV1() const
612 /// Returns fTriggerResponseV1
614 return fTriggerResponseV1;
618 //____________________________________________________________________
619 Int_t AliMUON::GetTriggerCoinc44() const
622 /// Returns fTriggerCoinc44
624 return fTriggerCoinc44;
628 //____________________________________________________________________
629 Bool_t AliMUON::GetTriggerEffCells() const
632 /// Returns fTriggerEffCells
634 return fTriggerEffCells;