+ }
+ return ok;
+}
+
+//________________________________________________________________
+Int_t AliT0CalibTimeEq::ComputeOfflineParams(const char* filePhys, Float_t *timecdb, Float_t *cfdvalue, Int_t badpmt)
+{
+ // fStatus implementation:
+ //ok means
+ // 1000 - can not open file
+ // for timediff
+ // 1-24 no histograms with time diff for more than okdiff channenls
+ // 100 >3 histos are empty
+ // - 1 if less 3 channels are empty ;for these channels OCDB value will be written back WARNING
+ // -2 low statistics in few channels; for these channels OCDB value will be written back WARNING
+ // for cfd
+ // 200 >3 histos are empty
+ // -11 if less 3 channels are empty ;for these channels OCDB value will be written back WARNING
+ // -22 low statistics in few channels; for these channels OCDB value will be written back WARNING
+ //
+ // compute offline equalized time
+ Float_t meandiff, sigmadiff, meanver, meancfdtime, sigmacfdtime;
+ meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
+ Int_t nent=0;
+ Int_t ok = 0;
+ Int_t okdiff=0;
+ Int_t okcfd=0;
+ TH1F *cfddiff = NULL;
+ TH1F *cfdtime = NULL;
+ TObjArray * tzeroObj = NULL;
+
+ gFile = TFile::Open(filePhys);
+ if(!gFile) {
+ AliError("No input PHYS data found ");
+ ok = 1000;
+ return ok;
+ }
+ else
+ {
+ meandiff = sigmadiff = meanver = meancfdtime = sigmacfdtime =0;
+ // TDirectory *dr = (TDirectory*) gFile->Get("T0Calib");
+ tzeroObj = dynamic_cast<TObjArray*>(gFile->Get("T0Calib"));
+ for (Int_t i=0; i<24; i++)
+ {
+ if (i != badpmt) {
+ if(tzeroObj) {
+ cfddiff = (TH1F*) tzeroObj->FindObject(Form("CFD1minCFD%d",i+1));
+ cfdtime = (TH1F*)tzeroObj->FindObject(Form("CFD%d",i+1));
+ }
+ else
+ {
+ cfddiff = (TH1F*)gFile->Get(Form("CFD1minCFD%d",i+1));
+ cfdtime = (TH1F*)gFile->Get(Form("CFD%d",i+1));
+
+ }
+ if(!cfddiff ) {
+ AliWarning(Form("no histograms collected by pass0 for diff channel %i", i));
+ okdiff++;
+ if(okdiff<4) {
+ meandiff = timecdb[i];
+ sigmadiff = 0;
+ ok = -1;
+ }
+ else
+ return 100+okdiff;
+ }
+ if(cfddiff) {
+ nent = Int_t(cfddiff->GetEntries());
+ if ( nent == 0) {
+ okdiff++;
+ if(okdiff<4) {
+ meandiff = timecdb[i];
+ sigmadiff = 0;
+ ok = - 1;
+ }
+ else
+ return 100;
+ }
+ if(nent<100 && nent>0) { //!!!!!
+ AliWarning(Form(" Not enouph data in PMT %i- PMT1: %i ", i, nent));
+ ok=-2;
+ meandiff = timecdb[i];
+ sigmadiff = 0;
+ }
+ if(nent>100 ) { //!!!!!
+ {
+ if(cfddiff->GetRMS()>1.5 )
+ GetMeanAndSigma(cfddiff, meandiff, sigmadiff);
+ if(cfddiff->GetRMS()<=1.5)
+ {
+ meandiff = cfddiff->GetMean();
+ sigmadiff = cfddiff->GetRMS();
+ }
+ Int_t maxBin = cfddiff->GetMaximumBin();
+ Double_t meanEstimate = cfddiff->GetBinCenter( maxBin);
+ if(TMath::Abs(meanEstimate - meandiff) > 20 ) meandiff = meanEstimate;
+ }
+ }
+ }
+ if(!cfdtime ) {
+ AliWarning(Form("no histograms collected by pass0 for time channel %i", i));
+ meancfdtime = cfdvalue[i];
+ okcfd++;
+ if(okcfd<4) {
+ meancfdtime = cfdvalue[i];
+ ok = -11;
+ }
+ else {
+ AliError(Form("no histograms collected by pass0 for time %i channels ", okcfd));
+ return 200;
+ }
+ }
+ if(cfdtime) {
+ nent = Int_t(cfdtime->GetEntries());
+ if (nent == 0 ||
+ (cfdtime->GetRMS() == 0 || cfdtime->GetMean() ==0 ) )
+ {
+ okcfd++;
+ if(okcfd<4) {
+ meancfdtime = cfdvalue[i];
+ ok = -11;
+ printf("!!!!bad data:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
+ i, nent, cfdtime->GetRMS(), cfdtime->GetMean(), fCFDvalue[i][0]);
+ }
+ else
+ {
+ printf("!!!!fatal data:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
+ i, nent, cfdtime->GetRMS(), cfdtime->GetMean(), fCFDvalue[i][0]);
+ AliError(Form(" histograms collected by pass0 for time %i channels are empty", okcfd));
+ return 200;
+ }
+ }
+
+
+ if(nent<100 && nent>0 )
+ {
+ AliWarning(Form(" Not enouph data in PMT in CFD peak %i - %i ", i, nent));
+ if(okcfd<4) {
+ meancfdtime = cfdvalue[i];
+ ok = -22;
+ printf("!!!!low statstics:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
+ i, nent, cfdtime->GetRMS(), cfdtime->GetMean(), fCFDvalue[i][0]);
+ }
+ else {
+ printf("!!!!low fatal statstics:: pmt %i nent%i RMS %f mean %f cdbtime %f \n",
+ i, nent, cfdtime->GetRMS(), cfdtime->GetMean(), fCFDvalue[i][0]);
+
+ AliError(Form(" Not enouph data in PMT in CFD peak %i in channels ", okcfd));
+ return 200;
+ }