]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCMonitor.cxx
Iteration number stored into output file
[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           return;
931           //Int_t hw_before1 = fPad[fChannelIter-2][0];
932           //Int_t hw_before2 = fPad[fChannelIter-3][0];
933           
934           if(fVerb){ cout  <<"\n //// Ambiguous hwaddress "   << nextHwAddress << "  write 10bit files and check file for eqid : "  << fEqId << " /////// " << endl;}
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           GetXY(xval ,yval , padmax,row ,pad);
1257           xdr    =  xval*m11 +yval*m12;
1258           ydr    =  xval*m21 +yval*m22;
1259           if(hglob->GetBinContent(hglob->GetXaxis()->FindBin(xdr),hglob->GetYaxis()->FindBin(ydr))==0)   hglob->Fill(xdr,ydr,(Int_t)max);
1260         }
1261     }
1262 }
1263
1264
1265 //__________________________________________________________________
1266 void AliTPCMonitor::GetXY( Double_t& xval , Double_t& yval , Int_t padmax, Int_t row , Int_t pad) const 
1267 {
1268   // Get x and y position of pad
1269   
1270   if(row<63) 
1271     {
1272       xval = fMirror*( 2*padmax -4*pad -2);
1273       yval = 852.25 +7.5*row;
1274     } 
1275   else 
1276     {
1277       xval = fMirror*( 3*padmax -6*pad -3);
1278       if((row-63)<63) {   yval = 10*(row-63) +1351;     } 
1279       else            {   yval = 15*(row-63-64)+1993.5; }
1280     }
1281   
1282
1283
1284 //__________________________________________________________________
1285 Int_t AliTPCMonitor::GetPadAtX(Float_t xval, Int_t row, Int_t padmax) const
1286 {
1287   // Get pad number at given position in x
1288   Int_t pad    = 0;
1289   
1290   if(row<63) {pad = (Int_t)( ( (xval/fMirror) +2 -2*padmax)/-4);}
1291   else       {pad = (Int_t)( ( (xval/fMirror) +3 -3*padmax)/-6);}
1292   
1293   if(pad>=padmax) return -1;
1294   else            return pad ;
1295   
1296 }
1297
1298 //__________________________________________________________________
1299 Int_t AliTPCMonitor::GetPadAtX(Float_t xval, Int_t row) const
1300 {
1301
1302  // Get pad number at given position in x
1303
1304   Int_t padmax = fMapHand->GetNumofPads(row);
1305   Int_t pad    = 0;
1306   
1307   if(row<63) {pad = (Int_t)( ( (xval/fMirror) +2 -2*padmax)/-4);}
1308   else       {pad = (Int_t)( ( (xval/fMirror) +3 -3*padmax)/-6);}
1309   
1310   if(pad>=padmax) return -1;
1311   else            return pad ;
1312   
1313 }
1314
1315 //__________________________________________________________________
1316 void AliTPCMonitor::DrawHists(Int_t histos) 
1317 {
1318
1319   // Draw sets of histograms
1320   // histos==1 : 2Dim histos for MAX adc  and add executables
1321   // histos==2 : distributions max/rms/sum 
1322   // histos==3 : global max adc for specified SideA/C
1323
1324
1325   if(fVerb)    cout << " Draw histos " << endl;  
1326   Char_t cside[10];
1327   if(GetLastSector()/18==0 ) sprintf(cside,"A");
1328   else                       sprintf(cside,"C");
1329   
1330   Char_t titleSEC[256];   sprintf(titleSEC   ,"Sector %i Side %s Run : %05i EventID %i "       ,GetLastSector()%18,cside,fRunId, fEventNumber);
1331   Char_t titleEvent[256]; sprintf(titleEvent ,"Time <-> Channles  %s"                          ,titleSEC);
1332   Char_t titleIROC[256];  sprintf(titleIROC  ,"IROC %s"                                        ,titleSEC);
1333   Char_t titleOROC[256];  sprintf(titleOROC  ,"OROC %s"                                        ,titleSEC);
1334   
1335   Char_t titleMAX[256];   sprintf(titleMAX   ,"Max (timebin: %i,%i) %s"                        ,GetRangeMaxAdcMin(),GetRangeMaxAdcMax(),titleSEC);
1336   Char_t titleSUM[256];   sprintf(titleSUM   ,"Sum (timebin: %i,%i) %s"                        ,GetRangeSumMin()   ,GetRangeSumMax()   ,titleSEC);
1337   Char_t titleBASE[256];  sprintf(titleBASE  ,"Baseline RMS<->Mean  (timebin: %i-%i) %s"       ,GetRangeBaseMin()  ,GetRangeBaseMax()  ,titleSEC);
1338   Char_t titleMEAN[256];  sprintf(titleMEAN  ,"Baseline Mean (timebin: %i-%i) %s"              ,GetRangeBaseMin()  ,GetRangeBaseMax()  ,titleSEC);
1339   Char_t titleRMS[256] ;  sprintf(titleRMS   ,"Baseline RMS (timebin: %i-%i) %s"               ,GetRangeBaseMin()  ,GetRangeBaseMax()  ,titleSEC);
1340
1341   if(histos==1) 
1342     {
1343       // IROC _______________________________________________________________
1344       TCanvas* ciroc = 0;
1345       ciroc = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("ciroc");
1346       if(!ciroc) 
1347         {
1348           ciroc = CreateCanvas("ciroc");
1349           fExecPlaneMax=0;
1350         }
1351       ciroc->cd();
1352       
1353       fHistIROC->SetXTitle("row");
1354       fHistIROC->SetYTitle("pad");
1355       if(GetPedestals()) fHistIROC->SetZTitle("max ADC (baseline sub)");
1356       else               fHistIROC->SetZTitle("max ADC ");
1357       fHistIROC->SetTitle(titleIROC);
1358       fHistIROC->SetMinimum(0.01);
1359       fHistIROC->Draw("COLZ");
1360       ciroc->UseCurrentStyle();
1361       
1362       
1363       fHistIROCTime->SetXTitle("row"); fHistIROCTime->SetZTitle("peak time (fit)");       fHistIROCTime->SetYTitle("pad");      fHistIROCTime->SetTitle(titleIROC);
1364       fHistIROCRMS->SetXTitle("row");  fHistIROCRMS->SetZTitle( "baseline rms (ADC)");    fHistIROCRMS->SetYTitle("pad");       fHistIROCRMS->SetTitle(titleIROC);
1365       
1366       // OROC
1367       TCanvas* coroc = 0;
1368       coroc =(TCanvas*)gROOT->GetListOfCanvases()->FindObject("coroc");
1369       if(!coroc) {
1370         coroc = CreateCanvas("coroc");
1371         fExecPlaneMax=0;
1372       }
1373       coroc->cd();
1374       
1375       fHistOROC->SetXTitle("row");
1376       fHistOROC->SetYTitle("pad");
1377       if(GetPedestals()) fHistOROC->SetZTitle("max ADC (baseline sub)");
1378       else               fHistOROC->SetZTitle("max ADC ");
1379       fHistOROC->SetTitle(titleOROC);
1380       fHistOROC->SetMinimum(0.01);
1381       fHistOROC->Draw("COLZ");
1382       coroc->UseCurrentStyle();
1383       
1384
1385       fHistOROCTime->SetXTitle("row"); fHistOROCTime->SetZTitle("peak time (fit) (timebins)"); fHistOROCTime->SetYTitle("pad"); fHistOROCTime->SetTitle(titleOROC);
1386       fHistOROCRMS->SetXTitle("row");  fHistOROCRMS->SetZTitle("baseline rms (ADC)");          fHistOROCRMS->SetYTitle("pad");  fHistOROCRMS->SetTitle(titleOROC);
1387
1388       // SUM 
1389       Char_t namesum[256] ; sprintf(namesum,"ADC sum (bins: %i, %i)",GetRangeSumMin() ,GetRangeSumMax() );
1390       fHistIROCSUM->SetXTitle("row");      fHistIROCSUM->SetZTitle(namesum);      fHistIROCSUM->SetYTitle("pad");      fHistIROCSUM->SetTitle(titleIROC);
1391       fHistOROCSUM->SetXTitle("row");      fHistOROCSUM->SetZTitle(namesum);      fHistOROCSUM->SetYTitle("pad");      fHistOROCSUM->SetTitle(titleOROC);
1392     
1393       // BASE
1394       Char_t namebase[256] ; sprintf(namebase ,"base mean (timbebin: %i, %i )",GetRangeBaseMin(),GetRangeBaseMax());
1395       fHistIROCBASE->SetXTitle("row"); fHistIROCBASE->SetZTitle(namebase);  fHistIROCBASE->SetYTitle("pad");      fHistIROCBASE->SetTitle(titleIROC);
1396       fHistOROCBASE->SetXTitle("row"); fHistOROCBASE->SetZTitle(namebase);  fHistOROCBASE->SetYTitle("pad");      fHistOROCBASE->SetTitle(titleOROC);
1397
1398       if(fHistIROCClone) fHistIROCClone->Delete();
1399       if(fHistOROCClone) fHistOROCClone->Delete();
1400       fHistIROCClone = (TH2F*)fHistIROC->Clone("fHistIROCClone");
1401       fHistOROCClone = (TH2F*)fHistOROC->Clone("fHistOROCClone");
1402       
1403       // Executables
1404       if(fExecPlaneMax==0) 
1405         {
1406           Char_t carry1[100];
1407           sprintf(carry1,".x %s/TPC/AliTPCMonitorExec.C(1)",gSystem->Getenv("ALICE_ROOT"));
1408           ciroc->AddExec("pad",carry1);
1409           coroc->AddExec("pad",carry1);
1410           
1411           Char_t carry2[100];
1412           sprintf(carry2,".x %s/TPC/AliTPCMonitorExec.C(2)",gSystem->Getenv("ALICE_ROOT"));
1413           ciroc->AddExec("row",carry2);
1414           coroc->AddExec("row",carry2);
1415           fExecPlaneMax=1;
1416         }
1417       coroc->Update();
1418       ciroc->Update();
1419     }
1420   else if(histos==2) 
1421     {
1422       // MAX ADC distribution  ____________________________________________
1423       TCanvas* cmax = 0;
1424       cmax = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("cmax");
1425       if(!cmax)  cmax = CreateCanvas("cmax"); 
1426     
1427       cmax->cd();
1428       fHistDistrMaxIROC->GetXaxis()->SetRangeUser(0.0,1000.0);
1429       fHistDistrMaxIROC->SetXTitle("max ADC (ADC)");
1430       fHistDistrMaxIROC->SetYTitle("counts");
1431       fHistDistrMaxIROC->SetTitle(titleMAX);
1432       fHistDistrMaxIROC->Draw("");
1433       fHistDistrMaxOROC->SetLineColor(2);
1434       fHistDistrMaxOROC->Draw("same");
1435     
1436       if(fHistDistrMaxOROC->GetMaximum()> fHistDistrMaxIROC->GetMaximum())  fHistDistrMaxIROC->SetMaximum(fHistDistrMaxOROC->GetMaximum()*1.1);
1437       
1438       TLegend* legio = new TLegend(0.6,0.6,0.8,0.8);
1439       legio->SetFillColor(0);
1440       legio->AddEntry(fHistDistrMaxIROC,"IROC","l");
1441       legio->AddEntry(fHistDistrMaxOROC,"OROC","l");
1442       legio->Draw("same");
1443     
1444       // ADC sum distribution
1445       TCanvas* csum = 0;
1446       csum = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("csum");
1447       if(!csum)  csum = CreateCanvas("csum") ;
1448       csum->cd();
1449     
1450       fHistDistrSumIROC->SetXTitle("sum ADC (ADC)");
1451       fHistDistrSumIROC->SetYTitle("counts");
1452       fHistDistrSumIROC->SetTitle(titleSUM);
1453       fHistDistrSumIROC->Draw("");
1454       fHistDistrSumOROC->SetLineColor(2);
1455       fHistDistrSumOROC->Draw("same");
1456       if(fHistDistrSumOROC->GetMaximum()> fHistDistrSumIROC->GetMaximum())  fHistDistrSumIROC->SetMaximum(fHistDistrSumOROC->GetMaximum()*1.1);
1457       legio->Draw("same");
1458     
1459       // BASELINE MEAN distribution
1460       TCanvas* cbasemean = 0;
1461       cbasemean = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("cbasemean");
1462       if(!cbasemean)  cbasemean = CreateCanvas("cbasemean"); 
1463       cbasemean->cd();
1464     
1465       fHistDistrBaseMeanIROC = fHistDistrBase2dIROC->ProjectionX("fHistDistrBaseMeanIROC");
1466       fHistDistrBaseMeanIROC->SetXTitle("base mean (ADC)");
1467       fHistDistrBaseMeanIROC->SetYTitle("counts");
1468       fHistDistrBaseMeanIROC->SetTitle(titleMEAN);
1469       fHistDistrBaseMeanIROC->Draw("");
1470     
1471       fHistDistrBaseMeanOROC = fHistDistrBase2dOROC->ProjectionX("fHistDistrBaseMeanOROC");
1472       fHistDistrBaseMeanOROC->SetLineColor(2);
1473       fHistDistrBaseMeanOROC->Draw("same");
1474       if(fHistDistrBaseMeanOROC->GetMaximum()>fHistDistrBaseMeanIROC->GetMaximum())   fHistDistrBaseMeanIROC->SetMaximum(fHistDistrBaseMeanOROC->GetMaximum()*1.1);
1475       legio->Draw("same");
1476
1477       TCanvas* cbaserms = 0;
1478       cbaserms = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("cbaserms");
1479       if(!cbaserms) cbaserms = CreateCanvas("cbaserms") ;
1480       cbaserms->cd();
1481     
1482       // BASELINE RMS distribution
1483       fHistDistrBaseRmsIROC = fHistDistrBase2dIROC->ProjectionY("fHistDistrBaseRmsIROC");
1484       fHistDistrBaseRmsIROC->SetXTitle("base rms (ADC)");
1485       fHistDistrBaseRmsIROC->SetYTitle("counts");
1486       fHistDistrBaseRmsIROC->SetTitle(titleRMS);
1487       fHistDistrBaseRmsIROC->Draw("");
1488     
1489       fHistDistrBaseRmsOROC = fHistDistrBase2dOROC->ProjectionY("fHistDistrBaseRmsOROC");
1490       fHistDistrBaseRmsOROC->SetLineColor(2);
1491       fHistDistrBaseRmsOROC->Draw("same");
1492       if(fHistDistrBaseRmsOROC->GetMaximum()>fHistDistrBaseRmsIROC->GetMaximum())  fHistDistrBaseRmsIROC->SetMaximum(fHistDistrBaseRmsOROC->GetMaximum()*1.1);
1493       legio->Draw("same");
1494     
1495       cmax->Update();
1496       csum->Update();
1497       cbasemean->Update();
1498       cbaserms->Update();
1499     }
1500   else  if(histos==3)
1501     {
1502       // GLOBAL MAX ADC _________________________________
1503       if(GetProcNextEvent()==1)
1504         {
1505           TCanvas* cglobA =0;
1506           TCanvas* cglobC =0;
1507             
1508           if(!(cglobC=(TCanvas*)gROOT->GetListOfCanvases()->FindObject("SIDE C all"))) cglobC = CreateCanvas("SIDE C all"); 
1509           if(!(cglobA=(TCanvas*)gROOT->GetListOfCanvases()->FindObject("SIDE A all"))) cglobA = CreateCanvas("SIDE A all"); 
1510             
1511           Char_t globtitle1[256]; sprintf(globtitle1,"SIDE A Run %05i (EventID %i)",fRunId,fEventNumber);
1512           Char_t globtitle2[256]; sprintf(globtitle2,"SIDE C Run %05i (EventID %i)",fRunId,fEventNumber);
1513             
1514           fHistGlobalMaxA->SetTitle(globtitle1);
1515           fHistGlobalMaxC->SetTitle(globtitle2);
1516           fHistGlobalMaxA->SetXTitle("x/mm");
1517           fHistGlobalMaxA->SetYTitle("y/mm");
1518           fHistGlobalMaxC->SetXTitle("x/mm");
1519           fHistGlobalMaxC->SetYTitle("y/mm");
1520             
1521           if(GetPedestals()==0)     {         fHistGlobalMaxA->SetZTitle("max adc (not baseline sub)");   fHistGlobalMaxC->SetZTitle("max adc (not baseline sub)");  }
1522           else                      {         fHistGlobalMaxA->SetZTitle("max adc ");                     fHistGlobalMaxC->SetZTitle("max adc ");                          }
1523           
1524           fHistGlobalMaxA->SetMinimum(0.01);
1525           fHistGlobalMaxC->SetMinimum(0.01);
1526             
1527           cglobC->cd() ; fHistGlobalMaxC->Draw("COLZ");
1528           cglobA->cd() ; fHistGlobalMaxA->Draw("COLZ");
1529             
1530           Char_t nameom[256];
1531           sprintf(nameom,".x  %s/TPC/AliTPCMonitorExec.C(3)",gSystem->Getenv("ALICE_ROOT"));
1532             
1533           if(fExecGlob==0) 
1534             { 
1535               if(fVerb)cout << " set exec " << nameom << endl;
1536               cglobC->AddExec("glob",nameom);
1537               cglobA->AddExec("glob",nameom);
1538               fExecGlob = 1;
1539             } 
1540           else 
1541             {
1542               cglobC->DeleteExec("glob");
1543               cglobA->DeleteExec("glob");
1544                 
1545               if(fVerb)  cout << " set exec " << nameom << endl;
1546               cglobC->AddExec("glob",nameom);
1547               cglobA->AddExec("glob",nameom);
1548                 
1549             }
1550           cglobC->Update();
1551           cglobA->Update();
1552         }
1553       
1554     }
1555 }
1556
1557
1558
1559 //__________________________________________________________________
1560 void AliTPCMonitor::DrawRMSMap() 
1561 {
1562   // Draw 2Dim rms histos for IROC and OROC 
1563   // and set executables for canvases
1564   
1565   TCanvas* crmsoroc =0;
1566   TCanvas* crmsiroc =0;
1567   if(!(crmsoroc = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("crmsoroc")))    crmsoroc    = CreateCanvas("crmsoroc");
1568   if(!(crmsiroc = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("crmsiroc")))    crmsiroc    = CreateCanvas("crmsiroc");
1569    
1570   crmsiroc->cd();  fHistIROCRMS->Draw("COLZ");
1571   crmsoroc->cd();  fHistOROCRMS->Draw("COLZ");
1572  
1573   Char_t carry1[100];  sprintf(carry1,".x %s/TPC/AliTPCMonitorExec.C(1)",gSystem->Getenv("ALICE_ROOT"));
1574   Char_t carry2[100];  sprintf(carry2,".x %s/TPC/AliTPCMonitorExec.C(2)",gSystem->Getenv("ALICE_ROOT"));
1575  
1576   if(fExecPadIrocRms==0) 
1577     {
1578       crmsiroc->AddExec("pad",carry1);
1579       crmsiroc->AddExec("row",carry2);
1580       fExecPadIrocRms=1;
1581     }
1582   
1583   if(fExecPadOrocRms==0) 
1584     {
1585       crmsoroc->AddExec("pad",carry1);
1586       crmsoroc->AddExec("row",carry2);
1587       fExecPadOrocRms=1;
1588     }
1589   
1590   crmsiroc->Update();
1591   crmsoroc->Update();
1592   
1593   DrawHists(2); 
1594
1595 }
1596
1597 //__________________________________________________________________
1598 void AliTPCMonitor::ExecPad() 
1599 {
1600
1601   // Executable for Pad 
1602   // Show time profile for channel the mouse is pointing at 
1603   
1604   Int_t event = gPad->GetEvent();
1605   if (event != 51)   return;
1606   
1607   TObject *select = gPad->GetSelected();
1608   if(!select)    return;
1609   if(!select->InheritsFrom("TH2")) { return;  }
1610   gPad->GetCanvas()->FeedbackMode(kTRUE);
1611   
1612   // get position
1613   Int_t    px        = gPad->GetEventX();
1614   Int_t    py        = gPad->GetEventY();
1615   Float_t  upy       = gPad->AbsPixeltoY(py);
1616   Float_t  upx       = gPad->AbsPixeltoX(px);
1617   Float_t  y         = gPad->PadtoY(upy);
1618   Float_t  x         = gPad->PadtoX(upx);
1619
1620   Int_t    setrange  = 0;
1621   
1622   TCanvas* cpad      = 0;
1623   //  Char_t   namehist[50];
1624   Char_t   projhist[60];
1625   Char_t   namesel[256];
1626   Char_t   namecanv[256];
1627
1628   Int_t    xbinmin  = 0;
1629   Int_t    xbinmax  = 0;
1630   Float_t  ybinmin  = 0;
1631   Float_t  ybinmax  = 0;
1632   Int_t    rocid     = 0;
1633   
1634   // Check wich Canvas executed the event 
1635   TH2S* fHistIndex=0;
1636   sprintf(namesel,select->GetName());
1637   if(strcmp(namesel,"fHistOROC")==0 || strcmp(namesel,"fHistOROCRMS")==0 || strcmp(namesel,"fHistOROCTime")==0 ) 
1638     {
1639       rocid = 1;
1640       fPadUsedRoc =1;
1641       sprintf(projhist,"ProjectionOROC");
1642       sprintf(namecanv,"coroc_ch");
1643       fHistIndex = fHistOROCIndex;
1644     }
1645   if(strcmp(namesel,"fHistIROC")==0 || strcmp(namesel,"fHistIROCRMS")==0 || strcmp(namesel,"fHistIROCTime")==0 ) 
1646     {
1647       rocid = 0;
1648       fPadUsedRoc=0;
1649       sprintf(projhist,"ProjectionIROC");
1650       sprintf(namecanv,"ciroc_ch");
1651       fHistIndex = fHistIROCIndex; 
1652     }
1653   
1654   // Check if Canvas already existed and get Ranges from former Prjection histogram 
1655   if((cpad=(TCanvas*)gROOT->GetListOfCanvases()->FindObject(namecanv))) 
1656     {
1657       cpad->cd();
1658       if(gROOT->Get(projhist)) 
1659         {
1660           setrange = 1;
1661           xbinmin = ((TH1D*)gROOT->Get(projhist))->GetXaxis()->GetFirst();
1662           xbinmax = ((TH1D*)gROOT->Get(projhist))->GetXaxis()->GetLast();
1663           ybinmin = ((TH1D*)gROOT->Get(projhist))->GetMinimum();
1664           ybinmax = ((TH1D*)gROOT->Get(projhist))->GetMaximum();
1665           delete gROOT->Get("legfit");
1666           delete gROOT->Get("fg");
1667         }
1668     } 
1669   else 
1670     {
1671       cpad = CreateCanvas(namecanv); cpad->cd();
1672     }
1673   
1674   // Get Bin 
1675   Int_t testy = fHistIndex->GetYaxis()->FindBin(y);
1676   Int_t testx = fHistIndex->GetXaxis()->FindBin(x);
1677   Int_t binchannel = (Int_t)fHistIndex->GetCellContent(testx,testy);
1678   if(binchannel>30000 || binchannel<0) return;
1679
1680   if(gROOT->Get(projhist))  delete gROOT->Get(projhist);
1681   // Get Projection   
1682   TH1D *hp = (TH1D*)(((TH1D*)fHistChannelTime->ProjectionY("hp",binchannel,binchannel))->Clone(projhist));
1683   
1684   // Make title and Pave for channel Info
1685   Char_t title[256];
1686   Int_t npadRow , npad  , nhw , nmax , hwadd;
1687   
1688   hwadd   = (Int_t)fHistChannelTime->GetCellContent(binchannel,0);
1689   fPadUsedHwAddr = hwadd;
1690   
1691   if(rocid==0)npadRow = fMapHand->GetPadRow(hwadd);
1692   else        npadRow = fMapHand->GetPadRow(hwadd)-63;
1693   npad                = fMapHand->GetPad(hwadd);
1694   nhw                 = hwadd;
1695   nmax                = (Int_t)hp->GetMaximum();
1696   
1697
1698   TPaveText*  legstat = new TPaveText(0.18,0.65,0.3,0.8,"NDC");
1699
1700   Int_t   connector   =  fMapHand->GetFECconnector(hwadd);
1701   Int_t   fecnr       =  fMapHand->GetFECfromHw(hwadd);
1702   Int_t   fecch       =  fMapHand->GetFECchannel(hwadd);
1703   Int_t   altrochip   =  fMapHand->GetAltro(hwadd);
1704   Int_t   altrochannel=  (fMapHand->GetAltroChannel(hwadd))%16;
1705   Int_t   fecloc      =  fMapHand->U2fGetFECinRCU(fecnr) ;
1706   Int_t   feclocbran  =  fMapHand->U2fGetFECinBranch(fecnr);
1707   Int_t   branch      =  fMapHand->U2fGetBranch(fecnr);
1708
1709   
1710   Short_t fecget      = (hwadd & AliTPCMonitorAltro::GetHwMaskFEC())   >> 7;
1711   Short_t branchget   = (hwadd & AliTPCMonitorAltro::GetHwMaskBranch())>> 11;
1712
1713
1714   Char_t nstat1[100];  Char_t nstat2[100];  Char_t nstat3[100];  Char_t nstat4[100];  
1715   Char_t nstat5[100];  Char_t nstat6[100];  Char_t nstat7[100];  Char_t nstat8[100];
1716   
1717   sprintf(nstat1,"Branch (map) \t %i (%i) \n",branchget,branch);
1718   sprintf(nstat2,"Fec in patch \t %i \n",fecloc);
1719   sprintf(nstat8,"Fec in branch (map)\t %i (%i)\n",fecget,feclocbran);
1720   sprintf(nstat7,"Connector  \t %i \n",connector);
1721   sprintf(nstat3,"Fec No.   \t %i \n",fecnr);
1722   sprintf(nstat4,"Fec chan  \t %i \n",fecch);
1723   sprintf(nstat5,"Altro chip\t %i \n",altrochip);
1724   sprintf(nstat6,"Altro chan\t %i \n",altrochannel);
1725   
1726   legstat->AddText(nstat1); legstat->AddText(nstat2);  legstat->AddText(nstat8);  legstat->AddText(nstat7);  
1727   legstat->AddText(nstat3); legstat->AddText(nstat4);  legstat->AddText(nstat5);  legstat->AddText(nstat6);
1728
1729   sprintf(title,"Row=%d Pad=%d Hw =%d maxADC =%d count =%d",npadRow,npad,nhw,nmax,binchannel);
1730   
1731   hp->SetName(projhist);
1732   hp->SetTitleSize(0.04);
1733   hp->SetTitle(title);
1734   hp->SetYTitle("ADC");
1735   hp->SetXTitle("Timebin");
1736   hp->GetXaxis()->SetTitleColor(1);
1737   
1738   if(setrange) 
1739     {
1740       hp->GetXaxis()->SetRange(xbinmin,xbinmax);
1741       hp->SetMinimum(ybinmin);
1742       hp->SetMaximum(ybinmax);
1743     }
1744   else  
1745     { 
1746       hp->SetMinimum(0.0);
1747       hp->SetMaximum(1000.0);
1748     }
1749   
1750   cpad->cd();
1751   hp->Draw();
1752   
1753   // Make Fit to peak
1754   if(GetPedestals() && fDisableFit==0) 
1755     {
1756       Int_t maxx  =    (Int_t)fHistAddrMaxAdcX->GetBinContent(hwadd);
1757       Float_t max  =  (Float_t)fHistAddrMaxAdc->GetBinContent(hwadd);
1758       Float_t base =  (Float_t)fHistAddrBaseMean->GetBinContent(hwadd);
1759       if(base!=0) 
1760         {
1761           if( ((max+base)/base)>1.2) 
1762             {
1763               TF1* fg = new TF1("fg",AliTPCMonitor::Gamma4,maxx-5,maxx+5,4);
1764               fg->SetParName(0,"Normalisation");
1765               fg->SetParName(1,"Minimum");
1766               fg->SetParName(2,"Width");
1767               fg->SetParName(3,"Base");
1768               fg->SetParameter(0,max);
1769               fg->SetParameter(1,maxx-2);
1770               fg->SetParameter(2,1.5);
1771               fg->FixParameter(3,0);
1772               fg->SetLineColor(4);
1773               fg->SetLineWidth(1);
1774               hp->Fit("fg","RQ");
1775               
1776               TLegend* legfit = new TLegend(0.6,0.7,0.7,0.8);
1777               legfit->AddEntry("fg","#Gamma 4 fit","l");
1778               legfit->SetFillColor(0);
1779               legfit->SetName("legfit");
1780               legfit->Draw("same");
1781             }
1782         }
1783     }
1784   legstat->SetFillColor(0);
1785   legstat->Draw("same");
1786   cpad->Update();
1787   return;
1788 }
1789
1790 //__________________________________________________________________
1791 void AliTPCMonitor::ExecRow() 
1792 {
1793
1794   // Executable for Pad 
1795   // Show profile of max adc over given pad row 
1796   // and 2dim histo  adc(pad-in-row,time bin)  
1797
1798   Int_t event = gPad->GetEvent();
1799   if (event != 61)    return;
1800   gPad->cd();
1801   TObject *select = gPad->GetSelected();
1802   if(!select)    return;
1803   if(!select->InheritsFrom("TH2")) {   return;  }
1804
1805   Int_t rocid = 0;
1806   //  Char_t namehist[50];
1807   Char_t rowhist[60];
1808   Char_t rowhistsum[60];
1809   Char_t rowhistmax[60];
1810   Char_t rowhistxmax[60];
1811   
1812   sprintf(rowhist,         "hrowtime");
1813   sprintf(rowhistxmax    ,"hxmax");
1814   sprintf(rowhistmax    , "hrowmax");
1815   
1816   // get position 
1817   Int_t   px  = gPad->GetEventX();
1818   Int_t   py  = gPad->GetEventY();
1819   Float_t upy = gPad->AbsPixeltoY(py);
1820   Float_t upx = gPad->AbsPixeltoX(px);
1821   Float_t y   = gPad->PadtoY(upy);
1822   Float_t x   = gPad->PadtoX(upx);
1823   
1824   TCanvas*crowtime   = 0;
1825   TCanvas*crowmax    = 0;
1826   TCanvas*cxmax      = 0;
1827   
1828   TH2S*  fHistIndex  = 0;
1829
1830   // ranges from already existing histos 
1831   Int_t    rowtimexmin = 0;
1832   Int_t    rowtimexmax = 0;
1833   Int_t    rowtimeymin = 0;
1834   Int_t    rowtimeymax = 0;
1835   Float_t  rowtimezmin = 0;
1836   Float_t  rowtimezmax = 0;
1837   
1838   Int_t    profrowxmin = 0;
1839   Int_t    profrowxmax = 0;
1840   Double_t profrowymin = 0;
1841   Double_t profrowymax = 0;
1842
1843   Int_t    profxxmin   = 0;
1844   Int_t    profxxmax   = 0;
1845   Double_t profxymin   = 0;
1846   Double_t profxymax   = 0;
1847
1848
1849   Int_t    setrange      = 0;
1850
1851
1852   if(     strcmp(select->GetName(),"fHistIROC")==0 || strcmp(select->GetName(),"fHistIROCRMS")==0 ) { fHistIndex = fHistIROCIndex;     rocid =1;   } 
1853   else if(strcmp(select->GetName(),"fHistOROC")==0 || strcmp(select->GetName(),"fHistOROCRMS")==0 ) { fHistIndex = fHistOROCIndex;     rocid =2;   }
1854   else                                                                                  { cout << " not implemented for this histo " << endl; return; }
1855   
1856   gPad->GetCanvas()->FeedbackMode(kTRUE);
1857   
1858  
1859
1860   // check if canvases exist //
1861   crowtime  = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("crowtime");
1862   crowmax   = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("crowmax");
1863   cxmax     = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("cxmax");
1864   
1865   if(!crowtime)   crowtime   = CreateCanvas("crowtime") ;
1866   if(!crowmax)    crowmax    = CreateCanvas("crowmax")  ;
1867   if(!cxmax  )    cxmax      = CreateCanvas("cxmax")    ;
1868   
1869   // check ranges of already existing histos 
1870   if(gROOT->Get(rowhist)) 
1871     {
1872       rowtimexmin  = ((TH2F*)gROOT->Get(rowhist))->GetXaxis()->GetFirst();
1873       rowtimexmax  = ((TH2F*)gROOT->Get(rowhist))->GetXaxis()->GetLast();
1874       rowtimeymin  = ((TH2F*)gROOT->Get(rowhist))->GetYaxis()->GetFirst();
1875       rowtimeymax  = ((TH2F*)gROOT->Get(rowhist))->GetYaxis()->GetLast();
1876       rowtimezmin  = ((TH2F*)gROOT->Get(rowhist))->GetMinimum();
1877       rowtimezmax  = ((TH2F*)gROOT->Get(rowhist))->GetMaximum();
1878       
1879       profrowxmin  = ((TH1F*)gROOT->Get(rowhistmax))->GetXaxis()->GetFirst();
1880       profrowxmax  = ((TH1F*)gROOT->Get(rowhistmax))->GetXaxis()->GetLast();
1881       profrowymin  = ((TH1F*)gROOT->Get(rowhistmax))->GetMinimum();
1882       profrowymax  = ((TH1F*)gROOT->Get(rowhistmax))->GetMaximum();
1883
1884       profxxmin    = ((TH1F*)gROOT->Get(rowhistxmax))->GetXaxis()->GetFirst();
1885       profxxmax    = ((TH1F*)gROOT->Get(rowhistxmax))->GetXaxis()->GetLast();
1886       profxymin    = ((TH1F*)gROOT->Get(rowhistxmax))->GetMinimum();
1887       profxymax    = ((TH1F*)gROOT->Get(rowhistxmax))->GetMaximum();
1888
1889       setrange =1;
1890       
1891       delete gROOT->Get(rowhist);
1892       delete gROOT->Get(rowhistmax);
1893       delete gROOT->Get(rowhistsum);
1894       delete gROOT->Get("hxmax");
1895       delete gROOT->Get("legrow");
1896     }
1897   
1898   // get channel for xy bin -> getRow -> getNrows -> getHw for each Pad in Row -> get channel for each hw -> make proj
1899   Int_t testy      = fHistIndex->GetYaxis()->FindBin(y);
1900   Int_t testx      = fHistIndex->GetXaxis()->FindBin(x);
1901   Int_t binchannel = (Int_t)fHistIndex->GetCellContent(testx,testy);
1902   
1903   if(binchannel>30000)    return;
1904   if(binchannel<=0 ) { crowtime->Update() ;    crowmax->Update() ;    return ;  }
1905   
1906   // get hwaddress 
1907   Int_t hwadd     = (Int_t)fHistChannelTime->GetCellContent(binchannel,0);
1908   Int_t row       = fMapHand->GetPadRow(hwadd);
1909   Int_t pad       = fMapHand->GetPad(hwadd)   ;
1910   Int_t numofpads =  fMapHand->GetNumofPads(row);
1911   
1912   // create histos 
1913   TH2F *hrowtime = new TH2F(rowhist     , ""  ,numofpads,0,numofpads,GetTimeBins(),0.0,GetTimeBins());
1914   TH1F *hrowmax  = new TH1F(rowhistmax , ""  ,numofpads,0,numofpads);
1915   TH1F *hxmax    = new TH1F(rowhistxmax, ""  ,159,0,159      );
1916   
1917   // Row profile ///////////
1918   if(fVerb) cout << " Number of pads " << numofpads << endl;
1919   for(Int_t padnr = 0; padnr<numofpads;padnr++) 
1920     {
1921       Int_t addrinrow = fMapHand->GetPadAddInRow(row,padnr );
1922       Int_t channel   = (Int_t)fHistAddrMapIndex->GetBinContent(addrinrow);
1923       if(channel==-1) continue;
1924       
1925       hrowmax->SetBinContent(padnr+1,fHistAddrMaxAdc->GetBinContent(addrinrow));
1926       TH1D *hp = fHistChannelTime->ProjectionY("hp",channel,channel);
1927       for(Int_t time = 0;time<GetTimeBins();time++) {
1928         
1929         Float_t val = hp->GetBinContent(time);
1930         hrowtime->SetCellContent(padnr+1,time+1,val);
1931       }
1932     }
1933   
1934   // X profile  /////////////
1935   Double_t xval  = 0.0;
1936   Double_t yval  = 0.0;
1937   GetXY(xval,yval,numofpads,row,pad);
1938   
1939   Int_t padnr = 0; 
1940   Int_t hw    = 0;
1941   for(Int_t nrow = 0; nrow<159; nrow++)
1942     {
1943       padnr = GetPadAtX(xval,nrow);
1944       if(padnr>=0)
1945         {
1946           hw = fMapHand->GetPadAddInRow(nrow,padnr);
1947           if(fPadMapHw[hw]==-1){ continue                                                      ; }
1948           else                { hxmax->SetBinContent(nrow+1,fHistAddrMaxAdc->GetBinContent(hw))   ;     }
1949         }
1950     }
1951   
1952   cxmax->cd();
1953   Char_t hxtitle[50] ; sprintf(hxtitle,"max adc in pads at x=%5.1f mm",xval);
1954   hxmax->SetTitle(hxtitle);
1955   hxmax->SetXTitle("row");
1956   if(!GetPedestals()) hxmax->SetYTitle("max adc (baseline sub.)");
1957   else                hxmax->SetYTitle("max adc ");
1958   hxmax->SetMinimum(0.01);
1959   hxmax->Draw("l");
1960   
1961   if(setrange)
1962     {
1963       hxmax->GetXaxis()->SetRange(profxxmin,profxxmax);
1964       hxmax->SetMinimum(profxymin);
1965       hxmax->SetMaximum(profxymax);
1966     }
1967   
1968   cxmax->Update();
1969  
1970   crowtime->cd();
1971   Char_t title[256];
1972   Char_t titlemax[256];
1973   if(rocid==1) {sprintf(title,"%s Row=%d",((TH2*)select)->GetTitle(),row)   ;    sprintf(titlemax,"IROC  max/sum Row=%d",row   );} 
1974   else         {sprintf(title,"%s Row=%d",((TH2*)select)->GetTitle(),row-63);    sprintf(titlemax,"OROC  max/sum Row=%d",row-63);}
1975   if(fVerb) cout << " set name " << endl;
1976   
1977
1978   // row vs time
1979   crowtime->cd();
1980   hrowtime->SetTitleSize(0.04);
1981   hrowtime->SetTitle(title);
1982   hrowtime->SetYTitle("timbin");
1983   hrowtime->SetXTitle("pad in row");
1984   hrowtime->SetZTitle("signal (ADC)");
1985
1986   hrowtime->GetXaxis()->SetTitleColor(1);
1987   hrowtime->SetMaximum(1000.0);
1988   hrowtime->SetMinimum(0.0);
1989   
1990   if(setrange) 
1991     {
1992       hrowtime->GetXaxis()->SetRange(rowtimexmin,rowtimexmax);
1993       hrowtime->GetYaxis()->SetRange(rowtimeymin,rowtimeymax);
1994       hrowtime->SetMinimum(rowtimezmin);
1995       hrowtime->SetMaximum(rowtimezmax);
1996     }
1997
1998   hrowtime->Draw("COLZ");
1999   crowtime->UseCurrentStyle();
2000   crowtime->Update();
2001
2002   // max and sum /////////////////////////
2003   crowmax->cd();
2004   if(setrange) {
2005     hrowmax->GetXaxis()->SetRange(profrowxmin,profrowxmax);
2006     hrowmax->SetMinimum(profrowymin);
2007     hrowmax->SetMaximum(profrowymax);
2008   }
2009   hrowmax->SetTitleSize(0.04);
2010   hrowmax->SetTitle(title);
2011   hrowmax->SetYTitle("max adc");
2012   hrowmax->SetXTitle("pad in row");
2013   hrowmax->GetXaxis()->SetTitleColor(1);
2014
2015   hrowmax->SetLineColor(2);
2016   hrowmax->Draw("l");                  
2017   crowmax->Update();
2018   
2019   return;
2020 }
2021
2022 //__________________________________________________________________
2023 void AliTPCMonitor::Write10bitChannel()
2024 {
2025   
2026   // Write 10 bit words form histogram for active(last pointed)  channel 
2027   
2028   if(fPadUsedHwAddr==-1){ AliWarning(" No active pad "); return ;}
2029   
2030   Int_t  pad     = (Int_t)fMapHand->GetPad(   fPadUsedHwAddr); 
2031   Int_t  row     = (Int_t)fMapHand->GetPadRow(fPadUsedHwAddr); 
2032   Int_t  channel = (Int_t)fPadMapHw[fPadUsedHwAddr];
2033   
2034   Char_t filenameroot[256];
2035   Char_t filenamedat[256];
2036   Char_t projhist[256];
2037
2038   if(fPadUsedRoc==1) { sprintf(projhist,"ProjectionOROC"); }
2039   if(fPadUsedRoc==0) { sprintf(projhist,"ProjectionIROC"); }
2040   
2041   sprintf(filenamedat, "Channel_Run%05i_EventID_%i_Pad_%i_Row_%i.dat"      ,fRunId,fEventNumber,pad,row);
2042   sprintf(filenameroot,"Channel_Run%05i_EventID_%i_Pad_%i_Row_%i.root"     ,fRunId,fEventNumber,pad,row);
2043   
2044   TH1D* hpr = 0; 
2045   if((hpr=(TH1D*)gROOT->Get(projhist))) 
2046     {
2047       // root histo 
2048       TFile f(filenameroot,"recreate");
2049       hpr->Write();
2050       f.Close();
2051
2052       // raw singal 
2053       ofstream datout(filenamedat,ios::out);
2054       datout <<"Timebin \t ADC value " << endl; 
2055       for(Int_t i = 1; i <GetTimeBins(); i++)
2056         {
2057           datout << i << " \t \t " << fPad[channel][i] << endl; 
2058         }
2059       datout.close();
2060     }
2061   else
2062     {
2063       AliWarning("No projection histo found ");
2064     }
2065 }
2066
2067 //__________________________________________________________________
2068 void AliTPCMonitor::ExecTransform() 
2069 {
2070
2071   // Make Fast Fourier Transformation for active pad
2072   // fft is only performed for a data sample of size 2^n
2073   // reduce window according to largest  power of 2 which is smaller than the viewing  range 
2074
2075   Char_t namecanv[256]; 
2076   Char_t projhist[256];
2077   Char_t namehtrimag[256];
2078   Char_t namehtrreal[256];
2079   
2080   if(fPadUsedRoc==1) {    sprintf(namecanv,"coroc_ch_trans") ;    sprintf(projhist,"ProjectionOROC");  }
2081   if(fPadUsedRoc==0) {    sprintf(namecanv,"ciroc_ch_trans") ;    sprintf(projhist,"ProjectionIROC");  }
2082
2083   TH1D*  hproj = 0;
2084   
2085   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 ;}
2086   else      hproj = (TH1D*)gROOT->Get(projhist) ;
2087
2088   
2089   if(fPadUsedRoc==1) {  sprintf(namehtrimag,"htransimagfreq_oroc");    sprintf(namehtrreal,"htransrealfreq_oroc");  } 
2090   else               {  sprintf(namehtrimag,"htransimagfreq_iroc");    sprintf(namehtrreal,"htransrealfreq_iroc");  }
2091   
2092   if( gROOT->Get(namehtrimag))  delete  gROOT->Get(namehtrimag);
2093   if( gROOT->Get(namehtrreal))  delete  gROOT->Get(namehtrreal);
2094   
2095   TCanvas *ctrans = 0;
2096   if(!(ctrans = (TCanvas*)gROOT->GetListOfCanvases()->FindObject(namecanv))) 
2097     {
2098       ctrans = CreateCanvas(namecanv);
2099       ctrans->Divide(1,2);
2100     }
2101   
2102   Int_t binfirst  =  hproj->GetXaxis()->GetFirst();
2103   Int_t binlast   =  hproj->GetXaxis()->GetLast();
2104   Int_t bins       =  binlast -binfirst +1;
2105     
2106   Int_t power = 0;
2107   for(Int_t pot = 0; pot<=10 ; pot++) 
2108     {
2109       Int_t comp =  (Int_t)TMath::Power(2,pot);
2110       if(bins>=comp)power = pot;
2111     }
2112   
2113   bins = (Int_t)TMath::Power(2,power);
2114   
2115   // sampling frequency ;
2116   Double_t  deltat = 1.0/(Float_t)GetSamplingFrequency();
2117   
2118   // output histo
2119   TH1D* htransrealfreq = new TH1D(namehtrreal,namehtrreal,10000,-1/(2*deltat),1/(2*deltat));
2120   TH1D* htransimagfreq = new TH1D(namehtrimag,namehtrimag,10000,-1/(2*deltat),1/(2*deltat));
2121
2122
2123   Char_t titlereal[256];
2124   Char_t titleimag[256];
2125   if(fPadUsedRoc==1) {    sprintf(titlereal,"OROC DFT real part");  sprintf(titleimag,"OROC DFT imag part");  } 
2126   else {                  sprintf(titlereal,"IROC DFT real part");  sprintf(titleimag,"IROC DFT imag part");  }
2127   
2128   htransrealfreq->SetTitle(titlereal);  htransrealfreq->SetXTitle("f/hz");  htransrealfreq->SetYTitle("z_{real}(f)");
2129   htransimagfreq->SetTitle(titleimag);  htransimagfreq->SetXTitle("f/hz");  htransimagfreq->SetYTitle("z_{imag}(f)");
2130   
2131   
2132   // create complex packed data array  
2133   const Int_t kdatasiz = 2*bins;
2134   Double_t*  data = new Double_t[kdatasiz];
2135   for(Int_t i=0;i<2*bins;i++)  { data[i]   =  0.0;}
2136   for(Int_t i=0;i<bins;i++)    { data[2*i] = (Double_t)hproj->GetBinContent(binfirst+i); }
2137   
2138   // make fourier transformation
2139   AliTPCMonitorFFT* four = new AliTPCMonitorFFT();
2140   four->ComplexRadix2ForwardWrap(data,1,bins);
2141   
2142   // write output  and fill histos forward  
2143   Double_t freq =  0.0;
2144   for(Int_t i=0;i<2*bins;i++) 
2145     {
2146       if(i<bins) 
2147         {
2148           if(i<(bins/2))  { freq = i/(bins*deltat)            ; } 
2149           else            { freq = -1*((bins-i)/(bins*deltat)); }
2150           htransrealfreq->Fill( freq,data[2*i]  );
2151           htransimagfreq->Fill( freq,data[2*i+1]);
2152           
2153           
2154         }
2155     }
2156   
2157   ctrans->cd(1);
2158   htransrealfreq->Draw();
2159   ctrans->cd(2);
2160   htransimagfreq->Draw();
2161   ctrans->Update();
2162   delete four;
2163   delete data;
2164 }
2165
2166 //__________________________________________________________________
2167 void AliTPCMonitor::ShowSel(Int_t* compval)               
2168 {
2169   
2170   // Show only selected components 
2171   // First restore original histogram from clone 
2172   // Than remove all not matching pads form histos 
2173   
2174   Int_t   connector   =  0;
2175   Int_t   fecnr       =  0;
2176   Int_t   altrochip   =  0;
2177   Int_t   feclocbran  =  0;
2178   Int_t   branch      =  0;
2179   Short_t rcuget      =  0;
2180   Int_t   emptyI      =  1;
2181   Int_t   index       = -1;
2182   Int_t   hwadd       =  0;
2183
2184   Float_t maxiroc     =  fHistIROCClone->GetMaximum();
2185   Float_t maxoroc     =  fHistOROCClone->GetMaximum();
2186  
2187   
2188   //  restore original histos 
2189   for(Int_t row = 0; row<fkNRowsIroc;  row++) 
2190     {
2191     for(Int_t pad = 0; pad<fkNPadsIroc;  pad++) 
2192       {
2193       index = (Int_t)fHistIROCIndex->GetCellContent(row+1,pad+1);
2194       if(index==-1)continue;
2195       else  fHistIROC->SetCellContent(row+1,pad+1,fHistIROCClone->GetCellContent(row+1,pad+1));
2196       }
2197     }
2198   for(Int_t row = 0; row<fkNRowsOroc;  row++) 
2199     {
2200       for(Int_t pad = 0; pad<fkNPadsOroc;  pad++) 
2201         {
2202           index = (Int_t)fHistOROCIndex->GetCellContent(row+1,pad+1);
2203           if(index==-1)continue;
2204           else    fHistOROC->SetCellContent(row+1,pad+1,fHistOROCClone->GetCellContent(row+1,pad+1));
2205         }
2206     }
2207   
2208   
2209   // remove not matching entries from fHistIROC/fHistOROC
2210   
2211   TH2F* fHist       =0;
2212   TH2S* fHistIndex  =0;
2213   Int_t npads       =0;
2214   Int_t subrows     =0;
2215   
2216   for(Int_t row = 0; row< (fkNRowsIroc + fkNRowsOroc);  row++) 
2217     {
2218       if(row<fkNRowsIroc) {  fHist=fHistIROC ; fHistIndex = fHistIROCIndex; npads = fkNPadsIroc; subrows =0         ;}
2219       else                {  fHist=fHistOROC ; fHistIndex = fHistOROCIndex; npads = fkNPadsOroc; subrows =fkNRowsIroc;}
2220       
2221       for(Int_t pad = 0; pad<npads;  pad++) 
2222         {
2223           index    = (Int_t)fHistIndex->GetCellContent(row -subrows +1,pad+1);
2224           if(index==-1)  continue ;  
2225           hwadd    = (Int_t)fHistChannelTime->GetCellContent(index,0);
2226           
2227           // global fecnr
2228           fecnr     =  fMapHand->GetFECfromHw(hwadd);
2229           if(compval[0]!=-1 && fecnr!=compval[0])      {          fHist->SetCellContent(row-subrows+1,pad+1,0);           continue;     }
2230           
2231           // rcu
2232           rcuget      = (hwadd & AliTPCMonitorAltro::GetHwMaskRCU())>> 12;
2233           if(compval[1]!=-1 && rcuget!=compval[1])     {          fHist->SetCellContent(row-subrows+1,pad+1,0);           continue;     }
2234           
2235           // branch
2236           branch    =  fMapHand->U2fGetBranch(fecnr) ;
2237           if(compval[2]!=-1 && branch!=compval[2])     {          fHist->SetCellContent(row-subrows+1,pad+1,0);           continue;     }
2238           
2239           // local fec
2240           feclocbran=   fMapHand->U2fGetFECinBranch(fecnr) ;
2241           if(compval[3]!=-1 && feclocbran!=compval[3]) {          fHist->SetCellContent(row-subrows+1,pad+1,0);           continue;     }
2242           
2243           // connector
2244           connector =  fMapHand->GetFECconnector(hwadd);
2245           if(compval[4]!=-1 && connector!=compval[4])  {          fHist->SetCellContent(row-subrows+1,pad+1,0);           continue;     }
2246           
2247           // Altro chip
2248           altrochip     =  fMapHand->GetAltro(hwadd);   
2249           if(compval[5]!=-1 && altrochip!=compval[5])      {      fHist->SetCellContent(row-subrows+1,pad+1,0);           continue;     }
2250           emptyI =0;
2251         }
2252     }
2253   
2254   TCanvas* c1 =0;
2255   TCanvas* c2 =0;
2256   if(gROOT->GetListOfCanvases()->FindObject("ciroc")) 
2257     {
2258       c1 = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("ciroc");
2259       c1->cd() ;
2260       fHistIROC->Draw("COLZ");
2261       fHistIROC->SetMaximum(maxiroc);
2262       fHistIROC->SetMinimum(0.0);   
2263       c1->Update();
2264     }
2265   if(gROOT->GetListOfCanvases()->FindObject("coroc")) 
2266     {
2267       c2 =  (TCanvas*)gROOT->GetListOfCanvases()->FindObject("coroc");
2268       c2->cd() ;
2269       fHistOROC->Draw("COLZ");
2270       fHistOROC->SetMaximum(maxoroc);
2271       fHistOROC->SetMinimum(0.0);
2272       c2->Update();
2273     }
2274   return ;
2275 }
2276
2277 //__________________________________________________________________
2278 void AliTPCMonitor::ResizeCanv() 
2279 {
2280   // Resize canvases and delete some of them
2281   
2282   Char_t carry1[100];  
2283   sprintf(carry1,".x %s/TPC/AliTPCMonitorExec.C(1)",gSystem->Getenv("ALICE_ROOT"));
2284   Char_t carry3[100];  
2285   sprintf(carry3,".x %s/TPC/AliTPCMonitorExec.C(2)",gSystem->Getenv("ALICE_ROOT"));
2286   if(fVerb) cout <<  " canv 1 " << endl;
2287   
2288   if(gROOT->GetListOfCanvases()->FindObject(        "coroc_ch")) {  delete gROOT->GetListOfCanvases()->FindObject("coroc_ch") ; }
2289   if(gROOT->GetListOfCanvases()->FindObject(        "ciroc_ch")) {  delete gROOT->GetListOfCanvases()->FindObject("ciroc_ch") ; }
2290   
2291   // for 2dim plots delete create and draw again
2292   if(gROOT->GetListOfCanvases()->FindObject("ciroc")) 
2293     {
2294       delete  gROOT->GetListOfCanvases()->FindObject("ciroc");
2295       TCanvas* ciroc = CreateCanvas("ciroc");
2296       ciroc->cd();
2297       fHistIROC->Draw("COLZ");
2298       ciroc->AddExec("pad",carry1);
2299       ciroc->AddExec("row",carry3);
2300       fExecPlaneMax=1;
2301       ciroc->Update();
2302     }
2303   // for 2dim plots delete create and draw again
2304   if(gROOT->GetListOfCanvases()->FindObject("coroc")) 
2305     {
2306       delete gROOT->GetListOfCanvases()->FindObject("coroc");
2307       TCanvas* coroc = CreateCanvas("coroc");
2308       coroc->cd();
2309       fHistOROC->Draw("COLZ");
2310       
2311       coroc->AddExec("pad",carry1);
2312       coroc->AddExec("row",carry3);
2313       coroc->Update();
2314       fExecPlaneMax=1;
2315     } 
2316   
2317   if(gROOT->GetListOfCanvases()->FindObject(       "cbasemean")) {    delete gROOT->GetListOfCanvases()->FindObject("cbasemean"); }
2318   if(gROOT->GetListOfCanvases()->FindObject(           "cbase")) {    delete gROOT->GetListOfCanvases()->FindObject("cbase");}
2319   if(gROOT->GetListOfCanvases()->FindObject(        "cbaserms")) {    delete gROOT->GetListOfCanvases()->FindObject("cbaserms");  }
2320   if(gROOT->GetListOfCanvases()->FindObject(            "cmax")) {    delete gROOT->GetListOfCanvases()->FindObject("cmax");      }
2321   if(gROOT->GetListOfCanvases()->FindObject(            "csum")) {    delete gROOT->GetListOfCanvases()->FindObject("csum");      }
2322   if(gROOT->GetListOfCanvases()->FindObject(  "ciroc_ch_trans")) {    delete gROOT->GetListOfCanvases()->FindObject("ciroc_ch_trans");}
2323   if(gROOT->GetListOfCanvases()->FindObject(  "coroc_ch_trans")) {    delete gROOT->GetListOfCanvases()->FindObject("coroc_ch_trans");}
2324   if(gROOT->GetListOfCanvases()->FindObject(       "crowtime")) {    delete gROOT->GetListOfCanvases()->FindObject("crowtime"); }
2325   if(gROOT->GetListOfCanvases()->FindObject(        "crowmax")) {    delete gROOT->GetListOfCanvases()->FindObject("crowmax");  }
2326   if(gROOT->GetListOfCanvases()->FindObject(          "cxmax")) {    delete gROOT->GetListOfCanvases()->FindObject("cxmax");    }
2327   if(gROOT->GetListOfCanvases()->FindObject(        "crmsoroc")) {    delete gROOT->GetListOfCanvases()->FindObject("crmsoroc");         fExecPadOrocRms = 0;   }
2328   if(gROOT->GetListOfCanvases()->FindObject(        "crmsiroc")) {    delete gROOT->GetListOfCanvases()->FindObject("crmsiroc");         fExecPadIrocRms = 0;   }
2329   if(gROOT->GetListOfCanvases()->FindObject(        "crowmax")) {    delete gROOT->GetListOfCanvases()->FindObject("crowmax");  }
2330   if(gROOT->GetListOfCanvases()->FindObject(        "crowmax")) {    delete gROOT->GetListOfCanvases()->FindObject("crowmax");  }
2331
2332 }
2333
2334
2335
2336
2337 //__________________________________________________________________
2338 Int_t AliTPCMonitor::ExecProcess() 
2339 {
2340   // Executable for global Histogram
2341   // Will be called from /TPC/AliTPCMonitorExec.C(3)
2342   // Call ProcessEvent for same event and sector pointed at 
2343   
2344   Int_t side   = 0;
2345   Int_t sector = 0;
2346   
2347   Int_t event = gPad->GetEvent();
2348   if(event != 61)  return -1;
2349   
2350   TObject *select = gPad->GetSelected();
2351   if(!select)  return -1;
2352   if(!select->InheritsFrom("TH2")) {gPad->SetUniqueID(0);    return -1;  }
2353   if(       strcmp(select->GetName(),"hglobal" )==0 || ( strcmp(select->GetName(),"SIDE A" )==0) ) side = 0;
2354   else  if( strcmp(select->GetName(),"hglobal2")==0 || ( strcmp(select->GetName(),"SIDE C" )==0) ) side = 1;
2355
2356   // get position
2357   Int_t   px    = gPad->GetEventX();
2358   Int_t   py    = gPad->GetEventY();
2359   Float_t upy   = gPad->AbsPixeltoY(py);
2360   Float_t upx   = gPad->AbsPixeltoX(px);
2361   Float_t y     = gPad->PadtoY(upy);
2362   Float_t x     = gPad->PadtoX(upx);
2363
2364   Int_t testy = ((TH2*)select)->GetYaxis()->FindBin(y);
2365   Int_t testx = ((TH2*)select)->GetXaxis()->FindBin(x);
2366   if(((TH2*)select)->GetCellContent(testx,testy)==0) return -1 ;
2367
2368   Float_t alpha = 0.0;
2369   if(x>0.0 && y > 0.0)    alpha = TMath::Abs(TMath::ATan(TMath::Abs(x/y)));
2370   if(x>0.0 && y < 0.0)    alpha = TMath::Abs(TMath::ATan(TMath::Abs(y/x)));
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   
2374   if(x>0.0 && y < 0.0)    alpha += (    TMath::Pi()/2);
2375   if(x<0.0 && y < 0.0)    alpha += (    TMath::Pi());
2376   if(x<0.0 && y > 0.0)    alpha += (1.5*TMath::Pi());
2377   
2378   sector =   (Int_t)(alpha/(2*TMath::Pi()/18.0));
2379   if(alpha> (sector+0.5)*(2*TMath::Pi()/18.0))  sector+=1;
2380   
2381   if(sector==18 && side ==0 ) {
2382     AliWarning("There was a wromg assignment of sector 0 with sector 18. Check sectors");
2383     sector =0;
2384   }
2385   
2386   sector = (18-sector +4)%18;
2387   SetLastSector(sector+ side*18);
2388   SetProcNextEvent(0);
2389   
2390   if(fVerb) cout << "AliTPCMonitor::ExecProcess()  next side          " <<   side    << " next sector        " <<    sector  << endl;
2391   
2392   return (Int_t)ProcessEvent();
2393
2394 }
2395
2396 //__________________________________________________________________
2397 Int_t AliTPCMonitor::GetRCUPatch(Int_t runid, Int_t eqid) const
2398 {
2399   
2400   // Return RCU patch index for given equipment id eqid 
2401   Int_t patch = 0;
2402   //if(runid>=704)
2403   if(runid>=0)
2404     {
2405       if(eqid>=1000) return 0;
2406       patch = fMapEqidsRcu[eqid] ;
2407     }
2408   else
2409     {
2410       if(eqid==408) {patch =  13*6+4 +0;  }
2411       if(eqid==409) {patch =  13*6+5 +0;  }
2412       if(eqid==509) {patch =  13*6+0 +0;  }
2413       if(eqid==512) {patch =  13*6+3 +0;  }
2414       if(eqid==513) {patch =  13*6+1 +0;  }
2415       if(eqid==517) {patch =  13*6+2 +0;  }
2416       
2417       if(eqid==404) {patch =  4*6+5 +0;   }
2418       if(eqid==504) {patch =  4*6+4 +0;   }
2419       if(eqid==407) {patch =  4*6+3 +0;   }  
2420       if(eqid==503) {patch =  4*6+2 +0;   }
2421       if(eqid==508) {patch =  4*6+1 +0;   }
2422       if(eqid==506) {patch =  4*6+0 +0;   }
2423     }
2424   return patch;
2425 }
2426
2427 //__________________________________________________________________
2428 void AliTPCMonitor::DumpHeader(AliRawReaderRoot * fReaderROOT) const
2429 {
2430   // Dump Event header for ROOT format
2431   
2432   cout << "EventHeader     : fReaderROOT->GetEquipmentSize()            :" << fReaderROOT->GetEquipmentSize()        << endl;
2433   cout << "EventHeader     : fReaderROOT->GetType()                     :" << fReaderROOT->GetType()                 << endl;
2434   cout << "EventHeader     : fReaderROOT->GetRunNumber()                :" << fReaderROOT->GetRunNumber()            << endl;
2435   cout << "EventHeader     : fReaderROOT->GetEventId()                  :" << *(fReaderROOT->GetEventId())           << endl;
2436   cout << "EventHeader     : fReaderROOT->GetLDCId()                    :" << fReaderROOT->GetLDCId()                << endl;
2437   cout << "EventHeader     : fReaderROOT->GetGDCId()                    :" << fReaderROOT->GetGDCId()                << endl;
2438 }
2439
2440 //__________________________________________________________________
2441 void AliTPCMonitor::DumpHeader(AliTPCMonitorDateFormat* dateform) const
2442 {
2443   // Dump Event header for DATE format
2444   
2445   cout << "EquipmentHeader : dateform->GetEquipmentSize()               :" << dateform->GetEquipmentSize()          << endl;
2446   cout << "EquipmentHeader : dateform->GetEquipmentType()               :" << dateform->GetEquipmentType()          << endl;
2447   cout << "EquipmentHeader : dateform->GetEquipmentID()                 :" << dateform->GetEquipmentID()            << endl;
2448   cout << "EquipmentHeader : dateform->GetEquipmentTypeAttribute()      :" << dateform->GetEquipmentTypeAttribute() << endl;
2449   cout << "EquipmentHeader : dateform->GetEquipmentBasicSize()          :" << dateform->GetEquipmentBasicSize()     << endl;
2450   cout << "EquipmentHeader : dateform->GetEquipmentHeaderSize()         :" << dateform->GetEquipmentHeaderSize()    << endl;
2451   cout << "EquipmentHeader : dateform->IsLastSubEventHeader()           :" << dateform->IsLastSubEventHeader()      << endl;
2452 }
2453
2454 //__________________________________________________________________
2455 Double_t AliTPCMonitor::Gamma4(Double_t* x, Double_t* par) {
2456   
2457   // Gamma4 function used to fit signals
2458   // Defined in sections: diverging branch set to 0 
2459   
2460   Double_t val  = 0.0; 
2461   if(x[0] > par[1])
2462     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];
2463   else 
2464     val = 0;
2465   return val;
2466 }
2467
2468 //__________________________________________________________________
2469 TCanvas* AliTPCMonitor::CreateCanvas(Char_t* name)
2470 {
2471   // Create Canvases 
2472   
2473   TCanvas* canv =0;
2474   
2475   Int_t xoffset  = GetCanvasXOffset();
2476   Int_t xsize    = GetCanvasXSize();
2477   Int_t ysize    = GetCanvasYSize();
2478   Int_t xspace   = GetCanvasXSpace();
2479   Int_t yspace   = GetCanvasYSpace();
2480   
2481   // ROC 2dim max distribution
2482   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;  }
2483   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;  }
2484   // ROC  2dim rms distribution
2485   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;  } 
2486   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;  }
2487   // Global ADC max Histos
2488   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;  }
2489   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;  }
2490   // 1 dim max sum basekine distribution
2491   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;  }
2492   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;  }
2493   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;  }  
2494   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;  }
2495   // Projections of single channel
2496   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;  }
2497   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;  }
2498   // FFT for single channel
2499   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;  }
2500   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;  }
2501   // row profile histograms
2502   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;  }
2503   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;  }
2504   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;  }
2505   else                                      {    cout   << " Warning Canvas name unknown "  << endl;                                                                                                  return 0   ;  }
2506 }
2507
2508 //__________________________________________________________________
2509 void AliTPCMonitor::WriteHistos()  
2510 {
2511   // Writes all available histograms to a file in current directory
2512   // File name will be specified by : sector, side, runid and eventnumber 
2513   
2514   if(GetEventProcessed())
2515     {
2516       AliInfo("Write histos to file");
2517       Char_t name[256]; 
2518       sprintf(name,"SIDE_%i_SECTOR_%02i_RUN_%05i_EventID_%06i.root",(GetLastSector()/18),(GetLastSector()%18),fRunId,fEventNumber);
2519       TFile* f = new TFile(name,"recreate");
2520       for(Int_t i =0; i<fHistList->GetEntries(); i++)
2521         {
2522           if(((TH1*)fHistList->At(i))!=0)    
2523             {
2524               ((TH1*)fHistList->At(i))->Write();
2525             }
2526         }
2527       f->ls();
2528       f->Close();
2529     }
2530   else
2531     { 
2532       AliError("No Event Processed : Chose Format , File and push 'Next Event' ");
2533     }
2534 }
2535
2536
2537 //__________________________________________________________________
2538 TH1* AliTPCMonitor::GetHisto(char* histname) 
2539 {
2540   
2541   // Returns histogram specified by histname
2542   // check available names for histos in CreateHistos()
2543   
2544   TH1* hist = 0;
2545   if((TH1*)fHistList->FindObject(histname))
2546     {
2547       hist = (TH1*)fHistList->FindObject(histname);
2548     }
2549   else 
2550     {
2551       cout << " AliTPCMonitor::GetHisto :: Can not find histo with name " << histname << endl;
2552     }
2553   return hist ;
2554 }