]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HMPID/AliHMPIDPreprocessor.cxx
Protection on the possibility to have just one data point. In case the fit is not...
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDPreprocessor.cxx
index 7783b93170715622e75a185a6935c38586fc1dee..869c3a90a5caf625ef23b083df13154de2ff6aeb 100644 (file)
@@ -9,7 +9,7 @@
 #include <TTimeStamp.h>           //Initialize()
 #include <TF1.h>                  //Process()
 #include <TF2.h>                  //Process()
-//#include <TString.h>
+#include <TString.h>
 #include <TGraph.h>               //Process()
 #include <TMatrix.h>              //ProcPed()
 #include <TList.h>                //ProcPed()
@@ -24,6 +24,10 @@ ClassImp(AliHMPIDPreprocessor)
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 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()));
@@ -45,13 +49,13 @@ UInt_t AliHMPIDPreprocessor::Process(TMap* pMap)
   if(! pMap) {
     Log("HMPID - ERROR - Not map of DCS aliases for HMPID - ");             return kTRUE;   // error in the DCS mapped aliases
   }   
-  if (runType == "PEDESTAL_RUN"){
+  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 == "PHYSICS" ){
+  } else if ( runType=="STANDALONE" || runType=="PHYSICS"){
     if (!ProcDcs(pMap)){
        Log("HMPID - ERROR - DCS processing failed!!");                     return kTRUE;   // error in DCS processing
     } else {
@@ -81,76 +85,114 @@ Bool_t AliHMPIDPreprocessor::ProcDcs(TMap* pMap)
   TF2 thr("RthrCH4"  ,"3*10^(3.01e-3*x-4.72)+170745848*exp(-y*0.0162012)"             ,2000,3000,900,1200); 
   
   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 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(7);        arQthre.SetOwner(kTRUE);     //7  Qthre=f(time) one pre chamber
-  TObjArray arUserCut(7);    arUserCut.SetOwner(kTRUE);     //7  user cut in number of sigmas
+  TObjArray arQthre(42);       arQthre.SetOwner(kTRUE);     //42 Qthre=f(time) one per sector
   
   AliDCSValue *pVal; Int_t cnt=0;
+  
+  Double_t xP,yP;
 
-// 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;
+// evaluate Environment Pressure
+  
+  TObjArray *pPenv=(TObjArray*)pMap->GetValue("HMP_DET/HMP_ENV/HMP_ENV_PENV.actual.value");
+  if(pPenv->GetEntries()) {
+    TIter nextPenv(pPenv);
+    TGraph *pGrPenv=new TGraph; cnt=0;
+    while((pVal=(AliDCSValue*)nextPenv())) pGrPenv->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat());        //P env
+    if( cnt==1) {
+      pGrPenv->GetPoint(0,xP,yP);
+      new TF1("Penv",Form("%f",yP),fStartTime,fEndTime);
+    } else {
+      pGrPenv->Fit(new TF1("Penv","1000+x*[0]",fStartTime,fEndTime),"Q");
+    }
+    delete pGrPenv;
+  } else {AliWarning(" No Data Points from HMP_ENV_PENV.actual.value!");return kFALSE;}
     
+// evaluate Pressure
+  
   for(Int_t iCh=0;iCh<7;iCh++){                   
+    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));
+    if(pP->GetEntries()) {
+      TIter nextP(pP);    
+      TGraph *pGrP=new TGraph; cnt=0; 
+      while((pVal=(AliDCSValue*)nextP())) pGrP->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat());            //P
+      if( cnt==1) {
+        pGrP->GetPoint(0,xP,yP);
+        new TF1(Form("P%i",iCh),Form("%f",yP),fStartTime,fEndTime);
+      } else {
+        pGrP->Fit(new TF1(Form("P%i",iCh),"[0] + x*[1]",fStartTime,fEndTime),"Q");
+      }
+      delete pGrP;
+    } else {AliWarning(" No Data Points from HMP_MP0-6_GAS_PMWPC.actual.value!");return kFALSE;}
+    
 // evaluate High Voltage
-    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)); TIter nextHV(pHV);
-    TGraph *pGrHV=new TGraph; cnt=0;
-    while((pVal=(AliDCSValue*)nextHV())) pGrHV->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat());            //P
-    if( cnt!=0) pGrHV->Fit(new TF1(Form("HV%i",iCh),"2000+x*[0]",fStartTime,fEndTime),"Q");                       //clm: if no DCS map entry don't fit
-    delete pGrHV;
-
-// 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),"4 + x*[0]",fStartTime,fEndTime),"Q");                       //clm: if no DCS map entry don't fit
-    delete pGrP;
     
+    for(Int_t iSec=0;iSec<6;iSec++){
+      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));
+      if(pHV->GetEntries()) {
+        TIter nextHV(pHV);
+        TGraph *pGrHV=new TGraph; cnt=0;
+        while((pVal=(AliDCSValue*)nextHV())) pGrHV->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat());            //HV
+        if( cnt==1) {
+          pGrHV->GetPoint(0,xP,yP);
+          new TF1(Form("HV%i_%i",iCh,iSec),Form("%f",yP),fStartTime,fEndTime);               
+        } else {
+          pGrHV->Fit(new TF1(Form("HV%i_%i",iCh,iSec),"[0]+x*[1]",fStartTime,fEndTime),"Q");               
+        }
+        delete pGrHV;
+      } else {AliWarning(" No Data Points from HMP_MP0-6_SEC0-5_HV.actual.vMon!");return kFALSE;}
+     
 // evaluate Qthre
-    arQthre.AddAt(new TF1(Form("HMP_Qthre%i",iCh),Form("3*10^(3.01e-3*HV%i - 4.72)+170745848*exp(-(P%i+Penv)*0.0162012)",iCh),fStartTime,fEndTime),iCh);
-
+     
+      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 UserCut
-    Int_t nSigmaUserCut = 3;
-    TObject *pUserCut = new TObject();pUserCut->SetUniqueID(nSigmaUserCut);
-    arUserCut.AddAt(pUserCut,iCh);    
+// evaluate Temperatures: in and out of the radiators    
     
-// evaluate Temperatures    
+    // T in
     for(Int_t iRad=0;iRad<3;iRad++){
-      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      
-      
-      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;
+      TObjArray *pT1=(TObjArray*)pMap->GetValue(Form("HMP_DET/HMP_MP%i/HMP_MP%i_LIQ_LOOP.actual.sensors.Rad%iIn_Temp",iCh,iCh,iRad));  
+      if(pT1->GetEntries()) {
+        TIter nextT1(pT1);//Tin
+        TGraph *pGrT1=new TGraph; cnt=0;  while((pVal=(AliDCSValue*)nextT1())) pGrT1->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat()); //T inlet
+        if(cnt==1) { 
+          pGrT1->GetPoint(0,xP,yP);
+          new TF1(Form("Tin%i%i",iCh,iRad),Form("%f",yP),fStartTime,fEndTime);
+        } else {
+          pGrT1->Fit(new TF1(Form("Tin%i%i",iCh,iRad),"[0]+[1]*x+[2]*sin([3]*x)",fStartTime,fEndTime),"Q");
+        }
+        delete pGrT1;
+      } else {AliWarning(" No Data Points from HMP_MP0-6_LIQ_LOOP.actual.sensors.Rad0-2In_Temp!");return kFALSE;}
+    // T out
+      TObjArray *pT2=(TObjArray*)pMap->GetValue(Form("HMP_DET/HMP_MP%i/HMP_MP%i_LIQ_LOOP.actual.sensors.Rad%iOut_Temp",iCh,iCh,iRad)); 
+      if(pT2->GetEntries()) {
+        TIter nextT2(pT2);//Tout      
+        TGraph *pGrT2=new TGraph; cnt=0;  while((pVal=(AliDCSValue*)nextT2())) pGrT2->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat()); //T outlet 
+        if(cnt==1) { 
+          pGrT2->GetPoint(0,xP,yP);
+          new TF1(Form("Tou%i%i",iCh,iRad),Form("%f",yP),fStartTime,fEndTime);
+        } else {
+          pGrT2->Fit(new TF1(Form("Tou%i%i",iCh,iRad),"[0]+[1]*x+[2]*sin([3]*x)",fStartTime,fEndTime),"Q");
+        }
+        delete pGrT2;
+      } else {AliWarning(" No Data Points from HMP_MP0-6_LIQ_LOOP.actual.sensors.Rad0-2Out_Temp!");return kFALSE;}
        
-           
-//      arTmean.Add(pRadTempF);  
 // 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");
+  metaData.SetComment("HMPID preprocessor fills TObjArrays.");
 
-  stDcsStore =   Store("Calib","Qthre",&arQthre,&metaData,0,kTRUE) &&    // from DCS 
-                 Store("Calib","Nmean",&arNmean,&metaData,0,kTRUE) &&    // from DCS
-                 Store("Calib","UserCut",&arUserCut,&metaData,0,kTRUE);  //really not from DCS...a method ProcManual maybe needed
+  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");    
   }
@@ -161,61 +203,61 @@ Bool_t AliHMPIDPreprocessor::ProcPed()
 {
 // Process pedestal files and create 7 M(padx,pady)=sigma, one for each chamber
 // Arguments:
-//   Returns: kTRUE on success
+// Returns: kTRUE on success
   
   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
-  
-  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()));
-  
-  for(Int_t i=0;i<pLdc->GetEntries();i++) {//lists of LDCs
-
-    //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;
+  
+  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
+  
+  for(Int_t iddl=0;iddl<AliHMPIDRawStream::kNDDL;iddl++)            //retrieve the files from LDCs independently the DDL<->LDC connection
+  {
+    TList *pLdc=GetFileSources(kDAQ,Form("HmpidPedDdl%02i.txt",iddl)); //get list of LDC names containing id "pedestals"
+    if(!pLdc) {Log(Form("ERROR: Retrieval of sources for pedestals: HmpidPedDdl%02i.txt failed!",iddl));continue;}
+    
+    Log(Form("HMPID - Pedestal files to be read --> %i LDCs for HMPID",pLdc->GetEntries()));
+    for(Int_t i=0;i<pLdc->GetEntries();i++) {//lists of LDCs -- but in general we have 1 LDC for 1 ped file
+    TString fileName = GetFile(kDAQ,Form("HmpidPedDdl%02i.txt",iddl),((TObjString*)pLdc->At(i))->GetName());
+    if(fileName.Length()==0) {Log(Form("ERROR retrieving pedestal file: HmpidPedDdl%02i.txt!",iddl));continue;}
+  
+    //reading pedestal file
+    ifstream infile(fileName.Data()); 
+    
+    if(!infile.is_open()) {Log("No pedestal file found for HMPID,bye!");continue;}
+    TMatrix *pM=(TMatrixF*)aDaqSig.At(iddl/2);
   
-  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>>nSigCut; pM->SetUniqueID(nSigCut); //n. of pedestal distribution sigmas used to create zero suppresion table
+    infile>>tName>>runNumber;Printf("Xcheck: reading run %i",runNumber);
+    infile>>tName>>ldcId;
+    infile>>tName>>timeStamp;
+    infile>>tName>>nEv; 
+    infile>>tName>>nDdlEv;
+    infile>>tName>>nBadEv;
+    infile>>tName>>nBadEvPer;
+    infile>>tName>>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;      
-      //dig.Raw(ddl,r,d,a);
-      rs.Raw(ddl,r,d,a);
-      AliHMPIDDigit dig(rs.GetPad(ddl,r,d,a),rs.GetCharge(ddl,r,d,a));
+      infile>>dec>>r>>d>>a>>mean>>sigma>>hex>>hard;
+      if(rs.GetPad(iddl,r,d,a)>=0){                    //the GetPad returns meaningful abs pad number                                                          
+      dig.SetPad(rs.GetPad(iddl,r,d,a));
+      dig.SetQ((Int_t)mean);
       (*pM)(dig.PadChX(),dig.PadChY()) = sigma;
+      }
     }
     infile.close();
-    Log(Form("Pedestal file for DDL %i read successfully",ddl));
-  }
+    Log(Form("Pedestal file for DDL %i read successfully",iddl));
   
+  }//LDCs reading entries
+
+ }//DDL 
+
   AliCDBMetaData metaData; 
   metaData.SetBeamPeriod(0); 
   metaData.SetResponsible("AliHMPIDPreprocessor"); 
-  metaData.SetComment("SIMULATED");
-  
+  metaData.SetComment("HMPID processor fills TObjArrays.");  
   stPedStore = Store("Calib","DaqSig",&aDaqSig,&metaData,0,kTRUE);
-  
   if(!stPedStore) {
     Log("HMPID - failure to store PEDESTAL data results in OCDB");    
   }
@@ -230,4 +272,3 @@ Double_t ProcTrans()
   return eMean;
 }   
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++