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