]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - T0/AliT0CalibData.cxx
Alexey: new macros for T0 visualization.
[u/mrichter/AliRoot.git] / T0 / AliT0CalibData.cxx
index 82086467ed904afe0e90fe3619bbb2094da53a66..815f417999ecc4200692545199794fa13b7510d6 100644 (file)
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
-#include <iostream>
-#include <fstream>
-#include <iomanip>
-#include <string>
-#include <TCanvas.h>
-
 #include "AliT0CalibData.h"
 #include "AliT0LookUpValue.h"
-#include "TObjArray.h"
-#include "TGraph.h"
-#include "TFile.h"
 #include "AliLog.h"
-#include "TObjString.h"
-
-#include "TAxis.h"
-#include "TH2F.h"
 
+#include <TCanvas.h>
+#include <TObjString.h>
+#include <TObjArray.h>
+#include <TGraph.h>
+#include <TFile.h>
+#include <TAxis.h>
+#include <TH2F.h>
+#include <TMath.h>
+#include <TSystem.h>
+#include <Riostream.h>
 
+#include <string>
 
 ClassImp(AliT0CalibData)
 
@@ -90,7 +88,6 @@ void AliT0CalibData::Reset()
 {
     memset(fTimeDelayCFD,1,24*sizeof(Float_t));
     memset(fTimeDelayLED,1,24*sizeof(Float_t));
-    memset(fGain,1,24*sizeof(Float_t));
 }
 
 
@@ -99,84 +96,118 @@ void  AliT0CalibData::Print(Option_t*) const
 {
 
   printf("\n   ----    PM Arrays       ----\n\n");
-  printf(" Time delay CFD \n");
-  for (Int_t i=0; i<24; i++) printf("  %f",fTimeDelayCFD[i]);
-  printf(" \n LED \n");
-  for (Int_t i=0; i<24; i++) printf("  %f",fTimeDelayLED[i]);
-  printf(" \n Gain \n");
-  for (Int_t i=0; i<24; i++) printf("  %f",fGain[i]);
-  printf(" \n");
+  printf(" Time delay CFD & LED\n");
+  for (Int_t i=0; i<24; i++) printf(" CFD  %f LED %f ",fTimeDelayCFD[i], fTimeDelayLED[i]);
 } 
 
 //________________________________________________________________
 void  AliT0CalibData::PrintLookup(Option_t*, Int_t iTRM, Int_t iTDC, Int_t iChannel) const
 {
+  
+  AliT0LookUpKey* lookkey= new AliT0LookUpKey();
+  AliT0LookUpValue*  lookvalue= new AliT0LookUpValue();
 
-   AliT0LookUpKey* lookkey= new AliT0LookUpKey();
-   AliT0LookUpValue*  lookvalue= new AliT0LookUpValue();
-     lookvalue->SetTRM(iTRM);
-     lookvalue->SetTDC(iTDC);
-     lookvalue->SetChain(0);
-     lookvalue->SetChannel(iChannel);
-
-     printf(" AliT0CalibData::PrintLookup ::start GetValue %i %i %i \n",iTRM, iTDC, iChannel);
-     lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
-     
-     cout<<"  AliT0CalibData::PrintLookup :: lookkey "<< lookkey<<endl;
-     if (lookkey)
-       {
-        cout<<" lookup KEY!!! "<<lookkey->GetKey()<<" VALUE "<<lookvalue->GetTRM()<<" "
-            <<lookvalue->GetTDC()<<" "
-            << lookvalue->GetChain()<<" "
-            <<lookvalue->GetChannel()<<endl;
-       }
-     
+  cout<<" Number Of TRMs in setup "<<GetNumberOfTRMs()<<endl;
+  lookvalue->SetTRM(iTRM);
+  lookvalue->SetTDC(iTDC);
+  lookvalue->SetChain(0);
+  lookvalue->SetChannel(iChannel);
 
+  
+  printf(" AliT0CalibData::PrintLookup ::start GetValue %i %i %i \n",iTRM, iTDC, iChannel);
+  lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
+  
+  cout<<"  AliT0CalibData::PrintLookup :: lookkey "<< lookkey<<endl;
+  if (lookkey)
+    {
+      cout<<" lookup KEY!!! "<<lookkey->GetKey()<<" VALUE "<<lookvalue->GetTRM()<<" "
+         <<lookvalue->GetTDC()<<" "
+         << lookvalue->GetChain()<<" "
+         <<lookvalue->GetChannel()<<endl;
+    }
+  
+  
 }
 
 //________________________________________________________________
 void AliT0CalibData::SetTimeDelayCFD(Float_t* TimeDelay)
 {
   if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayCFD[t] = TimeDelay[t];
-  //  else for(int t=0; t<24; t++) fTimeDelay[t] = 0.;
-}
-//________________________________________________________________
-void AliT0CalibData::SetTimeDelayLED(Float_t* TimeDelay)
+}  
+  //________________________________________________________________
+  void AliT0CalibData::SetTimeDelayLED(Float_t* TimeDelay)
 {
   if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayLED[t] = TimeDelay[t];
-  //  else for(int t=0; t<24; t++) fTimeDelay[t] = 0.;
 }
 
+
 //________________________________________________________________
-void AliT0CalibData::SetGain(Float_t* Gain)
+void AliT0CalibData::SetWalk(Int_t ipmt)
 {
-  if(Gain) for(int t=0; t<24; t++) fGain[t] = Gain[t];
-  // else for(int t=0; t<24; t++) fGain[t] = 0.;
-}
 
+  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;
 
-//________________________________________________________________
-void AliT0CalibData::SetWalk(Int_t ipmt, const Char_t *filename)
-{
+    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++;
+         //      cout<<ii<<" "<<ind<<" "<<y[ind]<<" "<<x[ind]<<" "<<sum<<endl;
+       }
+      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];
+         //      cout<<ii<<" "<<ind<<" "<<y[ind]<<" "<<x[ind]<<" iin "<<iin<<" mean "<<time[isum]<<" amp "<< amplitude[isum]<<" "<<isum<<endl;
+         iin=0;
+         isum++;
+         sum=0;
+       }
+    }
 
-  TFile *file = new TFile(filename);
-  char funcname[256];
-  sprintf(funcname,"CFD%i",ipmt+1);
-  TF1* gr = (TF1*)file->Get(funcname);
+  inFile.close();
+
+  TGraph* gr = new TGraph(isum, amplitude, time);
   fWalk.AddAtAndExpand(gr,ipmt);
-  file->Close();
 }
 
 
 //________________________________________________________________
 
-void AliT0CalibData::SetSlewingLED(Int_t ipmt,const Char_t *filename)
+void AliT0CalibData::SetSlewingLED(Int_t ipmt)
 {
   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));}
   
@@ -196,13 +227,14 @@ void AliT0CalibData::SetSlewingLED(Int_t ipmt,const Char_t *filename)
 
 //________________________________________________________________
 
-void AliT0CalibData::SetSlewingRec(Int_t ipmt,const Char_t *filename)
+void AliT0CalibData::SetSlewingRec(Int_t ipmt)
 {
   Float_t mv, ps; 
   Float_t x[100], y[100];
   string buffer;
   
-  ifstream inFile(filename);
+ const char * filename = gSystem->ExpandPathName("$ALICE_ROOT/T0/data/CFD-LED.root");
+   ifstream inFile(filename);
   if(!inFile) {AliError(Form("Cannot open file %s !",filename));}
   
   inFile >> mv>>ps;
@@ -222,54 +254,71 @@ void AliT0CalibData::SetSlewingRec(Int_t ipmt,const Char_t *filename)
   
 }
 
+//________________________________________________________________
 
 void AliT0CalibData::ReadAsciiLookup(const Char_t *filename)
 {
+  Int_t key, trm, tdc, chain, channel;
 
   if(filename == 0){
     AliError(Form("Please, specify file with database")) ;
     return ;
   }
 
-  //  AliT0LookUpKey * lookkey= new AliT0LookUpKey();
-  //AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
 
   ifstream lookup;
   lookup.open(filename);
-  if(!lookup) {AliError(Form("Cannot open file %s !",filename));}
+  if(!lookup)
+    {
+      //  AliLog(Form("Cannot open file %s ! Getting hardcoded value",filename));
+
+      //      fNumberOfTRMs = 2;
+      SetNumberOfTRMs(2);
+      trm=0; tdc=0; chain=0; channel=0; key=0;
+      for (Int_t ik=0; ik<108; ik++)
+       {
+         AliT0LookUpKey * lookkey= new AliT0LookUpKey();
+         AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
+         
+         lookvalue->SetTRM(trm);
+         lookvalue->SetTDC(tdc);
+         lookvalue->SetChain(chain);
+         lookvalue->SetChannel(channel);
+         lookkey->SetKey(ik);
+         if(ik>53) { trm=1; tdc=0; channel=0;}
+         if (channel<7) channel +=2;
+         else {channel = 0; tdc++;}
+       }
+    }
   Char_t varname[11];
-  Int_t key, trm, tdc, chain, channel;
-  // while(lookup.eof())
-
- for (Int_t i=0; i<108; i++)
-//    for (Int_t i=0;i<3;i++)
+  Int_t ntrms;
+  if(lookup)
     {
-       AliT0LookUpKey * lookkey= new AliT0LookUpKey();
-       AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
-
- lookup>>varname>>key>>trm>>chain>>tdc>>channel;
-      lookvalue->SetTRM(trm);
-      lookvalue->SetTDC(tdc);
-      lookvalue->SetChain(chain);
-      lookvalue->SetChannel(channel);
-      lookkey->SetKey(key);
-
-      //      cout<<"TRM="<<trm<<" TDC="<<tdc<<" chain="<<chain<<" channel="<<channel<<" key="<<key<<endl;
-
-      cout<<"AliT0CalibData:: "<<varname<<" "<<key<<" "<<trm<<" "<<chain<<" "<<tdc<<" "<<channel<<endl;
-
-      //    fLookup.Add((TObject*)lookkey,(TObject*)lookvalue);
-      // ar_key.AddAt(lookkey,i);
-      // ar_val.AddAt(lookvalue,i);
-
-        fLookup.Add((TObject*)lookvalue,(TObject*)lookkey);
-
+      lookup>>ntrms;
+      cout<<" !!!!!!! ntrms "<<ntrms<<endl;
+      //      fNumberOfTRMs=ntrms;
+      SetNumberOfTRMs(ntrms);
+       while(!lookup.eof())
+       {
+         AliT0LookUpKey * lookkey= new AliT0LookUpKey();
+         AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
+         
+         lookup>>varname>>key>>trm>>chain>>tdc>>channel;
+         lookvalue->SetTRM(trm);
+         lookvalue->SetTDC(tdc);
+         lookvalue->SetChain(chain);
+         lookvalue->SetChannel(channel);
+         lookkey->SetKey(key);
+         cout<<"lookup "<<varname<<" "<<key<<" "<<trm<<" "<<chain<<" "<<tdc<<" "<<channel<<endl;         
+         
+         fLookup.Add((TObject*)lookvalue,(TObject*)lookkey);
+         
+       }
+      
+      lookup.close();
+      
     }
-
-   lookup.close();
-
 }
-
 //________________________________________________________________
 
 Int_t AliT0CalibData::GetChannel(Int_t trm,  Int_t tdc, Int_t chain, Int_t channel)
@@ -278,8 +327,8 @@ Int_t AliT0CalibData::GetChannel(Int_t trm,  Int_t tdc, Int_t chain, Int_t chann
   AliT0LookUpKey * lookkey;//= new AliT0LookUpKey();
   AliT0LookUpValue * lookvalue= new AliT0LookUpValue(trm,tdc,chain,channel);
 
-     lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
-    cout<<"AliT0CalibData:: key "<<lookkey->GetKey()<<endl;
+  lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
+
   return lookkey->GetKey();
 
 }