]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUON.cxx
Added two data members fSDigitizerType, fDigitizerType to be able to change
[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 // Defaults parameters for Z positions of chambers
76 // taken from values for "stations" in AliMUON::AliMUON
77 //     const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
78 // and from array "dstation" in AliMUONv1::CreateGeometry
79 //          Float_t dstation[5]={20., 20., 20, 20., 20.};
80 //     for tracking chambers,
81 //          according to (Z1 = zch - dstation) and  (Z2 = zch + dstation)
82 //          for the first and second chambers in the station, respectively,
83 // and from "DTPLANES" in AliMUONv1::CreateGeometry
84 //           const Float_t DTPLANES = 15.;
85 //     for trigger chambers,
86 //          according to (Z1 = zch) and  (Z2 = zch + DTPLANES)
87 //          for the first and second chambers in the station, respectively
88
89 ClassImp(AliMUON)
90
91 //__________________________________________________________________
92 AliMUON::AliMUON()
93   : AliDetector(),
94     fNCh(0),
95     fNTrackingCh(0),
96     fMUONData(0),
97     fSplitLevel(0),
98     fChambers(0),
99     fTriggerCircuits(0),
100     fGeometryBuilder(0),
101     fSegmentation(0),
102     fAccCut(kFALSE),
103     fAccMin(0.),
104     fAccMax(0.),   
105     fMaxStepGas(0.),
106     fMaxStepAlu(0.),
107     fMaxDestepGas(0.),
108     fMaxDestepAlu(0.),
109     fMaxIterPad(0),
110     fCurIterPad(0),
111     fTriggerScalerEvent(kFALSE),
112     fSDigitizerType(""),
113     fDigitizerType("")
114 {
115 // Default Constructor
116 //
117         AliDebug(1,Form("default (empty) ctor this=%p",this));
118     fIshunt          = 0;
119 }
120
121 //__________________________________________________________________
122 AliMUON::AliMUON(const char *name, const char *title,
123                  const char* sDigitizerClassName,
124                  const char* digitizerClassName)
125   : AliDetector(name,title),
126     fNCh(AliMUONConstants::NCh()),
127     fNTrackingCh(AliMUONConstants::NTrackingCh()),
128     fMUONData(0),
129     fSplitLevel(0),
130     fChambers(0),
131     fTriggerCircuits(0),
132     fGeometryBuilder(0),
133     fSegmentation(0),
134     fAccCut(kFALSE),
135     fAccMin(0.),
136     fAccMax(0.),   
137     fMaxStepGas(0.1),
138     fMaxStepAlu(0.1),
139     fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200 
140     fMaxDestepAlu(-1), // in the calculation of the tracking parameters
141     fMaxIterPad(0),
142     fCurIterPad(0),
143           fTriggerScalerEvent(kFALSE),
144     fSDigitizerType(sDigitizerClassName),
145     fDigitizerType(digitizerClassName)
146 {
147         AliDebug(1,Form("ctor this=%p",this));
148   fIshunt =  0;
149
150   SetMarkerColor(kRed);//
151     
152   // Geometry builder
153   fGeometryBuilder = new AliMUONGeometryBuilder(this);
154   
155   // Common geometry definitions
156   fGeometryBuilder
157     ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
158
159 //
160 // Creating List of Chambers
161     Int_t ch;
162     fChambers = new TObjArray(AliMUONConstants::NCh());
163
164     // Loop over stations
165     for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
166       // Loop over 2 chambers in the station
167       for (Int_t stCH = 0; stCH < 2; stCH++) {
168         //
169         //    
170         //    Default Parameters for Muon Tracking Stations
171         ch = 2 * st + stCH;
172         if (ch < AliMUONConstants::NTrackingCh()) {
173           fChambers->AddAt(new AliMUONChamber(ch),ch);
174         } else {
175           fChambers->AddAt(new AliMUONChamberTrigger(ch, GetGeometryTransformer()),ch);
176         }
177       } // Chamber stCH (0, 1) in 
178     }     // Station st (0...)
179     
180     // cp new design of AliMUONTriggerDecision
181     fTriggerCircuits = new TObjArray(AliMUONConstants::NTriggerCircuit());
182     for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
183       fTriggerCircuits->AddAt(new AliMUONTriggerCircuit(),circ);          
184     }
185 }
186
187 //____________________________________________________________________
188 AliMUON::AliMUON(const AliMUON& rMUON)
189  : AliDetector(rMUON)
190 {
191 // Protected copy constructor
192
193   AliFatal("Not implemented.");
194 }
195
196 //____________________________________________________________________
197 AliMUON::~AliMUON()
198 {
199 // Destructor
200   AliDebug(1,Form("dtor this=%p",this));
201   fIshunt  = 0;
202
203   if (fChambers){
204     fChambers->Delete();
205     delete fChambers;
206   }
207   if (fTriggerCircuits){
208     fTriggerCircuits->Delete();
209     delete fTriggerCircuits;
210   }
211   delete fMUONData;
212   delete fGeometryBuilder;
213   delete fSegmentation;
214 }
215
216 //________________________________________________________________________
217 AliMUON& AliMUON::operator = (const AliMUON& rhs)
218 {
219 // Protected assignement operator
220
221   if (this == &rhs) return *this;
222
223   AliFatal("Not implemented.");
224     
225   return *this;  
226 }
227
228 //_____________________________________________________________________________
229 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
230 {
231 // Adds the geometry builder to the list
232 // ---
233
234   fGeometryBuilder->AddBuilder(geomBuilder);
235 }
236
237 //____________________________________________________________________
238 void AliMUON::BuildGeometry()
239 {
240 // Geometry for event display
241
242
243 //     for (Int_t i = 0; i < AliMUONConstants::NCh(); i++)     
244 //       this->Chamber(i).SegmentationModel2(1)->Draw("eventdisplay");// to be check !
245      
246   
247 }
248
249 //____________________________________________________________________
250 const AliMUONGeometry*  AliMUON::GetGeometry() const
251 {
252 // Return geometry parametrisation
253
254   if ( !fGeometryBuilder) {
255     AliWarningStream() << "GeometryBuilder not defined." << std::endl;
256     return 0;
257   }
258   
259   return fGeometryBuilder->GetGeometry();
260 }   
261
262 //____________________________________________________________________
263 const AliMUONGeometryTransformer*  AliMUON::GetGeometryTransformer() const
264 {
265 // Return geometry parametrisation
266
267   const AliMUONGeometry* kGeometry = GetGeometry();
268   
269   if ( !kGeometry) return 0;
270
271   return kGeometry->GetTransformer();
272 }   
273
274 //__________________________________________________________________
275 void  AliMUON::SetTreeAddress()
276 {
277   GetMUONData()->SetLoader(fLoader); 
278   //  GetMUONData()->MakeBranch("D,S,RC");
279   //  GetMUONData()->SetTreeAddress("H,D,S,RC");
280   GetMUONData()->SetTreeAddress("H");
281   if (fHits !=  GetMUONData()->Hits())  {
282     if ( gAlice->GetMCApp() )
283       if ( gAlice->GetMCApp()->GetHitLists() ) {
284         fHits = GetMUONData()->Hits();
285         gAlice->GetMCApp()->AddHitList(fHits); // For purifyKine, only necessary when Hit list is created in AliMUONData
286       }  
287   }
288   fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector    
289 }
290
291 //_________________________________________________________________
292 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
293 {
294 // Set the inverse charge slope for chamber id
295     Int_t i=2*(id-1);    //PH    ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
296     //PH    ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
297     ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
298     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
299 }
300 //__________________________________________________________________
301 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
302 {
303 // Set sigma of charge spread for chamber id
304     Int_t i=2*(id-1);
305     ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
306     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
307 }
308 //___________________________________________________________________
309 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
310 {
311 // Set integration limits for charge spread
312     Int_t i=2*(id-1);
313     ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
314     ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
315 }
316
317 //__________________________________________________________________
318 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
319 {
320 // Set maximum number for ADCcounts (saturation)
321     Int_t i=2*(id-1);
322     ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
323     ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
324 }
325
326 //__________________________________________________________________
327 void AliMUON::SetMaxStepGas(Float_t p1)
328 {
329 // Set stepsize in gas
330   fMaxStepGas=p1;
331 }
332 //__________________________________________________________________
333 void AliMUON::SetMaxStepAlu(Float_t p1)
334 {
335 // Set step size in Alu
336     fMaxStepAlu=p1;
337 }
338 //__________________________________________________________________
339 void AliMUON::SetMaxDestepGas(Float_t p1)
340 {
341 // Set maximum step size in Gas
342     fMaxDestepGas=p1;
343 }
344 //__________________________________________________________________
345 void AliMUON::SetMaxDestepAlu(Float_t p1)
346 {
347 // Set maximum step size in Alu
348   fMaxDestepAlu=p1;
349 }
350
351 //____________________________________________________________________
352 Float_t  AliMUON::GetMaxStepGas() const
353 {
354 // Return stepsize in gas
355   
356   return fMaxStepGas;
357 }  
358
359 //____________________________________________________________________
360 Float_t  AliMUON::GetMaxStepAlu() const
361 {
362 // Return step size in Alu
363   
364   return fMaxStepAlu;
365 }
366   
367 //____________________________________________________________________
368 Float_t  AliMUON::GetMaxDestepGas() const
369 {
370 // Return maximum step size in Gas
371   
372   return fMaxDestepGas;
373 }
374   
375 //____________________________________________________________________
376 Float_t  AliMUON::GetMaxDestepAlu() const
377 {
378 // Return maximum step size in Gas
379   
380   return fMaxDestepAlu;
381 }
382
383 //____________________________________________________________________
384  void  AliMUON::SetAlign(Bool_t align)
385 {
386  // Sets option for alignement to geometry builder
387  
388    fGeometryBuilder->SetAlign(align);
389 }   
390
391 //____________________________________________________________________
392  void  AliMUON::SetAlign(const TString& fileName, Bool_t align)
393 {
394  // Sets option for alignement to geometry builder
395  
396    fGeometryBuilder->SetAlign(fileName, align);
397 }   
398
399 //____________________________________________________________________
400 void   AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
401 {
402 // Set the response for chamber id
403     ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
404 }
405 //____________________________________________________________________
406 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
407 {
408   // FIXME: the selection of the class should be done through a factory
409   // mechanism. (see also Hits2SDigits()).
410   
411   AliInfo(Form("Digitizer used : %s",fDigitizerType.Data()));
412   
413   if ( fDigitizerType == "digitizer:default" )
414   {
415     return new AliMUONDigitizerv2(manager);
416   }
417   else if ( fDigitizerType == "digitizer:NewDigitizerNewTrigger" ) 
418   {
419     return new AliMUONDigitizerV3(manager,AliMUONDigitizerV3::kTriggerElectronics);
420   }
421   else if ( fDigitizerType == "digitizer:NewDigitizerOldTrigger" )
422   {
423     return new AliMUONDigitizerV3(manager,AliMUONDigitizerV3::kTriggerDecision);
424   }
425   else
426   {
427     AliFatal(Form("Unknown digitizer type : %s",fDigitizerType.Data()));
428   }
429   return 0x0;
430 }
431
432 //_____________________________________________________________________
433 TString
434 AliMUON::SDigitizerType() const
435 {
436   return fSDigitizerType;
437 }
438
439 //_____________________________________________________________________
440 void AliMUON::SDigits2Digits()
441 {
442
443 // write TreeD here 
444
445     char hname[30];
446     //    sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
447     fLoader->TreeD()->Write(hname,TObject::kOverwrite);
448     fLoader->TreeD()->Reset();
449 }
450
451 //_____________________________________________________________________
452 void AliMUON::Hits2SDigits()
453 {
454   // FIXME: the selection of the sdigitizer should be done through a
455   // factory mechanism.
456   
457   AliInfo(Form("SDigitizer used : %s",fSDigitizerType.Data()));
458
459   if ( fSDigitizerType == "sdigitizer:default" )
460   {
461     // Adaption of AliMUONSDigitizerv1 to be excuted by the AliSimulation framework
462     AliRunLoader* runLoader = fLoader->GetRunLoader();
463     AliRunDigitizer   * manager = new AliRunDigitizer(1,1);
464     manager->SetInputStream(0,runLoader->GetFileName(),AliConfig::GetDefaultEventFolderName());
465     AliMUONDigitizer * dMUON   = new AliMUONSDigitizerv1(manager);
466     fLoader->LoadHits("READ");
467     for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
468       runLoader->GetEvent(iEvent);
469       dMUON->Exec("");
470     }
471     fLoader->UnloadHits();
472   }
473   else if ( fSDigitizerType == "sdigitizer:AliMUONSDigitizerV2" )
474   {
475     TTask* sdigitizer = new AliMUONSDigitizerV2;
476     sdigitizer->ExecuteTask();
477   }
478   else
479   {
480     AliFatal(Form("Unknown sdigitizer classname : %s",fSDigitizerType.Data()));
481   }
482 }
483
484 //_____________________________________________________________________
485 TString
486 AliMUON::DigitizerType() const
487 {
488   return fDigitizerType;
489 }
490
491 //_____________________________________________________________________
492 void AliMUON::Digits2Raw()
493 {
494   // convert digits of the current event to raw data
495   AliMUONRawWriter rawData(fLoader,fMUONData);
496
497   if (fTriggerScalerEvent == kTRUE) rawData.SetScalerEvent();
498   if (!rawData.Digits2Raw()) AliInfo("pb writting raw data");
499 }
500
501 //_______________________________________________________________________
502 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
503
504 //builds standard getter (AliLoader type)
505 //if detector wants to use castomized getter, it must overload this method
506
507  
508  AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
509          GetName(),topfoldername));
510  fLoader   = new AliLoader(GetName(),topfoldername);
511  fMUONData = new AliMUONData(fLoader,GetName(),GetName()); 
512  fMUONData->SetSplitLevel(fSplitLevel);
513  return fLoader;
514 }
515 //_______________________________________________________________________
516
517 AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
518 {
519 //
520 //  Return rawcluster (icluster) for chamber ichamber and cathode icathod
521 //  Obsolete ??
522     TClonesArray *muonRawCluster  = GetMUONData()->RawClusters(ichamber);
523     ResetRawClusters();
524     TTree *treeR = fLoader->TreeR();
525     Int_t nent=(Int_t)treeR->GetEntries();
526     treeR->GetEvent(nent-2+icathod-1);
527     //treeR->GetEvent(icathod);
528     //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
529
530     AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
531     //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
532     
533     return  mRaw;
534 }
535 //________________________________________________________________________
536