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