]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCMonitor.cxx
Updated Laser survey meaauserments
[u/mrichter/AliRoot.git] / TPC / AliTPCMonitor.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 /*
17 $Log$
18 Revision 1.3  2007/10/12 13:36:27  cvetan
19 Coding convention fixes from Stefan
20
21 Revision 1.2  2007/09/18 09:44:45  cvetan
22 Sorting out some issues concerning the compilation with and without DATE support
23
24 Revision 1.1  2007/09/17 10:23:31  cvetan
25 New TPC monitoring package from Stefan Kniege. The monitoring package can be started by running TPCMonitor.C macro located in macros folder.
26
27 */   
28
29 ////////////////////////////////////////////////////////////////////////
30 ////
31 //// AliTPCMonitor class
32 //// 
33 //// Main class for TPC Monitor
34 //// Monitor can handle rootified data, files and online streams in DATE format.
35 //// The monitor GUI is started by the macro TPCMonitor.C
36 //// 
37 //// In the The data are read in in two read cycles. 
38 //// If no sector is specified (sectorid==-1) all sectors are read and only the max value 
39 //// for each channel is stored in a global histogram for Side A and C.
40 //// In this way the whole TPC can be read in at once.
41 ////
42 //// If the sector is specified  only one sector is read in and additional quantities
43 //// e.g baseline and baseline rms are calculated and stored. 
44 //// 
45 //// Author: Stefan Kniege, IKF, Frankfurt
46 ////       
47 ////
48 /////////////////////////////////////////////////////////////////////////
49
50
51
52 #include "AliLog.h"
53 #include "AliTPCMonitor.h"   
54 #include "AliTPCMonitorMappingHandler.h"
55 #include "AliTPCMonitorFFT.h"
56 #include "AliRawReader.h"
57 #include "AliRawReaderRoot.h"
58 #include "AliRawEventHeaderBase.h"
59 #include "AliAltroRawStreamV3.h"
60 #include "TH2F.h" 
61 #include "TF1.h"
62 #include "TMath.h"
63 #include "TCanvas.h"
64 #include "TH3S.h"
65 #include "TLegend.h"
66 #include "TROOT.h" 
67 #include "TDirectory.h"
68 #include "TSystem.h"
69 #include "TPaveText.h"   
70 #include "TFile.h"
71 #include <Riostream.h>
72
73 ClassImp(AliTPCMonitor)
74
75 const Int_t AliTPCMonitor::fgkHwMaskFEC              = 0x0780;                          
76 const Int_t AliTPCMonitor::fgkHwMaskBranch           = 0x0800;                          
77 const Int_t AliTPCMonitor::fgkHwMaskFECChannel       = 0x007f;                          
78 const Int_t AliTPCMonitor::fgkHwMaskAltroChannel     = 0x000f;                          
79 const Int_t AliTPCMonitor::fgkHwMaskAltroChip        = 0x0070;                          
80 const Int_t AliTPCMonitor::fgkHwMaskRCU              = 0x7000;                          
81
82 //____________________________________________________________________________
83 AliTPCMonitor::AliTPCMonitor(char* name, char* title) : 
84 AliTPCMonitorConfig(name,title),
85 fPad(new Int_t*[GetMaxHwAddr()]),
86 fPadMapHw(new Float_t[GetMaxHwAddr()]),
87 fPadMapRCU(new Int_t*[GetMaxHwAddr()]),
88 fHistIROC(0),
89 fHistOROC(0),
90 fHistIROCIndex(0),
91 fHistOROCIndex(0),
92 fHistIROCTime(0),
93 fHistOROCTime(0),
94 fHistIROCClone(0),
95 fHistOROCClone(0),
96 fHistIROCRMS(0),
97 fHistOROCRMS(0),
98 fHistIROCBASE(0),
99 fHistOROCBASE(0),
100 fHistIROCSUM(0),
101 fHistOROCSUM(0),
102 fHistChannelTime(0),
103 fHistAddrMapIndex(0),
104 fHistAddrMaxAdc(0),
105 fHistAddrBaseMean(0),
106 fHistAddrMaxAdcX(0),
107 fHistAddrAdcSum(0),
108 fHistAddrBaseRms(0),
109 fHistDistrSumIROC(0),
110 fHistDistrMaxIROC(0),
111 fHistDistrSumOROC(0),
112 fHistDistrMaxOROC(0),
113 fHistDistrBase2dIROC(0),
114 fHistDistrBase2dOROC(0),
115 fHistDistrBaseRmsIROC(0),
116 fHistDistrBaseMeanIROC(0),
117 fHistDistrBaseRmsOROC(0),
118 fHistDistrBaseMeanOROC(0),
119 fHistGlobalMaxA(0),
120 fHistGlobalMaxC(0),
121 fHistList(new TObjArray()),
122
123 fkNRowsIroc(63),
124 fkNRowsOroc(96),
125
126 fkNPadsIroc(110),
127 fkNPadsOroc(140),
128 fkNPadMinIroc(-55),
129 fkNPadMinOroc(-70),
130 fkNPadMaxIroc(55),
131 fkNPadMaxOroc(70),
132 fVerb(0),
133 fLastEv(0),
134 fEventNumber(0),
135 fEventNumberOld(0),
136 fDisableFit(0),
137 fExecGlob(0),
138 fExecPlaneMax(0),
139 fExecPadIrocRms(0),
140 fExecPadOrocRms(0),
141 fRunId(0),
142 fEqId(0),
143 fPadUsedRoc(-1),
144 fPadUsedHwAddr(-1),
145 fGdcId(0),
146 fLdcId(0),
147 fLdcIdOld(1),
148 fMapEqidsSec(new Int_t*[36]),
149 fMapEqidsRcu(new Int_t[1000]),
150 fMirror(1),
151 fChannelIter(0),
152 fMapHand(0),
153 fRawReader(0)
154 {
155   // Constructor
156   
157   for(Int_t i = 0; i<GetMaxHwAddr(); i++) { fPad[i]       = new Int_t[GetTimeBins()];}
158   for(Int_t i = 0; i<GetMaxHwAddr(); i++) { fPadMapRCU[i] = new Int_t[6];}
159   for(Int_t i = 0; i<36; i++) { fMapEqidsSec[i]       = new Int_t[6];}
160   
161   if (gDirectory)
162   {
163     if (!gDirectory->GetList())
164     {
165       Warning("Build","Current directory is not a valid directory");
166       return;
167     }
168     AliTPCMonitor *hold = (AliTPCMonitor*)gDirectory->GetList()->FindObject(GetName());
169     if(hold)
170     {
171       Warning("Build","Replacing existing histogram: %s (Potential memory leak).",GetName());
172       gDirectory->GetList()->Remove(hold);
173     }
174     gDirectory->Append(this);
175   }
176   CreateHistos();
177   SetEqIds();
178   
179 }
180
181 //____________________________________________________________________________
182 AliTPCMonitor::AliTPCMonitor(const AliTPCMonitor &monitor):
183 AliTPCMonitorConfig(monitor.GetName(),monitor.GetTitle()),
184 fPad(new Int_t*[GetMaxHwAddr()]),
185 fPadMapHw(new Float_t[GetMaxHwAddr()]),
186 fPadMapRCU(new Int_t*[GetMaxHwAddr()]),
187 fHistIROC(0),
188 fHistOROC(0),
189 fHistIROCIndex(0),
190 fHistOROCIndex(0),
191 fHistIROCTime(0),
192 fHistOROCTime(0),
193 fHistIROCClone(0),
194 fHistOROCClone(0),
195 fHistIROCRMS(0),
196 fHistOROCRMS(0),
197 fHistIROCBASE(0),
198 fHistOROCBASE(0),
199 fHistIROCSUM(0),
200 fHistOROCSUM(0),
201 fHistChannelTime(0),
202 fHistAddrMapIndex(0),
203 fHistAddrMaxAdc(0),
204 fHistAddrBaseMean(0),
205 fHistAddrMaxAdcX(0),
206 fHistAddrAdcSum(0),
207 fHistAddrBaseRms(0),
208 fHistDistrSumIROC(0),
209 fHistDistrMaxIROC(0),
210 fHistDistrSumOROC(0),
211 fHistDistrMaxOROC(0),
212 fHistDistrBase2dIROC(0),
213 fHistDistrBase2dOROC(0),
214 fHistDistrBaseRmsIROC(0),
215 fHistDistrBaseMeanIROC(0),
216 fHistDistrBaseRmsOROC(0),
217 fHistDistrBaseMeanOROC(0),
218 fHistGlobalMaxA(0),
219 fHistGlobalMaxC(0),
220 fHistList(new TObjArray()),
221 fkNRowsIroc(monitor.fkNRowsIroc),
222 fkNRowsOroc(monitor.fkNRowsOroc),
223 fkNPadsIroc(monitor.fkNPadsIroc),
224 fkNPadsOroc(monitor.fkNPadsOroc),
225 fkNPadMinIroc(monitor.fkNPadMinIroc),
226 fkNPadMinOroc(monitor.fkNPadMinOroc),
227 fkNPadMaxIroc(monitor.fkNPadMaxIroc),
228 fkNPadMaxOroc(monitor.fkNPadMaxOroc),
229 fVerb(monitor.fVerb),
230 fLastEv(monitor.fLastEv),
231 fEventNumber(monitor.fEventNumber),
232 fEventNumberOld(monitor.fEventNumberOld),
233 fDisableFit(monitor.fDisableFit),
234 fExecGlob(monitor.fExecGlob),
235 fExecPlaneMax(monitor.fExecPlaneMax),
236 fExecPadIrocRms(monitor.fExecPadIrocRms),
237 fExecPadOrocRms(monitor.fExecPadOrocRms),
238 fRunId(monitor.fRunId),
239 fEqId(monitor.fEqId),
240 fPadUsedRoc(monitor.fPadUsedRoc),
241 fPadUsedHwAddr(monitor.fPadUsedHwAddr),
242 fGdcId(monitor.fGdcId),
243 fLdcId(monitor.fLdcId),
244 fLdcIdOld(monitor.fLdcIdOld),
245 fMapEqidsSec(new Int_t*[36]),
246 fMapEqidsRcu(new Int_t[1000]),
247 fMirror(monitor.fMirror),
248 fChannelIter(monitor.fChannelIter),
249 fMapHand(monitor.fMapHand),
250 fRawReader(monitor.fRawReader)
251 {
252   // copy constructor
253   
254   fHistIROC=(TH2F*)monitor.fHistIROC->Clone(); fHistList->Add(fHistIROC);
255   fHistOROC=(TH2F*)monitor.fHistOROC->Clone(); fHistList->Add(fHistOROC);
256   fHistIROCIndex=(TH2S*)monitor.fHistIROCIndex->Clone(); fHistList->Add(fHistIROCIndex);
257   fHistOROCIndex=(TH2S*)monitor.fHistOROCIndex->Clone(); fHistList->Add(fHistOROCIndex);
258   fHistIROCTime=(TH2F*)monitor.fHistIROCTime->Clone(); fHistList->Add(fHistIROCTime);
259   fHistOROCTime=(TH2F*)monitor.fHistOROCTime->Clone(); fHistList->Add(fHistOROCTime);
260   fHistIROCClone=(TH2F*)monitor.fHistIROCClone->Clone(); fHistList->Add(fHistIROCClone);
261   fHistOROCClone=(TH2F*)monitor.fHistOROCClone->Clone(); fHistList->Add(fHistOROCClone);
262   fHistIROCRMS=(TH2F*)monitor.fHistIROCRMS->Clone(); fHistList->Add(fHistIROCRMS);
263   fHistOROCRMS=(TH2F*)monitor.fHistOROCRMS->Clone(); fHistList->Add(fHistOROCRMS);
264   fHistIROCBASE=(TH2F*)monitor.fHistIROCBASE->Clone(); fHistList->Add(fHistIROCBASE);
265   fHistOROCBASE=(TH2F*)monitor.fHistOROCBASE->Clone(); fHistList->Add(fHistOROCBASE);
266   fHistIROCSUM=(TH2F*)monitor.fHistIROCSUM->Clone(); fHistList->Add(fHistIROCSUM);
267   fHistOROCSUM=(TH2F*)monitor.fHistOROCSUM->Clone(); fHistList->Add(fHistOROCSUM);
268   
269   fHistChannelTime=(TH2F*)monitor.fHistChannelTime->Clone(); fHistList->Add(fHistChannelTime);
270   
271   fHistAddrMapIndex=(TH1F*)monitor.fHistAddrMapIndex->Clone(); fHistList->Add(fHistAddrMapIndex);
272   fHistAddrMaxAdc=(TH1F*)monitor.fHistAddrMaxAdc->Clone(); fHistList->Add(fHistAddrMaxAdc);
273   fHistAddrBaseMean=(TH1F*)monitor.fHistAddrBaseMean->Clone(); fHistList->Add(fHistAddrBaseMean);
274   fHistAddrMaxAdcX=(TH1F*)monitor.fHistAddrMaxAdcX->Clone(); fHistList->Add(fHistAddrMaxAdcX);
275   fHistAddrAdcSum=(TH1F*)monitor.fHistAddrAdcSum->Clone(); fHistList->Add(fHistAddrAdcSum);
276   fHistAddrBaseRms=(TH1F*)monitor.fHistAddrBaseRms->Clone(); fHistList->Add(fHistAddrBaseRms);
277   
278   
279   fHistDistrSumIROC=(TH1F*)monitor.fHistDistrSumIROC->Clone(); fHistList->Add(fHistDistrSumIROC);
280   fHistDistrMaxIROC=(TH1F*)monitor.fHistDistrMaxIROC->Clone(); fHistList->Add(fHistDistrMaxIROC);
281   fHistDistrSumOROC=(TH1F*)monitor.fHistDistrSumOROC->Clone(); fHistList->Add(fHistDistrSumOROC);
282   fHistDistrMaxOROC=(TH1F*)monitor.fHistDistrMaxOROC->Clone(); fHistList->Add(fHistDistrMaxOROC);
283   
284   fHistDistrBase2dIROC=(TH2F*)monitor.fHistDistrBase2dIROC->Clone(); fHistList->Add(fHistDistrBase2dIROC);
285   fHistDistrBase2dOROC=(TH2F*)monitor.fHistDistrBase2dOROC->Clone(); fHistList->Add(fHistDistrBase2dOROC);
286   fHistDistrBaseRmsIROC=(TH1D*)monitor.fHistDistrBaseRmsIROC->Clone(); fHistList->Add(fHistDistrBaseRmsIROC);
287   fHistDistrBaseMeanIROC=(TH1D*)monitor.fHistDistrBaseMeanIROC->Clone(); fHistList->Add(fHistDistrBaseMeanIROC);
288   fHistDistrBaseRmsOROC=(TH1D*)monitor.fHistDistrBaseRmsOROC->Clone(); fHistList->Add(fHistDistrBaseRmsOROC);
289   fHistDistrBaseMeanOROC=(TH1D*)monitor.fHistDistrBaseMeanOROC->Clone(); fHistList->Add(fHistDistrBaseMeanOROC);
290   
291   fHistGlobalMaxA=(TH2S*)monitor.fHistGlobalMaxA->Clone(); fHistList->Add(fHistGlobalMaxA);
292   fHistGlobalMaxC=(TH2S*)monitor.fHistGlobalMaxC->Clone(); fHistList->Add(fHistGlobalMaxC);
293   
294   // fPad       = new Int_t*[monitor.GetMaxHwAddr()];
295   for(Int_t i = 0; i<GetMaxHwAddr(); i++) { fPad[i]       = new Int_t[monitor.GetTimeBins()];}
296   
297   //fPadMapRCU = new Int_t*[monitor.GetMaxHwAddr()];
298   for(Int_t i = 0; i<monitor.GetMaxHwAddr(); i++) { fPadMapRCU[i] = new Int_t[6];}
299   
300   //fPadMapHw  = new Float_t[monitor.GetMaxHwAddr()];
301   
302   //fMapEqidsRcu   = new Int_t[1000];
303   //fMapEqidsSec   = new Int_t*[36];
304   for(Int_t i = 0; i<36; i++) { fMapEqidsSec[i]       = new Int_t[6];}
305   SetEqIds();
306   
307   if (gDirectory)
308   {
309     if (!gDirectory->GetList())
310     {
311       Warning("Build","Current directory is not a valid directory");
312       
313     }
314     else
315     {
316       AliTPCMonitor *hold = (AliTPCMonitor*)gDirectory->GetList()->FindObject(monitor.GetName());
317       if(hold)
318       {
319         Warning("Build","Replacing existing histogram: %s (Potential memory leak).",monitor.GetName());
320         gDirectory->GetList()->Remove(hold);
321       }
322       gDirectory->Append(this);
323     }
324   }
325 }
326
327
328 //____________________________________________________________________________
329
330 AliTPCMonitor &AliTPCMonitor:: operator= (const AliTPCMonitor& monitor)
331 {
332   // assigment operator
333   if(this!=&monitor)
334   {
335     ((AliTPCMonitorConfig *)this)->operator=(monitor);
336     fkNRowsIroc=monitor.fkNRowsIroc;
337     fkNRowsOroc=monitor.fkNRowsOroc;
338     fkNPadsIroc=monitor.fkNPadsIroc;
339     fkNPadsOroc=monitor.fkNPadsOroc;
340     fkNPadMinIroc=monitor.fkNPadMinIroc;
341     fkNPadMinOroc=monitor.fkNPadMinOroc;
342     fkNPadMaxIroc=monitor.fkNPadMaxIroc;
343     fkNPadMaxOroc=monitor.fkNPadMaxOroc;
344     fVerb=monitor.fVerb;
345     fLastEv=monitor.fLastEv;
346     fEventNumber=monitor.fEventNumber;
347     fEventNumberOld=monitor.fEventNumberOld;
348     fDisableFit=monitor.fDisableFit;
349     fExecGlob=monitor.fExecGlob;
350     fExecPlaneMax=monitor.fExecPlaneMax;
351     fExecPadIrocRms=monitor.fExecPadIrocRms;
352     fExecPadOrocRms=monitor.fExecPadOrocRms;
353     fRunId=monitor.fRunId;
354     fEqId=monitor.fEqId;
355     fPadUsedRoc=monitor.fPadUsedRoc;
356     fPadUsedHwAddr=monitor.fPadUsedHwAddr;
357     fGdcId=monitor.fGdcId;
358     fLdcId=monitor.fLdcId;
359     fLdcIdOld=monitor.fLdcIdOld;
360     fMapHand=monitor.fMapHand;
361     fRawReader=monitor.fRawReader;
362     
363     
364     fHistList = new TObjArray();
365     fHistIROC=(TH2F*)monitor.fHistIROC->Clone(); fHistList->Add(fHistIROC);
366     fHistOROC=(TH2F*)monitor.fHistOROC->Clone(); fHistList->Add(fHistOROC);
367     fHistIROCIndex=(TH2S*)monitor.fHistIROCIndex->Clone(); fHistList->Add(fHistIROCIndex);
368     fHistOROCIndex=(TH2S*)monitor.fHistOROCIndex->Clone(); fHistList->Add(fHistOROCIndex);
369     fHistIROCTime=(TH2F*)monitor.fHistIROCTime->Clone(); fHistList->Add(fHistIROCTime);
370     fHistOROCTime=(TH2F*)monitor.fHistOROCTime->Clone(); fHistList->Add(fHistOROCTime);
371     fHistIROCClone=(TH2F*)monitor.fHistIROCClone->Clone(); fHistList->Add(fHistIROCClone);
372     fHistOROCClone=(TH2F*)monitor.fHistOROCClone->Clone(); fHistList->Add(fHistOROCClone);
373     fHistIROCRMS=(TH2F*)monitor.fHistIROCRMS->Clone(); fHistList->Add(fHistIROCRMS);
374     fHistOROCRMS=(TH2F*)monitor.fHistOROCRMS->Clone(); fHistList->Add(fHistOROCRMS);
375     fHistIROCBASE=(TH2F*)monitor.fHistIROCBASE->Clone(); fHistList->Add(fHistIROCBASE);
376     fHistOROCBASE=(TH2F*)monitor.fHistOROCBASE->Clone(); fHistList->Add(fHistOROCBASE);
377     fHistIROCSUM=(TH2F*)monitor.fHistIROCSUM->Clone(); fHistList->Add(fHistIROCSUM);
378     fHistOROCSUM=(TH2F*)monitor.fHistOROCSUM->Clone(); fHistList->Add(fHistOROCSUM);
379     
380     fHistChannelTime=(TH2F*)monitor.fHistChannelTime->Clone(); fHistList->Add(fHistChannelTime);
381     
382     fHistAddrMapIndex=(TH1F*)monitor.fHistAddrMapIndex->Clone(); fHistList->Add(fHistAddrMapIndex);
383     fHistAddrMaxAdc=(TH1F*)monitor.fHistAddrMaxAdc->Clone(); fHistList->Add(fHistAddrMaxAdc);
384     fHistAddrBaseMean=(TH1F*)monitor.fHistAddrBaseMean->Clone(); fHistList->Add(fHistAddrBaseMean);
385     fHistAddrMaxAdcX=(TH1F*)monitor.fHistAddrMaxAdcX->Clone(); fHistList->Add(fHistAddrMaxAdcX);
386     fHistAddrAdcSum=(TH1F*)monitor.fHistAddrAdcSum->Clone(); fHistList->Add(fHistAddrAdcSum);
387     fHistAddrBaseRms=(TH1F*)monitor.fHistAddrBaseRms->Clone(); fHistList->Add(fHistAddrBaseRms);
388     
389     
390     fHistDistrSumIROC=(TH1F*)monitor.fHistDistrSumIROC->Clone(); fHistList->Add(fHistDistrSumIROC);
391     fHistDistrMaxIROC=(TH1F*)monitor.fHistDistrMaxIROC->Clone(); fHistList->Add(fHistDistrMaxIROC);
392     fHistDistrSumOROC=(TH1F*)monitor.fHistDistrSumOROC->Clone(); fHistList->Add(fHistDistrSumOROC);
393     fHistDistrMaxOROC=(TH1F*)monitor.fHistDistrMaxOROC->Clone(); fHistList->Add(fHistDistrMaxOROC);
394     
395     fHistDistrBase2dIROC=(TH2F*)monitor.fHistDistrBase2dIROC->Clone(); fHistList->Add(fHistDistrBase2dIROC);
396     fHistDistrBase2dOROC=(TH2F*)monitor.fHistDistrBase2dOROC->Clone(); fHistList->Add(fHistDistrBase2dOROC);
397     fHistDistrBaseRmsIROC=(TH1D*)monitor.fHistDistrBaseRmsIROC->Clone(); fHistList->Add(fHistDistrBaseRmsIROC);
398     fHistDistrBaseMeanIROC=(TH1D*)monitor.fHistDistrBaseMeanIROC->Clone(); fHistList->Add(fHistDistrBaseMeanIROC);
399     fHistDistrBaseRmsOROC=(TH1D*)monitor.fHistDistrBaseRmsOROC->Clone(); fHistList->Add(fHistDistrBaseRmsOROC);
400     fHistDistrBaseMeanOROC=(TH1D*)monitor.fHistDistrBaseMeanOROC->Clone(); fHistList->Add(fHistDistrBaseMeanOROC);
401     
402     fHistGlobalMaxA=(TH2S*)monitor.fHistGlobalMaxA->Clone(); fHistList->Add(fHistGlobalMaxA);
403     fHistGlobalMaxC=(TH2S*)monitor.fHistGlobalMaxC->Clone(); fHistList->Add(fHistGlobalMaxC);
404     
405     fPad       = new Int_t*[monitor.GetMaxHwAddr()];
406     for(Int_t i = 0; i<GetMaxHwAddr(); i++) { fPad[i]       = new Int_t[monitor.GetTimeBins()];}
407     
408     fPadMapRCU = new Int_t*[monitor.GetMaxHwAddr()];
409     for(Int_t i = 0; i<monitor.GetMaxHwAddr(); i++) { fPadMapRCU[i] = new Int_t[6];}
410     
411     fPadMapHw  = new Float_t[monitor.GetMaxHwAddr()];
412     
413     fMapEqidsRcu   = new Int_t[1000];
414     fMapEqidsSec   = new Int_t*[36];
415     for(Int_t i = 0; i<36; i++) { fMapEqidsSec[i]       = new Int_t[6];}
416     SetEqIds();
417     
418     if (gDirectory)
419     {
420       if (!gDirectory->GetList())
421       {
422         Warning("Build","Current directory is not a valid directory");
423         return  *this;
424       }
425       AliTPCMonitor *hold = (AliTPCMonitor*)gDirectory->GetList()->FindObject(monitor.GetName());
426       if(hold)
427       {
428         Warning("Build","Replacing existing histogram: %s (Potential memory leak).",monitor.GetName());
429         gDirectory->GetList()->Remove(hold);
430       }
431       gDirectory->Append(this);
432     }
433   }
434   return *this;
435 }
436
437
438 //____________________________________________________________________________
439 AliTPCMonitor::~AliTPCMonitor() 
440 {
441   // Destructor
442   
443   for(Int_t i = 0; i<GetMaxHwAddr(); i++) { delete[] fPad[i] ;}
444   for(Int_t i = 0; i<GetMaxHwAddr(); i++) { delete[] fPadMapRCU[i];}
445   delete[] fPadMapHw ;
446   DeleteHistos();
447 }
448
449 //____________________________________________________________________________
450 void AliTPCMonitor::CreateHistos() 
451 {
452   // Create histograms to be displayed
453   
454   if(fVerb) cout << " create new ones " << endl;
455   fHistIROC            = new TH2F("fHistIROC"            ,"fHistIROC"           ,fkNRowsIroc,0,fkNRowsIroc,fkNPadsIroc, fkNPadMinIroc, fkNPadMaxIroc);       fHistList->Add(fHistIROC);
456   fHistOROC            = new TH2F("fHistOROC"            ,"fHistOROC"           ,fkNRowsOroc,0,fkNRowsOroc,fkNPadsOroc, fkNPadMinOroc, fkNPadMaxOroc);       fHistList->Add(fHistOROC);
457   
458   fHistIROCIndex       = new TH2S("fHistIROCIndex"       ,"fHistIROCIndex"      ,fkNRowsIroc,0,fkNRowsIroc,fkNPadsIroc, fkNPadMinIroc, fkNPadMaxIroc);       fHistList->Add(fHistIROCIndex);
459   fHistOROCIndex       = new TH2S("fHistOROCIndex"       ,"fHistOROCIndex"      ,fkNRowsOroc,0,fkNRowsOroc,fkNPadsOroc, fkNPadMinOroc, fkNPadMaxOroc);       fHistList->Add(fHistOROCIndex);
460   
461   fHistIROCTime        = new TH2F("fHistIROCTime"        ,"fHistIROCTime"       ,fkNRowsIroc,0,fkNRowsIroc,fkNPadsIroc, fkNPadMinIroc, fkNPadMaxIroc);       fHistList->Add(fHistIROCTime);
462   fHistOROCTime        = new TH2F("fHistOROCTime"        ,"fHistOROCTime"       ,fkNRowsOroc,0,fkNRowsOroc,fkNPadsOroc, fkNPadMinOroc, fkNPadMaxOroc);       fHistList->Add(fHistOROCTime);
463   
464   fHistIROCRMS         = new TH2F("fHistIROCRMS"         ,"fHistIROCRMS"        ,fkNRowsIroc,0,fkNRowsIroc,fkNPadsIroc, fkNPadMinIroc, fkNPadMaxIroc);       fHistList->Add(fHistIROCRMS);
465   fHistOROCRMS         = new TH2F("fHistOROCRMS"         ,"fHistOROCRMS"        ,fkNRowsOroc,0,fkNRowsOroc,fkNPadsOroc, fkNPadMinOroc, fkNPadMaxOroc);       fHistList->Add(fHistOROCRMS);
466   
467   fHistIROCSUM         = new TH2F("fHistIROCSUM"         ,"fHistIROCSUM"        ,fkNRowsIroc,0,fkNRowsIroc,fkNPadsIroc, fkNPadMinIroc, fkNPadMaxIroc);       fHistList->Add(fHistIROCSUM);
468   fHistOROCSUM         = new TH2F("fHistOROCSUM"         ,"fHistOROCSUM"        ,fkNRowsOroc,0,fkNRowsOroc,fkNPadsOroc, fkNPadMinOroc, fkNPadMaxOroc);       fHistList->Add(fHistOROCSUM);
469   
470   fHistIROCBASE        = new TH2F("fHistIROCBASE"        ,"fHistIROCBASE"       ,fkNRowsIroc,0,fkNRowsIroc,fkNPadsIroc, fkNPadMinIroc, fkNPadMaxIroc);       fHistList->Add(fHistIROCBASE);
471   fHistOROCBASE        = new TH2F("fHistOROCBASE"        ,"fHistOROCBASE"       ,fkNRowsOroc,0,fkNRowsOroc,fkNPadsOroc, fkNPadMinOroc, fkNPadMaxOroc);       fHistList->Add(fHistOROCBASE);
472   
473   
474   fHistChannelTime     = new TH2F("fHistChannelTime"     ,"fHistChannelTime"    ,GetNumOfChannels(),0,GetNumOfChannels(),GetTimeBins(),0,GetTimeBins());fHistList->Add(fHistChannelTime);
475   fHistAddrMapIndex    = new TH1F("fHistAddrMapIndex"    ,"fHistAddrMapIndex"   ,GetMaxHwAddr()    ,0,GetMaxHwAddr());                                  fHistList->Add(fHistAddrMapIndex);
476   fHistAddrMaxAdc      = new TH1F("fHistAddrMaxAdc"      ,"fHistAddrMaxAdc"     ,GetMaxHwAddr(),0,GetMaxHwAddr());                                      fHistList->Add(fHistAddrMaxAdc);
477   fHistAddrMaxAdcX     = new TH1F("fHistAddrMaxAdcX"     ,"fHistAddrMaxAdcX"    ,GetMaxHwAddr(),0,GetMaxHwAddr());                                      fHistList->Add(fHistAddrMaxAdcX);
478   fHistAddrBaseMean    = new TH1F("fHistAddrBaseMean"    ,"fHistAddrBaseMean"   ,GetMaxHwAddr(),0,GetMaxHwAddr());                                      fHistList->Add(fHistAddrBaseMean);
479   fHistAddrAdcSum      = new TH1F("fHistAddrAdcSum"      ,"fHistAddrAdcSum"     ,GetMaxHwAddr(),0,GetMaxHwAddr());                                      fHistList->Add(fHistAddrAdcSum);
480   fHistAddrBaseRms     = new TH1F("fHistAddrBaseRms"     ,"fHistAddrBaseRms"    ,GetMaxHwAddr(),0,GetMaxHwAddr());                                      fHistList->Add(fHistAddrBaseRms);
481   fHistDistrSumIROC    = new TH1F("fHistDistrSumIROC"    ,"fHistDistrSumIROC"   ,400,0.0,4000.0);                                                       fHistList->Add(fHistDistrSumIROC);
482   fHistDistrMaxIROC    = new TH1F("fHistDistrMaxIROC"    ,"fHistDistrMaxIROC"   ,500,0.0,1000.0);                                                       fHistList->Add(fHistDistrMaxIROC);
483   fHistDistrSumOROC    = new TH1F("fHistDistrSumOROC"    ,"fHistDistrSumOROC"   ,400,0.0,4000.0);                                                       fHistList->Add(fHistDistrSumOROC);
484   fHistDistrMaxOROC    = new TH1F("fHistDistrMaxOROC"    ,"fHistDistrMaxOROC"   ,500,0.0,1000.0);                                                       fHistList->Add(fHistDistrMaxOROC);
485   
486   fHistDistrBase2dIROC = new TH2F("fHistDistrBase2dIROC" ,"fHistDistrBase2dIROC",100,0.0,100.0,100,0.0,10.0);                                           fHistList->Add(fHistDistrBase2dIROC);
487   fHistDistrBase2dOROC = new TH2F("fHistDistrBase2dOROC" ,"fHistDistrBase2dOROC",100,0.0,100.0,100,0.0,10.0);                                           fHistList->Add(fHistDistrBase2dOROC);
488   
489   fHistGlobalMaxA      = new TH2S("SIDE A"               ,"SIDE A"              ,500,-3000,3000,500,-3000,3000);                                        fHistList->Add(fHistGlobalMaxA);
490   fHistGlobalMaxC      = new TH2S("SIDE C"               ,"SIDE C"              ,500,-3000,3000,500,-3000,3000);                                        fHistList->Add(fHistGlobalMaxC);
491   
492   ResetArrays();
493 }
494 //____________________________________________________________________________
495 Int_t AliTPCMonitor::ProcessEvent()
496 {
497   // Process Event
498   // Depending on the value of the sector id all sectors (sectorid == -1) are processed.
499   //
500   // In this case only the maximum values are calculated per pad and filled to the global histograms
501   // In a second loop the last processed(displayed) sector will be processed (sectorid!=-1)
502   // again and the baseline rms and further quantities are calculated
503   //
504   // If only one sector should be processed SetProcOneSector(1) should be set.
505   // In this case only the specified (last/last displayed) sector will be processed.
506   //
507   // If GetProcNextEvent()==0 the same event will be processed again
508   
509   
510   Int_t sectorid = 0;
511   Int_t retflag  = 0; // id of last sector + 1000,  or error flag
512   if(GetProcNextEvent()==1 && fLastEv) { AliInfo("Last event already processed"); }
513   if(GetProcNextEvent()==1) ResetSectorArray();
514   
515   
516   if(GetProcNextEvent()==0 || GetProcOneSector()==1 ) sectorid = GetLastSector();
517   else                                                sectorid = -1;
518   
519   // first iteration
520   retflag = ReadDataNew(sectorid);
521   
522   SetLastProcFile(GetFile());
523   
524   if(retflag>=10 && retflag<1000){ AliError("Could not read event properly: Check file name and format or try next event");  return 0  ;}
525   
526   DrawHists(3);
527   
528   // second iteration
529   if(sectorid==-1 && retflag >1000)
530   {
531     AliInfo("Second read cycle");
532     SetProcNextEvent(0);
533     if(GetLastSectorDisplayed()==-1) {sectorid =  GetLastSector()         ;    }
534     else                             {sectorid =  GetLastSectorDisplayed();  SetLastSector(sectorid)           ;  }
535     retflag = ReadDataNew(sectorid);
536   }
537   
538   SetLastSectorDisplayed(sectorid)  ;
539   fMapHand->ReadfecHwMap(GetLastSector());
540   FillHistsPadPlane();
541   DrawHists(1);
542   SetEventProcessed(1);
543   return retflag;
544 }
545 //__________________________________________________________________
546 Int_t AliTPCMonitor::ReadDataNew(Int_t secid)
547 {
548   // Read Data File/Stream  for specified Format.
549   // Payload will be extracted from either ROOT or DATE format
550   // and passed to FillHistsDecode for decoding of the adc information
551   
552   if (!fRawReader){
553     fRawReader = AliRawReader::Create(GetFile());
554     SetLastProcFile(GetFile());
555   } else if (strcmp(GetLastProcFile(),GetFile())!=0){
556     delete fRawReader;
557     fRawReader = AliRawReader::Create(GetFile());
558 //     printf("New file!!!\n");
559     SetLastProcFile(GetFile());
560   }
561   
562   if (!fRawReader){
563     AliWarning("Coult not initialize raw reader");
564     return 11;
565   }
566   
567   Bool_t skip=kTRUE;
568   while(skip && GetProcNextEvent())
569   {
570     if(fVerb) cout << "AliTPCMonitor::ReadDataNew get event " << endl;
571     if(fRawReader->IsA()==AliRawReaderRoot::Class()){
572       printf("Root, NextEvent: %d\n",GetEventID());
573       if (!fRawReader->GotoEvent(GetEventID())){AliError("Could not get next Event"); return 11 ;}
574     } else if(!fRawReader->NextEvent()) { AliError("Could not get next Event"); return 11 ;}
575     // skip all events but physics, calibration and software trigger events!
576     UInt_t eventType=fRawReader->GetType();
577     if ( !(eventType==AliRawEventHeaderBase::kPhysicsEvent ||
578            eventType==AliRawEventHeaderBase::kCalibrationEvent ||
579            eventType==AliRawEventHeaderBase::kSystemSoftwareTriggerEvent ||
580            eventType==AliRawEventHeaderBase::kDetectorSoftwareTriggerEvent) ) {
581              if (fVerb) cout<< "Skipping event! Its neither of 'physics, calibration and software trigger event'" << endl;
582              if(fRawReader->IsA()==AliRawReaderRoot::Class()){
583                if (fEventNumber<fRawReader->GetNumberOfEvents()-1) ++fEventNumber;
584                else {AliError("No more events");return 11;}
585              }
586              continue;
587            }
588     skip=kFALSE;
589     //test if the TPC has data
590     UChar_t *data=0;
591     fRawReader->Select("TPC");
592     Int_t eventNr=fRawReader->GetEventIndex();
593     if (!fRawReader->ReadNextData(data)) {
594       skip=kTRUE;
595       printf("%d - %d\n",fEventNumber,fRawReader->GetNumberOfEvents());
596       if(fRawReader->IsA()==AliRawReaderRoot::Class()){
597         if (fEventNumber<fRawReader->GetNumberOfEvents()-1){
598           ++eventNr;
599           printf("inc conter\n");
600         }
601         else {
602           AliError("No more events");
603           return 11;
604         }
605       }
606     }
607     fEventNumber = eventNr;
608     fEventNumberOld = eventNr;
609   }
610   
611 //   printf("secid: %d\n",secid);
612   
613   //========================== Histogram filling ======================
614   ResetHistos() ;
615   AliAltroRawStreamV3 *altro=new AliAltroRawStreamV3(fRawReader);
616   altro->SelectRawData("TPC");
617   altro->Reset();
618   fChannelIter=0;
619   
620   Int_t     hw                = 0;
621   Int_t     nextHwAddress     = 0;
622   Int_t     rcupatch          = 0;
623   Int_t     maxADC            = 0;
624   Int_t     maxx              = 0;
625   Int_t     sum               = 0;
626   Int_t     sumn              = 0;
627   Int_t           lastrcuid   = 0;
628   
629   while ( altro->NextDDL() ){
630     fGdcId        = fRawReader->GetGDCId() ;
631     fLdcId        = fRawReader->GetLDCId() ;
632     fRunId        = fRawReader->GetRunNumber() ;
633     fEqId         = fRawReader->GetEquipmentId();
634     rcupatch      = GetRCUPatch(fRunId, fEqId);
635     Int_t rcupatchSector=rcupatch%6;
636     lastrcuid     = (rcupatch+1000);
637 //     printf("RCU patch: %d, LDC: %d, EqId: %d\n",rcupatch, fLdcId, fEqId);
638     if(fLdcIdOld!=fLdcId &&  fChannelIter!=0) {
639       if(secid==-1)
640       {
641         FillGlobal(GetLastSector());
642         ResetArrays();
643 //         printf("filled sector: %d\n",GetLastSector());
644         fChannelIter =0;
645       }
646       else
647       {
648         return lastrcuid;
649 //         if (rcupatch/6!=secid) continue;
650       }
651 //       fChannelIter=0;
652     }
653     if (!CheckEqId(secid,fEqId)) continue;
654     while ( altro->NextChannel() ){
655       hw=altro->GetHWAddress();
656       nextHwAddress         = ( hw + (rcupatchSector<<12) );
657       fPad[fChannelIter][0] = nextHwAddress ;
658       fPadMapHw[nextHwAddress]    =  fChannelIter  ;
659       maxADC=0;
660       while ( altro->NextBunch() ){
661         Int_t  startTbin    = (Int_t)altro->GetStartTimeBin();
662         Int_t  bunchlength  = (Int_t)altro->GetBunchLength();
663         const UShort_t *sig = altro->GetSignals();
664         for (Int_t iTimeBin = 0; iTimeBin<bunchlength; iTimeBin++){
665           Int_t adc=(Int_t)sig[iTimeBin];
666           Int_t ntime=startTbin-iTimeBin;
667           //fill channel information
668           fPad[fChannelIter][ntime]  = adc;
669           if( (adc>maxADC) && (ntime>=GetRangeMaxAdcMin()) && (ntime<GetRangeMaxAdcMax()  ))  {maxADC = adc;maxx = ntime ;}
670           if(              (ntime>=GetRangeSumMin())    && (ntime<GetRangeSumMax()     ))  {sum+=adc; sumn++;}
671           
672         }
673       }
674       //get pedestal, noise
675       Float_t pedestal=TMath::Mean(GetRangeBaseMax()-GetRangeBaseMin(),fPad[fChannelIter]+GetRangeBaseMin());
676       Float_t noise   =TMath::RMS(GetRangeBaseMax()-GetRangeBaseMin(),fPad[fChannelIter]+GetRangeBaseMin());
677       fHistAddrMaxAdc->SetBinContent(nextHwAddress,maxADC-GetPedestals()*pedestal);
678       
679       if(secid!=-1)
680       {
681         if(rcupatchSector<2)
682         {
683           fHistDistrBase2dIROC->Fill(pedestal,noise);
684           fHistDistrSumIROC->Fill(sum);
685           fHistDistrMaxIROC->Fill(maxADC-pedestal*GetPedestals());
686           fHistDistrSumIROC->Fill(sum -sumn*pedestal*GetPedestals());
687         }
688         else
689         {
690           fHistDistrBase2dOROC->Fill(pedestal,noise);
691           fHistDistrSumOROC->Fill(sum);
692           fHistDistrMaxOROC->Fill(maxADC-pedestal*GetPedestals());
693           fHistDistrSumOROC->Fill(sum -sumn*pedestal*GetPedestals());
694         }
695         
696         fHistAddrAdcSum->SetBinContent(  nextHwAddress,sum);
697         fHistAddrMapIndex->SetBinContent(nextHwAddress,fChannelIter);
698         fHistAddrBaseMean->SetBinContent(nextHwAddress,pedestal);
699         fHistAddrMaxAdcX->SetBinContent( nextHwAddress,maxx);
700         fHistAddrBaseRms->SetBinContent( nextHwAddress,noise);
701       }
702       
703       ++fChannelIter;
704     }
705     SetLastSector(rcupatch/6);
706     if(fChannelIter!=0 && secid==-1 ) SetSectorFilled(rcupatch/6);
707     fLdcIdOld = fLdcId ;
708   }
709   delete altro;
710   if(fChannelIter!=0 && secid==-1) { FillGlobal(GetLastSector());}
711   return lastrcuid;
712 }
713
714
715
716
717
718
719
720
721
722
723
724 //____________________________________________________________________________
725 void AliTPCMonitor::FillHistsPadPlane() 
726 {
727   // Fill 2Dim histograms for IROC and OROC (max , rms and sum)
728   
729   if(fVerb)cout << "AliTPCMonitor::FillHistsPadPlane() Start  " << endl;
730   if(fVerb)PrintConfig();
731   
732   Int_t pad    = 0;
733   Int_t row    = 0;
734   Int_t padmax = 0;
735   Int_t hwadd  = 0;
736   
737   for(Int_t ch = 0; ch<fChannelIter; ch++)
738   {
739     hwadd=  fPad[ch][0];
740     fHistChannelTime->SetCellContent(ch,0,hwadd);
741     
742     for(Int_t bin = 1; bin <GetTimeBins(); bin++)
743     {
744       if( fHistChannelTime->GetCellContent(ch,bin)!=0)  cout << " cellcontent already set " << endl;
745       if(     GetPedestals()==1 ) fHistChannelTime->SetCellContent(ch,bin,(fPad[ch][bin]- fHistAddrBaseMean->GetBinContent(hwadd)));
746       else                        fHistChannelTime->SetCellContent(ch,bin,(fPad[ch][bin]));
747     }
748     
749     pad    = fMapHand->GetPad(   hwadd);
750     row    = fMapHand->GetPadRow(hwadd);
751     padmax = fMapHand->GetNumofPads(row);
752     
753     if(row<63)
754     {
755       fHistIROC->SetCellContent(     row    +1 ,pad +55 -padmax/2 +1,fHistAddrMaxAdc->GetBinContent(  hwadd));
756       fHistIROCIndex->SetCellContent(row    +1 ,pad +55 -padmax/2 +1,ch);
757       fHistIROCRMS->SetCellContent(  row    +1 ,pad +55 -padmax/2 +1,fHistAddrBaseRms->GetBinContent( hwadd));
758       fHistIROCBASE->SetCellContent( row    +1 ,pad +55 -padmax/2 +1,fHistAddrBaseMean->GetBinContent(hwadd));
759       fHistIROCSUM->SetCellContent(  row    +1 ,pad +55 -padmax/2 +1,fHistAddrAdcSum->GetBinContent(  hwadd));
760     }
761     else
762     {
763       fHistOROC->SetCellContent(     row-63 +1 ,pad +70 -padmax/2 +1,fHistAddrMaxAdc->GetBinContent(  hwadd));
764       fHistOROCIndex->SetCellContent(row-63 +1 ,pad +70 -padmax/2 +1,ch);
765       fHistOROCRMS->SetCellContent(  row-63 +1 ,pad +70 -padmax/2 +1,fHistAddrBaseRms->GetBinContent( hwadd));
766       fHistOROCBASE->SetCellContent( row-63 +1 ,pad +70 -padmax/2 +1,fHistAddrBaseMean->GetBinContent(hwadd));
767       fHistOROCSUM->SetCellContent(  row-63 +1 ,pad +70 -padmax/2 +1,fHistAddrAdcSum->GetBinContent(  hwadd));
768     }
769   }
770   
771   fHistChannelTime->GetXaxis()->SetRange(0,fChannelIter);
772   fHistChannelTime->GetYaxis()->SetRange(0,GetTimeBins());
773 }
774
775
776
777 //____________________________________________________________________________
778 void AliTPCMonitor::ResetArrays() 
779 {
780   // Reset data arrays
781   for(Int_t row = 0 ; row < fkNRowsIroc; row++)
782   {
783     for(Int_t pad = 0 ; pad <  fkNPadsIroc ; pad++)
784     {
785       fHistIROCIndex->SetCellContent(row+1,pad+1,-1);
786     }
787   }
788   for(Int_t row = 0 ; row < fkNRowsOroc; row++)
789   {
790     for(Int_t pad = 0 ; pad <  fkNPadsOroc ; pad++)
791     {
792       fHistOROCIndex->SetCellContent(row+1,pad+1,-1);
793     }
794   }
795   
796   for(Int_t ch= 0; ch<GetMaxHwAddr(); ch++)
797   {
798     fHistAddrMaxAdcX->SetBinContent(ch,-1);
799     fHistAddrMapIndex->SetBinContent(ch,-1);
800     fHistAddrMaxAdc->SetBinContent(  ch, 0);
801     fHistAddrBaseMean->SetBinContent(  ch, 0);
802     fHistAddrAdcSum->SetBinContent(  ch, 0);
803     fHistAddrBaseRms->SetBinContent(ch, 0);
804   }
805   
806   for(Int_t ch = 0; ch< GetNumOfChannels(); ch++)
807   {
808     for(Int_t bin = 0; bin< GetTimeBins(); bin++)
809     {
810       fPad[ch][bin] = 0;
811     }
812   }
813   for(Int_t ch = 0; ch< GetMaxHwAddr(); ch++)
814   {
815     fPadMapHw[ch]=-1;
816     fPadMapRCU[ch][0]=-1;
817     fPadMapRCU[ch][1]=-1;
818     fPadMapRCU[ch][2]=-1;
819     fPadMapRCU[ch][3]=-1;
820     fPadMapRCU[ch][4]=-1;
821     fPadMapRCU[ch][5]=-1;
822   }
823   fPadUsedHwAddr=-1;
824 }
825
826
827 //____________________________________________________________________________
828 void AliTPCMonitor::ResetHistos() 
829 {
830   // Reset all but
831   for(Int_t i =0; i<fHistList->GetEntries(); i++)
832   {
833     if(GetProcNextEvent()==0 && strcmp(((TH1*)fHistList->At(i))->GetName(),"SIDE A")==0) continue;
834     if(GetProcNextEvent()==0 && strcmp(((TH1*)fHistList->At(i))->GetName(),"SIDE C")==0) continue;
835     ((TH1*)fHistList->At(i))->Reset();
836   }
837   ResetArrays();
838 }
839
840 //____________________________________________________________________________
841 void AliTPCMonitor::DeleteHistos() 
842 {
843   // Delete histograms
844   for(Int_t i =0; i<fHistList->GetEntries(); i++)
845   {
846     delete (TH1*)fHistList->At(i);
847   }
848 }
849
850
851 //__________________________________________________________________
852 Int_t AliTPCMonitor::CheckEqId(Int_t secid,Int_t eqid)
853 {
854   // Check if equipment id corresponds to any  rcu patch in sector
855   // Equipment ids changed during commisioning in 2006 (starting from run 704)
856   // However Runids started from 0 again in 2007
857   // Now only runids from commissioning in 2006 after runid 704 and all new ones are supported.
858   // Comment in equipment check for runids < 704 if old runs should be processed
859   
860   if(fVerb) cout << "AliTPCMonitor::CheckEqId  : SectorId  " << secid << " EquipmentId " << eqid  << " runid " << fRunId <<  endl;
861   Int_t passed =1;
862   //skip all eqids which do not belong to the TPC
863   if ( eqid<768||eqid>983 ) return 0;
864   //
865   if(fRunId<704 && 0) // commented out --> runs with runid < 704 in 2006 are not recognized anymore
866   {
867     if( (secid>-1) && (secid<36) )   // if ( secid is in range) { take only specific eqids}  else { take all }
868     {
869       if(      (secid==13) && ( eqid!=408 && eqid!=409  &&  eqid!=509 && eqid!=512  && eqid!=513 && eqid!=517 )) {passed=0;}
870       else if( (secid==4)  && ( eqid!=404 && eqid!=504  &&  eqid!=407 && eqid!=503  && eqid!=508 && eqid!=506 )) {passed=0;}
871     }
872     else                                                                   {if(fVerb) cout << "passed check "<< endl; }
873   }
874   else
875   {
876     if( (secid>-1) && (secid<36) )   // if ( secid is in range) { take only specific eqids}  else { take all }
877     {
878       if(eqid!=fMapEqidsSec[secid][0] && eqid!= fMapEqidsSec[secid][1] && eqid!=fMapEqidsSec[secid][2] &&
879          eqid!=fMapEqidsSec[secid][3] && eqid!= fMapEqidsSec[secid][4] && eqid!=fMapEqidsSec[secid][5] )  {passed=0;}
880     }
881     else                                                                   {if(fVerb) cout << "passed check "<< endl;}
882   }
883   
884   return passed;
885 }
886
887 //__________________________________________________________________
888 void AliTPCMonitor::SetEqIds()
889 {
890   // Set mapping for equipment ids
891   for(Int_t i = 0; i<36 ; i++)
892   {
893     for(Int_t j = 0; j<6; j++)
894     {
895       if(j<2) fMapEqidsSec[i][j]= 768+i*2+j;
896       else    fMapEqidsSec[i][j]= 840+i*4+j-2;
897     }
898   }
899   
900   for(Int_t i = 0; i<36 ; i++)
901   {
902     for(Int_t j = 0; j<6; j++)
903     {
904       if(j<2) fMapEqidsRcu[768+i*2+j]   = i*6 +j;
905       else    fMapEqidsRcu[840+i*4+j-2] = i*6 +j;
906     }
907   }
908 }
909
910 //__________________________________________________________________
911 void AliTPCMonitor::FillGlobal(Int_t sector) 
912 {
913   
914   // Fill global histograms with max adc for each channel
915   
916   TH2S* hglob =0;
917   if((sector/18) ==0) hglob =  fHistGlobalMaxA;
918   else                hglob =  fHistGlobalMaxC;
919   
920   Float_t  rotsec  = (2*TMath::Pi()/18.0);
921   Float_t  rot     = (-rotsec*(sector%18)  +4*rotsec);
922   
923   Float_t  m11     =    TMath::Cos(rot);
924   Float_t  m12     =    TMath::Sin(rot);
925   Float_t  m21     = -1*TMath::Sin(rot);
926   Float_t  m22     =    TMath::Cos(rot);
927   
928   Int_t    max     = 0; // use integer for global view
929   
930   Double_t xval    = 0.0;
931   Double_t yval    = 0.0;
932   
933   Int_t    pad     = 0;
934   Int_t    row     = 0;
935   Int_t    padmax  = 0;
936   
937   Float_t  xdr     = 0;
938   Float_t  ydr     = 0;
939   
940   for(Int_t hw = 0; hw<fHistAddrMaxAdc->GetNbinsX(); hw++)
941   {
942     max = (Int_t)fHistAddrMaxAdc->GetBinContent(hw);
943     if(max!=-1)
944     {
945       pad    = fMapHand->GetPad(   hw);
946       row    = fMapHand->GetPadRow(hw);
947       padmax = fMapHand->GetNumofPads(row);
948       if (sector%36>17) fMirror=-1;
949       else fMirror=1;
950       GetXY(xval ,yval , padmax,row ,pad);
951       xdr    =  xval*m11 +yval*m12;
952       ydr    =  xval*m21 +yval*m22;
953       if(hglob->GetBinContent(hglob->GetXaxis()->FindBin(xdr),hglob->GetYaxis()->FindBin(ydr))==0)   hglob->Fill(xdr,ydr,(Int_t)max);
954     }
955   }
956 }
957
958
959 //__________________________________________________________________
960 void AliTPCMonitor::GetXY( Double_t& xval , Double_t& yval , Int_t padmax, Int_t row , Int_t pad) const 
961 {
962   // Get x and y position of pad
963   
964   if(row<63)
965   {
966     xval = fMirror*( 2*padmax -4*pad -2);
967     yval = 852.25 +7.5*row;
968   }
969   else
970   {
971     xval = fMirror*( 3*padmax -6*pad -3);
972     if((row-63)<63) {     yval = 10*(row-63) +1351;     }
973     else              {   yval = 15*(row-63-64)+1993.5; }
974   }
975   
976
977
978 //__________________________________________________________________
979 Int_t AliTPCMonitor::GetPadAtX(Float_t xval, Int_t row, Int_t padmax) const
980 {
981   // Get pad number at given position in x
982   Int_t pad    = 0;
983   
984   if(row<63) {pad = (Int_t)( ( (xval/fMirror) +2 -2*padmax)/-4);}
985   else       {pad = (Int_t)( ( (xval/fMirror) +3 -3*padmax)/-6);}
986   
987   if(pad>=padmax) return -1;
988   else            return pad ;
989   
990 }
991
992 //__________________________________________________________________
993 Int_t AliTPCMonitor::GetPadAtX(Float_t xval, Int_t row) const
994 {
995   
996  // Get pad number at given position in x
997   
998   Int_t padmax = fMapHand->GetNumofPads(row);
999   Int_t pad    = 0;
1000   
1001   if(row<63) {pad = (Int_t)( ( (xval/fMirror) +2 -2*padmax)/-4);}
1002   else       {pad = (Int_t)( ( (xval/fMirror) +3 -3*padmax)/-6);}
1003   
1004   if(pad>=padmax) return -1;
1005   else            return pad ;
1006   
1007 }
1008
1009 //__________________________________________________________________
1010 void AliTPCMonitor::DrawHists(Int_t histos) 
1011 {
1012   
1013   // Draw sets of histograms
1014   // histos==1 : 2Dim histos for MAX adc  and add executables
1015   // histos==2 : distributions max/rms/sum
1016   // histos==3 : global max adc for specified SideA/C
1017   
1018   
1019   if(fVerb)    cout << " Draw histos " << endl;
1020   Char_t cside[10];
1021   if(GetLastSector()/18==0 ) sprintf(cside,"A");
1022   else                       sprintf(cside,"C");
1023   
1024   Char_t titleSEC[256];   sprintf(titleSEC   ,"Sector %i Side %s Run : %05i EventID %i "       ,GetLastSector()%18,cside,fRunId, fEventNumber);
1025   Char_t titleEvent[256]; sprintf(titleEvent ,"Time <-> Channles  %s"                          ,titleSEC);
1026   Char_t titleIROC[256];  sprintf(titleIROC  ,"IROC %s"                                        ,titleSEC);
1027   Char_t titleOROC[256];  sprintf(titleOROC  ,"OROC %s"                                        ,titleSEC);
1028   
1029   Char_t titleMAX[256];   sprintf(titleMAX   ,"Max (timebin: %i,%i) %s"                        ,GetRangeMaxAdcMin(),GetRangeMaxAdcMax(),titleSEC);
1030   Char_t titleSUM[256];   sprintf(titleSUM   ,"Sum (timebin: %i,%i) %s"                        ,GetRangeSumMin()   ,GetRangeSumMax()   ,titleSEC);
1031   Char_t titleBASE[256];  sprintf(titleBASE  ,"Baseline RMS<->Mean  (timebin: %i-%i) %s"       ,GetRangeBaseMin()  ,GetRangeBaseMax()  ,titleSEC);
1032   Char_t titleMEAN[256];  sprintf(titleMEAN  ,"Baseline Mean (timebin: %i-%i) %s"              ,GetRangeBaseMin()  ,GetRangeBaseMax()  ,titleSEC);
1033   Char_t titleRMS[256] ;  sprintf(titleRMS   ,"Baseline RMS (timebin: %i-%i) %s"               ,GetRangeBaseMin()  ,GetRangeBaseMax()  ,titleSEC);
1034   
1035   if(histos==1)
1036   {
1037       // IROC _______________________________________________________________
1038     TCanvas* ciroc = 0;
1039     ciroc = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("ciroc");
1040     if(!ciroc)
1041     {
1042       ciroc = CreateCanvas("ciroc");
1043       fExecPlaneMax=0;
1044     }
1045     ciroc->cd();
1046     
1047     fHistIROC->SetXTitle("row");
1048     fHistIROC->SetYTitle("pad");
1049     if(GetPedestals()) fHistIROC->SetZTitle("max ADC (baseline sub)");
1050     else               fHistIROC->SetZTitle("max ADC ");
1051     fHistIROC->SetTitle(titleIROC);
1052     fHistIROC->SetMinimum(0.01);
1053     fHistIROC->Draw("COLZ");
1054     ciroc->UseCurrentStyle();
1055     
1056     
1057     fHistIROCTime->SetXTitle("row"); fHistIROCTime->SetZTitle("peak time (fit)");       fHistIROCTime->SetYTitle("pad");      fHistIROCTime->SetTitle(titleIROC);
1058     fHistIROCRMS->SetXTitle("row");  fHistIROCRMS->SetZTitle( "baseline rms (ADC)");    fHistIROCRMS->SetYTitle("pad");       fHistIROCRMS->SetTitle(titleIROC);
1059     
1060       // OROC
1061     TCanvas* coroc = 0;
1062     coroc =(TCanvas*)gROOT->GetListOfCanvases()->FindObject("coroc");
1063     if(!coroc) {
1064       coroc = CreateCanvas("coroc");
1065       fExecPlaneMax=0;
1066     }
1067     coroc->cd();
1068     
1069     fHistOROC->SetXTitle("row");
1070     fHistOROC->SetYTitle("pad");
1071     if(GetPedestals()) fHistOROC->SetZTitle("max ADC (baseline sub)");
1072     else               fHistOROC->SetZTitle("max ADC ");
1073     fHistOROC->SetTitle(titleOROC);
1074     fHistOROC->SetMinimum(0.01);
1075     fHistOROC->Draw("COLZ");
1076     coroc->UseCurrentStyle();
1077     
1078     
1079     fHistOROCTime->SetXTitle("row"); fHistOROCTime->SetZTitle("peak time (fit) (timebins)"); fHistOROCTime->SetYTitle("pad"); fHistOROCTime->SetTitle(titleOROC);
1080     fHistOROCRMS->SetXTitle("row");  fHistOROCRMS->SetZTitle("baseline rms (ADC)");          fHistOROCRMS->SetYTitle("pad");  fHistOROCRMS->SetTitle(titleOROC);
1081     
1082       // SUM
1083     Char_t namesum[256] ; sprintf(namesum,"ADC sum (bins: %i, %i)",GetRangeSumMin() ,GetRangeSumMax() );
1084     fHistIROCSUM->SetXTitle("row");      fHistIROCSUM->SetZTitle(namesum);      fHistIROCSUM->SetYTitle("pad");      fHistIROCSUM->SetTitle(titleIROC);
1085     fHistOROCSUM->SetXTitle("row");      fHistOROCSUM->SetZTitle(namesum);      fHistOROCSUM->SetYTitle("pad");      fHistOROCSUM->SetTitle(titleOROC);
1086     
1087       // BASE
1088     Char_t namebase[256] ; sprintf(namebase ,"base mean (timbebin: %i, %i )",GetRangeBaseMin(),GetRangeBaseMax());
1089     fHistIROCBASE->SetXTitle("row"); fHistIROCBASE->SetZTitle(namebase);  fHistIROCBASE->SetYTitle("pad");      fHistIROCBASE->SetTitle(titleIROC);
1090     fHistOROCBASE->SetXTitle("row"); fHistOROCBASE->SetZTitle(namebase);  fHistOROCBASE->SetYTitle("pad");      fHistOROCBASE->SetTitle(titleOROC);
1091     
1092     if(fHistIROCClone) fHistIROCClone->Delete();
1093     if(fHistOROCClone) fHistOROCClone->Delete();
1094     fHistIROCClone = (TH2F*)fHistIROC->Clone("fHistIROCClone");
1095     fHistOROCClone = (TH2F*)fHistOROC->Clone("fHistOROCClone");
1096     
1097       // Executables
1098     if(fExecPlaneMax==0)
1099     {
1100       Char_t carry1[100];
1101       sprintf(carry1,".x %s/TPC/AliTPCMonitorExec.C(1)",gSystem->Getenv("ALICE_ROOT"));
1102       ciroc->AddExec("pad",carry1);
1103       coroc->AddExec("pad",carry1);
1104       
1105       Char_t carry2[100];
1106       sprintf(carry2,".x %s/TPC/AliTPCMonitorExec.C(2)",gSystem->Getenv("ALICE_ROOT"));
1107       ciroc->AddExec("row",carry2);
1108       coroc->AddExec("row",carry2);
1109       fExecPlaneMax=1;
1110     }
1111     coroc->Update();
1112     ciroc->Update();
1113   }
1114   else if(histos==2)
1115   {
1116       // MAX ADC distribution  ____________________________________________
1117     TCanvas* cmax = 0;
1118     cmax = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("cmax");
1119     if(!cmax)  cmax = CreateCanvas("cmax");
1120     
1121     cmax->cd();
1122     fHistDistrMaxIROC->GetXaxis()->SetRangeUser(0.0,1000.0);
1123     fHistDistrMaxIROC->SetXTitle("max ADC (ADC)");
1124     fHistDistrMaxIROC->SetYTitle("counts");
1125     fHistDistrMaxIROC->SetTitle(titleMAX);
1126     fHistDistrMaxIROC->Draw("");
1127     fHistDistrMaxOROC->SetLineColor(2);
1128     fHistDistrMaxOROC->Draw("same");
1129     
1130     if(fHistDistrMaxOROC->GetMaximum()> fHistDistrMaxIROC->GetMaximum())  fHistDistrMaxIROC->SetMaximum(fHistDistrMaxOROC->GetMaximum()*1.1);
1131     
1132     TLegend* legio = new TLegend(0.6,0.6,0.8,0.8);
1133     legio->SetFillColor(0);
1134     legio->AddEntry(fHistDistrMaxIROC,"IROC","l");
1135     legio->AddEntry(fHistDistrMaxOROC,"OROC","l");
1136     legio->Draw("same");
1137     
1138       // ADC sum distribution
1139     TCanvas* csum = 0;
1140     csum = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("csum");
1141     if(!csum)  csum = CreateCanvas("csum") ;
1142     csum->cd();
1143     
1144     fHistDistrSumIROC->SetXTitle("sum ADC (ADC)");
1145     fHistDistrSumIROC->SetYTitle("counts");
1146     fHistDistrSumIROC->SetTitle(titleSUM);
1147     fHistDistrSumIROC->Draw("");
1148     fHistDistrSumOROC->SetLineColor(2);
1149     fHistDistrSumOROC->Draw("same");
1150     if(fHistDistrSumOROC->GetMaximum()> fHistDistrSumIROC->GetMaximum())  fHistDistrSumIROC->SetMaximum(fHistDistrSumOROC->GetMaximum()*1.1);
1151     legio->Draw("same");
1152     
1153       // BASELINE MEAN distribution
1154     TCanvas* cbasemean = 0;
1155     cbasemean = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("cbasemean");
1156     if(!cbasemean)  cbasemean = CreateCanvas("cbasemean");
1157     cbasemean->cd();
1158     
1159     fHistDistrBaseMeanIROC = fHistDistrBase2dIROC->ProjectionX("fHistDistrBaseMeanIROC");
1160     fHistDistrBaseMeanIROC->SetXTitle("base mean (ADC)");
1161     fHistDistrBaseMeanIROC->SetYTitle("counts");
1162     fHistDistrBaseMeanIROC->SetTitle(titleMEAN);
1163     fHistDistrBaseMeanIROC->Draw("");
1164     
1165     fHistDistrBaseMeanOROC = fHistDistrBase2dOROC->ProjectionX("fHistDistrBaseMeanOROC");
1166     fHistDistrBaseMeanOROC->SetLineColor(2);
1167     fHistDistrBaseMeanOROC->Draw("same");
1168     if(fHistDistrBaseMeanOROC->GetMaximum()>fHistDistrBaseMeanIROC->GetMaximum())   fHistDistrBaseMeanIROC->SetMaximum(fHistDistrBaseMeanOROC->GetMaximum()*1.1);
1169     legio->Draw("same");
1170     
1171     TCanvas* cbaserms = 0;
1172     cbaserms = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("cbaserms");
1173     if(!cbaserms) cbaserms = CreateCanvas("cbaserms") ;
1174     cbaserms->cd();
1175     
1176       // BASELINE RMS distribution
1177     fHistDistrBaseRmsIROC = fHistDistrBase2dIROC->ProjectionY("fHistDistrBaseRmsIROC");
1178     fHistDistrBaseRmsIROC->SetXTitle("base rms (ADC)");
1179     fHistDistrBaseRmsIROC->SetYTitle("counts");
1180     fHistDistrBaseRmsIROC->SetTitle(titleRMS);
1181     fHistDistrBaseRmsIROC->Draw("");
1182     
1183     fHistDistrBaseRmsOROC = fHistDistrBase2dOROC->ProjectionY("fHistDistrBaseRmsOROC");
1184     fHistDistrBaseRmsOROC->SetLineColor(2);
1185     fHistDistrBaseRmsOROC->Draw("same");
1186     if(fHistDistrBaseRmsOROC->GetMaximum()>fHistDistrBaseRmsIROC->GetMaximum())  fHistDistrBaseRmsIROC->SetMaximum(fHistDistrBaseRmsOROC->GetMaximum()*1.1);
1187     legio->Draw("same");
1188     
1189     cmax->Update();
1190     csum->Update();
1191     cbasemean->Update();
1192     cbaserms->Update();
1193   }
1194   else  if(histos==3)
1195   {
1196       // GLOBAL MAX ADC _________________________________
1197     if(GetProcNextEvent()==1)
1198     {
1199       TCanvas* cglobA =0;
1200       TCanvas* cglobC =0;
1201       
1202       if(!(cglobC=(TCanvas*)gROOT->GetListOfCanvases()->FindObject("SIDE C all"))) cglobC = CreateCanvas("SIDE C all");
1203       if(!(cglobA=(TCanvas*)gROOT->GetListOfCanvases()->FindObject("SIDE A all"))) cglobA = CreateCanvas("SIDE A all");
1204       
1205       Char_t globtitle1[256]; sprintf(globtitle1,"SIDE A Run %05i (EventID %i)",fRunId,fEventNumber);
1206       Char_t globtitle2[256]; sprintf(globtitle2,"SIDE C Run %05i (EventID %i)",fRunId,fEventNumber);
1207       
1208       fHistGlobalMaxA->SetTitle(globtitle1);
1209       fHistGlobalMaxC->SetTitle(globtitle2);
1210       fHistGlobalMaxA->SetXTitle("x/mm");
1211       fHistGlobalMaxA->SetYTitle("y/mm");
1212       fHistGlobalMaxC->SetXTitle("x/mm");
1213       fHistGlobalMaxC->SetYTitle("y/mm");
1214       
1215       if(GetPedestals()==0)     {             fHistGlobalMaxA->SetZTitle("max adc (not baseline sub)");   fHistGlobalMaxC->SetZTitle("max adc (not baseline sub)");  }
1216       else                          {         fHistGlobalMaxA->SetZTitle("max adc ");                     fHistGlobalMaxC->SetZTitle("max adc ");                          }
1217       
1218       fHistGlobalMaxA->SetMinimum(0.01);
1219       fHistGlobalMaxC->SetMinimum(0.01);
1220       
1221       cglobC->cd() ; fHistGlobalMaxC->Draw("COLZ");
1222       cglobA->cd() ; fHistGlobalMaxA->Draw("COLZ");
1223       
1224       Char_t nameom[256];
1225       sprintf(nameom,".x  %s/TPC/AliTPCMonitorExec.C(3)",gSystem->Getenv("ALICE_ROOT"));
1226       
1227       if(fExecGlob==0)
1228       {
1229         if(fVerb)cout << " set exec " << nameom << endl;
1230         cglobC->AddExec("glob",nameom);
1231         cglobA->AddExec("glob",nameom);
1232         fExecGlob = 1;
1233       }
1234       else
1235       {
1236         cglobC->DeleteExec("glob");
1237         cglobA->DeleteExec("glob");
1238         
1239         if(fVerb)  cout << " set exec " << nameom << endl;
1240         cglobC->AddExec("glob",nameom);
1241         cglobA->AddExec("glob",nameom);
1242         
1243       }
1244       cglobC->Update();
1245       cglobA->Update();
1246     }
1247     
1248   }
1249 }
1250
1251
1252
1253 //__________________________________________________________________
1254 void AliTPCMonitor::DrawRMSMap() 
1255 {
1256   // Draw 2Dim rms histos for IROC and OROC
1257   // and set executables for canvases
1258   
1259   TCanvas* crmsoroc =0;
1260   TCanvas* crmsiroc =0;
1261   if(!(crmsoroc = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("crmsoroc")))    crmsoroc    = CreateCanvas("crmsoroc");
1262   if(!(crmsiroc = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("crmsiroc")))    crmsiroc    = CreateCanvas("crmsiroc");
1263   
1264   crmsiroc->cd();  fHistIROCRMS->Draw("COLZ");
1265   crmsoroc->cd();  fHistOROCRMS->Draw("COLZ");
1266   
1267   Char_t carry1[100];  sprintf(carry1,".x %s/TPC/AliTPCMonitorExec.C(1)",gSystem->Getenv("ALICE_ROOT"));
1268   Char_t carry2[100];  sprintf(carry2,".x %s/TPC/AliTPCMonitorExec.C(2)",gSystem->Getenv("ALICE_ROOT"));
1269   
1270   if(fExecPadIrocRms==0)
1271   {
1272     crmsiroc->AddExec("pad",carry1);
1273     crmsiroc->AddExec("row",carry2);
1274     fExecPadIrocRms=1;
1275   }
1276   
1277   if(fExecPadOrocRms==0)
1278   {
1279     crmsoroc->AddExec("pad",carry1);
1280     crmsoroc->AddExec("row",carry2);
1281     fExecPadOrocRms=1;
1282   }
1283   
1284   crmsiroc->Update();
1285   crmsoroc->Update();
1286   
1287   DrawHists(2);
1288   
1289 }
1290
1291 //__________________________________________________________________
1292 void AliTPCMonitor::ExecPad() 
1293 {
1294   
1295   // Executable for Pad
1296   // Show time profile for channel the mouse is pointing at
1297   
1298   Int_t event = gPad->GetEvent();
1299   if (event != 51)   return;
1300   
1301   TObject *select = gPad->GetSelected();
1302   if(!select)    return;
1303   if(!select->InheritsFrom("TH2")) { return;  }
1304   gPad->GetCanvas()->FeedbackMode(kTRUE);
1305   
1306   // get position
1307   Int_t    px        = gPad->GetEventX();
1308   Int_t    py        = gPad->GetEventY();
1309   Float_t  upy       = gPad->AbsPixeltoY(py);
1310   Float_t  upx       = gPad->AbsPixeltoX(px);
1311   Float_t  y         = gPad->PadtoY(upy);
1312   Float_t  x         = gPad->PadtoX(upx);
1313   
1314   Int_t    setrange  = 0;
1315   
1316   TCanvas* cpad      = 0;
1317   //  Char_t   namehist[50];
1318   Char_t   projhist[60];
1319   Char_t   namesel[256];
1320   Char_t   namecanv[256];
1321   
1322   Int_t    xbinmin  = 0;
1323   Int_t    xbinmax  = 0;
1324   Float_t  ybinmin  = 0;
1325   Float_t  ybinmax  = 0;
1326   Int_t    rocid     = 0;
1327   // Check wich Canvas executed the event
1328   TH2S* fHistIndex=0;
1329   sprintf(namesel,select->GetName());
1330   if(strcmp(namesel,"fHistOROC")==0 || strcmp(namesel,"fHistOROCRMS")==0 || strcmp(namesel,"fHistOROCTime")==0 )
1331   {
1332     rocid = 1;
1333     fPadUsedRoc =1;
1334     sprintf(projhist,"ProjectionOROC");
1335     sprintf(namecanv,"coroc_ch");
1336     fHistIndex = fHistOROCIndex;
1337   }
1338   if(strcmp(namesel,"fHistIROC")==0 || strcmp(namesel,"fHistIROCRMS")==0 || strcmp(namesel,"fHistIROCTime")==0 )
1339   {
1340     rocid = 0;
1341     fPadUsedRoc=0;
1342     sprintf(projhist,"ProjectionIROC");
1343     sprintf(namecanv,"ciroc_ch");
1344     fHistIndex = fHistIROCIndex;
1345   }
1346   
1347   // Check if Canvas already existed and get Ranges from former Prjection histogram
1348   if((cpad=(TCanvas*)gROOT->GetListOfCanvases()->FindObject(namecanv)))
1349   {
1350     cpad->cd();
1351     if(gROOT->Get(projhist))
1352     {
1353       setrange = 1;
1354       xbinmin = ((TH1D*)gROOT->Get(projhist))->GetXaxis()->GetFirst();
1355       xbinmax = ((TH1D*)gROOT->Get(projhist))->GetXaxis()->GetLast();
1356       ybinmin = ((TH1D*)gROOT->Get(projhist))->GetMinimum();
1357       ybinmax = ((TH1D*)gROOT->Get(projhist))->GetMaximum();
1358       delete gROOT->Get("legfit");
1359       delete gROOT->Get("fg");
1360     }
1361   }
1362   else
1363   {
1364     cpad = CreateCanvas(namecanv); cpad->cd();
1365   }
1366   
1367   // Get Bin
1368   Int_t testy = fHistIndex->GetYaxis()->FindBin(y);
1369   Int_t testx = fHistIndex->GetXaxis()->FindBin(x);
1370   Int_t binchannel = (Int_t)fHistIndex->GetCellContent(testx,testy);
1371   if(binchannel>30000 || binchannel<0) return;
1372   
1373   TH1D *hp=(TH1D*)gROOT->Get(projhist);
1374   if(!hp)  hp=new TH1D(projhist,projhist,GetTimeBins(),0,GetTimeBins());//delete gROOT->Get(projhist);
1375   // Get Projection
1376 //   TH1D *hp = (TH1D*)(((TH1D*)fHistChannelTime->ProjectionY("hp",binchannel,binchannel))->Clone(projhist));
1377 //   TH1D *hp = fHistChannelTime->ProjectionY(projhist,binchannel,binchannel);
1378 //   hp->Reset();
1379   Int_t nbinsx=fHistChannelTime->GetNbinsX();
1380   for (Int_t itb=0;itb<GetTimeBins();++itb){
1381     hp->GetArray()[itb]=fHistChannelTime->GetArray()[binchannel+itb*(nbinsx+2)];
1382   }
1383 //   printf("hi\n");
1384 //   return;
1385   
1386   // Make title and Pave for channel Info
1387   Char_t title[256];
1388   Int_t npadRow , npad  , nhw , nmax , hwadd;
1389   
1390   hwadd   = (Int_t)fHistChannelTime->GetCellContent(binchannel,0);
1391   fPadUsedHwAddr = hwadd;
1392   
1393   if(rocid==0)npadRow = fMapHand->GetPadRow(hwadd);
1394   else        npadRow = fMapHand->GetPadRow(hwadd)-63;
1395   npad                = fMapHand->GetPad(hwadd);
1396   nhw                 = hwadd;
1397   nmax                = (Int_t)hp->GetMaximum();
1398   
1399   
1400   TPaveText*  legstat = new TPaveText(0.18,0.65,0.3,0.8,"NDC");
1401   
1402   Int_t   connector   =  fMapHand->GetFECconnector(hwadd);
1403   Int_t   fecnr       =  fMapHand->GetFECfromHw(hwadd);
1404   Int_t   fecch       =  fMapHand->GetFECchannel(hwadd);
1405   Int_t   altrochip   =  fMapHand->GetAltro(hwadd);
1406   Int_t   altrochannel=  (fMapHand->GetAltroChannel(hwadd))%16;
1407   Int_t   fecloc      =  fMapHand->U2fGetFECinRCU(fecnr) ;
1408   Int_t   feclocbran  =  fMapHand->U2fGetFECinBranch(fecnr);
1409   Int_t   branch      =  fMapHand->U2fGetBranch(fecnr);
1410   
1411   
1412   Short_t fecget      = (hwadd & fgkHwMaskFEC)   >> 7;
1413   Short_t branchget   = (hwadd & fgkHwMaskBranch)>> 11;
1414   
1415   
1416   Char_t nstat1[100];  Char_t nstat2[100];  Char_t nstat3[100];  Char_t nstat4[100];
1417   Char_t nstat5[100];  Char_t nstat6[100];  Char_t nstat7[100];  Char_t nstat8[100];
1418   
1419   sprintf(nstat1,"Branch (map) \t %i (%i) \n",branchget,branch);
1420   sprintf(nstat2,"Fec in patch \t %i \n",fecloc);
1421   sprintf(nstat8,"Fec in branch (map)\t %i (%i)\n",fecget,feclocbran);
1422   sprintf(nstat7,"Connector  \t %i \n",connector);
1423   sprintf(nstat3,"Fec No.   \t %i \n",fecnr);
1424   sprintf(nstat4,"Fec chan  \t %i \n",fecch);
1425   sprintf(nstat5,"Altro chip\t %i \n",altrochip);
1426   sprintf(nstat6,"Altro chan\t %i \n",altrochannel);
1427   
1428   legstat->AddText(nstat1); legstat->AddText(nstat2);  legstat->AddText(nstat8);  legstat->AddText(nstat7);
1429   legstat->AddText(nstat3); legstat->AddText(nstat4);  legstat->AddText(nstat5);  legstat->AddText(nstat6);
1430   
1431   sprintf(title,"Row=%d Pad=%d Hw =%d maxADC =%d count =%d",npadRow,npad,nhw,nmax,binchannel);
1432   
1433 //   hp->SetName(projhist);
1434   hp->SetTitleSize(0.04);
1435   hp->SetTitle(title);
1436   hp->SetYTitle("ADC");
1437   hp->SetXTitle("Timebin");
1438   hp->GetXaxis()->SetTitleColor(1);
1439   
1440   if(setrange)
1441   {
1442     hp->GetXaxis()->SetRange(xbinmin,xbinmax);
1443     hp->SetMinimum(ybinmin);
1444     hp->SetMaximum(ybinmax);
1445   }
1446   else
1447   {
1448     hp->SetMinimum(0.0);
1449     hp->SetMaximum(1000.0);
1450   }
1451   
1452   cpad->cd();
1453   hp->Draw();
1454   
1455   // Make Fit to peak
1456   if(GetPedestals() && fDisableFit==0)
1457   {
1458     Int_t maxx  =    (Int_t)fHistAddrMaxAdcX->GetBinContent(hwadd);
1459     Float_t max  =  (Float_t)fHistAddrMaxAdc->GetBinContent(hwadd);
1460     Float_t base =  (Float_t)fHistAddrBaseMean->GetBinContent(hwadd);
1461     if(base!=0)
1462     {
1463       if( ((max+base)/base)>1.2)
1464       {
1465         TF1* fg = new TF1("fg",AliTPCMonitor::Gamma4,maxx-5,maxx+5,4);
1466         fg->SetParName(0,"Normalisation");
1467         fg->SetParName(1,"Minimum");
1468         fg->SetParName(2,"Width");
1469         fg->SetParName(3,"Base");
1470         fg->SetParameter(0,max);
1471         fg->SetParameter(1,maxx-2);
1472         fg->SetParameter(2,1.5);
1473         fg->FixParameter(3,0);
1474         fg->SetLineColor(4);
1475         fg->SetLineWidth(1);
1476         hp->Fit("fg","RQ");
1477         
1478         TLegend* legfit = new TLegend(0.6,0.7,0.7,0.8);
1479         legfit->AddEntry("fg","#Gamma 4 fit","l");
1480         legfit->SetFillColor(0);
1481         legfit->SetName("legfit");
1482         legfit->Draw("same");
1483       }
1484     }
1485   }
1486   legstat->SetFillColor(0);
1487   legstat->Draw("same");
1488   cpad->Update();
1489   return;
1490 }
1491
1492 //__________________________________________________________________
1493 void AliTPCMonitor::ExecRow() 
1494 {
1495   
1496   // Executable for Pad
1497   // Show profile of max adc over given pad row
1498   // and 2dim histo  adc(pad-in-row,time bin)
1499   
1500   Int_t event = gPad->GetEvent();
1501   if (event != 61)    return;
1502   gPad->cd();
1503   TObject *select = gPad->GetSelected();
1504   if(!select)    return;
1505   if(!select->InheritsFrom("TH2")) {   return;  }
1506   
1507   Int_t rocid = 0;
1508   //  Char_t namehist[50];
1509   Char_t rowhist[60];
1510   Char_t rowhistsum[60];
1511   Char_t rowhistmax[60];
1512   Char_t rowhistxmax[60];
1513   
1514   sprintf(rowhist,         "hrowtime");
1515   sprintf(rowhistxmax    ,"hxmax");
1516   sprintf(rowhistmax    , "hrowmax");
1517   
1518   // get position
1519   Int_t   px  = gPad->GetEventX();
1520   Int_t   py  = gPad->GetEventY();
1521   Float_t upy = gPad->AbsPixeltoY(py);
1522   Float_t upx = gPad->AbsPixeltoX(px);
1523   Float_t y   = gPad->PadtoY(upy);
1524   Float_t x   = gPad->PadtoX(upx);
1525   
1526   TCanvas*crowtime   = 0;
1527   TCanvas*crowmax    = 0;
1528   TCanvas*cxmax      = 0;
1529   
1530   TH2S*  fHistIndex  = 0;
1531   
1532   // ranges from already existing histos
1533   Int_t    rowtimexmin = 0;
1534   Int_t    rowtimexmax = 0;
1535   Int_t    rowtimeymin = 0;
1536   Int_t    rowtimeymax = 0;
1537   Float_t  rowtimezmin = 0;
1538   Float_t  rowtimezmax = 0;
1539   
1540   Int_t    profrowxmin = 0;
1541   Int_t    profrowxmax = 0;
1542   Double_t profrowymin = 0;
1543   Double_t profrowymax = 0;
1544   
1545   Int_t    profxxmin   = 0;
1546   Int_t    profxxmax   = 0;
1547   Double_t profxymin   = 0;
1548   Double_t profxymax   = 0;
1549   
1550   
1551   Int_t    setrange      = 0;
1552   
1553   
1554   if(     strcmp(select->GetName(),"fHistIROC")==0 || strcmp(select->GetName(),"fHistIROCRMS")==0 ) { fHistIndex = fHistIROCIndex;     rocid =1;   }
1555   else if(strcmp(select->GetName(),"fHistOROC")==0 || strcmp(select->GetName(),"fHistOROCRMS")==0 ) { fHistIndex = fHistOROCIndex;     rocid =2;   }
1556   else                                                                                  { cout << " not implemented for this histo " << endl; return; }
1557   
1558   gPad->GetCanvas()->FeedbackMode(kTRUE);
1559   
1560   
1561   
1562   // check if canvases exist //
1563   crowtime  = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("crowtime");
1564   crowmax   = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("crowmax");
1565   cxmax     = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("cxmax");
1566   
1567   if(!crowtime)   crowtime   = CreateCanvas("crowtime") ;
1568   if(!crowmax)    crowmax    = CreateCanvas("crowmax")  ;
1569   if(!cxmax  )    cxmax      = CreateCanvas("cxmax")    ;
1570   
1571   // check ranges of already existing histos
1572   if(gROOT->Get(rowhist))
1573   {
1574     rowtimexmin  = ((TH2F*)gROOT->Get(rowhist))->GetXaxis()->GetFirst();
1575     rowtimexmax  = ((TH2F*)gROOT->Get(rowhist))->GetXaxis()->GetLast();
1576     rowtimeymin  = ((TH2F*)gROOT->Get(rowhist))->GetYaxis()->GetFirst();
1577     rowtimeymax  = ((TH2F*)gROOT->Get(rowhist))->GetYaxis()->GetLast();
1578     rowtimezmin  = ((TH2F*)gROOT->Get(rowhist))->GetMinimum();
1579     rowtimezmax  = ((TH2F*)gROOT->Get(rowhist))->GetMaximum();
1580     
1581     profrowxmin  = ((TH1F*)gROOT->Get(rowhistmax))->GetXaxis()->GetFirst();
1582     profrowxmax  = ((TH1F*)gROOT->Get(rowhistmax))->GetXaxis()->GetLast();
1583     profrowymin  = ((TH1F*)gROOT->Get(rowhistmax))->GetMinimum();
1584     profrowymax  = ((TH1F*)gROOT->Get(rowhistmax))->GetMaximum();
1585     
1586     profxxmin    = ((TH1F*)gROOT->Get(rowhistxmax))->GetXaxis()->GetFirst();
1587     profxxmax    = ((TH1F*)gROOT->Get(rowhistxmax))->GetXaxis()->GetLast();
1588     profxymin    = ((TH1F*)gROOT->Get(rowhistxmax))->GetMinimum();
1589     profxymax    = ((TH1F*)gROOT->Get(rowhistxmax))->GetMaximum();
1590     
1591     setrange =1;
1592     
1593     delete gROOT->Get(rowhist);
1594     delete gROOT->Get(rowhistmax);
1595     delete gROOT->Get(rowhistsum);
1596     delete gROOT->Get("hxmax");
1597     delete gROOT->Get("legrow");
1598   }
1599   
1600   // get channel for xy bin -> getRow -> getNrows -> getHw for each Pad in Row -> get channel for each hw -> make proj
1601   Int_t testy      = fHistIndex->GetYaxis()->FindBin(y);
1602   Int_t testx      = fHistIndex->GetXaxis()->FindBin(x);
1603   Int_t binchannel = (Int_t)fHistIndex->GetCellContent(testx,testy);
1604   
1605   if(binchannel>30000)    return;
1606   if(binchannel<=0 ) { crowtime->Update() ;    crowmax->Update() ;    return ;  }
1607   
1608   // get hwaddress
1609   Int_t hwadd     = (Int_t)fHistChannelTime->GetCellContent(binchannel,0);
1610   Int_t row       = fMapHand->GetPadRow(hwadd);
1611   Int_t pad       = fMapHand->GetPad(hwadd)   ;
1612   Int_t numofpads =  fMapHand->GetNumofPads(row);
1613   
1614   // create histos
1615   TH2F *hrowtime = new TH2F(rowhist     , ""  ,numofpads,0,numofpads,GetTimeBins(),0.0,GetTimeBins());
1616   TH1F *hrowmax  = new TH1F(rowhistmax , ""  ,numofpads,0,numofpads);
1617   TH1F *hxmax    = new TH1F(rowhistxmax, ""  ,159,0,159      );
1618   
1619   // Row profile ///////////
1620   if(fVerb) cout << " Number of pads " << numofpads << endl;
1621   for(Int_t padnr = 0; padnr<numofpads;padnr++)
1622   {
1623     Int_t addrinrow = fMapHand->GetPadAddInRow(row,padnr );
1624     Int_t channel   = (Int_t)fHistAddrMapIndex->GetBinContent(addrinrow);
1625     if(channel==-1) continue;
1626     
1627     hrowmax->SetBinContent(padnr+1,fHistAddrMaxAdc->GetBinContent(addrinrow));
1628     TH1D *hp = fHistChannelTime->ProjectionY("hp",channel,channel);
1629     for(Int_t time = 0;time<GetTimeBins();time++) {
1630       
1631       Float_t val = hp->GetBinContent(time);
1632       hrowtime->SetCellContent(padnr+1,time+1,val);
1633     }
1634   }
1635   
1636   // X profile  /////////////
1637   Double_t xval  = 0.0;
1638   Double_t yval  = 0.0;
1639   GetXY(xval,yval,numofpads,row,pad);
1640   
1641   Int_t padnr = 0;
1642   Int_t hw    = 0;
1643   for(Int_t nrow = 0; nrow<159; nrow++)
1644   {
1645     padnr = GetPadAtX(xval,nrow);
1646     if(padnr>=0)
1647     {
1648       hw = fMapHand->GetPadAddInRow(nrow,padnr);
1649       if(fPadMapHw[hw]==-1){ continue                                                      ; }
1650       else                { hxmax->SetBinContent(nrow+1,fHistAddrMaxAdc->GetBinContent(hw))   ; }
1651     }
1652   }
1653   
1654   cxmax->cd();
1655   Char_t hxtitle[50] ; sprintf(hxtitle,"max adc in pads at x=%5.1f mm",xval);
1656   hxmax->SetTitle(hxtitle);
1657   hxmax->SetXTitle("row");
1658   if(!GetPedestals()) hxmax->SetYTitle("max adc (baseline sub.)");
1659   else                hxmax->SetYTitle("max adc ");
1660   hxmax->SetMinimum(0.01);
1661   hxmax->Draw("l");
1662   
1663   if(setrange)
1664   {
1665     hxmax->GetXaxis()->SetRange(profxxmin,profxxmax);
1666     hxmax->SetMinimum(profxymin);
1667     hxmax->SetMaximum(profxymax);
1668   }
1669   
1670   cxmax->Update();
1671   
1672   crowtime->cd();
1673   Char_t title[256];
1674   Char_t titlemax[256];
1675   if(rocid==1) {sprintf(title,"%s Row=%d",((TH2*)select)->GetTitle(),row)   ;    sprintf(titlemax,"IROC  max/sum Row=%d",row   );}
1676   else         {sprintf(title,"%s Row=%d",((TH2*)select)->GetTitle(),row-63);    sprintf(titlemax,"OROC  max/sum Row=%d",row-63);}
1677   if(fVerb) cout << " set name " << endl;
1678   
1679   
1680   // row vs time
1681   crowtime->cd();
1682   hrowtime->SetTitleSize(0.04);
1683   hrowtime->SetTitle(title);
1684   hrowtime->SetYTitle("timbin");
1685   hrowtime->SetXTitle("pad in row");
1686   hrowtime->SetZTitle("signal (ADC)");
1687   
1688   hrowtime->GetXaxis()->SetTitleColor(1);
1689   hrowtime->SetMaximum(1000.0);
1690   hrowtime->SetMinimum(0.0);
1691   
1692   if(setrange)
1693   {
1694     hrowtime->GetXaxis()->SetRange(rowtimexmin,rowtimexmax);
1695     hrowtime->GetYaxis()->SetRange(rowtimeymin,rowtimeymax);
1696     hrowtime->SetMinimum(rowtimezmin);
1697     hrowtime->SetMaximum(rowtimezmax);
1698   }
1699   
1700   hrowtime->Draw("COLZ");
1701   crowtime->UseCurrentStyle();
1702   crowtime->Update();
1703   
1704   // max and sum /////////////////////////
1705   crowmax->cd();
1706   if(setrange) {
1707     hrowmax->GetXaxis()->SetRange(profrowxmin,profrowxmax);
1708     hrowmax->SetMinimum(profrowymin);
1709     hrowmax->SetMaximum(profrowymax);
1710   }
1711   hrowmax->SetTitleSize(0.04);
1712   hrowmax->SetTitle(title);
1713   hrowmax->SetYTitle("max adc");
1714   hrowmax->SetXTitle("pad in row");
1715   hrowmax->GetXaxis()->SetTitleColor(1);
1716   
1717   hrowmax->SetLineColor(2);
1718   hrowmax->Draw("l");
1719   crowmax->Update();
1720   
1721   return;
1722 }
1723
1724 //__________________________________________________________________
1725 void AliTPCMonitor::Write10bitChannel()
1726 {
1727   
1728   // Write 10 bit words form histogram for active(last pointed)  channel
1729   
1730   if(fPadUsedHwAddr==-1){ AliWarning(" No active pad "); return ;}
1731   
1732   Int_t  pad     = (Int_t)fMapHand->GetPad(   fPadUsedHwAddr);
1733   Int_t  row     = (Int_t)fMapHand->GetPadRow(fPadUsedHwAddr);
1734   Int_t  channel = (Int_t)fPadMapHw[fPadUsedHwAddr];
1735   
1736   Char_t filenameroot[256];
1737   Char_t filenamedat[256];
1738   Char_t projhist[256];
1739   
1740   if(fPadUsedRoc==1) { sprintf(projhist,"ProjectionOROC"); }
1741   if(fPadUsedRoc==0) { sprintf(projhist,"ProjectionIROC"); }
1742   
1743   sprintf(filenamedat, "Channel_Run%05i_EventID_%i_Pad_%i_Row_%i.dat"      ,fRunId,fEventNumber,pad,row);
1744   sprintf(filenameroot,"Channel_Run%05i_EventID_%i_Pad_%i_Row_%i.root"     ,fRunId,fEventNumber,pad,row);
1745   
1746   TH1D* hpr = 0;
1747   if((hpr=(TH1D*)gROOT->Get(projhist)))
1748   {
1749       // root histo
1750     TFile f(filenameroot,"recreate");
1751     hpr->Write();
1752     f.Close();
1753     
1754       // raw singal
1755     ofstream datout(filenamedat,ios::out);
1756     datout <<"Timebin \t ADC value " << endl;
1757     for(Int_t i = 1; i <GetTimeBins(); i++)
1758     {
1759       datout << i << " \t \t " << fPad[channel][i] << endl;
1760     }
1761     datout.close();
1762   }
1763   else
1764   {
1765     AliWarning("No projection histo found ");
1766   }
1767 }
1768
1769 //__________________________________________________________________
1770 void AliTPCMonitor::ExecTransform() 
1771 {
1772   
1773   // Make Fast Fourier Transformation for active pad
1774   // fft is only performed for a data sample of size 2^n
1775   // reduce window according to largest  power of 2 which is smaller than the viewing  range
1776   
1777   Char_t namecanv[256];
1778   Char_t namecanv2[256];
1779   Char_t projhist[256];
1780   Char_t namehtrimag[256];
1781   Char_t namehtrreal[256];
1782   Char_t namehtrmag[256];
1783   
1784   if(fPadUsedRoc==1) {    sprintf(namecanv,"coroc_ch_trans") ; sprintf(namecanv2,"coroc_ch_trans2") ;   sprintf(projhist,"ProjectionOROC");  }
1785   if(fPadUsedRoc==0) {    sprintf(namecanv,"ciroc_ch_trans") ; sprintf(namecanv2,"ciroc_ch_trans2") ;  sprintf(projhist,"ProjectionIROC");  }
1786   
1787   TH1D*  hproj = 0;
1788   
1789   if((TH1D*)gROOT->Get(projhist)==0){AliWarning("Proj histo does not exist \n Move mouse over 2d histo choose channel \n and drag mouse form histo again!");  return ;}
1790   else      hproj = (TH1D*)gROOT->Get(projhist) ;
1791   
1792   
1793   if(fPadUsedRoc==1) {  sprintf(namehtrimag,"htransimagfreq_oroc");    sprintf(namehtrreal,"htransrealfreq_oroc"); sprintf(namehtrmag,"htransmagfreq_oroc");  }
1794   else               {  sprintf(namehtrimag,"htransimagfreq_iroc");    sprintf(namehtrreal,"htransrealfreq_iroc"); sprintf(namehtrmag,"htransmagfreq_iroc");  }
1795   
1796   if( gROOT->Get(namehtrimag))  delete  gROOT->Get(namehtrimag);
1797   if( gROOT->Get(namehtrreal))  delete  gROOT->Get(namehtrreal);
1798   if( gROOT->Get(namehtrmag))  delete  gROOT->Get(namehtrmag);
1799   
1800   TCanvas *ctrans = 0;
1801   if(!(ctrans = (TCanvas*)gROOT->GetListOfCanvases()->FindObject(namecanv)))
1802   {
1803     ctrans = CreateCanvas(namecanv);
1804     ctrans->Divide(1,2);
1805   }
1806   TCanvas *ctrans2 = 0;
1807   if(!(ctrans2 = (TCanvas*)gROOT->GetListOfCanvases()->FindObject(namecanv2)))
1808   {
1809     ctrans2 = CreateCanvas(namecanv2);
1810 //      ctrans2->Divide(1,2);
1811   }
1812   
1813   Int_t binfirst  =  hproj->GetXaxis()->GetFirst();
1814   Int_t binlast   =  hproj->GetXaxis()->GetLast();
1815   Int_t bins       =  binlast -binfirst +1;
1816   
1817   Int_t power = 0;
1818   for(Int_t pot = 0; pot<=10 ; pot++)
1819   {
1820     Int_t comp =  (Int_t)TMath::Power(2,pot);
1821     if(bins>=comp)power = pot;
1822   }
1823   
1824   bins = (Int_t)TMath::Power(2,power);
1825   
1826   // sampling frequency ;
1827   Double_t  deltat = 1.0/(Float_t)GetSamplingFrequency();
1828   
1829   // output histo
1830   TH1D* htransrealfreq = new TH1D(namehtrreal,namehtrreal,10000,-1/(2*deltat),1/(2*deltat));
1831   TH1D* htransimagfreq = new TH1D(namehtrimag,namehtrimag,10000,-1/(2*deltat),1/(2*deltat));
1832   TH1D* htransmag      = new TH1D(namehtrmag,namehtrmag,10000,-1/(2*deltat),1/(2*deltat));
1833   
1834   Char_t titlereal[256];
1835   Char_t titleimag[256];
1836   Char_t titlemag[256];
1837   if(fPadUsedRoc==1) {    sprintf(titlereal,"OROC DFT real part");  sprintf(titleimag,"OROC DFT imag part");  sprintf(titlemag,"OROC DFT magnitude");  }
1838   else {                  sprintf(titlereal,"IROC DFT real part");  sprintf(titleimag,"IROC DFT imag part");  sprintf(titlemag,"IROC DFT magnitude");  }
1839   
1840   htransrealfreq->SetTitle(titlereal);  htransrealfreq->SetXTitle("f/hz");  htransrealfreq->SetYTitle("z_{real}(f)");
1841   htransimagfreq->SetTitle(titleimag);  htransimagfreq->SetXTitle("f/hz");  htransimagfreq->SetYTitle("z_{imag}(f)");
1842   htransmag->SetTitle(titlemag);  htransmag->SetXTitle("f/hz");  htransmag->SetYTitle("mag(f)");
1843   
1844   // create complex packed data array
1845   const Int_t kdatasiz = 2*bins;
1846   Double_t*  data = new Double_t[kdatasiz];
1847   for(Int_t i=0;i<2*bins;i++)  { data[i]   =  0.0;}
1848   for(Int_t i=0;i<bins;i++)    { data[2*i] = (Double_t)hproj->GetBinContent(binfirst+i); }
1849   
1850   // make fourier transformation
1851   AliTPCMonitorFFT* four = new AliTPCMonitorFFT();
1852   four->ComplexRadix2ForwardWrap(data,1,bins);
1853   
1854   // write output  and fill histos forward
1855   Double_t freq =  0.0;
1856   for(Int_t i=0;i<2*bins;i++)
1857   {
1858     if(i<bins)
1859     {
1860       if(i<(bins/2))  { freq = i/(bins*deltat)            ; }
1861       else            { freq = -1*((bins-i)/(bins*deltat)); }
1862       htransrealfreq->Fill( freq,data[2*i]  );
1863       htransimagfreq->Fill( freq,data[2*i+1]);
1864       htransmag->Fill( freq, TMath::Sqrt(data[2*i]*data[2*i]+data[2*i+1]*data[2*i+1]) );
1865     }
1866   }
1867   
1868   ctrans->cd(1);
1869   htransrealfreq->Draw();
1870   ctrans->cd(2);
1871   htransimagfreq->Draw();
1872   ctrans->Update();
1873   ctrans2->cd();
1874   htransmag->Draw();
1875   ctrans2->Update();
1876   delete four;
1877   delete [] data;
1878 }
1879
1880 //__________________________________________________________________
1881 void AliTPCMonitor::ShowSel(Int_t* compval)               
1882 {
1883   
1884   // Show only selected components
1885   // First restore original histogram from clone
1886   // Than remove all not matching pads form histos
1887   
1888   Int_t   connector   =  0;
1889   Int_t   fecnr       =  0;
1890   Int_t   altrochip   =  0;
1891   Int_t   feclocbran  =  0;
1892   Int_t   branch      =  0;
1893   Short_t rcuget      =  0;
1894   Int_t   emptyI      =  1;
1895   Int_t   index       = -1;
1896   Int_t   hwadd       =  0;
1897   
1898   Float_t maxiroc     =  fHistIROCClone->GetMaximum();
1899   Float_t maxoroc     =  fHistOROCClone->GetMaximum();
1900   
1901   
1902   //  restore original histos
1903   for(Int_t row = 0; row<fkNRowsIroc;  row++)
1904   {
1905     for(Int_t pad = 0; pad<fkNPadsIroc;  pad++)
1906     {
1907       index = (Int_t)fHistIROCIndex->GetCellContent(row+1,pad+1);
1908       if(index==-1)continue;
1909       else  fHistIROC->SetCellContent(row+1,pad+1,fHistIROCClone->GetCellContent(row+1,pad+1));
1910     }
1911   }
1912   for(Int_t row = 0; row<fkNRowsOroc;  row++)
1913   {
1914     for(Int_t pad = 0; pad<fkNPadsOroc;  pad++)
1915     {
1916       index = (Int_t)fHistOROCIndex->GetCellContent(row+1,pad+1);
1917       if(index==-1)continue;
1918       else    fHistOROC->SetCellContent(row+1,pad+1,fHistOROCClone->GetCellContent(row+1,pad+1));
1919     }
1920   }
1921   
1922   
1923   // remove not matching entries from fHistIROC/fHistOROC
1924   
1925   TH2F* fHist       =0;
1926   TH2S* fHistIndex  =0;
1927   Int_t npads       =0;
1928   Int_t subrows     =0;
1929   
1930   for(Int_t row = 0; row< (fkNRowsIroc + fkNRowsOroc);  row++)
1931   {
1932     if(row<fkNRowsIroc) {  fHist=fHistIROC ; fHistIndex = fHistIROCIndex; npads = fkNPadsIroc; subrows =0         ;}
1933     else                {  fHist=fHistOROC ; fHistIndex = fHistOROCIndex; npads = fkNPadsOroc; subrows =fkNRowsIroc;}
1934     
1935     for(Int_t pad = 0; pad<npads;  pad++)
1936     {
1937       index    = (Int_t)fHistIndex->GetCellContent(row -subrows +1,pad+1);
1938       if(index==-1)  continue ;
1939       hwadd    = (Int_t)fHistChannelTime->GetCellContent(index,0);
1940       
1941     // global fecnr
1942       fecnr     =  fMapHand->GetFECfromHw(hwadd);
1943       if(compval[0]!=-1 && fecnr!=compval[0])      {      fHist->SetCellContent(row-subrows+1,pad+1,0);           continue;     }
1944       
1945     // rcu
1946       rcuget      = (hwadd & fgkHwMaskRCU)>> 12;
1947       if(compval[1]!=-1 && rcuget!=compval[1])     {      fHist->SetCellContent(row-subrows+1,pad+1,0);           continue;     }
1948       
1949     // branch
1950       branch    =  fMapHand->U2fGetBranch(fecnr) ;
1951       if(compval[2]!=-1 && branch!=compval[2])     {      fHist->SetCellContent(row-subrows+1,pad+1,0);           continue;     }
1952       
1953     // local fec
1954       feclocbran=   fMapHand->U2fGetFECinBranch(fecnr) ;
1955       if(compval[3]!=-1 && feclocbran!=compval[3]) {      fHist->SetCellContent(row-subrows+1,pad+1,0);           continue;     }
1956       
1957     // connector
1958       connector =  fMapHand->GetFECconnector(hwadd);
1959       if(compval[4]!=-1 && connector!=compval[4])  {      fHist->SetCellContent(row-subrows+1,pad+1,0);           continue;     }
1960       
1961     // Altro chip
1962       altrochip     =  fMapHand->GetAltro(hwadd);
1963       if(compval[5]!=-1 && altrochip!=compval[5])      {          fHist->SetCellContent(row-subrows+1,pad+1,0);           continue;     }
1964       emptyI =0;
1965     }
1966   }
1967   
1968   TCanvas* c1 =0;
1969   TCanvas* c2 =0;
1970   if(gROOT->GetListOfCanvases()->FindObject("ciroc"))
1971   {
1972     c1 = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("ciroc");
1973     c1->cd() ;
1974     fHistIROC->Draw("COLZ");
1975     fHistIROC->SetMaximum(maxiroc);
1976     fHistIROC->SetMinimum(0.0);
1977     c1->Update();
1978   }
1979   if(gROOT->GetListOfCanvases()->FindObject("coroc"))
1980   {
1981     c2 =  (TCanvas*)gROOT->GetListOfCanvases()->FindObject("coroc");
1982     c2->cd() ;
1983     fHistOROC->Draw("COLZ");
1984     fHistOROC->SetMaximum(maxoroc);
1985     fHistOROC->SetMinimum(0.0);
1986     c2->Update();
1987   }
1988   return ;
1989 }
1990
1991 //__________________________________________________________________
1992 void AliTPCMonitor::ResizeCanv() 
1993 {
1994   // Resize canvases and delete some of them
1995   
1996   Char_t carry1[100];
1997   sprintf(carry1,".x %s/TPC/AliTPCMonitorExec.C(1)",gSystem->Getenv("ALICE_ROOT"));
1998   Char_t carry3[100];
1999   sprintf(carry3,".x %s/TPC/AliTPCMonitorExec.C(2)",gSystem->Getenv("ALICE_ROOT"));
2000   if(fVerb) cout <<  " canv 1 " << endl;
2001   
2002   if(gROOT->GetListOfCanvases()->FindObject(        "coroc_ch")) {  delete gROOT->GetListOfCanvases()->FindObject("coroc_ch") ; }
2003   if(gROOT->GetListOfCanvases()->FindObject(        "ciroc_ch")) {  delete gROOT->GetListOfCanvases()->FindObject("ciroc_ch") ; }
2004   
2005   // for 2dim plots delete create and draw again
2006   if(gROOT->GetListOfCanvases()->FindObject("ciroc"))
2007   {
2008     delete  gROOT->GetListOfCanvases()->FindObject("ciroc");
2009     TCanvas* ciroc = CreateCanvas("ciroc");
2010     ciroc->cd();
2011     fHistIROC->Draw("COLZ");
2012     ciroc->AddExec("pad",carry1);
2013     ciroc->AddExec("row",carry3);
2014     fExecPlaneMax=1;
2015     ciroc->Update();
2016   }
2017   // for 2dim plots delete create and draw again
2018   if(gROOT->GetListOfCanvases()->FindObject("coroc"))
2019   {
2020     delete gROOT->GetListOfCanvases()->FindObject("coroc");
2021     TCanvas* coroc = CreateCanvas("coroc");
2022     coroc->cd();
2023     fHistOROC->Draw("COLZ");
2024     
2025     coroc->AddExec("pad",carry1);
2026     coroc->AddExec("row",carry3);
2027     coroc->Update();
2028     fExecPlaneMax=1;
2029   }
2030   
2031   if(gROOT->GetListOfCanvases()->FindObject(       "cbasemean")) {    delete gROOT->GetListOfCanvases()->FindObject("cbasemean"); }
2032   if(gROOT->GetListOfCanvases()->FindObject(           "cbase")) {    delete gROOT->GetListOfCanvases()->FindObject("cbase");}
2033   if(gROOT->GetListOfCanvases()->FindObject(        "cbaserms")) {    delete gROOT->GetListOfCanvases()->FindObject("cbaserms");  }
2034   if(gROOT->GetListOfCanvases()->FindObject(            "cmax")) {    delete gROOT->GetListOfCanvases()->FindObject("cmax");      }
2035   if(gROOT->GetListOfCanvases()->FindObject(            "csum")) {    delete gROOT->GetListOfCanvases()->FindObject("csum");      }
2036   if(gROOT->GetListOfCanvases()->FindObject(  "ciroc_ch_trans")) {    delete gROOT->GetListOfCanvases()->FindObject("ciroc_ch_trans");}
2037   if(gROOT->GetListOfCanvases()->FindObject(  "coroc_ch_trans")) {    delete gROOT->GetListOfCanvases()->FindObject("coroc_ch_trans");}
2038   if(gROOT->GetListOfCanvases()->FindObject(       "crowtime")) {    delete gROOT->GetListOfCanvases()->FindObject("crowtime"); }
2039   if(gROOT->GetListOfCanvases()->FindObject(        "crowmax")) {    delete gROOT->GetListOfCanvases()->FindObject("crowmax");  }
2040   if(gROOT->GetListOfCanvases()->FindObject(          "cxmax")) {    delete gROOT->GetListOfCanvases()->FindObject("cxmax");    }
2041   if(gROOT->GetListOfCanvases()->FindObject(        "crmsoroc")) {    delete gROOT->GetListOfCanvases()->FindObject("crmsoroc");         fExecPadOrocRms = 0;   }
2042   if(gROOT->GetListOfCanvases()->FindObject(        "crmsiroc")) {    delete gROOT->GetListOfCanvases()->FindObject("crmsiroc");         fExecPadIrocRms = 0;   }
2043   if(gROOT->GetListOfCanvases()->FindObject(        "crowmax")) {    delete gROOT->GetListOfCanvases()->FindObject("crowmax");  }
2044   if(gROOT->GetListOfCanvases()->FindObject(        "crowmax")) {    delete gROOT->GetListOfCanvases()->FindObject("crowmax");  }
2045   
2046 }
2047
2048
2049
2050
2051 //__________________________________________________________________
2052 Int_t AliTPCMonitor::ExecProcess() 
2053 {
2054   // Executable for global Histogram
2055   // Will be called from /TPC/AliTPCMonitorExec.C(3)
2056   // Call ProcessEvent for same event and sector pointed at
2057   
2058   Int_t side   = 0;
2059   Int_t sector = 0;
2060   
2061   Int_t event = gPad->GetEvent();
2062   if(event != 61)  return -1;
2063   
2064   TObject *select = gPad->GetSelected();
2065   if(!select)  return -1;
2066   if(!select->InheritsFrom("TH2")) {gPad->SetUniqueID(0);    return -1;  }
2067   if(       strcmp(select->GetName(),"hglobal" )==0 || ( strcmp(select->GetName(),"SIDE A" )==0) ) side = 0;
2068   else  if( strcmp(select->GetName(),"hglobal2")==0 || ( strcmp(select->GetName(),"SIDE C" )==0) ) side = 1;
2069   
2070   // get position
2071   Int_t   px    = gPad->GetEventX();
2072   Int_t   py    = gPad->GetEventY();
2073   Float_t upy   = gPad->AbsPixeltoY(py);
2074   Float_t upx   = gPad->AbsPixeltoX(px);
2075   Float_t y     = gPad->PadtoY(upy);
2076   Float_t x     = gPad->PadtoX(upx);
2077   
2078   Int_t testy = ((TH2*)select)->GetYaxis()->FindBin(y);
2079   Int_t testx = ((TH2*)select)->GetXaxis()->FindBin(x);
2080   if(((TH2*)select)->GetCellContent(testx,testy)==0) return -1 ;
2081   
2082   Float_t alpha = 0.0;
2083   if(x>0.0 && y > 0.0)    alpha = TMath::Abs(TMath::ATan(TMath::Abs(x/y)));
2084   if(x>0.0 && y < 0.0)    alpha = TMath::Abs(TMath::ATan(TMath::Abs(y/x)));
2085   if(x<0.0 && y < 0.0)    alpha = TMath::Abs(TMath::ATan(TMath::Abs(x/y)));
2086   if(x<0.0 && y > 0.0)    alpha = TMath::Abs(TMath::ATan(TMath::Abs(y/x)));
2087   
2088   if(x>0.0 && y < 0.0)    alpha += (    TMath::Pi()/2);
2089   if(x<0.0 && y < 0.0)    alpha += (    TMath::Pi());
2090   if(x<0.0 && y > 0.0)    alpha += (1.5*TMath::Pi());
2091   
2092   sector =   (Int_t)(alpha/(2*TMath::Pi()/18.0));
2093   if(alpha> (sector+0.5)*(2*TMath::Pi()/18.0))  sector+=1;
2094   
2095   if(sector==18 && side ==0 ) {
2096     AliWarning("There was a wromg assignment of sector 0 with sector 18. Check sectors");
2097     sector =0;
2098   }
2099   
2100   sector = (18-sector +4)%18;
2101   SetLastSector(sector+ side*18);
2102   SetProcNextEvent(0);
2103   
2104   if(fVerb) cout << "AliTPCMonitor::ExecProcess()  next side          " <<   side    << " next sector        " <<    sector  << endl;
2105   
2106   return (Int_t)ProcessEvent();
2107   
2108 }
2109
2110 //__________________________________________________________________
2111 Int_t AliTPCMonitor::GetRCUPatch(Int_t runid, Int_t eqid) const
2112 {
2113   
2114   // Return RCU patch index for given equipment id eqid
2115   Int_t patch = 0;
2116   //if(runid>=704)
2117   if ( eqid<768 || eqid>983 ) return 0; //no TPC eqid
2118   if(runid>=0)
2119   {
2120     if(eqid>=1000) return 0;
2121     patch = fMapEqidsRcu[eqid] ;
2122   }
2123   else
2124   {
2125     if(eqid==408) {patch =  13*6+4 +0;  }
2126     if(eqid==409) {patch =  13*6+5 +0;  }
2127     if(eqid==509) {patch =  13*6+0 +0;  }
2128     if(eqid==512) {patch =  13*6+3 +0;  }
2129     if(eqid==513) {patch =  13*6+1 +0;  }
2130     if(eqid==517) {patch =  13*6+2 +0;  }
2131     
2132     if(eqid==404) {patch =  4*6+5 +0;   }
2133     if(eqid==504) {patch =  4*6+4 +0;   }
2134     if(eqid==407) {patch =  4*6+3 +0;   }
2135     if(eqid==503) {patch =  4*6+2 +0;   }
2136     if(eqid==508) {patch =  4*6+1 +0;   }
2137     if(eqid==506) {patch =  4*6+0 +0;   }
2138   }
2139   return patch;
2140 }
2141
2142 //__________________________________________________________________
2143 void AliTPCMonitor::DumpHeader(AliRawReader * reader) const
2144 {
2145   // Dump Event header for  format
2146   
2147   cout << "EventHeader     : fReader->GetEquipmentSize()            :" << reader->GetEquipmentSize()        << endl;
2148   cout << "EventHeader     : fReader->GetType()                     :" << reader->GetType()                 << endl;
2149   cout << "EventHeader     : fReader->GetRunNumber()                :" << reader->GetRunNumber()            << endl;
2150   cout << "EventHeader     : fReader->GetEventId()                  :" << *(reader->GetEventId())           << endl;
2151   cout << "EventHeader     : fReader->GetLDCId()                    :" << reader->GetLDCId()                << endl;
2152   cout << "EventHeader     : fReader->GetGDCId()                    :" << reader->GetGDCId()                << endl;
2153 }
2154
2155
2156 //__________________________________________________________________
2157 Double_t AliTPCMonitor::Gamma4(Double_t* x, Double_t* par) {
2158   
2159   // Gamma4 function used to fit signals
2160   // Defined in sections: diverging branch set to 0
2161   
2162   Double_t val  = 0.0;
2163   if(x[0] > par[1])
2164     val = par[0]*exp(4.0)* pow((x[0]-par[1])/par[2],4)*exp(-4.0*(x[0]-par[1])/par[2])+ par[3];
2165   else
2166     val = 0;
2167   return val;
2168 }
2169
2170 //__________________________________________________________________
2171 TCanvas* AliTPCMonitor::CreateCanvas(const Char_t* name)
2172 {
2173   // Create Canvases
2174   
2175   TCanvas* canv =0;
2176   
2177   Int_t xoffset  = GetCanvasXOffset();
2178   Int_t xsize    = GetCanvasXSize();
2179   Int_t ysize    = GetCanvasYSize();
2180   Int_t xspace   = GetCanvasXSpace();
2181   Int_t yspace   = GetCanvasYSpace();
2182   
2183   // ROC 2dim max distribution
2184   if(     strcmp(name,"coroc"         )==0) {    canv   = new TCanvas("coroc"         ,"coroc"      ,                   -1+xoffset,(Int_t)(yspace+0.5*ysize) ,(Int_t)(1.5*xsize),(Int_t)(1.5*ysize)); return canv;  }
2185   else if(strcmp(name,"ciroc"         )==0) {    canv   = new TCanvas("ciroc"         ,"ciroc"      ,                   -1+xoffset,                     0    ,(Int_t)(1.5*xsize),(Int_t)(1.5*ysize)); return canv;  }
2186   // ROC  2dim rms distribution
2187   else if(strcmp(name,"crmsoroc"      )==0) {    canv   = new TCanvas("crmsoroc"      ,"crmsoroc"   ,                   -1+xoffset,(Int_t)(yspace+0.5*ysize) ,(Int_t)(1.5*xsize),(Int_t)(1.5*ysize)); return canv;  }
2188   else if(strcmp(name,"crmsiroc"      )==0) {    canv   = new TCanvas("crmsiroc"      ,"crmsiroc"   ,                   -1+xoffset,                        0 ,(Int_t)(1.5*xsize),(Int_t)(1.5*ysize)); return canv;  }
2189   // Global ADC max Histos
2190   else if(strcmp(name,"SIDE C all"    )==0) {    canv   = new TCanvas("SIDE C all"    ,"SIDE C all" ,   (Int_t)(3*xspace+ xoffset),(Int_t)(yspace+0.5*ysize) ,(Int_t)(1.5*xsize),(Int_t)(1.5*ysize)); return canv;  }
2191   else if(strcmp(name,"SIDE A all"    )==0) {    canv   = new TCanvas("SIDE A all"    ,"SIDE A all" ,   (Int_t)(3*xspace+ xoffset),                        0 ,(Int_t)(1.5*xsize),(Int_t)(1.5*ysize)); return canv;  }
2192   // 1 dim max sum basekine distribution
2193   else if(strcmp(name,"cmax"          )==0) {    canv   = new TCanvas("cmax"          ,"cmax"       ,                   -1+xoffset,                 3*yspace ,(Int_t)(1.0*xsize),(Int_t)(1.0*ysize)); return canv;  }
2194   else if(strcmp(name,"csum"          )==0) {    canv   = new TCanvas("csum"          ,"csum"       ,               xspace+xoffset,                 3*yspace ,(Int_t)(1.0*xsize),(Int_t)(1.0*ysize)); return canv;  }
2195   else if(strcmp(name,"cbasemean"     )==0) {    canv   = new TCanvas("cbasemean"     ,"cbasemean"  ,             2*xspace+xoffset,                 3*yspace ,(Int_t)(1.0*xsize),(Int_t)(1.0*ysize)); return canv;  }
2196   else if(strcmp(name,"cbaserms"      )==0) {    canv   = new TCanvas("cbaserms"      ,"cbaserms"   ,             3*xspace+xoffset,                 3*yspace ,(Int_t)(1.0*xsize),(Int_t)(1.0*ysize)); return canv;  }
2197   // Projections of single channel
2198   else if(strcmp(name,"coroc_ch"      )==0) {    canv   = new TCanvas("coroc_ch"      ,"coroc_ch"   ,   (Int_t)(1.5*xspace+xoffset),(Int_t)(yspace+0.5*ysize),(Int_t)(1.5*xsize),(Int_t)(1.5*ysize)); return canv;  }
2199   else if(strcmp(name,"ciroc_ch"      )==0) {    canv   = new TCanvas("ciroc_ch"      ,"ciroc_ch"   ,   (Int_t)(1.5*xspace+xoffset),                       0 ,(Int_t)(1.5*xsize),(Int_t)(1.5*ysize)); return canv;  }
2200   // FFT for single channel
2201   else if(strcmp(name,"coroc_ch_trans")==0) {    canv   = new TCanvas("coroc_ch_trans","coroc_ch_trans",(Int_t)(3.0*xspace+xoffset),(Int_t)(yspace+0.5*ysize),(Int_t)(1.5*xsize),(Int_t)(1.5*ysize)); return canv;  }
2202   else if(strcmp(name,"ciroc_ch_trans")==0) {    canv   = new TCanvas("ciroc_ch_trans","ciroc_ch_trans",(Int_t)(3.0*xspace+xoffset),                       0 ,(Int_t)(1.5*xsize),(Int_t)(1.5*ysize)); return canv;  }
2203   else if(strcmp(name,"coroc_ch_trans2")==0) {    canv   = new TCanvas("coroc_ch_trans2","coroc_ch_trans2",(Int_t)(3.0*xspace+xoffset),(Int_t)(yspace+0.5*ysize),(Int_t)(1.5*xsize),(Int_t)(1.5*ysize)); return canv;  }
2204   else if(strcmp(name,"ciroc_ch_trans2")==0) {    canv   = new TCanvas("ciroc_ch_trans2","ciroc_ch_trans2",(Int_t)(3.0*xspace+xoffset),                       0 ,(Int_t)(1.5*xsize),(Int_t)(1.5*ysize)); return canv;  }
2205   // row profile histograms
2206   else if(strcmp(name,"crowtime"     )==0) {    canv   = new TCanvas("crowtime"     ,"crowtime"  ,              1*xspace+xoffset,         2*yspace +ysize ,(Int_t)(1.0*xsize),(Int_t)(1.0*ysize)); return canv;  }
2207   else if(strcmp(name,"crowmax"      )==0) {    canv   = new TCanvas("crowmax"      ,"crowmax"   ,              2*xspace+xoffset,         2*yspace +ysize ,(Int_t)(1.0*xsize),(Int_t)(1.0*ysize)); return canv;  }
2208   else if(strcmp(name,"cxmax"        )==0) {    canv   = new TCanvas("cxmax"        ,"cxmax"     ,              3*xspace+xoffset,         2*yspace +ysize ,(Int_t)(1.0*xsize),(Int_t)(1.0*ysize)); return canv;  }
2209   else                                      {    cout   << " Warning Canvas name unknown "  << endl;                                                                                                  return 0   ;  }
2210 }
2211
2212 //__________________________________________________________________
2213 void AliTPCMonitor::WriteHistos()  
2214 {
2215   // Writes all available histograms to a file in current directory
2216   // File name will be specified by : sector, side, runid and eventnumber
2217   
2218   if(GetEventProcessed())
2219   {
2220     AliInfo("Write histos to file");
2221     Char_t name[256];
2222     sprintf(name,"SIDE_%i_SECTOR_%02i_RUN_%05i_EventID_%06i.root",(GetLastSector()/18),(GetLastSector()%18),fRunId,fEventNumber);
2223     TFile* f = new TFile(name,"recreate");
2224     for(Int_t i =0; i<fHistList->GetEntries(); i++)
2225     {
2226       if(((TH1*)fHistList->At(i))!=0)
2227       {
2228         ((TH1*)fHistList->At(i))->Write();
2229       }
2230     }
2231     f->ls();
2232     f->Close();
2233   }
2234   else
2235   {
2236     AliError("No Event Processed : Chose Format , File and push 'Next Event' ");
2237   }
2238 }
2239
2240
2241 //__________________________________________________________________
2242 TH1* AliTPCMonitor::GetHisto(char* histname) 
2243 {
2244   
2245   // Returns histogram specified by histname
2246   // check available names for histos in CreateHistos()
2247   
2248   TH1* hist = 0;
2249   if((TH1*)fHistList->FindObject(histname))
2250   {
2251     hist = (TH1*)fHistList->FindObject(histname);
2252   }
2253   else
2254   {
2255     cout << " AliTPCMonitor::GetHisto :: Can not find histo with name " << histname << endl;
2256   }
2257   return hist ;
2258 }