Update of TPC and TOF tender supplies
authorwiechula <wiechula@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 19 Jan 2011 11:48:45 +0000 (11:48 +0000)
committerwiechula <wiechula@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 19 Jan 2011 11:48:45 +0000 (11:48 +0000)
ANALYSIS/CMakelibTENDERSupplies.pkg
ANALYSIS/PROOF-INF.TENDERSupplies/SETUP.C
ANALYSIS/TenderSupplies/AddTaskTender.C
ANALYSIS/TenderSupplies/AliTOFTenderSupply.cxx
ANALYSIS/TenderSupplies/AliTOFTenderSupply.h
ANALYSIS/TenderSupplies/AliTPCTenderSupply.cxx
ANALYSIS/TenderSupplies/AliTPCTenderSupply.h

index d2537ab..a41a6d8 100644 (file)
@@ -31,10 +31,10 @@ string ( REPLACE ".cxx" ".h"  HDRS "${SRCS}")
 
 set ( DHDR  TenderSuppliesLinkDef.h)
 
-set ( EINCLUDE  ANALYSIS ANALYSIS/Tender STEER TOF TRD/Cal VZERO ANALYSIS/TenderSupplies)
+set ( EINCLUDE  ANALYSIS ANALYSIS/Tender STEER TOF TRD/Cal VZERO ANALYSIS/TenderSupplies TPC T0)
 
 if( ALICE_TARGET STREQUAL "win32gcc")
        
-               set ( PACKSOFLAGS  ${SOFLAGS} -L${ALICE_ROOT}/lib/tgt_${ALICE_TARGET} -lSTEERBase -lSTEER -lANALYSIS -lCDB)
+               set ( PACKSOFLAGS  ${SOFLAGS} -L${ALICE_ROOT}/lib/tgt_${ALICE_TARGET} -lSTEERBase -lSTEER -lANALYSIS -lCDB -lT0base -lT0rec -lTPCbase)
 
 endif( ALICE_TARGET STREQUAL "win32gcc")
index 1597d04..222366c 100644 (file)
@@ -9,6 +9,8 @@ void SETUP()
   CheckLoadLibrary("libGeom");
   CheckLoadLibrary("libVMC");
   CheckLoadLibrary("libMinuit");
+  CheckLoadLibrary("libGui");
+  CheckLoadLibrary("libXMLParser");
   
   // Load the AliROOT library
   CheckLoadLibrary("libANALYSIS");
@@ -16,11 +18,13 @@ void SETUP()
   CheckLoadLibrary("libESD");
   CheckLoadLibrary("libCDB");
   CheckLoadLibrary("libTENDER");
-  //Load libs needed for TOFbase
+  //Load libs needed for TOF
   CheckLoadLibrary("libProof");
   CheckLoadLibrary("libRAWDatabase");
   CheckLoadLibrary("libSTEER");
   CheckLoadLibrary("libTOFbase");
+  CheckLoadLibrary("libT0base");
+  CheckLoadLibrary("libT0rec");
 
   CheckLoadLibrary("libTENDERSupplies");
   
index 90a1817..ea0b4c9 100644 (file)
@@ -34,12 +34,13 @@ AliAnalysisTask *AddTaskTender(Bool_t useV0=kFALSE){
   //========= Attach TPC supply ======
   AliTPCTenderSupply *tpcSupply=new AliTPCTenderSupply("TPCtender");
   tpcSupply->SetDebugLevel(2);
-  tpcSupply->SetMip(50.);
+  //tpcSupply->SetMip(50.);
   tender->AddSupply(tpcSupply);
 
   //========= Attach TOF supply ======
-  AliTOFTenderSupply *TOFtender = new AliTOFTenderSupply("TOFtender");
-  tender->AddSupply(TOFtender);
+  AliTOFTenderSupply *tofTender = new AliTOFTenderSupply("TOFtender");
+  tofTender->SetTimeZeroType(AliESDpid::kTOF_T0);
+  tender->AddSupply(tofTender);
   
   //========= Attach TRD supply ======
   AliTRDTenderSupply *trdSupply=new AliTRDTenderSupply("TRDtender");
index 477c904..d2de04a 100644 (file)
-/**************************************************************************\r
- * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *\r
- *                                                                        *\r
- * Author: The ALICE Off-line Project.                                    *\r
- * Contributors are mentioned in the code where appropriate.              *\r
- *                                                                        *\r
- * Permission to use, copy, modify and distribute this software and its   *\r
- * documentation strictly for non-commercial purposes is hereby granted   *\r
- * without fee, provided that the above copyright notice appears in all   *\r
- * copies and that both the copyright notice and this permission notice   *\r
- * appear in the supporting documentation. The authors make no claims     *\r
- * about the suitability of this software for any purpose. It is          *\r
- * provided "as is" without express or implied warranty.                  *\r
- **************************************************************************/\r
-\r
-\r
-///////////////////////////////////////////////////////////////////////////////\r
-//                                                                           //\r
-// TOF tender: reapply TOF pid on the fly                                    //\r
-//                                                                           //\r
-///////////////////////////////////////////////////////////////////////////////\r
-#include <AliLog.h>\r
-#include <AliESDEvent.h>\r
-#include <AliESDInputHandler.h>\r
-#include <AliAnalysisManager.h>\r
-#include <AliESDpid.h>\r
-#include <AliTender.h>\r
-\r
-#include "AliTOFcalib.h"\r
-#include "AliTOFT0maker.h"\r
-\r
-#include "AliTOFTenderSupply.h"\r
-\r
-\r
-AliTOFTenderSupply::AliTOFTenderSupply() :\r
-  AliTenderSupply(),\r
-  fESDpid(0x0),\r
-  fIsMC(kFALSE),\r
-  fTOFCalib(0x0),\r
-  fTOFT0maker(0x0),\r
-  fTOFres(100.)\r
-{\r
-  //\r
-  // default ctor\r
-  //\r
-}\r
-\r
-//_____________________________________________________\r
-AliTOFTenderSupply::AliTOFTenderSupply(const char *name, const AliTender *tender) :\r
-  AliTenderSupply(name,tender),\r
-  fESDpid(0x0),\r
-  fIsMC(kFALSE),\r
-  fTOFCalib(0x0),\r
-  fTOFT0maker(0x0),\r
-  fTOFres(100.)\r
-{\r
-  //\r
-  // named ctor\r
-  //\r
-}\r
-\r
-//_____________________________________________________\r
-void AliTOFTenderSupply::Init()\r
-{\r
-  //\r
-  // Initialise TOF tender\r
-  //\r
-\r
-\r
-  //\r
-  // Setup PID object\r
-  //\r
-\r
-  // Check if another detector already created the esd pid object\r
-  // if not we create it and set it to the ESD input handler\r
-  fESDpid=fTender->GetESDhandler()->GetESDpid();\r
-  if (!fESDpid) {\r
-    fESDpid=new AliESDpid;\r
-    fTender->GetESDhandler()->SetESDpid(fESDpid);\r
-  }\r
-\r
-  //Set proper resolution in case of MC\r
-  AliAnalysisManager *mgr=AliAnalysisManager::GetAnalysisManager();\r
-  if (mgr->GetMCtruthEventHandler()) fIsMC=kTRUE;\r
-\r
-\r
-  //\r
-  // Create TOF calibration classes\r
-  //\r
-  if (!fTOFCalib){\r
-      fTOFCalib=new AliTOFcalib();\r
-      fTOFCalib->SetCorrectTExp(kTRUE); // apply a fine tuning on the expected times at low momenta\r
-      if(fIsMC) fTOFCalib->SetCalibrateTOFsignal(kFALSE); // no new calibration\r
-//      fTOFCalib->Init();\r
-  }\r
-  if (!fTOFT0maker) {\r
-      fTOFT0maker = new AliTOFT0maker(fESDpid,fTOFCalib);\r
-      fTOFT0maker->SetTimeResolution(fTOFres); // set TOF resolution for the PID\r
-  }\r
-}\r
-\r
-//_____________________________________________________\r
-void AliTOFTenderSupply::ProcessEvent()\r
-{\r
-  //\r
-  // Reapply pid information\r
-  //\r
-\r
-  //no corrections for MC\r
-  AliAnalysisManager *mgr=AliAnalysisManager::GetAnalysisManager();\r
-  if (mgr->GetMCtruthEventHandler()) return;\r
-\r
-  AliESDEvent *event=fTender->GetEvent();\r
-  if (!event) return;\r
-\r
-  //recalculate TOF signal\r
-  if (fTender->RunChanged()){\r
-    fTOFCalib->Init(fTender->GetRun());\r
-  }\r
-  fTOFCalib->CalibrateESD(event);\r
-\r
-  if(fIsMC) fTOFT0maker->TuneForMC(event);\r
-\r
-  //Calculate event time zero\r
-  fTOFT0maker->ComputeT0TOF(event);\r
-  fTOFT0maker->ApplyT0TOF(event);\r
-\r
-  event->SetT0(0.0);\r
-\r
-  //\r
-  // recalculate PID probabilities\r
-  //\r
-\r
-  Int_t ntracks=event->GetNumberOfTracks();\r
-  for(Int_t itrack = 0; itrack < ntracks; itrack++){\r
-    fESDpid->MakeTOFPID(event->GetTrack(itrack),0);\r
-  }\r
-\r
-}\r
-\r
-\r
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+
+///////////////////////////////////////////////////////////////////////////////
+//                                                                           //
+// TOF tender: reapply TOF pid on the fly                                    //
+//                                                                           //
+///////////////////////////////////////////////////////////////////////////////
+#include <AliLog.h>
+#include <AliESDEvent.h>
+#include <AliESDInputHandler.h>
+#include <AliAnalysisManager.h>
+#include <AliESDpid.h>
+#include <AliTender.h>
+
+#include <AliTOFcalib.h>
+#include <AliTOFT0maker.h>
+
+#include <AliCDBManager.h>
+#include <AliCDBEntry.h>
+#include <AliT0CalibSeasonTimeShift.h>
+
+#include "AliTOFTenderSupply.h"
+
+AliTOFTenderSupply::AliTOFTenderSupply() :
+  AliTenderSupply(),
+  fESDpid(0x0),
+  fIsMC(kFALSE),
+  fApplyT0(kFALSE),
+  fTimeZeroType(3),
+  fCorrectExpTimes(kTRUE),
+  fTOFCalib(0x0),
+  fTOFT0maker(0x0),
+  fTOFres(100.)
+
+
+{
+  //
+  // default ctor
+  //
+
+  fT0shift[0] = 0;
+  fT0shift[1] = 0;
+  fT0shift[2] = 0;
+  fT0shift[3] = 0;
+}
+
+//_____________________________________________________
+AliTOFTenderSupply::AliTOFTenderSupply(const char *name, const AliTender *tender) :
+  AliTenderSupply(name,tender),
+  fESDpid(0x0),
+  fIsMC(kFALSE),
+  fApplyT0(kFALSE),
+  fTimeZeroType(3),
+  fCorrectExpTimes(kTRUE),
+  fTOFCalib(0x0),
+  fTOFT0maker(0x0),
+  fTOFres(100.) 
+{
+  //
+  // named ctor
+  //
+
+  fT0shift[0] = 0;
+  fT0shift[1] = 0;
+  fT0shift[2] = 0;
+  fT0shift[3] = 0;
+}
+
+//_____________________________________________________
+void AliTOFTenderSupply::Init()
+{
+  //
+  // Initialise TOF tender
+  //
+
+
+  //
+  // Setup PID object
+  //
+
+  // Check if another detector already created the esd pid object
+  // if not we create it and set it to the ESD input handler
+  fESDpid=fTender->GetESDhandler()->GetESDpid();
+  if (!fESDpid) {
+    fESDpid=new AliESDpid;
+    fTender->GetESDhandler()->SetESDpid(fESDpid);
+  }
+
+  //Set proper resolution in case of MC
+  AliAnalysisManager *mgr=AliAnalysisManager::GetAnalysisManager();
+  if (mgr->GetMCtruthEventHandler()) fIsMC=kTRUE;
+
+
+  //
+  // Create TOF calibration classes
+  //
+  if (!fTOFCalib){
+      fTOFCalib=new AliTOFcalib();
+      fTOFCalib->SetCorrectTExp(fCorrectExpTimes); // apply a fine tuning on the expected times at low momenta
+      if(fIsMC) fTOFCalib->SetCalibrateTOFsignal(kFALSE); // no new calibration
+//      fTOFCalib->Init();
+  }
+  if (!fTOFT0maker) {
+      fTOFT0maker = new AliTOFT0maker(fESDpid,fTOFCalib);
+      fTOFT0maker->SetTimeResolution(fTOFres); // set TOF resolution for the PID
+      printf("tof time res = %f\n",fTOFres);
+  }
+}
+
+//_____________________________________________________
+void AliTOFTenderSupply::ProcessEvent()
+{
+  //
+  // Reapply pid information
+  //
+
+  //no corrections for MC
+  AliAnalysisManager *mgr=AliAnalysisManager::GetAnalysisManager();
+  if (mgr->GetMCtruthEventHandler()) return;
+
+  AliESDEvent *event=fTender->GetEvent();
+  if (!event) return;
+    
+  //recalculate TOF signal
+  if (fTender->RunChanged()){
+    fTOFCalib->Init(fTender->GetRun());
+    
+    if(event->GetT0TOF()){ // read T0 detector correction from OCDB
+      // OCDB instance
+      AliCDBManager* ocdbMan = AliCDBManager::Instance();
+      ocdbMan->SetRun(fTender->GetRun());    
+      AliCDBEntry *entry = ocdbMan->Get("T0/Calib/TimeAdjust/");
+      if(entry) {
+       AliT0CalibSeasonTimeShift *clb = (AliT0CalibSeasonTimeShift*) entry->GetObject();
+       Float_t *t0means= clb->GetT0Means();
+       //      Float_t *t0sigmas = clb->GetT0Sigmas();
+       fT0shift[0] = t0means[0];
+       fT0shift[1] = t0means[1];
+       fT0shift[2] = t0means[2];
+       fT0shift[3] = t0means[3];
+      }   
+    }
+  }
+  fTOFCalib->CalibrateESD(event);
+  
+  if(fIsMC){
+    Float_t t0true = fTOFT0maker->TuneForMC(event);
+    
+    if(event->GetT0TOF()){// add the t0 smearing also to the T0 detector information
+      event->SetT0TOF(0,event->GetT0TOF(0) + t0true);
+      event->SetT0TOF(1,event->GetT0TOF(1) + t0true);
+      event->SetT0TOF(2,event->GetT0TOF(2) + t0true);  
+    }
+  }
+  
+  if(event->GetT0TOF()){ // write the T0 detector corrected times
+    if(event->GetT0TOF(0) == 0) event->SetT0TOF(0, 9999999.);
+    if(event->GetT0TOF(1) == 0) event->SetT0TOF(1, 99999.);
+    if(event->GetT0TOF(2) == 0) event->SetT0TOF(2, 99999.);
+
+    event->SetT0TOF(0,event->GetT0TOF(0) - fT0shift[0]);
+    event->SetT0TOF(1,event->GetT0TOF(1) - fT0shift[1]);
+    event->SetT0TOF(2,event->GetT0TOF(2) - fT0shift[2]);      
+
+    if(event->GetT0TOF(0) > 9000000) event->SetT0TOF(0, 9999999.);
+    if(event->GetT0TOF(1) > 90000) event->SetT0TOF(1, 99999.);
+    if(event->GetT0TOF(2) > 90000) event->SetT0TOF(2, 99999.);
+  }
+  
+  //Calculate event time zero
+  fTOFT0maker->ComputeT0TOF(event);
+  fTOFT0maker->WriteInESD(event);
+
+  // subtract the T0-TOF information to the TOF times
+  if(fApplyT0){
+    fTOFT0maker->ApplyT0TOF(event);
+    event->SetT0(0.0);
+  }
+
+  //
+  // recalculate PID probabilities
+  //
+
+  fESDpid->SetTOFResponse(event, (AliESDpid::EStartTimeType_t)fTimeZeroType);
+  
+  Int_t ntracks=event->GetNumberOfTracks();
+  for(Int_t itrack = 0; itrack < ntracks; itrack++){
+    fESDpid->MakeTOFPID(event->GetTrack(itrack),0);
+  }
+  
+  
+}
+
+
+
index a512657..0fb1f17 100644 (file)
@@ -1,51 +1,61 @@
-#ifndef ALITOFTENDERSUPPLY_H\r
-#define ALITOFTENDERSUPPLY_H\r
-\r
-/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *\r
- * See cxx source for full Copyright notice                               */\r
-\r
-////////////////////////////////////////////////////////////////////////\r
-//                                                                    //\r
-//  TPC tender, reapply pid on the fly                                //\r
-//                                                                    //\r
-////////////////////////////////////////////////////////////////////////\r
-\r
-#include <AliTenderSupply.h>\r
-\r
-class AliESDpid;\r
-class AliTOFcalib;\r
-class AliTOFT0maker;\r
-\r
-class AliTOFTenderSupply: public AliTenderSupply {\r
-\r
-public:\r
-  AliTOFTenderSupply();\r
-  AliTOFTenderSupply(const char *name, const AliTender *tender=NULL);\r
-\r
-  virtual ~AliTOFTenderSupply(){;}\r
-\r
-  virtual void              Init();\r
-  virtual void              ProcessEvent();\r
-\r
-  // TOF method\r
-  void SetTOFres(Float_t res){fTOFres=res;}\r
-\r
-private:\r
-  AliESDpid          *fESDpid;         //! ESD pid object\r
-\r
-  Bool_t fIsMC;\r
-\r
-  // variables for TOF calibrations\r
-  AliTOFcalib     *fTOFCalib;    //! recalibrate TOF signal with OCDB\r
-  AliTOFT0maker   *fTOFT0maker;     //! TOF maker objects (apply all the correction for T0)\r
-\r
-  Float_t fTOFres;                   // TOF resolution\r
-\r
-  AliTOFTenderSupply(const AliTOFTenderSupply&c);\r
-  AliTOFTenderSupply& operator= (const AliTOFTenderSupply&c);\r
-\r
-  ClassDef(AliTOFTenderSupply, 1);\r
-};\r
-\r
-\r
-#endif \r
+#ifndef ALITOFTENDERSUPPLY_H
+#define ALITOFTENDERSUPPLY_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+////////////////////////////////////////////////////////////////////////
+//                                                                    //
+//  TPC tender, reapply pid on the fly                                //
+//                                                                    //
+////////////////////////////////////////////////////////////////////////
+
+#include <AliTenderSupply.h>
+#include "AliESDpid.h"
+
+class AliESDpid;
+class AliTOFcalib;
+class AliTOFT0maker;
+
+class AliTOFTenderSupply: public AliTenderSupply {
+
+public:
+  AliTOFTenderSupply();
+  AliTOFTenderSupply(const char *name, const AliTender *tender=NULL);
+
+  virtual ~AliTOFTenderSupply(){;}
+
+  virtual void              Init();
+  virtual void              ProcessEvent();
+
+  // TOF method
+  void SetTOFres(Float_t res){fTOFres=res;}
+  void SetApplyT0(Bool_t flag=kTRUE){fApplyT0=flag;};
+  void SetCorrectExpTimes(Bool_t flag=kTRUE){fCorrectExpTimes=flag;};
+  
+  virtual void SetTimeZeroType(AliESDpid::EStartTimeType_t tofTimeZeroType) {fTimeZeroType = tofTimeZeroType;}
+
+private:
+  AliESDpid          *fESDpid;         //! ESD pid object
+
+  Bool_t fIsMC;              // flag for MC data
+  Bool_t fApplyT0;           // flag to subtract the T0-TOF (deprecated)
+  Int_t  fTimeZeroType;      // flag to discriminate the time zero type 
+  Bool_t fCorrectExpTimes;   // flag to apply Expected Time correction 
+
+  // variables for TOF calibrations
+  AliTOFcalib     *fTOFCalib;    //! recalibrate TOF signal with OCDB
+  AliTOFT0maker   *fTOFT0maker;     //! TOF maker objects (apply all the correction for T0)
+
+  Float_t fTOFres;                   // TOF resolution
+  Float_t fT0shift[4];               // T0 detector correction from OCDB
+
+  AliTOFTenderSupply(const AliTOFTenderSupply&c);
+  AliTOFTenderSupply& operator= (const AliTOFTenderSupply&c);
+
+  ClassDef(AliTOFTenderSupply, 2);
+};
+
+
+#endif 
+
index cd38f0c..c838be2 100644 (file)
 ///////////////////////////////////////////////////////////////////////////////
 
 #include <TList.h>
+#include <TObjArray.h>
 #include <TObjString.h>
 #include <TChain.h>
+#include <TFile.h>
+#include <TString.h>
+#include <TPRegexp.h>
 
 #include <AliDCSSensor.h>
 #include <AliGRPObject.h>
 #include <AliCDBEntry.h>
 #include <AliCDBRunRange.h>
 #include <AliTender.h>
+#include <AliTPCcalibDButil.h>
+#include <AliPID.h>
 
 #include "AliTPCTenderSupply.h"
 
 
 AliTPCTenderSupply::AliTPCTenderSupply() :
-  AliTenderSupply(),
-  fESDpid(0x0),
-  fGainNew(0x0),
-  fGainOld(0x0),
-  fGainCorrection(kTRUE),
-  fPcorrection(kFALSE),
-  fDebugLevel(0),
-  fMip(50),
-  fGRP(0x0)
+AliTenderSupply(),
+fESDpid(0x0),
+fGainNew(0x0),
+fGainOld(0x0),
+fGainCorrection(kTRUE),
+fPcorrection(kFALSE),
+fArrPidResponseMaster(0x0),
+fDebugLevel(0),
+fMip(50),
+fGRP(0x0)
 {
   //
   // default ctor
@@ -60,15 +67,16 @@ AliTPCTenderSupply::AliTPCTenderSupply() :
 
 //_____________________________________________________
 AliTPCTenderSupply::AliTPCTenderSupply(const char *name, const AliTender *tender) :
-  AliTenderSupply(name,tender),
-  fESDpid(0x0),
-  fGainNew(0x0),
-  fGainOld(0x0),
-  fGainCorrection(kTRUE),
-  fPcorrection(kFALSE),
-  fDebugLevel(0),
-  fMip(50),
-  fGRP(0x0)
+AliTenderSupply(name,tender),
+fESDpid(0x0),
+fGainNew(0x0),
+fGainOld(0x0),
+fGainCorrection(kTRUE),
+fPcorrection(kFALSE),
+fArrPidResponseMaster(0x0),
+fDebugLevel(0),
+fMip(50),
+fGRP(0x0)
 {
   //
   // named ctor
@@ -82,6 +90,7 @@ void AliTPCTenderSupply::Init()
   // Initialise TPC tender
   //
 
+  AliLog::SetClassDebugLevel("AliTPCTenderSupply",10);
   AliAnalysisManager *mgr=AliAnalysisManager::GetAnalysisManager();
   //
   // Setup PID object
@@ -118,20 +127,20 @@ void AliTPCTenderSupply::Init()
     alephParameters[3] = 2.12543e+00;
     alephParameters[4] = 4.88663e+00;
     //temporary solution
-    fESDpid->GetTPCResponse().SetMip(fMip);
-    if (fDebugLevel>0) printf("AliTPCTenderSupply::Init - Use Data parametrisation, Mip set to: %.3f\n",fMip);
+    //fESDpid->GetTPCResponse().SetMip(fMip);
+    if (fDebugLevel>0) AliInfo(Form("Use Data parametrisation, Mip set to: %.3f\n",fMip));
     //fESDpid->GetTPCResponse().SetMip(49.2);
   } else {
     //force no gain and P correction in MC
     fGainCorrection=kFALSE;
     fPcorrection=kFALSE;
-    if (fDebugLevel>0) printf("AliTPCTenderSupply::Init - Use MC parametrisation\n");
+    if (fDebugLevel>0) AliInfo("Use MC parametrisation\n");
   }
   
   fESDpid->GetTPCResponse().SetBetheBlochParameters(
     alephParameters[0],alephParameters[1],alephParameters[2],
     alephParameters[3],alephParameters[4]);
-
+  
   //set detector resolution parametrisation
   fESDpid->GetTPCResponse().SetSigma(3.79301e-03, 2.21280e+04);
 }
@@ -142,20 +151,22 @@ void AliTPCTenderSupply::ProcessEvent()
   //
   // Reapply pid information
   //
-
+  
   AliESDEvent *event=fTender->GetEvent();
   if (!event) return;
   
   //load gain correction if run has changed
   if (fTender->RunChanged()){
-    if (fDebugLevel>0) printf("AliTPCTenderSupply::ProcessEvent - Run Changed (%d)\n",fTender->GetRun());
+    if (fDebugLevel>0) AliInfo(Form("Run Changed (%d)\n",fTender->GetRun()));
+    SetParametrisation();
     if (fGainCorrection) SetSplines();
   }
   
   //
   // get gain correction factor
   //
-  Double_t corrFactor = GetGainCorrection();
+  Double_t corrFactor = 1;
+  if (fGainCorrection) corrFactor=GetGainCorrection();
   
   //
   // - correct TPC signals
@@ -177,9 +188,9 @@ void AliTPCTenderSupply::SetSplines()
   //
   // Get Gain splines from OCDB
   //
-
+  
   AliInfo("Update Gain splines");
-
+  
   //
   // Get GPR info for pressure correction
   //
@@ -191,7 +202,7 @@ void AliTPCTenderSupply::SetSplines()
   } else {
     fGRP = (AliGRPObject*)entryGRP->GetObject();
   }
-  if (fDebugLevel>1) printf("AliTPCTenderSupply::SetSplines - Used GRP entry: %s\n",entryGRP->GetId().ToString().Data());
+  if (fDebugLevel>1) AliInfo(Form("GRP entry used: %s\n",entryGRP->GetId().ToString().Data()));
   
   fGainNew=0x0;
   fGainOld=0x0;
@@ -209,14 +220,14 @@ void AliTPCTenderSupply::SetSplines()
     AliError("No UserInfo found in tree");
     return;
   }
-
+  
   TList *cdbList=(TList*)userInfo->FindObject("cdbList");
   if (!cdbList) {
     AliError("No cdbList found in UserInfo");
     if (AliLog::GetGlobalLogLevel()>=AliLog::kError) userInfo->Print();
     return;
   }
-
+  
   TIter nextCDB(cdbList);
   TObjString *os=0x0;
   while ( (os=(TObjString*)nextCDB()) ){
@@ -229,7 +240,7 @@ void AliTPCTenderSupply::SetSplines()
       return;
     }
     
-    if (fDebugLevel>1) printf("AliTPCTenderSupply::SetSplines - Used old Gain entry: %s\n",entry->GetId().ToString().Data());
+    if (fDebugLevel>1) AliInfo(Form("Used old Gain entry: %s\n",entry->GetId().ToString().Data()));
     
     TObjArray *arr=(TObjArray *)entry->GetObject();
     if (!arr) {
@@ -247,7 +258,7 @@ void AliTPCTenderSupply::SetSplines()
     delete id;
     break;
   }
-
+  
   //
   //new gain correction
   //
@@ -256,10 +267,10 @@ void AliTPCTenderSupply::SetSplines()
     AliError("No new gain calibration entry found");
     return;
   }
-  if (fDebugLevel>1) printf("AliTPCTenderSupply::SetSplines - Used new Gain entry: %s\n",entryNew->GetId().ToString().Data());
+  if (fDebugLevel>1) AliInfo(Form("Used new Gain entry: %s\n",entryNew->GetId().ToString().Data()));
   
   if (entryNew->GetId().GetLastRun()==AliCDBRunRange::Infinity()){
-    if (fDebugLevel>0) printf("AliTPCTenderSupply::SetSplines - Use P correction\n");
+    if (fDebugLevel>0) AliInfo("Use P correction\n");
     fPcorrection=kTRUE;
   }
   
@@ -282,19 +293,209 @@ Double_t AliTPCTenderSupply::GetGainCorrection()
   //
   AliESDEvent *event=fTender->GetEvent();
   UInt_t time=event->GetTimeStamp();
+
+  Double_t gain=1;
   
-  Double_t gain = 1.;
-  if (!fGainOld) return gain;
-  if (fGainNew) gain = fGainOld->Eval(time)/fGainNew->Eval(time);
+  
+  if (fGainOld){
+    //TODO TODO TODO
+    //first correction for the eval
+    // needs to be removed when the fix is in AliROOT and
+    // the production was done with EvalGraphConst
+    //TODO TODO TODO
+    if (fTender->GetRun()<=138154||fTender->GetRun()==138197){
+      Double_t valDefault = fGainOld->Eval(time);
+      Double_t valConst   = AliTPCcalibDButil::EvalGraphConst(fGainOld, time);
+      gain = valDefault/valConst;
+    }
+    if (fGainNew){
+      gain *= AliTPCcalibDButil::EvalGraphConst(fGainOld,time)/AliTPCcalibDButil::EvalGraphConst(fGainNew,time);
+    }
+  }
   
   //If there is only the default calibration, at least apply correction for pressure
   if (fPcorrection){
     if (fGRP) {
       Double_t pressure=fGRP->GetCavernAtmosPressure()->GetValue(time);
-      gain=fGainOld->Eval(time)/(7.03814-0.00459798*pressure)/49.53*fMip;
+//       gain=fGainOld->Eval(time)/(7.03814-0.00459798*pressure)/49.53*fMip;
+//       gain=fGainOld->Eval(time)/(7.03814-0.00459798*pressure)/51.51*fMip;
+      gain=AliTPCcalibDButil::EvalGraphConst(fGainOld,time)/(7.03814-0.00459798*pressure)/51.51*fMip;
     }
   }
   
   return gain;
 }
 
+//_____________________________________________________
+void AliTPCTenderSupply::SetParametrisation()
+{
+  //
+  // Change BB parametrisation for current run
+  //
+
+  //Get CDB Entry with pid response parametrisations
+  AliCDBEntry *pidCDB=fTender->GetCDBManager()->Get("TPC/Calib/PidResponse",fTender->GetRun());
+  if (pidCDB){
+    fArrPidResponseMaster=(TObjArray*)pidCDB->GetObject();
+  }
+
+  //Get the current file to check the reconstruction pass (UGLY, but not stored in ESD... )
+  TFile *file=((TChain*)fTender->GetInputData(0))->GetCurrentFile();
+  if (!file) {
+    AliError("File not found, not changing parametrisation");
+    return;
+  }
+
+  Int_t run=fTender->GetRun();
+  AliAnalysisManager *mgr=AliAnalysisManager::GetAnalysisManager();
+  Double_t alephParameters[5]={0,0,0,0,0};
+
+  //find the period by run number (UGLY, but not stored in ESD... )
+  TString period;
+  if (run>=114737&&run<=117223) period="LHC10B";
+  else if (run>=118503&&run<=121040) period="LHC10C";
+  else if (run>=122195&&run<=126437) period="LHC10D";
+  else if (run>=127719&&run<=130850) period="LHC10E";
+  else if (run>=133004&&run<=135029) period="LHC10F";
+  else if (run>=135654&&run<=136377) period="LHC10G";
+  else if (run>=136851&&run<=139517) period="LHC10H";
+  else if (run>=139699) period="LHC11A";
+  
+  //find pass from file name (UGLY, but not stored in ESD... )
+  TString fileName(file->GetName());
+  Int_t pass=0;
+  if (fileName.Contains("/pass1")) {
+    pass=1;
+  } else if (fileName.Contains("/pass2")) {
+    pass=2;
+  }
+
+  //beam type
+  TString beamtype=fTender->GetEvent()->GetBeamType();
+  if (beamtype.IsNull()||beamtype.Contains("No Beam")) beamtype="p-p";
+  beamtype.ToUpper();
+  beamtype.ReplaceAll("-","");
+  
+  //
+  // Set default parametrisations for data and MC
+  //
+  Bool_t isMC=mgr->GetMCtruthEventHandler();
+  if (isMC){
+    //MC data
+    alephParameters[0] = 2.15898e+00/50.;
+    alephParameters[1] = 1.75295e+01;
+    alephParameters[2] = 3.40030e-09;
+    alephParameters[3] = 1.96178e+00;
+    alephParameters[4] = 3.91720e+00;
+    
+  } else {
+    //data parametrisation
+
+    
+    //use defaut data parametrisation in case no other will be selected
+    alephParameters[0] = 0.0283086/0.97;
+    alephParameters[1] = 2.63394e+01;
+    alephParameters[2] = 5.04114e-11;
+    alephParameters[3] = 2.12543e+00;
+    alephParameters[4] = 4.88663e+00;
+
+    fESDpid->GetTPCResponse().SetSigma(3.79301e-03, 2.21280e+04);
+    
+    if (pass==1){
+      
+    } else if (pass==2){
+      //find period
+      if (run>=114737&&run<=117223){
+        //LHC10b
+      } else if (run>=118503&&run<=121040) {
+        //LHC10c
+      } else if (run>=122195){
+        //LHC10d +
+        // last run in LHC10d: &&run<126437
+        alephParameters[0] = 1.63246/50.;
+        alephParameters[1] = 2.20028e+01;
+        alephParameters[2] = TMath::Exp(-2.48879e+01);
+        alephParameters[3] = 2.39804e+00;
+        alephParameters[4] = 5.12090e+00;
+      
+        //
+        fESDpid->GetTPCResponse().SetSigma(2.30176e-02, 5.60422e+02);
+      }
+    }
+    
+    if ( beamtype == "PBPB" ){
+      AliInfo("BETHE-BLOCH parametrization for PbPb !!!!!!!!!!!!!!!!!!!!!!\n");
+
+      alephParameters[0] = 1.25202/50.;   //was 1.79571/55.;
+      alephParameters[1] = 2.74992e+01;   //was 22.0028;
+      alephParameters[2] = TMath::Exp(-3.31517e+01);  //was1.55354e-11;
+      alephParameters[3] = 2.46246;       //was 2.39804; 
+      alephParameters[4] = 6.78938;       //was 5.1209;
+    }
+  }
+  
+  fESDpid->GetTPCResponse().SetBetheBlochParameters(
+    alephParameters[0],alephParameters[1],alephParameters[2],
+    alephParameters[3],alephParameters[4]);
+
+  //data type
+  TString datatype="DATA";
+  //in case of mc pass is per default 1
+  if (isMC) {
+    datatype="MC";
+    pass=1;
+  }
+
+  //
+  //set the new parametrisation
+  //
+
+  if (fArrPidResponseMaster){
+    TObject *grAll=0x0;
+    //for MC don't use period information
+    if (isMC) period="[A-Z0-9]*";
+    //pattern for the default entry (valid for all particles)
+    TPRegexp reg(Form("TSPLINE3_%s_([A-Z]*)_%s_PASS%d_%s_MEAN",datatype.Data(),period.Data(),pass,beamtype.Data()));
+    
+    //loop over entries and filter them
+    for (Int_t iresp=0; iresp<fArrPidResponseMaster->GetEntriesFast();++iresp){
+      TObject *responseFunction=fArrPidResponseMaster->At(iresp);
+      TString responseName=responseFunction->GetName();
+      
+      if (!reg.MatchB(responseName)) continue;
+      
+      TObjArray *arr=reg.MatchS(responseName);
+      TString particleName=arr->At(1)->GetName();
+      delete arr;
+      if (particleName.IsNull()) continue;
+      if (particleName=="ALL") grAll=responseFunction;
+      else {
+        //find particle id
+        for (Int_t ispec=0; ispec<AliPID::kSPECIES; ++ispec){
+          TString particle=AliPID::ParticleName(ispec);
+          particle.ToUpper();
+          if ( particle == particleName ){
+            //test if there is already a function set. If yes, cleanup
+            TObject *old=const_cast<TObject*>(fESDpid->GetTPCResponse().GetResponseFunction((AliPID::EParticleType)ispec));
+            if (old) delete old;
+            fESDpid->GetTPCResponse().SetResponseFunction((AliPID::EParticleType)ispec,responseFunction);
+            fESDpid->GetTPCResponse().SetUseDatabase(kTRUE);
+            AliInfo(Form("Adding graph: %d - %s\n",ispec,responseFunction->GetName()));
+            break;
+          }
+        }
+      }
+    }
+
+    //set default response function to all particles which don't have a specific one
+    if (grAll){
+      for (Int_t ispec=0; ispec<AliPID::kSPECIES; ++ispec){
+        if (!fESDpid->GetTPCResponse().GetResponseFunction((AliPID::EParticleType)ispec)){
+          fESDpid->GetTPCResponse().SetResponseFunction((AliPID::EParticleType)ispec,grAll);
+          AliInfo(Form("Adding graph: %d - %s\n",ispec,grAll->GetName()));
+        }
+      }
+    }
+  }
+}
+
index 7d60292..5f4f99c 100644 (file)
@@ -14,6 +14,7 @@
 
 #include <AliTenderSupply.h>
 
+class TObjArray;
 class AliESDpid;
 class AliSplineFit;
 class AliGRPObject;
@@ -29,6 +30,7 @@ public:
   void SetGainCorrection(Bool_t gainCorr) {fGainCorrection=gainCorr;}
   void SetDebugLevel(Int_t level)         {fDebugLevel=level;}
   void SetMip(Double_t mip)               {fMip=mip;}
+  void SetResponseFunctions(TObjArray *arr) {fArrPidResponseMaster=arr;}
   
   virtual void              Init();
   virtual void              ProcessEvent();
@@ -40,6 +42,7 @@ private:
 
   Bool_t fGainCorrection;            //Perform gain correction
   Bool_t fPcorrection;               //!Perform pressure correction
+  TObjArray *fArrPidResponseMaster;  //array with gain curves
 
   Int_t fDebugLevel;                 //debug level
   Double_t fMip;                     //mip position
@@ -49,6 +52,8 @@ private:
   void SetSplines();
   Double_t GetGainCorrection();
   
+  void SetParametrisation();
+  
   AliTPCTenderSupply(const AliTPCTenderSupply&c);
   AliTPCTenderSupply& operator= (const AliTPCTenderSupply&c);