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