]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HMPID/AliHMPIDCalib.cxx
remove bad modules BEFORE cleaning digits
[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
21f61e25 19#include <fstream>
20#include <TTree.h>
0f1281b2 21
22
21f61e25 23
24ClassImp(AliHMPIDCalib)
25
26
27//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3c8e86a0 28AliHMPIDCalib::AliHMPIDCalib():
29faddl(0x0),
30fPadAdc(0x0),
31fIsPad(0x0),
32fFile(0x0),
33fLdcId(0),
34fTimeStamp(0),
35fRunNum(0),
36fSigCut(0),
37fWritePads(0)
21f61e25 38{
3e60bb92 39 //
40 //constructor
41 //
3c8e86a0 42 faddl = new Bool_t[AliHMPIDRawStream::kNDDL];
43 Int_t nPads = (AliHMPIDParam::kMaxCh+1)*(AliHMPIDParam::kMaxPcx+1)*(AliHMPIDParam::kMaxPcy+1);
44 fPadAdc=new TH1I*[nPads];
45 fIsPad=new Bool_t[nPads];
46 for(Int_t np=0;np<nPads;np++) {fPadAdc[np]=0x0; fIsPad[np]=kFALSE;}
47 fWritePads=kFALSE;
21f61e25 48 Init();
49}
50//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
51AliHMPIDCalib::~AliHMPIDCalib()
52{
3e60bb92 53 //
21f61e25 54 //destructor
3e60bb92 55 //
3c8e86a0 56 if (faddl) { delete [] faddl; faddl = 0x0; }
57 if (fPadAdc) {delete [] fPadAdc; fPadAdc=0x0; }
58 if (fIsPad) {delete [] fIsPad; fIsPad=0x0; }
59 if (fFile) {delete fFile; fFile=0x0; }
60 fLdcId=0;
61 fTimeStamp=0;
62 fRunNum=0;
63 fSigCut=0;
64 fWritePads=0;
65}//dtor
21f61e25 66//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
67void AliHMPIDCalib::Init()
68{
21f61e25 69 //
3e60bb92 70 //Init the q calc.
3c8e86a0 71 //Arguments: none
72 //Return: none
21f61e25 73 //
3c8e86a0 74 fSigCut=3;
75
76 for(Int_t iDDL=0; iDDL< AliHMPIDRawStream::kNDDL; iDDL++)
3e60bb92 77 {
3c8e86a0 78 for(Int_t ierr=0; ierr <AliHMPIDRawStream::kSumErr ; ierr++) {
79 fErr[iDDL][ierr]=0;
80 }
81
3e60bb92 82 faddl[iDDL]=kFALSE;
3c8e86a0 83 for(Int_t row = 1; row <=AliHMPIDRawStream::kNRows; row++){
84 for(Int_t dil = 1; dil <=AliHMPIDRawStream::kNDILOGICAdd; dil++){
85 for(Int_t pad = 0; pad < AliHMPIDRawStream::kNPadAdd; pad++){
86 fsq[iDDL][row][dil][pad]=0;
87 fsq2[iDDL][row][dil][pad]=0;
88 }//pad
89 }//dil
90 }//row
91 }//DDL
3e60bb92 92}//Init()
21f61e25 93//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3c8e86a0 94void AliHMPIDCalib::SetRunParams(ULong_t runNum,Int_t timeStamp, Int_t ldcId)
95{
96 //
97 //Set run parameters for the Pedestal and Error Files
98 //Arguments: run number, time stamp and LDC Id
99 //Returns: none
100 //
101 fRunNum=(Int_t)runNum;
102 fTimeStamp=timeStamp;
103 fLdcId=ldcId;
104}//SetRunParams()
105//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
106void AliHMPIDCalib::SetSigCutFromFile(Char_t* name)
21f61e25 107{
108 //
3c8e86a0 109 //Set Sigma Cut from the file on the LDC, if the input file is not present default value is set!
110 //Arguments: the name of the SigmaCut file on the LDC
111 //Returns: none
112 //
113 Int_t nSigCut=0;
114 ifstream infile(name);
115 if(!infile.is_open()) {fSigCut=3; return;}
116 while(!infile.eof())
117 {
118 infile>>nSigCut;
119 }
120 infile.close();
121 fSigCut=nSigCut;
122}//SetSigCutFromFile()
123//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
124void AliHMPIDCalib::InitHisto(Int_t q,Int_t histocnt,Char_t* name)
125{
126 //
127 //Init the pad histos. For one DDL we have 11520 pads. ONLY if ENABLED!
128 //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)
129 //Returns: none
130 //
131
132 fFile->cd();
133 Double_t lowbin,highbin=0;
134// Printf("InitHisto: histocnt: %d Name: %s",histocnt,name);
135 if(fIsPad[histocnt]==kTRUE) return;
136
137 lowbin=q-40.5; highbin=q+40.5;
138 fPadAdc[histocnt]=new TH1I(name,name,81,lowbin,highbin);
139 fPadAdc[histocnt]->Sumw2();
140 fIsPad[histocnt]=kTRUE;
141
142}//InitHisto()
143//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
144void AliHMPIDCalib::FillHisto(Int_t histocnt,Int_t q)
145{
146 //
147 //Fill the ADC histograms for each pad
148 //Arguments: q-charge, the absolute number of the histogram (AliHMPIDParam::kMaxCh+1)*(AliHMPIDParam::kMaxPcx+1)*(AliHMPIDParam::kMaxPcy+1)
149 //Returns: none
150 //
151 fFile->cd();
152 if(fIsPad[histocnt]==kFALSE) return;
153 fPadAdc[histocnt]->Fill(q);
154
155}//InitHisto()
156//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
157void AliHMPIDCalib::InitFile(Int_t ldcId)
158{
159 //
160 //Initialize the ADC histo output file (one per LDC)
161 //Arguments: LDC Id
162 //Returns: none
163 //
164 fFile=new TFile(Form("HmpidPadsOnLdc%2d.root",ldcId),"RECREATE");
165}//InitFile()
166//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
167void AliHMPIDCalib::CloseFile(Int_t /*ldcId*/)
168{
169 //
170 //Close the ADC histo output file (one per LDC)
171 //Arguments: LDC Id
172 //Returns: none
173 //
174 fFile->cd();
175 Int_t nPads = (AliHMPIDParam::kMaxCh+1)*(AliHMPIDParam::kMaxPcx+1)*(AliHMPIDParam::kMaxPcy+1);
176 for(Int_t np=0;np<nPads;np++) {if(fIsPad[np]==kTRUE) fPadAdc[np]->Write();}
177 fFile->Close();
178}//CloseFile()
179//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
180void AliHMPIDCalib::FillPedestal(Int_t abspad,Int_t q)
181{
182 //
183 //Called from the HMPIDda and fills the pedestal values
184 //Arguments: absulote pad number as from AliHMPIDParam and q-charge
185 //Returns: none
21f61e25 186 //
0f1281b2 187 Int_t nDDL=0, row=0, dil=0, adr=0;
188 //The decoding (abs. pad -> ddl,dil,...) is the same as in AliHMPIDDigit::Raw
189 Int_t y2a[6]={5,3,1,0,2,4};
190
3c8e86a0 191 nDDL= 2*AliHMPIDParam::A2C(abspad)+AliHMPIDParam::A2P(abspad)%2; //DDL# 0..13
192 Int_t tmp= 1+AliHMPIDParam::A2P(abspad)/2*8+AliHMPIDParam::A2Y(abspad)/6; //temp variable
193 row= (AliHMPIDParam::A2P(abspad)%2)? 25-tmp:tmp; //row r=1..24
194 dil= 1+AliHMPIDParam::A2X(abspad)/8; //DILOGIC
195 adr=y2a[AliHMPIDParam::A2Y(abspad)%6]+6*(AliHMPIDParam::A2X(abspad)%8); //ADDRESS 0..47
0f1281b2 196 //........... decoding done
3c8e86a0 197
198
3e60bb92 199 if(q>0) {
200 fsq[nDDL][row][dil][adr]+=q;
201 fsq2[nDDL][row][dil][adr]+=(q*q);
202 faddl[nDDL]=kTRUE;
203 }
204
3c8e86a0 205 Int_t histocnt=0;
206 histocnt=(nDDL)*11520+(row-1)*480+(dil-1)*48+adr; //Histo counter for a single DDL
207 if(fWritePads==kTRUE)
208 {
209 InitHisto(q,histocnt,Form("hPad_Ch_%d_Pc_%d_Px_%d_Py_%d",
210 AliHMPIDParam::A2C(abspad),AliHMPIDParam::A2P(abspad),AliHMPIDParam::A2X(abspad),AliHMPIDParam::A2Y(abspad)));
211 FillHisto(histocnt,q);
212 }
213
21f61e25 214}//FillPedestal()
215//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3c8e86a0 216void AliHMPIDCalib::FillErrors(Int_t nDDL,Int_t eType, Int_t nErr)
0f1281b2 217{
218 //
3c8e86a0 219 //Fill decoding errors from AliHMPIDRawStream
220 //Arguments: nDDL-DDL number, eType- error type as in AliHMPIDRawStream.h and the # of occurence for eType
221 //Retutns: none
0f1281b2 222 //
3c8e86a0 223 if(nErr<=0) return;
224 if(eType < 0 || eType> AliHMPIDRawStream::kSumErr ) return;
225 fErr[nDDL][eType]=fErr[nDDL][eType]+nErr;
0f1281b2 226
227}//FillErrors()
228//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3c8e86a0 229Bool_t AliHMPIDCalib::WriteErrors(Int_t nDDL, Char_t* name, Int_t nEv)
0f1281b2 230{
231 //
232 //Write decoding errors to a txt file
3c8e86a0 233 //Arguments: nDDL-DDL number, name of the error file and number of the read events
234 //Retutns: kTRUE/kFALSE
0f1281b2 235 //
236
3c8e86a0 237 if(faddl[nDDL]==kFALSE) return kFALSE; //if ddl is missing no error file is created
238 ofstream outerr; outerr.open(name); //open error file
239 outerr << Form("%6s %2d\n","RunNum",(Int_t)fRunNum); //read run number
240 outerr << Form("%6s %2d\n","LdcId" , fLdcId); //read LDC Id
241 outerr << Form("%6s %2d\n","TimeSt", fTimeStamp); //read time stamp
242 outerr << Form("%6s %2d\n","NumEvt", nEv); //read number of events processed
243
244 for(Int_t ierr=0; ierr <AliHMPIDRawStream::kSumErr; ierr++) outerr << Form("%2d\t",fErr[nDDL][ierr]); //write errors
245 outerr << Form("\n"); //last break
246 outerr.close(); //write error file
0f1281b2 247 return kTRUE;
248
249}//FillErrors()
250//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3c8e86a0 251Bool_t AliHMPIDCalib::CalcPedestal(Int_t nDDL, Char_t* name, Int_t nEv)
21f61e25 252{
253 //
254 //Calculate pedestal for each pad
3c8e86a0 255 //Arguments: nDDL-DDL number, name of the pedestal file and number of the read events
256 //Retutns: kTRUE/kFALSE
21f61e25 257 //
3c8e86a0 258
0f1281b2 259
260 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?!
3e60bb92 261 Float_t mean=0,sigma=0;
262 Float_t qs2m=0,qsm2=0;
21f61e25 263 ofstream out; //to write the pedestal text files
21f61e25 264 Int_t inhard;
3e60bb92 265 out.open(name);
3c8e86a0 266 //out << Form("%2d %2d\n",(Int_t)runNum,nEv);
267 out << Form("%6s %2d\n","RunNum",(Int_t)fRunNum);
268 out << Form("%6s %2d\n","LdcId" , fLdcId);
269 out << Form("%6s %2d\n","TimeSt", fTimeStamp);
270 out << Form("%6s %2d\n","NumEvt", nEv);
271 out << Form("%6s %2d\n","SigCut", fSigCut);
272 for(Int_t row = 1; row <= AliHMPIDRawStream::kNRows; row++){
273 for(Int_t dil = 1; dil <= AliHMPIDRawStream::kNDILOGICAdd; dil++){
274 for(Int_t pad = 0; pad < AliHMPIDRawStream::kNPadAdd; pad++){
3e60bb92 275
276 mean = fsq[nDDL][row][dil][pad]/1.0/nEv;
277
278 qs2m = fsq2[nDDL][row][dil][pad]/1.0/nEv;
279 qsm2 = TMath::Power(fsq[nDDL][row][dil][pad]/1.0/nEv,2);
280 sigma= TMath::Sqrt(qs2m-qsm2);
281
282 inhard=((Int_t(mean))<<9)+Int_t(mean+3*sigma);
283 out << Form("%2i %2i %2i %5.2f %5.2f %x\n",row,dil,pad,mean,sigma,inhard);
21f61e25 284 }//adr
285 }//dil
286 }//row
287 out.close(); //write pedestal file
288 return kTRUE;
289}//CaclPedestal()
290//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++