ROOT logo
/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/


///////////////////////////////////////////////////////////////////////////////
//                                                                           //
//  Recalculate VZERO timing and decision using the tender                   //
//  (in case the LHC phase drift is updated in OCDB)                         //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

#include <TList.h>
#include <TObjString.h>
#include <TChain.h>
#include <TF1.h>

#include <AliLog.h>
#include <AliESDEvent.h>
#include <AliESDVZERO.h>
#include <AliCDBId.h>
#include <AliCDBManager.h>
#include <AliCDBEntry.h>
#include <AliTender.h>
#include <AliLHCClockPhase.h>
#include <AliVZEROCalibData.h>
#include <AliVZEROTriggerMask.h>
#include <AliVZEROReconstructor.h>

#include "AliVZEROTenderSupply.h"

ClassImp(AliVZEROTenderSupply)

AliVZEROTenderSupply::AliVZEROTenderSupply() :
  AliTenderSupply(),
  fCalibData(NULL),
  fTimeSlewing(NULL),
  fRecoParam(NULL),
  fLHCClockPhase(0),
  fDebug(kFALSE)
{
  //
  // default ctor
  //
}

//_____________________________________________________
AliVZEROTenderSupply::AliVZEROTenderSupply(const char *name, const AliTender *tender) :
  AliTenderSupply(name,tender),
  fCalibData(NULL),
  fTimeSlewing(NULL),
  fRecoParam(NULL),
  fLHCClockPhase(0),
  fDebug(kFALSE)
{
  //
  // named ctor
  //
}

//_____________________________________________________
void AliVZEROTenderSupply::Init()
{
  //
  // Initialise VZERO tender
  //
}

//_____________________________________________________
void AliVZEROTenderSupply::ProcessEvent()
{
  //
  // Reapply the LHC-clock phase drift
  //

  AliESDEvent *event=fTender->GetEvent();
  if (!event) return;
  
  //load gain correction if run has changed
  if (fTender->RunChanged()){
    if (fDebug) printf("AliVZEROTenderSupply::ProcessEvent - Run Changed (%d)\n",fTender->GetRun());
    GetPhaseCorrection();

    AliCDBEntry *entryGeom = fTender->GetCDBManager()->Get("GRP/Geometry/Data",fTender->GetRun());
    if (!entryGeom) {
      AliError("No geometry entry is found");
      return;
    } else {
      if (fDebug) printf("AliVZEROTenderSupply::Used geometry entry: %s\n",entryGeom->GetId().ToString().Data());
    }

    AliCDBEntry *entryCal = fTender->GetCDBManager()->Get("VZERO/Calib/Data",fTender->GetRun());
    if (!entryCal) {
      AliError("No VZERO calibration entry is found");
      fCalibData = NULL;
      return;
    } else {
      fCalibData = (AliVZEROCalibData*)entryCal->GetObject();
      if (fDebug) printf("AliVZEROTenderSupply::Used VZERO calibration entry: %s\n",entryCal->GetId().ToString().Data());
    }

    AliCDBEntry *entrySlew = fTender->GetCDBManager()->Get("VZERO/Calib/TimeSlewing",fTender->GetRun());
    if (!entrySlew) {
      AliError("VZERO time slewing function is not found in OCDB !");
      fTimeSlewing = NULL;
      return;
    } else {
      fTimeSlewing = (TF1*)entrySlew->GetObject();
      if (fDebug) printf("AliVZEROTenderSupply::Used VZERO time slewing entry: %s\n",entrySlew->GetId().ToString().Data());
    }

    AliCDBEntry *entryRecoParam = fTender->GetCDBManager()->Get("VZERO/Calib/RecoParam",fTender->GetRun());
    if (!entryRecoParam) {
      AliError("VZERO reco-param object is not found in OCDB !");
      fRecoParam = NULL;
      return;
    } else {
      TObjArray *recoParamArr = (TObjArray*)entryRecoParam->GetObject();
      if (fDebug) printf("AliVZEROTenderSupply::Used VZERO reco-param entry: %s\n",entryRecoParam->GetId().ToString().Data());
      fRecoParam = NULL;
      for(Int_t i = 0; i < recoParamArr->GetEntriesFast(); i++) {
	AliVZERORecoParam *par = (AliVZERORecoParam*)recoParamArr->At(i);
	if (!par) continue;
	if (par->IsDefault()) fRecoParam = par;
      }
      if (!fRecoParam) AliError("No default VZERO reco-param object is found in OCDB !");
    }
  }

  if (!fCalibData || !fTimeSlewing || !fRecoParam) {
    AliWarning("VZERO calibration objects not found!");
    return;
  }
  //
  // correct VZERO time signals and decision
  //
  AliESDVZERO *esdVZERO = event->GetVZEROData();
  if (!esdVZERO) {
    AliError("No VZERO object is found inside ESD!");
    return;
  }
  if (!esdVZERO->TestBit(AliESDVZERO::kDecisionFilled)) {
    AliWarning("VZERO offline trigger decisions were not filled in ESD, the tender supply is disabled");
    return;
  }

  if (fDebug) printf("LHC-clock phase correction: %f\n",fLHCClockPhase);

  if (fDebug) printf("Original VZERO decision %d (%f ns) and %d (%f ns)\n",
		     esdVZERO->GetV0ADecision(),esdVZERO->GetV0ATime(),
		     esdVZERO->GetV0CDecision(),esdVZERO->GetV0CTime());
  Float_t time[64];
  for(Int_t i = 0; i < 64; ++i) {
    time[i] = esdVZERO->GetTime(i);
    if (time[i] > (AliVZEROReconstructor::kInvalidTime + 1e-6))
      time[i] += fLHCClockPhase;
  }
  esdVZERO->SetTime(time);

  {
    AliVZEROTriggerMask triggerMask;
    triggerMask.SetRecoParam(fRecoParam);
    triggerMask.FillMasks(esdVZERO, fCalibData, fTimeSlewing);
  }
  if (fDebug) printf("Modified VZERO decision %d (%f ns) and %d (%f ns)\n",
		     esdVZERO->GetV0ADecision(),esdVZERO->GetV0ATime(),
		     esdVZERO->GetV0CDecision(),esdVZERO->GetV0CTime());

}

//_____________________________________________________
void AliVZEROTenderSupply::GetPhaseCorrection()
{
  //
  // Get Gain splines from OCDB
  //

  AliInfo("Get LHC-clock phase correction");

  //
  //find previous entry from the UserInfo
  //
  TTree *tree=((TChain*)fTender->GetInputData(0))->GetTree();
  if (!tree) {
    AliError("Tree not found in ESDhandler");
    return;
  }
  
  TList *userInfo=(TList*)tree->GetUserInfo();
  if (!userInfo) {
    AliError("No UserInfo found in tree");
    return;
  }

  TList *cdbList=(TList*)userInfo->FindObject("cdbList");
  if (!cdbList) {
    AliError("No cdbList found in UserInfo");
    if (AliLog::GetGlobalLogLevel()>=AliLog::kError) userInfo->Print();
    return;
  }

  Float_t oldPhase = 0;

  TIter nextCDB(cdbList);
  TObjString *os=0x0;
  while ( (os=(TObjString*)nextCDB()) ){
    if (!(os->GetString().Contains("GRP/Calib/LHCClockPhase"))) continue;
    AliCDBId *id=AliCDBId::MakeFromString(os->GetString());
    
    AliCDBEntry *entry=fTender->GetCDBManager()->Get(*id);
    if (!entry) {
      AliError("The previous LHC-clock phase entry is not found");
      delete id;
      return;
    }
    
    if (fDebug) printf("AliVZEROTenderSupply::Used old LHC-clock phase entry: %s\n",entry->GetId().ToString().Data());
    
    AliLHCClockPhase *phase = (AliLHCClockPhase*)entry->GetObject();
    if (!phase) {
      AliError("Phase object is not found in the calibration entry");
      delete id;
      return;
    }

    oldPhase = phase->GetMeanPhase();

    delete id;
    break;
  }

  //
  //new LHC-clock phase entry
  //
  Float_t newPhase = 0;
  AliCDBEntry *entryNew=fTender->GetCDBManager()->Get("GRP/Calib/LHCClockPhase",fTender->GetRun());
  if (!entryNew) {
    AliError("No new LHC-clock phase calibration entry is found");
    return;
  }
  if (fDebug) printf("AliVZEROTenderSupply::Used new LHC-clock phase entry: %s\n",entryNew->GetId().ToString().Data());
  
  AliLHCClockPhase *phase2 = (AliLHCClockPhase*)entryNew->GetObject();
  if (!phase2) {
    AliError("Phase object is not found in the calibration entry");
    return;
  }

  newPhase = phase2->GetMeanPhase();

  fLHCClockPhase = newPhase - oldPhase;
}
 AliVZEROTenderSupply.cxx:1
 AliVZEROTenderSupply.cxx:2
 AliVZEROTenderSupply.cxx:3
 AliVZEROTenderSupply.cxx:4
 AliVZEROTenderSupply.cxx:5
 AliVZEROTenderSupply.cxx:6
 AliVZEROTenderSupply.cxx:7
 AliVZEROTenderSupply.cxx:8
 AliVZEROTenderSupply.cxx:9
 AliVZEROTenderSupply.cxx:10
 AliVZEROTenderSupply.cxx:11
 AliVZEROTenderSupply.cxx:12
 AliVZEROTenderSupply.cxx:13
 AliVZEROTenderSupply.cxx:14
 AliVZEROTenderSupply.cxx:15
 AliVZEROTenderSupply.cxx:16
 AliVZEROTenderSupply.cxx:17
 AliVZEROTenderSupply.cxx:18
 AliVZEROTenderSupply.cxx:19
 AliVZEROTenderSupply.cxx:20
 AliVZEROTenderSupply.cxx:21
 AliVZEROTenderSupply.cxx:22
 AliVZEROTenderSupply.cxx:23
 AliVZEROTenderSupply.cxx:24
 AliVZEROTenderSupply.cxx:25
 AliVZEROTenderSupply.cxx:26
 AliVZEROTenderSupply.cxx:27
 AliVZEROTenderSupply.cxx:28
 AliVZEROTenderSupply.cxx:29
 AliVZEROTenderSupply.cxx:30
 AliVZEROTenderSupply.cxx:31
 AliVZEROTenderSupply.cxx:32
 AliVZEROTenderSupply.cxx:33
 AliVZEROTenderSupply.cxx:34
 AliVZEROTenderSupply.cxx:35
 AliVZEROTenderSupply.cxx:36
 AliVZEROTenderSupply.cxx:37
 AliVZEROTenderSupply.cxx:38
 AliVZEROTenderSupply.cxx:39
 AliVZEROTenderSupply.cxx:40
 AliVZEROTenderSupply.cxx:41
 AliVZEROTenderSupply.cxx:42
 AliVZEROTenderSupply.cxx:43
 AliVZEROTenderSupply.cxx:44
 AliVZEROTenderSupply.cxx:45
 AliVZEROTenderSupply.cxx:46
 AliVZEROTenderSupply.cxx:47
 AliVZEROTenderSupply.cxx:48
 AliVZEROTenderSupply.cxx:49
 AliVZEROTenderSupply.cxx:50
 AliVZEROTenderSupply.cxx:51
 AliVZEROTenderSupply.cxx:52
 AliVZEROTenderSupply.cxx:53
 AliVZEROTenderSupply.cxx:54
 AliVZEROTenderSupply.cxx:55
 AliVZEROTenderSupply.cxx:56
 AliVZEROTenderSupply.cxx:57
 AliVZEROTenderSupply.cxx:58
 AliVZEROTenderSupply.cxx:59
 AliVZEROTenderSupply.cxx:60
 AliVZEROTenderSupply.cxx:61
 AliVZEROTenderSupply.cxx:62
 AliVZEROTenderSupply.cxx:63
 AliVZEROTenderSupply.cxx:64
 AliVZEROTenderSupply.cxx:65
 AliVZEROTenderSupply.cxx:66
 AliVZEROTenderSupply.cxx:67
 AliVZEROTenderSupply.cxx:68
 AliVZEROTenderSupply.cxx:69
 AliVZEROTenderSupply.cxx:70
 AliVZEROTenderSupply.cxx:71
 AliVZEROTenderSupply.cxx:72
 AliVZEROTenderSupply.cxx:73
 AliVZEROTenderSupply.cxx:74
 AliVZEROTenderSupply.cxx:75
 AliVZEROTenderSupply.cxx:76
 AliVZEROTenderSupply.cxx:77
 AliVZEROTenderSupply.cxx:78
 AliVZEROTenderSupply.cxx:79
 AliVZEROTenderSupply.cxx:80
 AliVZEROTenderSupply.cxx:81
 AliVZEROTenderSupply.cxx:82
 AliVZEROTenderSupply.cxx:83
 AliVZEROTenderSupply.cxx:84
 AliVZEROTenderSupply.cxx:85
 AliVZEROTenderSupply.cxx:86
 AliVZEROTenderSupply.cxx:87
 AliVZEROTenderSupply.cxx:88
 AliVZEROTenderSupply.cxx:89
 AliVZEROTenderSupply.cxx:90
 AliVZEROTenderSupply.cxx:91
 AliVZEROTenderSupply.cxx:92
 AliVZEROTenderSupply.cxx:93
 AliVZEROTenderSupply.cxx:94
 AliVZEROTenderSupply.cxx:95
 AliVZEROTenderSupply.cxx:96
 AliVZEROTenderSupply.cxx:97
 AliVZEROTenderSupply.cxx:98
 AliVZEROTenderSupply.cxx:99
 AliVZEROTenderSupply.cxx:100
 AliVZEROTenderSupply.cxx:101
 AliVZEROTenderSupply.cxx:102
 AliVZEROTenderSupply.cxx:103
 AliVZEROTenderSupply.cxx:104
 AliVZEROTenderSupply.cxx:105
 AliVZEROTenderSupply.cxx:106
 AliVZEROTenderSupply.cxx:107
 AliVZEROTenderSupply.cxx:108
 AliVZEROTenderSupply.cxx:109
 AliVZEROTenderSupply.cxx:110
 AliVZEROTenderSupply.cxx:111
 AliVZEROTenderSupply.cxx:112
 AliVZEROTenderSupply.cxx:113
 AliVZEROTenderSupply.cxx:114
 AliVZEROTenderSupply.cxx:115
 AliVZEROTenderSupply.cxx:116
 AliVZEROTenderSupply.cxx:117
 AliVZEROTenderSupply.cxx:118
 AliVZEROTenderSupply.cxx:119
 AliVZEROTenderSupply.cxx:120
 AliVZEROTenderSupply.cxx:121
 AliVZEROTenderSupply.cxx:122
 AliVZEROTenderSupply.cxx:123
 AliVZEROTenderSupply.cxx:124
 AliVZEROTenderSupply.cxx:125
 AliVZEROTenderSupply.cxx:126
 AliVZEROTenderSupply.cxx:127
 AliVZEROTenderSupply.cxx:128
 AliVZEROTenderSupply.cxx:129
 AliVZEROTenderSupply.cxx:130
 AliVZEROTenderSupply.cxx:131
 AliVZEROTenderSupply.cxx:132
 AliVZEROTenderSupply.cxx:133
 AliVZEROTenderSupply.cxx:134
 AliVZEROTenderSupply.cxx:135
 AliVZEROTenderSupply.cxx:136
 AliVZEROTenderSupply.cxx:137
 AliVZEROTenderSupply.cxx:138
 AliVZEROTenderSupply.cxx:139
 AliVZEROTenderSupply.cxx:140
 AliVZEROTenderSupply.cxx:141
 AliVZEROTenderSupply.cxx:142
 AliVZEROTenderSupply.cxx:143
 AliVZEROTenderSupply.cxx:144
 AliVZEROTenderSupply.cxx:145
 AliVZEROTenderSupply.cxx:146
 AliVZEROTenderSupply.cxx:147
 AliVZEROTenderSupply.cxx:148
 AliVZEROTenderSupply.cxx:149
 AliVZEROTenderSupply.cxx:150
 AliVZEROTenderSupply.cxx:151
 AliVZEROTenderSupply.cxx:152
 AliVZEROTenderSupply.cxx:153
 AliVZEROTenderSupply.cxx:154
 AliVZEROTenderSupply.cxx:155
 AliVZEROTenderSupply.cxx:156
 AliVZEROTenderSupply.cxx:157
 AliVZEROTenderSupply.cxx:158
 AliVZEROTenderSupply.cxx:159
 AliVZEROTenderSupply.cxx:160
 AliVZEROTenderSupply.cxx:161
 AliVZEROTenderSupply.cxx:162
 AliVZEROTenderSupply.cxx:163
 AliVZEROTenderSupply.cxx:164
 AliVZEROTenderSupply.cxx:165
 AliVZEROTenderSupply.cxx:166
 AliVZEROTenderSupply.cxx:167
 AliVZEROTenderSupply.cxx:168
 AliVZEROTenderSupply.cxx:169
 AliVZEROTenderSupply.cxx:170
 AliVZEROTenderSupply.cxx:171
 AliVZEROTenderSupply.cxx:172
 AliVZEROTenderSupply.cxx:173
 AliVZEROTenderSupply.cxx:174
 AliVZEROTenderSupply.cxx:175
 AliVZEROTenderSupply.cxx:176
 AliVZEROTenderSupply.cxx:177
 AliVZEROTenderSupply.cxx:178
 AliVZEROTenderSupply.cxx:179
 AliVZEROTenderSupply.cxx:180
 AliVZEROTenderSupply.cxx:181
 AliVZEROTenderSupply.cxx:182
 AliVZEROTenderSupply.cxx:183
 AliVZEROTenderSupply.cxx:184
 AliVZEROTenderSupply.cxx:185
 AliVZEROTenderSupply.cxx:186
 AliVZEROTenderSupply.cxx:187
 AliVZEROTenderSupply.cxx:188
 AliVZEROTenderSupply.cxx:189
 AliVZEROTenderSupply.cxx:190
 AliVZEROTenderSupply.cxx:191
 AliVZEROTenderSupply.cxx:192
 AliVZEROTenderSupply.cxx:193
 AliVZEROTenderSupply.cxx:194
 AliVZEROTenderSupply.cxx:195
 AliVZEROTenderSupply.cxx:196
 AliVZEROTenderSupply.cxx:197
 AliVZEROTenderSupply.cxx:198
 AliVZEROTenderSupply.cxx:199
 AliVZEROTenderSupply.cxx:200
 AliVZEROTenderSupply.cxx:201
 AliVZEROTenderSupply.cxx:202
 AliVZEROTenderSupply.cxx:203
 AliVZEROTenderSupply.cxx:204
 AliVZEROTenderSupply.cxx:205
 AliVZEROTenderSupply.cxx:206
 AliVZEROTenderSupply.cxx:207
 AliVZEROTenderSupply.cxx:208
 AliVZEROTenderSupply.cxx:209
 AliVZEROTenderSupply.cxx:210
 AliVZEROTenderSupply.cxx:211
 AliVZEROTenderSupply.cxx:212
 AliVZEROTenderSupply.cxx:213
 AliVZEROTenderSupply.cxx:214
 AliVZEROTenderSupply.cxx:215
 AliVZEROTenderSupply.cxx:216
 AliVZEROTenderSupply.cxx:217
 AliVZEROTenderSupply.cxx:218
 AliVZEROTenderSupply.cxx:219
 AliVZEROTenderSupply.cxx:220
 AliVZEROTenderSupply.cxx:221
 AliVZEROTenderSupply.cxx:222
 AliVZEROTenderSupply.cxx:223
 AliVZEROTenderSupply.cxx:224
 AliVZEROTenderSupply.cxx:225
 AliVZEROTenderSupply.cxx:226
 AliVZEROTenderSupply.cxx:227
 AliVZEROTenderSupply.cxx:228
 AliVZEROTenderSupply.cxx:229
 AliVZEROTenderSupply.cxx:230
 AliVZEROTenderSupply.cxx:231
 AliVZEROTenderSupply.cxx:232
 AliVZEROTenderSupply.cxx:233
 AliVZEROTenderSupply.cxx:234
 AliVZEROTenderSupply.cxx:235
 AliVZEROTenderSupply.cxx:236
 AliVZEROTenderSupply.cxx:237
 AliVZEROTenderSupply.cxx:238
 AliVZEROTenderSupply.cxx:239
 AliVZEROTenderSupply.cxx:240
 AliVZEROTenderSupply.cxx:241
 AliVZEROTenderSupply.cxx:242
 AliVZEROTenderSupply.cxx:243
 AliVZEROTenderSupply.cxx:244
 AliVZEROTenderSupply.cxx:245
 AliVZEROTenderSupply.cxx:246
 AliVZEROTenderSupply.cxx:247
 AliVZEROTenderSupply.cxx:248
 AliVZEROTenderSupply.cxx:249
 AliVZEROTenderSupply.cxx:250
 AliVZEROTenderSupply.cxx:251
 AliVZEROTenderSupply.cxx:252
 AliVZEROTenderSupply.cxx:253
 AliVZEROTenderSupply.cxx:254
 AliVZEROTenderSupply.cxx:255
 AliVZEROTenderSupply.cxx:256
 AliVZEROTenderSupply.cxx:257
 AliVZEROTenderSupply.cxx:258
 AliVZEROTenderSupply.cxx:259
 AliVZEROTenderSupply.cxx:260
 AliVZEROTenderSupply.cxx:261
 AliVZEROTenderSupply.cxx:262
 AliVZEROTenderSupply.cxx:263