]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITS.cxx
New ITS code replacing the old structure and simulations code.
[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$
3bd79107 18Revision 1.9.2.8 2000/06/12 18:05:59 barbera
19fixed posible compilation errors on HP unix
20
21Revision 1.9.2.7 2000/06/11 20:20:18 barbera
22New AliITS base clase for the new structure.
23
24Revision 1.9.2.3 2000/02/02 13:42:09 barbera
25fixed AliITS.cxx for new AliRun structure. Added ITS hits list to list of hits which will have their track numbers updated
26
27Revision 1.9.2.2 2000/01/23 03:03:13 nilsen
28//fixed FillModule. Removed fi(fabs(xl)<dx....
29
30Revision 1.9.2.1 2000/01/12 19:03:32 nilsen
31This is the version of the files after the merging done in December 1999.
32See the ReadMe110100.txt file for details
c9a71be1 33
1cedd08a 34Revision 1.9 1999/11/14 14:33:25 fca
35Correct problems with distructors and pointers, thanks to I.Hrivnacova
36
6c854497 37Revision 1.8 1999/09/29 09:24:19 fca
38Introduction of the Copyright and cvs Log
39
4c039060 40*/
41
fe4da5cc 42///////////////////////////////////////////////////////////////////////////////
58005f18 43//
44// An overview of the basic philosophy of the ITS code development
45// and analysis is show in the figure below.
fe4da5cc 46//Begin_Html
47/*
a92b2b7d 48<img src="picts/ITS/ITS_Analysis_schema.gif">
fe4da5cc 49</pre>
50<br clear=left>
51<font size=+2 color=red>
58005f18 52<p>Roberto Barbera is in charge of the ITS Offline code (1999).
fe4da5cc 53<a href="mailto:roberto.barbera@ct.infn.it">Roberto Barbera</a>.
54</font>
55<pre>
56*/
57//End_Html
58005f18 58//
59// AliITS. Inner Traking System base class.
60// This class contains the base procedures for the Inner Tracking System
61//
62//Begin_Html
63/*
a92b2b7d 64<img src="picts/ITS/AliITS_Class_Diagram.gif">
58005f18 65</pre>
66<br clear=left>
67<font size=+2 color=red>
68<p>This show the class diagram of the different elements that are part of
69the AliITS class.
70</font>
71<pre>
72*/
73//End_Html
74//
75// Version: 0
76// Written by Rene Brun, Federico Carminati, and Roberto Barbera
77//
78// Version: 1
79// Modified and documented by Bjorn S. Nilsen
80// July 11 1999
81//
3bd79107 82// Version: 2
83// Modified and documented by A. Bologna
84// October 18 1999
85//
58005f18 86// AliITS is the general base class for the ITS. Also see AliDetector for
87// futher information.
88//
fe4da5cc 89///////////////////////////////////////////////////////////////////////////////
90
91#include <TMath.h>
92#include <TRandom.h>
93#include <TVector.h>
3bd79107 94#include <TObjArray.h>
95#include <TClonesArray.h>
96#include <TROOT.h>
97#include <TObjectTable.h>
98
99
bb8ac1e0 100
fe4da5cc 101#include "AliRun.h"
3bd79107 102#include "AliITS.h"
103#include "AliITSMap.h"
104#include "AliITSClusterFinder.h"
105#include "AliITSsimulation.h"
106#include "AliITSsimulationFastPoints.h"
107#include "AliITSsegmentationSPD.h"
108#include "AliITSresponseSPD.h"
109#include "AliITSsegmentationSDD.h"
110#include "AliITSresponseSDD.h"
111#include "AliITSsegmentationSSD.h"
112#include "AliITSresponseSSD.h"
113//#include "AliITStrack.h"
fe4da5cc 114
c9a71be1 115
3bd79107 116ClassImp(AliITS)
117
fe4da5cc 118//_____________________________________________________________________________
3bd79107 119AliITS::AliITS() : AliDetector() {
fe4da5cc 120 //
121 // Default initialiser for ITS
58005f18 122 // The default constructor of the AliITS class. In addition to
123 // creating the AliITS class it zeros the variables fIshunt (a member
124 // of AliDetector class), fEuclidOut, and fIdN, and zeros the pointers
3bd79107 125 // fITSpoints, fIdSens, and fIdName. The AliDetector default constructor
126 // is also called.
fe4da5cc 127 //
3bd79107 128
58005f18 129 fIshunt = 0;
130 fEuclidOut = 0;
131 fIdN = 0;
132 fIdName = 0;
133 fIdSens = 0;
6c854497 134 fITSmodules = 0;
3bd79107 135 //
136 fDetTypes = 0;
137 SetNDetTypes();
138 //
139 fDtype = 0;
140 fNdtype = 0;
141 fCtype = 0;
142 fNctype = 0;
143 fRecPoints = 0;
144 fNRecPoints = 0;
145 //
146 fITSgeom=0;
fe4da5cc 147}
3bd79107 148
fe4da5cc 149//_____________________________________________________________________________
58005f18 150AliITS::AliITS(const char *name, const char *title):AliDetector(name,title){
fe4da5cc 151 //
152 // Default initialiser for ITS
58005f18 153 // The constructor of the AliITS class. In addition to creating the
154 // AliITS class, it allocates memory for the TClonesArrays fHits and
155 // fDigits, and for the TObjArray fITSpoints. It also zeros the variables
156 // fIshunt (a member of AliDetector class), fEuclidOut, and fIdN, and zeros
157 // the pointers fIdSens and fIdName. To help in displaying hits via the ROOT
158 // macro display.C AliITS also sets the marker color to red. The variables
159 // passes with this constructor, const char *name and *title, are used by
160 // the constructor of AliDetector class. See AliDetector class for a
161 // description of these parameters and its constructor functions.
fe4da5cc 162 //
58005f18 163
164 fHits = new TClonesArray("AliITShit", 1560);
1cedd08a 165 gAlice->AddHitList(fHits);
3bd79107 166
167 SetNDetTypes();
168
169 fNdtype = 0;
170 fDtype = 0;
171 fCtype = 0;
172 fNctype = 0;
173
174 fRecPoints = 0;
175 fNRecPoints = 0;
176
177
178 fITSmodules = 0;
58005f18 179
180 fIshunt = 0;
181 fEuclidOut = 0;
182 fIdN = 0;
183 fIdName = 0;
184 fIdSens = 0;
3bd79107 185
186 fDetTypes = new TObjArray(fNDetTypes);
187
188 Int_t i;
189 for(i=0;i<fNDetTypes;i++) {
190 (*fDetTypes)[i]=new AliITSDetType();
191 }
192 //
58005f18 193
fe4da5cc 194 SetMarkerColor(kRed);
58005f18 195
3bd79107 196 fITSgeom=0;
197}
198//___________________________________________________________________________
199AliITS::AliITS(AliITS &source){
200 if(this==&source) return;
201 printf("Error: You are not allowed to make a copy of the AliITS\n");
202 exit(1);
fe4da5cc 203}
3bd79107 204//____________________________________________________________________________
205AliITS& AliITS::operator=(AliITS &source){
206 if(this==&source) return *this;
207 printf("Error: You are not allowed to make a copy of the AliITS\n");
208 exit(1);
209}
210//____________________________________________________________________________
211void AliITS::ClearModules(){
212 //clear the modules TObjArray
213 Int_t i;
214
215 if(fITSmodules!=0) {
216 Int_t indSPD = fITSgeom->GetModuleIndex(2,fITSgeom->GetNladders(2),
217 fITSgeom->GetNdetectors(2));
218 Int_t indSDD = fITSgeom->GetModuleIndex(4,fITSgeom->GetNladders(4),
219 fITSgeom->GetNdetectors(4));
220 for(i=0;i<fITSmodules->GetEntriesFast();i++){
221 if(i<indSPD)
222 delete (AliITSmodule *) fITSmodules->At(i);
223 else if(i<indSDD)
224 delete (AliITSmodule *) fITSmodules->At(i);
225 else
226 delete (AliITSmodule *) fITSmodules->At(i);
227 } // end for i
228 }// end if fITSmodules!=0
fe4da5cc 229
3bd79107 230}
fe4da5cc 231//_____________________________________________________________________________
58005f18 232AliITS::~AliITS(){
fe4da5cc 233 //
234 // Default distructor for ITS
58005f18 235 // The default destructor of the AliITS class. In addition to deleting
236 // the AliITS class it deletes the memory pointed to by the fHits, fDigits,
237 // fIdSens, fIdName, and fITSpoints.
fe4da5cc 238 //
3bd79107 239
240
fe4da5cc 241 delete fHits;
242 delete fDigits;
3bd79107 243 delete fRecPoints;
58005f18 244 if(fIdName!=0) delete[] fIdName;
245 if(fIdSens!=0) delete[] fIdSens;
3bd79107 246 if(fITSmodules!=0) {
247 this->ClearModules();
248 delete fITSmodules;
249 }// end if fITSmodules!=0
fe4da5cc 250
fe4da5cc 251 //
3bd79107 252 Int_t i;
253 if(fDtype) {
254 for(i=0;i<fNDetTypes;i++) {
255 delete (*fDtype)[i];
256 fNdtype[i]=0;
257 }
258 }
259
260 for(i=0;i<fNDetTypes;i++) {
261 delete (*fCtype)[i];
262 fNctype[i]=0;
263 }
264
fe4da5cc 265 //
3bd79107 266
267 if (fDetTypes) {
268 fDetTypes->Delete();
269 delete fDetTypes;
270 }
271
272 if (fTreeC) delete fTreeC;
273
274}
275
276//___________________________________________
277AliITSDetType* AliITS::DetType(Int_t id)
278{
279 //return pointer to id detector type
280 return ((AliITSDetType*) (*fDetTypes)[id]);
281
282}
283//___________________________________________
284void AliITS::SetClasses(Int_t id, TString digit, TString cluster)
285{
286 //set the digit and cluster classes to be used for the id detector type
287 ((AliITSDetType*) (*fDetTypes)[id])->ClassNames(digit,cluster);
288
289}
290//___________________________________________
291void AliITS::SetResponseModel(Int_t id, AliITSresponse *response)
292{
293 //set the response model for the id detector type
294
295 ((AliITSDetType*) (*fDetTypes)[id])->ResponseModel(response);
296
fe4da5cc 297}
298
3bd79107 299//___________________________________________
300void AliITS::SetSegmentationModel(Int_t id, AliITSsegmentation *seg)
301{
302 //set the segmentation model for the id detector type
303
304 ((AliITSDetType*) (*fDetTypes)[id])->SegmentationModel(seg);
305
306}
307
308//___________________________________________
309void AliITS::SetSimulationModel(Int_t id, AliITSsimulation *sim)
310{
311 //set the simulation model for the id detector type
312
313 ((AliITSDetType*) (*fDetTypes)[id])->SimulationModel(sim);
314
315}
316//___________________________________________
317void AliITS::SetReconstructionModel(Int_t id, AliITSClusterFinder *reconst)
318{
319 //set the cluster finder model for the id detector type
320
321 ((AliITSDetType*) (*fDetTypes)[id])->ReconstructionModel(reconst);
58005f18 322
58005f18 323}
324
fe4da5cc 325//_____________________________________________________________________________
58005f18 326void AliITS::AddHit(Int_t track, Int_t *vol, Float_t *hits){
fe4da5cc 327 //
328 // Add an ITS hit
58005f18 329 // The function to add information to the AliITShit class. See the
330 // AliITShit class for a full description. This function allocates the
331 // necessary new space for the hit information and passes the variable
332 // track, and the pointers *vol and *hits to the AliITShit constructor
333 // function.
fe4da5cc 334 //
335 TClonesArray &lhits = *fHits;
336 new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
337}
3bd79107 338//_____________________________________________________________________________
339void AliITS::AddRealDigit(Int_t id, Int_t *digits)
340{
341 // add a real digit - as coming from data
342
343 TClonesArray &ldigits = *((TClonesArray*)(*fDtype)[id]);
344 new(ldigits[fNdtype[id]++]) AliITSdigit(digits);
345
346}
347//_____________________________________________________________________________
348void AliITS::AddDigit(Int_t id, AliITSdigit *d)
349{
350
351 // add a simulated digit
352
353 // should have ctors of type AliITSdigitSDD(const AliITSdigitSDD &)
354
355 TClonesArray &ldigits = *((TClonesArray*)(*fDtype)[id]);
356
357 switch(id)
358 {
359 case 0:
360 new(ldigits[fNdtype[id]++]) AliITSdigitSPD(*((AliITSdigitSPD*)d));
361 break;
362 case 1:
363 new(ldigits[fNdtype[id]++]) AliITSdigitSDD(*((AliITSdigitSDD*)d));
364 break;
365 case 2:
366 new(ldigits[fNdtype[id]++]) AliITSdigitSSD(*((AliITSdigitSSD*)d));
367 break;
368 }
369
370}
371
372//_____________________________________________________________________________
373void AliITS::AddDigit(Int_t id,Float_t phys,Int_t *digits,Int_t *tracks,Float_t *charges){
374
375 // add a simulated digit to the list
376
377 TClonesArray &ldigits = *((TClonesArray*)(*fDtype)[id]);
378 switch(id)
379 {
380 case 0:
381 new(ldigits[fNdtype[id]++]) AliITSdigitSPD(digits,tracks);
382 break;
383 case 1:
384 new(ldigits[fNdtype[id]++]) AliITSdigitSDD(phys,digits,tracks,charges);
385 break;
386 case 2:
387 new(ldigits[fNdtype[id]++]) AliITSdigitSSD(digits,tracks);
388 break;
389 }
390
391}
392
393//_____________________________________________________________________________
394void AliITS::AddCluster(Int_t id, AliITSRawCluster *c)
395{
396
397 // add a cluster to the list
398
399 // should have ctors of type AliITSRawClusterSDD(const AliITSRawClusterSDD &)
400
401 TClonesArray &lcl = *((TClonesArray*)(*fCtype)[id]);
402
403 switch(id)
404 {
405 case 0:
406 new(lcl[fNctype[id]++]) AliITSRawClusterSPD(*((AliITSRawClusterSPD*)c));
407 break;
408 case 1:
409 new(lcl[fNctype[id]++]) AliITSRawClusterSDD(*((AliITSRawClusterSDD*)c));
410 break;
411 case 2:
412 new(lcl[fNctype[id]++]) AliITSRawClusterSSD(*((AliITSRawClusterSSD*)c));
413 break;
414 }
415
416}
417
418
419//_____________________________________________________________________________
420void AliITS::AddRecPoint(const AliITSRecPoint &r)
421{
422 //
423 // Add a reconstructed space point to the list
424 //
425 TClonesArray &lrecp = *fRecPoints;
426 new(lrecp[fNRecPoints++]) AliITSRecPoint(r);
427}
428
429
430//____________________________________________
431void AliITS::ResetDigits()
432{
433 //
434 // Reset number of digits and the digits array for thE ITS detector
435 //
436
437 if (!fDtype) return;
438
439 Int_t i;
440 for(i=0;i<fNDetTypes;i++ ) {
441 if ((*fDtype)[i]) ((TClonesArray*)(*fDtype)[i])->Clear();
442 if (fNdtype) fNdtype[i]=0;
443 }
444}
445
446//____________________________________________
447void AliITS::ResetDigits(Int_t i)
448{
449 //
450 // Reset number of digits and the digits array for this branch
451 //
452 if ((*fDtype)[i]) ((TClonesArray*)(*fDtype)[i])->Clear();
453 if (fNdtype) fNdtype[i]=0;
454
455}
456//____________________________________________
457void AliITS::ResetClusters()
458{
459 //
460 // Reset number of clusters and the clusters array for ITS
461 //
462
463 Int_t i;
464 for(i=0;i<fNDetTypes;i++ ) {
465 if ((*fCtype)[i]) ((TClonesArray*)(*fCtype)[i])->Clear();
466 if (fNctype) fNctype[i]=0;
467 }
468
469}
470//____________________________________________
471void AliITS::ResetClusters(Int_t i)
472{
473 //
474 // Reset number of clusters and the clusters array for this branch
475 //
476 if ((*fCtype)[i]) ((TClonesArray*)(*fCtype)[i])->Clear();
477 if (fNctype) fNctype[i]=0;
478
479}
480
481
482//____________________________________________
483void AliITS::ResetRecPoints()
484{
485 //
486 // Reset number of rec points and the rec points array
487 //
488 fNRecPoints = 0;
489 if (fRecPoints) fRecPoints->Clear();
490
491}
492
fe4da5cc 493//_____________________________________________________________________________
58005f18 494Int_t AliITS::DistancetoPrimitive(Int_t , Int_t ){
fe4da5cc 495 //
496 // Distance from mouse to ITS on the screen. Dummy routine
58005f18 497 // A dummy routine used by the ROOT macro display.C to allow for the
498 // use of the mouse (pointing device) in the macro. In general this should
499 // never be called. If it is it returns the number 9999 for any value of
500 // x and y.
fe4da5cc 501 //
502 return 9999;
503}
504
505//_____________________________________________________________________________
58005f18 506void AliITS::Init(){
fe4da5cc 507 //
508 // Initialise ITS after it has been built
58005f18 509 // This routine initializes the AliITS class. It is intended to be called
510 // from the Init function in AliITSv?. Besides displaying a banner
3bd79107 511 // indicating that it has been called it initializes the array fIdSens
512 // and sets the default segmentation, response, digit and raw cluster classes
58005f18 513 // Therefore it should be called after a call to CreateGeometry.
fe4da5cc 514 //
3bd79107 515
516
517 SetDefaults();
518
fe4da5cc 519 Int_t i;
3bd79107 520
fe4da5cc 521 printf("\n");
522 for(i=0;i<35;i++) printf("*");
523 printf(" ITS_INIT ");
524 for(i=0;i<35;i++) printf("*");
525 printf("\n");
526 //
527 //
58005f18 528 for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
fe4da5cc 529 //
530 for(i=0;i<80;i++) printf("*");
531 printf("\n");
532}
533
3bd79107 534//_____________________________________________________________________________
535void AliITS::SetDefaults()
536{
537 // sets the default segmentation, response, digit and raw cluster classes
538
539
540 AliITSDetType *iDetType;
541
542 //SPD
543
544 AliITSsegmentationSPD *seg0=new AliITSsegmentationSPD(fITSgeom);
545 AliITSresponseSPD *resp0=new AliITSresponseSPD();
546 iDetType=DetType(0);
547 if (!iDetType->GetSegmentationModel()) SetSegmentationModel(0,seg0);
548 if (!iDetType->GetResponseModel()) SetResponseModel(0,resp0);
549 // set digit and raw cluster classes to be used
550 const char *kData=resp0->DataType();
551 if (strstr(kData,"real")) {
552 iDetType->ClassNames("AliITSdigit","AliITSRawClusterSPD");
553 } else iDetType->ClassNames("AliITSdigitSPD","AliITSRawClusterSPD");
554
555 // SDD //
556 AliITSresponseSDD *resp1=new AliITSresponseSDD();
557 AliITSsegmentationSDD *seg1=new AliITSsegmentationSDD(fITSgeom,resp1);
558 iDetType=DetType(1);
559 if (!iDetType->GetSegmentationModel()) SetSegmentationModel(1,seg1);
560 if (!iDetType->GetResponseModel()) SetResponseModel(1,resp1);
561 kData=resp1->DataType();
562 Option_t *opt=resp1->ZeroSuppOption();
563 if ((!strstr(opt,"2D")) && (!strstr(opt,"1D")) || strstr(kData,"real") ) {
564 iDetType->ClassNames("AliITSdigit","AliITSRawClusterSDD");
565 } else iDetType->ClassNames("AliITSdigitSDD","AliITSRawClusterSDD");
566
567 // SSD
568 AliITSsegmentationSSD *seg2=new AliITSsegmentationSSD(fITSgeom);
569 AliITSresponseSSD *resp2=new AliITSresponseSSD();
570 iDetType=DetType(2);
571 if (!iDetType->GetSegmentationModel()) SetSegmentationModel(2,seg2);
572 if (!iDetType->GetResponseModel()) SetResponseModel(2,resp2);
573 kData=resp2->DataType();
574 if (strstr(kData,"real")) {
575 iDetType->ClassNames("AliITSdigit","AliITSRawClusterSSD");
576 } else iDetType->ClassNames("AliITSdigitSSD","AliITSRawClusterSSD");
577
578 if (fNDetTypes>3) {
579 Warning("SetDefaults","Only the three basic detector types are initialised!");
580 }
581
582}
583
584
585//_____________________________________________________________________________
586
587void AliITS::MakeTreeC(Option_t *option)
588{
589 // create a separate tree to store the clusters
590
591 char *optC = strstr(option,"C");
592 if (optC && !fTreeC) fTreeC = new TTree("TC","Clusters in ITS");
593
594 Int_t buffersize = 4000;
595 char branchname[30];
596
597 char *det[3] = {"SPD","SDD","SSD"};
598
599 // one branch for Clusters per type of detector
600 Int_t i;
601 for(i=0; i<fNDetTypes ;i++) {
602 if (fNDetTypes==3) sprintf(branchname,"%sClusters%s",GetName(),det[i]);
603 else sprintf(branchname,"%sClusters%d",GetName(),i+1);
604 if (fCtype && fTreeC) {
605 TreeC()->Branch(branchname,&((*fCtype)[i]), buffersize);
606 printf("Making Branch %s for Clusters of detector type %d\n",branchname,i+1);
607 }
608 }
609
610}
611
612//_____________________________________________________________________________
613void AliITS::GetTreeC(Int_t event)
614{
615
616 // get the clusters tree for this event and set the branch address
617 char treeName[20];
618 char branchname[30];
619
620 char *det[3] = {"SPD","SDD","SSD"};
621
622 ResetClusters();
623 if (fTreeC) {
624 delete fTreeC;
625 }
626
627 sprintf(treeName,"TreeC%d",event);
628 fTreeC = (TTree*)gDirectory->Get(treeName);
629
630
631 TBranch *branch;
632 if (fTreeC) {
633 Int_t i;
634 for(i=0; i<fNDetTypes; i++) {
635 if (fNDetTypes==3) sprintf(branchname,"%sClusters%s",GetName(),det[i]);
636 else sprintf(branchname,"%sClusters%d",GetName(),i+1);
637 if (fCtype) {
638 branch = fTreeC->GetBranch(branchname);
639 if (branch) branch->SetAddress(&((*fCtype)[i]));
640 }
641 }
642 } else {
643 printf("ERROR: cannot find Clusters Tree for event:%d\n",event);
644 }
645
646}
fe4da5cc 647//_____________________________________________________________________________
58005f18 648void AliITS::MakeBranch(Option_t* option){
fe4da5cc 649 //
3bd79107 650 // Creates Tree branches for the ITS.
fe4da5cc 651 //
3bd79107 652
653
fe4da5cc 654 Int_t buffersize = 4000;
3bd79107 655 char branchname[30];
fe4da5cc 656 sprintf(branchname,"%s",GetName());
657
658 AliDetector::MakeBranch(option);
659
fe4da5cc 660
3bd79107 661// one branch for digits per type of detector
662
663 char *det[3] = {"SPD","SDD","SSD"};
664
665 fNdtype = new Int_t[fNDetTypes];
666 fDtype = new TObjArray(fNDetTypes);
667
668 fNctype = new Int_t[fNDetTypes];
669 fCtype = new TObjArray(fNDetTypes);
670
671 const char *kDigclass;
672 const char *kClclass;
673
674 Int_t i;
675 for(i=0; i<fNDetTypes ;i++) {
676 AliITSDetType *iDetType=DetType(i);
677 iDetType->GetClassNames(kDigclass,kClclass);
678 //printf("i, digclass, recclass %d %s %s\n",i,kDigclass,kClclass);
679 // digits
680 (*fDtype)[i] = new TClonesArray(kDigclass,100);
681 fNdtype[i]=0;
682 // clusters
683 (*fCtype)[i] = new TClonesArray(kClclass,100);
684 fNctype[i]=0;
685 }
686
687
688 for(i=0; i<fNDetTypes ;i++) {
689 if (fNDetTypes==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
690 else sprintf(branchname,"%sDigits%d",GetName(),i+1);
691
692 if (fDtype && gAlice->TreeD()) {
693 gAlice->TreeD()->Branch(branchname,&((*fDtype)[i]), buffersize);
694 printf("Making Branch %s for digits of type %d\n",branchname,i+1);
695 }
696 }
697
698 // only one branch for rec points for all detector types
699 sprintf(branchname,"%sRecPoints",GetName());
700
701 fRecPoints=new TClonesArray("AliITSRecPoint",1000);
702
703 if (fRecPoints && gAlice->TreeR()) {
704 gAlice->TreeR()->Branch(branchname,&fRecPoints, buffersize);
705 printf("Making Branch %s for reconstructed space points\n",branchname);
706 }
707
708
709}
710
711//___________________________________________
712void AliITS::SetTreeAddress()
713{
714
715 // Set branch address for the Trees.
716
717 char branchname[30];
718 AliDetector::SetTreeAddress();
719
720 char *det[3] = {"SPD","SDD","SSD"};
721
722 TBranch *branch;
723 TTree *treeD = gAlice->TreeD();
724 TTree *treeR = gAlice->TreeR();
725
726 Int_t i;
727 if (treeD) {
728 for(i=0; i<fNDetTypes; i++) {
729 if (fNDetTypes==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
730 else sprintf(branchname,"%sDigits%d",GetName(),i+1);
731 if (fDtype) {
732 branch = treeD->GetBranch(branchname);
733 if (branch) branch->SetAddress(&((*fDtype)[i]));
734 }
735 }
736 }
737
738
739 if (treeR) {
740 sprintf(branchname,"%sRecPoints",GetName());
741 if (fRecPoints) {
742 branch = treeR->GetBranch(branchname);
743 if (branch) branch->SetAddress(&fRecPoints);
744 }
745 }
746
747
748}
749
750//____________________________________________________________________________
751void AliITS::InitModules(Int_t size,Int_t &nmodules){
752
753 //initialize the modules array
754
755 Int_t nl,indexMAX,index;
756 Int_t indSPD,indSDD;
757
758 if(size<=0){ // default to using data stored in AliITSgeom
759 if(fITSgeom==0) {
760 printf("Error in AliITS::InitModule fITSgeom not defined\n");
761 return;
762 } // end if fITSgeom==0
763 nl = fITSgeom->GetNlayers();
764 indexMAX = fITSgeom->GetModuleIndex(nl,fITSgeom->GetNladders(nl),
765 fITSgeom->GetNdetectors(nl))+1;
766 nmodules = indexMAX;
767 fITSmodules = new TObjArray(indexMAX);
768 indSPD = fITSgeom->GetModuleIndex(2,fITSgeom->GetNladders(2),
769 fITSgeom->GetNdetectors(2));
770 indSDD = fITSgeom->GetModuleIndex(4,fITSgeom->GetNladders(4),
771 fITSgeom->GetNdetectors(4));
772 for(index=0;index<indexMAX;index++){
773 if(index<=indSPD)
774 fITSmodules->AddAt( new AliITSmodule(index),index);
775 else if(index<=indSDD)
776 fITSmodules->AddAt( new AliITSmodule(index),index);
777 else
778 fITSmodules->AddAt( new AliITSmodule(index),index);
779 } // end for index
780 }else{
781 fITSmodules = new TObjArray(size);
782 nmodules = size;
783 } // end i size<=0
784}
785
786//____________________________________________________________________________
787void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t lastev,Int_t nmodules,Option_t *option,Text_t *filename){
788
789 // fill the modules with the sorted by module hits; add hits from background
790 // if option=Add
791
792 static TTree *trH1; //Tree with background hits
793 static TClonesArray *fHits2; //List of hits for one track only
794
795 static Bool_t first=kTRUE;
796 static TFile *file;
797 char *add = strstr(option,"Add");
798
799
800 if (add ) {
801 if(first) {
802 cout<<"filename "<<filename<<endl;
803 file=new TFile(filename);
804 cout<<"I have opened "<<filename<<" file "<<endl;
805 fHits2 = new TClonesArray("AliITShit",1000 );
806 }
807 first=kFALSE;
808 file->cd();
809 file->ls();
810 // Get Hits Tree header from file
811 if(fHits2) fHits2->Clear();
812 if(trH1) delete trH1;
813 trH1=0;
814
815 char treeName[20];
816 sprintf(treeName,"TreeH%d",bgrev);
817 trH1 = (TTree*)gDirectory->Get(treeName);
818 //printf("TrH1 %p of treename %s for event %d \n",trH1,treeName,bgrev);
819
820 if (!trH1) {
821 printf("ERROR: cannot find Hits Tree for event:%d\n",bgrev);
822 }
823 // Set branch addresses
824 TBranch *branch;
825 char branchname[20];
826 sprintf(branchname,"%s",GetName());
827 if (trH1 && fHits2) {
828 branch = trH1->GetBranch(branchname);
829 if (branch) branch->SetAddress(&fHits2);
830 }
831
832 // test
833 //Int_t ntracks1 =(Int_t)TrH1->GetEntries();
834 //printf("background - ntracks1 - %d\n",ntracks1);
835 }
836
837 // store temporarily coordinates of signal particles - see where delete
838 static Int_t *signal;
839 if(!signal) signal=new Int_t[nmodules];
840 memset(signal,0,sizeof(int)*nmodules);
841 Float_t xhit[nmodules][4];
842 Float_t yhit[nmodules][4];
843
844 Int_t npart = gAlice->GetEvent(evnt);
845 if(npart<=0) return;
846 TClonesArray *itsHits = this->Hits();
847 Int_t lay,lad,det,index;
848 AliITShit *itsHit=0;
849 AliITSmodule *mod=0;
850
851 TTree *iTH = gAlice->TreeH();
852 Int_t ntracks =(Int_t) iTH->GetEntries();
853
854 Int_t t,h;
855 for(t=0; t<ntracks; t++){
856 gAlice->ResetHits();
857 iTH->GetEvent(t);
858 Int_t nhits = itsHits->GetEntriesFast();
859 if (!nhits) continue;
860 // cout << nhits << " hits in track " << t << endl;
861 for(h=0; h<nhits; h++){
862 itsHit = (AliITShit *)itsHits->UncheckedAt(h);
863 itsHit->GetDetectorID(lay,lad,det);
864 index = fITSgeom->GetModuleIndex(lay,lad,det);
865 mod = this->GetModule(index);
866 if (add) {
867 xhit[index][signal[index]]=itsHit->fX;
868 yhit[index][signal[index]]=itsHit->fY;
869 signal[index]++;
870 if (signal[index] >4)
871 printf("index,nsignal %d %d\n",index,signal[index]);
872 }
873 if(lay == 1 || lay == 2)
874 mod->AddHit((AliITShit *) itsHit,t,h);
875 else if(lay == 3 || lay == 4)
876 mod->AddHit((AliITShit *) itsHit,t,h);
877 else if(lay == 5 || lay ==6)
878 mod->AddHit((AliITShit *)itsHit,t,h);
879 else
880 mod->AddHit(itsHit,t,h);
881
882 } // end loop over hits
883 } // end loop over tracks
884
885 // open the file with background
886
887 if (add ) {
888 Int_t track,i,isig;
889 ntracks =(Int_t)trH1->GetEntries();
890 //printf("background - ntracks1 %d\n",ntracks);
891 //printf("background - Start loop over tracks \n");
892 // Loop over tracks
893
894 for(track=0; track<ntracks; track++) {
895
896 if (fHits2) fHits2->Clear();
897 trH1->GetEvent(track);
898 // Loop over hits
899 for(i=0;i<fHits2->GetEntriesFast();++i) {
900
901 itsHit=(AliITShit*) (*fHits2)[i];
902 itsHit->GetDetectorID(lay,lad,det);
903 index = fITSgeom->GetModuleIndex(lay,lad,det);
904 mod = this->GetModule(index);
905
906 Float_t xbgr=itsHit->fX;
907 Float_t ybgr=itsHit->fY;
908 Float_t ebgr=itsHit->GetIonization();
909 Bool_t cond=kFALSE;
910
911 for(isig =0; isig < signal[index]; isig++) {
912 Float_t dist=
913 (xbgr-xhit[index][isig])*(xbgr-xhit[index][isig])
914 +(ybgr-yhit[index][isig])*(ybgr-yhit[index][isig]);
915 if (dist<0.2&& ebgr!=0) cond=kTRUE; // check this number for ITS!
916 }
917 if (!cond) continue;
918 if(lay == 1 || lay == 2)
919 mod->AddHit((AliITShit *) itsHit,track,i);
920 else if(lay == 3 || lay == 4)
921 mod->AddHit((AliITShit *) itsHit,track,i);
922 else if(lay == 5 || lay ==6)
923 mod->AddHit((AliITShit *)itsHit,track,i);
924 else
925 mod->AddHit(itsHit,track,i);
926
927
928 } // end loop over hits
929 } // end loop over tracks
930
931 TTree *fAli=gAlice->TreeK();
932 TFile *fileAli=0;
933
934 if (fAli) fileAli =fAli->GetCurrentFile();
935 //printf("fAli, file %p %p\n",fAli,file);
936 file->cd();
937
938 } // end if add
939
940 //if (evnt==lastev) {delete [] signal; delete signal;}
941
942 //gObjectTable->Print();
943
944}
945
946
947//____________________________________________________________________________
948void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t lastev,Int_t size,
949Option_t *option,Option_t *opt,Text_t *filename)
950{
951 // keep galice.root for signal and name differently the file for
952 // background when add! otherwise the track info for signal will be lost !
953
954 char *all = strstr(opt,"All");
955 char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),strstr(opt,"SSD")};
956 //printf("Det 1 2 3 %s %s %s \n",det[0],det[1],det[2]);
957
958 Int_t nmodules;
959 InitModules(size,nmodules);
960 FillModules(evNumber,bgrev,lastev,nmodules,option,filename);
961 //printf("nmodules %d\n",nmodules);
962
963 TBranch *branch;
964 AliITSsimulation* sim;
965
966 TObjArray *branches=gAlice->TreeD()->GetListOfBranches();
967 AliITSgeom *geom = GetITSgeom();
968
969 Int_t id,module;
970 for(id=0;id<3;id++) {
971 //printf("id %d All %s det[id] %s \n",id,all,det[id]);
972 if (!all && !det[id]) continue;
973 branch = (TBranch*)branches->UncheckedAt(id);
974 AliITSDetType *iDetType=DetType(id);
975 sim = (AliITSsimulation*)iDetType->GetSimulationModel();
976 if (!sim) {
977 Error("HitsToDigits","The simulation class was not instantiated!");
978 exit(1);
979 // or SetDefaultSimulation(id,iDetType*);
980 }
981 Int_t first = geom->GetStartDet(id);
982 Int_t last = geom->GetLastDet(id);
983 //printf("det type %d first, last %d %d \n",id,first,last);
984 for(module=first;module<=last;module++) {
985 AliITSmodule *mod = (AliITSmodule *)fITSmodules->At(module);
986 sim->DigitiseModule(mod,module,evNumber);
987 // fills all branches - wasted disk space
988 gAlice->TreeD()->Fill();
989 ResetDigits();
990 // try and fill only the branch
991 //branch->Fill();
992 //ResetDigits(id);
993 } // loop over modules
994 } // loop over detector types
995
996
997 ClearModules();
998
999 //Int_t nentries=(Int_t)gAlice->TreeD()->GetEntries();
1000
1001 char hname[30];
1002 sprintf(hname,"TreeD%d",evNumber);
1003 gAlice->TreeD()->Write(hname);
1004 // reset tree
1005 gAlice->TreeD()->Reset();
1006
1007}
1008
1009
1010//____________________________________________________________________________
1011void AliITS::DigitsToRecPoints(Int_t evNumber,Int_t lastentry,Option_t *opt)
1012{
1013
1014 char *all = strstr(opt,"All");
1015 char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),strstr(opt,"SSD")};
1016
1017 static Bool_t first=kTRUE;
1018 if (first) {
1019 MakeTreeC("C");
1020 first=kFALSE;
1021 }
1022 TTree *iTC=TreeC();
1023
1024 TBranch *branch;
1025 AliITSClusterFinder* rec;
1026
1027 TObjArray *branches=gAlice->TreeR()->GetListOfBranches();
1028 AliITSgeom *geom = GetITSgeom();
1029
1030 Int_t id,module;
1031 for(id=0;id<fNDetTypes;id++) {
1032 if (!all && !det[id]) continue;
1033 branch = (TBranch*)branches->UncheckedAt(id);
1034 AliITSDetType *iDetType=DetType(id);
1035 rec = (AliITSClusterFinder*)iDetType->GetReconstructionModel();
1036 if (!rec) {
1037 Error("DigitsToRecPoints","The cluster finder class was not instantiated!");
1038 exit(1);
1039 // or SetDefaultClusterFinder(id,iDetType*);
1040 }
1041 TClonesArray *itsDigits = this->DigitsAddress(id);
1042
1043 Int_t first = geom->GetStartDet(id);
1044 Int_t last = geom->GetLastDet(id);
1045 //printf("det type %d first, last %d %d \n",id,first,last);
1046 for(module=first;module<=last;module++) {
1047 //printf("AliITS: module=%d\n",module);
1048 this->ResetDigits();
1049 if (all) gAlice->TreeD()->GetEvent(lastentry+module);
1050 else gAlice->TreeD()->GetEvent(lastentry+(module-first));
1051 Int_t ndigits = itsDigits->GetEntriesFast();
1052 if (ndigits) rec->FindRawClusters();
1053 gAlice->TreeR()->Fill();
1054 ResetRecPoints();
1055 iTC->Fill();
1056 ResetClusters();
1057 // try and fill only the branch
1058 //branch->Fill();
1059 //ResetRecPoints(id);
1060 } // loop over modules
1061 } // loop over detector types
1062
1063
1064 //Int_t nentries=(Int_t)gAlice->TreeR()->GetEntries();
1065
1066 //Int_t ncentries=(Int_t)TC->GetEntries();
1067
1068 char hname[30];
1069 sprintf(hname,"TreeR%d",evNumber);
1070 gAlice->TreeR()->Write(hname);
1071 // reset tree
1072 gAlice->TreeR()->Reset();
1073
1074 sprintf(hname,"TreeC%d",evNumber);
1075 iTC->Write(hname);
1076 iTC->Reset();
1077}
1078
1079
1080//____________________________________________________________________________
1081void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t lastev,Int_t size,
1082Option_t *option,Option_t *opt,Text_t *filename)
1083{
1084 // keep galice.root for signal and name differently the file for
1085 // background when add! otherwise the track info for signal will be lost !
1086
1087 char *all = strstr(opt,"All");
1088 char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),strstr(opt,"SSD")};
1089
1090 Int_t nmodules;
1091 InitModules(size,nmodules);
1092 FillModules(evNumber,bgrev,lastev,nmodules,option,filename);
1093
1094 static AliITSsimulationFastPoints* sim=0;
1095 if (!sim) sim = new AliITSsimulationFastPoints();
1096
1097
1098 AliITSgeom *geom = GetITSgeom();
1099
1100 Int_t id,module;
1101 for(id=0;id<3;id++) {
1102 if (!all && !det[id]) continue;
1103 Int_t first = geom->GetStartDet(id);
1104 Int_t last = geom->GetLastDet(id);
1105 for(module=first;module<=last;module++) {
1106 AliITSmodule *mod = (AliITSmodule *)fITSmodules->At(module);
1107 sim->CreateFastRecPoints(mod);
1108 gAlice->TreeR()->Fill();
1109 ResetRecPoints();
1110 } // loop over modules
1111 } // loop over detector types
1112
1113
1114 ClearModules();
1115
1116 //Int_t nentries=(Int_t)gAlice->TreeR()->GetEntries();
1117
1118 char hname[30];
1119 sprintf(hname,"TreeR%d",evNumber);
1120 gAlice->TreeR()->Write(hname);
1121 // reset tree
1122 gAlice->TreeR()->Reset();
1123
fe4da5cc 1124}
1125
58005f18 1126//____________________________________________________________________________
1127void AliITS::Streamer(TBuffer &R__b){
1128 // Stream an object of class AliITS.
1129 Int_t i,j,l;
1130
3bd79107 1131 AliITSDetType *det;
1132 AliITSresponse *response;
1133 AliITSsegmentation *seg;
1134 TClonesArray *digitsaddress;
1135 TClonesArray *clustaddr;
1136
1137
58005f18 1138 if (R__b.IsReading()) {
1139 Version_t R__v = R__b.ReadVersion();
1140 if (R__v == 1) {
1141 AliDetector::Streamer(R__b);
1142 R__b >> fITSgeom;
58005f18 1143 R__b >> fEuclidOut;
1144 R__b >> fIdN;
1145 if(fIdSens!=0) delete[] fIdSens;
1146 if(fIdName!=0) delete[] fIdName;
1147 fIdSens = new Int_t[fIdN];
1148 fIdName = new char*[fIdN];
1149 for(i=0;i<fIdN;i++) R__b >> fIdSens[i];
1150 for(i=0;i<fIdN;i++){
1151 R__b >> l;
1152 fIdName[i] = new char[l+1]; // add room for null character.
1153 for(j=0;j<l;j++) R__b >> fIdName[i][j];
1154 fIdName[i][l] = '\0'; // Null terminate this string.
1155 } // end for i
1156 R__b >> fMajorVersion;
1157 R__b >> fMinorVersion;
3bd79107 1158 R__b >> fDtype;
1159 R__b.ReadArray(fNdtype);
1160 R__b >> fCtype;
1161 R__b.ReadArray(fNctype);
1162 R__b >> fDetTypes;
1163 R__b >> fNDetTypes;
1164 R__b >> fRecPoints;
1165 R__b >> fNRecPoints;
1166 // stream out only response and segmentation
1167 for(i=0;i<fNDetTypes;i++) {
1168 det=(AliITSDetType*)(*fDetTypes)[i];
1169 det->Streamer(R__b);
1170 response=det->GetResponseModel();
1171 if (response) response->Streamer(R__b);
1172 seg=det->GetSegmentationModel();
1173 if (seg) seg->Streamer(R__b);
1174 digitsaddress=(TClonesArray*) (*fDtype)[i];
1175 digitsaddress->Streamer(R__b);
1176 clustaddr=(TClonesArray*) (*fCtype)[i];
1177 clustaddr->Streamer(R__b);
1178 }
1179
58005f18 1180 } // end if (R__v)
1181 } else {
1182 R__b.WriteVersion(AliITS::IsA());
1183 AliDetector::Streamer(R__b);
1184 R__b << fITSgeom;
58005f18 1185 R__b << fEuclidOut;
1186 R__b << fIdN;
1187 for(i=0;i<fIdN;i++) R__b <<fIdSens[i];
1188 for(i=0;i<fIdN;i++){
1189 l = strlen(fIdName[i]);
1190 R__b << l;
1191 for(j=0;j<l;j++) R__b << fIdName[i][j];
1192 } // end for i
1193 R__b << fMajorVersion;
1194 R__b << fMinorVersion;
3bd79107 1195 R__b << fDtype;
1196 R__b.WriteArray(fNdtype, fNDetTypes);
1197 R__b << fCtype;
1198 R__b.WriteArray(fNctype, fNDetTypes);
1199 R__b << fDetTypes;
1200 R__b << fNDetTypes;
1201 R__b << fRecPoints;
1202 R__b << fNRecPoints;
1203 for(i=0;i<fNDetTypes;i++) {
1204 det=(AliITSDetType*)(*fDetTypes)[i];
1205 det->Streamer(R__b);
1206 response=det->GetResponseModel();
1207 if(response) response->Streamer(R__b);
1208 seg=det->GetSegmentationModel();
1209 if (seg) seg->Streamer(R__b);
1210 digitsaddress=(TClonesArray*) (*fDtype)[i];
1211 digitsaddress->Streamer(R__b);
1212 clustaddr=(TClonesArray*) (*fCtype)[i];
1213 clustaddr->Streamer(R__b);
1214 }
58005f18 1215 }
3bd79107 1216
1217
fe4da5cc 1218}
3bd79107 1219
1220ClassImp(AliITSRecPoint)
1221ClassImp(AliITSsegmentation)
1222ClassImp(AliITSresponse)
1223//ClassImp(AliITStrack)
1224