]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - MUON/AliMUON.cxx
Reversing previous commit (Gines)
[u/mrichter/AliRoot.git] / MUON / AliMUON.cxx
... / ...
CommitLineData
1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
18
19///////////////////////////////////////////////
20// Manager and hits classes for set:MUON //
21////////////////////////////////////////////////
22
23#include "Riostream.h"
24
25#include <AliPDG.h>
26#include <TBRIK.h>
27#include <TCanvas.h>
28#include <TDirectory.h>
29#include <TFile.h>
30#include <TGeometry.h>
31#include <TMinuit.h>
32#include <TNode.h>
33#include <TNtuple.h>
34#include <TObjArray.h>
35#include <TObject.h>
36#include <TObjectTable.h>
37#include <TPad.h>
38#include <TParticle.h>
39#include <TROOT.h>
40#include <TRandom.h>
41#include <TRotMatrix.h>
42#include <TTUBE.h>
43#include <TTUBE.h>
44#include <TTree.h>
45#include <TVector.h>
46#include <TVirtualMC.h>
47
48//#include "AliHeader.h"
49#include "AliLoader.h"
50#include "AliRunDigitizer.h"
51#include "AliMC.h"
52#include "AliRun.h"
53#include "AliMUON.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"
67
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
81
82ClassImp(AliMUON)
83
84//__________________________________________________________________
85AliMUON::AliMUON()
86 : AliDetector(),
87 fNCh(0),
88 fNTrackingCh(0),
89 fMUONData(0),
90 fSplitLevel(0),
91 fChambers(0),
92 fTriggerCircuits(0),
93 fGeometryBuilder(0),
94 fAccCut(kFALSE),
95 fAccMin(0.),
96 fAccMax(0.),
97 fMaxStepGas(0.),
98 fMaxStepAlu(0.),
99 fMaxDestepGas(0.),
100 fMaxDestepAlu(0.),
101 fMaxIterPad(0),
102 fCurIterPad(0),
103 fMerger(0)
104{
105// Default Constructor
106//
107 fIshunt = 0;
108}
109
110//__________________________________________________________________
111AliMUON::AliMUON(const char *name, const char *title)
112 : AliDetector(name,title),
113 fNCh(AliMUONConstants::NCh()),
114 fNTrackingCh(AliMUONConstants::NTrackingCh()),
115 fMUONData(0),
116 fSplitLevel(0),
117 fChambers(0),
118 fTriggerCircuits(0),
119 fGeometryBuilder(0),
120 fAccCut(kFALSE),
121 fAccMin(0.),
122 fAccMax(0.),
123 fMaxStepGas(0.1),
124 fMaxStepAlu(0.1),
125 fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200
126 fMaxDestepAlu(-1), // in the calculation of the tracking parameters
127 fMaxIterPad(0),
128 fCurIterPad(0),
129 fMerger(0)
130{
131
132 fIshunt = 0;
133
134 SetMarkerColor(kRed);//
135//
136// Creating List of Chambers
137 Int_t ch;
138 fChambers = new TObjArray(AliMUONConstants::NCh());
139
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++) {
144 //
145 //
146 // Default Parameters for Muon Tracking Stations
147 ch = 2 * st + stCH;
148 if (ch < AliMUONConstants::NTrackingCh()) {
149 fChambers->AddAt(new AliMUONChamber(ch),ch);
150 } else {
151 fChambers->AddAt(new AliMUONChamberTrigger(ch),ch);
152 }
153 AliMUONChamber* chamber = (AliMUONChamber*) fChambers->At(ch);
154 //chamber->SetGid(0);
155 // Default values for Z of chambers
156 chamber->SetZ(AliMUONConstants::DefaultChamberZ(ch));
157 //
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);
162 //
163 } // Chamber stCH (0, 1) in
164 } // Station st (0...)
165
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);
170 }
171
172 // Geometry builder
173 fGeometryBuilder = new AliMUONGeometryBuilder(this);
174}
175
176//____________________________________________________________________
177AliMUON::AliMUON(const AliMUON& rMUON)
178 : AliDetector(rMUON)
179{
180// Protected copy constructor
181
182 Fatal("AliMUONMergerModule", "Not implemented.");
183}
184
185//____________________________________________________________________
186AliMUON::~AliMUON()
187{
188// Destructor
189 if(fDebug) printf("%s: Calling AliMUON destructor !!!\n",ClassName());
190 fIshunt = 0;
191 if (fMerger) delete fMerger;
192
193 if (fChambers){
194 fChambers->Delete();
195 delete fChambers;
196 }
197 if (fTriggerCircuits){
198 fTriggerCircuits->Delete();
199 delete fTriggerCircuits;
200 }
201 delete fMUONData;
202 delete fGeometryBuilder;
203}
204
205//________________________________________________________________________
206AliMUON& AliMUON::operator = (const AliMUON& rhs)
207{
208// Protected assignement operator
209
210 if (this == &rhs) return *this;
211
212 Fatal("operator=", "Not implemented.");
213
214 return *this;
215}
216
217//_____________________________________________________________________________
218void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
219{
220// Adds the geometry builder to the list
221// ---
222
223 fGeometryBuilder->AddBuilder(geomBuilder);
224}
225
226//____________________________________________________________________
227void AliMUON::BuildGeometry()
228{
229// Geometry for event display
230
231 for (Int_t i=0; i<7; i++) {
232 for (Int_t j=0; j<2; j++) {
233 Int_t id=2*i+j+1;
234 this->Chamber(id-1).SegmentationModel(1)->Draw("eventdisplay");
235 }
236 }
237}
238
239//__________________________________________________________________
240void AliMUON::SetTreeAddress()
241{
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
251 }
252 }
253 fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector
254}
255
256//____________________________________________________________________
257void AliMUON::SetPadSize(Int_t id, Int_t isec, Float_t p1, Float_t p2)
258{
259// Set the pad size for chamber id and cathode isec
260 Int_t i=2*(id-1);
261 ((AliMUONChamber*) fChambers->At(i)) ->SetPadSize(isec,p1,p2);
262 ((AliMUONChamber*) fChambers->At(i+1))->SetPadSize(isec,p1,p2);
263}
264
265//___________________________________________
266void AliMUON::SetChambersZ(const Float_t *Z)
267{
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]);
272 return;
273}
274//_________________________________________________________________
275void AliMUON::SetChambersZToDefault()
276{
277 // Set Z values for all chambers (tracking and trigger)
278 // to default values
279 SetChambersZ(AliMUONConstants::DefaultChamberZ());
280 return;
281}
282//_________________________________________________________________
283void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
284{
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);
290}
291//__________________________________________________________________
292void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
293{
294// Set sigma of charge spread for chamber id
295 Int_t i=2*(id-1);
296 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
297 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
298}
299//___________________________________________________________________
300void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
301{
302// Set integration limits for charge spread
303 Int_t i=2*(id-1);
304 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
305 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
306}
307
308//__________________________________________________________________
309void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
310{
311// Set maximum number for ADCcounts (saturation)
312 Int_t i=2*(id-1);
313 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
314 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
315}
316
317//__________________________________________________________________
318void AliMUON::SetMaxStepGas(Float_t p1)
319{
320// Set stepsize in gas
321 fMaxStepGas=p1;
322}
323//__________________________________________________________________
324void AliMUON::SetMaxStepAlu(Float_t p1)
325{
326// Set step size in Alu
327 fMaxStepAlu=p1;
328}
329//__________________________________________________________________
330void AliMUON::SetMaxDestepGas(Float_t p1)
331{
332// Set maximum step size in Gas
333 fMaxDestepGas=p1;
334}
335//__________________________________________________________________
336void AliMUON::SetMaxDestepAlu(Float_t p1)
337{
338// Set maximum step size in Alu
339 fMaxDestepAlu=p1;
340}
341
342//___________________________________________________________________
343void AliMUON::SetAcceptance(Bool_t acc, Float_t angmin, Float_t angmax)
344{
345// Set acceptance cuts
346 fAccCut=acc;
347 fAccMin=angmin*TMath::Pi()/180;
348 fAccMax=angmax*TMath::Pi()/180;
349 Int_t ch;
350 if (acc) {
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++) {
354 ch = 2 * st + 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)));
358 } // chamber loop
359 } // station loop
360 }
361}
362
363//____________________________________________________________________
364Float_t AliMUON::GetMaxStepGas() const
365{
366// Return stepsize in gas
367
368 return fMaxStepGas;
369}
370
371//____________________________________________________________________
372Float_t AliMUON::GetMaxStepAlu() const
373{
374// Return step size in Alu
375
376 return fMaxStepAlu;
377}
378
379//____________________________________________________________________
380Float_t AliMUON::GetMaxDestepGas() const
381{
382// Return maximum step size in Gas
383
384 return fMaxDestepGas;
385}
386
387//____________________________________________________________________
388Float_t AliMUON::GetMaxDestepAlu() const
389{
390// Return maximum step size in Gas
391
392 return fMaxDestepAlu;
393}
394
395//____________________________________________________________________
396 void AliMUON::SetAlign(Bool_t align)
397 {
398 // Sets option for alignement to geometry builder
399
400 fGeometryBuilder->SetAlign(align);
401}
402
403//____________________________________________________________________
404void AliMUON::SetSegmentationModel(Int_t id, Int_t isec, AliSegmentation *segmentation)
405{
406// Set the segmentation for chamber id cathode isec
407 ((AliMUONChamber*) fChambers->At(id))->SetSegmentationModel(isec, segmentation);
408
409}
410//____________________________________________________________________
411void AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
412{
413// Set the response for chamber id
414 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
415}
416//____________________________________________________________________
417void AliMUON::SetNsec(Int_t id, Int_t nsec)
418{
419// Set number of segmented cathods for chamber id
420 ((AliMUONChamber*) fChambers->At(id))->SetNsec(nsec);
421}
422//____________________________________________________________________
423AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
424{
425 return new AliMUONDigitizerv2(manager);
426}
427//_____________________________________________________________________
428void AliMUON::SDigits2Digits()
429{
430
431// write TreeD here
432
433 if (!fMerger) {
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;
437 }
438 fMerger = new AliMUONMerger();
439 }
440 fMerger->Init();
441 fMerger->Digitise();
442 char hname[30];
443 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
444 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
445 fLoader->TreeD()->Reset();
446}
447
448//_____________________________________________________________________
449void AliMUON::Hits2SDigits()
450{
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);
459 dMUON->Exec("");
460 }
461 fLoader->UnloadHits();
462}
463//_____________________________________________________________________
464void AliMUON::Digits2Raw()
465{
466 // convert digits of the current event to raw data
467 AliMUONRawData* rawData;
468
469 rawData = new AliMUONRawData(fLoader);
470 if (!rawData->WriteRawData()) Info("MUON","pb writting raw data");
471 delete rawData;
472 return;
473}
474//_______________________________________________________________________
475AliLoader* AliMUON::MakeLoader(const char* topfoldername)
476{
477//builds standard getter (AliLoader type)
478//if detector wants to use castomized getter, it must overload this method
479
480 if (GetDebug())
481 Info("MakeLoader",
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);
487 return fLoader;
488}
489//_______________________________________________________________________
490AliMUONPadHit* AliMUON::FirstPad(AliMUONHit* hit, TClonesArray *clusters)
491{
492// to be removed
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);
501 } else {
502 return 0;
503 }
504}
505//_______________________________________________________________________
506AliMUONPadHit* AliMUON::NextPad(TClonesArray *clusters)
507{
508 // To be removed
509// Get next pad (in iterator)
510//
511 fCurIterPad++;
512 if (fCurIterPad <= fMaxIterPad) {
513 return (AliMUONPadHit*) clusters->UncheckedAt(fCurIterPad-1);
514 } else {
515 return 0;
516 }
517}
518//_______________________________________________________________________
519
520AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
521{
522//
523// Return rawcluster (icluster) for chamber ichamber and cathode icathod
524// Obsolete ??
525 TClonesArray *muonRawCluster = GetMUONData()->RawClusters(ichamber);
526 ResetRawClusters();
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();
532
533 AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
534 //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
535
536 return mRaw;
537}
538//________________________________________________________________________
539void AliMUON::SetMerger(AliMUONMerger* merger)
540{
541// Set pointer to merger
542 fMerger = merger;
543}
544//________________________________________________________________________
545AliMUONMerger* AliMUON::Merger()
546{
547// Return pointer to merger
548 return fMerger;
549}
550/* PH Commented out waiting for correct implementation
551//________________________________________________________________________
552void AliMUON::RemapTrackHitIDs(Int_t* map)
553{
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:
558//
559// num_primaries = AliStack::GetNprimary();
560// num_tracks = AliStack::GetNtracks();
561// track = AliMUONHit::Track()
562//
563// if (track < num_primaries)
564// particleindex = track + num_tracks - num_primaries;
565// else
566// particleindex = track - num_primaries;
567
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++)
572 {
573 AliMUONHit* hit = static_cast<AliMUONHit*>( hits->At(i) );
574 hit->SetTrack( map[hit->Track()] );
575 };
576};
577*/