]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/AliT0CalibLaserData.cxx
Fixing T0 compilation
[u/mrichter/AliRoot.git] / T0 / AliT0CalibLaserData.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id:  */
17
18 //____________________________________________________________________
19 //                                                                          
20 // T0 - T0. 
21 //
22 // This class privides GIU service for reading RAW data from Laser
23 // during electronics test 
24 //                                                       
25 #include "TH1F.h"
26 #include "TH2F.h"
27 #include "TMap.h"
28 #include "TFile.h"
29 #include "TTree.h"
30 #include "TBranch.h"
31 #include "AliT0RawReader.h"
32 #include "TGLabel.h"
33 #include "TGFileDialog.h"
34 #include <iostream>
35
36 #include "AliT0CalibLaserData.h"
37
38 #include "AliCDBManager.h"
39 #include "AliRawReader.h"
40 #include "AliRawReaderRoot.h"
41 #include "AliT0LookUpValue.h"
42 #include "AliT0LookUpKey.h"
43 #include "AliT0Parameters.h"
44 #include "AliT0RawReader.h"
45
46 ClassImp(AliT0CalibLaserData)
47   //const char *fFileName;
48 AliT0CalibLaserData::AliT0CalibLaserData() : TObject(),
49                                              fTEntry(0),
50                                              fFileName(" ")
51   
52 {
53 //
54 }
55 /*
56 //________________________________________________________________
57
58 AliT0CalibLaserData::AliT0CalibLaserData(const AliT0CalibLaserData& calibda) : TObject(),
59                                          fRunNumber(905)
60 {
61 //copy constructor
62   
63 }
64 //________________________________________________________________
65
66 AliT0CalibLaserData &AliT0CalibLaserData::operator =(const AliT0CalibLaserData& calibda)
67 {
68 // assignment operator
69
70   return *this;
71 }
72 //________________________________________________________________
73 AliT0CalibLaserData::~AliT0CalibLaserData()
74 {
75   //
76 }
77 */
78 //________________________________________________________________
79
80 void AliT0CalibLaserData::ReadHistSize()
81 {
82   //build GUI frame for reading:
83   // - run number
84   // - histograms rates
85
86     
87     TGMainFrame* fMain = new TGMainFrame(0,1500,1500);
88     fMain->SetLayoutManager( new TGMatrixLayout(fMain,10,7) );
89  
90     fMain->AddFrame( new TGLabel(fMain, " Histogram") );
91     fMain->AddFrame( new TGLabel(fMain, "X min") );
92     fMain->AddFrame( new TGLabel(fMain, "X max") );
93     fMain->AddFrame( new TGLabel(fMain, "X N# channels") );
94   
95     fMain->AddFrame( new TGLabel(fMain, "Y min") );
96     fMain->AddFrame( new TGLabel(fMain, "Y max") );
97     fMain->AddFrame( new TGLabel(fMain, "Y N# channels") );
98
99     fMain->AddFrame( new TGLabel(fMain, "QTC" ) );
100     fEntries[0] = new TGNumberEntry(fMain, 0);
101     fMain->AddFrame(fEntries[0]);
102     fEntries[1] = new TGNumberEntry(fMain, 10000);
103     fMain->AddFrame(fEntries[1]);
104     fEntries[2] = new TGNumberEntry(fMain, 2500);
105     fMain->AddFrame(fEntries[2]);
106     fMain->AddFrame( new TGLabel(fMain, " ") );
107     fMain->AddFrame( new TGLabel(fMain, " ") );
108     fMain->AddFrame( new TGLabel(fMain, " ") );
109   
110     fMain->AddFrame( new TGLabel(fMain, "LED - CFD" ) );
111     fEntries[3] = new TGNumberEntry(fMain, 0);
112     fMain->AddFrame(fEntries[3]);
113     fEntries[4] = new TGNumberEntry(fMain, 1000);
114     fMain->AddFrame(fEntries[4]);
115     fEntries[5] = new TGNumberEntry(fMain, 1000);
116     fMain->AddFrame(fEntries[5]);
117     fMain->AddFrame( new TGLabel(fMain, " ") );
118     fMain->AddFrame( new TGLabel(fMain, " ") );
119     fMain->AddFrame( new TGLabel(fMain, " ") );
120     fMain->AddFrame( new TGLabel(fMain, "CFD vs QTC " ) );
121  // QTC axis X
122     fEntries[6] = new TGNumberEntry(fMain, 0.);
123     fMain->AddFrame(fEntries[6]);
124     fEntries[7] = new TGNumberEntry(fMain, 8000);
125     fMain->AddFrame(fEntries[7]);
126     fEntries[8] = new TGNumberEntry(fMain, 800);
127     fMain->AddFrame(fEntries[8]);
128 // CFD axis Y 
129    fEntries[9] = new TGNumberEntry(fMain, 0);
130     fMain->AddFrame(fEntries[9]);
131     fEntries[10] = new TGNumberEntry(fMain, 5000);
132     fMain->AddFrame(fEntries[10]);
133     fEntries[11] = new TGNumberEntry(fMain, 5000);
134     fMain->AddFrame(fEntries[11]);
135 //
136     fMain->AddFrame( new TGLabel(fMain, "CFD vs LED-CFD " ) );
137 //LED-CFD axis X
138     fEntries[12] = new TGNumberEntry(fMain, 0);
139     fMain->AddFrame(fEntries[12]);
140     fEntries[13] = new TGNumberEntry(fMain, 1000);
141     fMain->AddFrame(fEntries[13]);
142     fEntries[14] = new TGNumberEntry(fMain, 1000);
143     fMain->AddFrame(fEntries[14]);
144 // CFD axis Y
145     fEntries[15] = new TGNumberEntry(fMain, 1000);
146     fMain->AddFrame(fEntries[15]);
147     fEntries[16] = new TGNumberEntry(fMain, 5000);
148     fMain->AddFrame(fEntries[16]);
149     fEntries[17] = new TGNumberEntry(fMain, 4000);
150     fMain->AddFrame(fEntries[17]);
151  
152    fMain->AddFrame( new TGLabel(fMain, "CFD C " ) );
153 //CFD side C
154     fEntries[18] = new TGNumberEntry(fMain, 0);
155     fMain->AddFrame(fEntries[18]);
156     fEntries[19] = new TGNumberEntry(fMain, 5000);
157     fMain->AddFrame(fEntries[19]);
158     fEntries[20] = new TGNumberEntry(fMain, 5000);
159     fMain->AddFrame(fEntries[20]);
160  
161     fMain->AddFrame( new TGLabel(fMain, "") );
162     fMain->AddFrame( new TGLabel(fMain, "") );
163     fMain->AddFrame( new TGLabel(fMain, "") );
164
165     fMain->AddFrame( new TGLabel(fMain, "CFD A " ) );
166 //CFD side A
167     fEntries[21] = new TGNumberEntry(fMain,0);
168     fMain->AddFrame(fEntries[21]);
169     fEntries[22] = new TGNumberEntry(fMain, 5000);
170     fMain->AddFrame(fEntries[22]);
171     fEntries[23] = new TGNumberEntry(fMain, 5000);
172     fMain->AddFrame(fEntries[23]);
173
174     fMain->AddFrame( new TGLabel(fMain, "") );
175     fMain->AddFrame( new TGLabel(fMain, "") );
176     fMain->AddFrame( new TGLabel(fMain, "") );
177
178
179     fMain->AddFrame( new TGLabel(fMain, "LED C " ) );
180 //LED axis X
181     fEntries[24] = new TGNumberEntry(fMain, 0);
182     fMain->AddFrame(fEntries[24]);
183     fEntries[25] = new TGNumberEntry(fMain, 5000);
184     fMain->AddFrame(fEntries[25]);
185     fEntries[26] = new TGNumberEntry(fMain, 5000);
186     fMain->AddFrame(fEntries[26]);
187
188    
189    for ( int i=0; i<27; i++ ) fEntries[i]->SetWidth(70);
190    fMain->AddFrame( new TGLabel(fMain, " File name") );
191    fTEntry = new TGTextEntry(fMain,"");
192    fMain->AddFrame(fTEntry);
193    fTEntry->SetWidth(80);
194     //    printf( "Max Length %d\n", fEntries[0]->GetMaxWidth() );
195
196     TGTextButton *fOk = new TGTextButton(fMain, "OK");
197     fOk->Connect("Clicked()","AliT0CalibLaserData",this,"DoOk()");
198     //    fOk->SetCommand(".q");
199     fMain->AddFrame(fOk);
200     
201     fMain->MapSubwindows();
202     fMain->Resize();
203     fMain->SetWindowName("Dialog");
204     fMain->MapWindow();
205 }
206     
207 void AliT0CalibLaserData::DoOk()
208 {
209   
210   fFileName = (fTEntry->GetText());
211   //OpenFile();
212   printf(" DoOK >>  File %s\n",fFileName);
213   for( int i=0; i<27; i++ ) 
214     fHistLimits[i] = fEntries[i]->GetNumber();
215   
216   ReadData();
217 }
218
219 void AliT0CalibLaserData::ReadData()
220 {
221   // reading RAW data from test LCS
222   // filling histograms
223   // fillinf tree
224   
225   
226   TH1I *hChannel[105];  TH1I *hQTC[24];  
227   TH2F *hCFDvsQTC[24]; TH2F *hCFDvsLED[24]; TH1I *h1CFDminLED[24];
228
229   Int_t allData[110][50];
230   Int_t numberOfHits[105];
231   
232   Char_t  buf1[20], buf2[20], buf3[20], buf4[20], buf7[20];
233   
234   Int_t channels[106];
235   
236   TString names[106], type;
237   AliT0LookUpKey* lookkey= new AliT0LookUpKey();
238   AliT0LookUpValue*  lookvalue= new AliT0LookUpValue();
239   AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
240   AliCDBManager::Instance()->SetRun(0);
241   AliT0Parameters *fParam = AliT0Parameters::Instance();
242   fParam->Init();
243   TMap *lookup = fParam->GetMapLookup();
244   TMapIter *iter = new TMapIter(lookup);
245   
246   for( Int_t iline=0; iline<106; iline++)
247     {
248       lookvalue = ( AliT0LookUpValue*) iter->Next();
249       lookkey = (AliT0LookUpKey*) lookup->GetValue((TObject*)lookvalue);
250       if(lookkey){
251         Int_t key=lookkey->GetKey();
252         names[key]=lookkey->GetChannelName();
253         //      if(names[key].Contains("QT0"))
254         //  hChannel[key] = new TH1F(names[key].Data(),names[key].Data(),1000,3000,5000);
255         //      else
256           hChannel[key] = new TH1I(names[key].Data(),names[key].Data(),Int_t(fHistLimits[20]),fHistLimits[18],fHistLimits[19]);
257         if(key >0 && key<13)
258           hChannel[key] = new TH1I(names[key].Data(),names[key].Data(),Int_t(fHistLimits[20]),fHistLimits[18],fHistLimits[19]);
259         if(key >13 && key<25)
260           hChannel[key] = new TH1I(names[key].Data(),names[key].Data(),Int_t(fHistLimits[26]),fHistLimits[24],fHistLimits[25]);
261         
262         if(key >57 && key<69)
263           hChannel[key] = new TH1I(names[key].Data(),names[key].Data(),Int_t (fHistLimits[23]),fHistLimits[21],fHistLimits[22]);
264         //      hitsname="xHits" + names[key];
265         //      hNumHits[key] = new TH1F(hitsname.Data(),hitsname.Data(),50,-0.25,24.25);
266       }
267       else
268         {printf(" no such value %i \n", iline);}
269       
270     } 
271   for(Int_t ic=0; ic<24; ic++) {
272     {
273       sprintf(buf1,"QTC%i",ic+1);
274       sprintf(buf2,"CFDvsQTC%i",ic+1);
275       sprintf(buf3,"CFDvsLED%i",ic+1);
276       sprintf(buf4,"LEDminCFD%i",ic+1);
277       sprintf(buf7,"mpd%i",ic+1);
278       
279       hQTC[ic] = new TH1I(buf1,"QTC",(Int_t)fHistLimits[2],fHistLimits[0],fHistLimits[1]);
280       h1CFDminLED[ic] = new TH1I(buf4,"LED - CFD",(Int_t)fHistLimits[5],fHistLimits[3],fHistLimits[4]);
281       
282       hCFDvsQTC[ic] = new TH2F(buf2,"CFD vs     QTC",
283                                (Int_t)fHistLimits[8],fHistLimits[6],fHistLimits[7],
284                                (Int_t)fHistLimits[11],fHistLimits[9],fHistLimits[10]);
285       hCFDvsLED[ic] = new TH2F(buf3,"CFD vs LED-CFD",
286                                (Int_t)fHistLimits[14],fHistLimits[12],fHistLimits[13],
287                                (Int_t)fHistLimits[17],fHistLimits[15],fHistLimits[16]);
288
289       
290     }
291
292
293   }
294   
295   TH1F*hEffCFD= new TH1F("hEffCFD","Effeciency",50,-0.25,24.25);
296   TH1F*hEffLED= new TH1F("hEffLED","Effeciency",50,-0.25,24.25);
297   TH1F*hEffQT0= new TH1F("hEffQT0","Effeciency",50,-0.25,24.25);
298   TH1F*hEffQT1= new TH1F("hEffQT1","Effeciency",50,-0.25,24.25);
299
300       
301      // Char_t filename[80];
302   //     sprintf(filename,"t0%i.raw",fRunNumber);
303   AliRawReader *reader = new AliRawReaderRoot(fFileName);
304    reader->LoadEquipmentIdsMap("T0map.txt");
305   //    reader->RequireHeader(kFALSE);
306   reader->RequireHeader(kTRUE);
307   AliT0RawReader *start = new AliT0RawReader(reader);
308   //  start->SetNumberOfTRM(1);
309   for (Int_t i0=0; i0<105; i0++)
310     {
311       for (Int_t j0=0; j0<50; j0++) allData[i0][j0]=0;  
312       numberOfHits[i0]=0;
313     }
314   Int_t event=0;
315   
316   while (reader->NextEvent()) {
317     start->Next();
318     for (Int_t i=0; i<105; i++) {
319       for (Int_t iHit=0; iHit<50; iHit++) 
320         {
321           allData[i][iHit]= start->GetData(i,iHit);
322           //      if( allData[i][iHit]>0)         cout<<i<<" "<<iHit<<" "<<allData[i][iHit]<<endl;
323         }
324     }
325     
326      if(event%1000 == 0) 
327     printf("Event:%d\n",event);
328     
329      //   if(event > 100000) break;
330     
331     for (Int_t it = 0; it<24; it=it+2)
332       {
333         Int_t cc=it/2;
334         for (Int_t iHit=0; iHit<5; iHit++)
335           {
336             if(allData[it+25][iHit] != 0 && allData[it+26][iHit] !=0)
337               {
338                 hQTC[cc]->Fill(allData[it+25][iHit]-allData[it+26][iHit]);
339                 if(allData[cc+1][iHit] != 0 ) 
340                   hCFDvsQTC[cc]->Fill(allData[it+25][iHit]-allData[it+26][iHit],
341                                       allData[cc+1][iHit]-allData[0][0]+5000.);
342               }
343             if(allData[cc+1][iHit] != 0 && allData[cc+13][iHit]!=0 ) 
344               {
345                 hCFDvsLED[cc]->Fill(allData[cc+13][iHit]-allData[cc+1][iHit],
346                                     allData[cc+1][iHit]-allData[0][0]+5000.);  
347                 h1CFDminLED[cc]->Fill(allData[cc+13][iHit]-allData[cc+1][iHit]);
348               }
349             
350           }
351       }
352     for (Int_t it = 24; it<48; it=it+2)
353       {
354         Int_t cc=(Int_t)(it/2);
355         for (Int_t iHit=0; iHit<5; iHit++)
356           {
357             if(allData[it+57][iHit] != 0 && allData[it+58][iHit] !=0)
358               {
359                 hQTC[cc]->Fill(allData[it+57][iHit]-allData[it+58][iHit]);
360                 //                  hmpd[cc]->Fill(allData[it+26][iHit]-allData[it+25][iHit]);
361                 if(allData[cc+1][iHit] != 0 ) 
362                   hCFDvsQTC[cc]->Fill(allData[it+57][iHit]-allData[it+58][iHit],
363                                       allData[cc+45][iHit]-allData[0][0]+5000);
364               }
365             if(allData[cc+57][iHit] != 0 && allData[cc+45][iHit]!=0 ) 
366               {
367                 hCFDvsLED[cc]->Fill(allData[cc+57][iHit]-allData[cc+45][iHit],
368                                     allData[cc+1][iHit]-allData[0][0]+5000);  
369                 h1CFDminLED[cc]->Fill(allData[cc+57][iHit]-allData[cc+45][iHit]);
370               }
371               
372         }
373       }
374     
375     
376     for (Int_t iHit=0; iHit<5; iHit++) 
377       {
378         
379         for(Int_t ik=1; ik<105; ik++)
380           { 
381             channels[ik] = -100;
382             if((allData[ik][iHit] - allData[0][0] +5000) != 0 &&   //!!!!! Uncomment it !!!!! and comment next line
383                //      if((allData[ik][iHit] - allData[1][0] ) != 0 &&     
384                  allData[ik][iHit] >0 ) 
385               {  
386                 numberOfHits[ik]++;
387                 //              hChannel[ik] -> Fill(allData[ik][iHit] - allData[1][0]);            //Comment this line !!!
388                 hChannel[ik] -> Fill(allData[ik][iHit] - allData[0][0]+5000);
389                 //      cout<<" zpis'>> "<<iHit<<" "<<ik<<" "<<allData[ik][iHit] - allData[0][0]<<endl;
390                 //      hChannel[ik] -> Fill(allData[0][0]-allData[ik][iHit] );
391                 //              channels[ik] = allData[ik][iHit] - allData[0][0];
392               }
393           }
394         //            digitsTree->Fill();   
395       }
396
397     event++;
398     
399   } //event
400
401
402   if (event>1)
403     {
404       printf("efficiency for %i events \n",event);
405       for (Int_t i0=1; i0<13;  i0++)
406         {
407           printf("%s  %f  %s  %f %s  %f  %s  %f \n ",
408                  names[i0].Data(), Float_t(numberOfHits[i0])/Float_t(event),
409                  names[i0+12].Data(),Float_t(numberOfHits[i0+12])/Float_t(event),
410                  names[i0+56].Data(),Float_t(numberOfHits[i0+56])/Float_t(event),
411                  names[i0+68].Data(),Float_t(numberOfHits[i0+68])/Float_t(event));
412           
413           hEffCFD->Fill(i0,Float_t(numberOfHits[i0])  / Float_t(event));
414           hEffLED->Fill(i0,Float_t(numberOfHits[i0+12]) / Float_t(event));
415           hEffCFD->Fill(i0+12,Float_t(numberOfHits[i0+56]) /Float_t(event));
416           hEffLED->Fill(i0+12,Float_t(numberOfHits[i0+68]) /Float_t(event));
417         }
418       printf("\n");      
419       for (Int_t i0=0; i0<24;  i0=i0+2)
420         {
421           hEffQT1->Fill(i0, Float_t (numberOfHits[i0+25]) / Float_t(event));
422           hEffQT0->Fill(i0, Float_t (numberOfHits[i0]+26) / Float_t(event));
423           hEffQT1->Fill((i0+12), Float_t (numberOfHits[i0]+81) /  Float_t(event));
424           hEffQT0->Fill((i0+12), Float_t (numberOfHits[i0]+82) /  Float_t(event));
425
426           printf("%s  %f  %s  %f %s  %f  %s  %f \n",
427                  names[i0+25].Data(), Float_t(numberOfHits[i0+25])/Float_t(event),
428                  names[i0+26].Data(),Float_t(numberOfHits[i0+26])/Float_t(event),
429                  names[i0+81].Data(),Float_t(numberOfHits[i0+81])/Float_t(event),
430                  names[i0+82].Data(),Float_t(numberOfHits[i0+82])/Float_t(event));
431         }
432     }         
433   
434
435   Char_t filehist[50]; 
436   // sprintf(filehist,"t0treeDA%s",fFileName);
437    sprintf(filehist,"t0tree%s",fFileName);
438   printf("\n Wrote data in %s !!\n",filehist);
439      TFile *hist = new TFile(filehist,"RECREATE");
440      hist->cd();
441      //  digitsTree->Write("",TObject::kOverwrite);
442      
443      hEffCFD->Write();
444      hEffLED->Write();
445      hEffQT0->Write();
446       hEffQT1->Write();
447       
448       for(Int_t ik=0; ik<105; ik++)     hChannel[ik] ->Write();
449       
450       for (Int_t i=0; i<24; i++)
451         {
452           hQTC[i]->Write();
453           hCFDvsQTC[i]->Write();
454           hCFDvsLED[i]->Write();
455           h1CFDminLED[i]->Write();
456         }
457       
458 }
459
460 void AliT0CalibLaserData::OpenFile()
461 {
462
463 const char *ft[]={"T0 raw files","*.root","All files","*",0,0};
464   TString dir(".");
465   TGFileInfo fi; fi.fFileTypes=ft; fi.fIniDir=StrDup(dir);
466   new TGFileDialog(gClient->GetRoot(), 0x0, kFDOpen, &fi);
467   if(!fi.fFilename) return;
468   // fFileName =*( fi.fFilename);
469   fFileName = fi.fFilename;
470   printf(" AliT0CalibLaserData::OpenFile %s %s\n",fi.fFilename, fFileName );
471   //  if(gFile){ gFile->Close(); gFile=0;}
472
473   // gFile=TFile::Open(fi.fFilename);
474
475 }
476