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