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