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