LCOV - code coverage report
Current view: top level - TOF/TOFbase - AliTOFcalib.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 158 1410 11.2 %
Date: 2016-06-14 17:26:59 Functions: 20 76 26.3 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : /*
      17             : $Log: AliTOFcalib.cxx,v $
      18             : Revision 1.21  2007/11/02 15:41:49  hristov
      19             : Provide return value if the function is not void
      20             : 
      21             : Revision 1.20  2007/10/26 15:13:50  zampolli
      22             : Using a TChain instead of a TTree
      23             : 
      24             : Revision 1.19  2007/10/23 15:27:38  zampolli
      25             : Rearrangement of Calibration objects for simulation
      26             : 
      27             : Revision 1.16  2007/10/08 10:13:26  zampolli
      28             : First Run and Last Run members added, infinite validity of calib obj implemented.
      29             : 
      30             : Revision 1.15  2007/10/04 13:23:28  zampolli
      31             : Updates to handle functionalities in TOF online/offline calibration according to the latest schema
      32             : 
      33             : Revision 1.14  2007/06/06 16:26:30  arcelli
      34             : remove fall-back call to local CDB storage
      35             : 
      36             : Revision 1.13  2007/04/20 13:59:40  arcelli
      37             : make protections agains failed retrieval of the CDB object in a proper way
      38             : 
      39             : Revision 1.12  2007/03/23 11:31:16  arcelli
      40             : CDB Entry for TOF Reconstruction Parameters
      41             : 
      42             : Revision 1.11  2007/02/28 18:08:26  arcelli
      43             : Add protection against failed retrieval of the CDB cal object
      44             : 
      45             : Revision 1.10  2006/08/22 13:30:49  arcelli
      46             : removal of effective c++ warnings (C.Zampolli)
      47             : 
      48             : Revision 1.9  2006/04/20 22:30:50  hristov
      49             : Coding conventions (Annalisa)
      50             : 
      51             : Revision 1.8  2006/04/16 22:29:05  hristov
      52             : Coding conventions (Annalisa)
      53             : 
      54             : Revision 1.7  2006/04/16 20:12:46  hristov
      55             : Removing memory leak in case of cached CDB entries
      56             : 
      57             : Revision 1.6  2006/04/11 15:28:32  hristov
      58             : Checks on cache status before deleting calibration objects (A.Colla)
      59             : 
      60             : Revision 1.5  2006/04/05 08:35:38  hristov
      61             : Coding conventions (S.Arcelli, C.Zampolli)
      62             : 
      63             : Revision 1.4  2006/03/31 11:26:46  arcelli
      64             :  changing CDB Ids according to standard convention
      65             : 
      66             : Revision 1.3  2006/03/28 14:57:02  arcelli
      67             : updates to handle new V5 geometry & some re-arrangements
      68             : 
      69             : Revision 1.2  2006/02/13 17:22:26  arcelli
      70             : just Fixing Log info
      71             : 
      72             : Revision 1.1  2006/02/13 16:10:48  arcelli
      73             : Add classes for TOF Calibration (C.Zampolli)
      74             : 
      75             : author: Chiara Zampolli, zampolli@bo.infn.it
      76             : */  
      77             : 
      78             : ///////////////////////////////////////////////////////////////////////////////
      79             : //                                                                           //
      80             : // class for TOF calibration                                                 //
      81             : //                                                                           //
      82             : ///////////////////////////////////////////////////////////////////////////////
      83             : 
      84             : #include "TF1.h"
      85             : #include "TFile.h"
      86             : #include "TH1F.h"
      87             : #include "TH1C.h"
      88             : #include "TH2F.h"
      89             : //#include "TList.h"
      90             : //#include "TROOT.h"
      91             : //#include "TStyle.h"
      92             : #include "TTree.h"
      93             : #include "TChain.h"
      94             : #include "TProfile.h"
      95             : #include "TGrid.h"
      96             : #include "TMath.h"
      97             : #include "TMap.h"
      98             : 
      99             : #include "AliCDBEntry.h"
     100             : #include "AliCDBRunRange.h"
     101             : #include "AliCDBId.h"
     102             : #include "AliCDBManager.h"
     103             : #include "AliCDBStorage.h"
     104             : #include "AliCDBMetaData.h"
     105             : //#include "AliESDtrack.h"
     106             : //#include "AliESD.h"
     107             : #include "AliLog.h"
     108             : 
     109             : #include "AliTOFcalib.h"
     110             : #include "AliTOFChannelOnlineArray.h"
     111             : #include "AliTOFChannelOnline.h"
     112             : #include "AliTOFChannelOnlineStatus.h"
     113             : #include "AliTOFChannelOnlineStatusArray.h"
     114             : #include "AliTOFChannelOffline.h"
     115             : #include "AliTOFGeometry.h"
     116             : #include "AliTOFRecoParam.h"
     117             : #include "AliTOFDeltaBCOffset.h"
     118             : #include "AliTOFCTPLatency.h"
     119             : #include "AliTOFT0Fill.h"
     120             : #include "AliTOFRunParams.h"
     121             : #include "AliLHCClockPhase.h"
     122             : #include "AliTOFResponseParams.h"
     123             : #include "AliESDEvent.h"
     124             : #include "AliESDtrack.h"
     125             : #include "TRandom.h"
     126             : 
     127             : class TROOT;
     128             : class TStyle;
     129             : 
     130             : //extern TROOT *gROOT;
     131             : extern TStyle *gStyle;
     132             : 
     133          26 : ClassImp(AliTOFcalib)
     134             : 
     135             : //_______________________________________________________________________
     136             : AliTOFcalib::AliTOFcalib():
     137           6 :   TTask("AliTOFcalib",""),
     138           6 :   fNChannels(-1),
     139           6 :   fTOFCalOnline(0x0),
     140           6 :   fTOFCalOnlinePulser(0x0),
     141           6 :   fTOFCalOnlineNoise(0x0),
     142           6 :   fTOFCalOnlineHW(0x0),
     143           6 :   fTOFCalOffline(0x0),
     144           6 :   fCal(0x0),
     145           6 :   fStatus(0x0),
     146           6 :   fTOFSimToT(0x0),
     147           6 :   fkValidity(0x0),
     148           6 :   fTree(0x0),
     149           6 :   fChain(0x0),
     150           6 :   fNruns(0),
     151           6 :   fFirstRun(0),
     152           6 :   fLastRun(AliCDBRunRange::Infinity()),
     153          18 :   fConfigMap(new TMap),
     154           6 :   fDeltaBCOffset(NULL),
     155           6 :   fCTPLatency(NULL),
     156           6 :   fT0Fill(NULL),
     157           6 :   fRunParams(NULL),
     158           6 :   fLHCClockPhase(NULL),
     159           6 :   fResponseParams(NULL),
     160           6 :   fReadoutEfficiency(NULL),
     161           6 :   fProblematic(NULL),
     162           6 :   fInitFlag(kFALSE),
     163           6 :   fRemoveMeanT0(kTRUE),
     164           6 :   fUseLHCClockPhase(kFALSE),
     165           6 :   fCalibrateTOFsignal(kTRUE),
     166           6 :   fCorrectTExp(kFALSE),
     167           6 :   fRunParamsSpecificVersion(-1)
     168          30 : { 
     169             :   //TOF Calibration Class ctor
     170           6 :   fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
     171             : 
     172           6 :   gRandom->SetSeed(123456789);
     173          12 : }
     174             : //____________________________________________________________________________ 
     175             : 
     176             : AliTOFcalib::AliTOFcalib(const AliTOFcalib & calib):
     177           0 :   TTask(calib),
     178           0 :   fNChannels(calib.fNChannels),
     179           0 :   fTOFCalOnline(0x0),
     180           0 :   fTOFCalOnlinePulser(0x0),
     181           0 :   fTOFCalOnlineNoise(0x0),
     182           0 :   fTOFCalOnlineHW(0x0),
     183           0 :   fTOFCalOffline(0x0),
     184           0 :   fCal(calib.fCal),
     185           0 :   fStatus(calib.fStatus),
     186           0 :   fTOFSimToT(calib.fTOFSimToT),
     187           0 :   fkValidity(calib.fkValidity),
     188           0 :   fTree(calib.fTree),
     189           0 :   fChain(calib.fChain),
     190           0 :   fNruns(calib.fNruns),
     191           0 :   fFirstRun(calib.fFirstRun),
     192           0 :   fLastRun(calib.fLastRun),
     193           0 :   fConfigMap(calib.fConfigMap),
     194           0 :   fDeltaBCOffset(NULL),
     195           0 :   fCTPLatency(NULL),
     196           0 :   fT0Fill(NULL),
     197           0 :   fRunParams(NULL),
     198           0 :   fLHCClockPhase(NULL),
     199           0 :   fResponseParams(NULL),
     200           0 :   fReadoutEfficiency(NULL),
     201           0 :   fProblematic(NULL),
     202           0 :   fInitFlag(calib.fInitFlag),
     203           0 :   fRemoveMeanT0(calib.fRemoveMeanT0),
     204           0 :   fUseLHCClockPhase(calib.fUseLHCClockPhase),
     205           0 :   fCalibrateTOFsignal(calib.fCalibrateTOFsignal),
     206           0 :   fCorrectTExp(calib.fCorrectTExp),
     207           0 :   fRunParamsSpecificVersion(calib.fRunParamsSpecificVersion)
     208           0 : {
     209             : 
     210           0 :   fTOFCalOnline = new TObjArray(fNChannels);
     211           0 :   fTOFCalOnlinePulser = new TObjArray(fNChannels);
     212           0 :   fTOFCalOnlineNoise = new TObjArray(fNChannels);
     213           0 :   fTOFCalOnlineHW = new TObjArray(fNChannels);
     214           0 :   fTOFCalOffline = new TObjArray(fNChannels);
     215           0 :   fTOFCalOnline->SetOwner();
     216           0 :   fTOFCalOnlinePulser->SetOwner();
     217           0 :   fTOFCalOnlineNoise->SetOwner();
     218           0 :   fTOFCalOnlineHW->SetOwner();
     219           0 :   fTOFCalOffline->SetOwner();
     220             : 
     221             :   //TOF Calibration Class copy ctor
     222           0 :   for (Int_t iarray = 0; iarray<fNChannels; iarray++){
     223           0 :     AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
     224           0 :     AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray);
     225           0 :     AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray);
     226           0 :     AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray);
     227           0 :     AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
     228           0 :     fTOFCalOnline->AddAt(calChOnline,iarray);
     229           0 :     fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
     230           0 :     fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
     231           0 :     fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
     232           0 :     fTOFCalOffline->AddAt(calChOffline,iarray);
     233             :   }
     234             : 
     235           0 :   if (calib.fDeltaBCOffset) fDeltaBCOffset = new AliTOFDeltaBCOffset(*calib.fDeltaBCOffset);
     236           0 :   if (calib.fCTPLatency) fCTPLatency = new AliTOFCTPLatency(*calib.fCTPLatency);
     237           0 :   if (calib.fT0Fill) fT0Fill = new AliTOFT0Fill(*calib.fT0Fill);
     238           0 :   if (calib.fRunParams) fRunParams = new AliTOFRunParams(*calib.fRunParams);
     239           0 :   if (calib.fResponseParams) fResponseParams = new AliTOFResponseParams(*calib.fResponseParams);
     240           0 :   if (calib.fReadoutEfficiency) fReadoutEfficiency = new TH1F(*calib.fReadoutEfficiency);
     241           0 :   if (calib.fProblematic) fProblematic = new TH1C(*calib.fProblematic);
     242             : 
     243           0 :   gRandom->SetSeed(123456789);
     244           0 : }
     245             : 
     246             : //____________________________________________________________________________ 
     247             : 
     248             : AliTOFcalib& AliTOFcalib::operator=(const AliTOFcalib &calib)
     249             : {
     250             :   //TOF Calibration Class assignment operator
     251             : 
     252           0 :   if (this == &calib)
     253           0 :     return *this;
     254             :   
     255           0 :   TTask::operator=(calib);
     256           0 :   fNChannels = calib.fNChannels;
     257           0 :   fCal = calib.fCal;
     258           0 :   fStatus = calib.fStatus;
     259           0 :   fTOFSimToT = calib.fTOFSimToT;
     260           0 :   fkValidity = calib.fkValidity;
     261           0 :   fTree = calib.fTree;
     262           0 :   fChain = calib.fChain;
     263           0 :   fNruns = calib.fNruns;
     264           0 :   fFirstRun = calib.fFirstRun;
     265           0 :   fLastRun = calib.fLastRun;
     266           0 :   for (Int_t iarray = 0; iarray<fNChannels; iarray++){
     267           0 :     AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
     268           0 :     AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
     269           0 :     AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray);
     270           0 :     AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray);
     271           0 :     AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray);
     272           0 :     fTOFCalOnline->AddAt(calChOnline,iarray);
     273           0 :     fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
     274           0 :     fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
     275           0 :     fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
     276           0 :     fTOFCalOffline->AddAt(calChOffline,iarray);
     277             :   }
     278             : 
     279           0 :   if (calib.fDeltaBCOffset) {
     280           0 :     if (fDeltaBCOffset) *fDeltaBCOffset = *calib.fDeltaBCOffset;
     281           0 :     else fDeltaBCOffset = new AliTOFDeltaBCOffset(*calib.fDeltaBCOffset);
     282             :   }
     283             : 
     284           0 :   if (calib.fCTPLatency) {
     285           0 :     if (fCTPLatency) *fCTPLatency = *calib.fCTPLatency;
     286           0 :     else fCTPLatency = new AliTOFCTPLatency(*calib.fCTPLatency);
     287             :   }
     288             : 
     289           0 :   if (calib.fT0Fill) {
     290           0 :     if (fT0Fill) *fT0Fill = *calib.fT0Fill;
     291           0 :     else fT0Fill = new AliTOFT0Fill(*calib.fT0Fill);
     292             :   }
     293           0 :   if (calib.fRunParams) {
     294           0 :     if (fRunParams) *fRunParams = *calib.fRunParams;
     295           0 :     else fRunParams = new AliTOFRunParams(*calib.fRunParams);
     296             :   }
     297           0 :   if (calib.fResponseParams) {
     298           0 :     if (fResponseParams) *fResponseParams = *calib.fResponseParams;
     299           0 :     else fResponseParams = new AliTOFResponseParams(*calib.fResponseParams);
     300             :   }
     301           0 :   if (calib.fReadoutEfficiency) {
     302           0 :     if (fReadoutEfficiency) *fReadoutEfficiency = *calib.fReadoutEfficiency;
     303           0 :     else fReadoutEfficiency = new TH1F(*calib.fReadoutEfficiency);
     304             :   }
     305           0 :   if (calib.fProblematic) {
     306           0 :     if (fProblematic) *fProblematic = *calib.fProblematic;
     307           0 :     else fProblematic = new TH1C(*calib.fProblematic);
     308             :   }
     309           0 :   fInitFlag = calib.fInitFlag;
     310           0 :   fRemoveMeanT0 = calib.fRemoveMeanT0;
     311           0 :   fUseLHCClockPhase = calib.fUseLHCClockPhase;
     312           0 :   fCalibrateTOFsignal = calib.fCalibrateTOFsignal;
     313           0 :   fCorrectTExp = calib.fCorrectTExp;
     314           0 :   fRunParamsSpecificVersion = calib.fRunParamsSpecificVersion;
     315             : 
     316           0 :   return *this;
     317           0 : }
     318             : 
     319             : //____________________________________________________________________________ 
     320             : 
     321             : AliTOFcalib::~AliTOFcalib()
     322          24 : {
     323             :   //TOF Calibration Class dtor
     324           8 :   if(!(AliCDBManager::Instance()->GetCacheFlag())){ // CDB objects must NOT be deleted if cache is active!
     325           0 :     if (fTOFCalOnline){
     326           0 :       delete fTOFCalOnline;
     327             :     }
     328           0 :     if (fTOFCalOnlinePulser){
     329           0 :       delete fTOFCalOnlinePulser;
     330             :     }
     331           0 :     if (fTOFCalOnlineNoise){
     332           0 :       delete fTOFCalOnlineNoise;
     333             :     }
     334           0 :     if (fTOFCalOnlineHW){
     335           0 :       delete fTOFCalOnlineHW;
     336             :     }
     337           0 :     if (fTOFCalOffline){
     338           0 :       delete fTOFCalOffline;
     339             :     }
     340           0 :     if (fCal){
     341           0 :       delete fCal;
     342             :     }
     343           0 :     if (fStatus){
     344           0 :       delete fStatus;
     345             :     }
     346           0 :     if (fConfigMap){
     347           0 :       delete fConfigMap;
     348             :     }
     349           0 :     if (fDeltaBCOffset) delete fDeltaBCOffset;
     350           0 :     if (fCTPLatency) delete fCTPLatency;
     351           0 :     if (fT0Fill) delete fT0Fill;
     352           0 :     if (fRunParams) delete fRunParams;
     353           0 :     if (fResponseParams) delete fResponseParams;
     354           0 :     if (fReadoutEfficiency) delete fReadoutEfficiency;
     355           0 :     if (fProblematic) delete fProblematic;
     356             :   }
     357           4 :   if (fTree!=0x0) delete fTree;
     358           4 :   if (fChain!=0x0) delete fChain;
     359             : 
     360          12 : }
     361             : //_____________________________________________________________________________
     362             : void AliTOFcalib::CreateCalArrays(){
     363             : 
     364             :   // creating arrays for online/offline calibration objs
     365             : 
     366           0 :   fTOFCalOnline = new TObjArray(fNChannels);
     367           0 :   fTOFCalOnlinePulser = new TObjArray(fNChannels);
     368           0 :   fTOFCalOnlineNoise = new TObjArray(fNChannels);
     369           0 :   fTOFCalOnlineHW = new TObjArray(fNChannels);
     370           0 :   fTOFCalOffline = new TObjArray(fNChannels);
     371           0 :   fTOFCalOnline->SetOwner();
     372           0 :   fTOFCalOnlinePulser->SetOwner();
     373           0 :   fTOFCalOnlineNoise->SetOwner();
     374           0 :   fTOFCalOnlineHW->SetOwner();
     375           0 :   fTOFCalOffline->SetOwner();
     376           0 :   for (Int_t iarray = 0; iarray<fNChannels; iarray++){
     377           0 :     AliTOFChannelOnline * calChOnline = new AliTOFChannelOnline();
     378           0 :     AliTOFChannelOnlineStatus * calChOnlineStPulser = new AliTOFChannelOnlineStatus();
     379           0 :     AliTOFChannelOnlineStatus * calChOnlineStNoise = new AliTOFChannelOnlineStatus();
     380           0 :     AliTOFChannelOnlineStatus * calChOnlineStHW = new AliTOFChannelOnlineStatus();
     381           0 :     AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
     382           0 :     fTOFCalOnline->AddAt(calChOnline,iarray);
     383           0 :     fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
     384           0 :     fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
     385           0 :     fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
     386           0 :     fTOFCalOffline->AddAt(calChOffline,iarray);
     387             :   }
     388           0 :   fCal = new AliTOFChannelOnlineArray(fNChannels);
     389           0 :   fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
     390           0 : }
     391             : //_____________________________________________________________________________
     392             : void AliTOFcalib::CreateCalObjects(){
     393             : 
     394             :   // creating arrays for online/offline calibration objs
     395             : 
     396           0 :   fTOFCalOffline = new TObjArray(fNChannels);
     397           0 :   fTOFCalOffline->SetOwner();
     398           0 :   for (Int_t iarray = 0; iarray<fNChannels; iarray++){
     399           0 :     AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
     400           0 :     fTOFCalOffline->AddAt(calChOffline,iarray);
     401             :   }
     402           0 :   fCal = new AliTOFChannelOnlineArray(fNChannels);
     403           0 :   fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
     404           0 : }
     405             : //_____________________________________________________________________________
     406             : void AliTOFcalib::WriteConfigMapOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
     407             : {
     408             :   //Write calibration parameters to the CDB
     409           0 :   SetFirstRun(minrun);
     410           0 :   SetLastRun(maxrun);
     411           0 :   AliCDBManager *man = AliCDBManager::Instance();
     412             :   const Char_t *sel1 = "Config" ;  // to be consistent with TOFPreprocessor
     413           0 :   TString out(Form("%s/%s",sel,sel1));
     414           0 :   AliDebug(2,Form("Writing TOF configuration map for online calib on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
     415           0 :   AliCDBId id(out,fFirstRun,fLastRun);
     416           0 :   AliCDBMetaData *md = new AliCDBMetaData();
     417           0 :   md->SetResponsible("Chiara Zampolli");
     418           0 :   if (!fConfigMap) {
     419             :     // deve uscire!!
     420             :   }
     421           0 :   man->Put(fConfigMap,id,md);
     422           0 :   delete md;
     423           0 : }
     424             : //_____________________________________________________________________________
     425             : 
     426             : void AliTOFcalib::WriteConfigMapOnCDB(const Char_t *sel)
     427             : {
     428             :   //Write calibration parameters to the CDB with infinite validity
     429           0 :   AliCDBManager *man = AliCDBManager::Instance();
     430             :   const Char_t *sel1 = "Config" ;  // to be consistent with TOFPreprocessor
     431           0 :   TString out(Form("%s/%s",sel,sel1));
     432           0 :   AliCDBRunRange runrange(fFirstRun,fLastRun);
     433           0 :   AliDebug(2,Form("Writing TOF config map for online calib on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
     434           0 :   AliCDBId id(out,runrange);
     435           0 :   AliCDBMetaData *md = new AliCDBMetaData();
     436           0 :   md->SetResponsible("Chiara Zampolli");
     437           0 :   if (!fConfigMap) {
     438             :     // deve uscire!!
     439             :   }
     440           0 :   man->Put(fConfigMap,id,md);
     441           0 :   delete md;
     442           0 : }
     443             : //_____________________________________________________________________________
     444             : void AliTOFcalib::WriteParOnlineDelayOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
     445             : {
     446             :   //Write calibration parameters to the CDB -------> new calib objs!!!!!
     447           0 :   SetFirstRun(minrun);
     448           0 :   SetLastRun(maxrun);
     449           0 :   AliCDBManager *man = AliCDBManager::Instance();
     450             :   const Char_t *sel1 = "ParOnlineDelay" ;  // to be consistent with TOFPreprocessor
     451           0 :   TString out(Form("%s/%s",sel,sel1));
     452           0 :   AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
     453           0 :   AliCDBId id(out,fFirstRun,fLastRun);
     454           0 :   AliCDBMetaData *md = new AliCDBMetaData();
     455           0 :   md->SetResponsible("Chiara Zampolli");
     456           0 :   if (!fCal) {
     457             :     // deve uscire!!
     458             :   }
     459           0 :   man->Put(fCal,id,md);
     460           0 :   delete md;
     461           0 : }
     462             : //_____________________________________________________________________________
     463             : void AliTOFcalib::WriteParOnlineStatusOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
     464             : {
     465             :   //Write calibration parameters to the CDB -------> new calib objs!!!!!
     466           0 :   SetFirstRun(minrun);
     467           0 :   SetLastRun(maxrun);
     468           0 :   AliCDBManager *man = AliCDBManager::Instance();
     469             :   const Char_t *sel1 = "Status" ;  // to be consistent with TOFPreprocessor
     470           0 :   TString out(Form("%s/%s",sel,sel1));
     471           0 :   AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
     472           0 :   AliCDBId id(out,fFirstRun,fLastRun);
     473           0 :   AliCDBMetaData *md = new AliCDBMetaData();
     474           0 :   md->SetResponsible("Chiara Zampolli");
     475           0 :   if (!fStatus) {
     476             :     // deve uscire!!
     477             :   }
     478           0 :   man->Put(fStatus,id,md);
     479           0 :   delete md;
     480           0 : }
     481             : //_____________________________________________________________________________
     482             : 
     483             : void AliTOFcalib::WriteParOnlineDelayOnCDB(const Char_t *sel)
     484             : {
     485             :   //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
     486           0 :   AliCDBManager *man = AliCDBManager::Instance();
     487             :   const Char_t *sel1 = "ParOnlineDelay" ;  // to be consistent with TOFPreprocessor
     488           0 :   TString out(Form("%s/%s",sel,sel1));
     489           0 :   AliCDBRunRange runrange(fFirstRun,fLastRun);
     490           0 :   AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
     491           0 :   AliCDBId id(out,runrange);
     492           0 :   AliCDBMetaData *md = new AliCDBMetaData();
     493           0 :   md->SetResponsible("Chiara Zampolli");
     494           0 :   if (!fCal) {
     495             :     // deve uscire!!
     496             :   }
     497           0 :   man->Put(fCal,id,md);
     498           0 :   delete md;
     499           0 : }
     500             : //_____________________________________________________________________________
     501             : 
     502             : void AliTOFcalib::WriteParOnlineStatusOnCDB(const Char_t *sel)
     503             : {
     504             :   //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
     505           0 :   AliCDBManager *man = AliCDBManager::Instance();
     506             :   const Char_t *sel1 = "Status" ;  // to be consistent with TOFPreprocessor
     507           0 :   TString out(Form("%s/%s",sel,sel1));
     508           0 :   AliCDBRunRange runrange(fFirstRun,fLastRun);
     509           0 :   AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
     510           0 :   AliCDBId id(out,runrange);
     511           0 :   AliCDBMetaData *md = new AliCDBMetaData();
     512           0 :   md->SetResponsible("Chiara Zampolli");
     513           0 :   if (!fStatus) {
     514             :     // deve uscire!!
     515             :   }
     516           0 :   man->Put(fStatus,id,md);
     517           0 :   delete md;
     518           0 : }
     519             : //_____________________________________________________________________________
     520             : void AliTOFcalib::WriteParOnlineOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
     521             : {
     522             :   //Write calibration parameters to the CDB
     523           0 :   SetFirstRun(minrun);
     524           0 :   SetLastRun(maxrun);
     525           0 :   AliCDBManager *man = AliCDBManager::Instance();
     526             :   const Char_t *sel1 = "ParOnline" ;  // to be consistent with TOFPreprocessor
     527           0 :   TString out(Form("%s/%s",sel,sel1));
     528           0 :   AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
     529           0 :   AliCDBId id(out,fFirstRun,fLastRun);
     530           0 :   AliCDBMetaData *md = new AliCDBMetaData();
     531           0 :   md->SetResponsible("Chiara Zampolli");
     532           0 :   if (!fTOFCalOnline) {
     533             :     // deve uscire!!
     534             :   }
     535           0 :   man->Put(fTOFCalOnline,id,md);
     536           0 :   delete md;
     537           0 : }
     538             : //_____________________________________________________________________________
     539             : void AliTOFcalib::WriteParOnlinePulserOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
     540             : {
     541             :   //Write calibration parameters from pulser to the CDB
     542           0 :   SetFirstRun(minrun);
     543           0 :   SetLastRun(maxrun);
     544           0 :   AliCDBManager *man = AliCDBManager::Instance();
     545             :   const Char_t *sel1 = "Pulser" ;  // to be consistent with TOFPreprocessor
     546           0 :   TString out(Form("%s/%s",sel,sel1));
     547           0 :   AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
     548           0 :   AliCDBId id(out,fFirstRun,fLastRun);
     549           0 :   AliCDBMetaData *md = new AliCDBMetaData();
     550           0 :   md->SetResponsible("Chiara Zampolli");
     551           0 :   if (!fTOFCalOnlinePulser) {
     552             :     // deve uscire!!
     553             :   }
     554           0 :   man->Put(fTOFCalOnlinePulser,id,md);
     555           0 :   delete md;
     556           0 : }
     557             : //_____________________________________________________________________________
     558             : void AliTOFcalib::WriteParOnlineNoiseOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
     559             : {
     560             :   //Write calibration parameters from noise to the CDB
     561           0 :   SetFirstRun(minrun);
     562           0 :   SetLastRun(maxrun);
     563           0 :   AliCDBManager *man = AliCDBManager::Instance();
     564             :   const Char_t *sel1 = "Noise" ;  // to be consistent with TOFPreprocessor
     565           0 :   TString out(Form("%s/%s",sel,sel1));
     566           0 :   AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
     567           0 :   AliCDBId id(out,fFirstRun,fLastRun);
     568           0 :   AliCDBMetaData *md = new AliCDBMetaData();
     569           0 :   md->SetResponsible("Chiara Zampolli");
     570           0 :   if (!fTOFCalOnlineNoise) {
     571             :     // deve uscire!!
     572             :   }
     573           0 :   man->Put(fTOFCalOnlineNoise,id,md);
     574           0 :   delete md;
     575           0 : }
     576             : //_____________________________________________________________________________
     577             : void AliTOFcalib::WriteParOnlineHWOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
     578             : {
     579             :   //Write calibration parameters from hardware to the CDB
     580           0 :   SetFirstRun(minrun);
     581           0 :   SetLastRun(maxrun);
     582           0 :   AliCDBManager *man = AliCDBManager::Instance();
     583             :   const Char_t *sel1 = "HW" ;  // to be consistent with TOFPreprocessor
     584           0 :   TString out(Form("%s/%s",sel,sel1));
     585           0 :   AliDebug(2,Form("Writing TOF online calib obj from hardware on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
     586           0 :   AliCDBId id(out,fFirstRun,fLastRun);
     587           0 :   AliCDBMetaData *md = new AliCDBMetaData();
     588           0 :   md->SetResponsible("Chiara Zampolli");
     589           0 :   if (!fTOFCalOnlineHW) {
     590             :     // deve uscire!!
     591             :   }
     592           0 :   man->Put(fTOFCalOnlineHW,id,md);
     593           0 :   delete md;
     594           0 : }
     595             : //_____________________________________________________________________________
     596             : 
     597             : void AliTOFcalib::WriteParOnlineOnCDB(const Char_t *sel)
     598             : {
     599             :   //Write calibration parameters to the CDB with infinite validity
     600           0 :   AliCDBManager *man = AliCDBManager::Instance();
     601             :   const Char_t *sel1 = "ParOnline" ;  // to be consistent with TOFPreprocessor
     602           0 :   TString out(Form("%s/%s",sel,sel1));
     603           0 :   AliCDBRunRange runrange(fFirstRun,fLastRun);
     604           0 :   AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
     605           0 :   AliCDBId id(out,runrange);
     606           0 :   AliCDBMetaData *md = new AliCDBMetaData();
     607           0 :   md->SetResponsible("Chiara Zampolli");
     608           0 :   if (!fTOFCalOnline) {
     609             :     // deve uscire!!
     610             :   }
     611           0 :   man->Put(fTOFCalOnline,id,md);
     612           0 :   delete md;
     613           0 : }
     614             : //_____________________________________________________________________________
     615             : 
     616             : void AliTOFcalib::WriteParOnlinePulserOnCDB(const Char_t *sel)
     617             : {
     618             :   //Write calibration parameters from pulser to the CDB with infinite validity
     619           0 :   AliCDBManager *man = AliCDBManager::Instance();
     620             :   const Char_t *sel1 = "Pulser" ;  // to be consistent with TOFPreprocessor
     621           0 :   TString out(Form("%s/%s",sel,sel1));
     622           0 :   AliCDBRunRange runrange(fFirstRun,fLastRun);
     623           0 :   AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
     624           0 :   AliCDBId id(out,runrange);
     625           0 :   AliCDBMetaData *md = new AliCDBMetaData();
     626           0 :   md->SetResponsible("Chiara Zampolli");
     627           0 :   if (!fTOFCalOnlinePulser) {
     628             :     // deve uscire!!
     629             :   }
     630           0 :   man->Put(fTOFCalOnlinePulser,id,md);
     631           0 :   delete md;
     632           0 : }
     633             : //_____________________________________________________________________________
     634             : 
     635             : void AliTOFcalib::WriteParOnlineNoiseOnCDB(const Char_t *sel)
     636             : {
     637             :   //Write calibration parameters from noise to the CDB with infinite validity
     638           0 :   AliCDBManager *man = AliCDBManager::Instance();
     639             :   const Char_t *sel1 = "Noise" ;  // to be consistent with TOFPreprocessor
     640           0 :   TString out(Form("%s/%s",sel,sel1));
     641           0 :   AliCDBRunRange runrange(fFirstRun,fLastRun);
     642           0 :   AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
     643           0 :   AliCDBId id(out,runrange);
     644           0 :   AliCDBMetaData *md = new AliCDBMetaData();
     645           0 :   md->SetResponsible("Chiara Zampolli");
     646           0 :   if (!fTOFCalOnlineNoise) {
     647             :     // deve uscire!!
     648             :   }
     649           0 :   man->Put(fTOFCalOnlineNoise,id,md);
     650           0 :   delete md;
     651           0 : }
     652             : //_____________________________________________________________________________
     653             : 
     654             : void AliTOFcalib::WriteParOnlineHWOnCDB(const Char_t *sel)
     655             : {
     656             :   //Write calibration parameters from hardware to the CDB with infinite validity
     657           0 :   AliCDBManager *man = AliCDBManager::Instance();
     658             :   const Char_t *sel1 = "HW" ;  // to be consistent with TOFPreprocessor
     659           0 :   TString out(Form("%s/%s",sel,sel1));
     660           0 :   AliCDBRunRange runrange(fFirstRun,fLastRun);
     661           0 :   AliDebug(2,Form("Writing TOF online calib obj from harware on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
     662           0 :   AliCDBId id(out,runrange);
     663           0 :   AliCDBMetaData *md = new AliCDBMetaData();
     664           0 :   md->SetResponsible("Chiara Zampolli");
     665           0 :   if (!fTOFCalOnlineHW) {
     666             :     // deve uscire!!
     667             :   }
     668           0 :   man->Put(fTOFCalOnlineHW,id,md);
     669           0 :   delete md;
     670           0 : }
     671             : //_____________________________________________________________________________
     672             : 
     673             : void AliTOFcalib::WriteParOfflineOnCDB(const Char_t *sel, const Char_t *validity, Int_t minrun, Int_t maxrun)
     674             : {
     675             :   //Write calibration parameters to the CDB
     676           0 :   SetFirstRun(minrun);
     677           0 :   SetLastRun(maxrun);
     678           0 :   AliCDBManager *man = AliCDBManager::Instance();
     679             :   const Char_t *sel1 = "ParOffline" ;
     680           0 :   TString out(Form("%s/%s",sel,sel1));
     681           0 :   AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
     682           0 :   AliCDBId id(out,fFirstRun,fLastRun);
     683           0 :   AliCDBMetaData *md = new AliCDBMetaData();
     684           0 :   md->SetResponsible("Chiara Zampolli");
     685           0 :   md->SetComment(validity);
     686           0 :   man->Put(fTOFCalOffline,id,md);
     687           0 :   delete md;
     688           0 : }
     689             : //_____________________________________________________________________________
     690             : 
     691             : void AliTOFcalib::WriteParOfflineOnCDB(const Char_t *sel, const Char_t *validity)
     692             : {
     693             :   //Write calibration parameters to the CDB with infinite validity
     694           0 :   AliCDBManager *man = AliCDBManager::Instance();
     695             :   const Char_t *sel1 = "ParOffline" ;
     696           0 :   TString out(Form("%s/%s",sel,sel1));
     697           0 :   AliCDBRunRange runrange(fFirstRun,fLastRun);
     698           0 :   AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
     699           0 :   AliCDBId id(out,runrange);
     700           0 :   AliCDBMetaData *md = new AliCDBMetaData();
     701           0 :   md->SetResponsible("Chiara Zampolli");
     702           0 :   md->SetComment(validity);
     703           0 :   man->Put(fTOFCalOffline,id,md);
     704           0 :   delete md;
     705           0 : }
     706             : //_____________________________________________________________________________
     707             : 
     708             : Bool_t AliTOFcalib::ReadConfigMapFromCDB(const Char_t *sel, Int_t nrun)
     709             : {
     710             :   //Read calibration parameters from the CDB
     711           0 :   AliCDBManager *man = AliCDBManager::Instance();
     712             :   const Char_t *sel1 = "Config" ;
     713           0 :   TString out(Form("%s/%s",sel,sel1));
     714           0 :   AliCDBEntry *entry = man->Get(out,nrun);
     715           0 :   if (!entry) { 
     716           0 :     AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
     717           0 :     exit(0);  
     718             :   }
     719           0 :   if(!entry->GetObject()){
     720           0 :     AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
     721           0 :     exit(0);  
     722             :   }  
     723             :   
     724           0 :   fConfigMap =(TMap*)entry->GetObject();
     725             : 
     726             :   return kTRUE; 
     727             :    
     728           0 : }
     729             : //_____________________________________________________________________________
     730             : 
     731             : Bool_t AliTOFcalib::ReadParOnlineDelayFromCDB(const Char_t *sel, Int_t nrun)
     732             : {
     733             :   //Read calibration parameters from the CDB -------> new calib objs!!!!!
     734           0 :   AliCDBManager *man = AliCDBManager::Instance();
     735             :   const Char_t *sel1 = "ParOnlineDelay" ;
     736           0 :   TString out(Form("%s/%s",sel,sel1));
     737           0 :   AliCDBEntry *entry = man->Get(out,nrun);
     738           0 :   if (!entry) { 
     739           0 :     AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
     740           0 :     exit(0);  
     741             :   }
     742           0 :   if(!entry->GetObject()){
     743           0 :     AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
     744           0 :     exit(0);  
     745             :   }  
     746             :   
     747           0 :   fCal =(AliTOFChannelOnlineArray*)entry->GetObject();
     748             : 
     749             :   return kTRUE; 
     750             :    
     751           0 : }
     752             : //_____________________________________________________________________________
     753             : 
     754             : Bool_t AliTOFcalib::ReadParOnlineStatusFromCDB(const Char_t *sel, Int_t nrun)
     755             : {
     756             :   //Read calibration parameters from the CDB -------> new calib objs!!!!!
     757           8 :   AliCDBManager *man = AliCDBManager::Instance();
     758             :   const Char_t *sel1 = "Status" ;
     759           4 :   TString out(Form("%s/%s",sel,sel1));
     760          12 :   AliCDBEntry *entry = man->Get(out,nrun);
     761           4 :   if (!entry) { 
     762           0 :     AliFatal("Exiting, no CDB object (Status) found!!!");
     763           0 :     exit(0);  
     764             :   }
     765           4 :   if(!entry->GetObject()){
     766           0 :     AliFatal("Exiting, no CDB object (Status) found!!!");
     767           0 :     exit(0);  
     768             :   }  
     769             :   
     770           4 :   fStatus =(AliTOFChannelOnlineStatusArray*)entry->GetObject();
     771             : 
     772             :   return kTRUE; 
     773             :    
     774           4 : }
     775             : //_____________________________________________________________________________
     776             : 
     777             : Bool_t AliTOFcalib::ReadParOnlineFromCDB(const Char_t *sel, Int_t nrun)
     778             : {
     779             :   //Read calibration parameters from the CDB
     780           0 :   AliCDBManager *man = AliCDBManager::Instance();
     781             :   const Char_t *sel1 = "ParOnline" ;
     782           0 :   TString out(Form("%s/%s",sel,sel1));
     783           0 :   AliCDBEntry *entry = man->Get(out,nrun);
     784           0 :   if (!entry) { 
     785           0 :     AliFatal("Exiting, no CDB object (ParOnline) found!!!");
     786           0 :     exit(0);  
     787             :   }
     788           0 :   if(!entry->GetObject()){
     789           0 :     AliFatal("Exiting, no CDB object (ParOnline) found!!!");
     790           0 :     exit(0);  
     791             :   }  
     792             :   
     793           0 :   fTOFCalOnline =(TObjArray*)entry->GetObject();
     794             : 
     795             :   return kTRUE; 
     796             :    
     797           0 : }
     798             : //_____________________________________________________________________________
     799             : 
     800             : Bool_t AliTOFcalib::ReadParOnlinePulserFromCDB(const Char_t *sel, Int_t nrun)
     801             : {
     802             :   //Read calibration parameters from pulser from the CDB
     803           0 :   AliCDBManager *man = AliCDBManager::Instance();
     804             :   const Char_t *sel1 = "Pulser" ;
     805           0 :   TString out(Form("%s/%s",sel,sel1));
     806           0 :   AliCDBEntry *entry = man->Get(out,nrun);
     807           0 :   if (!entry) { 
     808           0 :     AliFatal("Exiting, no CDB object (Pulser) found!!!");
     809           0 :     exit(0);  
     810             :   }
     811           0 :   if(!entry->GetObject()){
     812           0 :     AliFatal("Exiting, no CDB object (Pulser) found!!!");
     813           0 :     exit(0);  
     814             :   }  
     815             :   
     816           0 :   fTOFCalOnlinePulser =(TObjArray*)entry->GetObject();
     817             : 
     818             :   return kTRUE; 
     819             :    
     820           0 : }
     821             : //_____________________________________________________________________________
     822             : 
     823             : Bool_t AliTOFcalib::ReadParOnlineNoiseFromCDB(const Char_t *sel, Int_t nrun)
     824             : {
     825             :   //Read calibration parameters from noise from the CDB
     826           0 :   AliCDBManager *man = AliCDBManager::Instance();
     827             :   const Char_t *sel1 = "Noise" ;
     828           0 :   TString out(Form("%s/%s",sel,sel1));
     829           0 :   AliCDBEntry *entry = man->Get(out,nrun);
     830           0 :   if (!entry) { 
     831           0 :     AliFatal("Exiting, no CDB object (Noise) found!!!");
     832           0 :     exit(0);  
     833             :   }
     834           0 :   if(!entry->GetObject()){
     835           0 :     AliFatal("Exiting, no CDB object (Noise) found!!!");
     836           0 :     exit(0);  
     837             :   }  
     838             :   
     839           0 :   fTOFCalOnlineNoise =(TObjArray*)entry->GetObject();
     840             : 
     841             :   return kTRUE; 
     842             :    
     843           0 : }
     844             : //_____________________________________________________________________________
     845             : 
     846             : Bool_t AliTOFcalib::ReadParOnlineHWFromCDB(const Char_t *sel, Int_t nrun)
     847             : {
     848             :   //Read calibration parameters from hardware from the CDB
     849           0 :   AliCDBManager *man = AliCDBManager::Instance();
     850             :   const Char_t *sel1 = "HW" ;
     851           0 :   TString out(Form("%s/%s",sel,sel1));
     852           0 :   AliCDBEntry *entry = man->Get(out,nrun);
     853           0 :   if (!entry) { 
     854           0 :     AliFatal("Exiting, no CDB object (HW map) found!!!");
     855           0 :     exit(0);  
     856             :   }
     857           0 :   if(!entry->GetObject()){
     858           0 :     AliFatal("Exiting, no CDB object (HW map) found!!!");
     859           0 :     exit(0);  
     860             :   }  
     861             :   
     862           0 :   fTOFCalOnlineHW =(TObjArray*)entry->GetObject();
     863             : 
     864             :   return kTRUE; 
     865             :    
     866           0 : }
     867             : //_____________________________________________________________________________
     868             : 
     869             : Bool_t AliTOFcalib::ReadParOfflineFromCDB(const Char_t *sel, Int_t nrun)
     870             : {
     871             :   //Read calibration parameters from the CDB
     872           8 :   AliCDBManager *man = AliCDBManager::Instance();
     873             :   const Char_t *sel1 = "ParOffline" ;
     874           4 :   TString out(Form("%s/%s",sel,sel1));
     875          12 :   AliCDBEntry *entry = man->Get(out,nrun);
     876           4 :   if (!entry) { 
     877           0 :     AliFatal("Exiting, no CDB object (ParOffline) found!!!");
     878           0 :     exit(0);  
     879             :   }
     880           4 :   if(!entry->GetObject()){
     881           0 :     AliFatal("Exiting, no CDB object (ParOffline) found!!!");
     882           0 :     exit(0);  
     883             :   }  
     884           4 :   AliCDBMetaData * md = entry->GetMetaData();
     885           8 :   fkValidity = md->GetComment();  
     886           4 :   fTOFCalOffline =(TObjArray*)entry->GetObject();
     887             : 
     888             :   return kTRUE; 
     889             :    
     890           4 : }
     891             : //_____________________________________________________________________________
     892             : void AliTOFcalib::WriteSimHistoOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, TH1F *histo){
     893             :   //Write Sim miscalibration parameters to the CDB
     894             : 
     895           0 :   fTOFSimToT=histo;
     896           0 :   AliCDBManager *man = AliCDBManager::Instance();
     897             :   const Char_t *sel1 = "SimHisto" ;
     898           0 :   TString out(Form("%s/%s",sel,sel1));
     899           0 :   AliCDBMetaData *mdhisto = new AliCDBMetaData();
     900           0 :   mdhisto->SetResponsible("Chiara Zampolli");
     901           0 :   AliCDBId id(out,minrun,maxrun);
     902           0 :   man->Put(fTOFSimToT,id,mdhisto);
     903           0 :   delete mdhisto;
     904           0 : }
     905             : //_____________________________________________________________________________
     906             : Bool_t AliTOFcalib::ReadSimHistoFromCDB(const Char_t *sel, Int_t nrun)
     907             : {
     908             :   //Read miscalibration parameters from the CDB
     909           0 :   AliCDBManager *man = AliCDBManager::Instance();
     910             : 
     911             :   // The Tot Histo
     912             : 
     913             :   const Char_t *sel1 = "SimHisto" ;
     914           0 :   TString out(Form("%s/%s",sel,sel1));
     915           0 :   AliCDBEntry *entry = man->Get(out,nrun);
     916           0 :   if (!entry) { 
     917           0 :     AliFatal("Exiting, no CDB object (SimHisto) found!!!");
     918           0 :     exit(0);  
     919             :   }
     920           0 :   if(!entry->GetObject()){
     921           0 :     AliFatal("Exiting, no CDB object (SimHisto) found!!!");
     922           0 :     exit(0);  
     923             :   }  
     924           0 :   TH1F *histo =(TH1F*)entry->GetObject();
     925           0 :   fTOFSimToT=histo;
     926             :   return kTRUE;
     927           0 : }
     928             : //_____________________________________________________________________________
     929             : void AliTOFcalib::WriteRecParOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFRecoParam *param){
     930             :   //Write reconstruction parameters to the CDB
     931             : 
     932           0 :   AliCDBManager *man = AliCDBManager::Instance();
     933           0 :   AliCDBMetaData *md = new AliCDBMetaData();
     934           0 :   md->SetResponsible("Silvia Arcelli");
     935             :   const Char_t *sel1 = "RecoParam" ;
     936           0 :   TString out(Form("%s/%s",sel,sel1));
     937           0 :   AliCDBId id(out,minrun,maxrun);
     938             : 
     939           0 :   TObjArray *arr=new TObjArray(1);
     940           0 :   arr->AddLast(param);
     941           0 :   man->Put(arr,id,md);
     942             :   //man->Put(param,id,md);
     943           0 :   delete md;
     944           0 : }
     945             : //_____________________________________________________________________________
     946             : void AliTOFcalib::WriteRecParOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, TObjArray *arr){
     947             :   //Write reconstruction parameters to the CDB
     948             : 
     949           0 :   AliCDBManager *man = AliCDBManager::Instance();
     950           0 :   AliCDBMetaData *md = new AliCDBMetaData();
     951           0 :   md->SetResponsible("Silvia Arcelli");
     952             :   const Char_t *sel1 = "RecoParam" ;
     953           0 :   TString out(Form("%s/%s",sel,sel1));
     954           0 :   AliCDBId id(out,minrun,maxrun);
     955           0 :   man->Put(arr,id,md);
     956           0 :   delete md;
     957           0 : }
     958             : //_____________________________________________________________________________
     959             : AliTOFRecoParam * AliTOFcalib::ReadRecParFromCDB(const Char_t *sel, Int_t nrun, Int_t eventType)
     960             : {
     961             :   //Read reconstruction parameters from the CDB
     962           2 :   AliCDBManager *man = AliCDBManager::Instance();
     963             :   const Char_t *sel1 = "RecoParam" ;
     964           1 :   TString out(Form("%s/%s",sel,sel1));
     965           3 :   AliCDBEntry *entry = man->Get(out,nrun);
     966           1 :   if (!entry) { 
     967           0 :     AliFatal("Exiting, no CDB object (RecoParam) found!!!");
     968           0 :     exit(0);  
     969             :   }  
     970           1 :   if(!entry->GetObject()){
     971           0 :     AliFatal("Exiting, no CDB object (RecoParam) found!!!");
     972           0 :     exit(0);  
     973             :   }  
     974             : 
     975           1 :   TObjArray *array = (TObjArray*)entry->GetObject();
     976             :   AliTOFRecoParam *param=0x0;
     977           1 :   if (eventType>=0 || eventType<array->GetEntries())
     978           2 :     param=(AliTOFRecoParam*)array->At(eventType);
     979             :   return param;
     980             : 
     981           1 : }
     982             : //-----------------------------------------------------------------------------
     983             : // Calibration methods
     984             : //-----------------------------------------------------------------------------
     985             : void AliTOFcalib::CreateTreeFromCDB(Int_t minrun, Int_t maxrun){
     986             : 
     987             :   // creating the chain with the trees for calibration
     988             :   // collecting them from reference data 
     989             :   // from minrun to maxrun
     990             : 
     991           0 :   Float_t p[CHENTRIESSMALL];
     992           0 :   Int_t nentries;
     993           0 :   fTree = new TTree("TOFCalib","Tree for TOF Calibration");
     994           0 :   fTree->Branch("nentries",&nentries,"nentries/I");
     995           0 :   fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
     996           0 :   AliCDBManager *man = AliCDBManager::Instance();
     997           0 :   AliCDBStorage *aStorage = man->GetStorage("local://$ALICE_ROOT/OCDB");
     998           0 :   for (Int_t irun = minrun;irun<=maxrun;irun++){
     999           0 :     AliCDBEntry *entry = aStorage->Get("TOF/RefData/TreeForCalib",irun);
    1000           0 :     if (!entry){
    1001           0 :       AliInfo(Form("No entry found for run %i",irun));
    1002           0 :     }
    1003             :     else{
    1004           0 :       TTree *tree = (TTree*)entry->GetObject();
    1005           0 :       tree->SetBranchAddress("nentries",&nentries);
    1006           0 :       tree->SetBranchAddress("TOFentries",p);      
    1007           0 :       fTree->CopyEntries(tree);
    1008           0 :       fNruns++;
    1009             :     }
    1010             :   }
    1011           0 :   AliInfo(Form("Number of runs being analyzed %i",fNruns));
    1012           0 : }
    1013             : //-----------------------------------------------------------------------------
    1014             : void AliTOFcalib::CreateTreeFromGrid(Int_t minrun, Int_t maxrun){
    1015             : 
    1016             :   // creating the chain with the trees for calibration
    1017             :   // collecting them from the Grid 
    1018             :   // from minrun to maxrun
    1019             : 
    1020           0 :   Float_t p[CHENTRIESSMALL];
    1021           0 :   Int_t nentries;
    1022           0 :   fTree = new TTree("TOFCalib","Tree for TOF Calibration");
    1023           0 :   fTree->SetDirectory(0);
    1024           0 :   fTree->Branch("nentries",&nentries,"nentries/I");
    1025           0 :   fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
    1026           0 :   AliInfo("connected to alien");
    1027           0 :   TGrid::Connect("alien://");
    1028             :   
    1029           0 :   TString filename;
    1030           0 :   for (Int_t irun = minrun;irun<=maxrun;irun++){
    1031           0 :     filename = Form("alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
    1032           0 :     TFile *filegrid = TFile::Open(filename.Data(),"READ");
    1033           0 :     TTree *tree = (TTree*)filegrid->Get("T");
    1034           0 :     tree->SetBranchAddress("nentries",&nentries);
    1035           0 :     tree->SetBranchAddress("TOFentries",p);      
    1036           0 :     fTree->CopyEntries(tree);
    1037           0 :     delete tree;
    1038           0 :     fNruns++;    
    1039             :   }
    1040             :   
    1041           0 :   AliInfo(Form("Number of runs being analyzed %i",fNruns));
    1042           0 : }
    1043             : //-----------------------------------------------------------------------------
    1044             : void AliTOFcalib::CreateTreeFromFile(Int_t minrun, Int_t maxrun){
    1045             : 
    1046             :   // creating the tree with the trees for calibration
    1047             :   // collecting them from reference data (from file)
    1048             :   // from minrun to maxrun
    1049             : 
    1050           0 :   Float_t p[CHENTRIESSMALL];
    1051           0 :   Int_t nentries;
    1052           0 :   fTree = new TTree("TOFCalib","Tree for TOF Calibration");
    1053           0 :   fTree->SetDirectory(0);
    1054           0 :   fTree->Branch("nentries",&nentries,"nentries/I");
    1055           0 :   fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
    1056           0 :   TString filename;
    1057           0 :   for (Int_t irun = minrun;irun<=maxrun;irun++){
    1058           0 :     filename = Form("$ALICE_ROOT/TOF/RefData/TreeForCalib/fileout_%i.root",irun);
    1059           0 :     TFile *file = new TFile(filename.Data(),"READ");
    1060           0 :     TTree *tree = (TTree*)file->Get("T");
    1061           0 :     tree->SetBranchAddress("nentries",&nentries);
    1062           0 :     tree->SetBranchAddress("TOFentries",p);      
    1063           0 :     fTree->CopyEntries(tree);
    1064           0 :     delete tree;
    1065           0 :     delete file;
    1066             :     file = 0x0;
    1067           0 :     fNruns++;
    1068             :   }
    1069             : 
    1070           0 :   AliInfo(Form("Number of runs being analyzed %i",fNruns));
    1071           0 : }
    1072             : //-----------------------------------------------------------------------------
    1073             : void AliTOFcalib::CreateChainFromGrid(Int_t minrun, Int_t maxrun){
    1074             : 
    1075             :   // creating the chain with the trees for calibration
    1076             :   // collecting them from the Grid 
    1077             :   // from minrun to maxrun
    1078             : 
    1079           0 :   fChain = new TChain("T");
    1080           0 :   AliInfo("connected to alien");
    1081           0 :   TGrid::Connect("alien://");
    1082             :   
    1083           0 :   TString filename;
    1084           0 :   for (Int_t irun = minrun;irun<=maxrun;irun++){
    1085           0 :     filename = Form("alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
    1086           0 :     fChain->Add(filename.Data());
    1087           0 :     fNruns++;    
    1088             :   }
    1089             :   
    1090           0 :   AliInfo(Form("Number of runs being analyzed %i",fNruns));
    1091           0 : }
    1092             : //-----------------------------------------------------------------------------
    1093             : Int_t AliTOFcalib::Calibrate(Int_t ichmin, Int_t ichmax, Option_t *optionSave, Option_t *optionFit){
    1094             : 
    1095             :   // calibrating summing more than one channels
    1096             :   // computing calibration parameters
    1097             :   // Returning codes:
    1098             :   // 0 -> everything was ok
    1099             :   // 1 -> no tree for calibration found
    1100             :   // 2 -> not enough statistics to perform calibration
    1101             :   // 3 -> problems with arrays
    1102             :   
    1103           0 :   TH1::AddDirectory(0);
    1104             : 
    1105           0 :   AliInfo(Form("*** Calibrating Histograms %s, summing more channels, from channel %i, to channel %i, storing Calib Pars in channel %i", GetName(),ichmin,ichmax,ichmin)) ; 
    1106           0 :   AliInfo(Form("Option for Saving histos = %s",optionSave )) ; 
    1107           0 :   AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ; 
    1108             : 
    1109           0 :   Float_t p[CHENTRIESSMALL];
    1110           0 :   Int_t nentries;
    1111             :   //fTree->SetBranchAddress("nentries",&nentries);
    1112             :   //fTree->SetBranchAddress("TOFentries",p);
    1113           0 :   fChain->SetBranchAddress("nentries",&nentries);
    1114           0 :   fChain->SetBranchAddress("TOFentries",p);
    1115             : 
    1116             :   Float_t ntracksTotalmean =0;
    1117           0 :   for (Int_t i=ichmin; i<ichmax; i++){
    1118             :     Int_t ientry = -1;
    1119           0 :     for (Int_t irun=0;irun<fNruns;irun++){
    1120           0 :       ientry = i+irun*fNChannels;
    1121             :       //fTree->GetEntry(ientry);
    1122           0 :       fChain->GetEntry(ientry);
    1123           0 :       Int_t ntracksRun=nentries/3;
    1124           0 :       ntracksTotalmean+=ntracksRun;
    1125             :     }
    1126             :   }
    1127             :   
    1128           0 :   if (ntracksTotalmean < MEANENTRIES) {
    1129           0 :     AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
    1130           0 :     return 2;
    1131             :   }
    1132             : 
    1133             :   //filling ToT and Time arrays
    1134             : 
    1135             :   Int_t nbinToT = 100;  // ToT bin width in Profile = 48.8 ps 
    1136             :   Float_t minToT = 0;   // ns
    1137             :   Float_t maxToT = 4.88;  // ns
    1138             : 
    1139           0 :   TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
    1140           0 :   TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
    1141             :   Int_t ntracksTotal = 0;
    1142             :   Int_t ntracksRun = 0;
    1143           0 :   Double_t binsProfile[101]; // sized larger than necessary, the correct 
    1144             :                              // dim being set in the booking of the profile
    1145             :   Int_t nusefulbins=0;
    1146             :   Float_t meantime=0;
    1147           0 :   for (Int_t i = ichmin;i<ichmax;i++){
    1148             :     Int_t ientry = -1;
    1149           0 :     for (Int_t irun=0;irun<fNruns;irun++){
    1150           0 :       ientry = i+irun*fNChannels;
    1151             :       //fTree->GetEntry(ientry);
    1152           0 :       fChain->GetEntry(ientry);
    1153           0 :       ntracksTotal+=nentries/3;
    1154             :       ntracksRun=nentries/3;
    1155           0 :       AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracks = %i",irun,i,nentries, ntracksRun));
    1156           0 :       for (Int_t j=0;j<ntracksRun;j++){
    1157           0 :         Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT; 
    1158           0 :         Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME; 
    1159           0 :         Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID; 
    1160           0 :         Float_t tot = p[idxexToT];
    1161           0 :         hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
    1162           0 :         meantime+=p[idxexTime]-p[idxexExTime];
    1163           0 :         hToT->Fill(tot);
    1164             :       }
    1165             :     }
    1166             :   }
    1167           0 :   nusefulbins = FindBins(hToT,&binsProfile[0]);
    1168           0 :   if (ntracksTotal != 0){
    1169           0 :           meantime/=ntracksTotal;
    1170           0 :   }
    1171           0 :   AliDebug(2, Form("meantime = %f",meantime));
    1172             :   
    1173           0 :   for (Int_t j=1;j<=nusefulbins;j++) {
    1174           0 :     AliDebug(2,Form(" summing channels from %i to %i, nusefulbins = %i, bin %i = %f",ichmin,ichmax,nusefulbins,j,binsProfile[j])); 
    1175             :   }
    1176             : 
    1177           0 :   TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G");  // CHECK THE BUILD OPTION, PLEASE!!!!!!
    1178           0 :   TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
    1179             : 
    1180           0 :   for (Int_t irun=0;irun<fNruns;irun++){
    1181             :     Int_t ientry = -1;
    1182           0 :     for (Int_t i=ichmin; i<ichmax; i++){
    1183           0 :       ientry = i+irun*fNChannels;
    1184             :       //fTree->GetEntry(ientry);
    1185           0 :       fChain->GetEntry(ientry);
    1186           0 :       ntracksRun=nentries/3;
    1187           0 :       for (Int_t j=0;j<ntracksRun;j++){
    1188           0 :         Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT; 
    1189           0 :         Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME; 
    1190           0 :         Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID; 
    1191           0 :         Float_t tot = p[idxexToT];
    1192           0 :         Float_t time = p[idxexTime]-p[idxexExTime];
    1193           0 :         AliDebug (2, Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
    1194           0 :         hSlewingProf->Fill(tot,time);  // if meantime is not used, the fill may be moved in the loop above
    1195           0 :         htimetot->Fill(tot,time-meantime);  // if meantime is not used, the fill may be moved in the loop above
    1196             :       }
    1197             :     }
    1198             :   }
    1199             : 
    1200           0 :   hSlewingProf->Fit("pol5",optionFit,"",0,4);
    1201           0 :   TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
    1202           0 :   Float_t par[6];    
    1203           0 :   for(Int_t kk=0;kk<6;kk++){
    1204           0 :     par[kk]=calibfunc->GetParameter(kk);
    1205           0 :     AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
    1206             :   }
    1207             : 
    1208           0 :   if(strstr(optionSave,"save")){
    1209           0 :     TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
    1210           0 :     fileProf->cd(); 
    1211           0 :     TString profName=Form("Profile%06i_%06i",ichmin,ichmax);
    1212           0 :     TString timeTotName=Form("TimeTot%06i_%06i",ichmin,ichmax);
    1213           0 :     TString totName=Form("Tot%06i_%06i",ichmin,ichmax);
    1214           0 :     TString deltaName=Form("Delta%06i_%06i",ichmin,ichmax);
    1215           0 :     hSlewingProf->Write(profName);
    1216           0 :     htimetot->Write(timeTotName);
    1217           0 :     hToT->Write(totName);
    1218           0 :     hdeltaTime->Write(deltaName);
    1219           0 :     fileProf->Close();
    1220           0 :     delete fileProf;
    1221             :     fileProf=0x0;
    1222           0 :   }
    1223             : 
    1224           0 :   delete hToT;
    1225             :   hToT=0x0;
    1226           0 :   delete hSlewingProf;
    1227             :   hSlewingProf=0x0;
    1228           0 :   delete htimetot;
    1229             :   htimetot=0x0;
    1230           0 :   delete hdeltaTime;
    1231             :   hdeltaTime=0x0;
    1232             : 
    1233           0 :   AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ichmin);
    1234           0 :   calChannel->SetSlewPar(par);
    1235           0 :   WriteParOfflineOnCDB("TOF/Calib","valid");
    1236             :   return 0;
    1237           0 : }
    1238             : //----------------------------------------------------------------------------
    1239             : Int_t AliTOFcalib::Calibrate(Int_t i, Option_t *optionSave, Option_t *optionFit){
    1240             : 
    1241             :   // computing calibration parameters for channel i
    1242             :   // Returning codes:
    1243             :   // 0 -> everything was ok
    1244             :   // 1 -> no tree for calibration found
    1245             :   // 2 -> not enough statistics to perform calibration
    1246             :   // 3 -> problems with arrays
    1247             : 
    1248           0 :   TH1::AddDirectory(0);
    1249             :   
    1250           0 :   AliInfo(Form("*** Calibrating Histograms (one channel) %s", GetName())) ; 
    1251           0 :   AliInfo(Form("Option for Saving histos = %s",optionSave )) ; 
    1252           0 :   AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ; 
    1253             : 
    1254           0 :   Float_t p[MAXCHENTRIESSMALL];
    1255           0 :   Int_t nentries;
    1256             :   //fTree->SetBranchAddress("nentries",&nentries);
    1257             :   //fTree->SetBranchAddress("TOFentries",p);
    1258           0 :   fChain->SetBranchAddress("nentries",&nentries);
    1259           0 :   fChain->SetBranchAddress("TOFentries",p);
    1260             : 
    1261             :   Float_t ntracksTotal =0;
    1262           0 :   for (Int_t irun=0;irun<fNruns;irun++){
    1263             :     Int_t ientry = -1;
    1264           0 :     ientry = i+irun*fNChannels;
    1265             :     //fTree->GetEntry(ientry);
    1266           0 :     fChain->GetEntry(ientry);
    1267           0 :     ntracksTotal+=nentries/3;    
    1268             :   }
    1269             :   
    1270           0 :   if (ntracksTotal < MEANENTRIES) {  
    1271           0 :     AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
    1272           0 :     return 2;
    1273             :   }
    1274             : 
    1275             :   //filling ToT and Time arrays
    1276             : 
    1277             :   Int_t nbinToT = 100;  // ToT bin width in Profile = 48.8 ps 
    1278             :   Float_t minToT = 0;   // ns
    1279             :   Float_t maxToT = 4.88;  // ns
    1280             : 
    1281           0 :   TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
    1282           0 :   TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
    1283             :   Int_t ntracksRun = 0;
    1284           0 :   Double_t binsProfile[101]; // sized larger than necessary, the correct 
    1285             :                              // dim being set in the booking of the profile
    1286             :   Int_t nusefulbins=0;
    1287             :   Float_t meantime=0;
    1288           0 :   for (Int_t irun=0;irun<fNruns;irun++){
    1289             :     Int_t ientry = -1;
    1290           0 :     ientry = i+irun*fNChannels;
    1291             :     //fTree->GetEntry(ientry);
    1292           0 :     fChain->GetEntry(ientry);
    1293           0 :     ntracksRun=nentries/3;
    1294           0 :     AliDebug(2,Form("run %i, channel %i, nentries = %i, ntracksRun = %i",irun, i ,nentries, ntracksRun));
    1295           0 :     for (Int_t j=0;j<ntracksRun;j++){
    1296           0 :       Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT; 
    1297           0 :       Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME; 
    1298           0 :       Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID; 
    1299           0 :       Float_t tot = p[idxexToT];
    1300           0 :       meantime+=p[idxexTime]-p[idxexExTime];
    1301           0 :       hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
    1302           0 :       hToT->Fill(tot);
    1303             :     }
    1304             :   }
    1305             : 
    1306           0 :   nusefulbins = FindBins(hToT,&binsProfile[0]);
    1307           0 :   meantime/=ntracksTotal;
    1308           0 :   AliDebug(2,Form("meantime = %f",meantime));
    1309             :   
    1310           0 :   for (Int_t j=1;j<=nusefulbins;j++) {
    1311           0 :     AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j])); 
    1312             :   }
    1313             : 
    1314           0 :   TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G");  // CHECK THE BUILD OPTION, PLEASE!!!!!!
    1315           0 :   TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
    1316           0 :   for (Int_t irun=0;irun<fNruns;irun++){
    1317             :     Int_t ientry = -1;
    1318           0 :     ientry = i+irun*fNChannels;
    1319             :     //fTree->GetEntry(ientry);
    1320           0 :     fChain->GetEntry(ientry);
    1321           0 :     ntracksRun=nentries/3;
    1322           0 :     for (Int_t j=0;j<ntracksRun;j++){
    1323           0 :       Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT; 
    1324           0 :       Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME; 
    1325           0 :       Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID; 
    1326           0 :       Float_t tot = p[idxexToT];
    1327           0 :       Float_t time = p[idxexTime]-p[idxexExTime];
    1328           0 :       AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
    1329           0 :       hSlewingProf->Fill(tot,time);  // if meantime is not used, the fill may be moved in the loop above
    1330           0 :       htimetot->Fill(tot,time-meantime);  // if meantime is not used, the fill may be moved in the loop above
    1331             :     }
    1332             :   }
    1333             : 
    1334           0 :   hSlewingProf->Fit("pol5",optionFit,"",0,4);
    1335           0 :   TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
    1336           0 :   Float_t par[6];    
    1337           0 :   for(Int_t kk=0;kk<6;kk++){
    1338           0 :     par[kk]=calibfunc->GetParameter(kk);
    1339           0 :     AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
    1340             :   }
    1341             : 
    1342             : 
    1343           0 :   if(strstr(optionSave,"save")){
    1344           0 :     TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
    1345           0 :     fileProf->cd();   
    1346           0 :     TString profName=Form("Profile%06i",i);
    1347           0 :     TString timeTotName=Form("TimeTot%06i",i);
    1348           0 :     TString totName=Form("Tot%06i",i);
    1349           0 :     TString deltaName=Form("Delta%06i",i);
    1350           0 :     hSlewingProf->Write(profName);
    1351           0 :     htimetot->Write(timeTotName);
    1352           0 :     hToT->Write(totName);
    1353           0 :     hdeltaTime->Write(deltaName);
    1354           0 :     fileProf->Close();
    1355           0 :     delete fileProf;
    1356             :     fileProf=0x0;
    1357           0 :   }
    1358             : 
    1359           0 :   delete hToT;
    1360             :   hToT=0x0; 
    1361           0 :   delete hSlewingProf;
    1362             :   hSlewingProf=0x0;
    1363           0 :   delete htimetot;
    1364             :   htimetot=0x0;
    1365           0 :   delete hdeltaTime;
    1366             :   hdeltaTime=0x0;
    1367             : 
    1368           0 :   AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
    1369           0 :   calChannel->SetSlewPar(par);
    1370           0 :   WriteParOfflineOnCDB("TOF/Calib","valid");
    1371             :   return 0;
    1372           0 : }
    1373             : //----------------------------------------------------------------------------
    1374             : Int_t AliTOFcalib::Calibrate(Int_t nch, Int_t *ch, Option_t *optionSave, Option_t *optionFit){
    1375             : 
    1376             :   // calibrating an array of channels
    1377             :   // computing calibration parameters
    1378             :   // Returning codes:
    1379             :   // 0 -> everything was ok
    1380             :   // 1 -> no tree for calibration found
    1381             :   // 2 -> not enough statistics to perform calibration
    1382             :   // 3 -> problems with arrays
    1383             :   
    1384           0 :   TH1::AddDirectory(0);
    1385             : 
    1386           0 :   AliInfo(Form("*** Calibrating Histograms %s, number of channels = %i", GetName(),nch)) ; 
    1387           0 :   AliInfo(Form("Option for Saving histos = %s",optionSave )) ; 
    1388           0 :   AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ; 
    1389           0 :   for (Int_t ich=0; ich<nch; ich++){
    1390           0 :     Int_t i = ch[ich];
    1391           0 :     AliInfo(Form("Calibrating channel = %i",i )) ; 
    1392             :   }
    1393           0 :   Float_t p[MAXCHENTRIESSMALL];
    1394           0 :   Int_t nentries;
    1395             :   //fTree->SetBranchAddress("nentries",&nentries);
    1396             :   //fTree->SetBranchAddress("TOFentries",p);
    1397           0 :   fChain->SetBranchAddress("nentries",&nentries);
    1398           0 :   fChain->SetBranchAddress("TOFentries",p);
    1399             : 
    1400             :   Float_t ntracksTotalmean =0;
    1401           0 :   for (Int_t ich=0; ich<nch; ich++){
    1402             :     Int_t ientry = -1;
    1403           0 :       Int_t i = ch[ich];
    1404           0 :       for (Int_t irun=0;irun<fNruns;irun++){
    1405           0 :       ientry = i+irun*fNChannels;
    1406             :       //fTree->GetEntry(ientry);
    1407           0 :       fChain->GetEntry(ientry);
    1408           0 :       ntracksTotalmean+=nentries/3;
    1409             :     }
    1410             :   }
    1411             : 
    1412           0 :   ntracksTotalmean/=nch;
    1413           0 :   if (ntracksTotalmean < MEANENTRIES) { 
    1414           0 :     AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
    1415           0 :     return 2;
    1416             :   }
    1417             : 
    1418             :   //filling ToT and Time arrays
    1419             : 
    1420             :   Int_t nbinToT = 100;  // ToT bin width in Profile = 48.8 ps 
    1421             :   Float_t minToT = 0;   // ns
    1422             :   Float_t maxToT = 4.88;  // ns
    1423             :   TFile * fileProf=0x0;
    1424           0 :   if(strstr(optionSave,"save")){
    1425           0 :     fileProf = new TFile("TOFCalibSave.root","recreate");
    1426           0 :   }
    1427           0 :   for (Int_t ich=0; ich<nch; ich++) {
    1428           0 :     TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
    1429           0 :     TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
    1430           0 :     Double_t binsProfile[101]; // sized larger than necessary, the correct 
    1431             :     // dim being set in the booking of the profile
    1432           0 :     TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
    1433             :     Int_t ntracksTotal = 0;
    1434             :     Int_t ntracksRun = 0;
    1435             :     Int_t nusefulbins=0;
    1436             :     Float_t meantime=0;
    1437             :     Int_t i=-1;
    1438           0 :     for (Int_t irun=0;irun<fNruns;irun++){
    1439           0 :       i = ch[ich]+irun*fNChannels;
    1440           0 :       AliDebug(2,Form("Calibrating channel %i",i));
    1441             :       //fTree->GetEntry(i);
    1442           0 :       fChain->GetEntry(i);
    1443           0 :       ntracksTotal+=nentries/3;
    1444             :     }
    1445           0 :     if (ntracksTotal < MEANENTRIES) {
    1446           0 :       AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %d), not calibrating channel and continuing.....",i,ntracksTotal));
    1447           0 :       continue;
    1448             :     }
    1449             :   
    1450           0 :     for (Int_t irun=0;irun<fNruns;irun++){
    1451           0 :       i = ch[ich]+irun*fNChannels;
    1452             :       //fTree->GetEntry(i);
    1453           0 :       fChain->GetEntry(i);
    1454           0 :       ntracksRun=nentries/3;
    1455           0 :       for (Int_t j=0;j<ntracksRun;j++){
    1456           0 :         Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT; 
    1457           0 :         Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME; 
    1458           0 :         Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID; 
    1459           0 :         Float_t tot = p[idxexToT];
    1460           0 :         hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
    1461           0 :         meantime+=p[idxexTime]-p[idxexExTime];
    1462           0 :         hToT->Fill(tot);
    1463             :       }
    1464             :     }
    1465             : 
    1466           0 :     nusefulbins = FindBins(hToT,&binsProfile[0]);
    1467           0 :     meantime/=ntracksTotal;
    1468           0 :     for (Int_t j=1;j<=nusefulbins;j++) {
    1469           0 :       AliDebug(2,Form(" channel %i, nusefulbins = %i, bin %i = %f",i,nusefulbins,j,binsProfile[j])); 
    1470             :     }
    1471             : 
    1472           0 :     TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G");  // CHECK THE BUILD OPTION, PLEASE!!!!!!
    1473           0 :     for (Int_t irun=0;irun<fNruns;irun++){
    1474           0 :       i = ch[ich]+irun*fNChannels;
    1475             :       //fTree->GetEntry(i);
    1476           0 :       fChain->GetEntry(i);
    1477           0 :       ntracksRun=nentries/3;
    1478           0 :       for (Int_t j=0;j<ntracksRun;j++){
    1479           0 :         Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT; 
    1480           0 :         Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME; 
    1481           0 :         Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID; 
    1482           0 :         Float_t tot = p[idxexToT];
    1483           0 :         Float_t time = p[idxexTime]-p[idxexExTime];
    1484           0 :         AliDebug(2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
    1485           0 :         hSlewingProf->Fill(tot,time);  // if meantime is not used, the fill may be moved in the loop above
    1486           0 :         htimetot->Fill(tot,time-meantime);  // if meantime is not used, the fill may be moved in the loop above
    1487             :       }
    1488             :     }
    1489             :     
    1490           0 :     hSlewingProf->Fit("pol5",optionFit,"",1,4);
    1491           0 :     TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
    1492           0 :     Float_t par[6];    
    1493           0 :     for(Int_t kk=0;kk<6;kk++){
    1494           0 :       par[kk]=calibfunc->GetParameter(kk);
    1495           0 :       AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
    1496             :     }
    1497             :     
    1498           0 :     if(strstr(optionSave,"save") && fileProf){
    1499           0 :       TString profName=Form("Profile%06i",i);
    1500           0 :       TString timeTotName=Form("TimeTot%06i",i);
    1501           0 :       TString totName=Form("Tot%06i",i);
    1502           0 :       TString deltaName=Form("Delta%06i",i);
    1503           0 :       fileProf->cd();
    1504           0 :       hSlewingProf->Write(profName);
    1505           0 :       htimetot->Write(timeTotName);
    1506           0 :       hToT->Write(totName);
    1507           0 :       hdeltaTime->Write(deltaName);
    1508           0 :     }
    1509             : 
    1510           0 :     AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(i);
    1511           0 :     calChannel->SetSlewPar(par);
    1512           0 :     delete hToT;
    1513             :     hToT=0x0;
    1514           0 :     delete hSlewingProf;
    1515             :     hSlewingProf=0x0;
    1516           0 :     delete htimetot;
    1517             :     htimetot=0x0;
    1518           0 :     delete hdeltaTime;
    1519             :     hdeltaTime=0x0;
    1520           0 :   }
    1521             : 
    1522           0 :   if(strstr(optionSave,"save") && fileProf){
    1523           0 :     fileProf->Close();
    1524           0 :     delete fileProf;
    1525             :     fileProf=0x0;
    1526           0 :   }
    1527           0 :   WriteParOfflineOnCDB("TOF/Calib","valid");
    1528             : 
    1529             :   return 0;
    1530           0 : }
    1531             : //----------------------------------------------------------------------------
    1532             : Int_t AliTOFcalib::CalibrateFromProfile(Int_t ich, Option_t *optionSave, Option_t *optionFit){
    1533             : 
    1534             :   // computing calibration parameters using the old profiling algo
    1535             :   // Returning codes:
    1536             :   // 0 -> everything was ok
    1537             :   // 1 -> no tree for calibration found
    1538             :   // 2 -> not enough statistics to perform calibration
    1539             :   // 3 -> problems with arrays
    1540             : 
    1541           0 :   TH1::AddDirectory(0);
    1542             : 
    1543           0 :   AliInfo(Form("*** Calibrating Histograms From Profile %s", GetName())) ; 
    1544           0 :   AliInfo(Form("Option for Saving histos = %s",optionSave )) ; 
    1545           0 :   AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ; 
    1546           0 :   Float_t p[MAXCHENTRIESSMALL];
    1547           0 :   Int_t nentries;
    1548             :   Int_t ntracksTotal=0;
    1549             :   //fTree->SetBranchAddress("nentries",&nentries);
    1550             :   //fTree->SetBranchAddress("TOFentries",p);
    1551           0 :   fChain->SetBranchAddress("nentries",&nentries);
    1552           0 :   fChain->SetBranchAddress("TOFentries",p);
    1553             : 
    1554           0 :   for (Int_t irun=0;irun<fNruns;irun++){
    1555           0 :     Int_t i = ich+irun*fNChannels;
    1556             :     //fTree->GetEntry(i);
    1557           0 :     fChain->GetEntry(i);
    1558           0 :     ntracksTotal+=nentries/3;
    1559             :   }
    1560             : 
    1561           0 :   if (ntracksTotal < MEANENTRIES) {  
    1562           0 :     AliInfo(Form(" Too small mean number of entires per channel (mean number = %d) not calibrating and exiting.....",ntracksTotal));
    1563           0 :     return 2;
    1564             :   }
    1565             : 
    1566           0 :   TH1F * hProf = Profile(ich);
    1567           0 :   hProf->Fit("pol5",optionFit,"",0,4);
    1568           0 :   TF1 * calibfunc = (TF1*)hProf->GetFunction("pol5");
    1569           0 :   Float_t par[6];    
    1570           0 :   for(Int_t kk=0;kk<6;kk++){
    1571           0 :     par[kk]=calibfunc->GetParameter(kk);
    1572           0 :     AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
    1573             :   }
    1574             : 
    1575           0 :   if(strstr(optionSave,"save")){
    1576           0 :     TFile * fileProf = new TFile("TOFCalibSave.root","recreate");
    1577           0 :     fileProf->cd(); 
    1578           0 :     TString profName=Form("Profile%06i",ich);
    1579           0 :     hProf->Write(profName);
    1580           0 :     fileProf->Close();
    1581           0 :     delete fileProf;
    1582             :     fileProf=0x0;
    1583           0 :   }
    1584             : 
    1585           0 :   delete hProf;
    1586             :   hProf=0x0;
    1587           0 :   AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ich);
    1588           0 :   calChannel->SetSlewPar(par);
    1589           0 :   WriteParOfflineOnCDB("TOF/Calib","valid");
    1590             :   return 0;
    1591           0 : }
    1592             : //----------------------------------------------------------------------------
    1593             : Int_t AliTOFcalib::Calibrate(Option_t *optionSave, Option_t *optionFit){
    1594             : 
    1595             :   // calibrating the whole TOF
    1596             :   // computing calibration parameters
    1597             :   // Returning codes:
    1598             :   // 0 -> everything was ok
    1599             :   // 1 -> no tree for calibration found
    1600             :   // 2 -> not enough statistics to perform calibration
    1601             :   // 3 -> problems with arrays
    1602             : 
    1603           0 :   TH1::AddDirectory(0);
    1604             : 
    1605           0 :   AliInfo(Form("*** Calibrating Histograms %s, all channels", GetName())) ; 
    1606           0 :   AliInfo(Form("Option for Saving histos = %s",optionSave )) ; 
    1607           0 :   AliInfo(Form("Option for Fitting Profile histos = %s",optionFit )) ; 
    1608             : 
    1609             :   TFile * fileProf=0x0;
    1610           0 :   if(strstr(optionSave,"save")){
    1611           0 :     fileProf = new TFile("TOFCalibSave.root","recreate");
    1612           0 :   }
    1613             : 
    1614           0 :   Float_t p[MAXCHENTRIESSMALL];
    1615           0 :   Int_t nentries;
    1616             :   //fTree->SetBranchAddress("nentries",&nentries);
    1617             :   //fTree->SetBranchAddress("TOFentries",p);
    1618           0 :   fChain->SetBranchAddress("nentries",&nentries);
    1619           0 :   fChain->SetBranchAddress("TOFentries",p);
    1620             : 
    1621             :   Float_t ntracksTotalmean =0;
    1622           0 :   for (Int_t ii=0; ii<fNChannels; ii++){
    1623           0 :     for (Int_t irun=0;irun<fNruns;irun++){
    1624           0 :       Int_t i = ii+irun*fNChannels;
    1625             :       //fTree->GetEntry(i);
    1626           0 :       fChain->GetEntry(i);
    1627           0 :       ntracksTotalmean+=nentries/3;
    1628             :     }
    1629             :   }
    1630             : 
    1631           0 :   ntracksTotalmean/=fNChannels;
    1632           0 :   if (ntracksTotalmean < MEANENTRIES) {
    1633           0 :     AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotalmean));
    1634           0 :     return 2;
    1635             :   }
    1636             : 
    1637             :   //filling ToT and Time arrays
    1638             : 
    1639             :   Int_t nbinToT = 100;  // ToT bin width in Profile = 50.0 ps 
    1640             :   Float_t minToT = 0;   // ns
    1641             :   Float_t maxToT = 4.88;// ns
    1642           0 :   for (Int_t ii=0; ii<fNChannels; ii++) {
    1643           0 :     TH1F *hToT = new TH1F("htot","htot",nbinToT, minToT, maxToT);
    1644           0 :     TH1F *hdeltaTime = new TH1F("hdeltaTime","hdeltaTime",200,2,4);
    1645           0 :     TH2F * htimetot = new TH2F("htimetot","htimetot",nbinToT, minToT, maxToT,600,-5,10);
    1646           0 :     if (ii%1000 == 0) AliDebug(1,Form("Calibrating channel %i ",ii));
    1647             :     //Int_t i = 3;
    1648             :     Int_t nusefulbins=0;
    1649           0 :     Double_t binsProfile[101]; // sized larger than necessary, the correct 
    1650             :                               // dim being set in the booking of the profile
    1651             :     Int_t ntracksRun = 0;
    1652             :     Int_t ntracksTotal = 0;
    1653           0 :     for (Int_t irun=0;irun<fNruns;irun++){
    1654           0 :       Int_t i = ii+irun*fNChannels;
    1655             :       //fTree->GetEntry(i);
    1656           0 :       fChain->GetEntry(i);
    1657           0 :       ntracksTotal+=nentries/3;
    1658             :     }
    1659           0 :     if (ntracksTotal < MEANENTRIES) {
    1660           0 :       AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %d), not calibrating channel and continuing.....",ii,ntracksTotal));
    1661           0 :       continue;
    1662             :     }
    1663             :     Float_t meantime=0;
    1664           0 :     for (Int_t irun=0;irun<fNruns;irun++){
    1665           0 :       Int_t i = ii+irun*fNChannels;
    1666             :       //fTree->GetEntry(i);
    1667           0 :       fChain->GetEntry(i);
    1668           0 :       ntracksRun=nentries/3;
    1669           0 :       for (Int_t j=0;j<ntracksRun;j++){
    1670           0 :         Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT; 
    1671           0 :         Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME; 
    1672           0 :         Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID; 
    1673           0 :         Float_t tot = p[idxexToT];
    1674           0 :         hdeltaTime->Fill(p[idxexTime]-p[idxexExTime]);
    1675           0 :         meantime+=p[idxexTime]-p[idxexExTime];
    1676           0 :         hToT->Fill(tot);
    1677             :       }
    1678             :     }
    1679           0 :     nusefulbins = FindBins(hToT,&binsProfile[0]);
    1680           0 :     meantime/=ntracksTotal;
    1681           0 :     for (Int_t j=0;j<nusefulbins;j++) {
    1682           0 :       AliDebug(2,Form(" channel %i, usefulbin = %i, low edge = %f",ii,j,binsProfile[j])); 
    1683             :     }
    1684           0 :     TProfile* hSlewingProf = new TProfile("hSlewingProf", "hSlewingProf",nusefulbins, binsProfile, "G");  // CHECK THE BUILD OPTION, PLEASE!!!!!!
    1685           0 :     for (Int_t irun=0;irun<fNruns;irun++){
    1686           0 :       Int_t i = ii+irun*fNChannels;
    1687             :       //fTree->GetEntry(i);
    1688           0 :       fChain->GetEntry(i);
    1689           0 :       ntracksRun=nentries/3;
    1690           0 :       for (Int_t j=0;j<ntracksRun;j++){
    1691           0 :         Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT; 
    1692           0 :         Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME; 
    1693           0 :         Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID; 
    1694           0 :         Float_t tot = p[idxexToT];
    1695           0 :         Float_t time = p[idxexTime]-p[idxexExTime];
    1696           0 :         AliDebug (2,Form("track = %i, time = %f, tot = %f, time-meantime = %f",j,time, tot, time-meantime));
    1697           0 :         hSlewingProf->Fill(tot,time);  // if meantime is not used, the fill may be moved in the loop above
    1698           0 :         htimetot->Fill(tot,time-meantime);  // if meantime is not used, the fill may be moved in the loop above
    1699             :       }
    1700             :     }
    1701           0 :     hSlewingProf->Fit("pol5",optionFit,"",1,4);
    1702           0 :     TF1 * calibfunc = (TF1*)hSlewingProf->GetFunction("pol5");
    1703           0 :     Float_t par[6];    
    1704           0 :     for(Int_t kk=0;kk<6;kk++){
    1705           0 :       par[kk]=calibfunc->GetParameter(kk);
    1706           0 :       AliDebug(2,Form("parameter %i = %f",kk,par[kk]));
    1707             :     }
    1708             : 
    1709           0 :     if(strstr(optionSave,"save") && fileProf){
    1710           0 :       TString profName=Form("Profile%06i",ii);
    1711           0 :       TString timeTotName=Form("TimeTot%06i",ii);
    1712           0 :       TString totName=Form("Tot%06i",ii);
    1713           0 :       TString deltaName=Form("Delta%06i",ii);
    1714           0 :       fileProf->cd();
    1715           0 :       hSlewingProf->Write(profName);
    1716           0 :       htimetot->Write(timeTotName);
    1717           0 :       hToT->Write(totName);
    1718           0 :       hdeltaTime->Write(deltaName);
    1719           0 :     }
    1720           0 :     AliTOFChannelOffline * calChannel = (AliTOFChannelOffline*)fTOFCalOffline->At(ii);
    1721           0 :     calChannel->SetSlewPar(par);
    1722             : 
    1723           0 :     delete hToT;
    1724             :     hToT=0x0;
    1725           0 :     delete hSlewingProf;
    1726             :     hSlewingProf=0x0;
    1727           0 :     delete htimetot;
    1728             :     htimetot=0x0;
    1729           0 :     delete hdeltaTime;
    1730             :     hdeltaTime=0x0;
    1731           0 :   }
    1732             : 
    1733           0 :   if(strstr(optionSave,"save")){
    1734           0 :     fileProf->Close();
    1735           0 :     delete fileProf;
    1736             :     fileProf=0x0;
    1737           0 :   }
    1738           0 :   WriteParOfflineOnCDB("TOF/Calib","valid");
    1739             :   return 0;
    1740           0 : }
    1741             : 
    1742             : //-----------------------------------------------------------------------
    1743             : TH1F* AliTOFcalib::Profile(Int_t ich)
    1744             : {
    1745             :   // profiling algo
    1746             : 
    1747           0 :   Float_t p[MAXCHENTRIESSMALL];
    1748           0 :   Int_t nentries;
    1749             :   //fTree->SetBranchAddress("nentries",&nentries);
    1750             :   //fTree->SetBranchAddress("TOFentries",p);
    1751           0 :   fChain->SetBranchAddress("nentries",&nentries);
    1752           0 :   fChain->SetBranchAddress("TOFentries",p);
    1753             : 
    1754             :   //Prepare histograms for Slewing Correction
    1755             :   const Int_t knbinToT = 100;
    1756             :   Int_t nbinTime = 200;
    1757             :   Float_t minTime = -5.5; //ns
    1758             :   Float_t maxTime = 5.5; //ns
    1759             :   Float_t minToT = 0; //ns
    1760             :   Float_t maxToT = 5.; //ns
    1761           0 :   Float_t deltaToT = (maxToT-minToT)/knbinToT;
    1762           0 :   Double_t mTime[knbinToT+1],mToT[knbinToT+1],meanTime[knbinToT+1], meanTime2[knbinToT+1],vToT[knbinToT+1], vToT2[knbinToT+1],meanToT[knbinToT+1],meanToT2[knbinToT+1],vTime[knbinToT+1],vTime2[knbinToT+1],sigmaTime[knbinToT+1];
    1763           0 :   Int_t n[knbinToT+1], nentrx[knbinToT+1];
    1764             :   //Double_t xlow[knbinToT+1],sigmaToT[knbinToT+1];  // not used for the time being
    1765           0 :   for (Int_t i = 0; i < knbinToT+1 ; i++){
    1766           0 :     mTime[i]=0;
    1767           0 :     mToT[i]=0;
    1768           0 :     n[i]=0;
    1769           0 :     meanTime[i]=0;
    1770           0 :     meanTime2[i]=0;
    1771           0 :     vToT[i]=0;
    1772           0 :     vToT2[i]=0;
    1773           0 :     meanToT[i]=0;
    1774           0 :     meanToT2[i]=0;
    1775           0 :     vTime[i]=0;
    1776           0 :     vTime2[i]=0;
    1777             :     //xlow[i]=0;
    1778           0 :     sigmaTime[i]=0;
    1779             :     //sigmaToT[i]=0;
    1780           0 :     n[i]=0;
    1781           0 :     nentrx[i]=0;
    1782             :   }
    1783           0 :   TH2F* hSlewing = new TH2F("hSlewing", "hSlewing", knbinToT, minToT, maxToT, nbinTime, minTime, maxTime);
    1784             :   Int_t ntracksRun = 0;
    1785           0 :   TH1F *histo = new TH1F("histo", "1D Time vs ToT", knbinToT, minToT, maxToT);
    1786           0 :   for (Int_t irun=0;irun<fNruns;irun++){
    1787           0 :     Int_t i = ich+irun*fNChannels;
    1788             :     //fTree->GetEntry(i);
    1789           0 :     fChain->GetEntry(i);
    1790           0 :     ntracksRun=nentries/3;
    1791           0 :     for (Int_t j=0;j<ntracksRun;j++){
    1792           0 :       Int_t idxexToT = (j* NIDXSMALL)+DELTAIDXTOT; 
    1793           0 :       Int_t idxexTime = (j* NIDXSMALL)+DELTAIDXTIME; 
    1794           0 :       Int_t idxexExTime = (j* NIDXSMALL)+DELTAIDXPID; 
    1795           0 :       Float_t tot = p[idxexToT];
    1796           0 :       Float_t time = p[idxexTime]-p[idxexExTime];
    1797           0 :       Int_t nx = (Int_t)((tot-minToT)/deltaToT)+1;
    1798           0 :       if ((tot != 0) && ( time!= 0)){
    1799           0 :         vTime[nx]+=time;
    1800           0 :         vTime2[nx]+=time*time;
    1801           0 :         vToT[nx]+=tot;
    1802           0 :         vToT2[nx]+=tot*tot;
    1803           0 :         nentrx[nx]++;
    1804           0 :         hSlewing->Fill(tot,time);
    1805           0 :       }
    1806             :     }
    1807             :   }
    1808           0 :   Int_t nbinsToT=hSlewing->GetNbinsX();
    1809           0 :   if (nbinsToT != knbinToT) {
    1810           0 :     AliError("Profile :: incompatible numbers of bins");
    1811           0 :     return 0x0;
    1812             :   }
    1813             :   
    1814             :   Int_t usefulBins=0;
    1815           0 :   for (Int_t i=1;i<=nbinsToT;i++){
    1816           0 :     if (nentrx[i]!=0){
    1817           0 :       n[usefulBins]+=nentrx[i];
    1818           0 :       if (n[usefulBins]==0 && i == nbinsToT) {
    1819           0 :         break;
    1820             :       }
    1821           0 :       meanTime[usefulBins]+=vTime[i];
    1822           0 :       meanTime2[usefulBins]+=vTime2[i];
    1823           0 :       meanToT[usefulBins]+=vToT[i];
    1824           0 :       meanToT2[usefulBins]+=vToT2[i];
    1825           0 :       if (n[usefulBins]<10 && i!=nbinsToT) continue; 
    1826           0 :       mTime[usefulBins]=meanTime[usefulBins]/n[usefulBins];
    1827           0 :       mToT[usefulBins]=meanToT[usefulBins]/n[usefulBins];
    1828           0 :       sigmaTime[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
    1829           0 :                             *(meanTime2[usefulBins]-meanTime[usefulBins]
    1830           0 :                             *meanTime[usefulBins]/n[usefulBins]));
    1831           0 :       if ((1./n[usefulBins]/n[usefulBins]
    1832           0 :            *(meanToT2[usefulBins]-meanToT[usefulBins]
    1833           0 :              *meanToT[usefulBins]/n[usefulBins]))< 0) {
    1834           0 :         AliError(" too small radical" );
    1835             :         //sigmaToT[usefulBins]=0;
    1836           0 :       }
    1837             :       else{       
    1838             :         //sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
    1839             :         //                   *(meanToT2[usefulBins]-meanToT[usefulBins]
    1840             :         //                   *meanToT[usefulBins]/n[usefulBins]));
    1841             :       }
    1842           0 :       usefulBins++;
    1843           0 :     }
    1844             :   }
    1845           0 :   for (Int_t i=0;i<usefulBins;i++){
    1846           0 :     Int_t binN = (Int_t)((mToT[i]-minToT)/deltaToT)+1;
    1847           0 :     histo->Fill(mToT[i],mTime[i]);
    1848           0 :     histo->SetBinError(binN,sigmaTime[i]);
    1849             :   } 
    1850           0 :   delete hSlewing;
    1851             :   hSlewing=0x0;
    1852             : 
    1853             :   return histo;
    1854           0 : }
    1855             : //----------------------------------------------------------------------------
    1856             : Int_t AliTOFcalib::FindBins(TH1F* h, Double_t *binsProfile) const{
    1857             : 
    1858             :   // to determine the bins for ToT histo
    1859             : 
    1860             :   Int_t cont = 0;
    1861             :   Int_t startBin = 1;
    1862           0 :   Int_t nbin = h->GetNbinsX();
    1863           0 :   Int_t nentries = (Int_t)h->GetEntries();
    1864           0 :   Float_t max = h->GetBinLowEdge(nbin);
    1865             :   Int_t nusefulbins=0;
    1866             :   Int_t maxcont=0;
    1867             :   // setting maxvalue of entries per bin
    1868           0 :   if (nentries <= 60) maxcont = 2;
    1869           0 :   else  if (nentries <= 100) maxcont = 5;
    1870           0 :   else  if (nentries <= 500) maxcont = 10;
    1871             :   else  maxcont = 20;
    1872           0 :   for (Int_t j=1;j<=nbin;j++) {
    1873           0 :     cont += (Int_t)h->GetBinContent(j);
    1874           0 :     if (j<nbin){
    1875           0 :       if (cont>=maxcont){
    1876           0 :         nusefulbins++;
    1877           0 :         binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
    1878             :         cont=0;
    1879           0 :         startBin=j+1;
    1880           0 :         continue;
    1881             :       }
    1882             :     }
    1883             :     else{
    1884           0 :       if (cont>=maxcont){
    1885           0 :         nusefulbins++;
    1886           0 :         binsProfile[nusefulbins-1]=h->GetBinLowEdge(startBin);
    1887           0 :         binsProfile[nusefulbins]=max;
    1888           0 :       }
    1889             :       else {
    1890           0 :         binsProfile[nusefulbins]=h->GetBinLowEdge(startBin);
    1891             :       }
    1892             :     }
    1893             :   }
    1894           0 :   return nusefulbins;
    1895             : }
    1896             : 
    1897             : 
    1898             : //----------------------------------------------------------------------------
    1899             : 
    1900             : void
    1901             : AliTOFcalib::CreateDeltaBCOffset()
    1902             : {
    1903             :   /*
    1904             :    * create deltaBC offset
    1905             :    */
    1906             : 
    1907           0 :   if (fDeltaBCOffset) {
    1908           0 :     AliWarning("DeltaBCOffset object already defined, cannot create a new one");
    1909           0 :     return;
    1910             :   }
    1911           0 :   fDeltaBCOffset = new AliTOFDeltaBCOffset();
    1912           0 : }
    1913             :   
    1914             : //----------------------------------------------------------------------------
    1915             : 
    1916             : void
    1917             : AliTOFcalib::CreateCTPLatency()
    1918             : {
    1919             :   /*
    1920             :    * create CTP latency
    1921             :    */
    1922             : 
    1923           0 :   if (fCTPLatency) {
    1924           0 :     AliWarning("CTPLatency object already defined, cannot create a new one");
    1925           0 :     return;
    1926             :   }
    1927           0 :   fCTPLatency = new AliTOFCTPLatency();
    1928           0 : }
    1929             :   
    1930             : //----------------------------------------------------------------------------
    1931             : 
    1932             : void
    1933             : AliTOFcalib::CreateT0Fill()
    1934             : {
    1935             :   /*
    1936             :    * create event-time
    1937             :    */
    1938             : 
    1939           0 :   if (fT0Fill) {
    1940           0 :     AliWarning("T0Fill object already defined, cannot create a new one");
    1941           0 :     return;
    1942             :   }
    1943           0 :   fT0Fill = new AliTOFT0Fill();
    1944           0 : }
    1945             :   
    1946             : //----------------------------------------------------------------------------
    1947             : 
    1948             : void
    1949             : AliTOFcalib::CreateRunParams()
    1950             : {
    1951             :   /*
    1952             :    * create run params
    1953             :    */
    1954             : 
    1955           0 :   if (fRunParams) {
    1956           0 :     AliWarning("RunParams object already defined, cannot create a new one");
    1957           0 :     return;
    1958             :   }
    1959           0 :   fRunParams = new AliTOFRunParams();
    1960           0 : }
    1961             :   
    1962             : //----------------------------------------------------------------------------
    1963             : 
    1964             : void
    1965             : AliTOFcalib::WriteDeltaBCOffsetOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
    1966             : {
    1967             :   /*
    1968             :    * deltaBC offset on CDB 
    1969             :    */
    1970             :   
    1971           0 :   if (!fDeltaBCOffset) return;
    1972           0 :   AliCDBId id(Form("%s/DeltaBCOffset", sel), minrun, maxrun);
    1973           0 :   AliCDBMetaData *md = new AliCDBMetaData();
    1974           0 :   md->SetResponsible("Roberto Preghenella");
    1975           0 :   AliCDBManager *man = AliCDBManager::Instance();
    1976           0 :   man->Put(fDeltaBCOffset, id, md);
    1977           0 :   AliDebug(2,Form("DeltaBCOffset written on CDB with run range [%i, %i] ",minrun ,maxrun));
    1978           0 :   delete md;
    1979           0 : }
    1980             : 
    1981             : //----------------------------------------------------------------------------
    1982             : 
    1983             : void
    1984             : AliTOFcalib::WriteCTPLatencyOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
    1985             : {
    1986             :   /*
    1987             :    * write CTP latency on CDB 
    1988             :    */
    1989             :   
    1990           0 :   if (!fCTPLatency) return;
    1991           0 :   AliCDBId id(Form("%s/CTPLatency", sel), minrun, maxrun);
    1992           0 :   AliCDBMetaData *md = new AliCDBMetaData();
    1993           0 :   md->SetResponsible("Roberto Preghenella");
    1994           0 :   AliCDBManager *man = AliCDBManager::Instance();
    1995           0 :   man->Put(fCTPLatency, id, md);
    1996           0 :   AliDebug(2,Form("CTPLatency written on CDB with run range [%i, %i] ",minrun ,maxrun));
    1997           0 :   delete md;
    1998           0 : }
    1999             : 
    2000             : //----------------------------------------------------------------------------
    2001             : 
    2002             : void
    2003             : AliTOFcalib::WriteT0FillOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
    2004             : {
    2005             :   /*
    2006             :    * write event-time on CDB 
    2007             :    */
    2008             :   
    2009           0 :   if (!fT0Fill) return;
    2010           0 :   AliCDBId id(Form("%s/T0Fill", sel), minrun, maxrun);
    2011           0 :   AliCDBMetaData *md = new AliCDBMetaData();
    2012           0 :   md->SetResponsible("Roberto Preghenella");
    2013           0 :   AliCDBManager *man = AliCDBManager::Instance();
    2014           0 :   man->Put(fT0Fill, id, md);
    2015           0 :   AliDebug(2,Form("T0Fill written on CDB with run range [%i, %i] ",minrun ,maxrun));
    2016           0 :   delete md;
    2017           0 : }
    2018             : 
    2019             : //----------------------------------------------------------------------------
    2020             : 
    2021             : void
    2022             : AliTOFcalib::WriteRunParamsOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
    2023             : {
    2024             :   /*
    2025             :    * write run params on CDB 
    2026             :    */
    2027             :   
    2028           0 :   if (!fRunParams) return;
    2029           0 :   AliCDBId id(Form("%s/RunParams", sel), minrun, maxrun);
    2030           0 :   AliCDBMetaData *md = new AliCDBMetaData();
    2031           0 :   md->SetResponsible("Roberto Preghenella");
    2032           0 :   AliCDBManager *man = AliCDBManager::Instance();
    2033           0 :   man->Put(fRunParams, id, md);
    2034           0 :   AliDebug(2,Form("RunParams written on CDB with run range [%i, %i] ",minrun ,maxrun));
    2035           0 :   delete md;
    2036           0 : }
    2037             : 
    2038             : //----------------------------------------------------------------------------
    2039             : 
    2040             : void
    2041             : AliTOFcalib::WriteReadoutEfficiencyOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
    2042             : {
    2043             :   /*
    2044             :    * write readout efficiency on CDB 
    2045             :    */
    2046             :   
    2047           0 :   if (!fReadoutEfficiency) return;
    2048           0 :   AliCDBId id(Form("%s/ReadoutEfficiency", sel), minrun, maxrun);
    2049           0 :   AliCDBMetaData *md = new AliCDBMetaData();
    2050           0 :   md->SetResponsible("Roberto Preghenella");
    2051           0 :   AliCDBManager *man = AliCDBManager::Instance();
    2052           0 :   man->Put(fReadoutEfficiency, id, md);
    2053           0 :   AliDebug(2,Form("ReadoutEfficiency written on CDB with run range [%i, %i] ",minrun ,maxrun));
    2054           0 :   delete md;
    2055           0 : }
    2056             : 
    2057             : //----------------------------------------------------------------------------
    2058             : 
    2059             : void
    2060             : AliTOFcalib::WriteProblematicOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
    2061             : {
    2062             :   /*
    2063             :    * write problematic on CDB 
    2064             :    */
    2065             :   
    2066           0 :   if (!fProblematic) return;
    2067           0 :   AliCDBId id(Form("%s/Problematic", sel), minrun, maxrun);
    2068           0 :   AliCDBMetaData *md = new AliCDBMetaData();
    2069           0 :   md->SetResponsible("Roberto Preghenella");
    2070           0 :   AliCDBManager *man = AliCDBManager::Instance();
    2071           0 :   man->Put(fProblematic, id, md);
    2072           0 :   AliDebug(2,Form("Problematic written on CDB with run range [%i, %i] ",minrun ,maxrun));
    2073           0 :   delete md;
    2074           0 : }
    2075             : 
    2076             : //----------------------------------------------------------------------------
    2077             : 
    2078             : Bool_t
    2079             : AliTOFcalib::ReadDeltaBCOffsetFromCDB(const Char_t *sel , Int_t nrun)
    2080             : {
    2081             :   /*
    2082             :    * read deltaBC offset from CDB
    2083             :    */
    2084             :   
    2085           8 :   AliCDBManager *man = AliCDBManager::Instance();
    2086           8 :   AliCDBEntry *entry = man->Get(Form("%s/DeltaBCOffset", sel),nrun);
    2087           4 :   if (!entry) { 
    2088           0 :     AliFatal("No DeltaBCOffset entry found in CDB");
    2089           0 :     exit(0);  
    2090             :   }
    2091           4 :   fDeltaBCOffset =(AliTOFDeltaBCOffset *)entry->GetObject();
    2092           4 :   if(!fDeltaBCOffset){
    2093           0 :     AliFatal("No DeltaBCOffset object found in CDB entry");
    2094           0 :     exit(0);  
    2095             :   }  
    2096           4 :   return kTRUE; 
    2097           0 : }
    2098             : 
    2099             : //----------------------------------------------------------------------------
    2100             : 
    2101             : Bool_t
    2102             : AliTOFcalib::ReadCTPLatencyFromCDB(const Char_t *sel , Int_t nrun)
    2103             : {
    2104             :   /*
    2105             :    * read CTP latency from CDB
    2106             :    */
    2107             :   
    2108           8 :   AliCDBManager *man = AliCDBManager::Instance();
    2109           8 :   AliCDBEntry *entry = man->Get(Form("%s/CTPLatency", sel),nrun);
    2110           4 :   if (!entry) { 
    2111           0 :     AliFatal("No CTPLatency entry found in CDB");
    2112           0 :     exit(0);  
    2113             :   }
    2114           4 :   fCTPLatency =(AliTOFCTPLatency *)entry->GetObject();
    2115           4 :   if(!fCTPLatency){
    2116           0 :     AliFatal("No CTPLatency object found in CDB entry");
    2117           0 :     exit(0);  
    2118             :   }  
    2119           4 :   return kTRUE; 
    2120           0 : }
    2121             : 
    2122             : //----------------------------------------------------------------------------
    2123             : 
    2124             : Bool_t
    2125             : AliTOFcalib::ReadT0FillFromCDB(const Char_t *sel , Int_t nrun)
    2126             : {
    2127             :   /*
    2128             :    * read event-time from CDB
    2129             :    */
    2130             :   
    2131           0 :   AliCDBManager *man = AliCDBManager::Instance();
    2132           0 :   AliCDBEntry *entry = man->Get(Form("%s/T0Fill", sel),nrun);
    2133           0 :   if (!entry) { 
    2134           0 :     AliFatal("No T0Fill entry found in CDB");
    2135           0 :     exit(0);  
    2136             :   }
    2137           0 :   fT0Fill =(AliTOFT0Fill *)entry->GetObject();
    2138           0 :   if(!fT0Fill){
    2139           0 :     AliFatal("No T0Fill object found in CDB entry");
    2140           0 :     exit(0);  
    2141             :   }  
    2142           0 :   return kTRUE; 
    2143           0 : }
    2144             : 
    2145             : //----------------------------------------------------------------------------
    2146             : 
    2147             : Bool_t
    2148             : AliTOFcalib::ReadRunParamsFromCDB(const Char_t *sel , Int_t nrun)
    2149             : {
    2150             :   /*
    2151             :    * read run params from CDB
    2152             :    */
    2153             :   
    2154           8 :   AliCDBManager *man = AliCDBManager::Instance();
    2155           8 :   AliCDBEntry *entry = man->Get(Form("%s/RunParams", sel),nrun, fRunParamsSpecificVersion);
    2156           4 :   if (!entry) { 
    2157           0 :     AliFatal("No RunParams entry found in CDB");
    2158           0 :     exit(0);  
    2159             :   }
    2160           4 :   fRunParams =(AliTOFRunParams *)entry->GetObject();
    2161           4 :   if(!fRunParams){
    2162           0 :     AliFatal("No RunParams object found in CDB entry");
    2163           0 :     exit(0);  
    2164             :   }  
    2165           4 :   return kTRUE; 
    2166           0 : }
    2167             : 
    2168             : //----------------------------------------------------------------------------
    2169             : 
    2170             : Bool_t
    2171             : AliTOFcalib::ReadLHCClockPhaseFromCDB(const Char_t *sel , Int_t nrun)
    2172             : {
    2173             :   /*
    2174             :    * read LHC clock-phase from CDB
    2175             :    */
    2176             :   
    2177           8 :   AliCDBManager *man = AliCDBManager::Instance();
    2178           8 :   AliCDBEntry *entry = man->Get(Form("%s/LHCClockPhase", sel),nrun);
    2179           4 :   if (!entry) { 
    2180           0 :     AliFatal("No LHCClockPhase entry found in CDB");
    2181           0 :     exit(0);  
    2182             :   }
    2183           4 :   fLHCClockPhase =(AliLHCClockPhase *)entry->GetObject();
    2184           4 :   if(!fRunParams){
    2185           0 :     AliFatal("No LHCClockPhase object found in CDB entry");
    2186           0 :     exit(0);  
    2187             :   }  
    2188           4 :   return kTRUE; 
    2189           0 : }
    2190             : 
    2191             : //----------------------------------------------------------------------------
    2192             : 
    2193             : Bool_t
    2194             : AliTOFcalib::ReadReadoutEfficiencyFromCDB(const Char_t *sel , Int_t nrun)
    2195             : {
    2196             :   /*
    2197             :    * read readout efficiency from CDB
    2198             :    */
    2199             :   
    2200           8 :   AliCDBManager *man = AliCDBManager::Instance();
    2201           8 :   AliCDBEntry *entry = man->Get(Form("%s/ReadoutEfficiency", sel),nrun);
    2202           4 :   if (!entry) { 
    2203           0 :     AliFatal("No ReadoutEfficiency entry found in CDB");
    2204           0 :     exit(0);  
    2205             :   }
    2206           4 :   fReadoutEfficiency = (TH1F *)entry->GetObject();
    2207           4 :   if(!fReadoutEfficiency){
    2208           0 :     AliFatal("No ReadoutEfficiency object found in CDB entry");
    2209           0 :     exit(0);  
    2210             :   }  
    2211           4 :   return kTRUE; 
    2212           0 : }
    2213             : 
    2214             : //----------------------------------------------------------------------------
    2215             : 
    2216             : Bool_t
    2217             : AliTOFcalib::ReadProblematicFromCDB(const Char_t *sel , Int_t nrun)
    2218             : {
    2219             :   /*
    2220             :    * read problematic from CDB
    2221             :    */
    2222             :   
    2223           8 :   AliCDBManager *man = AliCDBManager::Instance();
    2224           8 :   AliCDBEntry *entry = man->Get(Form("%s/Problematic", sel),nrun);
    2225           4 :   if (!entry) { 
    2226           0 :     AliFatal("No Problematic entry found in CDB");
    2227           0 :     exit(0);  
    2228             :   }
    2229           4 :   fProblematic = (TH1C *)entry->GetObject();
    2230           4 :   if(!fProblematic){
    2231           0 :     AliFatal("No Problematic object found in CDB entry");
    2232           0 :     exit(0);  
    2233             :   }  
    2234           4 :   return kTRUE; 
    2235           0 : }
    2236             : 
    2237             : //----------------------------------------------------------------------------
    2238             : 
    2239             : Bool_t 
    2240             : AliTOFcalib::Init(Int_t run)
    2241             : {
    2242             :   /*
    2243             :    * init
    2244             :    */
    2245             : 
    2246           8 :   if (fInitFlag) {
    2247           0 :     AliWarning("the class was already initialized, re-initialize it");
    2248           0 :     fInitFlag = kFALSE;
    2249           0 :   }
    2250             :   
    2251             :   /* read channel status array */
    2252           4 :   if (!ReadParOnlineStatusFromCDB("TOF/Calib", run)) {
    2253           0 :     AliError("cannot get \"Status\" object from OCDB");
    2254           0 :     return kFALSE;
    2255             :   }
    2256             :   /* get par offline array */
    2257           4 :   if (!ReadParOfflineFromCDB("TOF/Calib", run)) {
    2258           0 :     AliError("cannot get \"ParOffline\" object from OCDB");
    2259           0 :     return kFALSE;
    2260             :   }
    2261             :   /* get deltaBC offset obj */
    2262           4 :   if (!ReadDeltaBCOffsetFromCDB("TOF/Calib", run)) {
    2263           0 :     AliError("cannot get \"DeltaBCOffset\" object from OCDB");
    2264           0 :     return kFALSE;
    2265             :   }
    2266             :   /* get CTP latency obj */
    2267           4 :   if (!ReadCTPLatencyFromCDB("TOF/Calib", run)) {
    2268           0 :     AliError("cannot get \"CTPLatency\" object from OCDB");
    2269           0 :     return kFALSE;
    2270             :   }
    2271             :   /* get run params obj */
    2272           4 :   if (!ReadRunParamsFromCDB("TOF/Calib", run)) {
    2273           0 :     AliError("cannot get \"RunParams\" object from OCDB");
    2274           0 :     return kFALSE;
    2275             :   }
    2276             :   /* get LHC clock-phase obj */
    2277           4 :   if (!ReadLHCClockPhaseFromCDB("GRP/Calib", run)) {
    2278           0 :     AliError("cannot get \"LHCClockPhase\" object from OCDB");
    2279           0 :     return kFALSE;
    2280             :   }
    2281             :   /* get readout efficiency obj */
    2282           4 :   if (!ReadReadoutEfficiencyFromCDB("TOF/Calib", run)) {
    2283           0 :     AliError("cannot get \"ReadoutEfficiency\" object from OCDB");
    2284           0 :     return kFALSE;
    2285             :   }
    2286             :   /* get readout efficiency obj */
    2287           4 :   if (!ReadProblematicFromCDB("TOF/Calib", run)) {
    2288           0 :     AliError("cannot get \"Problematic\" object from OCDB");
    2289           0 :     return kFALSE;
    2290             :   }
    2291             :   /* get response params */
    2292           4 :   TFile *responseFile = TFile::Open("$ALICE_ROOT/TOF/data/AliTOFresponsePar.root");
    2293           8 :   if (!responseFile || !responseFile->IsOpen()) {
    2294           0 :     AliError("cannot open \"ResponseParams\" local file");
    2295           0 :     return kFALSE;
    2296             :   }
    2297           4 :   fResponseParams = (AliTOFResponseParams *)responseFile->Get("ResponseParams");
    2298           4 :   if (!fResponseParams) {
    2299           0 :     AliError("cannot get \"ResponseParams\" object from local file");
    2300           0 :     return kFALSE;
    2301             :   }
    2302           4 :   responseFile->Close();
    2303             : 
    2304             :   /* check whether to use the clock phase */
    2305           4 :   if (fRunParams->GetUseLHCClockPhase())
    2306           0 :     fUseLHCClockPhase = kTRUE;
    2307             :  
    2308           4 :   if (fUseLHCClockPhase)
    2309           0 :     AliInfo("calibration using BPTX LHC clock-phase");
    2310             : 
    2311             :   /* all done */
    2312           4 :   fInitFlag = kTRUE;
    2313           4 :   return kTRUE;
    2314             : 
    2315           4 : }
    2316             : 
    2317             : //----------------------------------------------------------------------------
    2318             : 
    2319             : Double_t
    2320             : AliTOFcalib::GetTimeCorrection(Int_t index, Double_t tot, Int_t deltaBC, Int_t l0l1, UInt_t timestamp)
    2321             : {
    2322             :   /*
    2323             :    * get time correction
    2324             :    */
    2325             : 
    2326         600 :   if (!fInitFlag) {
    2327           0 :     AliError("class not yet initialized. Initialize it before.");
    2328           0 :     return 0.;
    2329             :   }
    2330             : 
    2331             :   /* deal with L0-L1 orbit crossing (negative values) */
    2332         300 :   if (l0l1 < 0) l0l1 += 3564;
    2333             : 
    2334             :   /* get calibration params */
    2335         300 :   AliTOFChannelOffline *parOffline = (AliTOFChannelOffline *)fTOFCalOffline->At(index);
    2336         300 :   Int_t deltaBCOffset = fDeltaBCOffset->GetDeltaBCOffset();
    2337         300 :   Float_t ctpLatency = fCTPLatency->GetCTPLatency();
    2338         300 :   Float_t tdcLatencyWindow = fStatus->GetLatencyWindow(index) * 1.e3;
    2339         300 :   Float_t timezero = fRunParams->EvalT0(timestamp);
    2340         300 :   Float_t clockphase = fLHCClockPhase->GetPhase(timestamp);
    2341             :   /* check whether to remove mean T0.
    2342             :    * useful when one wants to compute mean T0 */
    2343         300 :   if (!fRemoveMeanT0) timezero = 0.;
    2344             :   /* check whether to use the clock phase */
    2345         300 :   if (fUseLHCClockPhase) timezero -= 1.e3 * clockphase;
    2346             : 
    2347             :   /* compute correction */
    2348             :   Double_t corr = 0.;
    2349             :   /* deltaBC correction */
    2350             :   deltaBC = deltaBCOffset; /* inhibit deltaBC correction for the time being */
    2351         300 :   corr += (deltaBC - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth();
    2352             :   /* L0-L1 latency correction */
    2353         300 :   corr -= l0l1 * AliTOFGeometry::BunchCrossingBinWidth();
    2354             :   /* CTP latency correction */
    2355         300 :   corr -= ctpLatency;
    2356             :   /* TDC latency window correction */
    2357         300 :   corr += tdcLatencyWindow;
    2358             :   /* time-zero correction */
    2359         300 :   corr += timezero;
    2360             :   /* time calibration correction */
    2361         300 :   if (tot < AliTOFGeometry::SlewTOTMin()) 
    2362         300 :     tot = AliTOFGeometry::SlewTOTMin();
    2363         300 :   if (tot > AliTOFGeometry::SlewTOTMax()) 
    2364           0 :     tot = AliTOFGeometry::SlewTOTMax();
    2365        4200 :   for (Int_t islew = 0; islew < 6; islew++)
    2366        1800 :     corr += parOffline->GetSlewPar(islew) * TMath::Power(tot, islew) * 1.e3;
    2367             : 
    2368             :   /* return correction */
    2369             :   return corr;
    2370         300 : }
    2371             : 
    2372             : //----------------------------------------------------------------------------
    2373             : 
    2374             : void
    2375             : AliTOFcalib::CalibrateESD(AliESDEvent *event)
    2376             : {
    2377             :   /*
    2378             :    * calibrate ESD
    2379             :    */
    2380             : 
    2381           0 :   if (!fInitFlag) {
    2382           0 :     AliError("class not yet initialized. Initialize it before.");
    2383           0 :     return;
    2384             :   }
    2385             : 
    2386             :   Int_t index, l0l1, deltaBC;
    2387             :   Double_t time, tot, corr;
    2388           0 :   UInt_t timestamp = event->GetTimeStamp();
    2389             : 
    2390             :   // calibrating TOF hits
    2391             : 
    2392             :   AliESDTOFHit* hit = NULL;
    2393             :   AliESDtrack* track = NULL;
    2394           0 :   TClonesArray* esdTOFhits = event->GetESDTOFHits();
    2395           0 :   if (esdTOFhits) { // new TOF data structure
    2396           0 :     for (Int_t ihit = 0; ihit < esdTOFhits->GetEntriesFast(); ihit++) {
    2397             :       
    2398             :       /* get track */
    2399           0 :       hit = (AliESDTOFHit*)esdTOFhits->At(ihit);
    2400             :       //if (!track || !(track->GetStatus() & AliESDtrack::kTOFout)) continue;
    2401           0 :       if (!hit) continue;
    2402             :       
    2403             :       /* calibrate TOF signal */
    2404           0 :       if (fCalibrateTOFsignal) {
    2405             :         /* get info */
    2406           0 :         index = hit->GetTOFchannel();
    2407           0 :         time = hit->GetTimeRaw();
    2408           0 :         tot = hit->GetTOT();
    2409           0 :         l0l1 = hit->GetL0L1Latency();
    2410           0 :         deltaBC = hit->GetDeltaBC();
    2411             :         /* get correction */
    2412           0 :         corr = GetTimeCorrection(index, tot, deltaBC, l0l1, timestamp);
    2413             :         /* apply correction */
    2414           0 :         time -= corr;
    2415             :         /* set new TOF signal */
    2416           0 :         hit->SetTime(time);
    2417           0 :       }
    2418             :       
    2419             :     }
    2420           0 :   }
    2421             :   else { // old TOF data structure
    2422             : 
    2423           0 :     for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) {
    2424             :    
    2425             :       /* get track */
    2426           0 :       track = event->GetTrack(itrk);
    2427           0 :       if (!track || !(track->GetStatus() & AliESDtrack::kTOFout)) continue;
    2428             :       
    2429             :       /* calibrate TOF signal */
    2430           0 :       if (fCalibrateTOFsignal) {
    2431             :         /* get info */
    2432           0 :         index = track->GetTOFCalChannel();
    2433           0 :         time = track->GetTOFsignalRaw();
    2434           0 :         tot = track->GetTOFsignalToT();
    2435           0 :         l0l1 = track->GetTOFL0L1();
    2436           0 :         deltaBC = track->GetTOFDeltaBC();
    2437             :         /* get correction */
    2438           0 :         corr = GetTimeCorrection(index, tot, deltaBC, l0l1, timestamp);
    2439             :         /* apply correction */
    2440           0 :         time -= corr;
    2441             :         /* set new TOF signal */
    2442           0 :         track->SetTOFsignal(time);
    2443           0 :       }
    2444             :     }
    2445             :     
    2446           0 :     if (fCorrectTExp) 
    2447           0 :       CalibrateTExp(event);
    2448             :   }
    2449             :   
    2450           0 : }
    2451             : 
    2452             : //----------------------------------------------------------------------------
    2453             : 
    2454             : Bool_t
    2455             : AliTOFcalib::IsChannelEnabled(Int_t index, Bool_t checkEfficiency, Bool_t checkProblematic)
    2456             : {
    2457             :   /*
    2458             :    * is channel enabled
    2459             :    */
    2460             : 
    2461         378 :   if (!fInitFlag) {
    2462           0 :     AliError("class not yet initialized. Initialize it before.");
    2463           0 :     return kTRUE;
    2464             :   }
    2465             : 
    2466             :   /* check bad status */
    2467         378 :   if (fStatus->GetPulserStatus(index) == AliTOFChannelOnlineStatusArray::kTOFPulserBad) return kFALSE;
    2468         378 :   if (fStatus->GetNoiseStatus(index) == AliTOFChannelOnlineStatusArray::kTOFNoiseBad) return kFALSE;
    2469         378 :   if (fStatus->GetHWStatus(index) == AliTOFChannelOnlineStatusArray::kTOFHWBad) return kFALSE;
    2470         756 :   if (checkEfficiency && !IsChannelEfficient(index)) return kFALSE;
    2471         756 :   if (checkProblematic && IsChannelProblematic(index)) return kFALSE;
    2472             :   
    2473             :   /* good status */
    2474         378 :   return kTRUE;
    2475             : 
    2476         378 : }
    2477             : 
    2478             : //----------------------------------------------------------------------------
    2479             : 
    2480             : Bool_t
    2481             : AliTOFcalib::IsChannelEfficient(Int_t index)
    2482             : {
    2483             :   /*
    2484             :    * is channel efficient
    2485             :    */
    2486             : 
    2487         756 :   if (!fInitFlag) {
    2488           0 :     AliError("class not yet initialized. Initialize it before.");
    2489           0 :     return kTRUE;
    2490             :   }
    2491             : 
    2492             :   /* check efficiency */
    2493         378 :   if (fReadoutEfficiency->GetBinContent(index + 1) < 0.95) return kFALSE;
    2494         378 :   return kTRUE;
    2495             : 
    2496         378 : }
    2497             : 
    2498             : //----------------------------------------------------------------------------
    2499             : 
    2500             : Bool_t
    2501             : AliTOFcalib::IsChannelProblematic(Int_t index)
    2502             : {
    2503             :   /*
    2504             :    * is channel problematic
    2505             :    */
    2506             : 
    2507         756 :   if (!fInitFlag) {
    2508           0 :     AliError("class not yet initialized. Initialize it before.");
    2509           0 :     return kTRUE;
    2510             :   }
    2511             : 
    2512             :   /* check problematic */
    2513         378 :   if (fProblematic->GetBinContent(index + 1) != 0) return kTRUE;
    2514         378 :   return kFALSE;
    2515             : 
    2516         378 : }
    2517             : 
    2518             : //----------------------------------------------------------------------------
    2519             : 
    2520             : void
    2521             : AliTOFcalib::CalibrateTExp(AliESDEvent *event) const
    2522             : {
    2523             :   /*
    2524             :    * calibrate TExp
    2525             :    */
    2526             : 
    2527             :   /* check if new TOF data structure, crash in case */
    2528           0 :   TClonesArray* esdTOFhits = event->GetESDTOFHits();
    2529           0 :   if (esdTOFhits) { 
    2530           0 :     AliFatal("This method is DEPRECATED, doing NOTHING");
    2531           0 :     return ;
    2532             :   }
    2533             : 
    2534           0 :   if (!fInitFlag) {
    2535           0 :     AliError("class not yet initialized. Initialize it before.");
    2536           0 :     return;
    2537             :   }
    2538             : 
    2539             :   /* loop over tracks */
    2540             :   AliESDtrack *track = NULL;
    2541           0 :   Double_t texp[AliPID::kSPECIESC];
    2542           0 :   for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) {
    2543             : 
    2544             :     /* get track */
    2545           0 :     track = event->GetTrack(itrk);
    2546           0 :     if (!track || !(track->GetStatus() & AliESDtrack::kTOFout)) continue;
    2547             : 
    2548             :     /* get integrated times */
    2549           0 :     track->GetIntegratedTimes(texp,AliPID::kSPECIESC);
    2550             :     /* loop over particle types and correct expected time */
    2551           0 :     for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++)
    2552           0 :       texp[ipart] += fResponseParams->EvalTExpCorr(ipart, track->P());
    2553             :     /* set integrated times */
    2554           0 :     track->SetIntegratedTimes(texp);
    2555             : 
    2556           0 :   }
    2557             : 
    2558           0 : }
    2559             : 
    2560             : //----------------------------------------------------------------------------
    2561             : 
    2562             : Double_t
    2563             : AliTOFcalib::TuneForMC(AliESDEvent *event, Double_t resolution)
    2564             : {
    2565             :   /*
    2566             :    * tune for MC
    2567             :    */
    2568             : 
    2569             :   /* check if new TOF data structure, crash in case */
    2570           0 :   TClonesArray* esdTOFhits = event->GetESDTOFHits();
    2571           0 :   if (esdTOFhits) { 
    2572           0 :     AliFatal("This method is DEPRECATED, doing NOTHING");
    2573           0 :     return 0.;
    2574             :   }
    2575             : 
    2576             :   /* get vertex spread and define T0-spread */
    2577           0 :   Double_t diamond2 = TMath::Abs(event->GetSigma2DiamondZ());
    2578           0 :   Double_t t0spread = TMath::Sqrt(diamond2) / 2.99792457999999984e-02;
    2579             :   /* generate random startTime */
    2580           0 :   Double_t startTime = gRandom->Gaus(0., t0spread);
    2581             :   /* define extra smearing for resolution */
    2582             :   Double_t defaultResolution = 80.;
    2583             :   Double_t extraSmearing = 0.;
    2584           0 :   if (resolution > defaultResolution)
    2585           0 :     extraSmearing = TMath::Sqrt(resolution * resolution - defaultResolution * defaultResolution);
    2586             : 
    2587             :   /* loop over tracks */
    2588             :   AliESDtrack *track = NULL;
    2589             :   Double_t time;
    2590           0 :   for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) {
    2591             :     /* get track */
    2592           0 :     track = event->GetTrack(itrk);
    2593           0 :     if (!track) continue;
    2594             :     /* check TOF match */
    2595           0 :     if (!track->IsOn(AliESDtrack::kTOFout)) continue;
    2596             :     /* check if channel is enabled */
    2597           0 :     if (!IsChannelEnabled(track->GetTOFCalChannel())) {
    2598             :       /* reset TOF status */
    2599           0 :       track->ResetStatus(AliESDtrack::kTOFin);
    2600           0 :       track->ResetStatus(AliESDtrack::kTOFout);
    2601           0 :       track->ResetStatus(AliESDtrack::kTOFmismatch);
    2602           0 :       track->ResetStatus(AliESDtrack::kTOFpid);
    2603           0 :     }
    2604             :     /* get original time and manipulate it */
    2605           0 :     time = track->GetTOFsignal();
    2606           0 :     time += startTime; /* add start time */
    2607           0 :     time += gRandom->Gaus(0., extraSmearing); /* extra smearing */
    2608           0 :     time -= 25.; /* remove 25 ps to center the signal */
    2609           0 :     track->SetTOFsignal(time);
    2610           0 :   }
    2611             : 
    2612             :   return startTime;
    2613           0 : }

Generated by: LCOV version 1.11