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 ////////////////////////////////////////////////////////////
13 #include "AliITSOnlineSPDphys.h"
14 #include "AliITSOnlineSPDphysInfo.h"
15 #include "AliITSOnlineSPDHitArray.h"
17 AliITSOnlineSPDphys::AliITSOnlineSPDphys(const Char_t *fileName, Bool_t readFromGridFile) :
21 fInfoModified(kFALSE),
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)
29 for(Int_t ihs =0; ihs<6; ihs++) fHitArray[ihs]=0x0;
31 Bool_t bRead = readFromGridFile;
34 FILE* fp0 = fopen(fFileName.Data(), "r");
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();
49 fFile = new TFile(fFileName.Data(), "RECREATE");
53 else { // read from file (grid or local)
55 fFile->GetObject("AliITSOnlineSPDphysInfo", fPhysInfo);
59 else { // create new local file
60 fPhysInfo = new AliITSOnlineSPDphysInfo();
62 fFile = new TFile(fFileName.Data(), "RECREATE");
69 AliITSOnlineSPDphys::AliITSOnlineSPDphys(const AliITSOnlineSPDphys& /*phys*/) :
73 fInfoModified(kFALSE),
77 for(Int_t i=0; i<6; i++) fHitArray[i]=0x0;
78 printf("This object should not be copied!");
81 AliITSOnlineSPDphys::~AliITSOnlineSPDphys() {
86 for (UInt_t hs=0; hs<6; hs++) {
87 if (fHitArray[hs]!=NULL) {
96 fFile = new TFile(fFileName.Data(), "UPDATE");
99 fFile->Delete("AliITSOnlineSPDphysInfo;*");
100 fFile->WriteTObject(fPhysInfo, "AliITSOnlineSPDphysInfo");
107 AliITSOnlineSPDphys& AliITSOnlineSPDphys::operator=(const AliITSOnlineSPDphys& phys) {
108 // assignment operator (should not be used)
109 printf("This object should not be copied!");
111 // still do nothing...
116 void 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];
122 fHitArray[hs] = NULL;
125 fPhysInfo->ClearThis();
128 fFile = new TFile(fFileName.Data(), "RECREATE");
130 fFile->WriteTObject(fPhysInfo, "AliITSOnlineSPDphysInfo");
134 void AliITSOnlineSPDphys::InitHitmap() {
135 // init hit arrays and hit events
136 for (UInt_t hs=0; hs<6; hs++) {
137 fHitArray[hs] = new AliITSOnlineSPDHitArray();
142 void 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");
149 if (GetEqNr()==999) {
150 SetEqNr(phys2->GetEqNr());
152 UInt_t nrRuns = phys2->GetNrRuns();
153 for (UInt_t i=0; i<nrRuns; i++) {
154 AddRunNr(phys2->GetRunNr(i));
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));
168 void 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]);
176 void AliITSOnlineSPDphys::SaveHitmap() {
177 // save hitmap to file
181 fFile = new TFile(fFileName.Data(), "UPDATE");
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());
193 void 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);
198 void 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;
202 fHitArray[hs]->SetHits(chipi,coli,rowi,(UInt_t)summedVal);
205 fHitArray[hs]->SetHits(chipi,coli,rowi,0);
209 void 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);
215 UInt_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);
219 Float_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();
223 return ((Float_t)GetHits(hs,chipi,coli,rowi))/ntr;
229 Float_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;
235 Float_t AliITSOnlineSPDphys::GetAverageMultiplicity(UInt_t hs, UInt_t chipi) {
236 // get average multiplicity for a chip
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);
247 UInt_t ntr = GetNrEvents();
255 Float_t AliITSOnlineSPDphys::GetAverageMultiplicityTot(UInt_t hs) {
256 // get average multiplicity for 10 chips
257 return GetAverageMultiplicity(hs,10);
260 void AliITSOnlineSPDphys::AddRunNr(UInt_t val) {
262 fPhysInfo->AddRunNr(val);
265 void AliITSOnlineSPDphys::SetEqNr(UInt_t val) {
267 fPhysInfo->SetEqNr(val);
270 void AliITSOnlineSPDphys::SetNrEvents(UInt_t val) {
272 fPhysInfo->SetNrEvents(val);
275 void AliITSOnlineSPDphys::AddNrEvents(Int_t val) {
276 // add val nr of events (val could be negative)
277 fPhysInfo->AddNrEvents(val);
280 void AliITSOnlineSPDphys::IncrementNrEvents() {
281 // increment nr of events
282 fPhysInfo->IncrementNrEvents();
287 UInt_t AliITSOnlineSPDphys::GetNrRuns() const {
288 return fPhysInfo->GetNrRuns();
290 UInt_t AliITSOnlineSPDphys::GetRunNr(UInt_t posi) const {
291 return fPhysInfo->GetRunNr(posi);
293 UInt_t AliITSOnlineSPDphys::GetEqNr() const {
294 return fPhysInfo->GetEqNr();
296 UInt_t AliITSOnlineSPDphys::GetNrEvents() const {
297 return fPhysInfo->GetNrEvents();