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