]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/TenderSupplies/AliVZEROTenderSupply.cxx
New VZERO tender supply which can be used in order to correct for the LHC clock phase...
[u/mrichter/AliRoot.git] / ANALYSIS / TenderSupplies / AliVZEROTenderSupply.cxx
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 ///////////////////////////////////////////////////////////////////////////////
18 //                                                                           //
19 //  Recalculate VZERO timing and decision using the tender                   //
20 //  (in case the LHC phase drift is updated in OCDB)                         //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include <TList.h>
25 #include <TObjString.h>
26 #include <TChain.h>
27 #include <TF1.h>
28
29 #include <AliLog.h>
30 #include <AliESDEvent.h>
31 #include <AliESDVZERO.h>
32 #include <AliCDBId.h>
33 #include <AliCDBManager.h>
34 #include <AliCDBEntry.h>
35 #include <AliTender.h>
36 #include <AliLHCClockPhase.h>
37 #include <AliVZEROCalibData.h>
38 #include <AliVZEROTriggerMask.h>
39
40 #include "AliVZEROTenderSupply.h"
41
42 ClassImp(AliVZEROTenderSupply)
43
44 AliVZEROTenderSupply::AliVZEROTenderSupply() :
45   AliTenderSupply(),
46   fCalibData(NULL),
47   fTimeSlewing(NULL),
48   fLHCClockPhase(0),
49   fDebug(kFALSE)
50 {
51   //
52   // default ctor
53   //
54 }
55
56 //_____________________________________________________
57 AliVZEROTenderSupply::AliVZEROTenderSupply(const char *name, const AliTender *tender) :
58   AliTenderSupply(name,tender),
59   fCalibData(NULL),
60   fTimeSlewing(NULL),
61   fLHCClockPhase(0),
62   fDebug(kFALSE)
63 {
64   //
65   // named ctor
66   //
67 }
68
69 //_____________________________________________________
70 void AliVZEROTenderSupply::Init()
71 {
72   //
73   // Initialise VZERO tender
74   //
75 }
76
77 //_____________________________________________________
78 void AliVZEROTenderSupply::ProcessEvent()
79 {
80   //
81   // Reapply the LHC-clock phase drift
82   //
83
84   AliESDEvent *event=fTender->GetEvent();
85   if (!event) return;
86   
87   //load gain correction if run has changed
88   if (fTender->RunChanged()){
89     if (fDebug) printf("AliVZEROTenderSupply::ProcessEvent - Run Changed (%d)\n",fTender->GetRun());
90     GetPhaseCorrection();
91
92     AliCDBEntry *entryCal = fTender->GetCDBManager()->Get("VZERO/Calib/Data",fTender->GetRun());
93     if (!entryCal) {
94       AliError("No VZERO calibration entry is found");
95       fCalibData = NULL;
96       return;
97     } else {
98       fCalibData = (AliVZEROCalibData*)entryCal->GetObject();
99       if (fDebug) printf("AliVZEROTenderSupply::Used VZERO calibration entry: %s\n",entryCal->GetId().ToString().Data());
100     }
101
102     AliCDBEntry *entrySlew = fTender->GetCDBManager()->Get("VZERO/Calib/TimeSlewing",fTender->GetRun());
103     if (!entrySlew) {
104       AliError("VZERO time slewing function is not found in OCDB !");
105       fTimeSlewing = NULL;
106       return;
107     } else {
108       fTimeSlewing = (TF1*)entrySlew->GetObject();
109       if (fDebug) printf("AliVZEROTenderSupply::Used VZERO time slewing entry: %s\n",entrySlew->GetId().ToString().Data());
110     }
111   }
112
113   if (!fCalibData || !fTimeSlewing) return;
114
115   //
116   // correct VZERO time signals and decision
117   //
118   AliESDVZERO *esdVZERO = event->GetVZEROData();
119   if (!esdVZERO) {
120     AliError("No VZERO object is found inside ESD!");
121     return;
122   }
123   if (!esdVZERO->TestBit(AliESDVZERO::kDecisionFilled)) {
124     AliWarning("VZERO offline trigger decisions were not filled in ESD, the tender supply is disabled");
125     return;
126   }
127
128   Float_t time[64];
129   for(Int_t i = 0; i < 64; ++i) {
130     time[i] = esdVZERO->GetTime(i);
131     time[i] += fLHCClockPhase;
132   }
133   esdVZERO->SetTime(time);
134
135   {
136     AliVZEROTriggerMask triggerMask;
137     triggerMask.FillMasks(esdVZERO, fCalibData, fTimeSlewing);
138   }
139
140 }
141
142 //_____________________________________________________
143 void AliVZEROTenderSupply::GetPhaseCorrection()
144 {
145   //
146   // Get Gain splines from OCDB
147   //
148
149   AliInfo("Get LHC-clock phase correction");
150
151   //
152   //find previous entry from the UserInfo
153   //
154   TTree *tree=((TChain*)fTender->GetInputData(0))->GetTree();
155   if (!tree) {
156     AliError("Tree not found in ESDhandler");
157     return;
158   }
159   
160   TList *userInfo=(TList*)tree->GetUserInfo();
161   if (!userInfo) {
162     AliError("No UserInfo found in tree");
163     return;
164   }
165
166   TList *cdbList=(TList*)userInfo->FindObject("cdbList");
167   if (!cdbList) {
168     AliError("No cdbList found in UserInfo");
169     if (AliLog::GetGlobalLogLevel()>=AliLog::kError) userInfo->Print();
170     return;
171   }
172
173   Float_t oldPhase = 0;
174
175   TIter nextCDB(cdbList);
176   TObjString *os=0x0;
177   while ( (os=(TObjString*)nextCDB()) ){
178     if (!(os->GetString().Contains("GRP/Calib/LHCClockPhase"))) continue;
179     AliCDBId *id=AliCDBId::MakeFromString(os->GetString());
180     
181     AliCDBEntry *entry=fTender->GetCDBManager()->Get(*id);
182     if (!entry) {
183       AliError("The previous LHC-clock phase entry is not found");
184       delete id;
185       return;
186     }
187     
188     if (fDebug) printf("AliVZEROTenderSupply::Used old LHC-clock phase entry: %s\n",entry->GetId().ToString().Data());
189     
190     AliLHCClockPhase *phase = (AliLHCClockPhase*)entry->GetObject();
191     if (!phase) {
192       AliError("Phase object is not found in the calibration entry");
193       delete id;
194       return;
195     }
196
197     oldPhase = phase->GetMeanPhase();
198
199     delete id;
200     break;
201   }
202
203   //
204   //new LHC-clock phase entry
205   //
206   Float_t newPhase = 0;
207   AliCDBEntry *entryNew=fTender->GetCDBManager()->Get("GRP/Calib/LHCClockPhase",fTender->GetRun());
208   if (!entryNew) {
209     AliError("No new LHC-clock phase calibration entry is found");
210     return;
211   }
212   if (fDebug) printf("AliVZEROTenderSupply::Used new LHC-clock phase entry: %s\n",entryNew->GetId().ToString().Data());
213   
214   AliLHCClockPhase *phase2 = (AliLHCClockPhase*)entryNew->GetObject();
215   if (!phase2) {
216     AliError("Phase object is not found in the calibration entry");
217     return;
218   }
219
220   newPhase = phase2->GetMeanPhase();
221
222   fLHCClockPhase = newPhase - oldPhase;
223 }