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, AliCDBStorage *db, 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 storage 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.)) {
232 zMeanVtx = histTRKvtxZ->GetMean();
233 zSigmaVtx = histTRKvtxZ->GetRMS();
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.)) {
300 zMeanVtx = histSPDvtxZ ->GetMean();
301 zSigmaVtx = histSPDvtxZ->GetRMS();
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 || writeMeanVertexSPD){
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, zSigmaVtx};
349 AliESDVertex *vertex = new AliESDVertex(posOnline, sigma, "vertex");
351 AliCDBId id("GRP/Calib/MeanVertex", runNb, runNb);
353 AliCDBMetaData metaData;
354 metaData.SetBeamPeriod(0); //check!!!!
355 metaData.SetResponsible("Davide Caffarri");
356 metaData.SetComment("Mean Vertex object used in reconstruction");
358 if (!db->Put(vertex, id, &metaData)) {
359 AliError(Form("Error while putting object in storage %s", db->GetURI().Data()));
367 Float_t meanMult = 40.;
369 Float_t resolVtx = 0.05;
371 Double_t xSigmaMult, ySigmaMult, corrXZ, corrYZ, lumiRegSquaredX, lumiRegSquaredY;
372 Double_t covarXZ=0., covarYZ=0.;
374 Bool_t highMultEnvironment = kTRUE;
376 TF1 *sigmaFitX, *sigmaFitY, *corrFit;
378 TH1F *histTRKdefMultX=0;
379 TH1F *histTRKdefMultY=0;
380 TH1F *histTRKHighMultX=0;
381 TH1F *histTRKHighMultY=0;
382 TH2F *histTRKVertexXZ=0;
383 TH2F *histTRKVertexYZ=0;
388 histTRKdefMultX = (TH1F*)list->FindObject("hTRKVertexXdefMult");
389 histTRKdefMultY = (TH1F*)list->FindObject("hTRKVertexYdefMult");
390 histTRKHighMultX = (TH1F*)list->FindObject("hTRKVertexXHighMult");
391 histTRKHighMultY = (TH1F*)list->FindObject("hTRKVertexYHighMult");
392 histTRKVertexXZ = (TH2F*)list->FindObject("hTRKVertexXZ");
393 histTRKVertexYZ = (TH2F*)list->FindObject("hTRKVertexYZ");
397 histTRKdefMultX = (TH1F*)file->Get("hTRKVertexXdefMult");
398 histTRKdefMultY = (TH1F*)file->Get("hTRKVertexYdefMult");
399 histTRKHighMultX = (TH1F*)file->Get("hTRKVertexXHighMult");
400 histTRKHighMultY = (TH1F*)file->Get("hTRKVertexYHighMult");
401 histTRKVertexXZ = (TH2F*)file->Get("hTRKVertexXZ");
402 histTRKVertexYZ = (TH2F*)file->Get("hTRKVertexYZ");
409 histTRKdefMultX = (TH1F*)list->FindObject("hITSSAVertexXdefMult");
410 histTRKdefMultY = (TH1F*)list->FindObject("hITSSAVertexYdefMult");
411 histTRKHighMultX = (TH1F*)list->FindObject("hITSSAVertexXHighMult");
412 histTRKHighMultY = (TH1F*)list->FindObject("hITSSAVertexYHighMult");
413 histTRKVertexXZ = (TH2F*)list->FindObject("hITSSAVertexXZ");
414 histTRKVertexYZ = (TH2F*)list->FindObject("hITSSAVertexYZ");
418 histTRKdefMultX = (TH1F*)file->Get("hITSSAVertexXdefMult");
419 histTRKdefMultY = (TH1F*)file->Get("hITSSAVertexYdefMult");
420 histTRKHighMultX = (TH1F*)file->Get("hITSSAVertexXHighMult");
421 histTRKHighMultY = (TH1F*)file->Get("hITSSAVertexYHighMult");
422 histTRKVertexXZ = (TH2F*)file->Get("hITSSAVertexXZ");
423 histTRKVertexYZ = (TH2F*)file->Get("hITSSAVertexYZ");
428 if ((histTRKHighMultX) && (histTRKHighMultY)){
430 Float_t nEntriesHighMultX = histTRKHighMultX->GetEffectiveEntries();
431 Float_t nEntriesHighMultY = histTRKHighMultY->GetEffectiveEntries();
433 if ((nEntriesHighMultX >100) && (nEntriesHighMultY>100)) {
434 AliWarning(Form("Setting High Mulitplicity environment"));
435 highMultEnvironment = kTRUE;
438 AliWarning(Form("Setting Low Mulitplicity environment"));
439 highMultEnvironment=kFALSE;
444 AliWarning(Form("No histos found, setting Low Mulitplicity environment"));
445 highMultEnvironment=kFALSE;
449 if (highMultEnvironment==kFALSE){
451 if ((!histTRKdefMultX) || (!histTRKdefMultY) || (histTRKdefMultX->GetEntries() < 40.) || (histTRKdefMultY->GetEntries() < 40.)){
452 AliWarning(Form("histos for lumi reg calculation not found, default value setted"));
457 histTRKdefMultX -> Fit("gaus", "M", "", -0.4, 0.4);
458 sigmaFitX = histTRKdefMultX -> GetFunction("gaus");
459 xSigmaMult = sigmaFitX->GetParameter(2);
461 lumiRegSquaredX = (xSigmaMult*xSigmaMult - ((resolVtx*resolVtx)/TMath::Power(meanMult, p2)));
462 if (lumiRegSquaredX < 0) {
463 AliWarning(Form("Problems with luminosiy region determination, update of the postion only"));
468 if (lumiRegSquaredX > 0 && lumiRegSquaredX < 0.0005){
469 xSigmaVtx = TMath::Sqrt(lumiRegSquaredX);
470 xSigmaVtx = xSigmaVtx*1.2;
473 histTRKdefMultY -> Fit("gaus", "M", "", -0.2, 0.6);
474 sigmaFitY = histTRKdefMultY -> GetFunction("gaus");
475 ySigmaMult = sigmaFitY->GetParameter(2);
477 lumiRegSquaredY= (ySigmaMult*ySigmaMult - ((resolVtx*resolVtx)/TMath::Power(meanMult, p2)));
478 if (lumiRegSquaredY < 0) {
479 AliWarning(Form("Problems with luminosiy region determination, update of the postion only"));
484 if (lumiRegSquaredY > 0 && lumiRegSquaredY < 0.0005){
485 ySigmaVtx = TMath::Sqrt(lumiRegSquaredY);
486 ySigmaVtx = ySigmaVtx*1.2;
489 TProfile *htrkXZ = histTRKVertexXZ ->ProfileY();
490 htrkXZ -> Fit("pol1", "M", "", -10., 10.);
491 corrFit = htrkXZ->GetFunction("pol1");
492 corrXZ = corrFit->GetParameter(1);
494 if (TMath::Abs(corrXZ) > 0.01) {
495 AliWarning(Form("Problems in the correlation fitting, not update the covariance matrix"));
499 covarXZ = corrXZ * zSigmaVtx*zSigmaVtx;
503 TProfile *htrkYZ = histTRKVertexYZ ->ProfileY();
504 htrkYZ -> Fit("pol1", "M", "", -10., 10.);
505 corrFit = htrkYZ->GetFunction("pol1");
506 corrYZ = corrFit->GetParameter(1);
508 if (TMath::Abs(corrYZ) > 0.01) {
509 AliWarning(Form("Problems in the correlation fitting, not update the covariance matrix"));
513 covarYZ = corrYZ*zSigmaVtx*zSigmaVtx;
519 if (highMultEnvironment==kTRUE){
521 histTRKHighMultX -> Fit("gaus", "M", "", -0.4, 0.4);
522 sigmaFitX = histTRKHighMultX -> GetFunction("gaus");
523 xSigmaMult = sigmaFitX->GetParameter(2);
525 if ((xSigmaMult <0) || (xSigmaMult>0.03)){
526 AliWarning(Form("Problems with luminosiy region determination, update of the postion only"));
531 xSigmaVtx = xSigmaMult;
532 xSigmaVtx = xSigmaVtx*1.2;
535 histTRKHighMultY -> Fit("gaus", "M", "", -0.2, 0.5);
536 sigmaFitY = histTRKHighMultY -> GetFunction("gaus");
537 ySigmaMult = sigmaFitY->GetParameter(2);
539 if ((ySigmaMult <0) || (ySigmaMult>0.03)){
540 AliWarning(Form("Problems with luminosiy region determination, update of the postion only"));
545 ySigmaVtx = ySigmaMult;
546 ySigmaVtx = ySigmaVtx*1.2;
549 TProfile *htrkXZ = histTRKVertexXZ ->ProfileY();
550 htrkXZ -> Fit("pol1", "M", "", -10., 10.);
551 corrFit = htrkXZ->GetFunction("pol1");
552 corrXZ = corrFit->GetParameter(1);
554 if (TMath::Abs(corrXZ) > 0.01) {
555 AliWarning(Form("Problems in the correlation fitting, not update the covariance matrix"));
559 covarXZ = corrXZ * zSigmaVtx*zSigmaVtx;
563 TProfile *htrkYZ = histTRKVertexYZ ->ProfileY();
564 htrkYZ -> Fit("pol1", "M", "", -10., 10.);
565 corrFit = htrkYZ->GetFunction("pol1");
566 corrYZ = corrFit->GetParameter(1);
568 if (TMath::Abs(corrYZ) > 0.01) {
569 AliWarning(Form("Problems in the correlation fitting, not update the covariance matrix"));
573 covarYZ = corrYZ*zSigmaVtx*zSigmaVtx;
578 Double_t position[3], covMatrix[6];
582 position[0] = xMeanVtx;
583 position[1] = yMeanVtx;
584 position[2] = zMeanVtx;
586 covMatrix[0] = xSigmaVtx*xSigmaVtx;
587 covMatrix[1] = 0.; //xy
588 covMatrix[2] = ySigmaVtx*ySigmaVtx;
589 covMatrix[3] = covarXZ;
590 covMatrix[4] = covarYZ;
591 covMatrix[5] = zSigmaVtx*zSigmaVtx;
594 //Printf ("%f, %f, %f, %f", xSigmaVtx, ySigmaVtx, covarXZ, covarYZ);
596 AliESDVertex *vertex = new AliESDVertex(position, covMatrix, chi2, nContr, "vertex");
598 AliCDBId id("GRP/Calib/MeanVertex", runNb, runNb);
600 AliCDBMetaData metaData;
601 metaData.SetBeamPeriod(0); //check!!!!
602 metaData.SetResponsible("Davide Caffarri");
603 metaData.SetComment("Mean Vertex object used in reconstruction");
605 if (!db->Put(vertex, id, &metaData)) {
606 AliError(Form("Error while putting object in storage %s", db->GetURI().Data()));