a/ AliTRDCalibTask.cxx .h: one histo more to quantify the event selection if any...
[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),
d631bec8 95 fIsMaxStep(kTRUE),
68585390 96 fTriggerScalerEvent(kFALSE),
e93b11d0 97 fTriggerResponseV1(kFALSE),
98 fTriggerCoinc44(0),
afb3ccf0 99 fTriggerEffCells(0),
8c0b5e70 100 fDigitizerWithNoise(1),
5c083cba 101 fDigitizerNSigmas(4.0),
5fe36481 102 fIsTailEffect(kTRUE),
241560c2 103 fRawWriter(0x0),
7435e1f8 104 fDigitMaker(0x0),
5ee595ac 105 fHitStore(0x0),
92c23b09 106 fDigitStoreConcreteClassName(),
2a5f75ae 107 fCalibrationData(0x0)
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),
d631bec8 132 fIsMaxStep(kTRUE),
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"),
2a5f75ae 144 fCalibrationData()
fe4da5cc 145{
92c23b09 146 /// Standard constructor
d19b6003 147
148 AliDebug(1,Form("ctor this=%p",this));
30178c30 149 fIshunt = 0;
92c23b09 150
e939a978 151 //PH SetMarkerColor(kRed);//
e118b27e 152
153 // Geometry builder
154 fGeometryBuilder = new AliMUONGeometryBuilder(this);
155
156 // Common geometry definitions
157 fGeometryBuilder
158 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
92c23b09 159
d5609cfc 160 // By default, add also all the needed geometry builders.
161 // If you want to change this from outside, please use ResetGeometryBuilder
162 // method, followed by AddGeometryBuilder ones.
92c23b09 163
d5609cfc 164 AddGeometryBuilder(new AliMUONSt1GeometryBuilderV2(this));
165 AddGeometryBuilder(new AliMUONSt2GeometryBuilderV2(this));
166 AddGeometryBuilder(new AliMUONSlatGeometryBuilder(this));
167 AddGeometryBuilder(new AliMUONTriggerGeometryBuilder(this));
168
169 //
170 // Creating List of Chambers
a9e2aefa 171 Int_t ch;
f665c1ea 172 fChambers = new TObjArray(AliMUONConstants::NCh());
7435e1f8 173 fChambers->SetOwner(kTRUE);
174
a9e2aefa 175 // Loop over stations
f665c1ea 176 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
a9e2aefa 177 // Loop over 2 chambers in the station
ce3f5e87 178 for (Int_t stCH = 0; stCH < 2; stCH++) {
179 //
180 //
181 // Default Parameters for Muon Tracking Stations
182 ch = 2 * st + stCH;
183 if (ch < AliMUONConstants::NTrackingCh()) {
184 fChambers->AddAt(new AliMUONChamber(ch),ch);
185 } else {
504d0837 186 fChambers->AddAt(new AliMUONChamberTrigger(ch, GetGeometryTransformer()),ch);
ce3f5e87 187 }
ce3f5e87 188 } // Chamber stCH (0, 1) in
a9e2aefa 189 } // Station st (0...)
92c23b09 190
191 Int_t runnumber = AliCDBManager::Instance()->GetRun();
192
193 fCalibrationData = new AliMUONCalibrationData(runnumber);
fe4da5cc 194}
30178c30 195
ce3f5e87 196//____________________________________________________________________
fe4da5cc 197AliMUON::~AliMUON()
198{
d19b6003 199/// Destructor
200
edee5e63 201 AliDebug(1,Form("dtor this=%p",this));
7435e1f8 202 delete fChambers;
d4bb94a1 203 delete fGeometryBuilder;
d5609cfc 204 delete fRawWriter;
241560c2 205 delete fDigitMaker;
7435e1f8 206 delete fHitStore;
92c23b09 207 delete fCalibrationData;
d1cd2474 208}
30178c30 209
d1cd2474 210//_____________________________________________________________________________
211void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
212{
d19b6003 213/// Add the geometry builder to the list
d1cd2474 214
d4bb94a1 215 fGeometryBuilder->AddBuilder(geomBuilder);
a897a37a 216}
c9d10ab5 217
ce3f5e87 218//____________________________________________________________________
504d0837 219const AliMUONGeometry* AliMUON::GetGeometry() const
220{
d19b6003 221/// Return geometry parametrisation
504d0837 222
223 if ( !fGeometryBuilder) {
224 AliWarningStream() << "GeometryBuilder not defined." << std::endl;
225 return 0;
226 }
227
228 return fGeometryBuilder->GetGeometry();
229}
230
231//____________________________________________________________________
232const AliMUONGeometryTransformer* AliMUON::GetGeometryTransformer() const
233{
d19b6003 234/// Return geometry parametrisation
504d0837 235
236 const AliMUONGeometry* kGeometry = GetGeometry();
237
238 if ( !kGeometry) return 0;
239
240 return kGeometry->GetTransformer();
241}
242
ce3f5e87 243//__________________________________________________________________
7435e1f8 244void
245AliMUON::MakeBranch(Option_t* opt)
a897a37a 246{
7435e1f8 247 /// Create branche(s) to hold MUON hits
248 AliDebug(1,"");
249
250 TString sopt(opt);
251 if ( sopt != "H" ) return;
252
253 if (!fHitStore)
254 {
255 fHitStore = new AliMUONHitStoreV1;
ae31c826 256 if ( gAlice->GetMCApp() )
7435e1f8 257 {
258 if ( gAlice->GetMCApp()->GetHitLists() )
259 {
260 // AliStack::PurifyKine needs to be able to loop on our hits
261 // to remap the track numbers.
262 gAlice->GetMCApp()->AddHitList(fHitStore->Collection());
6d2f7cbd 263 }
7435e1f8 264 }
265 }
266
267 TTree* treeH = fLoader->TreeH();
268
269 if (!treeH)
270 {
271 AliFatal("No TreeH");
307d9d04 272 }
7435e1f8 273
274 fHitStore->Connect(*treeH);
275}
276
277//__________________________________________________________________
278void
279AliMUON::SetTreeAddress()
280{
281 /// Set Hits tree address
282
283// if ( gAlice->GetMCApp() && fHitStore )
284// {
285// TList* l = gAlice->GetMCApp()->GetHitLists();
286// if ( l )
287// {
288// TObject* o = l->First();
289// if (o!=fHitStore->HitCollection())
290// {
291// AliError(Form("Something is strange hitcollection=%x",fHitStore->HitCollection()));
292// l->Print();
293// }
294// }
295// }
296}
297
298//_________________________________________________________________
299void
300AliMUON::ResetHits()
301{
302 /// Reset hits
303
304 AliDebug(1,"");
305 if (fHitStore) fHitStore->Clear();
a9e2aefa 306}
307
ce3f5e87 308//_________________________________________________________________
a897a37a 309void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
fe4da5cc 310{
d19b6003 311/// Set the inverse charge slope for chamber id
312
ce3f5e87 313 Int_t i=2*(id-1); //PH ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
314 //PH ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
2682e810 315 ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
316 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
fe4da5cc 317}
ce3f5e87 318//__________________________________________________________________
a897a37a 319void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
fe4da5cc 320{
d19b6003 321/// Set sigma of charge spread for chamber id
322
fe4da5cc 323 Int_t i=2*(id-1);
2682e810 324 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
325 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
fe4da5cc 326}
ce3f5e87 327//___________________________________________________________________
a897a37a 328void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
fe4da5cc 329{
d19b6003 330/// Set integration limits for charge spread
fe4da5cc 331 Int_t i=2*(id-1);
2682e810 332 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
333 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
fe4da5cc 334}
335
ce3f5e87 336//__________________________________________________________________
d09fafb0 337void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
fe4da5cc 338{
d19b6003 339/// Set maximum number for ADCcounts (saturation)
340
fe4da5cc 341 Int_t i=2*(id-1);
2682e810 342 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
343 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
fe4da5cc 344}
d4bb94a1 345
ce3f5e87 346//__________________________________________________________________
a897a37a 347void AliMUON::SetMaxStepGas(Float_t p1)
fe4da5cc 348{
d19b6003 349/// Set stepsize in gas
350
ce3f5e87 351 fMaxStepGas=p1;
fe4da5cc 352}
ce3f5e87 353//__________________________________________________________________
a897a37a 354void AliMUON::SetMaxStepAlu(Float_t p1)
fe4da5cc 355{
d19b6003 356/// Set step size in Alu
357
fe4da5cc 358 fMaxStepAlu=p1;
359}
ce3f5e87 360//__________________________________________________________________
a897a37a 361void AliMUON::SetMaxDestepGas(Float_t p1)
fe4da5cc 362{
d19b6003 363/// Set maximum step size in Gas
364
fe4da5cc 365 fMaxDestepGas=p1;
366}
ce3f5e87 367//__________________________________________________________________
a897a37a 368void AliMUON::SetMaxDestepAlu(Float_t p1)
fe4da5cc 369{
d19b6003 370/// Set maximum step size in Alu
371
ce3f5e87 372 fMaxDestepAlu=p1;
fe4da5cc 373}
d4bb94a1 374
d1cd2474 375//____________________________________________________________________
376Float_t AliMUON::GetMaxStepGas() const
377{
d19b6003 378/// Return stepsize in gas
d1cd2474 379
380 return fMaxStepGas;
381}
382
383//____________________________________________________________________
384Float_t AliMUON::GetMaxStepAlu() const
385{
d19b6003 386/// Return step size in Alu
d1cd2474 387
388 return fMaxStepAlu;
389}
390
391//____________________________________________________________________
392Float_t AliMUON::GetMaxDestepGas() const
393{
d19b6003 394/// Return maximum step size in Gas
d1cd2474 395
396 return fMaxDestepGas;
397}
398
399//____________________________________________________________________
400Float_t AliMUON::GetMaxDestepAlu() const
401{
d19b6003 402/// Return maximum step size in Gas
d1cd2474 403
404 return fMaxDestepAlu;
405}
d4bb94a1 406
ce3f5e87 407//____________________________________________________________________
883746f3 408 void AliMUON::SetAlign(Bool_t align)
a713db22 409{
d19b6003 410/// Set option for alignement to geometry builder
883746f3 411
412 fGeometryBuilder->SetAlign(align);
413}
fe4da5cc 414
ce3f5e87 415//____________________________________________________________________
82d1ac0a 416 void AliMUON::SetAlign(const TString& fileName, Bool_t align)
417{
d19b6003 418/// Set option for alignement to geometry builder
82d1ac0a 419
420 fGeometryBuilder->SetAlign(fileName, align);
421}
422
423//____________________________________________________________________
7435e1f8 424void AliMUON::SetResponseModel(Int_t id, const AliMUONResponse& response)
fe4da5cc 425{
d19b6003 426/// Set the response for chamber id
2682e810 427 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
fe4da5cc 428}
d19b6003 429
ce3f5e87 430//____________________________________________________________________
c92eb8ad 431AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
85a5290f 432{
a3249004 433/// Return digitizer
68585390 434
92c23b09 435 AliMUONDigitizerV3* digitizer = new AliMUONDigitizerV3(manager, fDigitizerWithNoise);
5c083cba 436 AliMUONDigitizerV3::SetNSigmas(fDigitizerNSigmas);
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{
ca8c8223 511 /// Convert raw data to SDigit
512
241560c2 513 if (!fLoader->TreeS()) fLoader->MakeSDigitsContainer();
ca8c8223 514
7435e1f8 515 TTree* treeS = fLoader->TreeS();
516
ca8c8223 517 AliMUONVDigitStore* sDigitStore = AliMUONVDigitStore::Create(DigitStoreClassName());
518
7435e1f8 519 sDigitStore->Connect(*treeS);
520
ca8c8223 521 if (!fDigitMaker) fDigitMaker = new AliMUONDigitMaker;
522 fDigitMaker->Raw2Digits(rawReader,sDigitStore,0x0,kTRUE);
7ead8580 523 treeS->Fill();
241560c2 524 fLoader->WriteSDigits("OVERWRITE");
ca8c8223 525
241560c2 526 fLoader->UnloadSDigits();
ca8c8223 527
7435e1f8 528 delete sDigitStore;
529
241560c2 530 return kTRUE;
241560c2 531}
532
ce3f5e87 533//_______________________________________________________________________
3fa6cfdd 534AliLoader* AliMUON::MakeLoader(const char* topfoldername)
535{
d19b6003 536/// Build standard getter (AliLoader type);
537/// if detector wants to use castomized getter, it must overload this method
8c343c7c 538
539 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
540 GetName(),topfoldername));
128843d9 541 fLoader = new AliLoader(GetName(),topfoldername);
241560c2 542
3fa6cfdd 543 return fLoader;
544}
ffd9faa2 545
d5609cfc 546//________________________________________________________________________
547void
548AliMUON::ResetGeometryBuilder()
549{
d19b6003 550/// Only to be used by "experts" wanting to change the geometry builders
551/// to be used.
552/// As the ctor of AliMUON now defines a default geometrybuilder, this
553/// ResetGeometryBuilder() must be called prior to call the
554/// AddGeometryBuilder()
555
d5609cfc 556 delete fGeometryBuilder;
557 fGeometryBuilder = new AliMUONGeometryBuilder(this);
558 fGeometryBuilder
559 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
560}
44b96781 561
562//____________________________________________________________________
563Bool_t AliMUON::GetTriggerResponseV1() const
564{
565///
566/// Returns fTriggerResponseV1
567///
568 return fTriggerResponseV1;
569
570}
571
e93b11d0 572//____________________________________________________________________
573Int_t AliMUON::GetTriggerCoinc44() const
574{
575///
576/// Returns fTriggerCoinc44
577///
578 return fTriggerCoinc44;
579
afb3ccf0 580}
581
582//____________________________________________________________________
88570609 583Bool_t AliMUON::GetTriggerEffCells() const
afb3ccf0 584{
585///
586/// Returns fTriggerEffCells
587///
588 return fTriggerEffCells;
589
e93b11d0 590}
591
a3249004 592//____________________________________________________________________
8c0b5e70 593Int_t AliMUON::GetDigitizerWithNoise() const
a3249004 594{
595///
596/// Returns fDigitizerWithNoise
597///
598 return fDigitizerWithNoise;
599
600}
601
b6c94614 602