12d3f3a5d9486a654b7b2ad8194019c5ed57b553
[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   Bool_t statusNoise=kFALSE, statusDcs=kFALSE;
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   }//CALIBRATION
59   else if ( runType=="STANDALONE" || runType=="PHYSICS"){   
60    statusDcs=ProcDcs(pMap);
61    statusNoise=ProcNoiseMap();
62    if(!statusDcs || !statusNoise) { Log(Form("HMPID - ERROR - Noise Map(%d) and/or DCS(%d) processing failed!! (0=OK, 1=FAILED)",statusNoise,statusDcs)); return kTRUE; }  // error in Noise Map or DCS processing
63    else                           { Log("HMPID - Noise Map and DCS processing successful!!");  return kFALSE;}  // ok
64   }//STANDALONE or PHYSICS run
65    else {
66     Log("HMPID - Nothing to do with preprocessor for HMPID, bye!");         return kFALSE;  // ok - nothing done
67   }
68 }//Process()
69 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
70 Bool_t AliHMPIDPreprocessor::ProcNoiseMap()
71 {
72   //
73   // Goal: Process the Noise Map created by the HMP Physics DA to mask 
74   // noisy channels from reconstruction and follow changes in accepatnce
75   // eg. DDL turn on/off after PEDESTAL run and between PHYSICS runs.
76   // Returns kFALSE on success
77  
78   Bool_t stProcNoise=kFALSE;
79   TFile  *fNoiseFile;
80   TH2F   *hNoiseMap = 0x0;
81   
82   TList *pNoiseSource=GetFileSources(kDAQ,"HmpPhysicsDaNoiseMap.root"); //get list of DAQ source names containing id "HmpPhysicsDaNoiseMap" --> defined in HMPIDphysda.cxx
83   if(!pNoiseSource) {Log(Form("ERROR: Retrieval of sources for noise map: HmpPhysicsDaNoiseMap.root is failed!")); return stProcNoise;}
84   
85   TString noiseFile = GetFile(kDAQ,Form("HmpPhysicsDaNoiseMap.root"),((TObjString*)pNoiseSource->At(0))->GetName());
86   if(noiseFile.Length()==0) {Log(Form("ERROR retrieving noise map file: HmpPhysicsDaNoiseMap.root")); return stProcNoise;}
87   
88   fNoiseFile = TFile::Open(noiseFile.Data(),"read");
89   if(!fNoiseFile) {Log(Form("ERROR cannot open NoiseFile: %s!",noiseFile.Data())); return stProcNoise;}
90   hNoiseMap = (TH2F*) fNoiseFile->Get("hHmpNoiseMaps");
91   
92   AliCDBMetaData metaDataHisto;
93   metaDataHisto.SetBeamPeriod(0);
94   metaDataHisto.SetResponsible("AliHMPIDPreprocessor"); 
95   metaDataHisto.SetComment("AliHMPIDPreprocessor stores the Noise Map object as Reference Data.");
96   AliInfo("Storing Reference Data");
97   stProcNoise = Store("Calib","NoiseMap",hNoiseMap,&metaDataHisto,0,kTRUE);
98   if(!stProcNoise) {
99     Log("HMPID - failure to store Noise Map data results in OCDB");    
100   }
101   return stProcNoise;
102 }//ProcNoiseMap
103 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
104 Bool_t AliHMPIDPreprocessor::ProcDcs(TMap* pMap)
105 {
106 // Process: 1 (old). inlet and outlet C6F14 temperature, stores TObjArray of 21 TF1, where TF1 is Nmean=f(t), one per radiator
107 // Process: 1. inlet and outlet C6F14 temperature, stores TObjArray of 42 TF1, where TF1 are Tin and Tout per radiator
108 //             + one function for the mean energy photon (in total 43).
109 //          2. CH4 pressure and HV                 stores TObjArray of 7 TF1 where TF1 is thr=f(t), one per chamber
110 // Arguments: pDcsMap - map of structure "alias name" - TObjArray of AliDCSValue
111 // Assume that: HV is the same during the run for a given chamber, different chambers might have different HV
112 //              P=f(t), different for different chambers
113 // Returns: kTRUE on success  
114
115   Bool_t stDcsStore=kFALSE;
116
117 // Qthr=f(HV,P) [V,mBar]  logA0=k*HV+b is taken from p. 64 TDR plot 2.59 for PC32 
118 //                           A0=f(P) is taken from DiMauro mail
119 // Qthr is estimated as 3*A0
120
121   TF2 thr("RthrCH4"  ,"3*10^(3.01e-3*x-4.72)+170745848*exp(-y*0.0162012)"             ,2000,3000,900,1200); 
122   
123   TObjArray arNmean(43);       arNmean.SetOwner(kTRUE);     //42 Tin and Tout one per radiator + 1 for ePhotMean
124   TObjArray arQthre(42);       arQthre.SetOwner(kTRUE);     //42 Qthre=f(time) one per sector
125   
126   AliDCSValue *pVal; Int_t cnt=0;
127   
128   Double_t xP,yP;
129
130   TF1 **pTin  = new TF1*[21];
131   TF1 **pTout = new TF1*[21];
132
133 // evaluate Environment Pressure
134   
135   TObjArray *pPenv=(TObjArray*)pMap->GetValue("HMP_DET/HMP_ENV/HMP_ENV_PENV.actual.value");
136   if(!pPenv) {
137     AliWarning(" No Data Points from HMP_ENV_PENV.actual.value!");
138     return kFALSE;
139   } else {
140     Log(Form(" Environment Pressure data              ---> %3i entries",pPenv->GetEntries()));
141     if(pPenv->GetEntries()) {
142       TIter nextPenv(pPenv);
143       TGraph *pGrPenv=new TGraph; cnt=0;
144       while((pVal=(AliDCSValue*)nextPenv())) pGrPenv->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat());        //P env
145       if( cnt==1) {
146         pGrPenv->GetPoint(0,xP,yP);
147         new TF1("Penv",Form("%f",yP),fStartTime,fEndTime);
148       } else {
149         pGrPenv->Fit(new TF1("Penv","1000+x*[0]",fStartTime,fEndTime),"Q");
150       }
151       delete pGrPenv;
152     } else {AliWarning(" No Data Points from HMP_ENV_PENV.actual.value!");return kFALSE;}
153   }  
154 // evaluate Pressure
155   
156   for(Int_t iCh=0;iCh<7;iCh++){                   
157     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));
158     if(!pP) {
159       AliWarning(Form(" No Data Points from HMP_MP%1i_GAS_PMWPC.actual.value!",iCh));
160       return kFALSE;
161     } else {
162         Log(Form(" Pressure for module %i data             ---> %3i entries",iCh,pP->GetEntries()));
163       if(pP->GetEntries()) {
164         TIter nextP(pP);    
165         TGraph *pGrP=new TGraph; cnt=0; 
166         while((pVal=(AliDCSValue*)nextP())) pGrP->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat());            //P
167         if( cnt==1) {
168           pGrP->GetPoint(0,xP,yP);
169           new TF1(Form("P%i",iCh),Form("%f",yP),fStartTime,fEndTime);
170         } else {
171           pGrP->Fit(new TF1(Form("P%i",iCh),"[0] + x*[1]",fStartTime,fEndTime),"Q");
172         }
173         delete pGrP;
174       } else {AliWarning(" No Data Points from HMP_MP0-6_GAS_PMWPC.actual.value!");return kFALSE;}
175     }
176     
177 // evaluate High Voltage
178     
179    for(Int_t iSec=0;iSec<6;iSec++){
180       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));
181       if(!pHV) {
182         AliWarning(Form(" No Data Points from HMP_MP%1i_SEC%1i_HV.actual.vMon!",iCh,iSec));
183         return kFALSE;
184       } else {
185         Log(Form(" HV for module %i and secto %i data       ---> %3i entries",iCh,iSec,pHV->GetEntries()));
186         if(pHV->GetEntries()) {
187           TIter nextHV(pHV);
188           TGraph *pGrHV=new TGraph; cnt=0;
189           while((pVal=(AliDCSValue*)nextHV())) pGrHV->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat());            //HV
190           if( cnt==1) {
191             pGrHV->GetPoint(0,xP,yP);
192             new TF1(Form("HV%i_%i",iCh,iSec),Form("%f",yP),fStartTime,fEndTime);               
193           } else {
194             pGrHV->Fit(new TF1(Form("HV%i_%i",iCh,iSec),"[0]+x*[1]",fStartTime,fEndTime),"Q");               
195           }
196           delete pGrHV;
197         } else {AliWarning(" No Data Points from HMP_MP0-6_SEC0-5_HV.actual.vMon!");return kFALSE;}
198       }   
199 // evaluate Qthre
200      
201       arQthre.AddAt(new TF1(Form("HMP_QthreC%iS%i",iCh,iSec),
202           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);
203
204      //arQthre.AddAt(new TF1(Form("HMP_QthreC%iS%i",iCh,iSec),"100",fStartTime,fEndTime),6*iCh+iSec);  
205     }
206 // evaluate Temperatures: in and out of the radiators    
207     // T in
208     for(Int_t iRad=0;iRad<3;iRad++){
209       
210       pTin[3*iCh+iRad]  = new TF1(Form("Tin%i%i" ,iCh,iRad),"[0]+[1]*x",fStartTime,fEndTime);
211       pTout[3*iCh+iRad] = new TF1(Form("Tout%i%i",iCh,iRad),"[0]+[1]*x",fStartTime,fEndTime);          
212
213       //pTin[3*iCh+iRad]  = new TF1(Form("Tin%i%i" ,iCh,iRad),"21",fStartTime,fEndTime);
214       //pTout[3*iCh+iRad] = new TF1(Form("Tout%i%i",iCh,iRad),"22",fStartTime,fEndTime);          
215                   
216     TObjArray *pT1=(TObjArray*)pMap->GetValue(Form("HMP_DET/HMP_MP%i/HMP_MP%i_LIQ_LOOP.actual.sensors.Rad%iIn_Temp",iCh,iCh,iRad));
217       if(!pT1) {
218         AliWarning(Form(" No Data Points from HMP_MP%1i_LIQ_LOOP.actual.sensors.Rad%1iIn_Temp!",iCh,iRad));
219         return kFALSE;
220       } else {
221         Log(Form(" Temperatures for module %i inside data  ---> %3i entries",iCh,pT1->GetEntries()));
222         if(pT1->GetEntries()) {
223           TIter nextT1(pT1);//Tin
224           TGraph *pGrT1=new TGraph; cnt=0;  while((pVal=(AliDCSValue*)nextT1())) pGrT1->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat()); //T inlet
225           if(cnt==1) { 
226             pGrT1->GetPoint(0,xP,yP);
227             pTin[3*iCh+iRad]->SetParameter(0,yP);
228             pTin[3*iCh+iRad]->SetParameter(1,0);
229           } else {
230             pGrT1->Fit(pTin[3*iCh+iRad],"Q");
231           }
232           delete pGrT1;
233         } else {AliWarning(" No Data Points from HMP_MP0-6_LIQ_LOOP.actual.sensors.Rad0-2In_Temp!");return kFALSE;}
234       }
235     // T out
236       TObjArray *pT2=(TObjArray*)pMap->GetValue(Form("HMP_DET/HMP_MP%i/HMP_MP%i_LIQ_LOOP.actual.sensors.Rad%iOut_Temp",iCh,iCh,iRad)); 
237       if(!pT2) {
238         AliWarning(Form(" No Data Points from HMP_MP%1i_LIQ_LOOP.actual.sensors.Rad%1iOut_Temp!",iCh,iRad));
239         return kFALSE;
240       } else {
241         Log(Form(" Temperatures for module %i outside data ---> %3i entries",iCh,pT2->GetEntries()));
242         if(pT2->GetEntries()) {
243           TIter nextT2(pT2);//Tout      
244           TGraph *pGrT2=new TGraph; cnt=0;  while((pVal=(AliDCSValue*)nextT2())) pGrT2->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat()); //T outlet 
245           if(cnt==1) { 
246             pGrT2->GetPoint(0,xP,yP);
247             pTout[3*iCh+iRad]->SetParameter(0,yP);
248             pTout[3*iCh+iRad]->SetParameter(1,0);
249           } else {
250             pGrT2->Fit(pTout[3*iCh+iRad],"Q");
251           }
252           delete pGrT2;
253         } else {AliWarning(" No Data Points from HMP_MP0-6_LIQ_LOOP.actual.sensors.Rad0-2Out_Temp!");return kFALSE;}
254       }
255         
256 // evaluate Mean Refractive Index
257       
258       arNmean.AddAt(pTin[3*iCh+iRad] ,6*iCh+2*iRad  ); //Tin =f(t)
259       arNmean.AddAt(pTout[3*iCh+iRad],6*iCh+2*iRad+1); //Tout=f(t)
260       
261     }//radiators loop
262   }//chambers loop
263   
264   Double_t eMean = ProcTrans(pMap);
265   arNmean.AddAt(new TF1("HMP_PhotEmean",Form("%f",eMean),fStartTime,fEndTime),42); //Photon energy mean
266     
267   AliCDBMetaData metaData; 
268   metaData.SetBeamPeriod(0); 
269   metaData.SetResponsible("AliHMPIDPreprocessor"); 
270   metaData.SetComment("HMPID preprocessor fills TObjArrays.");
271
272   stDcsStore =   Store("Calib","Qthre",&arQthre,&metaData,0,kTRUE) &&    // from DCS  0,kTRUE generates the file from Run 0 to Run 99999999
273                  Store("Calib","Nmean",&arNmean,&metaData,0,kTRUE);      // from DCS
274 //  stDcsStore =   Store("Calib","Qthre",&arQthre,&metaData) &&    // from DCS 
275 //                 Store("Calib","Nmean",&arNmean,&metaData);      // from DCS
276   if(!stDcsStore) {
277     Log("HMPID - failure to store DCS data results in OCDB");    
278   }
279   
280 //  arNmean.Delete();
281 //  arQthre.Delete();
282
283 //  for(Int_t i=0;i<21;i++) delete pTin[i]; delete []pTin;
284 //  for(Int_t i=0;i<21;i++) delete pTout[i]; delete []pTout;
285   
286   return stDcsStore;
287 }//Process()
288 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
289 Bool_t AliHMPIDPreprocessor::ProcPed()
290 {
291 // Process pedestal files and create 7 M(padx,pady)=sigma, one for each chamber
292 // Arguments:
293 // Returns: kTRUE on success
294   
295   Bool_t stPedStore=kFALSE;
296   Bool_t stDeadMaskedStore=kFALSE;
297   AliHMPIDDigit dig;
298   AliHMPIDRawStream rs;
299   Int_t nSigCut,r,d,a,hard;  Float_t mean,sigma;
300   Int_t  runNumber,ldcId,timeStamp,nEv,nDdlEv,nBadEv;  Char_t tName[10]; 
301   Float_t nBadEvPer;
302   
303   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
304   TObjArray aDeadMasked(7); aDeadMasked.SetOwner(kTRUE); for(Int_t i=0;i<7;i++) aDeadMasked.AddAt(new TMatrix(160,144),i);     //TObjArray of 7 TMatrixF, m(padx,pady)=pedestal
305   
306   for(Int_t iddl=0;iddl<AliHMPIDRawStream::kNDDL;iddl++)            //retrieve the files from LDCs independently the DDL<->LDC connection
307   {
308     TList *pLdc=GetFileSources(kDAQ,Form("HmpidPedDdl%02i.txt",iddl)); //get list of LDC names containing id "pedestals"
309     if(!pLdc) {Log(Form("ERROR: Retrieval of sources for pedestals: HmpidPedDdl%02i.txt failed!",iddl));continue;}
310     
311     Log(Form("HMPID - Pedestal files to be read --> %i LDCs for HMPID",pLdc->GetEntries()));
312     for(Int_t i=0;i<pLdc->GetEntries();i++) {//lists of LDCs -- but in general we have 1 LDC for 1 ped file
313     TString fileName = GetFile(kDAQ,Form("HmpidPedDdl%02i.txt",iddl),((TObjString*)pLdc->At(i))->GetName());
314     if(fileName.Length()==0) {Log(Form("ERROR retrieving pedestal file: HmpidPedDdl%02i.txt!",iddl));continue;}
315   
316     //reading pedestal file
317     ifstream infile(fileName.Data()); 
318     
319     if(!infile.is_open()) {Log("No pedestal file found for HMPID,bye!");continue;}
320     TMatrix *pM=(TMatrixF*)aDaqSig.At(iddl/2);
321     TMatrix *pDM=(TMatrixF*)aDeadMasked.At(iddl/2);
322     infile>>tName>>runNumber;Printf("Xcheck: reading run %i",runNumber);
323     infile>>tName>>ldcId;
324     infile>>tName>>timeStamp;
325     infile>>tName>>nEv; 
326     infile>>tName>>nDdlEv;
327     infile>>tName>>nBadEv;
328     infile>>tName>>nBadEvPer;
329     infile>>tName>>nSigCut; pM->SetUniqueID(nSigCut); //n. of pedestal distribution sigmas used to create zero suppresion table
330     while(!infile.eof()){
331       infile>>dec>>r>>d>>a>>mean>>sigma>>hex>>hard;
332       if(rs.GetPad(iddl,r,d,a)>=0){                     //the GetPad returns meaningful abs pad number                                                          
333       dig.SetPad(rs.GetPad(iddl,r,d,a));
334       dig.SetQ((Int_t)mean);
335       (*pM)(dig.PadChX(),dig.PadChY()) = sigma;
336       if( (mean == AliHMPIDParam::kPadMeanZeroCharge && sigma == AliHMPIDParam::kPadSigmaZeroCharge) || 
337           (mean == AliHMPIDParam::kPadMeanMasked     && sigma == AliHMPIDParam::kPadSigmaMasked)     ) 
338         {(*pDM)(dig.PadChX(),dig.PadChY()) = mean;} 
339       }
340     }
341     infile.close();
342     Log(Form("Pedestal file for DDL %i read successfully",iddl));
343   
344  
345     
346   }//LDCs reading entries
347
348  }//DDL 
349
350   AliCDBMetaData metaData; 
351   metaData.SetBeamPeriod(0); 
352   metaData.SetResponsible("AliHMPIDPreprocessor"); 
353   metaData.SetComment("HMPID processor fills TObjArrays.");  
354   stPedStore = Store("Calib","DaqSig",&aDaqSig,&metaData,0,kTRUE);
355   if(!stPedStore) {     Log("HMPID - failure to store PEDESTAL data results in OCDB");      }
356   stDeadMaskedStore = Store("Calib","Masked",&aDeadMasked,&metaData,0,kTRUE);
357   if(!stDeadMaskedStore) {     Log("HMPID - failure to store DEAD & MASKED channel map  in OCDB");      }
358   Bool_t pedRes=stPedStore*stDeadMaskedStore;
359   return pedRes;
360   
361 }//ProcPed()  
362 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
363 Double_t AliHMPIDPreprocessor::ProcTrans(TMap* pMap)
364 {
365   //  Process transparency monitoring data and calculates Emean  
366   
367   Double_t sEnergProb=0, sProb=0;
368
369   Double_t tRefCR5 = 19. ;                                      // mean temperature of CR5 where the system is in place
370
371   Double_t eMean = 0;
372       
373   AliDCSValue *pVal;
374
375   for(Int_t i=0; i<30; i++){
376
377     // evaluate wavelenght 
378     TObjArray *pWaveLenght = (TObjArray*)pMap->GetValue(Form("HMP_DET/HMP_INFR/HMP_INFR_TRANPLANT/HMP_INFR_TRANPLANT_MEASURE.mesure%i.waveLenght",i));
379     if(!pWaveLenght){ 
380         AliWarning(Form("No Data Point values for HMP_DET/HMP_INFR/HMP_INFR_TRANPLANT/HMP_INFR_TRANPLANT_MEASURE.mesure%i.waveLenght  -----> Default E mean used!!!!!",i));
381         return DefaultEMean(); // to be checked
382       } 
383         
384     pVal=(AliDCSValue*)pWaveLenght->At(0);
385     Double_t lambda = pVal->GetFloat();
386
387     if(lambda<150. || lambda>230.){ 
388         AliWarning(Form("Wrong value for HMP_DET/HMP_INFR/HMP_INFR_TRANPLANT/HMP_INFR_TRANPLANT_MEASURE.mesure%i.waveLenght  -----> Default E mean used!!!!!",i));
389         return DefaultEMean(); // to be checked
390       } 
391
392     Double_t photEn = 1239.842609/lambda;     // 1239.842609 from nm to eV
393     
394     if(photEn<AliHMPIDParam::EPhotMin() || photEn>AliHMPIDParam::EPhotMax()) continue;
395     
396     // evaluate phototube current for argon reference
397     TObjArray *pArgonRef  = (TObjArray*)pMap->GetValue(Form("HMP_DET/HMP_INFR/HMP_INFR_TRANPLANT/HMP_INFR_TRANPLANT_MEASURE.mesure%i.argonReference",i));
398     if(!pArgonRef){ 
399         AliWarning(Form("No Data Point values for HMP_DET/HMP_INFR/HMP_INFR_TRANPLANT/HMP_INFR_TRANPLANT_MEASURE.mesure%i.argonReference  -----> Default E mean used!!!!!",i));
400         return DefaultEMean(); // to be checked
401       } 
402
403     pVal=(AliDCSValue*)pArgonRef->At(0);    
404     Double_t aRefArgon = pVal->GetFloat();
405
406     // evaluate phototube current for argon cell
407     TObjArray *pArgonCell = (TObjArray*)pMap->GetValue(Form("HMP_DET/HMP_INFR/HMP_INFR_TRANPLANT/HMP_INFR_TRANPLANT_MEASURE.mesure%i.argonCell",i));
408     if(!pArgonCell){ 
409         AliWarning(Form("No Data Point values for HMP_DET/HMP_INFR/HMP_INFR_TRANPLANT/HMP_INFR_TRANPLANT_MEASURE.mesure%i.argonCell  -----> Default E mean used!!!!!",i));
410         return DefaultEMean(); // to be checked
411       } 
412       
413     pVal=(AliDCSValue*)pArgonRef->At(0);
414     Double_t aCellArgon = pVal->GetFloat();
415
416     //evaluate phototube current for freon reference
417     TObjArray *pFreonRef  = (TObjArray*)pMap->GetValue(Form("HMP_DET/HMP_INFR/HMP_INFR_TRANPLANT/HMP_INFR_TRANPLANT_MEASURE.mesure%i.c6f14Reference",i));
418     if(!pFreonRef){ 
419         AliWarning(Form("No Data Point values for HMP_DET/HMP_INFR/HMP_INFR_TRANPLANT/HMP_INFR_TRANPLANT_MEASURE.mesure%i.c6f14Reference  -----> Default E mean used!!!!!",i));
420         return DefaultEMean(); // to be checked
421       } 
422         
423     pVal=(AliDCSValue*)pFreonRef->At(0);
424     Double_t aRefFreon = pVal->GetFloat();
425
426     //evaluate phototube current for freon cell
427     TObjArray *pFreonCell = (TObjArray*)pMap->GetValue(Form("HMP_DET/HMP_INFR/HMP_INFR_TRANPLANT/HMP_INFR_TRANPLANT_MEASURE.mesure%i.c6f14Cell",i));
428     if(!pFreonCell){
429         AliWarning(Form("No Data Point values for HMP_DET/HMP_INFR/HMP_INFR_TRANPLANT/HMP_INFR_TRANPLANT_MEASURE.mesure%i.c6f14Cell  -----> Default E mean used!!!!!",i));
430         return DefaultEMean(); // to be checked
431       }
432
433     pVal=(AliDCSValue*)pFreonCell->At(0);
434     Double_t aCellFreon = pVal->GetFloat();
435  
436    //evaluate correction factor to calculate trasparency (Ref. NIMA 486 (2002) 590-609)
437     
438     Double_t aN1 = AliHMPIDParam::NIdxRad(photEn,tRefCR5);
439     Double_t aN2 = AliHMPIDParam::NMgF2Idx(photEn);
440     Double_t aN3 = 1;                              // Argon Idx
441
442     Double_t aR1               = ((aN1 - aN2)*(aN1 - aN2))/((aN1 + aN2)*(aN1 + aN2));
443     Double_t aR2               = ((aN2 - aN3)*(aN2 - aN3))/((aN2 + aN3)*(aN2 + aN3));
444     Double_t aT1               = (1 - aR1);
445     Double_t aT2               = (1 - aR2);
446     Double_t aCorrFactor       = (aT1*aT1)/(aT2*aT2);
447
448     // evaluate 15 mm of thickness C6F14 Trans
449     Double_t aTransRad;
450     
451     if(aRefFreon*aRefArgon>0) {
452       aTransRad  = TMath::Power((aCellFreon/aRefFreon)/(aCellArgon/aRefArgon)*aCorrFactor,1.5);
453     } else {
454       return DefaultEMean();
455     }
456
457     // evaluate 0.5 mm of thickness SiO2 Trans
458     Double_t aTransSiO2 = TMath::Exp(-0.5/AliHMPIDParam::LAbsWin(photEn));
459
460     // evaluate 80 cm of thickness Gap (low density CH4) transparency
461     Double_t aTransGap  = TMath::Exp(-80./AliHMPIDParam::LAbsGap(photEn));
462
463     // evaluate CsI quantum efficiency
464     Double_t aCsIQE            = AliHMPIDParam::QEffCSI(photEn);
465
466     // evaluate total convolution of all material optical properties
467     Double_t aTotConvolution   = aTransRad*aTransSiO2*aTransGap*aCsIQE;
468
469     sEnergProb+=aTotConvolution*photEn;  
470   
471     sProb+=aTotConvolution;  
472 }
473   if(sProb>0) {
474     eMean = sEnergProb/sProb;
475   } else {
476     return DefaultEMean();
477   }
478   Log(Form(" Mean energy photon calculated ---> %f eV ",eMean));
479
480   if(eMean<AliHMPIDParam::EPhotMin() || eMean>AliHMPIDParam::EPhotMax()) return DefaultEMean();
481   
482   return eMean;
483 }   
484 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
485 Double_t AliHMPIDPreprocessor::DefaultEMean()
486 {
487     Double_t eMean = 6.675;      //just set a refractive index for C6F14 at ephot=6.675 eV @ T=25 C
488     AliWarning(Form("Mean energy for photons out of range [%f,%f] in Preprocessor. Default value Eph=%f eV taken.",AliHMPIDParam::EPhotMin(),
489                                                                                                                    AliHMPIDParam::EPhotMax(),
490                                                                                                                    eMean));
491     return eMean;
492 }