]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TENDER/TenderSupplies/AliVZEROTenderSupply.cxx
Split: Tender*, EventMixing out of ANALYSIS
[u/mrichter/AliRoot.git] / TENDER / 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 #include <AliVZEROReconstructor.h>
40
41 #include "AliVZEROTenderSupply.h"
42
43 ClassImp(AliVZEROTenderSupply)
44
45 AliVZEROTenderSupply::AliVZEROTenderSupply() :
46   AliTenderSupply(),
47   fCalibData(NULL),
48   fTimeSlewing(NULL),
49   fRecoParam(NULL),
50   fLHCClockPhase(0),
51   fDebug(kFALSE)
52 {
53   //
54   // default ctor
55   //
56 }
57
58 //_____________________________________________________
59 AliVZEROTenderSupply::AliVZEROTenderSupply(const char *name, const AliTender *tender) :
60   AliTenderSupply(name,tender),
61   fCalibData(NULL),
62   fTimeSlewing(NULL),
63   fRecoParam(NULL),
64   fLHCClockPhase(0),
65   fDebug(kFALSE)
66 {
67   //
68   // named ctor
69   //
70 }
71
72 //_____________________________________________________
73 void AliVZEROTenderSupply::Init()
74 {
75   //
76   // Initialise VZERO tender
77   //
78 }
79
80 //_____________________________________________________
81 void AliVZEROTenderSupply::ProcessEvent()
82 {
83   //
84   // Reapply the LHC-clock phase drift
85   //
86
87   AliESDEvent *event=fTender->GetEvent();
88   if (!event) return;
89   
90   //load gain correction if run has changed
91   if (fTender->RunChanged()){
92     if (fDebug) printf("AliVZEROTenderSupply::ProcessEvent - Run Changed (%d)\n",fTender->GetRun());
93     GetPhaseCorrection();
94
95     AliCDBEntry *entryGeom = fTender->GetCDBManager()->Get("GRP/Geometry/Data",fTender->GetRun());
96     if (!entryGeom) {
97       AliError("No geometry entry is found");
98       return;
99     } else {
100       if (fDebug) printf("AliVZEROTenderSupply::Used geometry entry: %s\n",entryGeom->GetId().ToString().Data());
101     }
102
103     AliCDBEntry *entryCal = fTender->GetCDBManager()->Get("VZERO/Calib/Data",fTender->GetRun());
104     if (!entryCal) {
105       AliError("No VZERO calibration entry is found");
106       fCalibData = NULL;
107       return;
108     } else {
109       fCalibData = (AliVZEROCalibData*)entryCal->GetObject();
110       if (fDebug) printf("AliVZEROTenderSupply::Used VZERO calibration entry: %s\n",entryCal->GetId().ToString().Data());
111     }
112
113     AliCDBEntry *entrySlew = fTender->GetCDBManager()->Get("VZERO/Calib/TimeSlewing",fTender->GetRun());
114     if (!entrySlew) {
115       AliError("VZERO time slewing function is not found in OCDB !");
116       fTimeSlewing = NULL;
117       return;
118     } else {
119       fTimeSlewing = (TF1*)entrySlew->GetObject();
120       if (fDebug) printf("AliVZEROTenderSupply::Used VZERO time slewing entry: %s\n",entrySlew->GetId().ToString().Data());
121     }
122
123     AliCDBEntry *entryRecoParam = fTender->GetCDBManager()->Get("VZERO/Calib/RecoParam",fTender->GetRun());
124     if (!entryRecoParam) {
125       AliError("VZERO reco-param object is not found in OCDB !");
126       fRecoParam = NULL;
127       return;
128     } else {
129       TObjArray *recoParamArr = (TObjArray*)entryRecoParam->GetObject();
130       if (fDebug) printf("AliVZEROTenderSupply::Used VZERO reco-param entry: %s\n",entryRecoParam->GetId().ToString().Data());
131       fRecoParam = NULL;
132       for(Int_t i = 0; i < recoParamArr->GetEntriesFast(); i++) {
133         AliVZERORecoParam *par = (AliVZERORecoParam*)recoParamArr->At(i);
134         if (!par) continue;
135         if (par->IsDefault()) fRecoParam = par;
136       }
137       if (!fRecoParam) AliError("No default VZERO reco-param object is found in OCDB !");
138     }
139   }
140
141   if (!fCalibData || !fTimeSlewing || !fRecoParam) {
142     AliWarning("VZERO calibration objects not found!");
143     return;
144   }
145   //
146   // correct VZERO time signals and decision
147   //
148   AliESDVZERO *esdVZERO = event->GetVZEROData();
149   if (!esdVZERO) {
150     AliError("No VZERO object is found inside ESD!");
151     return;
152   }
153   if (!esdVZERO->TestBit(AliESDVZERO::kDecisionFilled)) {
154     AliWarning("VZERO offline trigger decisions were not filled in ESD, the tender supply is disabled");
155     return;
156   }
157
158   if (fDebug) printf("LHC-clock phase correction: %f\n",fLHCClockPhase);
159
160   if (fDebug) printf("Original VZERO decision %d (%f ns) and %d (%f ns)\n",
161                      esdVZERO->GetV0ADecision(),esdVZERO->GetV0ATime(),
162                      esdVZERO->GetV0CDecision(),esdVZERO->GetV0CTime());
163   Float_t time[64];
164   for(Int_t i = 0; i < 64; ++i) {
165     time[i] = esdVZERO->GetTime(i);
166     if (time[i] > (AliVZEROReconstructor::kInvalidTime + 1e-6))
167       time[i] += fLHCClockPhase;
168   }
169   esdVZERO->SetTime(time);
170
171   {
172     AliVZEROTriggerMask triggerMask;
173     triggerMask.SetRecoParam(fRecoParam);
174     triggerMask.FillMasks(esdVZERO, fCalibData, fTimeSlewing);
175   }
176   if (fDebug) printf("Modified VZERO decision %d (%f ns) and %d (%f ns)\n",
177                      esdVZERO->GetV0ADecision(),esdVZERO->GetV0ATime(),
178                      esdVZERO->GetV0CDecision(),esdVZERO->GetV0CTime());
179
180 }
181
182 //_____________________________________________________
183 void AliVZEROTenderSupply::GetPhaseCorrection()
184 {
185   //
186   // Get Gain splines from OCDB
187   //
188
189   AliInfo("Get LHC-clock phase correction");
190
191   //
192   //find previous entry from the UserInfo
193   //
194   TTree *tree=((TChain*)fTender->GetInputData(0))->GetTree();
195   if (!tree) {
196     AliError("Tree not found in ESDhandler");
197     return;
198   }
199   
200   TList *userInfo=(TList*)tree->GetUserInfo();
201   if (!userInfo) {
202     AliError("No UserInfo found in tree");
203     return;
204   }
205
206   TList *cdbList=(TList*)userInfo->FindObject("cdbList");
207   if (!cdbList) {
208     AliError("No cdbList found in UserInfo");
209     if (AliLog::GetGlobalLogLevel()>=AliLog::kError) userInfo->Print();
210     return;
211   }
212
213   Float_t oldPhase = 0;
214
215   TIter nextCDB(cdbList);
216   TObjString *os=0x0;
217   while ( (os=(TObjString*)nextCDB()) ){
218     if (!(os->GetString().Contains("GRP/Calib/LHCClockPhase"))) continue;
219     AliCDBId *id=AliCDBId::MakeFromString(os->GetString());
220     
221     AliCDBEntry *entry=fTender->GetCDBManager()->Get(*id);
222     if (!entry) {
223       AliError("The previous LHC-clock phase entry is not found");
224       delete id;
225       return;
226     }
227     
228     if (fDebug) printf("AliVZEROTenderSupply::Used old LHC-clock phase entry: %s\n",entry->GetId().ToString().Data());
229     
230     AliLHCClockPhase *phase = (AliLHCClockPhase*)entry->GetObject();
231     if (!phase) {
232       AliError("Phase object is not found in the calibration entry");
233       delete id;
234       return;
235     }
236
237     oldPhase = phase->GetMeanPhase();
238
239     delete id;
240     break;
241   }
242
243   //
244   //new LHC-clock phase entry
245   //
246   Float_t newPhase = 0;
247   AliCDBEntry *entryNew=fTender->GetCDBManager()->Get("GRP/Calib/LHCClockPhase",fTender->GetRun());
248   if (!entryNew) {
249     AliError("No new LHC-clock phase calibration entry is found");
250     return;
251   }
252   if (fDebug) printf("AliVZEROTenderSupply::Used new LHC-clock phase entry: %s\n",entryNew->GetId().ToString().Data());
253   
254   AliLHCClockPhase *phase2 = (AliLHCClockPhase*)entryNew->GetObject();
255   if (!phase2) {
256     AliError("Phase object is not found in the calibration entry");
257     return;
258   }
259
260   newPhase = phase2->GetMeanPhase();
261
262   fLHCClockPhase = newPhase - oldPhase;
263 }