]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HMPID/AliHMPIDPreprocessor.cxx
UserCut removed from OCDB (not more necessary). Now UserCut from RecoParam or defaults
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDPreprocessor.cxx
index 034e6a68efdc408f34ae6992d149f643eff8e0c1..f3f20302ab6912545eaa39a0e24b5c2209c9f4cd 100644 (file)
@@ -1,15 +1,19 @@
-#include "AliHMPIDPreprocessor.h" //header
-
-#include <Riostream.h>
-#include <AliCDBMetaData.h>
-#include <AliDCSValue.h>      
-#include <TObjString.h>       //Process()
-#include <TF1.h>              //Process()
-#include <TF2.h>              //Process()
-#include <TGraph.h>           //Process()
-#include <TMatrixF.h>         //Process()
-#include <AliLog.h>           //Process() 
-
+#include "AliHMPIDPreprocessor.h" //header no includes
+#include "AliHMPIDDigit.h"        //ProcPed()
+#include "AliHMPIDRawStream.h"    //ProcPed()
+#include <Riostream.h>            //ProcPed()  
+#include <AliLog.h>               //all
+#include <AliCDBMetaData.h>       //ProcPed(), ProcDcs()
+#include <AliDCSValue.h>          //ProcDcs()
+#include <TObjString.h>           //ProcDcs(), ProcPed()
+#include <TTimeStamp.h>           //Initialize()
+#include <TF1.h>                  //Process()
+#include <TF2.h>                  //Process()
+#include <TString.h>
+#include <TGraph.h>               //Process()
+#include <TMatrix.h>              //ProcPed()
+#include <TList.h>                //ProcPed()
+#include <TSystem.h>              //ProcPed()
 //.
 // HMPID Preprocessor base class
 //.
 //.
 ClassImp(AliHMPIDPreprocessor)
 
-char *AliHMPIDPreprocessor::fgP ="HMP_DET/HMP_MP%i/HMP_MP%i_GAS/HMP_MP%i_GAS_PMWC.actual.value";
-char *AliHMPIDPreprocessor::fgT1="HMP_DET/HMP_MP%i/HMP_MP%i_LIQ_LOOP.actual.sensors.Rad%iIn_Temp";
-char *AliHMPIDPreprocessor::fgT2="HMP_DET/HMP_MP%i/HMP_MP%i_LIQ_LOOP.actual.sensors.Rad%iOut_Temp";
-char *AliHMPIDPreprocessor::fgHV="HMP_DET/HMP_MP%i/HMP_MP%i_PW/HMP_MP%i_SEC0/HMP_MP%i_SEC0_HV.actual.vMon";
-
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 void AliHMPIDPreprocessor::Initialize(Int_t run, UInt_t startTime,UInt_t endTime)
 {
+// Initialize the parameter coming from AliPreprocessor
+//  run -> run number
+// startTime -> starting time 
+// endTime   -> ending time
   AliPreprocessor::Initialize(run, startTime, endTime);
+  
+  AliInfo(Form("HMPID started for Run %d \n\tStartTime %s \n\t  EndTime %s", run,TTimeStamp(startTime).AsString(),TTimeStamp(endTime).AsString()));
+
 }
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 UInt_t AliHMPIDPreprocessor::Process(TMap* pMap)
 {
+// Process all information from DCS and DAQ
+// Arguments: pMap- map of DCS aliases
+// Returns: 0 on success or 1 on error (opposite to Store!)
+
+  TString runType = GetRunType();
+  Log(Form(" AliHMPIDPreprocessor: RunType is %s",runType.Data()));
+  
+// start to check event type and procedures
+  
+  Log("HMPID - Process in Preprocessor started");
+  if(! pMap) {
+    Log("HMPID - ERROR - Not map of DCS aliases for HMPID - ");             return kTRUE;   // error in the DCS mapped aliases
+  }   
+  if (runType == "CALIBRATION"){
+    if (!ProcPed()){
+       Log("HMPID - ERROR - Pedestal processing failed!!");                return kTRUE;   // error in pedestal processing
+    } else {
+       Log("HMPID - Pedestal processing successful!!");                    return kFALSE;  // ok for pedestals
+    }
+  } else if ( runType=="STANDALONE" || runType=="PHYSICS"){
+    if (!ProcDcs(pMap)){
+       Log("HMPID - ERROR - DCS processing failed!!");                     return kTRUE;   // error in DCS processing
+    } else {
+       Log("HMPID - DCS processing successful!!");                         return kFALSE;  // ok for DCS
+    }
+  } else {
+    Log("HMPID - Nothing to do with preprocessor for HMPID, bye!");         return kFALSE;  // ok - nothing done
+  }
+}//Process()
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Bool_t AliHMPIDPreprocessor::ProcDcs(TMap* pMap)
+{
 // Process: 1. inlet and outlet C6F14 temperature, stores TObjArray of 21 TF1, where TF1 is Nmean=f(t), one per radiator
 //          2. CH4 pressure and HV                 stores TObjArray of 7 TF1 where TF1 is thr=f(t), one per chamber
 // Arguments: pDcsMap - map of structure "alias name" - TObjArray of AliDCSValue
 // Assume that: HV is the same during the run for a given chamber, different chambers might have different HV
 //              P=f(t), different for different chambers
-  TObjArray arDaqSig(14); arDaqSig.SetOwner(kTRUE);
-  for(Int_t iddl=0;iddl<14;iddl++){
-    arDaqSig.AddAt(new TObjArray(24),iddl);
-    for(Int_t row=1;row<=24;row++){
-      ((TObjArray*)arDaqSig.At(iddl))->Add(new TMatrixF(1,10,0,47));
-    }
-  }
-  TObjArray arSigCut(14); arSigCut.SetOwner(kTRUE);                                  //14  n. of sigmas for zero suppression
-  Int_t ddl,r,d,a,hard;
-  Float_t mean,sigma;
-  Int_t sigmaCut;
-  for(Int_t iddl=0;iddl<14;iddl++){
-    TObject *sigCut= new TObject; 
-    const char *name=GetFile(kDAQ,"pedestals",Form("DDL%i",iddl));                   //first analyse a set of pedestal files
-    ifstream infile(name);
-    //
-    infile>>sigmaCut;
-    sigCut->SetUniqueID(sigmaCut);arSigCut.AddAt(sigCut,iddl);
-    TObjArray *pTmp = (TObjArray*)arDaqSig.At(iddl);
-    TMatrixF *pM;
-    while(!infile.eof()){
-      infile>>dec>>ddl>>r>>d>>a>>mean>>sigma>>hex>>hard;
-      pM = (TMatrixF*)pTmp->At(r-1);
-      (*pM)(d,a) = sigma;
-    }
-    //
-    infile.close();
-    Printf("file %s read successfully",name);
-  }
+// Returns: kTRUE on success  
 
-  if(!pMap)  return 0;                    //no DCS map provided 
-  Double_t sor=0,eor=1500;
+  Bool_t stDcsStore=kFALSE;
 
-  TF2 idx("RidxC4F14","sqrt(1+0.554*(1239.84/x)^2/((1239.84/x)^2-5796)-0.0005*(y-20))",5.5 ,8.5 ,0  ,50);  //N=f(Ephot,T) [eV,grad C] DiMauro mail
-  TF2 thr("RthrCH4"  ,"x+170745848*exp(-y*0.0162012)"                                                      ,2000,3000,900,1200); //thr=f(HV,P)  [V,mBar]
-//  Double_t eMean=6.67786;                                                                                  //mean energy of photon defined  by transperancy window
+  TF2 idx("RidxC4F14","sqrt(1+0.554*(1239.84/x)^2/((1239.84/x)^2-5769)-0.0005*(y-20))",5.5 ,8.5 ,0  ,50);  //N=f(Ephot,T) [eV,grad C] DiMauro mail
   
-//  TObjArray arTmean(21); arTmean.SetOwner(kTRUE);     //21 Tmean=f(time) one per radiator
-//  TObjArray arPress(7);  arPress.SetOwner(kTRUE);     //7  Press=f(time) one pre chamber
-  TObjArray arNmean(21); arNmean.SetOwner (kTRUE);     //21 Nmean=f(time) one per radiator
-  TObjArray arQthre(7);  arQthre.SetOwner (kTRUE);     //7  Qthre=f(time) one pre chamber
+// Qthr=f(HV,P) [V,mBar]  logA0=k*HV+b is taken from p. 64 TDR plot 2.59 for PC32 
+//                           A0=f(P) is taken from DiMauro mail
+// Qthr is estimated as 3*A0
+  TF2 thr("RthrCH4"  ,"3*10^(3.01e-3*x-4.72)+170745848*exp(-y*0.0162012)"             ,2000,3000,900,1200); 
   
-//  AliDCSValue *pVal; Int_t cnt=0;
-    
-  for(Int_t iCh=0;iCh<7;iCh++){            
- //   TObjArray *pHV=(TObjArray*)pMap->GetValue(Form("HMP_DET/HMP_MP%i/HMP_MP%i_PW/HMP_MP%i_SEC0/HMP_MP%i_SEC0_HV.actual.vMon",iCh,iCh,iCh,iCh)); //HV
-//    pVal=(AliDCSValue*)pHV->At(0); Float_t hv=pVal->GetFloat();//HV    
+  TObjArray arTmean(21);       arTmean.SetOwner(kTRUE);     //21 Tmean=f(time) one per radiator
+  TObjArray arPress(7);        arPress.SetOwner(kTRUE);     //7  Press=f(time) one per chamber
+  TObjArray arNmean(21);       arNmean.SetOwner(kTRUE);     //21 Nmean=f(time) one per radiator
+  TObjArray arQthre(42);       arQthre.SetOwner(kTRUE);     //42 Qthre=f(time) one per sector
+  
+  AliDCSValue *pVal; Int_t cnt=0;
 
-//    TObjArray *pP =(TObjArray*)pMap->GetValue(Form(fP,iCh,iCh,iCh)); //P
-//    TGraph *pGrP; cnt=0;TIter nextp(pP); while((pVal=(AliDCSValue*)nextp())) pGrP->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat()); //P
-                                                                         
-//    TF1 *pFuP=new TF1(Form("P%i",iCh),"1005",sor,eor); 
-//    pGrP->Fit(pFuP,"Q"); delete pGrP;
-    TF1 *pFuQ=new TF1(Form("HMP_Qthre%i",iCh),"100",sor,eor);
-    arQthre.AddAt(pFuQ,iCh);    
+// evaluate environment pressure
+  TObjArray *pPenv=(TObjArray*)pMap->GetValue("HMP_DET/HMP_ENV/HMP_ENV_PENV.actual.value");TIter nextPenv(pPenv);
+  TGraph *pGrPenv=new TGraph; cnt=0;
+  while((pVal=(AliDCSValue*)nextPenv())) pGrPenv->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat());        //P env
+  if( cnt!=0) pGrPenv->Fit(new TF1("Penv","1000+x*[0]",fStartTime,fEndTime),"Q");                               //clm: if no DCS map entry don't fit
+  delete pGrPenv;
+    
+  for(Int_t iCh=0;iCh<7;iCh++){                   
+// evaluate Pressure
+    TObjArray *pP =(TObjArray*)pMap->GetValue(Form("HMP_DET/HMP_MP%i/HMP_MP%i_GAS/HMP_MP%i_GAS_PMWPC.actual.value",iCh,iCh,iCh));
+    TIter nextP(pP);    
+    TGraph *pGrP=new TGraph; cnt=0; 
+    while((pVal=(AliDCSValue*)nextP())) pGrP->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat());            //P
+    if( cnt!=0) pGrP->Fit(new TF1(Form("P%i",iCh),"[0] + x*[1]",fStartTime,fEndTime),"Q");                        //clm: if no DCS map entry don't fit
+    delete pGrP;
+    
+    for(Int_t iSec=0;iSec<6;iSec++){
+// evaluate High Voltage
+     TObjArray *pHV=(TObjArray*)pMap->GetValue(Form("HMP_DET/HMP_MP%i/HMP_MP%i_PW/HMP_MP%i_SEC%i/HMP_MP%i_SEC%i_HV.actual.vMon",iCh,iCh,iCh,iSec,iCh,iSec));TIter nextHV(pHV);
+     TGraph *pGrHV=new TGraph; cnt=0;
+     while((pVal=(AliDCSValue*)nextHV())) pGrHV->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat());            //HV
+     if( cnt!=0) pGrHV->Fit(new TF1(Form("HV%i_%i",iCh,iSec),"[0]+x*[1]",fStartTime,fEndTime),"Q");               //clm: if no DCS map entry don't fit
+     delete pGrHV;
+// evaluate Qthre
+     arQthre.AddAt(new TF1(Form("HMP_QthreC%iS%i",iCh,iSec),
+         Form("3*10^(3.01e-3*HV%i_%i - 4.72)+170745848*exp(-(P%i+Penv)*0.0162012)",iCh,iSec,iCh),fStartTime,fEndTime),6*iCh+iSec);
+    }
+    
+// evaluate Temperatures    
     for(Int_t iRad=0;iRad<3;iRad++){
-//      TObjArray *pT1=(TObjArray*)pMap->GetValue(Form(fT1,iCh,iCh,iRad)); //Tin
-//      TGraph *pGrT1=new TGraph; cnt=0; TIter next1(pT1); while((pVal=(AliDCSValue*)next1())) pGrT1->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat()); //inlet temperature
-//      pGrT1->Fit(new TF1(Form("Tin%i%i",iCh,iRad),"[0]+[1]*x+[2]*sin([3]*x)",sor,eor),"Q");       //now fit the temp graph 
+      TObjArray *pT1=(TObjArray*)pMap->GetValue(Form("HMP_DET/HMP_MP%i/HMP_MP%i_LIQ_LOOP.actual.sensors.Rad%iIn_Temp",iCh,iCh,iRad));  TIter nextT1(pT1);//Tin
+      TObjArray *pT2=(TObjArray*)pMap->GetValue(Form("HMP_DET/HMP_MP%i/HMP_MP%i_LIQ_LOOP.actual.sensors.Rad%iOut_Temp",iCh,iCh,iRad)); TIter nextT2(pT2);//Tout      
       
-//      TObjArray *pT2=(TObjArray*)pMap->GetValue(Form(fT2,iCh,iCh,iRad));//Tout      
-//      TGraph *pGrT2=new TGraph; cnt=0; TIter next2(pT2); while((pVal=(AliDCSValue*)next2())) pGrT2->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat()); //outlet temperature
-//      TF1*pFuT1=new TF1(Form("Tout%i%i",iCh,iRad),"13",sor,eor)      
-//      pGrT2->Fit(,"Q");       //now fit the temp graph 
+      TGraph *pGrT1=new TGraph; cnt=0;  while((pVal=(AliDCSValue*)nextT1())) pGrT1->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat()); //T inlet
+      if(cnt!=0) pGrT1->Fit(new TF1(Form("Tin%i%i",iCh,iRad),"[0]+[1]*x+[2]*sin([3]*x)",fStartTime,fEndTime),"Q");       //fit Tin graph -- clm: if DCS entry
       
+      TGraph *pGrT2=new TGraph; cnt=0;  while((pVal=(AliDCSValue*)nextT2())) pGrT2->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat()); //T outlet 
+      if(cnt!=0) pGrT2->Fit(new TF1(Form("Tou%i%i",iCh,iRad),"[0]+[1]*x+[2]*sin([3]*x)",fStartTime,fEndTime),"Q");       //fit Tout graph -- clm: if DCS entry
+            
+      delete pGrT1;  delete pGrT2;
+       
+           
 //      arTmean.Add(pRadTempF);  
-      TF1 *pFuN=new TF1(Form("HMP_Nmean%i-%i",iCh,iRad),"1.292",sor,eor); pFuN->SetLineColor(iRad+2); pFuN->SetLineWidth(1);
-      arNmean.AddAt(pFuN,3*iCh+iRad);
-//      delete pGrT1;  delete pGrT2;
+// evaluate Mean Refractive Index
+      arNmean.AddAt(new TF1(Form("HMP_Nmean%i-%i",iCh,iRad),"1.292",fStartTime,fEndTime),3*iCh+iRad); //Nmean=f(t)
     }//radiators loop
   }//chambers loop
   
-  AliCDBMetaData metaData; metaData.SetBeamPeriod(0); metaData.SetResponsible("AliHMPIDPreprocessor"); metaData.SetComment("SIMULATED");
+  AliCDBMetaData metaData; 
+  metaData.SetBeamPeriod(0); 
+  metaData.SetResponsible("AliHMPIDPreprocessor"); 
+  metaData.SetComment("SIMULATED");
+
+  stDcsStore =   Store("Calib","Qthre",&arQthre,&metaData) &&    // from DCS 
+                 Store("Calib","Nmean",&arNmean,&metaData);      // from DCS
+  if(!stDcsStore) {
+    Log("HMPID - failure to store DCS data results in OCDB");    
+  }
+  return stDcsStore;
+}//Process()
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Bool_t AliHMPIDPreprocessor::ProcPed()
+{
+// Process pedestal files and create 7 M(padx,pady)=sigma, one for each chamber
+// Arguments:
+//   Returns: kTRUE on success
   
-//  arQthre.Print();
-//  Store("Calib", "Press" , &arPress , &metaData); 
-//  Store("Calib", "Tmean" , &arTmean , &metaData);
+  Bool_t stPedStore=kFALSE;
+
+  TObjArray aDaqSig(7); aDaqSig.SetOwner(kTRUE); for(Int_t i=0;i<7;i++) aDaqSig.AddAt(new TMatrix(160,144),i); //TObjArray of 7 TMatrixF, m(padx,pady)=sigma
   
-  if(Store("Calib","Qthre"    ,&arQthre , &metaData,0,kTRUE) == kTRUE && 
-     Store("Calib","Nmean"    ,&arNmean , &metaData,0,kTRUE) == kTRUE &&   
-     Store("Calib","DaqSigCut",&arSigCut, &metaData,0,kTRUE) == kTRUE &&
-     Store("Calib","DaqSig"   ,&arDaqSig, &metaData,0,kTRUE) == kTRUE    ) return 0; //all OK
-  else
-    return 1;
+  TList *pLdc=GetFileSources(kDAQ,"pedestals"); //get list of LDC names containing id "pedestals"
+
+  if(!pLdc) {
+        Log("ERROR: Retrieval of sources for pedestals failed!");
+        return kFALSE;}
+
+  Log(Form("HMPID - Pedestal files to be read --> %i LDCs for HMPID",pLdc->GetEntries()));
   
-  //  AliInfo("End.");  
+  for(Int_t i=0;i<pLdc->GetEntries();i++) {//lists of LDCs
 
-}//Process()
-//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+    //gSystem->Exec(Form("tar xf %s",GetFile(kDAQ,"pedestals",((TObjString*)pLdc->At(i))->GetName()))); //untar pedestal files from current LDC
+  
+  TString fileName = GetFile(kDAQ,"pedestals", ((TObjString*)pLdc->At(i))->GetName());
+
+  if(fileName.Length()==0) {
+        Log("ERROR retrieving pedestal file!");
+        return kFALSE;  }
+
+  gSystem->Exec(Form("tar xf %s",fileName.Data()));
+
+ }
+
+  AliHMPIDDigit dig;
+  AliHMPIDRawStream rs;
+  Int_t nSigCut,r,d,a,hard;  Float_t mean,sigma;
+  Int_t  runNumber,ldcId,timeStamp,nEv,nDdlEv,nBadEv;  Char_t tName[10]; 
+  Float_t nBadEvPer;
+    
+  for(Int_t ddl=0;ddl<14;ddl++){  
+    ifstream infile(Form("HmpidPedDdl%02i.txt",ddl));
+    if(!infile.is_open()) {Log("No pedestal file found for HMPID,bye!");return kFALSE;}
+    TMatrix *pM=(TMatrixF*)aDaqSig.At(ddl/2);
+    infile>>tName>>runNumber;
+    infile>>tName>>ldcId;
+    infile>>tName>>timeStamp;
+    infile>>tName>>nEv; 
+    infile>>tName>>nDdlEv;
+    infile>>tName>>nBadEv;
+    infile>>tName>>nBadEvPer;
+    infile>>nSigCut; pM->SetUniqueID(nSigCut); //n. of pedestal distribution sigmas used to create zero suppresion table
+    while(!infile.eof()){
+      infile>>dec>>r>>d>>a>>mean>>sigma>>hex>>hard;      
+      AliHMPIDDigit dig(rs.GetPad(ddl,r,d,a),(Int_t)mean);
+      (*pM)(dig.PadChX(),dig.PadChY()) = sigma;
+    }
+    infile.close();
+    Log(Form("Pedestal file for DDL %i read successfully",ddl));
+  }
+  
+  AliCDBMetaData metaData; 
+  metaData.SetBeamPeriod(0); 
+  metaData.SetResponsible("AliHMPIDPreprocessor"); 
+  metaData.SetComment("SIMULATED");
   
+  stPedStore = Store("Calib","DaqSig",&aDaqSig,&metaData,0,kTRUE);
+  
+  if(!stPedStore) {
+    Log("HMPID - failure to store PEDESTAL data results in OCDB");    
+  }
+  return stPedStore;
+  
+}//ProcPed()  
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Double_t ProcTrans()
+{
+// Process transparency monitoring data and calculates Emean  
+  Double_t eMean=6.67786;     //mean energy of photon defined  by transperancy window
+  return eMean;
+}   
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++