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