]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FIT/FITbase/AliFITDigitizer.cxx
Update master to aliroot
[u/mrichter/AliRoot.git] / FIT / FITbase / AliFITDigitizer.cxx
CommitLineData
c1c44db3 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
48ClassImp(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//___________________________________________
62AliFITDigitizer::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//------------------------------------------------------------------------
75AliFITDigitizer::~AliFITDigitizer()
76{
77// Destructor
78
79 AliDebug(1,"FIT");
80
81 }
82
83//------------------------------------------------------------------------
84Bool_t AliFITDigitizer::Init()
85{
86// Initialization
87 AliDebug(1," Init");
88 return kTRUE;
89
90}
91
92//---------------------------------------------------------------------
93void 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//____________________________________________________________________________
142void AliFITDigitizer::DigitizeHits()
143{
144
a1455eb4 145 Int_t hit, nhits;
146 Float_t time[240], besttime[240];
147 Int_t countE[240];
c1c44db3 148 Int_t timeCFD, timeLED, timeQT1, timeQT0;
149
150 Int_t threshold = 0; //photoelectrons
c1c44db3 151 Float_t channelWidth = 24.4 ;
152 Int_t pmt, mcp, volume, qt;
153 //eqailized distance from IP
a1455eb4 154 Float_t zdetC = 84;
155 Float_t zdetA = 335.;
c1c44db3 156 Float_t c = 0.0299792458; // cm/ps
157 Float_t eqdistance = (zdetA - zdetC) /c;
a1455eb4 158 Float_t ph2Mip = 318;
c1c44db3 159
160 AliFITHits *startHit;
161 TBranch *brHits=0;
162
163 Int_t nFiles=fDigInput->GetNinputs();
164 for (Int_t inputFile=0; inputFile<nFiles; inputFile++) {
165 if (inputFile < nFiles-1) {
166 AliWarning(Form("ignoring input stream %d", inputFile));
167 continue;
168 }
169
a1455eb4 170 for (Int_t i0=0; i0<240; i0++)
c1c44db3 171 {
172 time[i0]=besttime[i0]=999999; countE[i0]=0;
173 }
174 AliRunLoader * inRL = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(inputFile));
175 AliLoader * fitLoader = inRL->GetLoader("FITLoader");
176 if (!inRL->GetAliRun()) inRL->LoadgAlice();
177 Int_t numpmt;
178 //read Hits
179 fitLoader->LoadHits("READ");//probably it is necessary to load them before
180 fHits = fFIT->Hits ();
181 TTree *th = fitLoader->TreeH();
182 brHits = th->GetBranch("FIT");
183 if (brHits) {
184 fFIT->SetHitsAddressBranch(brHits);
185 }else{
186 AliWarning("Branch FIT hit not found for this event");
187 continue;
188 }
189 Int_t ntracks = (Int_t) th->GetEntries();
190 if (ntracks<=0) return;
191 // Start loop on tracks in the hits containers
192 for (Int_t track=0; track<ntracks;track++) {
193 brHits->GetEntry(track);
194 nhits = fHits->GetEntriesFast();
195 for (hit=0;hit<nhits;hit++)
196 {
197 startHit = (AliFITHits*) fHits->UncheckedAt(hit);
198 if (!startHit) {
199 AliError("The unchecked hit doesn't exist");
200 break;
201 }
a1455eb4 202 Float_t ipart = startHit->Particle();
203 if (ipart<49) continue;
c1c44db3 204 pmt = startHit->Pmt();
205 mcp = startHit->MCP();
206 volume = startHit->Volume();
a1455eb4 207 if(volume==2) continue;
208 numpmt= 4*mcp + pmt;
c1c44db3 209 besttime[numpmt] = startHit->Time();
210 if(besttime[numpmt]<time[numpmt]) time[numpmt]=besttime[numpmt];
211 countE[numpmt]++;
212 } //hits loop
213 } //track loop
214
a1455eb4 215 for (Int_t ipmt=0; ipmt<240; ipmt++)
c1c44db3 216 {
217 if (countE[ipmt]>threshold && time[ipmt]<50000 && time[ipmt]>0 ) {
218 //fill ADC
219 // QTC procedure:
a1455eb4 220 // 1MIP ->318phe ;
221 qt= 1000* countE[ipmt] /ph2Mip; // 318 ph/Mip
222 // fill TDC
223 if (ipmt>100) time[ipmt] = time[ipmt] + eqdistance;
224 timeCFD = Int_t (gRandom->Gaus(time[ipmt], 50)/channelWidth );
225 timeLED = Int_t (time[ipmt]/channelWidth );
226 timeQT0 = 0;
227 timeQT1 = qt ;
228 AliDebug(1,Form("Digits::::: numpmt %i time CFD %i QTC %i :: counts %i \n ", ipmt, timeCFD, timeQT1, countE[ipmt]) );
229 fFIT-> AddDigit(ipmt, timeCFD, timeLED, timeQT0, timeQT1, 0);
c1c44db3 230 } //hitted PMTs
231 } //pmt loop
232 fitLoader->UnloadHits();
233
234 }
235}
236
237//____________________________________________________________________________
a1455eb4 238void AliFITDigitizer::AddDigit(Int_t npmt,
c1c44db3 239 Int_t timeCFD, Int_t timeLED, Int_t timeQT0,
240 Int_t timeQT1)
241 {
242
243// Adds Digit
244
245 TClonesArray &ldigits = *fDigits;
246
247 new(ldigits[fNdigits++]) AliFITDigit(npmt,
248 timeCFD, timeLED, timeQT0, timeQT1);
249
250}
251//____________________________________________________________________________
252void AliFITDigitizer::ResetDigits()
253{
254
255// Clears Digits
256
257 fNdigits = 0;
258 if (fDigits) fDigits->Clear();
259}