Changes of Jens Wiechula
[u/mrichter/AliRoot.git] / TPC / CalibMacros / CalibEnv.C
CommitLineData
d47d42ee 1/*
7ce80437 2.x ~/NimStyle.C
3.x ~/rootlogon.C
4
d47d42ee 5gSystem->AddIncludePath("-I$ALICE_ROOT/TPC");
e2914767 6
e2914767 7
8
7ce80437 9.L $ALICE_ROOT/TPC/CalibMacros/CalibEnv.C+
d47d42ee 10Init();
6e7d7dc4 11CalibEnv("run.list");
7ce80437 12GetTree();
13
e79211e8 14TFile f("dcsTime.root")
d47d42ee 15
7ce80437 16//
17// if you want to use alien OCDB
18//
19gSystem->Load("libXrdClient.so");
20gSystem->Load("libNetx.so");
21if (!gGrid) TGrid::Connect("alien://",0,0,"t");
22
23
e2914767 24
d47d42ee 25*/
26
27#include <iostream>
28#include <fstream>
5312f439 29#include <stdio.h>
d47d42ee 30#include <AliCDBManager.h>
31#include <AliCDBEntry.h>
32#include <AliLog.h>
33#include <AliMagF.h>
34#include "AliTPCcalibDB.h"
892226be 35#include "AliTPCcalibDButil.h"
d47d42ee 36#include "AliTPCAltroMapping.h"
37#include "AliTPCExB.h"
38#include "AliTPCCalROC.h"
39#include "AliTPCCalPad.h"
40#include "AliTPCSensorTempArray.h"
41#include "AliGRPObject.h"
42#include "AliTPCTransform.h"
43#include "TFile.h"
44#include "TKey.h"
45#include "TObjArray.h"
46#include "TObjString.h"
47#include "TString.h"
48#include "AliTPCCalPad.h"
5312f439 49#include "AliTPCROC.h"
50#include "AliTPCParam.h"
d47d42ee 51#include "AliTPCCalibPulser.h"
52#include "AliTPCCalibPedestal.h"
53#include "AliTPCCalibCE.h"
54#include "AliTPCExBFirst.h"
55#include "TTreeStream.h"
56#include "AliTPCTempMap.h"
5312f439 57#include "TVectorD.h"
58#include "TMatrixD.h"
6e7d7dc4 59#include "AliTPCCalibRaw.h"
d47d42ee 60
7ce80437 61
62TTree * dcsTree=0;
63
6fb51ca4 64void GetProductionInfo(Int_t run, Int_t &nalien, Int_t &nRawAlien, Int_t &nlocal, Int_t &nRawLocal);
5312f439 65
6e7d7dc4 66void Init2008(){
d47d42ee 67 //
68 //
69 //
162637e4 70 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
71 AliCDBManager::Instance()->SetSpecificStorage("TPC/Calib/Parameters","local://$ALICE_ROOT/OCDB");
e6970ab5 72 AliCDBManager::Instance()->SetSpecificStorage("GRP/GRP/Data","local:///lustre/alice/alien/alice/data/2008/LHC08d/OCDB/");
73 AliCDBManager::Instance()->SetSpecificStorage("TPC/Calib/Temperature","local:///lustre/alice/alien/alice/data/2008/LHC08d/OCDB/");
74 AliCDBManager::Instance()->SetSpecificStorage("TPC/Calib/HighVoltage","local:///lustre/alice/alien/alice/data/2008/LHC08d/OCDB/");
75 AliCDBManager::Instance()->SetSpecificStorage("TPC/Calib/Goofie","local:///lustre/alice/alien/alice/data/2008/LHC08d/OCDB/");
d47d42ee 76 AliCDBManager::Instance()->SetRun(1);
e2914767 77}
78
6e7d7dc4 79void Init(){
80 AliCDBManager::Instance()->SetDefaultStorage("local:///lustre/alice/alien/alice/data/2009/OCDB/");
81 AliCDBManager::Instance()->SetRun(1);
82}
d47d42ee 83
e2914767 84void InitAlien(const char *path="LHC08b"){
85 //
86 //
87 //
88 TString alpath="alien://folder=/alice/data/2008/";
89 alpath+=path;
90 alpath+="/OCDB";
7ce80437 91
162637e4 92 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
93 AliCDBManager::Instance()->SetSpecificStorage("TPC/Calib/Parameters","local://$ALICE_ROOT/OCDB");
e2914767 94 AliCDBManager::Instance()->SetSpecificStorage("GRP/GRP/Data",alpath.Data());
95 AliCDBManager::Instance()->SetSpecificStorage("TPC/Calib/Temperature",alpath.Data());
96 AliCDBManager::Instance()->SetSpecificStorage("TPC/Calib/Goofie",alpath.Data());
97 AliCDBManager::Instance()->SetRun(1);
d47d42ee 98}
99
100
101void CalibEnv(const char * runList){
102 //
103 //
7ce80437 104 //
e79211e8 105 AliTPCcalibDB * calibDB = AliTPCcalibDB::Instance();
d47d42ee 106 ifstream in;
107 in.open(runList);
108 Int_t irun=0;
e79211e8 109 TTreeSRedirector *pcstream = new TTreeSRedirector("dcsTime.root");
892226be 110 AliTPCcalibDButil dbutil;
d47d42ee 111 // for (Int_t irun=startRun; irun<stopRun; irun++){
112 while(in.good()) {
113 in >> irun;
6e7d7dc4 114 if (in.eof()) break;
d47d42ee 115 if (irun==0) continue;
e2914767 116 printf("Processing run %d ...\n",irun);
5312f439 117 AliTPCcalibDB::Instance()->SetRun(irun);
892226be 118 dbutil.UpdateFromCalibDB();
d47d42ee 119 AliDCSSensor * sensorPressure = AliTPCcalibDB::Instance()->GetPressureSensor(irun);
120 if (!sensorPressure) continue;
121 AliTPCSensorTempArray * tempArray = AliTPCcalibDB::Instance()->GetTemperatureSensor(irun);
122 AliTPCTempMap * tempMap = new AliTPCTempMap(tempArray);
123 AliDCSSensorArray* goofieArray = AliTPCcalibDB::Instance()->GetGoofieSensors(irun);
124 //
125 Int_t startTime = sensorPressure->GetStartTime();
126 Int_t endTime = sensorPressure->GetEndTime();
6fb51ca4 127 Int_t startTimeGRP = AliTPCcalibDB::GetGRP(irun)->GetTimeStart();
128 Int_t stopTimeGRP = AliTPCcalibDB::GetGRP(irun)->GetTimeEnd();
d47d42ee 129 Int_t dtime = TMath::Max((endTime-startTime)/20,10*60);
892226be 130 //Goofie statistical data
131 TVectorD vecEntries, vecMean, vecMedian,vecRMS;
132 dbutil.ProcessGoofie(vecEntries ,vecMedian, vecMean, vecRMS);
5312f439 133 //CE data processing - see ProcessCEdata function for description of the results
134 TVectorD fitResultsA, fitResultsC;
892226be 135 Int_t nmaskedCE;
136 dbutil.ProcessCEdata("gx++gy++lx++lx**2",fitResultsA,fitResultsC,nmaskedCE);
137 TVectorD vecTEntries, vecTMean, vecTRMS, vecTMedian, vecQEntries, vecQMean, vecQRMS, vecQMedian;
138 Float_t driftTimeA, driftTimeC;
139 dbutil.ProcessCEgraphs(vecTEntries, vecTMean, vecTRMS, vecTMedian,
140 vecQEntries, vecQMean, vecQRMS, vecQMedian,
141 driftTimeA, driftTimeC );
5312f439 142 //noise data Processing - see ProcessNoiseData function for description of the results
143 TVectorD vNoiseMean, vNoiseMeanSenRegions, vNoiseRMS, vNoiseRMSSenRegions;
144 Int_t nonMaskedZero=0;
892226be 145 dbutil.ProcessNoiseData(vNoiseMean, vNoiseMeanSenRegions, vNoiseRMS, vNoiseRMSSenRegions, nonMaskedZero);
e6970ab5 146 //L3 data
5312f439 147 Float_t bz=AliTPCcalibDB::GetBz(irun);
148 Char_t l3pol=AliTPCcalibDB::GetL3Polarity(irun);
149 //calibration Pulser data processing
5312f439 150 Int_t nOffChannels=0;
892226be 151 TVectorD vTimePulser;
152 nOffChannels=dbutil.GetNPulserOutliers();
153 dbutil.ProcessPulser(vTimePulser);
154 //ALTRO data
155 Int_t nMasked=0;
156 dbutil.ProcessALTROConfig(nMasked);
6e7d7dc4 157 //Calib RAW data
158 Int_t nFailL1=-1;
159 if (calibDB->GetCalibRaw())
160 nFailL1=calibDB->GetCalibRaw()->GetNFailL1Phase();
5312f439 161 //production information
6fb51ca4 162 Int_t nalien=0,nRawAlien=0,nlocal=0,nRawLocal=0;
e6970ab5 163// GetProductionInfo(irun, nalien, nRawAlien, nlocal,nRawLocal);
5312f439 164 //run type
165 TObjString runType(AliTPCcalibDB::GetRunType(irun).Data());
166
d47d42ee 167 for (Int_t itime=startTime; itime<endTime; itime+=dtime){
168 //
5312f439 169 TTimeStamp tstamp(itime);
e79211e8 170 Float_t valuePressure = calibDB->GetPressure(tstamp,irun,0);
171 Float_t valuePressure2 = calibDB->GetPressure(tstamp,irun,1);
5312f439 172 //temperature fits
d47d42ee 173 TLinearFitter * fitter = 0;
174 TVectorD vecTemp[10];
e79211e8 175 for (Int_t itype=0; itype<5; itype++)
5312f439 176 for (Int_t iside=0; iside<2; iside++){
177 fitter= tempMap->GetLinearFitter(itype,iside,tstamp);
178 if (!fitter) continue;
179 fitter->Eval();
180 fitter->GetParameters(vecTemp[itype+iside*5]);
181 delete fitter;
182 }
183 //measured skirt temperatures
184 TVectorD vecSkirtTempA(18);
185 TVectorD vecSkirtTempC(18);
186 Int_t nsenTemp=tempArray->NumSensors();
187 for (Int_t isenTemp=0;isenTemp<nsenTemp;++isenTemp){
188 AliTPCSensorTemp *senTemp=(AliTPCSensorTemp*)tempArray->GetSensorNum(isenTemp);
189 if (senTemp->GetType()!=3) continue;
190 if (TMath::Sqrt(senTemp->GetX()*senTemp->GetX()+senTemp->GetY()*senTemp->GetY())<100) continue; //only skirt, outer FC vessel
191 Double_t val=senTemp->GetValue(tstamp);
192 if (senTemp->GetSide()==0)
193 vecSkirtTempA[senTemp->GetSector()]=val;
194 else
195 vecSkirtTempC[senTemp->GetSector()]=val;
196 }
892226be 197 //goofie data
198 TVectorD vecGoofie;
5312f439 199 if (goofieArray){
200 vecGoofie.ResizeTo(goofieArray->NumSensors());
5312f439 201 for (Int_t isensor=0; isensor<goofieArray->NumSensors();isensor++){
202 AliDCSSensor *gsensor = goofieArray->GetSensor(isensor);
203 if (gsensor){
204 vecGoofie[isensor] = gsensor->GetValue(tstamp);
205 }
206 }
892226be 207 } else {
208 vecGoofie.ResizeTo(19);
d47d42ee 209 }
892226be 210 Double_t ptrelative0 = AliTPCcalibDB::GetPTRelative((UInt_t)itime,irun,0);
211 Double_t ptrelative1 = AliTPCcalibDB::GetPTRelative((UInt_t)itime,irun,1);
e2914767 212 //
5312f439 213 TVectorD voltagesIROC(36);
214 TVectorD voltagesOROC(36);
892226be 215 for(Int_t j=1; j<36; j++) voltagesIROC[j-1] = AliTPCcalibDB::Instance()->GetChamberHighVoltage(irun, j,itime);
216 for(Int_t j=36; j<72; j++) voltagesOROC[j-36] = AliTPCcalibDB::Instance()->GetChamberHighVoltage(irun, j,itime);
7ce80437 217 Double_t voltIROC = TMath::Median(36, voltagesIROC.GetMatrixArray());
218 Double_t voltOROC = TMath::Median(36, voltagesOROC.GetMatrixArray());
219 //
5312f439 220 Float_t coverIA=AliTPCcalibDB::GetCoverVoltage(irun,0,itime);
221 Float_t coverIC=AliTPCcalibDB::GetCoverVoltage(irun,18,itime);
222 Float_t coverOA=AliTPCcalibDB::GetCoverVoltage(irun,36,itime);
223 Float_t coverOC=AliTPCcalibDB::GetCoverVoltage(irun,54,itime);
224 Float_t skirtA=AliTPCcalibDB::GetSkirtVoltage(irun,0,itime);
225 Float_t skirtC=AliTPCcalibDB::GetSkirtVoltage(irun,18,itime);
226 Float_t ggOffA=AliTPCcalibDB::GetGGoffsetVoltage(irun,0,itime);
227 Float_t ggOffC=AliTPCcalibDB::GetGGoffsetVoltage(irun,18,itime);
228
229
230
e2914767 231 //tempMap->GetLinearFitter(0,0,itime);
e6970ab5 232 (*pcstream)<<"dcs"<<
5312f439 233 "run="<<irun<<
234 "time="<<itime<<
6fb51ca4 235 "startTimeGRP="<<startTimeGRP<<
236 "stopTimeGRP="<<stopTimeGRP<<
5312f439 237 //run type
238 "runType.="<<&runType<<
239 // voltage setting
240 "VIROC.="<<&voltagesIROC<<
241 "VOROC.="<<&voltagesOROC<<
242 "medianVIROC="<<voltIROC<<
243 "medianVOROC="<<voltOROC<<
7ce80437 244 "coverIA=" << coverIA <<
245 "coverIC=" << coverIC <<
246 "coverOA=" << coverOA <<
247 "coverOC=" << coverOC <<
248 "skirtA=" << skirtA <<
249 "skirtC=" << skirtC <<
250 "ggOffA=" << ggOffA <<
251 "ggOffC=" << ggOffC <<
5312f439 252 //
253 "ptrel0="<<ptrelative0<< // deltaTP/TP - A side
254 "ptrel1="<<ptrelative1<< // deltaTP/TPC - C side
255 "goofie.="<<&vecGoofie<<
256 "goofieE.="<<&vecEntries<<
257 "goofieMean.="<<&vecMean<<
258 "goofieMedian.="<<&vecMedian<<
259 "goofieRMS.="<<&vecRMS<<
260 //
261 "press="<<valuePressure<<
262 "press2="<<valuePressure2<<
263 "temp00.="<<&vecTemp[0]<<
264 "temp10.="<<&vecTemp[1]<<
265 "temp20.="<<&vecTemp[2]<<
266 "temp30.="<<&vecTemp[3]<<
267 "temp40.="<<&vecTemp[4]<<
268 "temp01.="<<&vecTemp[5]<<
269 "temp11.="<<&vecTemp[6]<<
270 "temp21.="<<&vecTemp[7]<<
271 "temp31.="<<&vecTemp[8]<<
272 "temp41.="<<&vecTemp[9]<<
273 "tempSkirtA.="<<&vecSkirtTempA<<
6e7d7dc4 274 "tempSkirtC.="<<&vecSkirtTempC;
275
276 (*pcstream)<<"dcs"<<
5312f439 277 //noise data
278 "meanNoise.="<<&vNoiseMean<<
279 "meanNoiseSen.="<<&vNoiseMeanSenRegions<<
280 "rmsNoise.="<<&vNoiseRMS<<
281 "rmsNoiseSen.="<<&vNoiseRMSSenRegions<<
282 "zeroNoise="<<nonMaskedZero<<
283 //pulser data
892226be 284 "timePulser.=" << &vTimePulser <<
5312f439 285 "nOffPulser="<<nOffChannels<<
892226be 286 //altro data
287 "nMasked="<<nMasked<<
5312f439 288 //ce data
289 "CEfitA.="<<&fitResultsA<<
290 "CEfitC.="<<&fitResultsC<<
892226be 291 "nmaskedCE="<<nmaskedCE<<
292 //ce graph data
293 "CEgrTEntries.="<<&vecTEntries<<
294 "CEgrTMean.="<<&vecTMean<<
295 "CEgrTRMS.="<<&vecTRMS<<
296 "CEgrTMedian.="<<&vecTMedian<<
297 "CEgrQEntries.="<<&vecQEntries<<
298 "CEgrQMean.="<<&vecQMean<<
299 "CEgrQRMS.="<<&vecQRMS<<
300 "CEgrQMedian.="<<&vecQMedian<<
892226be 301 "CEgrDriftA="<<driftTimeA<<
302 "CEgrDriftC="<<driftTimeC<<
6e7d7dc4 303 //calib raw data
304 "nFailL1="<<nFailL1<<
5312f439 305 // b field
306 "Bz="<< bz <<
307 "L3polarity="<<l3pol<<
308 // production information
309 "nalien="<<nalien<<
6fb51ca4 310 "nRawAlien="<<nRawAlien<<
5312f439 311 "nlocal="<<nlocal<<
6fb51ca4 312 "nRawLocal="<<nRawLocal<<
5312f439 313 "\n";
d47d42ee 314 }
315 }
316 delete pcstream;
317}
318
319
5312f439 320
5312f439 321
6fb51ca4 322void GetProductionInfo(Int_t run, Int_t &nalien, Int_t &nRawAlien, Int_t &nlocal, Int_t &nRawLocal){
5312f439 323 //
324 // find number of ESDs in central and local production for run
325 //
326
327 nalien=0;
6fb51ca4 328 nRawAlien=0;
5312f439 329 nlocal=0;
6fb51ca4 330 nRawLocal=0;
5312f439 331 TString sNlines;
5312f439 332 //find number of ESDs in alien
333 TString command="alien_find /alice/data/2009 ";
334 command += Form("%09d",run);
335 command += " | grep AliESDs.root | wc -l";
6fb51ca4 336 sNlines = gSystem->GetFromPipe(command.Data());
5312f439 337 nalien=sNlines.Atoi();
6fb51ca4 338 //find number of raw files on alien
339 command="alien_find /alice/data/2009 ";
340 command += Form("%09d",run);
341 command += " | grep raw | grep -v tag | wc -l";
342 sNlines = gSystem->GetFromPipe(command.Data());
343 nRawAlien=sNlines.Atoi();
5312f439 344 //find number of ESDs local
6fb51ca4 345 command="find /lustre/alice/alien/alice/data/2009 -name AliESDs.root | grep ";
5312f439 346 command += Form("%09d",run);
6fb51ca4 347 command += " | wc -l";
348 sNlines = gSystem->GetFromPipe(command.Data());
5312f439 349 nlocal=sNlines.Atoi();
6fb51ca4 350 //find number of local raw data files
351 command="find /lustre/alice/alien/alice/data/2009 -name \"*.root\" | grep ";
352 command += Form("%09d",run);
353 command += " | grep raw | grep -v tag | wc -l";
354 sNlines = gSystem->GetFromPipe(command.Data());
355 nRawLocal=sNlines.Atoi();
5312f439 356}
e2914767 357
358void FilterMag(const char * runList){
359 //
360 //
361 //
362 // AliTPCcalibDB * calibDB = AliTPCcalibDB::Instance();
363 ifstream in;
364 in.open(runList);
365 Int_t irun=0;
366 while(in.good()) {
367 in >> irun;
368 if (irun==0) continue;
369 AliGRPObject *grp = AliTPCcalibDB::GetGRP(irun);
370 Float_t current = -1;
371 Float_t bz = -1;
5312f439 372// Float_t press = 0;
e2914767 373 if (grp){
374 current = grp->GetL3Current((AliGRPObject::Stats)0);
375 bz = 5*current/30000.;
376 printf("Run%d\tL3 current%f\tBz\t%f\n",irun,current,bz);
377 }
378 else{
379 printf("Run%d\tL3 current%f\tBz\t%f\n",irun,current,bz);
380 }
381 }
7ce80437 382
383}
384
385
386void GetTree(){
387 TFile *fdcs = new TFile("dcsTime.root");
5312f439 388 dcsTree = (TTree*)fdcs->Get("dcs");
7ce80437 389 //
390 // mean temp A
5312f439 391
7ce80437 392 dcsTree->Draw("temp30.fElements[0]");
5312f439 393
e2914767 394}
395
7ce80437 396void GetNominalValues(){
397 //
398 if (!dcsTree) return;
399}
400
401
402
403
d47d42ee 404/*
405
406AliDCSSensor * sensorPressure = AliTPCcalibDB::Instance()->GetPressureSensor(62084);
407entry = AliCDBManager::Instance()->Get("TPC/Calib/Temperature",run);
408AliTPCSensorTempArray * tempArray = (AliTPCSensorTempArray *)entry->GetObject();
409AliTPCSensorTempArray * tempArray = (AliTPCSensorTempArray *)AliTPCcalibDB::Instance()->GetTemperatureSensor(62084)
410AliTPCTempMap * tempMap = new AliTPCTempMap(tempArray);
e79211e8 411TLinearFitter * fitter = tempMap->GetLinearFitter(0,0,tempArray->GetStartTime());
d47d42ee 412
413AliDCSSensorArray* goofieArray = AliTPCcalibDB::Instance()->GetGoofieSensors(62084);
414
415*/
7ce80437 416
417/*
418
419void PlotPressureResol(){
420 //
421 // Example
422 //
423 dcs->Draw("100000*(press-press2-4.782)/press/sqrt(2.)>>his(100,-50,50)","run>61400","")
424 his->SetXTitle("#sigma_{P/P_{0}}(10^{-5})");
425 gPad->SaveAs("picDCS/deltaPoverP.eps");
426 gPad->SaveAs("picDCS/deltaPoverP.gif");
5312f439 427
7ce80437 428}
429void PlotTresol(){
430 //
431 // T resolution example
432 // plot difference of the temperature from A and C side
433 // Supposing the error is independent - (division by sqrt(2))
434 dcs->Draw("100000*(temp30.fElements[0]-temp31.fElements[0]+0.00509)/(temp31.fElements[0]+273.15)/sqrt(2.)>>his(100,-5,5)","run>61400","");
435 his->SetXTitle("#sigma_{T/T_{0}}(10^{-5})");
436 gPad->SaveAs("picDCS/deltaToverT.eps");
437 gPad->SaveAs("picDCS/deltaToverT.gif");
438}
439*/