]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUON.cxx
b701e6201005709e4ba075947a0fcd426e346b72
[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 "AliMUONRawWriter.h"
64 #include "AliLog.h"
65
66 #include "AliMUONSDigitizerV2.h"
67 #include "AliMUONDigitizerV3.h"
68 #include "AliMUONDigitMaker.h"
69
70 #include "AliMUONSt1GeometryBuilderV2.h"
71 #include "AliMUONSt2GeometryBuilderV2.h"
72 #include "AliMUONSlatGeometryBuilder.h"
73 #include "AliMUONTriggerGeometryBuilder.h"
74
75 #include "AliMUONDigitStoreV1.h"
76 #include "AliMUONVTriggerStore.h"
77 #include "AliMUONHitStoreV1.h"
78
79 // Defaults parameters for Z positions of chambers
80 // taken from values for "stations" in AliMUON::AliMUON
81 //     const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
82 // and from array "dstation" in AliMUONv1::CreateGeometry
83 //          Float_t dstation[5]={20., 20., 20, 20., 20.};
84 //     for tracking chambers,
85 //          according to (Z1 = zch - dstation) and  (Z2 = zch + dstation)
86 //          for the first and second chambers in the station, respectively,
87 // and from "DTPLANES" in AliMUONv1::CreateGeometry
88 //           const Float_t DTPLANES = 15.;
89 //     for trigger chambers,
90 //          according to (Z1 = zch) and  (Z2 = zch + DTPLANES)
91 //          for the first and second chambers in the station, respectively
92
93 /// \cond CLASSIMP
94 ClassImp(AliMUON)  
95 /// \endcond
96
97 //__________________________________________________________________
98 AliMUON::AliMUON()
99   : AliDetector(),
100     fNCh(0),
101     fNTrackingCh(0),
102     fSplitLevel(0),
103     fChambers(0),
104     fGeometryBuilder(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     fHitStore(0x0)
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     fSplitLevel(0),
135     fChambers(0),
136     fGeometryBuilder(0),
137     fAccCut(kFALSE),
138     fAccMin(0.),
139     fAccMax(0.),   
140     fMaxStepGas(0.1),
141     fMaxStepAlu(0.1),
142     fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200 
143     fMaxDestepAlu(-1), // in the calculation of the tracking parameters
144     fMaxIterPad(0),
145     fCurIterPad(0),
146     fTriggerScalerEvent(kFALSE),
147     fTriggerResponseV1(kFALSE),
148     fTriggerCoinc44(0),
149     fTriggerEffCells(0),
150     fDigitizerWithNoise(kTRUE),
151     fRawWriter(0x0),
152     fDigitMaker(new AliMUONDigitMaker),
153     fHitStore(0x0)
154 {
155 /// Standard constructor  
156   
157   AliDebug(1,Form("ctor this=%p",this));
158   fIshunt =  0;
159
160   //PH SetMarkerColor(kRed);//
161     
162   // Geometry builder
163   fGeometryBuilder = new AliMUONGeometryBuilder(this);
164   
165   // Common geometry definitions
166   fGeometryBuilder
167     ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
168
169   // By default, add also all the needed geometry builders.
170   // If you want to change this from outside, please use ResetGeometryBuilder
171   // method, followed by AddGeometryBuilder ones.
172
173   AddGeometryBuilder(new AliMUONSt1GeometryBuilderV2(this));
174   AddGeometryBuilder(new AliMUONSt2GeometryBuilderV2(this));
175   AddGeometryBuilder(new AliMUONSlatGeometryBuilder(this));
176   AddGeometryBuilder(new AliMUONTriggerGeometryBuilder(this));
177   
178   //
179   // Creating List of Chambers
180     Int_t ch;
181     fChambers = new TObjArray(AliMUONConstants::NCh());
182     fChambers->SetOwner(kTRUE);
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   delete fChambers;
209   delete fGeometryBuilder;
210   delete fRawWriter;
211   delete fDigitMaker;
212   delete fHitStore;
213 }
214
215 //_____________________________________________________________________________
216 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
217 {
218 /// Add the geometry builder to the list
219
220   fGeometryBuilder->AddBuilder(geomBuilder);
221 }
222
223 //____________________________________________________________________
224 void AliMUON::BuildGeometry()
225 {
226 /// Geometry for event display
227
228
229 //     for (Int_t i = 0; i < AliMUONConstants::NCh(); i++)     
230 //       this->Chamber(i).SegmentationModel2(1)->Draw("eventdisplay");// to be check !
231      
232   
233 }
234
235 //____________________________________________________________________
236 const AliMUONGeometry*  AliMUON::GetGeometry() const
237 {
238 /// Return geometry parametrisation
239
240   if ( !fGeometryBuilder) {
241     AliWarningStream() << "GeometryBuilder not defined." << std::endl;
242     return 0;
243   }
244   
245   return fGeometryBuilder->GetGeometry();
246 }   
247
248 //____________________________________________________________________
249 const AliMUONGeometryTransformer*  AliMUON::GetGeometryTransformer() const
250 {
251 /// Return geometry parametrisation
252
253   const AliMUONGeometry* kGeometry = GetGeometry();
254   
255   if ( !kGeometry) return 0;
256
257   return kGeometry->GetTransformer();
258 }   
259
260 //__________________________________________________________________
261 void 
262 AliMUON::MakeBranch(Option_t* opt)
263 {
264   /// Create branche(s) to hold MUON hits
265   AliDebug(1,"");
266   
267   TString sopt(opt);
268   if ( sopt != "H" ) return;
269     
270   if (!fHitStore)
271   {
272     fHitStore = new AliMUONHitStoreV1;
273     if ( gAlice->GetMCApp() )
274     {
275       if ( gAlice->GetMCApp()->GetHitLists() ) 
276       {
277         // AliStack::PurifyKine needs to be able to loop on our hits
278         // to remap the track numbers.
279         gAlice->GetMCApp()->AddHitList(fHitStore->Collection()); 
280       }  
281     }
282   }
283
284   TTree* treeH = fLoader->TreeH();
285   
286   if (!treeH)
287   {
288     AliFatal("No TreeH");
289   }
290   
291   fHitStore->Connect(*treeH);
292 }
293
294 //__________________________________________________________________
295 void  
296 AliMUON::SetTreeAddress()
297 {
298   /// Set Hits tree address  
299  
300 //  if ( gAlice->GetMCApp() && fHitStore )
301 //  {
302 //    TList* l = gAlice->GetMCApp()->GetHitLists();
303 //    if ( l )
304 //    {
305 //      TObject* o = l->First();
306 //      if (o!=fHitStore->HitCollection())
307 //      {
308 //        AliError(Form("Something is strange hitcollection=%x",fHitStore->HitCollection()));
309 //        l->Print();        
310 //      }
311 //    }  
312 //  }  
313 }
314
315 //_________________________________________________________________
316 void
317 AliMUON::ResetHits()
318 {
319   /// Reset hits
320   
321   AliDebug(1,"");
322   if (fHitStore) fHitStore->Clear();
323 }
324
325 //_________________________________________________________________
326 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
327 {
328 /// Set the inverse charge slope for chamber id
329
330     Int_t i=2*(id-1);    //PH    ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
331     //PH    ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
332     ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
333     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
334 }
335 //__________________________________________________________________
336 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
337 {
338 /// Set sigma of charge spread for chamber id
339
340     Int_t i=2*(id-1);
341     ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
342     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
343 }
344 //___________________________________________________________________
345 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
346 {
347 /// Set integration limits for charge spread
348     Int_t i=2*(id-1);
349     ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
350     ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
351 }
352
353 //__________________________________________________________________
354 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
355 {
356 /// Set maximum number for ADCcounts (saturation)
357
358     Int_t i=2*(id-1);
359     ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
360     ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
361 }
362
363 //__________________________________________________________________
364 void AliMUON::SetMaxStepGas(Float_t p1)
365 {
366 /// Set stepsize in gas
367
368   fMaxStepGas=p1;
369 }
370 //__________________________________________________________________
371 void AliMUON::SetMaxStepAlu(Float_t p1)
372 {
373 /// Set step size in Alu
374
375     fMaxStepAlu=p1;
376 }
377 //__________________________________________________________________
378 void AliMUON::SetMaxDestepGas(Float_t p1)
379 {
380 /// Set maximum step size in Gas
381
382     fMaxDestepGas=p1;
383 }
384 //__________________________________________________________________
385 void AliMUON::SetMaxDestepAlu(Float_t p1)
386 {
387 /// Set maximum step size in Alu
388
389   fMaxDestepAlu=p1;
390 }
391
392 //____________________________________________________________________
393 Float_t  AliMUON::GetMaxStepGas() const
394 {
395 /// Return stepsize in gas
396   
397   return fMaxStepGas;
398 }  
399
400 //____________________________________________________________________
401 Float_t  AliMUON::GetMaxStepAlu() const
402 {
403 /// Return step size in Alu
404   
405   return fMaxStepAlu;
406 }
407   
408 //____________________________________________________________________
409 Float_t  AliMUON::GetMaxDestepGas() const
410 {
411 /// Return maximum step size in Gas
412   
413   return fMaxDestepGas;
414 }
415   
416 //____________________________________________________________________
417 Float_t  AliMUON::GetMaxDestepAlu() const
418 {
419 /// Return maximum step size in Gas
420   
421   return fMaxDestepAlu;
422 }
423
424 //____________________________________________________________________
425  void  AliMUON::SetAlign(Bool_t align)
426 {
427 /// Set option for alignement to geometry builder
428  
429    fGeometryBuilder->SetAlign(align);
430 }   
431
432 //____________________________________________________________________
433  void  AliMUON::SetAlign(const TString& fileName, Bool_t align)
434 {
435 /// Set option for alignement to geometry builder
436  
437    fGeometryBuilder->SetAlign(fileName, align);
438 }   
439
440 //____________________________________________________________________
441 void   AliMUON::SetResponseModel(Int_t id, const AliMUONResponse& response)
442 {
443 /// Set the response for chamber id
444     ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
445 }
446
447 //____________________________________________________________________
448 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
449 {
450 /// Return digitizer
451   
452   return new AliMUONDigitizerV3(manager, fDigitizerWithNoise);
453 }
454
455 //_____________________________________________________________________
456 void AliMUON::SDigits2Digits()
457 {
458 /// Write TreeD here only 
459
460     char hname[30];
461     //    sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
462     fLoader->TreeD()->Write(hname,TObject::kOverwrite);
463     fLoader->TreeD()->Reset();
464 }
465
466 //_____________________________________________________________________
467 void AliMUON::Hits2SDigits()
468 {
469 /// Perform Hits2Digits using SDigitizerV2
470   
471   AliMUONSDigitizerV2 sdigitizer;
472   sdigitizer.ExecuteTask();
473 }
474
475 //_____________________________________________________________________
476 void AliMUON::Digits2Raw()
477 {
478 /// Convert digits of the current event to raw data
479
480   if (!fRawWriter)
481   {
482     fRawWriter = new AliMUONRawWriter;
483     AliDebug(1,Form("Creating %s",fRawWriter->ClassName()));
484     if (fTriggerScalerEvent == kTRUE) 
485     {
486       fRawWriter->SetScalersNumbers();
487     }
488   }
489   
490   fLoader->LoadDigits("READ");
491   
492   TTree* treeD = fLoader->TreeD();
493   
494   if (!treeD)
495   {
496     AliError("Could not get TreeD");
497     return;
498   }
499   
500   AliMUONVTriggerStore*  triggerStore = AliMUONVTriggerStore::Create(*treeD);
501   AliMUONVDigitStore* digitStore = AliMUONVDigitStore::Create(*treeD);
502
503   triggerStore->Connect(*treeD,kFALSE);
504   digitStore->Connect(*treeD,kFALSE);
505   
506   treeD->GetEvent(0);
507   
508   if (!fRawWriter->Digits2Raw(digitStore,triggerStore))
509   {
510     AliError("pb writting raw data");
511   }
512   
513   delete triggerStore;
514   delete digitStore;
515   
516   fLoader->UnloadDigits();
517 }
518
519 //_____________________________________________________________________
520 Bool_t AliMUON::Raw2SDigits(AliRawReader* rawReader)
521 {
522 /// Convert  raw data to SDigit
523 /// Only for tracking for the moment (ChF) 
524
525   fLoader->LoadDigits("READ");
526   if (!fLoader->TreeS()) fLoader->MakeSDigitsContainer();
527
528   TTree* treeS = fLoader->TreeS();
529   
530   AliMUONVDigitStore* sDigitStore = new AliMUONDigitStoreV1;
531   sDigitStore->Connect(*treeS);
532   
533   fDigitMaker->Raw2Digits(rawReader,sDigitStore,0x0);
534
535   fLoader->WriteSDigits("OVERWRITE");
536
537   fLoader->UnloadSDigits();
538
539   delete sDigitStore;
540   
541   return kTRUE;
542 }
543
544 //_______________________________________________________________________
545 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
546
547 /// Build standard getter (AliLoader type);
548 /// if detector wants to use castomized getter, it must overload this method
549  
550  AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
551          GetName(),topfoldername));
552  fLoader   = new AliLoader(GetName(),topfoldername);
553
554  return fLoader;
555 }
556
557 //________________________________________________________________________
558 void
559 AliMUON::ResetGeometryBuilder()
560 {
561 /// Only to be used by "experts" wanting to change the geometry builders
562 /// to be used. 
563 /// As the ctor of AliMUON now defines a default geometrybuilder, this
564 /// ResetGeometryBuilder() must be called prior to call the 
565 /// AddGeometryBuilder()
566
567   delete fGeometryBuilder;
568   fGeometryBuilder = new AliMUONGeometryBuilder(this);
569   fGeometryBuilder
570     ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
571 }
572
573 //____________________________________________________________________
574 Bool_t  AliMUON::GetTriggerResponseV1() const
575 {
576 ///
577 /// Returns fTriggerResponseV1
578 ///  
579     return fTriggerResponseV1;
580     
581 }  
582
583 //____________________________________________________________________
584 Int_t  AliMUON::GetTriggerCoinc44() const
585 {
586 ///
587 /// Returns fTriggerCoinc44
588 ///  
589     return fTriggerCoinc44;
590     
591 }
592
593 //____________________________________________________________________
594 Bool_t  AliMUON::GetTriggerEffCells() const
595 {
596 ///
597 /// Returns fTriggerEffCells
598 ///  
599     return fTriggerEffCells;
600     
601 }  
602
603 //____________________________________________________________________
604 Bool_t  AliMUON::GetDigitizerWithNoise() const
605 {
606 ///
607 /// Returns fDigitizerWithNoise
608 ///  
609     return fDigitizerWithNoise;
610     
611 }  
612