1 // **************************************************************************
2 // * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 // * Author: The ALICE Off-line Project. *
5 // * Contributors are mentioned in the code where appropriate. *
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 // **************************************************************************
16 #include "AliHMPIDCalib.h" //class header
17 #include "AliHMPIDParam.h" //class header
18 #include "AliHMPIDRawStream.h" //class header
24 ClassImp(AliHMPIDCalib)
27 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28 AliHMPIDCalib::AliHMPIDCalib():
51 faddl = new Bool_t[AliHMPIDRawStream::kNDDL];
52 Int_t nPads = (AliHMPIDParam::kMaxCh+1)*(AliHMPIDParam::kMaxPcx+1)*(AliHMPIDParam::kMaxPcy+1);
54 fpedQ0 = new Int_t***[AliHMPIDRawStream::kNDDL+1];
55 fsq2 = new Float_t ***[AliHMPIDRawStream::kNDDL+1];
56 fsq = new Float_t ***[AliHMPIDRawStream::kNDDL+1];
57 fnpc = new Int_t ***[AliHMPIDRawStream::kNDDL+1];
58 fErr = new Int_t*[AliHMPIDRawStream::kNDDL+1];
60 fnDDLInStream = new Int_t[AliHMPIDRawStream::kNDDL+1];
61 fnDDLOutStream = new Int_t[AliHMPIDRawStream::kNDDL+1];
64 for(Int_t iDDL=0;iDDL<AliHMPIDRawStream::kNDDL+1;iDDL++) {
66 fErr[iDDL] = new Int_t[AliHMPIDRawStream::kSumErr+1];
67 fpedQ0[iDDL] = new Int_t**[AliHMPIDRawStream::kNRows+1];
68 fsq[iDDL] = new Float_t**[AliHMPIDRawStream::kNRows+1];
69 fsq2[iDDL] = new Float_t**[AliHMPIDRawStream::kNRows+1];
70 fnpc[iDDL] = new Int_t**[AliHMPIDRawStream::kNRows+1];
72 for(Int_t iRow=0;iRow<AliHMPIDRawStream::kNRows+1;iRow++) {
74 fpedQ0[iDDL][iRow] = new Int_t*[AliHMPIDRawStream::kNDILOGICAdd+1];
75 fsq[iDDL][iRow] = new Float_t*[AliHMPIDRawStream::kNDILOGICAdd+1];
76 fsq2[iDDL][iRow] = new Float_t*[AliHMPIDRawStream::kNDILOGICAdd+1];
77 fnpc[iDDL][iRow] = new Int_t*[AliHMPIDRawStream::kNDILOGICAdd+1];
79 for(Int_t iDil=1;iDil<AliHMPIDRawStream::kNDILOGICAdd+1;iDil++){
81 fpedQ0[iDDL][iRow][iDil] = new Int_t[AliHMPIDRawStream::kNPadAdd+1];
82 fsq2[iDDL][iRow][iDil] = new Float_t[AliHMPIDRawStream::kNPadAdd+1];
83 fsq[iDDL][iRow][iDil] = new Float_t[AliHMPIDRawStream::kNPadAdd+1];
84 fnpc[iDDL][iRow][iDil] = new Int_t[AliHMPIDRawStream::kNPadAdd+1];
89 for(Int_t iDDL=0;iDDL<AliHMPIDRawStream::kNDDL+1;iDDL++) {
91 fnDDLInStream[iDDL]=-1;
92 fnDDLOutStream[iDDL]=-1;
94 for(Int_t iErr=0;iErr<AliHMPIDRawStream::kSumErr+1;iErr++) {fErr[iDDL][iErr]=0;}
96 for(Int_t iRow=0;iRow<AliHMPIDRawStream::kNRows+1;iRow++) {
97 for(Int_t iDil=1;iDil<AliHMPIDRawStream::kNDILOGICAdd+1;iDil++) {
98 for(Int_t iPad=1;iPad<AliHMPIDRawStream::kNPadAdd+1;iPad++) {
99 fpedQ0[iDDL][iRow][iDil][iPad]=0;
100 fsq[iDDL][iRow][iDil][iPad]=0;
101 fsq2[iDDL][iRow][iDil][iPad]=0;
102 fnpc[iDDL][iRow][iDil][iPad]=0;
108 fPadAdc=new TH1I*[nPads];
109 fIsPad=new Bool_t[nPads];
110 for(Int_t np=0;np<nPads;np++) {fPadAdc[np]=0x0; fIsPad[np]=kFALSE;}
116 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
117 AliHMPIDCalib::~AliHMPIDCalib()
122 if (faddl) { delete [] faddl; faddl = 0x0; }
123 if (fPadAdc) { delete [] fPadAdc; fPadAdc=0x0; }
124 if (fIsPad) { delete [] fIsPad; fIsPad=0x0; }
125 if (fFile) { delete fFile; fFile=0x0; }
127 for(Int_t iErr=0;iErr<AliHMPIDRawStream::kSumErr+1;iErr++) { delete [] fErr[iErr];} delete [] fErr;
129 for(Int_t iDDL=0; iDDL< AliHMPIDRawStream::kNDDL; iDDL++)
130 for(Int_t iRow=0;iRow<AliHMPIDRawStream::kNRows+1;iRow++)
131 for(Int_t iDil=1;iDil<AliHMPIDRawStream::kNDILOGICAdd+1;iDil++)
133 delete [] fpedQ0[iDDL][iRow][iDil]; //del iPad
134 delete [] fsq[iDDL][iRow][iDil]; //del iPad
135 delete [] fsq2[iDDL][iRow][iDil]; //del iPad
136 delete [] fnpc[iDDL][iRow][iDil]; //del iPad
138 for(Int_t iDDL=0; iDDL< AliHMPIDRawStream::kNDDL; iDDL++)
139 for(Int_t iRow=0;iRow<AliHMPIDRawStream::kNRows+1;iRow++)
141 delete [] fpedQ0[iDDL][iRow]; //del iRow
142 delete [] fsq[iDDL][iRow]; //del iRow
143 delete [] fsq2[iDDL][iRow]; //del iRow
144 delete [] fnpc[iDDL][iRow]; //del iRow
147 for(Int_t iDDL=0; iDDL< AliHMPIDRawStream::kNDDL; iDDL++)
149 delete [] fpedQ0[iDDL]; //del iRow
150 delete [] fsq2[iDDL]; //del iRow
151 delete [] fsq[iDDL]; //del iRow
152 delete [] fnpc[iDDL]; //del iRow
173 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
174 void AliHMPIDCalib::Init()
182 for(Int_t iDDL=0; iDDL< AliHMPIDRawStream::kNDDL; iDDL++)
184 for(Int_t ierr=0; ierr <AliHMPIDRawStream::kSumErr ; ierr++) {
191 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
192 void AliHMPIDCalib::SetRunParams(ULong_t runNum,Int_t timeStamp, Int_t ldcId)
195 //Set run parameters for the Pedestal and Error Files
196 //Arguments: run number, time stamp and LDC Id
199 fRunNum=(Int_t)runNum;
200 fTimeStamp=timeStamp;
203 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
204 void AliHMPIDCalib::SetSigCutFromFile(Char_t* name)
207 //Set Sigma Cut from the file on the LDC, if the input file is not present default value is set!
208 //Arguments: the name of the SigmaCut file on the LDC
212 ifstream infile(name);
213 if(!infile.is_open()) {fSigCut=3; return;}
220 }//SetSigCutFromFile()
221 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
222 void AliHMPIDCalib::InitHisto(Int_t q,Int_t histocnt,Char_t* name)
225 //Init the pad histos. For one DDL we have 11520 pads. ONLY if ENABLED!
226 //Arguments: q-charge, the absolute number of the histogram (AliHMPIDParam::kMaxCh+1)*(AliHMPIDParam::kMaxPcx+1)*(AliHMPIDParam::kMaxPcy+1) and the name of the histogram (unique)
229 if(fWritePads==kFALSE) return;
231 Double_t lowbin,highbin=0;
232 lowbin=q-40.5; highbin=q+40.5;
234 if(fIsPad[histocnt]==kTRUE) return;
236 if(fLargeHisto==kFALSE) fPadAdc[histocnt]=new TH1I(name,name,81,lowbin,highbin);
237 if(fLargeHisto==kTRUE) fPadAdc[histocnt]=new TH1I(name,name,4093,-0.5,4092.5);
238 fPadAdc[histocnt]->Sumw2();
239 fIsPad[histocnt]=kTRUE;
242 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
243 void AliHMPIDCalib::FillHisto(Int_t histocnt,Int_t q)
246 //Fill the ADC histograms for each pad
247 //Arguments: q-charge, the absolute number of the histogram (AliHMPIDParam::kMaxCh+1)*(AliHMPIDParam::kMaxPcx+1)*(AliHMPIDParam::kMaxPcy+1)
250 if(fIsPad[histocnt]==kFALSE) return;
252 fPadAdc[histocnt]->Fill(q);
255 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
256 void AliHMPIDCalib::InitFile(Int_t inVal)
259 //Initialize the ADC histo output file (one per LDC)
263 if(fWritePads==kFALSE ) return;
264 if(fLargeHisto==kFALSE) fFile=new TFile(Form("HmpidPadsOnLdc%2d.root",inVal),"RECREATE");
265 if(fLargeHisto==kTRUE) fFile=new TFile(Form("Run%d_DDL%d.root",inVal,fSelectDDL),"RECREATE");
268 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
269 void AliHMPIDCalib::CloseFile()
272 //Close the ADC histo output file (one per LDC)
277 Int_t nPads = (AliHMPIDParam::kMaxCh+1)*(AliHMPIDParam::kMaxPcx+1)*(AliHMPIDParam::kMaxPcy+1);
278 for(Int_t np=0;np<nPads;np++) {if(fIsPad[np]==kTRUE) fPadAdc[np]->Write();}
281 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
282 void AliHMPIDCalib::FillPedestal(Int_t abspad,Int_t q)
285 //Called from the HMPIDda and fills the pedestal values
286 //Arguments: absulote pad number as from AliHMPIDParam and q-charge
289 if(q<0) AliFatal("Negative charge is read!!!!!!");
291 Int_t nDDL=0, row=0, dil=0, adr=0;
292 //The decoding (abs. pad -> ddl,dil,...) is the same as in AliHMPIDDigit::Raw
293 Int_t y2a[6]={5,3,1,0,2,4};
295 nDDL= 2*AliHMPIDParam::A2C(abspad)+AliHMPIDParam::A2P(abspad)%2; //DDL# 0..13
296 Int_t tmp= 1+AliHMPIDParam::A2P(abspad)/2*8+AliHMPIDParam::A2Y(abspad)/6; //temp variable
297 row= (AliHMPIDParam::A2P(abspad)%2)? tmp:25-tmp; //row r=1..24
298 dil= 1+AliHMPIDParam::A2X(abspad)/8; //DILOGIC
299 adr=y2a[AliHMPIDParam::A2Y(abspad)%6]+6*(AliHMPIDParam::A2X(abspad)%8); //ADDRESS 0..47
300 //........... decoding done
302 // if(row<1 || row > 24 || nDDL < 0 || nDDL > 13 || dil < 1 || dil > 10 || adr < 0 || adr >47) AliFatal(Form("ddl %d row %d dil %d adr %d",nDDL,row,dil,adr));
307 fsq[nDDL][row][dil][adr]+=q;
308 fsq2[nDDL][row][dil][adr]+=q*q;
309 fnpc[nDDL][row][dil][adr]++; //Count how many times the pad is good (can be different from the good DDL count)
314 fpedQ0[nDDL][row][dil][adr]++; //Count how many times a pad charge is zero
317 Int_t histocnt=0; histocnt=(nDDL)*11520+(row-1)*480+(dil-1)*48+adr; //Histo counter for a single DDL
319 if(fWritePads==kTRUE) //works but make it nicer later....
321 if( fLargeHisto==kTRUE && nDDL==fSelectDDL) {
322 InitHisto(q,histocnt,Form("hDDL_%d_Row_%d_Dil_%d_Pad_%d",nDDL,row,dil,adr)); //for large histos use hardware naming
323 FillHisto(histocnt,q);
325 if(fLargeHisto==kFALSE)
327 InitHisto(q,histocnt,Form("hPad_Ch_%d_Pc_%d_Px_%d_Py_%d",AliHMPIDParam::A2C(abspad),AliHMPIDParam::A2P(abspad),AliHMPIDParam::A2X(abspad),AliHMPIDParam::A2Y(abspad)));
328 FillHisto(histocnt,q);
333 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
334 void AliHMPIDCalib::FillErrors(Int_t nDDL,Int_t eType, Int_t nErr)
337 //Fill decoding errors from AliHMPIDRawStream
338 //Arguments: nDDL-DDL number, eType- error type as in AliHMPIDRawStream.h and the # of occurence for eType
342 if(eType < 0 || eType> AliHMPIDRawStream::kSumErr ) return;
343 fErr[nDDL][eType]=fErr[nDDL][eType]+nErr;
347 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
348 void AliHMPIDCalib::FillDDLCnt(Int_t iddl,Int_t inDDL, Int_t outDDL)
351 //Fill decoding DDL check from RawStream
352 //Arguments: iddl - DDL under setting, inDDL- How many times the DDL is present in the raw stream, outDDL - How many time sthe DDL is succesfylly decoded
356 if(inDDL==-1) return;
357 if(fnDDLInStream[iddl]==-1) {fnDDLInStream[iddl]=0; fnDDLOutStream[iddl]=0;}
358 fnDDLInStream[iddl]+=inDDL;
359 fnDDLOutStream[iddl]+=outDDL;
363 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
364 Bool_t AliHMPIDCalib::WriteErrors(Int_t nDDL, Char_t* name, Int_t nEv)
367 //Write decoding errors to a txt file
368 //Arguments: nDDL-DDL number, name of the error file and number of the read events
369 //Retutns: kTRUE/kFALSE
372 if(faddl[nDDL]==kFALSE) return kFALSE; //if ddl is missing no error file is created
373 ofstream outerr; outerr.open(name); //open error file
374 outerr << Form("%8s %2d\n","RunNumber",(Int_t)fRunNum); //read run number
375 outerr << Form("%8s %2d\n","LdcId" , fLdcId); //read LDC Id
376 outerr << Form("%8s %2d\n","TimeStamp", fTimeStamp); //read time stamp
377 outerr << Form("%8s %2d\n","TotNumEvt", nEv); //read number of total events processed
378 outerr << Form("%8s %2d\n","TotDDLEvt", fnDDLInStream[nDDL]); //read number of bad events for DDL # nDDL processed
379 outerr << Form("%8s %2d\n","NumBadEvt", fnDDLInStream[nDDL]-fnDDLOutStream[nDDL]); //read number of bad events for DDL # nDDL processed
380 outerr << Form("%8s %2.2f\n","NBadE(%)", (fnDDLInStream[nDDL]-fnDDLOutStream[nDDL])*100.0/nEv); //read number of bad events (in %) for DDL # nDDL processed
382 for(Int_t ierr=0; ierr <AliHMPIDRawStream::kSumErr; ierr++) outerr << Form("%2d\t",fErr[nDDL][ierr]); //write errors
383 outerr << Form("\n"); //last break
384 /* write out pads with 0 charge read */
385 for(Int_t row = 1; row <= AliHMPIDRawStream::kNRows; row++){
386 for(Int_t dil = 1; dil <= AliHMPIDRawStream::kNDILOGICAdd; dil++){
387 for(Int_t pad = 0; pad < AliHMPIDRawStream::kNPadAdd; pad++){
388 if(fpedQ0[nDDL][row][dil][pad]>0) outerr<< Form("%2d %2d %2d %3d\n",row,dil,pad,fpedQ0[nDDL][row][dil][pad]);
394 outerr.close(); //write error file
398 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
399 Bool_t AliHMPIDCalib::CalcPedestal(Int_t nDDL, Char_t* name, Int_t nEv)
402 //Calculate pedestal for each pad
403 //Arguments: nDDL-DDL number, name of the pedestal file and number of the read events
404 //Retutns: kTRUE/kFALSE
408 if(faddl[nDDL]==kFALSE) return kFALSE; //if ddl is missing no ped file is created (and also for LDC selection). Check with Paolo what he checks for?!
409 Double_t mean=0,sigma=0;
410 Double_t qs2m=0,qsm2=0;
411 ofstream out; //to write the pedestal text files
415 out << Form("%8s %2d\n","RunNumber",(Int_t)fRunNum); //read run number
416 out << Form("%8s %2d\n","LdcId" , fLdcId); //read LDC Id
417 out << Form("%8s %2d\n","TimeStamp", fTimeStamp); //read time stamp
418 out << Form("%8s %2d\n","TotNumEvt", nEv); //read number of total events processed
419 out << Form("%8s %2d\n","TotDDLEvt", fnDDLInStream[nDDL]); //read number of bad events for DDL # nDDL processed
420 out << Form("%8s %2d\n","NumBadEvt", fnDDLInStream[nDDL]-fnDDLOutStream[nDDL]); //read number of bad events for DDL # nDDL processed
421 out << Form("%8s %2f\n","NBadE(%)", (fnDDLInStream[nDDL]-fnDDLOutStream[nDDL])*100.0/nEv); //read number of bad events (in %) for DDL # nDDL processed
422 out << Form("%8s %2.2d\n","#SigCut", fSigCut); //# of sigma cuts
424 for(Int_t row = 1; row <= AliHMPIDRawStream::kNRows; row++){
425 for(Int_t dil = 1; dil <= AliHMPIDRawStream::kNDILOGICAdd; dil++){
426 for(Int_t pad = 0; pad < AliHMPIDRawStream::kNPadAdd; pad++){
428 mean = 50;sigma = 100;
430 nEvPerPad=fnpc[nDDL][row][dil][pad];
433 if(nEvPerPad < 1 ) { //if the pad is bad then we assign 100 for the sigma and 50 for the mean
438 mean = fsq[nDDL][row][dil][pad]*1.0/nEvPerPad;
439 qs2m = fsq2[nDDL][row][dil][pad]*1.0/nEvPerPad;
440 qsm2 = TMath::Power(fsq[nDDL][row][dil][pad]*1.0/nEvPerPad,2);
441 sigma = TMath::Sqrt(TMath::Abs(qs2m-qsm2));
444 inhard=((Int_t(mean))<<9)+Int_t(mean+3*sigma);
445 out << Form("%2i %2i %2i %5.2f %5.2f %4.4x \n",row,dil,pad,mean,sigma,inhard);
447 //if(sigma > 3.0) Printf("WARNING SIGMA DDL: %2d row: %2d dil: %2d pad: %2d mean: %3.2f sigma: %2.2f nEvPerPad: %02d fnDDLOutStream: %02d fpedQ0: %02d",nDDL,row,dil,pad,mean,sigma,nEvPerPad,fnDDLOutStream[nDDL],fpedQ0[nDDL][row][dil][pad]);
453 out.close(); //write pedestal file
456 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++