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");
83 AliITSOnlineSPDphys& AliITSOnlineSPDphys::operator=(const AliITSOnlineSPDphys& phys) {
84 // assignment operator (should not be used)
85 printf("This object should not be copied!");
87 // still do nothing...
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) {
101 fPhysInfo->ClearThis();
104 fFile = new TFile(fFileName.Data(), "RECREATE");
106 fFile->WriteTObject(fPhysInfo, "AliITSOnlineSPDphysInfo");
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();
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");
125 if (GetEqNr()==999) {
126 SetEqNr(phys2->GetEqNr());
128 UInt_t nrRuns = phys2->GetNrRuns();
129 for (UInt_t i=0; i<nrRuns; i++) {
130 AddRunNr(phys2->GetRunNr(i));
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));
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]);
152 void AliITSOnlineSPDphys::SaveHitmap() {
153 // save hitmap to file
157 fFile = new TFile(fFileName.Data(), "UPDATE");
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());
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);
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;
178 fHitArray[hs]->SetHits(chipi,coli,rowi,(UInt_t)summedVal);
181 fHitArray[hs]->SetHits(chipi,coli,rowi,0);
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);
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);
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();
199 return ((Float_t)GetHits(hs,chipi,coli,rowi))/ntr;
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;
211 Float_t AliITSOnlineSPDphys::GetAverageMultiplicity(UInt_t hs, UInt_t chipi) {
212 // get average multiplicity for a chip
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);
223 UInt_t ntr = GetNrEvents();
231 Float_t AliITSOnlineSPDphys::GetAverageMultiplicityTot(UInt_t hs) {
232 // get average multiplicity for 10 chips
233 return GetAverageMultiplicity(hs,10);
236 void AliITSOnlineSPDphys::AddRunNr(UInt_t val) {
238 fPhysInfo->AddRunNr(val);
241 void AliITSOnlineSPDphys::SetEqNr(UInt_t val) {
243 fPhysInfo->SetEqNr(val);
246 void AliITSOnlineSPDphys::SetNrEvents(UInt_t val) {
248 fPhysInfo->SetNrEvents(val);
251 void AliITSOnlineSPDphys::AddNrEvents(Int_t val) {
252 // add val nr of events (val could be negative)
253 fPhysInfo->AddNrEvents(val);
256 void AliITSOnlineSPDphys::IncrementNrEvents() {
257 // increment nr of events
258 fPhysInfo->IncrementNrEvents();
263 UInt_t AliITSOnlineSPDphys::GetNrRuns() const {
264 return fPhysInfo->GetNrRuns();
266 UInt_t AliITSOnlineSPDphys::GetRunNr(UInt_t posi) const {
267 return fPhysInfo->GetRunNr(posi);
269 UInt_t AliITSOnlineSPDphys::GetEqNr() const {
270 return fPhysInfo->GetEqNr();
272 UInt_t AliITSOnlineSPDphys::GetNrEvents() const {
273 return fPhysInfo->GetNrEvents();