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>
48 //#include "AliHeader.h"
49 #include "AliLoader.h"
50 #include "AliRunDigitizer.h"
54 #include "AliMUONChamberTrigger.h"
55 #include "AliMUONConstants.h"
56 #include "AliMUONHit.h"
57 #include "AliMUONMerger.h"
58 #include "AliMUONPadHit.h"
59 #include "AliMUONRawCluster.h"
60 #include "AliMUONTransientDigit.h"
61 #include "AliMUONTriggerCircuit.h"
62 #include "AliMUONGeometryBuilder.h"
63 #include "AliMUONVGeometryBuilder.h"
64 #include "AliMUONDigitizerv2.h"
65 #include "AliMUONSDigitizerv1.h"
66 #include "AliMUONRawData.h"
69 // Defaults parameters for Z positions of chambers
70 // taken from values for "stations" in AliMUON::AliMUON
71 // const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
72 // and from array "dstation" in AliMUONv1::CreateGeometry
73 // Float_t dstation[5]={20., 20., 20, 20., 20.};
74 // for tracking chambers,
75 // according to (Z1 = zch - dstation) and (Z2 = zch + dstation)
76 // for the first and second chambers in the station, respectively,
77 // and from "DTPLANES" in AliMUONv1::CreateGeometry
78 // const Float_t DTPLANES = 15.;
79 // for trigger chambers,
80 // according to (Z1 = zch) and (Z2 = zch + DTPLANES)
81 // for the first and second chambers in the station, respectively
85 //__________________________________________________________________
106 // Default Constructor
111 //__________________________________________________________________
112 AliMUON::AliMUON(const char *name, const char *title)
113 : AliDetector(name,title),
114 fNCh(AliMUONConstants::NCh()),
115 fNTrackingCh(AliMUONConstants::NTrackingCh()),
126 fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200
127 fMaxDestepAlu(-1), // in the calculation of the tracking parameters
135 SetMarkerColor(kRed);//
137 // Creating List of Chambers
139 fChambers = new TObjArray(AliMUONConstants::NCh());
141 // Loop over stations
142 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
143 // Loop over 2 chambers in the station
144 for (Int_t stCH = 0; stCH < 2; stCH++) {
147 // Default Parameters for Muon Tracking Stations
149 if (ch < AliMUONConstants::NTrackingCh()) {
150 fChambers->AddAt(new AliMUONChamber(ch),ch);
152 fChambers->AddAt(new AliMUONChamberTrigger(ch),ch);
154 AliMUONChamber* chamber = (AliMUONChamber*) fChambers->At(ch);
155 //chamber->SetGid(0);
156 // Default values for Z of chambers
157 chamber->SetZ(AliMUONConstants::DefaultChamberZ(ch));
159 chamber->InitGeo(AliMUONConstants::DefaultChamberZ(ch));
160 // Set chamber inner and outer radius to default
161 chamber->SetRInner(AliMUONConstants::Dmin(st)/2);
162 chamber->SetROuter(AliMUONConstants::Dmax(st)/2);
164 } // Chamber stCH (0, 1) in
165 } // Station st (0...)
167 // cp new design of AliMUONTriggerDecision
168 fTriggerCircuits = new TObjArray(AliMUONConstants::NTriggerCircuit());
169 for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
170 fTriggerCircuits->AddAt(new AliMUONTriggerCircuit(),circ);
174 fGeometryBuilder = new AliMUONGeometryBuilder(this);
177 //____________________________________________________________________
178 AliMUON::AliMUON(const AliMUON& rMUON)
181 // Protected copy constructor
183 AliFatal("Not implemented.");
186 //____________________________________________________________________
190 AliDebug(1,"Calling AliMUON destructor");
192 if (fMerger) delete fMerger;
198 if (fTriggerCircuits){
199 fTriggerCircuits->Delete();
200 delete fTriggerCircuits;
203 delete fGeometryBuilder;
206 //________________________________________________________________________
207 AliMUON& AliMUON::operator = (const AliMUON& rhs)
209 // Protected assignement operator
211 if (this == &rhs) return *this;
213 AliFatal("Not implemented.");
218 //_____________________________________________________________________________
219 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
221 // Adds the geometry builder to the list
224 fGeometryBuilder->AddBuilder(geomBuilder);
227 //____________________________________________________________________
228 void AliMUON::BuildGeometry()
230 // Geometry for event display
232 for (Int_t i=0; i<7; i++) {
233 for (Int_t j=0; j<2; j++) {
235 this->Chamber(id-1).SegmentationModel(1)->Draw("eventdisplay");
240 //__________________________________________________________________
241 void AliMUON::SetTreeAddress()
243 GetMUONData()->SetLoader(fLoader);
244 // GetMUONData()->MakeBranch("D,S,RC");
245 // GetMUONData()->SetTreeAddress("H,D,S,RC");
246 GetMUONData()->SetTreeAddress("H");
247 if (fHits != GetMUONData()->Hits()) {
248 if ( gAlice->GetMCApp() )
249 if ( gAlice->GetMCApp()->GetHitLists() ) {
250 fHits = GetMUONData()->Hits();
251 gAlice->GetMCApp()->AddHitList(fHits); // For purifyKine, only necessary when Hit list is created in AliMUONData
254 fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector
257 //____________________________________________________________________
258 void AliMUON::SetPadSize(Int_t id, Int_t isec, Float_t p1, Float_t p2)
260 // Set the pad size for chamber id and cathode isec
262 ((AliMUONChamber*) fChambers->At(i)) ->SetPadSize(isec,p1,p2);
263 ((AliMUONChamber*) fChambers->At(i+1))->SetPadSize(isec,p1,p2);
266 //___________________________________________
267 void AliMUON::SetChambersZ(const Float_t *Z)
269 // Set Z values for all chambers (tracking and trigger)
270 // from the array pointed to by "Z"
271 for (Int_t ch = 0; ch < AliMUONConstants::NCh(); ch++)
272 ((AliMUONChamber*) fChambers->At(ch))->SetZ(Z[ch]);
275 //_________________________________________________________________
276 void AliMUON::SetChambersZToDefault()
278 // Set Z values for all chambers (tracking and trigger)
280 SetChambersZ(AliMUONConstants::DefaultChamberZ());
283 //_________________________________________________________________
284 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
286 // Set the inverse charge slope for chamber id
287 Int_t i=2*(id-1); //PH ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
288 //PH ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
289 ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
290 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
292 //__________________________________________________________________
293 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
295 // Set sigma of charge spread for chamber id
297 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
298 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
300 //___________________________________________________________________
301 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
303 // Set integration limits for charge spread
305 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
306 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
309 //__________________________________________________________________
310 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
312 // Set maximum number for ADCcounts (saturation)
314 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
315 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
318 //__________________________________________________________________
319 void AliMUON::SetMaxStepGas(Float_t p1)
321 // Set stepsize in gas
324 //__________________________________________________________________
325 void AliMUON::SetMaxStepAlu(Float_t p1)
327 // Set step size in Alu
330 //__________________________________________________________________
331 void AliMUON::SetMaxDestepGas(Float_t p1)
333 // Set maximum step size in Gas
336 //__________________________________________________________________
337 void AliMUON::SetMaxDestepAlu(Float_t p1)
339 // Set maximum step size in Alu
343 //___________________________________________________________________
344 void AliMUON::SetAcceptance(Bool_t acc, Float_t angmin, Float_t angmax)
346 // Set acceptance cuts
348 fAccMin=angmin*TMath::Pi()/180;
349 fAccMax=angmax*TMath::Pi()/180;
352 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
353 // Loop over 2 chambers in the station
354 for (Int_t stCH = 0; stCH < 2; stCH++) {
356 // Set chamber inner and outer radius according to acceptance cuts
357 Chamber(ch).SetRInner(TMath::Abs(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMin)));
358 Chamber(ch).SetROuter(TMath::Abs(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMax)));
364 //____________________________________________________________________
365 Float_t AliMUON::GetMaxStepGas() const
367 // Return stepsize in gas
372 //____________________________________________________________________
373 Float_t AliMUON::GetMaxStepAlu() const
375 // Return step size in Alu
380 //____________________________________________________________________
381 Float_t AliMUON::GetMaxDestepGas() const
383 // Return maximum step size in Gas
385 return fMaxDestepGas;
388 //____________________________________________________________________
389 Float_t AliMUON::GetMaxDestepAlu() const
391 // Return maximum step size in Gas
393 return fMaxDestepAlu;
396 //____________________________________________________________________
397 void AliMUON::SetAlign(Bool_t align)
399 // Sets option for alignement to geometry builder
401 fGeometryBuilder->SetAlign(align);
404 //____________________________________________________________________
405 void AliMUON::SetSegmentationModel(Int_t id, Int_t isec, AliSegmentation *segmentation)
407 // Set the segmentation for chamber id cathode isec
408 ((AliMUONChamber*) fChambers->At(id))->SetSegmentationModel(isec, segmentation);
411 //____________________________________________________________________
412 void AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
414 // Set the response for chamber id
415 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
417 //____________________________________________________________________
418 void AliMUON::SetNsec(Int_t id, Int_t nsec)
420 // Set number of segmented cathods for chamber id
421 ((AliMUONChamber*) fChambers->At(id))->SetNsec(nsec);
423 //____________________________________________________________________
424 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
426 return new AliMUONDigitizerv2(manager);
428 //_____________________________________________________________________
429 void AliMUON::SDigits2Digits()
435 AliDebug(1,"Create default AliMUONMerger ");
436 AliDebug(1," no merging, just digitization of 1 event will be done");
437 fMerger = new AliMUONMerger();
442 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
443 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
444 fLoader->TreeD()->Reset();
447 //_____________________________________________________________________
448 void AliMUON::Hits2SDigits()
450 // Adaption of AliMUONSDigitizerv1 to be excuted by the AliSimulation framework
451 AliRunLoader* runLoader = fLoader->GetRunLoader();
452 AliRunDigitizer * manager = new AliRunDigitizer(1,1);
453 manager->SetInputStream(0,runLoader->GetFileName(),AliConfig::GetDefaultEventFolderName());
454 AliMUONDigitizer * dMUON = new AliMUONSDigitizerv1(manager);
455 fLoader->LoadHits("READ");
456 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
457 runLoader->GetEvent(iEvent);
460 fLoader->UnloadHits();
462 //_____________________________________________________________________
463 void AliMUON::Digits2Raw()
465 // convert digits of the current event to raw data
466 AliMUONRawData* rawData;
468 rawData = new AliMUONRawData(fLoader);
469 if (!rawData->WriteRawData()) AliInfo("pb writting raw data");
473 //_______________________________________________________________________
474 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
476 //builds standard getter (AliLoader type)
477 //if detector wants to use castomized getter, it must overload this method
480 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
481 GetName(),topfoldername));
482 fLoader = new AliLoader(GetName(),topfoldername);
483 fMUONData = new AliMUONData(fLoader,GetName(),GetName());
484 fMUONData->SetSplitLevel(fSplitLevel);
487 //_______________________________________________________________________
488 AliMUONPadHit* AliMUON::FirstPad(AliMUONHit* hit, TClonesArray *clusters)
491 // Initialise the pad iterator
492 // Return the address of the first padhit for hit
493 TClonesArray *theClusters = clusters;
494 Int_t nclust = theClusters->GetEntriesFast();
495 if (nclust && hit->PHlast() > 0) {
496 fMaxIterPad=hit->PHlast();
497 fCurIterPad=hit->PHfirst();
498 return (AliMUONPadHit*) clusters->UncheckedAt(fCurIterPad-1);
503 //_______________________________________________________________________
504 AliMUONPadHit* AliMUON::NextPad(TClonesArray *clusters)
507 // Get next pad (in iterator)
510 if (fCurIterPad <= fMaxIterPad) {
511 return (AliMUONPadHit*) clusters->UncheckedAt(fCurIterPad-1);
516 //_______________________________________________________________________
518 AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
521 // Return rawcluster (icluster) for chamber ichamber and cathode icathod
523 TClonesArray *muonRawCluster = GetMUONData()->RawClusters(ichamber);
525 TTree *treeR = fLoader->TreeR();
526 Int_t nent=(Int_t)treeR->GetEntries();
527 treeR->GetEvent(nent-2+icathod-1);
528 //treeR->GetEvent(icathod);
529 //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
531 AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
532 //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
536 //________________________________________________________________________
537 void AliMUON::SetMerger(AliMUONMerger* merger)
539 // Set pointer to merger
542 //________________________________________________________________________
543 AliMUONMerger* AliMUON::Merger()
545 // Return pointer to merger
548 /* PH Commented out waiting for correct implementation
549 //________________________________________________________________________
550 void AliMUON::RemapTrackHitIDs(Int_t* map)
552 // Remaps the track numbers in the hits arrays, so that they correspond
553 // to the entry indices in the Kine tree.
554 // The correspondance is not direct. To get the real index into the Kine tree
555 // compute the particle index as follows:
557 // num_primaries = AliStack::GetNprimary();
558 // num_tracks = AliStack::GetNtracks();
559 // track = AliMUONHit::Track()
561 // if (track < num_primaries)
562 // particleindex = track + num_tracks - num_primaries;
564 // particleindex = track - num_primaries;
566 // Remap the track numbers based on the specified map.
567 AliMUONData* data = GetMUONData();
568 TClonesArray* hits = data->Hits();
569 for (Int_t i = 0; i < hits->GetEntriesFast(); i++)
571 AliMUONHit* hit = static_cast<AliMUONHit*>( hits->At(i) );
572 hit->SetTrack( map[hit->Track()] );