]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSCalibHistoProducer.cxx
syst. check that reads the MC information for the case of TPC-only
[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 #include "AliRawReader.h"
35
36 ClassImp(AliPHOSCalibHistoProducer)
37
38 //-----------------------------------------------------------------------------
39 AliPHOSCalibHistoProducer::AliPHOSCalibHistoProducer() : 
40   fRawDecoder(0),fHistoFile(0),fUpdatingRate(100),
41   fEvents(0),fNbins(100),fXlow(0.),fXup(1000.)
42 {
43   // Constructor: initializes data members
44   // Checks existence of histograms which might have been left
45   // from the previous runs to continues their filling
46
47   fHistoFile =  new TFile("calibHisto.root","update");
48   
49   for(Int_t module=0; module<5; module++) {
50     for(Int_t column=0; column<56; column++) {
51       for(Int_t row=0; row<64; row++) {
52         char hname[128];
53         sprintf(hname,"mod%dcol%drow%d",module,column,row);
54         TH1F* hist = (TH1F*)fHistoFile->Get(hname);
55         if(hist) 
56           fAmpHisto[module][column][row]=hist;
57         else 
58           fAmpHisto[module][column][row] = 0;     
59       }
60     }
61   }
62 }
63
64 //-----------------------------------------------------------------------------            
65 AliPHOSCalibHistoProducer::AliPHOSCalibHistoProducer(Int_t nbinsx, Double_t xlow, Double_t xup) :
66   fRawDecoder(0),fHistoFile(0),fUpdatingRate(100),
67   fEvents(0),fNbins(nbinsx),fXlow(xlow),fXup(xup)
68 {
69   // Constructor: initializes data members.
70   // Checks existence of histograms which might have been left
71   // from the previous runs to continues their filling.
72   // In addition sets number of bins, low and upper limits common for all histograms.
73
74   fHistoFile =  new TFile("calibHisto.root","update");
75
76   for(Int_t module=0; module<5; module++) {
77     for(Int_t column=0; column<56; column++) {
78       for(Int_t row=0; row<64; row++) {
79         char hname[128];
80         sprintf(hname,"mod%dcol%drow%d",module,column,row);
81         TH1F* hist = (TH1F*)fHistoFile->Get(hname);
82         if(hist)
83           fAmpHisto[module][column][row]=hist;
84         else
85           fAmpHisto[module][column][row] = 0;
86       }
87     }
88   }
89 }
90
91 //-----------------------------------------------------------------------------
92 AliPHOSCalibHistoProducer::~AliPHOSCalibHistoProducer()
93 {
94   // Destructor
95   
96   UpdateHistoFile();
97   if(fHistoFile) delete fHistoFile;
98
99 }
100
101 //-----------------------------------------------------------------------------
102 AliPHOSCalibHistoProducer::AliPHOSCalibHistoProducer(const AliPHOSCalibHistoProducer &histoproducer) :
103   TObject(histoproducer),fRawDecoder(histoproducer.fRawDecoder),fHistoFile(histoproducer.fHistoFile),
104   fUpdatingRate(histoproducer.fUpdatingRate),
105   fEvents(histoproducer.fEvents),fNbins(histoproducer.fNbins),fXlow(histoproducer.fXlow),fXup(histoproducer.fXup)
106 {
107   //Copy constructor.
108
109   for(Int_t module=0; module<5; module++) {
110     for(Int_t column=0; column<56; column++) {
111       for(Int_t row=0; row<64; row++) {
112         char hname[128];
113         sprintf(hname,"mod%dcol%drow%d",module,column,row);
114         TH1F* hist = (TH1F*)histoproducer.fHistoFile->Get(hname);
115         if(hist) 
116           fAmpHisto[module][column][row]= new TH1F(*hist);
117         else
118           fAmpHisto[module][column][row]=0;
119       }
120     }
121   }
122 }
123
124 //-----------------------------------------------------------------------------
125 AliPHOSCalibHistoProducer& AliPHOSCalibHistoProducer::operator= 
126 (const AliPHOSCalibHistoProducer &histoproducer)
127 {
128   //Assignment operator.
129
130   if(this != &histoproducer) {
131
132     fRawDecoder = histoproducer.fRawDecoder;
133     fHistoFile = histoproducer.fHistoFile;
134     fUpdatingRate = histoproducer.fUpdatingRate;
135     fEvents = histoproducer.fEvents;
136     fEvents = histoproducer.fEvents;
137     fNbins = histoproducer.fNbins;
138     fXlow = histoproducer.fXlow;
139     fXup = histoproducer.fXup;   
140     
141     for(Int_t module=0; module<5; module++) {
142       for(Int_t column=0; column<56; column++) {
143         for(Int_t row=0; row<64; row++) {
144           if(fAmpHisto[module][column][row]){
145             delete fAmpHisto[module][column][row];
146             fAmpHisto[module][column][row] = histoproducer.fAmpHisto[module][column][row];
147           }
148           else
149           fAmpHisto[module][column][row] = histoproducer.fAmpHisto[module][column][row];
150         }
151       }
152     }
153
154
155   }
156
157   return *this;
158 }
159 //-----------------------------------------------------------------------------
160 void AliPHOSCalibHistoProducer::Run()
161 {
162   // Reads raw data of current event and fills amplitude histograms
163   // The histograms are written to file every fUpdatingRate events
164
165   if(!fRawDecoder) AliFatal("Raw decoder not set!");
166   
167   Double_t energy;
168   Int_t mod,col,row;
169   
170   while(fRawDecoder->NextDigit()) {
171     
172     if(fRawDecoder->IsLowGain()) continue; 
173
174     energy = fRawDecoder->GetEnergy();
175     
176     mod = fRawDecoder->GetModule()-1;
177     col = fRawDecoder->GetColumn()-1;
178     row = fRawDecoder->GetRow()-1;
179     
180     if(fAmpHisto[mod][col][row]) {
181       fAmpHisto[mod][col][row]->Fill(energy);
182     }
183     else {
184       char hname[128];
185       sprintf(hname,"mod%dcol%drow%d",mod,col,row);
186       fAmpHisto[mod][col][row] = new TH1F(hname,hname,fNbins,fXlow,fXup);
187       fAmpHisto[mod][col][row]->Fill(energy);
188     }
189   }
190     // update histograms in local file every 100th event
191     if(fEvents != 0 && fEvents%fUpdatingRate == 0) {
192       AliInfo(Form("Updating histo file, event %d, run %d\n",
193                    fEvents,fRawDecoder->GetRawReader()->GetRunNumber()));
194       UpdateHistoFile();
195     }
196     
197     //   UpdateHistoFile();
198     //   AliInfo(Form("%d events of run %d processed.",iEvent,runNum));
199   
200   fEvents++;
201   
202 }
203
204 //-----------------------------------------------------------------------------
205 void AliPHOSCalibHistoProducer::UpdateHistoFile()
206 {
207   // Write histograms to file
208
209   if(!fHistoFile) return;
210   if(!fHistoFile->IsOpen()) return;
211
212   TH1F* hist=0;
213   char hname[128];
214   char htitle[128];
215
216   for(Int_t module=0; module<5; module++) {
217     sprintf(hname,"hMeanE%d",module);
218     sprintf(htitle,"Mean energies in module %d",module);
219     TH2F hMeanE(hname,htitle,56,0.,56.,64,0.,64);
220
221     for(Int_t column=0; column<56; column++) {
222       for(Int_t row=0; row<64; row++) {
223         hist = fAmpHisto[module][column][row]; 
224         if(hist) hist->Write(hist->GetName(),TObject::kWriteDelete);
225         if(hist) hMeanE.SetBinContent(column,row,hist->GetMean());
226       }
227     }
228     hMeanE.Write(hMeanE.GetName(),TObject::kWriteDelete);
229   }
230
231 }