]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFPreprocessor.cxx
Very preliminary version of TOF-T0 online calibration algorithm. TO be used as an...
[u/mrichter/AliRoot.git] / TOF / AliTOFPreprocessor.cxx
index 041a006e68f708aa017c8f55a967b6510b2c564f..8c1279d567c22b3ca95ca2b8eedfc7b26c26ae4e 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-*/  
+/* $Id$ */
 
-#include "AliTOFPreprocessor.h"
+#include <Riostream.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <TFile.h>
+#include <TH1.h>
+#include <TH1F.h>
+#include <TH1S.h>
+#include <TH2S.h>
+#include <TMath.h>
+#include <TObjArray.h>
+#include <TObjString.h>
+#include <TTimeStamp.h>
 
 #include "AliCDBMetaData.h"
 #include "AliLog.h"
-#include "AliTOFDataDCS.h"
-#include "TFile.h"
-#include "TObjArray.h"
-#include "TObjString.h"
 #include "AliTOFCalOnline.h"
 #include "AliTOFChannelOnline.h"
+#include "AliTOFDataDCS.h"
 #include "AliTOFGeometryV5.h"
-#include "TTimeStamp.h"
-#include "TH1F.h"
+#include "AliTOFPreprocessor.h"
 
 class TF1;
 class AliDCSValue;
@@ -46,13 +52,14 @@ class AliTOFGeometry;
 ClassImp(AliTOFPreprocessor)
 
 const Int_t AliTOFPreprocessor::fgkBinRangeAve    = 13; // number of bins where to calculate the mean 
+const Double_t AliTOFPreprocessor::fgkThrPar    = 0.013; // parameter used to trigger the calculation of the delay
 
 //_____________________________________________________________________________
 
-AliTOFPreprocessor::AliTOFPreprocessor(const char* detector, AliShuttleInterface* shuttle) :
-  AliPreprocessor(detector, shuttle),
+AliTOFPreprocessor::AliTOFPreprocessor(AliShuttleInterface* shuttle) :
+  AliPreprocessor("TOF", shuttle),
   fData(0),
-  fArray(0),
+  fh2(0),
   fCal(0),
   fTOFGeometry(0)
 {
@@ -64,6 +71,14 @@ AliTOFPreprocessor::AliTOFPreprocessor(const char* detector, AliShuttleInterface
 AliTOFPreprocessor::~AliTOFPreprocessor()
 {
   // destructor
+  delete fData;
+  fData = 0;
+  delete fh2;
+  fh2 = 0;
+  delete fCal;
+  fCal = 0;
+  delete fTOFGeometry;
+  fTOFGeometry = 0;
 }
 
 //______________________________________________________________________________
@@ -79,7 +94,7 @@ void AliTOFPreprocessor::Initialize(Int_t run, UInt_t startTime,
                TTimeStamp(endTime).AsString()));
 
        fData = new AliTOFDataDCS(fRun, fStartTime, fEndTime);
-       fArray = new TObjArray();
+       fh2 = 0x0;
        fTOFGeometry = new AliTOFGeometryV5();
        fCal = new AliTOFCalOnline(fTOFGeometry);
        fCal->CreateArray();
@@ -91,6 +106,7 @@ UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap)
 {
   // Fills data into a AliTOFDataDCS object
 
+  TH1::AddDirectory(0);
   UInt_t resultDCS=0;
   UInt_t resultDAQ=0;
   UInt_t resultDAQRef=0;
@@ -99,7 +115,7 @@ UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap)
   // processing DCS
 
   if (!dcsAliasMap){
-    AliInfo(Form("No DCS map found "));
+    Log("No DCS map found");
   }
   else {
   // The processing of the DCS input data is forwarded to AliTOFDataDCS
@@ -108,69 +124,94 @@ UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap)
     metaDataDCS.SetBeamPeriod(0);
     metaDataDCS.SetResponsible("Chiara Zampolli");
     metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object.");     resultDCS = Store("Calib","DCSData",fData, &metaDataDCS);
-    result+=resultDCS;
+    //    result+=resultDCS;
     if (!resultDCS){
-      AliInfo(Form("some problems occurred while storing DCS data processing results"));
+      Log("Some problems occurred while storing DCS data processing results");
+      return 0;
     }
   }
 
   // processing DAQ
 
   TFile * daqFile=0x0;
-  TList* list = GetFileSources(kDAQ, "DELAYS");
 
+  //retrieving data at Run level
+  TList* list = GetFileSources(kDAQ, "RUNLevel");
   if (list)
     {
-      AliInfo("The following sources produced files with the id DELAYS");
+      AliInfo("The following sources produced files with the id RUNLevel");
       list->Print();
       for (Int_t jj=0;jj<list->GetEntries();jj++){
        TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
        AliInfo(Form("found source %s", str->String().Data()));
        // file to be stored run per run
-       const char* fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName());
-       if (fileNameRun){
-         AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun));
-         daqFile = new TFile(fileNameRun,"READ");
-         fArray = (TObjArray*) daqFile->Get("ciccio");
+       TString fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName());
+       if (fileNameRun.Length()>0){
+         AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun.Data()));
+         daqFile = new TFile(fileNameRun.Data(),"READ");
+         fh2 = (TH2S*) daqFile->Get("htof");
          AliCDBMetaData metaDataHisto;
          metaDataHisto.SetBeamPeriod(0);
          metaDataHisto.SetResponsible("Chiara Zampolli");
          metaDataHisto.SetComment("This preprocessor stores the array of histos object as Reference Data.");
-         resultDAQRef = StoreReferenceData("Calib","DAQData",fArray, &metaDataHisto);
-         result+=resultDAQRef*2;
+         resultDAQRef = StoreReferenceData("Calib","DAQData",fh2, &metaDataHisto);
+         //      result+=resultDAQRef*2;
          if (!resultDAQRef){
-           AliInfo(Form("some problems occurred::No Reference Data stored"));
+           Log("some problems occurred::No Reference Data stored, still going on (please check!)");
          }
          daqFile->Close();
          delete daqFile;
        }
 
        else{
-         AliError(Form("The file %s does not exist",fileNameRun)); 
-       }
-       
+          Log("The input data file from DAQ (run-level) was not found, still going on with Cumulative data file (please check!) "); 
+        }
+      }
+    }
+  else{
+    Log("The input data file list from DAQ (run-level) was not found, still going on with Cumulative data file (please check!) "); 
+  }
+
+  //Total files, with summed histos
+
+  TList* listTot = GetFileSources(kDAQ, "DELAYS");
+  if (listTot)
+    {
+      AliInfo("The following sources produced files with the id DELAYS");
+      listTot->Print();
+      for (Int_t jj=0;jj<listTot->GetEntries();jj++){
+       TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj));
+       AliInfo(Form("found source %s", str->String().Data()));
+
        // file with summed histos, to extract calib params
-       const char *fileName = GetFile(kDAQ, "DELAYS", str->GetName());
-       if (fileName){
-         AliInfo(Form("Got the file %s, now we can extract some values.", fileName));
-
-         daqFile = new TFile(fileName,"READ");
-         fArray = (TObjArray*) daqFile->Get("ciccio");
-         if (!fArray){
-           AliInfo(Form("some problems occurred:: No histo array retrieved"));
+       TString fileName = GetFile(kDAQ, "DELAYS", str->GetName());
+       if (fileName.Length()>0){
+         AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data()));
+
+         daqFile = new TFile(fileName.Data(),"READ");
+         fh2 = (TH2S*) daqFile->Get("htoftot");
+         if (!fh2){
+           Log("some problems occurred:: No histo retrieved, TOF exiting from Shuttle");
+           delete daqFile;
+           return 0;
          }
-         
          else {
-           Int_t nentries=(Int_t)fArray->GetEntries();
-           AliInfo(Form(" il numero di entries e' = %i ", nentries)); 
+           static const Int_t kSize=fh2->GetNbinsX();
+           static const Int_t kNBins=fh2->GetNbinsY();
+           static const Double_t kXBinmin=fh2->GetYaxis()->GetBinLowEdge(1);
            Int_t npads = fCal->NPads();
-           TH1F *h1 = new TH1F();
-           for (Int_t i=0 ; i<nentries; i++){
+           if (kSize != npads){
+             Log(" number of bins along x different from number of pads, found only a subset of the histograms, TOF exiting from Shuttle");
+             delete daqFile;
+              return 0;
+           }
+           for (Int_t ich=0;ich<kSize;ich++){
+             TH1S *h1 = new TH1S("h1","h1",kNBins,kXBinmin-0.5,kNBins*1.+kXBinmin-0.5);
+             for (Int_t ibin=0;ibin<kNBins;ibin++){
+               h1->SetBinContent(ibin+1,fh2->GetBinContent(ich+1,ibin+1));
+             }
              Bool_t found=kFALSE; 
-             h1 = (TH1F*)fArray->At(i);
-             Float_t minContent=h1->Integral()*0.01; //for the time being 
-             //we use integral() since we simulate landau distribution
-             //Float_t minContent=h1->GetEntries()*0.01;
+             Float_t minContent=h1->Integral()*fgkThrPar; 
              Int_t nbinsX = h1->GetNbinsX();
              Int_t startBin=1;
              for (Int_t j=1; j<=nbinsX; j++){
@@ -184,7 +225,7 @@ UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap)
                  break;
                }
              }
-             if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",i));
+             if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",ich));
              // Now calculate the mean over the interval. 
              Double_t mean = 0;
              Double_t sumw2 = 0;
@@ -194,18 +235,17 @@ UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap)
                nent=nent+h1->GetBinContent(startBin+k);                 
                sumw2=sumw2+(h1->GetBinCenter(startBin+k))*(h1->GetBinCenter(startBin+k))*(h1->GetBinContent(startBin+k));
              }
-             
              mean= mean/nent; //<x>
              sumw2=sumw2/nent; //<x^2>
              Double_t rmsmean= 0;
              rmsmean = TMath::Sqrt((sumw2-mean*mean)/nent);
-             if (i<npads) {
-               AliTOFChannelOnline * ch = fCal->GetChannel(i);
+             if (ich<npads) {
+               AliTOFChannelOnline * ch = fCal->GetChannel(ich);
                ch->SetDelay(mean);
              }
-           }
            delete h1;
-           h1=0;
+           h1=0x0;
+           }
          }
          daqFile->Close();
          delete daqFile;
@@ -214,26 +254,35 @@ UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap)
          metaData.SetResponsible("Chiara Zampolli");
          metaData.SetComment("This preprocessor fills an AliTOFCal object.");
          resultDAQ = Store("Calib","OnlineDelay",fCal, &metaData);
-         result+=resultDAQ*2*2;
+          if(!resultDAQ){
+           Log("Some problems occurred while storing DAQ data processing results");
+           return 0;
+         }
        }
        else{
-         AliError(Form("The file %s does not exist",fileName)); 
+         Log("The Cumulative data file from DAQ does not exist, TOF exiting from Shuttle"); 
+          return 0;
        }
       }
     }
   else{
-    AliInfo(Form("Problem: no list found"));
+    Log("Problem: no list for Cumulative data file from DAQ was found, TOF exiting from Shuttle");
+    return 0;
   }
 
-  delete list;
-  list = 0;
+  //  delete list;
+  // list = 0;
+  // delete listTot;
+  // listTot = 0;
   daqFile=0;
-  delete fData;
-  fData = 0;
-  delete fCal;
-  fCal = 0;
-  delete fArray;
-  fArray = 0;
+
+  if(resultDCS ==2|| resultDAQ ==2) {
+    result=2;
+  }
+  else{ 
+    result=1;
+  }
+
   return result;
 }