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