"Setting correct gains for Pb-p in simulation"
[u/mrichter/AliRoot.git] / T0 / AliT0CalibOffsetChannelsTask.cxx
CommitLineData
a65a7e70 1#include "TChain.h"
2#include "TTree.h"
3#include "TH1D.h"
4#include "TF1.h"
5#include "TCanvas.h"
6#include "TObjArray.h"
7
8#include "AliAnalysisTask.h"
9#include "AliAnalysisManager.h"
10
11#include "AliESDEvent.h"
12#include "AliESDInputHandler.h"
13
14#include "AliT0CalibOffsetChannelsTask.h"
15
16//#include "AliCDBMetaData.h"
17//#include "AliCDBId.h"
18//#include "AliCDBEntry.h"
19//#include "AliCDBManager.h"
20//#include "AliCDBStorage.h"
21
22// Task should calculate channels offset
23// Authors: Alla
24
25ClassImp(AliT0CalibOffsetChannelsTask)
26//________________________________________________________________________
27AliT0CalibOffsetChannelsTask::AliT0CalibOffsetChannelsTask()
28 : AliAnalysisTaskSE(), fESD(0x0), fTzeroObject(0x0),
29 fTzeroORA(0x0), fTzeroORC(0x0), fResolution(0x0), fTzeroORAplusORC(0x0),
30 fRunNumber(0),fRefPMTA(12), fRefPMTC(0)
31{
32 // Constructor
33
34 for( int ip=0; ip < 24; ip++){
35 fTimeDiff[ip] = 0;
36 fCFD[ip] = 0;
37 fCDBdelays[ip]= 0;
38 fCDBcfds[ip]= 0;
39 if (ip<4 ) fCDBT0s[ip]= 0;
40 }
41
42 // Define input and output slots here
43 // Input slot #0 works with a TChain
44 // DefineInput(0, TChain::Class());
45 // DefineOutput(1, TObjArray::Class());
46}
47
48
49//________________________________________________________________________
50AliT0CalibOffsetChannelsTask::AliT0CalibOffsetChannelsTask(const char *name)
51 : AliAnalysisTaskSE(name), fESD(0), fTzeroObject(0),
52 fTzeroORA(0x0), fTzeroORC(0x0), fResolution(0x0), fTzeroORAplusORC(0x0),
53 fRunNumber(0),fRefPMTA(12), fRefPMTC(0)
54{
55 // Constructor
56
57 for( int ip=0; ip < 24; ip++){
58 fTimeDiff[ip] = 0;
59 fCFD[ip] = 0;
60 fCDBdelays[ip]= 0;
61 fCDBcfds[ip]= 0;
62 if (ip<4 ) fCDBT0s[ip]= 0;
63
64 }
65
66 // Define input and output slots here
67 // Input slot #0 works with a TChain
68 DefineInput(0, TChain::Class());
69 DefineOutput(1, TObjArray::Class());
70 // Output slot #0 id reserved by the base class for AOD
71 // Output slot #1 writes into a TH1 container
72}
73
74//________________________________________________________________________
75AliT0CalibOffsetChannelsTask::~AliT0CalibOffsetChannelsTask()
76{
77 // Destructor
78 // printf("AliT0CalibOffsetChannels~AliT0CalibOffsetChannels() ");
79 delete fTzeroORA;
80 delete fTzeroORC;
81 delete fResolution;
82 delete fTzeroORAplusORC;
83 for( Int_t ip=0; ip < 24; ip++){
84 delete fTimeDiff[ip];
85 delete fCFD[ip];
86 }
87
88 delete fTzeroObject;
89}
90
91//________________________________________________________________________
92/*void AliT0CalibOffsetChannelsTaskX::ConnectInputData(Option_t *) {
93 //
94 //
95 //
96 TTree* tree=dynamic_cast<TTree*>(GetInputData(0));
97 if (!tree) {
98 printf("ERROR: Could not read chain from input slot 0");
99 }
100 else {
101 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
102 if (!esdH) {
103 printf ("ERROR: Could not get ESDInputHandler");
104 }
105 else {
106 fESD = esdH->GetEvent();
107 printf ("*** CONNECTED NEW EVENT ****");
108 }
109 }
110}
111*/
112//________________________________________________________________________
113void AliT0CalibOffsetChannelsTask::UserCreateOutputObjects()
114{
115 // Create histograms
116 Float_t low = fCDBcfds[fRefPMTC] - 500;
117 Float_t high = fCDBcfds[fRefPMTA] + 500;
118 for (Int_t i=0; i<24; i++) {
119 fTimeDiff[i] = new TH1F (Form("CFD1minCFD%d",i+1),"fTimeDiff",150, -300, 300);
120 fCFD[i] = new TH1F(Form("CFD%d",i+1),"CFD",250,low, high);//6000, 7000);
121 // fCFD[i] = new TH1F(Form("CFD%d",i+1),"CFD",250, -1000, 1000);//6000, 7000);
122 }
123
124 fTzeroORAplusORC = new TH1F("fTzeroORAplusORC","ORA+ORC /2",200,-4000,4000); //or A plus or C
125 fResolution = new TH1F("fResolution","fResolution",200,-2000,2000);// or A minus or C spectrum
126 fTzeroORA = new TH1F("fTzeroORA","fTzeroORA",200,-4000,4000);// or A spectrum
127 fTzeroORC = new TH1F("fTzeroORC","fTzeroORC",200,-4000,4000);// or C spectrum
128
129
130 fTzeroObject = new TObjArray(0);
131 fTzeroObject->SetOwner(kTRUE);
132
133 for (Int_t i=0; i<24; i++)
134 fTzeroObject->AddAtAndExpand(fTimeDiff[i],i);
135
136 for (Int_t i=0; i<24; i++)
137 fTzeroObject->AddAtAndExpand(fCFD[i],i+24); //24 - 48
138
139 fTzeroObject->AddAtAndExpand(fTzeroORAplusORC, 48);
140 fTzeroObject->AddAtAndExpand(fResolution, 49);
141 fTzeroObject->AddAtAndExpand(fTzeroORA, 50);
142 fTzeroObject->AddAtAndExpand(fTzeroORC, 51);
143
144 PostData(1, fTzeroObject);
145 // Called once
146}
147
148//________________________________________________________________________
149void AliT0CalibOffsetChannelsTask::UserExec(Option_t *)
150{
151 // Main loop
152 // Called for each event
153
154 // Post output data.
155
156 fESD = dynamic_cast<AliESDEvent*>(InputEvent());
157 if (!fESD) {
158 printf("ERROR: fESD not available\n");
159 return;
160 }
1e0b9acd 161 AliESDTZERO* tz= (AliESDTZERO*) fESD->GetESDTZERO();
a65a7e70 162 Int_t trigT0 = fESD->GetT0Trig();
1e0b9acd 163 Float_t tvdctr = tz->GetTVDC(0);
a65a7e70 164 Bool_t eq = kTRUE;
165 fRunNumber = fESD->GetRunNumber() ;
166 if( fRunNumber<165747) eq = kFALSE;
167
168 const Double32_t* time = fESD->GetT0time();
169 const Double32_t* amp = fESD->GetT0amplitude();
170
1e0b9acd 171 if(tvdctr>-5 && tvdctr<5 && tvdctr!=0) { //event selection
172 // cout<<" tvdc "<<tvdctr<<endl;
173 Double32_t diff;
174 for (Int_t i=0; i<24; i++) {
175 if( time[i] > 0 && amp[i]>0.1 ){
176 if (eq) {
a65a7e70 177 fCFD[i]->Fill( time[i] );//////!!!!!
178 if( time[fRefPMTC] > 0 && i<12) {
179 diff = time[i]-time[fRefPMTC];
180 fTimeDiff[i]->Fill( diff);
181 }
182 if( time[fRefPMTA] >0 && i>11) {
183 diff = time[i]-time[fRefPMTA] ;
184 fTimeDiff[i]->Fill( diff);
185 }
1e0b9acd 186 } //eq=1
187 else {
188 fCFD[i]->Fill( time[i] + fCDBdelays[i] );
189 if( time[fRefPMTC] > 0 && i<12) {
190 diff = time[i]-time[fRefPMTC] + fCDBdelays[i];
191 fTimeDiff[i]->Fill( diff);
192 } //C
193 if( time[fRefPMTA] >0 && i>11) {
194 diff = time[i]-time[fRefPMTA] + fCDBdelays[i];
195 fTimeDiff[i]->Fill( diff);
196 } //A
197 } //eq=0
198 }
199
a65a7e70 200 }
a65a7e70 201 const Double32_t* mean = fESD->GetT0TOF();
202 Double32_t meanTOF = mean[0] + fCDBT0s[0] ;
203 Double32_t orA = mean[1] + fCDBT0s[1] ;
204 Double32_t orC = mean[2] + fCDBT0s[2] ;
1e0b9acd 205
a65a7e70 206 if(orA<99999) fTzeroORA->Fill(orA);
207 if(orC<99999) fTzeroORC->Fill(orC);
208 if(orA<99999 && orC<99999) fResolution->Fill((orA-orC)/2.);
209 if(orA<99999 && orC<99999) fTzeroORAplusORC->Fill(meanTOF);
210 } //if TVDC on
a65a7e70 211 PostData(1, fTzeroObject);
1e0b9acd 212}
213//________________________________________________________________________
a65a7e70 214 void AliT0CalibOffsetChannelsTask::Terminate(Option_t *)
215{
216
217 // Called once at the end of the query
218}
219