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"
70 #include "AliMUONFactory.h"
73 // Defaults parameters for Z positions of chambers
74 // taken from values for "stations" in AliMUON::AliMUON
75 // const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
76 // and from array "dstation" in AliMUONv1::CreateGeometry
77 // Float_t dstation[5]={20., 20., 20, 20., 20.};
78 // for tracking chambers,
79 // according to (Z1 = zch - dstation) and (Z2 = zch + dstation)
80 // for the first and second chambers in the station, respectively,
81 // and from "DTPLANES" in AliMUONv1::CreateGeometry
82 // const Float_t DTPLANES = 15.;
83 // for trigger chambers,
84 // according to (Z1 = zch) and (Z2 = zch + DTPLANES)
85 // for the first and second chambers in the station, respectively
89 //__________________________________________________________________
99 fSegmentationType(1),// set to 1 default wise old seg
113 // Default Constructor
118 //__________________________________________________________________
119 AliMUON::AliMUON(const char *name, const char *title)
120 : AliDetector(name,title),
121 fNCh(AliMUONConstants::NCh()),
122 fNTrackingCh(AliMUONConstants::NTrackingCh()),
128 fSegmentationType(1),// set to 1 default wise old seg
135 fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200
136 fMaxDestepAlu(-1), // in the calculation of the tracking parameters
145 SetMarkerColor(kRed);//
148 fGeometryBuilder = new AliMUONGeometryBuilder(this);
150 // Common geometry definitions
152 ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
154 // Define the global transformation:
155 // Transformation from the old ALICE coordinate system to a new one:
157 TGeoRotation* rotGlobal
158 = new TGeoRotation("rotGlobal", 90., 180., 90., 90., 180., 0.);
160 ->SetGlobalTransformation (TGeoCombiTrans(0., 0., 0., rotGlobal));
162 // Detection elements indexing
163 fDEIndexing = new AliMUONGeometryDEIndexing();
166 // Creating List of Chambers
168 fChambers = new TObjArray(AliMUONConstants::NCh());
170 // Loop over stations
171 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
172 // Loop over 2 chambers in the station
173 for (Int_t stCH = 0; stCH < 2; stCH++) {
176 // Default Parameters for Muon Tracking Stations
178 if (ch < AliMUONConstants::NTrackingCh()) {
179 fChambers->AddAt(new AliMUONChamber(ch),ch);
181 fChambers->AddAt(new AliMUONChamberTrigger(ch),ch);
183 AliMUONChamber* chamber = (AliMUONChamber*) fChambers->At(ch);
184 //chamber->SetGid(0);
185 // Default values for Z of chambers
186 chamber->SetZ(AliMUONConstants::DefaultChamberZ(ch));
188 chamber->InitGeo(AliMUONConstants::DefaultChamberZ(ch));
189 // Set chamber inner and outer radius to default
190 chamber->SetRInner(AliMUONConstants::Dmin(st)/2.);
191 chamber->SetROuter(AliMUONConstants::Dmax(st)/2.);
193 } // Chamber stCH (0, 1) in
194 } // Station st (0...)
196 // cp new design of AliMUONTriggerDecision
197 fTriggerCircuits = new TObjArray(AliMUONConstants::NTriggerCircuit());
198 for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
199 fTriggerCircuits->AddAt(new AliMUONTriggerCircuit(),circ);
203 //____________________________________________________________________
204 AliMUON::AliMUON(const AliMUON& rMUON)
207 // Protected copy constructor
209 AliFatal("Not implemented.");
212 //____________________________________________________________________
216 AliDebug(1,"Calling AliMUON destructor");
218 if (fMerger) delete fMerger;
224 if (fTriggerCircuits){
225 fTriggerCircuits->Delete();
226 delete fTriggerCircuits;
229 delete fGeometryBuilder;
234 //________________________________________________________________________
235 AliMUON& AliMUON::operator = (const AliMUON& rhs)
237 // Protected assignement operator
239 if (this == &rhs) return *this;
241 AliFatal("Not implemented.");
246 //_____________________________________________________________________________
247 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
249 // Adds the geometry builder to the list
252 fGeometryBuilder->AddBuilder(geomBuilder);
255 //____________________________________________________________________
256 void AliMUON::BuildGeometry()
258 // Geometry for event display
260 if (!fSegmentationType) {
261 AliFatal("No Segmentation Type defined.");
265 if (fSegmentationType == 1) {
266 for (Int_t i=0; i<7; i++) {
267 for (Int_t j=0; j<2; j++) {
269 this->Chamber(id-1).SegmentationModel(1)->Draw("eventdisplay");
273 // for (Int_t i=0; i<14; i++) {
274 // for (Int_t j=0; j<100; j++) {
275 // Int_t id= (i+1)*100 + j;
276 // this->Chamber(i).SegmentationModel2(1)->Draw(id,"eventdisplay");// to be check !
282 //__________________________________________________________________
283 void AliMUON::SetTreeAddress()
285 GetMUONData()->SetLoader(fLoader);
286 // GetMUONData()->MakeBranch("D,S,RC");
287 // GetMUONData()->SetTreeAddress("H,D,S,RC");
288 GetMUONData()->SetTreeAddress("H");
289 if (fHits != GetMUONData()->Hits()) {
290 if ( gAlice->GetMCApp() )
291 if ( gAlice->GetMCApp()->GetHitLists() ) {
292 fHits = GetMUONData()->Hits();
293 gAlice->GetMCApp()->AddHitList(fHits); // For purifyKine, only necessary when Hit list is created in AliMUONData
296 fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector
299 //____________________________________________________________________
300 void AliMUON::SetPadSize(Int_t id, Int_t isec, Float_t p1, Float_t p2)
302 // Set the pad size for chamber id and cathode isec
304 ((AliMUONChamber*) fChambers->At(i)) ->SetPadSize(isec,p1,p2);
305 ((AliMUONChamber*) fChambers->At(i+1))->SetPadSize(isec,p1,p2);
308 //___________________________________________
309 void AliMUON::SetChambersZ(const Float_t *Z)
311 // Set Z values for all chambers (tracking and trigger)
312 // from the array pointed to by "Z"
313 for (Int_t ch = 0; ch < AliMUONConstants::NCh(); ch++)
314 ((AliMUONChamber*) fChambers->At(ch))->SetZ(Z[ch]);
317 //_________________________________________________________________
318 void AliMUON::SetChambersZToDefault()
320 // Set Z values for all chambers (tracking and trigger)
322 SetChambersZ(AliMUONConstants::DefaultChamberZ());
325 //_________________________________________________________________
326 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
328 // Set the inverse charge slope for chamber id
329 Int_t i=2*(id-1); //PH ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
330 //PH ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
331 ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
332 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
334 //__________________________________________________________________
335 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
337 // Set sigma of charge spread for chamber id
339 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
340 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
342 //___________________________________________________________________
343 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
345 // Set integration limits for charge spread
347 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
348 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
351 //__________________________________________________________________
352 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
354 // Set maximum number for ADCcounts (saturation)
356 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
357 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
360 //__________________________________________________________________
361 void AliMUON::SetMaxStepGas(Float_t p1)
363 // Set stepsize in gas
366 //__________________________________________________________________
367 void AliMUON::SetMaxStepAlu(Float_t p1)
369 // Set step size in Alu
372 //__________________________________________________________________
373 void AliMUON::SetMaxDestepGas(Float_t p1)
375 // Set maximum step size in Gas
378 //__________________________________________________________________
379 void AliMUON::SetMaxDestepAlu(Float_t p1)
381 // Set maximum step size in Alu
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);
431 //____________________________________________________________________
432 void AliMUON::SetSegmentationModel(Int_t id, Int_t isec, AliMUONGeometrySegmentation* segmentation)
434 // Set the segmentation for chamber id cathode isec
435 ((AliMUONChamber*) fChambers->At(id))->SetSegmentationModel(isec, segmentation);
438 //____________________________________________________________________
439 void AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
441 // Set the response for chamber id
442 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
444 //____________________________________________________________________
445 void AliMUON::SetNsec(Int_t id, Int_t nsec)
447 // Set number of segmented cathods for chamber id
448 ((AliMUONChamber*) fChambers->At(id))->SetNsec(nsec);
450 //____________________________________________________________________
451 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
453 return new AliMUONDigitizerv2(manager);
455 //_____________________________________________________________________
456 void AliMUON::SDigits2Digits()
462 AliDebug(1,"Create default AliMUONMerger ");
463 AliDebug(1," no merging, just digitization of 1 event will be done");
464 fMerger = new AliMUONMerger();
469 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
470 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
471 fLoader->TreeD()->Reset();
474 //_____________________________________________________________________
475 void AliMUON::Hits2SDigits()
477 // Adaption of AliMUONSDigitizerv1 to be excuted by the AliSimulation framework
478 AliRunLoader* runLoader = fLoader->GetRunLoader();
479 AliRunDigitizer * manager = new AliRunDigitizer(1,1);
480 manager->SetInputStream(0,runLoader->GetFileName(),AliConfig::GetDefaultEventFolderName());
481 AliMUONDigitizer * dMUON = new AliMUONSDigitizerv1(manager);
482 fLoader->LoadHits("READ");
483 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
484 runLoader->GetEvent(iEvent);
487 fLoader->UnloadHits();
489 //_____________________________________________________________________
490 void AliMUON::Digits2Raw()
492 // convert digits of the current event to raw data
493 AliMUONRawData* rawData;
495 rawData = new AliMUONRawData(fLoader);
496 if (!rawData->WriteRawData()) AliInfo("pb writting raw data");
500 //_______________________________________________________________________
501 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
503 //builds standard getter (AliLoader type)
504 //if detector wants to use castomized getter, it must overload this method
507 AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
508 GetName(),topfoldername));
509 fLoader = new AliLoader(GetName(),topfoldername);
510 fMUONData = new AliMUONData(fLoader,GetName(),GetName());
511 fMUONData->SetSplitLevel(fSplitLevel);
514 //_______________________________________________________________________
515 AliMUONPadHit* AliMUON::FirstPad(AliMUONHit* hit, TClonesArray *clusters)
518 // Initialise the pad iterator
519 // Return the address of the first padhit for hit
520 TClonesArray *theClusters = clusters;
521 Int_t nclust = theClusters->GetEntriesFast();
522 if (nclust && hit->PHlast() > 0) {
523 fMaxIterPad=hit->PHlast();
524 fCurIterPad=hit->PHfirst();
525 return (AliMUONPadHit*) clusters->UncheckedAt(fCurIterPad-1);
530 //_______________________________________________________________________
531 AliMUONPadHit* AliMUON::NextPad(TClonesArray *clusters)
534 // Get next pad (in iterator)
537 if (fCurIterPad <= fMaxIterPad) {
538 return (AliMUONPadHit*) clusters->UncheckedAt(fCurIterPad-1);
543 //_______________________________________________________________________
545 AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
548 // Return rawcluster (icluster) for chamber ichamber and cathode icathod
550 TClonesArray *muonRawCluster = GetMUONData()->RawClusters(ichamber);
552 TTree *treeR = fLoader->TreeR();
553 Int_t nent=(Int_t)treeR->GetEntries();
554 treeR->GetEvent(nent-2+icathod-1);
555 //treeR->GetEvent(icathod);
556 //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
558 AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
559 //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
563 //________________________________________________________________________
564 void AliMUON::SetMerger(AliMUONMerger* merger)
566 // Set pointer to merger
569 //________________________________________________________________________
570 AliMUONMerger* AliMUON::Merger()
572 // Return pointer to merger
575 /* PH Commented out waiting for correct implementation
576 //________________________________________________________________________
577 void AliMUON::RemapTrackHitIDs(Int_t* map)
579 // Remaps the track numbers in the hits arrays, so that they correspond
580 // to the entry indices in the Kine tree.
581 // The correspondance is not direct. To get the real index into the Kine tree
582 // compute the particle index as follows:
584 // num_primaries = AliStack::GetNprimary();
585 // num_tracks = AliStack::GetNtracks();
586 // track = AliMUONHit::Track()
588 // if (track < num_primaries)
589 // particleindex = track + num_tracks - num_primaries;
591 // particleindex = track - num_primaries;
593 // Remap the track numbers based on the specified map.
594 AliMUONData* data = GetMUONData();
595 TClonesArray* hits = data->Hits();
596 for (Int_t i = 0; i < hits->GetEntriesFast(); i++)
598 AliMUONHit* hit = static_cast<AliMUONHit*>( hits->At(i) );
599 hit->SetTrack( map[hit->Track()] );