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 "AliMUONGeometry.h"
60 #include "AliMUONGeometryTransformer.h"
61 #include "AliMUONGeometryBuilder.h"
62 #include "AliMUONCommonGeometryBuilder.h"
63 #include "AliMUONVGeometryBuilder.h"
64 #include "AliMUONGeometrySegmentation.h"
65 #include "AliMUONRawWriter.h"
66 #include "AliMUONSegmentation.h"
69 #include "AliMUONSDigitizerV2.h"
70 #include "AliMUONDigitizerV3.h"
71 #include "AliMUONDigitMaker.h"
73 #include "AliMUONSt1GeometryBuilderV2.h"
74 #include "AliMUONSt2GeometryBuilderV2.h"
75 #include "AliMUONSlatGeometryBuilder.h"
76 #include "AliMUONTriggerGeometryBuilder.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 //__________________________________________________________________
115 fTriggerScalerEvent(kFALSE),
116 fTriggerResponseV1(kFALSE),
119 fDigitizerWithNoise(kTRUE),
124 /// Default Constructor
126 AliDebug(1,Form("default (empty) ctor this=%p",this));
130 //__________________________________________________________________
131 AliMUON::AliMUON(const char *name)
132 : AliDetector(name,name),
133 fNCh(AliMUONConstants::NCh()),
134 fNTrackingCh(AliMUONConstants::NTrackingCh()),
145 fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200
146 fMaxDestepAlu(-1), // in the calculation of the tracking parameters
149 fTriggerScalerEvent(kFALSE),
150 fTriggerResponseV1(kFALSE),
153 fDigitizerWithNoise(kTRUE),
155 fDigitMaker(new AliMUONDigitMaker(kFALSE))
157 /// Standard constructor
159 AliDebug(1,Form("ctor this=%p",this));
162 SetMarkerColor(kRed);//
165 fGeometryBuilder = new AliMUONGeometryBuilder(this);
167 // Common geometry definitions
169 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
171 // By default, add also all the needed geometry builders.
172 // If you want to change this from outside, please use ResetGeometryBuilder
173 // method, followed by AddGeometryBuilder ones.
175 AddGeometryBuilder(new AliMUONSt1GeometryBuilderV2(this));
176 AddGeometryBuilder(new AliMUONSt2GeometryBuilderV2(this));
177 AddGeometryBuilder(new AliMUONSlatGeometryBuilder(this));
178 AddGeometryBuilder(new AliMUONTriggerGeometryBuilder(this));
181 // Creating List of Chambers
183 fChambers = new TObjArray(AliMUONConstants::NCh());
185 // Loop over stations
186 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
187 // Loop over 2 chambers in the station
188 for (Int_t stCH = 0; stCH < 2; stCH++) {
191 // Default Parameters for Muon Tracking Stations
193 if (ch < AliMUONConstants::NTrackingCh()) {
194 fChambers->AddAt(new AliMUONChamber(ch),ch);
196 fChambers->AddAt(new AliMUONChamberTrigger(ch, GetGeometryTransformer()),ch);
198 } // Chamber stCH (0, 1) in
199 } // Station st (0...)
203 //____________________________________________________________________
208 AliDebug(1,Form("dtor this=%p",this));
217 delete fGeometryBuilder;
218 delete fSegmentation;
223 //_____________________________________________________________________________
224 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
226 /// Add the geometry builder to the list
228 fGeometryBuilder->AddBuilder(geomBuilder);
231 //____________________________________________________________________
232 void AliMUON::BuildGeometry()
234 /// Geometry for event display
237 // for (Int_t i = 0; i < AliMUONConstants::NCh(); i++)
238 // this->Chamber(i).SegmentationModel2(1)->Draw("eventdisplay");// to be check !
243 //____________________________________________________________________
244 const AliMUONGeometry* AliMUON::GetGeometry() const
246 /// Return geometry parametrisation
248 if ( !fGeometryBuilder) {
249 AliWarningStream() << "GeometryBuilder not defined." << std::endl;
253 return fGeometryBuilder->GetGeometry();
256 //____________________________________________________________________
257 const AliMUONGeometryTransformer* AliMUON::GetGeometryTransformer() const
259 /// Return geometry parametrisation
261 const AliMUONGeometry* kGeometry = GetGeometry();
263 if ( !kGeometry) return 0;
265 return kGeometry->GetTransformer();
268 //__________________________________________________________________
269 void AliMUON::SetTreeAddress()
271 /// Set Hits tree address
273 GetMUONData()->SetLoader(fLoader);
274 // GetMUONData()->MakeBranch("D,S,RC");
275 // GetMUONData()->SetTreeAddress("H,D,S,RC");
276 GetMUONData()->SetTreeAddress("H");
277 if (fHits != GetMUONData()->Hits()) {
278 if ( gAlice->GetMCApp() )
279 if ( gAlice->GetMCApp()->GetHitLists() ) {
280 fHits = GetMUONData()->Hits();
281 gAlice->GetMCApp()->AddHitList(fHits); // For purifyKine, only necessary when Hit list is created in AliMUONData
284 fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector
287 //_________________________________________________________________
288 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
290 /// Set the inverse charge slope for chamber id
292 Int_t i=2*(id-1); //PH ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
293 //PH ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
294 ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
295 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
297 //__________________________________________________________________
298 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
300 /// Set sigma of charge spread for chamber id
303 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
304 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
306 //___________________________________________________________________
307 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
309 /// Set integration limits for charge spread
311 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
312 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
315 //__________________________________________________________________
316 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
318 /// Set maximum number for ADCcounts (saturation)
321 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
322 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
325 //__________________________________________________________________
326 void AliMUON::SetMaxStepGas(Float_t p1)
328 /// Set stepsize in gas
332 //__________________________________________________________________
333 void AliMUON::SetMaxStepAlu(Float_t p1)
335 /// Set step size in Alu
339 //__________________________________________________________________
340 void AliMUON::SetMaxDestepGas(Float_t p1)
342 /// Set maximum step size in Gas
346 //__________________________________________________________________
347 void AliMUON::SetMaxDestepAlu(Float_t p1)
349 /// Set maximum step size in Alu
354 //____________________________________________________________________
355 Float_t AliMUON::GetMaxStepGas() const
357 /// Return stepsize in gas
362 //____________________________________________________________________
363 Float_t AliMUON::GetMaxStepAlu() const
365 /// Return step size in Alu
370 //____________________________________________________________________
371 Float_t AliMUON::GetMaxDestepGas() const
373 /// Return maximum step size in Gas
375 return fMaxDestepGas;
378 //____________________________________________________________________
379 Float_t AliMUON::GetMaxDestepAlu() const
381 /// Return maximum step size in Gas
383 return fMaxDestepAlu;
386 //____________________________________________________________________
387 void AliMUON::SetAlign(Bool_t align)
389 /// Set option for alignement to geometry builder
391 fGeometryBuilder->SetAlign(align);
394 //____________________________________________________________________
395 void AliMUON::SetAlign(const TString& fileName, Bool_t align)
397 /// Set option for alignement to geometry builder
399 fGeometryBuilder->SetAlign(fileName, align);
402 //____________________________________________________________________
403 void AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
405 /// Set the response for chamber id
406 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
409 //____________________________________________________________________
410 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
414 return new AliMUONDigitizerV3(manager, fDigitizerWithNoise);
417 //_____________________________________________________________________
418 void AliMUON::SDigits2Digits()
420 /// Write TreeD here only
423 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
424 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
425 fLoader->TreeD()->Reset();
428 //_____________________________________________________________________
429 void AliMUON::Hits2SDigits()
431 /// Perform Hits2Digits using SDigitizerV2
433 TTask* sdigitizer = new AliMUONSDigitizerV2;
434 sdigitizer->ExecuteTask();
437 //_____________________________________________________________________
438 void AliMUON::Digits2Raw()
440 /// Convert digits of the current event to raw data
444 fRawWriter = new AliMUONRawWriter(fMUONData);
445 if (fTriggerScalerEvent == kTRUE)
447 fRawWriter->SetScalersNumbers();
451 if (!fRawWriter->Digits2Raw())
453 AliError("pb writting raw data");
457 //_____________________________________________________________________
458 Bool_t AliMUON::Raw2SDigits(AliRawReader* rawReader)
460 /// Convert raw data to SDigit
461 /// Only for tracking for the moment (ChF)
463 //fLoader->LoadDigits("READ");
464 if (!fLoader->TreeS()) fLoader->MakeSDigitsContainer();
466 fMUONData->MakeBranch("S");
467 fMUONData->SetTreeAddress("S");
468 fDigitMaker->Raw2Digits(rawReader);
469 fMUONData->Fill("S");
471 fLoader->WriteSDigits("OVERWRITE");
472 fMUONData->ResetSDigits();
473 fLoader->UnloadSDigits();
479 //_______________________________________________________________________
480 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
482 /// Build standard getter (AliLoader type);
483 /// if detector wants to use castomized getter, it must overload this method
485 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
486 GetName(),topfoldername));
487 fLoader = new AliLoader(GetName(),topfoldername);
488 fMUONData = new AliMUONData(fLoader,GetName(),GetName());
489 fMUONData->SetSplitLevel(fSplitLevel);
491 fDigitMaker->SetMUONData(fMUONData);
495 //_______________________________________________________________________
497 AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
499 /// Return rawcluster (icluster) for chamber ichamber and cathode icathod
502 TClonesArray *muonRawCluster = GetMUONData()->RawClusters(ichamber);
504 TTree *treeR = fLoader->TreeR();
505 Int_t nent=(Int_t)treeR->GetEntries();
506 treeR->GetEvent(nent-2+icathod-1);
507 //treeR->GetEvent(icathod);
508 //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
510 AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
511 //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
516 //________________________________________________________________________
518 AliMUON::ResetGeometryBuilder()
520 /// Only to be used by "experts" wanting to change the geometry builders
522 /// As the ctor of AliMUON now defines a default geometrybuilder, this
523 /// ResetGeometryBuilder() must be called prior to call the
524 /// AddGeometryBuilder()
526 delete fGeometryBuilder;
527 fGeometryBuilder = new AliMUONGeometryBuilder(this);
529 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
532 //____________________________________________________________________
533 Bool_t AliMUON::GetTriggerResponseV1() const
536 /// Returns fTriggerResponseV1
538 return fTriggerResponseV1;
542 //____________________________________________________________________
543 Int_t AliMUON::GetTriggerCoinc44() const
546 /// Returns fTriggerCoinc44
548 return fTriggerCoinc44;
552 //____________________________________________________________________
553 Bool_t AliMUON::GetTriggerEffCells() const
556 /// Returns fTriggerEffCells
558 return fTriggerEffCells;
562 //____________________________________________________________________
563 Bool_t AliMUON::GetDigitizerWithNoise() const
566 /// Returns fDigitizerWithNoise
568 return fDigitizerWithNoise;