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