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 //-----------------------------------------------------------------------------
27 #include "AliMUONSDigitizerV2.h"
28 #include "AliMUONDigitizerV3.h"
29 #include "AliMUONDigitMaker.h"
30 #include "AliMUONDigit.h"
31 #include "AliMUONCalibrationData.h"
33 #include "AliMUONDigitStoreV1.h"
34 #include "AliMUONTriggerStoreV1.h"
35 #include "AliMUONHitStoreV1.h"
37 #include "AliMUONChamberTrigger.h"
38 #include "AliMUONConstants.h"
39 #include "AliMUONGeometry.h"
40 #include "AliMUONGeometryTransformer.h"
41 #include "AliMUONGeometryBuilder.h"
42 #include "AliMUONVGeometryBuilder.h"
43 #include "AliMUONCommonGeometryBuilder.h"
44 #include "AliMUONSt1GeometryBuilderV2.h"
45 #include "AliMUONSt2GeometryBuilderV2.h"
46 #include "AliMUONSlatGeometryBuilder.h"
47 #include "AliMUONTriggerGeometryBuilder.h"
48 #include "AliMUONDigitCalibrator.h"
49 #include "AliMUONRecoParam.h"
50 #include "AliCDBManager.h"
51 #include "AliCDBEntry.h"
53 #include "AliMUONRawWriter.h"
55 #include "AliLoader.h"
56 #include "AliCDBManager.h"
57 #include "AliRunDigitizer.h"
60 #include "AliRawDataHeaderSim.h"
63 #include <TObjArray.h>
65 // Defaults parameters for Z positions of chambers
66 // taken from values for "stations" in AliMUON::AliMUON
67 // const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
68 // and from array "dstation" in AliMUONv1::CreateGeometry
69 // Float_t dstation[5]={20., 20., 20, 20., 20.};
70 // for tracking chambers,
71 // according to (Z1 = zch - dstation) and (Z2 = zch + dstation)
72 // for the first and second chambers in the station, respectively,
73 // and from "DTPLANES" in AliMUONv1::CreateGeometry
74 // const Float_t DTPLANES = 15.;
75 // for trigger chambers,
76 // according to (Z1 = zch) and (Z2 = zch + DTPLANES)
77 // for the first and second chambers in the station, respectively
83 //__________________________________________________________________
101 fTriggerScalerEvent(kFALSE),
102 fTriggerResponseV1(kFALSE),
105 fDigitizerWithNoise(1),
106 fDigitizerNSigmas(4.0),
107 fIsTailEffect(kTRUE),
108 fConvertTrigger(kFALSE),
112 fDigitStoreConcreteClassName(),
113 fCalibrationData(0x0),
114 fDigitCalibrator(0x0)
116 /// Default Constructor
118 AliDebug(1,Form("default (empty) ctor this=%p",this));
122 //__________________________________________________________________
123 AliMUON::AliMUON(const char *name, const char* title)
124 : AliDetector(name, title),
125 fNCh(AliMUONConstants::NCh()),
126 fNTrackingCh(AliMUONConstants::NTrackingCh()),
135 fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200
136 fMaxDestepAlu(-1), // in the calculation of the tracking parameters
140 fTriggerScalerEvent(kFALSE),
141 fTriggerResponseV1(kFALSE),
144 fDigitizerWithNoise(1),
145 fDigitizerNSigmas(4.0),
146 fIsTailEffect(kTRUE),
147 fConvertTrigger(kFALSE),
149 fDigitMaker(new AliMUONDigitMaker),
151 fDigitStoreConcreteClassName("AliMUONDigitStoreV2S"),
153 fDigitCalibrator(0x0)
155 /// Standard constructor
157 AliDebug(1,Form("ctor this=%p",this));
160 //PH SetMarkerColor(kRed);//
163 fGeometryBuilder = new AliMUONGeometryBuilder(this);
165 // Common geometry definitions
167 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
169 // By default, add also all the needed geometry builders.
170 // If you want to change this from outside, please use ResetGeometryBuilder
171 // method, followed by AddGeometryBuilder ones.
173 AddGeometryBuilder(new AliMUONSt1GeometryBuilderV2(this));
174 AddGeometryBuilder(new AliMUONSt2GeometryBuilderV2(this));
175 AddGeometryBuilder(new AliMUONSlatGeometryBuilder(this));
176 AddGeometryBuilder(new AliMUONTriggerGeometryBuilder(this));
179 // Creating List of Chambers
181 fChambers = new TObjArray(AliMUONConstants::NCh());
182 fChambers->SetOwner(kTRUE);
184 // Loop over stations
185 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
186 // Loop over 2 chambers in the station
187 for (Int_t stCH = 0; stCH < 2; stCH++) {
190 // Default Parameters for Muon Tracking Stations
192 if (ch < AliMUONConstants::NTrackingCh()) {
193 fChambers->AddAt(new AliMUONChamber(ch),ch);
195 fChambers->AddAt(new AliMUONChamberTrigger(ch, GetGeometryTransformer()),ch);
197 } // Chamber stCH (0, 1) in
198 } // Station st (0...)
200 Int_t runnumber = AliCDBManager::Instance()->GetRun();
202 fCalibrationData = new AliMUONCalibrationData(runnumber);
205 //____________________________________________________________________
210 AliDebug(1,Form("dtor this=%p",this));
212 delete fGeometryBuilder;
216 delete fCalibrationData;
217 delete fDigitCalibrator;
220 //_____________________________________________________________________________
221 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
223 /// Add the geometry builder to the list
225 fGeometryBuilder->AddBuilder(geomBuilder);
228 //____________________________________________________________________
229 const AliMUONGeometry* AliMUON::GetGeometry() const
231 /// Return geometry parametrisation
233 if ( !fGeometryBuilder) {
234 AliWarningStream() << "GeometryBuilder not defined." << std::endl;
238 return fGeometryBuilder->GetGeometry();
241 //____________________________________________________________________
242 const AliMUONGeometryTransformer* AliMUON::GetGeometryTransformer() const
244 /// Return geometry parametrisation
246 const AliMUONGeometry* kGeometry = GetGeometry();
248 if ( !kGeometry) return 0;
250 return kGeometry->GetTransformer();
253 //__________________________________________________________________
255 AliMUON::MakeBranch(Option_t* opt)
257 /// Create branche(s) to hold MUON hits
261 if ( sopt != "H" ) return;
265 fHitStore = new AliMUONHitStoreV1;
266 if ( gAlice->GetMCApp() )
268 if ( gAlice->GetMCApp()->GetHitLists() )
270 // AliStack::PurifyKine needs to be able to loop on our hits
271 // to remap the track numbers.
272 gAlice->GetMCApp()->AddHitList(fHitStore->Collection());
277 TTree* treeH = fLoader->TreeH();
281 AliFatal("No TreeH");
284 fHitStore->Connect(*treeH);
287 //__________________________________________________________________
289 AliMUON::SetTreeAddress()
291 /// Set Hits tree address
293 // if ( gAlice->GetMCApp() && fHitStore )
295 // TList* l = gAlice->GetMCApp()->GetHitLists();
298 // TObject* o = l->First();
299 // if (o!=fHitStore->HitCollection())
301 // AliError(Form("Something is strange hitcollection=%x",fHitStore->HitCollection()));
308 //_________________________________________________________________
315 if (fHitStore) fHitStore->Clear();
318 //_________________________________________________________________
319 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
321 /// Set the inverse charge slope for chamber id
323 Int_t i=2*(id-1); //PH ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
324 //PH ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
325 ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
326 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
328 //__________________________________________________________________
329 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
331 /// Set sigma of charge spread for chamber id
334 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
335 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
337 //___________________________________________________________________
338 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
340 /// Set integration limits for charge spread
342 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
343 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
346 //__________________________________________________________________
347 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
349 /// Set maximum number for ADCcounts (saturation)
352 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
353 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
356 //__________________________________________________________________
357 void AliMUON::SetMaxStepGas(Float_t p1)
359 /// Set stepsize in gas
363 //__________________________________________________________________
364 void AliMUON::SetMaxStepAlu(Float_t p1)
366 /// Set step size in Alu
370 //__________________________________________________________________
371 void AliMUON::SetMaxDestepGas(Float_t p1)
373 /// Set maximum step size in Gas
377 //__________________________________________________________________
378 void AliMUON::SetMaxDestepAlu(Float_t p1)
380 /// Set maximum step size in Alu
385 //____________________________________________________________________
386 Float_t AliMUON::GetMaxStepGas() const
388 /// Return stepsize in gas
393 //____________________________________________________________________
394 Float_t AliMUON::GetMaxStepAlu() const
396 /// Return step size in Alu
401 //____________________________________________________________________
402 Float_t AliMUON::GetMaxDestepGas() const
404 /// Return maximum step size in Gas
406 return fMaxDestepGas;
409 //____________________________________________________________________
410 Float_t AliMUON::GetMaxDestepAlu() const
412 /// Return maximum step size in Gas
414 return fMaxDestepAlu;
417 //____________________________________________________________________
418 void AliMUON::SetAlign(Bool_t align)
420 /// Set option for alignement to geometry builder
422 fGeometryBuilder->SetAlign(align);
425 //____________________________________________________________________
426 void AliMUON::SetAlign(const TString& fileName, Bool_t align)
428 /// Set option for alignement to geometry builder
430 fGeometryBuilder->SetAlign(fileName, align);
433 //____________________________________________________________________
434 void AliMUON::SetResponseModel(Int_t id, const AliMUONResponse& response)
436 /// Set the response for chamber id
437 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
440 //____________________________________________________________________
441 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
445 AliMUONDigitizerV3* digitizer = new AliMUONDigitizerV3(manager, fDigitizerWithNoise);
446 AliMUONDigitizerV3::SetNSigmas(fDigitizerNSigmas);
447 digitizer->SetCalibrationData(fCalibrationData);
451 //_____________________________________________________________________
452 void AliMUON::SDigits2Digits()
454 /// Write TreeD here only
457 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
458 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
459 fLoader->TreeD()->Reset();
462 //_____________________________________________________________________
463 void AliMUON::Hits2SDigits()
465 /// Perform Hits2Digits using SDigitizerV2
467 AliMUONSDigitizerV2 sdigitizer;
468 sdigitizer.ExecuteTask();
471 //_____________________________________________________________________
472 void AliMUON::Digits2Raw()
474 /// Convert digits of the current event to raw data
476 AliRawDataHeaderSim header;
480 fRawWriter = new AliMUONRawWriter;
481 AliDebug(1,Form("Creating %s",fRawWriter->ClassName()));
482 if (fTriggerScalerEvent == kTRUE)
484 fRawWriter->SetScalersNumbers();
488 fLoader->LoadDigits("READ");
490 TTree* treeD = fLoader->TreeD();
494 AliError("Could not get TreeD");
498 AliMUONVTriggerStore* triggerStore = AliMUONVTriggerStore::Create(*treeD);
499 AliMUONVDigitStore* digitStore = AliMUONVDigitStore::Create(*treeD);
501 triggerStore->Connect(*treeD,kFALSE);
502 digitStore->Connect(*treeD,kFALSE);
506 fRawWriter->SetHeader(header);
507 if (!fRawWriter->Digits2Raw(digitStore,triggerStore))
509 AliError("pb writting raw data");
515 fLoader->UnloadDigits();
518 //_____________________________________________________________________
519 Bool_t AliMUON::Raw2SDigits(AliRawReader* rawReader)
521 /// Convert raw data to SDigit
523 if (!fLoader->TreeS()) fLoader->MakeSDigitsContainer();
525 TTree* treeS = fLoader->TreeS();
527 AliMUONVDigitStore* sDigitStore = AliMUONVDigitStore::Create(DigitStoreClassName());
528 AliMUONVTriggerStore* triggerStore = 0x0;
530 sDigitStore->Connect(*treeS);
532 if (!fDigitMaker) fDigitMaker = new AliMUONDigitMaker;
534 if (fConvertTrigger) {
535 triggerStore = new AliMUONTriggerStoreV1;
536 triggerStore->Connect(*treeS,true);
537 fDigitMaker->SetMakeTriggerDigits(true);
540 if (!fDigitCalibrator)
542 AliMUONRecoParam* recoParam = 0x0;
544 AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Calib/RecoParam");
548 // load recoParam according OCDB content (single or array)
549 if (!(recoParam = dynamic_cast<AliMUONRecoParam*>(entry->GetObject())))
551 TObjArray* recoParamArray = static_cast<TObjArray*>(entry->GetObject());
553 for(Int_t i = 0; i < recoParamArray->GetEntriesFast(); ++i)
555 recoParam = static_cast<AliMUONRecoParam*>(recoParamArray->UncheckedAt(i));
556 if (recoParam && recoParam->IsDefault()) break;
564 AliFatal("Cannot work without recoparams !");
567 TString calibMode = recoParam->GetCalibrationMode();
569 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,recoParam,calibMode.Data());
572 fDigitMaker->Raw2Digits(rawReader,sDigitStore,triggerStore);
574 fDigitCalibrator->Calibrate(*sDigitStore);
576 TIter next(sDigitStore->CreateIterator());
577 AliMUONDigit* sdigit;
579 // now tweak the digits to make them "as fresh as possible", i.e.
580 // reset their calibrated status, as they'll be calibrated again
582 while ( ( sdigit = static_cast<AliMUONDigit*>(next()) ) )
584 sdigit->Calibrated(kFALSE);
589 fLoader->WriteSDigits("OVERWRITE");
591 fLoader->UnloadSDigits();
600 //_______________________________________________________________________
601 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
603 /// Build standard getter (AliLoader type);
604 /// if detector wants to use castomized getter, it must overload this method
606 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
607 GetName(),topfoldername));
608 fLoader = new AliLoader(GetName(),topfoldername);
613 //________________________________________________________________________
615 AliMUON::ResetGeometryBuilder()
617 /// Only to be used by "experts" wanting to change the geometry builders
619 /// As the ctor of AliMUON now defines a default geometrybuilder, this
620 /// ResetGeometryBuilder() must be called prior to call the
621 /// AddGeometryBuilder()
623 delete fGeometryBuilder;
624 fGeometryBuilder = new AliMUONGeometryBuilder(this);
626 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
629 //____________________________________________________________________
630 Bool_t AliMUON::GetTriggerResponseV1() const
633 /// Returns fTriggerResponseV1
635 return fTriggerResponseV1;
639 //____________________________________________________________________
640 Int_t AliMUON::GetTriggerCoinc44() const
643 /// Returns fTriggerCoinc44
645 return fTriggerCoinc44;
649 //____________________________________________________________________
650 Bool_t AliMUON::GetTriggerEffCells() const
653 /// Returns fTriggerEffCells
655 return fTriggerEffCells;
659 //____________________________________________________________________
660 Int_t AliMUON::GetDigitizerWithNoise() const
663 /// Returns fDigitizerWithNoise
665 return fDigitizerWithNoise;