]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HMPID/AliHMPIDCalib.cxx
AliEveTrackCounter, AliEveTrackCounterEditor
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDCalib.cxx
index 8cce6ffb8ecced87fcaf24abdb54d3ebc13302c5..139f95ad39de7778701353d8645052611d334c35 100644 (file)
 #include "AliHMPIDCalib.h" //class header
 #include "AliHMPIDParam.h" //class header
 #include "AliHMPIDRawStream.h" //class header
+#include "AliHMPIDDigit.h" //class header
 #include <fstream>
 #include <TTree.h>
+#include <TSystem.h>
+#include <TTimeStamp.h>
+
+
 
 
 
@@ -43,7 +48,7 @@ fWritePads(0),
 fnDDLInStream(0x0),
 fnDDLOutStream(0x0),
 fLargeHisto(kFALSE),
-fSelectDDL(0)  
+fSelectDDL(0)
 {
   //
   //constructor
@@ -178,8 +183,10 @@ void AliHMPIDCalib::Init()
   //Arguments: none
   //Return: none
   //
-    fSigCut=3;  
-    for(Int_t iDDL=0; iDDL< AliHMPIDRawStream::kNDDL; iDDL++) 
+    
+  fSigCut=3;  //the standard cut
+       
+  for(Int_t iDDL=0; iDDL< AliHMPIDRawStream::kNDDL; iDDL++) 
       {
          for(Int_t ierr=0; ierr <AliHMPIDRawStream::kSumErr ; ierr++) {
             fErr[iDDL][ierr]=0;
@@ -201,7 +208,7 @@ void AliHMPIDCalib::SetRunParams(ULong_t runNum,Int_t timeStamp, Int_t ldcId)
   fLdcId=ldcId;
 }//SetRunParams()
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-void AliHMPIDCalib::SetSigCutFromFile(Char_t* name)
+void AliHMPIDCalib::SetSigCutFromFile(TString hmpInFile)
 {
   //
   //Set Sigma Cut from the file on the LDC, if the input file is not present default value is set!
@@ -209,16 +216,18 @@ void AliHMPIDCalib::SetSigCutFromFile(Char_t* name)
   //Returns: none
   //
   Int_t nSigCut=0;
-  ifstream infile(name);
+  ifstream infile(hmpInFile.Data());
   if(!infile.is_open()) {fSigCut=3; return;}
   while(!infile.eof())
     {
     infile>>nSigCut;
   }
   infile.close();
+  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;}
+  Printf("DAQ Sigma Cut from DAQ DB is: %d",nSigCut);
   fSigCut=nSigCut; 
 }//SetSigCutFromFile()    
-//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 void AliHMPIDCalib::InitHisto(Int_t q,Int_t histocnt,Char_t* name)
 {
   //
@@ -283,26 +292,20 @@ void AliHMPIDCalib::FillPedestal(Int_t abspad,Int_t q)
 {
   //
   //Called from the HMPIDda and fills the pedestal values
-  //Arguments: absulote pad number as from AliHMPIDParam and q-charge
+  //Arguments: absolute pad number as from AliHMPIDParam and q-charge
   //Returns: none
   //
   if(q<0) AliFatal("Negative charge is read!!!!!!");
   
+  UInt_t w32;
   Int_t nDDL=0, row=0, dil=0, adr=0;
   //The decoding (abs. pad -> ddl,dil,...) is the same as in AliHMPIDDigit::Raw
-  Int_t y2a[6]={5,3,1,0,2,4};
-
-       nDDL=  2*AliHMPIDParam::A2C(abspad)+AliHMPIDParam::A2P(abspad)%2;              //DDL# 0..13
-  Int_t tmp=   1+AliHMPIDParam::A2P(abspad)/2*8+AliHMPIDParam::A2Y(abspad)/6;         //temp variable
-        row=   (AliHMPIDParam::A2P(abspad)%2)? tmp:25-tmp;                            //row r=1..24
-        dil=  1+AliHMPIDParam::A2X(abspad)/8;                                         //DILOGIC 
-        adr=y2a[AliHMPIDParam::A2Y(abspad)%6]+6*(AliHMPIDParam::A2X(abspad)%8);       //ADDRESS 0..47 
+  
+  AliHMPIDDigit dig(abspad,q);
+  dig.Raw(w32,nDDL,row,dil,adr);
+  
   //........... decoding done      
 
-//     if(row<1 || row > 24 || nDDL < 0 || nDDL > 13 || dil < 1 || dil > 10 || adr < 0 || adr >47) AliFatal(Form("ddl %d row %d dil %d adr %d",nDDL,row,dil,adr));
-            
-       
-        
      if(q>0) { 
         fsq[nDDL][row][dil][adr]+=q;
       fsq2[nDDL][row][dil][adr]+=q*q;
@@ -367,8 +370,7 @@ Bool_t AliHMPIDCalib::WriteErrors(Int_t nDDL, Char_t* name, Int_t nEv)
   //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
@@ -392,11 +394,12 @@ Bool_t AliHMPIDCalib::WriteErrors(Int_t nDDL, Char_t* name, Int_t nEv)
                                                                                                                                                                                        
                                                                
   outerr.close();                                                                                        //write error file
+  
   return kTRUE;
     
 }//FillErrors()
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-Bool_t AliHMPIDCalib::CalcPedestal(Int_t nDDL, Char_t* name, Int_t nEv)    
+Bool_t AliHMPIDCalib::CalcPedestal(Int_t nDDL, Char_t* name, Char_t *name2,Int_t nEv)    
 {
   //
   //Calculate pedestal for each pad  
@@ -404,11 +407,14 @@ Bool_t AliHMPIDCalib::CalcPedestal(Int_t nDDL, Char_t* name, Int_t nEv)
   //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 feeOffset=196657;
+  ofstream feeInput; feeInput.open(Form("%s",name2));      //write thr file for Fe2C
+  
   Double_t mean=0,sigma=0;
   Double_t qs2m=0,qsm2=0;
-  ofstream out;                                           //to write the pedestal text files
+  ofstream out;                                            //to write the pedestal text files
   Int_t inhard;
   Int_t nEvPerPad=0;
   out.open(name);
@@ -419,9 +425,12 @@ Bool_t AliHMPIDCalib::CalcPedestal(Int_t nDDL, Char_t* name, Int_t nEv)
   out << Form("%8s %2d\n","TotDDLEvt",      fnDDLInStream[nDDL]);                                     //read number of bad events for DDL # nDDL processed
   out << Form("%8s %2d\n","NumBadEvt",      fnDDLInStream[nDDL]-fnDDLOutStream[nDDL]);                //read number of bad events for DDL # nDDL processed
   out << Form("%8s %2f\n","NBadE(%)",       (fnDDLInStream[nDDL]-fnDDLOutStream[nDDL])*100.0/nEv);    //read number of bad events (in %) for DDL # nDDL processed
-  out << Form("%8s %2.2d\n","#SigCut",      fSigCut);                                                 //# of sigma cuts
+  out << Form("%8s %d\n","#SigCut",      fSigCut);                                                 //# of sigma cuts
       
   for(Int_t row = 1; row <= AliHMPIDRawStream::kNRows; row++){
+    feeInput << Form("0xabcdabcd \n");                                                                    //before each row we write a marker to separate the rows within a DDL                       
+    
+   
     for(Int_t dil = 1; dil <= AliHMPIDRawStream::kNDILOGICAdd; dil++){
       for(Int_t pad = 0; pad < AliHMPIDRawStream::kNPadAdd; pad++){
         
@@ -429,7 +438,6 @@ Bool_t AliHMPIDCalib::CalcPedestal(Int_t nDDL, Char_t* name, Int_t nEv)
         
         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;
@@ -440,18 +448,86 @@ Bool_t AliHMPIDCalib::CalcPedestal(Int_t nDDL, Char_t* name, Int_t nEv)
          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 << 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 << Form("0x%4.4x\n",idd+feeOffset);                 
       }//dil
+      
+      
     }//row
     out.close();                                          //write pedestal file
+    feeInput.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("HmpidPed%d_%d.dat",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; }
+        else 
+        {
+          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));
+        }
+        
+        if(nEvPerPad2 < 1 ) { mean2  = 4000; sigma2 = 1000; }
+        else
+        {        
+         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()
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+