]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGPP/CalibMacros/CPass0/makeOCDB.C
updates:
[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
5cebce24 15void makeOCDB(Int_t runNumber, TString targetOCDBstorage="", TString sourceOCDBstorage="raw://")
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());
f5d76b59 38
27eb9bff 39 // Steering Tasks - set output storage
40 // DefaultStorage set already before - in ConfigCalibTrain.C
5cebce24 41
a9f9c69b 42 // Setting the mirror SEs for the default storage
43 TString mirrorsStr("ALICE::CERN::OCDB,ALICE::FZK::SE,ALICE::LLNL::SE");
44 AliCDBManager::Instance()->SetMirrorSEs(mirrorsStr.Data());
45 printf("List of mirror SEs set to: \"%s\"\n",mirrorsStr.Data());
27eb9bff 46
a9f9c69b 47 // activate target OCDB storage
48 AliCDBStorage* targetStorage = 0x0;
151e8511 49 if (targetOCDBstorage.Length()==0) {
50 targetOCDBstorage+="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
51 targetStorage = AliCDBManager::Instance()->GetStorage(targetOCDBstorage.Data());
52 }
a9f9c69b 53 else if (targetOCDBstorage.CompareTo("same",TString::kIgnoreCase) == 0 ){
54 targetStorage = AliCDBManager::Instance()->GetDefaultStorage();
55 }
56 else {
57 targetStorage = AliCDBManager::Instance()->GetStorage(targetOCDBstorage.Data());
a9f9c69b 58 }
59 printf("** targetOCDBstorage: \"%s\"\n",targetOCDBstorage.Data());
60
61 // specific storage for TPC/Calib/Correction entry
9e160db9 62 if (gSystem->AccessPathName("TPC", kFileExists)==0) {
63 AliCDBManager::Instance()->SetSpecificStorage("TPC/Calib/Correction","local://");
64 }
27eb9bff 65
66 // TPC part
f5d76b59 67 AliTPCPreprocessorOffline *procesTPC = 0;
a9f9c69b 68 if (detStr.Contains("TPC")){
5f6a1789 69 Printf("\n******* Calibrating TPC *******");
a9f9c69b 70 procesTPC = new AliTPCPreprocessorOffline;
f5d76b59 71 // switch on parameter validation
ccc4150f 72 procesTPC->SetTimeGainRange(0.5,5.0);
73 procesTPC->SetMaxVDriftCorr(0.2);
a9f9c69b 74 //procesTPC->SetMinTracksVdrift(100000);
f5d76b59 75 procesTPC->SwitchOnValidation();
5f6a1789 76
f5d76b59 77 // Make timegain calibration
5cebce24 78 //proces.CalibTimeGain("CalibObjects.root", runNumber,AliCDBRunRange::Infinity(),targetOCDBstorage);
a9f9c69b 79 procesTPC->CalibTimeGain("CalibObjects.root", runNumber,runNumber,targetStorage);
f5d76b59 80
81 // Make vdrift calibration
5cebce24 82 //proces.CalibTimeVdrift("CalibObjects.root",runNumber,AliCDBRunRange::Infinity(),targetOCDBstorage);
a9f9c69b 83 procesTPC->CalibTimeVdrift("CalibObjects.root",runNumber,runNumber,targetStorage);
f5d76b59 84 }
5f6a1789 85
27eb9bff 86 // TOF part
f5d76b59 87 AliTOFAnalysisTaskCalibPass0 *procesTOF=0;
a9f9c69b 88 if (detStr.Contains("TOF") && detStr.Contains("TPC")){
f5d76b59 89 procesTOF = new AliTOFAnalysisTaskCalibPass0;
5f6a1789 90 Printf("\n******* Calibrating TOF *******");
a9f9c69b 91 procesTOF->ProcessOutput("CalibObjects.root", targetStorage);
f5d76b59 92 }
5f6a1789 93
f5d76b59 94 // T0 part
95 AliT0PreprocessorOffline *procesT0= 0;
a9f9c69b 96 if (detStr.Contains("T0")) {
5f6a1789 97 Printf("\n******* Calibrating T0 *******");
f5d76b59 98 // Make calibration of channels offset
151e8511 99 procesT0 = new AliT0PreprocessorOffline;
a9f9c69b 100 procesT0->Process("CalibObjects.root",runNumber, runNumber, targetStorage);
f5d76b59 101 }
5f6a1789 102
f5d76b59 103 //TRD part
f5d76b59 104 AliTRDPreprocessorOffline *procesTRD = 0;
a9f9c69b 105 if (detStr.Contains("TRD") && detStr.Contains("TPC")){
5f6a1789 106 Printf("\n******* Calibrating TRD *******");
f5d76b59 107 procesTRD = new AliTRDPreprocessorOffline;
108 procesTRD->SetLinearFitForVdrift(kTRUE);
109 procesTRD->SetMinStatsVdriftT0PH(600*10);
110 procesTRD->SetMinStatsVdriftLinear(50);
111 procesTRD->SetMinStatsGain(600);
112 procesTRD->SetLimitValidateNoData(60);
113 procesTRD->SetLimitValidateBadCalib(60);
114 procesTRD->SetAlternativeDriftVelocityFit(kTRUE);
115 procesTRD->Init("CalibObjects.root");
116 Int_t versionVdriftUsed = procesTRD->GetVersionVdriftUsed();
117 Int_t subversionVdriftUsed = procesTRD->GetSubVersionVdriftUsed();
118 Int_t versionGainUsed = procesTRD->GetVersionGainUsed();
119 Int_t subversionGainUsed = procesTRD->GetSubVersionGainUsed();
120 Int_t versionExBUsed = procesTRD->GetVersionExBUsed();
121 Int_t subversionExBUsed = procesTRD->GetSubVersionExBUsed();
122 printf("version and subversion vdrift %d and %d\n",versionVdriftUsed,subversionVdriftUsed);
123 printf("version and subversion gain %d and %d\n",versionGainUsed,subversionGainUsed);
124 printf("version and subversion exb %d and %d\n",versionExBUsed,subversionExBUsed);
a9f9c69b 125 procesTRD->Process("CalibObjects.root",runNumber,runNumber,targetStorage);
f5d76b59 126 }
27eb9bff 127
f5d76b59 128 //Mean Vertex
129 AliMeanVertexPreprocessorOffline * procesMeanVtx=0;
a9f9c69b 130 if (detStr.Contains("ITSSPD")) {
5f6a1789 131 Printf("\n******* Calibrating MeanVertex *******");
a9f9c69b 132 procesMeanVtx = new AliMeanVertexPreprocessorOffline;
133 procesMeanVtx->ProcessOutput("CalibObjects.root", targetStorage, runNumber);
f5d76b59 134 }
135
136 //
137 // Print calibration status into the stdout
138 //
139 Int_t trdStatus = (procesTRD) ? procesTRD->GetStatus():0;
140 Int_t tofStatus = (procesTOF) ? procesTOF->GetStatus():0;
141 Int_t t0Status = (procesT0) ? procesT0->GetStatus():0;
a9f9c69b 142 Int_t tpcStatus = (procesTPC) ? procesTPC->GetStatus():0;
4d14c5b5 143 Int_t meanVtxStatus = (procesMeanVtx) ? procesMeanVtx->GetStatus():0;
f5d76b59 144 //
5f6a1789 145 printf("\n");
146 printf("******* CPass0 calibration status *******\n");
f5d76b59 147 printf("TRD calibration status=%d\n",trdStatus);
148 printf("TOF calibration status=%d\n",tofStatus);
149 printf("TPC calibration status=%d\n",tpcStatus);
150 printf("T0 calibration status=%d\n",t0Status);
4d14c5b5 151 printf("MeanVertex calibration status=%d\n",meanVtxStatus);
f5d76b59 152 //
153 TTreeSRedirector *pcstream = new TTreeSRedirector("cpassStat.root","recreate");
154 printCalibStat(runNumber, "CalibObjects.root",pcstream);
155 delete pcstream;
156 return;
aa5ee6d0 157}
158
159
5f6a1789 160// function to print statistics used to calibrate the various detectors
f5d76b59 161
162void printCalibStat(Int_t run, const char * fname, TTreeSRedirector * pcstream){
5f6a1789 163
f5d76b59 164 //
165 // Dump the statistical information about all histograms in the calibration files
166 // into the statistical tree, print on the screen (log files) as well
167 //
168 //
169 // 1. Default dump for all histograms
170 // Information to dump:
171 // stat =Entries, Mean, MeanError, RMS, MaxBin
172 // Branch naming convention:
173 // <detName>_<hisName><statName>
174 //
175 // 2. Detector statistical information - to be implemented by expert
176 // - First version implemented by MI
177 //
178 //
5f6a1789 179
f5d76b59 180 TFile *fin = TFile::Open(fname);
181 if (!fin) return;
182 const Double_t kMaxHis=10000;
5f6a1789 183
f5d76b59 184 TList * keyList = fin->GetListOfKeys();
185 Int_t nkeys=keyList->GetEntries();
186 Double_t *hisEntries = new Double_t[kMaxHis];
187 Double_t *hisMean = new Double_t[kMaxHis];
188 Double_t *hisMeanError = new Double_t[kMaxHis];
189 Double_t *hisRMS = new Double_t[kMaxHis];
190 Double_t *hisMaxBin = new Double_t[kMaxHis];
191 Int_t counter=0;
192
193 if (pcstream) (*pcstream)<<"calibStatAll"<<"run="<<run;
5f6a1789 194 for (Int_t ikey=0; ikey<nkeys; ikey++){
195 TObject * object = fin->Get(keyList->At(ikey)->GetName());
196 if (!object) continue;
197 if (object->InheritsFrom("TCollection")==0) continue;
198 TSeqCollection *collection = (TSeqCollection*)object;
199 Int_t nentries= collection->GetEntries();
200 for (Int_t ihis=0; ihis<nentries; ihis++){
201 TObject * ohis = collection->At(ihis);
202 if (!ohis) continue;
203 if (ohis->InheritsFrom("TH1")==0) continue;
204 TH1* phis = (TH1*)ohis;
205 hisEntries[counter]=phis->GetEntries();
206 Int_t idim=1;
207 if (ohis->InheritsFrom("TH2")) idim=2;
208 if (ohis->InheritsFrom("TH3")) idim=3;
209 hisMean[counter]=phis->GetMean(idim);
210 hisMeanError[counter]=phis->GetMeanError(idim);
211 hisRMS[counter]=phis->GetRMS(idim);
212 hisMaxBin[counter]=phis->GetBinCenter(phis->GetMaximumBin());
213 if (pcstream) (*pcstream)<<"calibStatAll"<<
214 Form("%s_%sEntries=",keyList->At(ikey)->GetName(), phis->GetName())<<hisEntries[counter]<<
215 Form("%s_%sMean=",keyList->At(ikey)->GetName(), phis->GetName())<<hisMean[counter]<<
216 Form("%s_%sMeanError=",keyList->At(ikey)->GetName(), phis->GetName())<<hisMeanError[counter]<<
217 Form("%s_%sRMS=",keyList->At(ikey)->GetName(), phis->GetName())<<hisRMS[counter]<<
218 Form("%s_%sMaxBin=",keyList->At(ikey)->GetName(), phis->GetName())<<hisMaxBin[counter];
219 //printf("Histo:\t%s_%s\t%f\t%d\n",keyList->At(ikey)->GetName(), phis->GetName(), hisEntries[counter],idim);
220 counter++;
221 }
222 delete object;
223 }
224
f5d76b59 225 //
5f6a1789 226 // Expert dump example (MI first iteration):
f5d76b59 227 //
228 // 0.) TOF dump
aa5ee6d0 229 //
5f6a1789 230
f5d76b59 231 Int_t tofEvents=0;
232 Int_t tofTracks=0;
233 TList * TOFCalib = (TList*)fin->Get("TOFHistos");
5f6a1789 234 if (TOFCalib) {
235 TH1 *histoEvents = (TH1*)TOFCalib->FindObject("hHistoVertexTimestamp");
236 TH1 *histoTracks = (TH1*)TOFCalib->FindObject("hHistoDeltatTimestamp");
237 if (histoEvents && histoTracks){
238 tofEvents = TMath::Nint(histoEvents->GetEntries());
239 tofTracks = TMath::Nint(histoTracks->GetEntries());
240 }
241 delete TOFCalib;
242 }
243 printf("Monalisa TOFevents\t%d\n",tofEvents);
f5d76b59 244 if (pcstream) (*pcstream)<<"calibStatAll"<<"TOFevents="<<tofEvents;
5f6a1789 245 printf("Monalisa TOFtracks\t%d\n",tofTracks);
f5d76b59 246 if (pcstream) (*pcstream)<<"calibStatAll"<<"TOFtracks="<<tofTracks;
5f6a1789 247
aa5ee6d0 248 //
f5d76b59 249 // 1.) TPC dump - usefull events/tracks for the calibration
aa5ee6d0 250 //
f5d76b59 251 Int_t tpcEvents=0;
252 Int_t tpcTracks=0;
20fcf270 253 TObject* obj = dynamic_cast<TObject*>(fin->Get("TPCCalib"));
254 TObjArray* array = dynamic_cast<TObjArray*>(obj);
255 TDirectory* dir = dynamic_cast<TDirectory*>(obj);
256 AliTPCcalibTime * calibTime = NULL;
257 if (dir) {
258 calibTime = dynamic_cast<AliTPCcalibTime*>(dir->Get("calibTime"));
259 }
260 else if (array){
261 calibTime = (AliTPCcalibTime *)array->FindObject("calibTime");
262 }
263 if (calibTime) {
5f6a1789 264 tpcEvents = TMath::Nint(calibTime->GetTPCVertexHisto(0)->GetEntries());
265 tpcTracks = TMath::Nint(calibTime->GetResHistoTPCITS(0)->GetEntries());
5f6a1789 266 }
267 printf("Monalisa TPCevents\t%d\n",tpcEvents);
f5d76b59 268 if (pcstream) (*pcstream)<<"calibStatAll"<<"TPCevents="<<tpcEvents;
5f6a1789 269 printf("Monalisa TPCtracks\t%d\n",tpcTracks);
f5d76b59 270 if (pcstream) (*pcstream)<<"calibStatAll"<<"TPCtracks="<<tpcTracks;
5f6a1789 271
aa5ee6d0 272 //
f5d76b59 273 // 2. TRD dump
274 //
275 Int_t trdEvents=0;
276 Int_t trdTracks=0;
277 TList * TRDCalib = (TList*)fin->Get("TRDCalib");
5f6a1789 278 if (TRDCalib) {
279 TH1 *histoEvents = (TH1*)TRDCalib->FindObject("NEventsInput_AliTRDCalibTask");
280 TH1 *histoTracks = (TH1*)TRDCalib->FindObject("AbsoluteGain_AliTRDCalibTask");
281 if (histoEvents && histoTracks){
282 trdEvents= TMath::Nint(histoEvents->GetEntries());
283 trdTracks= TMath::Nint(histoTracks->GetEntries());
284 }
285 delete TRDCalib;
286 }
287 printf("Monalisa TRDevents\t%d\n",trdEvents);
f5d76b59 288 if (pcstream) (*pcstream)<<"calibStatAll"<<"TRDevents="<<trdEvents;
5f6a1789 289 printf("Monalisa TRDtracks\t%d\n",trdTracks);
f5d76b59 290 if (pcstream) (*pcstream)<<"calibStatAll"<<"TRDtracks="<<trdTracks;
5f6a1789 291
f5d76b59 292 //
293 // 3. T0 dump
294 //
295 Int_t T0Events=0;
296 TList * T0Calib = (TList*)fin->Get("T0Calib");
5f6a1789 297 if (T0Calib) {
298 TH1 *histoEvents = (TH1*) T0Calib->FindObject("fTzeroORAplusORC");
299 if (histoEvents){
300 T0Events= TMath::Nint(histoEvents->GetEntries());
301 }
302 delete T0Calib;
303 }
304 printf("Monalisa T0events\t%d\n",T0Events);
f5d76b59 305 if (pcstream) (*pcstream)<<"calibStatAll"<<"T0events="<<T0Events;
5f6a1789 306
f5d76b59 307 //
5f6a1789 308 // 4. Mean vertex - dump
309 Int_t meanVertexEvents=0;
310 TList * meanVertexCalib = (TList*)fin->Get("MeanVertex");
311 if (meanVertexCalib) {
caf1b142 312 TH1 *histoEvents = (TH1*) meanVertexCalib->FindObject("hTRKVertexX");
5cebce24 313 if (histoEvents){
5f6a1789 314 meanVertexEvents = TMath::Nint(histoEvents->GetEntries());
315 }
316 delete meanVertexCalib;
317 }
318 printf("Monalisa MeanVertexevents\t%d\n",meanVertexEvents);
319 if (pcstream) (*pcstream)<<"calibStatAll"<<"MeanVertexevents="<<meanVertexEvents;
320
f5d76b59 321 //
5f6a1789 322 // 5. SDD dump
f5d76b59 323 //
324 Int_t sddEvents=0;
325 Int_t sddTracks=0;
326 TList * SDDCalib = (TList*)fin->Get("clistSDDCalib");
5f6a1789 327 if (SDDCalib) {
328 TH1 *histoEvents = (TH1*) SDDCalib->FindObject("hNEvents");
329 if (histoEvents ){
330 sddEvents = TMath::Nint(histoEvents->GetBinContent(4));
331 sddTracks = TMath::Nint(histoEvents->GetBinContent(5));
332 }
333 delete SDDCalib;
334 }
335 printf("Monalisa SDDevents\t%d\n",sddEvents);
f5d76b59 336 if (pcstream) (*pcstream)<<"calibStatAll"<<"SDDevents="<<sddEvents;
5f6a1789 337 printf("Monalisa SDDtracks\t%d\n",sddTracks);
f5d76b59 338 if (pcstream) (*pcstream)<<"calibStatAll"<<"SDDtracks="<<sddTracks;
5f6a1789 339
f5d76b59 340 //
341 if (pcstream) (*pcstream)<<"calibStatAll"<<"\n";
342 delete fin;
343
27eb9bff 344}
f5d76b59 345