]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FIT/AliFITDigitizer.cxx
changes for FIT
[u/mrichter/AliRoot.git] / FIT / AliFITDigitizer.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2000, 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
17 /******************************************************************
18  *    Produde digits from hits
19  *       digits is TObject and includes
20  *      We are writing array if C & A  TDC
21  *      C & A  ADC (will need for slow simulation)
22  *      TOF first particle C & A
23  *      mean time and time difference (vertex position)
24  *
25  *      Alla.Maevskaya@cern.ch 
26  ****************************************************************/
27
28
29 #include <TArrayI.h>
30 #include <TFile.h>
31 #include <TGraph.h>
32 #include <TH1F.h>
33 #include <TMath.h>
34 #include <TRandom.h>
35 #include <TTree.h> 
36
37 #include "AliLog.h"
38 #include "AliFITDigitizer.h"
39 #include "AliFIT.h"
40 #include "AliFITHits.h"
41 #include "AliFITDigit.h"
42 #include "AliDigitizationInput.h"
43 #include "AliRun.h"
44 #include <AliLoader.h>
45 #include <AliRunLoader.h>
46 #include <stdlib.h>
47
48 ClassImp(AliFITDigitizer)
49
50 //___________________________________________
51   AliFITDigitizer::AliFITDigitizer()  :AliDigitizer(),
52                                      fFIT(0),
53                                      fHits(0),
54                                      fDigits(0),
55                                      fNdigits(0)
56 {
57 // Default ctor - don't use it
58
59 }
60
61 //___________________________________________
62 AliFITDigitizer::AliFITDigitizer(AliDigitizationInput* digInput) 
63   :AliDigitizer(digInput),
64    fFIT(0),
65    fHits(0),
66    fDigits(0),
67    fNdigits(0)
68 {
69 // ctor which should be used
70  
71 }
72
73
74 //------------------------------------------------------------------------
75 AliFITDigitizer::~AliFITDigitizer()
76 {
77 // Destructor
78
79   AliDebug(1,"FIT");
80
81  }
82
83 //------------------------------------------------------------------------
84 Bool_t AliFITDigitizer::Init()
85 {
86 // Initialization
87   AliDebug(1," Init");
88  return kTRUE;
89
90 }
91  
92 //---------------------------------------------------------------------
93 void AliFITDigitizer::Digitize(Option_t* /*option*/)
94 {
95
96   /*
97     Produde digits from hits
98     digits is TObject and includes
99     We are writing array if C & A for each channel CFD, LED, QT0 and QT1
100     C & A  ADC (will need for slow simulation)
101   */
102   
103   
104   
105   //output loader 
106   AliDebug(1,"start...");
107   //input loader
108   //
109   // From hits to digits
110   //
111   
112   AliRunLoader *outRL = AliRunLoader::GetRunLoader(fDigInput->GetOutputFolderName());
113   AliLoader * outFitLoader = outRL->GetLoader("FITLoader");
114   
115   fFIT  = static_cast<AliFIT*>(gAlice->GetDetector("FIT"));
116   if (!fFIT) {
117     AliError("Can not get FIT from gAlice");
118     return;
119   }  
120   fFIT->ResetDigits();
121   
122   DigitizeHits();
123   
124   //load digits    
125   outFitLoader->LoadDigits("UPDATE");
126   TTree *treeD  = outFitLoader->TreeD();
127   if (treeD == 0x0) {
128     outFitLoader->MakeTree("D");
129     treeD = outFitLoader->TreeD();
130   }
131   treeD->Reset();
132   fFIT  = (AliFIT*)outRL ->GetAliRun()->GetDetector("FIT");
133   // Make a branch in the tree 
134   fFIT->MakeBranch("D");
135   treeD->Fill();
136   
137   outFitLoader->WriteDigits("OVERWRITE");
138   fFIT->ResetDigits();
139   outFitLoader->UnloadDigits();
140 }
141 //____________________________________________________________________________
142 void AliFITDigitizer::DigitizeHits()
143 {
144
145    Int_t hit, nhits;
146   Float_t time[160], besttime[160];
147   Int_t countE[160];
148   Int_t timeCFD, timeLED, timeQT1, timeQT0;
149
150   Int_t threshold = 0; //photoelectrons
151   Int_t ph2Mip = 200;    
152   Float_t mip2qtc=0.005; 
153   Float_t channelWidth = 24.4 ; 
154   Int_t pmt, mcp, volume, qt; 
155   //eqailized distance from IP
156   Float_t zdetC = 82;
157   Float_t zdetA = 375.;
158   Float_t c = 0.0299792458; // cm/ps
159   Float_t eqdistance = (zdetA - zdetC) /c;
160   
161   AliFITHits  *startHit;
162   TBranch *brHits=0;
163  
164   Int_t nFiles=fDigInput->GetNinputs();
165   for (Int_t inputFile=0; inputFile<nFiles;  inputFile++) {
166     if (inputFile < nFiles-1) {
167       AliWarning(Form("ignoring input stream %d", inputFile));
168       continue;
169      }
170
171   for (Int_t i0=0; i0<160; i0++)
172       {
173         time[i0]=besttime[i0]=999999; countE[i0]=0;
174       }
175   AliRunLoader * inRL = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(inputFile));
176   AliLoader * fitLoader = inRL->GetLoader("FITLoader");
177   if (!inRL->GetAliRun()) inRL->LoadgAlice();
178   Int_t numpmt;
179   //read Hits 
180   fitLoader->LoadHits("READ");//probably it is necessary to load them before
181   fHits = fFIT->Hits ();
182   TTree *th = fitLoader->TreeH();
183   brHits = th->GetBranch("FIT");
184   if (brHits) {
185     fFIT->SetHitsAddressBranch(brHits);
186   }else{
187     AliWarning("Branch FIT hit not found for this event");
188     continue;      
189   } 
190   Int_t ntracks    = (Int_t) th->GetEntries();
191   if (ntracks<=0) return;
192   // Start loop on tracks in the hits containers
193   for (Int_t track=0; track<ntracks;track++) {
194     brHits->GetEntry(track);
195     nhits = fHits->GetEntriesFast();
196     for (hit=0;hit<nhits;hit++) 
197       {
198         startHit   = (AliFITHits*) fHits->UncheckedAt(hit);
199         if (!startHit) {
200           AliError("The unchecked hit doesn't exist");
201           break;
202         }
203         pmt = startHit->Pmt();
204         mcp = startHit->MCP();
205         volume = startHit->Volume();
206         numpmt= volume*80 +4*(mcp) + (pmt-1);
207         besttime[numpmt] = startHit->Time();
208         if(besttime[numpmt]<time[numpmt]) time[numpmt]=besttime[numpmt];
209         countE[numpmt]++;
210       } //hits loop
211   } //track loop
212   
213   for (Int_t ipmt=0; ipmt<160; ipmt++)
214     {
215       if (countE[ipmt]>threshold && time[ipmt]<50000 && time[ipmt]>0 ) {
216         //fill ADC
217         // QTC procedure:
218         // 1MIP ->200phe  ;
219           qt= countE[ipmt] /*/ph2Mip*/;  // 50mv/Mip amp in mV 
220           //  fill TDC
221           if (ipmt<80) time[ipmt] = time[ipmt] + eqdistance;
222           timeCFD = Int_t (gRandom->Gaus(time[ipmt], 50)/channelWidth ); 
223           timeLED =  Int_t (time[ipmt]/channelWidth );
224           timeQT0 = 0;
225           timeQT1 = Int_t (qt ) ;
226           AliDebug(1,Form("Digits:::::  numpmt %i  time CFD %i QTC  %i :: counts %i \n ",  ipmt, timeCFD, timeQT1,  countE[ipmt]) );
227           fFIT-> AddDigit(ipmt,   timeCFD, timeLED, timeQT0,  timeQT1, 0);
228       } //hitted PMTs
229     } //pmt loop
230   fitLoader->UnloadHits();
231   
232   }
233 }
234
235 //____________________________________________________________________________
236 void AliFITDigitizer::AddSDigit(Int_t npmt,  
237                                 Int_t timeCFD, Int_t timeLED, Int_t timeQT0, 
238                                 Int_t timeQT1) 
239  { 
240  
241 // Adds Digit 
242  
243   TClonesArray &ldigits = *fDigits;  
244          
245   new(ldigits[fNdigits++]) AliFITDigit(npmt,  
246                                        timeCFD, timeLED, timeQT0, timeQT1);
247          
248 }
249 //____________________________________________________________________________
250 void AliFITDigitizer::ResetDigits()
251 {
252
253 // Clears Digits
254
255   fNdigits = 0;
256   if (fDigits) fDigits->Clear();
257 }