improved amplitude calibration
authoralla <alla@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 28 Feb 2010 19:09:52 +0000 (19:09 +0000)
committeralla <alla@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 28 Feb 2010 19:09:52 +0000 (19:09 +0000)
T0/AliT0CalibWalk.cxx
T0/AliT0CalibWalk.h
T0/AliT0Preprocessor.cxx
T0/AliT0Preprocessor.h

index 43f2910..8d5c721 100644 (file)
@@ -92,109 +92,18 @@ AliT0CalibWalk::~AliT0CalibWalk()
 {
   //
 }
-//________________________________________________________________
-void AliT0CalibWalk::SetWalk(Int_t ipmt)
-{
-  //read QTC walk graph from external file
-
-  Int_t mv, ps; 
-  Int_t x[70000], y[70000], index[70000];
-  Float_t time[10000],amplitude[10000];
-  string buffer;
-  Bool_t down=false;
-  
-  const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-Amp.txt");
-  ifstream inFile(filename);
-  if(!inFile) AliError(Form("Cannot open file %s !",filename));
-  
-  Int_t i=0;
-  while(getline(inFile,buffer)){
-    inFile >> ps >> mv;
-
-    x[i]=ps; y[i]=mv;
-    i++;
-  }
-  inFile.close();
-  //  cout<<" number of data "<<i<<endl;
-  TMath::Sort(i, y, index,down);
-  Int_t amp=0, iin=0, isum=0, sum=0;
-  Int_t ind=0;
-  for (Int_t ii=0; ii<i; ii++)
-    {
-      ind=index[ii];
-      if(y[ind] == amp)
-       {
-         sum +=x[ind];
-         iin++;
-       }
-      else
-       {
-         if(iin>0)
-           time[isum] = Float_t (sum/(iin));
-         else
-           time[isum] =Float_t (x[ind]);
-         amplitude[isum] = Float_t (amp);
-         amp=y[ind];
-         iin=0;
-         isum++;
-         sum=0;
-       }
-    }
+//________________________________________________________________  
 
-  inFile.close();
-
-  TGraph* gr = new TGraph(isum, amplitude, time);
-  fWalk.AddAtAndExpand(gr,ipmt);
-
-  //should be change to real
-  Double_t xq[10] = { 1220, 1370, 1542, 1697, 1860, 2023,2171,2331,2495,2684};
-  Double_t yq[10] = {1,2,3,4,5,6,7,8,9,10};
-  TGraph* gr1 = new TGraph(10, xq, yq);
-  fQTC.AddAtAndExpand(gr1,ipmt);
-}
-
-//________________________________________________________________
-
-void AliT0CalibWalk::SetAmpLEDRec(Int_t ipmt)
-{
-  // read LED walk from external file
-  Float_t mv, ps; 
-  Float_t x[100], y[100];
-  string buffer;
-  
-  const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-LED.txt");
-   ifstream inFile(filename);
-  if(!inFile) {AliError(Form("Cannot open file %s !",filename));}
-  
-  inFile >> mv>>ps;
-  Int_t i=0;
-  
-  while(getline(inFile,buffer)){
-    x[i]=mv; y[i]=ps;  
-    inFile >> mv >> ps;
-    i++;
-  }
-  inFile.close();
-  Float_t y1[100], x1[100];
-  for (Int_t ir=0; ir<i; ir++){
-    y1[ir]=y[i-ir]; x1[ir]=x[i-ir];}
-  TGraph* gr = new TGraph(i,y1,x1);
-  fAmpLEDRec.AddAtAndExpand(gr,ipmt);
-  //should be change to real
-  Double_t xq[10] = { 411, 412,413,415,417,419,422,428,437,452};
-  Double_t yq[10] = {1,2,3,4,5,6,7,8,9,10};
-  TGraph* gr1 = new TGraph(10, xq, yq);
-  fAmpLED.AddAtAndExpand(gr1,ipmt);
-  
-}
-
-//________________________________________________________________
-
-void AliT0CalibWalk::MakeWalkCorrGraph(const char *laserFile)
+Bool_t AliT0CalibWalk::MakeWalkCorrGraph(const char *laserFile)
 {
   //make walk corerction for preprocessor
-  Int_t nmips=14;
+  Int_t npeaks = 20;
+  Int_t sigma=3.;
+  Bool_t down=false;
+  Int_t index[20];
+  Bool_t ok=true;
+  Float_t   mips[20];
+  
   gFile = TFile::Open(laserFile);
   if(!gFile) {
     AliError("No input laser data found ");
@@ -202,83 +111,133 @@ void AliT0CalibWalk::MakeWalkCorrGraph(const char *laserFile)
   else
     {
       //      gFile->ls();
-
-      Float_t x1[14], y1[14]; 
-      Float_t x2[14], y2[14];
-  
-      Float_t mips[14] = {1.,2,3,4,5,6,7,8,9,10,20,30,40,50};
-     
-      Float_t xx1[14],yy1[14], xx[14];
-      for (Int_t ii=0; ii<14; ii++)
-       {      x1[ii]=0; y1[ii]=0; x2[ii]=0; y2[ii]=0; }
+      TH1F* hAmp = (TH1F*) gFile->Get("hAmpLaser");
+      Int_t nmips=0;
+      for (Int_t ibin=0; ibin<1000; ibin++) {
+       Float_t bincont = hAmp->GetBinContent(ibin);
+       if(bincont>0){ 
+         mips[nmips] = hAmp->GetXaxis()->GetBinCenter(ibin);
+         cout<<ibin<<" bincont "<<bincont<<" amp "<< mips[nmips]<<endl;
+         nmips++;
+       }       
+      }     
+      Float_t x1[20], y1[20]; 
+      Float_t x2[20], xx2[20],y2[20];
+      Float_t xx1[20],yy1[20], xx[20];
       
+      Float_t cfd0[24];
+      Int_t startim = 0;
       
-      TH2F*  hCFDvsQTC[24][14]; TH2F*  hCFDvsLED[24][14];
+      for (Int_t ii=0; ii<nmips; ii++)
+       x1[ii] = y1[ii] = x2[ii] = y2[ii] = 0; 
       
       for (Int_t i=0; i<24; i++)
        {
-         for (Int_t im=0; im<nmips; im++)
+         for (Int_t im=startim; im<nmips; im++)
            {         
-             TString qtc = Form("CFDvsQTC%i_%i",i+1,im+1);
-             TString led = Form("CFDvsLED%i_%i",i+1,im+1);
-             hCFDvsQTC[i][im] = (TH2F*) gFile->Get(qtc.Data()) ;
-             hCFDvsLED[i][im] = (TH2F*) gFile->Get(led.Data());
-             
-             if(!hCFDvsQTC[i][im] || !hCFDvsLED[i][im]) 
-               AliWarning(Form(" no walk correction data in LASER DA for channel %i for amplitude %f MIPs",i,mips[im]));
+             Float_t fitmean=0;
+             TString cfd = Form("hCFD%i_%i",i+1,im+1);
+             TString qtc = Form("hQTC%i_%i",i+1,im+1);
+             TString led = Form("hLED%i_%i",i+1,im+1);
              
-             Float_t qtc0 = hCFDvsQTC[i][0]->GetMean(2);             
-             if(hCFDvsQTC[i][im])
-               {         
-                 x1[im] = hCFDvsQTC[i][im]->GetMean(1);
-                 y1[im] =  hCFDvsQTC[i][im]->GetMean(2) - qtc0;
+             TH1F *hCFD = (TH1F*) gFile->Get(cfd.Data()) ;
+             TH1F *hLED = (TH1F*) gFile->Get(led.Data());
+             TH1F *hQTC = (TH1F*) gFile->Get(qtc.Data()) ;
+             hCFD->SetDirectory(0);
+             hQTC->SetDirectory(0);
+             hLED->SetDirectory(0);
+             if(!hCFD )
+               AliWarning(Form(" no CFD data in LASER DA for channel %i for amplitude %f MIPs",i,mips[im]));
+             if(!hQTC )
+               AliWarning(Form(" no QTC correction data in LASER DA for channel %i for amplitude %f MIPs",i,mips[im]));
+             if(!hLED)       
+               AliWarning(Form(" no LED correction data in LASER DA for channel %i for amplitude %f MIPs",i,mips[im]));
+             
+             if(hCFD ) {
+               TSpectrum *s = new TSpectrum(2*npeaks,1);
+               Int_t nfound = s->Search(hCFD,sigma," ",0.1);
+               if(nfound!=0){
+                 Float_t *xpeak = s->GetPositionX();
+                 TMath::Sort(nfound, xpeak, index,down);
+                 Float_t xp = xpeak[index[0]];
+                 Double_t hmax = xp+3*sigma;
+                 Double_t hmin = xp-3*sigma;
+                 hCFD->GetXaxis()->SetRangeUser(hmin-10,hmax+10);
                }
-             Float_t led0 = hCFDvsLED[i][0]->GetMean(2);
-             if( hCFDvsLED[i][im]){
-                 x2[im] = hCFDvsLED[i][im]->GetMean(1);
-                 y2[im] =  hCFDvsLED[i][im]->GetMean(2) - led0;
+               else
+                 {
+                   hCFD->Rebin(2);
+                   TSpectrum *s = new TSpectrum(2*npeaks,1);
+                   Int_t nfound = s->Search(hCFD,sigma," ",0.1);
+                   if(nfound!=0){
+                     Float_t *xpeak = s->GetPositionX();
+                     TMath::Sort(nfound, xpeak, index,down);
+                     Float_t xp = xpeak[index[0]];
+                     Double_t hmax = xp+3*sigma;
+                     Double_t hmin = xp-3*sigma;
+                     hCFD->GetXaxis()->SetRangeUser(hmin-10,hmax+10);
+                   }
+                   else 
+                     ok=false;
+                 }
+
+               if (im == 0) cfd0[i] = hCFD->GetMean();
+               y1[im] =  hCFD->GetMean() - cfd0[i];
+             }
+             if( hQTC) x1[im] = hQTC->GetMean();
+             
+             if( hLED){
+               TSpectrum *s = new TSpectrum(2*npeaks,1);
+               Int_t nfound = s->Search(hLED,sigma," ",0.1);
+               if(nfound!=0){
+                 Float_t *xpeak = s->GetPositionX();
+                 TMath::Sort(nfound, xpeak, index,down);
+                 Float_t xp = xpeak[index[0]];
+                 Double_t hmax = xp+10*sigma;
+                 Double_t hmin = xp-10*sigma;
+                 hLED->GetXaxis()->SetRangeUser(hmin-10,hmax+10);
                }
+               else 
+                 ok=false;
+               x2[im] = hLED->GetMean();
+               xx2[im] = x2[nmips-im-1]; 
+             }
              xx[im]=mips[im];
+             
+             if (hQTC) delete  hQTC;
+             if (hCFD) delete  hCFD;
+             if (hLED) delete  hLED;
            }
+         
          for (Int_t imi=0; imi<nmips; imi++)
            {
              yy1[imi] = Float_t (mips[nmips-imi-1]);
              xx1[imi] = x2[nmips-imi-1]; 
+             //              cout<<" LED rev "<<i<<" "<<imi<<" "<<xx1[imi]<<" "<< yy1[imi]<<"nmips-imi-1 = "<< nmips-imi-1<<endl;
            }
-         if(i==0) cout<<"Making graphs..."<<endl;
          
+         if(i==0) cout<<"Making graphs..."<<endl;
+                 
          TGraph *grwalkqtc = new TGraph (nmips,x1,y1);
-         TGraph *grwalkled = new TGraph (nmips,x2,y2);
+         grwalkqtc->SetTitle(Form("PMT%i",i));
+         TGraph *grwalkled = new TGraph (nmips,x2,y1);
+         grwalkled->SetTitle(Form("PMT%i",i));
          fWalk.AddAtAndExpand(grwalkqtc,i);
          fAmpLEDRec.AddAtAndExpand(grwalkled,i);
+         //      cout<<" add walk "<<i<<endl;
         
          //fit amplitude graphs to make comparison wth new one   
          TGraph *grampled = new TGraph (nmips,xx1,yy1);
          TGraph *grqtc = new TGraph (nmips,x1,xx);
          fQTC.AddAtAndExpand(grqtc,i);  
          fAmpLED.AddAtAndExpand(grampled,i);
+         //      cout<<" add amp "<<i<<endl;
 
-         //fit amplitude graphs
-         Double_t parled [2], parqtc[2];
-
-         TF1 *fuled = new TF1("fuled","expo",x1[0],x1[nmips]);
-         TF1 *fuqtc = new TF1 ("fuqtc","pol1",x1[0],x1[nmips]);
-         grqtc->Fit("fuqtc","Q"," ",x1[0],x1[nmips]);
-         grampled->Fit("fuled","Q"," ",xx1[0],xx1[nmips]);
-         fuled->GetParameters(&parled[0]);
-         fuqtc->GetParameters(&parqtc[0]);
-
-         for(Int_t ipar=0; ipar<2; ipar++) {
-           SetQTCpar(i,ipar,parqtc[ipar]);
-           SetAmpLEDpar(i,ipar,parled[ipar]);
-           //      cout<<" pars :::: "<<i<<" "<<ipar<<" qtc "<<parqtc[ipar]<<" led "<<parled[ipar]<<endl;
-         }
-
-         if(i==23){
+         if(i==23)
            cout<<"Graphs created..."<<endl;
-         }
        }
     } //if gFile exits
+  return ok;
 }
 
 
index e96a04e..fa3a936 100644 (file)
@@ -23,27 +23,17 @@ class AliT0CalibWalk: public TNamed {
   
   
   TGraph *GetWalk(Int_t ipmt )  const {return (TGraph*)fWalk.At(ipmt);}
-  void SetWalk(Int_t ipmt) ;
   TObjArray* GetfWalk() {return &fWalk;}    
 
   TGraph *GetQTC(Int_t ipmt )  const {return (TGraph*)fQTC.At(ipmt);}
-  Float_t  GetQTCpar(Int_t channel, Int_t ipar)    const 
-  {return fQTCpar[channel][ ipar ];}
-  void SetQTCpar(Int_t channel,Int_t ipar, Float_t val) 
-  {fQTCpar[channel][ipar]=val;}
  
   TGraph *GetAmpLED(Int_t ipmt )  const {return (TGraph*)fAmpLED.At(ipmt);}
-  Float_t  GetLEDpar(Int_t channel, Int_t ipar)    const 
-  {return fAmpLEDpar[channel][ ipar ];}
-  void SetAmpLEDpar(Int_t channel,Int_t ipar, Float_t val)
-  {fAmpLEDpar[channel][ipar]=val;}
  
-  void MakeWalkCorrGraph(const char *laserFile);
+  Bool_t MakeWalkCorrGraph(const char *laserFile);
   
   
 
   TGraph *  GetAmpLEDRec(Int_t ipmt) const   {return (TGraph*)fAmpLEDRec.At(ipmt);}
-  void      SetAmpLEDRec(Int_t ipmt) ;
    
  protected:
    
@@ -51,11 +41,9 @@ class AliT0CalibWalk: public TNamed {
    TObjArray   fAmpLEDRec;  //time - amp. LED-CFD for reconstruction
    TObjArray   fQTC;  //time - amp. walk
    TObjArray   fAmpLED;  //time - amp. LED-CFD for reconstruction
-   Float_t   fQTCpar[24][2]; // fitted parameters QTC amplitude
-   Float_t   fAmpLEDpar[24][2]; // fitted parameters fAmpLEDpar amplitude
   
    //
-   ClassDef(AliT0CalibWalk,4)    // T0 Amplitude Calibration data
+   ClassDef(AliT0CalibWalk,5)    // T0 Amplitude Calibration data
      };
 
      typedef AliT0CalibWalk AliSTARTCalibWalk; // for backward compatibility
index 637f327..1ca8b37 100644 (file)
@@ -65,7 +65,7 @@ AliT0Preprocessor::AliT0Preprocessor(AliShuttleInterface* shuttle) :
   //constructor
   AddRunType("PHYSICS");
   AddRunType("STANDALONE");
-  //  AddRunType("LASER");
+  AddRunType("AMPLITUDE_CALIBRATION");
 }
 //____________________________________________________
 
@@ -92,8 +92,8 @@ Bool_t AliT0Preprocessor::ProcessDCS(){
        Log(Form("ProcessDCS - RunType: %s",runType.Data()));
 
        if((runType == "STANDALONE")||
-          (runType == "PHYSICS") ) {
-          //     || (runType == "LASER")){
+          (runType == "PHYSICS") 
+          || (runType == "AMPLITUDE_CALIBRATION")){
 
          //      return kFALSE;
                return kTRUE;
@@ -141,111 +141,58 @@ UInt_t AliT0Preprocessor::ProcessDCSDataPoints(TMap* dcsAliasMap){
 }
 //____________________________________________________
 
-UInt_t AliT0Preprocessor::ProcessLaser(){
-       // Processing data from DAQ Standalone run
+UInt_t AliT0Preprocessor::ProcessLaser()
+{
+  // Processing data from DAQ Standalone run
   Log("Processing Laser calibration - Walk Correction");
+  Bool_t resultLaser = kFALSE;
+  Bool_t writeok = kFALSE;
+  //processing DAQ
+  TObjString *source;
+  TList* list = GetFileSources(kDAQ, "AMPLITUDE_CALIBRATION");
+  AliT0CalibWalk *laser = new AliT0CalibWalk();
+  if (list)
+    {
+      TIter iter(list);
+      while ((source = dynamic_cast<TObjString *> (iter.Next())))
+       {
+         const char *laserFile = GetFile(kDAQ, "AMPLITUDE_CALIBRATION", source->GetName());
+         if (laserFile)
+           {
+             Log(Form("File with Id LASER found in source %s!", source->GetName()));
+            writeok = laser->MakeWalkCorrGraph(laserFile);
+             
+           }
+       }
+      
+      AliCDBMetaData metaData;
+      metaData.SetBeamPeriod(0);
+      metaData.SetResponsible("Tomek&Michal");
+      metaData.SetComment("Walk correction from laser runs.");
+      if (writeok) resultLaser=Store("Calib","Slewing_Walk", laser, &metaData, 0, 1);
+      else {
+       
+       Log(Form("writeok = %d no peaks in CFD spectra",writeok));
+       return 0;
+      }                  
+      Log(Form("resultLaser = %d",resultLaser));
+    }
+  else
+    {
+      Log(Form("Could not find file with Id LASER in source %s!", source->GetName()));
+      return 1;
+    }
   
-  //Retrieve the last T0 calibration object
-
-  Float_t parqtcold[24][2], parledold[24][2],parqtcnew[24][2], parlednew[24][2] , goodled[24][2], goodqtc[24][2];
-
-  //  std::cout<<"sizeof "<<sizeof(parqtcold)<<std::endl;
-  memset(parqtcold, 0, sizeof(parqtcold));
-  memset(parqtcnew, 0, sizeof(parqtcnew));
-  memset(parledold, 0, sizeof(parledold));
-  memset(parlednew, 0, sizeof(parlednew));
-  Int_t iStore=0;
-
-
-  AliT0CalibWalk* clb=0;
-  AliCDBEntry* entryCalib = GetFromOCDB("Calib", "Slewing_Walk");
-  if(!entryCalib)
-    Log(Form("Cannot find any AliCDBEntry for [Calib, SlewingWalk]!"));
+  if (!resultLaser)
+    {
+      Log("No Laser Data stored");
+      return 3;//return error code for failure in storing Laser Data
+    }
   else {
-    clb =dynamic_cast<AliT0CalibWalk*>(entryCalib->GetObject());
-    for(Int_t i=0; i<24; i++)
-      {
-       for(Int_t ipar=0; ipar<2; ipar++)
-         {
-           //    std::cout<<"parqtcold "<<parqtcold[i][ipar]<<std::endl;
-           parqtcold[i][ipar] = clb->GetQTCpar(i,ipar);
-           parledold[i][ipar] = clb->GetLEDpar(i, ipar);
-           goodqtc[i][ipar] = 999;
-           goodled[i][ipar] = 999;
-           //    std:: cout<<" old "<<i<<" "<<ipar<<" qtc "<< parqtcold[i][ipar]<<" led "<<parledold[i][ipar]<< std::endl;
-         }
-      }
+    Log("No sources found for id LASER!");
+    return 1;
   }
-
-
-    Bool_t resultLaser=kFALSE;
-    //processing DAQ
-    TList* list = GetFileSources(kDAQ, "LASER");
-    if (list)
-      {
-       TIter iter(list);
-       TObjString *source;
-       while ((source = dynamic_cast<TObjString *> (iter.Next())))
-         {
-           const char *laserFile = GetFile(kDAQ, "LASER", source->GetName());
-           if (laserFile)
-              {
-                Log(Form("File with Id LASER found in source %s!", source->GetName()));
-                AliT0CalibWalk *laser = new AliT0CalibWalk();
-                laser->MakeWalkCorrGraph(laserFile);
-               //check difference with what was before
-               if(laser && clb ){
-                 iStore = 1;                           
-                 for(Int_t i=0; i<24; i++)
-                   {
-                     for(Int_t ifit=0; ifit<2; ifit++)
-                       {
-                         parqtcnew[i][ifit] = laser->GetQTCpar(i,ifit);
-                         if( parqtcold[i][ifit] != 0 && parqtcnew[i][ifit] !=0) 
-                           {
-                             goodqtc[i][ifit] = 
-                               (parqtcnew[i][ifit] - parqtcold[i][ifit])/parqtcold[i][ifit];
-                             //                               std::cout<<"qtc "<<i<<" "<<ifit<<" "<< goodqtc[i][ifit]<< std::endl;
-                           }
-                         parlednew[i][ifit] = laser->GetLEDpar(i,ifit);
-                         if(parledold[i][ifit] != 0 && parlednew[i][ifit]!= 0 ) 
-                           {
-                             goodled[i][ifit]= 
-                               (parlednew[i][ifit] - parledold[i][ifit])/parledold[i][ifit];   
-                             //                               std::cout<<"led "<<i<<" "<<ifit<<" "<< goodled[i][ifit]<< std::endl;
-                           }                   
-                         //      if(TMath::Abs(goodqtc[i][ifit])>0.1 || 
-                         //         TMath::Abs(goodled[i][ifit])>0.1) 
-                         //        iStore = 0;
-                       }
-                   }
-               }
-
-               AliCDBMetaData metaData;
-               metaData.SetBeamPeriod(0);
-                metaData.SetResponsible("Tomek&Michal");
-                metaData.SetComment("Walk correction from laser runs.");
-               if( iStore>0)
-                 resultLaser=Store("Calib","Slewing_Walk", laser, &metaData, 0, 1);
-                delete laser;
-               Log(Form("resultLaser = %d",resultLaser));
-              }
-              else
-              {
-                Log(Form("Could not find file with Id LASER in source %s!", source->GetName()));
-                return 1;
-              }
-            }
-            if (!resultLaser)
-            {
-              Log("No Laser Data stored");
-              return 3;//return error code for failure in storing Laser Data
-            }
-          } else {
-               Log("No sources found for id LASER!");
-               return 1;
-         }
-       return 0;
+  return 0;
 }
 
 //____________________________________________________
@@ -326,8 +273,8 @@ UInt_t AliT0Preprocessor::Process(TMap* dcsAliasMap )
       return iresultDCS;
     }
   }
-  /*
-  if(runType == "LASER"){
+  
+  if(runType == "AMPLITUDE_CALIBRATION"){
     Int_t iresultLaser = ProcessLaser();
     if(dcsDP==1){
       Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);
@@ -337,7 +284,7 @@ UInt_t AliT0Preprocessor::Process(TMap* dcsAliasMap )
     Log(Form("iresultLaser = %d",iresultLaser));
     return iresultLaser;
   }
-  */
+  
   else if(runType == "PHYSICS"){
     Int_t iresultPhysics = ProcessPhysics();
     if(dcsDP==1){
index 74d67a8..4119a48 100644 (file)
@@ -8,7 +8,7 @@
 
 
 // T0 preprocessor. 
-// Takes data from DCS and passes it to the class AliTOFDataDCS for processing and writes the result to the Reference DB.
+// Takes data from DCS and passes it to the class AliT0DataDCS for processing and writes the result to the Reference DB.
 // Takes data form DAQ (both from Laser Calibration and Physics runs), processes it, and stores either to OCDB or to Reference DB.
 
 #include "AliPreprocessor.h"