new shifter histogram implemented HeaderBCID vs TRM BC ID
[u/mrichter/AliRoot.git] / T0 / AliT0PreprocessorOffline.cxx
CommitLineData
dd162229 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// T0 preprocessor:
20// 2) takes data after pass0 ,
21// processes it, and stores either to OCDB .
22
23
24#include "AliT0PreprocessorOffline.h"
65521adf 25#include "AliT0RecoParam.h"
dd162229 26#include "AliT0CalibTimeEq.h"
27#include "AliCDBStorage.h"
28#include "AliCDBMetaData.h"
29#include "AliCDBManager.h"
612737bb 30#include "AliCTPTimeParams.h"
31#include "AliLHCClockPhase.h"
65521adf 32#include "AliT0CalibSeasonTimeShift.h"
612737bb 33#include "AliT0CalibLatency.h"
dd162229 34#include "AliCDBEntry.h"
35#include "AliLog.h"
36
37#include <TTimeStamp.h>
38#include <TFile.h>
39#include <TObjString.h>
40#include <TNamed.h>
41#include "TClass.h"
42
43
44ClassImp(AliT0PreprocessorOffline)
45
46//____________________________________________________
47AliT0PreprocessorOffline::AliT0PreprocessorOffline():
65521adf 48TNamed("AliT0PreprocessorOffline","AliT0PreprocessorOffline"),
49 startRun(0), // start Run - used to make fast selection in THnSparse
50 endRun(0), // end Run - used to make fast selection in THnSparse
51 startTime(0), // startTime - used to make fast selection in THnSparse
52 endTime(0), // endTime - used to make fast selection in THnSparse
53 ocdbStorage("") // path to the OCDB storage
54
dd162229 55{
56 //constructor
57}
58//____________________________________________________
59
60AliT0PreprocessorOffline::~AliT0PreprocessorOffline()
61{
62 //destructor
63
64}
65//____________________________________________________
65521adf 66void AliT0PreprocessorOffline::Process(TString filePhysName, Int_t ustartRun, Int_t uendRun, TString pocdbStorage)
67{
e24f582d 68 CalibOffsetChannels(filePhysName, ustartRun, uendRun, pocdbStorage);
65521adf 69 CalibT0sPosition(filePhysName, ustartRun, uendRun, pocdbStorage);
70}
dd162229 71//____________________________________________________
72
65521adf 73void AliT0PreprocessorOffline::CalibOffsetChannels(TString filePhysName, Int_t ustartRun, Int_t uendRun, TString pocdbStorage)
dd162229 74{
75
b0ab3f59 76 Float_t zero_timecdb[24]={0};
77 Float_t *timecdb = zero_timecdb;
78 Float_t *cfdvalue = zero_timecdb;
65521adf 79 Int_t badpmt=0;
dd162229 80 //Processing data from DAQ Physics run
81 AliInfo("Processing Time Offset between channels");
b0ab3f59 82 if (pocdbStorage.Length()>0) ocdbStorage=pocdbStorage;
83 else
84 ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
85 AliCDBEntry *entry = AliCDBManager::Instance()->Get("GRP/CTP/CTPtiming");
86 if (!entry) AliFatal("CTP timing parameters are not found in OCDB !");
87 AliCTPTimeParams *ctpParams = (AliCTPTimeParams*)entry->GetObject();
88 Float_t l1Delay = (Float_t)ctpParams->GetDelayL1L0()*25.0;
89
90 AliCDBEntry *entry1 = AliCDBManager::Instance()->Get("GRP/CTP/TimeAlign");
91 if (!entry1) AliFatal("CTP time-alignment is not found in OCDB !");
92 AliCTPTimeParams *ctpTimeAlign = (AliCTPTimeParams*)entry1->GetObject();
93 l1Delay += ((Float_t)ctpTimeAlign->GetDelayL1L0()*25.0);
94
95 AliCDBEntry *entry4 = AliCDBManager::Instance()->Get("GRP/Calib/LHCClockPhase");
96 if (!entry4) AliFatal("LHC clock-phase shift is not found in OCDB !");
97 AliLHCClockPhase *phase = (AliLHCClockPhase*)entry4->GetObject();
98 Float_t fGRPdelays = l1Delay - phase->GetMeanPhase();
593a6aab 99
b0ab3f59 100 AliCDBEntry *entryL = AliCDBManager::Instance()->Get("T0/Calib/Latency");
593a6aab 101 if (!entryL) AliFatal(" T0 Latency is not found in OCDB !");
b0ab3f59 102 AliT0CalibLatency *lat = (AliT0CalibLatency*)entryL->GetObject();
103 Float_t fLatencyHPTDC = lat->GetLatencyHPTDC();
104 Float_t fLatencyL1 = lat->GetLatencyL1();
593a6aab 105
b0ab3f59 106 AliCDBEntry *entryCalib = AliCDBManager::Instance()->Get("T0/Calib/TimeDelay");
107 if(!entryCalib) {
108 AliWarning(Form("Cannot find any AliCDBEntry for [Calib, TimeDelay]!"));
109 }
110 else
dd162229 111 {
b0ab3f59 112 AliT0CalibTimeEq *clb = (AliT0CalibTimeEq*)entryCalib->GetObject();
612737bb 113 timecdb = clb->GetTimeEq();
114 cfdvalue = clb->GetCFDvalue();
115 for (Int_t i=0; i<24; i++) {
116 if( cfdvalue[i] < 500 ) cfdvalue[i] =( 1000.*fLatencyHPTDC - 1000.*fLatencyL1 + 1000.*fGRPdelays)/24.4;
117 printf("Calc mean CFD time %i %f \n",i,cfdvalue[i]);
118 }
b0ab3f59 119 }
120 AliCDBEntry *entryCalibreco = AliCDBManager::Instance()->Get("T0/Calib/RecoParam");
121 if(entryCalibreco) {
122 AliT0RecoParam *rpr = (AliT0RecoParam*) entryCalibreco->GetObject();
123 badpmt = rpr->GetRefPoint();
124 printf(" bad PMT %i \n", badpmt);
125 }
126 AliT0CalibTimeEq *offline = new AliT0CalibTimeEq();
127 Bool_t writeok = offline->ComputeOfflineParams(filePhysName.Data(), timecdb, cfdvalue, badpmt);
128 AliCDBMetaData metaData;
129 metaData.SetBeamPeriod(1);
130 metaData.SetResponsible("Alla Maevskaya");
131 metaData.SetComment("Time equalizing result with slew");
dd162229 132
b0ab3f59 133 if (writeok) {
134 AliCDBId* id1=NULL;
135 id1=new AliCDBId("T0/Calib/TimeDelay", ustartRun, uendRun );
136 AliCDBStorage* gStorage = AliCDBManager::Instance()->GetStorage(ocdbStorage);
137 gStorage->Put(offline, (*id1), &metaData);
138 }
139 else {
140
141 AliWarning(Form("writeok = %d data is not OK to be in OCDB",writeok));
dd162229 142 }
b0ab3f59 143
144 delete offline;
145
dd162229 146}
65521adf 147//-------------------------------------------------------------------------------------
148void AliT0PreprocessorOffline::CalibT0sPosition(TString filePhysName, Int_t ustartRun, Int_t uendRun, TString pocdbStorage)
149{
b0ab3f59 150 Float_t zero_timecdb[4]={0};
151 Float_t *timecdb = zero_timecdb;
152 if (pocdbStorage.Length()>0) ocdbStorage=pocdbStorage;
153 else
154 ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
155 AliCDBEntry *entryCalib = AliCDBManager::Instance()->Get("T0/Calib/TimeAdjust");
156 if(!entryCalib) {
157 AliWarning(Form("Cannot find any AliCDBEntry for [Calib, TimeAdjust]!"));
158 }
159 else
65521adf 160 {
b0ab3f59 161 AliT0CalibSeasonTimeShift *clb = (AliT0CalibSeasonTimeShift*)entryCalib->GetObject();
162 timecdb = clb->GetT0Means();
163 }
164
165 AliT0CalibSeasonTimeShift *offline = new AliT0CalibSeasonTimeShift();
166 Bool_t writeok = offline->SetT0Par(filePhysName.Data(), timecdb);
167 AliCDBMetaData metaData;
168 metaData.SetBeamPeriod(1);
169 metaData.SetResponsible("Alla Maevskaya");
170 metaData.SetComment("Time equalizing result with slew");
171
172 if (writeok) {
173 AliCDBId* id1=NULL;
65521adf 174 id1=new AliCDBId("T0/Calib/TimeAdjust", ustartRun, uendRun);
175 AliCDBStorage* gStorage = AliCDBManager::Instance()->GetStorage(ocdbStorage);
176 gStorage->Put(offline, (*id1), &metaData);
b0ab3f59 177 }
178
65521adf 179}