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