]> git.uio.no Git - u/mrichter/AliRoot.git/blob - START/AliSTARTDigitizer.cxx
Some additional changes related to the previous changes. AliL3Transform
[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 <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"<<endl;
121       exit(111);
122     } 
123     Int_t ntracks    = (Int_t) th->GetEntries();
124     if (ntracks<=0) return;
125     // Start loop on tracks in the hits containers
126     for (Int_t track=0; track<ntracks;track++) {
127       brHits->GetEntry(track);
128       nhits = STARThits->GetEntriesFast();
129       for (hit=0;hit<nhits;hit++) {
130         startHit   = (AliSTARThit*) STARThits->UncheckedAt(hit);
131         pmt=startHit->fPmt;
132         volume = startHit->fVolume;
133         if(volume==1){
134           timeright = startHit->fTime;
135           if(timeright<besttimeright) {
136             besttimeright=timeright;
137           } //timeright
138         }//time for right shoulder
139         if(volume==2){            
140           timeleft = startHit->fTime;
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 koef=69.7/350.;
151     besttimeleft=koef*besttimeleft;
152     Float_t besttimeleftGaus=gRandom->Gaus(besttimeleft,0.05);
153     timediff=besttimerightGaus-besttimeleftGaus;
154     meanTime=(besttimerightGaus+besttimeleftGaus)/2.;
155     if ( TMath::Abs(timediff)<TMath::Abs(3.) && meanTime<TMath::Abs(5.)) 
156      {
157        //we assume centre of bunch is 5ns after TTS signal
158        //TOF values are relative of the end of bunch
159        Float_t ppBunch=25;
160     
161        ppBunch=ppBunch-10/2;
162        Float_t t1=1000.*besttimeleftGaus;
163        Float_t t2=1000.*besttimerightGaus;
164        t1=t1/channelWidth+ppBunch; //time in ps to channelWidth
165        t2=t2/channelWidth+ppBunch; //time in ps to channelWidth
166        timeav=(t1+t2)/2.;
167      
168        // Time to TDC signal
169        // 256 channels for timediff, range 1ns
170        
171        timediff=128+1000*timediff/channelWidth; // time in ps 
172
173        timeAv = (Int_t)(timeav);   // time (ps) channel numbres
174        timeDiff = (Int_t)(timediff); // time ( ps) channel numbres
175        fdigits->Set(timeAv,timeDiff);
176        fdigits->Print();
177      }
178     else
179       {timeAv=999999; timeDiff=99999;}
180
181 // trick to find out output dir:
182     TTree *outTree = fManager->GetTreeD();
183     if (!outTree) {
184       cerr<<"something wrong with output...."<<endl;
185       exit(111);
186     }
187     TDirectory *wd = gDirectory;
188     outTree->GetDirectory()->cd();
189     fdigits->Write(nameDigits);
190     wd->cd();
191   }
192
193 }
194
195