Added possibility to monitor performance in simulation with respect to geometry and...
[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 // Class that can be plugged in the simulation to monitor transport timing per 
17 // particle for each geometry volume.
18 //
19 //  andrei.gheata@cern.ch 
20
21 class TH2F;
22
23
24 //______________________________________________________________________________
25 class AliTransportMonitor : public TObject {
26 public:
27   //________________________________________________________________
28   class AliTransportMonitorVol : public TNamed {
29   public:
30     //___________________________________________________
31     class AliPMonData {
32     public:
33       Int_t         fPDG;        // particle PDG
34       Double_t      fEdt;        // Energy * dt integral
35       Double_t      fTime;       // Total transport time for the particle in this volume
36       AliPMonData() : fPDG(0), fEdt(0), fTime(0) {}
37       virtual ~AliPMonData() {}
38       ClassDef(AliPMonData, 1)     // Basic monitoring info structure
39     };   
40     //___________________________________________________   
41     AliTransportMonitorVol();
42     virtual ~AliTransportMonitorVol();
43     
44     Int_t           GetNtypes() const {return fNtypes;}
45     void            StepInfo(Int_t    pdg,
46                              Double_t energy, 
47                              Double_t dt,
48                              Double_t x, Double_t y, Double_t z);
49     Double_t        GetTotalTime() const       {return fTotalTime;}
50     Double_t        GetTime(Int_t itype) const {return fPData[itype].fTime;}
51     Double_t        GetEmed(Int_t itype) const {return (fTotalTime>0)?fPData[itype].fEdt/fTotalTime : 0.;}
52     Int_t           GetPDG(Int_t itype)  const {return fPData[itype].fPDG;}
53     TH2F           *GetHistogram() const {return fTimeRZ;}
54     private:
55       AliPMonData  &GetPMonData(Int_t pdg);
56       AliTransportMonitorVol(const AliTransportMonitorVol& other) : TNamed(other), fNtypes(0), fTotalTime(0), fPData(0), fTimeRZ(0), fParticles() {}
57       AliTransportMonitorVol &operator=(const AliTransportMonitorVol&) {return *this;}
58     private:
59       Int_t         fNtypes;     // Number of different particle types
60       Double_t      fTotalTime;  // Total time spent in this volume
61       AliPMonData  *fPData;      //[fNtypes] Array of particle data
62       TH2F         *fTimeRZ;     // Timing R-Z histogram per volume
63       typedef std::map<Int_t, Int_t>         ParticleMap_t;
64       typedef ParticleMap_t::iterator        ParticleMapIt_t;
65       ParticleMap_t fParticles;  //! Map of stored particla data  
66   
67   ClassDef(AliTransportMonitorVol,1)  // Helper to hold particle info per volume
68   };
69   //________________________________________________________________
70 private:
71   AliTransportMonitor(const AliTransportMonitor&other) : TObject(other), fTotalTime(0), fTimer(), fVolumeMon(0) {}
72   AliTransportMonitor &operator=(const AliTransportMonitor&) {return *this;}
73 public:
74   AliTransportMonitor();
75   AliTransportMonitor(Int_t nvolumes);
76   virtual ~AliTransportMonitor();
77   
78   void              StepInfo(Int_t    volId,
79                              Int_t    pdg,
80                              Double_t energy, 
81                              Double_t x, Double_t y, Double_t z);
82   void              Print(Option_t *volName="") const;
83   void              DummyStep();
84   void              Start();
85   void              Stop();
86   void              Export(const char *fname);
87   static AliTransportMonitor *Import(const char *fname);
88 private:
89   Double_t          fTotalTime;  // Total simulation time
90   TStopwatch        fTimer;      //! Global timer
91   TObjArray        *fVolumeMon;  // Array of monitoring objects per volume
92   
93 ClassDef(AliTransportMonitor,1)  // Class to monitor timing per volume 
94 };
95 //______________________________________________________________________________
96
97
98 #endif //ALI_TRANSPORTMONITOR__H