Bug fixes and code cleaning
[u/mrichter/AliRoot.git] / START / AliSTART.cxx
CommitLineData
4c039060 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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$Log$
528332ba 18Revision 1.10 2000/10/02 21:28:13 fca
19Removal of useless dependecies via forward declarations
20
94de3818 21Revision 1.9 2000/07/13 16:41:29 fca
22New START corrected for coding conventions
23
ef51244a 24Revision 1.8 2000/03/27 17:24:25 alla
25Modifing geometry
26
c345bb4f 27Revision 1.6 2000/01/21 15:45:23 fca
28New Version from Alla
29
971579f6 30Revision 1.5 2000/01/19 17:17:15 fca
31Introducing a list of lists of hits -- more hits allowed for detector now
32
1cedd08a 33Revision 1.4 1999/11/12 15:04:00 fca
34Modifications from A.Maevskaya
35
82fc3fb3 36Revision 1.3 1999/09/29 09:24:29 fca
37Introduction of the Copyright and cvs Log
38
4c039060 39*/
40
6ca40650 41///////////////////////////////////////////////////////////////////////////////
42// //
43// START (T-Zero) Detector //
44// This class contains the base procedures for the START //
45// detector //
46// //
47//Begin_Html
48/*
49<img src="gif/AliSTARTClass.gif">
50</pre>
51<br clear=left>
52<font size=+2 color=red>
53<p>The responsible person for this module is
54<a href="mailto:Alla.Maevskaia@cern.ch">Alla Maevskaia</a>.
55</font>
56<pre>
57*/
58//End_Html
59// //
60// //
61///////////////////////////////////////////////////////////////////////////////
62
6ca40650 63#include <iostream.h>
64#include <fstream.h>
971579f6 65
66#include "TMath.h"
67#include "TTUBE.h"
68#include "TNode.h"
c345bb4f 69#include "TRandom.h"
971579f6 70#include "TGeometry.h"
71#include "AliRun.h"
72#include "AliSTART.h"
73#include "AliSTARTdigit.h"
6ca40650 74#include "AliMC.h"
971579f6 75#include "AliSTARThit.h"
c345bb4f 76#include "AliSTARTvertex.h"
971579f6 77
6ca40650 78ClassImp(AliSTART)
ef51244a 79
80static AliSTARTdigit *digits;
81
6ca40650 82//_____________________________________________________________________________
99560b47 83AliSTART::AliSTART()
6ca40650 84{
85 //
86 // Default constructor for class AliSTART
87 //
88 fIshunt = 0;
971579f6 89 fHits = 0;
90 fDigits = 0;
6ca40650 91}
92
93//_____________________________________________________________________________
94AliSTART::AliSTART(const char *name, const char *title)
95 : AliDetector(name,title)
96{
97 //
98 // Standard constructor for START Detector
99 //
971579f6 100
c345bb4f 101
6ca40650 102 //
103 // Initialise Hit array
971579f6 104 fHits = new TClonesArray("AliSTARThit", 405);
c345bb4f 105 // gAlice->AddHitList(fHits);
106 // fDigits = new TClonesArray("AliSTARTdigit",500);
6ca40650 107
108 fIshunt = 0;
c345bb4f 109 fIdSens = 0;
6ca40650 110 SetMarkerColor(kRed);
111}
112
113//_____________________________________________________________________________
114void AliSTART::AddHit(Int_t track, Int_t *vol, Float_t *hits)
115{
116 //
117 // Add a START hit
118 //
119 TClonesArray &lhits = *fHits;
120 new(lhits[fNhits++]) AliSTARThit(fIshunt,track,vol,hits);
121}
971579f6 122
123//_____________________________________________________________________________
c345bb4f 124
971579f6 125void AliSTART::AddDigit(Int_t *tracks,Int_t *digits)
126{
c345bb4f 127
128 // Add a START digit to the list
129
130// printf (" AddDigit*******");
131 // TClonesArray &ldigits = *fDigits;
132 // new(ldigits[fNdigits++]) AliSTARTdigit(tracks,digits);
971579f6 133}
c345bb4f 134
6ca40650 135//_____________________________________________________________________________
136void AliSTART::BuildGeometry()
137{
138 //
139 // Build simple ROOT TNode geometry for event display
140 //
ef51244a 141 TNode *node, *top;
6ca40650 142 const int kColorSTART = 19;
143 //
ef51244a 144 top=gAlice->GetGeometry()->GetNode("alice");
6ca40650 145
146 // START define the different volumes
147 new TRotMatrix("rot999","rot999", 90,0,90,90,180,0);
148
149 new TTUBE("S_STR1","START volume 1","void",5.,10.7,5.3);
ef51244a 150 top->cd();
151 node = new TNode("STR1","STR1","S_STR1",0,0,75.,"");
152 node->SetLineColor(kColorSTART);
153 fNodes->Add(node);
6ca40650 154
155 new TTUBE("S_STR2","START volume 2","void",5.,10.7,5.3);
ef51244a 156 top->cd();
157 node = new TNode("STR2","STR2","S_STR2",0,0,-75,"rot999");
158 node->SetLineColor(kColorSTART);
159 fNodes->Add(node);
6ca40650 160}
161
162//_____________________________________________________________________________
163Int_t AliSTART::DistanceToPrimitive(Int_t px, Int_t py)
164{
165 //
166 // Calculate the distance from the mouse to the START on the screen
167 // Dummy routine
168 //
169 return 9999;
170}
171
6ca40650 172//-------------------------------------------------------------------------
173void AliSTART::Init()
174{
175 //
176 // Initialis the START after it has been built
177 Int_t i;
6ca40650 178 //
179 printf("\n");
180 for(i=0;i<35;i++) printf("*");
181 printf(" START_INIT ");
182 for(i=0;i<35;i++) printf("*");
183 printf("\n");
184 //
185 // Here the START initialisation code (if any!)
186 for(i=0;i<80;i++) printf("*");
187 printf("\n");
971579f6 188 //
189 //
c345bb4f 190 // fIdSensRad=gMC->VolId("PTOP");
191 // fIdSensPC =gMC->VolId("T0PC");
6ca40650 192
193}
194
195//---------------------------------------------------------------------------
196void AliSTART::MakeBranch(Option_t* option)
197{
ef51244a 198 //
199 // Specific START branches
200 //
c345bb4f 201 AliSTARTdigit *digits;
6ca40650 202 // Create Tree branches for the START.
c345bb4f 203 Int_t buffersize = 400;
6ca40650 204 char branchname[10];
205 sprintf(branchname,"%s",GetName());
206
207 AliDetector::MakeBranch(option);
208
ef51244a 209 TTree *td = gAlice->TreeD();
c345bb4f 210 digits = new AliSTARTdigit();
528332ba 211 td->Branch(branchname,"AliSTARTdigit",digits, buffersize);
c345bb4f 212 printf("Making Branch %s for digits\n",branchname);
213
214/*
215 gAlice->TreeR()->Branch(branchname,"Int_t",&fZposit, buffersize);
216 printf("Making Branch %s for vertex position %d\n",branchname);
217 */
6ca40650 218}
971579f6 219
220//_____________________________________________________________________________
c345bb4f 221
971579f6 222void AliSTART::Hit2digit(Int_t evnum)
223{
ef51244a 224 //
225 // From hits to digits
226 //
227 Float_t x,y,e;
971579f6 228 Int_t nbytes = 0;
ef51244a 229 Int_t hit;
971579f6 230 Int_t nhits;
231 Int_t volume,pmt;
c345bb4f 232 char nameTH[8],nameTD[8];
233 Float_t timediff,timeright,timeleft,timeav;
234 Float_t besttimeright,besttimeleft,meanTime;
ef51244a 235 Int_t channelWidth=10;
971579f6 236
237 TParticle *particle;
971579f6 238 AliSTARThit *startHit;
239
c345bb4f 240 Int_t buffersize=256;
241 Int_t split=1;
242
243 digits= new AliSTARTdigit();
244 TBranch *bDig=0;
971579f6 245
c345bb4f 246
247 // Event ------------------------- LOOP
248
249 sprintf(nameTD,"TreeD%d",evnum);
ef51244a 250 TTree *td = new TTree(nameTD,"START");
251 bDig = td->Branch("START","AliSTARTdigit",&digits,buffersize,split);
971579f6 252
253 besttimeright=9999.;
254 besttimeleft=9999.;
ef51244a 255 Int_t timeDiff=0;
256 Int_t timeAv=0;
971579f6 257
258 Int_t nparticles = gAlice->GetEvent(evnum);
259 if (nparticles <= 0) return;
260 printf("\n nparticles %d\n",nparticles);
261
ef51244a 262 TClonesArray *particles = gAlice->Particles();
c345bb4f 263
971579f6 264 sprintf(nameTH,"TreeH%d",evnum);
265 printf("%s\n",nameTH);
ef51244a 266 TTree *th = gAlice->TreeH();
267 Int_t ntracks = (Int_t) th->GetEntries();
971579f6 268 if (ntracks<=0) return;
269 // Start loop on tracks in the hits containers
270 for (Int_t track=0; track<ntracks;track++) {
271 gAlice->ResetHits();
ef51244a 272 nbytes += th->GetEvent(track);
273 particle=(TParticle*)particles->UncheckedAt(track);
c345bb4f 274 nhits =fHits->GetEntriesFast();
275
971579f6 276 for (hit=0;hit<nhits;hit++) {
277 startHit = (AliSTARThit*)fHits->UncheckedAt(hit);
278 pmt=startHit->fPmt;
279 e=startHit->fEtot;
94de3818 280 x=startHit->X();
281 y=startHit->Y();
971579f6 282 volume = startHit->fVolume;
283 if(volume==1){
284 timeright = startHit->fTime;
285 if(timeright<besttimeright) {
286 besttimeright=timeright;
971579f6 287 } //timeright
288 }//time for right shoulder
289 if(volume==2){
290 timeleft = startHit->fTime;
291 // printf("timeleft %f\n",timeleft);
292 if(timeleft<besttimeleft) {
293 besttimeleft=timeleft;
971579f6 294 } //timeleftbest
295 }//time for left shoulder
296 } //hit loop
297 } //track loop
971579f6 298
c345bb4f 299 //folding with experimental time distribution
ef51244a 300 Float_t besttimerightGaus=gRandom->Gaus(besttimeright,0.05);
301 Float_t besttimeleftGaus=gRandom->Gaus(besttimeleft,0.05);
302 timediff=besttimerightGaus-besttimeleftGaus;
303 meanTime=(besttimerightGaus+besttimeleftGaus)/2.;
304 if ( TMath::Abs(timediff)<2. && meanTime<3.)
c345bb4f 305 {
ef51244a 306 //we assume centre of bunch is 5ns after TTS signal
307 //TOF values are relative of the end of bunch
308 Float_t ppBunch=25;
971579f6 309
ef51244a 310 ppBunch=ppBunch-10/2;
c345bb4f 311 Float_t t1=1000.*besttimeleftGaus;
312 Float_t t2=1000.*besttimerightGaus;
ef51244a 313 t1=t1/channelWidth+ppBunch; //time in ps to channelWidth
314 t2=t2/channelWidth+ppBunch; //time in ps to channelWidth
c345bb4f 315
316 timeav=(t1+t2)/2.;
317
318 // Time to TDC signal
319 // 256 channels for timediff, range 1ns
320
ef51244a 321 timediff=128+1000*timediff/channelWidth; // time in ps
322
323 timeAv = (Int_t)(timeav); // time (ps) channel numbres
324 timeDiff = (Int_t)(timediff); // time ( ps) channel numbres
325 digits->Set(timeAv,timeDiff);
326 }
327 else
328 {timeAv=999999; timeDiff=99999;}
329 td->Fill();
c345bb4f 330 digits->MyDump();
ef51244a 331 printf("digits-> %d \n",digits->GetTime());
332 td->Write();
333 // } //timediff
c345bb4f 334
335
336} // end macro
337
338
339
340
341
342
343
344
345
6ca40650 346
971579f6 347
ef51244a 348
971579f6 349
c345bb4f 350