Line data Source code
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
17 : #include "AliHMPIDParam.h" //class header
18 : #include "AliHMPIDRawStream.h" //class header
19 : #include "AliHMPIDDigit.h" //class header
20 : #include <fstream>
21 : #include <TTree.h>
22 : #include <TSystem.h>
23 : #include <TTimeStamp.h>
24 :
25 :
26 :
27 : using std::ifstream;
28 : using std::ofstream;
29 16 : ClassImp(AliHMPIDCalib)
30 :
31 :
32 : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33 0 : AliHMPIDCalib::AliHMPIDCalib():
34 0 : faddl(0x0),
35 0 : fsq(0x0),
36 0 : fsq2(0x0),
37 0 : fnpc(0x0),
38 0 : fpedQ0(0x0),
39 0 : fErr(0x0),
40 0 : fPadAdc(0x0),
41 0 : fIsPad(0x0),
42 0 : fFile(0x0),
43 0 : fLdcId(0),
44 0 : fTimeStamp(0),
45 0 : fRunNum(0),
46 0 : fSigCut(0),
47 0 : fnDDLInStream(0x0),
48 0 : fnDDLOutStream(0x0),
49 0 : fLargeHisto(kFALSE),
50 0 : fSelectDDL(0),
51 0 : fDeadMap(0x0),
52 0 : fPedMeanMap(0x0),
53 0 : fPedSigMap(0x0),
54 0 : f1DPedMean(0x0),
55 0 : f1DPedSigma(0x0),
56 0 : fNumMaskedPads(0),
57 0 : fNumDeadPads(0)
58 0 : {
59 : //
60 : //constructor
61 : //
62 :
63 0 : faddl = new Bool_t[AliHMPIDRawStream::kNDDL];
64 : Int_t nPads = (AliHMPIDParam::kMaxCh+1)*(AliHMPIDParam::kMaxPcx+1)*(AliHMPIDParam::kMaxPcy+1);
65 :
66 0 : fpedQ0 = new Int_t***[AliHMPIDRawStream::kNDDL+1];
67 0 : fsq2 = new Float_t ***[AliHMPIDRawStream::kNDDL+1];
68 0 : fsq = new Float_t ***[AliHMPIDRawStream::kNDDL+1];
69 0 : fnpc = new Int_t ***[AliHMPIDRawStream::kNDDL+1];
70 0 : fErr = new Int_t*[AliHMPIDRawStream::kNDDL+1];
71 :
72 0 : fnDDLInStream = new Int_t[AliHMPIDRawStream::kNDDL+1];
73 0 : fnDDLOutStream = new Int_t[AliHMPIDRawStream::kNDDL+1];
74 :
75 :
76 0 : for(Int_t iDDL=0;iDDL<AliHMPIDRawStream::kNDDL+1;iDDL++) {
77 :
78 0 : fErr[iDDL] = new Int_t[AliHMPIDRawStream::kSumErr+1];
79 0 : fpedQ0[iDDL] = new Int_t**[AliHMPIDRawStream::kNRows+1];
80 0 : fsq[iDDL] = new Float_t**[AliHMPIDRawStream::kNRows+1];
81 0 : fsq2[iDDL] = new Float_t**[AliHMPIDRawStream::kNRows+1];
82 0 : fnpc[iDDL] = new Int_t**[AliHMPIDRawStream::kNRows+1];
83 :
84 0 : for(Int_t iRow=0;iRow<AliHMPIDRawStream::kNRows+1;iRow++) {
85 :
86 0 : fpedQ0[iDDL][iRow] = new Int_t*[AliHMPIDRawStream::kNDILOGICAdd+1];
87 0 : fsq[iDDL][iRow] = new Float_t*[AliHMPIDRawStream::kNDILOGICAdd+1];
88 0 : fsq2[iDDL][iRow] = new Float_t*[AliHMPIDRawStream::kNDILOGICAdd+1];
89 0 : fnpc[iDDL][iRow] = new Int_t*[AliHMPIDRawStream::kNDILOGICAdd+1];
90 :
91 0 : for(Int_t iDil=1;iDil<AliHMPIDRawStream::kNDILOGICAdd+1;iDil++){
92 :
93 0 : fpedQ0[iDDL][iRow][iDil] = new Int_t[AliHMPIDRawStream::kNPadAdd+1];
94 0 : fsq2[iDDL][iRow][iDil] = new Float_t[AliHMPIDRawStream::kNPadAdd+1];
95 0 : fsq[iDDL][iRow][iDil] = new Float_t[AliHMPIDRawStream::kNPadAdd+1];
96 0 : fnpc[iDDL][iRow][iDil] = new Int_t[AliHMPIDRawStream::kNPadAdd+1];
97 : }//iDil
98 : }//iRow
99 : }//iDDL
100 :
101 0 : for(Int_t iDDL=0;iDDL<AliHMPIDRawStream::kNDDL+1;iDDL++) {
102 :
103 0 : fnDDLInStream[iDDL]=-1;
104 0 : fnDDLOutStream[iDDL]=-1;
105 :
106 0 : for(Int_t iErr=0;iErr<AliHMPIDRawStream::kSumErr+1;iErr++) {fErr[iDDL][iErr]=0;}
107 :
108 0 : for(Int_t iRow=0;iRow<AliHMPIDRawStream::kNRows+1;iRow++) {
109 0 : for(Int_t iDil=1;iDil<AliHMPIDRawStream::kNDILOGICAdd+1;iDil++) {
110 0 : for(Int_t iPad=1;iPad<AliHMPIDRawStream::kNPadAdd+1;iPad++) {
111 0 : fpedQ0[iDDL][iRow][iDil][iPad]=0;
112 0 : fsq[iDDL][iRow][iDil][iPad]=0;
113 0 : fsq2[iDDL][iRow][iDil][iPad]=0;
114 0 : fnpc[iDDL][iRow][iDil][iPad]=0;
115 : }//iPad
116 : }//iDil
117 : }//iRow
118 : }//iDDL
119 :
120 0 : fPadAdc=new TH1I*[nPads];
121 0 : fIsPad=new Bool_t[nPads];
122 0 : for(Int_t np=0;np<nPads;np++) {fPadAdc[np]=0x0; fIsPad[np]=kFALSE;}
123 :
124 0 : Init();
125 0 : }
126 : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
127 : AliHMPIDCalib::~AliHMPIDCalib()
128 0 : {
129 : //
130 : //destructor
131 : //
132 0 : if (faddl) { delete [] faddl; faddl = 0x0; }
133 0 : if (fPadAdc) { delete [] fPadAdc; fPadAdc=0x0; }
134 0 : if (fIsPad) { delete [] fIsPad; fIsPad=0x0; }
135 0 : if (fFile) { delete fFile; fFile=0x0; }
136 0 : if (fDeadMap) { delete fDeadMap;fDeadMap=0x0; }
137 :
138 0 : for(Int_t iErr=0;iErr<AliHMPIDRawStream::kSumErr+1;iErr++) { delete [] fErr[iErr];} delete [] fErr;
139 :
140 0 : for(Int_t iDDL=0; iDDL< AliHMPIDRawStream::kNDDL; iDDL++)
141 0 : for(Int_t iRow=0;iRow<AliHMPIDRawStream::kNRows+1;iRow++)
142 0 : for(Int_t iDil=1;iDil<AliHMPIDRawStream::kNDILOGICAdd+1;iDil++)
143 : {
144 0 : delete [] fpedQ0[iDDL][iRow][iDil]; //del iPad
145 0 : delete [] fsq[iDDL][iRow][iDil]; //del iPad
146 0 : delete [] fsq2[iDDL][iRow][iDil]; //del iPad
147 0 : delete [] fnpc[iDDL][iRow][iDil]; //del iPad
148 : }
149 0 : for(Int_t iDDL=0; iDDL< AliHMPIDRawStream::kNDDL; iDDL++)
150 0 : for(Int_t iRow=0;iRow<AliHMPIDRawStream::kNRows+1;iRow++)
151 : {
152 0 : delete [] fpedQ0[iDDL][iRow]; //del iRow
153 0 : delete [] fsq[iDDL][iRow]; //del iRow
154 0 : delete [] fsq2[iDDL][iRow]; //del iRow
155 0 : delete [] fnpc[iDDL][iRow]; //del iRow
156 : }
157 :
158 0 : for(Int_t iDDL=0; iDDL< AliHMPIDRawStream::kNDDL; iDDL++)
159 : {
160 0 : delete [] fpedQ0[iDDL]; //del iRow
161 0 : delete [] fsq2[iDDL]; //del iRow
162 0 : delete [] fsq[iDDL]; //del iRow
163 0 : delete [] fnpc[iDDL]; //del iRow
164 : }
165 :
166 0 : delete [] fpedQ0;
167 0 : delete [] fsq2;
168 0 : delete [] fsq;
169 0 : delete [] fnpc;
170 :
171 0 : fpedQ0=0;
172 0 : fsq2=0;
173 0 : fsq=0;
174 0 : fnpc=0;
175 :
176 0 : fLdcId=0;
177 0 : fTimeStamp=0;
178 0 : fRunNum=0;
179 0 : fSigCut=0;
180 0 : fLargeHisto=kFALSE;
181 0 : fSelectDDL=0;
182 0 : fNumMaskedPads=0;
183 :
184 0 : if (fPedMeanMap) { delete [] fPedMeanMap; fPedMeanMap=0x0; }
185 0 : if (fPedSigMap) { delete [] fPedSigMap; fPedSigMap=0x0; }
186 0 : if (f1DPedMean) { delete [] f1DPedMean; f1DPedMean=0x0; }
187 0 : if (f1DPedSigma) { delete [] f1DPedSigma; f1DPedSigma=0x0; }
188 :
189 0 : }//dtor
190 : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
191 : void AliHMPIDCalib::Init()
192 : {
193 : //
194 : //Init the q calc.
195 : //Arguments: none
196 : //Return: none
197 : //
198 :
199 0 : fSigCut=3; //the standard cut
200 :
201 :
202 0 : for(Int_t iDDL=0; iDDL< AliHMPIDRawStream::kNDDL; iDDL++)
203 : {
204 0 : for(Int_t ierr=0; ierr <AliHMPIDRawStream::kSumErr ; ierr++) {
205 0 : fErr[iDDL][ierr]=0;
206 : }
207 :
208 0 : faddl[iDDL]=kFALSE;
209 : }//DDL
210 :
211 0 : Int_t nbins[4]={14, 24, 10, 48};
212 0 : Double_t binmin[4]={ 0, 1, 1, 0};
213 0 : Double_t binmax[4]={14, 25, 11, 48};
214 0 : fDeadMap = new THnSparseD("fDeadMap","Dead Channel Map",4,nbins,binmin,binmax);
215 :
216 0 : fPedMeanMap = new TH2F*[AliHMPIDParam::kMaxCh+1];
217 0 : fPedSigMap = new TH2F*[AliHMPIDParam::kMaxCh+1];
218 0 : f1DPedMean = new TH1F*[(AliHMPIDParam::kMaxCh+1)*(AliHMPIDParam::kMaxPc+1)];
219 0 : f1DPedSigma = new TH1F*[(AliHMPIDParam::kMaxCh+1)*(AliHMPIDParam::kMaxPc+1)];
220 :
221 : // Int_t mapmin,mapmax;
222 0 : for(Int_t iCh=0;iCh<AliHMPIDParam::kMaxCh+1;iCh++)
223 : {
224 0 : fPedMeanMap[iCh]=new TH2F(Form("fPedMeanMap%d",iCh),Form("fPedMeanMap%d;pad x;pad y;Mean pedestal (ADC)",iCh),160, 0,160,144,0,144);fPedMeanMap[iCh]->SetStats(kFALSE);
225 0 : fPedSigMap[iCh] =new TH2F(Form("fPedSigMap%d",iCh), Form("fPedSigMap%d;pad x;pad y;Sigma pedestal (ADC)",iCh), 160, 0,160,144,0,144);fPedSigMap[iCh]->SetStats(kFALSE);
226 : }
227 0 : for(Int_t iCh=0;iCh<=AliHMPIDParam::kMaxCh;iCh++)
228 : {
229 0 : for(Int_t iFee=0;iFee<6;iFee++)
230 : {
231 0 : f1DPedMean[6*iCh+iFee] = new TH1F(Form("f1DPedMean_Ch%d_FEE_%d" , iCh,iFee),Form("Mean Pedestals, RICH %d, FEE %d;Channels;Mean pedestal (ADC)" ,iCh,iFee),3840,0,3840);f1DPedMean[6*iCh+iFee]->SetStats(kFALSE);
232 0 : f1DPedSigma[6*iCh+iFee] = new TH1F(Form("f1DPedSigma_Ch%d_FEE_%d" ,iCh,iFee),Form("Sigma Pedestal, RICH %d, FEE %d;Channels;Sigma pedestal (ADC)" ,iCh,iFee),3840,0,3840);f1DPedSigma[6*iCh+iFee]->SetStats(kFALSE);
233 : }
234 : }
235 :
236 0 : }//Init()
237 : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
238 : void AliHMPIDCalib::SetRunParams(ULong_t runNum,Int_t timeStamp, Int_t ldcId)
239 : {
240 : //
241 : //Set run parameters for the Pedestal and Error Files
242 : //Arguments: run number, time stamp and LDC Id
243 : //Returns: none
244 : //
245 0 : fRunNum=(Int_t)runNum;
246 0 : fTimeStamp=timeStamp;
247 0 : fLdcId=ldcId;
248 0 : }//SetRunParams()
249 : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
250 : void AliHMPIDCalib::SetSigCutFromFile(TString hmpInFile)
251 : {
252 : //
253 : //Set Sigma Cut from the file on the LDC, if the input file is not present default value is set!
254 : //Arguments: the name of the SigmaCut file on the LDC
255 : //Returns: none
256 : //
257 0 : Int_t nSigCut=0;
258 0 : ifstream infile(hmpInFile.Data());
259 0 : if(!infile.is_open()) {fSigCut=3; return;}
260 0 : while(!infile.eof())
261 : {
262 0 : infile>>nSigCut;
263 : }
264 0 : infile.close();
265 0 : if(nSigCut< 0 || nSigCut > 15 ) {Printf("WARNING: DAQ Sigma Cut from DAQ DB is out of bounds: %d, resetting it to 3!!!",nSigCut);nSigCut=3;}
266 0 : Printf("DAQ Sigma Cut from DAQ DB is: %d",nSigCut);
267 0 : fSigCut=nSigCut;
268 0 : }//SetSigCutFromFile()
269 : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
270 : void AliHMPIDCalib::SetDeadChannelMapFromFile(TString hmpInFile)
271 : {
272 : //
273 : //Set Dead Channel Map Cut from the file on the LDC, if the input file is not present default value is set!
274 : //Arguments: the name of the Dead Channel Map file on the LDC
275 : //Returns: none
276 : //
277 0 : Char_t header[256];
278 0 : Int_t ddl=0,row=0,dil=0,pad=0,ch=0,pc=0,chpadx=0,chpady=0,px=0,py=0,isitmasked=0;
279 0 : UInt_t dw=0;
280 0 : Double_t bin[4];
281 0 : ifstream infile(hmpInFile.Data());
282 0 : if(!infile.is_open()) {Printf("HMPID Dead Channel Map file cannot be opened!!!! No mask is applied!!!");return;}
283 0 : infile.getline(header,256);
284 0 : AliHMPIDDigit dig;
285 0 : while(!infile.eof())
286 : {
287 0 : infile>>ch>>chpadx>>chpady>>isitmasked; //read in masked coordinates; coordinates are in the module coordinate system
288 0 : pc=(chpadx/80)+2*(chpady/48); //get PC number
289 0 : px=chpadx-80*(chpadx/80); //get pad X in PC coordinates
290 0 : py=chpady-48*(chpady/48); //get pad Y in PC coordinates --- can we do it better??? -- just with one conversion???? clm
291 0 : if(!dig.Set(ch,pc,px,py,0) && isitmasked) { //in the AliHMPIDDigit:Set there is already a check if the coordinates makes sense
292 0 : dig.Raw(dw,ddl,row,dil,pad);
293 0 : bin[0]=ddl; bin[1]=row; bin[2]=dil; bin[3]=pad;
294 0 : fDeadMap->Fill(bin,1);
295 : }
296 : }
297 0 : infile.close();
298 :
299 0 : }//SetDeadChannelMapFromFile()
300 : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
301 : void AliHMPIDCalib::FillPedestal(Int_t abspad,Int_t q)
302 : {
303 : //
304 : //Called from the HMPIDda and fills the pedestal values
305 : //Arguments: absolute pad number as from AliHMPIDParam and q-charge
306 : //Returns: none
307 : //
308 0 : if(q<0) {
309 0 : AliError("Negative charge is read!!!!!!");
310 0 : return;
311 : }
312 0 : UInt_t w32;
313 0 : Int_t nDDL=0, row=0, dil=0, adr=0;
314 : //The decoding (abs. pad -> ddl,dil,...) is the same as in AliHMPIDDigit::Raw
315 :
316 0 : AliHMPIDDigit dig(abspad,q);
317 0 : dig.Raw(w32,nDDL,row,dil,adr);
318 :
319 : //........... decoding done
320 :
321 0 : if(q>0) {
322 0 : fsq[nDDL][row][dil][adr]+=q;
323 0 : fsq2[nDDL][row][dil][adr]+=q*q;
324 0 : fnpc[nDDL][row][dil][adr]++; //Count how many times the pad is good (can be different from the good DDL count)
325 0 : faddl[nDDL]=kTRUE;
326 0 : }
327 : else
328 : {
329 0 : fpedQ0[nDDL][row][dil][adr]++; //Count how many times a pad charge is zero
330 : }
331 :
332 : // Int_t histocnt=0; histocnt=(nDDL)*11520+(row-1)*480+(dil-1)*48+adr; //Histo counter for a single DDL
333 :
334 0 : }//FillPedestal()
335 : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
336 : void AliHMPIDCalib::FillErrors(Int_t nDDL,Int_t eType, Int_t nErr)
337 : {
338 : //
339 : //Fill decoding errors from AliHMPIDRawStream
340 : //Arguments: nDDL-DDL number, eType- error type as in AliHMPIDRawStream.h and the # of occurence for eType
341 : //Retutns: none
342 : //
343 0 : if(nErr<=0) return;
344 0 : if(eType < 0 || eType> AliHMPIDRawStream::kSumErr ) return;
345 0 : fErr[nDDL][eType]=fErr[nDDL][eType]+nErr;
346 :
347 :
348 0 : }//FillErrors()
349 : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
350 : void AliHMPIDCalib::FillDDLCnt(Int_t iddl,Int_t inDDL, Int_t outDDL)
351 : {
352 : //
353 : //Fill decoding DDL check from RawStream
354 : //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
355 : //Retutns: none
356 : //
357 :
358 0 : if(inDDL==-1) return;
359 0 : if(fnDDLInStream[iddl]==-1) {fnDDLInStream[iddl]=0; fnDDLOutStream[iddl]=0;}
360 0 : fnDDLInStream[iddl]+=inDDL;
361 0 : fnDDLOutStream[iddl]+=outDDL;
362 :
363 :
364 0 : }//FillDDLCnt()
365 : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
366 : Bool_t AliHMPIDCalib::WriteErrors(Int_t nDDL, Char_t* name, Int_t nEv)
367 : {
368 : //
369 : //Write decoding errors to a txt file
370 : //Arguments: nDDL-DDL number, name of the error file and number of the read events
371 : //Retutns: kTRUE/kFALSE
372 : //
373 0 : if(faddl[nDDL]==kFALSE) return kFALSE; //if ddl is missing no error file is created
374 0 : ofstream outerr; outerr.open(name); //open error file
375 0 : outerr << Form("%8s %2d\n","RunNumber",(Int_t)fRunNum); //read run number
376 0 : outerr << Form("%8s %2d\n","LdcId" , fLdcId); //read LDC Id
377 0 : outerr << Form("%8s %2d\n","TimeStamp", fTimeStamp); //read time stamp
378 0 : outerr << Form("%8s %2d\n","TotNumEvt", nEv); //read number of total events processed
379 0 : outerr << Form("%8s %2d\n","TotDDLEvt", fnDDLInStream[nDDL]); //read number of bad events for DDL # nDDL processed
380 0 : outerr << Form("%8s %2d\n","NumBadEvt", fnDDLInStream[nDDL]-fnDDLOutStream[nDDL]); //read number of bad events for DDL # nDDL processed
381 0 : 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 :
383 0 : for(Int_t ierr=0; ierr <AliHMPIDRawStream::kSumErr; ierr++) outerr << Form("%2d\t",fErr[nDDL][ierr]); //write errors
384 0 : outerr << Form("\n"); //last break
385 : /* write out pads with 0 charge read */
386 0 : for(Int_t row = 1; row <= AliHMPIDRawStream::kNRows; row++){
387 0 : for(Int_t dil = 1; dil <= AliHMPIDRawStream::kNDILOGICAdd; dil++){
388 0 : for(Int_t pad = 0; pad < AliHMPIDRawStream::kNPadAdd; pad++){
389 0 : if(fpedQ0[nDDL][row][dil][pad]>0) outerr<< Form("%2d %2d %2d %3d\n",row,dil,pad,fpedQ0[nDDL][row][dil][pad]);
390 : }
391 : }
392 : }
393 :
394 :
395 0 : outerr.close(); //write error file
396 :
397 : return kTRUE;
398 :
399 0 : }//FillErrors()
400 : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
401 : Bool_t AliHMPIDCalib::CalcPedestal(Int_t nDDL, Char_t* name, Char_t *name2,Int_t nEv)
402 : {
403 : //
404 : //Calculate pedestal for each pad
405 : //Arguments: nDDL-DDL number, name of the pedestal file and number of the read events
406 : //Retutns: kTRUE/kFALSE
407 : //
408 :
409 0 : 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?!
410 :
411 : Int_t feeOffset=196657;
412 0 : ofstream feeInput; feeInput.open(Form("%s",name2)); //write thr file for Fe2C
413 :
414 : Double_t mean=0,sigma=0, threshold=0;
415 : Double_t qs2m=0,qsm2=0;
416 0 : ofstream out; //to write the pedestal text files
417 : Int_t inhard;
418 : Int_t nEvPerPad=0;
419 : Int_t pedbin=0;
420 :
421 : Int_t abspad,ch,pc,pcx,pcy,chX,chY,fee;
422 0 : Int_t binSp[4]={0};
423 0 : out.open(name);
424 0 : out << Form("%8s %2d\n","RunNumber",(Int_t)fRunNum); //read run number
425 0 : out << Form("%8s %2d\n","LdcId" , fLdcId); //read LDC Id
426 0 : out << Form("%8s %2d\n","TimeStamp", fTimeStamp); //read time stamp
427 0 : out << Form("%8s %2d\n","TotNumEvt", nEv); //read number of total events processed
428 0 : out << Form("%8s %2d\n","TotDDLEvt", fnDDLInStream[nDDL]); //read number of bad events for DDL # nDDL processed
429 0 : out << Form("%8s %2d\n","NumBadEvt", fnDDLInStream[nDDL]-fnDDLOutStream[nDDL]); //read number of bad events for DDL # nDDL processed
430 0 : out << Form("%8s %2f\n","NBadE(%)", (fnDDLInStream[nDDL]-fnDDLOutStream[nDDL])*100.0/nEv); //read number of bad events (in %) for DDL # nDDL processed
431 0 : out << Form("%8s %d\n","#SigCut", fSigCut); //# of sigma cuts
432 :
433 0 : for(Int_t row = 1; row <= AliHMPIDRawStream::kNRows; row++){
434 0 : feeInput << Form("0xabcdabcd \n"); //before each row we write a marker to separate the rows within a DDL
435 :
436 :
437 0 : for(Int_t dil = 1; dil <= AliHMPIDRawStream::kNDILOGICAdd; dil++){
438 0 : for(Int_t pad = 0; pad < AliHMPIDRawStream::kNPadAdd; pad++){
439 : mean = 50;sigma = 100; //init maen and sigma to a low value
440 0 : nEvPerPad=fnpc[nDDL][row][dil][pad]; //check how many times the pad was read out
441 0 : abspad=AliHMPIDRawStream::GetPad(nDDL,row,dil,pad); //get the absolute oad coordinate
442 0 : ch=AliHMPIDParam::A2C(abspad); //get chamber number
443 0 : pc=AliHMPIDParam::A2P(abspad); //get PC number
444 0 : pcx=AliHMPIDParam::A2X(abspad); //get pad x in PC
445 0 : pcy=AliHMPIDParam::A2Y(abspad); //get pad y in PC
446 0 : chX = (pc%2)*AliHMPIDParam::kPadPcX+pcx; //get pad x in Ch
447 0 : chY = (pc/2)*AliHMPIDParam::kPadPcY+pcy; //get pad y in Ch
448 0 : binSp[0]=nDDL+1;binSp[1]=row;binSp[2]=dil;binSp[3]=pad+1; //set dead map coordinates for check
449 :
450 0 : if(nEvPerPad < 1 ) { //if the pad is bad then we assign 100 for the sigma and 50 for the mean
451 : mean = AliHMPIDParam::kPadMeanZeroCharge;
452 : sigma = AliHMPIDParam::kPadSigmaZeroCharge;
453 0 : fNumDeadPads++;
454 0 : }
455 0 : else if(fDeadMap->GetBinContent(binSp)>0) //check if channel is masked, if yes set maksed values
456 : {
457 : mean = AliHMPIDParam::kPadMeanMasked;
458 : sigma = AliHMPIDParam::kPadSigmaMasked;
459 0 : fNumMaskedPads++;
460 0 : }
461 : else{
462 0 : mean = fsq[nDDL][row][dil][pad]*1.0/nEvPerPad;
463 0 : qs2m = fsq2[nDDL][row][dil][pad]*1.0/nEvPerPad;
464 0 : qsm2 = TMath::Power(fsq[nDDL][row][dil][pad]*1.0/nEvPerPad,2);
465 0 : sigma = TMath::Sqrt(TMath::Abs(qs2m-qsm2));
466 : }
467 :
468 : //The electronics takes the 32bit int as: first 9 bits for the pedestal and the second 9 bits for threshold
469 0 : threshold = mean+fSigCut*sigma;
470 0 : if(mean > 511.0 || threshold > 511.0) {mean = AliHMPIDParam::kPadMeanMasked; threshold = AliHMPIDParam::kPadMeanMasked + 5.0 * AliHMPIDParam::kPadSigmaMasked; }
471 : //inhard=((Int_t(mean+fSigCut*sigma))<<9)+Int_t(mean); //right calculation, xchecked with Paolo 8/4/2008
472 0 : inhard=((Int_t(threshold))<<9)+Int_t(mean); //right calculation, xchecked with Paolo 8/4/2008
473 :
474 0 : out << Form("%2i %2i %2i %5.3f %5.3f %4.4x \n",row,dil,pad,mean,sigma,inhard);
475 0 : feeInput << Form("0x%4.4x\n",inhard);
476 :
477 : // fill histograms to be exported to AMORE
478 0 : fPedMeanMap[ch]->SetTitle(Form("PedMeanMap%d RunNum: %d",ch,fRunNum));
479 0 : fPedSigMap[ch]->SetTitle(Form("PedSigmaMap%d RunNum: %d",ch,fRunNum));
480 0 : fPedMeanMap[ch]->Fill(chX,chY,mean);
481 0 : fPedSigMap[ch]->Fill(chX,chY,sigma);
482 0 : if(nDDL%2==0) pedbin = (24-row)*2*480+(10-dil)*48+pad;
483 0 : if(nDDL%2!=0) pedbin = (row*2-1)*480+(10-dil)*48+pad;
484 0 : pedbin = pedbin - 3840*(pedbin/3840);
485 0 : fee=AliHMPIDRawStream::GetFee(nDDL,row);
486 0 : f1DPedMean[6*(nDDL/2)+fee]->SetTitle(Form("PedMean_Ch%d_FEE_%d RunNum: %d",ch,fee,fRunNum));
487 0 : f1DPedSigma[6*(nDDL/2)+fee]->SetTitle(Form("PedSigma_Ch%d_FEE_%d RunNum: %d",ch,fee,fRunNum));
488 0 : f1DPedMean[6*(nDDL/2)+fee]->Fill(pedbin,mean);
489 0 : f1DPedSigma[6*(nDDL/2)+fee]->Fill(pedbin,sigma);
490 :
491 : }//adr==pad
492 : //we have to write up to 64 not 48 in the DILOGIC since they are daisy chained!
493 : //offset and format is defined for the Fe2C code
494 0 : for(Int_t idd=0;idd<16;idd++) feeInput << Form("0x%4.4x\n",idd+feeOffset);
495 : }//dil
496 :
497 :
498 : }//row
499 0 : out.close(); //write pedestal file
500 0 : feeInput.close();
501 :
502 : return kTRUE;
503 0 : }//CaclPedestal()
504 : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|