]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUON.cxx
Removing obsolete classes AliMUONMerger and AliMUONPadHit (Gines)
[u/mrichter/AliRoot.git] / MUON / AliMUON.cxx
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 "AliMUONRawCluster.h"
58 #include "AliMUONTransientDigit.h"
59 #include "AliMUONTriggerCircuit.h"
60 #include "AliMUONGeometryBuilder.h"
61 #include "AliMUONCommonGeometryBuilder.h"
62 #include "AliMUONVGeometryBuilder.h"    
63 #include "AliMUONGeometryDEIndexing.h"  
64 #include "AliMUONGeometrySegmentation.h"
65 #include "AliMUONDigitizerv2.h"
66 #include "AliMUONSDigitizerv1.h"
67 #include "AliMUONRawData.h"
68 #include "AliMUONFactoryV2.h"
69 #include "AliLog.h"
70
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
84
85 ClassImp(AliMUON)
86
87 //__________________________________________________________________
88 AliMUON::AliMUON()
89   : AliDetector(),
90     fNCh(0),
91     fNTrackingCh(0),
92     fMUONData(0),
93     fSplitLevel(0),
94     fChambers(0),
95     fTriggerCircuits(0),
96     fGeometryBuilder(0),
97     fSegmentationType(2),// set to 2 default wise new seg
98     fDEIndexing(0),
99     fAccCut(kFALSE),
100     fAccMin(0.),
101     fAccMax(0.),   
102     fMaxStepGas(0.),
103     fMaxStepAlu(0.),
104     fMaxDestepGas(0.),
105     fMaxDestepAlu(0.),
106     fMaxIterPad(0),
107     fCurIterPad(0),
108     fFactory(0)
109 {
110 // Default Constructor
111 //
112     fIshunt          = 0;
113 }
114
115 //__________________________________________________________________
116 AliMUON::AliMUON(const char *name, const char *title)
117   : AliDetector(name,title),
118     fNCh(AliMUONConstants::NCh()),
119     fNTrackingCh(AliMUONConstants::NTrackingCh()),
120     fMUONData(0),
121     fSplitLevel(0),
122     fChambers(0),
123     fTriggerCircuits(0),
124     fGeometryBuilder(0),
125     fSegmentationType(2),// set to 2 default wise new seg
126     fDEIndexing(0),
127     fAccCut(kFALSE),
128     fAccMin(0.),
129     fAccMax(0.),   
130     fMaxStepGas(0.1),
131     fMaxStepAlu(0.1),
132     fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200 
133     fMaxDestepAlu(-1), // in the calculation of the tracking parameters
134     fMaxIterPad(0),
135     fCurIterPad(0),
136     fFactory(0)
137 {
138
139   fIshunt =  0;
140
141   SetMarkerColor(kRed);//
142     
143   // Geometry builder
144   fGeometryBuilder = new AliMUONGeometryBuilder(this);
145   
146   // Common geometry definitions
147   fGeometryBuilder
148     ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
149
150   // Define the global transformation:
151   // Transformation from the old ALICE coordinate system to a new one:
152   // x->-x, z->-z 
153   TGeoRotation* rotGlobal 
154     = new TGeoRotation("rotGlobal", 90., 180., 90., 90., 180., 0.);
155   fGeometryBuilder
156     ->SetGlobalTransformation (TGeoCombiTrans(0., 0., 0., rotGlobal));
157
158   // Detection elements indexing
159   fDEIndexing = new AliMUONGeometryDEIndexing();
160
161 //
162 // Creating List of Chambers
163     Int_t ch;
164     fChambers = new TObjArray(AliMUONConstants::NCh());
165
166     // Loop over stations
167     for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
168       // Loop over 2 chambers in the station
169       for (Int_t stCH = 0; stCH < 2; stCH++) {
170         //
171         //    
172         //    Default Parameters for Muon Tracking Stations
173         ch = 2 * st + stCH;
174         if (ch < AliMUONConstants::NTrackingCh()) {
175           fChambers->AddAt(new AliMUONChamber(ch),ch);
176         } else {
177           fChambers->AddAt(new AliMUONChamberTrigger(ch),ch);
178         }
179         AliMUONChamber* chamber = (AliMUONChamber*) fChambers->At(ch);
180         //chamber->SetGid(0);
181         // Default values for Z of chambers
182         chamber->SetZ(AliMUONConstants::DefaultChamberZ(ch));
183         //
184         chamber->InitGeo(AliMUONConstants::DefaultChamberZ(ch));
185         //          Set chamber inner and outer radius to default
186         chamber->SetRInner(AliMUONConstants::Dmin(st)/2.);
187         chamber->SetROuter(AliMUONConstants::Dmax(st)/2.);
188         //
189       } // Chamber stCH (0, 1) in 
190     }     // Station st (0...)
191     
192     // cp new design of AliMUONTriggerDecision
193     fTriggerCircuits = new TObjArray(AliMUONConstants::NTriggerCircuit());
194     for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
195       fTriggerCircuits->AddAt(new AliMUONTriggerCircuit(),circ);          
196     }
197 }
198
199 //____________________________________________________________________
200 AliMUON::AliMUON(const AliMUON& rMUON)
201  : AliDetector(rMUON)
202 {
203 // Protected copy constructor
204
205   AliFatal("Not implemented.");
206 }
207
208 //____________________________________________________________________
209 AliMUON::~AliMUON()
210 {
211 // Destructor
212   AliDebug(1,"Calling AliMUON destructor");
213   fIshunt  = 0;
214
215   if (fChambers){
216     fChambers->Delete();
217     delete fChambers;
218   }
219   if (fTriggerCircuits){
220     fTriggerCircuits->Delete();
221     delete fTriggerCircuits;
222   }
223   delete fMUONData;
224   delete fGeometryBuilder;
225   delete fDEIndexing;
226   delete fFactory; 
227 }
228
229 //________________________________________________________________________
230 AliMUON& AliMUON::operator = (const AliMUON& rhs)
231 {
232 // Protected assignement operator
233
234   if (this == &rhs) return *this;
235
236   AliFatal("Not implemented.");
237     
238   return *this;  
239 }
240
241 //_____________________________________________________________________________
242 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
243 {
244 // Adds the geometry builder to the list
245 // ---
246
247   fGeometryBuilder->AddBuilder(geomBuilder);
248 }
249
250 //____________________________________________________________________
251 void AliMUON::BuildGeometry()
252 {
253 // Geometry for event display
254
255   if (!fSegmentationType) {
256     AliFatal("No Segmentation Type defined.");
257     return;
258   }
259
260
261 //     for (Int_t i = 0; i < AliMUONConstants::NCh(); i++)     
262 //       this->Chamber(i).SegmentationModel2(1)->Draw("eventdisplay");// to be check !
263      
264   
265 }
266
267 //__________________________________________________________________
268 void  AliMUON::SetTreeAddress()
269 {
270   GetMUONData()->SetLoader(fLoader); 
271   //  GetMUONData()->MakeBranch("D,S,RC");
272   //  GetMUONData()->SetTreeAddress("H,D,S,RC");
273   GetMUONData()->SetTreeAddress("H");
274   if (fHits !=  GetMUONData()->Hits())  {
275     if ( gAlice->GetMCApp() )
276       if ( gAlice->GetMCApp()->GetHitLists() ) {
277         fHits = GetMUONData()->Hits();
278         gAlice->GetMCApp()->AddHitList(fHits); // For purifyKine, only necessary when Hit list is created in AliMUONData
279       }  
280   }
281   fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector    
282 }
283
284 //___________________________________________
285 void AliMUON::SetChambersZ(const Float_t *Z)
286 {
287   // Set Z values for all chambers (tracking and trigger)
288   // from the array pointed to by "Z"
289     for (Int_t ch = 0; ch < AliMUONConstants::NCh(); ch++)
290         ((AliMUONChamber*) fChambers->At(ch))->SetZ(Z[ch]);
291     return;
292 }
293 //_________________________________________________________________
294 void AliMUON::SetChambersZToDefault()
295 {
296   // Set Z values for all chambers (tracking and trigger)
297   // to default values
298   SetChambersZ(AliMUONConstants::DefaultChamberZ());
299   return;
300 }
301 //_________________________________________________________________
302 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
303 {
304 // Set the inverse charge slope for chamber id
305     Int_t i=2*(id-1);    //PH    ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
306     //PH    ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
307     ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
308     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
309 }
310 //__________________________________________________________________
311 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
312 {
313 // Set sigma of charge spread for chamber id
314     Int_t i=2*(id-1);
315     ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
316     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
317 }
318 //___________________________________________________________________
319 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
320 {
321 // Set integration limits for charge spread
322     Int_t i=2*(id-1);
323     ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
324     ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
325 }
326
327 //__________________________________________________________________
328 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
329 {
330 // Set maximum number for ADCcounts (saturation)
331     Int_t i=2*(id-1);
332     ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
333     ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
334 }
335
336 //__________________________________________________________________
337 void AliMUON::SetMaxStepGas(Float_t p1)
338 {
339 // Set stepsize in gas
340   fMaxStepGas=p1;
341 }
342 //__________________________________________________________________
343 void AliMUON::SetMaxStepAlu(Float_t p1)
344 {
345 // Set step size in Alu
346     fMaxStepAlu=p1;
347 }
348 //__________________________________________________________________
349 void AliMUON::SetMaxDestepGas(Float_t p1)
350 {
351 // Set maximum step size in Gas
352     fMaxDestepGas=p1;
353 }
354 //__________________________________________________________________
355 void AliMUON::SetMaxDestepAlu(Float_t p1)
356 {
357 // Set maximum step size in Alu
358   fMaxDestepAlu=p1;
359 }
360
361 //____________________________________________________________________
362 Float_t  AliMUON::GetMaxStepGas() const
363 {
364 // Return stepsize in gas
365   
366   return fMaxStepGas;
367 }  
368
369 //____________________________________________________________________
370 Float_t  AliMUON::GetMaxStepAlu() const
371 {
372 // Return step size in Alu
373   
374   return fMaxStepAlu;
375 }
376   
377 //____________________________________________________________________
378 Float_t  AliMUON::GetMaxDestepGas() const
379 {
380 // Return maximum step size in Gas
381   
382   return fMaxDestepGas;
383 }
384   
385 //____________________________________________________________________
386 Float_t  AliMUON::GetMaxDestepAlu() const
387 {
388 // Return maximum step size in Gas
389   
390   return fMaxDestepAlu;
391 }
392
393 //____________________________________________________________________
394  void  AliMUON::SetAlign(Bool_t align)
395 {
396  // Sets option for alignement to geometry builder
397  
398    fGeometryBuilder->SetAlign(align);
399 }   
400     
401 //____________________________________________________________________
402 void   AliMUON::SetSegmentationModel(Int_t id, Int_t isec, AliMUONGeometrySegmentation*  segmentation)
403 {
404 // Set the segmentation for chamber id cathode isec
405     ((AliMUONChamber*) fChambers->At(id))->SetSegmentationModel(isec, segmentation);
406
407 }
408 //____________________________________________________________________
409 void   AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
410 {
411 // Set the response for chamber id
412     ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
413 }
414 //____________________________________________________________________
415 void   AliMUON::SetNsec(Int_t id, Int_t nsec)
416 {
417 // Set number of segmented cathods for chamber id
418     ((AliMUONChamber*) fChambers->At(id))->SetNsec(nsec);
419 }
420 //____________________________________________________________________
421 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
422 {
423   return new AliMUONDigitizerv2(manager);
424 }
425 //_____________________________________________________________________
426 void AliMUON::SDigits2Digits()
427 {
428
429 // write TreeD here 
430
431     char hname[30];
432     //    sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
433     fLoader->TreeD()->Write(hname,TObject::kOverwrite);
434     fLoader->TreeD()->Reset();
435 }
436
437 //_____________________________________________________________________
438 void AliMUON::Hits2SDigits()
439 {
440   // Adaption of AliMUONSDigitizerv1 to be excuted by the AliSimulation framework
441   AliRunLoader* runLoader = fLoader->GetRunLoader();
442   AliRunDigitizer   * manager = new AliRunDigitizer(1,1);
443   manager->SetInputStream(0,runLoader->GetFileName(),AliConfig::GetDefaultEventFolderName());
444   AliMUONDigitizer * dMUON   = new AliMUONSDigitizerv1(manager);
445   fLoader->LoadHits("READ");
446   for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
447     runLoader->GetEvent(iEvent);
448     dMUON->Exec("");
449   }
450   fLoader->UnloadHits();
451 }
452 //_____________________________________________________________________
453 void AliMUON::Digits2Raw()
454 {
455   // convert digits of the current event to raw data
456   AliMUONRawData* rawData;
457
458   rawData = new AliMUONRawData(fLoader);
459   if (!rawData->WriteRawData()) AliInfo("pb writting raw data");
460   delete rawData;
461   return;
462 }
463 //_______________________________________________________________________
464 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
465
466 //builds standard getter (AliLoader type)
467 //if detector wants to use castomized getter, it must overload this method
468
469  
470  AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
471          GetName(),topfoldername));
472  fLoader   = new AliLoader(GetName(),topfoldername);
473  fMUONData = new AliMUONData(fLoader,GetName(),GetName()); 
474  fMUONData->SetSplitLevel(fSplitLevel);
475  return fLoader;
476 }
477 //_______________________________________________________________________
478
479 AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
480 {
481 //
482 //  Return rawcluster (icluster) for chamber ichamber and cathode icathod
483 //  Obsolete ??
484     TClonesArray *muonRawCluster  = GetMUONData()->RawClusters(ichamber);
485     ResetRawClusters();
486     TTree *treeR = fLoader->TreeR();
487     Int_t nent=(Int_t)treeR->GetEntries();
488     treeR->GetEvent(nent-2+icathod-1);
489     //treeR->GetEvent(icathod);
490     //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
491
492     AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
493     //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
494     
495     return  mRaw;
496 }
497 //________________________________________________________________________
498