#include "AliHMPIDDigit.h" //class header
#include <fstream>
#include <TTree.h>
+#include <TSystem.h>
+#include <TTimeStamp.h>
+
+
fnDDLInStream(0x0),
fnDDLOutStream(0x0),
fLargeHisto(kFALSE),
-fSelectDDL(0)
+fSelectDDL(0),
+fDaOut(0),
+fFeeIn(0)
{
//
//constructor
//Arguments: none
//Return: none
//
- fSigCut=3;
- for(Int_t iDDL=0; iDDL< AliHMPIDRawStream::kNDDL; iDDL++)
+
+ fSigCut=3; //the standard cut
+ fFeeIn="";
+ fDaOut="";
+
+
+ for(Int_t iDDL=0; iDDL< AliHMPIDRawStream::kNDDL; iDDL++)
{
for(Int_t ierr=0; ierr <AliHMPIDRawStream::kSumErr ; ierr++) {
fErr[iDDL][ierr]=0;
infile.close();
fSigCut=nSigCut;
}//SetSigCutFromFile()
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+void AliHMPIDCalib::SetSigCutFromShell(Char_t *env)
+{
+ //
+ //Set Sigma Cut from the Shell on the LDC, if the input file is not present default value is set!
+ //Arguments: none
+ //Returns: none
+ //
+ Int_t nSigCut=0;
+ TString ssc(gSystem->Getenv(env));
+ //make it nicer later...
+ if(ssc=="1") { nSigCut=1; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
+ else if(ssc=="2") { nSigCut=2; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
+ else if(ssc=="3") { nSigCut=3; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
+ else if(ssc=="4") { nSigCut=4; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
+ else if(ssc=="5") { nSigCut=5; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
+ else if(ssc=="6") { nSigCut=6; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
+ else if(ssc=="7") { nSigCut=7; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
+ else if(ssc=="8") { nSigCut=8; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
+ else if(ssc=="9") { nSigCut=9; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
+ else if(ssc=="10") { nSigCut=10; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
+ else if(ssc=="11") { nSigCut=11; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
+ else if(ssc=="12") { nSigCut=12; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
+ else if(ssc=="13") { nSigCut=13; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
+ else if(ssc=="14") { nSigCut=14; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
+ else if(ssc=="15") { nSigCut=15; Printf("DAQ Sigma Cut from shell is: %d",nSigCut);}
+ else { nSigCut=3; Printf("DAQ Sigma Cut from shell is too large set it back to default: %d",nSigCut);}
+
+ fSigCut=nSigCut;
+}//SetSigCutFromFile()
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void SetDaOutFromShell(Char_t* name); //Set out dir. of DA from Bash Shell
+void AliHMPIDCalib::SetFeeInFromShell(Char_t* env)
+{
+ //
+ //Set the path where the Fe2C is looking for the threshold files
+ //Arguments: none
+ //Returns: none
+ //
+ TString sFeeIn(gSystem->Getenv(env));
+ if(sFeeIn.Data()=="") sFeeIn="/local/home/hmpid/";
+ if(sFeeIn.EndsWith("/")) fFeeIn=sFeeIn;
+ else fFeeIn=Form("%s/",sFeeIn.Data());
+ if(gSystem->OpenDirectory(fFeeIn.Data())==0)
+ {
+ Printf("========== HMPID-DA WARNING: directory %s does not exist! Switching to /tmp! ==========",fFeeIn.Data());
+ fFeeIn="/tmp/";
+ }
+ Printf("HMPID_FEE_IN=%s",fFeeIn.Data());
+}
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void SetDaOutFromShell(Char_t* name); //Set out dir. of DA from Bash Shell
+void AliHMPIDCalib::SetDaOutFromShell(Char_t* env)
+{
+ //
+ //Set the standard path where the DA write the output
+ //Arguments: none
+ //Returns: none
+ //
+ TString sDaOut(gSystem->Getenv(env));
+ if(sDaOut=="") sDaOut="/local/home/hmpid/";
+ if(sDaOut.EndsWith("/")) fDaOut=sDaOut;
+ else fDaOut=Form("%s/",sDaOut.Data());
+
+ if(gSystem->OpenDirectory(fDaOut.Data())==0)
+ {
+ Printf("========== HMPID-DA WARNING: directory %s does not exist! Switching to /tmp! ==========",fDaOut.Data());
+ fDaOut="/tmp/";
+ }
+ Printf("HMPID_DA_OUT=%s",fDaOut.Data());
+}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void AliHMPIDCalib::InitHisto(Int_t q,Int_t histocnt,Char_t* name)
{
//Write decoding errors to a txt file
//Arguments: nDDL-DDL number, name of the error file and number of the read events
//Retutns: kTRUE/kFALSE
- //
-
+ //
if(faddl[nDDL]==kFALSE) return kFALSE; //if ddl is missing no error file is created
ofstream outerr; outerr.open(name); //open error file
outerr << Form("%8s %2d\n","RunNumber",(Int_t)fRunNum); //read run number
outerr.close(); //write error file
+
return kTRUE;
}//FillErrors()
//Retutns: kTRUE/kFALSE
//
-
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?!
+ Int_t ddlOffset=1536;
+ Int_t feeOffset=196657;
+ ofstream feeInput[24];
+
+ 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
+
Double_t mean=0,sigma=0;
Double_t qs2m=0,qsm2=0;
ofstream out; //to write the pedestal text files
out << Form("%8s %2.2d\n","#SigCut", fSigCut); //# of sigma cuts
for(Int_t row = 1; row <= AliHMPIDRawStream::kNRows; row++){
+ //write thr file for Fe2C
+
for(Int_t dil = 1; dil <= AliHMPIDRawStream::kNDILOGICAdd; dil++){
for(Int_t pad = 0; pad < AliHMPIDRawStream::kNPadAdd; pad++){
nEvPerPad=fnpc[nDDL][row][dil][pad];
-
if(nEvPerPad < 1 ) { //if the pad is bad then we assign 100 for the sigma and 50 for the mean
mean = 4000;
sigma = 1000;
qsm2 = TMath::Power(fsq[nDDL][row][dil][pad]*1.0/nEvPerPad,2);
sigma = TMath::Sqrt(TMath::Abs(qs2m-qsm2));
}
-
- inhard=((Int_t(mean))<<9)+Int_t(mean+3*sigma);
- out << Form("%2i %2i %2i %5.2f %5.2f %4.4x \n",row,dil,pad,mean,sigma,inhard);
-
- //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]);
-
-
+
+ inhard=((Int_t(mean+fSigCut*sigma))<<9)+Int_t(mean); //right calculation, xchecked with Paolo 8/4/2008
+ out << Form("%2i %2i %2i %5.3f %5.3f %4.4x \n",row,dil,pad,mean,sigma,inhard);
+
+ feeInput[row-1] << Form("0x%4.4x\n",inhard);
+ //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]);
}//adr
+
+ //we have to write up to 64 not 48 in the DILOGIC since they are daisy chained!
+ //offset and format is defined for the Fe2C code
+ for(Int_t idd=0;idd<16;idd++) feeInput[row-1] << Form("0x%4.4x\n",idd+feeOffset);
}//dil
+
+
}//row
out.close(); //write pedestal file
+ for(Int_t ir=0;ir<AliHMPIDRawStream::kNRows;ir++) feeInput[ir].close();
+
return kTRUE;
}//CaclPedestal()
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Bool_t AliHMPIDCalib::CalcPedestalPaolo(Int_t nDDL, Char_t* /*name*/, Int_t nEv)
+{
+ //
+ //Calculate pedestal for each pad
+ //Arguments: nDDL-DDL number, name of the pedestal file and number of the read events
+ //Retutns: kTRUE/kFALSE
+ //
+ //----------------- write files in the format of Paolo -----------------------
+ 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?!
+ Int_t ddlOffset=1536;
+ Int_t cnt=0;
+ Double_t mean1=0,sigma1=0;
+ Double_t qs2m1=0,qsm21=0;
+ Double_t mean2=0,sigma2=0;
+ Double_t qs2m2=0,qsm22=0;
+ Int_t nEvPerPad1=0;
+ Int_t nEvPerPad2=0;
+
+ ofstream pped[3];
+ for(Int_t iseg=1;iseg<4;iseg++) pped[iseg-1].open(Form("%sHmpidPed%d_%d.dat",fDaOut.Data(),nDDL+ddlOffset,iseg));
+
+ for(Int_t row = 1; row <= AliHMPIDRawStream::kNRows/2; row++){
+
+ //write header
+ pped[(row-1)/4]<<Form("ID_Nevt_NChan_Row_Row_P0_P1_S0_S1 \n");
+ 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);
+
+ cnt=0;
+ for(Int_t dil = 1; dil <= AliHMPIDRawStream::kNDILOGICAdd; dil++){
+ for(Int_t pad = 0; pad < AliHMPIDRawStream::kNPadAdd; pad++){
+
+ nEvPerPad1=fnpc[nDDL][2*row-1][dil][pad];
+ nEvPerPad2=fnpc[nDDL][2*row][dil][pad];
+
+ if(nEvPerPad1 < 1 ) { mean1 = 4000; sigma1 = 1000; }
+ if(nEvPerPad2 < 1 ) { mean2 = 4000; sigma2 = 1000; }
+
+ mean1 = fsq[nDDL][2*row-1][dil][pad]*1.0/nEvPerPad1;
+ qs2m1 = fsq2[nDDL][2*row-1][dil][pad]*1.0/nEvPerPad1;
+ qsm21 = TMath::Power(fsq[nDDL][2*row-1][dil][pad]*1.0/nEvPerPad1,2);
+ sigma1 = TMath::Sqrt(TMath::Abs(qs2m1-qsm21));
+
+ mean2 = fsq[nDDL][2*row][dil][pad]*1.0/nEvPerPad2;
+ qs2m2 = fsq2[nDDL][2*row][dil][pad]*1.0/nEvPerPad2;
+ qsm22 = TMath::Power(fsq[nDDL][2*row][dil][pad]*1.0/nEvPerPad2,2);
+ sigma2 = TMath::Sqrt(TMath::Abs(qs2m2-qsm22));
+
+ pped[(row-1)/4]<<Form("%d %3.3lf %3.3lf %3.3lf %3.3lf \n",cnt,mean1,sigma1,mean2,sigma2);cnt++;
+ }//pad
+ }//dil
+ }//row
+ for(Int_t ir=0;ir<3;ir++) {pped[ir].close(); }
+ return kTRUE;
+}//CalcPedestalPaolo()
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
//#include <TH1S.h>
#include <TMath.h>
#include <TFile.h>
+#include <TString.h>
#include "AliHMPIDParam.h"
#include "AliHMPIDRawStream.h"
void FillErrors(Int_t nDDL,Int_t nErrType, Int_t nErr); //Fill the errors from RawStream
void FillDDLCnt(Int_t iddl,Int_t inDDL, Int_t outDDL); //Fill the errors from RawStream
Bool_t CalcPedestal(Int_t nDDL, Char_t* name, Int_t nEv); //number of the DDL, name of the output file and the number of events processed
+ Bool_t CalcPedestalPaolo(Int_t nDDL, Char_t* name, Int_t nEv); //number of the DDL, name of the output file and the number of events processed
+
Bool_t WriteErrors(Int_t nDDL, Char_t* name, Int_t nEv); //number of the DDL, name of the output file and the number of events processed
void InitHisto(Int_t q,Int_t histocnt,Char_t* name); //Init the pad histograms
void FillHisto(Int_t histocnt,Int_t q); //Fill the ADC histograms
void SetRunParams(ULong_t runNum,Int_t timeStamp, Int_t ldcId); //Set Run Parameters such as Run Number, TimeStamp, LDCid
void SetSigCut(Int_t nSigCut) { fSigCut=nSigCut;} //Set Sigma Cuts from Setter
void SetSigCutFromFile(Char_t* name); //Set Sigma Cuts from File
+ void SetSigCutFromShell(Char_t* name); //Set Sigma Cuts from Bash Shell
+ void SetDaOutFromShell(Char_t* name); //Set out dir. of DA from Bash Shell
+ void SetFeeInFromShell(Char_t* name); //Set out dir. for Fe2C from Bash Shell
+
+ TString GetDaOutFromShell() {return fDaOut;} //Get out dir. of DA from Bash Shell
+ TString GetFeeInFromShell() {return fFeeIn;} //Get out dir. for Fe2C from Bash Shell
void SetWriteHistoPads(Bool_t isOn) {fWritePads=isOn;} //Set wether ADC histos of pads are written or not
void SetWriteHistoPads(Bool_t isOn,Bool_t isLarge,Int_t nDDL) {fWritePads=isOn;fLargeHisto=isLarge;fSelectDDL=nDDL;} //Set wether ADC histos of pads are written or not
Bool_t GetWritePads() const{return fWritePads;} //Set wether ADC histos of pads are written or not
Int_t *fnDDLOutStream; // if the DDL is in the raw data
Bool_t fLargeHisto; //Default is kFALSE.if kTRUE then write large pad histograms with 4093 bins!!!! Only if you have 2GB of RAM!!!
Int_t fSelectDDL; //Select the DDL to write for the in the large histograms. Only ONE at one time!
-
+
+ TString fDaOut; //Store the DA output files in this directory
+ TString fFeeIn; //
private:
AliHMPIDCalib(const AliHMPIDCalib& c); //dummy copy constructor
AliHMPIDCalib &operator=(const AliHMPIDCalib& c); //dummy assignment operator
#include "AliBitPacking.h"
//ROOT
-#include "TFile.h"
#include "TROOT.h"
+#include "TFile.h"
+#include "TSystem.h"
+#include "TString.h"
#include "TObject.h"
#include "TPluginManager.h"
monitorSetNowait();
monitorSetNoWaitNetworkTimeout(1000);
+ /* set local storage of ped files for Fe2C */
+
+
/* init the pedestal calculation */
AliHMPIDCalib *pCal=new AliHMPIDCalib();
/* Set the number of sigma cuts inside the file HmpidSigmaCut.txt on BOTH LDCs! */
/* If the file is NOT present then the default cut 3 will be used!*/
- pCal->SetSigCutFromFile("HmpidSigmaCut.txt");
+
+ //pCal->SetSigCutFromFile("HmpidSigmaCut.txt");
+ pCal->SetSigCutFromShell("HMPID_SIGMA_CUT"); //decision to make later: wether to use file or env variable...
+ pCal->SetDaOutFromShell("HMPID_DA_OUT"); //decision to make later: wether to use file or env variable...
+ pCal->SetFeeInFromShell("HMPID_FEE_IN"); //decision to make later: wether to use file or env variable...
+
+
/* ONLY set this option to kTRUE if you want to create the ADC dsitributions for all 161280 pads!!!!*/
/* kTRUE is not suggested for production mode b/c of the memory consumption! */
pCal->SetWriteHistoPads(kFALSE); //use this option for default production useage!!!
/* report progress */
daqDA_progressReport(90);
-
+ TString sDaOut=pCal->GetDaOutFromShell();
+
for(Int_t nDDL=0; nDDL < AliHMPIDRawStream::kNDDL; nDDL++) {
/* Calculate pedestal for the given ddl, if there is no ddl go t next */
- if(!pCal->CalcPedestal(nDDL,Form("./HmpidPedDdl%02i.txt",nDDL),iEvtNcal)) continue;
- if(!pCal->WriteErrors(nDDL,Form("./HmpidErrorsDdl%02i.txt",nDDL),iEvtNcal)) continue;
+ if(!pCal->CalcPedestal(nDDL,Form("%sHmpidPedDdl%02i.txt",sDaOut.Data(),nDDL),iEvtNcal)) continue;
+ /* to create pedestal file as Paolo uncomment the line */
+// if(!pCal->CalcPedestalPaolo(nDDL,Form("%sHmpidPedDdl%02i.txt",sDaOut.Data(),nDDL),iEvtNcal)) continue;
+ if(!pCal->WriteErrors(nDDL,Form("%sHmpidErrorsDdl%02i.txt",sDaOut.Data(),nDDL),iEvtNcal)) continue;
/* store the result file on FES */
- status=daqDA_FES_storeFile(Form("./HmpidPedDdl%02i.txt",nDDL),Form("HMPID_DA_Pedestals_ddl=%02i",nDDL));
+ status=daqDA_FES_storeFile(Form("%sHmpidPedDdl%02i.txt",sDaOut.Data(),nDDL),Form("HMPID_DA_Pedestals_ddl=%02i",nDDL));
if (status) { printf("Failed to export file : %d\n",status); }
- status=daqDA_FES_storeFile(Form("./HmpidErrorsDdl%02i.txt",nDDL),Form("HMPID_DA_Errors_ddl=%02i",nDDL));
+ status=daqDA_FES_storeFile(Form("%sHmpidErrorsDdl%02i.txt",sDaOut.Data(),nDDL),Form("HMPID_DA_Errors_ddl=%02i",nDDL));
if (status) { printf("Failed to export file : %d\n",status); }
}//nDDL