]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSOnlineSPDphysAnalyzer.cxx
In Open() and GotoEvent() try the ESD operations first, fallback to run-loader.
[u/mrichter/AliRoot.git] / ITS / AliITSOnlineSPDphysAnalyzer.cxx
CommitLineData
6727e2db 1/**************************************************************************
2 * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16////////////////////////////////////////////////////////////
17// Author: Henrik Tydesjo //
18// This class is used in the detector algorithm framework //
19// to process the data stored in special container files //
20// (see AliITSOnlineSPDphys). //
21////////////////////////////////////////////////////////////
22
23#include "AliITSOnlineSPDphysAnalyzer.h"
24#include "AliITSOnlineSPDphys.h"
25#include "AliITSOnlineCalibrationSPDhandler.h"
26#include "AliITSRawStreamSPD.h"
27#include "AliITSIntMap.h"
28#include <TStyle.h>
29#include <TMath.h>
30#include <TF1.h>
31#include <TGraph.h>
32#include <TH2F.h>
33#include <TError.h>
34#include <iostream>
35#include <fstream>
36
37AliITSOnlineSPDphysAnalyzer::AliITSOnlineSPDphysAnalyzer(const Char_t *fileName, AliITSOnlineCalibrationSPDhandler* handler) :
38 fFileName(fileName),fPhysObj(NULL),fHandler(handler),
39 fNrEnoughStatChips(0),fNrDeadChips(0),fNrInefficientChips(0),
40 fNrEqHits(0),fbDeadProcessed(kFALSE),
41 fThreshNoisy(1),fThreshNoisyExp(-12),fThreshDead(1),fThreshDeadExp(-12),
42 fMinEventsForNoisy(10000),fMinEventsForDead(10000),
43 fDefinitelyNoisyRatio(0.1),
44 fMinNrEqHitsForDeadChips(60000),fRatioToMeanForInefficientChip(0.1)//!!!
45{
46 // constructor
47 Init();
48}
49
50AliITSOnlineSPDphysAnalyzer::AliITSOnlineSPDphysAnalyzer(AliITSOnlineSPDphys* physObj, AliITSOnlineCalibrationSPDhandler* handler) :
51 fFileName("test.root"),fPhysObj(NULL),fHandler(handler),
52 fNrEnoughStatChips(0),fNrDeadChips(0),fNrInefficientChips(0),
53 fNrEqHits(0),fbDeadProcessed(kFALSE),
54 fThreshNoisy(1),fThreshNoisyExp(-12),fThreshDead(1),fThreshDeadExp(-12),
55 fMinEventsForNoisy(10000),fMinEventsForDead(10000),
56 fDefinitelyNoisyRatio(0.1),
57 fMinNrEqHitsForDeadChips(60000),fRatioToMeanForInefficientChip(0.1)//!!!
58{
59 // alt constructor
60 fPhysObj = physObj;
61}
62
63AliITSOnlineSPDphysAnalyzer::AliITSOnlineSPDphysAnalyzer(const AliITSOnlineSPDphysAnalyzer& handle) :
64 fFileName("test.root"),fPhysObj(NULL),fHandler(NULL),
65 fNrEnoughStatChips(0),fNrDeadChips(0),fNrInefficientChips(0),
66 fNrEqHits(0),fbDeadProcessed(kFALSE),
67 fThreshNoisy(1),fThreshNoisyExp(-12),fThreshDead(1),fThreshDeadExp(-12),
68 fMinEventsForNoisy(10000),fMinEventsForDead(10000),
69 fDefinitelyNoisyRatio(0.1),
70 fMinNrEqHitsForDeadChips(60000),fRatioToMeanForInefficientChip(0.1)//!!!
71{
72 // copy constructor, only copies the filename and params (not the processed data)
73 fFileName=handle.fFileName;
74 fThreshNoisy = handle.fThreshNoisy;
75 fThreshNoisyExp = handle.fThreshNoisyExp;
76 fThreshDead = handle.fThreshDead;
77 fThreshDeadExp = handle.fThreshDeadExp;
78 fMinEventsForNoisy = handle.fMinEventsForNoisy;
79 fMinEventsForDead = handle.fMinEventsForDead;
80 fDefinitelyNoisyRatio = handle.fDefinitelyNoisyRatio;
81 fMinNrEqHitsForDeadChips = handle.fMinNrEqHitsForDeadChips;
82 fRatioToMeanForInefficientChip = handle.fRatioToMeanForInefficientChip;
83
84 Init();
85}
86
87AliITSOnlineSPDphysAnalyzer::~AliITSOnlineSPDphysAnalyzer() {
88 // destructor
89 if (fPhysObj!=NULL) delete fPhysObj;
90}
91
92AliITSOnlineSPDphysAnalyzer& AliITSOnlineSPDphysAnalyzer::operator=(const AliITSOnlineSPDphysAnalyzer& handle) {
93 // assignment operator, only copies the filename and params (not the processed data)
94 if (this!=&handle) {
95 if (fPhysObj!=NULL) delete fPhysObj;
96
97 fFileName=handle.fFileName;
98 fThreshNoisy = handle.fThreshNoisy;
99 fThreshNoisyExp = handle.fThreshNoisyExp;
100 fThreshDead = handle.fThreshDead;
101 fThreshDeadExp = handle.fThreshDeadExp;
102 fMinEventsForNoisy = handle.fMinEventsForNoisy;
103 fMinEventsForDead = handle.fMinEventsForDead;
104 fDefinitelyNoisyRatio = handle.fDefinitelyNoisyRatio;
105 fMinNrEqHitsForDeadChips = handle.fMinNrEqHitsForDeadChips;
106 fRatioToMeanForInefficientChip = handle.fRatioToMeanForInefficientChip;
107
108 fPhysObj = NULL;
109 fHandler = NULL;
110 fNrEnoughStatChips = 0;
111 fNrDeadChips = 0;
112 fNrInefficientChips = 0;
113 fNrEqHits = 0;
114 fbDeadProcessed = kFALSE;
115
116 Init();
117 }
118 return *this;
119}
120
121void AliITSOnlineSPDphysAnalyzer::Init() {
122 // initialize container obj
123 FILE* fp0 = fopen(fFileName.Data(), "r");
124 if (fp0 == NULL) {
125 return;
126 }
127 else {
128 fclose(fp0);
129 }
130 fPhysObj = new AliITSOnlineSPDphys(fFileName.Data());
131}
132
133void AliITSOnlineSPDphysAnalyzer::SetParam(const Char_t *pname, const Char_t *pval) {
134 // set a parameter
135 TString name = pname;
136 TString val = pval;
137 // printf("Setting Param %s to %s\n",name.Data(),val.Data());
138 if (name.CompareTo("MistakeProbabilityNoisy")==0) {
139 Double_t mistakeProbabilityNoisy = val.Atof();
140 fThreshNoisy = mistakeProbabilityNoisy;
141 fThreshNoisyExp = 0;
142 Exponent(fThreshNoisy,fThreshNoisyExp);
143 fThreshNoisy/=(20*6*10*32*256);
144 Exponent(fThreshNoisy,fThreshNoisyExp);
145 }
146 else if (name.CompareTo("MistakeProbabilityDead")==0) {
147 Double_t mistakeProbabilityDead = val.Atof();
148 fThreshDead = mistakeProbabilityDead;
149 fThreshDeadExp = 0;
150 Exponent(fThreshDead,fThreshDeadExp);
151 fThreshDead/=(20*6*10*32*256);
152 Exponent(fThreshDead,fThreshDeadExp);
153 }
154 else if (name.CompareTo("fMinEventsForNoisy")==0) {
155 fMinEventsForNoisy = val.Atoi();
156 }
157 else if (name.CompareTo("fMinEventsForDead")==0) {
158 fMinEventsForDead = val.Atoi();
159 }
160 else if (name.CompareTo("fDefinitelyNoisyRatio")==0) {
161 fDefinitelyNoisyRatio = val.Atof();
162 }
163 else if (name.CompareTo("fMinNrEqHitsForDeadChips")==0) {
164 fMinNrEqHitsForDeadChips = val.Atof();
165 }
166 else if (name.CompareTo("fRatioToMeanForInefficientChip")==0) {
167 fRatioToMeanForInefficientChip = val.Atof();
168 }
169 else {
170 Error("AliITSOnlineSPDphysAnalyzer::SetParam","Parameter %s in configuration file unknown.",name.Data());
171 }
172}
173
174void AliITSOnlineSPDphysAnalyzer::ReadParamsFromLocation(const Char_t *dirName) {
175 // opens file (default name) in dir dirName and reads parameters from it
176 TString paramsFileName = Form("%s/physics_params.txt",dirName);
177 ifstream paramsFile;
178 paramsFile.open(paramsFileName, ifstream::in);
179 if (paramsFile.fail()) {
180 printf("No config file (%s) present. Using default tuning parameters.\n",paramsFileName.Data());
181 }
182 else {
183 while(1) {
184 Char_t paramN[50];
185 Char_t paramV[50];
186 paramsFile >> paramN;
187 if (paramsFile.eof()) break;
188 paramsFile >> paramV;
189 SetParam(paramN,paramV);
190 if (paramsFile.eof()) break;
191 }
192 paramsFile.close();
193 }
194}
195
196
197UInt_t AliITSOnlineSPDphysAnalyzer::ProcessNoisyPixels() {
198 // process noisy pixel data , returns number of chips with enough statistics
199 if (fPhysObj==NULL) {
200 Warning("AliITSOnlineSPDphysAnalyzer::ProcessNoisyPixels","No data!");
201 return 0;
202 }
203 // do we have enough events to even try the algorithm?
204 if (GetNrEvents() < fMinEventsForNoisy) {
205 Warning("AliITSOnlineSPDphysAnalyzer::ProcessNoisyPixels","Nr events (%d) < fMinEventsForNoisy (%d)!",GetNrEvents(),fMinEventsForNoisy);
206 return 0;
207 }
208 // handler should be initialized
209 if (fHandler==NULL) {
210 Error("AliITSOnlineSPDphysAnalyzer::ProcessNoisyPixels","Calibration handler is not initialized!");
211 return 0;
212 }
213
214 UInt_t nrEnoughStatChips = 0;
215
216 for (UInt_t hs=0; hs<6; hs++) {
217 for (UInt_t chip=0; chip<10; chip++) {
218
219 UInt_t nrPixels = 0;
220 UInt_t nrChipHits = 0;
221 UInt_t nrMostHits = 0;
222 for (UInt_t col=0; col<32; col++) {
223 for (UInt_t row=0; row<256; row++) {
224 UInt_t nrHits = fPhysObj->GetHits(hs,chip,col,row);
225 nrChipHits += nrHits;
226 // if (nrHits>0) nrPixels++; // don't include pixels that might be dead
227 nrPixels++;
228 if (nrHits>fDefinitelyNoisyRatio*GetNrEvents()) {
229 fHandler->SetNoisyPixel(GetEqNr(),hs,chip,col,row);
230 nrPixels--;
231 nrChipHits-=nrHits;
232 }
233 else {
234 if (nrMostHits<nrHits) nrMostHits=nrHits;
235 }
236 }
237 }
238
239 if (nrChipHits>0) { // otherwise there are for sure no noisy
240 // Binomial with n events and probability p for pixel hit
241 UInt_t n = GetNrEvents();
242 if (nrPixels>0 && n>0) {
243
244 Double_t p = (Double_t)nrChipHits/nrPixels/n;
245
246 Double_t bin = 1;
247 Int_t binExp = 0;
248 // Bin(n,k=0):
249 for (UInt_t i=0; i<n; i++) {
250 bin*=(1-p);
251 Exponent(bin,binExp);
252 }
253 // Bin(n,k)
254 UInt_t k=1;
255 while (((binExp>fThreshNoisyExp || (binExp==fThreshNoisyExp && bin>fThreshNoisy)) || k<n*p) && k<=n) {
256 k++;
257 bin = bin*(n-k+1)/k*p/(1-p);
258 Exponent(bin,binExp);
259 }
260
261 // can we find noisy pixels...?
262 if (k<=n) {
263 // printf("eq %d , hs %d , chip %d : Noisy level = %d\n",GetEqNr(),hs,chip,k);
264 nrEnoughStatChips++;
265 // add noisy pixels to handler
266 UInt_t noiseLimit=k;
267 if (nrMostHits>=noiseLimit) {
268 for (UInt_t col=0; col<32; col++) {
269 for (UInt_t row=0; row<256; row++) {
270 UInt_t nrHits = fPhysObj->GetHits(hs,chip,col,row);
271 if (nrHits >= noiseLimit) {
272 fHandler->SetNoisyPixel(GetEqNr(),hs,chip,col,row);
273 }
274 }
275 }
276 }
277 }
278 }
279
280 }
281
282 } // for chip
283 } // for hs
284
285 return nrEnoughStatChips;
286}
287
288
289UInt_t AliITSOnlineSPDphysAnalyzer::ProcessDeadPixels() {
290 // process dead pixel data , returns number of chips with enough statistics
291 if (fPhysObj==NULL) {
292 Warning("AliITSOnlineSPDphysAnalyzer::ProcessDeadPixels","No data!");
293 return 0;
294 }
295 // do we have enough events to even try the algorithm?
296 if (GetNrEvents() < fMinEventsForDead) {
297 Warning("AliITSOnlineSPDphysAnalyzer::ProcessDeadPixels","Nr events (%d) < fMinEventsForDead (%d)!",GetNrEvents(),fMinEventsForDead);
298 return 0;
299 }
300 // handler should be initialized
301 if (fHandler==NULL) {
302 Error("AliITSOnlineSPDphysAnalyzer::ProcessDeadPixels","Calibration handler is not initialized!");
303 return 0;
304 }
305
b696414b 306 AliITSIntMap* possiblyDead = new AliITSIntMap();
6727e2db 307 AliITSIntMap* possiblyIneff = new AliITSIntMap();
308
309 fNrEnoughStatChips = 0;
310 fNrDeadChips = 0;
311 fNrInefficientChips = 0;
312 UInt_t nrPossiblyDeadChips = 0;
313 fNrEqHits = 0;
314
6727e2db 315
b696414b 316 for (UInt_t hs=0; hs<6; hs++) {
478d804c 317 if (!fHandler->IsActiveHS(GetEqNr(),hs)) {
b696414b 318 fNrDeadChips+=10;
319 }
320 else {
321 for (UInt_t chip=0; chip<10; chip++) {
478d804c 322 if (!fHandler->IsActiveChip(GetEqNr(),hs,chip)) {
b696414b 323 fNrDeadChips++;
324 }
325 else {
326 // perform search for individual dead pixels...
b696414b 327 Bool_t good=kFALSE;
328
329 UInt_t nrPossiblyDeadPixels = 0;
330 UInt_t nrPixels = 0;
331 UInt_t nrChipHits = 0;
332 for (UInt_t col=0; col<32; col++) {
333 for (UInt_t row=0; row<256; row++) {
334 UInt_t nrHits = fPhysObj->GetHits(hs,chip,col,row);
335 nrChipHits += nrHits;
336 if (!fHandler->IsPixelNoisy(GetEqNr(),hs,chip,col,row)) {
337 // don't include noisy pixels
338 nrPixels++;
339 if (nrHits==0) {
340 nrPossiblyDeadPixels++;
478d804c 341 }
342 else {
343 fHandler->UnSetDeadPixel(GetEqNr(),hs,chip,col,row); // unset (no action unless dead before)
b696414b 344 }
345 }
346 else {
347 nrChipHits -= nrHits; // this is needed when running offline (online nrHits should be 0 already)
348 }
6727e2db 349 }
350 }
b696414b 351 fNrEqHits+=nrChipHits;
352
478d804c 353 if (nrChipHits>0) {
354 // make sure the chip is not flagged as dead
355 fHandler->SetDeadChip(GetEqNr(),hs,chip,kFALSE);
6727e2db 356 }
6727e2db 357
b696414b 358 if (nrPossiblyDeadPixels==0) {
359 // no need to see if we have enough statistics...
360 fNrEnoughStatChips++;
361 good=kTRUE;
362 // printf("%3d",good);
363 // if (chip==9) printf("\n");
364 continue;
365 }
6727e2db 366
b696414b 367 if (nrChipHits==0) {
368 nrPossiblyDeadChips++;
b696414b 369 possiblyDead->Insert(hs,chip);
370 good=kFALSE;
371 // printf("%3d",good);
372 // if (chip==9) printf("\n");
373 continue;
374 }
6727e2db 375
b696414b 376 // Binomial with n events and probability p for pixel hit
377 UInt_t n = GetNrEvents();
378 if (nrPixels>0 && n>0) {
379
380 Double_t p = (Double_t)nrChipHits/nrPixels/n;
381
382 // probability of falsely assigning a dead pixel
383 Double_t falselyDeadProb = 1;
384 Int_t falselyDeadProbExp = 0;
385 for (UInt_t i=0; i<n; i++) {
386 falselyDeadProb*=(1-p);
387 Exponent(falselyDeadProb,falselyDeadProbExp);
388 // can we find dead pixels...?
389 if (falselyDeadProbExp<fThreshDeadExp || (falselyDeadProbExp==fThreshDeadExp && falselyDeadProb<fThreshDead)) {
390 fNrEnoughStatChips++;
391 good=kTRUE;
392 // add dead pixels to handler
478d804c 393 for (UInt_t col=0; col<32; col++) {
394 for (UInt_t row=0; row<256; row++) {
395 UInt_t nrHits = fPhysObj->GetHits(hs,chip,col,row);
396 if (!fHandler->IsPixelNoisy(GetEqNr(),hs,chip,col,row)) {
397 // don't include noisy pixels
398 nrPixels++;
399 if (nrHits==0) {
400 fHandler->SetDeadPixel(GetEqNr(),hs,chip,col,row);
401 }
402 }
403 }
404 }
b696414b 405 break;
406 }
407 }
408 if (!good) {
409 // this might be an inefficient chip
410 possiblyIneff->Insert(hs*10+chip,nrChipHits);
411 }
6727e2db 412
b696414b 413 }
414 else {
415 if (n>0) {
416 // this is a completely noisy chip... put in category enough stat
417 fNrEnoughStatChips++;
418 good=kTRUE;
419 }
420 }
6727e2db 421
b696414b 422 // printf("%3d",good);
423 // if (chip==9) printf("\n");
6727e2db 424
6727e2db 425 }
b696414b 426 } // for chip
427 }
6727e2db 428 } // for hs
b696414b 429
6727e2db 430
b696414b 431 Int_t key,val;
478d804c 432
6727e2db 433 // dead chips?
434 if (fNrEqHits>fMinNrEqHitsForDeadChips) {
b696414b 435 while (possiblyDead->Pop(key,val)) {
478d804c 436 fHandler->SetDeadChip(GetEqNr(),key,val,kFALSE);
b696414b 437 }
438 fNrDeadChips+=nrPossiblyDeadChips;
6727e2db 439 }
b696414b 440 delete possiblyDead;
6727e2db 441
442 // inefficient chips?
6727e2db 443 while (possiblyIneff->Pop(key,val)) {
444 if (val<fNrEqHits/60*fRatioToMeanForInefficientChip) {
445 fNrInefficientChips++;
446 }
447 }
448 delete possiblyIneff;
449
450
451 fbDeadProcessed = kTRUE;
452
453 return fNrEnoughStatChips;
454}
455
456
457UInt_t AliITSOnlineSPDphysAnalyzer::GetNrEnoughStatChips() {
458 // returns nr of enough stat chips
459 if (!fbDeadProcessed) ProcessDeadPixels();
460 return fNrEnoughStatChips;
461}
462UInt_t AliITSOnlineSPDphysAnalyzer::GetNrDeadChips() {
463 // returns nr of dead chips
464 if (!fbDeadProcessed) ProcessDeadPixels();
465 return fNrDeadChips;
466}
467UInt_t AliITSOnlineSPDphysAnalyzer::GetNrInefficientChips() {
468 // returns nr of inefficient chips
469 if (!fbDeadProcessed) ProcessDeadPixels();
470 return fNrInefficientChips;
471}
472UInt_t AliITSOnlineSPDphysAnalyzer::GetNrNeedsMoreStatChips() {
473 // returns nr of needs more stat chips
474 if (!fbDeadProcessed) ProcessDeadPixels();
475 return 60-fNrEnoughStatChips-fNrDeadChips-fNrInefficientChips;
476}
477
478UInt_t AliITSOnlineSPDphysAnalyzer::GetEqNr() const {
479 // returns the eq nr of phys obj
480 if (fPhysObj!=NULL) return fPhysObj->GetEqNr();
481 else return 999;
482}
483
484UInt_t AliITSOnlineSPDphysAnalyzer::GetNrEvents() const {
485 // returns the nr of events of phys obj
486 if (fPhysObj!=NULL) return fPhysObj->GetNrEvents();
487 else return 0;
488}
489
490void AliITSOnlineSPDphysAnalyzer::Exponent(Double_t &val, Int_t &valExp) const {
491 // put double in format with val and exp so that 1<val<10 - The actual value is val*10e(valExp)
492 while (val>10) {
493 val/=10;
494 valExp++;
495 }
496 while (val<1) {
497 val*=10;
498 valExp--;
499 }
500}
501
502
503
504TH2F* AliITSOnlineSPDphysAnalyzer::GetHitMapTot() {
505 // creates and returns a pointer to a hitmap histo (half sector style a la spdmood)
506 if (fPhysObj==NULL) {
507 Error("AliITSOnlineSPDphysAnalyzer::GetHitMapTot","No data!");
508 return NULL;
509 }
510 TString histoname = Form("Eq %d",GetEqNr());
511 TH2F* fHitMapTot = new TH2F(histoname.Data(),histoname.Data(),32*10,-0.5,32*10-0.5,256*6,-0.5,256*6-0.5);
512 fHitMapTot->SetNdivisions(-10,"X");
513 fHitMapTot->SetNdivisions(-006,"Y");
514 fHitMapTot->SetTickLength(0,"X");
515 fHitMapTot->SetTickLength(0,"Y");
516 fHitMapTot->GetXaxis()->SetLabelColor(gStyle->GetCanvasColor());
517 fHitMapTot->GetYaxis()->SetLabelColor(gStyle->GetCanvasColor());
518 for (UInt_t hs=0; hs<6; hs++) {
519 for (UInt_t chipNr=0; chipNr<10; chipNr++) {
520 for (UInt_t col=0; col<32; col++) {
521 for (UInt_t row=0; row<256; row++) {
522 fHitMapTot->Fill(chipNr*32+col,(5-hs)*256+row,fPhysObj->GetHits(hs,chipNr,col,row));
523 }
524 }
525 }
526 }
527 return fHitMapTot;
528}
529
530TH2F* AliITSOnlineSPDphysAnalyzer::GetHitMapChip(UInt_t hs, UInt_t chip) {
531 // creates and returns a pointer to a hitmap histo (chip style a la spdmood)
532 if (fPhysObj==NULL) {
533 Error("AliITSOnlineSPDphysAnalyzer::GetHitMapChip","No data!");
534 return NULL;
535 }
536
537 TString histoName;
538 TString histoTitle;
539 histoName = Form("fChipHisto_%d_%d_%d", GetEqNr(), hs, chip);
540 histoTitle = Form("Eq ID %d, Half Stave %d, Chip %d", GetEqNr(), hs, chip);
541
542 TH2F *returnHisto = new TH2F(histoName.Data(), histoTitle.Data(), 32, -0.5, 31.5, 256, -0.5, 255.5);
543 returnHisto->SetMinimum(0);
544 for (UInt_t col=0; col<32; col++) {
545 for (UInt_t row=0; row<256; row++) {
546 returnHisto->Fill(col,row,fPhysObj->GetHits(hs,chip,col,row));
547 }
548 }
549
550 return returnHisto;
551}