Andreas's improvement of support
[u/mrichter/AliRoot.git] / START / readDigits.C
1 void readDigits() 
2 {
3  
4   // Dynamically link some shared libs
5   if (gClassTable->GetID("AliRun") < 0) {
6     gROOT->LoadMacro("loadlibs.C");
7     loadlibs();
8   }
9   char filename[100];
10   sprintf(filename,"galice.root");
11   AliRunLoader* rl = AliRunLoader::Open("galice.root",AliConfig::fgkDefaultEventFolderName,"read");
12   if (rl == 0x0)
13    {
14      cerr<<"Can not open session for file galice.root\n";
15      return;
16    }
17
18   rl->LoadgAlice();
19   gAlice = rl->GetAliRun();
20   
21   AliSTART* START  = (AliSTART *)gAlice->GetDetector("START");
22   
23   rl->LoadHeader();
24   rl->LoadKinematics("READ");
25   Int_t retval;
26   AliLoader* lstart = rl->GetLoader("STARTLoader");
27
28   Int_t iNevents=rl->GetNumberOfEvents();
29   cout<<"  nevents   "<<iNevents<<endl;
30
31    char nameTD[8],nameTR[8];
32
33   TH1F *hTimediff = new TH1F("hTimediff","Time difference",100,0,200);
34   TH1F *hTimePs = new TH1F("hTimePs","Time in Ps",100,-200,200);
35   TH1F *hMeanTime = new TH1F("hMeanTime","Time in Ps",100,2000,2500);
36   TH1F *hallADC = new TH1F("hallright","ADC summary right",100,0,200);
37   TH1F *hADCright = new TH1F("hADCright","ADC right",100,0,200);
38   TH1F *hADCleft = new TH1F("hADCleft","ADC left",100,0,200);
39   TH1F *hTimeright = new TH1F("hTimeright","Time right",100,2000.,3200.);
40   TH1F *hTimeleft = new TH1F("hTimeleft","Time left",100,2000.,3200.);
41   TH1F *hBestTimeright = new TH1F("hBestTimeright","First time right",
42                                   100,2000.,3200);
43   TH1F *hBestTimeleft = new TH1F("hBestTimeleft","First time left",
44                                  100,11000.,13000.);
45    
46   //  digits = new AliSTARTdigit();
47   AliSTARTdigit *digits   ; // digits
48   digits = new AliSTARTdigit();
49  
50   timeRight = new TArrayI(12);
51   timeLeft = new TArrayI(12);
52   ADCRight = new TArrayI(12);
53   ADCLeft = new TArrayI(12);
54
55  // Event ------------------------- LOOP  
56   for (Int_t j=0; j<iNevents; j++){
57     //  gAlice->GetEvent(j);
58     rl->GetEvent(j);
59     //   lstart->Dump();
60     lstart->LoadHits("READ");
61     lstart->LoadDigits("READ");
62     sprintf(nameTD,"START_D_%d",j);
63     printf("%s\n",nameTD);
64   TObject *td = (TObject*)gDirectory->Get(nameTD);
65   // td->Dump();
66     //   cout<<" td "<<td<<endl;
67   td->Read(nameTD);
68    digits->Read(nameTD);
69    //   digits->Read(nameTD);
70   // digits->Print();
71   printf("time %d\n",digits->GetTimeDiff());
72    
73     if(digits->GetTimeDiff()!=999999){
74       Int_t timediff = digits->GetTimeDiff();
75       //     Double_t timePs=(timediff-128)*10.; // time in Ps channel_width =10ps
76       Int_t timePs=(512-timediff)*2.5.; // time in Ps channel_width =10ps
77       cout<<"timediff "<<timediff<<" timePs "<<timePs<<endl;
78       hTimediff->Fill(timediff);
79       hTimePs->Fill(timePs);
80       Int_t mean=digits->GetMeanTime();
81       cout<<" mean "<<mean<<endl;
82       mean=mean*2.5;
83       hMeanTime->Fill(mean);
84       Int_t br=digits->GetBestTimeRight(); 
85       Int_t bl=digits->GetBestTimeLeft();
86       cout<<"BestTimeRight "<<br*2.5<<" BestTimeLeft "<<bl*2.5<<endl;
87       hBestTimeright->Fill(br*2.5); 
88       hBestTimeleft ->Fill(bl*2.5); 
89       digits->GetTimeRight(*timeRight );
90       digits->GetTimeLeft(*timeLeft );
91       digits->GetADCRight(*ADCRight );
92       digits->GetADCLeft(*ADCLeft );
93         for (Int_t i=0; i<12; i++) 
94         {
95           Int_t t=timeRight.At(i);
96           Int_t ADC=ADCRight.At(i);
97           hTimeright->Fill(t*2.5);
98           hADCright->Fill(ADC);
99         }
100         for (Int_t i=0; i<12; i++) 
101         {
102           Int_t ADC=ADCRight.At(i);
103           Int_t t=timeLeft.At(i);
104           hTimeleft->Fill(t*2.5);
105           hADCleft->Fill(ADC);
106         }
107     }
108   }
109   
110   Hfile = new TFile("Figdigits.root","RECREATE","Histograms for START digits");
111   printf("Writting histograms to root file \n");
112   Hfile->cd();
113   //Create a canvas, set the view range, show histograms
114   gStyle->SetOptStat(111111);
115   //  TCanvas *c1 = new TCanvas("c1","Alice START Time ",400,10,600,600);
116   hADCright->Write();
117   hADCleft->Write();
118   hTimeright->Write();
119   hTimeleft->Write();
120   hTimePs->SetXTitle("arriving time, ps");
121   hTimePs->SetYTitle("number of events");
122   hTimePs->Write();
123   hMeanTime->Write();
124   hBestTimeright->Write(); 
125   hBestTimeleft ->Write(); 
126   Hfile->Close();
127     
128  
129 } // end of macro
130
131
132
133