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 printf("This object should not be copied!");
80 AliITSOnlineSPDphys::~AliITSOnlineSPDphys() {
85 for (UInt_t hs=0; hs<6; hs++) {
86 if (fHitArray[hs]!=NULL) {
95 fFile = new TFile(fFileName.Data(), "UPDATE");
98 fFile->Delete("AliITSOnlineSPDphysInfo;*");
99 fFile->WriteTObject(fPhysInfo, "AliITSOnlineSPDphysInfo");
106 AliITSOnlineSPDphys& AliITSOnlineSPDphys::operator=(const AliITSOnlineSPDphys& phys) {
107 // assignment operator (should not be used)
108 printf("This object should not be copied!");
110 // still do nothing...
115 void AliITSOnlineSPDphys::ClearThis() {
116 // clear this phys, close file and open new
117 for (UInt_t hs=0; hs<6; hs++) {
118 if (fHitArray[hs]!=NULL) {
119 delete fHitArray[hs];
121 fHitArray[hs] = NULL;
124 fPhysInfo->ClearThis();
127 fFile = new TFile(fFileName.Data(), "RECREATE");
129 fFile->WriteTObject(fPhysInfo, "AliITSOnlineSPDphysInfo");
133 void AliITSOnlineSPDphys::InitHitmap() {
134 // init hit arrays and hit events
135 for (UInt_t hs=0; hs<6; hs++) {
136 fHitArray[hs] = new AliITSOnlineSPDHitArray();
141 void AliITSOnlineSPDphys::AddPhys(AliITSOnlineSPDphys* phys2) {
142 // add hitmap and info from another phys object
143 if (phys2==NULL) return;
144 if (GetEqNr()!=phys2->GetEqNr() && GetEqNr()!=999) {
145 printf("AliITSOnlineSPDphys::AddPhys eqNr mismatch!\n");
148 if (GetEqNr()==999) {
149 SetEqNr(phys2->GetEqNr());
151 UInt_t nrRuns = phys2->GetNrRuns();
152 for (UInt_t i=0; i<nrRuns; i++) {
153 AddRunNr(phys2->GetRunNr(i));
155 SetNrEvents(GetNrEvents() + phys2->GetNrEvents());
156 for (UInt_t hs=0; hs<6; hs++) {
157 for (UInt_t chip=0; chip<10; chip++) {
158 for (UInt_t col=0; col<32; col++) {
159 for (UInt_t row=0; row<256; row++) {
160 SetHits(hs,chip,col,row,GetHits(hs,chip,col,row)+phys2->GetHits(hs,chip,col,row));
167 void AliITSOnlineSPDphys::ReadHitmap() {
168 // read hitmap into memory
169 for (UInt_t hs=0; hs<6; hs++) {
170 TString hName = Form("HitArray_HS%d",hs);
171 fFile->GetObject(hName.Data(), fHitArray[hs]);
175 void AliITSOnlineSPDphys::SaveHitmap() {
176 // save hitmap to file
180 fFile = new TFile(fFileName.Data(), "UPDATE");
183 for (UInt_t hs=0; hs<6; hs++) {
184 TString hName = Form("HitArray_HS%d",hs);
185 TString hDelete = Form("%s;*",hName.Data());
186 fFile->Delete(hDelete.Data());
187 fFile->WriteTObject(fHitArray[hs], hName.Data());
192 void AliITSOnlineSPDphys::SetHits(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi, UInt_t val) {
193 // set nr of hits for pixel
194 fHitArray[hs]->SetHits(chipi,coli,rowi,val);
197 void AliITSOnlineSPDphys::AddHits(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi, Int_t val) {
198 // add val nr of hits for pixel (val could be negative)
199 Int_t summedVal = fHitArray[hs]->GetHits(chipi,coli,rowi)+val;
201 fHitArray[hs]->SetHits(chipi,coli,rowi,(UInt_t)summedVal);
204 fHitArray[hs]->SetHits(chipi,coli,rowi,0);
208 void AliITSOnlineSPDphys::IncrementHits(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
209 // increment nr of hits for pixel
210 fHitArray[hs]->IncrementHits(chipi,coli,rowi);
214 UInt_t AliITSOnlineSPDphys::GetHits(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
215 // get nr of hits for pixel
216 return fHitArray[hs]->GetHits(chipi,coli,rowi);
218 Float_t AliITSOnlineSPDphys::GetHitsEfficiency(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
219 // get the hit efficiency for pixel
220 UInt_t ntr = GetNrEvents();
222 return ((Float_t)GetHits(hs,chipi,coli,rowi))/ntr;
228 Float_t AliITSOnlineSPDphys::GetHitsEfficiencyError(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
229 // get error in hit efficiency for pixel
230 Float_t hits = GetHits(hs,chipi,coli,rowi);
231 UInt_t ntr = GetNrEvents();
232 return sqrt(hits*(ntr-hits)/ntr)/ntr;
234 Float_t AliITSOnlineSPDphys::GetAverageMultiplicity(UInt_t hs, UInt_t chipi) {
235 // get average multiplicity for a chip
237 for (UInt_t chip=0;chip<10;chip++) {
238 if (chipi==10 || chip==chipi) {
239 for (Int_t col=0; col<32; col++) {
240 for (Int_t row=0; row<256; row++) {
241 nrhits+=GetHits(hs,chip,col,row);
246 UInt_t ntr = GetNrEvents();
254 Float_t AliITSOnlineSPDphys::GetAverageMultiplicityTot(UInt_t hs) {
255 // get average multiplicity for 10 chips
256 return GetAverageMultiplicity(hs,10);
259 void AliITSOnlineSPDphys::AddRunNr(UInt_t val) {
261 fPhysInfo->AddRunNr(val);
264 void AliITSOnlineSPDphys::SetEqNr(UInt_t val) {
266 fPhysInfo->SetEqNr(val);
269 void AliITSOnlineSPDphys::SetNrEvents(UInt_t val) {
271 fPhysInfo->SetNrEvents(val);
274 void AliITSOnlineSPDphys::AddNrEvents(Int_t val) {
275 // add val nr of events (val could be negative)
276 fPhysInfo->AddNrEvents(val);
279 void AliITSOnlineSPDphys::IncrementNrEvents() {
280 // increment nr of events
281 fPhysInfo->IncrementNrEvents();
286 UInt_t AliITSOnlineSPDphys::GetNrRuns() const {
287 return fPhysInfo->GetNrRuns();
289 UInt_t AliITSOnlineSPDphys::GetRunNr(UInt_t posi) const {
290 return fPhysInfo->GetRunNr(posi);
292 UInt_t AliITSOnlineSPDphys::GetEqNr() const {
293 return fPhysInfo->GetEqNr();
295 UInt_t AliITSOnlineSPDphys::GetNrEvents() const {
296 return fPhysInfo->GetNrEvents();