]> git.uio.no Git - u/mrichter/AliRoot.git/blob - START/AliSTARTReconstructor.cxx
f094cc0ea419f9f5d9ed4fb31058a7b8bde3b808
[u/mrichter/AliRoot.git] / START / AliSTARTReconstructor.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 #include <Riostream.h>
19
20 #include <TDirectory.h>
21
22 #include "AliRunLoader.h"
23 #include "AliRun.h"
24 #include <AliESD.h>
25 #include "AliLog.h"
26 #include <TClonesArray.h>
27 #include "AliSTARTRecPoint.h"
28 #include "AliRawReader.h"
29 #include "AliSTARTRawReader.h"
30 #include "AliSTARTLoader.h"
31 #include "AliSTARTdigit.h"
32 #include "AliSTARTReconstructor.h"
33 #include "AliSTARTParameters.h"
34 #include "AliSTARTAlignData.h"
35 #include "AliSTARTCalibData.h"
36 #include "AliCDBLocal.h"
37 #include "AliCDBStorage.h"
38 #include "AliCDBManager.h"
39 #include "AliCDBEntry.h"
40
41 #include <TArrayI.h>
42
43 ClassImp(AliSTARTReconstructor)
44 AliSTARTAlignData* AliSTARTReconstructor::fgAlignData = 0;
45 AliSTARTCalibData* AliSTARTReconstructor::fgCalibData = 0;
46
47   void  AliSTARTReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
48 {
49   //START raw data-> digits conversion
50  // reconstruct time information from raw data
51   AliSTARTRawReader myrawreader(rawReader,digitsTree);
52   myrawreader.NextThing();
53 }
54   void AliSTARTReconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const
55 {
56 // START digits reconstruction
57 // STARTRecPoint writing 
58
59     //Q->T-> coefficients !!!! should be asked!!!
60   //  Float_t ph2MIP=500;
61   Float_t gain[24], timeDelayCFD[24], timeDelayLED[24];
62   Int_t threshold =50; //photoelectrons
63   //  Int_t mV2channel=200000/(25*25);  //5V -> 200ns
64   Float_t zdetA,zdetC;
65   TObjArray slewingLED;
66     
67   TArrayI * fADC = new TArrayI(24); 
68   TArrayI * fTimeCFD = new TArrayI(24); 
69   TArrayI * fADCLED = new TArrayI(24); 
70   TArrayI * fTimeLED = new TArrayI(24); 
71
72   AliSTARTParameters* param = AliSTARTParameters::Instance();
73   Int_t ph2MIP = param->GetPh2Mip();     
74   Int_t channelWidth = param->GetChannelWidth() ;  
75   
76     for (Int_t i=0; i<24; i++){
77       timeDelayCFD[i] = param->GetTimeDelayCFD(i);
78       timeDelayLED[i] = param->GetTimeDelayLED(i);
79       gain[i] = param->GetGain(i);
80       slewingLED.AddAtAndExpand(param->GetSlew(i),i);
81     }
82     zdetC = param->GetZposition(0);
83     zdetA  = param->GetZposition(1);
84   
85   AliDebug(1,Form("Start DIGITS reconstruction "));
86    Int_t channelWigth=25; //ps
87
88   TBranch *brDigits=digitsTree->GetBranch("START");
89   cout<<" TBranch *brDigits "<<brDigits<<endl;
90   AliSTARTdigit *fDigits = new AliSTARTdigit();
91   if (brDigits) {
92     brDigits->SetAddress(&fDigits);
93   }else{
94     cerr<<"EXEC Branch START digits not found"<<endl;
95     return;
96   }
97   //  brDigits->Print();
98   brDigits->GetEntry(0);
99   cout<<"  brDigits->GetEntry(0); "<<endl;
100   //  fDigits->Print();
101   fDigits->GetTime(*fTimeCFD);
102   cout<<"  fDigits->GetTime(*fTimeCFD); "<<endl;
103   fDigits->GetADC(*fADC);
104   fDigits->GetTimeAmp(*fTimeLED);
105   fDigits->GetADCAmp(*fADCLED);
106
107   Float_t time[24], adc[24];
108   for (Int_t ipmt=0; ipmt<24; ipmt++)
109     {
110       
111       if(fTimeCFD->At(ipmt)){
112          time[ipmt] = channelWigth *( fTimeCFD->At(ipmt)) - 1000*timeDelayCFD[ipmt];
113          cout<<ipmt<<" "<<time[ipmt];
114          Float_t adc_digmV = channelWigth * Float_t (fADC->At(ipmt)) ;
115          cout<<"  adc_digmV "<< adc_digmV;
116          //      adc[ipmt] = ( TMath::Exp (fADC->At(ipmt)) / gain[ipmt] /mV2channel );
117          adc[ipmt] = TMath::Exp(adc_digmV);
118          cout<<" adc"<<adc[ipmt]<<" inMIP "<<adc[ipmt]/50<< endl;
119       }
120     }
121
122   Int_t besttimeright=channelWigth * (fDigits->BestTimeRight());
123   Int_t besttimeleft=channelWigth * (fDigits->BestTimeLeft());
124
125   //folding with experimental time distribution
126   //  Float_t c = 29.9792; // cm/ns
127   Float_t c = 0.0299792; // cm/ps
128   Float_t lenr=TMath::Sqrt(zdetA*zdetA + 6.5*6.5);
129   Float_t lenl=TMath::Sqrt(zdetC*zdetC + 6.5*6.5);
130   Float_t timeDiff=channelWigth * (fDigits->TimeDiff());
131   Int_t meanTime=channelWigth * (fDigits->MeanTime());
132   Float_t ds=(c*(timeDiff)-(lenr-lenl))/2;
133   AliDebug(2,Form(" timediff in ns %f  real point%f",timeDiff,ds));
134   
135   /*
136   fDigits->GetSumMult(*fSumMult);
137   Int_t multipl[4]; 
138  
139  for (Int_t i=0; i<4; i++)
140     {
141       Float_t  mult=Float_t (fSumMult->At(i));
142       Float_t   realMultmV=TMath::Exp(mult/mV2channel);
143       multipl[i]=Int_t ((realMultmV/ph2mV)/500+0.5);
144     }
145   */
146
147   //  AliDebug(2,Form(" multiplicity Abs side %i  multiplicity non-Abs side %i",multipl[1],multipl[2]));
148
149   AliSTARTRecPoint* frecpoints= new AliSTARTRecPoint ();
150   clustersTree->Branch( "START", "AliSTARTRecPoint" ,&frecpoints, 405,1);
151   frecpoints->SetTimeBestRight(besttimeright);
152   frecpoints->SetTimeBestLeft(besttimeleft);
153   frecpoints->SetVertex(ds);
154   frecpoints->SetMeanTime(meanTime);
155   /*
156   frecpoints->SetMult(multipl[0]);
157   frecpoints->SetMultA(multipl[2]);
158   frecpoints->SetMultC(multipl[1]);
159   */
160   clustersTree->Fill();
161 }
162
163
164 void AliSTARTReconstructor::FillESD(AliRunLoader* runLoader, AliESD *pESD) const
165 {
166
167   /***************************************************
168   Resonstruct digits to vertex position
169   ****************************************************/
170   
171   //  Float_t c = 0.3;  //speed of light mm/ps
172   // Float_t Zposition=0;
173   
174   if (!runLoader) {
175     AliError("Reconstruct >> No run loader");
176     return;
177   }
178   
179   AliDebug(1,Form("Start FillESD START"));
180
181   AliSTARTLoader* pStartLoader = (AliSTARTLoader*) runLoader->GetLoader("STARTLoader");
182  
183   pStartLoader->LoadRecPoints("READ");
184   
185     TTree *treeR = pStartLoader->TreeR();
186   
187    AliSTARTRecPoint* frecpoints= new AliSTARTRecPoint ();
188     if (!frecpoints) {
189     AliError("Reconstruct Fill ESD >> no recpoints found");
190     return;
191   }
192   
193   AliDebug(1,Form("Start FillESD START"));
194    TBranch *brRec = treeR->GetBranch("START");
195     if (brRec) {
196       brRec->SetAddress(&frecpoints);
197     }else{
198       cerr<<"EXEC Branch START rec not found"<<endl;
199       exit(111);
200     } 
201  
202     brRec->GetEntry(0);
203     Float_t Zposition=frecpoints->GetVertex();
204     
205     pESD->SetT0zVertex(Zposition);
206     pStartLoader->UnloadRecPoints();
207     
208 } // vertex in 3 sigma
209
210
211
212
213
214