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. //
6 // Hitmaps and information on nr of events with hits //
7 // is stored in this file (AliITSOnlineSPDHitArray and //
8 // AliITSOnlineSPDHitEvent). Also some general //
9 // information is stored (AliITSOnlineSPDscanInfo). //
10 // When switching between different steps of the scan, //
11 // the previous step is automatically stored on the file. //
12 // With this scheme there is no risk of running out of //
14 ////////////////////////////////////////////////////////////
19 #include "AliITSOnlineSPDscan.h"
20 #include "AliITSOnlineSPDscanInfo.h"
21 #include "AliITSOnlineSPDHitArray.h"
22 #include "AliITSOnlineSPDHitEvent.h"
24 ClassImp(AliITSOnlineSPDscan)
26 AliITSOnlineSPDscan::AliITSOnlineSPDscan(Char_t *fileName) :
31 fInfoModified(kFALSE),
34 // constructor, open file for reading or writing
35 sprintf(fFileName,"%s",fileName);
36 // look for a previously saved info object
37 // (if file not found create a new one and return, else read)
38 FILE* fp0 = fopen(fFileName, "r");
40 fScanInfo = new AliITSOnlineSPDscanInfo();
41 fFile = new TFile(fFileName, "RECREATE");
46 fFile = new TFile(fFileName, "READ");
48 fFile->GetObject("AliITSOnlineSPDscanInfo", fScanInfo);
53 AliITSOnlineSPDscan::AliITSOnlineSPDscan(const AliITSOnlineSPDscan& /*scan*/) :
58 fInfoModified(kFALSE),
61 printf("This object should not be copied!");
64 AliITSOnlineSPDscan::~AliITSOnlineSPDscan() {
69 for (UInt_t hs=0; hs<6; hs++) {
70 if (fCurrentHitArray[hs]!=NULL) {
71 delete fCurrentHitArray[hs];
72 fCurrentHitArray[hs]=NULL;
74 if (fCurrentHitEvent[hs]!=NULL) {
75 delete fCurrentHitEvent[hs];
76 fCurrentHitEvent[hs]=NULL;
83 fFile = new TFile(fFileName, "UPDATE");
86 fFile->Delete("AliITSOnlineSPDscanInfo;*");
87 fFile->WriteTObject(fScanInfo, "AliITSOnlineSPDscanInfo");
93 AliITSOnlineSPDscan& AliITSOnlineSPDscan::operator=(const AliITSOnlineSPDscan& scan) {
94 // assignment operator (should not be used)
95 printf("This object should not be copied!");
97 // still do nothing...
103 //TObjArray* AliITSOnlineSPDscan::GetAsTObjArray() {
104 // TObjArray *arr = new TObjArray();
105 // arr->Add(fScanInfo);
106 // for (UInt_t step=0; step<GetNSteps(); step++) {
107 // SwitchToStep(step);
108 // for (UInt_t hs=0; hs<6; hs++) {
109 // arr->Add(fCurrentHitArray[hs]->CloneThis());
110 // arr->Add(fCurrentHitEvent[hs]->CloneThis());
116 //void AliITSOnlineSPDscan::ReadFromTObjArray(TObjArray *arr) {
118 // Int_t nrEntries = arr->GetEntriesFast();
119 // if (nrEntries>0 && nrEntries%2==1) {
120 // fScanInfo = (AliITSOnlineSPDscanInfo*) arr->At(0);
121 // fInfoModified=kTRUE;
122 // FillFromTObjArray(arr,nrEntries);
126 //void AliITSOnlineSPDscan::FillFromTObjArray(TObjArray *arr, UInt_t nrEntries) {
129 // while (index<nrEntries) {
130 // UInt_t step=(index-1)/12;
131 // SwitchToStep(step);
133 // fCurrentHitArray[hs] = (AliITSOnlineSPDHitArray*) arr->At(index);
136 // fCurrentHitEvent[hs] = (AliITSOnlineSPDHitEvent*) arr->At(index);
145 void AliITSOnlineSPDscan::ClearThis() {
146 // clear this scan, close file and open new
147 for (UInt_t hs=0; hs<6; hs++) {
148 if (fCurrentHitArray[hs]!=NULL) {
149 delete fCurrentHitArray[hs];
151 fCurrentHitArray[hs] = NULL;
152 if (fCurrentHitEvent[hs]!=NULL) {
153 delete fCurrentHitEvent[hs];
155 fCurrentHitEvent[hs] = NULL;
157 fScanInfo->ClearThis();
160 fFile = new TFile(fFileName, "RECREATE");
162 fFile->WriteTObject(fScanInfo, "AliITSOnlineSPDscanInfo");
166 void AliITSOnlineSPDscan::Init() {
167 // init hit arrays and hit events
168 for (UInt_t hs=0; hs<6; hs++) {
169 fCurrentHitArray[hs]=NULL;
170 fCurrentHitEvent[hs]=NULL;
175 UInt_t AliITSOnlineSPDscan::AddScanStep() {
176 // add a new scan step
178 return fScanInfo->AddScanStep();
181 void AliITSOnlineSPDscan::CreateNewStep() {
183 // save current step to file (if modified)
188 for (UInt_t hs=0; hs<6; hs++) {
189 if (fCurrentHitArray[hs]!=NULL) {
190 delete fCurrentHitArray[hs];
192 fCurrentHitArray[hs] = new AliITSOnlineSPDHitArray();
193 if (fCurrentHitEvent[hs]!=NULL) {
194 delete fCurrentHitEvent[hs];
196 fCurrentHitEvent[hs] = new AliITSOnlineSPDHitEvent();
198 fCurrentStep = fScanInfo->GetNSteps();
203 void AliITSOnlineSPDscan::SwitchToStep(UInt_t nsi) {
204 // switch to step nsi (save current step first if needed)
205 if ((Int_t)nsi!=fCurrentStep) {
209 for (UInt_t hs=0; hs<6; hs++) {
210 if (fCurrentHitArray[hs]!=NULL) {
211 delete fCurrentHitArray[hs];
212 fCurrentHitArray[hs]=NULL;
214 if (fCurrentHitEvent[hs]!=NULL) {
215 delete fCurrentHitEvent[hs];
216 fCurrentHitEvent[hs]=NULL;
219 if (nsi>=GetNSteps()) {
220 FillGap(nsi); // makes fCurrentStep = nsi
229 void AliITSOnlineSPDscan::FillGap(UInt_t nsi) {
230 //create new steps until nsi is reached
231 while (nsi>=GetNSteps()) {
232 fCurrentStep = AddScanStep();
236 void AliITSOnlineSPDscan::ReadCurrentStep() {
237 // read current step index into memory
238 for (UInt_t hs=0; hs<6; hs++) {
240 sprintf(stepName,"HitArray_HS%d_Step%d",hs,fCurrentStep);
241 fFile->GetObject(stepName, fCurrentHitArray[hs]);
242 Char_t stepName2[40];
243 sprintf(stepName2,"HitEvent_HS%d_Step%d",hs,fCurrentStep);
244 fFile->GetObject(stepName2, fCurrentHitEvent[hs]);
248 void AliITSOnlineSPDscan::SaveCurrentStep() {
249 // save current step to file
253 fFile = new TFile(fFileName, "UPDATE");
256 for (UInt_t hs=0; hs<6; hs++) {
258 sprintf(stepName,"HitArray_HS%d_Step%d",hs,fCurrentStep);
259 Char_t stepDelete[40];
260 sprintf(stepDelete,"%s;*",stepName);
261 fFile->Delete(stepDelete);
262 fFile->WriteTObject(fCurrentHitArray[hs], stepName);
263 Char_t stepName2[40];
264 sprintf(stepName2,"HitEvent_HS%d_Step%d",hs,fCurrentStep);
265 Char_t stepDelete2[40];
266 sprintf(stepDelete2,"%s;*",stepName2);
267 fFile->Delete(stepDelete2);
268 fFile->WriteTObject(fCurrentHitEvent[hs], stepName2);
273 void AliITSOnlineSPDscan::SetHits(UInt_t nsi, UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi, UInt_t val) {
274 // set nr of hits for pixel
276 fCurrentHitArray[hs]->SetHits(chipi,coli,rowi,val);
279 void AliITSOnlineSPDscan::IncrementHits(UInt_t nsi, UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
280 // increment nr of hits for pixel
282 fCurrentHitArray[hs]->IncrementHits(chipi,coli,rowi);
285 void AliITSOnlineSPDscan::SetHitEvents(UInt_t nsi, UInt_t hs, UInt_t chipi, Int_t val) {
286 // set nr of hit events for a chip
288 fCurrentHitEvent[hs]->SetHitEvent(chipi,val);
291 void AliITSOnlineSPDscan::SetHitEventsTot(UInt_t nsi, UInt_t hs, Int_t val) {
292 // set nr of hit events for 10 chips together
293 SetHitEvents(nsi,hs,10,val);
295 void AliITSOnlineSPDscan::IncrementHitEvents(UInt_t nsi, UInt_t hs, UInt_t chipi) {
296 // increment nr of hit events for a chip
298 fCurrentHitEvent[hs]->IncrementHitEvent(chipi);
301 void AliITSOnlineSPDscan::IncrementHitEventsTot(UInt_t nsi, UInt_t hs) {
302 // increment nr of hit events for 10 chips
303 IncrementHitEvents(nsi,hs,10);
307 UInt_t AliITSOnlineSPDscan::GetHits(UInt_t nsi, UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
308 // get nr of hits for pixel
309 if (nsi<GetNSteps()) {
311 return fCurrentHitArray[hs]->GetHits(chipi,coli,rowi);
317 Float_t AliITSOnlineSPDscan::GetHitsEfficiency(UInt_t nsi, UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
318 // get the hit efficiency for pixel
319 UInt_t ntr = GetTriggers(nsi);
321 return ((Float_t)GetHits(nsi,hs,chipi,coli,rowi))/ntr;
327 Float_t AliITSOnlineSPDscan::GetHitsEfficiencyError(UInt_t nsi, UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
328 // get error in hit efficiency for pixel
329 Float_t hits = GetHits(nsi,hs,chipi,coli,rowi);
330 UInt_t ntr = GetTriggers(nsi);
331 return sqrt(hits*(ntr-hits)/ntr)/ntr;
333 UInt_t AliITSOnlineSPDscan::GetHitEvents(UInt_t nsi, UInt_t hs, UInt_t chipi) {
334 // get nr of hit events for a chip
335 if (nsi<GetNSteps()) {
337 return fCurrentHitEvent[hs]->GetHitEvent(chipi);
343 UInt_t AliITSOnlineSPDscan::GetHitEventsTot(UInt_t nsi, UInt_t hs) {
344 // get nr of hit events for 10 chips
345 return GetHitEvents(nsi,hs,10);
347 Float_t AliITSOnlineSPDscan::GetHitEventsEfficiency(UInt_t nsi, UInt_t hs, UInt_t chipi) {
348 // get the hit events efficiency for a chip
349 UInt_t ntr = GetTriggers(nsi);
351 return ((Float_t)GetHitEvents(nsi,hs,chipi))/ntr;
357 Float_t AliITSOnlineSPDscan::GetHitEventsTotEfficiency(UInt_t nsi, UInt_t hs) {
358 // get the hit events efficiency for 10 chips
359 return GetHitEventsEfficiency(nsi,hs,10);
361 Float_t AliITSOnlineSPDscan::GetHitEventsEfficiencyError(UInt_t nsi, UInt_t hs, UInt_t chipi) {
362 // get error in hit events efficiency for a chip
363 Float_t hitevents = (Float_t) GetHitEvents(nsi,hs,chipi);
364 UInt_t ntr = GetTriggers(nsi);
365 return sqrt(hitevents*(ntr-hitevents)/ntr)/ntr;
367 Float_t AliITSOnlineSPDscan::GetHitEventsTotEfficiencyError(UInt_t nsi, UInt_t hs) {
368 // get error in hit events efficiency for 10 chips
369 return GetHitEventsEfficiencyError(nsi,hs,10);
371 Float_t AliITSOnlineSPDscan::GetAverageMultiplicity(UInt_t nsi, UInt_t hs, UInt_t chipi) {
372 // get average multiplicity for a chip
374 for (UInt_t chip=0;chip<10;chip++) {
375 if (chipi==10 || chip==chipi) {
376 for (Int_t col=0; col<32; col++) {
377 for (Int_t row=0; row<256; row++) {
378 nrhits+=GetHits(nsi,hs,chip,col,row);
383 UInt_t ntr = GetTriggers(nsi);
391 Float_t AliITSOnlineSPDscan::GetAverageMultiplicityTot(UInt_t nsi, UInt_t hs) {
392 // get average multiplicity for 10 chips
393 return GetAverageMultiplicity(nsi,hs,10);
397 void AliITSOnlineSPDscan::SetType(UInt_t val) {
399 fScanInfo->SetType(val);
402 void AliITSOnlineSPDscan::SetRunNr(UInt_t val) {
404 fScanInfo->SetRunNr(val);
407 void AliITSOnlineSPDscan::SetRouterNr(UInt_t val) {
409 fScanInfo->SetRouterNr(val);
412 void AliITSOnlineSPDscan::SetTriggers(UInt_t nsi, UInt_t val) {
413 // set nr of triggers
414 fScanInfo->SetTriggers(nsi,val);
417 void AliITSOnlineSPDscan::SetChipPresent(UInt_t hs, UInt_t chipi, Bool_t val){
419 fScanInfo->SetChipPresent(hs,chipi,val);
422 void AliITSOnlineSPDscan::SetRowStart(UInt_t val){
424 fScanInfo->SetRowStart(val);
427 void AliITSOnlineSPDscan::SetRowEnd(UInt_t val){
429 fScanInfo->SetRowEnd(val);
432 void AliITSOnlineSPDscan::SetDacStart(UInt_t val){
434 fScanInfo->SetDacStart(val);
437 void AliITSOnlineSPDscan::SetDacEnd(UInt_t val){
439 fScanInfo->SetDacEnd(val);
442 void AliITSOnlineSPDscan::SetDacStep(UInt_t val){
444 fScanInfo->SetDacStep(val);
447 void AliITSOnlineSPDscan::IncrementTriggers(UInt_t nsi) {
448 // increment nr of triggers
449 fScanInfo->IncrementTriggers(nsi);
455 UInt_t AliITSOnlineSPDscan::GetNSteps() const {
456 return fScanInfo->GetNSteps();
458 UInt_t AliITSOnlineSPDscan::GetType() const {
459 return fScanInfo->GetType();
461 UInt_t AliITSOnlineSPDscan::GetRunNr() const {
462 return fScanInfo->GetRunNr();
464 UInt_t AliITSOnlineSPDscan::GetRouterNr() const {
465 return fScanInfo->GetRouterNr();
467 UInt_t AliITSOnlineSPDscan::GetTriggers(UInt_t nsi) const {
468 return fScanInfo->GetTriggers(nsi);
470 Bool_t AliITSOnlineSPDscan::GetChipPresent(UInt_t hs, UInt_t chipi) const {
471 return fScanInfo->GetChipPresent(hs,chipi);
473 UInt_t AliITSOnlineSPDscan::GetRowStart() const {
474 return fScanInfo->GetRowStart();
476 UInt_t AliITSOnlineSPDscan::GetRowEnd() const {
477 return fScanInfo->GetRowEnd();
479 UInt_t AliITSOnlineSPDscan::GetDacStart() const {
480 return fScanInfo->GetDacStart();
482 UInt_t AliITSOnlineSPDscan::GetDacEnd() const {
483 return fScanInfo->GetDacEnd();
485 UInt_t AliITSOnlineSPDscan::GetDacStep() const {
486 return fScanInfo->GetDacStep();