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