set refrence PMT=2 if LHC10bc
[u/mrichter/AliRoot.git] / PWGPP / CalibMacros / CPass0 / AddTaskT0Calib.C
CommitLineData
27eb9bff 1void readCDB (TObject *task1);
2//_____________________________________________________________________________
3AliAnalysisTask *AddTaskT0Calib(Int_t runNumber)
4{
5 //
6 // add calibration task
7 //
8 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
9 if (!mgr) {
10 ::Error("AddTaskT0Calib", "No analysis manager to connect to.");
11 return NULL;
12 }
13
14 // check the input handler
15 if (!mgr->GetInputEventHandler()) {
16 ::Error("AddTaskT0Calib", "This task requires an input event handler");
17 return NULL;
18 }
19
20 // set TPC OCDB parameters
21 //ConfigOCDB(runNumber);
22
23 // setup task
24 AliT0CalibOffsetChannelsTask *task1 = new AliT0CalibOffsetChannelsTask("CalibObjectsTrain1");
25 readCDB(task1, runNumber);
cf6e0541 26 task1-> SetRefPMT(12,2);
27eb9bff 27 mgr->AddTask(task1);
28
29 // AliT0AnalysisTaskQA * task2 = new AliT0AnalysisTaskQA("QA task");
30 // mgr->AddTask(task2);
31
32 AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
33 if (!cinput1) cinput1 = mgr->CreateContainer("cchain",TChain::Class(),
34 AliAnalysisManager::kInputContainer);
35 AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("T0Calib",TObjArray::Class(), AliAnalysisManager::kOutputContainer, "AliESDfriends_v1.root");
36
37 mgr->ConnectInput(task1,0,cinput1);
38 mgr->ConnectOutput(task1,1,coutput1);
39 return task1;
40}
41//_____________________________________________________________________________
42void readCDB (TObject *task1, Int_t runNumber) {
43
44 Float_t zero_timecdb[24]={0};
45 Float_t *timecdb = zero_timecdb;
46 Float_t cfdvalue[24][5];
47 for(Int_t i=0; i<24; i++)
48 for (Int_t i0=0; i0<5; i0++)
49 cfdvalue[i][i0] = 0;
50
51 Float_t zero_shiftcdb[4]={0};
52 Float_t *shiftcdb = zero_shiftcdb;
53 AliT0CalibOffsetChannelsTask *mytask = (AliT0CalibOffsetChannelsTask*)task1;
54
55 AliCDBManager* man = AliCDBManager::Instance();
27eb9bff 56 AliCDBEntry *entry = AliCDBManager::Instance()->Get("GRP/CTP/CTPtiming");
57 if (!entry) AliFatal("CTP timing parameters are not found in OCDB !");
58 AliCTPTimeParams *ctpParams = (AliCTPTimeParams*)entry->GetObject();
59 Float_t l1Delay = (Float_t)ctpParams->GetDelayL1L0()*25.0;
60
61 AliCDBEntry *entry1 = AliCDBManager::Instance()->Get("GRP/CTP/TimeAlign");
62 if (!entry1) AliFatal("CTP time-alignment is not found in OCDB !");
63 AliCTPTimeParams *ctpTimeAlign = (AliCTPTimeParams*)entry1->GetObject();
64 l1Delay += ((Float_t)ctpTimeAlign->GetDelayL1L0()*25.0);
65
66 AliCDBEntry *entry4 = AliCDBManager::Instance()->Get("GRP/Calib/LHCClockPhase");
67 if (!entry4) AliFatal("LHC clock-phase shift is not found in OCDB !");
68 AliLHCClockPhase *phase = (AliLHCClockPhase*)entry4->GetObject();
69 Float_t fGRPdelays = l1Delay - phase->GetMeanPhase();
70
71 AliCDBEntry *entryCalib0 = man->Get("T0/Calib/Latency");
72 if(!entryCalib0) {
73 AliError::(Form("Cannot find any AliCDBEntry for [Calib, Latency]!"));
74 return;
75 }
76 AliT0CalibLatency *calibda=(AliT0CalibLatency*)entryCalib0->GetObject();
77 Float_t fLatencyL1 = calibda->GetLatencyL1();
78 Float_t fLatencyHPTDC = calibda->GetLatencyHPTDC();
79
80 AliCDBEntry *entryCalib1 = man->Get("T0/Calib/TimeDelay");
81 if(!entryCalib1) {
82 AliError::(Form("Cannot find any AliCDBEntry for [Calib, TimeDelay]!"));
83 return;
84 }
85 else
86 {
87 AliT0CalibTimeEq *clb = (AliT0CalibTimeEq*)entryCalib1->GetObject();
88 timecdb = clb->GetTimeEq();
89 for(Int_t i=0; i<24; i++)
90 for (Int_t i0=0; i0<5; i0++){
91 cfdvalue[i][i0] = clb->GetCFDvalue(i, i0);
92 }
93 }
94
95 for (Int_t i=0; i<24; i++) {
96 Float_t cfdmean = cfdvalue[i][0];
97 if( cfdvalue[i][0] < 500 || cfdvalue[i][0] > 50000) cfdmean = ( 1000.*fLatencyHPTDC - 1000.*fLatencyL1 + 1000.*fGRPdelays)/24.4;
98 mytask->SetCFDvalue(i, cfdmean);
99 mytask->SetTimeEq(i, timecdb[i]);
100 }
101
102 AliCDBEntry *entryCalib2 = man->Get("T0/Calib/TimeAdjust");
103 if(!entryCalib2) {
104 AliError(Form("Cannot find any AliCDBEntry for [Calib, TimeAdjust]!"));
105 }
106 else
107 {
108 AliT0CalibSeasonTimeShift *clb1 = (AliT0CalibSeasonTimeShift*)entryCalib2->GetObject();
109 shiftcdb = clb1->GetT0Means();
110 }
111
112 for (Int_t i=0; i<4; i++) mytask->SetT0Means(i,shiftcdb[i]);
113}