]> git.uio.no Git - u/mrichter/AliRoot.git/blob - START/AliSTARTDigitizer.cxx
Code cleanup, removing debug printouts (Alla)
[u/mrichter/AliRoot.git] / START / AliSTARTDigitizer.cxx
1
2 /**************************************************************************
3  * Copyright(c) 1998-2000, ALICE Experiment at CERN, All rights reserved. *
4  *                                                                        *
5  * Author: The ALICE Off-line Project.                                    *
6  * Contributors are mentioned in the code where appropriate.              *
7  *                                                                        *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          *
14  * provided "as is" without express or implied warranty.                  *
15  **************************************************************************/
16
17
18 #include <TTree.h> 
19 #include <TFile.h>
20 #include <TDirectory.h>
21 #include <TRandom.h>
22 #include <TArrayI.h>
23 #include <TError.h>
24 #include <TH1F.h>
25 #include <TGraph.h>
26
27 #include "AliLog.h"
28 #include "AliSTARTDigitizer.h"
29 #include "AliSTART.h"
30 #include "AliSTARThit.h"
31 #include "AliSTARTdigit.h"
32 #include "AliRunDigitizer.h"
33 #include <AliDetector.h>
34 #include "AliRun.h"
35 #include <AliLoader.h>
36 #include <AliRunLoader.h>
37 #include <stdlib.h>
38 #include <Riostream.h>
39 #include <Riostream.h>
40 #include "AliSTARTParameters.h"
41 #include "AliCDBLocal.h"
42 #include "AliCDBStorage.h"
43 #include "AliCDBManager.h"
44 #include "AliCDBEntry.h"
45
46 ClassImp(AliSTARTDigitizer)
47
48 //___________________________________________
49   AliSTARTDigitizer::AliSTARTDigitizer()  :AliDigitizer()
50 {
51 // Default ctor - don't use it
52   ;
53 }
54
55 //___________________________________________
56 AliSTARTDigitizer::AliSTARTDigitizer(AliRunDigitizer* manager) 
57   :AliDigitizer(manager),
58    fSTART(0),
59    fHits(0),
60    fdigits(0),
61    ftimeCFD(0),
62    ftimeLED(0),
63    fADC(0),
64    fADC0(0)
65 {
66 // ctor which should be used
67
68   AliDebug(1,"processed");
69
70   fSTART = 0;
71   fHits = 0;
72   fdigits = 0;
73
74   ftimeCFD = new TArrayI(24); 
75   fADC = new TArrayI(24); 
76   ftimeLED = new TArrayI(24); 
77   fADC0 = new TArrayI(24); 
78   
79
80 }
81
82 //------------------------------------------------------------------------
83 AliSTARTDigitizer::~AliSTARTDigitizer()
84 {
85 // Destructor
86
87   AliDebug(1,"START");
88
89   delete ftimeCFD;
90   delete fADC;
91   delete ftimeLED;
92   delete  fADC0;
93 }
94
95  //------------------------------------------------------------------------
96 Bool_t AliSTARTDigitizer::Init()
97 {
98 // Initialization
99   AliDebug(1," Init");
100  return kTRUE;
101 }
102  
103
104 //---------------------------------------------------------------------
105
106 void AliSTARTDigitizer::Exec(Option_t* /*option*/)
107 {
108
109   /*
110     Produde digits from hits
111         digits is TObject and includes
112         We are writing array if left & right  TDC
113         left & right  ADC (will need for slow simulation)
114         TOF first particle left & right
115         mean time and time difference (vertex position)
116         
117   */
118
119   //output loader 
120   AliRunLoader *outRL = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
121   AliLoader * pOutStartLoader = outRL->GetLoader("STARTLoader");
122
123   AliDebug(1,"start...");
124   //input loader
125   //
126   // From hits to digits
127   //
128  Int_t hit, nhits;
129   Int_t countE[24];
130   Int_t volume, pmt, trCFD, trLED; 
131   Float_t sl, qt;
132   Int_t  bestRightTDC, bestLeftTDC, qtCh;
133   Float_t time[24], besttime[24], timeGaus[24] ;
134   //  Float_t channelWidth=25.; //ps
135     //Q->T-> coefficients !!!! should be asked!!!
136   Float_t gain[24],timeDelayCFD[24], timeDelayLED[24];
137   Int_t threshold =50; //photoelectrons
138   Float_t zdetA, zdetC;
139   TObjArray slewingLED;
140   AliSTARTParameters* param = AliSTARTParameters::Instance();
141   Int_t ph2Mip = param->GetPh2Mip();     
142   Int_t channelWidth = param->GetChannelWidth() ;  
143   
144   param->Init();
145   for (Int_t i=0; i<24; i++){
146     timeDelayCFD[i] = param->GetTimeDelayCFD(i);
147     timeDelayLED[i] = param->GetTimeDelayLED(i);
148     gain[i] = param->GetGain(i);
149     TGraph* gr = param ->GetSlew(i);
150     slewingLED.AddAtAndExpand(gr,i);
151     TGraph* grEff = param ->GetPMTeff(i);
152     fEffPMT.AddAtAndExpand(grEff,i);
153   }
154   zdetC = param->GetZposition(0);
155   zdetA = param->GetZposition(1);
156   
157   AliSTARThit  *startHit;
158   TBranch *brHits=0;
159   
160   Int_t nFiles=fManager->GetNinputs();
161   for (Int_t inputFile=0; inputFile<nFiles;  inputFile++) {
162     if (inputFile < nFiles-1) {
163         AliWarning(Form("ignoring input stream %d", inputFile));
164         continue;
165         
166     }
167     
168     Float_t besttimeright=99999.;
169     Float_t besttimeleft=99999.;
170     Int_t pmtBestRight=9999;
171     Int_t pmtBestLeft=9999;
172     Int_t timeDiff=99999, meanTime=0;
173     Int_t sumMult =0;
174     ftimeCFD -> Reset();
175     fADC -> Reset();
176     fADC0 -> Reset();
177     ftimeLED ->Reset();
178     for (Int_t i0=0; i0<24; i0++)
179       {
180         time[i0]=besttime[i0]=timeGaus[i0]=99999; countE[i0]=0;
181       }
182     AliRunLoader * inRL = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
183     AliLoader * pInStartLoader = inRL->GetLoader("STARTLoader");
184     if (!inRL->GetAliRun()) inRL->LoadgAlice();
185     AliSTART *fSTART  = (AliSTART*)inRL ->GetAliRun()->GetDetector("START");
186
187        //read Hits 
188     pInStartLoader->LoadHits("READ");//probably it is necessary to load them before
189     TClonesArray *fHits = fSTART->Hits ();
190     TTree *th = pInStartLoader->TreeH();
191     brHits = th->GetBranch("START");
192     if (brHits) {
193       fSTART->SetHitsAddressBranch(brHits);
194     }else{
195       AliError("Branch START hit not found");
196       exit(111);
197     } 
198     Int_t ntracks    = (Int_t) th->GetEntries();
199     
200     if (ntracks<=0) return;
201     // Start loop on tracks in the hits containers
202     for (Int_t track=0; track<ntracks;track++) {
203       brHits->GetEntry(track);
204       nhits = fHits->GetEntriesFast();
205       for (hit=0;hit<nhits;hit++) 
206         {
207           startHit   = (AliSTARThit*) fHits->UncheckedAt(hit);
208           if (!startHit) {
209             AliError("The unchecked hit doesn't exist");
210             break;
211           }
212           pmt=startHit->Pmt();
213           Int_t numpmt=pmt-1;
214                   Double_t e=startHit->Etot();
215           volume = startHit->Volume();
216           
217           if(e>0 && RegisterPhotoE(numpmt,e)) {
218             countE[numpmt]++;
219             besttime[numpmt] = startHit->Time();
220             if(besttime[numpmt]<time[numpmt])
221               {
222                 time[numpmt]=besttime[numpmt];
223               }
224           } //photoelectron accept 
225         } //hits loop
226     } //track loop
227     
228     //spread time right&left by 25ps   && besttime
229     Float_t c = 0.0299792; // cm/ps
230     
231     Float_t koef=(zdetA-zdetC)/c; //correction position difference by cable
232     for (Int_t ipmt=0; ipmt<12; ipmt++){
233       if(countE[ipmt] > threshold) {
234         timeGaus[ipmt]=gRandom->Gaus(time[ipmt],25)+koef;
235         if(timeGaus[ipmt]<besttimeleft){
236           besttimeleft=timeGaus[ipmt]; //timeleft
237           pmtBestLeft=ipmt;}
238       }
239     }
240     for ( Int_t ipmt=12; ipmt<24; ipmt++){
241       if(countE[ipmt] > threshold) {
242         timeGaus[ipmt]=gRandom->Gaus(time[ipmt],25); 
243         if(timeGaus[ipmt]<besttimeright) {
244           besttimeright=timeGaus[ipmt]; //timeright
245           pmtBestRight=ipmt;}
246       } 
247     }
248   
249    //folding with alignmentz position distribution  
250
251     bestLeftTDC=Int_t ((besttimeleft+1000*timeDelayCFD[pmtBestLeft])
252                        /channelWidth);
253  
254     bestRightTDC=Int_t ((besttimeright+1000*timeDelayCFD[pmtBestLeft])
255                         /channelWidth);
256     timeDiff=Int_t (((besttimeleft-besttimeright)+1000*timeDelayCFD[pmtBestRight])
257                     /channelWidth);
258     meanTime=Int_t (((besttimeright+1000*timeDelayCFD[pmtBestLeft]+
259                       besttimeleft+1000*timeDelayCFD[pmtBestLeft])/2.)
260                     /channelWidth);
261  
262      AliDebug(2,Form(" time in ns %f %f  ",besttimeleft,besttimeright ));
263     for (Int_t i=0; i<24; i++)
264       {
265         Float_t  al = countE[i]; 
266         if (al>threshold && timeGaus[i]<50000 ) {
267         //fill ADC
268         // QTC procedure:
269         // phe -> mV 0.3; 1MIP ->500phe -> ln (amp (mV)) = 5;
270         // max 200ns, HIJING  mean 50000phe -> 15000mv -> ln = 15 (s zapasom)
271         // channel 25ps
272           qt= 50.*al*gain[i]/ph2Mip;  // 50mv/Mip amp in mV 
273         //  fill TDC
274           trCFD = Int_t (timeGaus[i] + 1000.*timeDelayCFD[i])/channelWidth; 
275           trLED= Int_t (timeGaus[i] + 1000.*timeDelayLED[i]); 
276           sl = ((TGraph*)slewingLED.At(i))->Eval(qt);
277           trLED = Int_t(( trLED + 1000*sl )/channelWidth);
278           qtCh=Int_t (1000.*TMath::Log(qt)) / channelWidth;
279           fADC0->AddAt(0,i);
280           fADC->AddAt(qtCh,i);
281           ftimeCFD->AddAt(Int_t (trCFD),i);
282           ftimeLED->AddAt(trLED,i); 
283           sumMult += Int_t ((al*gain[i]/ph2Mip)*50) ;
284         }
285       } //pmt loop
286
287         if (sumMult > threshold){
288           fSumMult =  Int_t (TMath::Log(sumMult));
289         }
290     fSTART->AddDigit(bestRightTDC,bestLeftTDC,meanTime,timeDiff,fSumMult,
291                      ftimeCFD,fADC,ftimeLED,fADC0);
292     pOutStartLoader->UnloadHits();
293   } //input streams loop
294   
295     //load digits    
296     pOutStartLoader->LoadDigits("UPDATE");
297     TTree *treeD  = pOutStartLoader->TreeD();
298     if (treeD == 0x0) {
299       pOutStartLoader->MakeTree("D");
300       treeD = pOutStartLoader->TreeD();
301     }
302     treeD->Reset();
303     fSTART  = (AliSTART*)outRL ->GetAliRun()->GetDetector("START");
304     // Make a branch in the tree 
305     fSTART->MakeBranch("D");
306      treeD->Fill();
307   
308      pOutStartLoader->WriteDigits("OVERWRITE");
309      
310      fSTART->ResetDigits();
311      pOutStartLoader->UnloadDigits();
312      
313 }
314
315
316 //------------------------------------------------------------------------
317 Bool_t AliSTARTDigitizer::RegisterPhotoE(Int_t ipmt,Double_t energy)
318 {
319
320   
321   //  Float_t hc=197.326960*1.e6; //mev*nm
322   Double_t hc=1.973*1.e-6; //gev*nm
323   Float_t lambda=hc/energy;
324   Float_t eff = ((TGraph*) fEffPMT.At(ipmt))->Eval(lambda);
325   Double_t  p = gRandom->Rndm();
326
327   if (p > eff)
328     return kFALSE;
329   
330   return kTRUE;
331 }
332
333 //----------------------------------------------------------------------------