Too wide range for charge.
[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 <TGraph.h>               //Process()
13 #include <TMatrix.h>              //ProcPed()
14 #include <TList.h>                //ProcPed()
15 #include <TSystem.h>              //ProcPed()
16 //.
17 // HMPID Preprocessor base class
18 //.
19 //.
20 //.
21 ClassImp(AliHMPIDPreprocessor)
22
23 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24 void AliHMPIDPreprocessor::Initialize(Int_t run, UInt_t startTime,UInt_t endTime)
25 {
26   AliPreprocessor::Initialize(run, startTime, endTime);
27   
28   AliInfo(Form("HMPID started for Run %d \n\tStartTime %s \n\t  EndTime %s", run,TTimeStamp(startTime).AsString(),TTimeStamp(endTime).AsString()));
29
30 }
31 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32 UInt_t AliHMPIDPreprocessor::Process(TMap* pMap)
33 {
34 // Process all information from DCS and DAQ
35 // Arguments: pMap- map of DCS aliases
36 // Returns: 0 on success or 1 on error (opposite to Store!)
37   
38   Log("HMPID - Process in Preprocessor started");
39   if(! pMap) {Log(" - Not map of DCS aliases for HMPID - ");return 1;}   
40   
41   TString runType = GetRunType();
42   Log(Form(" AliHMPIDPreprocessor: RunType is %s",runType.Data()));
43   Bool_t result1,result2;
44   if (runType == "PEDESTAL_RUN"){
45     result1 = ProcPed(); return !result1;
46   } else if ( runType == "PHYSICS" ){
47     result1 = ProcPed(); 
48     result2 = ProcDcs(pMap); return !(result1&&result2);
49   } else {
50     Log("HMPID - Nothing to do with preprocessor for HMPID, bye!");
51   return kFALSE;
52   }
53   
54 }//Process()
55 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56 Bool_t AliHMPIDPreprocessor::ProcDcs(TMap* pMap)
57 {
58 // Process: 1. inlet and outlet C6F14 temperature, stores TObjArray of 21 TF1, where TF1 is Nmean=f(t), one per radiator
59 //          2. CH4 pressure and HV                 stores TObjArray of 7 TF1 where TF1 is thr=f(t), one per chamber
60 // Arguments: pDcsMap - map of structure "alias name" - TObjArray of AliDCSValue
61 // Assume that: HV is the same during the run for a given chamber, different chambers might have different HV
62 //              P=f(t), different for different chambers
63 // Returns: kTRUE on success  
64
65   Bool_t stDcsStore=kFALSE;
66
67   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
68   
69 // Qthr=f(HV,P) [V,mBar]  logA0=k*HV+b is taken from p. 64 TDR plot 2.59 for PC32 
70 //                           A0=f(P) is taken from DiMauro mail
71 // Qthr is estimated as 3*A0
72   TF2 thr("RthrCH4"  ,"3*10^(3.01e-3*x-4.72)+170745848*exp(-y*0.0162012)"             ,2000,3000,900,1200); 
73   
74   TObjArray arTmean(21);       arTmean.SetOwner(kTRUE);     //21 Tmean=f(time) one per radiator
75   TObjArray arPress(7);        arPress.SetOwner(kTRUE);     //7  Press=f(time) one pre chamber
76   TObjArray arNmean(21);       arNmean.SetOwner(kTRUE);     //21 Nmean=f(time) one per radiator
77   TObjArray arQthre(7);        arQthre.SetOwner(kTRUE);     //7  Qthre=f(time) one pre chamber
78   TObjArray arUserCut(7);    arUserCut.SetOwner(kTRUE);     //7  user cut in number of sigmas
79   
80   AliDCSValue *pVal; Int_t cnt=0;
81     
82   for(Int_t iCh=0;iCh<7;iCh++){                   
83 // evaluate High Voltage
84     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);
85     TGraph *pGrHV=new TGraph; cnt=0;
86     while((pVal=(AliDCSValue*)nextHV())) pGrHV->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat());            //P
87     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
88     delete pGrHV;
89
90 // evaluate Pressure
91     TObjArray *pP =(TObjArray*)pMap->GetValue(Form("HMP_DET/HMP_MP%i/HMP_MP%i_GAS/HMP_MP%i_GAS_PMWC.actual.value"           ,iCh,iCh,iCh));    TIter nextP(pP);
92     TGraph *pGrP=new TGraph; cnt=0; 
93     while((pVal=(AliDCSValue*)nextP())) pGrP->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat());            //P
94     if( cnt!=0) pGrP->Fit(new TF1(Form("P%i",iCh),"1005+x*[0]",fStartTime,fEndTime),"Q");                       //clm: if no DCS map entry don't fit
95     delete pGrP;
96     
97 // evaluate Qthre
98     arQthre.AddAt(new TF1(Form("HMP_Qthre%i",iCh),Form("3*10^(3.01e-3*HV%i - 4.72)+170745848*exp(-P%i*0.0162012)",iCh),fStartTime,fEndTime),iCh);
99
100     
101 // evaluate UserCut
102     Int_t nSigmaUserCut = 3;
103     TObject *pUserCut = new TObject();pUserCut->SetUniqueID(nSigmaUserCut);
104     arUserCut.AddAt(pUserCut,iCh);    
105     
106 // evaluate Temperatures    
107     for(Int_t iRad=0;iRad<3;iRad++){
108       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
109       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      
110       
111       TGraph *pGrT1=new TGraph; cnt=0;  while((pVal=(AliDCSValue*)nextT1())) pGrT1->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat()); //T inlet
112       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
113       
114       TGraph *pGrT2=new TGraph; cnt=0;  while((pVal=(AliDCSValue*)nextT2())) pGrT2->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat()); //T outlet 
115       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
116             
117       delete pGrT1;  delete pGrT2;
118         
119             
120 //      arTmean.Add(pRadTempF);  
121 // evaluate Mean Refractive Index
122       arNmean.AddAt(new TF1(Form("HMP_Nmean%i-%i",iCh,iRad),"1.292",fStartTime,fEndTime),3*iCh+iRad); //Nmean=f(t)
123     }//radiators loop
124   }//chambers loop
125   
126   AliCDBMetaData metaData; 
127   metaData.SetBeamPeriod(0); 
128   metaData.SetResponsible("AliHMPIDPreprocessor"); 
129   metaData.SetComment("SIMULATED");
130
131   stDcsStore =   Store("Calib","Qthre",&arQthre,&metaData,0,kTRUE) &&    // from DCS 
132                  Store("Calib","Nmean",&arNmean,&metaData,0,kTRUE) &&    // from DCS
133                  Store("Calib","UserCut",&arUserCut,&metaData,0,kTRUE);  //really not from DCS...a method ProcManual maybe needed
134   if(!stDcsStore) {
135     Log("HMPID - failure to store DCS data results in OCDB");    
136   }
137   return stDcsStore;
138 }//Process()
139 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
140 Bool_t AliHMPIDPreprocessor::ProcPed()
141 {
142 // Process pedestal files and create 7 M(padx,pady)=sigma, one for each chamber
143 // Arguments:
144 //   Returns: kTRUE on success
145   
146   Bool_t stPedStore=kFALSE;
147
148   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
149   
150   TList *pLdc=GetFileSources(kDAQ,"pedestals"); //get list of LDC names containing id "pedestals"
151   Log(Form("HMPID - Pedestal files to be read --> %i LDCs for HMPID",pLdc->GetEntries()));
152   
153   for(Int_t i=0;i<pLdc->GetEntries();i++)//lists of LDCs
154     gSystem->Exec(Form("tar xf %s",GetFile(kDAQ,"pedestals",((TObjString*)pLdc->At(i))->GetName()))); //untar pedestal files from current LDC
155   
156   AliHMPIDDigit dig;
157   AliHMPIDRawStream rs;
158   Int_t nSigCut,r,d,a,hard;  Float_t mean,sigma;
159   
160   for(Int_t ddl=0;ddl<14;ddl++){  
161     ifstream infile(Form("HmpidPedDdl%02i.txt",ddl));
162     if(!infile.is_open()) {Log("No pedestal file found for HMPID,bye!");return kFALSE;}
163     TMatrix *pM=(TMatrixF*)aDaqSig.At(ddl/2);
164     infile>>nSigCut; pM->SetUniqueID(nSigCut); //n. of pedestal distribution sigmas used to create zero suppresion table
165     while(!infile.eof()){
166       infile>>dec>>r>>d>>a>>mean>>sigma>>hex>>hard;      
167       //dig.Raw(ddl,r,d,a);
168       rs.Raw(ddl,r,d,a);
169       AliHMPIDDigit dig(rs.GetPad(ddl,r,d,a),rs.GetCharge(ddl,r,d,a));
170       (*pM)(dig.PadChX(),dig.PadChY()) = sigma;
171     }
172     infile.close();
173     Log(Form("Pedestal file for DDL %i read successfully",ddl));
174   }
175   
176   AliCDBMetaData metaData; 
177   metaData.SetBeamPeriod(0); 
178   metaData.SetResponsible("AliHMPIDPreprocessor"); 
179   metaData.SetComment("SIMULATED");
180   
181   stPedStore = Store("Calib","DaqSig",&aDaqSig,&metaData,0,kTRUE);
182   
183   if(!stPedStore) {
184     Log("HMPID - failure to store PEDESTAL data results in OCDB");    
185   }
186   return stPedStore;
187   
188 }//ProcPed()  
189 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
190 Double_t ProcTrans()
191 {
192 // Process transparency monitoring data and calculates Emean  
193   Double_t eMean=6.67786;     //mean energy of photon defined  by transperancy window
194   return eMean;
195 }   
196 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
197