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