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