minors
[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()
520ee7b5 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{
b38ac33a 27// Initialize the parameter coming from AliPreprocessor
28// run -> run number
29// startTime -> starting time
30// endTime -> ending time
d3da6dc4 31 AliPreprocessor::Initialize(run, startTime, endTime);
ad712d2e 32
33 AliInfo(Form("HMPID started for Run %d \n\tStartTime %s \n\t EndTime %s", run,TTimeStamp(startTime).AsString(),TTimeStamp(endTime).AsString()));
34
d3da6dc4 35}
36//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
abb5f786 37UInt_t AliHMPIDPreprocessor::Process(TMap* pMap)
d3da6dc4 38{
56d2de52 39// Process all information from DCS and DAQ
40// Arguments: pMap- map of DCS aliases
ad712d2e 41// Returns: 0 on success or 1 on error (opposite to Store!)
af66844d 42
9cc1a411 43 TString runType = GetRunType();
ad712d2e 44 Log(Form(" AliHMPIDPreprocessor: RunType is %s",runType.Data()));
af66844d 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 }
520ee7b5 52 if (runType == "CALIBRATION"){
af66844d 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 }
520ee7b5 58 } else if ( runType=="STANDALONE" || runType=="PHYSICS"){
af66844d 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 }
9cc1a411 64 } else {
af66844d 65 Log("HMPID - Nothing to do with preprocessor for HMPID, bye!"); return kFALSE; // ok - nothing done
9cc1a411 66 }
56d2de52 67}//Process()
68//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
69Bool_t AliHMPIDPreprocessor::ProcDcs(TMap* pMap)
70{
abb5f786 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
a0e5c1b9 75// P=f(t), different for different chambers
56d2de52 76// Returns: kTRUE on success
d3da6dc4 77
ad712d2e 78 Bool_t stDcsStore=kFALSE;
79
37bac312 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
d3da6dc4 81
56d2de52 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
9cc1a411 87 TObjArray arTmean(21); arTmean.SetOwner(kTRUE); //21 Tmean=f(time) one per radiator
49881df7 88 TObjArray arPress(7); arPress.SetOwner(kTRUE); //7 Press=f(time) one per chamber
9cc1a411 89 TObjArray arNmean(21); arNmean.SetOwner(kTRUE); //21 Nmean=f(time) one per radiator
49881df7 90 TObjArray arQthre(42); arQthre.SetOwner(kTRUE); //42 Qthre=f(time) one per sector
d3da6dc4 91
56d2de52 92 AliDCSValue *pVal; Int_t cnt=0;
32d20573 93
94 Double_t xP,yP;
f357a568 95
32d20573 96// evaluate Environment Pressure
97
98 TObjArray *pPenv=(TObjArray*)pMap->GetValue("HMP_DET/HMP_ENV/HMP_ENV_PENV.actual.value");
7b2a49b9 99 Log(Form(" Environment Pressure data ---> %3i entries",pPenv->GetEntries()));
32d20573 100 if(pPenv->GetEntries()) {
101 TIter nextPenv(pPenv);
102 TGraph *pGrPenv=new TGraph; cnt=0;
103 while((pVal=(AliDCSValue*)nextPenv())) pGrPenv->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat()); //P env
104 if( cnt==1) {
105 pGrPenv->GetPoint(0,xP,yP);
106 new TF1("Penv",Form("%f",yP),fStartTime,fEndTime);
107 } else {
108 pGrPenv->Fit(new TF1("Penv","1000+x*[0]",fStartTime,fEndTime),"Q");
109 }
110 delete pGrPenv;
111 } else {AliWarning(" No Data Points from HMP_ENV_PENV.actual.value!");return kFALSE;}
abb5f786 112
ad712d2e 113// evaluate Pressure
32d20573 114
115 for(Int_t iCh=0;iCh<7;iCh++){
49881df7 116 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));
7b2a49b9 117 Log(Form(" Pressure for module %i data ---> %3i entries",iCh,pP->GetEntries()));
32d20573 118 if(pP->GetEntries()) {
119 TIter nextP(pP);
120 TGraph *pGrP=new TGraph; cnt=0;
121 while((pVal=(AliDCSValue*)nextP())) pGrP->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat()); //P
122 if( cnt==1) {
123 pGrP->GetPoint(0,xP,yP);
124 new TF1(Form("P%i",iCh),Form("%f",yP),fStartTime,fEndTime);
125 } else {
126 pGrP->Fit(new TF1(Form("P%i",iCh),"[0] + x*[1]",fStartTime,fEndTime),"Q");
127 }
128 delete pGrP;
129 } else {AliWarning(" No Data Points from HMP_MP0-6_GAS_PMWPC.actual.value!");return kFALSE;}
afe12692 130
49881df7 131// evaluate High Voltage
32d20573 132
133 for(Int_t iSec=0;iSec<6;iSec++){
134 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));
7b2a49b9 135 Log(Form(" HV for module %i and secto %i data ---> %3i entries",iCh,iSec,pHV->GetEntries()));
32d20573 136 if(pHV->GetEntries()) {
137 TIter nextHV(pHV);
138 TGraph *pGrHV=new TGraph; cnt=0;
139 while((pVal=(AliDCSValue*)nextHV())) pGrHV->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat()); //HV
140 if( cnt==1) {
141 pGrHV->GetPoint(0,xP,yP);
142 new TF1(Form("HV%i_%i",iCh,iSec),Form("%f",yP),fStartTime,fEndTime);
143 } else {
144 pGrHV->Fit(new TF1(Form("HV%i_%i",iCh,iSec),"[0]+x*[1]",fStartTime,fEndTime),"Q");
145 }
146 delete pGrHV;
147 } else {AliWarning(" No Data Points from HMP_MP0-6_SEC0-5_HV.actual.vMon!");return kFALSE;}
148
ad712d2e 149// evaluate Qthre
32d20573 150
151 arQthre.AddAt(new TF1(Form("HMP_QthreC%iS%i",iCh,iSec),
152 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);
49881df7 153 }
afe12692 154
32d20573 155// evaluate Temperatures: in and out of the radiators
156
157 // T in
d3da6dc4 158 for(Int_t iRad=0;iRad<3;iRad++){
32d20573 159 TObjArray *pT1=(TObjArray*)pMap->GetValue(Form("HMP_DET/HMP_MP%i/HMP_MP%i_LIQ_LOOP.actual.sensors.Rad%iIn_Temp",iCh,iCh,iRad));
7b2a49b9 160 Log(Form(" Temperatures for module %i inside data ---> %3i entries",iCh,pT1->GetEntries()));
32d20573 161 if(pT1->GetEntries()) {
162 TIter nextT1(pT1);//Tin
163 TGraph *pGrT1=new TGraph; cnt=0; while((pVal=(AliDCSValue*)nextT1())) pGrT1->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat()); //T inlet
164 if(cnt==1) {
165 pGrT1->GetPoint(0,xP,yP);
166 new TF1(Form("Tin%i%i",iCh,iRad),Form("%f",yP),fStartTime,fEndTime);
167 } else {
168 pGrT1->Fit(new TF1(Form("Tin%i%i",iCh,iRad),"[0]+[1]*x+[2]*sin([3]*x)",fStartTime,fEndTime),"Q");
169 }
170 delete pGrT1;
171 } else {AliWarning(" No Data Points from HMP_MP0-6_LIQ_LOOP.actual.sensors.Rad0-2In_Temp!");return kFALSE;}
172 // T out
173 TObjArray *pT2=(TObjArray*)pMap->GetValue(Form("HMP_DET/HMP_MP%i/HMP_MP%i_LIQ_LOOP.actual.sensors.Rad%iOut_Temp",iCh,iCh,iRad));
7b2a49b9 174 Log(Form(" Temperatures for module %i outside data ---> %3i entries",iCh,pT2->GetEntries()));
32d20573 175 if(pT2->GetEntries()) {
176 TIter nextT2(pT2);//Tout
177 TGraph *pGrT2=new TGraph; cnt=0; while((pVal=(AliDCSValue*)nextT2())) pGrT2->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat()); //T outlet
178 if(cnt==1) {
179 pGrT2->GetPoint(0,xP,yP);
180 new TF1(Form("Tou%i%i",iCh,iRad),Form("%f",yP),fStartTime,fEndTime);
181 } else {
182 pGrT2->Fit(new TF1(Form("Tou%i%i",iCh,iRad),"[0]+[1]*x+[2]*sin([3]*x)",fStartTime,fEndTime),"Q");
183 }
184 delete pGrT2;
185 } else {AliWarning(" No Data Points from HMP_MP0-6_LIQ_LOOP.actual.sensors.Rad0-2Out_Temp!");return kFALSE;}
43724042 186
ad712d2e 187// evaluate Mean Refractive Index
32d20573 188
56d2de52 189 arNmean.AddAt(new TF1(Form("HMP_Nmean%i-%i",iCh,iRad),"1.292",fStartTime,fEndTime),3*iCh+iRad); //Nmean=f(t)
32d20573 190
d3da6dc4 191 }//radiators loop
192 }//chambers loop
193
ad712d2e 194 AliCDBMetaData metaData;
195 metaData.SetBeamPeriod(0);
196 metaData.SetResponsible("AliHMPIDPreprocessor");
b7c14c1c 197 metaData.SetComment("HMPID preprocessor fills TObjArrays.");
ad712d2e 198
43601401 199 stDcsStore = Store("Calib","Qthre",&arQthre,&metaData) && // from DCS
65201c45 200 Store("Calib","Nmean",&arNmean,&metaData); // from DCS
ad712d2e 201 if(!stDcsStore) {
202 Log("HMPID - failure to store DCS data results in OCDB");
203 }
204 return stDcsStore;
d3da6dc4 205}//Process()
206//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56d2de52 207Bool_t AliHMPIDPreprocessor::ProcPed()
208{
209// Process pedestal files and create 7 M(padx,pady)=sigma, one for each chamber
210// Arguments:
48558cb5 211// Returns: kTRUE on success
ad712d2e 212
213 Bool_t stPedStore=kFALSE;
56d2de52 214 AliHMPIDDigit dig;
21f61e25 215 AliHMPIDRawStream rs;
56d2de52 216 Int_t nSigCut,r,d,a,hard; Float_t mean,sigma;
7c912209 217 Int_t runNumber,ldcId,timeStamp,nEv,nDdlEv,nBadEv; Char_t tName[10];
218 Float_t nBadEvPer;
48558cb5 219
220 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
221
222 for(Int_t iddl=0;iddl<AliHMPIDRawStream::kNDDL;iddl++) //retrieve the files from LDCs independently the DDL<->LDC connection
223 {
224 TList *pLdc=GetFileSources(kDAQ,Form("HmpidPedDdl%02i.txt",iddl)); //get list of LDC names containing id "pedestals"
225 if(!pLdc) {Log(Form("ERROR: Retrieval of sources for pedestals: HmpidPedDdl%02i.txt failed!",iddl));continue;}
9477d3cd 226
48558cb5 227 Log(Form("HMPID - Pedestal files to be read --> %i LDCs for HMPID",pLdc->GetEntries()));
228 for(Int_t i=0;i<pLdc->GetEntries();i++) {//lists of LDCs -- but in general we have 1 LDC for 1 ped file
229 TString fileName = GetFile(kDAQ,Form("HmpidPedDdl%02i.txt",iddl),((TObjString*)pLdc->At(i))->GetName());
230 if(fileName.Length()==0) {Log(Form("ERROR retrieving pedestal file: HmpidPedDdl%02i.txt!",iddl));continue;}
b7c14c1c 231
48558cb5 232 //reading pedestal file
70e96725 233 ifstream infile(fileName.Data());
234
48558cb5 235 if(!infile.is_open()) {Log("No pedestal file found for HMPID,bye!");continue;}
236 TMatrix *pM=(TMatrixF*)aDaqSig.At(iddl/2);
237
70e96725 238 infile>>tName>>runNumber;Printf("Xcheck: reading run %i",runNumber);
9477d3cd 239 infile>>tName>>ldcId;
240 infile>>tName>>timeStamp;
241 infile>>tName>>nEv;
7c912209 242 infile>>tName>>nDdlEv;
243 infile>>tName>>nBadEv;
244 infile>>tName>>nBadEvPer;
b7c14c1c 245 infile>>tName>>nSigCut; pM->SetUniqueID(nSigCut); //n. of pedestal distribution sigmas used to create zero suppresion table
56d2de52 246 while(!infile.eof()){
ec575c20 247 infile>>dec>>r>>d>>a>>mean>>sigma>>hex>>hard;
df8ff88a 248 if(rs.GetPad(iddl,r,d,a)>=0){ //the GetPad returns meaningful abs pad number
ec575c20 249 dig.SetPad(rs.GetPad(iddl,r,d,a));
250 dig.SetQ((Int_t)mean);
ab5ca5d6 251 (*pM)(dig.PadChX(),dig.PadChY()) = sigma;
df8ff88a 252 }
56d2de52 253 }
254 infile.close();
48558cb5 255 Log(Form("Pedestal file for DDL %i read successfully",iddl));
ad712d2e 256
48558cb5 257 }//LDCs reading entries
258
259 }//DDL
260
ad712d2e 261 AliCDBMetaData metaData;
262 metaData.SetBeamPeriod(0);
263 metaData.SetResponsible("AliHMPIDPreprocessor");
48558cb5 264 metaData.SetComment("HMPID processor fills TObjArrays.");
ad712d2e 265 stPedStore = Store("Calib","DaqSig",&aDaqSig,&metaData,0,kTRUE);
ad712d2e 266 if(!stPedStore) {
267 Log("HMPID - failure to store PEDESTAL data results in OCDB");
268 }
269 return stPedStore;
270
56d2de52 271}//ProcPed()
272//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
273Double_t ProcTrans()
274{
275// Process transparency monitoring data and calculates Emean
276 Double_t eMean=6.67786; //mean energy of photon defined by transperancy window
277 return eMean;
278}
279//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++