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():
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;}
50 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
51 AliHMPIDCalib::~AliHMPIDCalib()
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; }
66 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
67 void AliHMPIDCalib::Init()
76 for(Int_t iDDL=0; iDDL< AliHMPIDRawStream::kNDDL; iDDL++)
78 for(Int_t ierr=0; ierr <AliHMPIDRawStream::kSumErr ; ierr++) {
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;
93 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
94 void AliHMPIDCalib::SetRunParams(ULong_t runNum,Int_t timeStamp, Int_t ldcId)
97 //Set run parameters for the Pedestal and Error Files
98 //Arguments: run number, time stamp and LDC Id
101 fRunNum=(Int_t)runNum;
102 fTimeStamp=timeStamp;
105 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
106 void AliHMPIDCalib::SetSigCutFromFile(Char_t* name)
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
114 ifstream infile(name);
115 if(!infile.is_open()) {fSigCut=3; return;}
122 }//SetSigCutFromFile()
123 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
124 void AliHMPIDCalib::InitHisto(Int_t q,Int_t histocnt,Char_t* name)
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)
133 Double_t lowbin,highbin=0;
134 // Printf("InitHisto: histocnt: %d Name: %s",histocnt,name);
135 if(fIsPad[histocnt]==kTRUE) return;
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;
143 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
144 void AliHMPIDCalib::FillHisto(Int_t histocnt,Int_t q)
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)
152 if(fIsPad[histocnt]==kFALSE) return;
153 fPadAdc[histocnt]->Fill(q);
156 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
157 void AliHMPIDCalib::InitFile(Int_t ldcId)
160 //Initialize the ADC histo output file (one per LDC)
164 fFile=new TFile(Form("HmpidPadsOnLdc%2d.root",ldcId),"RECREATE");
166 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
167 void AliHMPIDCalib::CloseFile(Int_t /*ldcId*/)
170 //Close the ADC histo output file (one per LDC)
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();}
179 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
180 void AliHMPIDCalib::FillPedestal(Int_t abspad,Int_t q)
183 //Called from the HMPIDda and fills the pedestal values
184 //Arguments: absulote pad number as from AliHMPIDParam and q-charge
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};
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
196 //........... decoding done
200 fsq[nDDL][row][dil][adr]+=q;
201 fsq2[nDDL][row][dil][adr]+=(q*q);
206 histocnt=(nDDL)*11520+(row-1)*480+(dil-1)*48+adr; //Histo counter for a single DDL
207 if(fWritePads==kTRUE)
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);
215 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
216 void AliHMPIDCalib::FillErrors(Int_t nDDL,Int_t eType, Int_t nErr)
219 //Fill decoding errors from AliHMPIDRawStream
220 //Arguments: nDDL-DDL number, eType- error type as in AliHMPIDRawStream.h and the # of occurence for eType
224 if(eType < 0 || eType> AliHMPIDRawStream::kSumErr ) return;
225 fErr[nDDL][eType]=fErr[nDDL][eType]+nErr;
228 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
229 Bool_t AliHMPIDCalib::WriteErrors(Int_t nDDL, Char_t* name, Int_t nEv)
232 //Write decoding errors to a txt file
233 //Arguments: nDDL-DDL number, name of the error file and number of the read events
234 //Retutns: kTRUE/kFALSE
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
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
250 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
251 Bool_t AliHMPIDCalib::CalcPedestal(Int_t nDDL, Char_t* name, Int_t nEv)
254 //Calculate pedestal for each pad
255 //Arguments: nDDL-DDL number, name of the pedestal file and number of the read events
256 //Retutns: kTRUE/kFALSE
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?!
261 Float_t mean=0,sigma=0;
262 Float_t qs2m=0,qsm2=0;
263 ofstream out; //to write the pedestal text files
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++){
276 mean = fsq[nDDL][row][dil][pad]/1.0/nEv;
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);
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);
287 out.close(); //write pedestal file
290 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++