Digits corresponded to new data format
[u/mrichter/AliRoot.git] / START / AliSTART.cxx
CommitLineData
4c039060 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
88cb7938 16/* $Id$ */
4c039060 17
6ca40650 18///////////////////////////////////////////////////////////////////////////////
19// //
20// START (T-Zero) Detector //
21// This class contains the base procedures for the START //
22// detector //
23// //
24//Begin_Html
25/*
26<img src="gif/AliSTARTClass.gif">
27</pre>
28<br clear=left>
29<font size=+2 color=red>
30<p>The responsible person for this module is
31<a href="mailto:Alla.Maevskaia@cern.ch">Alla Maevskaia</a>.
32</font>
33<pre>
34*/
35//End_Html
36// //
37// //
38///////////////////////////////////////////////////////////////////////////////
39
ef0750c2 40#include <Riostream.h>
971579f6 41
88cb7938 42#include <TFile.h>
43#include <TGeometry.h>
44#include <TMath.h>
45#include <TNode.h>
46#include <TParticle.h>
47#include <TRandom.h>
48#include <TTUBE.h>
49#include <TVirtualMC.h>
affef71b 50#include <AliESD.h>
2ab0c725 51
e4da63c2 52#include "AliLog.h"
53#include "AliMC.h"
88cb7938 54#include "AliLoader.h"
971579f6 55#include "AliRun.h"
db173afc 56#include "TClonesArray.h"
971579f6 57#include "AliSTART.h"
6fc133d2 58#include "AliSTARTLoader.h"
971579f6 59#include "AliSTARTdigit.h"
971579f6 60#include "AliSTARThit.h"
85a5290f 61#include "AliSTARTDigitizer.h"
e4da63c2 62#include "AliSTARTRawData.h"
db173afc 63#include "AliSTARTRecPoint.h"
4951e003 64#include "AliLog.h"
971579f6 65
6ca40650 66ClassImp(AliSTART)
ef51244a 67
e4da63c2 68 //static AliSTARTdigit *digits;
ef51244a 69
6ca40650 70//_____________________________________________________________________________
99560b47 71AliSTART::AliSTART()
6ca40650 72{
73 //
74 // Default constructor for class AliSTART
75 //
f3ed336b 76 fIshunt = 1;
971579f6 77 fHits = 0;
78 fDigits = 0;
db173afc 79 fRecPoints = 0;
6ca40650 80}
81
82//_____________________________________________________________________________
83AliSTART::AliSTART(const char *name, const char *title)
84 : AliDetector(name,title)
85{
86 //
87 // Standard constructor for START Detector
88 //
971579f6 89
c345bb4f 90
6ca40650 91 //
92 // Initialise Hit array
971579f6 93 fHits = new TClonesArray("AliSTARThit", 405);
f1538e33 94 gAlice->GetMCApp()->AddHitList(fHits);
db173afc 95 fDigits = new AliSTARTdigit();
96 fRecPoints = new AliSTARTRecPoint();
f3ed336b 97 fIshunt = 1;
c345bb4f 98 fIdSens = 0;
6ca40650 99 SetMarkerColor(kRed);
100}
bff160c8 101
102//_____________________________________________________________________________
103AliSTART::~AliSTART() {
db173afc 104
bff160c8 105 if (fHits) {
106 fHits->Delete();
107 delete fHits;
db173afc 108 }
109 /*
110 if (fDigits) {
111 fDigits->Delete();
112 delete fDigits;
113 cout<<" delete fDigits; "<<endl;
bff160c8 114 }
db173afc 115 if (fRecPoints) {
116 fRecPoints ->Delete();
117 delete fRecPoints;
118 cout<<" delete fRecPoints; "<<endl;
119 }
120 */
bff160c8 121}
6ca40650 122
123//_____________________________________________________________________________
124void AliSTART::AddHit(Int_t track, Int_t *vol, Float_t *hits)
125{
126 //
127 // Add a START hit
128 //
129 TClonesArray &lhits = *fHits;
130 new(lhits[fNhits++]) AliSTARThit(fIshunt,track,vol,hits);
131}
971579f6 132
e73d68f2 133
971579f6 134//_____________________________________________________________________________
c345bb4f 135
db173afc 136void AliSTART::AddDigit(Int_t besttimeright, Int_t besttimeleft, Int_t meantime,
e3f84715 137 Int_t timediff, Int_t sumMult,
db173afc 138 TArrayI *time, TArrayI *adc, TArrayI *timeAmp, TArrayI *adcAmp)
971579f6 139{
c345bb4f 140
db173afc 141 // Add a START digit to the list.
142 //
c345bb4f 143
db173afc 144 if (!fDigits) {
145 fDigits = new AliSTARTdigit();
146 }
147 fDigits-> SetTimeBestRight(besttimeright);
148 fDigits->SetTimeBestLeft(besttimeleft);
149 fDigits-> SetMeanTime(meantime);
150 fDigits-> SetDiffTime(timediff);
e3f84715 151 fDigits-> SetSumMult(sumMult);
db173afc 152 fDigits->SetTime(*time);
153 fDigits->SetTimeAmp(*timeAmp);
154 fDigits->SetADC(*adc);
155 fDigits->SetADCAmp(*adcAmp);
971579f6 156}
c345bb4f 157
db173afc 158
6ca40650 159//_____________________________________________________________________________
160void AliSTART::BuildGeometry()
161{
162 //
163 // Build simple ROOT TNode geometry for event display
164 //
ef51244a 165 TNode *node, *top;
6ca40650 166 const int kColorSTART = 19;
f3ed336b 167
ef51244a 168 top=gAlice->GetGeometry()->GetNode("alice");
6ca40650 169
170 // START define the different volumes
44b06417 171 new TRotMatrix("rotx999","rot999", 90,0,90,90,180,0);
6ca40650 172
2ca99a7f 173 new TTUBE("S_0ST1","START volume 1","void",5.,10.7,5.3);
ef51244a 174 top->cd();
1663993c 175 node = new TNode("0ST1","0ST01","S_0ST1",0,0,-69.7,"");
ef51244a 176 node->SetLineColor(kColorSTART);
177 fNodes->Add(node);
6ca40650 178
2ca99a7f 179 new TTUBE("S_0ST2","START volume 2","void",5.,10.7,5.3);
ef51244a 180 top->cd();
1663993c 181 node = new TNode("0ST2","0ST2","S_0ST2",0,0,350,"rotx999");
ef51244a 182 node->SetLineColor(kColorSTART);
183 fNodes->Add(node);
6ca40650 184}
185
186//_____________________________________________________________________________
7fe81cad 187Int_t AliSTART::DistanceToPrimitive(Int_t /*px*/, Int_t /*py*/)
6ca40650 188{
189 //
190 // Calculate the distance from the mouse to the START on the screen
191 // Dummy routine
192 //
193 return 9999;
194}
195
6ca40650 196//-------------------------------------------------------------------------
197void AliSTART::Init()
198{
199 //
200 // Initialis the START after it has been built
201 Int_t i;
6ca40650 202 //
4951e003 203 if(AliLog::GetGlobalDebugLevel()>0) {
9e1a0ddb 204 printf("\n%s: ",ClassName());
205 for(i=0;i<35;i++) printf("*");
206 printf(" START_INIT ");
207 for(i=0;i<35;i++) printf("*");
208 printf("\n%s: ",ClassName());
209 //
210 // Here the START initialisation code (if any!)
211 for(i=0;i<80;i++) printf("*");
212 printf("\n");
213 }
6ca40650 214}
215
216//---------------------------------------------------------------------------
88cb7938 217void AliSTART::MakeBranch(Option_t* option)
6ca40650 218{
ef51244a 219 //
db173afc 220// Create Tree branches for the START.
221
222 // Options:
223 //
224 // H Make a branch of TClonesArray of AliSTARTHit's
225 // D Make a branch of TClonesArray of AliSTARTDigit's
226 //
227 // R Make a branch of AliSTARTRecPoints
ef51244a 228 //
e73d68f2 229 char branchname[20];
6ca40650 230 sprintf(branchname,"%s",GetName());
231
e73d68f2 232 const char *cH = strstr(option,"H");
db173afc 233 const char *cD = strstr(option,"D");
234 const char *cR = strstr(option,"R");
235
236 if (cH && fLoader->TreeH())
e73d68f2 237 {
88cb7938 238 if (fHits == 0x0) fHits = new TClonesArray("AliSTARThit", 405);
db173afc 239 AliDetector::MakeBranch(option);
e73d68f2 240 }
db173afc 241
242
243 if (cD && fLoader->TreeD())
244 {
245 if (fDigits == 0x0) fDigits = new AliSTARTdigit();
246 // MakeBranchInTree(fLoader->TreeD(), branchname,
247 // &fDigits, 405, 0);
248 fLoader->TreeD()->Branch(branchname,"AliSTARTdigit",&fDigits,405,1);
e3f84715 249 // fLoader->TreeD()->Print();
db173afc 250 }
251 if (cR && fLoader->TreeR())
252 {
253 if (fRecPoints == 0x0) fRecPoints = new AliSTARTRecPoint();
254 MakeBranchInTree(fLoader->TreeR(), branchname,
255 &fRecPoints, 405, 0);
256 }
2ab0c725 257
6ca40650 258}
971579f6 259
e73d68f2 260//_____________________________________________________________________________
261void AliSTART::ResetHits()
262{
263 AliDetector::ResetHits();
264
e73d68f2 265}
db173afc 266//____________________________________________________________________
267void AliSTART::ResetDigits()
268{
269 //
270 // Reset number of digits and the digits array for this detector
271 //
272 if (fDigits) fDigits->Clear();
273}
e73d68f2 274
275//_____________________________________________________________________________
276void AliSTART::SetTreeAddress()
277{
e4da63c2 278
88cb7938 279 TTree *treeH;
88cb7938 280 treeH = TreeH();
e73d68f2 281
282 if (treeH)
e73d68f2 283 {
88cb7938 284 if (fHits == 0x0) fHits = new TClonesArray("AliSTARThit", 405);
e73d68f2 285 }
88cb7938 286
287 AliDetector::SetTreeAddress();
db173afc 288 TTree *treeD = fLoader->TreeD();
289 if (treeD) {
290 if (fDigits == 0x0) fDigits = new AliSTARTdigit();
291 TBranch* branch = treeD->GetBranch ("START");
292 if (branch) branch->SetAddress(&fDigits);
293 }
294
295 TTree *treeR = fLoader->TreeR();
296 if (treeR) {
297 if (fRecPoints == 0x0) fRecPoints = new AliSTARTRecPoint() ;
298 TBranch* branch = treeR->GetBranch ("START");
299 if (branch) branch->SetAddress(&fRecPoints);
300 }
301
e73d68f2 302}
303
e4da63c2 304
db173afc 305//_____________________________________________________________________________
306void AliSTART::MakeBranchInTreeD(TTree *treeD, const char *file)
307{
308 //
309 // Create TreeD branches for the FMD
310 //
311 const Int_t kBufferSize = 4000;
312 char branchname[20];
313 sprintf(branchname,"%s",GetName());
314 if(treeD)
315 {
316 MakeBranchInTree(treeD, branchname,&fDigits, kBufferSize, file);
317 }
6fc133d2 318}
319
85a5290f 320//_____________________________________________________________________________
c92eb8ad 321AliDigitizer* AliSTART::CreateDigitizer(AliRunDigitizer* manager) const
85a5290f 322{
323 return new AliSTARTDigitizer(manager);
324}
e4da63c2 325//____________________________________________________________________________
326void AliSTART::Digits2Raw()
327{
328//
329// Starting from the START digits, writes the Raw Data objects
330//
db173afc 331// AliSTARTLoader* pStartLoader = (AliSTARTLoader*)fLoader;
332 fLoader ->LoadDigits("read");
333 TTree* treeD = fLoader->TreeD();
334 if (!treeD) {
335 AliError("no digits tree");
336 return;
337 }
338 if (fDigits == 0x0) fDigits = new AliSTARTdigit();
339
340 TBranch *branch = treeD->GetBranch("START");
341 if (branch) {
342 branch->SetAddress(&fDigits);
343 }else{
344 AliError("Branch START DIGIT not found");
345 exit(111);
346 }
e4da63c2 347 AliSTARTRawData rawWriter;
348 rawWriter.SetVerbose(0);
db173afc 349
e4da63c2 350 AliDebug(2,Form(" Formatting raw data for START "));
db173afc 351 branch->GetEntry(0);
352 // rawWriter.RawDataSTART(treeD->GetBranch("START"));
353 rawWriter.RawDataSTART(fDigits);
354
355
356 fLoader->UnloadDigits();
e4da63c2 357
e4da63c2 358}