1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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.
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.
36 //*-- Author : D.Peressounko (RRC KI) after A.V. Kuryakin, (Sarov)
37 //////////////////////////////////////////////////////////////////////////////
39 // --- ROOT system ---
41 #include "TClonesArray.h"
45 #include "TGroupButton.h"
50 // --- Standard library ---
51 #include "TBenchmark.h"
52 #include "Riostream.h"
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 "AliPHOSRawStream2004.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"
69 ClassImp(AliPHOSOnlineMonitor)
72 //____________________________________________________________________________
73 AliPHOSOnlineMonitor::AliPHOSOnlineMonitor():
74 TDialogCanvas("PHOS","PHOS",150,300),
80 fCanvasList(new TList),
81 fHistosList(new TList),
91 //add this TFitPanel to the list of cleanups such that in case
92 //the referenced object is deleted, its pointer be reset
93 gROOT->GetListOfCleanups()->Add(this);
96 fRefPad = (TPad*)gROOT->GetSelectedPad();
98 fGeom = AliPHOSGeometry::GetInstance("IHEP","") ;
100 //____________________________________________________________________________
101 AliPHOSOnlineMonitor::AliPHOSOnlineMonitor(const char * inputfile):
102 TDialogCanvas("PHOS","PHOS",150,300),
105 fReconstruct(kFALSE),
108 fCanvasList(new TList),
109 fHistosList(new TList),
110 fInputFile(inputfile),
119 //add this TFitPanel to the list of cleanups such that in case
120 //the referenced object is deleted, its pointer be reset
121 gROOT->GetListOfCleanups()->Add(this);
124 fRefPad = (TPad*)gROOT->GetSelectedPad();
126 fGeom = AliPHOSGeometry::GetInstance("IHEP","") ;
129 //____________________________________________________________________________
130 AliPHOSOnlineMonitor::AliPHOSOnlineMonitor(const AliPHOSOnlineMonitor & /*rhs*/):
134 fReconstruct(kFALSE),
143 Fatal("AliPHOSOnlineMonitor", "not implemented");
146 //____________________________________________________________________________
147 AliPHOSOnlineMonitor & AliPHOSOnlineMonitor::operator = (const AliPHOSOnlineMonitor &)
149 Fatal("operator = ", "not implemented");
153 //____________________________________________________________________________
154 AliPHOSOnlineMonitor::~AliPHOSOnlineMonitor()
156 //Obvious, but unevoidable comment for destructor: cleans up everething.
157 TIter nextCanvas(fCanvasList);
159 while((c=(TCanvas*)nextCanvas()))
163 TIter nextHisto(fHistosList);
165 while((h=(TH1D*)nextHisto()))
173 //____________________________________________________________________________
174 void AliPHOSOnlineMonitor::MakeButtons(void){
175 //Make buttons on graphical menu
182 Float_t dy = (ymax-ymin)/nButtons ;
186 b = new TGroupButton("APPLY","Triggers","",xmin,y1,xmax,y2);
190 b = new TGroupButton("APPLY","Pedestals","",xmin,y1,xmax,y2);
194 b = new TGroupButton("APPLY","Spectrum all","",xmin,y1,xmax,y2);
198 b = new TGroupButton("APPLY","Spectrum g","",xmin,y1,xmax,y2);
202 b = new TGroupButton("APPLY","Inv Mass","",xmin,y1,xmax,y2);
204 for(Int_t i=1; i<=5; i++){
208 sprintf(name,"Edep(ADC) %d",i) ;
209 b = new TGroupButton("APPLY",name,"",xmin,y1,xmax,y2);
212 for(Int_t i=1; i<=5; i++){
216 sprintf(name,"Edep(Cal) %d",i) ;
217 b = new TGroupButton("APPLY",name,"",xmin,y1,xmax,y2);
222 b = new TGroupButton("APPLY","Go","",xmin,y1,xmax,y2);
226 //____________________________________________________________________________
227 void AliPHOSOnlineMonitor::Apply(const char *action){
228 //Function to handle button actions
230 TDialogCanvas::Apply() ;
233 TGroupButton *button;
234 TIter next(fPrimitives);
236 if (!strcmp(action,"Triggers")) {
240 if (!strcmp(action,"Pedestals")) {
243 if (!strcmp(action,"Spectrum all")) {
244 DrawSpectrum("all") ;
246 if (!strcmp(action,"Spectrum g")) {
247 DrawSpectrum("gamma") ;
249 if (!strcmp(action,"Inv Mass")) {
252 if(strstr(action,"Edep")){
255 sscanf(action,"%s %d",tmp,&n) ;
257 if(strstr(action,"Cal"))
261 if (!strcmp(action,"Go")) {
265 //Mark button as pressed
266 if(strcmp(action,"Go")){ //Do not mark "Go" button
267 while ((obj = next())) {
268 if (obj->InheritsFrom(TGroupButton::Class())) {
269 button = (TGroupButton*)obj;
270 if(!strcmp(button->GetTitle(),action)){
271 if (button->GetBorderMode() > 0){
272 button->SetBorderMode(-1) ;
273 button->Modified(kTRUE);
280 //____________________________________________________________________________
281 void AliPHOSOnlineMonitor::SetInputFile(const char * filename){
282 //close previously opened
284 fInputFile = filename ;
286 //____________________________________________________________________________
287 void AliPHOSOnlineMonitor::DrawPedestals(){
288 //Prepare canvas and histograms for drawing pedestals
290 TIter nextCanvas(fCanvasList);
292 Bool_t exists = kFALSE ;
293 while((c=(TCanvas*)nextCanvas())){
294 if(!strcmp(c->GetName(),"Pedestals")){
300 c = new TDialogCanvas("Pedestals","Pedestals",300,200) ;
301 fCanvasList->AddLast(c) ;
304 TIter nextHisto(fHistosList);
307 while((h=(TH1D*)nextHisto())){
308 if(!strcmp(h->GetName(),"hPedestals")){
314 h = new TH1D("hPedestals","Pedestals per event",fGeom->GetNModules()*fGeom->GetNCristalsInModule(),0.,
315 1.*fGeom->GetNModules()*fGeom->GetNCristalsInModule()) ;
316 fHistosList->AddLast(h) ;
322 fScanPed = kTRUE ; //We will scan pedestals
325 //____________________________________________________________________________
326 void AliPHOSOnlineMonitor::DrawTriggers(){
327 //Prepare canvas and histogram for drawing triggers
329 TIter nextCanvas(fCanvasList);
331 Bool_t exists = kFALSE ;
332 while((c=(TCanvas*)nextCanvas())){
333 if(!strcmp(c->GetName(),"Triggers")){
339 c = new TDialogCanvas("Triggers","Triggers",200,200) ;
340 fCanvasList->AddLast(c) ;
343 TIter nextHisto(fHistosList);
346 while((h=(TH1D*)nextHisto())){
347 if(!strcmp(h->GetName(),"hTriggers")){
353 h = new TH1D("hTriggers","Triggers",2,0.,2.) ;
354 fHistosList->AddLast(h) ;
357 h->SetBit(TH1::kCanRebin);
358 h->Fill("LED",0.0000001) ;
359 h->Fill("PUL",0.0000001) ;
360 h->Fill("PED",0.0000001) ;
361 h->Fill("NEL",0.0000001) ;
362 h->Fill("WEL",0.0000001) ;
363 h->Fill("SOB",0.0000001) ;
364 h->Fill("EOB",0.0000001) ;
365 h->Fill("wrong",0.0000001) ;
366 h->LabelsOption("h");
372 //____________________________________________________________________________
373 void AliPHOSOnlineMonitor::DrawSpectrum(const char * opt){
374 //Prepare canvas and histograms for drawing spectra of all reconstructed particles or photons
376 TString name("Spectrum") ;
379 TIter nextCanvas(fCanvasList);
381 Bool_t exists = kFALSE ;
382 while((c=(TCanvas*)nextCanvas())){
383 if(!strcmp(c->GetName(),name.Data())){
389 c = new TDialogCanvas(name,name,250,300) ;
390 fCanvasList->AddLast(c) ;
393 TIter nextHisto(fHistosList);
397 while((h=(TH1D*)nextHisto())){
398 if(!strcmp(h->GetName(),name.Data())){
404 h = new TH1D(name,name,100,0.,100.) ;
405 fHistosList->AddLast(h) ;
411 fReconstruct = kTRUE ;
412 fScanSig = kTRUE ; //We will scan pedestals
415 //____________________________________________________________________________
416 void AliPHOSOnlineMonitor::DrawMinv(){
417 TIter nextCanvas(fCanvasList);
419 Bool_t exists = kFALSE ;
420 while((c=(TCanvas*)nextCanvas())){
421 if(!strcmp(c->GetName(),"InvMass")){
427 c = new TDialogCanvas("InvMass","Invariant mass",300,200) ;
428 fCanvasList->AddLast(c) ;
431 TIter nextHisto(fHistosList);
434 while((h=(TH1D*)nextHisto())){
435 if(!strcmp(h->GetName(),"hInvMass")){
441 h = new TH1D("hInvMass","hInvMass",1000,0.,1.0) ;
442 fHistosList->AddLast(h) ;
448 fReconstruct = kTRUE ;
449 fScanSig = kTRUE ; //We will scan pedestals
451 //____________________________________________________________________________
452 void AliPHOSOnlineMonitor::DrawEdep(Int_t mod,const char * opt){
454 sprintf(name,"Edep%s %d",opt,mod) ;
456 TIter nextCanvas(fCanvasList);
458 Bool_t exists = kFALSE ;
459 while((c=(TCanvas*)nextCanvas())){
460 if(!strcmp(c->GetName(),name)){
466 c = new TDialogCanvas(name,name,300,200) ;
467 fCanvasList->AddLast(c) ;
470 TIter nextHisto(fHistosList);
473 sprintf(name,"hEdep%s%d",opt,mod) ;
474 while((h=(TH2D*)nextHisto())){
475 if(!strcmp(h->GetName(),name)){
481 h = new TH2D(name,name,fGeom->GetNPhi(),0.,1.*fGeom->GetNPhi(),fGeom->GetNZ(),0.,1.*fGeom->GetNZ()) ;
482 fHistosList->AddLast(h) ;
488 fScanSig = kTRUE ; //We will scan signal events
489 if(strstr(opt,"Cal"))
490 fReconstruct = kTRUE ;
493 //____________________________________________________________________________
494 void AliPHOSOnlineMonitor::ScanPedestals(TClonesArray * digits){
495 //This method is called for events with PED trigger
496 //We fill bins with ADC values
498 TH1D * h = (TH1D*)gROOT->FindObjectAny("hPedestals");
500 Error("ScanPedestals","Can not fild histogram hPedestals") ;
503 for(Int_t i=0; i<digits->GetEntriesFast(); i++){
504 AliPHOSDigit * dig = static_cast<AliPHOSDigit*>(digits->At(i)) ;
505 h->AddBinContent(dig->GetId(),dig->GetAmp()) ;
508 //____________________________________________________________________________
509 void AliPHOSOnlineMonitor::ScanEdep(TClonesArray * digits){
510 //Fill 2D distribution of ADC values in NEL and WEL events
511 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
512 AliPHOSCalibrationDB *cdb = 0 ;
514 cdb = gime->CalibrationDB() ;
519 for(Int_t i=0; i<digits->GetEntriesFast(); i++){
520 AliPHOSDigit * dig = static_cast<AliPHOSDigit*>(digits->At(i)) ;
522 fGeom->AbsToRelNumbering(dig->GetId(),relId) ;
523 if(mod != relId[0]){ //new module, look for histograms
525 sprintf(name,"hEdep%d",mod) ;
526 h = (TH2D*)gROOT->FindObjectAny(name);
527 sprintf(name,"hEdepCal%d",mod) ;
528 hCal = (TH2D*)gROOT->FindObjectAny(name);
531 h->Fill(relId[2]-0.1,relId[3]-0.1,1.*dig->GetAmp()) ;
533 hCal->Fill(relId[2]-0.1,relId[3]-0.1,cdb->Calibrate(dig->GetAmp(),dig->GetId())) ;
536 //____________________________________________________________________________
537 void AliPHOSOnlineMonitor::ScanRecon(TClonesArray * recParticles){
538 if(!recParticles || recParticles->GetEntries()==0) return ;
540 TH1D* hSpectr = (TH1D*)gROOT->FindObjectAny("hSpectrumall");
541 TH1D* hSpectrGam= (TH1D*)gROOT->FindObjectAny("hSpectrumgamma");
542 TH1D* hInvMass = (TH1D*)gROOT->FindObjectAny("hInvMass");
543 for(Int_t i=0; i<recParticles->GetEntriesFast() ; i++){
544 AliPHOSRecParticle * p = (AliPHOSRecParticle *)recParticles->At(i) ;
545 if(hSpectr)hSpectr->Fill(p->Energy()) ;
546 if(hSpectrGam && p->IsPhoton())hSpectrGam->Fill(p->Energy()) ;
548 for(Int_t j=i+1; j<recParticles->GetEntriesFast() ; j++){
549 AliPHOSRecParticle * p2 = (AliPHOSRecParticle *)recParticles->At(j) ;
550 Double_t e = p->Energy() + p2->Energy() ;
551 Double_t x = p->Px() + p2->Px() ;
552 Double_t y = p->Py() + p2->Py() ;
553 Double_t z = p->Pz() + p2->Pz() ;
554 Double_t m = e*e-x*x-y*y-z*z ;
555 hInvMass->Fill(m>0?TMath::Sqrt(m): 0. ) ;
560 //____________________________________________________________________________
561 void AliPHOSOnlineMonitor::ScanTrigger(Int_t trig){
562 //Fills trigger distribution
564 TH1D * h = (TH1D*)gROOT->FindObjectAny("hTriggers");
567 case AliPHOSRawStream2004::kLED : h->Fill("LED",1.) ; break ;
568 case AliPHOSRawStream2004::kPUL : h->Fill("PUL",1.) ; break ;
569 case AliPHOSRawStream2004::kPED : h->Fill("PED",1.) ; break ;
570 case AliPHOSRawStream2004::kNEL : h->Fill("NEL",1.) ; break ;
571 case AliPHOSRawStream2004::kWEL : h->Fill("WEL",1.) ; break ;
572 case AliPHOSRawStream2004::kSOB : h->Fill("SOB",1.) ; break ;
573 case AliPHOSRawStream2004::kEOB : h->Fill("EOB",1.) ; break ;
574 default : h->Fill("wrong",1.) ;
577 //____________________________________________________________________________
578 void AliPHOSOnlineMonitor::SetConTableDB(const char * filename){
579 //Read ConnectionTableDB from file
580 TFile * file = new TFile(filename) ;
581 AliPHOSConTableDB * tmp = (AliPHOSConTableDB*)file->Get("AliPHOSConTableDB") ;
582 fcdb = new AliPHOSConTableDB(*tmp) ;
585 //____________________________________________________________________________
586 void AliPHOSOnlineMonitor::Go(){
587 //Perform scan of curent event
588 gBenchmark->Start("PHOSOnlineMon");
590 //First test if we need "Connection table" then open it
594 Info("Go","Read Connection table from file \"ConTableDB.root\"") ;
596 Error("Go","Please, set connection table with SetConTableDB() method") ;
601 AliPHOSGetterLight * gime = AliPHOSGetterLight::Instance("PHOS","On Flight") ;
603 //Configure CalibrManager to read data from file
604 //Create calibration database and read it
605 AliPHOSCalibrationDB * calibDB = 0 ;
606 if(fScanSig || fReconstruct){ //We will ned calibration parameters
607 AliPHOSCalibrManager::GetInstance("CalibrDB.root","root") ;
608 //If we configured manager to read from ASCII file,
609 //give him connection table. OK, it will not harm in any case.
610 AliPHOSCalibrManager::GetInstance()->SetConTable(fcdb) ;
612 calibDB = new AliPHOSCalibrationDB("OnLine") ;
613 calibDB->GetParameters() ; //Read parameters using Manager
614 gime->SetCalibrationDB(calibDB) ;
618 AliRawReaderDateV3 *rawReader = new AliRawReaderDateV3(fInputFile) ;
619 rawReader->RequireHeader(kFALSE);
620 AliPHOSRawStream2004 *rawStream = new AliPHOSRawStream2004(rawReader) ;
621 rawStream->SetConTableDB(fcdb) ;
623 TClonesArray * digits = gime->Digits() ;
624 TClonesArray * recParticles = gime->RecParticles() ;
625 AliPHOSClusterizerv1* clu = 0 ;
626 AliPHOSTrackSegmentMakerv1 * tsm = 0 ;
627 AliPHOSPIDv1 * pid = 0 ;
628 if(fReconstruct){ //We will need calibation parameters
629 clu = new AliPHOSClusterizerv1(gime->PHOSGeometry()) ;
630 clu->SetWriting(0) ; //Do not write to file
631 clu->SetEmcMinE(0.05) ; //Minimal energy of the digit
632 clu->SetEmcLocalMaxCut(0.05) ; //Height of local maximum over environment
633 clu->SetEmcClusteringThreshold(0.2) ; //Minimal energy to start cluster
634 // clu->SetUnfolding(kFALSE) ; //Do not unfold
635 tsm = new AliPHOSTrackSegmentMakerv1(gime->PHOSGeometry());
636 tsm->SetWriting(0) ; //Do not write to file
637 pid = new AliPHOSPIDv1(gime->PHOSGeometry()) ;
638 pid->SetWriting(0) ; //Do not write to file
642 //Scan all event in file
644 while(rawReader->NextEvent()){
645 //Is it PHYSICAL event
646 if(rawReader->GetType() == AliRawEventHeaderBase::kPhysicsEvent){
648 if(fNevents%100 ==0){
649 printf("\b\b\b\b\b\b%6d",fNevents) ;
651 if(rawStream->ReadDigits(digits)){
655 ScanTrigger(rawStream->GetTrigger()) ;
656 if(rawStream->IsPEDevent() && fScanPed){
657 ScanPedestals(digits) ;
659 if((rawStream->IsNELevent() || rawStream->IsWELevent()) && fScanSig){
663 // gime->Clusterizer()->Exec("") ;
664 // gime->TrackSegmentMaker()->Exec("") ;
665 // gime->PID()->Exec("") ;
666 ScanRecon(recParticles) ;
671 if(fNevents%fNUpdate == 0 ){ //upate all histograms
672 TIter nextCanvas(fCanvasList);
674 while((c=(TCanvas*)nextCanvas())){
679 gSystem->ProcessEvents();
681 // if(fNevents>=200)break ;
684 gBenchmark->Stop("PHOSOnlineMon");
685 Float_t time = gBenchmark->GetCpuTime("PHOSOnlineMon") ;
686 printf("took %f seconds for scanning, i.e. %f seconds per event %d \n",
687 time,time/fNevents,fNevents) ;
689 //Update canvas with histograms at the end
690 TIter nextCanvas(fCanvasList);
692 while((c=(TCanvas*)nextCanvas())){
699 printf("delete 1 \n") ;
700 if(calibDB) delete calibDB ;
704 //____________________________________________________________________________
705 void AliPHOSOnlineMonitor::Clean(){
706 //Cleans content of all histograms
708 TIter nextHisto(fHistosList);
710 while((h=(TH1D*)nextHisto())){
713 TIter nextCanvas(fCanvasList);
715 while((c=(TCanvas*)nextCanvas())){
719 //____________________________________________________________________________
720 void AliPHOSOnlineMonitor::Reset(){
721 //delets all canvas and histograms,
722 //marks buttons as unpressed
724 TIter nextHisto(fHistosList);
726 while((h=(TH1D*)nextHisto())){
727 fHistosList->Remove(h) ;
730 TIter nextCanvas(fCanvasList);
732 while((c=(TCanvas*)nextCanvas())){
733 fCanvasList->Remove(c) ;
737 TGroupButton *button;
738 TIter next(fPrimitives);
740 //Mark buttons as anpressed
741 while ((obj = next())) {
742 if (obj->InheritsFrom(TGroupButton::Class())) {
743 button = (TGroupButton*)obj;
744 if (button->GetBorderMode() < 0){
745 button->SetBorderMode(1) ;
746 button->Modified(kTRUE);
752 //____________________________________________________________________________
753 void AliPHOSOnlineMonitor::WriteHistograms(const char * filename){
754 //Write filled histograms to file
755 TFile * file = new TFile(filename,"Update") ;
757 TIter nextHisto(fHistosList);
759 while((h=(TH1*)nextHisto())){
760 h->Write(0,TObject::kOverwrite) ;