]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSOnlineSPDphys.cxx
Added Eventplane Dependence in dPhi Correlations code
[u/mrichter/AliRoot.git] / ITS / AliITSOnlineSPDphys.cxx
CommitLineData
6727e2db 1////////////////////////////////////////////////////////////
2// Author: Henrik Tydesjo //
3// Interface class to the containers of an online scan. //
4// Directly connected to a TFile with all containers. //
5// Handles reading and writing of this TFile. Hitmaps are //
6// stored in this file (AliITSOnlineSPDHitArray). //
7// Also some general information is stored //
8// (AliITSOnlineSPDphysInfo). //
9////////////////////////////////////////////////////////////
10
11#include <math.h>
6727e2db 12#include <TFile.h>
13#include "AliITSOnlineSPDphys.h"
14#include "AliITSOnlineSPDphysInfo.h"
15#include "AliITSOnlineSPDHitArray.h"
16
6ddf3d66 17AliITSOnlineSPDphys::AliITSOnlineSPDphys(const Char_t *fileName, Bool_t readFromGridFile) :
6727e2db 18 fFile(NULL),
19 fWrite(kFALSE),
20 fModified(kFALSE),
21 fInfoModified(kFALSE),
22 fPhysInfo(NULL),
23 fFileName(fileName)
24{
25 // constructor, open file for reading or writing
26 // look for a previously saved info object
27 // (if file not found create a new one and return, else read)
6ddf3d66 28
f84d7d19 29 for(Int_t ihs =0; ihs<6; ihs++) fHitArray[ihs]=0x0;
30
6ddf3d66 31 Bool_t bRead = readFromGridFile;
32
33 if (!bRead) {
34 FILE* fp0 = fopen(fFileName.Data(), "r");
35 if (fp0 != NULL) {
36 bRead=kTRUE;
37 fclose(fp0);
38 }
39 }
40
41 if (bRead) { // open file for reading
42 fFile = TFile::Open(fFileName.Data(), "READ");
43 if (fFile==NULL) { // grid file not found, create new local default file
44 printf("ERROR: AliITSOnlineSPDphys: File %s not found! Creating 'test999.root' file instead\n",fFileName.Data());
45 // create default empty file:
46 fFileName = "test999.root";
47 fPhysInfo = new AliITSOnlineSPDphysInfo();
48 fInfoModified=kTRUE;
49 fFile = new TFile(fFileName.Data(), "RECREATE");
50 fWrite=kTRUE;
51 InitHitmap();
52 }
53 else { // read from file (grid or local)
54 fWrite=kFALSE;
55 fFile->GetObject("AliITSOnlineSPDphysInfo", fPhysInfo);
56 ReadHitmap();
57 }
58 }
59 else { // create new local file
6727e2db 60 fPhysInfo = new AliITSOnlineSPDphysInfo();
61 fInfoModified=kTRUE;
62 fFile = new TFile(fFileName.Data(), "RECREATE");
63 fWrite=kTRUE;
64 InitHitmap();
65 }
6ddf3d66 66
6727e2db 67}
68
69AliITSOnlineSPDphys::AliITSOnlineSPDphys(const AliITSOnlineSPDphys& /*phys*/) :
70 fFile(NULL),
71 fWrite(kFALSE),
72 fModified(kFALSE),
73 fInfoModified(kFALSE),
74 fPhysInfo(NULL),
75 fFileName(".")
76{
9806b6f8 77 for(Int_t i=0; i<6; i++) fHitArray[i]=0x0;
6727e2db 78 printf("This object should not be copied!");
79}
80
81AliITSOnlineSPDphys::~AliITSOnlineSPDphys() {
82 // destructor
83 if (fModified) {
84 SaveHitmap();
85 }
86 for (UInt_t hs=0; hs<6; hs++) {
87 if (fHitArray[hs]!=NULL) {
88 delete fHitArray[hs];
89 fHitArray[hs]=NULL;
90 }
91 }
92 if (fInfoModified) {
93 if (!fWrite) {
94 fFile->Close();
95 delete fFile;
96 fFile = new TFile(fFileName.Data(), "UPDATE");
97 fWrite=kTRUE;
98 }
99 fFile->Delete("AliITSOnlineSPDphysInfo;*");
100 fFile->WriteTObject(fPhysInfo, "AliITSOnlineSPDphysInfo");
08ed0911 101 }
102 if (fFile!=NULL) {
6727e2db 103 delete fFile;
104 }
105}
106
107AliITSOnlineSPDphys& AliITSOnlineSPDphys::operator=(const AliITSOnlineSPDphys& phys) {
108 // assignment operator (should not be used)
109 printf("This object should not be copied!");
110 if (this!=&phys) {
111 // still do nothing...
112 }
113 return *this;
114}
115
116void AliITSOnlineSPDphys::ClearThis() {
117 // clear this phys, close file and open new
118 for (UInt_t hs=0; hs<6; hs++) {
119 if (fHitArray[hs]!=NULL) {
120 delete fHitArray[hs];
121 }
122 fHitArray[hs] = NULL;
123 }
124 InitHitmap();
125 fPhysInfo->ClearThis();
126 fFile->Close();
127 delete fFile;
128 fFile = new TFile(fFileName.Data(), "RECREATE");
129 fWrite=kTRUE;
130 fFile->WriteTObject(fPhysInfo, "AliITSOnlineSPDphysInfo");
131 fInfoModified=kTRUE;
132}
133
134void AliITSOnlineSPDphys::InitHitmap() {
135 // init hit arrays and hit events
136 for (UInt_t hs=0; hs<6; hs++) {
137 fHitArray[hs] = new AliITSOnlineSPDHitArray();
138 }
139 fModified=kTRUE;
140}
141
142void AliITSOnlineSPDphys::AddPhys(AliITSOnlineSPDphys* phys2) {
143 // add hitmap and info from another phys object
144 if (phys2==NULL) return;
145 if (GetEqNr()!=phys2->GetEqNr() && GetEqNr()!=999) {
146 printf("AliITSOnlineSPDphys::AddPhys eqNr mismatch!\n");
147 return;
148 }
149 if (GetEqNr()==999) {
150 SetEqNr(phys2->GetEqNr());
151 }
152 UInt_t nrRuns = phys2->GetNrRuns();
153 for (UInt_t i=0; i<nrRuns; i++) {
154 AddRunNr(phys2->GetRunNr(i));
155 }
156 SetNrEvents(GetNrEvents() + phys2->GetNrEvents());
157 for (UInt_t hs=0; hs<6; hs++) {
158 for (UInt_t chip=0; chip<10; chip++) {
159 for (UInt_t col=0; col<32; col++) {
160 for (UInt_t row=0; row<256; row++) {
161 SetHits(hs,chip,col,row,GetHits(hs,chip,col,row)+phys2->GetHits(hs,chip,col,row));
162 }
163 }
164 }
165 }
166}
167
168void AliITSOnlineSPDphys::ReadHitmap() {
169 // read hitmap into memory
170 for (UInt_t hs=0; hs<6; hs++) {
171 TString hName = Form("HitArray_HS%d",hs);
172 fFile->GetObject(hName.Data(), fHitArray[hs]);
173 }
174}
175
176void AliITSOnlineSPDphys::SaveHitmap() {
177 // save hitmap to file
178 if (!fWrite) {
179 fFile->Close();
180 delete fFile;
181 fFile = new TFile(fFileName.Data(), "UPDATE");
182 fWrite=kTRUE;
183 }
184 for (UInt_t hs=0; hs<6; hs++) {
185 TString hName = Form("HitArray_HS%d",hs);
186 TString hDelete = Form("%s;*",hName.Data());
187 fFile->Delete(hDelete.Data());
188 fFile->WriteTObject(fHitArray[hs], hName.Data());
189 }
190 fModified=kFALSE;
191}
192
193void AliITSOnlineSPDphys::SetHits(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi, UInt_t val) {
194 // set nr of hits for pixel
195 fHitArray[hs]->SetHits(chipi,coli,rowi,val);
196 fModified=kTRUE;
197}
198void AliITSOnlineSPDphys::AddHits(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi, Int_t val) {
199 // add val nr of hits for pixel (val could be negative)
200 Int_t summedVal = fHitArray[hs]->GetHits(chipi,coli,rowi)+val;
201 if (summedVal>0) {
202 fHitArray[hs]->SetHits(chipi,coli,rowi,(UInt_t)summedVal);
203 }
204 else {
205 fHitArray[hs]->SetHits(chipi,coli,rowi,0);
206 }
207 fModified=kTRUE;
208}
209void AliITSOnlineSPDphys::IncrementHits(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
210 // increment nr of hits for pixel
211 fHitArray[hs]->IncrementHits(chipi,coli,rowi);
212 fModified=kTRUE;
213}
214
215UInt_t AliITSOnlineSPDphys::GetHits(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
216 // get nr of hits for pixel
217 return fHitArray[hs]->GetHits(chipi,coli,rowi);
218}
219Float_t AliITSOnlineSPDphys::GetHitsEfficiency(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
220 // get the hit efficiency for pixel
221 UInt_t ntr = GetNrEvents();
222 if (ntr>0) {
223 return ((Float_t)GetHits(hs,chipi,coli,rowi))/ntr;
224 }
225 else {
226 return 0;
227 }
228}
229Float_t AliITSOnlineSPDphys::GetHitsEfficiencyError(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
230 // get error in hit efficiency for pixel
231 Float_t hits = GetHits(hs,chipi,coli,rowi);
232 UInt_t ntr = GetNrEvents();
233 return sqrt(hits*(ntr-hits)/ntr)/ntr;
234}
235Float_t AliITSOnlineSPDphys::GetAverageMultiplicity(UInt_t hs, UInt_t chipi) {
236 // get average multiplicity for a chip
237 Float_t nrhits = 0;
238 for (UInt_t chip=0;chip<10;chip++) {
239 if (chipi==10 || chip==chipi) {
240 for (Int_t col=0; col<32; col++) {
241 for (Int_t row=0; row<256; row++) {
242 nrhits+=GetHits(hs,chip,col,row);
243 }
244 }
245 }
246 }
247 UInt_t ntr = GetNrEvents();
248 if (ntr>0) {
249 return nrhits/ntr;
250 }
251 else {
252 return 0;
253 }
254}
255Float_t AliITSOnlineSPDphys::GetAverageMultiplicityTot(UInt_t hs) {
256 // get average multiplicity for 10 chips
257 return GetAverageMultiplicity(hs,10);
258}
259
260void AliITSOnlineSPDphys::AddRunNr(UInt_t val) {
261 // add a run nr
262 fPhysInfo->AddRunNr(val);
263 fInfoModified=kTRUE;
264}
265void AliITSOnlineSPDphys::SetEqNr(UInt_t val) {
266 // set router nr
267 fPhysInfo->SetEqNr(val);
268 fInfoModified=kTRUE;
269}
270void AliITSOnlineSPDphys::SetNrEvents(UInt_t val) {
271 // set nr of events
272 fPhysInfo->SetNrEvents(val);
273 fInfoModified=kTRUE;
274}
275void AliITSOnlineSPDphys::AddNrEvents(Int_t val) {
276 // add val nr of events (val could be negative)
277 fPhysInfo->AddNrEvents(val);
278 fInfoModified=kTRUE;
279}
280void AliITSOnlineSPDphys::IncrementNrEvents() {
281 // increment nr of events
282 fPhysInfo->IncrementNrEvents();
283 fInfoModified=kTRUE;
284}
285
286
287UInt_t AliITSOnlineSPDphys::GetNrRuns() const {
288 return fPhysInfo->GetNrRuns();
289}
290UInt_t AliITSOnlineSPDphys::GetRunNr(UInt_t posi) const {
291 return fPhysInfo->GetRunNr(posi);
292}
293UInt_t AliITSOnlineSPDphys::GetEqNr() const {
294 return fPhysInfo->GetEqNr();
295}
296UInt_t AliITSOnlineSPDphys::GetNrEvents() const {
297 return fPhysInfo->GetNrEvents();
298}
9806b6f8 299
300