]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUON.cxx
Possibility to specify local parameters added also to the constructor AliAlignObj...
[u/mrichter/AliRoot.git] / MUON / AliMUON.cxx
CommitLineData
4c039060 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
4c039060 15
88cb7938 16/* $Id$ */
17
a9e2aefa 18
19///////////////////////////////////////////////
fe4da5cc 20// Manager and hits classes for set:MUON //
21////////////////////////////////////////////////
22
88cb7938 23#include "Riostream.h"
24
25#include <AliPDG.h>
a897a37a 26#include <TBRIK.h>
88cb7938 27#include <TCanvas.h>
28#include <TDirectory.h>
29#include <TFile.h>
94de3818 30#include <TGeometry.h>
88cb7938 31#include <TMinuit.h>
fe4da5cc 32#include <TNode.h>
88cb7938 33#include <TNtuple.h>
fe4da5cc 34#include <TObjArray.h>
88cb7938 35#include <TObject.h>
36#include <TObjectTable.h>
37#include <TPad.h>
a897a37a 38#include <TParticle.h>
39#include <TROOT.h>
88cb7938 40#include <TRandom.h>
41#include <TRotMatrix.h>
42#include <TTUBE.h>
a9e2aefa 43#include <TTUBE.h>
88cb7938 44#include <TTree.h>
45#include <TVector.h>
46#include <TVirtualMC.h>
fe4da5cc 47
d4bb94a1 48//#include "AliHeader.h"
88cb7938 49#include "AliLoader.h"
dbb4e169 50#include "AliRunDigitizer.h"
307d9d04 51#include "AliMC.h"
fac3a970 52#include "AliRun.h"
fe4da5cc 53#include "AliMUON.h"
88cb7938 54#include "AliMUONChamberTrigger.h"
88cb7938 55#include "AliMUONConstants.h"
ffd9faa2 56#include "AliMUONHit.h"
a9e2aefa 57#include "AliMUONRawCluster.h"
88cb7938 58#include "AliMUONTransientDigit.h"
ecfa008b 59#include "AliMUONTriggerCircuit.h"
504d0837 60#include "AliMUONGeometry.h"
61#include "AliMUONGeometryTransformer.h"
d4bb94a1 62#include "AliMUONGeometryBuilder.h"
e118b27e 63#include "AliMUONCommonGeometryBuilder.h"
d1cd2474 64#include "AliMUONVGeometryBuilder.h"
a713db22 65#include "AliMUONGeometrySegmentation.h"
dbb4e169 66#include "AliMUONDigitizerv2.h"
d1775029 67#include "AliMUONSDigitizerv1.h"
a19e2543 68#include "AliMUONRawWriter.h"
504d0837 69#include "AliMUONSegmentation.h"
8c343c7c 70#include "AliLog.h"
a9e2aefa 71
68585390 72#include "AliMUONSDigitizerV2.h"
73#include "AliMUONDigitizerV3.h"
74
d5609cfc 75#include "AliMUONSt1GeometryBuilderV2.h"
76#include "AliMUONSt2GeometryBuilderV2.h"
77#include "AliMUONSlatGeometryBuilder.h"
78#include "AliMUONTriggerGeometryBuilder.h"
79
a9e2aefa 80// Defaults parameters for Z positions of chambers
81// taken from values for "stations" in AliMUON::AliMUON
82// const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
83// and from array "dstation" in AliMUONv1::CreateGeometry
84// Float_t dstation[5]={20., 20., 20, 20., 20.};
85// for tracking chambers,
86// according to (Z1 = zch - dstation) and (Z2 = zch + dstation)
87// for the first and second chambers in the station, respectively,
88// and from "DTPLANES" in AliMUONv1::CreateGeometry
89// const Float_t DTPLANES = 15.;
90// for trigger chambers,
91// according to (Z1 = zch) and (Z2 = zch + DTPLANES)
92// for the first and second chambers in the station, respectively
fe4da5cc 93
fe4da5cc 94ClassImp(AliMUON)
30178c30 95
ce3f5e87 96//__________________________________________________________________
fe4da5cc 97AliMUON::AliMUON()
30178c30 98 : AliDetector(),
99 fNCh(0),
100 fNTrackingCh(0),
101 fMUONData(0),
102 fSplitLevel(0),
103 fChambers(0),
30178c30 104 fTriggerCircuits(0),
d4bb94a1 105 fGeometryBuilder(0),
504d0837 106 fSegmentation(0),
30178c30 107 fAccCut(kFALSE),
108 fAccMin(0.),
109 fAccMax(0.),
110 fMaxStepGas(0.),
111 fMaxStepAlu(0.),
112 fMaxDestepGas(0.),
113 fMaxDestepAlu(0.),
114 fMaxIterPad(0),
ced309a5 115 fCurIterPad(0),
68585390 116 fTriggerScalerEvent(kFALSE),
117 fSDigitizerType(""),
d5609cfc 118 fDigitizerType(""),
119 fRawWriter(0x0)
fe4da5cc 120{
de05461e 121// Default Constructor
122//
edee5e63 123 AliDebug(1,Form("default (empty) ctor this=%p",this));
1bd26093 124 fIshunt = 0;
fe4da5cc 125}
30178c30 126
ce3f5e87 127//__________________________________________________________________
68585390 128AliMUON::AliMUON(const char *name, const char *title,
129 const char* sDigitizerClassName,
130 const char* digitizerClassName)
30178c30 131 : AliDetector(name,title),
132 fNCh(AliMUONConstants::NCh()),
133 fNTrackingCh(AliMUONConstants::NTrackingCh()),
134 fMUONData(0),
135 fSplitLevel(0),
136 fChambers(0),
30178c30 137 fTriggerCircuits(0),
d4bb94a1 138 fGeometryBuilder(0),
504d0837 139 fSegmentation(0),
30178c30 140 fAccCut(kFALSE),
141 fAccMin(0.),
142 fAccMax(0.),
143 fMaxStepGas(0.1),
144 fMaxStepAlu(0.1),
145 fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200
146 fMaxDestepAlu(-1), // in the calculation of the tracking parameters
147 fMaxIterPad(0),
ced309a5 148 fCurIterPad(0),
68585390 149 fTriggerScalerEvent(kFALSE),
150 fSDigitizerType(sDigitizerClassName),
d5609cfc 151 fDigitizerType(digitizerClassName),
152 fRawWriter(0x0)
fe4da5cc 153{
edee5e63 154 AliDebug(1,Form("ctor this=%p",this));
30178c30 155 fIshunt = 0;
a897a37a 156
ce3f5e87 157 SetMarkerColor(kRed);//
e118b27e 158
159 // Geometry builder
160 fGeometryBuilder = new AliMUONGeometryBuilder(this);
161
162 // Common geometry definitions
163 fGeometryBuilder
164 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
165
d5609cfc 166 // By default, add also all the needed geometry builders.
167 // If you want to change this from outside, please use ResetGeometryBuilder
168 // method, followed by AddGeometryBuilder ones.
169
170 AddGeometryBuilder(new AliMUONSt1GeometryBuilderV2(this));
171 AddGeometryBuilder(new AliMUONSt2GeometryBuilderV2(this));
172 AddGeometryBuilder(new AliMUONSlatGeometryBuilder(this));
173 AddGeometryBuilder(new AliMUONTriggerGeometryBuilder(this));
174
175 //
176 // Creating List of Chambers
a9e2aefa 177 Int_t ch;
f665c1ea 178 fChambers = new TObjArray(AliMUONConstants::NCh());
d1cd2474 179
a9e2aefa 180 // Loop over stations
f665c1ea 181 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
a9e2aefa 182 // Loop over 2 chambers in the station
ce3f5e87 183 for (Int_t stCH = 0; stCH < 2; stCH++) {
184 //
185 //
186 // Default Parameters for Muon Tracking Stations
187 ch = 2 * st + stCH;
188 if (ch < AliMUONConstants::NTrackingCh()) {
189 fChambers->AddAt(new AliMUONChamber(ch),ch);
190 } else {
504d0837 191 fChambers->AddAt(new AliMUONChamberTrigger(ch, GetGeometryTransformer()),ch);
ce3f5e87 192 }
ce3f5e87 193 } // Chamber stCH (0, 1) in
a9e2aefa 194 } // Station st (0...)
ce3f5e87 195
ce3f5e87 196 // cp new design of AliMUONTriggerDecision
197 fTriggerCircuits = new TObjArray(AliMUONConstants::NTriggerCircuit());
198 for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
199 fTriggerCircuits->AddAt(new AliMUONTriggerCircuit(),circ);
200 }
fe4da5cc 201}
30178c30 202
ce3f5e87 203//____________________________________________________________________
30178c30 204AliMUON::AliMUON(const AliMUON& rMUON)
205 : AliDetector(rMUON)
a9e2aefa 206{
30178c30 207// Protected copy constructor
208
8c343c7c 209 AliFatal("Not implemented.");
a9e2aefa 210}
30178c30 211
ce3f5e87 212//____________________________________________________________________
fe4da5cc 213AliMUON::~AliMUON()
214{
de05461e 215// Destructor
edee5e63 216 AliDebug(1,Form("dtor this=%p",this));
ce3f5e87 217 fIshunt = 0;
d1cd2474 218
c6df4ef2 219 if (fChambers){
220 fChambers->Delete();
221 delete fChambers;
222 }
223 if (fTriggerCircuits){
224 fTriggerCircuits->Delete();
225 delete fTriggerCircuits;
226 }
227 delete fMUONData;
d4bb94a1 228 delete fGeometryBuilder;
504d0837 229 delete fSegmentation;
d5609cfc 230 delete fRawWriter;
d1cd2474 231}
30178c30 232
233//________________________________________________________________________
234AliMUON& AliMUON::operator = (const AliMUON& rhs)
235{
236// Protected assignement operator
237
238 if (this == &rhs) return *this;
239
8c343c7c 240 AliFatal("Not implemented.");
30178c30 241
242 return *this;
243}
244
d1cd2474 245//_____________________________________________________________________________
246void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
247{
248// Adds the geometry builder to the list
249// ---
250
d4bb94a1 251 fGeometryBuilder->AddBuilder(geomBuilder);
a897a37a 252}
c9d10ab5 253
ce3f5e87 254//____________________________________________________________________
fe4da5cc 255void AliMUON::BuildGeometry()
256{
de05461e 257// Geometry for event display
c9d10ab5 258
002920d1 259
ae89d471 260// for (Int_t i = 0; i < AliMUONConstants::NCh(); i++)
261// this->Chamber(i).SegmentationModel2(1)->Draw("eventdisplay");// to be check !
262
002920d1 263
fe4da5cc 264}
c9d10ab5 265
504d0837 266//____________________________________________________________________
267const AliMUONGeometry* AliMUON::GetGeometry() const
268{
269// Return geometry parametrisation
270
271 if ( !fGeometryBuilder) {
272 AliWarningStream() << "GeometryBuilder not defined." << std::endl;
273 return 0;
274 }
275
276 return fGeometryBuilder->GetGeometry();
277}
278
279//____________________________________________________________________
280const AliMUONGeometryTransformer* AliMUON::GetGeometryTransformer() const
281{
282// Return geometry parametrisation
283
284 const AliMUONGeometry* kGeometry = GetGeometry();
285
286 if ( !kGeometry) return 0;
287
288 return kGeometry->GetTransformer();
289}
290
ce3f5e87 291//__________________________________________________________________
292void AliMUON::SetTreeAddress()
a897a37a 293{
ce3f5e87 294 GetMUONData()->SetLoader(fLoader);
d1775029 295 // GetMUONData()->MakeBranch("D,S,RC");
296 // GetMUONData()->SetTreeAddress("H,D,S,RC");
52c9bc11 297 GetMUONData()->SetTreeAddress("H");
307d9d04 298 if (fHits != GetMUONData()->Hits()) {
ae31c826 299 if ( gAlice->GetMCApp() )
6d2f7cbd 300 if ( gAlice->GetMCApp()->GetHitLists() ) {
301 fHits = GetMUONData()->Hits();
302 gAlice->GetMCApp()->AddHitList(fHits); // For purifyKine, only necessary when Hit list is created in AliMUONData
303 }
307d9d04 304 }
6d2f7cbd 305 fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector
a9e2aefa 306}
307
ce3f5e87 308//_________________________________________________________________
a897a37a 309void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
fe4da5cc 310{
de05461e 311// Set the inverse charge slope for chamber id
ce3f5e87 312 Int_t i=2*(id-1); //PH ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
313 //PH ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
2682e810 314 ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
315 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
fe4da5cc 316}
ce3f5e87 317//__________________________________________________________________
a897a37a 318void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
fe4da5cc 319{
de05461e 320// Set sigma of charge spread for chamber id
fe4da5cc 321 Int_t i=2*(id-1);
2682e810 322 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
323 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
fe4da5cc 324}
ce3f5e87 325//___________________________________________________________________
a897a37a 326void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
fe4da5cc 327{
de05461e 328// Set integration limits for charge spread
fe4da5cc 329 Int_t i=2*(id-1);
2682e810 330 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
331 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
fe4da5cc 332}
333
ce3f5e87 334//__________________________________________________________________
d09fafb0 335void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
fe4da5cc 336{
de05461e 337// Set maximum number for ADCcounts (saturation)
fe4da5cc 338 Int_t i=2*(id-1);
2682e810 339 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
340 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
fe4da5cc 341}
d4bb94a1 342
ce3f5e87 343//__________________________________________________________________
a897a37a 344void AliMUON::SetMaxStepGas(Float_t p1)
fe4da5cc 345{
de05461e 346// Set stepsize in gas
ce3f5e87 347 fMaxStepGas=p1;
fe4da5cc 348}
ce3f5e87 349//__________________________________________________________________
a897a37a 350void AliMUON::SetMaxStepAlu(Float_t p1)
fe4da5cc 351{
de05461e 352// Set step size in Alu
fe4da5cc 353 fMaxStepAlu=p1;
354}
ce3f5e87 355//__________________________________________________________________
a897a37a 356void AliMUON::SetMaxDestepGas(Float_t p1)
fe4da5cc 357{
de05461e 358// Set maximum step size in Gas
fe4da5cc 359 fMaxDestepGas=p1;
360}
ce3f5e87 361//__________________________________________________________________
a897a37a 362void AliMUON::SetMaxDestepAlu(Float_t p1)
fe4da5cc 363{
de05461e 364// Set maximum step size in Alu
ce3f5e87 365 fMaxDestepAlu=p1;
fe4da5cc 366}
d4bb94a1 367
d1cd2474 368//____________________________________________________________________
369Float_t AliMUON::GetMaxStepGas() const
370{
371// Return stepsize in gas
372
373 return fMaxStepGas;
374}
375
376//____________________________________________________________________
377Float_t AliMUON::GetMaxStepAlu() const
378{
379// Return step size in Alu
380
381 return fMaxStepAlu;
382}
383
384//____________________________________________________________________
385Float_t AliMUON::GetMaxDestepGas() const
386{
387// Return maximum step size in Gas
388
389 return fMaxDestepGas;
390}
391
392//____________________________________________________________________
393Float_t AliMUON::GetMaxDestepAlu() const
394{
395// Return maximum step size in Gas
396
397 return fMaxDestepAlu;
398}
d4bb94a1 399
883746f3 400//____________________________________________________________________
401 void AliMUON::SetAlign(Bool_t align)
a713db22 402{
883746f3 403 // Sets option for alignement to geometry builder
404
405 fGeometryBuilder->SetAlign(align);
406}
fe4da5cc 407
82d1ac0a 408//____________________________________________________________________
409 void AliMUON::SetAlign(const TString& fileName, Bool_t align)
410{
411 // Sets option for alignement to geometry builder
412
413 fGeometryBuilder->SetAlign(fileName, align);
414}
415
ce3f5e87 416//____________________________________________________________________
a9e2aefa 417void AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
fe4da5cc 418{
de05461e 419// Set the response for chamber id
2682e810 420 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
fe4da5cc 421}
ce3f5e87 422//____________________________________________________________________
c92eb8ad 423AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
85a5290f 424{
68585390 425 // FIXME: the selection of the class should be done through a factory
426 // mechanism. (see also Hits2SDigits()).
427
428 AliInfo(Form("Digitizer used : %s",fDigitizerType.Data()));
429
430 if ( fDigitizerType == "digitizer:default" )
431 {
432 return new AliMUONDigitizerv2(manager);
433 }
434 else if ( fDigitizerType == "digitizer:NewDigitizerNewTrigger" )
435 {
436 return new AliMUONDigitizerV3(manager,AliMUONDigitizerV3::kTriggerElectronics);
437 }
438 else if ( fDigitizerType == "digitizer:NewDigitizerOldTrigger" )
439 {
440 return new AliMUONDigitizerV3(manager,AliMUONDigitizerV3::kTriggerDecision);
441 }
442 else
443 {
444 AliFatal(Form("Unknown digitizer type : %s",fDigitizerType.Data()));
445 }
446 return 0x0;
447}
448
449//_____________________________________________________________________
450TString
451AliMUON::SDigitizerType() const
452{
453 return fSDigitizerType;
85a5290f 454}
68585390 455
ce3f5e87 456//_____________________________________________________________________
2ab0c725 457void AliMUON::SDigits2Digits()
458{
d963c261 459
460// write TreeD here
461
d963c261 462 char hname[30];
88cb7938 463 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
464 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
465 fLoader->TreeD()->Reset();
2ab0c725 466}
a9e2aefa 467
d1775029 468//_____________________________________________________________________
469void AliMUON::Hits2SDigits()
470{
68585390 471 // FIXME: the selection of the sdigitizer should be done through a
472 // factory mechanism.
473
474 AliInfo(Form("SDigitizer used : %s",fSDigitizerType.Data()));
475
476 if ( fSDigitizerType == "sdigitizer:default" )
477 {
478 // Adaption of AliMUONSDigitizerv1 to be excuted by the AliSimulation framework
479 AliRunLoader* runLoader = fLoader->GetRunLoader();
480 AliRunDigitizer * manager = new AliRunDigitizer(1,1);
481 manager->SetInputStream(0,runLoader->GetFileName(),AliConfig::GetDefaultEventFolderName());
482 AliMUONDigitizer * dMUON = new AliMUONSDigitizerv1(manager);
483 fLoader->LoadHits("READ");
484 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
485 runLoader->GetEvent(iEvent);
486 dMUON->Exec("");
487 }
488 fLoader->UnloadHits();
489 }
490 else if ( fSDigitizerType == "sdigitizer:AliMUONSDigitizerV2" )
491 {
492 TTask* sdigitizer = new AliMUONSDigitizerV2;
493 sdigitizer->ExecuteTask();
dbb4e169 494 }
68585390 495 else
496 {
497 AliFatal(Form("Unknown sdigitizer classname : %s",fSDigitizerType.Data()));
498 }
499}
500
501//_____________________________________________________________________
502TString
503AliMUON::DigitizerType() const
504{
505 return fDigitizerType;
d1775029 506}
68585390 507
39e39255 508//_____________________________________________________________________
509void AliMUON::Digits2Raw()
510{
511 // convert digits of the current event to raw data
d5609cfc 512 if (!fRawWriter)
513 {
514 fRawWriter = new AliMUONRawWriter(fMUONData);
515 if (fTriggerScalerEvent == kTRUE)
516 {
517 fRawWriter->SetScalerEvent();
518 }
519 }
520
521 if (!fRawWriter->Digits2Raw())
522 {
523 AliError("pb writting raw data");
524 }
39e39255 525}
68585390 526
ce3f5e87 527//_______________________________________________________________________
3fa6cfdd 528AliLoader* AliMUON::MakeLoader(const char* topfoldername)
529{
530//builds standard getter (AliLoader type)
531//if detector wants to use castomized getter, it must overload this method
532
8c343c7c 533
534 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
535 GetName(),topfoldername));
128843d9 536 fLoader = new AliLoader(GetName(),topfoldername);
ce3f5e87 537 fMUONData = new AliMUONData(fLoader,GetName(),GetName());
d652f85c 538 fMUONData->SetSplitLevel(fSplitLevel);
3fa6cfdd 539 return fLoader;
540}
ce3f5e87 541//_______________________________________________________________________
a897a37a 542
543AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
544{
de05461e 545//
546// Return rawcluster (icluster) for chamber ichamber and cathode icathod
547// Obsolete ??
ce3f5e87 548 TClonesArray *muonRawCluster = GetMUONData()->RawClusters(ichamber);
a897a37a 549 ResetRawClusters();
88cb7938 550 TTree *treeR = fLoader->TreeR();
a9e2aefa 551 Int_t nent=(Int_t)treeR->GetEntries();
552 treeR->GetEvent(nent-2+icathod-1);
553 //treeR->GetEvent(icathod);
554 //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
a897a37a 555
a9e2aefa 556 AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
a897a37a 557 //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
558
559 return mRaw;
560}
ffd9faa2 561
d5609cfc 562//________________________________________________________________________
563void
564AliMUON::ResetGeometryBuilder()
565{
566 // Only to be used by "experts" wanting to change the geometry builders
567 // to be used.
568 // As the ctor of AliMUON now defines a default geometrybuilder, this
569 // ResetGeometryBuilder() must be called prior to call the
570 // AddGeometryBuilder()
571 delete fGeometryBuilder;
572 fGeometryBuilder = new AliMUONGeometryBuilder(this);
573 fGeometryBuilder
574 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
575}