a28e4b1f6d995a0605d83255b0d08b80c8f0da48
[u/mrichter/AliRoot.git] / STEER / STEER / AliTransportMonitor.h
1 #ifndef ALI_TRANSPORTMONITOR__H
2 #define ALI_TRANSPORTMONITOR__H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 #ifndef ROOT_TNamed
7 #include "TNamed.h"
8 #endif
9
10 #include <map>
11
12 #ifndef ROOT_TStopwatch
13 #include "TStopwatch.h"
14 #endif
15
16 #ifndef ROOT_TH2F
17 #include "TH2F.h"
18 #endif
19
20 // Class that can be plugged in the simulation to monitor transport timing per 
21 // particle for each geometry volume.
22 //
23 //  andrei.gheata@cern.ch 
24
25
26
27 //______________________________________________________________________________
28 class AliTransportMonitor : public TObject {
29 public:
30   //________________________________________________________________
31   class AliTransportMonitorVol : public TNamed {
32   public:
33     //___________________________________________________
34     class AliPMonData {
35     public:
36       Int_t         fPDG;        // particle PDG
37       Double_t      fEdt;        // Energy * dt integral
38       Double_t      fTime;       // Total transport time for the particle in this volume
39       AliPMonData() : fPDG(0), fEdt(0), fTime(0) {}
40       void          Merge(AliPMonData* pdata) {fTime = 0.5*(fTime+pdata->fTime); fEdt = 0.5 * (fEdt+pdata->fEdt);}
41       virtual ~AliPMonData() {}
42       ClassDef(AliPMonData, 1)     // Basic monitoring info structure
43     };   
44     //___________________________________________________   
45     AliTransportMonitorVol();
46     virtual ~AliTransportMonitorVol();
47     
48     Int_t           GetNtypes() const {return fNtypes;}
49     void            StepInfo(Int_t    pdg,
50                              Double_t energy, 
51                              Double_t dt,
52                              Double_t x, Double_t y, Double_t z);
53     Double_t        GetTotalTime() const       {return fTotalTime;}
54     Double_t        GetTime(Int_t itype) const {return fPData[itype].fTime;}
55     Double_t        GetEmed(Int_t itype) const {return (fTotalTime>0)?fPData[itype].fEdt/fTotalTime : 0.;}
56     Int_t           GetPDG(Int_t itype)  const {return fPData[itype].fPDG;}
57     TH2F           *GetHistogram() const {return fTimeRZ;}
58     AliPMonData    *GetPMonData(Int_t itype) const {AliPMonData obj = fPData[itype]; return &obj;} 
59     void            Merge(AliTransportMonitorVol* volM);
60     private:
61       AliPMonData  &GetPMonData(Int_t pdg);
62       AliTransportMonitorVol(const AliTransportMonitorVol& other) : TNamed(other), fNtypes(0), fTotalTime(0), fPData(0), fTimeRZ(0), fParticles() {}
63       AliTransportMonitorVol &operator=(const AliTransportMonitorVol&) {return *this;}
64     private:
65       Int_t         fNtypes;     // Number of different particle types
66       Double_t      fTotalTime;  // Total time spent in this volume
67       AliPMonData  *fPData;      //[fNtypes] Array of particle data
68       TH2F         *fTimeRZ;     // Timing R-Z histogram per volume
69       typedef std::map<Int_t, Int_t>         ParticleMap_t;
70       typedef ParticleMap_t::iterator        ParticleMapIt_t;
71       ParticleMap_t fParticles;  //! Map of stored particla data  
72   
73   ClassDef(AliTransportMonitorVol,1)  // Helper to hold particle info per volume
74   };
75   //________________________________________________________________
76 private:
77   AliTransportMonitor(const AliTransportMonitor&other) : TObject(other), fTotalTime(0), fTimer(), fVolumeMon(0) {}
78   AliTransportMonitor &operator=(const AliTransportMonitor&) {return *this;}
79 public:
80   AliTransportMonitor();
81   AliTransportMonitor(Int_t nvolumes);
82   virtual ~AliTransportMonitor();
83   
84   void              StepInfo(Int_t    volId,
85                              Int_t    pdg,
86                              Double_t energy, 
87                              Double_t x, Double_t y, Double_t z);
88   void              Print(Option_t *volName="") const;
89   void              DummyStep();
90   void              Start();
91   void              Stop();
92   void              Export(const char *fname);
93   TObjArray*        GetVolumes() const {return fVolumeMon;}
94   void              Merge(AliTransportMonitor* mergeMon);
95   static AliTransportMonitor *Import(const char *fname);
96 private:
97   Double_t          fTotalTime;  // Total simulation time
98   TStopwatch        fTimer;      //! Global timer
99   TObjArray        *fVolumeMon;  // Array of monitoring objects per volume
100   
101 ClassDef(AliTransportMonitor,1)  // Class to monitor timing per volume 
102 };
103 //______________________________________________________________________________
104
105
106 #endif //ALI_TRANSPORTMONITOR__H