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