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