effc++ warnings corrected
[u/mrichter/AliRoot.git] / PWG0 / TPC / AliTPCRawHistograms.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 // This class contains a number of histograms for diagnostics of a TPC
19 // read out chamber from the raw data
20 //
21 // TODO:
22 //  
23 //
24 //
25
26
27 #include <TCanvas.h>
28 #include <TCollection.h>
29 #include <TFile.h>
30 #include <TH1F.h>
31 #include <TH3F.h>
32 #include <TLatex.h>
33 #include <TNtuple.h>
34 #include <TStyle.h>
35
36 #include "AliLog.h"
37 #include "AliTPCRawHistograms.h"
38 #include "AliTPCRawStream.h"
39
40 //____________________________________________________________________
41 ClassImp(AliTPCRawHistograms)
42
43 //____________________________________________________________________
44 AliTPCRawHistograms::AliTPCRawHistograms() 
45   : TNamed(),
46     fTimeStart(0),
47     fTimeStop(0),
48     fhDigits(0),
49     fhSignal(0),
50     fDigitTree(0)
51 {
52   // default constructor
53 }
54
55 //____________________________________________________________________
56 AliTPCRawHistograms::AliTPCRawHistograms(Int_t detector, const Char_t* /* comment */, Int_t timeStart, Int_t timeStop)
57   : TNamed(),
58     fTimeStart(timeStart),
59     fTimeStop(timeStop),
60     fhDigits(0),
61     fhSignal(new TH1F("fhSignal", "fhSignal", 200, 0, 2000)),
62     fDigitTree(new TNtuple("fDigitTree", "fDigitTree", "row:pad:time:signal"))
63 {
64   // constructor 
65   
66   // make name and title
67   if (detector < 0 || detector >= 72) {
68     AliDebug(AliLog::kError, Form("Detector %d does not exist", detector));
69     return;
70   }
71       
72   Int_t sector = detector%18;
73   TString side;
74   TString inout;
75   if (detector<18 || ( detector>=36 && detector<54))
76     side.Form("A");
77   else 
78     side.Form("B");
79   
80   if (detector<36)
81     inout.Form("IROC");
82   else 
83     inout.Form("OROC");
84
85   TString name;
86   name.Form("sector_%s%d_%s", side.Data(), sector, inout.Data());
87   
88   SetName(name);
89   SetTitle(Form("%s (detector %d)",name.Data(), detector));
90
91   Float_t yRange   = 45;
92   Int_t nPadRows   = 96;
93   
94   if (TString(name).Contains("IROC")) {
95     yRange = 25;
96     nPadRows = 63;
97   }
98   
99   // do not add this hists to the directory
100   Bool_t oldStatus = TH1::AddDirectoryStatus();
101   TH1::AddDirectory(kFALSE);
102
103   fhDigits = new TH3F("fhDigits", Form("signal distribution;row;pad;time", name.Data()), nPadRows, -0.5, -0.5 + nPadRows, 150, -0.5, 149.5, 100, 0, 1200);
104
105   TH1::AddDirectory(oldStatus);
106 }
107
108 //____________________________________________________________________
109 AliTPCRawHistograms::AliTPCRawHistograms(const AliTPCRawHistograms& c) : TNamed(c),
110     fTimeStart(0),
111     fTimeStop(0),
112     fhDigits(0),
113     fhSignal(0),
114     fDigitTree(0)
115 {
116   // copy constructor
117
118   ((AliTPCRawHistograms &)c).Copy(*this);
119 }
120
121 //____________________________________________________________________
122 AliTPCRawHistograms::~AliTPCRawHistograms()
123 {
124   //
125   // destructor
126   //
127
128 }
129
130 //____________________________________________________________________
131 AliTPCRawHistograms &AliTPCRawHistograms::operator=(const AliTPCRawHistograms &c)
132 {
133   // assigment operator
134
135   if (this != &c)
136     ((AliTPCRawHistograms &) c).Copy(*this);
137
138   return *this;
139 }
140
141
142 //____________________________________________________________________
143 Long64_t AliTPCRawHistograms::Merge(TCollection* list)
144 {
145   // Merge a list of AliTPCRawHistograms objects with this (needed for
146   // PROOF). 
147   // Returns the number of merged objects (including this).
148
149   if (!list)
150     return 0;
151   
152   if (list->IsEmpty())
153     return 1;
154
155   //  TIterator* iter = list->MakeIterator();
156   //  TObject* obj;
157
158    Int_t count = 0;
159
160 /*
161   // collections of measured and generated histograms
162   TList* collectionQmaxVsRow     = new TList;
163   TList* collectionQtotVsRow     = new TList;
164   TList* collectionSigmaYVsRow   = new TList;
165   TList* collectionSigmaZVsRow   = new TList;
166                                         
167   TList* collectionQmaxProfileYVsRow    = new TList;
168   TList* collectionQtotProfileYVsRow    = new TList;
169   TList* collectionSigmaYProfileYVsRow  = new TList;
170   TList* collectionSigmaZProfileYVsRow  = new TList;
171
172   TList* collectionQmaxProfileZVsRow    = new TList;
173   TList* collectionQtotProfileZVsRow    = new TList;
174   TList* collectionSigmaYProfileZVsRow  = new TList;
175   TList* collectionSigmaZProfileZVsRow  = new TList;
176
177   TList* collectionQtotVsTime  = new TList;
178   TList* collectionQmaxVsTime  = new TList;
179
180    while ((obj = iter->Next())) {
181     
182      AliTPCRawHistograms* entry = dynamic_cast<AliTPCRawHistograms*> (obj);
183      if (entry == 0) 
184        continue;
185
186      collectionQmaxVsRow          ->Add(entry->fhQmaxVsRow         );
187      collectionQtotVsRow          ->Add(entry->fhQtotVsRow         );
188      collectionSigmaYVsRow        ->Add(entry->fhSigmaYVsRow       );
189      collectionSigmaZVsRow        ->Add(entry->fhSigmaZVsRow       );
190                                                                            
191      collectionQmaxProfileYVsRow  ->Add(entry->fhQmaxProfileYVsRow );
192      collectionQtotProfileYVsRow  ->Add(entry->fhQtotProfileYVsRow );
193      collectionSigmaYProfileYVsRow->Add(entry->fhSigmaYProfileYVsRow);
194      collectionSigmaZProfileYVsRow->Add(entry->fhSigmaZProfileYVsRow);
195
196      collectionQmaxProfileZVsRow  ->Add(entry->fhQmaxProfileZVsRow );
197      collectionQtotProfileZVsRow  ->Add(entry->fhQtotProfileZVsRow );
198      collectionSigmaYProfileZVsRow->Add(entry->fhSigmaYProfileZVsRow);
199      collectionSigmaZProfileZVsRow->Add(entry->fhSigmaZProfileZVsRow);
200
201      collectionQtotVsTime->Add(entry->fhQtotVsTime);
202      collectionQmaxVsTime->Add(entry->fhQmaxVsTime);
203
204
205      count++;
206    }
207
208    fhQmaxVsRow          ->Merge(collectionQmaxVsRow       );       
209    fhQtotVsRow          ->Merge(collectionQtotVsRow       );       
210    fhSigmaYVsRow        ->Merge(collectionSigmaYVsRow     );       
211    fhSigmaZVsRow        ->Merge(collectionSigmaZVsRow     );       
212                                                                      
213    fhQmaxProfileYVsRow  ->Merge(collectionQmaxProfileYVsRow  ); 
214    fhQtotProfileYVsRow  ->Merge(collectionQtotProfileYVsRow  );
215    fhSigmaYProfileYVsRow->Merge(collectionSigmaYProfileYVsRow);
216    fhSigmaZProfileYVsRow->Merge(collectionSigmaZProfileYVsRow);
217
218    fhQmaxProfileZVsRow  ->Merge(collectionQmaxProfileZVsRow  ); 
219    fhQtotProfileZVsRow  ->Merge(collectionQtotProfileZVsRow  );
220    fhSigmaYProfileZVsRow->Merge(collectionSigmaYProfileZVsRow);
221    fhSigmaZProfileZVsRow->Merge(collectionSigmaZProfileZVsRow);
222
223    fhQtotVsTime->Merge(collectionQtotVsTime);
224    fhQmaxVsTime->Merge(collectionQmaxVsTime);
225
226    delete collectionQmaxVsRow;          
227    delete collectionQtotVsRow;  
228    delete collectionSigmaYVsRow;          
229    delete collectionSigmaZVsRow;          
230                                   
231    delete collectionQmaxProfileYVsRow;  
232    delete collectionQtotProfileYVsRow;  
233    delete collectionSigmaYProfileYVsRow;
234    delete collectionSigmaZProfileYVsRow;
235
236    delete collectionQmaxProfileZVsRow;  
237    delete collectionQtotProfileZVsRow;  
238    delete collectionSigmaYProfileZVsRow;
239    delete collectionSigmaZProfileZVsRow;
240
241    delete collectionQtotVsTime;
242    delete collectionQmaxVsTime;*/
243
244   return count+1;
245 }
246
247 //____________________________________________________________________
248 void AliTPCRawHistograms::FillDigit(AliTPCRawStream* rawStream, Int_t /*time*/) 
249 {
250   //
251   // Fills the different histograms with the information from a raw digit
252   //
253   
254   Int_t signal = rawStream->GetSignal();
255   Int_t row = rawStream->GetRow();
256   Int_t pad = rawStream->GetPad();
257   Int_t timeBin = rawStream->GetTime();
258
259   if (signal > 120)
260     fhDigits->Fill(row, pad, timeBin, signal);
261     
262   fhSignal->Fill(signal);
263   
264   fDigitTree->Fill(row, pad, timeBin, signal);
265 }
266
267 //____________________________________________________________________
268 void AliTPCRawHistograms::SaveHistograms()
269 {
270   //
271   // saves the histograms
272   //
273
274   gDirectory->mkdir(fName.Data());
275   gDirectory->cd(fName.Data());
276
277   fhDigits           ->Write();
278   fhSignal           ->Write();
279   fDigitTree->Write();
280                         
281   gDirectory->cd("../");
282 }
283
284 //____________________________________________________________________
285 TCanvas* AliTPCRawHistograms::DrawHistograms(const Char_t* /*opt*/) {
286   //
287   // Draws some histograms and save the canvas as eps and gif file.
288   //  
289
290   TCanvas* c = new TCanvas(Form("plots_%s",fName.Data()), fName.Data(), 1200, 1000);
291
292   gStyle->SetOptStat(0);
293   gStyle->SetOptFit(0);
294
295   gStyle->SetPadLeftMargin(0.05);
296
297   c->Divide(3,3);
298
299   c->Draw();  
300
301   c->cd(1);
302   
303   // this is not really a nice way to do it...
304   c->GetPad(1)->Delete();
305   
306   TLatex* name = new TLatex(0.1,0.8,fName.Data());
307   name->SetTextSize(0.02);
308   name->DrawClone();
309
310   c->cd(2);
311   fhDigits->Draw();
312
313   c->cd(3);
314   fhSignal->Draw();         
315                         
316   return c;
317 }