]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUON.cxx
937d3bd9e71156145e2413a34b4dbd1e205305ce
[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 ///////////////////////////////////////////////
20 //  Manager and hits classes for set:MUON     //
21 ////////////////////////////////////////////////
22
23 #include "Riostream.h"
24
25 #include <AliPDG.h>
26 #include <TBRIK.h>
27 #include <TCanvas.h>
28 #include <TDirectory.h>
29 #include <TFile.h>
30 #include <TGeometry.h>
31 #include <TMinuit.h>
32 #include <TNode.h> 
33 #include <TNtuple.h>
34 #include <TObjArray.h>
35 #include <TObject.h>
36 #include <TObjectTable.h>
37 #include <TPad.h>
38 #include <TParticle.h>
39 #include <TROOT.h>
40 #include <TRandom.h> 
41 #include <TRotMatrix.h>
42 #include <TTUBE.h>
43 #include <TTUBE.h>
44 #include <TTree.h> 
45 #include <TVector.h>
46 #include <TVirtualMC.h>
47
48 //#include "AliHeader.h"
49 #include "AliLoader.h"
50 #include "AliRunDigitizer.h"
51 #include "AliMC.h"
52 #include "AliRun.h"     
53 #include "AliMUON.h"
54 #include "AliMUONChamberTrigger.h"
55 #include "AliMUONConstants.h"
56 #include "AliMUONHit.h" 
57 #include "AliMUONRawCluster.h"
58 #include "AliMUONTransientDigit.h"
59 #include "AliMUONTriggerCircuit.h"
60 #include "AliMUONGeometry.h"
61 #include "AliMUONGeometryTransformer.h"
62 #include "AliMUONGeometryBuilder.h"
63 #include "AliMUONCommonGeometryBuilder.h"
64 #include "AliMUONVGeometryBuilder.h"    
65 #include "AliMUONGeometrySegmentation.h"
66 #include "AliMUONDigitizerv2.h"
67 #include "AliMUONSDigitizerv1.h"
68 #include "AliMUONRawWriter.h"
69 #include "AliMUONSegmentation.h"
70 #include "AliLog.h"
71
72 #include "AliMUONSDigitizerV2.h"
73 #include "AliMUONDigitizerV3.h"
74
75 #include "AliMUONSt1GeometryBuilderV2.h"
76 #include "AliMUONSt2GeometryBuilderV2.h"
77 #include "AliMUONSlatGeometryBuilder.h"
78 #include "AliMUONTriggerGeometryBuilder.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 ClassImp(AliMUON)
95
96 //__________________________________________________________________
97 AliMUON::AliMUON()
98   : AliDetector(),
99     fNCh(0),
100     fNTrackingCh(0),
101     fMUONData(0),
102     fSplitLevel(0),
103     fChambers(0),
104     fTriggerCircuits(0),
105     fGeometryBuilder(0),
106     fSegmentation(0),
107     fAccCut(kFALSE),
108     fAccMin(0.),
109     fAccMax(0.),   
110     fMaxStepGas(0.),
111     fMaxStepAlu(0.),
112     fMaxDestepGas(0.),
113     fMaxDestepAlu(0.),
114     fMaxIterPad(0),
115     fCurIterPad(0),
116     fTriggerScalerEvent(kFALSE),
117     fSDigitizerType(""),
118     fDigitizerType(""),
119   fRawWriter(0x0)
120 {
121 // Default Constructor
122 //
123         AliDebug(1,Form("default (empty) ctor this=%p",this));
124     fIshunt          = 0;
125 }
126
127 //__________________________________________________________________
128 AliMUON::AliMUON(const char *name, const char *title,
129                  const char* sDigitizerClassName,
130                  const char* digitizerClassName)
131   : AliDetector(name,title),
132     fNCh(AliMUONConstants::NCh()),
133     fNTrackingCh(AliMUONConstants::NTrackingCh()),
134     fMUONData(0),
135     fSplitLevel(0),
136     fChambers(0),
137     fTriggerCircuits(0),
138     fGeometryBuilder(0),
139     fSegmentation(0),
140     fAccCut(kFALSE),
141     fAccMin(0.),
142     fAccMax(0.),   
143     fMaxStepGas(0.1),
144     fMaxStepAlu(0.1),
145     fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200 
146     fMaxDestepAlu(-1), // in the calculation of the tracking parameters
147     fMaxIterPad(0),
148     fCurIterPad(0),
149           fTriggerScalerEvent(kFALSE),
150     fSDigitizerType(sDigitizerClassName),
151     fDigitizerType(digitizerClassName),
152   fRawWriter(0x0)
153 {
154         AliDebug(1,Form("ctor this=%p",this));
155   fIshunt =  0;
156
157   SetMarkerColor(kRed);//
158     
159   // Geometry builder
160   fGeometryBuilder = new AliMUONGeometryBuilder(this);
161   
162   // Common geometry definitions
163   fGeometryBuilder
164     ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
165
166   // By default, add also all the needed geometry builders.
167   // If you want to change this from outside, please use ResetGeometryBuilder
168   // method, followed by AddGeometryBuilder ones.
169
170   AddGeometryBuilder(new AliMUONSt1GeometryBuilderV2(this));
171   AddGeometryBuilder(new AliMUONSt2GeometryBuilderV2(this));
172   AddGeometryBuilder(new AliMUONSlatGeometryBuilder(this));
173   AddGeometryBuilder(new AliMUONTriggerGeometryBuilder(this));
174   
175   //
176   // Creating List of Chambers
177     Int_t ch;
178     fChambers = new TObjArray(AliMUONConstants::NCh());
179
180     // Loop over stations
181     for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
182       // Loop over 2 chambers in the station
183       for (Int_t stCH = 0; stCH < 2; stCH++) {
184         //
185         //    
186         //    Default Parameters for Muon Tracking Stations
187         ch = 2 * st + stCH;
188         if (ch < AliMUONConstants::NTrackingCh()) {
189           fChambers->AddAt(new AliMUONChamber(ch),ch);
190         } else {
191           fChambers->AddAt(new AliMUONChamberTrigger(ch, GetGeometryTransformer()),ch);
192         }
193       } // Chamber stCH (0, 1) in 
194     }     // Station st (0...)
195     
196     // cp new design of AliMUONTriggerDecision
197     fTriggerCircuits = new TObjArray(AliMUONConstants::NTriggerCircuit());
198     for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
199       fTriggerCircuits->AddAt(new AliMUONTriggerCircuit(),circ);          
200     }
201 }
202
203 //____________________________________________________________________
204 AliMUON::AliMUON(const AliMUON& rMUON)
205  : AliDetector(rMUON)
206 {
207 // Protected copy constructor
208
209   AliFatal("Not implemented.");
210 }
211
212 //____________________________________________________________________
213 AliMUON::~AliMUON()
214 {
215 // Destructor
216   AliDebug(1,Form("dtor this=%p",this));
217   fIshunt  = 0;
218
219   if (fChambers){
220     fChambers->Delete();
221     delete fChambers;
222   }
223   if (fTriggerCircuits){
224     fTriggerCircuits->Delete();
225     delete fTriggerCircuits;
226   }
227   delete fMUONData;
228   delete fGeometryBuilder;
229   delete fSegmentation;
230   delete fRawWriter;
231 }
232
233 //________________________________________________________________________
234 AliMUON& AliMUON::operator = (const AliMUON& rhs)
235 {
236 // Protected assignement operator
237
238   if (this == &rhs) return *this;
239
240   AliFatal("Not implemented.");
241     
242   return *this;  
243 }
244
245 //_____________________________________________________________________________
246 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
247 {
248 // Adds the geometry builder to the list
249 // ---
250
251   fGeometryBuilder->AddBuilder(geomBuilder);
252 }
253
254 //____________________________________________________________________
255 void AliMUON::BuildGeometry()
256 {
257 // Geometry for event display
258
259
260 //     for (Int_t i = 0; i < AliMUONConstants::NCh(); i++)     
261 //       this->Chamber(i).SegmentationModel2(1)->Draw("eventdisplay");// to be check !
262      
263   
264 }
265
266 //____________________________________________________________________
267 const AliMUONGeometry*  AliMUON::GetGeometry() const
268 {
269 // Return geometry parametrisation
270
271   if ( !fGeometryBuilder) {
272     AliWarningStream() << "GeometryBuilder not defined." << std::endl;
273     return 0;
274   }
275   
276   return fGeometryBuilder->GetGeometry();
277 }   
278
279 //____________________________________________________________________
280 const AliMUONGeometryTransformer*  AliMUON::GetGeometryTransformer() const
281 {
282 // Return geometry parametrisation
283
284   const AliMUONGeometry* kGeometry = GetGeometry();
285   
286   if ( !kGeometry) return 0;
287
288   return kGeometry->GetTransformer();
289 }   
290
291 //__________________________________________________________________
292 void  AliMUON::SetTreeAddress()
293 {
294   GetMUONData()->SetLoader(fLoader); 
295   //  GetMUONData()->MakeBranch("D,S,RC");
296   //  GetMUONData()->SetTreeAddress("H,D,S,RC");
297   GetMUONData()->SetTreeAddress("H");
298   if (fHits !=  GetMUONData()->Hits())  {
299     if ( gAlice->GetMCApp() )
300       if ( gAlice->GetMCApp()->GetHitLists() ) {
301         fHits = GetMUONData()->Hits();
302         gAlice->GetMCApp()->AddHitList(fHits); // For purifyKine, only necessary when Hit list is created in AliMUONData
303       }  
304   }
305   fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector    
306 }
307
308 //_________________________________________________________________
309 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
310 {
311 // Set the inverse charge slope for chamber id
312     Int_t i=2*(id-1);    //PH    ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
313     //PH    ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
314     ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
315     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
316 }
317 //__________________________________________________________________
318 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
319 {
320 // Set sigma of charge spread for chamber id
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     Int_t i=2*(id-1);
339     ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
340     ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
341 }
342
343 //__________________________________________________________________
344 void AliMUON::SetMaxStepGas(Float_t p1)
345 {
346 // Set stepsize in gas
347   fMaxStepGas=p1;
348 }
349 //__________________________________________________________________
350 void AliMUON::SetMaxStepAlu(Float_t p1)
351 {
352 // Set step size in Alu
353     fMaxStepAlu=p1;
354 }
355 //__________________________________________________________________
356 void AliMUON::SetMaxDestepGas(Float_t p1)
357 {
358 // Set maximum step size in Gas
359     fMaxDestepGas=p1;
360 }
361 //__________________________________________________________________
362 void AliMUON::SetMaxDestepAlu(Float_t p1)
363 {
364 // Set maximum step size in Alu
365   fMaxDestepAlu=p1;
366 }
367
368 //____________________________________________________________________
369 Float_t  AliMUON::GetMaxStepGas() const
370 {
371 // Return stepsize in gas
372   
373   return fMaxStepGas;
374 }  
375
376 //____________________________________________________________________
377 Float_t  AliMUON::GetMaxStepAlu() const
378 {
379 // Return step size in Alu
380   
381   return fMaxStepAlu;
382 }
383   
384 //____________________________________________________________________
385 Float_t  AliMUON::GetMaxDestepGas() const
386 {
387 // Return maximum step size in Gas
388   
389   return fMaxDestepGas;
390 }
391   
392 //____________________________________________________________________
393 Float_t  AliMUON::GetMaxDestepAlu() const
394 {
395 // Return maximum step size in Gas
396   
397   return fMaxDestepAlu;
398 }
399
400 //____________________________________________________________________
401  void  AliMUON::SetAlign(Bool_t align)
402 {
403  // Sets option for alignement to geometry builder
404  
405    fGeometryBuilder->SetAlign(align);
406 }   
407
408 //____________________________________________________________________
409  void  AliMUON::SetAlign(const TString& fileName, Bool_t align)
410 {
411  // Sets option for alignement to geometry builder
412  
413    fGeometryBuilder->SetAlign(fileName, align);
414 }   
415
416 //____________________________________________________________________
417 void   AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
418 {
419 // Set the response for chamber id
420     ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
421 }
422 //____________________________________________________________________
423 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
424 {
425   // FIXME: the selection of the class should be done through a factory
426   // mechanism. (see also Hits2SDigits()).
427   
428   AliInfo(Form("Digitizer used : %s",fDigitizerType.Data()));
429   
430   if ( fDigitizerType == "digitizer:default" )
431   {
432     return new AliMUONDigitizerv2(manager);
433   }
434   else if ( fDigitizerType == "digitizer:NewDigitizerNewTrigger" ) 
435   {
436     return new AliMUONDigitizerV3(manager,AliMUONDigitizerV3::kTriggerElectronics);
437   }
438   else if ( fDigitizerType == "digitizer:NewDigitizerOldTrigger" )
439   {
440     return new AliMUONDigitizerV3(manager,AliMUONDigitizerV3::kTriggerDecision);
441   }
442   else
443   {
444     AliFatal(Form("Unknown digitizer type : %s",fDigitizerType.Data()));
445   }
446   return 0x0;
447 }
448
449 //_____________________________________________________________________
450 TString
451 AliMUON::SDigitizerType() const
452 {
453   return fSDigitizerType;
454 }
455
456 //_____________________________________________________________________
457 void AliMUON::SDigits2Digits()
458 {
459
460 // write TreeD here 
461
462     char hname[30];
463     //    sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
464     fLoader->TreeD()->Write(hname,TObject::kOverwrite);
465     fLoader->TreeD()->Reset();
466 }
467
468 //_____________________________________________________________________
469 void AliMUON::Hits2SDigits()
470 {
471   // FIXME: the selection of the sdigitizer should be done through a
472   // factory mechanism.
473   
474   AliInfo(Form("SDigitizer used : %s",fSDigitizerType.Data()));
475
476   if ( fSDigitizerType == "sdigitizer:default" )
477   {
478     // Adaption of AliMUONSDigitizerv1 to be excuted by the AliSimulation framework
479     AliRunLoader* runLoader = fLoader->GetRunLoader();
480     AliRunDigitizer   * manager = new AliRunDigitizer(1,1);
481     manager->SetInputStream(0,runLoader->GetFileName(),AliConfig::GetDefaultEventFolderName());
482     AliMUONDigitizer * dMUON   = new AliMUONSDigitizerv1(manager);
483     fLoader->LoadHits("READ");
484     for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
485       runLoader->GetEvent(iEvent);
486       dMUON->Exec("");
487     }
488     fLoader->UnloadHits();
489   }
490   else if ( fSDigitizerType == "sdigitizer:AliMUONSDigitizerV2" )
491   {
492     TTask* sdigitizer = new AliMUONSDigitizerV2;
493     sdigitizer->ExecuteTask();
494   }
495   else
496   {
497     AliFatal(Form("Unknown sdigitizer classname : %s",fSDigitizerType.Data()));
498   }
499 }
500
501 //_____________________________________________________________________
502 TString
503 AliMUON::DigitizerType() const
504 {
505   return fDigitizerType;
506 }
507
508 //_____________________________________________________________________
509 void AliMUON::Digits2Raw()
510 {
511   // convert digits of the current event to raw data
512   if (!fRawWriter)
513   {
514     fRawWriter = new AliMUONRawWriter(fMUONData);
515     if (fTriggerScalerEvent == kTRUE) 
516     {
517       fRawWriter->SetScalerEvent();
518     }
519   }
520   
521   if (!fRawWriter->Digits2Raw()) 
522   {
523     AliError("pb writting raw data");
524   }
525 }
526
527 //_______________________________________________________________________
528 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
529
530 //builds standard getter (AliLoader type)
531 //if detector wants to use castomized getter, it must overload this method
532
533  
534  AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
535          GetName(),topfoldername));
536  fLoader   = new AliLoader(GetName(),topfoldername);
537  fMUONData = new AliMUONData(fLoader,GetName(),GetName()); 
538  fMUONData->SetSplitLevel(fSplitLevel);
539  return fLoader;
540 }
541 //_______________________________________________________________________
542
543 AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
544 {
545 //
546 //  Return rawcluster (icluster) for chamber ichamber and cathode icathod
547 //  Obsolete ??
548     TClonesArray *muonRawCluster  = GetMUONData()->RawClusters(ichamber);
549     ResetRawClusters();
550     TTree *treeR = fLoader->TreeR();
551     Int_t nent=(Int_t)treeR->GetEntries();
552     treeR->GetEvent(nent-2+icathod-1);
553     //treeR->GetEvent(icathod);
554     //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
555
556     AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
557     //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
558     
559     return  mRaw;
560 }
561
562 //________________________________________________________________________
563 void
564 AliMUON::ResetGeometryBuilder()
565 {
566   // Only to be used by "experts" wanting to change the geometry builders
567   // to be used. 
568   // As the ctor of AliMUON now defines a default geometrybuilder, this
569   // ResetGeometryBuilder() must be called prior to call the 
570   // AddGeometryBuilder()
571   delete fGeometryBuilder;
572   fGeometryBuilder = new AliMUONGeometryBuilder(this);
573   fGeometryBuilder
574     ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
575 }