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 Bool_t bRead = readFromGridFile;
32 FILE* fp0 = fopen(fFileName.Data(), "r");
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();
47 fFile = new TFile(fFileName.Data(), "RECREATE");
51 else { // read from file (grid or local)
53 fFile->GetObject("AliITSOnlineSPDphysInfo", fPhysInfo);
57 else { // create new local file
58 fPhysInfo = new AliITSOnlineSPDphysInfo();
60 fFile = new TFile(fFileName.Data(), "RECREATE");
67 AliITSOnlineSPDphys::AliITSOnlineSPDphys(const AliITSOnlineSPDphys& /*phys*/) :
71 fInfoModified(kFALSE),
75 printf("This object should not be copied!");
78 AliITSOnlineSPDphys::~AliITSOnlineSPDphys() {
83 for (UInt_t hs=0; hs<6; hs++) {
84 if (fHitArray[hs]!=NULL) {
93 fFile = new TFile(fFileName.Data(), "UPDATE");
96 fFile->Delete("AliITSOnlineSPDphysInfo;*");
97 fFile->WriteTObject(fPhysInfo, "AliITSOnlineSPDphysInfo");
104 AliITSOnlineSPDphys& AliITSOnlineSPDphys::operator=(const AliITSOnlineSPDphys& phys) {
105 // assignment operator (should not be used)
106 printf("This object should not be copied!");
108 // still do nothing...
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];
119 fHitArray[hs] = NULL;
122 fPhysInfo->ClearThis();
125 fFile = new TFile(fFileName.Data(), "RECREATE");
127 fFile->WriteTObject(fPhysInfo, "AliITSOnlineSPDphysInfo");
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();
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");
146 if (GetEqNr()==999) {
147 SetEqNr(phys2->GetEqNr());
149 UInt_t nrRuns = phys2->GetNrRuns();
150 for (UInt_t i=0; i<nrRuns; i++) {
151 AddRunNr(phys2->GetRunNr(i));
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));
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]);
173 void AliITSOnlineSPDphys::SaveHitmap() {
174 // save hitmap to file
178 fFile = new TFile(fFileName.Data(), "UPDATE");
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());
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);
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;
199 fHitArray[hs]->SetHits(chipi,coli,rowi,(UInt_t)summedVal);
202 fHitArray[hs]->SetHits(chipi,coli,rowi,0);
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);
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);
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();
220 return ((Float_t)GetHits(hs,chipi,coli,rowi))/ntr;
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;
232 Float_t AliITSOnlineSPDphys::GetAverageMultiplicity(UInt_t hs, UInt_t chipi) {
233 // get average multiplicity for a chip
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);
244 UInt_t ntr = GetNrEvents();
252 Float_t AliITSOnlineSPDphys::GetAverageMultiplicityTot(UInt_t hs) {
253 // get average multiplicity for 10 chips
254 return GetAverageMultiplicity(hs,10);
257 void AliITSOnlineSPDphys::AddRunNr(UInt_t val) {
259 fPhysInfo->AddRunNr(val);
262 void AliITSOnlineSPDphys::SetEqNr(UInt_t val) {
264 fPhysInfo->SetEqNr(val);
267 void AliITSOnlineSPDphys::SetNrEvents(UInt_t val) {
269 fPhysInfo->SetNrEvents(val);
272 void AliITSOnlineSPDphys::AddNrEvents(Int_t val) {
273 // add val nr of events (val could be negative)
274 fPhysInfo->AddNrEvents(val);
277 void AliITSOnlineSPDphys::IncrementNrEvents() {
278 // increment nr of events
279 fPhysInfo->IncrementNrEvents();
284 UInt_t AliITSOnlineSPDphys::GetNrRuns() const {
285 return fPhysInfo->GetNrRuns();
287 UInt_t AliITSOnlineSPDphys::GetRunNr(UInt_t posi) const {
288 return fPhysInfo->GetRunNr(posi);
290 UInt_t AliITSOnlineSPDphys::GetEqNr() const {
291 return fPhysInfo->GetEqNr();
293 UInt_t AliITSOnlineSPDphys::GetNrEvents() const {
294 return fPhysInfo->GetNrEvents();