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