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