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