]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/AliHMPIDPreprocessor.cxx
869c3a90a5caf625ef23b083df13154de2ff6aeb
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDPreprocessor.cxx
1 #include "AliHMPIDPreprocessor.h" //header no includes
2 #include "AliHMPIDDigit.h"        //ProcPed()
3 #include "AliHMPIDRawStream.h"    //ProcPed()
4 #include <Riostream.h>            //ProcPed()  
5 #include <AliLog.h>               //all
6 #include <AliCDBMetaData.h>       //ProcPed(), ProcDcs()
7 #include <AliDCSValue.h>          //ProcDcs()
8 #include <TObjString.h>           //ProcDcs(), ProcPed()
9 #include <TTimeStamp.h>           //Initialize()
10 #include <TF1.h>                  //Process()
11 #include <TF2.h>                  //Process()
12 #include <TString.h>
13 #include <TGraph.h>               //Process()
14 #include <TMatrix.h>              //ProcPed()
15 #include <TList.h>                //ProcPed()
16 #include <TSystem.h>              //ProcPed()
17 //.
18 // HMPID Preprocessor base class
19 //.
20 //.
21 //.
22 ClassImp(AliHMPIDPreprocessor)
23
24 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
25 void AliHMPIDPreprocessor::Initialize(Int_t run, UInt_t startTime,UInt_t endTime)
26 {
27 // Initialize the parameter coming from AliPreprocessor
28 //  run -> run number
29 // startTime -> starting time 
30 // endTime   -> ending time
31   AliPreprocessor::Initialize(run, startTime, endTime);
32   
33   AliInfo(Form("HMPID started for Run %d \n\tStartTime %s \n\t  EndTime %s", run,TTimeStamp(startTime).AsString(),TTimeStamp(endTime).AsString()));
34
35 }
36 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
37 UInt_t AliHMPIDPreprocessor::Process(TMap* pMap)
38 {
39 // Process all information from DCS and DAQ
40 // Arguments: pMap- map of DCS aliases
41 // Returns: 0 on success or 1 on error (opposite to Store!)
42
43   TString runType = GetRunType();
44   Log(Form(" AliHMPIDPreprocessor: RunType is %s",runType.Data()));
45   
46 // start to check event type and procedures
47   
48   Log("HMPID - Process in Preprocessor started");
49   if(! pMap) {
50     Log("HMPID - ERROR - Not map of DCS aliases for HMPID - ");             return kTRUE;   // error in the DCS mapped aliases
51   }   
52   if (runType == "CALIBRATION"){
53     if (!ProcPed()){
54         Log("HMPID - ERROR - Pedestal processing failed!!");                return kTRUE;   // error in pedestal processing
55     } else {
56         Log("HMPID - Pedestal processing successful!!");                    return kFALSE;  // ok for pedestals
57     }
58   } else if ( runType=="STANDALONE" || runType=="PHYSICS"){
59     if (!ProcDcs(pMap)){
60         Log("HMPID - ERROR - DCS processing failed!!");                     return kTRUE;   // error in DCS processing
61     } else {
62         Log("HMPID - DCS processing successful!!");                         return kFALSE;  // ok for DCS
63     }
64   } else {
65     Log("HMPID - Nothing to do with preprocessor for HMPID, bye!");         return kFALSE;  // ok - nothing done
66   }
67 }//Process()
68 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
69 Bool_t AliHMPIDPreprocessor::ProcDcs(TMap* pMap)
70 {
71 // Process: 1. inlet and outlet C6F14 temperature, stores TObjArray of 21 TF1, where TF1 is Nmean=f(t), one per radiator
72 //          2. CH4 pressure and HV                 stores TObjArray of 7 TF1 where TF1 is thr=f(t), one per chamber
73 // Arguments: pDcsMap - map of structure "alias name" - TObjArray of AliDCSValue
74 // Assume that: HV is the same during the run for a given chamber, different chambers might have different HV
75 //              P=f(t), different for different chambers
76 // Returns: kTRUE on success  
77
78   Bool_t stDcsStore=kFALSE;
79
80   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
81   
82 // Qthr=f(HV,P) [V,mBar]  logA0=k*HV+b is taken from p. 64 TDR plot 2.59 for PC32 
83 //                           A0=f(P) is taken from DiMauro mail
84 // Qthr is estimated as 3*A0
85   TF2 thr("RthrCH4"  ,"3*10^(3.01e-3*x-4.72)+170745848*exp(-y*0.0162012)"             ,2000,3000,900,1200); 
86   
87   TObjArray arTmean(21);       arTmean.SetOwner(kTRUE);     //21 Tmean=f(time) one per radiator
88   TObjArray arPress(7);        arPress.SetOwner(kTRUE);     //7  Press=f(time) one per chamber
89   TObjArray arNmean(21);       arNmean.SetOwner(kTRUE);     //21 Nmean=f(time) one per radiator
90   TObjArray arQthre(42);       arQthre.SetOwner(kTRUE);     //42 Qthre=f(time) one per sector
91   
92   AliDCSValue *pVal; Int_t cnt=0;
93   
94   Double_t xP,yP;
95
96 // evaluate Environment Pressure
97   
98   TObjArray *pPenv=(TObjArray*)pMap->GetValue("HMP_DET/HMP_ENV/HMP_ENV_PENV.actual.value");
99   if(pPenv->GetEntries()) {
100     TIter nextPenv(pPenv);
101     TGraph *pGrPenv=new TGraph; cnt=0;
102     while((pVal=(AliDCSValue*)nextPenv())) pGrPenv->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat());        //P env
103     if( cnt==1) {
104       pGrPenv->GetPoint(0,xP,yP);
105       new TF1("Penv",Form("%f",yP),fStartTime,fEndTime);
106     } else {
107       pGrPenv->Fit(new TF1("Penv","1000+x*[0]",fStartTime,fEndTime),"Q");
108     }
109     delete pGrPenv;
110   } else {AliWarning(" No Data Points from HMP_ENV_PENV.actual.value!");return kFALSE;}
111     
112 // evaluate Pressure
113   
114   for(Int_t iCh=0;iCh<7;iCh++){                   
115     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));
116     if(pP->GetEntries()) {
117       TIter nextP(pP);    
118       TGraph *pGrP=new TGraph; cnt=0; 
119       while((pVal=(AliDCSValue*)nextP())) pGrP->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat());            //P
120       if( cnt==1) {
121         pGrP->GetPoint(0,xP,yP);
122         new TF1(Form("P%i",iCh),Form("%f",yP),fStartTime,fEndTime);
123       } else {
124         pGrP->Fit(new TF1(Form("P%i",iCh),"[0] + x*[1]",fStartTime,fEndTime),"Q");
125       }
126       delete pGrP;
127     } else {AliWarning(" No Data Points from HMP_MP0-6_GAS_PMWPC.actual.value!");return kFALSE;}
128     
129 // evaluate High Voltage
130     
131     for(Int_t iSec=0;iSec<6;iSec++){
132       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));
133       if(pHV->GetEntries()) {
134         TIter nextHV(pHV);
135         TGraph *pGrHV=new TGraph; cnt=0;
136         while((pVal=(AliDCSValue*)nextHV())) pGrHV->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat());            //HV
137         if( cnt==1) {
138           pGrHV->GetPoint(0,xP,yP);
139           new TF1(Form("HV%i_%i",iCh,iSec),Form("%f",yP),fStartTime,fEndTime);               
140         } else {
141           pGrHV->Fit(new TF1(Form("HV%i_%i",iCh,iSec),"[0]+x*[1]",fStartTime,fEndTime),"Q");               
142         }
143         delete pGrHV;
144       } else {AliWarning(" No Data Points from HMP_MP0-6_SEC0-5_HV.actual.vMon!");return kFALSE;}
145      
146 // evaluate Qthre
147      
148       arQthre.AddAt(new TF1(Form("HMP_QthreC%iS%i",iCh,iSec),
149           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);
150     }
151     
152 // evaluate Temperatures: in and out of the radiators    
153     
154     // T in
155     for(Int_t iRad=0;iRad<3;iRad++){
156       TObjArray *pT1=(TObjArray*)pMap->GetValue(Form("HMP_DET/HMP_MP%i/HMP_MP%i_LIQ_LOOP.actual.sensors.Rad%iIn_Temp",iCh,iCh,iRad));  
157       if(pT1->GetEntries()) {
158         TIter nextT1(pT1);//Tin
159         TGraph *pGrT1=new TGraph; cnt=0;  while((pVal=(AliDCSValue*)nextT1())) pGrT1->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat()); //T inlet
160         if(cnt==1) { 
161           pGrT1->GetPoint(0,xP,yP);
162           new TF1(Form("Tin%i%i",iCh,iRad),Form("%f",yP),fStartTime,fEndTime);
163         } else {
164           pGrT1->Fit(new TF1(Form("Tin%i%i",iCh,iRad),"[0]+[1]*x+[2]*sin([3]*x)",fStartTime,fEndTime),"Q");
165         }
166         delete pGrT1;
167       } else {AliWarning(" No Data Points from HMP_MP0-6_LIQ_LOOP.actual.sensors.Rad0-2In_Temp!");return kFALSE;}
168     // T out
169       TObjArray *pT2=(TObjArray*)pMap->GetValue(Form("HMP_DET/HMP_MP%i/HMP_MP%i_LIQ_LOOP.actual.sensors.Rad%iOut_Temp",iCh,iCh,iRad)); 
170       if(pT2->GetEntries()) {
171         TIter nextT2(pT2);//Tout      
172         TGraph *pGrT2=new TGraph; cnt=0;  while((pVal=(AliDCSValue*)nextT2())) pGrT2->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat()); //T outlet 
173         if(cnt==1) { 
174           pGrT2->GetPoint(0,xP,yP);
175           new TF1(Form("Tou%i%i",iCh,iRad),Form("%f",yP),fStartTime,fEndTime);
176         } else {
177           pGrT2->Fit(new TF1(Form("Tou%i%i",iCh,iRad),"[0]+[1]*x+[2]*sin([3]*x)",fStartTime,fEndTime),"Q");
178         }
179         delete pGrT2;
180       } else {AliWarning(" No Data Points from HMP_MP0-6_LIQ_LOOP.actual.sensors.Rad0-2Out_Temp!");return kFALSE;}
181         
182 // evaluate Mean Refractive Index
183       
184       arNmean.AddAt(new TF1(Form("HMP_Nmean%i-%i",iCh,iRad),"1.292",fStartTime,fEndTime),3*iCh+iRad); //Nmean=f(t)
185       
186     }//radiators loop
187   }//chambers loop
188   
189   AliCDBMetaData metaData; 
190   metaData.SetBeamPeriod(0); 
191   metaData.SetResponsible("AliHMPIDPreprocessor"); 
192   metaData.SetComment("HMPID preprocessor fills TObjArrays.");
193
194   stDcsStore =   Store("Calib","Qthre",&arQthre,&metaData) &&    // from DCS 
195                  Store("Calib","Nmean",&arNmean,&metaData);      // from DCS
196   if(!stDcsStore) {
197     Log("HMPID - failure to store DCS data results in OCDB");    
198   }
199   return stDcsStore;
200 }//Process()
201 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
202 Bool_t AliHMPIDPreprocessor::ProcPed()
203 {
204 // Process pedestal files and create 7 M(padx,pady)=sigma, one for each chamber
205 // Arguments:
206 // Returns: kTRUE on success
207   
208   Bool_t stPedStore=kFALSE;
209   AliHMPIDDigit dig;
210   AliHMPIDRawStream rs;
211   Int_t nSigCut,r,d,a,hard;  Float_t mean,sigma;
212   Int_t  runNumber,ldcId,timeStamp,nEv,nDdlEv,nBadEv;  Char_t tName[10]; 
213   Float_t nBadEvPer;
214   
215   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
216   
217   for(Int_t iddl=0;iddl<AliHMPIDRawStream::kNDDL;iddl++)            //retrieve the files from LDCs independently the DDL<->LDC connection
218   {
219     TList *pLdc=GetFileSources(kDAQ,Form("HmpidPedDdl%02i.txt",iddl)); //get list of LDC names containing id "pedestals"
220     if(!pLdc) {Log(Form("ERROR: Retrieval of sources for pedestals: HmpidPedDdl%02i.txt failed!",iddl));continue;}
221     
222     Log(Form("HMPID - Pedestal files to be read --> %i LDCs for HMPID",pLdc->GetEntries()));
223     for(Int_t i=0;i<pLdc->GetEntries();i++) {//lists of LDCs -- but in general we have 1 LDC for 1 ped file
224     TString fileName = GetFile(kDAQ,Form("HmpidPedDdl%02i.txt",iddl),((TObjString*)pLdc->At(i))->GetName());
225     if(fileName.Length()==0) {Log(Form("ERROR retrieving pedestal file: HmpidPedDdl%02i.txt!",iddl));continue;}
226   
227     //reading pedestal file
228     ifstream infile(fileName.Data()); 
229     
230     if(!infile.is_open()) {Log("No pedestal file found for HMPID,bye!");continue;}
231     TMatrix *pM=(TMatrixF*)aDaqSig.At(iddl/2);
232   
233     infile>>tName>>runNumber;Printf("Xcheck: reading run %i",runNumber);
234     infile>>tName>>ldcId;
235     infile>>tName>>timeStamp;
236     infile>>tName>>nEv; 
237     infile>>tName>>nDdlEv;
238     infile>>tName>>nBadEv;
239     infile>>tName>>nBadEvPer;
240     infile>>tName>>nSigCut; pM->SetUniqueID(nSigCut); //n. of pedestal distribution sigmas used to create zero suppresion table
241     while(!infile.eof()){
242       infile>>dec>>r>>d>>a>>mean>>sigma>>hex>>hard;
243       if(rs.GetPad(iddl,r,d,a)>=0){                     //the GetPad returns meaningful abs pad number                                                          
244       dig.SetPad(rs.GetPad(iddl,r,d,a));
245       dig.SetQ((Int_t)mean);
246       (*pM)(dig.PadChX(),dig.PadChY()) = sigma;
247       }
248     }
249     infile.close();
250     Log(Form("Pedestal file for DDL %i read successfully",iddl));
251   
252   }//LDCs reading entries
253
254  }//DDL 
255
256   AliCDBMetaData metaData; 
257   metaData.SetBeamPeriod(0); 
258   metaData.SetResponsible("AliHMPIDPreprocessor"); 
259   metaData.SetComment("HMPID processor fills TObjArrays.");  
260   stPedStore = Store("Calib","DaqSig",&aDaqSig,&metaData,0,kTRUE);
261   if(!stPedStore) {
262     Log("HMPID - failure to store PEDESTAL data results in OCDB");    
263   }
264   return stPedStore;
265   
266 }//ProcPed()  
267 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
268 Double_t ProcTrans()
269 {
270 // Process transparency monitoring data and calculates Emean  
271   Double_t eMean=6.67786;     //mean energy of photon defined  by transperancy window
272   return eMean;
273 }   
274 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++