]> git.uio.no Git - u/mrichter/AliRoot.git/blame - T0/AliT0CalibLaserData.cxx
New class for calibration of laser data (Alla)
[u/mrichter/AliRoot.git] / T0 / AliT0CalibLaserData.cxx
CommitLineData
fc387e80 1#include "TH1F.h"
2#include "TH2F.h"
3#include "TMap.h"
4#include "TFile.h"
5#include "TTree.h"
6#include "TBranch.h"
7#include "AliT0RawReader.h"
8#include "TGLabel.h"
9#include <iostream.h>
10
11#include "AliT0CalibLaserData.h"
12
13#include "AliCDBManager.h"
14#include "AliRawReader.h"
15#include "AliRawReaderDate.h"
16#include "AliT0LookUpValue.h"
17#include "AliT0Parameters.h"
18#include "AliT0RawReader.h"
19#include "AliLog.h"
20
21ClassImp(AliT0CalibLaserData)
22
23AliT0CalibLaserData::AliT0CalibLaserData() : TObject(),
24 fRunNumber(905)
25{
26//
27}
28/*
29//________________________________________________________________
30
31AliT0CalibLaserData::AliT0CalibLaserData(const AliT0CalibLaserData& calibda) : TObject(),
32 fRunNumber(905)
33{
34//copy constructor
35
36}
37//________________________________________________________________
38
39AliT0CalibLaserData &AliT0CalibLaserData::operator =(const AliT0CalibLaserData& calibda)
40{
41// assignment operator
42
43 return *this;
44}
45//________________________________________________________________
46//AliT0CalibLaserData::~AliT0CalibLaserData()
47//{
48 //
49//}
50*/
51//________________________________________________________________
52
53void AliT0CalibLaserData::ReadHistSize(Int_t rNumber)
54{
55 fRunNumber = rNumber;
56
57 TGMainFrame* fMain = new TGMainFrame(0,1500,1500);
58 fMain->SetLayoutManager( new TGMatrixLayout(fMain,7,7) );
59
60 fMain->AddFrame( new TGLabel(fMain, " Histogram") );
61 fMain->AddFrame( new TGLabel(fMain, "X min") );
62 fMain->AddFrame( new TGLabel(fMain, "X max") );
63 fMain->AddFrame( new TGLabel(fMain, "X N# channels") );
64
65 fMain->AddFrame( new TGLabel(fMain, "Y min") );
66 fMain->AddFrame( new TGLabel(fMain, "Y max") );
67 fMain->AddFrame( new TGLabel(fMain, "Y N# channels") );
68
69 fMain->AddFrame( new TGLabel(fMain, "QTC" ) );
70 fEntries[0] = new TGNumberEntry(fMain, 0);
71 fMain->AddFrame(fEntries[0]);
72 fEntries[1] = new TGNumberEntry(fMain, 10000);
73 fMain->AddFrame(fEntries[1]);
74 fEntries[2] = new TGNumberEntry(fMain, 10000);
75 fMain->AddFrame(fEntries[2]);
76 fMain->AddFrame( new TGLabel(fMain, " ") );
77 fMain->AddFrame( new TGLabel(fMain, " ") );
78 fMain->AddFrame( new TGLabel(fMain, " ") );
79
80 fMain->AddFrame( new TGLabel(fMain, "LED - CFD" ) );
81 fEntries[3] = new TGNumberEntry(fMain, 0);
82 fMain->AddFrame(fEntries[3]);
83 fEntries[4] = new TGNumberEntry(fMain, 10000);
84 fMain->AddFrame(fEntries[4]);
85 fEntries[5] = new TGNumberEntry(fMain, 10000);
86 fMain->AddFrame(fEntries[5]);
87 fMain->AddFrame( new TGLabel(fMain, " ") );
88 fMain->AddFrame( new TGLabel(fMain, " ") );
89 fMain->AddFrame( new TGLabel(fMain, " ") );
90 fMain->AddFrame( new TGLabel(fMain, "CFD vs QTC " ) );
91 // QTC axis X
92 fEntries[6] = new TGNumberEntry(fMain, 1000.);
93 fMain->AddFrame(fEntries[6]);
94 fEntries[7] = new TGNumberEntry(fMain, 8000.5);
95 fMain->AddFrame(fEntries[7]);
96 fEntries[8] = new TGNumberEntry(fMain, 700);
97 fMain->AddFrame(fEntries[8]);
98// CFD axis Y
99 fEntries[9] = new TGNumberEntry(fMain, 0);
100 fMain->AddFrame(fEntries[9]);
101 fEntries[10] = new TGNumberEntry(fMain, 10000);
102 fMain->AddFrame(fEntries[10]);
103 fEntries[11] = new TGNumberEntry(fMain, 10000);
104 fMain->AddFrame(fEntries[11]);
105//
106 fMain->AddFrame( new TGLabel(fMain, "CFD vs LED-CFD " ) );
107//LED-CFD axis X
108 fEntries[12] = new TGNumberEntry(fMain, 0);
109 fMain->AddFrame(fEntries[12]);
110 fEntries[13] = new TGNumberEntry(fMain, 500);
111 fMain->AddFrame(fEntries[13]);
112 fEntries[14] = new TGNumberEntry(fMain, 500);
113 fMain->AddFrame(fEntries[14]);
114// CFD axis Y
115 fEntries[15] = new TGNumberEntry(fMain, 3900);
116 fMain->AddFrame(fEntries[15]);
117 fEntries[16] = new TGNumberEntry(fMain, 4100);
118 fMain->AddFrame(fEntries[16]);
119 fEntries[17] = new TGNumberEntry(fMain, 200);
120 fMain->AddFrame(fEntries[17]);
121
122 fMain->AddFrame( new TGLabel(fMain, " Number of run") );
123 fEntries[18] = new TGNumberEntry(fMain, 905);
124 fMain->AddFrame(fEntries[18]);
125
126 for ( int i=0; i<19; i++ ) fEntries[i]->SetWidth(70);
127 // printf( "Max Length %d\n", fEntries[0]->GetMaxWidth() );
128
129 TGTextButton *fOk = new TGTextButton(fMain, "OK");
130 fOk->Connect("Clicked()","AliT0CalibLaserData",this,"DoOk()");
131 // fOk->SetCommand(".q");
132 fMain->AddFrame(fOk);
133
134 fMain->MapSubwindows();
135 fMain->Resize();
136 fMain->SetWindowName("Dialog");
137 fMain->MapWindow();
138}
139
140void AliT0CalibLaserData::DoOk()
141{
142 printf("it worked !\n");
143 // delete fMain;
144 fRunNumber = Int_t (fEntries[18]->GetNumber());
145 cout<<" RUN NUMBER "<<fRunNumber<<endl;
146 for( int i=0; i<18; i++ ) fHistLimits[i] = fEntries[i]->GetNumber();
147 for( int i=0; i<18; i++ ) cout<<fHistLimits[i]<<" ";
148 cout<<endl;
149 ReadData();
150
151}
152
153void AliT0CalibLaserData::ReadData()
154{
155
156 TH1F *hChannel[105]; TH1F *hQTC[12];
157 TH2F *hCFD_QTC[12]; TH2F *hCFD_LED[12]; TH1F *h1CFD_LED[12];
158 TH1F *hmpd[12];
159 Int_t allData[110][20];
160 Int_t numberOfHits[105];
161
162 Char_t buf1[20], buf2[20], buf3[20], buf4[20], buf7[20];
163
164 TTree* digitsTree = new TTree("testData","Tree of test data Digits");
165 TBranch *b[106];
166
167 Int_t channels[106];
168
169 TString names[106], type;
170 AliT0LookUpKey* lookkey= new AliT0LookUpKey();
171 AliT0LookUpValue* lookvalue= new AliT0LookUpValue();
172 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
173 AliCDBManager::Instance()->SetRun(0);
174 AliT0Parameters *fParam = AliT0Parameters::Instance();
175 fParam->Init();
176 TMap *lookup = fParam->GetMapLookup();
177 TMapIter *iter = new TMapIter(lookup);
178
179 for( Int_t iline=0; iline<106; iline++)
180 {
181 lookvalue = ( AliT0LookUpValue*) iter->Next();
182 lookkey = (AliT0LookUpKey*) lookup->GetValue((TObject*)lookvalue);
183 if(lookkey){
184 Int_t key=lookkey->GetKey();
185 names[key]=lookkey->GetChannelName();
186 // cout<<lookkey->GetKey()<<" "<<lookkey->GetChannelName()<<" trm "<<lookvalue->GetTRM()<<" tdc "<<lookvalue->GetTDC()<<" chain "<<lookvalue->GetChain()<<" channel "<<lookvalue->GetChannel()<<endl;
187 hChannel[key] = new TH1F(names[key].Data(),names[key].Data(),30000,0,30000);
188 // hitsname="xHits" + names[key];
189 // hNumHits[key] = new TH1F(hitsname.Data(),hitsname.Data(),50,-0.25,24.25);
190 type =names[key] + "/I";
191 b[key]=digitsTree->Branch(names[key].Data(),&channels[key], type);
192 }
193 else
194 {cout<<iline<<" no such value "<<endl;}
195
196 }
197 for(Int_t ic=0; ic<12; ic++) {
198 {
199 sprintf(buf1,"QTC%i",ic+1);
200 sprintf(buf2,"CFDvsQTC%i",ic+1);
201 sprintf(buf3,"CFDvsLED%i",ic+1);
202 sprintf(buf4,"LED_CFD%i",ic+1);
203 sprintf(buf7,"mpd%i",ic+1);
204
205 hQTC[ic] = new TH1F(buf1,"QTC",(Int_t)fHistLimits[2],fHistLimits[0],fHistLimits[1]);
206 h1CFD_LED[ic] = new TH1F(buf4,"LED - CFD",(Int_t)fHistLimits[5],fHistLimits[3],fHistLimits[4]);
207 hmpd[ic] = new TH1F(buf7,"mpd",20000,-10000.0,10000.0);
208 hCFD_QTC[ic] = new TH2F(buf2,"CFD vs QTC",
209 (Int_t)fHistLimits[8],fHistLimits[6],fHistLimits[7],
210 (Int_t)fHistLimits[11],fHistLimits[9],fHistLimits[10]);
211 hCFD_LED[ic] = new TH2F(buf3,"CFD vs LED-CFD",
212 (Int_t)fHistLimits[14],fHistLimits[12],fHistLimits[13],
213 (Int_t)fHistLimits[17],fHistLimits[15],fHistLimits[16]);
214
215
216 }
217
218
219 }
220 // cout<<" hist created "<<endl;
221
222 TH1F*hEffCFD= new TH1F("hEffCFD","Effeciency",50,-0.25,24.25);
223 TH1F*hEffLED= new TH1F("hEffLED","Effeciency",50,-0.25,24.25);
224 TH1F*hEffQT0= new TH1F("hEffQT0","Effeciency",50,-0.25,24.25);
225 TH1F*hEffQT1= new TH1F("hEffQT1","Effeciency",50,-0.25,24.25);
226
227
228 Char_t filename[100];
229 sprintf(filename,"/home/t0/alice/testSep07/raw/t0%i.001.raw",fRunNumber);
230 AliRawReader *reader = new AliRawReaderDate(filename);
231 if(!reader) AliFatal(Form("Can not opne file ",filename));
232 // AliRawReader *reader = new AliRawReaderFile();
233 reader->LoadEquipmentIdsMap("T0map.txt");
234 // reader->RequireHeader(kFALSE);
235 reader->RequireHeader(kTRUE);
236 AliT0RawReader *start = new AliT0RawReader(reader);
237 // start->SetNumberOfTRM(1);
238 for (Int_t i0=0; i0<105; i0++)
239 {
240 for (Int_t j0=0; j0<5; j0++) allData[i0][j0]=0;
241 numberOfHits[i0]=0;
242 }
243 Int_t event=0;
244
245 while (reader->NextEvent()) {
246 start->Next();
247 for (Int_t i=0; i<105; i++) {
248 for (Int_t iHit=0; iHit<20; iHit++)
249 {
250 allData[i][iHit]= start->GetData(i,iHit);
251 }
252 }
253
254 if(event%1000 == 0) printf("Event:%d\n",event);
255
256 // if(event > 100000) break;
257
258
259 for (Int_t it = 0; it<24; it=it+2)
260 {
261 for (Int_t iHit=0; iHit<20; iHit++)
262 {
263 if(allData[it+25][iHit] != 0 && allData[it+26][iHit] !=0)
264 {
265 Int_t cc=it/2;
266 hQTC[cc]->Fill(allData[it+25][iHit]-allData[it+26][iHit]);
267 hmpd[cc]->Fill(allData[it+26][iHit]-allData[it+25][iHit]);
268 if(allData[cc+1][iHit] != 0 ) hCFD_QTC[cc]->Fill(allData[it+25][iHit]-allData[it+26][iHit],allData[cc+1][iHit]-allData[0][0]);
269 if(allData[cc+1][iHit] != 0 && allData[cc+13][iHit]!=0 )
270 {
271 hCFD_LED[cc]->Fill(allData[cc+13][iHit]-allData[cc+1][iHit],allData[cc+1][iHit]-allData[0][0]);
272 h1CFD_LED[cc]->Fill(allData[cc+13][iHit]-allData[cc+1][iHit]);
273 }
274 }
275 }
276 }
277
278 for (Int_t iHit=0; iHit<20; iHit++)
279 {
280
281 for(Int_t ik=1; ik<105; ik++)
282 {
283 channels[ik] = -100;
284 if((allData[ik][iHit] - allData[0][0]) > 0 )
285 {
286 numberOfHits[ik]++;
287 hChannel[ik] -> Fill(allData[ik][iHit] - allData[0][0]);
288 channels[ik] = allData[ik][iHit] - allData[0][0];
289 }
290 }
291 // digitsTree->Fill();
292 }
293
294 event++;
295
296 } //event
297
298
299 if (event>1)
300 {
301 cout<<"efficiency for "<<event<<" events"<<endl;
302 for (Int_t i0=1; i0<13; i0++)
303 {
304
305 cout<<names[i0].Data()<<" "<<Float_t(numberOfHits[i0])/Float_t(event)<<" ";
306 cout<<names[i0+13].Data()<<" "<<Float_t(numberOfHits[i0])/Float_t(event)<<" ";
307 cout<<names[i0+57].Data()<<" "<<Float_t(numberOfHits[i0])/Float_t(event)<<" ";
308 cout<<names[i0+69].Data()<<" "<<Float_t(numberOfHits[i0])/Float_t(event)<<endl;
309
310 hEffCFD->Fill(i0,Float_t(numberOfHits[i0]) / Float_t(event));
311 hEffLED->Fill(i0,Float_t(numberOfHits[i0+13]) / Float_t(event));
312 hEffCFD->Fill(i0+12,Float_t(numberOfHits[i0+57]) /Float_t(event));
313 hEffLED->Fill(i0+12,Float_t(numberOfHits[i0+69]) /Float_t(event));
314 }
315 cout<<endl;
316
317 for (Int_t i0=0; i0<24; i0=i0+2)
318 {
319 hEffQT1->Fill(i0, Float_t (numberOfHits[i0+25]) / Float_t(event));
320 hEffQT0->Fill(i0, Float_t (numberOfHits[i0]+26) / Float_t(event));
321 hEffQT1->Fill((i0+12), Float_t (numberOfHits[i0]+81) / Float_t(event));
322 hEffQT0->Fill((i0+12), Float_t (numberOfHits[i0]+82) / Float_t(event));
323 cout<<names[i0+25].Data()<<" "<<Float_t(numberOfHits[i0+25])/Float_t(event)<<" ";
324 cout<<names[i0+26].Data()<<" "<<Float_t(numberOfHits[i0+26])/Float_t(event)<<" ";
325 cout<<names[i0+81].Data()<<" "<<Float_t(numberOfHits[i0]+81)/Float_t(event)<<" ";
326 cout<<names[i0+82].Data()<<" "<<Float_t(numberOfHits[i0]+82)/Float_t(event)<<endl;
327
328
329 }
330 }
331
332
333 Char_t filehist[100];
334 sprintf(filehist,"/home/t0/alice/testSep07/tree/t0tree%i.root",fRunNumber);
335 // sprintf(filehist,"test.root");
336 TFile *hist = new TFile(filehist,"RECREATE");
337 cout<<" writing hist in file "<<filehist<<endl;
338
339 // digitsTree->Write("",TObject::kOverwrite);
340
341 hEffCFD->Write();
342 hEffLED->Write();
343 hEffQT0->Write();
344 hEffQT1->Write();
345
346 for(Int_t ik=0; ik<105; ik++) {
347 if (hChannel[ik]->GetEntries()>0 ) hChannel[ik] ->Write();
348 }
349 for (Int_t i=0; i<12; i++)
350 {
351 hQTC[i]->Write();
352 hmpd[i]->Write();
353 hCFD_QTC[i]->Write();
354 hCFD_LED[i]->Write();
355 h1CFD_LED[i]->Write();
356 }
357
358
359 hist->Close();
360 cout<<" hist in file"<<endl;
361
362}