Increased the default window for the TOF signal visualization
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDCalib.cxx
CommitLineData
21f61e25 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#include "AliHMPIDCalib.h" //class header
3c8e86a0 17#include "AliHMPIDParam.h" //class header
18#include "AliHMPIDRawStream.h" //class header
08801509 19#include "AliHMPIDDigit.h" //class header
21f61e25 20#include <fstream>
21#include <TTree.h>
cdd8604a 22#include <TSystem.h>
23#include <TTimeStamp.h>
24
25
0f1281b2 26
27
21f61e25 28
29ClassImp(AliHMPIDCalib)
30
31
32//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3c8e86a0 33AliHMPIDCalib::AliHMPIDCalib():
34faddl(0x0),
ee812b5b 35fsq(0x0),
36fsq2(0x0),
37fnpc(0x0),
38fpedQ0(0x0),
39fErr(0x0),
3c8e86a0 40fPadAdc(0x0),
41fIsPad(0x0),
42fFile(0x0),
43fLdcId(0),
44fTimeStamp(0),
45fRunNum(0),
46fSigCut(0),
ee812b5b 47fWritePads(0),
48fnDDLInStream(0x0),
49fnDDLOutStream(0x0),
50fLargeHisto(kFALSE),
cdd8604a 51fSelectDDL(0),
52fDaOut(0),
53fFeeIn(0)
21f61e25 54{
3e60bb92 55 //
56 //constructor
57 //
3c8e86a0 58 faddl = new Bool_t[AliHMPIDRawStream::kNDDL];
59 Int_t nPads = (AliHMPIDParam::kMaxCh+1)*(AliHMPIDParam::kMaxPcx+1)*(AliHMPIDParam::kMaxPcy+1);
ee812b5b 60
61 fpedQ0 = new Int_t***[AliHMPIDRawStream::kNDDL+1];
62 fsq2 = new Float_t ***[AliHMPIDRawStream::kNDDL+1];
63 fsq = new Float_t ***[AliHMPIDRawStream::kNDDL+1];
64 fnpc = new Int_t ***[AliHMPIDRawStream::kNDDL+1];
65 fErr = new Int_t*[AliHMPIDRawStream::kNDDL+1];
66
67 fnDDLInStream = new Int_t[AliHMPIDRawStream::kNDDL+1];
68 fnDDLOutStream = new Int_t[AliHMPIDRawStream::kNDDL+1];
69
70
71 for(Int_t iDDL=0;iDDL<AliHMPIDRawStream::kNDDL+1;iDDL++) {
72
73 fErr[iDDL] = new Int_t[AliHMPIDRawStream::kSumErr+1];
74 fpedQ0[iDDL] = new Int_t**[AliHMPIDRawStream::kNRows+1];
75 fsq[iDDL] = new Float_t**[AliHMPIDRawStream::kNRows+1];
76 fsq2[iDDL] = new Float_t**[AliHMPIDRawStream::kNRows+1];
77 fnpc[iDDL] = new Int_t**[AliHMPIDRawStream::kNRows+1];
78
79 for(Int_t iRow=0;iRow<AliHMPIDRawStream::kNRows+1;iRow++) {
80
81 fpedQ0[iDDL][iRow] = new Int_t*[AliHMPIDRawStream::kNDILOGICAdd+1];
82 fsq[iDDL][iRow] = new Float_t*[AliHMPIDRawStream::kNDILOGICAdd+1];
83 fsq2[iDDL][iRow] = new Float_t*[AliHMPIDRawStream::kNDILOGICAdd+1];
84 fnpc[iDDL][iRow] = new Int_t*[AliHMPIDRawStream::kNDILOGICAdd+1];
85
86 for(Int_t iDil=1;iDil<AliHMPIDRawStream::kNDILOGICAdd+1;iDil++){
87
88 fpedQ0[iDDL][iRow][iDil] = new Int_t[AliHMPIDRawStream::kNPadAdd+1];
89 fsq2[iDDL][iRow][iDil] = new Float_t[AliHMPIDRawStream::kNPadAdd+1];
90 fsq[iDDL][iRow][iDil] = new Float_t[AliHMPIDRawStream::kNPadAdd+1];
91 fnpc[iDDL][iRow][iDil] = new Int_t[AliHMPIDRawStream::kNPadAdd+1];
92 }//iDil
93 }//iRow
94 }//iDDL
95
96 for(Int_t iDDL=0;iDDL<AliHMPIDRawStream::kNDDL+1;iDDL++) {
97
98 fnDDLInStream[iDDL]=-1;
99 fnDDLOutStream[iDDL]=-1;
100
101 for(Int_t iErr=0;iErr<AliHMPIDRawStream::kSumErr+1;iErr++) {fErr[iDDL][iErr]=0;}
102
103 for(Int_t iRow=0;iRow<AliHMPIDRawStream::kNRows+1;iRow++) {
104 for(Int_t iDil=1;iDil<AliHMPIDRawStream::kNDILOGICAdd+1;iDil++) {
105 for(Int_t iPad=1;iPad<AliHMPIDRawStream::kNPadAdd+1;iPad++) {
106 fpedQ0[iDDL][iRow][iDil][iPad]=0;
107 fsq[iDDL][iRow][iDil][iPad]=0;
108 fsq2[iDDL][iRow][iDil][iPad]=0;
109 fnpc[iDDL][iRow][iDil][iPad]=0;
110 }//iPad
111 }//iDil
112 }//iRow
113 }//iDDL
114
3c8e86a0 115 fPadAdc=new TH1I*[nPads];
116 fIsPad=new Bool_t[nPads];
117 for(Int_t np=0;np<nPads;np++) {fPadAdc[np]=0x0; fIsPad[np]=kFALSE;}
118 fWritePads=kFALSE;
ee812b5b 119
120
21f61e25 121 Init();
122}
123//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
124AliHMPIDCalib::~AliHMPIDCalib()
125{
3e60bb92 126 //
21f61e25 127 //destructor
3e60bb92 128 //
ee812b5b 129 if (faddl) { delete [] faddl; faddl = 0x0; }
130 if (fPadAdc) { delete [] fPadAdc; fPadAdc=0x0; }
131 if (fIsPad) { delete [] fIsPad; fIsPad=0x0; }
132 if (fFile) { delete fFile; fFile=0x0; }
133
134 for(Int_t iErr=0;iErr<AliHMPIDRawStream::kSumErr+1;iErr++) { delete [] fErr[iErr];} delete [] fErr;
135
136 for(Int_t iDDL=0; iDDL< AliHMPIDRawStream::kNDDL; iDDL++)
137 for(Int_t iRow=0;iRow<AliHMPIDRawStream::kNRows+1;iRow++)
138 for(Int_t iDil=1;iDil<AliHMPIDRawStream::kNDILOGICAdd+1;iDil++)
139 {
140 delete [] fpedQ0[iDDL][iRow][iDil]; //del iPad
141 delete [] fsq[iDDL][iRow][iDil]; //del iPad
142 delete [] fsq2[iDDL][iRow][iDil]; //del iPad
143 delete [] fnpc[iDDL][iRow][iDil]; //del iPad
144 }
145 for(Int_t iDDL=0; iDDL< AliHMPIDRawStream::kNDDL; iDDL++)
146 for(Int_t iRow=0;iRow<AliHMPIDRawStream::kNRows+1;iRow++)
147 {
148 delete [] fpedQ0[iDDL][iRow]; //del iRow
149 delete [] fsq[iDDL][iRow]; //del iRow
150 delete [] fsq2[iDDL][iRow]; //del iRow
151 delete [] fnpc[iDDL][iRow]; //del iRow
152 }
153
154 for(Int_t iDDL=0; iDDL< AliHMPIDRawStream::kNDDL; iDDL++)
155 {
156 delete [] fpedQ0[iDDL]; //del iRow
157 delete [] fsq2[iDDL]; //del iRow
158 delete [] fsq[iDDL]; //del iRow
159 delete [] fnpc[iDDL]; //del iRow
160 }
161
162 delete [] fpedQ0;
163 delete [] fsq2;
164 delete [] fsq;
165 delete [] fnpc;
166
167 fpedQ0=0;
168 fsq2=0;
169 fsq=0;
170 fnpc=0;
171
3c8e86a0 172 fLdcId=0;
173 fTimeStamp=0;
174 fRunNum=0;
175 fSigCut=0;
176 fWritePads=0;
ee812b5b 177 fLargeHisto=kFALSE;
178 fSelectDDL=0;
3c8e86a0 179}//dtor
21f61e25 180//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
181void AliHMPIDCalib::Init()
182{
21f61e25 183 //
3e60bb92 184 //Init the q calc.
3c8e86a0 185 //Arguments: none
186 //Return: none
21f61e25 187 //
cdd8604a 188
189 fSigCut=3; //the standard cut
190 fFeeIn="";
191 fDaOut="";
192
193
194 for(Int_t iDDL=0; iDDL< AliHMPIDRawStream::kNDDL; iDDL++)
3e60bb92 195 {
3c8e86a0 196 for(Int_t ierr=0; ierr <AliHMPIDRawStream::kSumErr ; ierr++) {
197 fErr[iDDL][ierr]=0;
198 }
199
3e60bb92 200 faddl[iDDL]=kFALSE;
ee812b5b 201 }//DDL
3e60bb92 202}//Init()
21f61e25 203//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3c8e86a0 204void AliHMPIDCalib::SetRunParams(ULong_t runNum,Int_t timeStamp, Int_t ldcId)
205{
206 //
207 //Set run parameters for the Pedestal and Error Files
208 //Arguments: run number, time stamp and LDC Id
209 //Returns: none
210 //
211 fRunNum=(Int_t)runNum;
212 fTimeStamp=timeStamp;
213 fLdcId=ldcId;
214}//SetRunParams()
215//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
216void AliHMPIDCalib::SetSigCutFromFile(Char_t* name)
21f61e25 217{
218 //
3c8e86a0 219 //Set Sigma Cut from the file on the LDC, if the input file is not present default value is set!
220 //Arguments: the name of the SigmaCut file on the LDC
221 //Returns: none
222 //
223 Int_t nSigCut=0;
224 ifstream infile(name);
225 if(!infile.is_open()) {fSigCut=3; return;}
226 while(!infile.eof())
227 {
228 infile>>nSigCut;
229 }
230 infile.close();
231 fSigCut=nSigCut;
232}//SetSigCutFromFile()
cdd8604a 233//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
234void AliHMPIDCalib::SetSigCutFromShell(Char_t *env)
235{
236 //
237 //Set Sigma Cut from the Shell on the LDC, if the input file is not present default value is set!
238 //Arguments: none
239 //Returns: none
240 //
241 Int_t nSigCut=0;
242 TString ssc(gSystem->Getenv(env));
243 //make it nicer later...
244 if(ssc=="1") { nSigCut=1; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
245 else if(ssc=="2") { nSigCut=2; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
246 else if(ssc=="3") { nSigCut=3; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
247 else if(ssc=="4") { nSigCut=4; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
248 else if(ssc=="5") { nSigCut=5; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
249 else if(ssc=="6") { nSigCut=6; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
250 else if(ssc=="7") { nSigCut=7; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
251 else if(ssc=="8") { nSigCut=8; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
252 else if(ssc=="9") { nSigCut=9; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
253 else if(ssc=="10") { nSigCut=10; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
254 else if(ssc=="11") { nSigCut=11; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
255 else if(ssc=="12") { nSigCut=12; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
256 else if(ssc=="13") { nSigCut=13; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
257 else if(ssc=="14") { nSigCut=14; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
258 else if(ssc=="15") { nSigCut=15; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
259 else { nSigCut=3; Printf("DAQ Sigma Cut from shell is too large set it back to default: %d",nSigCut);}
260
261 fSigCut=nSigCut;
262}//SetSigCutFromFile()
263//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void SetDaOutFromShell(Char_t* name); //Set out dir. of DA from Bash Shell
264void AliHMPIDCalib::SetFeeInFromShell(Char_t* env)
265{
266 //
267 //Set the path where the Fe2C is looking for the threshold files
268 //Arguments: none
269 //Returns: none
270 //
271 TString sFeeIn(gSystem->Getenv(env));
272 if(sFeeIn.Data()=="") sFeeIn="/local/home/hmpid/";
273 if(sFeeIn.EndsWith("/")) fFeeIn=sFeeIn;
274 else fFeeIn=Form("%s/",sFeeIn.Data());
275 if(gSystem->OpenDirectory(fFeeIn.Data())==0)
276 {
277 Printf("========== HMPID-DA WARNING: directory %s does not exist! Switching to /tmp! ==========",fFeeIn.Data());
278 fFeeIn="/tmp/";
279 }
280 Printf("HMPID_FEE_IN=%s",fFeeIn.Data());
281}
282//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void SetDaOutFromShell(Char_t* name); //Set out dir. of DA from Bash Shell
283void AliHMPIDCalib::SetDaOutFromShell(Char_t* env)
284{
285 //
286 //Set the standard path where the DA write the output
287 //Arguments: none
288 //Returns: none
289 //
290 TString sDaOut(gSystem->Getenv(env));
291 if(sDaOut=="") sDaOut="/local/home/hmpid/";
292 if(sDaOut.EndsWith("/")) fDaOut=sDaOut;
293 else fDaOut=Form("%s/",sDaOut.Data());
294
295 if(gSystem->OpenDirectory(fDaOut.Data())==0)
296 {
297 Printf("========== HMPID-DA WARNING: directory %s does not exist! Switching to /tmp! ==========",fDaOut.Data());
298 fDaOut="/tmp/";
299 }
300 Printf("HMPID_DA_OUT=%s",fDaOut.Data());
301}
3c8e86a0 302//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
303void AliHMPIDCalib::InitHisto(Int_t q,Int_t histocnt,Char_t* name)
304{
305 //
306 //Init the pad histos. For one DDL we have 11520 pads. ONLY if ENABLED!
307 //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)
308 //Returns: none
309 //
ee812b5b 310 if(fWritePads==kFALSE) return;
3c8e86a0 311 fFile->cd();
312 Double_t lowbin,highbin=0;
ee812b5b 313 lowbin=q-40.5; highbin=q+40.5;
314
3c8e86a0 315 if(fIsPad[histocnt]==kTRUE) return;
316
ee812b5b 317 if(fLargeHisto==kFALSE) fPadAdc[histocnt]=new TH1I(name,name,81,lowbin,highbin);
318 if(fLargeHisto==kTRUE) fPadAdc[histocnt]=new TH1I(name,name,4093,-0.5,4092.5);
3c8e86a0 319 fPadAdc[histocnt]->Sumw2();
320 fIsPad[histocnt]=kTRUE;
321
322}//InitHisto()
323//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
324void AliHMPIDCalib::FillHisto(Int_t histocnt,Int_t q)
325{
326 //
327 //Fill the ADC histograms for each pad
328 //Arguments: q-charge, the absolute number of the histogram (AliHMPIDParam::kMaxCh+1)*(AliHMPIDParam::kMaxPcx+1)*(AliHMPIDParam::kMaxPcy+1)
329 //Returns: none
330 //
3c8e86a0 331 if(fIsPad[histocnt]==kFALSE) return;
ee812b5b 332 fFile->cd();
3c8e86a0 333 fPadAdc[histocnt]->Fill(q);
334
335}//InitHisto()
336//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
77e40af5 337void AliHMPIDCalib::InitFile(Int_t inVal)
3c8e86a0 338{
339 //
340 //Initialize the ADC histo output file (one per LDC)
341 //Arguments: LDC Id
342 //Returns: none
343 //
77e40af5 344 if(fWritePads==kFALSE ) return;
345 if(fLargeHisto==kFALSE) fFile=new TFile(Form("HmpidPadsOnLdc%2d.root",inVal),"RECREATE");
346 if(fLargeHisto==kTRUE) fFile=new TFile(Form("Run%d_DDL%d.root",inVal,fSelectDDL),"RECREATE");
347
3c8e86a0 348}//InitFile()
349//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
77e40af5 350void AliHMPIDCalib::CloseFile()
3c8e86a0 351{
352 //
353 //Close the ADC histo output file (one per LDC)
354 //Arguments: LDC Id
355 //Returns: none
356 //
357 fFile->cd();
358 Int_t nPads = (AliHMPIDParam::kMaxCh+1)*(AliHMPIDParam::kMaxPcx+1)*(AliHMPIDParam::kMaxPcy+1);
359 for(Int_t np=0;np<nPads;np++) {if(fIsPad[np]==kTRUE) fPadAdc[np]->Write();}
360 fFile->Close();
361}//CloseFile()
362//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
363void AliHMPIDCalib::FillPedestal(Int_t abspad,Int_t q)
364{
365 //
366 //Called from the HMPIDda and fills the pedestal values
08801509 367 //Arguments: absolute pad number as from AliHMPIDParam and q-charge
3c8e86a0 368 //Returns: none
21f61e25 369 //
ee812b5b 370 if(q<0) AliFatal("Negative charge is read!!!!!!");
371
08801509 372 UInt_t w32;
0f1281b2 373 Int_t nDDL=0, row=0, dil=0, adr=0;
374 //The decoding (abs. pad -> ddl,dil,...) is the same as in AliHMPIDDigit::Raw
08801509 375
376 AliHMPIDDigit dig(abspad,q);
377 dig.Raw(w32,nDDL,row,dil,adr);
378
0f1281b2 379 //........... decoding done
3e60bb92 380
ee812b5b 381 if(q>0) {
382 fsq[nDDL][row][dil][adr]+=q;
383 fsq2[nDDL][row][dil][adr]+=q*q;
384 fnpc[nDDL][row][dil][adr]++; //Count how many times the pad is good (can be different from the good DDL count)
385 faddl[nDDL]=kTRUE;
386 }
387 else
388 {
389 fpedQ0[nDDL][row][dil][adr]++; //Count how many times a pad charge is zero
3c8e86a0 390 }
ee812b5b 391
392 Int_t histocnt=0; histocnt=(nDDL)*11520+(row-1)*480+(dil-1)*48+adr; //Histo counter for a single DDL
393
394 if(fWritePads==kTRUE) //works but make it nicer later....
395 {
396 if( fLargeHisto==kTRUE && nDDL==fSelectDDL) {
397 InitHisto(q,histocnt,Form("hDDL_%d_Row_%d_Dil_%d_Pad_%d",nDDL,row,dil,adr)); //for large histos use hardware naming
398 FillHisto(histocnt,q);
399 }
400 if(fLargeHisto==kFALSE)
401 {
402 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)));
403 FillHisto(histocnt,q);
404 }
405 }//fWritePads
3c8e86a0 406
21f61e25 407}//FillPedestal()
408//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3c8e86a0 409void AliHMPIDCalib::FillErrors(Int_t nDDL,Int_t eType, Int_t nErr)
0f1281b2 410{
411 //
3c8e86a0 412 //Fill decoding errors from AliHMPIDRawStream
413 //Arguments: nDDL-DDL number, eType- error type as in AliHMPIDRawStream.h and the # of occurence for eType
414 //Retutns: none
0f1281b2 415 //
3c8e86a0 416 if(nErr<=0) return;
417 if(eType < 0 || eType> AliHMPIDRawStream::kSumErr ) return;
418 fErr[nDDL][eType]=fErr[nDDL][eType]+nErr;
ee812b5b 419
0f1281b2 420
421}//FillErrors()
422//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ee812b5b 423void AliHMPIDCalib::FillDDLCnt(Int_t iddl,Int_t inDDL, Int_t outDDL)
424{
425 //
426 //Fill decoding DDL check from RawStream
427 //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
428 //Retutns: none
429 //
430
431 if(inDDL==-1) return;
432 if(fnDDLInStream[iddl]==-1) {fnDDLInStream[iddl]=0; fnDDLOutStream[iddl]=0;}
433 fnDDLInStream[iddl]+=inDDL;
434 fnDDLOutStream[iddl]+=outDDL;
435
436
437}//FillDDLCnt()
438//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3c8e86a0 439Bool_t AliHMPIDCalib::WriteErrors(Int_t nDDL, Char_t* name, Int_t nEv)
0f1281b2 440{
441 //
442 //Write decoding errors to a txt file
3c8e86a0 443 //Arguments: nDDL-DDL number, name of the error file and number of the read events
444 //Retutns: kTRUE/kFALSE
cdd8604a 445 //
ee812b5b 446 if(faddl[nDDL]==kFALSE) return kFALSE; //if ddl is missing no error file is created
447 ofstream outerr; outerr.open(name); //open error file
448 outerr << Form("%8s %2d\n","RunNumber",(Int_t)fRunNum); //read run number
449 outerr << Form("%8s %2d\n","LdcId" , fLdcId); //read LDC Id
450 outerr << Form("%8s %2d\n","TimeStamp", fTimeStamp); //read time stamp
451 outerr << Form("%8s %2d\n","TotNumEvt", nEv); //read number of total events processed
452 outerr << Form("%8s %2d\n","TotDDLEvt", fnDDLInStream[nDDL]); //read number of bad events for DDL # nDDL processed
453 outerr << Form("%8s %2d\n","NumBadEvt", fnDDLInStream[nDDL]-fnDDLOutStream[nDDL]); //read number of bad events for DDL # nDDL processed
454 outerr << Form("%8s %2.2f\n","NBadE(%)", (fnDDLInStream[nDDL]-fnDDLOutStream[nDDL])*100.0/nEv); //read number of bad events (in %) for DDL # nDDL processed
455
3c8e86a0 456 for(Int_t ierr=0; ierr <AliHMPIDRawStream::kSumErr; ierr++) outerr << Form("%2d\t",fErr[nDDL][ierr]); //write errors
457 outerr << Form("\n"); //last break
77e40af5 458 /* write out pads with 0 charge read */
459 for(Int_t row = 1; row <= AliHMPIDRawStream::kNRows; row++){
460 for(Int_t dil = 1; dil <= AliHMPIDRawStream::kNDILOGICAdd; dil++){
461 for(Int_t pad = 0; pad < AliHMPIDRawStream::kNPadAdd; pad++){
462 if(fpedQ0[nDDL][row][dil][pad]>0) outerr<< Form("%2d %2d %2d %3d\n",row,dil,pad,fpedQ0[nDDL][row][dil][pad]);
463 }
464 }
465 }
466
467
3c8e86a0 468 outerr.close(); //write error file
cdd8604a 469
0f1281b2 470 return kTRUE;
471
472}//FillErrors()
473//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3c8e86a0 474Bool_t AliHMPIDCalib::CalcPedestal(Int_t nDDL, Char_t* name, Int_t nEv)
21f61e25 475{
476 //
477 //Calculate pedestal for each pad
3c8e86a0 478 //Arguments: nDDL-DDL number, name of the pedestal file and number of the read events
479 //Retutns: kTRUE/kFALSE
21f61e25 480 //
3c8e86a0 481
0f1281b2 482 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?!
cdd8604a 483 Int_t ddlOffset=1536;
484 Int_t feeOffset=196657;
485 ofstream feeInput[24];
486
487 for(Int_t ir=0;ir<AliHMPIDRawStream::kNRows;ir++) feeInput[ir].open(Form("%sthr%d_%d.dat",fFeeIn.Data(),ddlOffset+nDDL,ir+1)); //for Fe2C every row has a file only with inhard
488
ee812b5b 489 Double_t mean=0,sigma=0;
490 Double_t qs2m=0,qsm2=0;
21f61e25 491 ofstream out; //to write the pedestal text files
21f61e25 492 Int_t inhard;
ee812b5b 493 Int_t nEvPerPad=0;
3e60bb92 494 out.open(name);
ee812b5b 495 out << Form("%8s %2d\n","RunNumber",(Int_t)fRunNum); //read run number
496 out << Form("%8s %2d\n","LdcId" , fLdcId); //read LDC Id
497 out << Form("%8s %2d\n","TimeStamp", fTimeStamp); //read time stamp
498 out << Form("%8s %2d\n","TotNumEvt", nEv); //read number of total events processed
499 out << Form("%8s %2d\n","TotDDLEvt", fnDDLInStream[nDDL]); //read number of bad events for DDL # nDDL processed
500 out << Form("%8s %2d\n","NumBadEvt", fnDDLInStream[nDDL]-fnDDLOutStream[nDDL]); //read number of bad events for DDL # nDDL processed
501 out << Form("%8s %2f\n","NBadE(%)", (fnDDLInStream[nDDL]-fnDDLOutStream[nDDL])*100.0/nEv); //read number of bad events (in %) for DDL # nDDL processed
502 out << Form("%8s %2.2d\n","#SigCut", fSigCut); //# of sigma cuts
503
3c8e86a0 504 for(Int_t row = 1; row <= AliHMPIDRawStream::kNRows; row++){
cdd8604a 505 //write thr file for Fe2C
506
3c8e86a0 507 for(Int_t dil = 1; dil <= AliHMPIDRawStream::kNDILOGICAdd; dil++){
508 for(Int_t pad = 0; pad < AliHMPIDRawStream::kNPadAdd; pad++){
3e60bb92 509
ee812b5b 510 mean = 50;sigma = 100;
3e60bb92 511
ee812b5b 512 nEvPerPad=fnpc[nDDL][row][dil][pad];
3e60bb92 513
ee812b5b 514 if(nEvPerPad < 1 ) { //if the pad is bad then we assign 100 for the sigma and 50 for the mean
9f99568d 515 mean = 4000;
516 sigma = 1000;
ee812b5b 517 }
518 else{
519 mean = fsq[nDDL][row][dil][pad]*1.0/nEvPerPad;
520 qs2m = fsq2[nDDL][row][dil][pad]*1.0/nEvPerPad;
521 qsm2 = TMath::Power(fsq[nDDL][row][dil][pad]*1.0/nEvPerPad,2);
522 sigma = TMath::Sqrt(TMath::Abs(qs2m-qsm2));
523 }
cdd8604a 524
525 inhard=((Int_t(mean+fSigCut*sigma))<<9)+Int_t(mean); //right calculation, xchecked with Paolo 8/4/2008
526 out << Form("%2i %2i %2i %5.3f %5.3f %4.4x \n",row,dil,pad,mean,sigma,inhard);
527
528 feeInput[row-1] << Form("0x%4.4x\n",inhard);
529 //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]);
21f61e25 530 }//adr
cdd8604a 531
532 //we have to write up to 64 not 48 in the DILOGIC since they are daisy chained!
533 //offset and format is defined for the Fe2C code
534 for(Int_t idd=0;idd<16;idd++) feeInput[row-1] << Form("0x%4.4x\n",idd+feeOffset);
21f61e25 535 }//dil
cdd8604a 536
537
21f61e25 538 }//row
539 out.close(); //write pedestal file
cdd8604a 540 for(Int_t ir=0;ir<AliHMPIDRawStream::kNRows;ir++) feeInput[ir].close();
541
21f61e25 542 return kTRUE;
543}//CaclPedestal()
544//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
cdd8604a 545Bool_t AliHMPIDCalib::CalcPedestalPaolo(Int_t nDDL, Char_t* /*name*/, Int_t nEv)
546{
547 //
548 //Calculate pedestal for each pad
549 //Arguments: nDDL-DDL number, name of the pedestal file and number of the read events
550 //Retutns: kTRUE/kFALSE
551 //
552 //----------------- write files in the format of Paolo -----------------------
553 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?!
554 Int_t ddlOffset=1536;
555 Int_t cnt=0;
556 Double_t mean1=0,sigma1=0;
557 Double_t qs2m1=0,qsm21=0;
558 Double_t mean2=0,sigma2=0;
559 Double_t qs2m2=0,qsm22=0;
560 Int_t nEvPerPad1=0;
561 Int_t nEvPerPad2=0;
562
563 ofstream pped[3];
564 for(Int_t iseg=1;iseg<4;iseg++) pped[iseg-1].open(Form("%sHmpidPed%d_%d.dat",fDaOut.Data(),nDDL+ddlOffset,iseg));
565
566 for(Int_t row = 1; row <= AliHMPIDRawStream::kNRows/2; row++){
567
568 //write header
569 pped[(row-1)/4]<<Form("ID_Nevt_NChan_Row_Row_P0_P1_S0_S1 \n");
570 pped[(row-1)/4]<<Form("%d %d %d %d %d %3.3lf %3.3lf %3.3lf %3.3lf \n",2*row-1,nEv,480,2*row-1,2*row,999.0,999.0,999.0,999.0);
571
572 cnt=0;
573 for(Int_t dil = 1; dil <= AliHMPIDRawStream::kNDILOGICAdd; dil++){
574 for(Int_t pad = 0; pad < AliHMPIDRawStream::kNPadAdd; pad++){
575
576 nEvPerPad1=fnpc[nDDL][2*row-1][dil][pad];
577 nEvPerPad2=fnpc[nDDL][2*row][dil][pad];
578
579 if(nEvPerPad1 < 1 ) { mean1 = 4000; sigma1 = 1000; }
cb9b108e 580 else
581 {
582 mean1 = fsq[nDDL][2*row-1][dil][pad]*1.0/nEvPerPad1;
583 qs2m1 = fsq2[nDDL][2*row-1][dil][pad]*1.0/nEvPerPad1;
584 qsm21 = TMath::Power(fsq[nDDL][2*row-1][dil][pad]*1.0/nEvPerPad1,2);
585 sigma1 = TMath::Sqrt(TMath::Abs(qs2m1-qsm21));
586 }
587
cdd8604a 588 if(nEvPerPad2 < 1 ) { mean2 = 4000; sigma2 = 1000; }
cb9b108e 589 else
590 {
cdd8604a 591 mean2 = fsq[nDDL][2*row][dil][pad]*1.0/nEvPerPad2;
592 qs2m2 = fsq2[nDDL][2*row][dil][pad]*1.0/nEvPerPad2;
593 qsm22 = TMath::Power(fsq[nDDL][2*row][dil][pad]*1.0/nEvPerPad2,2);
594 sigma2 = TMath::Sqrt(TMath::Abs(qs2m2-qsm22));
cb9b108e 595 }
cdd8604a 596 pped[(row-1)/4]<<Form("%d %3.3lf %3.3lf %3.3lf %3.3lf \n",cnt,mean1,sigma1,mean2,sigma2);cnt++;
597 }//pad
598 }//dil
599 }//row
600 for(Int_t ir=0;ir<3;ir++) {pped[ir].close(); }
601 return kTRUE;
602}//CalcPedestalPaolo()
603//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
604
ee812b5b 605