]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUON.cxx
Fixing memory leaks
[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
3d1463c8 18//-----------------------------------------------------------------------------
d19b6003 19// Class AliMUON
20// ------------------
21// AliDetector class for MUON subsystem
22// providing simulation data management
3d1463c8 23//-----------------------------------------------------------------------------
fe4da5cc 24
4069c48e 25#include "AliMUON.h"
88cb7938 26
4069c48e 27#include "AliMUONSDigitizerV2.h"
28#include "AliMUONDigitizerV3.h"
29#include "AliMUONDigitMaker.h"
30#include "AliMUONCalibrationData.h"
31
32#include "AliMUONDigitStoreV1.h"
33#include "AliMUONVTriggerStore.h"
34#include "AliMUONHitStoreV1.h"
fe4da5cc 35
88cb7938 36#include "AliMUONChamberTrigger.h"
88cb7938 37#include "AliMUONConstants.h"
504d0837 38#include "AliMUONGeometry.h"
39#include "AliMUONGeometryTransformer.h"
d4bb94a1 40#include "AliMUONGeometryBuilder.h"
d1cd2474 41#include "AliMUONVGeometryBuilder.h"
4069c48e 42#include "AliMUONCommonGeometryBuilder.h"
d5609cfc 43#include "AliMUONSt1GeometryBuilderV2.h"
44#include "AliMUONSt2GeometryBuilderV2.h"
45#include "AliMUONSlatGeometryBuilder.h"
46#include "AliMUONTriggerGeometryBuilder.h"
47
4069c48e 48#include "AliMUONRawWriter.h"
49
50#include "AliLoader.h"
51#include "AliCDBManager.h"
52#include "AliRunDigitizer.h"
53#include "AliMC.h"
54#include "AliRun.h"
55#include "AliRawDataHeaderSim.h"
56#include "AliLog.h"
57
58#include <TObjArray.h>
7435e1f8 59
a9e2aefa 60// Defaults parameters for Z positions of chambers
61// taken from values for "stations" in AliMUON::AliMUON
62// const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
63// and from array "dstation" in AliMUONv1::CreateGeometry
64// Float_t dstation[5]={20., 20., 20, 20., 20.};
65// for tracking chambers,
66// according to (Z1 = zch - dstation) and (Z2 = zch + dstation)
67// for the first and second chambers in the station, respectively,
68// and from "DTPLANES" in AliMUONv1::CreateGeometry
69// const Float_t DTPLANES = 15.;
70// for trigger chambers,
71// according to (Z1 = zch) and (Z2 = zch + DTPLANES)
72// for the first and second chambers in the station, respectively
fe4da5cc 73
13985652 74/// \cond CLASSIMP
75ClassImp(AliMUON)
76/// \endcond
30178c30 77
ce3f5e87 78//__________________________________________________________________
fe4da5cc 79AliMUON::AliMUON()
30178c30 80 : AliDetector(),
81 fNCh(0),
82 fNTrackingCh(0),
30178c30 83 fSplitLevel(0),
84 fChambers(0),
d4bb94a1 85 fGeometryBuilder(0),
30178c30 86 fAccCut(kFALSE),
87 fAccMin(0.),
88 fAccMax(0.),
89 fMaxStepGas(0.),
90 fMaxStepAlu(0.),
91 fMaxDestepGas(0.),
92 fMaxDestepAlu(0.),
93 fMaxIterPad(0),
ced309a5 94 fCurIterPad(0),
68585390 95 fTriggerScalerEvent(kFALSE),
e93b11d0 96 fTriggerResponseV1(kFALSE),
97 fTriggerCoinc44(0),
afb3ccf0 98 fTriggerEffCells(0),
8c0b5e70 99 fDigitizerWithNoise(1),
5c083cba 100 fDigitizerNSigmas(4.0),
5fe36481 101 fIsTailEffect(kTRUE),
241560c2 102 fRawWriter(0x0),
7435e1f8 103 fDigitMaker(0x0),
5ee595ac 104 fHitStore(0x0),
92c23b09 105 fDigitStoreConcreteClassName(),
2a5f75ae 106 fCalibrationData(0x0)
fe4da5cc 107{
d19b6003 108/// Default Constructor
109
110 AliDebug(1,Form("default (empty) ctor this=%p",this));
1bd26093 111 fIshunt = 0;
fe4da5cc 112}
30178c30 113
ce3f5e87 114//__________________________________________________________________
9bf406e1 115AliMUON::AliMUON(const char *name, const char* title)
116 : AliDetector(name, title),
30178c30 117 fNCh(AliMUONConstants::NCh()),
118 fNTrackingCh(AliMUONConstants::NTrackingCh()),
30178c30 119 fSplitLevel(0),
120 fChambers(0),
d4bb94a1 121 fGeometryBuilder(0),
30178c30 122 fAccCut(kFALSE),
123 fAccMin(0.),
124 fAccMax(0.),
125 fMaxStepGas(0.1),
126 fMaxStepAlu(0.1),
127 fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200
128 fMaxDestepAlu(-1), // in the calculation of the tracking parameters
129 fMaxIterPad(0),
ced309a5 130 fCurIterPad(0),
e93b11d0 131 fTriggerScalerEvent(kFALSE),
132 fTriggerResponseV1(kFALSE),
133 fTriggerCoinc44(0),
afb3ccf0 134 fTriggerEffCells(0),
8c0b5e70 135 fDigitizerWithNoise(1),
5c083cba 136 fDigitizerNSigmas(4.0),
5fe36481 137 fIsTailEffect(kTRUE),
241560c2 138 fRawWriter(0x0),
7435e1f8 139 fDigitMaker(new AliMUONDigitMaker),
5ee595ac 140 fHitStore(0x0),
92c23b09 141 fDigitStoreConcreteClassName("AliMUONDigitStoreV2S"),
2a5f75ae 142 fCalibrationData()
fe4da5cc 143{
92c23b09 144 /// Standard constructor
d19b6003 145
146 AliDebug(1,Form("ctor this=%p",this));
30178c30 147 fIshunt = 0;
92c23b09 148
e939a978 149 //PH SetMarkerColor(kRed);//
e118b27e 150
151 // Geometry builder
152 fGeometryBuilder = new AliMUONGeometryBuilder(this);
153
154 // Common geometry definitions
155 fGeometryBuilder
156 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
92c23b09 157
d5609cfc 158 // By default, add also all the needed geometry builders.
159 // If you want to change this from outside, please use ResetGeometryBuilder
160 // method, followed by AddGeometryBuilder ones.
92c23b09 161
d5609cfc 162 AddGeometryBuilder(new AliMUONSt1GeometryBuilderV2(this));
163 AddGeometryBuilder(new AliMUONSt2GeometryBuilderV2(this));
164 AddGeometryBuilder(new AliMUONSlatGeometryBuilder(this));
165 AddGeometryBuilder(new AliMUONTriggerGeometryBuilder(this));
166
167 //
168 // Creating List of Chambers
a9e2aefa 169 Int_t ch;
f665c1ea 170 fChambers = new TObjArray(AliMUONConstants::NCh());
7435e1f8 171 fChambers->SetOwner(kTRUE);
172
a9e2aefa 173 // Loop over stations
f665c1ea 174 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
a9e2aefa 175 // Loop over 2 chambers in the station
ce3f5e87 176 for (Int_t stCH = 0; stCH < 2; stCH++) {
177 //
178 //
179 // Default Parameters for Muon Tracking Stations
180 ch = 2 * st + stCH;
181 if (ch < AliMUONConstants::NTrackingCh()) {
182 fChambers->AddAt(new AliMUONChamber(ch),ch);
183 } else {
504d0837 184 fChambers->AddAt(new AliMUONChamberTrigger(ch, GetGeometryTransformer()),ch);
ce3f5e87 185 }
ce3f5e87 186 } // Chamber stCH (0, 1) in
a9e2aefa 187 } // Station st (0...)
92c23b09 188
189 Int_t runnumber = AliCDBManager::Instance()->GetRun();
190
191 fCalibrationData = new AliMUONCalibrationData(runnumber);
fe4da5cc 192}
30178c30 193
ce3f5e87 194//____________________________________________________________________
fe4da5cc 195AliMUON::~AliMUON()
196{
d19b6003 197/// Destructor
198
edee5e63 199 AliDebug(1,Form("dtor this=%p",this));
7435e1f8 200 delete fChambers;
d4bb94a1 201 delete fGeometryBuilder;
d5609cfc 202 delete fRawWriter;
241560c2 203 delete fDigitMaker;
7435e1f8 204 delete fHitStore;
92c23b09 205 delete fCalibrationData;
d1cd2474 206}
30178c30 207
d1cd2474 208//_____________________________________________________________________________
209void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
210{
d19b6003 211/// Add the geometry builder to the list
d1cd2474 212
d4bb94a1 213 fGeometryBuilder->AddBuilder(geomBuilder);
a897a37a 214}
c9d10ab5 215
504d0837 216//____________________________________________________________________
217const AliMUONGeometry* AliMUON::GetGeometry() const
218{
d19b6003 219/// Return geometry parametrisation
504d0837 220
221 if ( !fGeometryBuilder) {
222 AliWarningStream() << "GeometryBuilder not defined." << std::endl;
223 return 0;
224 }
225
226 return fGeometryBuilder->GetGeometry();
227}
228
229//____________________________________________________________________
230const AliMUONGeometryTransformer* AliMUON::GetGeometryTransformer() const
231{
d19b6003 232/// Return geometry parametrisation
504d0837 233
234 const AliMUONGeometry* kGeometry = GetGeometry();
235
236 if ( !kGeometry) return 0;
237
238 return kGeometry->GetTransformer();
239}
240
ce3f5e87 241//__________________________________________________________________
7435e1f8 242void
243AliMUON::MakeBranch(Option_t* opt)
a897a37a 244{
7435e1f8 245 /// Create branche(s) to hold MUON hits
246 AliDebug(1,"");
247
248 TString sopt(opt);
249 if ( sopt != "H" ) return;
250
251 if (!fHitStore)
252 {
253 fHitStore = new AliMUONHitStoreV1;
ae31c826 254 if ( gAlice->GetMCApp() )
7435e1f8 255 {
256 if ( gAlice->GetMCApp()->GetHitLists() )
257 {
258 // AliStack::PurifyKine needs to be able to loop on our hits
259 // to remap the track numbers.
260 gAlice->GetMCApp()->AddHitList(fHitStore->Collection());
6d2f7cbd 261 }
7435e1f8 262 }
263 }
264
265 TTree* treeH = fLoader->TreeH();
266
267 if (!treeH)
268 {
269 AliFatal("No TreeH");
307d9d04 270 }
7435e1f8 271
272 fHitStore->Connect(*treeH);
273}
274
275//__________________________________________________________________
276void
277AliMUON::SetTreeAddress()
278{
279 /// Set Hits tree address
280
281// if ( gAlice->GetMCApp() && fHitStore )
282// {
283// TList* l = gAlice->GetMCApp()->GetHitLists();
284// if ( l )
285// {
286// TObject* o = l->First();
287// if (o!=fHitStore->HitCollection())
288// {
289// AliError(Form("Something is strange hitcollection=%x",fHitStore->HitCollection()));
290// l->Print();
291// }
292// }
293// }
294}
295
296//_________________________________________________________________
297void
298AliMUON::ResetHits()
299{
300 /// Reset hits
301
302 AliDebug(1,"");
303 if (fHitStore) fHitStore->Clear();
a9e2aefa 304}
305
ce3f5e87 306//_________________________________________________________________
a897a37a 307void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
fe4da5cc 308{
d19b6003 309/// Set the inverse charge slope for chamber id
310
ce3f5e87 311 Int_t i=2*(id-1); //PH ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
312 //PH ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
2682e810 313 ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
314 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
fe4da5cc 315}
ce3f5e87 316//__________________________________________________________________
a897a37a 317void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
fe4da5cc 318{
d19b6003 319/// Set sigma of charge spread for chamber id
320
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{
d19b6003 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{
d19b6003 337/// Set maximum number for ADCcounts (saturation)
338
fe4da5cc 339 Int_t i=2*(id-1);
2682e810 340 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
341 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
fe4da5cc 342}
d4bb94a1 343
ce3f5e87 344//__________________________________________________________________
a897a37a 345void AliMUON::SetMaxStepGas(Float_t p1)
fe4da5cc 346{
d19b6003 347/// Set stepsize in gas
348
ce3f5e87 349 fMaxStepGas=p1;
fe4da5cc 350}
ce3f5e87 351//__________________________________________________________________
a897a37a 352void AliMUON::SetMaxStepAlu(Float_t p1)
fe4da5cc 353{
d19b6003 354/// Set step size in Alu
355
fe4da5cc 356 fMaxStepAlu=p1;
357}
ce3f5e87 358//__________________________________________________________________
a897a37a 359void AliMUON::SetMaxDestepGas(Float_t p1)
fe4da5cc 360{
d19b6003 361/// Set maximum step size in Gas
362
fe4da5cc 363 fMaxDestepGas=p1;
364}
ce3f5e87 365//__________________________________________________________________
a897a37a 366void AliMUON::SetMaxDestepAlu(Float_t p1)
fe4da5cc 367{
d19b6003 368/// Set maximum step size in Alu
369
ce3f5e87 370 fMaxDestepAlu=p1;
fe4da5cc 371}
d4bb94a1 372
d1cd2474 373//____________________________________________________________________
374Float_t AliMUON::GetMaxStepGas() const
375{
d19b6003 376/// Return stepsize in gas
d1cd2474 377
378 return fMaxStepGas;
379}
380
381//____________________________________________________________________
382Float_t AliMUON::GetMaxStepAlu() const
383{
d19b6003 384/// Return step size in Alu
d1cd2474 385
386 return fMaxStepAlu;
387}
388
389//____________________________________________________________________
390Float_t AliMUON::GetMaxDestepGas() const
391{
d19b6003 392/// Return maximum step size in Gas
d1cd2474 393
394 return fMaxDestepGas;
395}
396
397//____________________________________________________________________
398Float_t AliMUON::GetMaxDestepAlu() const
399{
d19b6003 400/// Return maximum step size in Gas
d1cd2474 401
402 return fMaxDestepAlu;
403}
d4bb94a1 404
883746f3 405//____________________________________________________________________
406 void AliMUON::SetAlign(Bool_t align)
a713db22 407{
d19b6003 408/// Set option for alignement to geometry builder
883746f3 409
410 fGeometryBuilder->SetAlign(align);
411}
fe4da5cc 412
82d1ac0a 413//____________________________________________________________________
414 void AliMUON::SetAlign(const TString& fileName, Bool_t align)
415{
d19b6003 416/// Set option for alignement to geometry builder
82d1ac0a 417
418 fGeometryBuilder->SetAlign(fileName, align);
419}
420
ce3f5e87 421//____________________________________________________________________
7435e1f8 422void AliMUON::SetResponseModel(Int_t id, const AliMUONResponse& response)
fe4da5cc 423{
d19b6003 424/// Set the response for chamber id
2682e810 425 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
fe4da5cc 426}
d19b6003 427
ce3f5e87 428//____________________________________________________________________
c92eb8ad 429AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
85a5290f 430{
a3249004 431/// Return digitizer
68585390 432
92c23b09 433 AliMUONDigitizerV3* digitizer = new AliMUONDigitizerV3(manager, fDigitizerWithNoise);
5c083cba 434 AliMUONDigitizerV3::SetNSigmas(fDigitizerNSigmas);
b89ac3d6 435 digitizer->SetCalibrationData(fCalibrationData);
92c23b09 436 return digitizer;
85a5290f 437}
68585390 438
ce3f5e87 439//_____________________________________________________________________
2ab0c725 440void AliMUON::SDigits2Digits()
441{
d19b6003 442/// Write TreeD here only
d963c261 443
d963c261 444 char hname[30];
88cb7938 445 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
446 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
447 fLoader->TreeD()->Reset();
2ab0c725 448}
a9e2aefa 449
d1775029 450//_____________________________________________________________________
451void AliMUON::Hits2SDigits()
452{
a3249004 453/// Perform Hits2Digits using SDigitizerV2
68585390 454
7435e1f8 455 AliMUONSDigitizerV2 sdigitizer;
456 sdigitizer.ExecuteTask();
d1775029 457}
68585390 458
39e39255 459//_____________________________________________________________________
460void AliMUON::Digits2Raw()
461{
d19b6003 462/// Convert digits of the current event to raw data
463
0014fbe8 464 AliRawDataHeaderSim header;
465
d5609cfc 466 if (!fRawWriter)
467 {
7435e1f8 468 fRawWriter = new AliMUONRawWriter;
469 AliDebug(1,Form("Creating %s",fRawWriter->ClassName()));
d5609cfc 470 if (fTriggerScalerEvent == kTRUE)
471 {
84ceeb06 472 fRawWriter->SetScalersNumbers();
d5609cfc 473 }
474 }
475
7435e1f8 476 fLoader->LoadDigits("READ");
477
478 TTree* treeD = fLoader->TreeD();
479
480 if (!treeD)
481 {
482 AliError("Could not get TreeD");
483 return;
484 }
485
486 AliMUONVTriggerStore* triggerStore = AliMUONVTriggerStore::Create(*treeD);
487 AliMUONVDigitStore* digitStore = AliMUONVDigitStore::Create(*treeD);
488
489 triggerStore->Connect(*treeD,kFALSE);
490 digitStore->Connect(*treeD,kFALSE);
491
492 treeD->GetEvent(0);
493
0014fbe8 494 fRawWriter->SetHeader(header);
7435e1f8 495 if (!fRawWriter->Digits2Raw(digitStore,triggerStore))
d5609cfc 496 {
497 AliError("pb writting raw data");
498 }
7435e1f8 499
500 delete triggerStore;
501 delete digitStore;
502
503 fLoader->UnloadDigits();
39e39255 504}
68585390 505
241560c2 506//_____________________________________________________________________
507Bool_t AliMUON::Raw2SDigits(AliRawReader* rawReader)
508{
509/// Convert raw data to SDigit
241560c2 510
7435e1f8 511 fLoader->LoadDigits("READ");
241560c2 512 if (!fLoader->TreeS()) fLoader->MakeSDigitsContainer();
513
7435e1f8 514 TTree* treeS = fLoader->TreeS();
515
516 AliMUONVDigitStore* sDigitStore = new AliMUONDigitStoreV1;
517 sDigitStore->Connect(*treeS);
518
519 fDigitMaker->Raw2Digits(rawReader,sDigitStore,0x0);
241560c2 520
521 fLoader->WriteSDigits("OVERWRITE");
7435e1f8 522
241560c2 523 fLoader->UnloadSDigits();
524
7435e1f8 525 delete sDigitStore;
526
241560c2 527 return kTRUE;
241560c2 528}
529
ce3f5e87 530//_______________________________________________________________________
3fa6cfdd 531AliLoader* AliMUON::MakeLoader(const char* topfoldername)
532{
d19b6003 533/// Build standard getter (AliLoader type);
534/// if detector wants to use castomized getter, it must overload this method
8c343c7c 535
536 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
537 GetName(),topfoldername));
128843d9 538 fLoader = new AliLoader(GetName(),topfoldername);
241560c2 539
3fa6cfdd 540 return fLoader;
541}
ffd9faa2 542
d5609cfc 543//________________________________________________________________________
544void
545AliMUON::ResetGeometryBuilder()
546{
d19b6003 547/// Only to be used by "experts" wanting to change the geometry builders
548/// to be used.
549/// As the ctor of AliMUON now defines a default geometrybuilder, this
550/// ResetGeometryBuilder() must be called prior to call the
551/// AddGeometryBuilder()
552
d5609cfc 553 delete fGeometryBuilder;
554 fGeometryBuilder = new AliMUONGeometryBuilder(this);
555 fGeometryBuilder
556 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
557}
44b96781 558
559//____________________________________________________________________
560Bool_t AliMUON::GetTriggerResponseV1() const
561{
562///
563/// Returns fTriggerResponseV1
564///
565 return fTriggerResponseV1;
566
567}
568
e93b11d0 569//____________________________________________________________________
570Int_t AliMUON::GetTriggerCoinc44() const
571{
572///
573/// Returns fTriggerCoinc44
574///
575 return fTriggerCoinc44;
576
afb3ccf0 577}
578
579//____________________________________________________________________
88570609 580Bool_t AliMUON::GetTriggerEffCells() const
afb3ccf0 581{
582///
583/// Returns fTriggerEffCells
584///
585 return fTriggerEffCells;
586
e93b11d0 587}
588
a3249004 589//____________________________________________________________________
8c0b5e70 590Int_t AliMUON::GetDigitizerWithNoise() const
a3249004 591{
592///
593/// Returns fDigitizerWithNoise
594///
595 return fDigitizerWithNoise;
596
597}
598
b6c94614 599