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 "AliMUONCommonGeometryBuilder.h"
64 #include "AliMUONVGeometryBuilder.h"
65 #include "AliMUONGeometryDEIndexing.h"
66 #include "AliMUONDigitizerv2.h"
67 #include "AliMUONSDigitizerv1.h"
68 #include "AliMUONRawData.h"
71 // Defaults parameters for Z positions of chambers
72 // taken from values for "stations" in AliMUON::AliMUON
73 // const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
74 // and from array "dstation" in AliMUONv1::CreateGeometry
75 // Float_t dstation[5]={20., 20., 20, 20., 20.};
76 // for tracking chambers,
77 // according to (Z1 = zch - dstation) and (Z2 = zch + dstation)
78 // for the first and second chambers in the station, respectively,
79 // and from "DTPLANES" in AliMUONv1::CreateGeometry
80 // const Float_t DTPLANES = 15.;
81 // for trigger chambers,
82 // according to (Z1 = zch) and (Z2 = zch + DTPLANES)
83 // for the first and second chambers in the station, respectively
87 //__________________________________________________________________
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()),
130 fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200
131 fMaxDestepAlu(-1), // in the calculation of the tracking parameters
139 SetMarkerColor(kRed);//
142 fGeometryBuilder = new AliMUONGeometryBuilder(this);
144 // Common geometry definitions
146 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
148 // Define the global transformation:
149 // Transformation from the old ALICE coordinate system to a new one:
151 TGeoRotation* rotGlobal
152 = new TGeoRotation("rotGlobal", 90., 180., 90., 90., 180., 0.);
154 ->SetGlobalTransformation (TGeoCombiTrans(0., 0., 0., rotGlobal));
156 // Detection elements indexing
157 fDEIndexing = new AliMUONGeometryDEIndexing();
160 // Creating List of Chambers
162 fChambers = new TObjArray(AliMUONConstants::NCh());
164 // Loop over stations
165 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
166 // Loop over 2 chambers in the station
167 for (Int_t stCH = 0; stCH < 2; stCH++) {
170 // Default Parameters for Muon Tracking Stations
172 if (ch < AliMUONConstants::NTrackingCh()) {
173 fChambers->AddAt(new AliMUONChamber(ch),ch);
175 fChambers->AddAt(new AliMUONChamberTrigger(ch),ch);
177 AliMUONChamber* chamber = (AliMUONChamber*) fChambers->At(ch);
178 //chamber->SetGid(0);
179 // Default values for Z of chambers
180 chamber->SetZ(AliMUONConstants::DefaultChamberZ(ch));
182 chamber->InitGeo(AliMUONConstants::DefaultChamberZ(ch));
183 // Set chamber inner and outer radius to default
184 chamber->SetRInner(AliMUONConstants::Dmin(st)/2);
185 chamber->SetROuter(AliMUONConstants::Dmax(st)/2);
187 } // Chamber stCH (0, 1) in
188 } // Station st (0...)
190 // cp new design of AliMUONTriggerDecision
191 fTriggerCircuits = new TObjArray(AliMUONConstants::NTriggerCircuit());
192 for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
193 fTriggerCircuits->AddAt(new AliMUONTriggerCircuit(),circ);
197 //____________________________________________________________________
198 AliMUON::AliMUON(const AliMUON& rMUON)
201 // Protected copy constructor
203 AliFatal("Not implemented.");
206 //____________________________________________________________________
210 AliDebug(1,"Calling AliMUON destructor");
212 if (fMerger) delete fMerger;
218 if (fTriggerCircuits){
219 fTriggerCircuits->Delete();
220 delete fTriggerCircuits;
223 delete fGeometryBuilder;
227 //________________________________________________________________________
228 AliMUON& AliMUON::operator = (const AliMUON& rhs)
230 // Protected assignement operator
232 if (this == &rhs) return *this;
234 AliFatal("Not implemented.");
239 //_____________________________________________________________________________
240 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
242 // Adds the geometry builder to the list
245 fGeometryBuilder->AddBuilder(geomBuilder);
248 //____________________________________________________________________
249 void AliMUON::BuildGeometry()
251 // Geometry for event display
253 for (Int_t i=0; i<7; i++) {
254 for (Int_t j=0; j<2; j++) {
256 this->Chamber(id-1).SegmentationModel(1)->Draw("eventdisplay");
261 //__________________________________________________________________
262 void AliMUON::SetTreeAddress()
264 GetMUONData()->SetLoader(fLoader);
265 // GetMUONData()->MakeBranch("D,S,RC");
266 // GetMUONData()->SetTreeAddress("H,D,S,RC");
267 GetMUONData()->SetTreeAddress("H");
268 if (fHits != GetMUONData()->Hits()) {
269 if ( gAlice->GetMCApp() )
270 if ( gAlice->GetMCApp()->GetHitLists() ) {
271 fHits = GetMUONData()->Hits();
272 gAlice->GetMCApp()->AddHitList(fHits); // For purifyKine, only necessary when Hit list is created in AliMUONData
275 fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector
278 //____________________________________________________________________
279 void AliMUON::SetPadSize(Int_t id, Int_t isec, Float_t p1, Float_t p2)
281 // Set the pad size for chamber id and cathode isec
283 ((AliMUONChamber*) fChambers->At(i)) ->SetPadSize(isec,p1,p2);
284 ((AliMUONChamber*) fChambers->At(i+1))->SetPadSize(isec,p1,p2);
287 //___________________________________________
288 void AliMUON::SetChambersZ(const Float_t *Z)
290 // Set Z values for all chambers (tracking and trigger)
291 // from the array pointed to by "Z"
292 for (Int_t ch = 0; ch < AliMUONConstants::NCh(); ch++)
293 ((AliMUONChamber*) fChambers->At(ch))->SetZ(Z[ch]);
296 //_________________________________________________________________
297 void AliMUON::SetChambersZToDefault()
299 // Set Z values for all chambers (tracking and trigger)
301 SetChambersZ(AliMUONConstants::DefaultChamberZ());
304 //_________________________________________________________________
305 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
307 // Set the inverse charge slope for chamber id
308 Int_t i=2*(id-1); //PH ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
309 //PH ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
310 ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
311 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
313 //__________________________________________________________________
314 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
316 // Set sigma of charge spread for chamber id
318 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
319 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
321 //___________________________________________________________________
322 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
324 // Set integration limits for charge spread
326 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
327 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
330 //__________________________________________________________________
331 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
333 // Set maximum number for ADCcounts (saturation)
335 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
336 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
339 //__________________________________________________________________
340 void AliMUON::SetMaxStepGas(Float_t p1)
342 // Set stepsize in gas
345 //__________________________________________________________________
346 void AliMUON::SetMaxStepAlu(Float_t p1)
348 // Set step size in Alu
351 //__________________________________________________________________
352 void AliMUON::SetMaxDestepGas(Float_t p1)
354 // Set maximum step size in Gas
357 //__________________________________________________________________
358 void AliMUON::SetMaxDestepAlu(Float_t p1)
360 // Set maximum step size in Alu
364 //___________________________________________________________________
365 void AliMUON::SetAcceptance(Bool_t acc, Float_t angmin, Float_t angmax)
367 // Set acceptance cuts
369 fAccMin=angmin*TMath::Pi()/180;
370 fAccMax=angmax*TMath::Pi()/180;
373 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
374 // Loop over 2 chambers in the station
375 for (Int_t stCH = 0; stCH < 2; stCH++) {
377 // Set chamber inner and outer radius according to acceptance cuts
378 Chamber(ch).SetRInner(TMath::Abs(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMin)));
379 Chamber(ch).SetROuter(TMath::Abs(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMax)));
385 //____________________________________________________________________
386 Float_t AliMUON::GetMaxStepGas() const
388 // Return stepsize in gas
393 //____________________________________________________________________
394 Float_t AliMUON::GetMaxStepAlu() const
396 // Return step size in Alu
401 //____________________________________________________________________
402 Float_t AliMUON::GetMaxDestepGas() const
404 // Return maximum step size in Gas
406 return fMaxDestepGas;
409 //____________________________________________________________________
410 Float_t AliMUON::GetMaxDestepAlu() const
412 // Return maximum step size in Gas
414 return fMaxDestepAlu;
417 //____________________________________________________________________
418 void AliMUON::SetAlign(Bool_t align)
420 // Sets option for alignement to geometry builder
422 fGeometryBuilder->SetAlign(align);
425 //____________________________________________________________________
426 void AliMUON::SetSegmentationModel(Int_t id, Int_t isec, AliSegmentation *segmentation)
428 // Set the segmentation for chamber id cathode isec
429 ((AliMUONChamber*) fChambers->At(id))->SetSegmentationModel(isec, segmentation);
432 //____________________________________________________________________
433 void AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
435 // Set the response for chamber id
436 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
438 //____________________________________________________________________
439 void AliMUON::SetNsec(Int_t id, Int_t nsec)
441 // Set number of segmented cathods for chamber id
442 ((AliMUONChamber*) fChambers->At(id))->SetNsec(nsec);
444 //____________________________________________________________________
445 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
447 return new AliMUONDigitizerv2(manager);
449 //_____________________________________________________________________
450 void AliMUON::SDigits2Digits()
456 AliDebug(1,"Create default AliMUONMerger ");
457 AliDebug(1," no merging, just digitization of 1 event will be done");
458 fMerger = new AliMUONMerger();
463 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
464 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
465 fLoader->TreeD()->Reset();
468 //_____________________________________________________________________
469 void AliMUON::Hits2SDigits()
471 // Adaption of AliMUONSDigitizerv1 to be excuted by the AliSimulation framework
472 AliRunLoader* runLoader = fLoader->GetRunLoader();
473 AliRunDigitizer * manager = new AliRunDigitizer(1,1);
474 manager->SetInputStream(0,runLoader->GetFileName(),AliConfig::GetDefaultEventFolderName());
475 AliMUONDigitizer * dMUON = new AliMUONSDigitizerv1(manager);
476 fLoader->LoadHits("READ");
477 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
478 runLoader->GetEvent(iEvent);
481 fLoader->UnloadHits();
483 //_____________________________________________________________________
484 void AliMUON::Digits2Raw()
486 // convert digits of the current event to raw data
487 AliMUONRawData* rawData;
489 rawData = new AliMUONRawData(fLoader);
490 if (!rawData->WriteRawData()) AliInfo("pb writting raw data");
494 //_______________________________________________________________________
495 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
497 //builds standard getter (AliLoader type)
498 //if detector wants to use castomized getter, it must overload this method
501 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
502 GetName(),topfoldername));
503 fLoader = new AliLoader(GetName(),topfoldername);
504 fMUONData = new AliMUONData(fLoader,GetName(),GetName());
505 fMUONData->SetSplitLevel(fSplitLevel);
508 //_______________________________________________________________________
509 AliMUONPadHit* AliMUON::FirstPad(AliMUONHit* hit, TClonesArray *clusters)
512 // Initialise the pad iterator
513 // Return the address of the first padhit for hit
514 TClonesArray *theClusters = clusters;
515 Int_t nclust = theClusters->GetEntriesFast();
516 if (nclust && hit->PHlast() > 0) {
517 fMaxIterPad=hit->PHlast();
518 fCurIterPad=hit->PHfirst();
519 return (AliMUONPadHit*) clusters->UncheckedAt(fCurIterPad-1);
524 //_______________________________________________________________________
525 AliMUONPadHit* AliMUON::NextPad(TClonesArray *clusters)
528 // Get next pad (in iterator)
531 if (fCurIterPad <= fMaxIterPad) {
532 return (AliMUONPadHit*) clusters->UncheckedAt(fCurIterPad-1);
537 //_______________________________________________________________________
539 AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
542 // Return rawcluster (icluster) for chamber ichamber and cathode icathod
544 TClonesArray *muonRawCluster = GetMUONData()->RawClusters(ichamber);
546 TTree *treeR = fLoader->TreeR();
547 Int_t nent=(Int_t)treeR->GetEntries();
548 treeR->GetEvent(nent-2+icathod-1);
549 //treeR->GetEvent(icathod);
550 //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
552 AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
553 //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
557 //________________________________________________________________________
558 void AliMUON::SetMerger(AliMUONMerger* merger)
560 // Set pointer to merger
563 //________________________________________________________________________
564 AliMUONMerger* AliMUON::Merger()
566 // Return pointer to merger
569 /* PH Commented out waiting for correct implementation
570 //________________________________________________________________________
571 void AliMUON::RemapTrackHitIDs(Int_t* map)
573 // Remaps the track numbers in the hits arrays, so that they correspond
574 // to the entry indices in the Kine tree.
575 // The correspondance is not direct. To get the real index into the Kine tree
576 // compute the particle index as follows:
578 // num_primaries = AliStack::GetNprimary();
579 // num_tracks = AliStack::GetNtracks();
580 // track = AliMUONHit::Track()
582 // if (track < num_primaries)
583 // particleindex = track + num_tracks - num_primaries;
585 // particleindex = track - num_primaries;
587 // Remap the track numbers based on the specified map.
588 AliMUONData* data = GetMUONData();
589 TClonesArray* hits = data->Hits();
590 for (Int_t i = 0; i < hits->GetEntriesFast(); i++)
592 AliMUONHit* hit = static_cast<AliMUONHit*>( hits->At(i) );
593 hit->SetTrack( map[hit->Track()] );