]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUON.cxx
Corrected GetNeighbours() (Laurent)
[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
d19b6003 18// ------------------
19// Class AliMUON
20// ------------------
21// AliDetector class for MUON subsystem
22// providing simulation data management
fe4da5cc 23
88cb7938 24#include "Riostream.h"
25
26#include <AliPDG.h>
a897a37a 27#include <TBRIK.h>
88cb7938 28#include <TCanvas.h>
29#include <TDirectory.h>
30#include <TFile.h>
94de3818 31#include <TGeometry.h>
88cb7938 32#include <TMinuit.h>
fe4da5cc 33#include <TNode.h>
88cb7938 34#include <TNtuple.h>
fe4da5cc 35#include <TObjArray.h>
88cb7938 36#include <TObject.h>
37#include <TObjectTable.h>
38#include <TPad.h>
a897a37a 39#include <TParticle.h>
40#include <TROOT.h>
88cb7938 41#include <TRandom.h>
42#include <TRotMatrix.h>
43#include <TTUBE.h>
a9e2aefa 44#include <TTUBE.h>
88cb7938 45#include <TTree.h>
46#include <TVector.h>
47#include <TVirtualMC.h>
fe4da5cc 48
d4bb94a1 49//#include "AliHeader.h"
88cb7938 50#include "AliLoader.h"
dbb4e169 51#include "AliRunDigitizer.h"
307d9d04 52#include "AliMC.h"
fac3a970 53#include "AliRun.h"
fe4da5cc 54#include "AliMUON.h"
88cb7938 55#include "AliMUONChamberTrigger.h"
88cb7938 56#include "AliMUONConstants.h"
ffd9faa2 57#include "AliMUONHit.h"
a9e2aefa 58#include "AliMUONRawCluster.h"
504d0837 59#include "AliMUONGeometry.h"
60#include "AliMUONGeometryTransformer.h"
d4bb94a1 61#include "AliMUONGeometryBuilder.h"
e118b27e 62#include "AliMUONCommonGeometryBuilder.h"
d1cd2474 63#include "AliMUONVGeometryBuilder.h"
a713db22 64#include "AliMUONGeometrySegmentation.h"
a19e2543 65#include "AliMUONRawWriter.h"
504d0837 66#include "AliMUONSegmentation.h"
8c343c7c 67#include "AliLog.h"
a9e2aefa 68
68585390 69#include "AliMUONSDigitizerV2.h"
70#include "AliMUONDigitizerV3.h"
241560c2 71#include "AliMUONDigitMaker.h"
68585390 72
d5609cfc 73#include "AliMUONSt1GeometryBuilderV2.h"
74#include "AliMUONSt2GeometryBuilderV2.h"
75#include "AliMUONSlatGeometryBuilder.h"
76#include "AliMUONTriggerGeometryBuilder.h"
77
a9e2aefa 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
fe4da5cc 91
13985652 92/// \cond CLASSIMP
93ClassImp(AliMUON)
94/// \endcond
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),
d4bb94a1 104 fGeometryBuilder(0),
504d0837 105 fSegmentation(0),
30178c30 106 fAccCut(kFALSE),
107 fAccMin(0.),
108 fAccMax(0.),
109 fMaxStepGas(0.),
110 fMaxStepAlu(0.),
111 fMaxDestepGas(0.),
112 fMaxDestepAlu(0.),
113 fMaxIterPad(0),
ced309a5 114 fCurIterPad(0),
68585390 115 fTriggerScalerEvent(kFALSE),
e93b11d0 116 fTriggerResponseV1(kFALSE),
117 fTriggerCoinc44(0),
afb3ccf0 118 fTriggerEffCells(0),
a3249004 119 fDigitizerWithNoise(kTRUE),
241560c2 120 fRawWriter(0x0),
121 fDigitMaker(0x0)
122
fe4da5cc 123{
d19b6003 124/// Default Constructor
125
126 AliDebug(1,Form("default (empty) ctor this=%p",this));
1bd26093 127 fIshunt = 0;
fe4da5cc 128}
30178c30 129
ce3f5e87 130//__________________________________________________________________
9bf406e1 131AliMUON::AliMUON(const char *name, const char* title)
132 : AliDetector(name, title),
30178c30 133 fNCh(AliMUONConstants::NCh()),
134 fNTrackingCh(AliMUONConstants::NTrackingCh()),
135 fMUONData(0),
136 fSplitLevel(0),
137 fChambers(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),
e93b11d0 149 fTriggerScalerEvent(kFALSE),
150 fTriggerResponseV1(kFALSE),
151 fTriggerCoinc44(0),
afb3ccf0 152 fTriggerEffCells(0),
a3249004 153 fDigitizerWithNoise(kTRUE),
241560c2 154 fRawWriter(0x0),
155 fDigitMaker(new AliMUONDigitMaker(kFALSE))
fe4da5cc 156{
d19b6003 157/// Standard constructor
158
159 AliDebug(1,Form("ctor this=%p",this));
30178c30 160 fIshunt = 0;
a897a37a 161
e939a978 162 //PH SetMarkerColor(kRed);//
e118b27e 163
164 // Geometry builder
165 fGeometryBuilder = new AliMUONGeometryBuilder(this);
166
167 // Common geometry definitions
168 fGeometryBuilder
169 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
170
d5609cfc 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.
174
175 AddGeometryBuilder(new AliMUONSt1GeometryBuilderV2(this));
176 AddGeometryBuilder(new AliMUONSt2GeometryBuilderV2(this));
177 AddGeometryBuilder(new AliMUONSlatGeometryBuilder(this));
178 AddGeometryBuilder(new AliMUONTriggerGeometryBuilder(this));
179
180 //
181 // Creating List of Chambers
a9e2aefa 182 Int_t ch;
f665c1ea 183 fChambers = new TObjArray(AliMUONConstants::NCh());
d1cd2474 184
a9e2aefa 185 // Loop over stations
f665c1ea 186 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
a9e2aefa 187 // Loop over 2 chambers in the station
ce3f5e87 188 for (Int_t stCH = 0; stCH < 2; stCH++) {
189 //
190 //
191 // Default Parameters for Muon Tracking Stations
192 ch = 2 * st + stCH;
193 if (ch < AliMUONConstants::NTrackingCh()) {
194 fChambers->AddAt(new AliMUONChamber(ch),ch);
195 } else {
504d0837 196 fChambers->AddAt(new AliMUONChamberTrigger(ch, GetGeometryTransformer()),ch);
ce3f5e87 197 }
ce3f5e87 198 } // Chamber stCH (0, 1) in
a9e2aefa 199 } // Station st (0...)
e478a3f2 200
fe4da5cc 201}
30178c30 202
ce3f5e87 203//____________________________________________________________________
fe4da5cc 204AliMUON::~AliMUON()
205{
d19b6003 206/// Destructor
207
edee5e63 208 AliDebug(1,Form("dtor this=%p",this));
ce3f5e87 209 fIshunt = 0;
d1cd2474 210
c6df4ef2 211 if (fChambers){
212 fChambers->Delete();
213 delete fChambers;
214 }
0c527060 215
c6df4ef2 216 delete fMUONData;
d4bb94a1 217 delete fGeometryBuilder;
504d0837 218 delete fSegmentation;
d5609cfc 219 delete fRawWriter;
241560c2 220 delete fDigitMaker;
d1cd2474 221}
30178c30 222
d1cd2474 223//_____________________________________________________________________________
224void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
225{
d19b6003 226/// Add the geometry builder to the list
d1cd2474 227
d4bb94a1 228 fGeometryBuilder->AddBuilder(geomBuilder);
a897a37a 229}
c9d10ab5 230
ce3f5e87 231//____________________________________________________________________
fe4da5cc 232void AliMUON::BuildGeometry()
233{
d19b6003 234/// Geometry for event display
c9d10ab5 235
002920d1 236
ae89d471 237// for (Int_t i = 0; i < AliMUONConstants::NCh(); i++)
238// this->Chamber(i).SegmentationModel2(1)->Draw("eventdisplay");// to be check !
239
002920d1 240
fe4da5cc 241}
c9d10ab5 242
504d0837 243//____________________________________________________________________
244const AliMUONGeometry* AliMUON::GetGeometry() const
245{
d19b6003 246/// Return geometry parametrisation
504d0837 247
248 if ( !fGeometryBuilder) {
249 AliWarningStream() << "GeometryBuilder not defined." << std::endl;
250 return 0;
251 }
252
253 return fGeometryBuilder->GetGeometry();
254}
255
256//____________________________________________________________________
257const AliMUONGeometryTransformer* AliMUON::GetGeometryTransformer() const
258{
d19b6003 259/// Return geometry parametrisation
504d0837 260
261 const AliMUONGeometry* kGeometry = GetGeometry();
262
263 if ( !kGeometry) return 0;
264
265 return kGeometry->GetTransformer();
266}
267
ce3f5e87 268//__________________________________________________________________
269void AliMUON::SetTreeAddress()
a897a37a 270{
d19b6003 271/// Set Hits tree address
272
ce3f5e87 273 GetMUONData()->SetLoader(fLoader);
d1775029 274 // GetMUONData()->MakeBranch("D,S,RC");
275 // GetMUONData()->SetTreeAddress("H,D,S,RC");
52c9bc11 276 GetMUONData()->SetTreeAddress("H");
307d9d04 277 if (fHits != GetMUONData()->Hits()) {
ae31c826 278 if ( gAlice->GetMCApp() )
6d2f7cbd 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
282 }
307d9d04 283 }
6d2f7cbd 284 fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector
a9e2aefa 285}
286
ce3f5e87 287//_________________________________________________________________
a897a37a 288void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
fe4da5cc 289{
d19b6003 290/// Set the inverse charge slope for chamber id
291
ce3f5e87 292 Int_t i=2*(id-1); //PH ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
293 //PH ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
2682e810 294 ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
295 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
fe4da5cc 296}
ce3f5e87 297//__________________________________________________________________
a897a37a 298void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
fe4da5cc 299{
d19b6003 300/// Set sigma of charge spread for chamber id
301
fe4da5cc 302 Int_t i=2*(id-1);
2682e810 303 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
304 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
fe4da5cc 305}
ce3f5e87 306//___________________________________________________________________
a897a37a 307void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
fe4da5cc 308{
d19b6003 309/// Set integration limits for charge spread
fe4da5cc 310 Int_t i=2*(id-1);
2682e810 311 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
312 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
fe4da5cc 313}
314
ce3f5e87 315//__________________________________________________________________
d09fafb0 316void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
fe4da5cc 317{
d19b6003 318/// Set maximum number for ADCcounts (saturation)
319
fe4da5cc 320 Int_t i=2*(id-1);
2682e810 321 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
322 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
fe4da5cc 323}
d4bb94a1 324
ce3f5e87 325//__________________________________________________________________
a897a37a 326void AliMUON::SetMaxStepGas(Float_t p1)
fe4da5cc 327{
d19b6003 328/// Set stepsize in gas
329
ce3f5e87 330 fMaxStepGas=p1;
fe4da5cc 331}
ce3f5e87 332//__________________________________________________________________
a897a37a 333void AliMUON::SetMaxStepAlu(Float_t p1)
fe4da5cc 334{
d19b6003 335/// Set step size in Alu
336
fe4da5cc 337 fMaxStepAlu=p1;
338}
ce3f5e87 339//__________________________________________________________________
a897a37a 340void AliMUON::SetMaxDestepGas(Float_t p1)
fe4da5cc 341{
d19b6003 342/// Set maximum step size in Gas
343
fe4da5cc 344 fMaxDestepGas=p1;
345}
ce3f5e87 346//__________________________________________________________________
a897a37a 347void AliMUON::SetMaxDestepAlu(Float_t p1)
fe4da5cc 348{
d19b6003 349/// Set maximum step size in Alu
350
ce3f5e87 351 fMaxDestepAlu=p1;
fe4da5cc 352}
d4bb94a1 353
d1cd2474 354//____________________________________________________________________
355Float_t AliMUON::GetMaxStepGas() const
356{
d19b6003 357/// Return stepsize in gas
d1cd2474 358
359 return fMaxStepGas;
360}
361
362//____________________________________________________________________
363Float_t AliMUON::GetMaxStepAlu() const
364{
d19b6003 365/// Return step size in Alu
d1cd2474 366
367 return fMaxStepAlu;
368}
369
370//____________________________________________________________________
371Float_t AliMUON::GetMaxDestepGas() const
372{
d19b6003 373/// Return maximum step size in Gas
d1cd2474 374
375 return fMaxDestepGas;
376}
377
378//____________________________________________________________________
379Float_t AliMUON::GetMaxDestepAlu() const
380{
d19b6003 381/// Return maximum step size in Gas
d1cd2474 382
383 return fMaxDestepAlu;
384}
d4bb94a1 385
883746f3 386//____________________________________________________________________
387 void AliMUON::SetAlign(Bool_t align)
a713db22 388{
d19b6003 389/// Set option for alignement to geometry builder
883746f3 390
391 fGeometryBuilder->SetAlign(align);
392}
fe4da5cc 393
82d1ac0a 394//____________________________________________________________________
395 void AliMUON::SetAlign(const TString& fileName, Bool_t align)
396{
d19b6003 397/// Set option for alignement to geometry builder
82d1ac0a 398
399 fGeometryBuilder->SetAlign(fileName, align);
400}
401
ce3f5e87 402//____________________________________________________________________
a9e2aefa 403void AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
fe4da5cc 404{
d19b6003 405/// Set the response for chamber id
2682e810 406 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
fe4da5cc 407}
d19b6003 408
ce3f5e87 409//____________________________________________________________________
c92eb8ad 410AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
85a5290f 411{
a3249004 412/// Return digitizer
68585390 413
a3249004 414 return new AliMUONDigitizerV3(manager, fDigitizerWithNoise);
85a5290f 415}
68585390 416
ce3f5e87 417//_____________________________________________________________________
2ab0c725 418void AliMUON::SDigits2Digits()
419{
d19b6003 420/// Write TreeD here only
d963c261 421
d963c261 422 char hname[30];
88cb7938 423 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
424 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
425 fLoader->TreeD()->Reset();
2ab0c725 426}
a9e2aefa 427
d1775029 428//_____________________________________________________________________
429void AliMUON::Hits2SDigits()
430{
a3249004 431/// Perform Hits2Digits using SDigitizerV2
68585390 432
a3249004 433 TTask* sdigitizer = new AliMUONSDigitizerV2;
434 sdigitizer->ExecuteTask();
d1775029 435}
68585390 436
39e39255 437//_____________________________________________________________________
438void AliMUON::Digits2Raw()
439{
d19b6003 440/// Convert digits of the current event to raw data
441
d5609cfc 442 if (!fRawWriter)
443 {
444 fRawWriter = new AliMUONRawWriter(fMUONData);
445 if (fTriggerScalerEvent == kTRUE)
446 {
84ceeb06 447 fRawWriter->SetScalersNumbers();
d5609cfc 448 }
449 }
450
451 if (!fRawWriter->Digits2Raw())
452 {
453 AliError("pb writting raw data");
454 }
39e39255 455}
68585390 456
241560c2 457//_____________________________________________________________________
458Bool_t AliMUON::Raw2SDigits(AliRawReader* rawReader)
459{
460/// Convert raw data to SDigit
461/// Only for tracking for the moment (ChF)
462
463 //fLoader->LoadDigits("READ");
464 if (!fLoader->TreeS()) fLoader->MakeSDigitsContainer();
465
466 fMUONData->MakeBranch("S");
467 fMUONData->SetTreeAddress("S");
468 fDigitMaker->Raw2Digits(rawReader);
469 fMUONData->Fill("S");
470
471 fLoader->WriteSDigits("OVERWRITE");
472 fMUONData->ResetSDigits();
473 fLoader->UnloadSDigits();
474
475 return kTRUE;
476
477}
478
ce3f5e87 479//_______________________________________________________________________
3fa6cfdd 480AliLoader* AliMUON::MakeLoader(const char* topfoldername)
481{
d19b6003 482/// Build standard getter (AliLoader type);
483/// if detector wants to use castomized getter, it must overload this method
8c343c7c 484
485 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
486 GetName(),topfoldername));
128843d9 487 fLoader = new AliLoader(GetName(),topfoldername);
ce3f5e87 488 fMUONData = new AliMUONData(fLoader,GetName(),GetName());
d652f85c 489 fMUONData->SetSplitLevel(fSplitLevel);
241560c2 490
491 fDigitMaker->SetMUONData(fMUONData);
492
3fa6cfdd 493 return fLoader;
494}
ce3f5e87 495//_______________________________________________________________________
a897a37a 496
497AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
498{
d19b6003 499/// Return rawcluster (icluster) for chamber ichamber and cathode icathod
500/// Obsolete ??
501
ce3f5e87 502 TClonesArray *muonRawCluster = GetMUONData()->RawClusters(ichamber);
a897a37a 503 ResetRawClusters();
88cb7938 504 TTree *treeR = fLoader->TreeR();
a9e2aefa 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();
a897a37a 509
a9e2aefa 510 AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
a897a37a 511 //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
512
513 return mRaw;
514}
ffd9faa2 515
d5609cfc 516//________________________________________________________________________
517void
518AliMUON::ResetGeometryBuilder()
519{
d19b6003 520/// Only to be used by "experts" wanting to change the geometry builders
521/// to be used.
522/// As the ctor of AliMUON now defines a default geometrybuilder, this
523/// ResetGeometryBuilder() must be called prior to call the
524/// AddGeometryBuilder()
525
d5609cfc 526 delete fGeometryBuilder;
527 fGeometryBuilder = new AliMUONGeometryBuilder(this);
528 fGeometryBuilder
529 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
530}
44b96781 531
532//____________________________________________________________________
533Bool_t AliMUON::GetTriggerResponseV1() const
534{
535///
536/// Returns fTriggerResponseV1
537///
538 return fTriggerResponseV1;
539
540}
541
e93b11d0 542//____________________________________________________________________
543Int_t AliMUON::GetTriggerCoinc44() const
544{
545///
546/// Returns fTriggerCoinc44
547///
548 return fTriggerCoinc44;
549
afb3ccf0 550}
551
552//____________________________________________________________________
88570609 553Bool_t AliMUON::GetTriggerEffCells() const
afb3ccf0 554{
555///
556/// Returns fTriggerEffCells
557///
558 return fTriggerEffCells;
559
e93b11d0 560}
561
a3249004 562//____________________________________________________________________
563Bool_t AliMUON::GetDigitizerWithNoise() const
564{
565///
566/// Returns fDigitizerWithNoise
567///
568 return fDigitizerWithNoise;
569
570}
571