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