2 /**************************************************************************
3 * Copyright(c) 1998-2000, ALICE Experiment at CERN, All rights reserved. *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
20 #include <TObjArray.h>
22 #include <TDirectory.h>
28 #include "AliSTARTDigitizer.h"
30 #include "AliSTARThit.h"
31 #include "AliSTARThitPhoton.h"
32 #include "AliSTARTdigit.h"
33 #include "AliRunDigitizer.h"
34 #include "AliHeader.h"
35 #include "AliGenEventHeader.h"
38 #include "AliLoader.h"
39 #include "AliRunLoader.h"
40 #include "AliSTARTLoader.h"
43 #include <Riostream.h>
44 #include <Riostream.h>
46 ClassImp(AliSTARTDigitizer)
48 //___________________________________________
49 AliSTARTDigitizer::AliSTARTDigitizer() :AliDigitizer()
51 // Default ctor - don't use it
55 //___________________________________________
56 AliSTARTDigitizer::AliSTARTDigitizer(AliRunDigitizer* manager)
57 :AliDigitizer(manager)
59 cout<<"AliSTARTDigitizer::AliSTARTDigitizer"<<endl;
60 // ctor which should be used
63 // cerr<<"AliSTARTDigitizer::AliSTARTDigitizer"
64 // <<"(AliRunDigitizer* manager) was processed"<<endl;
68 //------------------------------------------------------------------------
69 AliSTARTDigitizer::~AliSTARTDigitizer()
76 //------------------------------------------------------------------------
77 Bool_t AliSTARTDigitizer::Init()
80 cout<<"AliSTARTDigitizer::Init"<<endl;
85 //---------------------------------------------------------------------
87 void AliSTARTDigitizer::Exec(Option_t* /*option*/)
91 AliRunLoader *inRL, *outRL;//in and out Run Loaders
92 AliLoader *ingime, *outgime;// in and out ITSLoaders
94 outRL = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
95 outgime = outRL->GetLoader("STARTLoader");
98 cout<<"AliSTARTDigitizer::>SDigits2Digits start...\n";
101 // From hits to digits
104 Int_t CountEr[13],CountEl[13]; //!!!
105 Int_t volume,pmt,tr,tl,sumRight;
106 Float_t timediff,timeav;
107 Float_t besttimeright,besttimeleft,meanTime;
108 Int_t bestRightADC,bestLeftADC;
109 Float_t besttimeleftGaus, besttimerightGaus;
110 Float_t timeright[13]={13*0};
111 Float_t timeleft[13]={13*0};
112 Float_t channelWidth=2.5; //ps
113 Int_t channelWidthADC=1; //ps
114 // Int_t thresholdAmpl=10;
116 ftimeRightTDC = new TArrayI(12);
117 ftimeLeftTDC = new TArrayI(12);
118 fRightADC = new TArrayI(12);
119 fLeftADC = new TArrayI(12);
121 inRL = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
124 // fHits = new TClonesArray ("AliSTARThit", 1000);
125 fPhotons = new TClonesArray ("AliSTARThitPhoton", 10000); //!!!
126 AliSTART *START = (AliSTART*) gAlice->GetDetector("START");
127 AliSTARThit *startHit;
128 //use if Cherenkov photons
129 // AliSTARThitPhoton *startHitPhoton; //!!!
131 TBranch *brHitPhoton=0;
132 fdigits= new AliSTARTdigit();
134 Int_t nFiles=fManager->GetNinputs();
135 for (Int_t inputFile=0; inputFile<nFiles; inputFile++) {
142 for (Int_t i0=0; i0<13; i0++)
144 timeright[i0]=0; timeleft[i0]=0;
145 CountEr[i0]=0; CountEl[i0]=0;
148 inRL = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
149 ingime = inRL->GetLoader("STARTLoader");
150 ingime->LoadHits("READ");//probably it is necessary to load them before
151 ingime->LoadDigits("UPDATE");//probably it is necessary to load them before
152 //use if Cherenkov photons
153 // TClonesArray *STARThitsPhotons = START->Photons ();
154 TClonesArray *fHits = START->Hits ();
155 // cout<<" Load "<<AliSTARTLoader::LoadDigits()<<endl;
157 TTree *th = ingime->TreeH();
158 brHits = th->GetBranch("START");
159 brHitPhoton = th->GetBranch("STARThitPhoton");
161 START->SetHitsAddressBranch(brHits,brHitPhoton);
163 cerr<<"EXEC Branch START hit not found"<<endl;
166 Int_t ntracks = (Int_t) th->GetEntries();
167 cout<<" ntracks "<<ntracks<<endl;
168 if (ntracks<=0) return;
169 // Start loop on tracks in the photon hits containers
173 cout<<"brHitPhoton "<<endl;
174 for (Int_t track=0; track<ntracks;track++) {
175 brHitPhoton -> GetEntry(track);;
176 nhits = STARThitsPhotons->GetEntriesFast();
177 for (hit=0;hit<nhits;hit++) {
178 startHitPhoton = (AliSTARThitPhoton*)
179 STARThitsPhotons ->UncheckedAt(hit);
180 pmt=startHitPhoton->fPmt;
181 volume = startHitPhoton->fArray;
182 if(RegisterPhotoE(startHitPhoton))
184 if (volume == 1) CountEr[pmt]++;
185 if (volume == 2) CountEl[pmt]++;
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 // cout<<" brHits hits "<<nhits<<endl;
196 for (hit=0;hit<nhits;hit++) {
197 startHit = (AliSTARThit*) fHits->UncheckedAt(hit);
199 volume = startHit->Volume();
201 timeright[pmt] = startHit->Time();
202 if(timeright[pmt]<besttimeright)
203 //&&CountEr[pmt-1]>thresholdAmpl)
205 besttimeright=timeright[pmt];
207 }//time for right shoulder
209 timeleft[pmt] = startHit->Time();
210 if(timeleft[pmt]<besttimeleft)
211 //&&CountEl[pmt-1]>thresholdAmpl)
213 besttimeleft=timeleft[pmt];
216 }//time for left shoulder
221 cout<<" right time "<<besttimeright<<
222 " right distance "<<besttimeright*30<<endl;;
223 cout<<" left time "<<besttimeleft<<
224 " left distance "<<besttimeleft*30<<endl;;
227 //folding with experimental time distribution
229 besttimeleftGaus=gRandom->Gaus(besttimeright,0.05);
230 cout<<" besttimeleftGaus "<<besttimeleftGaus<<endl;
231 bestLeftADC=Int_t (besttimeleftGaus*1000/channelWidth);
232 Float_t koef=69.7/350.;
233 besttimeright=koef*besttimeleft;
234 besttimerightGaus=gRandom->Gaus(besttimeleft,0.05);
236 bestRightADC=Int_t (besttimerightGaus*1000/channelWidth);
237 timediff=besttimerightGaus-besttimeleftGaus;
238 cout<<" timediff in ns "<<timediff<<" z= "<<timediff*30<<endl;
239 meanTime=(besttimerightGaus+besttimeleftGaus)/2.;
240 if ( TMath::Abs(timediff)<TMath::Abs(0.3) )
242 Float_t t1=1000.*besttimeleftGaus;
243 Float_t t2=1000.*besttimerightGaus;
244 t1=t1/channelWidth; //time in ps to channelWidth
245 t2=t2/channelWidth; //time in ps to channelWidth
248 // Time to TDC signal
249 // 256 channels for timediff, range 1ns
251 timediff=512+1000*timediff/channelWidth; // time in ps
253 timeAv = (Int_t)(timeav); // time channel numbres
254 timeDiff = (Int_t)(timediff); // time channel numbres
256 fdigits->SetTimeBestLeft(bestLeftADC);
257 fdigits->SetTimeBestRight(bestRightADC);
258 fdigits->SetMeanTime(timeAv);
259 fdigits->SetTimeDiff(timeDiff);
260 for (Int_t i=0; i<12; i++)
263 timeright[i+1]=gRandom->Gaus(timeright[i+1],0.05);
264 timeleft[i+1]=gRandom->Gaus(timeleft[i+1],0.05);
265 tr= Int_t (timeright[i+1]*1000/channelWidth);
267 tl= Int_t (timeleft[i+1]*1000/channelWidth);
270 ftimeRightTDC->AddAt(tr,i);
271 ftimeLeftTDC->AddAt(tl,i);
273 Int_t al=( Int_t ) CountEl[i+1]/ channelWidthADC;
274 Int_t ar=( Int_t ) CountEr[i+1]/ channelWidthADC;
275 fRightADC->AddAt(ar,i);
276 fLeftADC ->AddAt(al,i);
277 sumRight+=CountEr[i+1];
279 fdigits->SetTimeRight(*ftimeRightTDC);
280 fdigits->SetTimeLeft(*ftimeLeftTDC);
281 fdigits->SetADCRight(*fRightADC);
282 fdigits->SetADCLeft(*fLeftADC);
283 // cout<<" before sum"<<endl;
284 fdigits->SetSumADCRight(sumRight);
287 {timeAv=999999; timeDiff=99999;}
289 // trick to find out output dir:
293 // trick to find out output dir:
294 TTree *outTree = fManager->GetTreeD();
296 cerr<<"something wrong with output...."<<endl;
300 Char_t nameDigits[20];
301 TDirectory *wd = gDirectory;
302 outTree->GetDirectory()->cd();
303 fdigits->Write(nameDigits);
304 cout<<nameDigits<<endl;
308 Char_t nameDigits[20];
309 sprintf(nameDigits,"START_D_%d",fManager->GetOutputEventNr());
310 fdigits->Write(nameDigits);
312 // outgime->WriteDigits("OVERWRITE");
317 //------------------------------------------------------------------------
318 Bool_t AliSTARTDigitizer::RegisterPhotoE(/*AliSTARThitPhoton *hit*/)
329 //----------------------------------------------------------------------------