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