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