]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSOnlineMonitor.cxx
Avoid compiler warnings.
[u/mrichter/AliRoot.git] / PHOS / AliPHOSOnlineMonitor.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 //_________________________________________________________________________
19 // Class intended to perform online monitoring of PHOS beamtests
20 // Being constructed, produces menu with list of available histograms to fill
21 // Once histograms are selected, button "Go" should be pressed to start scan of data.
22 // Prepared histograms will be periodically updated during scan of the data.
23 // Note:
24 // 1. To plot most of histograms, a "Connection Table", relating ADC signal index and AbsId 
25 //    of PHOS crystal, should be created beforehand. To do this, call macro
26 //       $ALICE_ROOT/PHOS/macros/BeamTest/MakeConTableDB.C 
27 //    with apropriate number of raws and columns of prototype.
28 // 2. To perform reconstruction and e.g. invariant mass analysis, a "Calibration Database"
29 //    should be created beforehand. To do this, call macro 
30 //       $ALICE_ROOT/PHOS/macros/BeamTest/MakeConTableDB.C 
31 //    to read calibration parameters from file or use AliPHOSCalibrator to calculate 
32 //    pedestal and gains.
33 // 3. Once histograms are filled with "Go" method, they can be written to file
34 //    with WriteHisto("Filename.root") method. 
35 //
36 //*-- Author : D.Peressounko (RRC KI) after A.V. Kuryakin, (Sarov) 
37 //////////////////////////////////////////////////////////////////////////////
38
39 // --- ROOT system ---
40 #include "TROOT.h"
41 #include "TClonesArray.h"
42 #include "TCanvas.h"
43 #include "TH1.h"
44 #include "TH2.h"
45 #include "TGroupButton.h"
46 #include "TFile.h"
47 #include "TSystem.h"
48
49
50 // --- Standard library ---
51 #include "TBenchmark.h"
52 #include "Riostream.h"
53
54 // --- AliRoot header files ---
55 #include "AliPHOSOnlineMonitor.h"
56 #include "AliPHOSConTableDB.h"
57 #include "AliPHOSGeometry.h"
58 #include "AliRawReaderDateV3.h"
59 #include "AliRawEventHeaderBase.h"
60 #include "AliPHOSRawStream.h"
61 #include "AliPHOSDigit.h"
62 #include "AliPHOSGetterLight.h"  
63 #include "AliPHOSClusterizerv1.h"  
64 #include "AliPHOSTrackSegmentMakerv1.h"  
65 #include "AliPHOSPIDv1.h"  
66 #include "AliPHOSCalibrManager.h" 
67 #include "AliPHOSCalibrationDB.h"
68
69 ClassImp(AliPHOSOnlineMonitor)
70
71
72 //____________________________________________________________________________ 
73 AliPHOSOnlineMonitor::AliPHOSOnlineMonitor(): TDialogCanvas("PHOS","PHOS",150,300)
74 {
75   
76   MakeButtons() ;
77   Modified(kTRUE);
78   Update();
79   SetEditable(kFALSE);
80   
81   //add this TFitPanel to the list of cleanups such that in case
82   //the referenced object is deleted, its pointer be reset
83   gROOT->GetListOfCleanups()->Add(this);
84   
85   fRefObject = this;
86   fRefPad    = (TPad*)gROOT->GetSelectedPad();
87
88   fScanPed = 0 ;
89   fScanSig = 0; 
90   fReconstruct = 0 ;
91
92   //Prepare list of canvas with histograms
93   fCanvasList = new TList() ;
94   fHistosList = new TList() ;
95
96   fcdb = 0 ;
97   fGeom = AliPHOSGeometry::GetInstance("IHEP","") ;
98   fNUpdate = 1000 ;
99
100 }
101 //____________________________________________________________________________ 
102 AliPHOSOnlineMonitor::AliPHOSOnlineMonitor(const char * inputfile): TDialogCanvas("PHOS","PHOS",150,300)
103 {
104
105   MakeButtons() ;
106   Modified(kTRUE);
107   Update();
108   SetEditable(kFALSE);
109   
110   //add this TFitPanel to the list of cleanups such that in case
111   //the referenced object is deleted, its pointer be reset
112   gROOT->GetListOfCleanups()->Add(this);
113   
114   fRefObject = this;
115   fRefPad    = (TPad*)gROOT->GetSelectedPad();
116
117   fScanPed = 0 ;
118   fScanSig = 0; 
119   fReconstruct = 0 ;
120
121   //Prepare list of canvas with histograms
122   fCanvasList = new TList() ;
123   fHistosList = new TList() ;
124
125   fInputFile = inputfile ;
126   fGeom = AliPHOSGeometry::GetInstance("IHEP","") ;
127   fcdb = 0 ;
128   fNUpdate = 1000 ;
129
130 }
131 //____________________________________________________________________________ 
132   AliPHOSOnlineMonitor::~AliPHOSOnlineMonitor()
133 {
134   //Obvious, but unevoidable comment for destructor: cleans up everething.
135   TIter nextCanvas(fCanvasList);
136   TCanvas * c ;
137   while((c=(TCanvas*)nextCanvas()))
138     delete c ;
139   delete fCanvasList ;
140   
141   TIter nextHisto(fHistosList);
142   TH1D * h ;
143   while((h=(TH1D*)nextHisto()))
144     delete h ;
145   delete fHistosList ; 
146
147   if(fcdb)
148     delete fcdb ;
149
150 }
151 //____________________________________________________________________________ 
152 void AliPHOSOnlineMonitor::MakeButtons(void){
153   //Make buttons on graphical menu
154   Int_t nButtons = 16;
155   TGroupButton * b ;
156   Float_t xmin = 0.0;
157   Float_t ymin = 0.01;
158   Float_t xmax = 0.99;
159   Float_t ymax = 0.99;
160   Float_t dy = (ymax-ymin)/nButtons ;
161
162   Float_t y2=ymax ;
163   Float_t y1=y2-dy ;
164   b = new TGroupButton("APPLY","Triggers","",xmin,y1,xmax,y2);
165   b->Draw();
166   y2=y1 ;
167   y1=y1-dy ;
168   b = new TGroupButton("APPLY","Pedestals","",xmin,y1,xmax,y2);
169   b->Draw();
170   y2=y1 ;
171   y1=y1-dy ;
172   b = new TGroupButton("APPLY","Spectrum all","",xmin,y1,xmax,y2);
173   b->Draw();
174   y2=y1 ;
175   y1=y1-dy ;
176   b = new TGroupButton("APPLY","Spectrum g","",xmin,y1,xmax,y2);
177   b->Draw();
178   y2=y1 ;
179   y1=y1-dy ;
180   b = new TGroupButton("APPLY","Inv Mass","",xmin,y1,xmax,y2);
181   b->Draw();
182   for(Int_t i=1; i<=5; i++){
183     y2=y1 ;
184     y1=y1-dy ;
185     char name[10] ;
186     sprintf(name,"Edep(ADC) %d",i) ;
187     b = new TGroupButton("APPLY",name,"",xmin,y1,xmax,y2);
188     b->Draw();
189   }
190   for(Int_t i=1; i<=5; i++){
191     y2=y1 ;
192     y1=y1-dy ;
193     char name[10] ;
194     sprintf(name,"Edep(Cal) %d",i) ;
195     b = new TGroupButton("APPLY",name,"",xmin,y1,xmax,y2);
196     b->Draw();
197   }
198   y2=y1 ;
199   y1=y1-dy ;
200   b = new TGroupButton("APPLY","Go","",xmin,y1,xmax,y2);
201   b->SetTextColor(2);
202   b->Draw();
203 }
204 //____________________________________________________________________________ 
205 void AliPHOSOnlineMonitor::Apply(const char *action){
206   //Function to handle button actions
207
208   TDialogCanvas::Apply() ;
209
210   TObject *obj;
211   TGroupButton *button;
212   TIter next(fPrimitives);
213   
214   if (!strcmp(action,"Triggers")) {
215     DrawTriggers() ;
216   }
217
218   if (!strcmp(action,"Pedestals")) {
219     DrawPedestals() ;
220   }
221   if (!strcmp(action,"Spectrum all")) {
222     DrawSpectrum("all") ;
223   }
224   if (!strcmp(action,"Spectrum g")) {
225     DrawSpectrum("gamma") ;
226   }
227   if (!strcmp(action,"Inv Mass")) {
228     DrawMinv() ;
229   }
230   if(strstr(action,"Edep")){
231     Int_t n ;
232     char tmp[10] ;
233     sscanf(action,"%s %d",tmp,&n) ;
234     char opt[5]="" ;
235     if(strstr(action,"Cal"))
236       sprintf(opt,"Cal") ;
237     DrawEdep(n,opt) ;
238   }
239   if (!strcmp(action,"Go")) {
240     Go() ;
241   }
242
243   //Mark button as pressed
244   if(strcmp(action,"Go")){ //Do not mark "Go" button
245     while ((obj = next())) {
246       if (obj->InheritsFrom(TGroupButton::Class())) {
247         button = (TGroupButton*)obj;
248         if(!strcmp(button->GetTitle(),action)){
249           if (button->GetBorderMode() > 0){
250             button->SetBorderMode(-1) ;
251             button->Modified(kTRUE);
252           }
253         }
254       }
255     }
256   }
257 }
258 //____________________________________________________________________________ 
259 void  AliPHOSOnlineMonitor::SetInputFile(const char * filename){
260   //close previously opened
261   
262   fInputFile = filename ;
263 }
264 //____________________________________________________________________________ 
265 void  AliPHOSOnlineMonitor::DrawPedestals(){
266   //Prepare canvas and histograms for drawing pedestals
267
268   TIter nextCanvas(fCanvasList);
269   TCanvas * c ;
270   Bool_t exists = kFALSE ;
271   while((c=(TCanvas*)nextCanvas())){
272     if(!strcmp(c->GetName(),"Pedestals")){
273       exists = kTRUE ;
274       break;
275     }
276   }
277   if(!exists){
278     c = new TDialogCanvas("Pedestals","Pedestals",300,200) ;
279     fCanvasList->AddLast(c) ;
280   }
281   
282   TIter nextHisto(fHistosList);
283   TH1D * h ;
284   exists = kFALSE ;
285   while((h=(TH1D*)nextHisto())){
286     if(!strcmp(h->GetName(),"hPedestals")){
287       exists = kTRUE ;
288       break;
289     }
290   }
291   if(!exists){
292     h = new TH1D("hPedestals","Pedestals per event",fGeom->GetNModules()*fGeom->GetNCristalsInModule(),0.,
293                  1.*fGeom->GetNModules()*fGeom->GetNCristalsInModule()) ;
294     fHistosList->AddLast(h) ;
295   }
296   
297   c->cd() ;
298   h->SetStats(0) ;
299   h->Draw() ;
300   fScanPed = kTRUE ; //We will scan pedestals
301
302 }
303 //____________________________________________________________________________ 
304 void  AliPHOSOnlineMonitor::DrawTriggers(){
305   //Prepare canvas and histogram for drawing triggers
306
307   TIter nextCanvas(fCanvasList);
308   TCanvas * c ;
309   Bool_t exists = kFALSE ;
310   while((c=(TCanvas*)nextCanvas())){
311     if(!strcmp(c->GetName(),"Triggers")){
312       exists = kTRUE ;
313       break;
314     }
315   }
316   if(!exists){
317     c = new TDialogCanvas("Triggers","Triggers",200,200) ;
318     fCanvasList->AddLast(c) ;
319   }
320   
321   TIter nextHisto(fHistosList);
322   TH1D * h ;
323   exists = kFALSE ;
324   while((h=(TH1D*)nextHisto())){
325     if(!strcmp(h->GetName(),"hTriggers")){
326       exists = kTRUE ;
327       break;
328     }
329   }
330   if(!exists){
331     h = new TH1D("hTriggers","Triggers",2,0.,2.) ;
332     fHistosList->AddLast(h) ;
333   }
334   //Make Labels
335   h->SetBit(TH1::kCanRebin);  
336   h->Fill("LED",0.0000001) ; 
337   h->Fill("PUL",0.0000001) ; 
338   h->Fill("PED",0.0000001) ; 
339   h->Fill("NEL",0.0000001) ; 
340   h->Fill("WEL",0.0000001) ; 
341   h->Fill("SOB",0.0000001) ; 
342   h->Fill("EOB",0.0000001) ; 
343   h->Fill("wrong",0.0000001) ;
344   h->LabelsOption("h");
345   h->LabelsDeflate();
346   h->SetStats(0) ;
347   c->cd() ;
348   h->Draw() ;
349 }
350 //____________________________________________________________________________ 
351 void  AliPHOSOnlineMonitor::DrawSpectrum(const char * opt){
352   //Prepare canvas and histograms for drawing spectra of all reconstructed particles or photons
353
354   TString name("Spectrum") ;
355   name+=opt ;
356   
357   TIter nextCanvas(fCanvasList);
358   TCanvas * c ;
359   Bool_t exists = kFALSE ;
360   while((c=(TCanvas*)nextCanvas())){
361     if(!strcmp(c->GetName(),name.Data())){
362       exists = kTRUE ;
363       break;
364     }
365   }
366   if(!exists){
367     c = new TDialogCanvas(name,name,250,300) ;
368     fCanvasList->AddLast(c) ;
369   }
370   
371   TIter nextHisto(fHistosList);
372   TH1D * h ;
373   exists = kFALSE ;
374   name.Prepend("h") ;
375   while((h=(TH1D*)nextHisto())){
376     if(!strcmp(h->GetName(),name.Data())){
377       exists = kTRUE ;
378       break;
379     }
380   }
381   if(!exists){
382     h = new TH1D(name,name,100,0.,100.) ;
383     fHistosList->AddLast(h) ;
384   }
385   
386   h->SetStats(0) ;
387   c->cd() ;
388   h->Draw() ;
389   fReconstruct = kTRUE ;
390   fScanSig = kTRUE ; //We will scan pedestals
391
392 }
393 //____________________________________________________________________________ 
394 void  AliPHOSOnlineMonitor::DrawMinv(){
395   TIter nextCanvas(fCanvasList);
396   TCanvas * c ;
397   Bool_t exists = kFALSE ;
398   while((c=(TCanvas*)nextCanvas())){
399     if(!strcmp(c->GetName(),"InvMass")){
400       exists = kTRUE ;
401       break;
402     }
403   }
404   if(!exists){
405     c = new TDialogCanvas("InvMass","Invariant mass",300,200) ;
406     fCanvasList->AddLast(c) ;
407   }
408   
409   TIter nextHisto(fHistosList);
410   TH1D * h ;
411   exists = kFALSE ;
412   while((h=(TH1D*)nextHisto())){
413     if(!strcmp(h->GetName(),"hInvMass")){
414       exists = kTRUE ;
415       break;
416     }
417   }
418   if(!exists){
419     h = new TH1D("hInvMass","hInvMass",1000,0.,1.0) ;
420     fHistosList->AddLast(h) ;
421   }
422   
423   c->cd() ;
424   h->Draw() ;
425   h->SetStats(0) ;
426   fReconstruct = kTRUE ;
427   fScanSig = kTRUE ; //We will scan pedestals
428 }
429 //____________________________________________________________________________ 
430 void  AliPHOSOnlineMonitor::DrawEdep(Int_t mod,const char * opt){
431   char name[15] ;
432   sprintf(name,"Edep%s %d",opt,mod) ;
433
434   TIter nextCanvas(fCanvasList);
435   TCanvas * c ;
436   Bool_t exists = kFALSE ;
437   while((c=(TCanvas*)nextCanvas())){
438     if(!strcmp(c->GetName(),name)){
439       exists = kTRUE ;
440       break;
441     }
442   }
443   if(!exists){
444     c = new TDialogCanvas(name,name,300,200) ;
445     fCanvasList->AddLast(c) ;
446   }
447   
448   TIter nextHisto(fHistosList);
449   TH2D * h ;
450   exists = kFALSE ;
451   sprintf(name,"hEdep%s%d",opt,mod) ;
452   while((h=(TH2D*)nextHisto())){
453     if(!strcmp(h->GetName(),name)){
454       exists = kTRUE ;
455       break;
456     }
457   }
458   if(!exists){
459     h = new TH2D(name,name,fGeom->GetNPhi(),0.,1.*fGeom->GetNPhi(),fGeom->GetNZ(),0.,1.*fGeom->GetNZ()) ;
460     fHistosList->AddLast(h) ;
461   }
462   
463   c->cd() ;
464   h->Draw("col") ;
465   h->SetStats(0) ;
466   fScanSig = kTRUE ; //We will scan signal events
467   if(strstr(opt,"Cal"))
468     fReconstruct = kTRUE ;
469  
470 }
471 //____________________________________________________________________________ 
472 void  AliPHOSOnlineMonitor::ScanPedestals(TClonesArray * digits){
473   //This method is called for events with PED trigger
474   //We fill bins with ADC values
475
476   TH1D * h = (TH1D*)gROOT->FindObjectAny("hPedestals");
477   if(!h){
478     Error("ScanPedestals","Can not fild histogram hPedestals") ;
479     return ;
480   }
481   for(Int_t i=0; i<digits->GetEntriesFast(); i++){
482     AliPHOSDigit * dig = static_cast<AliPHOSDigit*>(digits->At(i)) ;
483     h->AddBinContent(dig->GetId(),dig->GetAmp()) ;
484   }
485 }
486 //____________________________________________________________________________ 
487 void  AliPHOSOnlineMonitor::ScanEdep(TClonesArray * digits){
488   //Fill 2D distribution of ADC values in NEL and WEL events
489   AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
490   AliPHOSCalibrationDB *cdb = 0 ;
491   if(gime)
492     cdb = gime->CalibrationDB() ;
493   Int_t mod = 0 ;
494   char name[15] ;
495   TH2D * h = 0 ;
496   TH2D * hCal = 0 ;
497   for(Int_t i=0; i<digits->GetEntriesFast(); i++){
498     AliPHOSDigit * dig = static_cast<AliPHOSDigit*>(digits->At(i)) ;
499     Int_t relId[4] ;
500     fGeom->AbsToRelNumbering(dig->GetId(),relId) ;
501     if(mod != relId[0]){ //new module, look for histograms
502       mod = relId[0] ;
503       sprintf(name,"hEdep%d",mod) ;
504       h = (TH2D*)gROOT->FindObjectAny(name);
505       sprintf(name,"hEdepCal%d",mod) ;
506       hCal = (TH2D*)gROOT->FindObjectAny(name);
507     }
508     if(h)
509       h->Fill(relId[2]-0.1,relId[3]-0.1,1.*dig->GetAmp()) ;
510     if(hCal)
511       hCal->Fill(relId[2]-0.1,relId[3]-0.1,cdb->Calibrate(dig->GetAmp(),dig->GetId())) ;
512   }
513 }
514 //____________________________________________________________________________ 
515 void  AliPHOSOnlineMonitor::ScanRecon(TClonesArray * recParticles){
516   if(!recParticles || recParticles->GetEntries()==0) return ;
517
518   TH1D* hSpectr   = (TH1D*)gROOT->FindObjectAny("hSpectrumall");
519   TH1D* hSpectrGam= (TH1D*)gROOT->FindObjectAny("hSpectrumgamma");
520   TH1D* hInvMass  = (TH1D*)gROOT->FindObjectAny("hInvMass");
521   for(Int_t i=0; i<recParticles->GetEntriesFast() ; i++){
522     AliPHOSRecParticle * p = (AliPHOSRecParticle *)recParticles->At(i) ;
523     if(hSpectr)hSpectr->Fill(p->Energy()) ;
524     if(hSpectrGam && p->IsPhoton())hSpectrGam->Fill(p->Energy()) ;
525     if(hInvMass){
526       for(Int_t j=i+1; j<recParticles->GetEntriesFast() ; j++){
527         AliPHOSRecParticle * p2 = (AliPHOSRecParticle *)recParticles->At(j) ;
528         Double_t e = p->Energy() + p2->Energy() ;
529         Double_t x = p->Px() + p2->Px() ;
530         Double_t y = p->Py() + p2->Py() ;
531         Double_t z = p->Pz() + p2->Pz() ;
532         Double_t m = e*e-x*x-y*y-z*z ;
533         hInvMass->Fill(m>0?TMath::Sqrt(m): 0. ) ;
534       }
535     }
536   }
537 }
538 //____________________________________________________________________________ 
539 void  AliPHOSOnlineMonitor::ScanTrigger(Int_t trig){
540   //Fills trigger distribution
541
542   TH1D * h = (TH1D*)gROOT->FindObjectAny("hTriggers");
543   if(!h) return ;
544   switch(trig){
545   case AliPHOSRawStream::kLED : h->Fill("LED",1.) ; break ;
546   case AliPHOSRawStream::kPUL : h->Fill("PUL",1.) ; break ;
547   case AliPHOSRawStream::kPED : h->Fill("PED",1.) ; break ;
548   case AliPHOSRawStream::kNEL : h->Fill("NEL",1.) ; break ;
549   case AliPHOSRawStream::kWEL : h->Fill("WEL",1.) ; break ;
550   case AliPHOSRawStream::kSOB : h->Fill("SOB",1.) ; break ;
551   case AliPHOSRawStream::kEOB : h->Fill("EOB",1.) ; break ;
552   default : h->Fill("wrong",1.) ;
553   }
554 }
555 //____________________________________________________________________________ 
556 void  AliPHOSOnlineMonitor::SetConTableDB(const char * filename){
557   //Read ConnectionTableDB from file
558   TFile * file = new TFile(filename) ;
559   AliPHOSConTableDB * tmp = (AliPHOSConTableDB*)file->Get("AliPHOSConTableDB") ;
560   fcdb = new AliPHOSConTableDB(*tmp) ;
561   file->Close() ; 
562 }
563 //____________________________________________________________________________ 
564 void  AliPHOSOnlineMonitor::Go(){
565   //Perform scan of curent event
566   gBenchmark->Start("PHOSOnlineMon"); 
567
568   //First test if we need "Connection table" then open it
569   if(!fcdb){
570     SetConTableDB() ;
571     if(fcdb){
572       Info("Go","Read Connection table from file \"ConTableDB.root\"") ;
573     }else{
574       Error("Go","Please, set connection table with SetConTableDB() method") ;
575       return ;
576     }
577   }
578
579   AliPHOSGetterLight * gime = AliPHOSGetterLight::Instance("PHOS","On Flight") ;
580
581   //Configure CalibrManager to read data from file
582   //Create calibration database and read it
583   AliPHOSCalibrationDB * calibDB = 0 ;
584   if(fScanSig || fReconstruct){ //We will ned calibration parameters
585     AliPHOSCalibrManager::GetInstance("CalibrDB.root","root") ;
586     //If we configured manager to read from ASCII file, 
587     //give him connection table. OK, it will not harm in any case.
588     AliPHOSCalibrManager::GetInstance()->SetConTable(fcdb) ;
589     
590     calibDB = new AliPHOSCalibrationDB("OnLine") ;
591     calibDB->GetParameters() ; //Read parameters using Manager
592     gime->SetCalibrationDB(calibDB) ;
593   }
594   
595   //Now open data file
596   AliRawReaderDateV3 *rawReader = new AliRawReaderDateV3(fInputFile) ; 
597   rawReader->RequireHeader(kFALSE);
598   AliPHOSRawStream     *rawStream = new AliPHOSRawStream(rawReader) ;
599   rawStream->SetConTableDB(fcdb) ;
600   
601   TClonesArray * digits = gime->Digits() ;
602   TClonesArray * recParticles = gime->RecParticles() ;
603   AliPHOSClusterizerv1* clu = 0 ;
604   AliPHOSTrackSegmentMakerv1 * tsm = 0 ;
605   AliPHOSPIDv1 * pid = 0 ;
606   if(fReconstruct){ //We will need calibation parameters
607     clu = new AliPHOSClusterizerv1("PHOS","On Flight") ;
608     clu->SetWriting(0) ; //Do not write to file
609     clu->SetEmcMinE(0.05) ;  //Minimal energy of the digit
610     clu->SetEmcLocalMaxCut(0.05) ; //Height of local maximum over environment
611     clu->SetEmcClusteringThreshold(0.2) ; //Minimal energy to start cluster
612 //    clu->SetUnfolding(kFALSE) ; //Do not unfold
613     tsm = new AliPHOSTrackSegmentMakerv1("PHOS","On Flight") ;
614     tsm->SetWriting(0) ; //Do not write to file
615     pid = new AliPHOSPIDv1("PHOS","On Flight") ;
616     pid->SetWriting(0) ; //Do not write to file    
617   }
618   
619   fNevents=0 ;
620   //Scan all event in file
621   printf("      ") ;
622   while(rawReader->NextEvent()){
623     //Is it PHYSICAL event
624     if(rawReader->GetType() == AliRawEventHeaderBase::kPhysicsEvent){
625       fNevents++ ;
626       if(fNevents%100 ==0){
627         printf("\b\b\b\b\b\b%6d",fNevents) ;
628       }
629       if(rawStream->ReadDigits(digits)){
630         
631         //Test trigger
632         //Pedestal Event
633         ScanTrigger(rawStream->GetTrigger()) ;
634         if(rawStream->IsPEDevent() && fScanPed){
635           ScanPedestals(digits) ;
636         }
637         if((rawStream->IsNELevent() || rawStream->IsWELevent()) && fScanSig){
638           ScanEdep(digits) ;
639           if(fReconstruct){
640             gime->Clusterizer()->Exec("") ;
641             gime->TrackSegmentMaker()->Exec("") ;
642             gime->PID()->Exec("") ;
643             ScanRecon(recParticles) ;
644           }
645         }
646       }
647       
648       if(fNevents%fNUpdate == 0 ){ //upate all histograms       
649         TIter nextCanvas(fCanvasList);
650         TCanvas * c ;
651         while((c=(TCanvas*)nextCanvas())){
652           c->Modified() ;
653           c->Update() ;
654         }
655       }
656       gSystem->ProcessEvents(); 
657     }
658     //    if(fNevents>=200)break ;
659   }
660   printf("\n") ;
661   gBenchmark->Stop("PHOSOnlineMon");
662   Float_t time = gBenchmark->GetCpuTime("PHOSOnlineMon") ;
663   printf("took %f seconds for scanning, i.e. %f seconds per event %d  \n",
664          time,time/fNevents,fNevents) ; 
665   
666   //Update canvas with histograms at the end
667   TIter nextCanvas(fCanvasList);
668   TCanvas * c ;
669   while((c=(TCanvas*)nextCanvas())){
670     c->Modified(kTRUE) ;
671   }
672   
673   if(clu)delete clu ;
674   if(tsm)delete tsm ;
675   if(pid)delete pid ;
676   printf("delete 1 \n") ;
677   if(calibDB) delete calibDB ;
678   delete rawStream ;
679   delete rawReader ;
680 }
681 //____________________________________________________________________________ 
682 void  AliPHOSOnlineMonitor::Clean(){
683   //Cleans content of all histograms
684
685   TIter nextHisto(fHistosList);
686   TH1D * h ;
687   while((h=(TH1D*)nextHisto())){
688     h->Reset("ISE") ;
689   }
690   TIter nextCanvas(fCanvasList);
691   TCanvas * c ;
692   while((c=(TCanvas*)nextCanvas())){
693     c->Modified() ;
694   }
695 }
696 //____________________________________________________________________________ 
697 void  AliPHOSOnlineMonitor::Reset(){
698   //delets all canvas and histograms,
699   //marks buttons as unpressed
700
701   TIter nextHisto(fHistosList);
702   TH1D * h ;
703   while((h=(TH1D*)nextHisto())){
704     fHistosList->Remove(h) ;
705     delete h ;
706   }
707   TIter nextCanvas(fCanvasList);
708   TCanvas * c ;
709   while((c=(TCanvas*)nextCanvas())){
710     fCanvasList->Remove(c) ;
711     delete c ;
712   }
713   TObject *obj;
714   TGroupButton *button;
715   TIter next(fPrimitives);
716   
717   //Mark buttons as anpressed
718   while ((obj = next())) {
719     if (obj->InheritsFrom(TGroupButton::Class())) {
720       button = (TGroupButton*)obj;
721       if (button->GetBorderMode() < 0){
722         button->SetBorderMode(1) ;
723         button->Modified(kTRUE);
724       }
725     }
726   }
727   
728 }
729 //____________________________________________________________________________ 
730 void  AliPHOSOnlineMonitor::WriteHistograms(const char * filename){
731   //Write filled histograms to file
732   TFile * file = new TFile(filename,"Update") ;
733   file->cd() ;
734   TIter nextHisto(fHistosList);
735   TH1 * h ;
736   while((h=(TH1*)nextHisto())){
737     h->Write(0,TObject::kOverwrite) ;
738   }
739   file->Close() ; 
740 }