fc0c3e6b60c2cd3364276a81985bd3c6bd75a6fe
[u/mrichter/AliRoot.git] / TPC / CalibMacros / CalibEnv.C
1 /*
2 gSystem->AddIncludePath("-I$ALICE_ROOT/TPC");
3
4 gSystem->Load("libXrdClient.so");
5 gSystem->Load("libNetx.so");
6 if (!gGrid) TGrid::Connect("alien://",0,0,"t");
7
8
9 .L CalibEnv.C++
10 Init();
11 CalibEnv("listAll.txt");
12 TFile f("dcsTime.root")
13
14
15 */
16
17 #include <iostream>
18 #include <fstream>
19 #include <AliCDBManager.h>
20 #include <AliCDBEntry.h>
21 #include <AliLog.h>
22 #include <AliMagF.h>
23 #include "AliTPCcalibDB.h"
24 #include "AliTPCAltroMapping.h"
25 #include "AliTPCExB.h"
26 #include "AliTPCCalROC.h"
27 #include "AliTPCCalPad.h"
28 #include "AliTPCSensorTempArray.h"
29 #include "AliGRPObject.h"
30 #include "AliTPCTransform.h"
31 #include "TFile.h"
32 #include "TKey.h"
33 #include "TObjArray.h"
34 #include "TObjString.h"
35 #include "TString.h"
36 #include "AliTPCCalPad.h"
37 #include "AliTPCCalibPulser.h"
38 #include "AliTPCCalibPedestal.h"
39 #include "AliTPCCalibCE.h"
40 #include "AliTPCExBFirst.h"
41 #include "TTreeStream.h"
42 #include "AliTPCTempMap.h"
43
44 void ProcessGoofie( AliDCSSensorArray* goofieArray, TVectorD & vecEntries, TVectorD & vecMedian, TVectorD &vecMean, TVectorD &vecRMS);
45
46 void Init(){
47   //
48   //
49   //
50   AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
51   AliCDBManager::Instance()->SetSpecificStorage("TPC/Calib/Parameters","local://$ALICE_ROOT");
52   AliCDBManager::Instance()->SetSpecificStorage("GRP/GRP/Data","local:///lustre_alpha/alice/alien/alice/data/2008/LHC08d/OCDB/");
53   AliCDBManager::Instance()->SetSpecificStorage("TPC/Calib/Temperature","local:///lustre_alpha/alice/alien/alice/data/2008/LHC08d/OCDB/");
54   AliCDBManager::Instance()->SetSpecificStorage("TPC/Calib/HighVoltage","local:///lustre_alpha/alice/alien/alice/data/2008/LHC08d/OCDB/");
55   AliCDBManager::Instance()->SetSpecificStorage("TPC/Calib/Goofie","local:///lustre_alpha/alice/alien/alice/data/2008/LHC08d/OCDB/");
56   AliCDBManager::Instance()->SetRun(1);
57 }
58
59
60 void InitAlien(const char *path="LHC08b"){
61   //
62   //
63   //
64   TString alpath="alien://folder=/alice/data/2008/";
65   alpath+=path;
66   alpath+="/OCDB";
67     
68   AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
69   AliCDBManager::Instance()->SetSpecificStorage("TPC/Calib/Parameters","local://$ALICE_ROOT");
70   AliCDBManager::Instance()->SetSpecificStorage("GRP/GRP/Data",alpath.Data());
71   AliCDBManager::Instance()->SetSpecificStorage("TPC/Calib/Temperature",alpath.Data());
72   AliCDBManager::Instance()->SetSpecificStorage("TPC/Calib/Goofie",alpath.Data());
73   AliCDBManager::Instance()->SetRun(1);
74 }
75
76
77 void CalibEnv(const char * runList){
78   //
79   //
80   //  
81   AliTPCcalibDB * calibDB = AliTPCcalibDB::Instance();
82   ifstream in;
83   in.open(runList);
84   Int_t irun=0;
85   TTreeSRedirector *pcstream = new TTreeSRedirector("dcsTime.root");
86   //  for (Int_t irun=startRun; irun<stopRun; irun++){
87   while(in.good()) {
88     in >> irun;
89     if (irun==0) continue;
90     printf("Processing run %d ...\n",irun);
91     AliDCSSensor * sensorPressure = AliTPCcalibDB::Instance()->GetPressureSensor(irun);
92     if (!sensorPressure) continue;
93     AliTPCSensorTempArray * tempArray = AliTPCcalibDB::Instance()->GetTemperatureSensor(irun);
94     AliTPCTempMap * tempMap = new AliTPCTempMap(tempArray);
95     AliDCSSensorArray* goofieArray = AliTPCcalibDB::Instance()->GetGoofieSensors(irun);
96     //
97     Int_t startTime = sensorPressure->GetStartTime();
98     Int_t endTime = sensorPressure->GetEndTime();
99     Int_t dtime = TMath::Max((endTime-startTime)/20,10*60);
100     for (Int_t itime=startTime; itime<endTime; itime+=dtime){
101       //
102       TTimeStamp tstamp(itime); 
103       Float_t valuePressure  = calibDB->GetPressure(tstamp,irun,0);
104       Float_t valuePressure2 = calibDB->GetPressure(tstamp,irun,1);
105
106       TLinearFitter * fitter = 0;
107       TVectorD vecTemp[10];
108       for (Int_t itype=0; itype<5; itype++)
109         for (Int_t iside=0; iside<2; iside++){    
110           fitter= tempMap->GetLinearFitter(itype,iside,tstamp);   
111           if (!fitter) continue;
112           fitter->Eval(); 
113           fitter->GetParameters(vecTemp[itype+iside*5]);
114           delete fitter;
115         } 
116       
117       
118       TVectorD vecGoofie, vecEntries, vecMean, vecMedian,vecRMS;
119       if (goofieArray){ 
120         vecGoofie.ResizeTo(goofieArray->NumSensors());
121         ProcessGoofie(goofieArray, vecEntries ,vecMedian, vecMean, vecRMS);
122         //
123         for (Int_t isensor=0; isensor<goofieArray->NumSensors();isensor++){
124           AliDCSSensor *gsensor = goofieArray->GetSensor(isensor);
125           if (gsensor){
126             vecGoofie[isensor] = gsensor->GetValue(tstamp);
127           }
128         }
129       }
130       Double_t ptrelative0 = AliTPCcalibDB::GetPTRelative(tstamp,irun,0);
131       Double_t ptrelative1 = AliTPCcalibDB::GetPTRelative(tstamp,irun,1);
132       //
133       Double_t voltagesIROC[36]; 
134       Double_t voltagesOROC[36]; 
135       for(Int_t j=1; j<36; j++) voltagesIROC[j-1] = AliTPCcalibDB::Instance()->GetChamberHighVoltage(startTime, irun, j);
136       for(Int_t j=36; j<72; j++) voltagesOROC[j-36] = AliTPCcalibDB::Instance()->GetChamberHighVoltage(startTime, irun, j);
137       Double_t voltIROC = TMath::Median(36, voltagesIROC);
138       Double_t voltOROC = TMath::Median(36, voltagesOROC);
139
140       //tempMap->GetLinearFitter(0,0,itime);
141       (*pcstream)<<"dcs"<<
142         "run="<<irun<<
143         "time="<<itime<<
144         "voltageIROC="<<voltIROC<<
145         "voltageOROC="<<voltOROC<<
146         "ptrel0="<<ptrelative0<<
147         "ptrel1="<<ptrelative1<<
148         "goofie.="<<&vecGoofie<<
149         "goofieE.="<<&vecEntries<<
150         "goofieMean.="<<&vecMean<<
151         "goofieMedian.="<<&vecMedian<<
152         "goofieRMS.="<<&vecRMS<<
153         "press="<<valuePressure<<
154         "press2="<<valuePressure2<<
155         "temp00.="<<&vecTemp[0]<<
156         "temp10.="<<&vecTemp[1]<<
157         "temp20.="<<&vecTemp[2]<<
158         "temp30.="<<&vecTemp[3]<<
159         "temp40.="<<&vecTemp[4]<<
160         "temp01.="<<&vecTemp[5]<<
161         "temp11.="<<&vecTemp[6]<<
162         "temp21.="<<&vecTemp[7]<<
163         "temp31.="<<&vecTemp[8]<<
164         "temp41.="<<&vecTemp[9]<<
165         "\n";
166     }
167   }
168   delete pcstream;
169 }
170
171
172 void ProcessGoofie( AliDCSSensorArray* goofieArray, TVectorD & vecEntries, TVectorD & vecMedian, TVectorD &vecMean, TVectorD &vecRMS){
173   /*
174     
175   1       TPC_ANODE_I_A00_STAT
176   2       TPC_DVM_CO2
177   3       TPC_DVM_DriftVelocity
178   4       TPC_DVM_FCageHV
179   5       TPC_DVM_GainFar
180   6       TPC_DVM_GainNear
181   7       TPC_DVM_N2
182   8       TPC_DVM_NumberOfSparks
183   9       TPC_DVM_PeakAreaFar
184   10      TPC_DVM_PeakAreaNear
185   11      TPC_DVM_PeakPosFar
186   12      TPC_DVM_PeakPosNear
187   13      TPC_DVM_PickupHV
188   14      TPC_DVM_Pressure
189   15      TPC_DVM_T1_Over_P
190   16      TPC_DVM_T2_Over_P
191   17      TPC_DVM_T_Over_P
192   18      TPC_DVM_TemperatureS1
193    */
194   //
195   //
196   //  TVectorD  vecMedian; TVectorD  vecEntries; TVectorD  vecMean; TVectorD  vecRMS;
197   Double_t kEpsilon=0.0000000001;
198   Double_t kBig=100000000000.;
199   Int_t nsensors = goofieArray->NumSensors();
200   vecEntries.ResizeTo(nsensors);
201   vecMedian.ResizeTo(nsensors);
202   vecMean.ResizeTo(nsensors);
203   vecRMS.ResizeTo(nsensors);
204   TVectorF values;
205   for (Int_t isensor=0; isensor<goofieArray->NumSensors();isensor++){
206     AliDCSSensor *gsensor = goofieArray->GetSensor(isensor);
207     if (gsensor &&  gsensor->GetGraph()){
208       Int_t npoints = gsensor->GetGraph()->GetN();
209       // filter zeroes
210       values.ResizeTo(npoints);
211       Int_t nused =0;
212       for (Int_t ipoint=0; ipoint<npoints; ipoint++){
213         if (TMath::Abs(gsensor->GetGraph()->GetY()[ipoint])>kEpsilon && 
214            TMath::Abs(gsensor->GetGraph()->GetY()[ipoint])<kBig ){
215           values[nused]=gsensor->GetGraph()->GetY()[ipoint];
216           nused++;
217         }
218       }
219       //
220       vecEntries[isensor]= nused;      
221       if (nused>1){
222         vecMedian[isensor] = TMath::Median(nused,values.GetMatrixArray());
223         vecMean[isensor]   = TMath::Mean(nused,values.GetMatrixArray());
224         vecRMS[isensor]    = TMath::RMS(nused,values.GetMatrixArray());
225       }
226     }
227   }
228 }
229
230
231 void FilterMag(const char * runList){
232   //
233   //
234   //
235   //  AliTPCcalibDB * calibDB = AliTPCcalibDB::Instance();
236   ifstream in;
237   in.open(runList);
238   Int_t irun=0;
239   while(in.good()) {
240     in >> irun;
241     if (irun==0) continue;
242     AliGRPObject *grp = AliTPCcalibDB::GetGRP(irun);
243     Float_t current = -1;
244     Float_t bz      = -1;
245     Float_t press   =  0;
246     if (grp){
247       current = grp->GetL3Current((AliGRPObject::Stats)0);
248       bz = 5*current/30000.;
249       printf("Run%d\tL3 current%f\tBz\t%f\n",irun,current,bz);
250     }
251     else{
252       printf("Run%d\tL3 current%f\tBz\t%f\n",irun,current,bz);
253     }
254   }
255
256 }
257
258 /*
259
260 AliDCSSensor * sensorPressure = AliTPCcalibDB::Instance()->GetPressureSensor(62084);
261 entry = AliCDBManager::Instance()->Get("TPC/Calib/Temperature",run);
262 AliTPCSensorTempArray * tempArray = (AliTPCSensorTempArray *)entry->GetObject();
263 AliTPCSensorTempArray * tempArray = (AliTPCSensorTempArray *)AliTPCcalibDB::Instance()->GetTemperatureSensor(62084)
264 AliTPCTempMap * tempMap = new AliTPCTempMap(tempArray);
265 TLinearFitter * fitter = tempMap->GetLinearFitter(0,0,tempArray->GetStartTime());
266
267 AliDCSSensorArray* goofieArray = AliTPCcalibDB::Instance()->GetGoofieSensors(62084);
268
269 */