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 "AliMUONVTriggerStore.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),
111 fDigitStoreConcreteClassName(),
112 fCalibrationData(0x0),
113 fDigitCalibrator(0x0)
115 /// Default Constructor
117 AliDebug(1,Form("default (empty) ctor this=%p",this));
121 //__________________________________________________________________
122 AliMUON::AliMUON(const char *name, const char* title)
123 : AliDetector(name, title),
124 fNCh(AliMUONConstants::NCh()),
125 fNTrackingCh(AliMUONConstants::NTrackingCh()),
134 fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200
135 fMaxDestepAlu(-1), // in the calculation of the tracking parameters
139 fTriggerScalerEvent(kFALSE),
140 fTriggerResponseV1(kFALSE),
143 fDigitizerWithNoise(1),
144 fDigitizerNSigmas(4.0),
145 fIsTailEffect(kTRUE),
147 fDigitMaker(new AliMUONDigitMaker),
149 fDigitStoreConcreteClassName("AliMUONDigitStoreV2S"),
151 fDigitCalibrator(0x0)
153 /// Standard constructor
155 AliDebug(1,Form("ctor this=%p",this));
158 //PH SetMarkerColor(kRed);//
161 fGeometryBuilder = new AliMUONGeometryBuilder(this);
163 // Common geometry definitions
165 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
167 // By default, add also all the needed geometry builders.
168 // If you want to change this from outside, please use ResetGeometryBuilder
169 // method, followed by AddGeometryBuilder ones.
171 AddGeometryBuilder(new AliMUONSt1GeometryBuilderV2(this));
172 AddGeometryBuilder(new AliMUONSt2GeometryBuilderV2(this));
173 AddGeometryBuilder(new AliMUONSlatGeometryBuilder(this));
174 AddGeometryBuilder(new AliMUONTriggerGeometryBuilder(this));
177 // Creating List of Chambers
179 fChambers = new TObjArray(AliMUONConstants::NCh());
180 fChambers->SetOwner(kTRUE);
182 // Loop over stations
183 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
184 // Loop over 2 chambers in the station
185 for (Int_t stCH = 0; stCH < 2; stCH++) {
188 // Default Parameters for Muon Tracking Stations
190 if (ch < AliMUONConstants::NTrackingCh()) {
191 fChambers->AddAt(new AliMUONChamber(ch),ch);
193 fChambers->AddAt(new AliMUONChamberTrigger(ch, GetGeometryTransformer()),ch);
195 } // Chamber stCH (0, 1) in
196 } // Station st (0...)
198 Int_t runnumber = AliCDBManager::Instance()->GetRun();
200 fCalibrationData = new AliMUONCalibrationData(runnumber);
203 //____________________________________________________________________
208 AliDebug(1,Form("dtor this=%p",this));
210 delete fGeometryBuilder;
214 delete fCalibrationData;
215 delete fDigitCalibrator;
218 //_____________________________________________________________________________
219 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
221 /// Add the geometry builder to the list
223 fGeometryBuilder->AddBuilder(geomBuilder);
226 //____________________________________________________________________
227 const AliMUONGeometry* AliMUON::GetGeometry() const
229 /// Return geometry parametrisation
231 if ( !fGeometryBuilder) {
232 AliWarningStream() << "GeometryBuilder not defined." << std::endl;
236 return fGeometryBuilder->GetGeometry();
239 //____________________________________________________________________
240 const AliMUONGeometryTransformer* AliMUON::GetGeometryTransformer() const
242 /// Return geometry parametrisation
244 const AliMUONGeometry* kGeometry = GetGeometry();
246 if ( !kGeometry) return 0;
248 return kGeometry->GetTransformer();
251 //__________________________________________________________________
253 AliMUON::MakeBranch(Option_t* opt)
255 /// Create branche(s) to hold MUON hits
259 if ( sopt != "H" ) return;
263 fHitStore = new AliMUONHitStoreV1;
264 if ( gAlice->GetMCApp() )
266 if ( gAlice->GetMCApp()->GetHitLists() )
268 // AliStack::PurifyKine needs to be able to loop on our hits
269 // to remap the track numbers.
270 gAlice->GetMCApp()->AddHitList(fHitStore->Collection());
275 TTree* treeH = fLoader->TreeH();
279 AliFatal("No TreeH");
282 fHitStore->Connect(*treeH);
285 //__________________________________________________________________
287 AliMUON::SetTreeAddress()
289 /// Set Hits tree address
291 // if ( gAlice->GetMCApp() && fHitStore )
293 // TList* l = gAlice->GetMCApp()->GetHitLists();
296 // TObject* o = l->First();
297 // if (o!=fHitStore->HitCollection())
299 // AliError(Form("Something is strange hitcollection=%x",fHitStore->HitCollection()));
306 //_________________________________________________________________
313 if (fHitStore) fHitStore->Clear();
316 //_________________________________________________________________
317 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
319 /// Set the inverse charge slope for chamber id
321 Int_t i=2*(id-1); //PH ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
322 //PH ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
323 ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
324 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
326 //__________________________________________________________________
327 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
329 /// Set sigma of charge spread for chamber id
332 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
333 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
335 //___________________________________________________________________
336 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
338 /// Set integration limits for charge spread
340 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
341 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
344 //__________________________________________________________________
345 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
347 /// Set maximum number for ADCcounts (saturation)
350 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
351 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
354 //__________________________________________________________________
355 void AliMUON::SetMaxStepGas(Float_t p1)
357 /// Set stepsize in gas
361 //__________________________________________________________________
362 void AliMUON::SetMaxStepAlu(Float_t p1)
364 /// Set step size in Alu
368 //__________________________________________________________________
369 void AliMUON::SetMaxDestepGas(Float_t p1)
371 /// Set maximum step size in Gas
375 //__________________________________________________________________
376 void AliMUON::SetMaxDestepAlu(Float_t p1)
378 /// Set maximum step size in Alu
383 //____________________________________________________________________
384 Float_t AliMUON::GetMaxStepGas() const
386 /// Return stepsize in gas
391 //____________________________________________________________________
392 Float_t AliMUON::GetMaxStepAlu() const
394 /// Return step size in Alu
399 //____________________________________________________________________
400 Float_t AliMUON::GetMaxDestepGas() const
402 /// Return maximum step size in Gas
404 return fMaxDestepGas;
407 //____________________________________________________________________
408 Float_t AliMUON::GetMaxDestepAlu() const
410 /// Return maximum step size in Gas
412 return fMaxDestepAlu;
415 //____________________________________________________________________
416 void AliMUON::SetAlign(Bool_t align)
418 /// Set option for alignement to geometry builder
420 fGeometryBuilder->SetAlign(align);
423 //____________________________________________________________________
424 void AliMUON::SetAlign(const TString& fileName, Bool_t align)
426 /// Set option for alignement to geometry builder
428 fGeometryBuilder->SetAlign(fileName, align);
431 //____________________________________________________________________
432 void AliMUON::SetResponseModel(Int_t id, const AliMUONResponse& response)
434 /// Set the response for chamber id
435 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
438 //____________________________________________________________________
439 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
443 AliMUONDigitizerV3* digitizer = new AliMUONDigitizerV3(manager, fDigitizerWithNoise);
444 AliMUONDigitizerV3::SetNSigmas(fDigitizerNSigmas);
445 digitizer->SetCalibrationData(fCalibrationData);
449 //_____________________________________________________________________
450 void AliMUON::SDigits2Digits()
452 /// Write TreeD here only
455 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
456 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
457 fLoader->TreeD()->Reset();
460 //_____________________________________________________________________
461 void AliMUON::Hits2SDigits()
463 /// Perform Hits2Digits using SDigitizerV2
465 AliMUONSDigitizerV2 sdigitizer;
466 sdigitizer.ExecuteTask();
469 //_____________________________________________________________________
470 void AliMUON::Digits2Raw()
472 /// Convert digits of the current event to raw data
474 AliRawDataHeaderSim header;
478 fRawWriter = new AliMUONRawWriter;
479 AliDebug(1,Form("Creating %s",fRawWriter->ClassName()));
480 if (fTriggerScalerEvent == kTRUE)
482 fRawWriter->SetScalersNumbers();
486 fLoader->LoadDigits("READ");
488 TTree* treeD = fLoader->TreeD();
492 AliError("Could not get TreeD");
496 AliMUONVTriggerStore* triggerStore = AliMUONVTriggerStore::Create(*treeD);
497 AliMUONVDigitStore* digitStore = AliMUONVDigitStore::Create(*treeD);
499 triggerStore->Connect(*treeD,kFALSE);
500 digitStore->Connect(*treeD,kFALSE);
504 fRawWriter->SetHeader(header);
505 if (!fRawWriter->Digits2Raw(digitStore,triggerStore))
507 AliError("pb writting raw data");
513 fLoader->UnloadDigits();
516 //_____________________________________________________________________
517 Bool_t AliMUON::Raw2SDigits(AliRawReader* rawReader)
519 /// Convert raw data to SDigit
521 if (!fLoader->TreeS()) fLoader->MakeSDigitsContainer();
523 TTree* treeS = fLoader->TreeS();
525 AliMUONVDigitStore* sDigitStore = AliMUONVDigitStore::Create(DigitStoreClassName());
527 sDigitStore->Connect(*treeS);
529 if (!fDigitMaker) fDigitMaker = new AliMUONDigitMaker;
531 if (!fDigitCalibrator)
533 AliMUONRecoParam* recoParam = 0x0;
535 AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Calib/RecoParam");
539 // load recoParam according OCDB content (single or array)
540 if (!(recoParam = dynamic_cast<AliMUONRecoParam*>(entry->GetObject())))
542 TObjArray* recoParamArray = static_cast<TObjArray*>(entry->GetObject());
544 for(Int_t i = 0; i < recoParamArray->GetEntriesFast(); ++i)
546 recoParam = static_cast<AliMUONRecoParam*>(recoParamArray->UncheckedAt(i));
547 if (recoParam && recoParam->IsDefault()) break;
555 AliFatal("Cannot work without recoparams !");
558 TString calibMode = recoParam->GetCalibrationMode();
560 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,recoParam,calibMode.Data());
563 fDigitMaker->Raw2Digits(rawReader,sDigitStore,0x0);
565 fDigitCalibrator->Calibrate(*sDigitStore);
567 TIter next(sDigitStore->CreateIterator());
568 AliMUONDigit* sdigit;
570 // now tweak the digits to make them "as fresh as possible", i.e.
571 // reset their calibrated status, as they'll be calibrated again
573 while ( ( sdigit = static_cast<AliMUONDigit*>(next()) ) )
575 sdigit->Calibrated(kFALSE);
580 fLoader->WriteSDigits("OVERWRITE");
582 fLoader->UnloadSDigits();
589 //_______________________________________________________________________
590 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
592 /// Build standard getter (AliLoader type);
593 /// if detector wants to use castomized getter, it must overload this method
595 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
596 GetName(),topfoldername));
597 fLoader = new AliLoader(GetName(),topfoldername);
602 //________________________________________________________________________
604 AliMUON::ResetGeometryBuilder()
606 /// Only to be used by "experts" wanting to change the geometry builders
608 /// As the ctor of AliMUON now defines a default geometrybuilder, this
609 /// ResetGeometryBuilder() must be called prior to call the
610 /// AddGeometryBuilder()
612 delete fGeometryBuilder;
613 fGeometryBuilder = new AliMUONGeometryBuilder(this);
615 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
618 //____________________________________________________________________
619 Bool_t AliMUON::GetTriggerResponseV1() const
622 /// Returns fTriggerResponseV1
624 return fTriggerResponseV1;
628 //____________________________________________________________________
629 Int_t AliMUON::GetTriggerCoinc44() const
632 /// Returns fTriggerCoinc44
634 return fTriggerCoinc44;
638 //____________________________________________________________________
639 Bool_t AliMUON::GetTriggerEffCells() const
642 /// Returns fTriggerEffCells
644 return fTriggerEffCells;
648 //____________________________________________________________________
649 Int_t AliMUON::GetDigitizerWithNoise() const
652 /// Returns fDigitizerWithNoise
654 return fDigitizerWithNoise;