]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - T0/AliT0CalibTimeEq.cxx
Coding rule violations.
[u/mrichter/AliRoot.git] / T0 / AliT0CalibTimeEq.cxx
index 3b1724ede73affb58fc86fd7fe284d0e7dcc3655..d746a46314e3a39b6f48220e3a64fe341088f4af 100644 (file)
@@ -109,37 +109,69 @@ void  AliT0CalibTimeEq::Print(Option_t*) const
 Bool_t AliT0CalibTimeEq::ComputeOnlineParams(const char* filePhys)
 {
   // compute online equalized time
-  Double_t mean=0, meanver=0;
-  Double_t rms=0, rmsver=0;
-  Int_t nent=0;
+  Float_t meandiff, sigmadiff, meanver, meancfdtime, sigmacfdtime;
+  meandiff = sigmadiff =  meanver = meancfdtime = sigmacfdtime =0;
+    // Double_t rms=0, rmscfd=0; 
+  Double_t rmsver=0;
+ Int_t nent=0;
   Bool_t ok=false;
   gFile = TFile::Open(filePhys);
-    if(!gFile) {
+  if(!gFile) {
     AliError("No input PHYS data found ");
   }
   else
     {
+      //    gFile->ls();
       ok=true;
-      Char_t buf1[30];
       for (Int_t i=0; i<24; i++)
        {
-         sprintf(buf1,"CFD1-CFD%d",i+1);
-         TH1F *cfd = (TH1F*) gFile->Get(buf1);
+         TH1F *cfd = (TH1F*) gFile->Get(Form("CFD1minCFD%d",i+1));
+         TH1F *cfdtime = (TH1F*) gFile->Get(Form("CFD%d",i+1));
          if(!cfd) AliWarning(Form("no histograms collected by PHYS DA for channel %i", i));
          //      printf(" i = %d buf1 = %s\n", i, buf1);
          if(cfd) {
-           mean=cfd->GetMean();
-           rms=cfd->GetRMS();
-           nent=cfd->GetEntries();
-           //      printf ("%f %f %i \n",mean,rms,nent);
-           if(nent<200 || rms>10 ) ok=false;
+           GetMeanAndSigma(cfd, meandiff, sigmadiff);
+           nent=cfd->GetEntries();
+           if(nent<500 || cfd->GetRMS()>20. ) {
+             ok=false;
+             AliWarning(Form("Data is not good enouph in PMT %i - mean %f rsm %f nentries %i", i,meandiff,sigmadiff , nent));
+             
+           }
+           else 
+             {
+               ok=false;
+               AliWarning(Form("Data is not good enouph in PMT %i , no clean peak", i));
+             }
+           if(!cfd) AliWarning(Form("no histograms collected by PHYS DA for channel %i", i));
+         }
+           //      printf(" i = %d buf1 = %s\n", i, buf1);
+         if(cfdtime) {
+           GetMeanAndSigma(cfdtime,meancfdtime, sigmacfdtime);
+           nent=cfdtime->GetEntries();
+           if(nent<500 || sigmacfdtime>30. ) {
+             ok=false;
+             AliWarning(Form("Data is not good enouph in PMT %i CFD data - meancfdtime %f rsm %f nentries %i", i,meancfdtime, sigmacfdtime, nent));
+               
+           }
          }
-          SetTimeEq(i,mean);
-          SetTimeEqRms(i,rms);
+         else 
+           {
+               ok=false;
+               AliWarning(Form("Data is not good enouph in PMT %i , no clean peak", i));
+             }
+         
+         
+       
+         SetTimeEq(i,meandiff);
+         SetTimeEqRms(i,sigmadiff);
+         SetCFDvalue(i,0,meancfdtime);
+         SetCFDvalue(i,0,sigmacfdtime);
          if (cfd) delete cfd;
+         if (cfdtime) delete cfdtime;
+
        }
       TH1F *ver = (TH1F*) gFile->Get("hVertex");
-      if(!ver) AliWarning("no Vertex histograms collected by PHYS DA for Zvertex");
+      if(!ver) AliWarning("no T0 histogram collected by PHYS DA ");
       if(ver) {
        meanver = ver->GetMean();
        rmsver = ver->GetRMS();
@@ -154,4 +186,107 @@ Bool_t AliT0CalibTimeEq::ComputeOnlineParams(const char* filePhys)
     return ok; 
 }
 
+//________________________________________________________________
+Bool_t AliT0CalibTimeEq::ComputeOfflineParams(const char* filePhys)
+{
+  // compute online equalized time
+  Float_t meandiff, sigmadiff, meanver, meancfdtime, sigmacfdtime;
+  meandiff = sigmadiff =  meanver = meancfdtime = sigmacfdtime =0;
+  // Double_t rms=0, rmscfd=0; 
+  Double_t rmsver=0;
+  Int_t nent=0;
+  Bool_t ok=false;
+  gFile = TFile::Open(filePhys);
+  if(!gFile) {
+    AliError("No input PHYS data found ");
+  }
+  else
+    {
+      //    gFile->ls();
+      ok=true;
+      TObjArray * TzeroObj = (TObjArray*) gFile->Get("fTzeroObject");
+      for (Int_t i=0; i<24; i++)
+       {
+         TH1F *cfddiff = (TH1F*)TzeroObj->At(i);
+         TH1F *cfdtime = (TH1F*)TzeroObj->At(i+24);
+         if(!cfddiff) AliWarning(Form("no histograms collected by PHYS DA for channel %i", i));
+         //      printf(" i = %d buf1 = %s\n", i, buf1);
+         if(cfddiff) {
+           GetMeanAndSigma(cfddiff,meandiff, sigmadiff);
+           nent=cfddiff->GetEntries();
+           if(nent<500 || cfddiff->GetRMS()>20. ) {
+             ok=false;
+             AliWarning(Form("Data is not good enouph in PMT %i - mean %f rsm %f nentries %i", i,meandiff,sigmadiff, nent));
+                     
+           }
+           else 
+             {
+               ok=false;
+               AliWarning(Form("Data is not good enouph in PMT %i , no clean peak", i));
+             }
+         if(!cfdtime) AliWarning(Form("no histograms collected by PHYS DA for channel %i", i));
+         //      printf(" i = %d buf1 = %s\n", i, buf1);
+         if(cfdtime) {
+           GetMeanAndSigma(cfdtime,meancfdtime, sigmacfdtime);
+           nent=cfdtime->GetEntries();
+           if(nent<500 || cfdtime->GetRMS()>30. ) {
+             ok=false;
+             AliWarning(Form("Data is not good enouph in PMT %i CFD data - mean %f rsm %f nentries %i", i,meancfdtime, sigmacfdtime, nent));
+               
+           }
+         }
+         else 
+           {
+               ok=false;
+               AliWarning(Form("Data is not good enouph in PMT %i , no clean peak", i));
+             }
+         }
+         
+       
+         SetTimeEq(i,meandiff);
+         SetTimeEqRms(i,sigmadiff);
+         SetCFDvalue(i,0,meancfdtime);
+         SetCFDvalue(i,0,sigmacfdtime);
+         if (cfddiff) delete cfddiff;
+         if (cfdtime) delete cfdtime;
+
+       }
+      TH1F *ver = (TH1F*) gFile->Get("hVertex");
+      if(!ver) AliWarning("no T0 histogram collected by PHYS DA ");
+      if(ver) {
+       meanver = ver->GetMean();
+       rmsver = ver->GetRMS();
+      }
+      SetMeanVertex(meanver);
+      SetRmsVertex(rmsver);
+      
+      gFile->Close();
+      delete gFile;
+
+    }
+    return ok; 
+}
+
+//________________________________________________________________________
+void AliT0CalibTimeEq::GetMeanAndSigma(TH1F* hist,  Float_t &mean, Float_t &sigma) {
+
+  const double window = 5.;  //fit window 
+  double norm  = hist->Integral();  // normalize to one count
+  hist->Scale(1./norm); 
+  double meanEstimate, sigmaEstimate; 
+  int maxBin;
+  maxBin        =  hist->GetMaximumBin(); //position of maximum
+  meanEstimate  =  hist->GetBinCenter( maxBin); // mean of gaussian sitting in maximum
+  sigmaEstimate = hist->GetRMS();
+  TF1* fit= new TF1("fit","gaus", meanEstimate - window*sigmaEstimate, meanEstimate + window*sigmaEstimate);
+  fit->SetParameters(hist->GetBinContent(maxBin), meanEstimate, sigmaEstimate);
+  hist->Fit("fit","R");
+
+  mean  = (Float_t) fit->GetParameter(1);
+  sigma = (Float_t) fit->GetParameter(2);
+
+  delete fit;
+}
+