]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSCalibHistoProducer.cxx
Optimizations introduced; some new histos added
[u/mrichter/AliRoot.git] / PHOS / AliPHOSCalibHistoProducer.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 AliPHOSCalibHistoProducer accumulating histograms
20 // with amplitudes per PHOS channel
21 // It is intended to run at DAQ computers (LDC, GDC, HLT or MOOD)
22 // and it fills the histograms with amplitudes per channel.
23 // Usage example see in PHOS/macros/Shuttle/AliPHOSCalibHistoProducer.C
24 //
25 // Author: Boris Polichtchouk, 4 October 2006
26 ///////////////////////////////////////////////////////////////////////////////
27
28 #include "AliLog.h"
29 #include "AliPHOSCalibHistoProducer.h"
30 #include "TH1.h"
31 #include "TH2F.h"
32 #include "TFile.h"
33 #include "AliPHOSRawDecoder.h"
34
35 ClassImp(AliPHOSCalibHistoProducer)
36
37 //-----------------------------------------------------------------------------
38 AliPHOSCalibHistoProducer::AliPHOSCalibHistoProducer() : 
39   fRawDecoder(0),fHistoFile(0),fUpdatingRate(100),fIsOldRCUFormat(kFALSE),
40   fEvents(0)
41 {
42   // Constructor: initializes data members
43   // Checks existence of histograms which might have been left
44   // from the previous runs to continues their filling
45
46   fHistoFile =  new TFile("calibHisto.root","update");
47   
48   for(Int_t module=0; module<5; module++) {
49     for(Int_t column=0; column<56; column++) {
50       for(Int_t row=0; row<64; row++) {
51         char hname[128];
52         sprintf(hname,"mod%dcol%drow%d",module,column,row);
53         TH1F* hist = (TH1F*)fHistoFile->Get(hname);
54         if(hist) 
55           fAmpHisto[module][column][row]=hist;
56         else 
57           fAmpHisto[module][column][row] = 0;     
58       }
59     }
60   }
61 }
62
63 //-----------------------------------------------------------------------------
64 AliPHOSCalibHistoProducer::~AliPHOSCalibHistoProducer()
65 {
66   // Destructor
67   
68   UpdateHistoFile();
69   if(fHistoFile) delete fHistoFile;
70
71 }
72
73 //-----------------------------------------------------------------------------
74 AliPHOSCalibHistoProducer::AliPHOSCalibHistoProducer(const AliPHOSCalibHistoProducer &histoproducer) :
75   TObject(histoproducer),fRawDecoder(histoproducer.fRawDecoder),fHistoFile(histoproducer.fHistoFile),
76   fUpdatingRate(histoproducer.fUpdatingRate),fIsOldRCUFormat(histoproducer.fIsOldRCUFormat),
77   fEvents(histoproducer.fEvents)
78 {
79   //Copy constructor.
80
81   for(Int_t module=0; module<5; module++) {
82     for(Int_t column=0; column<56; column++) {
83       for(Int_t row=0; row<64; row++) {
84         char hname[128];
85         sprintf(hname,"mod%dcol%drow%d",module,column,row);
86         TH1F* hist = (TH1F*)histoproducer.fHistoFile->Get(hname);
87         if(hist) 
88           fAmpHisto[module][column][row]= new TH1F(*hist);
89         else
90           fAmpHisto[module][column][row]=0;
91       }
92     }
93   }
94 }
95
96 //-----------------------------------------------------------------------------
97 AliPHOSCalibHistoProducer& AliPHOSCalibHistoProducer::operator= 
98 (const AliPHOSCalibHistoProducer &histoproducer)
99 {
100   //Assignment operator.
101
102   if(this != &histoproducer) {
103
104     fRawDecoder = histoproducer.fRawDecoder;
105     fHistoFile = histoproducer.fHistoFile;
106     fUpdatingRate = histoproducer.fUpdatingRate;
107     fIsOldRCUFormat = histoproducer.fIsOldRCUFormat;
108     fEvents = histoproducer.fEvents;
109
110     for(Int_t module=0; module<5; module++) {
111       for(Int_t column=0; column<56; column++) {
112         for(Int_t row=0; row<64; row++) {
113           if(fAmpHisto[module][column][row]){
114             delete fAmpHisto[module][column][row];
115             fAmpHisto[module][column][row] = histoproducer.fAmpHisto[module][column][row];
116           }
117           else
118           fAmpHisto[module][column][row] = histoproducer.fAmpHisto[module][column][row];
119         }
120       }
121     }
122
123
124   }
125
126   return *this;
127 }
128 //-----------------------------------------------------------------------------
129 void AliPHOSCalibHistoProducer::Run()
130 {
131   // Reads raw data of current event and fills amplitude histograms
132   // The histograms are written to file every fUpdatingRate events
133
134   if(!fRawDecoder) AliFatal("Raw decoder not set!");
135   
136   Double_t energy;
137   Int_t mod,col,row;
138   
139   if(fIsOldRCUFormat)
140     fRawDecoder->SetOldRCUFormat(kTRUE);
141
142   while(fRawDecoder->NextDigit()) {
143     
144     if(fRawDecoder->IsLowGain()) continue; 
145
146     energy = fRawDecoder->GetEnergy();
147     if(energy<10) continue; // noise
148     
149     mod = fRawDecoder->GetModule()-1;
150     col = fRawDecoder->GetColumn()-1;
151     row = fRawDecoder->GetRow()-1;
152     
153     if(fAmpHisto[mod][col][row]) {
154       fAmpHisto[mod][col][row]->Fill(energy);
155     }
156     else {
157       char hname[128];
158       sprintf(hname,"mod%dcol%drow%d",mod,col,row);
159       fAmpHisto[mod][col][row] = new TH1F(hname,hname,100,0.,1000.);
160       fAmpHisto[mod][col][row]->Fill(energy);
161     }
162     
163     // update histograms in local file every 100th event
164     if(fEvents%fUpdatingRate == 0) {
165       AliInfo(Form("Updating histo file, event %d, run %d\n",
166                    fEvents,fRawDecoder->GetRawReader()->GetRunNumber()));
167       UpdateHistoFile();
168     }
169     
170     //   UpdateHistoFile();
171     //   AliInfo(Form("%d events of run %d processed.",iEvent,runNum));
172   }
173   
174   fEvents++;
175   
176 }
177
178 //-----------------------------------------------------------------------------
179 void AliPHOSCalibHistoProducer::UpdateHistoFile()
180 {
181   // Write histograms to file
182
183   if(!fHistoFile) return;
184   if(!fHistoFile->IsOpen()) return;
185
186   TH1F* hist=0;
187   char hname[128];
188   char htitle[128];
189
190   for(Int_t module=0; module<5; module++) {
191     sprintf(hname,"hMeanE%d",module);
192     sprintf(htitle,"Mean energies in module %d",module);
193     TH2F hMeanE(hname,htitle,56,0.,56.,64,0.,64);
194
195     for(Int_t column=0; column<56; column++) {
196       for(Int_t row=0; row<64; row++) {
197         hist = fAmpHisto[module][column][row]; 
198         if(hist) hist->Write(hist->GetName(),TObject::kWriteDelete);
199         if(hist) hMeanE.SetBinContent(column,row,hist->GetMean());
200       }
201     }
202     hMeanE.Write(hMeanE.GetName(),TObject::kWriteDelete);
203   }
204
205 }