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 ////////////////////////////////////////////////////////////
14 #include "AliITSOnlineSPDphys.h"
15 #include "AliITSOnlineSPDphysInfo.h"
16 #include "AliITSOnlineSPDHitArray.h"
18 AliITSOnlineSPDphys::AliITSOnlineSPDphys(const Char_t *fileName) :
22 fInfoModified(kFALSE),
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");
31 fPhysInfo = new AliITSOnlineSPDphysInfo();
33 fFile = new TFile(fFileName.Data(), "RECREATE");
39 fFile = new TFile(fFileName.Data(), "READ");
41 fFile->GetObject("AliITSOnlineSPDphysInfo", fPhysInfo);
46 AliITSOnlineSPDphys::AliITSOnlineSPDphys(const AliITSOnlineSPDphys& /*phys*/) :
50 fInfoModified(kFALSE),
54 printf("This object should not be copied!");
57 AliITSOnlineSPDphys::~AliITSOnlineSPDphys() {
62 for (UInt_t hs=0; hs<6; hs++) {
63 if (fHitArray[hs]!=NULL) {
72 fFile = new TFile(fFileName.Data(), "UPDATE");
75 fFile->Delete("AliITSOnlineSPDphysInfo;*");
76 fFile->WriteTObject(fPhysInfo, "AliITSOnlineSPDphysInfo");
82 AliITSOnlineSPDphys& AliITSOnlineSPDphys::operator=(const AliITSOnlineSPDphys& phys) {
83 // assignment operator (should not be used)
84 printf("This object should not be copied!");
86 // still do nothing...
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) {
100 fPhysInfo->ClearThis();
103 fFile = new TFile(fFileName.Data(), "RECREATE");
105 fFile->WriteTObject(fPhysInfo, "AliITSOnlineSPDphysInfo");
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();
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");
124 if (GetEqNr()==999) {
125 SetEqNr(phys2->GetEqNr());
127 UInt_t nrRuns = phys2->GetNrRuns();
128 for (UInt_t i=0; i<nrRuns; i++) {
129 AddRunNr(phys2->GetRunNr(i));
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));
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]);
151 void AliITSOnlineSPDphys::SaveHitmap() {
152 // save hitmap to file
156 fFile = new TFile(fFileName.Data(), "UPDATE");
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());
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);
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;
177 fHitArray[hs]->SetHits(chipi,coli,rowi,(UInt_t)summedVal);
180 fHitArray[hs]->SetHits(chipi,coli,rowi,0);
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);
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);
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();
198 return ((Float_t)GetHits(hs,chipi,coli,rowi))/ntr;
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;
210 Float_t AliITSOnlineSPDphys::GetAverageMultiplicity(UInt_t hs, UInt_t chipi) {
211 // get average multiplicity for a chip
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);
222 UInt_t ntr = GetNrEvents();
230 Float_t AliITSOnlineSPDphys::GetAverageMultiplicityTot(UInt_t hs) {
231 // get average multiplicity for 10 chips
232 return GetAverageMultiplicity(hs,10);
235 void AliITSOnlineSPDphys::AddRunNr(UInt_t val) {
237 fPhysInfo->AddRunNr(val);
240 void AliITSOnlineSPDphys::SetEqNr(UInt_t val) {
242 fPhysInfo->SetEqNr(val);
245 void AliITSOnlineSPDphys::SetNrEvents(UInt_t val) {
247 fPhysInfo->SetNrEvents(val);
250 void AliITSOnlineSPDphys::AddNrEvents(Int_t val) {
251 // add val nr of events (val could be negative)
252 fPhysInfo->AddNrEvents(val);
255 void AliITSOnlineSPDphys::IncrementNrEvents() {
256 // increment nr of events
257 fPhysInfo->IncrementNrEvents();
262 UInt_t AliITSOnlineSPDphys::GetNrRuns() const {
263 return fPhysInfo->GetNrRuns();
265 UInt_t AliITSOnlineSPDphys::GetRunNr(UInt_t posi) const {
266 return fPhysInfo->GetRunNr(posi);
268 UInt_t AliITSOnlineSPDphys::GetEqNr() const {
269 return fPhysInfo->GetEqNr();
271 UInt_t AliITSOnlineSPDphys::GetNrEvents() const {
272 return fPhysInfo->GetNrEvents();