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