]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGPP/CalibMacros/CPass0/makeOCDB.C
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / PWGPP / CalibMacros / CPass0 / makeOCDB.C
CommitLineData
27eb9bff 1/*
2 macro to extract the OCDB entries
3
4 input: CalibObjects.root
5 ouput: TimeGain and TimeVdrift calibration objects for TPC and TRD
6
7 Example:
4c8432c7 8 .L $ALICE_ROOT/PWGPP/CalibMacros/CPass0/makeOCDB.C
27eb9bff 9 makeOCDB("105160");
10
11*/
12
f5d76b59 13void printCalibStat(Int_t run, const char * fname, TTreeSRedirector * pcstream);
aa5ee6d0 14
a4d010b1 15void makeOCDB(Int_t runNumber, TString targetOCDBstorage="", TString sourceOCDBstorage="raw://", Int_t detectorBitsQualityFlag = -1)
27eb9bff 16{
17 //
5f6a1789 18 // extract OCDB entries for detectors participating in the calibration for the current run
27eb9bff 19 //
5f6a1789 20
cd9dc5c7 21 gROOT->Macro("$ALICE_ROOT/PWGPP/CalibMacros/CPass0/LoadLibraries.C");
22 gROOT->LoadMacro("$ALICE_ROOT/PWGPP/CalibMacros/CPass0/ConfigCalibTrain.C");
27eb9bff 23
24 // switch off log info
25 AliLog::SetClassDebugLevel("AliESDEvent",0);
26
27 // config GRP
27eb9bff 28 printf("runNumber from runCalibTrain = %d\n",runNumber);
5cebce24 29 ConfigCalibTrain(runNumber, sourceOCDBstorage.Data());
5f6a1789 30
f5d76b59 31 // check the presence of the detectors
32 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
a9f9c69b 33 AliGRPObject* grpData = dynamic_cast<AliGRPObject*>(entry->GetObject());
f5d76b59 34 if (!grpData) {printf("Failed to get GRP data for run",runNumber); return;}
a9f9c69b 35 Int_t activeDetectors = grpData->GetDetectorMask();
f5d76b59 36 TString detStr = AliDAQ::ListOfTriggeredDetectors(activeDetectors);
37 printf("Detectors in the data:\n%s\n",detStr.Data());
5803b241 38 TString LHCperiod = grpData->GetLHCPeriod();
39 Bool_t isLHC10 = LHCperiod.Contains("LHC10");
40 printf("LHCperiod:%s\n isLHC10:%d\n",LHCperiod.Data(),(Int_t)isLHC10);
f5d76b59 41
27eb9bff 42 // Steering Tasks - set output storage
43 // DefaultStorage set already before - in ConfigCalibTrain.C
5cebce24 44
a9f9c69b 45 // Setting the mirror SEs for the default storage
46 TString mirrorsStr("ALICE::CERN::OCDB,ALICE::FZK::SE,ALICE::LLNL::SE");
47 AliCDBManager::Instance()->SetMirrorSEs(mirrorsStr.Data());
48 printf("List of mirror SEs set to: \"%s\"\n",mirrorsStr.Data());
27eb9bff 49
a9f9c69b 50 // activate target OCDB storage
51 AliCDBStorage* targetStorage = 0x0;
151e8511 52 if (targetOCDBstorage.Length()==0) {
53 targetOCDBstorage+="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
54 targetStorage = AliCDBManager::Instance()->GetStorage(targetOCDBstorage.Data());
55 }
a9f9c69b 56 else if (targetOCDBstorage.CompareTo("same",TString::kIgnoreCase) == 0 ){
57 targetStorage = AliCDBManager::Instance()->GetDefaultStorage();
58 }
59 else {
60 targetStorage = AliCDBManager::Instance()->GetStorage(targetOCDBstorage.Data());
a9f9c69b 61 }
62 printf("** targetOCDBstorage: \"%s\"\n",targetOCDBstorage.Data());
63
64 // specific storage for TPC/Calib/Correction entry
9e160db9 65 if (gSystem->AccessPathName("TPC", kFileExists)==0) {
66 AliCDBManager::Instance()->SetSpecificStorage("TPC/Calib/Correction","local://");
67 }
27eb9bff 68
2fc6be25 69 // Magnetic field
70 AliMagF* fld = TGeoGlobalMagField::Instance()->GetField();
71 Double_t bz = fld->SolenoidField();
72 Bool_t isMagFieldON = kTRUE;
73 if (TMath::Abs(bz)>0) {
74 printf("Mag field is %f --> ON\n", bz);
75 }
76 else {
77 isMagFieldON = kFALSE;
78 printf("Mag field is %f --> OFF\n", bz);
79 }
80
a4d010b1 81 // Quality flags
82 Bool_t TPC_qf = kTRUE;
83 Bool_t TOF_qf = kTRUE;
84 Bool_t TRD_qf = kTRUE;
85 Bool_t T0_qf = kTRUE;
86 Bool_t SDD_qf = kTRUE;
87 Bool_t SPD_qf = kTRUE;
88
89 if (detectorBitsQualityFlag != -1){
90 TPC_qf = ((detectorBitsQualityFlag & AliDAQ::kTPC_QF) == AliDAQ::kTPC_QF)? kTRUE : kFALSE;
91 TOF_qf = ((detectorBitsQualityFlag & AliDAQ::kTOF_QF) == AliDAQ::kTOF_QF)? kTRUE : kFALSE;
92 TRD_qf = ((detectorBitsQualityFlag & AliDAQ::kTRD_QF) == AliDAQ::kTRD_QF)? kTRUE : kFALSE;
93 T0_qf = ((detectorBitsQualityFlag & AliDAQ::kT0_QF) == AliDAQ::kT0_QF)? kTRUE : kFALSE;
94 SDD_qf = ((detectorBitsQualityFlag & AliDAQ::kSDD_QF) == AliDAQ::kSDD_QF)? kTRUE : kFALSE;
95 SPD_qf = ((detectorBitsQualityFlag & AliDAQ::kSPD_QF) == AliDAQ::kSPD_QF)? kTRUE : kFALSE;
96 }
97
98 Printf("Quality flags: detectorBitsQualityFlag = %d, TPC = %d, TOF = %d, TRD = %d, T0 = %d, SDD = %d, SPD = %d", detectorBitsQualityFlag, (Int_t)TPC_qf, (Int_t)TOF_qf, (Int_t)TRD_qf, (Int_t)T0_qf, (Int_t)SDD_qf, (Int_t)SPD_qf);
99 return;
100
27eb9bff 101 // TPC part
f5d76b59 102 AliTPCPreprocessorOffline *procesTPC = 0;
a4d010b1 103 if (detStr.Contains("TPC") && TPC_qf){
5f6a1789 104 Printf("\n******* Calibrating TPC *******");
a9f9c69b 105 procesTPC = new AliTPCPreprocessorOffline;
f5d76b59 106 // switch on parameter validation
ccc4150f 107 procesTPC->SetTimeGainRange(0.5,5.0);
108 procesTPC->SetMaxVDriftCorr(0.2);
a9f9c69b 109 //procesTPC->SetMinTracksVdrift(100000);
f5d76b59 110 procesTPC->SwitchOnValidation();
5f6a1789 111
f5d76b59 112 // Make timegain calibration
5cebce24 113 //proces.CalibTimeGain("CalibObjects.root", runNumber,AliCDBRunRange::Infinity(),targetOCDBstorage);
2fc6be25 114 if (isMagFieldON) procesTPC->CalibTimeGain("CalibObjects.root", runNumber,runNumber,targetStorage);
f5d76b59 115
116 // Make vdrift calibration
5cebce24 117 //proces.CalibTimeVdrift("CalibObjects.root",runNumber,AliCDBRunRange::Infinity(),targetOCDBstorage);
a9f9c69b 118 procesTPC->CalibTimeVdrift("CalibObjects.root",runNumber,runNumber,targetStorage);
f5d76b59 119 }
a4d010b1 120 else {
121 Printf("\n******* NOT Calibrating TPC: detStr = %s, TPC_qf = %d *******", detStr.Data(), (Int_t)TPC_qf);
122 }
5f6a1789 123
27eb9bff 124 // TOF part
f5d76b59 125 AliTOFAnalysisTaskCalibPass0 *procesTOF=0;
a4d010b1 126 if (detStr.Contains("TOF") && detStr.Contains("TPC") && TOF_qf){
f5d76b59 127 procesTOF = new AliTOFAnalysisTaskCalibPass0;
5f6a1789 128 Printf("\n******* Calibrating TOF *******");
2fc6be25 129 if (isMagFieldON) procesTOF->ProcessOutput("CalibObjects.root", targetStorage);
130 else {
131 printf("Not calibrating TOF in case of mag field OFF\n");
132 }
f5d76b59 133 }
a4d010b1 134 else {
135 Printf("\n******* NOT Calibrating TOF: detStr = %s, TOF_qf = %d *******", detStr.Data(), (Int_t)TOF_qf);
136 }
5f6a1789 137
f5d76b59 138 // T0 part
139 AliT0PreprocessorOffline *procesT0= 0;
a4d010b1 140 if (detStr.Contains("T0") && T0_qf) {
5f6a1789 141 Printf("\n******* Calibrating T0 *******");
f5d76b59 142 // Make calibration of channels offset
151e8511 143 procesT0 = new AliT0PreprocessorOffline;
a2021d69 144 if(isLHC10)
145 procesT0->CalibOffsetChannels("CalibObjects.root",runNumber, runNumber, targetStorage);
146 else
147 procesT0->Process("CalibObjects.root",runNumber, runNumber, targetStorage);
f5d76b59 148 }
a4d010b1 149 else {
150 Printf("\n******* NOT Calibrating T0: detStr = %s, T0_qf = %d *******", detStr.Data(), (Int_t)T0_qf);
151 }
5f6a1789 152
f5d76b59 153 //TRD part
f5d76b59 154 AliTRDPreprocessorOffline *procesTRD = 0;
a4d010b1 155 if (detStr.Contains("TRD") && detStr.Contains("TPC") && TRD_qf){
5f6a1789 156 Printf("\n******* Calibrating TRD *******");
f5d76b59 157 procesTRD = new AliTRDPreprocessorOffline;
5803b241 158 if(isLHC10) procesTRD->SetSwitchOnChamberStatus(kFALSE);
f5d76b59 159 procesTRD->SetLinearFitForVdrift(kTRUE);
160 procesTRD->SetMinStatsVdriftT0PH(600*10);
161 procesTRD->SetMinStatsVdriftLinear(50);
162 procesTRD->SetMinStatsGain(600);
163 procesTRD->SetLimitValidateNoData(60);
164 procesTRD->SetLimitValidateBadCalib(60);
165 procesTRD->SetAlternativeDriftVelocityFit(kTRUE);
166 procesTRD->Init("CalibObjects.root");
167 Int_t versionVdriftUsed = procesTRD->GetVersionVdriftUsed();
168 Int_t subversionVdriftUsed = procesTRD->GetSubVersionVdriftUsed();
169 Int_t versionGainUsed = procesTRD->GetVersionGainUsed();
170 Int_t subversionGainUsed = procesTRD->GetSubVersionGainUsed();
171 Int_t versionExBUsed = procesTRD->GetVersionExBUsed();
172 Int_t subversionExBUsed = procesTRD->GetSubVersionExBUsed();
173 printf("version and subversion vdrift %d and %d\n",versionVdriftUsed,subversionVdriftUsed);
174 printf("version and subversion gain %d and %d\n",versionGainUsed,subversionGainUsed);
175 printf("version and subversion exb %d and %d\n",versionExBUsed,subversionExBUsed);
a9f9c69b 176 procesTRD->Process("CalibObjects.root",runNumber,runNumber,targetStorage);
f5d76b59 177 }
a4d010b1 178 else {
179 Printf("\n******* NOT Calibrating TRD: detStr = %s, TRD_qf = %d *******", detStr.Data(), (Int_t)TRD_qf);
180 }
27eb9bff 181
f5d76b59 182 //Mean Vertex
183 AliMeanVertexPreprocessorOffline * procesMeanVtx=0;
a4d010b1 184 if (detStr.Contains("ITSSPD") && SPD_qf) {
5f6a1789 185 Printf("\n******* Calibrating MeanVertex *******");
a9f9c69b 186 procesMeanVtx = new AliMeanVertexPreprocessorOffline;
187 procesMeanVtx->ProcessOutput("CalibObjects.root", targetStorage, runNumber);
f5d76b59 188 }
a4d010b1 189 else {
190 Printf("\n******* NOT Calibrating MeanVertex: detStr = %s, SPD_qf = %d *******", detStr.Data(), (Int_t)SPD_qf);
191 }
f5d76b59 192
193 //
194 // Print calibration status into the stdout
195 //
196 Int_t trdStatus = (procesTRD) ? procesTRD->GetStatus():0;
197 Int_t tofStatus = (procesTOF) ? procesTOF->GetStatus():0;
198 Int_t t0Status = (procesT0) ? procesT0->GetStatus():0;
a9f9c69b 199 Int_t tpcStatus = (procesTPC) ? procesTPC->GetStatus():0;
4d14c5b5 200 Int_t meanVtxStatus = (procesMeanVtx) ? procesMeanVtx->GetStatus():0;
f5d76b59 201 //
5f6a1789 202 printf("\n");
203 printf("******* CPass0 calibration status *******\n");
f5d76b59 204 printf("TRD calibration status=%d\n",trdStatus);
205 printf("TOF calibration status=%d\n",tofStatus);
206 printf("TPC calibration status=%d\n",tpcStatus);
207 printf("T0 calibration status=%d\n",t0Status);
4d14c5b5 208 printf("MeanVertex calibration status=%d\n",meanVtxStatus);
f5d76b59 209 //
210 TTreeSRedirector *pcstream = new TTreeSRedirector("cpassStat.root","recreate");
211 printCalibStat(runNumber, "CalibObjects.root",pcstream);
212 delete pcstream;
213 return;
aa5ee6d0 214}
215
216
5f6a1789 217// function to print statistics used to calibrate the various detectors
f5d76b59 218
219void printCalibStat(Int_t run, const char * fname, TTreeSRedirector * pcstream){
5f6a1789 220
f5d76b59 221 //
222 // Dump the statistical information about all histograms in the calibration files
223 // into the statistical tree, print on the screen (log files) as well
224 //
225 //
226 // 1. Default dump for all histograms
227 // Information to dump:
228 // stat =Entries, Mean, MeanError, RMS, MaxBin
229 // Branch naming convention:
230 // <detName>_<hisName><statName>
231 //
232 // 2. Detector statistical information - to be implemented by expert
233 // - First version implemented by MI
234 //
235 //
5f6a1789 236
f5d76b59 237 TFile *fin = TFile::Open(fname);
238 if (!fin) return;
239 const Double_t kMaxHis=10000;
5f6a1789 240
f5d76b59 241 TList * keyList = fin->GetListOfKeys();
242 Int_t nkeys=keyList->GetEntries();
243 Double_t *hisEntries = new Double_t[kMaxHis];
244 Double_t *hisMean = new Double_t[kMaxHis];
245 Double_t *hisMeanError = new Double_t[kMaxHis];
246 Double_t *hisRMS = new Double_t[kMaxHis];
247 Double_t *hisMaxBin = new Double_t[kMaxHis];
248 Int_t counter=0;
249
250 if (pcstream) (*pcstream)<<"calibStatAll"<<"run="<<run;
5f6a1789 251 for (Int_t ikey=0; ikey<nkeys; ikey++){
252 TObject * object = fin->Get(keyList->At(ikey)->GetName());
253 if (!object) continue;
254 if (object->InheritsFrom("TCollection")==0) continue;
255 TSeqCollection *collection = (TSeqCollection*)object;
256 Int_t nentries= collection->GetEntries();
257 for (Int_t ihis=0; ihis<nentries; ihis++){
258 TObject * ohis = collection->At(ihis);
259 if (!ohis) continue;
260 if (ohis->InheritsFrom("TH1")==0) continue;
261 TH1* phis = (TH1*)ohis;
262 hisEntries[counter]=phis->GetEntries();
263 Int_t idim=1;
264 if (ohis->InheritsFrom("TH2")) idim=2;
265 if (ohis->InheritsFrom("TH3")) idim=3;
266 hisMean[counter]=phis->GetMean(idim);
267 hisMeanError[counter]=phis->GetMeanError(idim);
268 hisRMS[counter]=phis->GetRMS(idim);
269 hisMaxBin[counter]=phis->GetBinCenter(phis->GetMaximumBin());
270 if (pcstream) (*pcstream)<<"calibStatAll"<<
271 Form("%s_%sEntries=",keyList->At(ikey)->GetName(), phis->GetName())<<hisEntries[counter]<<
272 Form("%s_%sMean=",keyList->At(ikey)->GetName(), phis->GetName())<<hisMean[counter]<<
273 Form("%s_%sMeanError=",keyList->At(ikey)->GetName(), phis->GetName())<<hisMeanError[counter]<<
274 Form("%s_%sRMS=",keyList->At(ikey)->GetName(), phis->GetName())<<hisRMS[counter]<<
275 Form("%s_%sMaxBin=",keyList->At(ikey)->GetName(), phis->GetName())<<hisMaxBin[counter];
276 //printf("Histo:\t%s_%s\t%f\t%d\n",keyList->At(ikey)->GetName(), phis->GetName(), hisEntries[counter],idim);
277 counter++;
278 }
279 delete object;
280 }
281
f5d76b59 282 //
5f6a1789 283 // Expert dump example (MI first iteration):
f5d76b59 284 //
285 // 0.) TOF dump
aa5ee6d0 286 //
5f6a1789 287
f5d76b59 288 Int_t tofEvents=0;
289 Int_t tofTracks=0;
290 TList * TOFCalib = (TList*)fin->Get("TOFHistos");
5f6a1789 291 if (TOFCalib) {
292 TH1 *histoEvents = (TH1*)TOFCalib->FindObject("hHistoVertexTimestamp");
293 TH1 *histoTracks = (TH1*)TOFCalib->FindObject("hHistoDeltatTimestamp");
294 if (histoEvents && histoTracks){
295 tofEvents = TMath::Nint(histoEvents->GetEntries());
296 tofTracks = TMath::Nint(histoTracks->GetEntries());
297 }
298 delete TOFCalib;
299 }
300 printf("Monalisa TOFevents\t%d\n",tofEvents);
f5d76b59 301 if (pcstream) (*pcstream)<<"calibStatAll"<<"TOFevents="<<tofEvents;
5f6a1789 302 printf("Monalisa TOFtracks\t%d\n",tofTracks);
f5d76b59 303 if (pcstream) (*pcstream)<<"calibStatAll"<<"TOFtracks="<<tofTracks;
5f6a1789 304
aa5ee6d0 305 //
f5d76b59 306 // 1.) TPC dump - usefull events/tracks for the calibration
aa5ee6d0 307 //
f5d76b59 308 Int_t tpcEvents=0;
309 Int_t tpcTracks=0;
20fcf270 310 TObject* obj = dynamic_cast<TObject*>(fin->Get("TPCCalib"));
311 TObjArray* array = dynamic_cast<TObjArray*>(obj);
312 TDirectory* dir = dynamic_cast<TDirectory*>(obj);
313 AliTPCcalibTime * calibTime = NULL;
314 if (dir) {
315 calibTime = dynamic_cast<AliTPCcalibTime*>(dir->Get("calibTime"));
316 }
317 else if (array){
318 calibTime = (AliTPCcalibTime *)array->FindObject("calibTime");
319 }
320 if (calibTime) {
5f6a1789 321 tpcEvents = TMath::Nint(calibTime->GetTPCVertexHisto(0)->GetEntries());
322 tpcTracks = TMath::Nint(calibTime->GetResHistoTPCITS(0)->GetEntries());
5f6a1789 323 }
324 printf("Monalisa TPCevents\t%d\n",tpcEvents);
f5d76b59 325 if (pcstream) (*pcstream)<<"calibStatAll"<<"TPCevents="<<tpcEvents;
5f6a1789 326 printf("Monalisa TPCtracks\t%d\n",tpcTracks);
f5d76b59 327 if (pcstream) (*pcstream)<<"calibStatAll"<<"TPCtracks="<<tpcTracks;
5f6a1789 328
aa5ee6d0 329 //
f5d76b59 330 // 2. TRD dump
331 //
332 Int_t trdEvents=0;
333 Int_t trdTracks=0;
334 TList * TRDCalib = (TList*)fin->Get("TRDCalib");
5f6a1789 335 if (TRDCalib) {
336 TH1 *histoEvents = (TH1*)TRDCalib->FindObject("NEventsInput_AliTRDCalibTask");
337 TH1 *histoTracks = (TH1*)TRDCalib->FindObject("AbsoluteGain_AliTRDCalibTask");
338 if (histoEvents && histoTracks){
339 trdEvents= TMath::Nint(histoEvents->GetEntries());
340 trdTracks= TMath::Nint(histoTracks->GetEntries());
341 }
342 delete TRDCalib;
343 }
344 printf("Monalisa TRDevents\t%d\n",trdEvents);
f5d76b59 345 if (pcstream) (*pcstream)<<"calibStatAll"<<"TRDevents="<<trdEvents;
5f6a1789 346 printf("Monalisa TRDtracks\t%d\n",trdTracks);
f5d76b59 347 if (pcstream) (*pcstream)<<"calibStatAll"<<"TRDtracks="<<trdTracks;
5f6a1789 348
f5d76b59 349 //
350 // 3. T0 dump
351 //
352 Int_t T0Events=0;
353 TList * T0Calib = (TList*)fin->Get("T0Calib");
5f6a1789 354 if (T0Calib) {
355 TH1 *histoEvents = (TH1*) T0Calib->FindObject("fTzeroORAplusORC");
356 if (histoEvents){
357 T0Events= TMath::Nint(histoEvents->GetEntries());
358 }
359 delete T0Calib;
360 }
361 printf("Monalisa T0events\t%d\n",T0Events);
f5d76b59 362 if (pcstream) (*pcstream)<<"calibStatAll"<<"T0events="<<T0Events;
5f6a1789 363
f5d76b59 364 //
5f6a1789 365 // 4. Mean vertex - dump
366 Int_t meanVertexEvents=0;
367 TList * meanVertexCalib = (TList*)fin->Get("MeanVertex");
368 if (meanVertexCalib) {
caf1b142 369 TH1 *histoEvents = (TH1*) meanVertexCalib->FindObject("hTRKVertexX");
5cebce24 370 if (histoEvents){
5f6a1789 371 meanVertexEvents = TMath::Nint(histoEvents->GetEntries());
372 }
373 delete meanVertexCalib;
374 }
375 printf("Monalisa MeanVertexevents\t%d\n",meanVertexEvents);
376 if (pcstream) (*pcstream)<<"calibStatAll"<<"MeanVertexevents="<<meanVertexEvents;
377
f5d76b59 378 //
5f6a1789 379 // 5. SDD dump
f5d76b59 380 //
381 Int_t sddEvents=0;
382 Int_t sddTracks=0;
383 TList * SDDCalib = (TList*)fin->Get("clistSDDCalib");
5f6a1789 384 if (SDDCalib) {
385 TH1 *histoEvents = (TH1*) SDDCalib->FindObject("hNEvents");
386 if (histoEvents ){
387 sddEvents = TMath::Nint(histoEvents->GetBinContent(4));
388 sddTracks = TMath::Nint(histoEvents->GetBinContent(5));
389 }
390 delete SDDCalib;
391 }
392 printf("Monalisa SDDevents\t%d\n",sddEvents);
f5d76b59 393 if (pcstream) (*pcstream)<<"calibStatAll"<<"SDDevents="<<sddEvents;
5f6a1789 394 printf("Monalisa SDDtracks\t%d\n",sddTracks);
f5d76b59 395 if (pcstream) (*pcstream)<<"calibStatAll"<<"SDDtracks="<<sddTracks;
5f6a1789 396
f5d76b59 397 //
398 if (pcstream) (*pcstream)<<"calibStatAll"<<"\n";
399 delete fin;
400
27eb9bff 401}
f5d76b59 402