1 /**************************************************************************
2 * Copyright(c) 1998-2011, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
19 // Mean Vertex preprocessor:
20 // 2) takes data after pass0 ,
21 // processes it, and stores either to OCDB .
25 #include "AliMeanVertexPreprocessorOffline.h"
27 #include "AliCDBStorage.h"
28 #include "AliCDBMetaData.h"
29 #include "AliCDBManager.h"
30 #include "AliCDBEntry.h"
33 #include <TTimeStamp.h>
35 #include <TObjString.h>
39 #include "AliESDVertex.h"
46 ClassImp(AliMeanVertexPreprocessorOffline)
48 //____________________________________________________
49 AliMeanVertexPreprocessorOffline::AliMeanVertexPreprocessorOffline():
50 TNamed("AliMeanVertexPreprocessorOffline","AliMeanVertexPreprocessorOffline")
55 //____________________________________________________
57 AliMeanVertexPreprocessorOffline::~AliMeanVertexPreprocessorOffline()
62 //____________________________________________________
63 void AliMeanVertexPreprocessorOffline::ProcessOutput(const char *filename, const char *dbString, Int_t runNb){
65 TFile *file = TFile::Open(filename);
66 if (!file || !file->IsOpen()){
67 AliError(Form("cannot open outputfile %s", filename));
72 AliError(Form("no OCDB path found, return"));
77 TList *list = (TList*)file->Get("MeanVertex");
79 TH1F *histTRKvtxX = 0x0;
80 TH1F *histTRKvtxY = 0x0;
81 TH1F *histTRKvtxZ = 0x0;
83 TH1F *histSPDvtxX = 0x0;
84 TH1F *histSPDvtxY = 0x0;
85 TH1F *histSPDvtxZ = 0x0;
88 Bool_t useTRKvtx = kTRUE;
89 Bool_t useITSSAvtx = kFALSE;
90 Bool_t useSPDvtx = kFALSE;
91 Bool_t spdAvailable = kTRUE;
92 Bool_t writeMeanVertexSPD = kFALSE;
93 Bool_t vertexerSPD3Doff=kFALSE;
98 histTRKvtxX = (TH1F*)file->Get("hTRKVertexX");
99 histTRKvtxY = (TH1F*)file->Get("hTRKVertexY");
100 histTRKvtxZ = (TH1F*)file->Get("hTRKVertexZ");
102 histSPDvtxX = (TH1F*)file->Get("hSPDVertexX");
103 histSPDvtxY = (TH1F*)file->Get("hSPDVertexY");
104 histSPDvtxZ = (TH1F*)file->Get("hSPDVertexZ");
106 if (!histTRKvtxX || !histTRKvtxY || !histTRKvtxZ){
111 histTRKvtxX = (TH1F*)file->FindObject("hITSSAVertexX");
112 histTRKvtxY = (TH1F*)file->FindObject("hITSSAVertexY");
113 histTRKvtxZ = (TH1F*)file->FindObject("hITSSAVertexZ");
115 if (!histTRKvtxX || !histTRKvtxY || !histTRKvtxZ){
120 if (!histSPDvtxX || !histSPDvtxY || !histSPDvtxZ){
121 AliError(Form("cannot find any histograms available from file"));
130 histTRKvtxX = (TH1F*)list->FindObject("hTRKVertexX");
131 histTRKvtxY = (TH1F*)list->FindObject("hTRKVertexY");
132 histTRKvtxZ = (TH1F*)list->FindObject("hTRKVertexZ");
134 histSPDvtxX = (TH1F*)list->FindObject("hSPDVertexX");
135 histSPDvtxY = (TH1F*)list->FindObject("hSPDVertexY");
136 histSPDvtxZ = (TH1F*)list->FindObject("hSPDVertexZ");
138 if (!histTRKvtxX || !histTRKvtxY || !histTRKvtxZ){
143 histTRKvtxX = (TH1F*)list->FindObject("hITSSAVertexX");
144 histTRKvtxY = (TH1F*)list->FindObject("hITSSAVertexY");
145 histTRKvtxZ = (TH1F*)list->FindObject("hITSSAVertexZ");
147 if (!histTRKvtxX || !histTRKvtxY || !histTRKvtxZ){
152 if (!histSPDvtxX || !histSPDvtxY || !histSPDvtxZ){
153 AliError(Form("cannot find any histograms available from list"));
164 Float_t nEntriesX = histTRKvtxX->GetEffectiveEntries();
165 Float_t nEntriesY = histTRKvtxY->GetEffectiveEntries();
166 Float_t nEntriesZ = histTRKvtxZ->GetEffectiveEntries();
168 if (nEntriesX < 50. || nEntriesY<50. || nEntriesZ<50.) {
169 AliError(Form("TRK vertex histograms have too few entries for fitting"));
176 Float_t nEntriesX = histTRKvtxX->GetEffectiveEntries();
177 Float_t nEntriesY = histTRKvtxY->GetEffectiveEntries();
178 Float_t nEntriesZ = histTRKvtxZ->GetEffectiveEntries();
180 if (nEntriesX < 50. || nEntriesY<50. || nEntriesZ<50.) {
181 AliError(Form("ITSSA vertex histograms have too few entries for fitting"));
187 Float_t nEntriesX = histSPDvtxX->GetEffectiveEntries();
188 Float_t nEntriesY = histSPDvtxY->GetEffectiveEntries();
189 Float_t nEntriesZ = histSPDvtxZ->GetEffectiveEntries();
191 if (nEntriesX < 50. || nEntriesY<50. || nEntriesZ<50.) {
192 spdAvailable = kFALSE;
193 if ((useTRKvtx==kFALSE) && (useITSSAvtx==kFALSE)){
194 AliError(Form("Also SPD vertex histograms have too few entries for fitting, return"));
199 if((nEntriesX == 0.)&&(nEntriesY==0.) && (nEntriesZ>0.)){
200 vertexerSPD3Doff = kTRUE;
201 AliWarning("Vertexer SPD 3D off");
204 Double_t xMeanVtx=0., yMeanVtx=0., zMeanVtx=0.;
205 Double_t xSigmaVtx=0., ySigmaVtx=0., zSigmaVtx=0.;
208 TF1 *fitVtxX, *fitVtxY, *fitVtxZ;
210 if (useTRKvtx || useITSSAvtx){
211 histTRKvtxX ->Fit("gaus", "M");
212 fitVtxX = histTRKvtxX -> GetFunction("gaus");
213 xMeanVtx = fitVtxX -> GetParameter(1);
214 if (TMath::Abs(xMeanVtx) > 2.) {
216 writeMeanVertexSPD=kTRUE;
219 histTRKvtxY ->Fit("gaus", "M");
220 fitVtxY = histTRKvtxY -> GetFunction("gaus");
221 yMeanVtx = fitVtxY -> GetParameter(1);
222 if (TMath::Abs(yMeanVtx) > 2.) {
224 writeMeanVertexSPD=kTRUE;
227 histTRKvtxZ ->Fit("gaus", "M");
228 fitVtxZ = histTRKvtxZ -> GetFunction("gaus");
229 zMeanVtx = fitVtxZ -> GetParameter(1);
230 zSigmaVtx = fitVtxZ -> GetParameter(2);
231 if ((TMath::Abs(zMeanVtx) > 20.) || (zSigmaVtx>12.)) {
234 writeMeanVertexSPD=kTRUE;
240 //check fits: compare histo mean with fit mean value
241 Double_t xHistoMean, yHistoMean, zHistoMean;
242 Double_t xHistoRMS, yHistoRMS, zHistoRMS;
244 if (useTRKvtx || useITSSAvtx){
245 xHistoMean = histTRKvtxX -> GetMean();
246 xHistoRMS = histTRKvtxX ->GetRMS();
248 if ((TMath::Abs(xHistoMean-xMeanVtx) > 0.5)){
249 AliWarning(Form("Possible problems with the fit mean very different from histo mean... using SPD vertex"));
251 useITSSAvtx = kFALSE;
255 yHistoMean = histTRKvtxY -> GetMean();
256 yHistoRMS = histTRKvtxY ->GetRMS();
258 if ((TMath::Abs(yHistoMean-yMeanVtx) > 0.5)){
259 AliWarning(Form("Possible problems with the fit mean very different from histo mean... using SPD vertex"));
261 useITSSAvtx = kFALSE;
265 zHistoMean = histTRKvtxZ -> GetMean();
266 zHistoRMS = histTRKvtxZ ->GetRMS();
268 if ((TMath::Abs(zHistoMean-zMeanVtx) > 1.)){
269 AliWarning(Form("Possible problems with the fit mean very different from histo mean... using SPD vertex"));
271 useITSSAvtx = kFALSE;
277 if ((useSPDvtx) && (spdAvailable) && (!vertexerSPD3Doff)){
279 histSPDvtxX ->Fit("gaus", "M");
280 fitVtxX = histSPDvtxX -> GetFunction("gaus");
281 xMeanVtx = fitVtxX -> GetParameter(1);
282 if (TMath::Abs(xMeanVtx) > 2.) {
284 writeMeanVertexSPD=kTRUE;
287 histSPDvtxY ->Fit("gaus", "M");
288 fitVtxY = histSPDvtxY -> GetFunction("gaus");
289 yMeanVtx = fitVtxY -> GetParameter(1);
290 if (TMath::Abs(yMeanVtx) > 2.) {
292 writeMeanVertexSPD=kTRUE;
295 histSPDvtxZ ->Fit("gaus", "M");
296 fitVtxZ = histSPDvtxZ -> GetFunction("gaus");
297 zMeanVtx = fitVtxZ -> GetParameter(1);
298 zSigmaVtx = fitVtxZ -> GetParameter(2);
299 if ((TMath::Abs(zMeanVtx) > 20.) || (zSigmaVtx>12.)) {
302 writeMeanVertexSPD = kTRUE;
306 else if ((useSPDvtx) && (!spdAvailable)){
307 AliError(Form("Difference between trkVtx and online one, SPD histos not enough entry or SPD 3D vertex off. Writing Mean Vertex SPD"));
308 writeMeanVertexSPD = kTRUE;
312 //check with online position
314 Double_t posOnline[3], sigmaOnline[3];
316 if (useTRKvtx || useITSSAvtx){
317 AliCDBManager *manCheck = AliCDBManager::Instance();
318 manCheck->SetDefaultStorage("raw://");
319 manCheck->SetRun(runNb);
321 AliCDBEntry *entr = manCheck->Get("GRP/Calib/MeanVertexSPD");
323 AliESDVertex *vtxOnline = (AliESDVertex*)entr->GetObject();
325 posOnline[0] = vtxOnline->GetX();
326 posOnline[1] = vtxOnline->GetY();
327 posOnline[2] = vtxOnline->GetZ();
329 sigmaOnline[0] = vtxOnline->GetXRes();
330 sigmaOnline[1] = vtxOnline->GetYRes();
331 sigmaOnline[2] = vtxOnline->GetZRes();
333 //vtxOnline->GetSigmaXYZ(sigmaOnline);
335 if ((TMath::Abs(posOnline[0]-xMeanVtx) > 0.1) || (TMath::Abs(posOnline[1]-yMeanVtx) > 0.1) || (TMath::Abs(posOnline[2]-zMeanVtx) > 1.)){
336 AliWarning(Form("vertex offline far from the online one"));
343 if (writeMeanVertexSPD){
345 AliWarning(Form("Writing Mean Vertex SPD, Mean Vertex not available"));
347 Double_t sigma[3]={0.0150, 0.0150, 6.};
349 AliESDVertex *vertex = new AliESDVertex(posOnline, sigma, "vertex");
351 AliCDBManager *cdb = AliCDBManager::Instance();
352 AliCDBStorage *sto = cdb->GetStorage(dbString);
356 AliError(Form("cannot get storage %s", dbString));
360 AliCDBId id("GRP/Calib/MeanVertex", runNb, runNb);
362 AliCDBMetaData metaData;
363 metaData.SetBeamPeriod(0); //check!!!!
364 metaData.SetResponsible("Davide Caffarri");
365 metaData.SetComment("Mean Vertex object used in reconstruction");
367 if (!sto->Put(vertex, id, &metaData)) {
368 AliError(Form("Error while putting object in storage %s", dbString));
376 Float_t meanMult = 40.;
378 Float_t resolVtx = 0.05;
380 Double_t xSigmaMult, ySigmaMult, corrXZ, corrYZ, lumiRegSquaredX, lumiRegSquaredY;
381 Double_t covarXZ=0., covarYZ=0.;
383 Bool_t highMultEnvironment = kTRUE;
385 TF1 *sigmaFitX, *sigmaFitY, *corrFit;
387 TH1F *histTRKdefMultX=0;
388 TH1F *histTRKdefMultY=0;
389 TH1F *histTRKHighMultX=0;
390 TH1F *histTRKHighMultY=0;
391 TH2F *histTRKVertexXZ=0;
392 TH2F *histTRKVertexYZ=0;
397 histTRKdefMultX = (TH1F*)list->FindObject("hTRKVertexXdefMult");
398 histTRKdefMultY = (TH1F*)list->FindObject("hTRKVertexYdefMult");
399 histTRKHighMultX = (TH1F*)list->FindObject("hTRKVertexXHighMult");
400 histTRKHighMultY = (TH1F*)list->FindObject("hTRKVertexYHighMult");
401 histTRKVertexXZ = (TH2F*)list->FindObject("hTRKVertexXZ");
402 histTRKVertexYZ = (TH2F*)list->FindObject("hTRKVertexYZ");
406 histTRKdefMultX = (TH1F*)file->Get("hTRKVertexXdefMult");
407 histTRKdefMultY = (TH1F*)file->Get("hTRKVertexYdefMult");
408 histTRKHighMultX = (TH1F*)file->Get("hTRKVertexXHighMult");
409 histTRKHighMultY = (TH1F*)file->Get("hTRKVertexYHighMult");
410 histTRKVertexXZ = (TH2F*)file->Get("hTRKVertexXZ");
411 histTRKVertexYZ = (TH2F*)file->Get("hTRKVertexYZ");
418 histTRKdefMultX = (TH1F*)list->FindObject("hITSSAVertexXdefMult");
419 histTRKdefMultY = (TH1F*)list->FindObject("hITSSAVertexYdefMult");
420 histTRKHighMultX = (TH1F*)list->FindObject("hITSSAVertexXHighMult");
421 histTRKHighMultY = (TH1F*)list->FindObject("hITSSAVertexYHighMult");
422 histTRKVertexXZ = (TH2F*)list->FindObject("hITSSAVertexXZ");
423 histTRKVertexYZ = (TH2F*)list->FindObject("hITSSAVertexYZ");
427 histTRKdefMultX = (TH1F*)file->Get("hITSSAVertexXdefMult");
428 histTRKdefMultY = (TH1F*)file->Get("hITSSAVertexYdefMult");
429 histTRKHighMultX = (TH1F*)file->Get("hITSSAVertexXHighMult");
430 histTRKHighMultY = (TH1F*)file->Get("hITSSAVertexYHighMult");
431 histTRKVertexXZ = (TH2F*)file->Get("hITSSAVertexXZ");
432 histTRKVertexYZ = (TH2F*)file->Get("hITSSAVertexYZ");
437 if ((histTRKHighMultX) && (histTRKHighMultY)){
439 Float_t nEntriesHighMultX = histTRKHighMultX->GetEffectiveEntries();
440 Float_t nEntriesHighMultY = histTRKHighMultY->GetEffectiveEntries();
442 if ((nEntriesHighMultX >100) && (nEntriesHighMultY>100)) {
443 AliWarning(Form("Setting High Mulitplicity environment"));
444 highMultEnvironment = kTRUE;
447 AliWarning(Form("Setting Low Mulitplicity environment"));
448 highMultEnvironment=kFALSE;
453 AliWarning(Form("No histos found, setting Low Mulitplicity environment"));
454 highMultEnvironment=kFALSE;
458 if (highMultEnvironment==kFALSE){
460 if ((!histTRKdefMultX) || (!histTRKdefMultY) || (histTRKdefMultX->GetEntries() < 40.) || (histTRKdefMultY->GetEntries() < 40.)){
461 AliWarning(Form("histos for lumi reg calculation not found, default value setted"));
466 histTRKdefMultX -> Fit("gaus", "M", "", -0.4, 0.4);
467 sigmaFitX = histTRKdefMultX -> GetFunction("gaus");
468 xSigmaMult = sigmaFitX->GetParameter(2);
470 lumiRegSquaredX = (xSigmaMult*xSigmaMult - ((resolVtx*resolVtx)/TMath::Power(meanMult, p2)));
471 if (lumiRegSquaredX < 0) {
472 AliWarning(Form("Problems with luminosiy region determination, update of the postion only"));
477 if (lumiRegSquaredX > 0 && lumiRegSquaredX < 0.0005){
478 xSigmaVtx = TMath::Sqrt(lumiRegSquaredX);
479 xSigmaVtx = xSigmaVtx*1.2;
482 histTRKdefMultY -> Fit("gaus", "M", "", -0.2, 0.6);
483 sigmaFitY = histTRKdefMultY -> GetFunction("gaus");
484 ySigmaMult = sigmaFitY->GetParameter(2);
486 lumiRegSquaredY= (ySigmaMult*ySigmaMult - ((resolVtx*resolVtx)/TMath::Power(meanMult, p2)));
487 if (lumiRegSquaredY < 0) {
488 AliWarning(Form("Problems with luminosiy region determination, update of the postion only"));
493 if (lumiRegSquaredY > 0 && lumiRegSquaredY < 0.0005){
494 ySigmaVtx = TMath::Sqrt(lumiRegSquaredY);
495 ySigmaVtx = ySigmaVtx*1.2;
498 TProfile *htrkXZ = histTRKVertexXZ ->ProfileY();
499 htrkXZ -> Fit("pol1", "M", "", -10., 10.);
500 corrFit = htrkXZ->GetFunction("pol1");
501 corrXZ = corrFit->GetParameter(1);
503 if (TMath::Abs(corrXZ) > 0.01) {
504 AliWarning(Form("Problems in the correlation fitting, not update the covariance matrix"));
508 covarXZ = corrXZ * zSigmaVtx*zSigmaVtx;
512 TProfile *htrkYZ = histTRKVertexYZ ->ProfileY();
513 htrkYZ -> Fit("pol1", "M", "", -10., 10.);
514 corrFit = htrkYZ->GetFunction("pol1");
515 corrYZ = corrFit->GetParameter(1);
517 if (TMath::Abs(corrYZ) > 0.01) {
518 AliWarning(Form("Problems in the correlation fitting, not update the covariance matrix"));
522 covarYZ = corrYZ*zSigmaVtx*zSigmaVtx;
528 if (highMultEnvironment==kTRUE){
530 histTRKHighMultX -> Fit("gaus", "M", "", -0.4, 0.4);
531 sigmaFitX = histTRKHighMultX -> GetFunction("gaus");
532 xSigmaMult = sigmaFitX->GetParameter(2);
534 if ((xSigmaMult <0) || (xSigmaMult>0.03)){
535 AliWarning(Form("Problems with luminosiy region determination, update of the postion only"));
540 xSigmaVtx = xSigmaMult;
541 xSigmaVtx = xSigmaVtx*1.2;
544 histTRKHighMultY -> Fit("gaus", "M", "", -0.2, 0.5);
545 sigmaFitY = histTRKHighMultY -> GetFunction("gaus");
546 ySigmaMult = sigmaFitY->GetParameter(2);
548 if ((ySigmaMult <0) || (ySigmaMult>0.03)){
549 AliWarning(Form("Problems with luminosiy region determination, update of the postion only"));
554 ySigmaVtx = ySigmaMult;
555 ySigmaVtx = ySigmaVtx*1.2;
558 TProfile *htrkXZ = histTRKVertexXZ ->ProfileY();
559 htrkXZ -> Fit("pol1", "M", "", -10., 10.);
560 corrFit = htrkXZ->GetFunction("pol1");
561 corrXZ = corrFit->GetParameter(1);
563 if (TMath::Abs(corrXZ) > 0.01) {
564 AliWarning(Form("Problems in the correlation fitting, not update the covariance matrix"));
568 covarXZ = corrXZ * zSigmaVtx*zSigmaVtx;
572 TProfile *htrkYZ = histTRKVertexYZ ->ProfileY();
573 htrkYZ -> Fit("pol1", "M", "", -10., 10.);
574 corrFit = htrkYZ->GetFunction("pol1");
575 corrYZ = corrFit->GetParameter(1);
577 if (TMath::Abs(corrYZ) > 0.01) {
578 AliWarning(Form("Problems in the correlation fitting, not update the covariance matrix"));
582 covarYZ = corrYZ*zSigmaVtx*zSigmaVtx;
587 Double_t position[3], covMatrix[6];
591 position[0] = xMeanVtx;
592 position[1] = yMeanVtx;
593 position[2] = zMeanVtx;
595 covMatrix[0] = xSigmaVtx*xSigmaVtx;
596 covMatrix[1] = 0.; //xy
597 covMatrix[2] = ySigmaVtx*ySigmaVtx;
598 covMatrix[3] = covarXZ;
599 covMatrix[4] = covarYZ;
600 covMatrix[5] = zSigmaVtx*zSigmaVtx;
603 //Printf ("%f, %f, %f, %f", xSigmaVtx, ySigmaVtx, covarXZ, covarYZ);
605 AliESDVertex *vertex = new AliESDVertex(position, covMatrix, chi2, nContr, "vertex");
607 AliCDBManager *cdb = AliCDBManager::Instance();
608 AliCDBStorage *sto = cdb->GetStorage(dbString);
612 AliError(Form("cannot get storage %s", dbString));
616 AliCDBId id("GRP/Calib/MeanVertex", runNb, runNb);
618 AliCDBMetaData metaData;
619 metaData.SetBeamPeriod(0); //check!!!!
620 metaData.SetResponsible("Davide Caffarri");
621 metaData.SetComment("Mean Vertex object used in reconstruction");
623 if (!sto->Put(vertex, id, &metaData)) {
624 AliError(Form("Error while putting object in storage %s", dbString));