ede9aff7 |
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 <TVector.h> |
20 | #include <TObjArray.h> |
21 | #include <TFile.h> |
22 | #include <TDirectory.h> |
23 | #include <TRandom.h> |
24 | |
25 | |
26 | #include "AliSTARTDigitizer.h" |
27 | #include "AliSTART.h" |
28 | #include "AliSTARThit.h" |
29 | #include "AliSTARTdigit.h" |
30 | #include "AliRunDigitizer.h" |
31 | |
32 | #include "AliRun.h" |
33 | #include "AliPDG.h" |
34 | |
35 | #include <stdlib.h> |
36 | #include <iostream.h> |
37 | #include <fstream.h> |
38 | |
39 | ClassImp(AliSTARTDigitizer) |
40 | |
41 | //___________________________________________ |
42 | AliSTARTDigitizer::AliSTARTDigitizer() :AliDigitizer() |
43 | { |
44 | // Default ctor - don't use it |
45 | ; |
46 | } |
47 | |
48 | //___________________________________________ |
49 | AliSTARTDigitizer::AliSTARTDigitizer(AliRunDigitizer* manager) |
50 | :AliDigitizer(manager) |
51 | { |
52 | cout<<"AliSTARTDigitizer::AliSTARTDigitizer"<<endl; |
53 | // ctor which should be used |
54 | // fDebug =0; |
55 | // if (GetDebug()>2) |
56 | // cerr<<"AliSTARTDigitizer::AliSTARTDigitizer" |
57 | // <<"(AliRunDigitizer* manager) was processed"<<endl; |
58 | |
59 | } |
60 | |
61 | //------------------------------------------------------------------------ |
62 | AliSTARTDigitizer::~AliSTARTDigitizer() |
63 | { |
64 | // Destructor |
65 | |
66 | |
67 | } |
68 | |
69 | //------------------------------------------------------------------------ |
70 | Bool_t AliSTARTDigitizer::Init() |
71 | { |
72 | // Initialization |
73 | cout<<"AliSTARTDigitizer::Init"<<endl; |
74 | return kTRUE; |
75 | } |
76 | |
77 | |
78 | //--------------------------------------------------------------------- |
79 | |
80 | void AliSTARTDigitizer::Exec(Option_t* option) |
81 | { |
82 | |
83 | |
84 | |
85 | #ifdef DEBUG |
86 | cout<<"AliSTARTDigitizer::>SDigits2Digits start...\n"; |
87 | #endif |
88 | // |
89 | // From hits to digits |
90 | // |
91 | Int_t hit; |
92 | Int_t nhits; |
93 | Int_t volume,pmt; |
94 | char nameDigits[20]; |
95 | Float_t timediff,timeright,timeleft,timeav; |
96 | Float_t besttimeright,besttimeleft,meanTime; |
97 | Int_t channelWidth=10; |
98 | fHits = new TClonesArray ("AliSTARThit", 1000); |
99 | AliSTART *START = (AliSTART*) gAlice->GetDetector("START"); |
100 | |
101 | AliSTARThit *startHit; |
102 | TBranch *brHits=0; |
103 | fdigits= new AliSTARTdigit(); |
104 | |
105 | Int_t nFiles=fManager->GetNinputs(); |
106 | for (Int_t inputFile=0; inputFile<nFiles; inputFile++) { |
107 | sprintf(nameDigits,"START_D_%d",fManager->GetOutputEventNr()); |
108 | |
109 | besttimeright=9999.; |
110 | besttimeleft=9999.; |
111 | Int_t timeDiff=0; |
112 | Int_t timeAv=0; |
113 | TClonesArray *STARThits = START->Hits (); |
114 | |
115 | TTree *th = fManager->GetInputTreeH(inputFile); |
116 | brHits = th->GetBranch("START"); |
117 | if (brHits) { |
118 | START->SetHitsAddressBranch(brHits); |
119 | }else{ |
120 | cerr<<"EXEC Branch START hit not found"<<exit; |
121 | } |
122 | Int_t ntracks = (Int_t) th->GetEntries(); |
123 | if (ntracks<=0) return; |
124 | // Start loop on tracks in the hits containers |
125 | for (Int_t track=0; track<ntracks;track++) { |
126 | brHits->GetEntry(track); |
127 | nhits = STARThits->GetEntriesFast(); |
128 | for (hit=0;hit<nhits;hit++) { |
129 | startHit = (AliSTARThit*) STARThits->UncheckedAt(hit); |
130 | pmt=startHit->fPmt; |
131 | volume = startHit->fVolume; |
132 | if(volume==1){ |
133 | timeright = startHit->fTime; |
134 | if(timeright<besttimeright) { |
135 | besttimeright=timeright; |
136 | } //timeright |
137 | }//time for right shoulder |
138 | if(volume==2){ |
139 | timeleft = startHit->fTime; |
140 | // printf("timeleft %f\n",timeleft); |
141 | if(timeleft<besttimeleft) { |
142 | besttimeleft=timeleft; |
143 | } //timeleftbest |
144 | }//time for left shoulder |
145 | } //hit loop |
146 | } //track loop |
147 | |
148 | //folding with experimental time distribution |
149 | Float_t besttimerightGaus=gRandom->Gaus(besttimeright,0.05); |
150 | Float_t besttimeleftGaus=gRandom->Gaus(besttimeleft,0.05); |
151 | timediff=besttimerightGaus-besttimeleftGaus; |
152 | meanTime=(besttimerightGaus+besttimeleftGaus)/2.; |
153 | if ( TMath::Abs(timediff)<TMath::Abs(10.) && meanTime<TMath::Abs(7.1)) |
154 | { |
155 | //we assume centre of bunch is 5ns after TTS signal |
156 | //TOF values are relative of the end of bunch |
157 | Float_t ppBunch=25; |
158 | |
159 | ppBunch=ppBunch-10/2; |
160 | Float_t t1=1000.*besttimeleftGaus; |
161 | Float_t t2=1000.*besttimerightGaus; |
162 | t1=t1/channelWidth+ppBunch; //time in ps to channelWidth |
163 | t2=t2/channelWidth+ppBunch; //time in ps to channelWidth |
164 | |
165 | timeav=(t1+t2)/2.; |
166 | |
167 | // Time to TDC signal |
168 | // 256 channels for timediff, range 1ns |
169 | |
170 | timediff=128+1000*timediff/channelWidth; // time in ps |
171 | |
172 | timeAv = (Int_t)(timeav); // time (ps) channel numbres |
173 | timeDiff = (Int_t)(timediff); // time ( ps) channel numbres |
174 | fdigits->Set(timeAv,timeDiff); |
175 | fdigits->Print(); |
176 | } |
177 | else |
178 | {timeAv=999999; timeDiff=99999;} |
179 | |
180 | // trick to find out output dir: |
181 | TTree *outTree = fManager->GetTreeD(); |
182 | if (!outTree) { |
183 | cerr<<"something wrong with output...."<<exit; |
184 | return; |
185 | } |
186 | TDirectory *wd = gDirectory; |
187 | outTree->GetDirectory()->cd(); |
188 | fdigits->Write(nameDigits); |
189 | wd->cd(); |
190 | } |
191 | |
192 | } |
193 | |
194 | |