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