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