]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSCpvDA1.cxx
Update from Alberica. Addition of VZERO equalized signals and ZNC.
[u/mrichter/AliRoot.git] / PHOS / AliPHOSCpvDA1.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2008, 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 // Class AliPHOSCpvDA1 accumulates histograms with amplitudes per CPV channel.
18 // It is intended to run at DAQ or HLT computers.
19 // Author: Boris Polishchuk, 25 January 2008.
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #include "AliPHOSCpvDA1.h"
23 #include "TString.h"
24
25 ClassImp(AliPHOSCpvDA1)
26
27 //----------------------------------------------------------------
28 AliPHOSCpvDA1::AliPHOSCpvDA1(int module) : TNamed(),
29  fHistoFile(0),fMod(module)
30
31 {
32   // Create DA1 ("Calibration DA") object.
33   // module is the CPV module number (0..4).
34   // Checks existence of histograms which might have been left
35   // from the previous runs to continue their filling.
36   // Histogram names: module_iX_iZ.
37   // Root file name: CPV_ModuleX_Calib.root, where X - module number.
38   
39   char name[128];
40   TString sname="CPV_Module%d_Calib";
41   snprintf(name,sname.Length(),sname.Data(),fMod);
42   SetName(name);
43
44   char title[128];
45   TString stitle="Calibration Detector Algorithm for CPV module %d";
46   snprintf(title,stitle.Length(),stitle.Data(),fMod);
47   SetTitle(title);
48
49   char rootname[128];
50   TString srootname="%s.root";
51   snprintf(rootname,srootname.Length(),srootname.Data(),GetName());
52
53   fHistoFile =  new TFile(rootname,"update");
54
55   char hname[128];
56   TH1F* hist1=0;
57   TString shname="%d_%d_%d";
58
59   for(Int_t iX=0; iX<128; iX++) {
60     for(Int_t iZ=0; iZ<56; iZ++) {
61       snprintf(hname,shname.Length(),shname.Data(),fMod,iX,iZ);
62       hist1 = (TH1F*)fHistoFile->Get(hname);
63       if(hist1) fCharge[iX][iZ] = hist1;
64       else
65         fCharge[iX][iZ] = 0;
66     }
67   }
68  
69 }
70
71 //-------------------------------------------------------------------
72 AliPHOSCpvDA1::AliPHOSCpvDA1(const AliPHOSCpvDA1& da) : TNamed(da),
73   fHistoFile(0),fMod(da.fMod)
74 {
75   // Copy constructor.
76
77   fHistoFile = new TFile(da.GetName(),"update");
78
79   char hname[128];
80   TH1F* hist1=0;
81
82   for(Int_t iX=0; iX<128; iX++) {
83     for(Int_t iZ=0; iZ<56; iZ++) {
84
85       snprintf(hname,128,"%d_%d_%d",fMod,iX,iZ);
86       hist1 = (TH1F*)da.fHistoFile->Get(hname);
87       if(hist1) fCharge[iX][iZ] = new TH1F(*hist1);
88       else
89         fCharge[iX][iZ] = 0;
90     }
91   }
92   
93 }
94
95 //-------------------------------------------------------------------
96 AliPHOSCpvDA1& AliPHOSCpvDA1::operator= (const AliPHOSCpvDA1& da)
97 {
98   //Assignment operator.
99
100   if(this != &da) {
101
102     TString oldname(fHistoFile->GetName());
103     TString newname(da.fHistoFile->GetName());
104
105     if(oldname != newname) {
106       delete fHistoFile;
107       fHistoFile = new TFile(da.fHistoFile->GetName(),"update");
108     }
109
110     fMod = da.fMod;
111
112     SetName(da.GetName());
113     SetTitle(da.GetTitle());
114
115     for(Int_t iX=0; iX<128; iX++) {
116       for(Int_t iZ=0; iZ<56; iZ++) {
117
118         if(fCharge[iX][iZ]) delete fCharge[iX][iZ];
119         fCharge[iX][iZ] = da.fCharge[iX][iZ];
120       }
121     }
122     
123   }
124
125   return *this;
126 }
127
128
129 //-------------------------------------------------------------------
130 AliPHOSCpvDA1::~AliPHOSCpvDA1()
131 {
132   // Destructor
133   
134   UpdateHistoFile();
135   if(fHistoFile) delete fHistoFile;
136   
137 }
138
139 //-------------------------------------------------------------------
140 void AliPHOSCpvDA1::FillHistograms(Float_t e[128][56]) 
141 {
142   // Fill charge deposit histograms of one event.
143   // Charge data is encoded as e[X][Z], 
144   // where X(0..127) and Z(0..55) - pad position in the CPV module, 
145   // Charge in ADC counts.
146   // If no charge read for particular channel, 
147   // the correspondent array entry should be filled by zero.
148   // WARNING: this function should be called once per event!
149
150   char hname[128];
151   char htitl[128];
152   
153   for(Int_t iX=0; iX<128; iX++) {
154     for (Int_t iZ=0; iZ<56; iZ++) {
155       
156       if(!e[iX][iZ]) continue;
157       
158       if(fCharge[iX][iZ]) 
159         fCharge[iX][iZ]->Fill(e[iX][iZ]);
160       else {
161         snprintf(hname,128,"%d_%d_%d",fMod,iX,iZ);
162         snprintf(htitl,128,"Charge deposited on the pad %d_%d_%d",fMod,iX,iZ);
163         fCharge[iX][iZ] = new TH1F(hname,htitl,1024,0.,1024.);
164         fCharge[iX][iZ]->Fill(e[iX][iZ]);
165       }
166       
167     }
168   }
169   
170 }
171
172 //-------------------------------------------------------------------
173 void AliPHOSCpvDA1::UpdateHistoFile()
174 {
175   // Write histograms to file
176
177   if(!fHistoFile) return;
178   if(!fHistoFile->IsOpen()) return;
179
180   TH1F* hist1=0;
181
182   for(Int_t iX=0; iX<128; iX++) {
183     for(Int_t iZ=0; iZ<56; iZ++) {
184       
185       hist1 = fCharge[iX][iZ];
186       if(hist1) hist1->Write(hist1->GetName(),TObject::kWriteDelete);
187     }
188   }
189
190 }
191