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