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