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"
70 #include "AliMUONRawData.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
138 SetMarkerColor(kRed);//
140 // Creating List of Chambers
142 fChambers = new TObjArray(AliMUONConstants::NCh());
143 fGeometryBuilders = new TObjArray(AliMUONConstants::NCh());
145 // Loop over stations
146 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
147 // Loop over 2 chambers in the station
148 for (Int_t stCH = 0; stCH < 2; stCH++) {
151 // Default Parameters for Muon Tracking Stations
153 if (ch < AliMUONConstants::NTrackingCh()) {
154 fChambers->AddAt(new AliMUONChamber(ch),ch);
156 fChambers->AddAt(new AliMUONChamberTrigger(ch),ch);
158 AliMUONChamber* chamber = (AliMUONChamber*) fChambers->At(ch);
159 //chamber->SetGid(0);
160 // Default values for Z of chambers
161 chamber->SetZ(AliMUONConstants::DefaultChamberZ(ch));
163 chamber->InitGeo(AliMUONConstants::DefaultChamberZ(ch));
164 // Set chamber inner and outer radius to default
165 chamber->SetRInner(AliMUONConstants::Dmin(st)/2);
166 chamber->SetROuter(AliMUONConstants::Dmax(st)/2);
168 } // Chamber stCH (0, 1) in
169 } // Station st (0...)
171 // cp new design of AliMUONTriggerDecision
172 fTriggerCircuits = new TObjArray(AliMUONConstants::NTriggerCircuit());
173 for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
174 fTriggerCircuits->AddAt(new AliMUONTriggerCircuit(),circ);
178 //____________________________________________________________________
179 AliMUON::AliMUON(const AliMUON& rMUON)
182 // Protected copy constructor
184 Fatal("AliMUONMergerModule", "Not implemented.");
187 //____________________________________________________________________
191 if(fDebug) printf("%s: Calling AliMUON destructor !!!\n",ClassName());
193 if (fMerger) delete fMerger;
195 if (fGeometryBuilders){
196 fGeometryBuilders->Delete();
197 delete fGeometryBuilders;
203 if (fTriggerCircuits){
204 fTriggerCircuits->Delete();
205 delete fTriggerCircuits;
210 //________________________________________________________________________
211 AliMUON& AliMUON::operator = (const AliMUON& rhs)
213 // Protected assignement operator
215 if (this == &rhs) return *this;
217 Fatal("operator=", "Not implemented.");
222 //_____________________________________________________________________________
223 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
225 // Adds the geometry builder to the list
228 fGeometryBuilders->Add(geomBuilder);
231 //____________________________________________________________________
232 void AliMUON::BuildGeometry()
234 // Geometry for event display
236 for (Int_t i=0; i<7; i++) {
237 for (Int_t j=0; j<2; j++) {
239 this->Chamber(id-1).SegmentationModel(1)->Draw("eventdisplay");
244 //__________________________________________________________________
245 void AliMUON::SetTreeAddress()
247 GetMUONData()->SetLoader(fLoader);
248 // GetMUONData()->MakeBranch("D,S,RC");
249 // GetMUONData()->SetTreeAddress("H,D,S,RC");
250 GetMUONData()->SetTreeAddress("H");
251 if (fHits != GetMUONData()->Hits()) {
252 if ( gAlice->GetMCApp() )
253 if ( gAlice->GetMCApp()->GetHitLists() ) {
254 fHits = GetMUONData()->Hits();
255 gAlice->GetMCApp()->AddHitList(fHits); // For purifyKine, only necessary when Hit list is created in AliMUONData
258 fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector
261 //____________________________________________________________________
262 void AliMUON::SetPadSize(Int_t id, Int_t isec, Float_t p1, Float_t p2)
264 // Set the pad size for chamber id and cathode isec
266 ((AliMUONChamber*) fChambers->At(i)) ->SetPadSize(isec,p1,p2);
267 ((AliMUONChamber*) fChambers->At(i+1))->SetPadSize(isec,p1,p2);
270 //___________________________________________
271 void AliMUON::SetChambersZ(const Float_t *Z)
273 // Set Z values for all chambers (tracking and trigger)
274 // from the array pointed to by "Z"
275 for (Int_t ch = 0; ch < AliMUONConstants::NCh(); ch++)
276 ((AliMUONChamber*) fChambers->At(ch))->SetZ(Z[ch]);
279 //_________________________________________________________________
280 void AliMUON::SetChambersZToDefault()
282 // Set Z values for all chambers (tracking and trigger)
284 SetChambersZ(AliMUONConstants::DefaultChamberZ());
287 //_________________________________________________________________
288 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
290 // Set the inverse charge slope for chamber id
291 Int_t i=2*(id-1); //PH ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
292 //PH ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
293 ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
294 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
296 //__________________________________________________________________
297 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
299 // Set sigma of charge spread for chamber id
301 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
302 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
304 //___________________________________________________________________
305 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
307 // Set integration limits for charge spread
309 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
310 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
313 //__________________________________________________________________
314 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
316 // Set maximum number for ADCcounts (saturation)
318 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
319 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
321 //__________________________________________________________________
322 void AliMUON::SetMaxStepGas(Float_t p1)
324 // Set stepsize in gas
327 //__________________________________________________________________
328 void AliMUON::SetMaxStepAlu(Float_t p1)
330 // Set step size in Alu
333 //__________________________________________________________________
334 void AliMUON::SetMaxDestepGas(Float_t p1)
336 // Set maximum step size in Gas
339 //__________________________________________________________________
340 void AliMUON::SetMaxDestepAlu(Float_t p1)
342 // Set maximum step size in Alu
345 //___________________________________________________________________
346 void AliMUON::SetAcceptance(Bool_t acc, Float_t angmin, Float_t angmax)
348 // Set acceptance cuts
350 fAccMin=angmin*TMath::Pi()/180;
351 fAccMax=angmax*TMath::Pi()/180;
354 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
355 // Loop over 2 chambers in the station
356 for (Int_t stCH = 0; stCH < 2; stCH++) {
358 // Set chamber inner and outer radius according to acceptance cuts
359 Chamber(ch).SetRInner(TMath::Abs(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMin)));
360 Chamber(ch).SetROuter(TMath::Abs(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMax)));
366 //____________________________________________________________________
367 Float_t AliMUON::GetMaxStepGas() const
369 // Return stepsize in gas
374 //____________________________________________________________________
375 Float_t AliMUON::GetMaxStepAlu() const
377 // Return step size in Alu
382 //____________________________________________________________________
383 Float_t AliMUON::GetMaxDestepGas() const
385 // Return maximum step size in Gas
387 return fMaxDestepGas;
390 //____________________________________________________________________
391 Float_t AliMUON::GetMaxDestepAlu() const
393 // Return maximum step size in Gas
395 return fMaxDestepAlu;
397 //____________________________________________________________________
398 void AliMUON::SetSegmentationModel(Int_t id, Int_t isec, AliSegmentation *segmentation)
400 // Set the segmentation for chamber id cathode isec
401 ((AliMUONChamber*) fChambers->At(id))->SetSegmentationModel(isec, segmentation);
404 //____________________________________________________________________
405 void AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
407 // Set the response for chamber id
408 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
410 //____________________________________________________________________
411 void AliMUON::SetNsec(Int_t id, Int_t nsec)
413 // Set number of segmented cathods for chamber id
414 ((AliMUONChamber*) fChambers->At(id))->SetNsec(nsec);
416 //____________________________________________________________________
417 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
419 return new AliMUONDigitizerv2(manager);
421 //_____________________________________________________________________
422 void AliMUON::SDigits2Digits()
428 if (gAlice->GetDebug()>0) {
429 cerr<<"AliMUON::SDigits2Digits: create default AliMUONMerger "<<endl;
430 cerr<<" no merging, just digitization of 1 event will be done"<<endl;
432 fMerger = new AliMUONMerger();
437 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
438 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
439 fLoader->TreeD()->Reset();
442 //_____________________________________________________________________
443 void AliMUON::Hits2SDigits()
445 // Adaption of AliMUONSDigitizerv1 to be excuted by the AliSimulation framework
446 AliRunLoader* runLoader = fLoader->GetRunLoader();
447 AliRunDigitizer * manager = new AliRunDigitizer(1,1);
448 manager->SetInputStream(0,runLoader->GetFileName(),AliConfig::GetDefaultEventFolderName());
449 AliMUONDigitizer * dMUON = new AliMUONSDigitizerv1(manager);
450 fLoader->LoadHits("READ");
451 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
452 runLoader->GetEvent(iEvent);
455 fLoader->UnloadHits();
457 //_____________________________________________________________________
458 void AliMUON::Digits2Raw()
460 // convert digits of the current event to raw data
461 AliMUONRawData* rawData;
463 rawData = new AliMUONRawData(fLoader);
464 if (!rawData->WriteRawData()) Info("MUON","pb writting raw data");
468 //_______________________________________________________________________
469 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
471 //builds standard getter (AliLoader type)
472 //if detector wants to use castomized getter, it must overload this method
476 "Creating standard getter for detector %s. Top folder is %s.",
477 GetName(),topfoldername);
478 fLoader = new AliLoader(GetName(),topfoldername);
479 fMUONData = new AliMUONData(fLoader,GetName(),GetName());
480 fMUONData->SetSplitLevel(fSplitLevel);
483 //_______________________________________________________________________
484 AliMUONPadHit* AliMUON::FirstPad(AliMUONHit* hit, TClonesArray *clusters)
487 // Initialise the pad iterator
488 // Return the address of the first padhit for hit
489 TClonesArray *theClusters = clusters;
490 Int_t nclust = theClusters->GetEntriesFast();
491 if (nclust && hit->PHlast() > 0) {
492 fMaxIterPad=hit->PHlast();
493 fCurIterPad=hit->PHfirst();
494 return (AliMUONPadHit*) clusters->UncheckedAt(fCurIterPad-1);
499 //_______________________________________________________________________
500 AliMUONPadHit* AliMUON::NextPad(TClonesArray *clusters)
503 // Get next pad (in iterator)
506 if (fCurIterPad <= fMaxIterPad) {
507 return (AliMUONPadHit*) clusters->UncheckedAt(fCurIterPad-1);
512 //_______________________________________________________________________
514 AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
517 // Return rawcluster (icluster) for chamber ichamber and cathode icathod
519 TClonesArray *muonRawCluster = GetMUONData()->RawClusters(ichamber);
521 TTree *treeR = fLoader->TreeR();
522 Int_t nent=(Int_t)treeR->GetEntries();
523 treeR->GetEvent(nent-2+icathod-1);
524 //treeR->GetEvent(icathod);
525 //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
527 AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
528 //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
532 //________________________________________________________________________
533 void AliMUON::SetMerger(AliMUONMerger* merger)
535 // Set pointer to merger
538 //________________________________________________________________________
539 AliMUONMerger* AliMUON::Merger()
541 // Return pointer to merger
544 /* PH Commented out waiting for correct implementation
545 //________________________________________________________________________
546 void AliMUON::RemapTrackHitIDs(Int_t* map)
548 // Remaps the track numbers in the hits arrays, so that they correspond
549 // to the entry indices in the Kine tree.
550 // The correspondance is not direct. To get the real index into the Kine tree
551 // compute the particle index as follows:
553 // num_primaries = AliStack::GetNprimary();
554 // num_tracks = AliStack::GetNtracks();
555 // track = AliMUONHit::Track()
557 // if (track < num_primaries)
558 // particleindex = track + num_tracks - num_primaries;
560 // particleindex = track - num_primaries;
562 // Remap the track numbers based on the specified map.
563 AliMUONData* data = GetMUONData();
564 TClonesArray* hits = data->Hits();
565 for (Int_t i = 0; i < hits->GetEntriesFast(); i++)
567 AliMUONHit* hit = static_cast<AliMUONHit*>( hits->At(i) );
568 hit->SetTrack( map[hit->Track()] );