]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/readLaserData.C
Please be more careful - never cache the data from the reco-params, but rather use...
[u/mrichter/AliRoot.git] / T0 / readLaserData.C
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 /*
8 #include "/scratch/alla/alice/AliRoot/STEER/AliCDBManager.h"
9 #include "/scratch/alla/alice/AliRoot/RAW/AliRawReader.h"
10 #include "/scratch/alla/alice/AliRoot/T0/AliT0LookUpValue.h"
11 #include "/scratch/alla/alice/AliRoot/T0/AliT0Parameters.h"
12 #include "/scratch/alla/alice/AliRoot/T0/AliT0RawReader.h"
13 */
14 void readLaserData(Int_t runNumber=905)
15 {
16
17   TH1F *hChannel[105];  TH1F *hNumHits[105];   TH1F *hQTC[12];  
18   TH2F *hCFD_QTC[12]; TH2F *hCFD_LED[12]; TH1F *h1CFD_LED[12];
19   TH1F *hQTCc[12];TH1F *hmpd[12];
20   Int_t allData[110][5];
21   Int_t numberOfHits[105];
22   
23   Char_t  buf1[10], buf2[10], buf3[10], buf4[10], buf5[10], buf6[10], buf7[10];
24
25   TTree* digitsTree = new TTree("testData","Tree of test data Digits");
26   TBranch *b[106];
27
28    Int_t channels[106];
29  
30   TString names[106], type;
31   AliT0LookUpKey* lookkey= new AliT0LookUpKey();
32   AliT0LookUpValue*  lookvalue= new AliT0LookUpValue();
33   AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
34   AliCDBManager::Instance()->SetRun(0);
35   AliT0Parameters *fParam = AliT0Parameters::Instance();
36   fParam->Init();
37   TMap *lookup = fParam->GetMapLookup();
38   TMapIter *iter = new TMapIter(lookup);
39   
40   for( Int_t iline=0; iline<106; iline++)
41     {
42       lookvalue = ( AliT0LookUpValue*) iter->Next();
43        lookkey = (AliT0LookUpKey*) lookup->GetValue((TObject*)lookvalue);
44       if(lookkey){
45         Int_t key=lookkey->GetKey();
46         names[key]=lookkey->GetChannelName();
47         //      cout<<lookkey->GetKey()<<" "<<lookkey->GetChannelName()<<" trm "<<lookvalue->GetTRM()<<" tdc "<<lookvalue->GetTDC()<<" chain  "<<lookvalue->GetChain()<<" channel "<<lookvalue->GetChannel()<<endl;
48         hChannel[key] = new TH1F(names[key].Data(),names[key].Data(),30000,0,30000);
49         //      hitsname="xHits" + names[key];
50         //      hNumHits[key] = new TH1F(hitsname.Data(),hitsname.Data(),50,-0.25,24.25);
51         type =names[key] + "/I";
52         b[key]=digitsTree->Branch(names[key].Data(),&channels[key], type);
53        }
54       else
55         {cout<<iline<<" no such value "<<endl;}
56         
57     } 
58   for(Int_t ic=0; ic<12; ic++) {
59     {
60       sprintf(buf1,"QTC%i",ic+1);
61       sprintf(buf2,"CFD_QTC%i",ic+1);
62       sprintf(buf3,"CFD_LED%i",ic+1);
63       sprintf(buf4,"LED-CFD%i",ic+1);
64       sprintf(buf5,"56__%i",ic+1);
65       sprintf(buf6,"55__%i",ic+1);
66       sprintf(buf7,"mpd%i",ic+1);
67       
68       
69       hQTC[ic] = new TH1F(buf1,"QTC",10000,0,10000.0);
70       hQTCc[ic] = new TH1F(buf6,"QTCsmall",10000,0.0,10000.0);
71       hmpd[ic] = new TH1F(buf7,"mpd",20000,-10000.0,10000.0);
72       //     hCFD_QTC[ic] = new TH2F(buf2,"CFD_QTC",7000,1000.5,8000.5,2000,12000.5,18000.5);
73       hCFD_QTC[ic] = new TH2F(buf2,"CFD_QTC",700,1000.5,8000.5,2000,12000.5,18000.5);
74       hCFD_LED[ic] = new TH2F(buf3,"CFD_LED",500,0.0,500.0,100,14600.0,14700.0);
75       h1CFD_LED[ic] = new TH1F(buf4,"CFD_LED",1000,0.0,1000.0);
76
77
78     }
79     
80
81   }
82   //   cout<<" hist created "<<endl;
83    
84   TH1F*hEffCFD= new TH1F("hEffCFD","Effeciency",50,-0.25,24.25);
85   TH1F*hEffLED= new TH1F("hEffLED","Effeciency",50,-0.25,24.25);
86   TH1F*hEffQT0= new TH1F("hEffQT0","Effeciency",50,-0.25,24.25);
87   TH1F*hEffQT1= new TH1F("hEffQT1","Effeciency",50,-0.25,24.25);
88   
89   
90   Char_t filename[13];
91   sprintf(filename,"t0%i.raw",runNumber);
92    AliRawReader *reader = new AliRawReaderDate(filename);
93  // AliRawReader *reader = new AliRawReaderFile();
94    reader->LoadEquipmentIdsMap("T0map.txt");
95   //    reader->RequireHeader(kFALSE);
96    reader->RequireHeader(kTRUE);
97    AliT0RawReader *start = new AliT0RawReader(reader);
98    //  start->SetNumberOfTRM(1);
99    for (Int_t i0=0; i0<105; i0++)
100      {
101        for (Int_t j0=0; j0<5; j0++) allData[i0][j0]=0;  
102        numberOfHits[i0]=0;
103      }
104    Int_t event=0;
105   
106    while (reader->NextEvent()) {
107      start->Next();
108      for (Int_t i=0; i<105; i++) {
109        for (Int_t iHit=0; iHit<5; iHit++) 
110         {
111           allData[i][iHit]= start->GetData(i,iHit);
112         }
113     }
114  
115    if(event%1000 == 0) printf("Event:%d\n",event);
116
117    //    if(event > 200000) break;
118     //  cout<<"!!!!  Event Number "<< event-2<<endl;
119    
120         for (Int_t it = 0; it<24; it=it+2)
121           {
122             for (Int_t iHit=0; iHit<5; iHit++)
123               {
124             if(allData[it+25][iHit] != 0 && allData[it+26][iHit] !=0)
125               {
126                 Int_t cc=it/2;
127                 // if( allData[56][0]-allData[0][0] > 0) 
128                 hQTC[cc]->Fill(allData[it+25][iHit]-allData[it+26][iHit]);
129                 if( allData[55][0]-allData[0][0] > 0) hQTCc[cc]->Fill(allData[it+26][iHit]-allData[it+25][iHit]);
130                 hmpd[cc]->Fill(allData[it+26][iHit]-allData[it+25][iHit]);
131                 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]);
132                 if(allData[cc+1][iHit] != 0 && allData[cc+13][iHit]!=0 ) 
133                   {
134                     hCFD_LED[cc]->Fill(allData[cc+13][iHit]-allData[cc+1][iHit],allData[cc+1][iHit]-allData[0][0]);  
135                     h1CFD_LED[cc]->Fill(allData[cc+13][iHit]-allData[cc+1][iHit]);
136                   }
137                 //  cout<<allData[cc+1][iHit]-allData[0][0]<<" "<<cc<<endl;
138               }
139           }
140       }
141         
142     for (Int_t iHit=0; iHit<5; iHit++) 
143       {
144         
145         for(Int_t ik=1; ik<105; ik++)
146           { 
147             channels[ik] = -100;
148             if((allData[ik][iHit] - allData[0][0]) > 0 ) 
149               {
150                 numberOfHits[ik]++;
151                 hChannel[ik] -> Fill(allData[ik][iHit] - allData[0][0]);
152                 channels[ik] = allData[ik][iHit] - allData[0][0];
153               }
154           }
155           digitsTree->Fill();   
156       }
157         
158     event++;
159
160   } //event
161
162   
163  if (event>1)
164     {
165       cout<<"efficiency for "<<event<<" events"<<endl;
166       for (Int_t i0=1; i0<13;  i0++)
167         {
168
169           cout<<names[i0].Data()<<" "<<Float_t(numberOfHits[i0])/Float_t(event)<<" ";
170           cout<<names[i0+13].Data()<<" "<<Float_t(numberOfHits[i0])/Float_t(event)<<" ";
171           cout<<names[i0+57].Data()<<" "<<Float_t(numberOfHits[i0])/Float_t(event)<<" ";
172           cout<<names[i0+69].Data()<<" "<<Float_t(numberOfHits[i0])/Float_t(event)<<endl;
173           
174           hEffCFD->Fill(i0,Float_t(numberOfHits[i0])  / Float_t(event));
175           hEffLED->Fill(i0,Float_t(numberOfHits[i0+13]) / Float_t(event));
176           hEffCFD->Fill(i0+12,Float_t(numberOfHits[i0+57]) /Float_t(event));
177           hEffLED->Fill(i0+12,Float_t(numberOfHits[i0+69]) /Float_t(event));
178         }
179       cout<<endl;
180   
181       for (Int_t i0=0; i0<24;  i0=i0+2)
182         {
183           hEffQT1->Fill(i0, Float_t (numberOfHits[i0+25]) / Float_t(event));
184           hEffQT0->Fill(i0, Float_t (numberOfHits[i0]+26) / Float_t(event));
185           hEffQT1->Fill((i0+12), Float_t (numberOfHits[i0]+81) /  Float_t(event));
186           hEffQT0->Fill((i0+12), Float_t (numberOfHits[i0]+82) /  Float_t(event));
187           cout<<names[i0+25].Data()<<" "<<Float_t(numberOfHits[i0+25])/Float_t(event)<<" ";
188           cout<<names[i0+26].Data()<<" "<<Float_t(numberOfHits[i0+26])/Float_t(event)<<" ";
189           cout<<names[i0+81].Data()<<" "<<Float_t(numberOfHits[i0]+81)/Float_t(event)<<" ";
190           cout<<names[i0+82].Data()<<" "<<Float_t(numberOfHits[i0]+82)/Float_t(event)<<endl;
191
192
193         }
194     }         
195       
196      
197   Char_t filehist[40]; 
198  sprintf(filehist,"t0tree%i.root",runNumber);
199  //  sprintf(filehist,"test.root",runNumber);
200  TFile *hist = new TFile(filehist,"RECREATE");
201   cout<<" writing hist in file "<<filehist<<endl;
202
203     digitsTree->Write("",TObject::kOverwrite);
204
205
206   hEffCFD->Write();
207   hEffLED->Write();
208   hEffQT0->Write();
209   hEffQT1->Write();
210
211   for(Int_t ik=0; ik<105; ik++) hChannel[ik] ->Write();
212    
213   for (i=0; i<12; i++)
214     {
215       hQTC[i]->Write();
216       hQTCc[i]->Write();
217       hmpd[i]->Write();
218       hCFD_QTC[i]->Write();
219       hCFD_LED[i]->Write();
220       h1CFD_LED[i]->Write();
221     }
222
223   cout<<" hist in file"<<endl;
224  
225 }
226