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 **************************************************************************/
19 ///////////////////////////////////////////////
20 // Manager and hits classes for set:MUON //
21 ////////////////////////////////////////////////
23 #include "Riostream.h"
28 #include <TDirectory.h>
30 #include <TGeometry.h>
34 #include <TObjArray.h>
36 #include <TObjectTable.h>
38 #include <TParticle.h>
41 #include <TRotMatrix.h>
46 #include <TVirtualMC.h>
49 #include "AliHeader.h"
50 #include "AliHitMap.h"
51 #include "AliLoader.h"
52 #include "AliRunDigitizer.h"
55 #include "AliMUONLoader.h"
57 #include "AliMUONChamberTrigger.h"
58 #include "AliMUONConstants.h"
59 #include "AliMUONDigit.h"
60 #include "AliMUONHit.h"
61 #include "AliMUONHitMapA1.h"
62 #include "AliMUONMerger.h"
63 #include "AliMUONPadHit.h"
64 #include "AliMUONRawCluster.h"
65 #include "AliMUONTransientDigit.h"
66 #include "AliMUONTriggerCircuit.h"
67 #include "AliMUONVGeometryBuilder.h"
68 #include "AliMUONDigitizerv2.h"
69 #include "AliMUONSDigitizerv1.h"
72 // Defaults parameters for Z positions of chambers
73 // taken from values for "stations" in AliMUON::AliMUON
74 // const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
75 // and from array "dstation" in AliMUONv1::CreateGeometry
76 // Float_t dstation[5]={20., 20., 20, 20., 20.};
77 // for tracking chambers,
78 // according to (Z1 = zch - dstation) and (Z2 = zch + dstation)
79 // for the first and second chambers in the station, respectively,
80 // and from "DTPLANES" in AliMUONv1::CreateGeometry
81 // const Float_t DTPLANES = 15.;
82 // for trigger chambers,
83 // according to (Z1 = zch) and (Z2 = zch + DTPLANES)
84 // for the first and second chambers in the station, respectively
88 //__________________________________________________________________
109 // Default Constructor
114 //__________________________________________________________________
115 AliMUON::AliMUON(const char *name, const char *title)
116 : AliDetector(name,title),
117 fNCh(AliMUONConstants::NCh()),
118 fNTrackingCh(AliMUONConstants::NTrackingCh()),
122 fGeometryBuilders(0),
129 fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200
130 fMaxDestepAlu(-1), // in the calculation of the tracking parameters
137 <img src="gif/alimuon.gif">
143 SetMarkerColor(kRed);//
145 // Creating List of Chambers
147 fChambers = new TObjArray(AliMUONConstants::NCh());
148 fGeometryBuilders = new TObjArray(AliMUONConstants::NCh());
150 // Loop over stations
151 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
152 // Loop over 2 chambers in the station
153 for (Int_t stCH = 0; stCH < 2; stCH++) {
156 // Default Parameters for Muon Tracking Stations
158 if (ch < AliMUONConstants::NTrackingCh()) {
159 fChambers->AddAt(new AliMUONChamber(ch),ch);
161 fChambers->AddAt(new AliMUONChamberTrigger(ch),ch);
163 AliMUONChamber* chamber = (AliMUONChamber*) fChambers->At(ch);
164 //chamber->SetGid(0);
165 // Default values for Z of chambers
166 chamber->SetZ(AliMUONConstants::DefaultChamberZ(ch));
168 chamber->InitGeo(AliMUONConstants::DefaultChamberZ(ch));
169 // Set chamber inner and outer radius to default
170 chamber->SetRInner(AliMUONConstants::Dmin(st)/2);
171 chamber->SetROuter(AliMUONConstants::Dmax(st)/2);
173 } // Chamber stCH (0, 1) in
174 } // Station st (0...)
176 // cp new design of AliMUONTriggerDecision
177 fTriggerCircuits = new TObjArray(AliMUONConstants::NTriggerCircuit());
178 for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
179 fTriggerCircuits->AddAt(new AliMUONTriggerCircuit(),circ);
183 //____________________________________________________________________
184 AliMUON::AliMUON(const AliMUON& rMUON)
187 // Protected copy constructor
189 Fatal("AliMUONMergerModule", "Not implemented.");
192 //____________________________________________________________________
196 if(fDebug) printf("%s: Calling AliMUON destructor !!!\n",ClassName());
198 if (fMerger) delete fMerger;
200 if (fGeometryBuilders){
201 fGeometryBuilders->Delete();
202 delete fGeometryBuilders;
208 if (fTriggerCircuits){
209 fTriggerCircuits->Delete();
210 delete fTriggerCircuits;
215 //________________________________________________________________________
216 AliMUON& AliMUON::operator = (const AliMUON& rhs)
218 // Protected assignement operator
220 if (this == &rhs) return *this;
222 Fatal("operator=", "Not implemented.");
227 //_____________________________________________________________________________
228 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
230 // Adds the geometry builder to the list
233 fGeometryBuilders->Add(geomBuilder);
235 //____________________________________________________________________
236 void AliMUON::BuildGeometry()
238 // Geometry for event display
239 for (Int_t i=0; i<7; i++) {
240 for (Int_t j=0; j<2; j++) {
242 this->Chamber(id-1).SegmentationModel(1)->Draw("eventdisplay");
246 //__________________________________________________________________
247 void AliMUON::SetTreeAddress()
249 GetMUONData()->SetLoader(fLoader);
250 // GetMUONData()->MakeBranch("D,S,RC");
251 // GetMUONData()->SetTreeAddress("H,D,S,RC");
252 GetMUONData()->SetTreeAddress("H");
253 if (fHits != GetMUONData()->Hits()) {
254 if ( gAlice->GetMCApp() )
255 if ( gAlice->GetMCApp()->GetHitLists() ) {
256 fHits = GetMUONData()->Hits();
257 gAlice->GetMCApp()->AddHitList(fHits); // For purifyKine, only necessary when Hit list is created in AliMUONData
260 fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector
263 //____________________________________________________________________
264 void AliMUON::SetPadSize(Int_t id, Int_t isec, Float_t p1, Float_t p2)
266 // Set the pad size for chamber id and cathode isec
268 ((AliMUONChamber*) fChambers->At(i)) ->SetPadSize(isec,p1,p2);
269 ((AliMUONChamber*) fChambers->At(i+1))->SetPadSize(isec,p1,p2);
272 //___________________________________________
273 void AliMUON::SetChambersZ(const Float_t *Z)
275 // Set Z values for all chambers (tracking and trigger)
276 // from the array pointed to by "Z"
277 for (Int_t ch = 0; ch < AliMUONConstants::NCh(); ch++)
278 ((AliMUONChamber*) fChambers->At(ch))->SetZ(Z[ch]);
281 //_________________________________________________________________
282 void AliMUON::SetChambersZToDefault()
284 // Set Z values for all chambers (tracking and trigger)
286 SetChambersZ(AliMUONConstants::DefaultChamberZ());
289 //_________________________________________________________________
290 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
292 // Set the inverse charge slope for chamber id
293 Int_t i=2*(id-1); //PH ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
294 //PH ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
295 ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
296 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
298 //__________________________________________________________________
299 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
301 // Set sigma of charge spread for chamber id
303 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
304 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
306 //___________________________________________________________________
307 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
309 // Set integration limits for charge spread
311 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
312 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
315 //__________________________________________________________________
316 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
318 // Set maximum number for ADCcounts (saturation)
320 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
321 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
323 //__________________________________________________________________
324 void AliMUON::SetMaxStepGas(Float_t p1)
326 // Set stepsize in gas
329 //__________________________________________________________________
330 void AliMUON::SetMaxStepAlu(Float_t p1)
332 // Set step size in Alu
335 //__________________________________________________________________
336 void AliMUON::SetMaxDestepGas(Float_t p1)
338 // Set maximum step size in Gas
341 //__________________________________________________________________
342 void AliMUON::SetMaxDestepAlu(Float_t p1)
344 // Set maximum step size in Alu
347 //___________________________________________________________________
348 void AliMUON::SetAcceptance(Bool_t acc, Float_t angmin, Float_t angmax)
350 // Set acceptance cuts
352 fAccMin=angmin*TMath::Pi()/180;
353 fAccMax=angmax*TMath::Pi()/180;
356 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
357 // Loop over 2 chambers in the station
358 for (Int_t stCH = 0; stCH < 2; stCH++) {
360 // Set chamber inner and outer radius according to acceptance cuts
361 Chamber(ch).SetRInner(TMath::Abs(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMin)));
362 Chamber(ch).SetROuter(TMath::Abs(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMax)));
368 //____________________________________________________________________
369 Float_t AliMUON::GetMaxStepGas() const
371 // Return stepsize in gas
376 //____________________________________________________________________
377 Float_t AliMUON::GetMaxStepAlu() const
379 // Return step size in Alu
384 //____________________________________________________________________
385 Float_t AliMUON::GetMaxDestepGas() const
387 // Return maximum step size in Gas
389 return fMaxDestepGas;
392 //____________________________________________________________________
393 Float_t AliMUON::GetMaxDestepAlu() const
395 // Return maximum step size in Gas
397 return fMaxDestepAlu;
399 //____________________________________________________________________
400 void AliMUON::SetSegmentationModel(Int_t id, Int_t isec, AliSegmentation *segmentation)
402 // Set the segmentation for chamber id cathode isec
403 ((AliMUONChamber*) fChambers->At(id))->SetSegmentationModel(isec, segmentation);
406 //____________________________________________________________________
407 void AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
409 // Set the response for chamber id
410 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
412 //____________________________________________________________________
413 void AliMUON::SetNsec(Int_t id, Int_t nsec)
415 // Set number of segmented cathods for chamber id
416 ((AliMUONChamber*) fChambers->At(id))->SetNsec(nsec);
418 //____________________________________________________________________
419 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
421 return new AliMUONDigitizerv2(manager);
423 //_____________________________________________________________________
424 void AliMUON::SDigits2Digits()
430 if (gAlice->GetDebug()>0) {
431 cerr<<"AliMUON::SDigits2Digits: create default AliMUONMerger "<<endl;
432 cerr<<" no merging, just digitization of 1 event will be done"<<endl;
434 fMerger = new AliMUONMerger();
439 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
440 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
441 fLoader->TreeD()->Reset();
444 //_____________________________________________________________________
445 void AliMUON::Hits2SDigits()
447 // Adaption of AliMUONSDigitizerv1 to be excuted by the AliSimulation framework
448 AliRunLoader* runLoader = fLoader->GetRunLoader();
449 AliRunDigitizer * manager = new AliRunDigitizer(1,1);
450 manager->SetInputStream(0,runLoader->GetFileName(),AliConfig::GetDefaultEventFolderName());
451 AliMUONDigitizer * dMUON = new AliMUONSDigitizerv1(manager);
452 fLoader->LoadHits("READ");
453 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
454 runLoader->GetEvent(iEvent);
457 fLoader->UnloadHits();
459 //_______________________________________________________________________
460 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
462 //builds standard getter (AliLoader type)
463 //if detector wants to use castomized getter, it must overload this method
467 "Creating standard getter for detector %s. Top folder is %s.",
468 GetName(),topfoldername);
469 fLoader = new AliLoader(GetName(),topfoldername);
470 fMUONData = new AliMUONData(fLoader,GetName(),GetName());
471 fMUONData->SetSplitLevel(fSplitLevel);
474 //_______________________________________________________________________
475 AliMUONPadHit* AliMUON::FirstPad(AliMUONHit* hit, TClonesArray *clusters)
478 // Initialise the pad iterator
479 // Return the address of the first padhit for hit
480 TClonesArray *theClusters = clusters;
481 Int_t nclust = theClusters->GetEntriesFast();
482 if (nclust && hit->PHlast() > 0) {
483 fMaxIterPad=hit->PHlast();
484 fCurIterPad=hit->PHfirst();
485 return (AliMUONPadHit*) clusters->UncheckedAt(fCurIterPad-1);
490 //_______________________________________________________________________
491 AliMUONPadHit* AliMUON::NextPad(TClonesArray *clusters)
494 // Get next pad (in iterator)
497 if (fCurIterPad <= fMaxIterPad) {
498 return (AliMUONPadHit*) clusters->UncheckedAt(fCurIterPad-1);
503 //_______________________________________________________________________
505 AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
508 // Return rawcluster (icluster) for chamber ichamber and cathode icathod
510 TClonesArray *muonRawCluster = GetMUONData()->RawClusters(ichamber);
512 TTree *treeR = fLoader->TreeR();
513 Int_t nent=(Int_t)treeR->GetEntries();
514 treeR->GetEvent(nent-2+icathod-1);
515 //treeR->GetEvent(icathod);
516 //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
518 AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
519 //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
523 //________________________________________________________________________
524 void AliMUON::SetMerger(AliMUONMerger* merger)
526 // Set pointer to merger
529 //________________________________________________________________________
530 AliMUONMerger* AliMUON::Merger()
532 // Return pointer to merger
535 //________________________________________________________________________
536 void AliMUON::RemapTrackHitIDs(Int_t* map)
538 // Remaps the track numbers in the hits arrays, so that they correspond
539 // to the entry indices in the Kine tree.
540 // The correspondance is not direct. To get the real index into the Kine tree
541 // compute the particle index as follows:
543 // num_primaries = AliStack::GetNprimary();
544 // num_tracks = AliStack::GetNtracks();
545 // track = AliMUONHit::Track()
547 // if (track < num_primaries)
548 // particleindex = track + num_tracks - num_primaries;
550 // particleindex = track - num_primaries;
552 // Remap the track numbers based on the specified map.
553 AliMUONData* data = GetMUONData();
554 TClonesArray* hits = data->Hits();
555 for (Int_t i = 0; i < hits->GetEntriesFast(); i++)
557 AliMUONHit* hit = static_cast<AliMUONHit*>( hits->At(i) );
558 hit->SetTrack( map[hit->Track()] );