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