1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-----------------------------------------------------------------------------
21 // AliDetector class for MUON subsystem
22 // providing simulation data management
23 //-----------------------------------------------------------------------------
28 #include "AliMUONSDigitizerV2.h"
29 #include "AliMUONDigitizerV3.h"
30 #include "AliMUONDigitMaker.h"
31 #include "AliMUONDigit.h"
32 #include "AliMUONCalibrationData.h"
34 #include "AliMUONDigitStoreV1.h"
35 #include "AliMUONTriggerStoreV1.h"
36 #include "AliMUONHitStoreV1.h"
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"
54 #include "AliMUONRawWriter.h"
56 #include "AliLoader.h"
57 #include "AliCDBManager.h"
58 #include "AliDigitizationInput.h"
61 #include "AliRawDataHeaderSim.h"
64 #include <TObjArray.h>
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
84 //__________________________________________________________________
102 fTriggerScalerEvent(kFALSE),
103 fTriggerResponseV1(0),
105 fTriggerEffCells(kTRUE),
106 fDigitizerWithNoise(1),
107 fDigitizerNSigmas(4.0),
108 fIsTailEffect(kTRUE),
109 fConvertTrigger(kFALSE),
113 fDigitStoreConcreteClassName(),
114 fCalibrationData(0x0),
115 fDigitCalibrator(0x0)
117 /// Default Constructor
119 AliDebug(1,Form("default (empty) ctor this=%p",this));
123 //__________________________________________________________________
124 AliMUON::AliMUON(const char *name, const char* title)
125 : AliDetector(name, title),
126 fNCh(AliMUONConstants::NCh()),
127 fNTrackingCh(AliMUONConstants::NTrackingCh()),
136 fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200
137 fMaxDestepAlu(-1), // in the calculation of the tracking parameters
141 fTriggerScalerEvent(kFALSE),
142 fTriggerResponseV1(0),
144 fTriggerEffCells(kTRUE),
145 fDigitizerWithNoise(1),
146 fDigitizerNSigmas(4.0),
147 fIsTailEffect(kTRUE),
148 fConvertTrigger(kFALSE),
150 fDigitMaker(new AliMUONDigitMaker),
152 fDigitStoreConcreteClassName("AliMUONDigitStoreV2S"),
154 fDigitCalibrator(0x0)
156 /// Standard constructor
158 AliDebug(1,Form("ctor this=%p",this));
161 //PH SetMarkerColor(kRed);//
164 fGeometryBuilder = new AliMUONGeometryBuilder(this);
166 // Common geometry definitions
168 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
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.
174 AddGeometryBuilder(new AliMUONSt1GeometryBuilderV2(this));
175 AddGeometryBuilder(new AliMUONSt2GeometryBuilderV2(this));
176 AddGeometryBuilder(new AliMUONSlatGeometryBuilder(this));
177 AddGeometryBuilder(new AliMUONTriggerGeometryBuilder(this));
180 // Creating List of Chambers
182 fChambers = new TObjArray(AliMUONConstants::NCh());
183 fChambers->SetOwner(kTRUE);
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++) {
191 // Default Parameters for Muon Tracking Stations
193 if (ch < AliMUONConstants::NTrackingCh()) {
194 fChambers->AddAt(new AliMUONChamber(ch),ch);
196 fChambers->AddAt(new AliMUONChamberTrigger(ch, GetGeometryTransformer()),ch);
198 } // Chamber stCH (0, 1) in
199 } // Station st (0...)
201 Int_t runnumber = AliCDBManager::Instance()->GetRun();
203 fCalibrationData = new AliMUONCalibrationData(runnumber);
206 //____________________________________________________________________
211 AliDebug(1,Form("dtor this=%p",this));
213 delete fGeometryBuilder;
217 delete fCalibrationData;
218 delete fDigitCalibrator;
221 //_____________________________________________________________________________
222 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
224 /// Add the geometry builder to the list
226 fGeometryBuilder->AddBuilder(geomBuilder);
229 //____________________________________________________________________
230 const AliMUONGeometry* AliMUON::GetGeometry() const
232 /// Return geometry parametrisation
234 if ( !fGeometryBuilder) {
235 AliWarningStream() << "GeometryBuilder not defined." << std::endl;
239 return fGeometryBuilder->GetGeometry();
242 //____________________________________________________________________
243 const AliMUONGeometryTransformer* AliMUON::GetGeometryTransformer() const
245 /// Return geometry parametrisation
247 const AliMUONGeometry* kGeometry = GetGeometry();
249 if ( !kGeometry) return 0;
251 return kGeometry->GetTransformer();
254 //__________________________________________________________________
256 AliMUON::MakeBranch(Option_t* opt)
258 /// Create branche(s) to hold MUON hits
262 if ( sopt != "H" ) return;
266 fHitStore = new AliMUONHitStoreV1;
267 if ( gAlice->GetMCApp() )
269 if ( gAlice->GetMCApp()->GetHitLists() )
271 // AliStack::PurifyKine needs to be able to loop on our hits
272 // to remap the track numbers.
273 gAlice->GetMCApp()->AddHitList(fHitStore->Collection());
278 TTree* treeH = fLoader->TreeH();
282 AliFatal("No TreeH");
285 fHitStore->Connect(*treeH);
288 //__________________________________________________________________
290 AliMUON::SetTreeAddress()
292 /// Set Hits tree address
294 // if ( gAlice->GetMCApp() && fHitStore )
296 // TList* l = gAlice->GetMCApp()->GetHitLists();
299 // TObject* o = l->First();
300 // if (o!=fHitStore->HitCollection())
302 // AliError(Form("Something is strange hitcollection=%x",fHitStore->HitCollection()));
309 //_________________________________________________________________
316 if (fHitStore) fHitStore->Clear();
319 //_________________________________________________________________
320 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
322 /// Set the inverse charge slope for chamber id
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);
329 //__________________________________________________________________
330 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
332 /// Set sigma of charge spread for chamber id
335 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
336 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
338 //___________________________________________________________________
339 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
341 /// Set integration limits for charge spread
343 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
344 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
347 //__________________________________________________________________
348 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
350 /// Set maximum number for ADCcounts (saturation)
353 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
354 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
357 //__________________________________________________________________
358 void AliMUON::SetMaxStepGas(Float_t p1)
360 /// Set stepsize in gas
364 //__________________________________________________________________
365 void AliMUON::SetMaxStepAlu(Float_t p1)
367 /// Set step size in Alu
371 //__________________________________________________________________
372 void AliMUON::SetMaxDestepGas(Float_t p1)
374 /// Set maximum step size in Gas
378 //__________________________________________________________________
379 void AliMUON::SetMaxDestepAlu(Float_t p1)
381 /// Set maximum step size in Alu
386 //____________________________________________________________________
387 Float_t AliMUON::GetMaxStepGas() const
389 /// Return stepsize in gas
394 //____________________________________________________________________
395 Float_t AliMUON::GetMaxStepAlu() const
397 /// Return step size in Alu
402 //____________________________________________________________________
403 Float_t AliMUON::GetMaxDestepGas() const
405 /// Return maximum step size in Gas
407 return fMaxDestepGas;
410 //____________________________________________________________________
411 Float_t AliMUON::GetMaxDestepAlu() const
413 /// Return maximum step size in Gas
415 return fMaxDestepAlu;
418 //____________________________________________________________________
419 void AliMUON::SetAlign(Bool_t align)
421 /// Set option for alignement to geometry builder
423 fGeometryBuilder->SetAlign(align);
426 //____________________________________________________________________
427 void AliMUON::SetAlign(const TString& fileName, Bool_t align)
429 /// Set option for alignement to geometry builder
431 fGeometryBuilder->SetAlign(fileName, align);
434 //____________________________________________________________________
435 void AliMUON::SetResponseModel(Int_t id, const AliMUONResponse& response)
437 /// Set the response for chamber id
438 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
441 //____________________________________________________________________
442 AliDigitizer* AliMUON::CreateDigitizer(AliDigitizationInput* digInput) const
446 AliMUONDigitizerV3* digitizer = new AliMUONDigitizerV3(digInput, fDigitizerWithNoise);
447 AliMUONDigitizerV3::SetNSigmas(fDigitizerNSigmas);
448 digitizer->SetCalibrationData(fCalibrationData,GetRecoParam());
452 //_____________________________________________________________________
453 void AliMUON::SDigits2Digits()
455 /// Write TreeD here only
458 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
459 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
460 fLoader->TreeD()->Reset();
463 //_____________________________________________________________________
464 void AliMUON::Hits2SDigits()
466 /// Perform Hits2Digits using SDigitizerV2
468 AliMUONSDigitizerV2 sdigitizer;
469 sdigitizer.Digitize();
472 //_____________________________________________________________________
473 void AliMUON::Digits2Raw()
475 /// Convert digits of the current event to raw data
477 AliRawDataHeaderSim header;
481 fRawWriter = new AliMUONRawWriter;
482 AliDebug(1,Form("Creating %s",fRawWriter->ClassName()));
483 if (fTriggerScalerEvent == kTRUE)
485 fRawWriter->SetScalersNumbers();
489 fLoader->LoadDigits("READ");
491 TTree* treeD = fLoader->TreeD();
495 AliError("Could not get TreeD");
499 AliMUONVTriggerStore* triggerStore = AliMUONVTriggerStore::Create(*treeD);
500 AliMUONVDigitStore* digitStore = AliMUONVDigitStore::Create(*treeD);
502 triggerStore->Connect(*treeD,kFALSE);
503 digitStore->Connect(*treeD,kFALSE);
507 fRawWriter->SetHeader(header);
508 if (!fRawWriter->Digits2Raw(digitStore,triggerStore))
510 AliError("pb writting raw data");
516 fLoader->UnloadDigits();
519 //_____________________________________________________________________
520 Bool_t AliMUON::Raw2SDigits(AliRawReader* rawReader)
522 /// Convert raw data to SDigit
524 if (!fLoader->TreeS()) fLoader->MakeSDigitsContainer();
526 TTree* treeS = fLoader->TreeS();
528 AliMUONVDigitStore* sDigitStore = AliMUONVDigitStore::Create(DigitStoreClassName());
529 AliMUONVTriggerStore* triggerStore = 0x0;
531 sDigitStore->Connect(*treeS);
533 if (!fDigitMaker) fDigitMaker = new AliMUONDigitMaker;
535 if (fConvertTrigger) {
536 triggerStore = new AliMUONTriggerStoreV1;
537 triggerStore->Connect(*treeS,true);
538 fDigitMaker->SetMakeTriggerDigits(true);
541 if (!fDigitCalibrator)
543 AliMUONRecoParam* recoParam = GetRecoParam();
547 AliFatal("Cannot work without recoparams !");
550 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,recoParam);
553 fDigitMaker->Raw2Digits(rawReader,sDigitStore,triggerStore);
555 fDigitCalibrator->Calibrate(*sDigitStore);
557 TIter next(sDigitStore->CreateIterator());
558 AliMUONDigit* sdigit;
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
563 while ( ( sdigit = static_cast<AliMUONDigit*>(next()) ) )
565 sdigit->Calibrated(kFALSE);
570 fLoader->WriteSDigits("OVERWRITE");
572 fLoader->UnloadSDigits();
581 //_______________________________________________________________________
582 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
584 /// Build standard getter (AliLoader type);
585 /// if detector wants to use castomized getter, it must overload this method
587 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
588 GetName(),topfoldername));
589 fLoader = new AliLoader(GetName(),topfoldername);
594 //________________________________________________________________________
596 AliMUON::ResetGeometryBuilder()
598 /// Only to be used by "experts" wanting to change the geometry builders
600 /// As the ctor of AliMUON now defines a default geometrybuilder, this
601 /// ResetGeometryBuilder() must be called prior to call the
602 /// AddGeometryBuilder()
604 delete fGeometryBuilder;
605 fGeometryBuilder = new AliMUONGeometryBuilder(this);
607 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
610 //____________________________________________________________________
611 Int_t AliMUON::GetTriggerResponseV1() const
614 /// Returns fTriggerResponseV1
616 return fTriggerResponseV1;
620 //____________________________________________________________________
621 Int_t AliMUON::GetTriggerCoinc44() const
624 /// Returns fTriggerCoinc44
626 return fTriggerCoinc44;
630 //____________________________________________________________________
631 Bool_t AliMUON::GetTriggerEffCells() const
634 /// Returns fTriggerEffCells
636 return fTriggerEffCells;
640 //____________________________________________________________________
641 Int_t AliMUON::GetDigitizerWithNoise() const
644 /// Returns fDigitizerWithNoise
646 return fDigitizerWithNoise;
650 //____________________________________________________________________
651 AliMUONRecoParam* AliMUON::GetRecoParam() const
653 AliMUONRecoParam* recoParam = 0x0;
655 AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Calib/RecoParam");
659 // load recoParam according OCDB content (single or array)
660 if (!(recoParam = dynamic_cast<AliMUONRecoParam*>(entry->GetObject())))
662 TObjArray* recoParamArray = static_cast<TObjArray*>(entry->GetObject());
664 for(Int_t i = 0; i < recoParamArray->GetEntriesFast(); ++i)
666 recoParam = static_cast<AliMUONRecoParam*>(recoParamArray->UncheckedAt(i));
667 if (recoParam && recoParam->IsDefault()) break;