Bug fix (Marian)
[u/mrichter/AliRoot.git] / TRD / AliTRDCalibPadStatus.cxx
CommitLineData
170c35f1 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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/* $Id$ */
17
0bc7827a 18////////////////////////////////////////////////////////////////////////////
19// //
20// Example: fill pedestal with Gaussian noise //
21// //
22// AliTRDCalibPadStatus ped; //
23// ped.TestEvent(numberofevent); //
24// //
25// // Method without histo //
26// ped.Analyse(); //
27// //
28// // Create the histo of the AliTRDCalROC //
29// TH2F * histo2dm = ped.GetCalRocMean(0,kFALSE)->MakeHisto2D(); //
30// histo2dm->Scale(10.0); //
31// TH1F * histo1dm = ped.GetCalRocMean(0,kFALSE)->MakeHisto1D(); //
32// histo1dm->Scale(10.0); //
33// TH2F * histo2ds = ped.GetCalRocSquares(0,kFALSE)->MakeHisto2D(); //
34// histo2ds->Scale(10.0); //
35// TH1F * histo1ds = ped.GetCalRocSquares(0,kFALSE)->MakeHisto1D(); //
36// histo1ds->Scale(10.0) //
37// //
38// // Draw output //
39// TCanvas* c1 = new TCanvas; //
40// c1->Divide(2,2); //
41// c1->cd(1); //
42// histo2dm->Draw("colz"); //
43// c1->cd(2); //
44// histo1dm->Draw(); //
45// c1->cd(3); //
46// histo2ds->Draw("colz"); //
47// c1->cd(4); //
48// histo1ds->Draw(); //
49// //
50// // Method with histo //
51// ped.AnalyseHisto(); //
52// //
53// // Take the histo //
54// TH1F *histo = ped.GetHisto(31); //
55// histo->SetEntries(1); //
56// histo->Draw(); //
57// //
58////////////////////////////////////////////////////////////////////////////
170c35f1 59
60//Root includes
61#include <TObjArray.h>
170c35f1 62#include <TH2F.h>
63#include <TString.h>
64#include <TMath.h>
170c35f1 65#include <TRandom.h>
66#include <TDirectory.h>
67#include <TFile.h>
f162af62 68
170c35f1 69//AliRoot includes
3a0f6479 70#include <AliMathBase.h>
170c35f1 71#include "AliRawReader.h"
72#include "AliRawReaderRoot.h"
73#include "AliRawReaderDate.h"
f162af62 74
3a0f6479 75//header file
e4db522f 76#include "AliLog.h"
3a0f6479 77#include "AliTRDCalibPadStatus.h"
5e64ce0d 78#include "AliTRDrawStreamBase.h"
f162af62 79#include "AliTRDgeometry.h"
3a0f6479 80#include "AliTRDCommonParam.h"
170c35f1 81#include "./Cal/AliTRDCalROC.h"
82#include "./Cal/AliTRDCalPadStatus.h"
289cc637 83#include "./Cal/AliTRDCalDet.h"
84#include "./Cal/AliTRDCalPad.h"
170c35f1 85#include "./Cal/AliTRDCalSingleChamberStatus.h"
170c35f1 86
87#ifdef ALI_DATE
88#include "event.h"
89#endif
90
170c35f1 91ClassImp(AliTRDCalibPadStatus) /*FOLD00*/
92
93//_____________________________________________________________________
94AliTRDCalibPadStatus::AliTRDCalibPadStatus() : /*FOLD00*/
95 TObject(),
f162af62 96 fGeo(0),
170c35f1 97 fAdcMin(0),
d95484e4 98 fAdcMax(21),
170c35f1 99 fDetector(-1),
cf46274d 100 fNumberOfTimeBins(0),
170c35f1 101 fCalRocArrayMean(540),
102 fCalRocArrayRMS(540),
e4db522f 103 fCalRocArrayMeand(540),
104 fCalRocArrayRMSd(540),
105 fHistoArray(540)
170c35f1 106{
107 //
108 // default constructor
109 //
f162af62 110
111 fGeo = new AliTRDgeometry();
112
170c35f1 113}
114
115//_____________________________________________________________________
116AliTRDCalibPadStatus::AliTRDCalibPadStatus(const AliTRDCalibPadStatus &ped) : /*FOLD00*/
117 TObject(ped),
f162af62 118 fGeo(0),
170c35f1 119 fAdcMin(ped.GetAdcMin()),
120 fAdcMax(ped.GetAdcMax()),
121 fDetector(ped.fDetector),
cf46274d 122 fNumberOfTimeBins(ped.fNumberOfTimeBins),
170c35f1 123 fCalRocArrayMean(540),
124 fCalRocArrayRMS(540),
e4db522f 125 fCalRocArrayMeand(540),
126 fCalRocArrayRMSd(540),
127 fHistoArray(540)
170c35f1 128{
129 //
130 // copy constructor
131 //
132 for (Int_t idet = 0; idet < 540; idet++){
170c35f1 133 const AliTRDCalROC *calRocMean = (AliTRDCalROC*)ped.fCalRocArrayMean.UncheckedAt(idet);
134 const AliTRDCalROC *calRocRMS = (AliTRDCalROC*)ped.fCalRocArrayRMS.UncheckedAt(idet);
e4db522f 135 const AliTRDCalROC *calRocMeand = (AliTRDCalROC*)ped.fCalRocArrayMeand.UncheckedAt(idet);
136 const AliTRDCalROC *calRocRMSd = (AliTRDCalROC*)ped.fCalRocArrayRMSd.UncheckedAt(idet);
170c35f1 137 const TH2F *hped = (TH2F*)ped.fHistoArray.UncheckedAt(idet);
138
170c35f1 139 if ( calRocMean != 0x0 ) fCalRocArrayMean.AddAt(new AliTRDCalROC(*calRocMean), idet);
140 if ( calRocRMS != 0x0 ) fCalRocArrayRMS.AddAt(new AliTRDCalROC(*calRocRMS), idet);
141
e4db522f 142 if ( calRocMeand != 0x0 ) fCalRocArrayMeand.AddAt(new AliTRDCalROC(*calRocMeand), idet);
143 if ( calRocRMSd != 0x0 ) fCalRocArrayRMSd.AddAt(new AliTRDCalROC(*calRocRMSd), idet);
144
170c35f1 145 if ( hped != 0x0 ){
146 TH2F *hNew = new TH2F(*hped);
147 hNew->SetDirectory(0);
148 fHistoArray.AddAt(hNew,idet);
149 }
150
151 }
f162af62 152 if (fGeo) {
153 delete fGeo;
154 }
155 fGeo = new AliTRDgeometry();
170c35f1 156}
f162af62 157
170c35f1 158//_____________________________________________________________________
159AliTRDCalibPadStatus& AliTRDCalibPadStatus::operator = (const AliTRDCalibPadStatus &source)
160{
161 //
162 // assignment operator
163 //
164 if (&source == this) return *this;
165 new (this) AliTRDCalibPadStatus(source);
166
167 return *this;
168}
f162af62 169
170c35f1 170//_____________________________________________________________________
171AliTRDCalibPadStatus::~AliTRDCalibPadStatus() /*FOLD00*/
172{
173 //
174 // destructor
175 //
1ca79a00 176 fCalRocArrayMean.Delete();
177 fCalRocArrayRMS.Delete();
178 fCalRocArrayMeand.Delete();
179 fCalRocArrayRMSd.Delete();
180 fHistoArray.Delete();
f162af62 181 if (fGeo) {
182 delete fGeo;
183 }
170c35f1 184}
f162af62 185
170c35f1 186//_____________________________________________________________________
170c35f1 187Int_t AliTRDCalibPadStatus::UpdateHisto(const Int_t icdet, /*FOLD00*/
e4db522f 188 const Int_t icRow,
189 const Int_t icCol,
190 const Int_t csignal,
191 const Int_t crowMax,
192 const Int_t ccold,
193 const Int_t icMcm)
170c35f1 194{
e4db522f 195 //
196 // Signal filling methode
197 //
170c35f1 198 Int_t nbchannel = icRow+icCol*crowMax;
e4db522f 199
200 // now the case of double read channel
201 if(ccold > 0){
202 nbchannel = (((ccold-1)*8+ icMcm)*crowMax+icRow)+144*crowMax;
203 //printf("nbchannel %d, ccold %d, icMcm %d, crowMax %d, icRow %d\n",nbchannel,ccold,icMcm,crowMax,icRow);
204 }
170c35f1 205
206 // fast filling methode.
207 // Attention: the entry counter of the histogram is not increased
208 // this means that e.g. the colz draw option gives an empty plot
209 Int_t bin = 0;
d95484e4 210 if ( !(((Int_t)csignal>=fAdcMax ) || ((Int_t)csignal<fAdcMin)) )
170c35f1 211 bin = (nbchannel+1)*(fAdcMax-fAdcMin+2)+((Int_t)csignal-fAdcMin+1);
d95484e4 212
213 //GetHisto(icdet,kTRUE)->Fill(csignal,nbchannel);
170c35f1 214
215 GetHisto(icdet,kTRUE)->GetArray()[bin]++;
216
217 return 0;
218}
219//_____________________________________________________________________
5e64ce0d 220Int_t AliTRDCalibPadStatus::ProcessEvent(AliTRDrawStreamBase *rawStream, Bool_t nocheck)
170c35f1 221{
222 //
e4db522f 223 // Event Processing loop - AliTRDRawStreamCosmic
3a0f6479 224 // 0 time bin problem or zero suppression
225 // 1 no input
226 // 2 input
227 //
170c35f1 228
3a0f6479 229 Int_t withInput = 1;
170c35f1 230
413153cb 231 rawStream->SetSharedPadReadout(kTRUE);
e4db522f 232
cf46274d 233 if(!nocheck) {
234 while (rawStream->Next()) {
235 Int_t rawversion = rawStream->GetRawVersion(); // current raw version
e4db522f 236 //if(!rawStream->IsDataZeroSuppressed()) {
237 if(rawversion > 2) {
238 AliInfo(Form("this is not no-zero-suppressed data, the version is %d",rawversion));
239 return 0;
240 }
cf46274d 241 Int_t idetector = rawStream->GetDet(); // current detector
242 Int_t iRow = rawStream->GetRow(); // current row
243 Int_t iRowMax = rawStream->GetMaxRow(); // current rowmax
244 Int_t iCol = rawStream->GetCol(); // current col
e4db522f 245
246
d95484e4 247 Int_t iADC = 21-rawStream->GetADC(); // current ADC
e4db522f 248 Int_t col = 0;
249 if(iADC == 1) col = 1;
250 else {
251 col = TMath::Max(0,(Int_t)(iADC-19));
252 if(col > 0) col++;
253 }
254 Int_t mcm = (Int_t)(iCol/18); // current group of 18 col pads
255 if(col > 1) mcm -= 1;
256 if(col ==1) mcm += 1;
257
258 //Bool_t shared = rawStream->IsCurrentPadShared();
259 //printf("ADC %d, iCol %d, col %d, mcm %d, shared %d\n",iADC,iCol,col,mcm,(Int_t)shared);
260
cf46274d 261 Int_t *signal = rawStream->GetSignals(); // current ADC signal
262 Int_t nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
263
e4db522f 264 if((fDetector != -1) && (nbtimebin != fNumberOfTimeBins)) {
265 AliInfo(Form("the number of time bins is %d, is different from the previous one %d",nbtimebin,fNumberOfTimeBins));
266 return 0;
267 }
cf46274d 268 fNumberOfTimeBins = nbtimebin;
269
d95484e4 270 for(Int_t k = 0; k < fNumberOfTimeBins; k++){
271 if(signal[k]>0) UpdateHisto(idetector,iRow,iCol,signal[k],iRowMax,col,mcm);
cf46274d 272 }
273
3a0f6479 274 withInput = 2;
cf46274d 275 }
276 }
277 else {
278 while (rawStream->Next()) {
279 Int_t idetector = rawStream->GetDet(); // current detector
280 Int_t iRow = rawStream->GetRow(); // current row
281 Int_t iRowMax = rawStream->GetMaxRow(); // current rowmax
282 Int_t iCol = rawStream->GetCol(); // current col
162a3e73 283
e4db522f 284
285 Int_t iADC = 21-rawStream->GetADC(); // current ADC
286 Int_t col = 0;
287 if(iADC == 1) col = 1;
288 else {
289 col = TMath::Max(0,(Int_t)(iADC-19));
290 if(col > 0) col++;
291 }
292 Int_t mcm = (Int_t)(iCol/18); // current group of 18 col pads
293 if(col > 1) mcm -= 1;
294 if(col ==1) mcm += 1;
295
cf46274d 296 Int_t *signal = rawStream->GetSignals(); // current ADC signal
297 Int_t nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
298
d95484e4 299
162a3e73 300 //printf("det %d, row %d, signal[0] %d, signal[1] %d, signal [2] %d\n", idetector, iRow, signal[0], signal[1], signal[2]);
301
d95484e4 302 for(Int_t k = 0; k < nbtimebin; k++){
303 if(signal[k]>0) {
304 UpdateHisto(idetector,iRow,iCol,signal[k],iRowMax,col,mcm);
162a3e73 305 //printf("Update with det %d, row %d, col %d, signal %d, rowmax %d, col %d, mcm %d\n",idetector,iRow,iCol,signal[n],iRowMax,col,mcm);
306 }
cf46274d 307 }
308
3a0f6479 309 withInput = 2;
170c35f1 310 }
170c35f1 311 }
312
313 return withInput;
314}
3a0f6479 315
170c35f1 316//_____________________________________________________________________
3a0f6479 317Int_t AliTRDCalibPadStatus::ProcessEvent(AliRawReader *rawReader, Bool_t nocheck)
170c35f1 318{
319 //
320 // Event processing loop - AliRawReader
321 //
322
5e64ce0d 323 Int_t result;
324
170c35f1 325 rawReader->Select("TRD");
5e64ce0d 326
327 AliTRDrawStreamBase *pstream = AliTRDrawStreamBase::GetRawStream(rawReader);
328
329 result = ProcessEvent(pstream, nocheck);
330
331 delete pstream;
170c35f1 332
5e64ce0d 333 return result;
170c35f1 334}
3a0f6479 335
170c35f1 336//_________________________________________________________________________
3a0f6479 337Int_t AliTRDCalibPadStatus::ProcessEvent(
170c35f1 338#ifdef ALI_DATE
cf46274d 339 eventHeaderStruct *event,
340 Bool_t nocheck
170c35f1 341#else
cf46274d 342 eventHeaderStruct* /*event*/,
343 Bool_t /*nocheck*/
170c35f1 344
345#endif
3a433fc4 346 )
170c35f1 347{
348 //
349 // process date event
350 //
351#ifdef ALI_DATE
352 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
cf46274d 353 Bool_t result=ProcessEvent(rawReader, nocheck);
170c35f1 354 delete rawReader;
355 return result;
356#else
357 Fatal("AliTRDCalibPadStatus", "this class was compiled without DATE");
358 return 0;
359#endif
360
361}
3a0f6479 362
170c35f1 363//_____________________________________________________________________
d95484e4 364Bool_t AliTRDCalibPadStatus::TestEventHisto(Int_t nevent, Int_t sm, Int_t ch) /*FOLD00*/
170c35f1 365{
366 //
367 // Test event loop
368 // fill one oroc and one iroc with random gaus
369 //
370
170c35f1 371 gRandom->SetSeed(0);
372
289cc637 373 for (Int_t ism=sm; ism<sm+1; ism++){
d95484e4 374 for (Int_t ich=ch; ich < ch+1; ich++){
170c35f1 375 for (Int_t ipl=0; ipl < 6; ipl++){
f162af62 376 for(Int_t irow = 0; irow < fGeo->GetRowMax(ipl,ich,ism); irow++){
377 for(Int_t icol = 0; icol < fGeo->GetColMax(ipl); icol++){
170c35f1 378 for (Int_t iTimeBin=0; iTimeBin<(30*nevent); iTimeBin++){
d95484e4 379 Int_t signal=TMath::Nint(gRandom->Gaus(10,1.5));
e4db522f 380 if ( signal>0 )UpdateHisto((ipl+ich*6+ism*6*5),irow,icol,signal,fGeo->GetRowMax(ipl,ich,ism),0,0);
170c35f1 381 }
382 }
383 }
384 }
385 }
386 }
387 return kTRUE;
388}
3a0f6479 389
170c35f1 390//_____________________________________________________________________
391TH2F* AliTRDCalibPadStatus::GetHisto(Int_t det, TObjArray *arr, /*FOLD00*/
392 Int_t nbinsY, Float_t ymin, Float_t ymax,
393 Char_t *type, Bool_t force)
394{
395 //
396 // return pointer to histogram
397 // if force is true create a new histogram if it doesn't exist allready
398 //
399 if ( !force || arr->UncheckedAt(det) )
400 return (TH2F*)arr->UncheckedAt(det);
401
402 // if we are forced and histogram doesn't yes exist create it
403 Char_t name[255], title[255];
404
37b0cf5e 405 sprintf(name,"hCalib%s%.3d",type,det);
170c35f1 406 sprintf(title,"%s calibration histogram detector %.2d;ADC channel;Channel (pad)",type,det);
407
3a0f6479 408
053767a4 409 Int_t nbchannels = fGeo->GetRowMax(GetLayer(det),GetStack(det),GetSector(det))*fGeo->GetColMax(GetLayer(det));
e4db522f 410
411 // we will add 3*8*rowMax channels at the end for the double counted
053767a4 412 nbchannels += 3*8*(fGeo->GetRowMax(GetLayer(det),GetStack(det),GetSector(det)));
e4db522f 413
170c35f1 414
415 // new histogram with calib information. One value for each pad!
416 TH2F* hist = new TH2F(name,title,
417 nbinsY, ymin, ymax,
418 nbchannels,0,nbchannels
419 );
420 hist->SetDirectory(0);
421 arr->AddAt(hist,det);
422 return hist;
423}
3a0f6479 424
170c35f1 425//_____________________________________________________________________
426TH2F* AliTRDCalibPadStatus::GetHisto(Int_t det, Bool_t force) /*FOLD00*/
427{
428 //
429 // return pointer to histogram
430 // if force is true create a new histogram if it doesn't exist allready
431 //
432 TObjArray *arr = &fHistoArray;
d95484e4 433 return GetHisto(det, arr, fAdcMax-fAdcMin, fAdcMin-0.5, fAdcMax-0.5, "Pedestal", force);
170c35f1 434}
3a0f6479 435
170c35f1 436//_____________________________________________________________________
cf46274d 437AliTRDCalROC* AliTRDCalibPadStatus::GetCalRoc(Int_t det, TObjArray* arr, Bool_t force) /*FOLD00*/
170c35f1 438{
439 //
440 // return pointer to ROC Calibration
441 // if force is true create a new AliTRDCalROC if it doesn't exist allready
442 //
443 if ( !force || arr->UncheckedAt(det) )
444 return (AliTRDCalROC*)arr->UncheckedAt(det);
445
446 // if we are forced and histogram doesn't yes exist create it
447
448 // new AliTRDCalROC. One value for each pad!
053767a4 449 AliTRDCalROC *croc = new AliTRDCalROC(GetLayer(det),GetStack(det));
170c35f1 450 arr->AddAt(croc,det);
451 return croc;
452}
453//_____________________________________________________________________
e4db522f 454AliTRDCalROC* AliTRDCalibPadStatus::GetCalRocMean(Int_t det, Bool_t force) /*FOLD00*/
170c35f1 455{
456 //
457 // return pointer to Carge ROC Calibration
458 // if force is true create a new histogram if it doesn't exist allready
459 //
e4db522f 460 TObjArray *arr = &fCalRocArrayMean;
461 return GetCalRoc(det, arr, force);
170c35f1 462}
3a0f6479 463
170c35f1 464//_____________________________________________________________________
e4db522f 465AliTRDCalROC* AliTRDCalibPadStatus::GetCalRocRMS(Int_t det, Bool_t force) /*FOLD00*/
170c35f1 466{
467 //
468 // return pointer to Carge ROC Calibration
469 // if force is true create a new histogram if it doesn't exist allready
470 //
e4db522f 471 TObjArray *arr = &fCalRocArrayRMS;
472 return GetCalRoc(det, arr, force);
170c35f1 473}
474//_____________________________________________________________________
e4db522f 475AliTRDCalROC* AliTRDCalibPadStatus::GetCalRocMeand(Int_t det, Bool_t force) /*FOLD00*/
170c35f1 476{
477 //
478 // return pointer to Carge ROC Calibration
479 // if force is true create a new histogram if it doesn't exist allready
480 //
e4db522f 481 TObjArray *arr = &fCalRocArrayMeand;
cf46274d 482 return GetCalRoc(det, arr, force);
170c35f1 483}
3a0f6479 484
170c35f1 485//_____________________________________________________________________
e4db522f 486AliTRDCalROC* AliTRDCalibPadStatus::GetCalRocRMSd(Int_t det, Bool_t force) /*FOLD00*/
170c35f1 487{
488 //
489 // return pointer to Carge ROC Calibration
490 // if force is true create a new histogram if it doesn't exist allready
491 //
e4db522f 492 TObjArray *arr = &fCalRocArrayRMSd;
cf46274d 493 return GetCalRoc(det, arr, force);
170c35f1 494}
3a0f6479 495
170c35f1 496//_____________________________________________________________________
497void AliTRDCalibPadStatus::AnalyseHisto() /*FOLD00*/
498{
499 //
500 // Calculate calibration constants
501 //
502
503 Int_t nbinsAdc = fAdcMax-fAdcMin;
504
d95484e4 505 TVectorD param(4);
170c35f1 506 TMatrixD dummy(3,3);
507
0bc7827a 508 Float_t *arrayHP=0;
170c35f1 509
510
511 for (Int_t idet=0; idet<540; idet++){
512 TH2F *hP = GetHisto(idet);
513 if ( !hP ) {
514 continue;
515 }
516
d95484e4 517 //printf("Entries for %d\n",idet);
518
170c35f1 519 AliTRDCalROC *rocMean = GetCalRocMean(idet,kTRUE);
520 AliTRDCalROC *rocRMS = GetCalRocRMS(idet,kTRUE);
521
0bc7827a 522 arrayHP = hP->GetArray();
170c35f1 523 Int_t nChannels = rocMean->GetNchannels();
524
525 for (Int_t iChannel=0; iChannel<nChannels; iChannel++){
526 Int_t offset = (nbinsAdc+2)*(iChannel+1)+1;
d95484e4 527 Double_t ret = AliMathBase::FitGaus(arrayHP+offset,nbinsAdc,fAdcMin-0.5,fAdcMax-0.5,&param,&dummy);
528 // if the fitting failed set noise and pedestal to 0
6ace5fe2 529 if ((ret==-4) || (ret==-1) || (ret==-2)) {
170c35f1 530 param[1]=0.0;
531 param[2]=0.0;
532 }
533 if((param[1]/10.0) > 65534.0) param[1] = 0.0;
534 if((param[2]/10.0) > 65534.0) param[2] = 0.0;
535 rocMean->SetValue(iChannel,param[1]/10.0);
536 rocRMS->SetValue(iChannel,param[2]/10.0);
537 }
e4db522f 538
539 // here we analyse doubled read channels
540
541 AliTRDCalROC *rocMeand = GetCalRocMeand(idet,kTRUE);
542 AliTRDCalROC *rocRMSd = GetCalRocRMSd(idet,kTRUE);
543
544 Int_t nrows = rocMeand->GetNrows();
545 Int_t shift = 144*nrows;
546 Int_t total = shift+3*8*nrows;
547
548 for (Int_t iChannel=shift; iChannel<total; iChannel++){
549 Int_t offset = (nbinsAdc+2)*(iChannel+1)+1;
d95484e4 550 Double_t ret = AliMathBase::FitGaus(arrayHP+offset,nbinsAdc,fAdcMin-0.5,fAdcMax-0.5,&param,&dummy);
e4db522f 551 // if the fitting failed set noise and pedestal to 0
552 if ((ret==-4) || (ret==-1) || (ret==-2)) {
553 param[1]=0.0;
554 param[2]=0.0;
555 }
556 if((param[1]/10.0) > 65534.0) param[1] = 0.0;
557 if((param[2]/10.0) > 65534.0) param[2] = 0.0;
558
559 // here we have to recalculate backward
560 Int_t nb = iChannel-shift;
561 Int_t row = nb%nrows;
562 Int_t j = (Int_t)(nb/nrows);
563 Int_t imcm = j%8;
564 Int_t icol = (Int_t)(j/8);
565
566 Int_t finalcol = 18*imcm;
567 if(icol > 0) icol += 17;
568 else icol = -1;
569 finalcol += icol;
570
571 Int_t channel = row+finalcol*nrows;
572
573 //printf("iChannel %d, nrows %d, finalcol %d, row %d, channel %d\n",iChannel,nrows,finalcol,row,channel);
574 if((finalcol < 0) || (finalcol >= 144)) continue;
575
576 rocMeand->SetValue(channel,param[1]/10.0);
577 rocRMSd->SetValue(channel,param[2]/10.0);
578 }
579
170c35f1 580 }
e4db522f 581
170c35f1 582}
3a0f6479 583
170c35f1 584//_______________________________________________________________________________________
585AliTRDCalPadStatus* AliTRDCalibPadStatus::CreateCalPadStatus()
586{
587 //
6ace5fe2 588 // Create Pad Status out of Mean and RMS values
37b0cf5e 589 // The chamber without data are masked, this is the corrected in the preprocessor
170c35f1 590 //
591
592 AliTRDCalPadStatus* obj = new AliTRDCalPadStatus("padstatus", "padstatus");
593
594 for (Int_t idet=0; idet<540; ++idet)
595 {
596 AliTRDCalSingleChamberStatus *calROC = obj->GetCalROC(idet);
597
e4db522f 598
37b0cf5e 599 if ( !GetCalRocMean(idet)) {
170c35f1 600 for(Int_t k = 0; k < calROC->GetNchannels(); k++){
37b0cf5e 601 calROC->SetStatus(k,AliTRDCalPadStatus::kNotConnected);
170c35f1 602 }
170c35f1 603 continue;
604 }
6ace5fe2 605
37b0cf5e 606
607 //Take the stuff
608 AliTRDCalROC *calRocMean = new AliTRDCalROC(*( (AliTRDCalROC *) GetCalRocMean(idet)));
609 AliTRDCalROC *calRocRMS = new AliTRDCalROC(*( (AliTRDCalROC *) GetCalRocRMS(idet)));
610
611 //Take the stuff second chance
612 AliTRDCalROC *calRocMeand = new AliTRDCalROC(*( (AliTRDCalROC *) GetCalRocMeand(idet)));
613 AliTRDCalROC *calRocRMSd = new AliTRDCalROC(*( (AliTRDCalROC *) GetCalRocRMSd(idet)));
614
615 calRocRMS->Unfold();
616 calRocRMSd->Unfold();
617
618
170c35f1 619 //Range
37b0cf5e 620 Int_t row = calROC->GetNrows();
621 Int_t col = calROC->GetNcols();
6ace5fe2 622
623 Double_t rmsmean = calRocMean->GetRMS()*10.0;
624 Double_t meanmean = calRocMean->GetMean()*10.0;
37b0cf5e 625 Double_t meansquares = calRocRMS->GetMean();
170c35f1 626
37b0cf5e 627
628 for(Int_t irow = 0; irow < row; irow++){
170c35f1 629
37b0cf5e 630 // for bridged pads
631 Float_t meanprevious = 0.0;
632 Float_t rmsprevious = 0.0;
633 Float_t mean = 0.0;
634 Float_t rms = 0.0;
6ace5fe2 635
37b0cf5e 636 for(Int_t icol = 0; icol < col; icol++){
637
638 mean = calRocMean->GetValue(icol,irow)*10.0;
639 rms = calRocRMS->GetValue(icol,irow);
640
641 if(icol > 0) {
642 meanprevious = calRocMean->GetValue((icol -1),irow)*10.0;
643 rmsprevious = calRocRMS->GetValue((icol - 1),irow);
644 }
645
646 Bool_t pb = kFALSE;
647 // masked if two noisy
648 if((rms <= 0.0001) || (TMath::Abs(mean-meanmean)>(5*rmsmean)) || (TMath::Abs(rms)>(5.0*TMath::Abs(meansquares)))) {
649
650 pb = kTRUE;
651 // look at second chance
652 Float_t meand = calRocMeand->GetValue(icol,irow)*10.0;
653 Float_t rmsd = calRocRMSd->GetValue(icol,irow);
654
655 if((rmsd <= 0.0001) || (TMath::Abs(meand-meanmean)>(5*rmsmean)) || (TMath::Abs(rmsd)>(5.0*TMath::Abs(meansquares)))) {
656 if((rmsd <= 0.0001) && (rms <= 0.0001)) {
657 calROC->SetStatus(icol,irow,AliTRDCalPadStatus::kNotConnected);
658 }
659 else {
660 calROC->SetStatus(icol, irow, AliTRDCalPadStatus::kMasked);
661 }
662 }
663 else {
664 calROC->SetStatus(icol, irow, AliTRDCalPadStatus::kReadSecond);
665 }
666 }
e4db522f 667
37b0cf5e 668
669 // bridge if previous pad found something
670 if(!pb) {
671 if((meanprevious == mean) && (rmsprevious == rms) && (mean > 0.0001)) {
672 //printf("mean previous %f, mean %f, rms %f, rmsprevious %f, col %d\n",meanprevious,mean,rms,rmsprevious,icol);
673 calROC->SetStatus(icol -1 ,irow, AliTRDCalPadStatus::kPadBridgedRight);
674 calROC->SetStatus(icol ,irow, AliTRDCalPadStatus::kPadBridgedLeft);
675 }
e4db522f 676 }
37b0cf5e 677
e4db522f 678 }
6ace5fe2 679 }
37b0cf5e 680
681 delete calRocMean;
682 delete calRocRMS;
683 delete calRocMeand;
684 delete calRocRMSd;
685
686
170c35f1 687 }
688
689 return obj;
690
691}
289cc637 692//_______________________________________________________________________________________
693AliTRDCalPad* AliTRDCalibPadStatus::CreateCalPad()
694{
695 //
696 // Create Pad Noise out of RMS values
697 //
698
699 AliTRDCalPad* obj = new AliTRDCalPad("PadNoise", "PadNoise");
700
701
702 for (Int_t det=0; det<AliTRDgeometry::kNdet; ++det) {
703
704 AliTRDCalROC *calROC22 = obj->GetCalROC(det);
705
706 AliTRDCalROC *calRocRMS = ((AliTRDCalROC *)GetCalRocRMS(det,kTRUE));
707
708 for(Int_t k = 0; k < calROC22->GetNchannels(); k++){
709 calROC22->SetValue(k,calRocRMS->GetValue(k));
710 }
711
712 }
713
714 return obj;
715
716}
717
718//_______________________________________________________________________________________
0bc7827a 719AliTRDCalDet* AliTRDCalibPadStatus::CreateCalDet() const
289cc637 720{
721 //
722 // Create Det Noise correction factor
723 //
724
725 AliTRDCalDet* obj = new AliTRDCalDet("DetNoise", "DetNoise (correction factor)");
726
727 for(Int_t l = 0; l < 540; l++){
728 obj->SetValue(l,10.0);
729 }
730
731 return obj;
732
733}
734
170c35f1 735//_____________________________________________________________________
736void AliTRDCalibPadStatus::DumpToFile(const Char_t *filename, const Char_t *dir, Bool_t append) /*FOLD00*/
737{
738 //
739 // Write class to file
740 //
741
742 TString sDir(dir);
743 TString option;
744
745 if ( append )
746 option = "update";
747 else
748 option = "recreate";
749
750 TDirectory *backup = gDirectory;
751 TFile f(filename,option.Data());
752 f.cd();
753 if ( !sDir.IsNull() ){
754 f.mkdir(sDir.Data());
755 f.cd(sDir);
756 }
757 this->Write();
758 f.Close();
759
760 if ( backup ) backup->cd();
3a0f6479 761}
762
6ace5fe2 763//_____________________________________________________________________
764void AliTRDCalibPadStatus::SetCalRocMean(AliTRDCalROC *mean, Int_t det) /*FOLD00*/
765{
766 //
767 // Put the AliTRDCalROC in the array fCalRocArrayMean
768 //
769
770
771 AliTRDCalROC *rocMean = GetCalRocMean(det,kTRUE);
772
773 Int_t nChannels = rocMean->GetNchannels();
774
775 for (Int_t iChannel=0; iChannel<nChannels; iChannel++){
776
777 rocMean->SetValue(iChannel,mean->GetValue(iChannel));
778
779 }
780
781}
782
783//_____________________________________________________________________
784void AliTRDCalibPadStatus::SetCalRocRMS(AliTRDCalROC *rms, Int_t det) /*FOLD00*/
785{
786 //
787 // Put the AliTRDCalROC in the array fCalRocArrayRMS
788 //
789
790
791 AliTRDCalROC *rocRms = GetCalRocRMS(det,kTRUE);
792
793 Int_t nChannels = rocRms->GetNchannels();
794
795 for (Int_t iChannel=0; iChannel<nChannels; iChannel++){
796
797 rocRms->SetValue(iChannel,rms->GetValue(iChannel));
798
799 }
800
801}
e4db522f 802//_____________________________________________________________________
803void AliTRDCalibPadStatus::SetCalRocMeand(AliTRDCalROC *mean, Int_t det) /*FOLD00*/
804{
805 //
806 // Put the AliTRDCalROC in the array fCalRocArrayMean
807 //
6ace5fe2 808
e4db522f 809
810 AliTRDCalROC *rocMean = GetCalRocMeand(det,kTRUE);
811
812 Int_t nChannels = rocMean->GetNchannels();
813
814 for (Int_t iChannel=0; iChannel<nChannels; iChannel++){
815
816 rocMean->SetValue(iChannel,mean->GetValue(iChannel));
817
818 }
819
820}
821
822//_____________________________________________________________________
823void AliTRDCalibPadStatus::SetCalRocRMSd(AliTRDCalROC *rms, Int_t det) /*FOLD00*/
824{
825 //
826 // Put the AliTRDCalROC in the array fCalRocArrayRMS
827 //
828
829
830 AliTRDCalROC *rocRms = GetCalRocRMSd(det,kTRUE);
831
832 Int_t nChannels = rocRms->GetNchannels();
833
834 for (Int_t iChannel=0; iChannel<nChannels; iChannel++){
835
836 rocRms->SetValue(iChannel,rms->GetValue(iChannel));
837
838 }
839
840}
3a0f6479 841//_____________________________________________________________________________
053767a4 842Int_t AliTRDCalibPadStatus::GetLayer(Int_t d) const
170c35f1 843{
844 //
053767a4 845 // Reconstruct the layer number from the detector number
170c35f1 846 //
847
848 return ((Int_t) (d % 6));
849
850}
851
852//_____________________________________________________________________________
053767a4 853Int_t AliTRDCalibPadStatus::GetStack(Int_t d) const
170c35f1 854{
855 //
856 // Reconstruct the chamber number from the detector number
857 //
858
859 return ((Int_t) (d % 30) / 6);
860
861}
3a0f6479 862
170c35f1 863//_____________________________________________________________________________
864Int_t AliTRDCalibPadStatus::GetSector(Int_t d) const
865{
866 //
867 // Reconstruct the sector number from the detector number
868 //
869
870 return ((Int_t) (d / 30));
871
872}
873
874