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