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