Leave the loop when primaries are filled (I.Hrivnacova)
[u/mrichter/AliRoot.git] / ITS / AliITS.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
16/*
17$Log$
2ab0c725 18Revision 1.28 2000/12/18 14:02:00 barbera
19new version of the ITS tracking to take into account the new TPC track parametrization
20
cc6e75dd 21Revision 1.27 2000/12/08 13:49:27 barbera
22Hidden declaration in a for loop removed to be compliant with HP-UX compiler
23
c5b22044 24Revision 1.26 2000/11/27 13:12:13 barbera
25New version containing the files for tracking
26
55b5a0b3 27Revision 1.25 2000/11/12 22:38:05 barbera
28Added header file for the SPD Bari model
29
dfe2a93f 30Revision 1.24 2000/10/09 22:18:12 barbera
31Bug fixes from MAriana to le AliITStest.C run correctly
32
65d4384f 33Revision 1.23 2000/10/05 20:47:42 nilsen
34fixed dependencies of include files. Tryed but failed to get a root automaticly
35generates streamer function to work. Modified SetDefaults.
36
143d1056 37Revision 1.9.2.15 2000/10/04 16:56:40 nilsen
38Needed to include stdlib.h
39
40=======
41Revision 1.22 2000/10/04 19:45:52 barbera
42Corrected by F. Carminati for v3.04
43
114da3a4 44Revision 1.21 2000/10/02 21:28:08 fca
45Removal of useless dependecies via forward declarations
46
94de3818 47Revision 1.20 2000/10/02 16:31:39 barbera
48General code clean-up
49
d5da1ecf 50Revision 1.9.2.14 2000/10/02 15:43:51 barbera
51General code clean-up (e.g., printf -> cout)
52
53Revision 1.19 2000/09/22 12:13:25 nilsen
54Patches and updates for fixes to this and other routines.
55
9c74c52b 56Revision 1.18 2000/07/12 05:32:20 fca
57Correcting several syntax problem with static members
58
b669392e 59Revision 1.17 2000/07/10 16:07:18 fca
60Release version of ITS code
61
3bd79107 62Revision 1.9.2.3 2000/02/02 13:42:09 barbera
63fixed AliITS.cxx for new AliRun structure. Added ITS hits list to list of hits which will have their track numbers updated
64
65Revision 1.9.2.2 2000/01/23 03:03:13 nilsen
66//fixed FillModule. Removed fi(fabs(xl)<dx....
67
68Revision 1.9.2.1 2000/01/12 19:03:32 nilsen
69This is the version of the files after the merging done in December 1999.
70See the ReadMe110100.txt file for details
c9a71be1 71
1cedd08a 72Revision 1.9 1999/11/14 14:33:25 fca
73Correct problems with distructors and pointers, thanks to I.Hrivnacova
74
6c854497 75Revision 1.8 1999/09/29 09:24:19 fca
76Introduction of the Copyright and cvs Log
77
4c039060 78*/
79
fe4da5cc 80///////////////////////////////////////////////////////////////////////////////
58005f18 81//
82// An overview of the basic philosophy of the ITS code development
83// and analysis is show in the figure below.
fe4da5cc 84//Begin_Html
85/*
a92b2b7d 86<img src="picts/ITS/ITS_Analysis_schema.gif">
fe4da5cc 87</pre>
88<br clear=left>
89<font size=+2 color=red>
58005f18 90<p>Roberto Barbera is in charge of the ITS Offline code (1999).
fe4da5cc 91<a href="mailto:roberto.barbera@ct.infn.it">Roberto Barbera</a>.
92</font>
93<pre>
94*/
95//End_Html
58005f18 96//
97// AliITS. Inner Traking System base class.
98// This class contains the base procedures for the Inner Tracking System
99//
100//Begin_Html
101/*
a92b2b7d 102<img src="picts/ITS/AliITS_Class_Diagram.gif">
58005f18 103</pre>
104<br clear=left>
105<font size=+2 color=red>
106<p>This show the class diagram of the different elements that are part of
107the AliITS class.
108</font>
109<pre>
110*/
111//End_Html
112//
113// Version: 0
114// Written by Rene Brun, Federico Carminati, and Roberto Barbera
115//
116// Version: 1
117// Modified and documented by Bjorn S. Nilsen
118// July 11 1999
119//
3bd79107 120// Version: 2
121// Modified and documented by A. Bologna
122// October 18 1999
123//
58005f18 124// AliITS is the general base class for the ITS. Also see AliDetector for
125// futher information.
126//
fe4da5cc 127///////////////////////////////////////////////////////////////////////////////
143d1056 128#include <stdlib.h>
fe4da5cc 129#include <TMath.h>
130#include <TRandom.h>
9c74c52b 131#include <TBranch.h>
fe4da5cc 132#include <TVector.h>
3bd79107 133#include <TObjArray.h>
3bd79107 134#include <TROOT.h>
135#include <TObjectTable.h>
9c74c52b 136#include <TFile.h>
137#include <TTree.h>
d5da1ecf 138#include <TString.h>
3bd79107 139
140
bb8ac1e0 141
fe4da5cc 142#include "AliRun.h"
3bd79107 143#include "AliITS.h"
144#include "AliITSMap.h"
e8189707 145#include "AliITSDetType.h"
3bd79107 146#include "AliITSClusterFinder.h"
147#include "AliITSsimulation.h"
143d1056 148#include "AliITSresponse.h"
3bd79107 149#include "AliITSsegmentationSPD.h"
150#include "AliITSresponseSPD.h"
dfe2a93f 151#include "AliITSresponseSPDbari.h"
3bd79107 152#include "AliITSsegmentationSDD.h"
153#include "AliITSresponseSDD.h"
154#include "AliITSsegmentationSSD.h"
155#include "AliITSresponseSSD.h"
9c74c52b 156#include "AliITShit.h"
157#include "AliITSgeom.h"
158#include "AliITSdigit.h"
159#include "AliITSmodule.h"
160#include "AliITSRecPoint.h"
161#include "AliITSRawCluster.h"
94de3818 162#include "AliMC.h"
114da3a4 163#include "stdlib.h"
e8189707 164
55b5a0b3 165#include "AliITStrack.h"
166#include "AliITSiotrack.h"
167#include "AliITStracking.h"
168#include "../TPC/AliTPC.h"
169#include "../TPC/AliTPCParam.h"
170
b669392e 171const Int_t AliITS::fgkNTYPES=3;
c9a71be1 172
3bd79107 173ClassImp(AliITS)
174
fe4da5cc 175//_____________________________________________________________________________
3bd79107 176AliITS::AliITS() : AliDetector() {
fe4da5cc 177 //
178 // Default initialiser for ITS
58005f18 179 // The default constructor of the AliITS class. In addition to
180 // creating the AliITS class it zeros the variables fIshunt (a member
181 // of AliDetector class), fEuclidOut, and fIdN, and zeros the pointers
3bd79107 182 // fITSpoints, fIdSens, and fIdName. The AliDetector default constructor
183 // is also called.
fe4da5cc 184 //
3bd79107 185
9c74c52b 186
58005f18 187 fIshunt = 0;
188 fEuclidOut = 0;
e8189707 189
190 //fNDetTypes = fgkNTYPES;
58005f18 191 fIdN = 0;
192 fIdName = 0;
193 fIdSens = 0;
6c854497 194 fITSmodules = 0;
3bd79107 195 //
196 fDetTypes = 0;
3bd79107 197 //
198 fDtype = 0;
199 fNdtype = 0;
200 fCtype = 0;
201 fNctype = 0;
202 fRecPoints = 0;
203 fNRecPoints = 0;
e8189707 204 fTreeC = 0;
3bd79107 205 //
206 fITSgeom=0;
fe4da5cc 207}
3bd79107 208
fe4da5cc 209//_____________________________________________________________________________
58005f18 210AliITS::AliITS(const char *name, const char *title):AliDetector(name,title){
fe4da5cc 211 //
212 // Default initialiser for ITS
58005f18 213 // The constructor of the AliITS class. In addition to creating the
214 // AliITS class, it allocates memory for the TClonesArrays fHits and
215 // fDigits, and for the TObjArray fITSpoints. It also zeros the variables
216 // fIshunt (a member of AliDetector class), fEuclidOut, and fIdN, and zeros
217 // the pointers fIdSens and fIdName. To help in displaying hits via the ROOT
218 // macro display.C AliITS also sets the marker color to red. The variables
219 // passes with this constructor, const char *name and *title, are used by
220 // the constructor of AliDetector class. See AliDetector class for a
221 // description of these parameters and its constructor functions.
fe4da5cc 222 //
58005f18 223
9c74c52b 224
58005f18 225 fHits = new TClonesArray("AliITShit", 1560);
1cedd08a 226 gAlice->AddHitList(fHits);
3bd79107 227
e8189707 228 //fNDetTypes = fgkNTYPES;
229
230 fNdtype = new Int_t[fgkNTYPES];
231 fDtype = new TObjArray(fgkNTYPES);
232
233 fNctype = new Int_t[fgkNTYPES];
234 fCtype = new TObjArray(fgkNTYPES);
3bd79107 235
3bd79107 236
237 fRecPoints = 0;
238 fNRecPoints = 0;
239
e8189707 240 fTreeC = 0;
3bd79107 241
242 fITSmodules = 0;
58005f18 243
244 fIshunt = 0;
245 fEuclidOut = 0;
246 fIdN = 0;
247 fIdName = 0;
248 fIdSens = 0;
3bd79107 249
e8189707 250 fDetTypes = new TObjArray(fgkNTYPES);
3bd79107 251
252 Int_t i;
e8189707 253 for(i=0;i<fgkNTYPES;i++) {
3bd79107 254 (*fDetTypes)[i]=new AliITSDetType();
e8189707 255 fNdtype[i]=0;
256 fNctype[i]=0;
3bd79107 257 }
258 //
58005f18 259
fe4da5cc 260 SetMarkerColor(kRed);
58005f18 261
3bd79107 262 fITSgeom=0;
263}
264//___________________________________________________________________________
265AliITS::AliITS(AliITS &source){
e8189707 266 // copy constructor
3bd79107 267 if(this==&source) return;
d5da1ecf 268 Error("AliITS::Copy constructor",
269 "You are not allowed to make a copy of the AliITS");
3bd79107 270 exit(1);
fe4da5cc 271}
3bd79107 272//____________________________________________________________________________
273AliITS& AliITS::operator=(AliITS &source){
e8189707 274 // assignment operator
3bd79107 275 if(this==&source) return *this;
d5da1ecf 276 Error("AliITS::operator=",
277 "You are not allowed to make a copy of the AliITS");
3bd79107 278 exit(1);
e8189707 279 return *this; //fake return
3bd79107 280}
281//____________________________________________________________________________
282void AliITS::ClearModules(){
283 //clear the modules TObjArray
3bd79107 284
9c74c52b 285 if(fITSmodules) fITSmodules->Delete();
fe4da5cc 286
3bd79107 287}
fe4da5cc 288//_____________________________________________________________________________
58005f18 289AliITS::~AliITS(){
fe4da5cc 290 //
291 // Default distructor for ITS
58005f18 292 // The default destructor of the AliITS class. In addition to deleting
293 // the AliITS class it deletes the memory pointed to by the fHits, fDigits,
294 // fIdSens, fIdName, and fITSpoints.
fe4da5cc 295 //
3bd79107 296
297
fe4da5cc 298 delete fHits;
299 delete fDigits;
3bd79107 300 delete fRecPoints;
143d1056 301// delete fIdName; // TObjArray of TObjStrings
302 if(fIdName!=0) delete[] fIdName; // Array of TStrings
58005f18 303 if(fIdSens!=0) delete[] fIdSens;
3bd79107 304 if(fITSmodules!=0) {
305 this->ClearModules();
306 delete fITSmodules;
307 }// end if fITSmodules!=0
fe4da5cc 308
fe4da5cc 309 //
3bd79107 310 if(fDtype) {
9c74c52b 311 fDtype->Delete();
312 delete fDtype;
3bd79107 313 }
9c74c52b 314 delete [] fNdtype;
315 if (fCtype) {
316 fCtype->Delete();
317 delete fCtype;
3bd79107 318 }
9c74c52b 319 delete [] fNctype;
fe4da5cc 320 //
3bd79107 321
322 if (fDetTypes) {
323 fDetTypes->Delete();
324 delete fDetTypes;
325 }
326
327 if (fTreeC) delete fTreeC;
e8189707 328
9c74c52b 329 if (fITSgeom) delete fITSgeom;
330
3bd79107 331}
332
333//___________________________________________
334AliITSDetType* AliITS::DetType(Int_t id)
335{
336 //return pointer to id detector type
337 return ((AliITSDetType*) (*fDetTypes)[id]);
338
339}
340//___________________________________________
e8189707 341void AliITS::SetClasses(Int_t id, const char *digit, const char *cluster)
3bd79107 342{
343 //set the digit and cluster classes to be used for the id detector type
344 ((AliITSDetType*) (*fDetTypes)[id])->ClassNames(digit,cluster);
345
346}
347//___________________________________________
348void AliITS::SetResponseModel(Int_t id, AliITSresponse *response)
349{
350 //set the response model for the id detector type
351
352 ((AliITSDetType*) (*fDetTypes)[id])->ResponseModel(response);
353
fe4da5cc 354}
355
3bd79107 356//___________________________________________
357void AliITS::SetSegmentationModel(Int_t id, AliITSsegmentation *seg)
358{
359 //set the segmentation model for the id detector type
360
361 ((AliITSDetType*) (*fDetTypes)[id])->SegmentationModel(seg);
362
363}
364
365//___________________________________________
366void AliITS::SetSimulationModel(Int_t id, AliITSsimulation *sim)
367{
368 //set the simulation model for the id detector type
369
370 ((AliITSDetType*) (*fDetTypes)[id])->SimulationModel(sim);
371
372}
373//___________________________________________
374void AliITS::SetReconstructionModel(Int_t id, AliITSClusterFinder *reconst)
375{
376 //set the cluster finder model for the id detector type
377
378 ((AliITSDetType*) (*fDetTypes)[id])->ReconstructionModel(reconst);
58005f18 379
58005f18 380}
381
fe4da5cc 382//_____________________________________________________________________________
58005f18 383void AliITS::AddHit(Int_t track, Int_t *vol, Float_t *hits){
fe4da5cc 384 //
385 // Add an ITS hit
58005f18 386 // The function to add information to the AliITShit class. See the
387 // AliITShit class for a full description. This function allocates the
388 // necessary new space for the hit information and passes the variable
389 // track, and the pointers *vol and *hits to the AliITShit constructor
390 // function.
fe4da5cc 391 //
392 TClonesArray &lhits = *fHits;
393 new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
394}
3bd79107 395//_____________________________________________________________________________
396void AliITS::AddRealDigit(Int_t id, Int_t *digits)
397{
398 // add a real digit - as coming from data
399
400 TClonesArray &ldigits = *((TClonesArray*)(*fDtype)[id]);
401 new(ldigits[fNdtype[id]++]) AliITSdigit(digits);
402
403}
404//_____________________________________________________________________________
e8189707 405void AliITS::AddSimDigit(Int_t id, AliITSdigit *d)
3bd79107 406{
407
408 // add a simulated digit
409
3bd79107 410 TClonesArray &ldigits = *((TClonesArray*)(*fDtype)[id]);
411
412 switch(id)
413 {
414 case 0:
415 new(ldigits[fNdtype[id]++]) AliITSdigitSPD(*((AliITSdigitSPD*)d));
416 break;
417 case 1:
418 new(ldigits[fNdtype[id]++]) AliITSdigitSDD(*((AliITSdigitSDD*)d));
419 break;
420 case 2:
421 new(ldigits[fNdtype[id]++]) AliITSdigitSSD(*((AliITSdigitSSD*)d));
422 break;
423 }
424
425}
426
427//_____________________________________________________________________________
e8189707 428void AliITS::AddSimDigit(Int_t id,Float_t phys,Int_t *digits,Int_t *tracks,Int_t *hits,Float_t *charges){
3bd79107 429
430 // add a simulated digit to the list
431
432 TClonesArray &ldigits = *((TClonesArray*)(*fDtype)[id]);
433 switch(id)
434 {
435 case 0:
e8189707 436 new(ldigits[fNdtype[id]++]) AliITSdigitSPD(digits,tracks,hits);
3bd79107 437 break;
438 case 1:
e8189707 439 new(ldigits[fNdtype[id]++]) AliITSdigitSDD(phys,digits,tracks,hits,charges);
3bd79107 440 break;
441 case 2:
e8189707 442 new(ldigits[fNdtype[id]++]) AliITSdigitSSD(digits,tracks,hits);
3bd79107 443 break;
444 }
445
446}
447
448//_____________________________________________________________________________
449void AliITS::AddCluster(Int_t id, AliITSRawCluster *c)
450{
451
452 // add a cluster to the list
453
3bd79107 454 TClonesArray &lcl = *((TClonesArray*)(*fCtype)[id]);
455
456 switch(id)
457 {
458 case 0:
459 new(lcl[fNctype[id]++]) AliITSRawClusterSPD(*((AliITSRawClusterSPD*)c));
460 break;
461 case 1:
462 new(lcl[fNctype[id]++]) AliITSRawClusterSDD(*((AliITSRawClusterSDD*)c));
463 break;
464 case 2:
465 new(lcl[fNctype[id]++]) AliITSRawClusterSSD(*((AliITSRawClusterSSD*)c));
466 break;
467 }
468
469}
470
471
472//_____________________________________________________________________________
473void AliITS::AddRecPoint(const AliITSRecPoint &r)
474{
475 //
476 // Add a reconstructed space point to the list
477 //
478 TClonesArray &lrecp = *fRecPoints;
479 new(lrecp[fNRecPoints++]) AliITSRecPoint(r);
480}
481
482
483//____________________________________________
484void AliITS::ResetDigits()
485{
486 //
9c74c52b 487 // Reset number of digits and the digits array for the ITS detector
3bd79107 488 //
489
490 if (!fDtype) return;
491
492 Int_t i;
e8189707 493 for (i=0;i<fgkNTYPES;i++ ) {
3bd79107 494 if ((*fDtype)[i]) ((TClonesArray*)(*fDtype)[i])->Clear();
495 if (fNdtype) fNdtype[i]=0;
496 }
497}
498
499//____________________________________________
500void AliITS::ResetDigits(Int_t i)
501{
502 //
503 // Reset number of digits and the digits array for this branch
504 //
e8189707 505 if ((*fDtype)[i]) ((TClonesArray*)(*fDtype)[i])->Clear();
506 if (fNdtype) fNdtype[i]=0;
3bd79107 507}
e8189707 508
509
3bd79107 510//____________________________________________
511void AliITS::ResetClusters()
512{
513 //
514 // Reset number of clusters and the clusters array for ITS
515 //
516
517 Int_t i;
e8189707 518 for (i=0;i<fgkNTYPES;i++ ) {
3bd79107 519 if ((*fCtype)[i]) ((TClonesArray*)(*fCtype)[i])->Clear();
520 if (fNctype) fNctype[i]=0;
521 }
522
523}
e8189707 524
3bd79107 525//____________________________________________
526void AliITS::ResetClusters(Int_t i)
527{
528 //
529 // Reset number of clusters and the clusters array for this branch
530 //
531 if ((*fCtype)[i]) ((TClonesArray*)(*fCtype)[i])->Clear();
532 if (fNctype) fNctype[i]=0;
533
534}
535
536
537//____________________________________________
538void AliITS::ResetRecPoints()
539{
540 //
541 // Reset number of rec points and the rec points array
542 //
3bd79107 543 if (fRecPoints) fRecPoints->Clear();
9c74c52b 544 fNRecPoints = 0;
3bd79107 545
546}
547
fe4da5cc 548//_____________________________________________________________________________
58005f18 549Int_t AliITS::DistancetoPrimitive(Int_t , Int_t ){
fe4da5cc 550 //
551 // Distance from mouse to ITS on the screen. Dummy routine
58005f18 552 // A dummy routine used by the ROOT macro display.C to allow for the
553 // use of the mouse (pointing device) in the macro. In general this should
554 // never be called. If it is it returns the number 9999 for any value of
555 // x and y.
fe4da5cc 556 //
557 return 9999;
558}
559
560//_____________________________________________________________________________
58005f18 561void AliITS::Init(){
fe4da5cc 562 //
563 // Initialise ITS after it has been built
58005f18 564 // This routine initializes the AliITS class. It is intended to be called
565 // from the Init function in AliITSv?. Besides displaying a banner
3bd79107 566 // indicating that it has been called it initializes the array fIdSens
567 // and sets the default segmentation, response, digit and raw cluster classes
58005f18 568 // Therefore it should be called after a call to CreateGeometry.
fe4da5cc 569 //
570 Int_t i;
143d1056 571
d5da1ecf 572 cout << endl;
573 for(i=0;i<30;i++) cout << "*";cout << " ITS_INIT ";
574 for(i=0;i<30;i++) cout << "*";cout << endl;
143d1056 575//
576 SetDefaults();
577// TObjArray of TObjStrings
578// for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId((fIdName->At(i))->GetName());
579// Array of TStrings
58005f18 580 for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
143d1056 581//
d5da1ecf 582 for(i=0;i<70;i++) cout << "*";
583 cout << endl;
fe4da5cc 584}
585
3bd79107 586//_____________________________________________________________________________
587void AliITS::SetDefaults()
588{
589 // sets the default segmentation, response, digit and raw cluster classes
590
65d4384f 591 printf("SetDefaults\n");
3bd79107 592
593 AliITSDetType *iDetType;
594
65d4384f 595
3bd79107 596 //SPD
597
65d4384f 598 iDetType=DetType(0);
143d1056 599 if (!iDetType->GetSegmentationModel()) {
65d4384f 600 AliITSsegmentationSPD *seg0=new AliITSsegmentationSPD(fITSgeom);
601 SetSegmentationModel(0,seg0);
602 }
603 if (!iDetType->GetResponseModel()) {
604 SetResponseModel(0,new AliITSresponseSPD());
605 }
3bd79107 606 // set digit and raw cluster classes to be used
65d4384f 607
608 const char *kData0=(iDetType->GetResponseModel())->DataType();
e8189707 609 if (strstr(kData0,"real")) {
3bd79107 610 iDetType->ClassNames("AliITSdigit","AliITSRawClusterSPD");
611 } else iDetType->ClassNames("AliITSdigitSPD","AliITSRawClusterSPD");
612
65d4384f 613 // SDD //
614 iDetType=DetType(1);
615 if (!iDetType->GetResponseModel()) {
616 SetResponseModel(1,new AliITSresponseSDD());
617 }
618 AliITSresponse *resp1=iDetType->GetResponseModel();
143d1056 619 if (!iDetType->GetSegmentationModel()) {
65d4384f 620 AliITSsegmentationSDD *seg1=new AliITSsegmentationSDD(fITSgeom,resp1);
143d1056 621 SetSegmentationModel(1,seg1);
143d1056 622 }
65d4384f 623 const char *kData1=(iDetType->GetResponseModel())->DataType();
624 const char *kopt=iDetType->GetResponseModel()->ZeroSuppOption();
e8189707 625 if ((!strstr(kopt,"2D")) && (!strstr(kopt,"1D")) || strstr(kData1,"real") ) {
3bd79107 626 iDetType->ClassNames("AliITSdigit","AliITSRawClusterSDD");
627 } else iDetType->ClassNames("AliITSdigitSDD","AliITSRawClusterSDD");
628
629 // SSD
65d4384f 630 iDetType=DetType(2);
143d1056 631 if (!iDetType->GetSegmentationModel()) {
65d4384f 632 AliITSsegmentationSSD *seg2=new AliITSsegmentationSSD(fITSgeom);
143d1056 633 SetSegmentationModel(2,seg2);
65d4384f 634 }
635 if (!iDetType->GetResponseModel()) {
636 SetResponseModel(2,new AliITSresponseSSD());
637 }
638 const char *kData2=(iDetType->GetResponseModel())->DataType();
e8189707 639 if (strstr(kData2,"real")) {
3bd79107 640 iDetType->ClassNames("AliITSdigit","AliITSRawClusterSSD");
641 } else iDetType->ClassNames("AliITSdigitSSD","AliITSRawClusterSSD");
642
e8189707 643 if (fgkNTYPES>3) {
3bd79107 644 Warning("SetDefaults","Only the three basic detector types are initialised!");
65d4384f 645 }
3bd79107 646
647}
65d4384f 648
649
650
e8189707 651//_____________________________________________________________________________
652void AliITS::SetDefaultSimulation()
653{
654 // to be written
655
656}
657//_____________________________________________________________________________
658void AliITS::SetDefaultClusterFinders()
659{
660 // to be written
661
662}
3bd79107 663//_____________________________________________________________________________
664
665void AliITS::MakeTreeC(Option_t *option)
666{
667 // create a separate tree to store the clusters
668
d5da1ecf 669 cout << "AliITS::MakeTreeC" << endl;
9c74c52b 670
3bd79107 671 char *optC = strstr(option,"C");
672 if (optC && !fTreeC) fTreeC = new TTree("TC","Clusters in ITS");
9c74c52b 673 else return;
3bd79107 674
675 Int_t buffersize = 4000;
676 char branchname[30];
677
678 char *det[3] = {"SPD","SDD","SSD"};
679
680 // one branch for Clusters per type of detector
681 Int_t i;
e8189707 682 for (i=0; i<fgkNTYPES ;i++) {
683 if (fgkNTYPES==3) sprintf(branchname,"%sClusters%s",GetName(),det[i]);
3bd79107 684 else sprintf(branchname,"%sClusters%d",GetName(),i+1);
685 if (fCtype && fTreeC) {
686 TreeC()->Branch(branchname,&((*fCtype)[i]), buffersize);
d5da1ecf 687 cout << "Making Branch " << branchname;
688 cout << " for Clusters of detector type " << i+1 << endl;
3bd79107 689 }
690 }
691
692}
693
694//_____________________________________________________________________________
695void AliITS::GetTreeC(Int_t event)
696{
697
d5da1ecf 698 cout << "AliITS::GetTreeC" << endl;
9c74c52b 699
3bd79107 700 // get the clusters tree for this event and set the branch address
701 char treeName[20];
702 char branchname[30];
703
704 char *det[3] = {"SPD","SDD","SSD"};
705
706 ResetClusters();
707 if (fTreeC) {
708 delete fTreeC;
709 }
710
711 sprintf(treeName,"TreeC%d",event);
712 fTreeC = (TTree*)gDirectory->Get(treeName);
713
714
715 TBranch *branch;
716 if (fTreeC) {
717 Int_t i;
e8189707 718 for (i=0; i<fgkNTYPES; i++) {
719 if (fgkNTYPES==3) sprintf(branchname,"%sClusters%s",GetName(),det[i]);
720 else sprintf(branchname,"%sClusters%d",GetName(),i+1);
721 if (fCtype) {
3bd79107 722 branch = fTreeC->GetBranch(branchname);
723 if (branch) branch->SetAddress(&((*fCtype)[i]));
724 }
725 }
726 } else {
d5da1ecf 727 Error("AliITS::GetTreeC",
728 "cannot find Clusters Tree for event:%d\n",event);
3bd79107 729 }
730
731}
fe4da5cc 732//_____________________________________________________________________________
2ab0c725 733void AliITS::MakeBranch(Option_t* option, char *file)
734{
fe4da5cc 735 //
3bd79107 736 // Creates Tree branches for the ITS.
fe4da5cc 737 //
2ab0c725 738 //
fe4da5cc 739 Int_t buffersize = 4000;
3bd79107 740 char branchname[30];
fe4da5cc 741 sprintf(branchname,"%s",GetName());
742
2ab0c725 743 AliDetector::MakeBranch(option,file);
fe4da5cc 744
2ab0c725 745 char *cD = strstr(option,"D");
746 char *cR = strstr(option,"R");
fe4da5cc 747
2ab0c725 748 if (cD) {
749 //
750 // one branch for digits per type of detector
751 //
3bd79107 752 char *det[3] = {"SPD","SDD","SSD"};
753
e8189707 754 char digclass[40];
755 char clclass[40];
3bd79107 756
757 Int_t i;
e8189707 758 for (i=0; i<fgkNTYPES ;i++) {
3bd79107 759 AliITSDetType *iDetType=DetType(i);
e8189707 760 iDetType->GetClassNames(digclass,clclass);
761 //printf("i, digclass, recclass %d %s %s\n",i,digclass,clclass);
3bd79107 762 // digits
e8189707 763 (*fDtype)[i] = new TClonesArray(digclass,10000);
3bd79107 764 // clusters
e8189707 765 (*fCtype)[i] = new TClonesArray(clclass,10000);
3bd79107 766 }
767
2ab0c725 768 for (i=0; i<fgkNTYPES ;i++) {
e8189707 769 if (fgkNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
2ab0c725 770 else sprintf(branchname,"%sDigits%d",GetName(),i+1);
771 if (fDtype && gAlice->TreeD()) {
772 gAlice->MakeBranchInTree(gAlice->TreeD(),
773 branchname, &((*fDtype)[i]), buffersize, file) ;
774 cout << "Making Branch " << branchname;
775 cout << " for digits of type "<< i+1 << endl;
3bd79107 776 }
2ab0c725 777 }
3bd79107 778 }
779
2ab0c725 780 if (cR) {
781 //
3bd79107 782 // only one branch for rec points for all detector types
2ab0c725 783 //
784 sprintf(branchname,"%sRecPoints",GetName());
785
786 fRecPoints=new TClonesArray("AliITSRecPoint",10000);
3bd79107 787
2ab0c725 788 if (fRecPoints && gAlice->TreeR()) {
789 gAlice->MakeBranchInTree(gAlice->TreeR(),
790 branchname, &fRecPoints, buffersize, file) ;
791 cout << "Making Branch " << branchname;
792 cout << " for reconstructed space points" << endl;
793 }
3bd79107 794 }
3bd79107 795}
796
797//___________________________________________
798void AliITS::SetTreeAddress()
799{
800
801 // Set branch address for the Trees.
802
803 char branchname[30];
804 AliDetector::SetTreeAddress();
805
806 char *det[3] = {"SPD","SDD","SSD"};
807
808 TBranch *branch;
809 TTree *treeD = gAlice->TreeD();
810 TTree *treeR = gAlice->TreeR();
811
812 Int_t i;
813 if (treeD) {
e8189707 814 for (i=0; i<fgkNTYPES; i++) {
815 if (fgkNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
3bd79107 816 else sprintf(branchname,"%sDigits%d",GetName(),i+1);
817 if (fDtype) {
818 branch = treeD->GetBranch(branchname);
819 if (branch) branch->SetAddress(&((*fDtype)[i]));
820 }
821 }
822 }
823
824
825 if (treeR) {
826 sprintf(branchname,"%sRecPoints",GetName());
827 if (fRecPoints) {
828 branch = treeR->GetBranch(branchname);
829 if (branch) branch->SetAddress(&fRecPoints);
830 }
831 }
832
833
834}
835
836//____________________________________________________________________________
837void AliITS::InitModules(Int_t size,Int_t &nmodules){
838
839 //initialize the modules array
840
e8189707 841 if(fITSmodules){
9c74c52b 842 fITSmodules->Delete();
e8189707 843 delete fITSmodules;
844 }
845
3bd79107 846 Int_t nl,indexMAX,index;
3bd79107 847
848 if(size<=0){ // default to using data stored in AliITSgeom
849 if(fITSgeom==0) {
d5da1ecf 850 Error("AliITS::InitModules",
851 "in AliITS::InitModule fITSgeom not defined\n");
3bd79107 852 return;
853 } // end if fITSgeom==0
854 nl = fITSgeom->GetNlayers();
855 indexMAX = fITSgeom->GetModuleIndex(nl,fITSgeom->GetNladders(nl),
856 fITSgeom->GetNdetectors(nl))+1;
857 nmodules = indexMAX;
858 fITSmodules = new TObjArray(indexMAX);
3bd79107 859 for(index=0;index<indexMAX;index++){
3bd79107 860 fITSmodules->AddAt( new AliITSmodule(index),index);
3bd79107 861 } // end for index
862 }else{
863 fITSmodules = new TObjArray(size);
9c74c52b 864 for(index=0;index<size;index++) {
865 fITSmodules->AddAt( new AliITSmodule(index),index);
866 }
867
3bd79107 868 nmodules = size;
869 } // end i size<=0
870}
871
872//____________________________________________________________________________
e8189707 873void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t nmodules,Option_t *option,Text_t *filename){
3bd79107 874
875 // fill the modules with the sorted by module hits; add hits from background
876 // if option=Add
877
9c74c52b 878
3bd79107 879 static TTree *trH1; //Tree with background hits
880 static TClonesArray *fHits2; //List of hits for one track only
881
882 static Bool_t first=kTRUE;
883 static TFile *file;
e8189707 884 char *addBgr = strstr(option,"Add");
3bd79107 885
886
e8189707 887 if (addBgr ) {
3bd79107 888 if(first) {
889 cout<<"filename "<<filename<<endl;
890 file=new TFile(filename);
891 cout<<"I have opened "<<filename<<" file "<<endl;
892 fHits2 = new TClonesArray("AliITShit",1000 );
893 }
894 first=kFALSE;
895 file->cd();
896 file->ls();
897 // Get Hits Tree header from file
898 if(fHits2) fHits2->Clear();
899 if(trH1) delete trH1;
900 trH1=0;
901
902 char treeName[20];
903 sprintf(treeName,"TreeH%d",bgrev);
904 trH1 = (TTree*)gDirectory->Get(treeName);
905 //printf("TrH1 %p of treename %s for event %d \n",trH1,treeName,bgrev);
906
907 if (!trH1) {
d5da1ecf 908 Error("AliITS::FillModules",
909 "cannot find Hits Tree for event:%d\n",bgrev);
3bd79107 910 }
911 // Set branch addresses
912 TBranch *branch;
913 char branchname[20];
914 sprintf(branchname,"%s",GetName());
915 if (trH1 && fHits2) {
916 branch = trH1->GetBranch(branchname);
917 if (branch) branch->SetAddress(&fHits2);
918 }
919
920 // test
921 //Int_t ntracks1 =(Int_t)TrH1->GetEntries();
922 //printf("background - ntracks1 - %d\n",ntracks1);
923 }
924
2ab0c725 925 //Int_t npart = gAlice->GetEvent(evnt);
926 //if(npart<=0) return;
3bd79107 927 TClonesArray *itsHits = this->Hits();
928 Int_t lay,lad,det,index;
929 AliITShit *itsHit=0;
930 AliITSmodule *mod=0;
931
932 TTree *iTH = gAlice->TreeH();
933 Int_t ntracks =(Int_t) iTH->GetEntries();
934
935 Int_t t,h;
936 for(t=0; t<ntracks; t++){
937 gAlice->ResetHits();
938 iTH->GetEvent(t);
939 Int_t nhits = itsHits->GetEntriesFast();
9c74c52b 940 //printf("nhits %d\n",nhits);
3bd79107 941 if (!nhits) continue;
3bd79107 942 for(h=0; h<nhits; h++){
943 itsHit = (AliITShit *)itsHits->UncheckedAt(h);
944 itsHit->GetDetectorID(lay,lad,det);
9c74c52b 945 // temporarily index=det-1 !!!
946 if(fITSgeom) index = fITSgeom->GetModuleIndex(lay,lad,det);
947 else index=det-1;
948 //
3bd79107 949 mod = this->GetModule(index);
9c74c52b 950 mod->AddHit(itsHit,t,h);
3bd79107 951 } // end loop over hits
952 } // end loop over tracks
953
954 // open the file with background
955
e8189707 956 if (addBgr ) {
957 Int_t track,i;
3bd79107 958 ntracks =(Int_t)trH1->GetEntries();
959 //printf("background - ntracks1 %d\n",ntracks);
960 //printf("background - Start loop over tracks \n");
961 // Loop over tracks
962
e8189707 963 for (track=0; track<ntracks; track++) {
3bd79107 964
965 if (fHits2) fHits2->Clear();
966 trH1->GetEvent(track);
967 // Loop over hits
968 for(i=0;i<fHits2->GetEntriesFast();++i) {
969
970 itsHit=(AliITShit*) (*fHits2)[i];
971 itsHit->GetDetectorID(lay,lad,det);
9c74c52b 972 // temporarily index=det-1 !!!
973 if(fITSgeom) index = fITSgeom->GetModuleIndex(lay,lad,det);
974 else index=det-1;
975 //
3bd79107 976 mod = this->GetModule(index);
9c74c52b 977 mod->AddHit(itsHit,track,i);
3bd79107 978 } // end loop over hits
979 } // end loop over tracks
980
981 TTree *fAli=gAlice->TreeK();
982 TFile *fileAli=0;
983
984 if (fAli) fileAli =fAli->GetCurrentFile();
9c74c52b 985 fileAli->cd();
3bd79107 986
987 } // end if add
988
3bd79107 989 //gObjectTable->Print();
990
991}
992
2ab0c725 993//____________________________________________________________________________
994
995void AliITS::SDigits2Digits()
996{
997
998 AliITSgeom *geom = GetITSgeom();
999
1000 // SPD
1001 AliITSDetType *iDetType;
1002 iDetType=DetType(0);
1003 AliITSsegmentationSPD *seg0=(AliITSsegmentationSPD*)iDetType->GetSegmentationModel();
1004 AliITSresponseSPD *res0 = (AliITSresponseSPD*)iDetType->GetResponseModel();
1005 AliITSsimulationSPD *sim0=new AliITSsimulationSPD(seg0,res0);
1006 SetSimulationModel(0,sim0);
1007 // test
1008 // printf("SPD dimensions %f %f \n",seg0->Dx(),seg0->Dz());
1009 // printf("SPD npixels %d %d \n",seg0->Npz(),seg0->Npx());
1010 // printf("SPD pitches %d %d \n",seg0->Dpz(0),seg0->Dpx(0));
1011 // end test
1012 //
1013 // SDD
1014 //Set response functions
1015 Float_t baseline = 10.;
1016 Float_t noise = 1.75;
1017
1018 // SDD compression param: 2 fDecrease, 2fTmin, 2fTmax or disable, 2 fTolerance
1019
1020 iDetType=DetType(1);
1021 AliITSresponseSDD *res1 = (AliITSresponseSDD*)iDetType->GetResponseModel();
1022 if (!res1) {
1023 res1=new AliITSresponseSDD();
1024 SetResponseModel(1,res1);
1025 }
1026 res1->SetMagicValue(900.);
1027 Float_t maxadc = res1->MaxAdc();
1028 Float_t topValue = res1->MagicValue();
1029 Float_t norm = maxadc/topValue;
1030
1031 Float_t fCutAmp = baseline + 2.*noise;
1032 fCutAmp *= norm;
1033 Int_t cp[8]={0,0,(int)fCutAmp,(int)fCutAmp,0,0,0,0}; //1D
1034
1035 //res1->SetZeroSupp("2D");
1036 res1->SetZeroSupp("1D");
1037 res1->SetNoiseParam(noise,baseline);
1038 res1->SetDo10to8(kTRUE);
1039 res1->SetCompressParam(cp);
1040 res1->SetMinVal(4);
1041 res1->SetDiffCoeff(3.6,40.);
1042 //res1->SetMagicValue(96.95);
1043 AliITSsegmentationSDD *seg1=(AliITSsegmentationSDD*)iDetType->GetSegmentationModel();
1044 if (!seg1) {
1045 seg1 = new AliITSsegmentationSDD(geom,res1);
1046 SetSegmentationModel(1,seg1);
1047 }
1048 AliITSsimulationSDD *sim1=new AliITSsimulationSDD(seg1,res1);
1049 sim1->SetDoFFT(1);
1050 sim1->SetCheckNoise(kFALSE);
1051 SetSimulationModel(1,sim1);
1052
1053 // SSD
1054 iDetType=DetType(2);
1055 AliITSsegmentationSSD *seg2=(AliITSsegmentationSSD*)iDetType->GetSegmentationModel();
1056 AliITSresponseSSD *res2 = (AliITSresponseSSD*)iDetType->GetResponseModel();
1057 res2->SetSigmaSpread(3.,2.);
1058 AliITSsimulationSSD *sim2=new AliITSsimulationSSD(seg2,res2);
1059 SetSimulationModel(2,sim2);
1060
1061 cerr<<"Digitizing ITS...\n";
1062
1063 TStopwatch timer;
1064 timer.Start();
1065 HitsToDigits(0,0,-1," ","All"," ");
1066 timer.Stop(); timer.Print();
1067
1068 delete sim0;
1069 delete sim1;
1070 delete sim2;
1071}
1072
3bd79107 1073
1074//____________________________________________________________________________
e8189707 1075void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size, Option_t *option, Option_t *opt,Text_t *filename)
3bd79107 1076{
1077 // keep galice.root for signal and name differently the file for
1078 // background when add! otherwise the track info for signal will be lost !
1079
9c74c52b 1080 // the condition below will disappear when the geom class will be
1081 // initialised for all versions - for the moment it is only for v5 !
1082 // 7 is the SDD beam test version
1083 Int_t ver = this->IsVersion();
1084 if(ver!=5 && ver!=7) return;
1085
3bd79107 1086 char *all = strstr(opt,"All");
1087 char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),strstr(opt,"SSD")};
3bd79107 1088
1089 Int_t nmodules;
1090 InitModules(size,nmodules);
e8189707 1091 FillModules(evNumber,bgrev,nmodules,option,filename);
3bd79107 1092
9c74c52b 1093 //TBranch *branch;
3bd79107 1094 AliITSsimulation* sim;
9c74c52b 1095 //TObjArray *branches=gAlice->TreeD()->GetListOfBranches();
3bd79107 1096 AliITSgeom *geom = GetITSgeom();
1097
1098 Int_t id,module;
9c74c52b 1099 Int_t first,last;
e8189707 1100 for (id=0;id<fgkNTYPES;id++) {
3bd79107 1101 if (!all && !det[id]) continue;
9c74c52b 1102 //branch = (TBranch*)branches->UncheckedAt(id);
3bd79107 1103 AliITSDetType *iDetType=DetType(id);
1104 sim = (AliITSsimulation*)iDetType->GetSimulationModel();
1105 if (!sim) {
1106 Error("HitsToDigits","The simulation class was not instantiated!");
1107 exit(1);
e8189707 1108 // or SetDefaultSimulation();
3bd79107 1109 }
9c74c52b 1110 if(geom) {
1111 first = geom->GetStartDet(id);
1112 last = geom->GetLastDet(id);
1113 } else first=last=0;
d5da1ecf 1114 cout << "det type " << id << " first, last "<< first << last << endl;
3bd79107 1115 for(module=first;module<=last;module++) {
1116 AliITSmodule *mod = (AliITSmodule *)fITSmodules->At(module);
1117 sim->DigitiseModule(mod,module,evNumber);
1118 // fills all branches - wasted disk space
1119 gAlice->TreeD()->Fill();
1120 ResetDigits();
1121 // try and fill only the branch
1122 //branch->Fill();
1123 //ResetDigits(id);
1124 } // loop over modules
1125 } // loop over detector types
1126
3bd79107 1127 ClearModules();
1128
e8189707 1129 Int_t nentries=(Int_t)gAlice->TreeD()->GetEntries();
d5da1ecf 1130 cout << "nentries in TreeD" << nentries << endl;
3bd79107 1131
1132 char hname[30];
1133 sprintf(hname,"TreeD%d",evNumber);
2ab0c725 1134 gAlice->TreeD()->Write(hname,TObject::kOverwrite);
3bd79107 1135 // reset tree
1136 gAlice->TreeD()->Reset();
1137
1138}
1139
1140
1141//____________________________________________________________________________
1142void AliITS::DigitsToRecPoints(Int_t evNumber,Int_t lastentry,Option_t *opt)
1143{
e8189707 1144 // cluster finding and reconstruction of space points
3bd79107 1145
9c74c52b 1146 // the condition below will disappear when the geom class will be
1147 // initialised for all versions - for the moment it is only for v5 !
1148 // 7 is the SDD beam test version
1149 Int_t ver = this->IsVersion();
1150 if(ver!=5 && ver!=7) return;
1151
3bd79107 1152 char *all = strstr(opt,"All");
1153 char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),strstr(opt,"SSD")};
1154
1155 static Bool_t first=kTRUE;
1156 if (first) {
1157 MakeTreeC("C");
1158 first=kFALSE;
1159 }
3bd79107 1160
9c74c52b 1161 TTree *iTC=TreeC();
1162
1163 //TBranch *branch;
3bd79107 1164 AliITSClusterFinder* rec;
1165
9c74c52b 1166 //TObjArray *branches=gAlice->TreeR()->GetListOfBranches();
3bd79107 1167 AliITSgeom *geom = GetITSgeom();
1168
1169 Int_t id,module;
e8189707 1170 for (id=0;id<fgkNTYPES;id++) {
3bd79107 1171 if (!all && !det[id]) continue;
9c74c52b 1172 //branch = (TBranch*)branches->UncheckedAt(id);
3bd79107 1173 AliITSDetType *iDetType=DetType(id);
1174 rec = (AliITSClusterFinder*)iDetType->GetReconstructionModel();
1175 if (!rec) {
1176 Error("DigitsToRecPoints","The cluster finder class was not instantiated!");
1177 exit(1);
e8189707 1178 // or SetDefaultClusterFinders();
3bd79107 1179 }
1180 TClonesArray *itsDigits = this->DigitsAddress(id);
1181
9c74c52b 1182 Int_t first,last;
1183 if(geom) {
1184 first = geom->GetStartDet(id);
1185 last = geom->GetLastDet(id);
1186 } else first=last=0;
1187 //printf("first last %d %d\n",first,last);
3bd79107 1188 for(module=first;module<=last;module++) {
3bd79107 1189 this->ResetDigits();
1190 if (all) gAlice->TreeD()->GetEvent(lastentry+module);
1191 else gAlice->TreeD()->GetEvent(lastentry+(module-first));
1192 Int_t ndigits = itsDigits->GetEntriesFast();
1193 if (ndigits) rec->FindRawClusters();
1194 gAlice->TreeR()->Fill();
1195 ResetRecPoints();
1196 iTC->Fill();
1197 ResetClusters();
1198 // try and fill only the branch
1199 //branch->Fill();
1200 //ResetRecPoints(id);
1201 } // loop over modules
1202 } // loop over detector types
1203
1204
e8189707 1205 Int_t nentries=(Int_t)gAlice->TreeR()->GetEntries();
1206 Int_t ncentries=(Int_t)iTC->GetEntries();
d5da1ecf 1207 cout << " nentries ncentries " << nentries << ncentries << endl;
3bd79107 1208
1209 char hname[30];
1210 sprintf(hname,"TreeR%d",evNumber);
2ab0c725 1211 gAlice->TreeR()->Write(hname,TObject::kOverwrite);
3bd79107 1212 // reset tree
1213 gAlice->TreeR()->Reset();
1214
1215 sprintf(hname,"TreeC%d",evNumber);
1216 iTC->Write(hname);
1217 iTC->Reset();
1218}
1219
1220
1221//____________________________________________________________________________
e8189707 1222void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
3bd79107 1223Option_t *option,Option_t *opt,Text_t *filename)
1224{
1225 // keep galice.root for signal and name differently the file for
1226 // background when add! otherwise the track info for signal will be lost !
1227
9c74c52b 1228
1229 // the condition below will disappear when the geom class will be
1230 // initialised for all versions - for the moment it is only for v5 !
1231 Int_t ver = this->IsVersion();
1232 if(ver!=5) return;
1233
3bd79107 1234 char *all = strstr(opt,"All");
1235 char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),strstr(opt,"SSD")};
1236
1237 Int_t nmodules;
e8189707 1238 InitModules(size,nmodules);
1239 FillModules(evNumber,bgrev,nmodules,option,filename);
3bd79107 1240
1241
e8189707 1242 AliITSsimulation* sim;
3bd79107 1243 AliITSgeom *geom = GetITSgeom();
1244
e8189707 1245 TRandom *random=new TRandom[9];
1246 random[0].SetSeed(111);
1247 random[1].SetSeed(222);
1248 random[2].SetSeed(333);
1249 random[3].SetSeed(444);
1250 random[4].SetSeed(555);
1251 random[5].SetSeed(666);
1252 random[6].SetSeed(777);
1253 random[7].SetSeed(888);
1254 random[8].SetSeed(999);
1255
1256
3bd79107 1257 Int_t id,module;
e8189707 1258 for (id=0;id<fgkNTYPES;id++) {
3bd79107 1259 if (!all && !det[id]) continue;
e8189707 1260 AliITSDetType *iDetType=DetType(id);
1261 sim = (AliITSsimulation*)iDetType->GetSimulationModel();
1262 if (!sim) {
1263 Error("HitsToFastPoints","The simulation class was not instantiated!");
1264 exit(1);
1265 // or SetDefaultSimulation();
1266 }
3bd79107 1267 Int_t first = geom->GetStartDet(id);
1268 Int_t last = geom->GetLastDet(id);
1269 for(module=first;module<=last;module++) {
1270 AliITSmodule *mod = (AliITSmodule *)fITSmodules->At(module);
e8189707 1271 sim->CreateFastRecPoints(mod,module,random);
3bd79107 1272 gAlice->TreeR()->Fill();
1273 ResetRecPoints();
1274 } // loop over modules
1275 } // loop over detector types
1276
1277
1278 ClearModules();
1279
1280 //Int_t nentries=(Int_t)gAlice->TreeR()->GetEntries();
1281
1282 char hname[30];
1283 sprintf(hname,"TreeR%d",evNumber);
2ab0c725 1284 gAlice->TreeR()->Write(hname,TObject::kOverwrite);
3bd79107 1285 // reset tree
1286 gAlice->TreeR()->Reset();
1287
e8189707 1288 delete [] random;
1289
fe4da5cc 1290}
1291
d5da1ecf 1292
e8189707 1293//____________________________________________________________________________
1294void AliITS::Streamer(TBuffer &R__b){
58005f18 1295 // Stream an object of class AliITS.
3bd79107 1296
e8189707 1297 Int_t i;
3bd79107 1298
58005f18 1299 if (R__b.IsReading()) {
235841d0 1300 Version_t R__v = R__b.ReadVersion();
1301 if (R__v) {
1302 AliDetector::Streamer(R__b);
e8189707 1303 R__b >> fIdN;
1304 R__b.ReadArray(fIdSens);
143d1056 1305 if(fIdName!=0) delete[] fIdName; // Array of TStrings
1306 fIdName = new TString[fIdN];
e8189707 1307 for(i=0;i<fIdN;i++) fIdName[i].Streamer(R__b);
235841d0 1308 R__b >> fITSgeom;
1309 R__b >> fITSmodules;
1310 R__b >> fEuclidOut;
235841d0 1311 R__b >> fMajorVersion;
1312 R__b >> fMinorVersion;
1313 R__b >> fDetTypes;
235841d0 1314 R__b >> fDtype;
1315 delete []fNdtype;
e8189707 1316 fNdtype = new Int_t[fgkNTYPES];
1317 R__b.ReadFastArray(fNdtype,fgkNTYPES);
235841d0 1318 R__b >> fCtype;
1319 delete []fNctype;
e8189707 1320 fNctype = new Int_t[fgkNTYPES];
1321 R__b.ReadFastArray(fNctype,fgkNTYPES);
235841d0 1322 R__b >> fRecPoints;
1323 R__b >> fNRecPoints;
235841d0 1324 R__b >> fTreeC;
1325 } // end if R__v
1326 } else { // writing
58005f18 1327 R__b.WriteVersion(AliITS::IsA());
1328 AliDetector::Streamer(R__b);
e8189707 1329 R__b << fIdN;
1330 R__b.WriteArray(fIdSens,fIdN);
1331 for(i=0;i<fIdN;i++) fIdName[i].Streamer(R__b);
58005f18 1332 R__b << fITSgeom;
2b2439bd 1333 R__b << fITSmodules;
58005f18 1334 R__b << fEuclidOut;
58005f18 1335 R__b << fMajorVersion;
1336 R__b << fMinorVersion;
3bd79107 1337 R__b << fDetTypes;
2b2439bd 1338 R__b << fDtype;
e8189707 1339 R__b.WriteFastArray(fNdtype,fgkNTYPES);
2b2439bd 1340 R__b << fCtype;
e8189707 1341 R__b.WriteFastArray(fNctype,fgkNTYPES);
3bd79107 1342 R__b << fRecPoints;
1343 R__b << fNRecPoints;
2b2439bd 1344 R__b << fTreeC;
235841d0 1345 } // end if
e8189707 1346
fe4da5cc 1347}
55b5a0b3 1348
1349//________________________________________________________________
1350
1351AliITStrack AliITS::Tracking(AliITStrack &track, AliITStrack *reference,TObjArray *fastpoints, Int_t
1352**vettid, Bool_t flagvert ) {
1353
1354//Origin A. Badala' and G.S. Pappalardo: e-mail Angela.Badala@ct.infn.it, Giuseppe.S.Pappalardo@ct.infn.it
1355
cc6e75dd 1356
55b5a0b3 1357 TList *list= new TList();
1358
1359 AliITStrack tr(track);
cc6e75dd 1360
55b5a0b3 1361 list->AddLast(&tr);
1362
1363 Double_t Pt=(tr).GetPt();
1364 //cout << "\n Pt = " << Pt <<"\n";
1365
55b5a0b3 1366 AliITStracking obj(list, reference, this, fastpoints,TMath::Abs(Pt),vettid, flagvert);
1367 list->Delete();
1368 delete list;
1369
1370 Int_t itot=-1;
1371 TVector VecTotLabref(18);
cc6e75dd 1372 Int_t lay, k;
1373 for(lay=5; lay>=0; lay--) {
55b5a0b3 1374 TVector VecLabref(3);
1375 VecLabref=(*reference).GetLabTrack(lay);
cc6e75dd 1376 for(k=0; k<3; k++) {itot++; VecTotLabref(itot)=VecLabref(k);}
55b5a0b3 1377 }
1378 Long_t labref;
1379 Int_t freq;
1380 (*reference).Search(VecTotLabref, labref, freq);
1381
1382 if(freq < 5) labref=-labref;
1383 (*reference).SetLabel(labref);
1384
1385 return *reference;
1386
1387}
1388
1389
1390
1391//________________________________________________________________
1392
1393
1394
1395void AliITS::DoTracking(Int_t evNumber, Int_t min_t, Int_t max_t, TFile *file, Bool_t flagvert) {
1396
1397// ex macro for tracking ITS
1398
1399 printf("begin DoTracking - file %p\n",file);
1400
1401 const char *pname="75x40_100x60";
1402
1403 struct GoodTrack {
1404 Int_t lab,code;
1405 Float_t px,py,pz,x,y,z,pxg,pyg,pzg,ptg;
1406 Bool_t flag;
1407 };
1408
1409
1410 gAlice->GetEvent(0);
1411
1412 AliTPC *TPC=(AliTPC*)gAlice->GetDetector("TPC");
1413 AliTPCParam *digp = (AliTPCParam*)file->Get(pname);
1414 if (digp!=0) TPC->SetParam(digp);
1415
1416 GoodTrack gt[7000];
1417 Int_t ngood=0;
1418 ifstream in("good_tracks");
1419
1420 cerr<<"Reading good tracks...\n";
1421 while (in>>gt[ngood].lab>>gt[ngood].code
1422 >>gt[ngood].px >>gt[ngood].py>>gt[ngood].pz
1423 >>gt[ngood].x >>gt[ngood].y >>gt[ngood].z
1424 >>gt[ngood].pxg >>gt[ngood].pyg >>gt[ngood].pzg
1425 >>gt[ngood].ptg >>gt[ngood].flag) {
1426 ngood++;
1427 cerr<<ngood<<'\r';
1428 if (ngood==7000) {
1429 cerr<<"Too many good tracks !\n";
1430 break;
1431 }
1432 }
1433 if (!in.eof()) cerr<<"Read error (good_tracks) !\n";
1434
1435
1436// Load tracks
1437 TFile *tf=TFile::Open("tpctracks.root");
1438 if (!tf->IsOpen()) {cerr<<"Can't open tpctracks.root !\n"; return ;}
1439 TObjArray tracks(200000);
1440 TTree *tracktree=(TTree*)tf->Get("TreeT");
1441 TBranch *tbranch=tracktree->GetBranch("tracks");
1442 Int_t nentr=(Int_t)tracktree->GetEntries();
cc6e75dd 1443 Int_t kk;
1444 for (kk=0; kk<nentr; kk++) {
55b5a0b3 1445 AliTPCtrack *iotrack=new AliTPCtrack;
1446 tbranch->SetAddress(&iotrack);
cc6e75dd 1447 tracktree->GetEvent(kk);
55b5a0b3 1448 tracks.AddLast(iotrack);
1449 }
1450 tf->Close();
1451
1452
1453 Int_t nt = tracks.GetEntriesFast();
1454 cerr<<"Number of found tracks "<<nt<<endl;
1455
1456 TVector DataOut(9);
1457 Int_t kkk=0;
1458
1459 Double_t ptg=0.,pxg=0.,pyg=0.,pzg=0.;
1460
1461 ////////////////////////////// good tracks definition in TPC ////////////////////////////////
1462
1463 ofstream out1 ("AliITSTrag.out");
cc6e75dd 1464 Int_t i;
1465 for (i=0; i<ngood; i++) out1 << gt[i].ptg << "\n";
55b5a0b3 1466 out1.close();
1467
1468
1469 TVector vec(5);
1470 TTree *TR=gAlice->TreeR();
1471 Int_t nent=(Int_t)TR->GetEntries();
1472 TClonesArray *recPoints = RecPoints();
1473 Int_t numbpoints;
1474 Int_t totalpoints=0;
1475 Int_t *np = new Int_t[nent];
1476 Int_t **vettid = new Int_t* [nent];
cc6e75dd 1477 Int_t mod;
1478 for (mod=0; mod<nent; mod++) {
55b5a0b3 1479 vettid[mod]=0;
1480 this->ResetRecPoints();
1481 gAlice->TreeR()->GetEvent(mod+1); //first entry in TreeR is empty
1482 numbpoints = recPoints->GetEntries();
1483 totalpoints+=numbpoints;
1484 np[mod] = numbpoints;
1485 //cout<<" mod = "<<mod<<" numbpoints = "<<numbpoints<<"\n"; getchar();
1486 vettid[mod] = new Int_t[numbpoints];
cc6e75dd 1487 Int_t ii;
1488 for (ii=0;ii<numbpoints; ii++) *(vettid[mod]+ii)=0;
55b5a0b3 1489 }
1490
1491 AliTPCtrack *track;
1492
1493
1494 if(min_t < 0) {min_t = 0; max_t = nt-1;}
1495
1496/*
1497 ///////////////////////////////// Definition of vertex end its error ////////////////////////////
1498 ////////////////////////// In the future it will be given by a method ///////////////////////////
1499 Double_t Vx=0.;
1500 Double_t Vy=0.;
1501 Double_t Vz=0.;
1502
1503 Float_t sigmavx=0.0050; // 50 microns
1504 Float_t sigmavy=0.0050; // 50 microns
1505 Float_t sigmavz=0.010; // 100 microns
1506
1507 //Vx+=gRandom->Gaus(0,sigmavx); Vy+=gRandom->Gaus(0,sigmavy); Vz+=gRandom->Gaus(0,sigmavz);
1508 TVector vertex(3), ervertex(3)
1509 vertex(0)=Vx; vertex(1)=Vy; vertex(2)=Vz;
1510 ervertex(0)=sigmavx; ervertex(1)=sigmavy; ervertex(2)=sigmavz;
1511 /////////////////////////////////////////////////////////////////////////////////////////////////
1512*/
1513
1514 //TDirectory *savedir=gDirectory;
1515
1516 TTree tracktree1("TreeT","Tree with ITS tracks");
1517 AliITSiotrack *iotrack=0;
1518 tracktree1.Branch("ITStracks","AliITSiotrack",&iotrack,32000,0);
1519
1520 ofstream out ("AliITSTra.out");
cc6e75dd 1521
1522 Int_t j;
1523 for (j=min_t; j<=max_t; j++) {
55b5a0b3 1524 track=(AliTPCtrack*)tracks.UncheckedAt(j);
1525 Int_t flaglab=0;
1526 if (!track) continue;
1527 ////// elimination of not good tracks ////////////
1528 Int_t ilab=TMath::Abs(track->GetLabel());
cc6e75dd 1529 Int_t iii;
1530 for (iii=0;iii<ngood;iii++) {
1531 //cout<<" ilab, gt[iii].lab = "<<ilab<<" "<<gt[iii].lab<<"\n"; getchar();
1532 if (ilab==gt[iii].lab) {
55b5a0b3 1533 flaglab=1;
cc6e75dd 1534 ptg=gt[iii].ptg;
1535 pxg=gt[iii].pxg;
1536 pyg=gt[iii].pyg;
1537 pzg=gt[iii].pzg;
55b5a0b3 1538 break;
1539 }
1540 }
1541 //cout<<" j flaglab = " <<j<<" "<<flaglab<<"\n"; getchar();
1542 if (!flaglab) continue;
1543 //cout<<" j = " <<j<<"\n"; getchar();
1544 /*
1545 ////// old propagation to the end of TPC //////////////
1546 Double_t xk=76.;
1547 track->PropagateTo(xk);
1548 xk-=0.11;
1549 track->PropagateTo(xk,42.7,2.27); //C
1550 xk-=2.6;
1551 track->PropagateTo(xk,36.2,1.98e-3); //C02
1552 xk-=0.051;
1553 track->PropagateTo(xk,42.7,2.27); //C
1554 ///////////////////////////////////////////////////
1555 */
1556
1557 ////// new propagation to the end of TPC //////////////
1558 Double_t xk=77.415;
1559 track->PropagateTo(xk, 28.94, 1.204e-3); //Ne
1560 xk -=0.01;
1561 track->PropagateTo(xk, 44.77, 1.71); //Tedlar
1562 xk -=0.04;
1563 track->PropagateTo(xk, 44.86, 1.45); //Kevlar
1564 xk -=2.0;
1565 track->PropagateTo(xk, 41.28, 0.029); //Nomex
1566 xk-=16;
1567 track->PropagateTo(xk,36.2,1.98e-3); //C02
1568 xk -=0.01;
1569 track->PropagateTo(xk, 24.01, 2.7); //Al
1570 xk -=0.01;
1571 track->PropagateTo(xk, 44.77, 1.71); //Tedlar
1572 xk -=0.04;
1573 track->PropagateTo(xk, 44.86, 1.45); //Kevlar
1574 xk -=0.5;
1575 track->PropagateTo(xk, 41.28, 0.029); //Nomex
1576
1577 ///////////////////////////////////////////////////////////////
1578
1579 ///////////////////////////////////////////////////////////////
1580 AliITStrack trackITS(*track);
1581 AliITStrack result(*track);
1582 AliITStrack primarytrack(*track);
1583
1584///////////////////////////////////////////////////////////////////////////////////////////////
1585 TVector Vgeant(3);
1586 Vgeant=result.GetVertex();
1587
1588 // Definition of Dv and Zv for vertex constraint
cc6e75dd 1589 Double_t sigmaDv=0.0050; Double_t sigmaZv=0.010;
1590 //Double_t sigmaDv=0.0015; Double_t sigmaZv=0.0015;
55b5a0b3 1591 Double_t uniform= gRandom->Uniform();
1592 Double_t signdv;
1593 if(uniform<=0.5) signdv=-1.;
1594 else
1595 signdv=1.;
1596
1597 Double_t Vr=TMath::Sqrt(Vgeant(0)*Vgeant(0)+ Vgeant(1)*Vgeant(1));
1598 Double_t Dv=gRandom->Gaus(signdv*Vr,(Float_t)sigmaDv);
1599 Double_t Zv=gRandom->Gaus(Vgeant(2),(Float_t)sigmaZv);
1600
1601 //cout<<" Dv e Zv = "<<Dv<<" "<<Zv<<"\n";
1602 trackITS.SetDv(Dv); trackITS.SetZv(Zv);
1603 trackITS.SetsigmaDv(sigmaDv); trackITS.SetsigmaZv(sigmaZv);
1604 result.SetDv(Dv); result.SetZv(Zv);
1605 result.SetsigmaDv(sigmaDv); result.SetsigmaZv(sigmaZv);
1606 primarytrack.SetDv(Dv); primarytrack.SetZv(Zv);
1607 primarytrack.SetsigmaDv(sigmaDv); primarytrack.SetsigmaZv(sigmaZv);
1608
1609/////////////////////////////////////////////////////////////////////////////////////////////////
1610
1611 primarytrack.PrimaryTrack();
1612 TVector d2=primarytrack.Getd2();
1613 TVector tgl2=primarytrack.Gettgl2();
1614 TVector dtgl=primarytrack.Getdtgl();
1615 trackITS.Setd2(d2); trackITS.Settgl2(tgl2); trackITS.Setdtgl(dtgl);
1616 result.Setd2(d2); result.Settgl2(tgl2); result.Setdtgl(dtgl);
1617 /*
1618 trackITS.SetVertex(vertex); trackITS.SetErrorVertex(ervertex);
1619 result.SetVertex(vertex); result.SetErrorVertex(ervertex);
1620 */
1621 Tracking(trackITS,&result,recPoints,vettid, flagvert);
1622
cc6e75dd 1623 cout<<" progressive track number = "<<j<<"\r";
1624 // cout<<j<<"\r";
1625 //cout<<" progressive track number = "<<j<<"\n";
55b5a0b3 1626 Long_t labITS=result.GetLabel();
cc6e75dd 1627 //cout << " ITS track label = " << labITS << "\n";
55b5a0b3 1628 int lab=track->GetLabel();
cc6e75dd 1629 // cout << " TPC track label = " << lab <<"\n";
55b5a0b3 1630 //result.GetClusters(); getchar(); //to print the cluster matrix
1631
1632//propagation to vertex
1633
1634 Double_t rbeam=3.;
cc6e75dd 1635
1636 result.Propagation(rbeam);
1637
55b5a0b3 1638 TMatrix *cov;
1639 cov=&result.GetCMatrix();
1640 Double_t pt=TMath::Abs(result.GetPt());
1641 Double_t Dr=result.GetD();
1642 Double_t Z=result.GetZ();
1643 Double_t tgl=result.GetTgl();
1644 Double_t C=result.GetC();
1645 Double_t Cy=C/2.;
1646 Double_t Dz=Z-(tgl/Cy)*TMath::ASin(result.arga(rbeam));
1647 Dz-=Vgeant(2);
cc6e75dd 1648
55b5a0b3 1649 // cout<<" Dr e dz alla fine = "<<Dr<<" "<<Dz<<"\n"; getchar();
1650 Double_t phi=result.Getphi();
1651 Double_t phivertex = phi - TMath::ASin(result.argA(rbeam));
1652 Double_t duepi=2.*TMath::Pi();
1653 if(phivertex>duepi) phivertex-=duepi;
1654 if(phivertex<0.) phivertex+=duepi;
cc6e75dd 1655 Double_t Dtot=TMath::Sqrt(Dr*Dr+Dz*Dz);
1656
55b5a0b3 1657//////////////////////////////////////////////////////////////////////////////////////////
1658 Int_t NumofCluster, idmodule,idpoint;
1659 NumofCluster=result.GetNumClust();
1660 if(NumofCluster >=5) {
1661
1662
1663 AliITSiotrack outtrack;
1664
1665 iotrack=&outtrack;
1666
1667 iotrack->SetStatePhi(phi);
1668 iotrack->SetStateZ(Z);
1669 iotrack->SetStateD(Dr);
1670 iotrack->SetStateTgl(tgl);
1671 iotrack->SetStateC(C);
1672 Double_t radius=result.Getrtrack();
1673 iotrack->SetRadius(radius);
1674 Int_t charge;
1675 if(C>0.) charge=-1; else charge=1;
1676 iotrack->SetCharge(charge);
1677
1678
1679
1680 iotrack->SetCovMatrix(cov);
1681
1682 Double_t px=pt*TMath::Cos(phi);
1683 Double_t py=pt*TMath::Sin(phi);
1684 Double_t pz=pt*tgl;
1685
1686 Double_t xtrack=Dr*TMath::Sin(phi);
1687 Double_t ytrack=Dr*TMath::Cos(phi);
1688 Double_t ztrack=Dz+Vgeant(2);
1689
1690
1691 iotrack->SetPx(px);
1692 iotrack->SetPy(py);
1693 iotrack->SetPz(pz);
1694 iotrack->SetX(xtrack);
1695 iotrack->SetY(ytrack);
1696 iotrack->SetZ(ztrack);
1697 iotrack->SetLabel(labITS);
1698
c5b22044 1699 Int_t il;
1700 for(il=0;il<6; il++){
55b5a0b3 1701 iotrack->SetIdPoint(il,result.GetIdPoint(il));
1702 iotrack->SetIdModule(il,result.GetIdModule(il));
1703 }
1704 tracktree1.Fill();
1705
1706 //cout<<" labITS = "<<labITS<<"\n";
1707 //cout<<" phi z Dr tgl C = "<<phi<<" "<<Z<<" "<<Dr<<" "<<tgl<<" "<<C<<"\n"; getchar();
1708
1709 DataOut(kkk) = ptg; kkk++; DataOut(kkk)=labITS; kkk++; DataOut(kkk)=lab; kkk++;
1710
c5b22044 1711 for (il=0;il<6;il++) {
55b5a0b3 1712 idpoint=result.GetIdPoint(il);
1713 idmodule=result.GetIdModule(il);
1714 *(vettid[idmodule]+idpoint)=1;
1715 iotrack->SetIdPoint(il,idpoint);
1716 iotrack->SetIdModule(il,idmodule);
1717 }
cc6e75dd 1718
1719 // cout<<" +++++++++++++ pt e ptg = "<<pt<<" "<<ptg<<" ++++++++++\n";
55b5a0b3 1720 Double_t difpt= (pt-ptg)/ptg*100.;
1721 DataOut(kkk)=difpt; kkk++;
1722 Double_t lambdag=TMath::ATan(pzg/ptg);
1723 Double_t lam=TMath::ATan(tgl);
1724 Double_t diflam = (lam - lambdag)*1000.;
1725 DataOut(kkk) = diflam; kkk++;
1726 Double_t phig=TMath::ATan(pyg/pxg);
1727 Double_t phi=phivertex;
1728 Double_t difphi = (phi - phig)*1000.;
1729 DataOut(kkk)=difphi; kkk++;
1730 DataOut(kkk)=Dtot*1.e4; kkk++;
1731 DataOut(kkk)=Dr*1.e4; kkk++;
1732 DataOut(kkk)=Dz*1.e4; kkk++;
cc6e75dd 1733 Int_t r;
1734 for (r=0; r<9; r++) { out<<DataOut(r)<<" ";}
55b5a0b3 1735 out<<"\n";
1736 kkk=0;
1737
1738
1739 } // end if on NumofCluster
1740 //gObjectTable->Print(); // stampa memoria
1741 } // end for (int j=min_t; j<=max_t; j++)
1742
1743 out.close();
1744
cc6e75dd 1745
55b5a0b3 1746 static Bool_t first=kTRUE;
1747 static TFile *tfile;
1748
1749 if(first) {
1750 tfile=new TFile("itstracks.root","RECREATE");
1751 //cout<<"I have opened itstracks.root file "<<endl;
1752 }
1753 first=kFALSE;
1754 tfile->cd();
1755 tfile->ls();
1756
1757 char hname[30];
1758 sprintf(hname,"TreeT%d",evNumber);
1759
1760 tracktree1.Write(hname);
1761
1762
1763
1764 TTree *fAli=gAlice->TreeK();
1765 TFile *fileAli=0;
1766
1767 if (fAli) fileAli =fAli->GetCurrentFile();
1768 fileAli->cd();
1769
1770 ////////////////////////////////////////////////////////////////////////////////////////////////
1771
1772 printf("delete vectors\n");
1773 if(np) delete [] np;
1774 if(vettid) delete [] vettid;
1775
1776}