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 "AliMUONGeometrySegmentation.h"
67 #include "AliMUONDigitizerv2.h"
68 #include "AliMUONSDigitizerv1.h"
69 #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 //__________________________________________________________________
98 fSegmentationType(1),// set to 1 default wise old seg
111 // Default Constructor
116 //__________________________________________________________________
117 AliMUON::AliMUON(const char *name, const char *title)
118 : AliDetector(name,title),
119 fNCh(AliMUONConstants::NCh()),
120 fNTrackingCh(AliMUONConstants::NTrackingCh()),
126 fSegmentationType(1),// set to 1 default wise old seg
133 fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200
134 fMaxDestepAlu(-1), // in the calculation of the tracking parameters
142 SetMarkerColor(kRed);//
145 fGeometryBuilder = new AliMUONGeometryBuilder(this);
147 // Common geometry definitions
149 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
151 // Define the global transformation:
152 // Transformation from the old ALICE coordinate system to a new one:
154 TGeoRotation* rotGlobal
155 = new TGeoRotation("rotGlobal", 90., 180., 90., 90., 180., 0.);
157 ->SetGlobalTransformation (TGeoCombiTrans(0., 0., 0., rotGlobal));
159 // Detection elements indexing
160 fDEIndexing = new AliMUONGeometryDEIndexing();
163 // Creating List of Chambers
165 fChambers = new TObjArray(AliMUONConstants::NCh());
167 // Loop over stations
168 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
169 // Loop over 2 chambers in the station
170 for (Int_t stCH = 0; stCH < 2; stCH++) {
173 // Default Parameters for Muon Tracking Stations
175 if (ch < AliMUONConstants::NTrackingCh()) {
176 fChambers->AddAt(new AliMUONChamber(ch),ch);
178 fChambers->AddAt(new AliMUONChamberTrigger(ch),ch);
180 AliMUONChamber* chamber = (AliMUONChamber*) fChambers->At(ch);
181 //chamber->SetGid(0);
182 // Default values for Z of chambers
183 chamber->SetZ(AliMUONConstants::DefaultChamberZ(ch));
185 chamber->InitGeo(AliMUONConstants::DefaultChamberZ(ch));
186 // Set chamber inner and outer radius to default
187 chamber->SetRInner(AliMUONConstants::Dmin(st)/2);
188 chamber->SetROuter(AliMUONConstants::Dmax(st)/2);
190 } // Chamber stCH (0, 1) in
191 } // Station st (0...)
193 // cp new design of AliMUONTriggerDecision
194 fTriggerCircuits = new TObjArray(AliMUONConstants::NTriggerCircuit());
195 for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
196 fTriggerCircuits->AddAt(new AliMUONTriggerCircuit(),circ);
200 //____________________________________________________________________
201 AliMUON::AliMUON(const AliMUON& rMUON)
204 // Protected copy constructor
206 AliFatal("Not implemented.");
209 //____________________________________________________________________
213 AliDebug(1,"Calling AliMUON destructor");
215 if (fMerger) delete fMerger;
221 if (fTriggerCircuits){
222 fTriggerCircuits->Delete();
223 delete fTriggerCircuits;
226 delete fGeometryBuilder;
230 //________________________________________________________________________
231 AliMUON& AliMUON::operator = (const AliMUON& rhs)
233 // Protected assignement operator
235 if (this == &rhs) return *this;
237 AliFatal("Not implemented.");
242 //_____________________________________________________________________________
243 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
245 // Adds the geometry builder to the list
248 fGeometryBuilder->AddBuilder(geomBuilder);
251 //____________________________________________________________________
252 void AliMUON::BuildGeometry()
254 // Geometry for event display
256 if (!fSegmentationType) {
257 AliFatal("No Segmentation Type defined.");
261 if (fSegmentationType == 1) {
262 for (Int_t i=0; i<7; i++) {
263 for (Int_t j=0; j<2; j++) {
265 this->Chamber(id-1).SegmentationModel(1)->Draw("eventdisplay");
269 // for (Int_t i=0; i<14; i++) {
270 // for (Int_t j=0; j<100; j++) {
271 // Int_t id= (i+1)*100 + j;
272 // this->Chamber(i).SegmentationModel2(1)->Draw(id,"eventdisplay");// to be check !
278 //__________________________________________________________________
279 void AliMUON::SetTreeAddress()
281 GetMUONData()->SetLoader(fLoader);
282 // GetMUONData()->MakeBranch("D,S,RC");
283 // GetMUONData()->SetTreeAddress("H,D,S,RC");
284 GetMUONData()->SetTreeAddress("H");
285 if (fHits != GetMUONData()->Hits()) {
286 if ( gAlice->GetMCApp() )
287 if ( gAlice->GetMCApp()->GetHitLists() ) {
288 fHits = GetMUONData()->Hits();
289 gAlice->GetMCApp()->AddHitList(fHits); // For purifyKine, only necessary when Hit list is created in AliMUONData
292 fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector
295 //____________________________________________________________________
296 void AliMUON::SetPadSize(Int_t id, Int_t isec, Float_t p1, Float_t p2)
298 // Set the pad size for chamber id and cathode isec
300 ((AliMUONChamber*) fChambers->At(i)) ->SetPadSize(isec,p1,p2);
301 ((AliMUONChamber*) fChambers->At(i+1))->SetPadSize(isec,p1,p2);
304 //___________________________________________
305 void AliMUON::SetChambersZ(const Float_t *Z)
307 // Set Z values for all chambers (tracking and trigger)
308 // from the array pointed to by "Z"
309 for (Int_t ch = 0; ch < AliMUONConstants::NCh(); ch++)
310 ((AliMUONChamber*) fChambers->At(ch))->SetZ(Z[ch]);
313 //_________________________________________________________________
314 void AliMUON::SetChambersZToDefault()
316 // Set Z values for all chambers (tracking and trigger)
318 SetChambersZ(AliMUONConstants::DefaultChamberZ());
321 //_________________________________________________________________
322 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
324 // Set the inverse charge slope for chamber id
325 Int_t i=2*(id-1); //PH ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
326 //PH ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
327 ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
328 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
330 //__________________________________________________________________
331 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
333 // Set sigma of charge spread for chamber id
335 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
336 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
338 //___________________________________________________________________
339 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
341 // Set integration limits for charge spread
343 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
344 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
347 //__________________________________________________________________
348 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
350 // Set maximum number for ADCcounts (saturation)
352 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
353 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
356 //__________________________________________________________________
357 void AliMUON::SetMaxStepGas(Float_t p1)
359 // Set stepsize in gas
362 //__________________________________________________________________
363 void AliMUON::SetMaxStepAlu(Float_t p1)
365 // Set step size in Alu
368 //__________________________________________________________________
369 void AliMUON::SetMaxDestepGas(Float_t p1)
371 // Set maximum step size in Gas
374 //__________________________________________________________________
375 void AliMUON::SetMaxDestepAlu(Float_t p1)
377 // Set maximum step size in Alu
381 //___________________________________________________________________
382 void AliMUON::SetAcceptance(Bool_t acc, Float_t angmin, Float_t angmax)
384 // Set acceptance cuts
386 fAccMin=angmin*TMath::Pi()/180;
387 fAccMax=angmax*TMath::Pi()/180;
390 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
391 // Loop over 2 chambers in the station
392 for (Int_t stCH = 0; stCH < 2; stCH++) {
394 // Set chamber inner and outer radius according to acceptance cuts
395 Chamber(ch).SetRInner(TMath::Abs(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMin)));
396 Chamber(ch).SetROuter(TMath::Abs(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMax)));
402 //____________________________________________________________________
403 Float_t AliMUON::GetMaxStepGas() const
405 // Return stepsize in gas
410 //____________________________________________________________________
411 Float_t AliMUON::GetMaxStepAlu() const
413 // Return step size in Alu
418 //____________________________________________________________________
419 Float_t AliMUON::GetMaxDestepGas() const
421 // Return maximum step size in Gas
423 return fMaxDestepGas;
426 //____________________________________________________________________
427 Float_t AliMUON::GetMaxDestepAlu() const
429 // Return maximum step size in Gas
431 return fMaxDestepAlu;
434 //____________________________________________________________________
435 void AliMUON::SetAlign(Bool_t align)
437 // Sets option for alignement to geometry builder
439 fGeometryBuilder->SetAlign(align);
442 //____________________________________________________________________
443 void AliMUON::SetSegmentationModel(Int_t id, Int_t isec, AliSegmentation *segmentation)
445 // Set the segmentation for chamber id cathode isec
446 ((AliMUONChamber*) fChambers->At(id))->SetSegmentationModel(isec, segmentation);
448 //____________________________________________________________________
449 void AliMUON::SetSegmentationModel(Int_t id, Int_t isec, AliMUONGeometrySegmentation* segmentation)
451 // Set the segmentation for chamber id cathode isec
452 ((AliMUONChamber*) fChambers->At(id))->SetSegmentationModel(isec, segmentation);
455 //____________________________________________________________________
456 void AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
458 // Set the response for chamber id
459 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
461 //____________________________________________________________________
462 void AliMUON::SetNsec(Int_t id, Int_t nsec)
464 // Set number of segmented cathods for chamber id
465 ((AliMUONChamber*) fChambers->At(id))->SetNsec(nsec);
467 //____________________________________________________________________
468 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
470 return new AliMUONDigitizerv2(manager);
472 //_____________________________________________________________________
473 void AliMUON::SDigits2Digits()
479 AliDebug(1,"Create default AliMUONMerger ");
480 AliDebug(1," no merging, just digitization of 1 event will be done");
481 fMerger = new AliMUONMerger();
486 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
487 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
488 fLoader->TreeD()->Reset();
491 //_____________________________________________________________________
492 void AliMUON::Hits2SDigits()
494 // Adaption of AliMUONSDigitizerv1 to be excuted by the AliSimulation framework
495 AliRunLoader* runLoader = fLoader->GetRunLoader();
496 AliRunDigitizer * manager = new AliRunDigitizer(1,1);
497 manager->SetInputStream(0,runLoader->GetFileName(),AliConfig::GetDefaultEventFolderName());
498 AliMUONDigitizer * dMUON = new AliMUONSDigitizerv1(manager);
499 fLoader->LoadHits("READ");
500 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
501 runLoader->GetEvent(iEvent);
504 fLoader->UnloadHits();
506 //_____________________________________________________________________
507 void AliMUON::Digits2Raw()
509 // convert digits of the current event to raw data
510 AliMUONRawData* rawData;
512 rawData = new AliMUONRawData(fLoader);
513 if (!rawData->WriteRawData()) AliInfo("pb writting raw data");
517 //_______________________________________________________________________
518 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
520 //builds standard getter (AliLoader type)
521 //if detector wants to use castomized getter, it must overload this method
524 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
525 GetName(),topfoldername));
526 fLoader = new AliLoader(GetName(),topfoldername);
527 fMUONData = new AliMUONData(fLoader,GetName(),GetName());
528 fMUONData->SetSplitLevel(fSplitLevel);
531 //_______________________________________________________________________
532 AliMUONPadHit* AliMUON::FirstPad(AliMUONHit* hit, TClonesArray *clusters)
535 // Initialise the pad iterator
536 // Return the address of the first padhit for hit
537 TClonesArray *theClusters = clusters;
538 Int_t nclust = theClusters->GetEntriesFast();
539 if (nclust && hit->PHlast() > 0) {
540 fMaxIterPad=hit->PHlast();
541 fCurIterPad=hit->PHfirst();
542 return (AliMUONPadHit*) clusters->UncheckedAt(fCurIterPad-1);
547 //_______________________________________________________________________
548 AliMUONPadHit* AliMUON::NextPad(TClonesArray *clusters)
551 // Get next pad (in iterator)
554 if (fCurIterPad <= fMaxIterPad) {
555 return (AliMUONPadHit*) clusters->UncheckedAt(fCurIterPad-1);
560 //_______________________________________________________________________
562 AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
565 // Return rawcluster (icluster) for chamber ichamber and cathode icathod
567 TClonesArray *muonRawCluster = GetMUONData()->RawClusters(ichamber);
569 TTree *treeR = fLoader->TreeR();
570 Int_t nent=(Int_t)treeR->GetEntries();
571 treeR->GetEvent(nent-2+icathod-1);
572 //treeR->GetEvent(icathod);
573 //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
575 AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
576 //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
580 //________________________________________________________________________
581 void AliMUON::SetMerger(AliMUONMerger* merger)
583 // Set pointer to merger
586 //________________________________________________________________________
587 AliMUONMerger* AliMUON::Merger()
589 // Return pointer to merger
592 /* PH Commented out waiting for correct implementation
593 //________________________________________________________________________
594 void AliMUON::RemapTrackHitIDs(Int_t* map)
596 // Remaps the track numbers in the hits arrays, so that they correspond
597 // to the entry indices in the Kine tree.
598 // The correspondance is not direct. To get the real index into the Kine tree
599 // compute the particle index as follows:
601 // num_primaries = AliStack::GetNprimary();
602 // num_tracks = AliStack::GetNtracks();
603 // track = AliMUONHit::Track()
605 // if (track < num_primaries)
606 // particleindex = track + num_tracks - num_primaries;
608 // particleindex = track - num_primaries;
610 // Remap the track numbers based on the specified map.
611 AliMUONData* data = GetMUONData();
612 TClonesArray* hits = data->Hits();
613 for (Int_t i = 0; i < hits->GetEntriesFast(); i++)
615 AliMUONHit* hit = static_cast<AliMUONHit*>( hits->At(i) );
616 hit->SetTrack( map[hit->Track()] );