]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUON.cxx
0597a7004d13028330f1259c2a626487733a5f17
[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 "AliMUONRawCluster.h"
59 #include "AliMUONTransientDigit.h"
60 #include "AliMUONTriggerCircuitNew.h"
61 #include "AliMUONGeometry.h"
62 #include "AliMUONGeometryTransformer.h"
63 #include "AliMUONGeometryBuilder.h"
64 #include "AliMUONCommonGeometryBuilder.h"
65 #include "AliMUONVGeometryBuilder.h"    
66 #include "AliMUONGeometrySegmentation.h"
67 #include "AliMUONDigitizerv2.h"
68 #include "AliMUONSDigitizerv1.h"
69 #include "AliMUONRawWriter.h"
70 #include "AliMUONSegmentation.h"
71 #include "AliLog.h"
72
73 #include "AliMUONSDigitizerV2.h"
74 #include "AliMUONDigitizerV3.h"
75 #include "AliMUONDigitMaker.h"
76
77 #include "AliMUONSt1GeometryBuilderV2.h"
78 #include "AliMUONSt2GeometryBuilderV2.h"
79 #include "AliMUONSlatGeometryBuilder.h"
80 #include "AliMUONTriggerGeometryBuilder.h"
81
82 // Defaults parameters for Z positions of chambers
83 // taken from values for "stations" in AliMUON::AliMUON
84 //     const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
85 // and from array "dstation" in AliMUONv1::CreateGeometry
86 //          Float_t dstation[5]={20., 20., 20, 20., 20.};
87 //     for tracking chambers,
88 //          according to (Z1 = zch - dstation) and  (Z2 = zch + dstation)
89 //          for the first and second chambers in the station, respectively,
90 // and from "DTPLANES" in AliMUONv1::CreateGeometry
91 //           const Float_t DTPLANES = 15.;
92 //     for trigger chambers,
93 //          according to (Z1 = zch) and  (Z2 = zch + DTPLANES)
94 //          for the first and second chambers in the station, respectively
95
96 /// \cond CLASSIMP
97 ClassImp(AliMUON)  
98 /// \endcond
99
100 //__________________________________________________________________
101 AliMUON::AliMUON()
102   : AliDetector(),
103     fNCh(0),
104     fNTrackingCh(0),
105     fMUONData(0),
106     fSplitLevel(0),
107     fChambers(0),
108     fTriggerCircuitsNew(0),
109     fGeometryBuilder(0),
110     fSegmentation(0),
111     fAccCut(kFALSE),
112     fAccMin(0.),
113     fAccMax(0.),   
114     fMaxStepGas(0.),
115     fMaxStepAlu(0.),
116     fMaxDestepGas(0.),
117     fMaxDestepAlu(0.),
118     fMaxIterPad(0),
119     fCurIterPad(0),
120     fTriggerScalerEvent(kFALSE),
121     fTriggerResponseV1(kFALSE),
122     fTriggerCoinc44(0),
123     fTriggerEffCells(0),
124     fSDigitizerType(""),
125     fDigitizerType(""),
126     fRawWriter(0x0),
127     fDigitMaker(0x0)
128
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                  const char* sDigitizerClassName,
139                  const char* digitizerClassName)
140   : AliDetector(name,title),
141     fNCh(AliMUONConstants::NCh()),
142     fNTrackingCh(AliMUONConstants::NTrackingCh()),
143     fMUONData(0),
144     fSplitLevel(0),
145     fChambers(0),
146     fTriggerCircuitsNew(0),
147     fGeometryBuilder(0),
148     fSegmentation(0),
149     fAccCut(kFALSE),
150     fAccMin(0.),
151     fAccMax(0.),   
152     fMaxStepGas(0.1),
153     fMaxStepAlu(0.1),
154     fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200 
155     fMaxDestepAlu(-1), // in the calculation of the tracking parameters
156     fMaxIterPad(0),
157     fCurIterPad(0),
158     fTriggerScalerEvent(kFALSE),
159     fTriggerResponseV1(kFALSE),
160     fTriggerCoinc44(0),
161     fTriggerEffCells(0),
162     fSDigitizerType(sDigitizerClassName),
163     fDigitizerType(digitizerClassName),
164     fRawWriter(0x0),
165     fDigitMaker(new AliMUONDigitMaker(kFALSE)) 
166 {
167 /// Standard constructor  
168   
169   AliDebug(1,Form("ctor this=%p",this));
170   fIshunt =  0;
171
172   SetMarkerColor(kRed);//
173     
174   // Geometry builder
175   fGeometryBuilder = new AliMUONGeometryBuilder(this);
176   
177   // Common geometry definitions
178   fGeometryBuilder
179     ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
180
181   // By default, add also all the needed geometry builders.
182   // If you want to change this from outside, please use ResetGeometryBuilder
183   // method, followed by AddGeometryBuilder ones.
184
185   AddGeometryBuilder(new AliMUONSt1GeometryBuilderV2(this));
186   AddGeometryBuilder(new AliMUONSt2GeometryBuilderV2(this));
187   AddGeometryBuilder(new AliMUONSlatGeometryBuilder(this));
188   AddGeometryBuilder(new AliMUONTriggerGeometryBuilder(this));
189   
190   //
191   // Creating List of Chambers
192     Int_t ch;
193     fChambers = new TObjArray(AliMUONConstants::NCh());
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 // trigger circuits
212     fTriggerCircuitsNew = new TObjArray(AliMUONConstants::NTriggerCircuit());
213     for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
214       fTriggerCircuitsNew->AddAt(new AliMUONTriggerCircuitNew(),circ);          
215     }
216 }
217
218 //____________________________________________________________________
219 AliMUON::~AliMUON()
220 {
221 /// Destructor
222
223   AliDebug(1,Form("dtor this=%p",this));
224   fIshunt  = 0;
225
226   if (fChambers){
227     fChambers->Delete();
228     delete fChambers;
229   }
230   if (fTriggerCircuitsNew){
231     fTriggerCircuitsNew->Delete();
232     delete fTriggerCircuitsNew;
233   }
234   
235   delete fMUONData;
236   delete fGeometryBuilder;
237   delete fSegmentation;
238   delete fRawWriter;
239   delete fDigitMaker;
240 }
241
242 //_____________________________________________________________________________
243 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
244 {
245 /// Add the geometry builder to the list
246
247   fGeometryBuilder->AddBuilder(geomBuilder);
248 }
249
250 //____________________________________________________________________
251 void AliMUON::BuildGeometry()
252 {
253 /// Geometry for event display
254
255
256 //     for (Int_t i = 0; i < AliMUONConstants::NCh(); i++)     
257 //       this->Chamber(i).SegmentationModel2(1)->Draw("eventdisplay");// to be check !
258      
259   
260 }
261
262 //____________________________________________________________________
263 const AliMUONGeometry*  AliMUON::GetGeometry() const
264 {
265 /// Return geometry parametrisation
266
267   if ( !fGeometryBuilder) {
268     AliWarningStream() << "GeometryBuilder not defined." << std::endl;
269     return 0;
270   }
271   
272   return fGeometryBuilder->GetGeometry();
273 }   
274
275 //____________________________________________________________________
276 const AliMUONGeometryTransformer*  AliMUON::GetGeometryTransformer() const
277 {
278 /// Return geometry parametrisation
279
280   const AliMUONGeometry* kGeometry = GetGeometry();
281   
282   if ( !kGeometry) return 0;
283
284   return kGeometry->GetTransformer();
285 }   
286
287 //__________________________________________________________________
288 void  AliMUON::SetTreeAddress()
289 {
290 /// Set Hits tree address
291
292   GetMUONData()->SetLoader(fLoader); 
293   //  GetMUONData()->MakeBranch("D,S,RC");
294   //  GetMUONData()->SetTreeAddress("H,D,S,RC");
295   GetMUONData()->SetTreeAddress("H");
296   if (fHits !=  GetMUONData()->Hits())  {
297     if ( gAlice->GetMCApp() )
298       if ( gAlice->GetMCApp()->GetHitLists() ) {
299         fHits = GetMUONData()->Hits();
300         gAlice->GetMCApp()->AddHitList(fHits); // For purifyKine, only necessary when Hit list is created in AliMUONData
301       }  
302   }
303   fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector    
304 }
305
306 //_________________________________________________________________
307 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
308 {
309 /// Set the inverse charge slope for chamber id
310
311     Int_t i=2*(id-1);    //PH    ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
312     //PH    ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
313     ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
314     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
315 }
316 //__________________________________________________________________
317 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
318 {
319 /// Set sigma of charge spread for chamber id
320
321     Int_t i=2*(id-1);
322     ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
323     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
324 }
325 //___________________________________________________________________
326 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
327 {
328 /// Set integration limits for charge spread
329     Int_t i=2*(id-1);
330     ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
331     ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
332 }
333
334 //__________________________________________________________________
335 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
336 {
337 /// Set maximum number for ADCcounts (saturation)
338
339     Int_t i=2*(id-1);
340     ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
341     ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
342 }
343
344 //__________________________________________________________________
345 void AliMUON::SetMaxStepGas(Float_t p1)
346 {
347 /// Set stepsize in gas
348
349   fMaxStepGas=p1;
350 }
351 //__________________________________________________________________
352 void AliMUON::SetMaxStepAlu(Float_t p1)
353 {
354 /// Set step size in Alu
355
356     fMaxStepAlu=p1;
357 }
358 //__________________________________________________________________
359 void AliMUON::SetMaxDestepGas(Float_t p1)
360 {
361 /// Set maximum step size in Gas
362
363     fMaxDestepGas=p1;
364 }
365 //__________________________________________________________________
366 void AliMUON::SetMaxDestepAlu(Float_t p1)
367 {
368 /// Set maximum step size in Alu
369
370   fMaxDestepAlu=p1;
371 }
372
373 //____________________________________________________________________
374 Float_t  AliMUON::GetMaxStepGas() const
375 {
376 /// Return stepsize in gas
377   
378   return fMaxStepGas;
379 }  
380
381 //____________________________________________________________________
382 Float_t  AliMUON::GetMaxStepAlu() const
383 {
384 /// Return step size in Alu
385   
386   return fMaxStepAlu;
387 }
388   
389 //____________________________________________________________________
390 Float_t  AliMUON::GetMaxDestepGas() const
391 {
392 /// Return maximum step size in Gas
393   
394   return fMaxDestepGas;
395 }
396   
397 //____________________________________________________________________
398 Float_t  AliMUON::GetMaxDestepAlu() const
399 {
400 /// Return maximum step size in Gas
401   
402   return fMaxDestepAlu;
403 }
404
405 //____________________________________________________________________
406  void  AliMUON::SetAlign(Bool_t align)
407 {
408 /// Set option for alignement to geometry builder
409  
410    fGeometryBuilder->SetAlign(align);
411 }   
412
413 //____________________________________________________________________
414  void  AliMUON::SetAlign(const TString& fileName, Bool_t align)
415 {
416 /// Set option for alignement to geometry builder
417  
418    fGeometryBuilder->SetAlign(fileName, align);
419 }   
420
421 //____________________________________________________________________
422 void   AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
423 {
424 /// Set the response for chamber id
425     ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
426 }
427
428 //____________________________________________________________________
429 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
430 {
431 /// FIXME: the selection of the class should be done through a factory
432 /// mechanism. (see also Hits2SDigits()).
433   
434   AliInfo(Form("Digitizer used : %s",fDigitizerType.Data()));
435   
436   if ( fDigitizerType == "digitizer:default" ) // NewDigitizerNewTrigger
437   {
438       return new AliMUONDigitizerV3(manager,kTRUE);
439   } 
440   else if ( fDigitizerType == "digitizer:NewDigitizerWONoiseNewTrigger" ) 
441   {                                     
442       return new AliMUONDigitizerV3(manager,kFALSE);
443   }
444   else
445   {
446     AliFatal(Form("Unknown digitizer type : %s",fDigitizerType.Data()));
447   }
448   return 0x0;
449 }
450
451 //_____________________________________________________________________
452 TString
453 AliMUON::SDigitizerType() const
454 {
455 /// Return digitizer type
456
457   return fSDigitizerType;
458 }
459
460 //_____________________________________________________________________
461 void AliMUON::SDigits2Digits()
462 {
463 /// Write TreeD here only 
464
465     char hname[30];
466     //    sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
467     fLoader->TreeD()->Write(hname,TObject::kOverwrite);
468     fLoader->TreeD()->Reset();
469 }
470
471 //_____________________________________________________________________
472 void AliMUON::Hits2SDigits()
473 {
474 /// FIXME: the selection of the sdigitizer should be done through a
475 /// factory mechanism.
476   
477   AliInfo(Form("SDigitizer used : %s",fSDigitizerType.Data()));
478
479   if ( fSDigitizerType == "sdigitizer:default" )
480   {
481     // Adaption of AliMUONSDigitizerv1 to be excuted by the AliSimulation framework
482     AliRunLoader* runLoader = fLoader->GetRunLoader();
483     AliRunDigitizer   * manager = new AliRunDigitizer(1,1);
484     manager->SetInputStream(0,runLoader->GetFileName(),AliConfig::GetDefaultEventFolderName());
485     AliMUONDigitizer * dMUON   = new AliMUONSDigitizerv1(manager);
486     fLoader->LoadHits("READ");
487     for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
488       runLoader->GetEvent(iEvent);
489       dMUON->Exec("");
490     }
491     fLoader->UnloadHits();
492   }
493   else if ( fSDigitizerType == "sdigitizer:AliMUONSDigitizerV2" )
494   {
495     TTask* sdigitizer = new AliMUONSDigitizerV2;
496     sdigitizer->ExecuteTask();
497   }
498   else
499   {
500     AliFatal(Form("Unknown sdigitizer classname : %s",fSDigitizerType.Data()));
501   }
502 }
503
504 //_____________________________________________________________________
505 TString
506 AliMUON::DigitizerType() const
507 {
508 /// Return digitizer type
509
510   return fDigitizerType;
511 }
512
513 //_____________________________________________________________________
514 void AliMUON::Digits2Raw()
515 {
516 /// Convert digits of the current event to raw data
517
518   if (!fRawWriter)
519   {
520     fRawWriter = new AliMUONRawWriter(fMUONData);
521     if (fTriggerScalerEvent == kTRUE) 
522     {
523       fRawWriter->SetScalersNumbers();
524     }
525   }
526   
527   if (!fRawWriter->Digits2Raw()) 
528   {
529     AliError("pb writting raw data");
530   }
531 }
532
533 //_____________________________________________________________________
534 Bool_t AliMUON::Raw2SDigits(AliRawReader* rawReader)
535 {
536 /// Convert  raw data to SDigit
537 /// Only for tracking for the moment (ChF) 
538
539   //fLoader->LoadDigits("READ");
540   if (!fLoader->TreeS()) fLoader->MakeSDigitsContainer();
541
542   fMUONData->MakeBranch("S");
543   fMUONData->SetTreeAddress("S");
544   fDigitMaker->Raw2Digits(rawReader);
545   fMUONData->Fill("S");
546
547   fLoader->WriteSDigits("OVERWRITE");
548   fMUONData->ResetSDigits();
549   fLoader->UnloadSDigits();
550
551   return kTRUE;
552
553 }
554
555 //_______________________________________________________________________
556 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
557
558 /// Build standard getter (AliLoader type);
559 /// if detector wants to use castomized getter, it must overload this method
560  
561  AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
562          GetName(),topfoldername));
563  fLoader   = new AliLoader(GetName(),topfoldername);
564  fMUONData = new AliMUONData(fLoader,GetName(),GetName()); 
565  fMUONData->SetSplitLevel(fSplitLevel);
566
567  fDigitMaker->SetMUONData(fMUONData);
568
569  return fLoader;
570 }
571 //_______________________________________________________________________
572
573 AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
574 {
575 /// Return rawcluster (icluster) for chamber ichamber and cathode icathod
576 /// Obsolete ??
577
578     TClonesArray *muonRawCluster  = GetMUONData()->RawClusters(ichamber);
579     ResetRawClusters();
580     TTree *treeR = fLoader->TreeR();
581     Int_t nent=(Int_t)treeR->GetEntries();
582     treeR->GetEvent(nent-2+icathod-1);
583     //treeR->GetEvent(icathod);
584     //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
585
586     AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
587     //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
588     
589     return  mRaw;
590 }
591
592 //________________________________________________________________________
593 void
594 AliMUON::ResetGeometryBuilder()
595 {
596 /// Only to be used by "experts" wanting to change the geometry builders
597 /// to be used. 
598 /// As the ctor of AliMUON now defines a default geometrybuilder, this
599 /// ResetGeometryBuilder() must be called prior to call the 
600 /// AddGeometryBuilder()
601
602   delete fGeometryBuilder;
603   fGeometryBuilder = new AliMUONGeometryBuilder(this);
604   fGeometryBuilder
605     ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
606 }
607
608 //____________________________________________________________________
609 Bool_t  AliMUON::GetTriggerResponseV1() const
610 {
611 ///
612 /// Returns fTriggerResponseV1
613 ///  
614     return fTriggerResponseV1;
615     
616 }  
617
618 //____________________________________________________________________
619 Int_t  AliMUON::GetTriggerCoinc44() const
620 {
621 ///
622 /// Returns fTriggerCoinc44
623 ///  
624     return fTriggerCoinc44;
625     
626 }
627
628 //____________________________________________________________________
629 Bool_t  AliMUON::GetTriggerEffCells() const
630 {
631 ///
632 /// Returns fTriggerEffCells
633 ///  
634     return fTriggerEffCells;
635     
636 }  
637