corrections to obey coding conventions
[u/mrichter/AliRoot.git] / MONITOR / AliMonitorTPC.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 //  This class creates and fills the monitor histograms for the TPC          //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24
25 #include "AliMonitorTPC.h"
26 #include "AliMonitorDataTPC.h"
27 #include "AliMonitorHisto.h"
28 #include "AliMonitorTrend.h"
29 #include "AliTPCParam.h"
30 #include "AliTPCRawStream.h"
31 #include "AliTPCClustersRow.h"
32 #include "AliTPCclusterMI.h"
33 #include "AliTPCtrack.h"
34 #include "AliRunLoader.h"
35 #include <TFolder.h>
36 #include <TTree.h>
37
38
39 ClassImp(AliMonitorTPC) 
40
41
42 //_____________________________________________________________________________
43 AliMonitorTPC::AliMonitorTPC(AliTPCParam* param)
44 {
45 // create a TPC monitor object with the given parameters
46
47   fParam = param;
48   fData = new AliMonitorDataTPC(10000);
49 }
50
51 //_____________________________________________________________________________
52 AliMonitorTPC::AliMonitorTPC(const AliMonitorTPC& monitor) :
53   AliMonitor(monitor)
54 {
55   Fatal("AliMonitorTPC", "copy constructor not implemented");
56 }
57
58 //_____________________________________________________________________________
59 AliMonitorTPC& AliMonitorTPC::operator = (const AliMonitorTPC& /*monitor*/)
60 {
61   Fatal("operator =", "assignment operator not implemented");
62   return *this;
63 }
64
65 //_____________________________________________________________________________
66 AliMonitorTPC::~AliMonitorTPC()
67 {
68   delete fData;
69 }
70
71
72 //_____________________________________________________________________________
73 void AliMonitorTPC::CreateHistos(TFolder* folder)
74 {
75 // create the TPC monitor histograms
76
77   fFolder = folder->AddFolder("TPC", "TPC");
78
79   fPadsCharge = CreateHisto1("PadsCharge", "charge distribution of pads", 
80                              100, 0, 200, "charge", "#Delta N/N",
81                              AliMonitorHisto::kNormEvents);
82
83   fClustersCharge = CreateHisto1("ClustersCharge", 
84                                  "charge distribution of clusters", 
85                                  100, 0, 1000, "charge", "#Delta N/N",
86                                  AliMonitorHisto::kNormEvents);
87
88   Int_t nRows = fParam->GetNRowLow() + fParam->GetNRowUp();
89   fNClustersVsRow = CreateHisto1("NClustersVsRow", 
90                                  "mean number of clusters per pad row", 
91                                  nRows, -0.5, nRows-0.5,
92                                  "pad row", "<N_{clusters}>",
93                                  AliMonitorHisto::kNormEvents);
94
95   Int_t nSector = fParam->GetNInnerSector();
96   fNClustersVsSector = CreateHisto1("NClustersVsSector", 
97                                     "mean number of clusters per sector", 
98                                     nSector, -0.5, nSector-0.5, 
99                                     "sector", "<N_{clusters}>",
100                                     AliMonitorHisto::kNormEvents);
101
102   fNTracks = CreateTrend("NTracks", "number of tracks per event", 
103                          "N_{tracks}");
104
105   fTrackPt = CreateHisto1("TrackPt", "pt distribution of tracks", 
106                           90, 0, 3, "p_{t} [GeV/c]", "#Delta N/N",
107                           AliMonitorHisto::kNormEntries);
108
109   fTrackEta = CreateHisto1("TrackEta", "eta distribution of tracks", 
110                            100, -2, 2, "#eta", "#Delta N/N",
111                            AliMonitorHisto::kNormEntries);
112
113   fTrackPhi = CreateHisto1("TrackPhi", "phi distribution of tracks", 
114                            120, 0, 360, "#phi [#circ]", "#Delta N/N",
115                            AliMonitorHisto::kNormEntries);
116   fTrackPhi->SetDescription("The phi distribution should be flat on average.\nIf it is not flat check for dead TPC sectors.");
117
118   fTrackNCl = CreateHisto1("TrackNCl", "Number of clusters per track", 
119                            200, 0, 200, "N_{clusters}", "#Delta N/N",
120                            AliMonitorHisto::kNormEntries);
121
122   fTrackDEdxVsP = CreateHisto2("TrackDEdxVsP", "dE/dx of tracks", 
123                                100, 0, 3, 100, 0, 200, 
124                                "p [GeV/c]", "dE/dx", "#Delta N/N",
125                                AliMonitorHisto::kNormEntries);
126 }
127
128
129 //_____________________________________________________________________________
130 void AliMonitorTPC::CreateBranches(TTree* tree)
131 {
132 // create a branch with TPC variables
133
134   tree->Branch("TPC", "AliMonitorDataTPC", &fData);
135 }
136
137
138 //_____________________________________________________________________________
139 void AliMonitorTPC::FillHistos(AliRunLoader* runLoader, 
140                                AliRawReader* rawReader)
141 {
142 // fill the TPC monitor histogrms
143
144   rawReader->Reset();
145   AliTPCRawStream input(rawReader);
146   while (input.Next()) {
147     fPadsCharge->Fill(input.GetSignal());
148   }
149
150   AliLoader* tpcLoader = runLoader->GetLoader("TPCLoader");
151   if (!tpcLoader) return;
152
153
154   tpcLoader->LoadRecPoints();
155   TTree* clusters = tpcLoader->TreeR();
156   if (!clusters) return;
157   AliTPCClustersRow* clustersRow = new AliTPCClustersRow;
158   clustersRow->SetClass("AliTPCclusterMI");
159   clusters->SetBranchAddress("Segment", &clustersRow);
160
161   for (Int_t i = 0; i < clusters->GetEntries(); i++) {
162     clusters->GetEntry(i);
163     Int_t iSector, iRow;
164     fParam->AdjustSectorRow(clustersRow->GetID(), iSector, iRow);
165     if (iSector >= fParam->GetNInnerSector()) {
166       iRow += fParam->GetNRowLow();
167       iSector -= fParam->GetNInnerSector();
168     }
169
170     TObjArray* array = clustersRow->GetArray();
171     for (Int_t j = 0; j < array->GetEntriesFast(); j++) {
172       AliTPCclusterMI* cluster = (AliTPCclusterMI*) array->At(j);
173       fClustersCharge->Fill(cluster->GetQ());
174       fNClustersVsRow->Fill(iRow);
175       fNClustersVsSector->Fill(iSector);
176     }
177   }
178   fNClustersVsSector->ScaleErrorBy(10.);
179
180   delete clustersRow;
181   tpcLoader->UnloadRecPoints();
182
183
184   tpcLoader->LoadTracks();
185   TTree* tracks = tpcLoader->TreeT();
186   if (!tracks) return;
187   AliTPCtrack* track = new AliTPCtrack;
188   tracks->SetBranchAddress("tracks", &track);
189
190   Int_t nTracks = (Int_t) tracks->GetEntries();
191   fNTracks->Fill(nTracks);
192   fData->SetNTracks(nTracks);
193   for (Int_t i = 0; i < nTracks; i++) {
194     tracks->GetEntry(i);
195     fTrackPt->Fill(track->Pt());
196     fTrackEta->Fill(track->Eta());
197     fTrackPhi->Fill(track->Phi() * TMath::RadToDeg());
198     fTrackNCl->Fill(track->GetNumberOfClusters());
199     fTrackDEdxVsP->Fill(track->P(), track->GetdEdx());
200
201     fData->SetData(i, track->Pt(), track->Eta(), 
202                    track->Phi() * TMath::RadToDeg());
203   }
204
205   delete track;
206   tpcLoader->UnloadTracks();
207 }