]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUON.cxx
Updated list of MUON libraries
[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 // Class AliMUON
20 // ------------------
21 // AliDetector class for MUON subsystem 
22 // providing simulation data management 
23
24 #include "Riostream.h"
25
26 #include <AliPDG.h>
27 #include <TBRIK.h>
28 #include <TCanvas.h>
29 #include <TDirectory.h>
30 #include <TFile.h>
31 #include <TGeometry.h>
32 #include <TMinuit.h>
33 #include <TNode.h> 
34 #include <TNtuple.h>
35 #include <TObjArray.h>
36 #include <TObject.h>
37 #include <TObjectTable.h>
38 #include <TPad.h>
39 #include <TParticle.h>
40 #include <TROOT.h>
41 #include <TRandom.h> 
42 #include <TRotMatrix.h>
43 #include <TTUBE.h>
44 #include <TTUBE.h>
45 #include <TTree.h> 
46 #include <TVector.h>
47 #include <TVirtualMC.h>
48
49 //#include "AliHeader.h"
50 #include "AliLoader.h"
51 #include "AliRunDigitizer.h"
52 #include "AliMC.h"
53 #include "AliRun.h"     
54 #include "AliMUON.h"
55 #include "AliMUONChamberTrigger.h"
56 #include "AliMUONConstants.h"
57 #include "AliMUONHit.h" 
58 #include "AliMUONGeometry.h"
59 #include "AliMUONGeometryTransformer.h"
60 #include "AliMUONGeometryBuilder.h"
61 #include "AliMUONCommonGeometryBuilder.h"
62 #include "AliMUONVGeometryBuilder.h"    
63 #include "AliMUONGeometrySegmentation.h"
64 #include "AliMUONRawWriter.h"
65 #include "AliMUONSegmentation.h"
66 #include "AliLog.h"
67
68 #include "AliMUONSDigitizerV2.h"
69 #include "AliMUONDigitizerV3.h"
70 #include "AliMUONDigitMaker.h"
71
72 #include "AliMUONSt1GeometryBuilderV2.h"
73 #include "AliMUONSt2GeometryBuilderV2.h"
74 #include "AliMUONSlatGeometryBuilder.h"
75 #include "AliMUONTriggerGeometryBuilder.h"
76
77 // Defaults parameters for Z positions of chambers
78 // taken from values for "stations" in AliMUON::AliMUON
79 //     const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
80 // and from array "dstation" in AliMUONv1::CreateGeometry
81 //          Float_t dstation[5]={20., 20., 20, 20., 20.};
82 //     for tracking chambers,
83 //          according to (Z1 = zch - dstation) and  (Z2 = zch + dstation)
84 //          for the first and second chambers in the station, respectively,
85 // and from "DTPLANES" in AliMUONv1::CreateGeometry
86 //           const Float_t DTPLANES = 15.;
87 //     for trigger chambers,
88 //          according to (Z1 = zch) and  (Z2 = zch + DTPLANES)
89 //          for the first and second chambers in the station, respectively
90
91 /// \cond CLASSIMP
92 ClassImp(AliMUON)  
93 /// \endcond
94
95 //__________________________________________________________________
96 AliMUON::AliMUON()
97   : AliDetector(),
98     fNCh(0),
99     fNTrackingCh(0),
100     fMUONData(0),
101     fSplitLevel(0),
102     fChambers(0),
103     fGeometryBuilder(0),
104     fSegmentation(0),
105     fAccCut(kFALSE),
106     fAccMin(0.),
107     fAccMax(0.),   
108     fMaxStepGas(0.),
109     fMaxStepAlu(0.),
110     fMaxDestepGas(0.),
111     fMaxDestepAlu(0.),
112     fMaxIterPad(0),
113     fCurIterPad(0),
114     fTriggerScalerEvent(kFALSE),
115     fTriggerResponseV1(kFALSE),
116     fTriggerCoinc44(0),
117     fTriggerEffCells(0),
118     fDigitizerWithNoise(kTRUE),
119     fRawWriter(0x0),
120     fDigitMaker(0x0)
121
122 {
123 /// Default Constructor
124     
125     AliDebug(1,Form("default (empty) ctor this=%p",this));
126     fIshunt          = 0;
127 }
128
129 //__________________________________________________________________
130 AliMUON::AliMUON(const char *name, const char* title)
131   : AliDetector(name, title),
132     fNCh(AliMUONConstants::NCh()),
133     fNTrackingCh(AliMUONConstants::NTrackingCh()),
134     fMUONData(0),
135     fSplitLevel(0),
136     fChambers(0),
137     fGeometryBuilder(0),
138     fSegmentation(0),
139     fAccCut(kFALSE),
140     fAccMin(0.),
141     fAccMax(0.),   
142     fMaxStepGas(0.1),
143     fMaxStepAlu(0.1),
144     fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200 
145     fMaxDestepAlu(-1), // in the calculation of the tracking parameters
146     fMaxIterPad(0),
147     fCurIterPad(0),
148     fTriggerScalerEvent(kFALSE),
149     fTriggerResponseV1(kFALSE),
150     fTriggerCoinc44(0),
151     fTriggerEffCells(0),
152     fDigitizerWithNoise(kTRUE),
153     fRawWriter(0x0),
154     fDigitMaker(new AliMUONDigitMaker(kFALSE)) 
155 {
156 /// Standard constructor  
157   
158   AliDebug(1,Form("ctor this=%p",this));
159   fIshunt =  0;
160
161   //PH SetMarkerColor(kRed);//
162     
163   // Geometry builder
164   fGeometryBuilder = new AliMUONGeometryBuilder(this);
165   
166   // Common geometry definitions
167   fGeometryBuilder
168     ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
169
170   // By default, add also all the needed geometry builders.
171   // If you want to change this from outside, please use ResetGeometryBuilder
172   // method, followed by AddGeometryBuilder ones.
173
174   AddGeometryBuilder(new AliMUONSt1GeometryBuilderV2(this));
175   AddGeometryBuilder(new AliMUONSt2GeometryBuilderV2(this));
176   AddGeometryBuilder(new AliMUONSlatGeometryBuilder(this));
177   AddGeometryBuilder(new AliMUONTriggerGeometryBuilder(this));
178   
179   //
180   // Creating List of Chambers
181     Int_t ch;
182     fChambers = new TObjArray(AliMUONConstants::NCh());
183
184     // Loop over stations
185     for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
186       // Loop over 2 chambers in the station
187       for (Int_t stCH = 0; stCH < 2; stCH++) {
188         //
189         //    
190         //    Default Parameters for Muon Tracking Stations
191         ch = 2 * st + stCH;
192         if (ch < AliMUONConstants::NTrackingCh()) {
193           fChambers->AddAt(new AliMUONChamber(ch),ch);
194         } else {
195           fChambers->AddAt(new AliMUONChamberTrigger(ch, GetGeometryTransformer()),ch);
196         }
197       } // Chamber stCH (0, 1) in 
198     }     // Station st (0...)
199
200 }
201
202 //____________________________________________________________________
203 AliMUON::~AliMUON()
204 {
205 /// Destructor
206
207   AliDebug(1,Form("dtor this=%p",this));
208   fIshunt  = 0;
209
210   if (fChambers){
211     fChambers->Delete();
212     delete fChambers;
213   }
214   
215   delete fMUONData;
216   delete fGeometryBuilder;
217   delete fSegmentation;
218   delete fRawWriter;
219   delete fDigitMaker;
220 }
221
222 //_____________________________________________________________________________
223 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
224 {
225 /// Add the geometry builder to the list
226
227   fGeometryBuilder->AddBuilder(geomBuilder);
228 }
229
230 //____________________________________________________________________
231 void AliMUON::BuildGeometry()
232 {
233 /// Geometry for event display
234
235
236 //     for (Int_t i = 0; i < AliMUONConstants::NCh(); i++)     
237 //       this->Chamber(i).SegmentationModel2(1)->Draw("eventdisplay");// to be check !
238      
239   
240 }
241
242 //____________________________________________________________________
243 const AliMUONGeometry*  AliMUON::GetGeometry() const
244 {
245 /// Return geometry parametrisation
246
247   if ( !fGeometryBuilder) {
248     AliWarningStream() << "GeometryBuilder not defined." << std::endl;
249     return 0;
250   }
251   
252   return fGeometryBuilder->GetGeometry();
253 }   
254
255 //____________________________________________________________________
256 const AliMUONGeometryTransformer*  AliMUON::GetGeometryTransformer() const
257 {
258 /// Return geometry parametrisation
259
260   const AliMUONGeometry* kGeometry = GetGeometry();
261   
262   if ( !kGeometry) return 0;
263
264   return kGeometry->GetTransformer();
265 }   
266
267 //__________________________________________________________________
268 void  AliMUON::SetTreeAddress()
269 {
270 /// Set Hits tree address
271
272   GetMUONData()->SetLoader(fLoader); 
273   //  GetMUONData()->MakeBranch("D,S,RC");
274   //  GetMUONData()->SetTreeAddress("H,D,S,RC");
275   GetMUONData()->SetTreeAddress("H");
276   if (fHits !=  GetMUONData()->Hits())  {
277     if ( gAlice->GetMCApp() )
278       if ( gAlice->GetMCApp()->GetHitLists() ) {
279         fHits = GetMUONData()->Hits();
280         gAlice->GetMCApp()->AddHitList(fHits); // For purifyKine, only necessary when Hit list is created in AliMUONData
281       }  
282   }
283   fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector    
284 }
285
286 //_________________________________________________________________
287 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
288 {
289 /// Set the inverse charge slope for chamber id
290
291     Int_t i=2*(id-1);    //PH    ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
292     //PH    ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
293     ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
294     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
295 }
296 //__________________________________________________________________
297 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
298 {
299 /// Set sigma of charge spread for chamber id
300
301     Int_t i=2*(id-1);
302     ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
303     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
304 }
305 //___________________________________________________________________
306 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
307 {
308 /// Set integration limits for charge spread
309     Int_t i=2*(id-1);
310     ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
311     ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
312 }
313
314 //__________________________________________________________________
315 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
316 {
317 /// Set maximum number for ADCcounts (saturation)
318
319     Int_t i=2*(id-1);
320     ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
321     ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
322 }
323
324 //__________________________________________________________________
325 void AliMUON::SetMaxStepGas(Float_t p1)
326 {
327 /// Set stepsize in gas
328
329   fMaxStepGas=p1;
330 }
331 //__________________________________________________________________
332 void AliMUON::SetMaxStepAlu(Float_t p1)
333 {
334 /// Set step size in Alu
335
336     fMaxStepAlu=p1;
337 }
338 //__________________________________________________________________
339 void AliMUON::SetMaxDestepGas(Float_t p1)
340 {
341 /// Set maximum step size in Gas
342
343     fMaxDestepGas=p1;
344 }
345 //__________________________________________________________________
346 void AliMUON::SetMaxDestepAlu(Float_t p1)
347 {
348 /// Set maximum step size in Alu
349
350   fMaxDestepAlu=p1;
351 }
352
353 //____________________________________________________________________
354 Float_t  AliMUON::GetMaxStepGas() const
355 {
356 /// Return stepsize in gas
357   
358   return fMaxStepGas;
359 }  
360
361 //____________________________________________________________________
362 Float_t  AliMUON::GetMaxStepAlu() const
363 {
364 /// Return step size in Alu
365   
366   return fMaxStepAlu;
367 }
368   
369 //____________________________________________________________________
370 Float_t  AliMUON::GetMaxDestepGas() const
371 {
372 /// Return maximum step size in Gas
373   
374   return fMaxDestepGas;
375 }
376   
377 //____________________________________________________________________
378 Float_t  AliMUON::GetMaxDestepAlu() const
379 {
380 /// Return maximum step size in Gas
381   
382   return fMaxDestepAlu;
383 }
384
385 //____________________________________________________________________
386  void  AliMUON::SetAlign(Bool_t align)
387 {
388 /// Set option for alignement to geometry builder
389  
390    fGeometryBuilder->SetAlign(align);
391 }   
392
393 //____________________________________________________________________
394  void  AliMUON::SetAlign(const TString& fileName, Bool_t align)
395 {
396 /// Set option for alignement to geometry builder
397  
398    fGeometryBuilder->SetAlign(fileName, align);
399 }   
400
401 //____________________________________________________________________
402 void   AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
403 {
404 /// Set the response for chamber id
405     ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
406 }
407
408 //____________________________________________________________________
409 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
410 {
411 /// Return digitizer
412   
413   return new AliMUONDigitizerV3(manager, fDigitizerWithNoise);
414 }
415
416 //_____________________________________________________________________
417 void AliMUON::SDigits2Digits()
418 {
419 /// Write TreeD here only 
420
421     char hname[30];
422     //    sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
423     fLoader->TreeD()->Write(hname,TObject::kOverwrite);
424     fLoader->TreeD()->Reset();
425 }
426
427 //_____________________________________________________________________
428 void AliMUON::Hits2SDigits()
429 {
430 /// Perform Hits2Digits using SDigitizerV2
431   
432   TTask* sdigitizer = new AliMUONSDigitizerV2;
433   sdigitizer->ExecuteTask();
434 }
435
436 //_____________________________________________________________________
437 void AliMUON::Digits2Raw()
438 {
439 /// Convert digits of the current event to raw data
440
441   if (!fRawWriter)
442   {
443     fRawWriter = new AliMUONRawWriter(fMUONData);
444     if (fTriggerScalerEvent == kTRUE) 
445     {
446       fRawWriter->SetScalersNumbers();
447     }
448   }
449   
450   if (!fRawWriter->Digits2Raw()) 
451   {
452     AliError("pb writting raw data");
453   }
454 }
455
456 //_____________________________________________________________________
457 Bool_t AliMUON::Raw2SDigits(AliRawReader* rawReader)
458 {
459 /// Convert  raw data to SDigit
460 /// Only for tracking for the moment (ChF) 
461
462   //fLoader->LoadDigits("READ");
463   if (!fLoader->TreeS()) fLoader->MakeSDigitsContainer();
464
465   fMUONData->MakeBranch("S");
466   fMUONData->SetTreeAddress("S");
467   fDigitMaker->Raw2Digits(rawReader);
468   fMUONData->Fill("S");
469
470   fLoader->WriteSDigits("OVERWRITE");
471   fMUONData->ResetSDigits();
472   fLoader->UnloadSDigits();
473
474   return kTRUE;
475
476 }
477
478 //_______________________________________________________________________
479 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
480
481 /// Build standard getter (AliLoader type);
482 /// if detector wants to use castomized getter, it must overload this method
483  
484  AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
485          GetName(),topfoldername));
486  fLoader   = new AliLoader(GetName(),topfoldername);
487  fMUONData = new AliMUONSimData(fLoader,GetName(),GetName()); 
488  fMUONData->SetSplitLevel(fSplitLevel);
489
490  fDigitMaker->SetMUONData(fMUONData);
491
492  return fLoader;
493 }
494
495 //________________________________________________________________________
496 void
497 AliMUON::ResetGeometryBuilder()
498 {
499 /// Only to be used by "experts" wanting to change the geometry builders
500 /// to be used. 
501 /// As the ctor of AliMUON now defines a default geometrybuilder, this
502 /// ResetGeometryBuilder() must be called prior to call the 
503 /// AddGeometryBuilder()
504
505   delete fGeometryBuilder;
506   fGeometryBuilder = new AliMUONGeometryBuilder(this);
507   fGeometryBuilder
508     ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
509 }
510
511 //____________________________________________________________________
512 Bool_t  AliMUON::GetTriggerResponseV1() const
513 {
514 ///
515 /// Returns fTriggerResponseV1
516 ///  
517     return fTriggerResponseV1;
518     
519 }  
520
521 //____________________________________________________________________
522 Int_t  AliMUON::GetTriggerCoinc44() const
523 {
524 ///
525 /// Returns fTriggerCoinc44
526 ///  
527     return fTriggerCoinc44;
528     
529 }
530
531 //____________________________________________________________________
532 Bool_t  AliMUON::GetTriggerEffCells() const
533 {
534 ///
535 /// Returns fTriggerEffCells
536 ///  
537     return fTriggerEffCells;
538     
539 }  
540
541 //____________________________________________________________________
542 Bool_t  AliMUON::GetDigitizerWithNoise() const
543 {
544 ///
545 /// Returns fDigitizerWithNoise
546 ///  
547     return fDigitizerWithNoise;
548     
549 }  
550