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