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