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"
68 // Defaults parameters for Z positions of chambers
69 // taken from values for "stations" in AliMUON::AliMUON
70 // const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
71 // and from array "dstation" in AliMUONv1::CreateGeometry
72 // Float_t dstation[5]={20., 20., 20, 20., 20.};
73 // for tracking chambers,
74 // according to (Z1 = zch - dstation) and (Z2 = zch + dstation)
75 // for the first and second chambers in the station, respectively,
76 // and from "DTPLANES" in AliMUONv1::CreateGeometry
77 // const Float_t DTPLANES = 15.;
78 // for trigger chambers,
79 // according to (Z1 = zch) and (Z2 = zch + DTPLANES)
80 // for the first and second chambers in the station, respectively
84 //__________________________________________________________________
105 // Default Constructor
110 //__________________________________________________________________
111 AliMUON::AliMUON(const char *name, const char *title)
112 : AliDetector(name,title),
113 fNCh(AliMUONConstants::NCh()),
114 fNTrackingCh(AliMUONConstants::NTrackingCh()),
125 fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200
126 fMaxDestepAlu(-1), // in the calculation of the tracking parameters
134 SetMarkerColor(kRed);//
136 // Creating List of Chambers
138 fChambers = new TObjArray(AliMUONConstants::NCh());
140 // Loop over stations
141 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
142 // Loop over 2 chambers in the station
143 for (Int_t stCH = 0; stCH < 2; stCH++) {
146 // Default Parameters for Muon Tracking Stations
148 if (ch < AliMUONConstants::NTrackingCh()) {
149 fChambers->AddAt(new AliMUONChamber(ch),ch);
151 fChambers->AddAt(new AliMUONChamberTrigger(ch),ch);
153 AliMUONChamber* chamber = (AliMUONChamber*) fChambers->At(ch);
154 //chamber->SetGid(0);
155 // Default values for Z of chambers
156 chamber->SetZ(AliMUONConstants::DefaultChamberZ(ch));
158 chamber->InitGeo(AliMUONConstants::DefaultChamberZ(ch));
159 // Set chamber inner and outer radius to default
160 chamber->SetRInner(AliMUONConstants::Dmin(st)/2);
161 chamber->SetROuter(AliMUONConstants::Dmax(st)/2);
163 } // Chamber stCH (0, 1) in
164 } // Station st (0...)
166 // cp new design of AliMUONTriggerDecision
167 fTriggerCircuits = new TObjArray(AliMUONConstants::NTriggerCircuit());
168 for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
169 fTriggerCircuits->AddAt(new AliMUONTriggerCircuit(),circ);
173 fGeometryBuilder = new AliMUONGeometryBuilder(this);
176 //____________________________________________________________________
177 AliMUON::AliMUON(const AliMUON& rMUON)
180 // Protected copy constructor
182 Fatal("AliMUONMergerModule", "Not implemented.");
185 //____________________________________________________________________
189 if(fDebug) printf("%s: Calling AliMUON destructor !!!\n",ClassName());
191 if (fMerger) delete fMerger;
197 if (fTriggerCircuits){
198 fTriggerCircuits->Delete();
199 delete fTriggerCircuits;
202 delete fGeometryBuilder;
205 //________________________________________________________________________
206 AliMUON& AliMUON::operator = (const AliMUON& rhs)
208 // Protected assignement operator
210 if (this == &rhs) return *this;
212 Fatal("operator=", "Not implemented.");
217 //_____________________________________________________________________________
218 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
220 // Adds the geometry builder to the list
223 fGeometryBuilder->AddBuilder(geomBuilder);
226 //____________________________________________________________________
227 void AliMUON::BuildGeometry()
229 // Geometry for event display
231 for (Int_t i=0; i<7; i++) {
232 for (Int_t j=0; j<2; j++) {
234 this->Chamber(id-1).SegmentationModel(1)->Draw("eventdisplay");
239 //__________________________________________________________________
240 void AliMUON::SetTreeAddress()
242 GetMUONData()->SetLoader(fLoader);
243 // GetMUONData()->MakeBranch("D,S,RC");
244 // GetMUONData()->SetTreeAddress("H,D,S,RC");
245 GetMUONData()->SetTreeAddress("H");
246 if (fHits != GetMUONData()->Hits()) {
247 if ( gAlice->GetMCApp() )
248 if ( gAlice->GetMCApp()->GetHitLists() ) {
249 fHits = GetMUONData()->Hits();
250 gAlice->GetMCApp()->AddHitList(fHits); // For purifyKine, only necessary when Hit list is created in AliMUONData
253 fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector
256 //____________________________________________________________________
257 void AliMUON::SetPadSize(Int_t id, Int_t isec, Float_t p1, Float_t p2)
259 // Set the pad size for chamber id and cathode isec
261 ((AliMUONChamber*) fChambers->At(i)) ->SetPadSize(isec,p1,p2);
262 ((AliMUONChamber*) fChambers->At(i+1))->SetPadSize(isec,p1,p2);
265 //___________________________________________
266 void AliMUON::SetChambersZ(const Float_t *Z)
268 // Set Z values for all chambers (tracking and trigger)
269 // from the array pointed to by "Z"
270 for (Int_t ch = 0; ch < AliMUONConstants::NCh(); ch++)
271 ((AliMUONChamber*) fChambers->At(ch))->SetZ(Z[ch]);
274 //_________________________________________________________________
275 void AliMUON::SetChambersZToDefault()
277 // Set Z values for all chambers (tracking and trigger)
279 SetChambersZ(AliMUONConstants::DefaultChamberZ());
282 //_________________________________________________________________
283 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
285 // Set the inverse charge slope for chamber id
286 Int_t i=2*(id-1); //PH ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
287 //PH ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
288 ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
289 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
291 //__________________________________________________________________
292 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
294 // Set sigma of charge spread for chamber id
296 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
297 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
299 //___________________________________________________________________
300 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
302 // Set integration limits for charge spread
304 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
305 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
308 //__________________________________________________________________
309 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
311 // Set maximum number for ADCcounts (saturation)
313 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
314 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
317 //__________________________________________________________________
318 void AliMUON::SetMaxStepGas(Float_t p1)
320 // Set stepsize in gas
323 //__________________________________________________________________
324 void AliMUON::SetMaxStepAlu(Float_t p1)
326 // Set step size in Alu
329 //__________________________________________________________________
330 void AliMUON::SetMaxDestepGas(Float_t p1)
332 // Set maximum step size in Gas
335 //__________________________________________________________________
336 void AliMUON::SetMaxDestepAlu(Float_t p1)
338 // Set maximum step size in Alu
342 //___________________________________________________________________
343 void AliMUON::SetAcceptance(Bool_t acc, Float_t angmin, Float_t angmax)
345 // Set acceptance cuts
347 fAccMin=angmin*TMath::Pi()/180;
348 fAccMax=angmax*TMath::Pi()/180;
351 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
352 // Loop over 2 chambers in the station
353 for (Int_t stCH = 0; stCH < 2; stCH++) {
355 // Set chamber inner and outer radius according to acceptance cuts
356 Chamber(ch).SetRInner(TMath::Abs(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMin)));
357 Chamber(ch).SetROuter(TMath::Abs(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMax)));
363 //____________________________________________________________________
364 Float_t AliMUON::GetMaxStepGas() const
366 // Return stepsize in gas
371 //____________________________________________________________________
372 Float_t AliMUON::GetMaxStepAlu() const
374 // Return step size in Alu
379 //____________________________________________________________________
380 Float_t AliMUON::GetMaxDestepGas() const
382 // Return maximum step size in Gas
384 return fMaxDestepGas;
387 //____________________________________________________________________
388 Float_t AliMUON::GetMaxDestepAlu() const
390 // Return maximum step size in Gas
392 return fMaxDestepAlu;
395 //____________________________________________________________________
396 void AliMUON::SetAlign(Bool_t align)
398 // Sets option for alignement to geometry builder
400 fGeometryBuilder->SetAlign(align);
403 //____________________________________________________________________
404 void AliMUON::SetSegmentationModel(Int_t id, Int_t isec, AliSegmentation *segmentation)
406 // Set the segmentation for chamber id cathode isec
407 ((AliMUONChamber*) fChambers->At(id))->SetSegmentationModel(isec, segmentation);
410 //____________________________________________________________________
411 void AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
413 // Set the response for chamber id
414 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
416 //____________________________________________________________________
417 void AliMUON::SetNsec(Int_t id, Int_t nsec)
419 // Set number of segmented cathods for chamber id
420 ((AliMUONChamber*) fChambers->At(id))->SetNsec(nsec);
422 //____________________________________________________________________
423 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
425 return new AliMUONDigitizerv2(manager);
427 //_____________________________________________________________________
428 void AliMUON::SDigits2Digits()
434 if (gAlice->GetDebug()>0) {
435 cerr<<"AliMUON::SDigits2Digits: create default AliMUONMerger "<<endl;
436 cerr<<" no merging, just digitization of 1 event will be done"<<endl;
438 fMerger = new AliMUONMerger();
443 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
444 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
445 fLoader->TreeD()->Reset();
448 //_____________________________________________________________________
449 void AliMUON::Hits2SDigits()
451 // Adaption of AliMUONSDigitizerv1 to be excuted by the AliSimulation framework
452 AliRunLoader* runLoader = fLoader->GetRunLoader();
453 AliRunDigitizer * manager = new AliRunDigitizer(1,1);
454 manager->SetInputStream(0,runLoader->GetFileName(),AliConfig::GetDefaultEventFolderName());
455 AliMUONDigitizer * dMUON = new AliMUONSDigitizerv1(manager);
456 fLoader->LoadHits("READ");
457 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
458 runLoader->GetEvent(iEvent);
461 fLoader->UnloadHits();
463 //_____________________________________________________________________
464 void AliMUON::Digits2Raw()
466 // convert digits of the current event to raw data
467 AliMUONRawData* rawData;
469 rawData = new AliMUONRawData(fLoader);
470 if (!rawData->WriteRawData()) Info("MUON","pb writting raw data");
474 //_______________________________________________________________________
475 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
477 //builds standard getter (AliLoader type)
478 //if detector wants to use castomized getter, it must overload this method
482 "Creating standard getter for detector %s. Top folder is %s.",
483 GetName(),topfoldername);
484 fLoader = new AliLoader(GetName(),topfoldername);
485 fMUONData = new AliMUONData(fLoader,GetName(),GetName());
486 fMUONData->SetSplitLevel(fSplitLevel);
489 //_______________________________________________________________________
490 AliMUONPadHit* AliMUON::FirstPad(AliMUONHit* hit, TClonesArray *clusters)
493 // Initialise the pad iterator
494 // Return the address of the first padhit for hit
495 TClonesArray *theClusters = clusters;
496 Int_t nclust = theClusters->GetEntriesFast();
497 if (nclust && hit->PHlast() > 0) {
498 fMaxIterPad=hit->PHlast();
499 fCurIterPad=hit->PHfirst();
500 return (AliMUONPadHit*) clusters->UncheckedAt(fCurIterPad-1);
505 //_______________________________________________________________________
506 AliMUONPadHit* AliMUON::NextPad(TClonesArray *clusters)
509 // Get next pad (in iterator)
512 if (fCurIterPad <= fMaxIterPad) {
513 return (AliMUONPadHit*) clusters->UncheckedAt(fCurIterPad-1);
518 //_______________________________________________________________________
520 AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
523 // Return rawcluster (icluster) for chamber ichamber and cathode icathod
525 TClonesArray *muonRawCluster = GetMUONData()->RawClusters(ichamber);
527 TTree *treeR = fLoader->TreeR();
528 Int_t nent=(Int_t)treeR->GetEntries();
529 treeR->GetEvent(nent-2+icathod-1);
530 //treeR->GetEvent(icathod);
531 //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
533 AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
534 //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
538 //________________________________________________________________________
539 void AliMUON::SetMerger(AliMUONMerger* merger)
541 // Set pointer to merger
544 //________________________________________________________________________
545 AliMUONMerger* AliMUON::Merger()
547 // Return pointer to merger
550 /* PH Commented out waiting for correct implementation
551 //________________________________________________________________________
552 void AliMUON::RemapTrackHitIDs(Int_t* map)
554 // Remaps the track numbers in the hits arrays, so that they correspond
555 // to the entry indices in the Kine tree.
556 // The correspondance is not direct. To get the real index into the Kine tree
557 // compute the particle index as follows:
559 // num_primaries = AliStack::GetNprimary();
560 // num_tracks = AliStack::GetNtracks();
561 // track = AliMUONHit::Track()
563 // if (track < num_primaries)
564 // particleindex = track + num_tracks - num_primaries;
566 // particleindex = track - num_primaries;
568 // Remap the track numbers based on the specified map.
569 AliMUONData* data = GetMUONData();
570 TClonesArray* hits = data->Hits();
571 for (Int_t i = 0; i < hits->GetEntriesFast(); i++)
573 AliMUONHit* hit = static_cast<AliMUONHit*>( hits->At(i) );
574 hit->SetTrack( map[hit->Track()] );