]>
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> | |
6727e2db | 12 | #include <TFile.h> |
13 | #include "AliITSOnlineSPDphys.h" | |
14 | #include "AliITSOnlineSPDphysInfo.h" | |
15 | #include "AliITSOnlineSPDHitArray.h" | |
16 | ||
6ddf3d66 | 17 | AliITSOnlineSPDphys::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 | ||
69 | AliITSOnlineSPDphys::AliITSOnlineSPDphys(const AliITSOnlineSPDphys& /*phys*/) : | |
70 | fFile(NULL), | |
71 | fWrite(kFALSE), | |
72 | fModified(kFALSE), | |
73 | fInfoModified(kFALSE), | |
74 | fPhysInfo(NULL), | |
75 | fFileName(".") | |
76 | { | |
77 | printf("This object should not be copied!"); | |
78 | } | |
79 | ||
80 | AliITSOnlineSPDphys::~AliITSOnlineSPDphys() { | |
81 | // destructor | |
82 | if (fModified) { | |
83 | SaveHitmap(); | |
84 | } | |
85 | for (UInt_t hs=0; hs<6; hs++) { | |
86 | if (fHitArray[hs]!=NULL) { | |
87 | delete fHitArray[hs]; | |
88 | fHitArray[hs]=NULL; | |
89 | } | |
90 | } | |
91 | if (fInfoModified) { | |
92 | if (!fWrite) { | |
93 | fFile->Close(); | |
94 | delete fFile; | |
95 | fFile = new TFile(fFileName.Data(), "UPDATE"); | |
96 | fWrite=kTRUE; | |
97 | } | |
98 | fFile->Delete("AliITSOnlineSPDphysInfo;*"); | |
99 | fFile->WriteTObject(fPhysInfo, "AliITSOnlineSPDphysInfo"); | |
08ed0911 | 100 | } |
101 | if (fFile!=NULL) { | |
6727e2db | 102 | delete fFile; |
103 | } | |
104 | } | |
105 | ||
106 | AliITSOnlineSPDphys& AliITSOnlineSPDphys::operator=(const AliITSOnlineSPDphys& phys) { | |
107 | // assignment operator (should not be used) | |
108 | printf("This object should not be copied!"); | |
109 | if (this!=&phys) { | |
110 | // still do nothing... | |
111 | } | |
112 | return *this; | |
113 | } | |
114 | ||
115 | void AliITSOnlineSPDphys::ClearThis() { | |
116 | // clear this phys, close file and open new | |
117 | for (UInt_t hs=0; hs<6; hs++) { | |
118 | if (fHitArray[hs]!=NULL) { | |
119 | delete fHitArray[hs]; | |
120 | } | |
121 | fHitArray[hs] = NULL; | |
122 | } | |
123 | InitHitmap(); | |
124 | fPhysInfo->ClearThis(); | |
125 | fFile->Close(); | |
126 | delete fFile; | |
127 | fFile = new TFile(fFileName.Data(), "RECREATE"); | |
128 | fWrite=kTRUE; | |
129 | fFile->WriteTObject(fPhysInfo, "AliITSOnlineSPDphysInfo"); | |
130 | fInfoModified=kTRUE; | |
131 | } | |
132 | ||
133 | void AliITSOnlineSPDphys::InitHitmap() { | |
134 | // init hit arrays and hit events | |
135 | for (UInt_t hs=0; hs<6; hs++) { | |
136 | fHitArray[hs] = new AliITSOnlineSPDHitArray(); | |
137 | } | |
138 | fModified=kTRUE; | |
139 | } | |
140 | ||
141 | void AliITSOnlineSPDphys::AddPhys(AliITSOnlineSPDphys* phys2) { | |
142 | // add hitmap and info from another phys object | |
143 | if (phys2==NULL) return; | |
144 | if (GetEqNr()!=phys2->GetEqNr() && GetEqNr()!=999) { | |
145 | printf("AliITSOnlineSPDphys::AddPhys eqNr mismatch!\n"); | |
146 | return; | |
147 | } | |
148 | if (GetEqNr()==999) { | |
149 | SetEqNr(phys2->GetEqNr()); | |
150 | } | |
151 | UInt_t nrRuns = phys2->GetNrRuns(); | |
152 | for (UInt_t i=0; i<nrRuns; i++) { | |
153 | AddRunNr(phys2->GetRunNr(i)); | |
154 | } | |
155 | SetNrEvents(GetNrEvents() + phys2->GetNrEvents()); | |
156 | for (UInt_t hs=0; hs<6; hs++) { | |
157 | for (UInt_t chip=0; chip<10; chip++) { | |
158 | for (UInt_t col=0; col<32; col++) { | |
159 | for (UInt_t row=0; row<256; row++) { | |
160 | SetHits(hs,chip,col,row,GetHits(hs,chip,col,row)+phys2->GetHits(hs,chip,col,row)); | |
161 | } | |
162 | } | |
163 | } | |
164 | } | |
165 | } | |
166 | ||
167 | void AliITSOnlineSPDphys::ReadHitmap() { | |
168 | // read hitmap into memory | |
169 | for (UInt_t hs=0; hs<6; hs++) { | |
170 | TString hName = Form("HitArray_HS%d",hs); | |
171 | fFile->GetObject(hName.Data(), fHitArray[hs]); | |
172 | } | |
173 | } | |
174 | ||
175 | void AliITSOnlineSPDphys::SaveHitmap() { | |
176 | // save hitmap to file | |
177 | if (!fWrite) { | |
178 | fFile->Close(); | |
179 | delete fFile; | |
180 | fFile = new TFile(fFileName.Data(), "UPDATE"); | |
181 | fWrite=kTRUE; | |
182 | } | |
183 | for (UInt_t hs=0; hs<6; hs++) { | |
184 | TString hName = Form("HitArray_HS%d",hs); | |
185 | TString hDelete = Form("%s;*",hName.Data()); | |
186 | fFile->Delete(hDelete.Data()); | |
187 | fFile->WriteTObject(fHitArray[hs], hName.Data()); | |
188 | } | |
189 | fModified=kFALSE; | |
190 | } | |
191 | ||
192 | void AliITSOnlineSPDphys::SetHits(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi, UInt_t val) { | |
193 | // set nr of hits for pixel | |
194 | fHitArray[hs]->SetHits(chipi,coli,rowi,val); | |
195 | fModified=kTRUE; | |
196 | } | |
197 | void AliITSOnlineSPDphys::AddHits(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi, Int_t val) { | |
198 | // add val nr of hits for pixel (val could be negative) | |
199 | Int_t summedVal = fHitArray[hs]->GetHits(chipi,coli,rowi)+val; | |
200 | if (summedVal>0) { | |
201 | fHitArray[hs]->SetHits(chipi,coli,rowi,(UInt_t)summedVal); | |
202 | } | |
203 | else { | |
204 | fHitArray[hs]->SetHits(chipi,coli,rowi,0); | |
205 | } | |
206 | fModified=kTRUE; | |
207 | } | |
208 | void AliITSOnlineSPDphys::IncrementHits(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) { | |
209 | // increment nr of hits for pixel | |
210 | fHitArray[hs]->IncrementHits(chipi,coli,rowi); | |
211 | fModified=kTRUE; | |
212 | } | |
213 | ||
214 | UInt_t AliITSOnlineSPDphys::GetHits(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) { | |
215 | // get nr of hits for pixel | |
216 | return fHitArray[hs]->GetHits(chipi,coli,rowi); | |
217 | } | |
218 | Float_t AliITSOnlineSPDphys::GetHitsEfficiency(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) { | |
219 | // get the hit efficiency for pixel | |
220 | UInt_t ntr = GetNrEvents(); | |
221 | if (ntr>0) { | |
222 | return ((Float_t)GetHits(hs,chipi,coli,rowi))/ntr; | |
223 | } | |
224 | else { | |
225 | return 0; | |
226 | } | |
227 | } | |
228 | Float_t AliITSOnlineSPDphys::GetHitsEfficiencyError(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) { | |
229 | // get error in hit efficiency for pixel | |
230 | Float_t hits = GetHits(hs,chipi,coli,rowi); | |
231 | UInt_t ntr = GetNrEvents(); | |
232 | return sqrt(hits*(ntr-hits)/ntr)/ntr; | |
233 | } | |
234 | Float_t AliITSOnlineSPDphys::GetAverageMultiplicity(UInt_t hs, UInt_t chipi) { | |
235 | // get average multiplicity for a chip | |
236 | Float_t nrhits = 0; | |
237 | for (UInt_t chip=0;chip<10;chip++) { | |
238 | if (chipi==10 || chip==chipi) { | |
239 | for (Int_t col=0; col<32; col++) { | |
240 | for (Int_t row=0; row<256; row++) { | |
241 | nrhits+=GetHits(hs,chip,col,row); | |
242 | } | |
243 | } | |
244 | } | |
245 | } | |
246 | UInt_t ntr = GetNrEvents(); | |
247 | if (ntr>0) { | |
248 | return nrhits/ntr; | |
249 | } | |
250 | else { | |
251 | return 0; | |
252 | } | |
253 | } | |
254 | Float_t AliITSOnlineSPDphys::GetAverageMultiplicityTot(UInt_t hs) { | |
255 | // get average multiplicity for 10 chips | |
256 | return GetAverageMultiplicity(hs,10); | |
257 | } | |
258 | ||
259 | void AliITSOnlineSPDphys::AddRunNr(UInt_t val) { | |
260 | // add a run nr | |
261 | fPhysInfo->AddRunNr(val); | |
262 | fInfoModified=kTRUE; | |
263 | } | |
264 | void AliITSOnlineSPDphys::SetEqNr(UInt_t val) { | |
265 | // set router nr | |
266 | fPhysInfo->SetEqNr(val); | |
267 | fInfoModified=kTRUE; | |
268 | } | |
269 | void AliITSOnlineSPDphys::SetNrEvents(UInt_t val) { | |
270 | // set nr of events | |
271 | fPhysInfo->SetNrEvents(val); | |
272 | fInfoModified=kTRUE; | |
273 | } | |
274 | void AliITSOnlineSPDphys::AddNrEvents(Int_t val) { | |
275 | // add val nr of events (val could be negative) | |
276 | fPhysInfo->AddNrEvents(val); | |
277 | fInfoModified=kTRUE; | |
278 | } | |
279 | void AliITSOnlineSPDphys::IncrementNrEvents() { | |
280 | // increment nr of events | |
281 | fPhysInfo->IncrementNrEvents(); | |
282 | fInfoModified=kTRUE; | |
283 | } | |
284 | ||
285 | ||
286 | UInt_t AliITSOnlineSPDphys::GetNrRuns() const { | |
287 | return fPhysInfo->GetNrRuns(); | |
288 | } | |
289 | UInt_t AliITSOnlineSPDphys::GetRunNr(UInt_t posi) const { | |
290 | return fPhysInfo->GetRunNr(posi); | |
291 | } | |
292 | UInt_t AliITSOnlineSPDphys::GetEqNr() const { | |
293 | return fPhysInfo->GetEqNr(); | |
294 | } | |
295 | UInt_t AliITSOnlineSPDphys::GetNrEvents() const { | |
296 | return fPhysInfo->GetNrEvents(); | |
297 | } |