]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITS.cxx
Modifications associated with remerging the Ba/Sa and Dubna pixel simulations,
[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
88cb7938 16/* $Id$ */
2ab0c725 17
4c039060 18
fe4da5cc 19///////////////////////////////////////////////////////////////////////////////
58005f18 20//
21// An overview of the basic philosophy of the ITS code development
22// and analysis is show in the figure below.
fe4da5cc 23//Begin_Html
24/*
a92b2b7d 25<img src="picts/ITS/ITS_Analysis_schema.gif">
fe4da5cc 26</pre>
27<br clear=left>
28<font size=+2 color=red>
58005f18 29<p>Roberto Barbera is in charge of the ITS Offline code (1999).
fe4da5cc 30<a href="mailto:roberto.barbera@ct.infn.it">Roberto Barbera</a>.
31</font>
32<pre>
33*/
34//End_Html
58005f18 35//
36// AliITS. Inner Traking System base class.
37// This class contains the base procedures for the Inner Tracking System
38//
39//Begin_Html
40/*
a92b2b7d 41<img src="picts/ITS/AliITS_Class_Diagram.gif">
58005f18 42</pre>
43<br clear=left>
44<font size=+2 color=red>
45<p>This show the class diagram of the different elements that are part of
46the AliITS class.
47</font>
48<pre>
49*/
50//End_Html
51//
52// Version: 0
53// Written by Rene Brun, Federico Carminati, and Roberto Barbera
54//
55// Version: 1
56// Modified and documented by Bjorn S. Nilsen
57// July 11 1999
58//
3bd79107 59// Version: 2
60// Modified and documented by A. Bologna
61// October 18 1999
62//
58005f18 63// AliITS is the general base class for the ITS. Also see AliDetector for
64// futher information.
65//
fe4da5cc 66///////////////////////////////////////////////////////////////////////////////
88cb7938 67
4ae5bbc4 68#include <Riostream.h>
143d1056 69#include <stdlib.h>
88cb7938 70
9c74c52b 71#include <TBranch.h>
caf37aec 72#include <TClonesArray.h>
9c74c52b 73#include <TFile.h>
88cb7938 74#include <TMath.h>
75#include <TObjectTable.h>
76#include <TROOT.h>
77#include <TRandom.h>
d5da1ecf 78#include <TString.h>
88cb7938 79#include <TTree.h>
80#include <TVector.h>
81#include <TVirtualMC.h>
3bd79107 82
88cb7938 83#include "AliConfig.h"
828e06c7 84#include "AliHeader.h"
3bd79107 85#include "AliITS.h"
88cb7938 86#include "AliITSClusterFinderSDD.h"
87#include "AliITSClusterFinderSPD.h"
88#include "AliITSClusterFinderSSD.h"
e8189707 89#include "AliITSDetType.h"
88cb7938 90#include "AliITSLoader.h"
41b19549 91#include "AliITSRawClusterSPD.h"
92#include "AliITSRawClusterSDD.h"
93#include "AliITSRawClusterSSD.h"
88cb7938 94#include "AliITSRecPoint.h"
e869281d 95#include "AliITSdigitSPD.h"
96#include "AliITSdigitSDD.h"
97#include "AliITSdigitSSD.h"
88cb7938 98#include "AliITSgeom.h"
99#include "AliITShit.h"
100#include "AliITSmodule.h"
101#include "AliITSpList.h"
3bd79107 102#include "AliITSresponseSDD.h"
88cb7938 103#include "AliITSresponseSPD.h"
3bd79107 104#include "AliITSresponseSSD.h"
828e06c7 105#include "AliITSsegmentationSDD.h"
88cb7938 106#include "AliITSsegmentationSPD.h"
828e06c7 107#include "AliITSsegmentationSSD.h"
828e06c7 108#include "AliITSsimulationSDD.h"
88cb7938 109#include "AliITSsimulationSPD.h"
828e06c7 110#include "AliITSsimulationSSD.h"
5d12ce38 111#include "AliMC.h"
85a5290f 112#include "AliITSDigitizer.h"
0421c3d1 113#include "AliITSDDLRawData.h"
8f726cb3 114#include "AliRun.h"
828e06c7 115
3bd79107 116ClassImp(AliITS)
3bd79107 117
2aea926d 118//______________________________________________________________________
e80bf2b3 119AliITS::AliITS() : AliDetector(),
120 fITSgeom(0),
121 fEuclidOut(0),
122 fITSmodules(0),
123 fOpt("All"),
124 fIdN(0),
125 fIdSens(0),
126 fIdName(0),
127 fNDetTypes(kNTYPES),
128 fDetTypes(0),
129 fSDigits(0),
130 fNSDigits(0),
131 fDtype(0),
132 fNdtype(0),
133 fCtype(0),
134 fNctype(0),
135 fRecPoints(0),
136 fNRecPoints(0),
137 fSelectedVertexer(0){
4a5bebc2 138 // Default initializer for ITS
2aea926d 139 // The default constructor of the AliITS class. In addition to
140 // creating the AliITS class it zeros the variables fIshunt (a member
141 // of AliDetector class), fEuclidOut, and fIdN, and zeros the pointers
142 // fITSpoints, fIdSens, and fIdName. The AliDetector default constructor
143 // is also called.
4a5bebc2 144 // Inputs:
145 // none.
146 // Outputs:
147 // none.
148 // Return:
149 // Blank ITS class.
3bd79107 150
2aea926d 151 fIshunt = 0; // not zeroed in AliDetector.
3bd79107 152
2aea926d 153 // AliITS variables.
aa044888 154// SetDetectors(); // default to fOpt="All". This variable not written out.
2aea926d 155 SetMarkerColor(kRed);
2257f27e 156 SelectVertexer(" ");
fe4da5cc 157}
2aea926d 158//______________________________________________________________________
e80bf2b3 159AliITS::AliITS(const char *name, const char *title):AliDetector(name,title),
160 fITSgeom(0),
161 fEuclidOut(0),
162 fITSmodules(0),
163 fOpt("All"),
164 fIdN(0),
165 fIdSens(0),
166 fIdName(0),
167 fNDetTypes(kNTYPES),
168 fDetTypes(0),
169 fSDigits(0),
170 fNSDigits(0),
171 fDtype(0),
172 fNdtype(0),
173 fCtype(0),
174 fNctype(0),
175 fRecPoints(0),
176 fNRecPoints(0),
177 fSelectedVertexer(0){
4a5bebc2 178 // The standard Constructor for the ITS class. In addition to
179 // creating the AliITS class, it allocates memory for the TClonesArrays
180 // fHits, fSDigits, fDigits, fITSpoints, and the TObjArray of fCtype
181 // (clusters). It also zeros the variables
2aea926d 182 // fIshunt (a member of AliDetector class), fEuclidOut, and fIdN, and zeros
183 // the pointers fIdSens and fIdName. To help in displaying hits via the
184 // ROOT macro display.C AliITS also sets the marker color to red. The
185 // variables passes with this constructor, const char *name and *title,
186 // are used by the constructor of AliDetector class. See AliDetector
187 // class for a description of these parameters and its constructor
188 // functions.
4a5bebc2 189 // Inputs:
190 // const char *name Detector name. Should always be "ITS"
191 // const char *title Detector title.
192 // Outputs:
193 // none.
194 // Return:
195 // An ITS class.
2aea926d 196
197 fIshunt = 0; // not zeroed in AliDetector
198 fHits = new TClonesArray("AliITShit", 1560);//not done in AliDetector
aacedc3e 199 // Not done in AliDetector.
200 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
2aea926d 201
202 fEuclidOut = 0;
203 fITSgeom = 0;
204 fITSmodules = 0;
cd77595e 205 SetDetectors(); // default to fOpt="All". This variable not written out.
2aea926d 206
207 fIdN = 0;
208 fIdName = 0;
209 fIdSens = 0;
210
211 fNDetTypes = kNTYPES;
212 fDetTypes = new TObjArray(fNDetTypes);
213
2aea926d 214 fSDigits = new TClonesArray("AliITSpListItem",1000);
215 fNSDigits = 0;
216
217 fNdtype = new Int_t[fNDetTypes];
218 fDtype = new TObjArray(fNDetTypes);
219
220 fCtype = new TObjArray(fNDetTypes);
221 fNctype = new Int_t[fNDetTypes];
2aea926d 222
223 fRecPoints = new TClonesArray("AliITSRecPoint",1000);
224 fNRecPoints = 0;
3bd79107 225
2aea926d 226 Int_t i;
227 for(i=0;i<fNDetTypes;i++) {
88cb7938 228 fDetTypes->AddAt(new AliITSDetType(),i);
229 fNdtype[i] = 0;
230 fNctype[i] = 0;
2aea926d 231 } // end for i
fe4da5cc 232
2aea926d 233 SetMarkerColor(kRed);
2257f27e 234 SelectVertexer(" ");
3bd79107 235}
2aea926d 236//______________________________________________________________________
58005f18 237AliITS::~AliITS(){
4a5bebc2 238 // Default destructor for ITS.
2aea926d 239 // The default destructor of the AliITS class. In addition to deleting
240 // the AliITS class it deletes the memory pointed to by the fHits, fDigits,
4a5bebc2 241 // fSDigits, fCtype, fITSmodules, fITSgeom, fRecPoints, fIdSens, fIdName,
242 // fITSpoints, fDetType and it's contents.
243 // Inputs:
244 // none.
245 // Outputs:
246 // none.
247 // Return:
248 // none.
2aea926d 249
88cb7938 250 if (fHits) {
251 fHits->Delete();
252 delete fHits;
253 fHits=0;
254 }
255 if (fSDigits) {
256 fSDigits->Delete();
257 delete fSDigits;
258 fSDigits=0;
259 }
260 if (fDigits) {
261 fDigits->Delete();
262 delete fDigits;
263 fDigits=0;
264 }
265 if (fRecPoints) {
266 fRecPoints->Delete();
267 delete fRecPoints;
268 fRecPoints=0;
269 }
270 delete[] fIdName; // Array of TStrings
271 delete[] fIdSens;
272 if(fITSmodules) {
273 this->ClearModules();
274 delete fITSmodules;
279a35d7 275 fITSmodules = 0;
88cb7938 276 }// end if fITSmodules!=0
277
278 if(fDtype) {
279 fDtype->Delete();
280 delete fDtype;
281 } // end if fDtype
282 delete [] fNdtype;
283 if (fCtype) {
284 fCtype->Delete();
285 delete fCtype;
286 fCtype = 0;
287 } // end if fCtype
288 delete [] fNctype;
289
290 if (fDetTypes) {
291 fDetTypes->Delete();
292 delete fDetTypes;
293 fDetTypes = 0;
294 } // end if fDetTypes
295
296
297 if (fITSgeom) delete fITSgeom;
3bd79107 298}
2aea926d 299//______________________________________________________________________
ac74f489 300AliITS::AliITS(const AliITS &source) : AliDetector(source){
4a5bebc2 301 // Copy constructor. This is a function which is not allowed to be
302 // done to the ITS. It exits with an error.
303 // Inputs:
304 // AliITS &source An AliITS class.
305 // Outputs:
306 // none.
307 // Return:
308 // none.
3bd79107 309
2aea926d 310 if(this==&source) return;
4a5bebc2 311 Error("Copy constructor",
88cb7938 312 "You are not allowed to make a copy of the AliITS");
2aea926d 313 exit(1);
3bd79107 314}
2aea926d 315//______________________________________________________________________
316AliITS& AliITS::operator=(AliITS &source){
4a5bebc2 317 // Assignment operator. This is a function which is not allowed to be
318 // done to the ITS. It exits with an error.
319 // Inputs:
320 // AliITS &source An AliITS class.
321 // Outputs:
322 // none.
323 // Return:
324 // none.
3bd79107 325
2aea926d 326 if(this==&source) return *this;
4a5bebc2 327 Error("operator=","You are not allowed to make a copy of the AliITS");
2aea926d 328 exit(1);
329 return *this; //fake return
3bd79107 330}
2aea926d 331//______________________________________________________________________
aacedc3e 332AliDigitizer* AliITS::CreateDigitizer(AliRunDigitizer* manager)const{
333 // Creates the AliITSDigitizer in a standard way for use via AliModule.
334 // This function can not be included in the .h file because of problems
335 // with the order of inclusion (recursive).
4a5bebc2 336 // Inputs:
aacedc3e 337 // AliRunDigitizer *manager The Manger class for Digitization
338 // Output:
339 // none.
4a5bebc2 340 // Return:
aacedc3e 341 // A new AliITSRunDigitizer (cast as a AliDigitizer).
3bd79107 342
aacedc3e 343 return new AliITSDigitizer(manager);
3bd79107 344}
2aea926d 345//______________________________________________________________________
346void AliITS::Init(){
4a5bebc2 347 // Initializer ITS after it has been built
2aea926d 348 // This routine initializes the AliITS class. It is intended to be
349 // called from the Init function in AliITSv?. Besides displaying a banner
350 // indicating that it has been called it initializes the array fIdSens
351 // and sets the default segmentation, response, digit and raw cluster
352 // classes therefore it should be called after a call to CreateGeometry.
4a5bebc2 353 // Inputs:
354 // none.
355 // Outputs:
356 // none.
357 // Return:
358 // none.
3bd79107 359 Int_t i;
3bd79107 360
2aea926d 361 SetDefaults();
362 // Array of TStrings
0e73d04c 363 if(gMC) for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
3bd79107 364}
2aea926d 365//______________________________________________________________________
366void AliITS::SetDefaults(){
4a5bebc2 367 // sets the default segmentation, response, digit and raw cluster classes.
368 // Inputs:
369 // none.
370 // Outputs:
371 // none.
372 // Return:
373 // none.
aacedc3e 374 AliITSsegmentation *seg;
375 AliITSresponse *resp;
2aea926d 376 AliITSDetType *iDetType;
377
aacedc3e 378 if(fDebug) Info("SetDefauls","%s: SetDefaults",ClassName());
379
2aea926d 380 //SPD
aacedc3e 381 iDetType = DetType(kSPD);
382 if(iDetType){
383 if (!iDetType->GetSegmentationModel()) {
384 seg = new AliITSsegmentationSPD(fITSgeom);
385 SetSegmentationModel(kSPD,seg);
386 } // end if
387 if (!iDetType->GetResponseModel()) {
388 SetResponseModel(kSPD,new AliITSresponseSPD());
389 } // end if
390 // set digit and raw cluster classes to be used
2aea926d 391
aacedc3e 392 const char *kData0=(iDetType->GetResponseModel())->DataType();
393 if (strstr(kData0,"real")) {
394 iDetType->ClassNames("AliITSdigit","AliITSRawClusterSPD");
395 } else iDetType->ClassNames("AliITSdigitSPD","AliITSRawClusterSPD");
396 } // end if iDetType
2aea926d 397
398 // SDD
aacedc3e 399 iDetType = DetType(kSDD);
400 if(iDetType){
401 if (!iDetType->GetResponseModel()) {
402 SetResponseModel(kSDD,new AliITSresponseSDD("simulated"));
403 } // end if
404 resp = iDetType->GetResponseModel();
405 if (!iDetType->GetSegmentationModel()) {
406 seg = new AliITSsegmentationSDD(fITSgeom,resp);
407 SetSegmentationModel(kSDD,seg);
408 } // end if
409 const char *kData1 = (iDetType->GetResponseModel())->DataType();
410 const char *kopt = iDetType->GetResponseModel()->ZeroSuppOption();
411 if((!strstr(kopt,"2D"))&&(!strstr(kopt,"1D")) ||
412 strstr(kData1,"real") ){
413 iDetType->ClassNames("AliITSdigit","AliITSRawClusterSDD");
414 } else iDetType->ClassNames("AliITSdigitSDD","AliITSRawClusterSDD");
415 } // end if iDetType
2aea926d 416
417 // SSD
aacedc3e 418 iDetType = DetType(kSSD);
419 if(iDetType){
420 if (!iDetType->GetSegmentationModel()) {
421 seg = new AliITSsegmentationSSD(fITSgeom);
422 SetSegmentationModel(kSSD,seg);
423 } // end if
424 if (!iDetType->GetResponseModel()) {
425 SetResponseModel(kSSD,new AliITSresponseSSD("simulated"));
426 } // end if
427 const char *kData2 = (iDetType->GetResponseModel())->DataType();
428 if (strstr(kData2,"real")) {
429 iDetType->ClassNames("AliITSdigit","AliITSRawClusterSSD");
430 } else iDetType->ClassNames("AliITSdigitSSD","AliITSRawClusterSSD");
431 } // end if iDetType
2aea926d 432
433 if (kNTYPES>3) {
88cb7938 434 Warning("SetDefaults",
435 "Only the three basic detector types are initialized!");
2aea926d 436 } // end if
3bd79107 437}
2aea926d 438//______________________________________________________________________
439void AliITS::SetDefaultSimulation(){
4a5bebc2 440 // sets the default simulation.
441 // Inputs:
442 // none.
443 // Outputs:
444 // none.
445 // Return:
446 // none.
2aea926d 447 AliITSDetType *iDetType;
54b8cf3b 448 AliITSsimulation *sim;
aacedc3e 449 AliITSsegmentation *seg;
450 AliITSresponse *res;
451
452 iDetType = DetType(kSPD);
453 if(iDetType){
454 sim = iDetType->GetSimulationModel();
455 if (!sim) {
456 seg = (AliITSsegmentation*)iDetType->GetSegmentationModel();
457 res = (AliITSresponse*)iDetType->GetResponseModel();
458 sim = new AliITSsimulationSPD(seg,res);
459 SetSimulationModel(kSPD,sim);
460 }else{ // simulation exists, make sure it is set up properly.
461 if(sim->GetResponseModel()==0) sim->SetResponseModel(
462 (AliITSresponse*)iDetType->GetResponseModel());
463 if(sim->GetSegmentationModel()==0) sim->SetSegmentationModel(
464 (AliITSsegmentation*)iDetType->GetSegmentationModel());
465 sim->Init();
466 } // end if
467 }// end if iDetType
468 iDetType = DetType(kSDD);
469 if(iDetType){
470 sim = iDetType->GetSimulationModel();
471 if (!sim) {
472 seg = (AliITSsegmentation*)iDetType->GetSegmentationModel();
473 res = (AliITSresponse*)iDetType->GetResponseModel();
474 sim = new AliITSsimulationSDD(seg,res);
475 SetSimulationModel(kSDD,sim);
476 }else{ // simulation exists, make sure it is set up properly.
477 if(sim->GetResponseModel()==0) sim->SetResponseModel(
478 (AliITSresponse*)iDetType->GetResponseModel());
479 if(sim->GetSegmentationModel()==0) sim->SetSegmentationModel(
480 (AliITSsegmentation*)iDetType->GetSegmentationModel());
481 sim->Init();
482 } //end if
483 }// end if iDetType
484 iDetType = DetType(kSSD);
485 if(iDetType){
486 sim = iDetType->GetSimulationModel();
487 if (!sim) {
488 seg =(AliITSsegmentation*)iDetType->GetSegmentationModel();
489 res = (AliITSresponse*)iDetType->GetResponseModel();
490 sim = new AliITSsimulationSSD(seg,res);
491 SetSimulationModel(kSSD,sim);
492 }else{ // simulation exists, make sure it is set up properly.
493 if(sim->GetResponseModel()==0) sim->SetResponseModel(
494 (AliITSresponse*)iDetType->GetResponseModel());
495 if(sim->GetSegmentationModel()==0) sim->SetSegmentationModel(
496 (AliITSsegmentation*)iDetType->GetSegmentationModel());
497 sim->Init();
498 } // end if
499 } // end if iDetType
3bd79107 500}
2aea926d 501//______________________________________________________________________
502void AliITS::SetDefaultClusterFinders(){
4a5bebc2 503 // Sets the default cluster finders. Used in finding RecPoints.
504 // Inputs:
505 // none.
506 // Outputs:
507 // none.
508 // Return:
509 // none.
aacedc3e 510 AliITSDetType *iDetType;
511 AliITSsegmentation *seg;
512 AliITSClusterFinder *clf;
513 AliITSresponse *res;
2aea926d 514
515 MakeTreeC();
2aea926d 516
517 // SPD
aacedc3e 518 iDetType=DetType(kSPD);
519 if(iDetType){
520 if (!iDetType->GetReconstructionModel()) {
521 seg =(AliITSsegmentation*)iDetType->GetSegmentationModel();
522 TClonesArray *dig0 = DigitsAddress(0);
523 TClonesArray *recp0 = ClustersAddress(0);
524 clf = new AliITSClusterFinderSPD(seg,dig0,recp0);
525 SetReconstructionModel(kSPD,clf);
526 } // end if
527 } // end if iDetType
2aea926d 528
529 // SDD
aacedc3e 530 iDetType=DetType(kSDD);
531 if(iDetType){
532 if (!iDetType->GetReconstructionModel()) {
533 seg = (AliITSsegmentation*)iDetType->GetSegmentationModel();
534 res = (AliITSresponse*)iDetType->GetResponseModel();
535 TClonesArray *dig1 = DigitsAddress(1);
536 TClonesArray *recp1 = ClustersAddress(1);
537 clf = new AliITSClusterFinderSDD(seg,res,dig1,recp1);
538 SetReconstructionModel(kSDD,clf);
539 } // end if
540 } // end if iDetType
2aea926d 541
542 // SSD
aacedc3e 543 iDetType=DetType(kSSD);
544 if(iDetType){
545 if (!iDetType->GetReconstructionModel()) {
546 seg = (AliITSsegmentation*)iDetType->GetSegmentationModel();
547 TClonesArray *dig2 = DigitsAddress(2);
548 clf = new AliITSClusterFinderSSD(seg,dig2);
549 SetReconstructionModel(kSSD,clf);
550 } // end if
551 } // end if iDetType
3bd79107 552}
2aea926d 553//______________________________________________________________________
88cb7938 554void AliITS::MakeBranch(Option_t* option){
2aea926d 555 // Creates Tree branches for the ITS.
4a5bebc2 556 // Inputs:
557 // Option_t *option String of Tree types S,D, and/or R.
558 // const char *file String of the file name where these branches
559 // are to be stored. If blank then these branches
560 // are written to the same tree as the Hits were
561 // read from.
562 // Outputs:
563 // none.
564 // Return:
565 // none.
88cb7938 566 Bool_t cH = (strstr(option,"H")!=0);
ff0e455e 567 Bool_t cS = (strstr(option,"S")!=0);
568 Bool_t cD = (strstr(option,"D")!=0);
569 Bool_t cR = (strstr(option,"R")!=0);
570 Bool_t cRF = (strstr(option,"RF")!=0);
88cb7938 571
ff0e455e 572 if(cRF)cR = kFALSE;
88cb7938 573 if(cH && (fHits == 0x0)) fHits = new TClonesArray("AliITShit", 1560);
574
575 AliDetector::MakeBranch(option);
2aea926d 576
88cb7938 577 if(cS) MakeBranchS(0);
578 if(cD) MakeBranchD(0);
579 if(cR) MakeBranchR(0);
580 if(cRF) MakeBranchRF(0);
fe4da5cc 581}
2aea926d 582//______________________________________________________________________
583void AliITS::SetTreeAddress(){
584 // Set branch address for the Trees.
4a5bebc2 585 // Inputs:
586 // none.
587 // Outputs:
588 // none.
589 // Return:
590 // none.
88cb7938 591 TTree *treeS = fLoader->TreeS();
592 TTree *treeD = fLoader->TreeD();
593 TTree *treeR = fLoader->TreeR();
aacedc3e 594 if (fLoader->TreeH() && (fHits == 0x0))
595 fHits = new TClonesArray("AliITShit", 1560);
596
2aea926d 597 AliDetector::SetTreeAddress();
598
599 SetTreeAddressS(treeS);
600 SetTreeAddressD(treeD);
601 SetTreeAddressR(treeR);
fe4da5cc 602}
2aea926d 603//______________________________________________________________________
2aea926d 604void AliITS::AddHit(Int_t track, Int_t *vol, Float_t *hits){
605 // Add an ITS hit
606 // The function to add information to the AliITShit class. See the
607 // AliITShit class for a full description. This function allocates the
608 // necessary new space for the hit information and passes the variable
609 // track, and the pointers *vol and *hits to the AliITShit constructor
610 // function.
4a5bebc2 611 // Inputs:
612 // Int_t track Track number which produced this hit.
613 // Int_t *vol Array of Integer Hit information. See AliITShit.h
614 // Float_t *hits Array of Floating Hit information. see AliITShit.h
615 // Outputs:
616 // none.
617 // Return:
618 // none.
2aea926d 619
620 TClonesArray &lhits = *fHits;
621 new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
3bd79107 622}
2aea926d 623//______________________________________________________________________
3bd79107 624void AliITS::InitModules(Int_t size,Int_t &nmodules){
4a5bebc2 625 // Initialize the modules array.
626 // Inputs:
627 // Int_t size Size of array of the number of modules to be
628 // created. If size <=0 then the number of modules
629 // is gotten from AliITSgeom class kept in fITSgeom.
630 // Outputs:
631 // Int_t &nmodules The number of modules existing.
632 // Return:
633 // none.
3bd79107 634
2aea926d 635 if(fITSmodules){
88cb7938 636 fITSmodules->Delete();
637 delete fITSmodules;
2aea926d 638 } // end fir fITSmoudles
e8189707 639
3bd79107 640 Int_t nl,indexMAX,index;
3bd79107 641
642 if(size<=0){ // default to using data stored in AliITSgeom
88cb7938 643 if(fITSgeom==0) {
644 Error("InitModules","fITSgeom not defined");
645 return;
646 } // end if fITSgeom==0
647 nl = fITSgeom->GetNlayers();
648 indexMAX = fITSgeom->GetModuleIndex(nl,fITSgeom->GetNladders(nl),
649 fITSgeom->GetNdetectors(nl))+1;
650 nmodules = indexMAX;
651 fITSmodules = new TObjArray(indexMAX);
652 for(index=0;index<indexMAX;index++){
653 fITSmodules->AddAt( new AliITSmodule(index),index);
654 } // end for index
3bd79107 655 }else{
88cb7938 656 fITSmodules = new TObjArray(size);
657 for(index=0;index<size;index++) {
658 fITSmodules->AddAt( new AliITSmodule(index),index);
659 } // end for index
9c74c52b 660
3bd79107 661 nmodules = size;
662 } // end i size<=0
663}
2aea926d 664//______________________________________________________________________
665void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t nmodules,
8e8eae84 666 Option_t *option, const char *filename){
2aea926d 667 // fill the modules with the sorted by module hits; add hits from
4a5bebc2 668 // background if option=Add.
669 // Inputs:
670 // Int_t evnt Event to be processed.
671 // Int_t bgrev Background Hit tree number.
672 // Int_t nmodules Not used.
673 // Option_t *option String indicating if merging hits or not. To
674 // merge hits set equal to "Add". Otherwise no
675 // background hits are considered.
676 // Test_t *filename File name containing the background hits..
677 // Outputs:
678 // none.
679 // Return:
680 // none.
3bd79107 681 static TTree *trH1; //Tree with background hits
3bd79107 682 static Bool_t first=kTRUE;
683 static TFile *file;
5cf7bbad 684 const char *addBgr = strstr(option,"Add");
3bd79107 685
ac74f489 686 evnt = nmodules; // Dummy use of variables to remove warnings
e8189707 687 if (addBgr ) {
88cb7938 688 if(first) {
689 file=new TFile(filename);
690 } // end if first
691 first=kFALSE;
692 file->cd();
693 file->ls();
694 // Get Hits Tree header from file
695 if(trH1) delete trH1;
696 trH1=0;
697
698 char treeName[20];
699 sprintf(treeName,"TreeH%d",bgrev);
700 trH1 = (TTree*)gDirectory->Get(treeName);
701 if (!trH1) {
702 Error("FillModules","cannot find Hits Tree for event:%d",bgrev);
703 } // end if !trH1
704 // Set branch addresses
2aea926d 705 } // end if addBgr
3bd79107 706
88cb7938 707 FillModules(fLoader->TreeH(),0); // fill from this file's tree.
3bd79107 708
e8189707 709 if (addBgr ) {
88cb7938 710 FillModules(trH1,10000000); // Default mask 10M.
711 TTree *fAli=fLoader->GetRunLoader()->TreeK();
712 TFile *fileAli=0;
713 if (fAli) fileAli =fAli->GetCurrentFile();
714 fileAli->cd();
3bd79107 715 } // end if add
3bd79107 716}
2aea926d 717//______________________________________________________________________
b4012daf 718void AliITS::FillModules(TTree *treeH, Int_t mask) {
719 // fill the modules with the sorted by module hits;
720 // can be called many times to do a merging
721 // Inputs:
722 // TTree *treeH The tree containing the hits to be copied into
723 // the modules.
724 // Int_t mask The track number mask to indecate which file
725 // this hits came from.
726 // Outputs:
727 // none.
728 // Return:
729 // none.
730
88cb7938 731 if (treeH == 0x0)
732 {
733 Error("FillModules","Tree is NULL");
734 }
b4012daf 735 Int_t lay,lad,det,index;
736 AliITShit *itsHit=0;
737 AliITSmodule *mod=0;
738 char branchname[20];
739 sprintf(branchname,"%s",GetName());
740 TBranch *branch = treeH->GetBranch(branchname);
741 if (!branch) {
88cb7938 742 Error("FillModules","%s branch in TreeH not found",branchname);
743 return;
b4012daf 744 } // end if !branch
745 branch->SetAddress(&fHits);
746 Int_t nTracks =(Int_t) treeH->GetEntries();
747 Int_t iPrimTrack,h;
748 for(iPrimTrack=0; iPrimTrack<nTracks; iPrimTrack++){
88cb7938 749 ResetHits();
750 Int_t nBytes = treeH->GetEvent(iPrimTrack);
751 if (nBytes <= 0) continue;
752 Int_t nHits = fHits->GetEntriesFast();
753 for(h=0; h<nHits; h++){
754 itsHit = (AliITShit *)fHits->UncheckedAt(h);
755 itsHit->GetDetectorID(lay,lad,det);
756 if (fITSgeom) {
757 index = fITSgeom->GetModuleIndex(lay,lad,det);
758 } else {
759 index=det-1; // This should not be used.
760 } // end if [You must have fITSgeom for this to work!]
761 mod = GetModule(index);
762 itsHit->SetTrack(itsHit->GetTrack()+mask); // Set track mask.
763 mod->AddHit(itsHit,iPrimTrack,h);
764 } // end loop over hits
b4012daf 765 } // end loop over tracks
766}
767//______________________________________________________________________
4a5bebc2 768void AliITS::MakeBranchS(const char *fl){
769 // Creates Tree Branch for the ITS summable digits.
770 // Inputs:
771 // cont char *fl File name where SDigits branch is to be written
772 // to. If blank it write the SDigits to the same
773 // file in which the Hits were found.
774 // Outputs:
775 // none.
776 // Return:
777 // none.
2aea926d 778 Int_t buffersize = 4000;
779 char branchname[30];
2ab0c725 780
2aea926d 781 // only one branch for SDigits.
782 sprintf(branchname,"%s",GetName());
88cb7938 783
784
7941072e 785 if(fLoader->TreeS()){
aacedc3e 786 if(fSDigits==0x0) fSDigits = new TClonesArray("AliITSpListItem",1000);
88cb7938 787 MakeBranchInTree(fLoader->TreeS(),branchname,&fSDigits,buffersize,fl);
2aea926d 788 } // end if
789}
790//______________________________________________________________________
791void AliITS::SetTreeAddressS(TTree *treeS){
792 // Set branch address for the ITS summable digits Trees.
4a5bebc2 793 // Inputs:
794 // TTree *treeS Tree containing the SDigits.
795 // Outputs:
796 // none.
797 // Return:
798 // none.
2aea926d 799 char branchname[30];
828e06c7 800
2aea926d 801 if(!treeS) return;
88cb7938 802 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliITSpListItem",1000);
2aea926d 803 TBranch *branch;
804 sprintf(branchname,"%s",GetName());
805 branch = treeS->GetBranch(branchname);
806 if (branch) branch->SetAddress(&fSDigits);
807}
808//______________________________________________________________________
9ad8b5dd 809void AliITS::MakeBranchInTreeD(TTree *treeD,const char *file){
2aea926d 810 // Creates Tree branches for the ITS.
4a5bebc2 811 // Inputs:
e0fc0305 812 // TTree *treeD Pointer to the Digits Tree.
4a5bebc2 813 // cont char *file File name where Digits branch is to be written
814 // to. If blank it write the SDigits to the same
815 // file in which the Hits were found.
816 // Outputs:
817 // none.
818 // Return:
819 // none.
2aea926d 820 // one branch for digits per type of detector
aacedc3e 821 const Char_t *det[3] = {"SPD","SDD","SSD"};
822 TString digclass;
2aea926d 823 Int_t i;
aacedc3e 824 Int_t buffersize = 4000;
825 Char_t branchname[30];
826
827 if (fDtype == 0x0) fDtype = new TObjArray(fNDetTypes);
2aea926d 828 for (i=0; i<kNTYPES ;i++) {
aacedc3e 829 digclass = DetType(i)->GetDigitClassName();
88cb7938 830 // digits
aacedc3e 831 if(!(fDtype->At(i))){
832 fDtype->AddAt(new TClonesArray(digclass.Data(),1000),i);
833 }else{
834 ResetDigits(i);
835 } // end if
836 if (kNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
837 else sprintf(branchname,"%sDigits%d",GetName(),i+1);
838 if (fDtype && treeD) {
839 MakeBranchInTree(treeD,branchname,&((*fDtype)[i]),buffersize,file);
840 } // end if
2aea926d 841 } // end for i
aacedc3e 842 /*
2aea926d 843 for (i=0; i<kNTYPES ;i++) {
88cb7938 844 if (kNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
845 else sprintf(branchname,"%sDigits%d",GetName(),i+1);
846 if (fDtype && treeD) {
aacedc3e 847 MakeBranchInTree(treeD,branchname,&((*fDtype)[i]),buffersize,file);
88cb7938 848 } // end if
2aea926d 849 } // end for i
aacedc3e 850 */
2ab0c725 851}
2aea926d 852//______________________________________________________________________
853void AliITS::SetTreeAddressD(TTree *treeD){
854 // Set branch address for the Trees.
4a5bebc2 855 // Inputs:
856 // TTree *treeD Tree containing the Digits.
857 // Outputs:
858 // none.
859 // Return:
860 // none.
2aea926d 861 const char *det[3] = {"SPD","SDD","SSD"};
862 TBranch *branch;
aacedc3e 863 TString digclass;
2aea926d 864 Int_t i;
aacedc3e 865 char branchname[30];
2ab0c725 866
2aea926d 867 if(!treeD) return;
aacedc3e 868 if (fDtype == 0x0) fDtype = new TObjArray(fNDetTypes);
2aea926d 869 for (i=0; i<kNTYPES; i++) {
aacedc3e 870 digclass = DetType(i)->GetDigitClassName();
88cb7938 871 // digits
aacedc3e 872 if(!(fDtype->At(i))) {
873 fDtype->AddAt(new TClonesArray(digclass.Data(),1000),i);
874 }else{
875 ResetDigits(i);
876 } // end if
88cb7938 877 if (kNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
878 else sprintf(branchname,"%sDigits%d",GetName(),i+1);
879 if (fDtype) {
880 branch = treeD->GetBranch(branchname);
881 if (branch) branch->SetAddress(&((*fDtype)[i]));
882 } // end if fDtype
2aea926d 883 } // end for i
884}
885//______________________________________________________________________
886void AliITS::Hits2SDigits(){
887 // Standard Hits to summable Digits function.
4a5bebc2 888 // Inputs:
889 // none.
890 // Outputs:
891 // none.
2aea926d 892
85a5290f 893 fLoader->LoadHits("read");
894 fLoader->LoadSDigits("recreate");
88cb7938 895 AliRunLoader* rl = fLoader->GetRunLoader();
85a5290f 896
897 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
aacedc3e 898 // Do the Hits to Digits operation. Use Standard input values.
899 // Event number from file, no background hit merging , use size from
900 // AliITSgeom class, option="All", input from this file only.
901 rl->GetEvent(iEvent);
902 if (!fLoader->TreeS()) fLoader->MakeTree("S");
903 MakeBranch("S");
904 SetTreeAddress();
905 HitsToPreDigits(iEvent,0,-1," ",fOpt," ");
906 } // end for iEvent
88cb7938 907
85a5290f 908 fLoader->UnloadHits();
85a5290f 909}
910//______________________________________________________________________
e0fc0305 911void AliITS::SDigitsToDigits(Option_t *opt){
2aea926d 912 // Standard Summable digits to Digits function.
4a5bebc2 913 // Inputs:
914 // none.
915 // Outputs:
916 // none.
e0fc0305 917 char name[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
918
919 if(!GetITSgeom()) return; // need transformations to do digitization.
920 AliITSgeom *geom = GetITSgeom();
921
922 const char *all = strstr(opt,"All");
923 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
88cb7938 924 strstr(opt,"SSD")};
e0fc0305 925 if( !det[0] && !det[1] && !det[2] ) all = "All";
926 else all = 0;
aacedc3e 927 static Bool_t setDef = kTRUE;
928 if(setDef) SetDefaultSimulation();
929 setDef = kFALSE;
e0fc0305 930
931 AliITSsimulation *sim = 0;
932 AliITSDetType *iDetType = 0;
88cb7938 933 TTree *trees = fLoader->TreeS();
e0fc0305 934 if( !(trees && this->GetSDigits()) ){
88cb7938 935 Error("SDigits2Digits","Error: No trees or SDigits. Returning.");
936 return;
e0fc0305 937 } // end if
938 sprintf( name, "%s", this->GetName() );
939 TBranch *brchSDigits = trees->GetBranch( name );
940
941 Int_t id,module;
942 for(module=0;module<geom->GetIndexMax();module++){
88cb7938 943 id = geom->GetModuleType(module);
e0fc0305 944 if (!all && !det[id]) continue;
88cb7938 945 iDetType = DetType(id);
946 sim = (AliITSsimulation*)iDetType->GetSimulationModel();
947 if (!sim) {
e80bf2b3 948 Error("SDigit2Digits","The simulation class was not "
949 "instanciated for module %d type %s!",module,
950 geom->GetModuleTypeName(module));
88cb7938 951 exit(1);
952 } // end if !sim
953 sim->InitSimulationModule(module,gAlice->GetEvNumber());
aacedc3e 954 //
88cb7938 955 // add summable digits to module
956 this->GetSDigits()->Clear();
957 brchSDigits->GetEvent(module);
958 sim->AddSDigitsToModule(GetSDigits(),0);
aacedc3e 959 //
e0fc0305 960 // Digitise current module sum(SDigits)->Digits
961 sim->FinishSDigitiseModule();
3bd79107 962
e0fc0305 963 // fills all branches - wasted disk space
88cb7938 964 fLoader->TreeD()->Fill();
e0fc0305 965 this->ResetDigits();
966 } // end for module
967
88cb7938 968 fLoader->TreeD()->GetEntries();
ed9afcd2 969
88cb7938 970 fLoader->TreeD()->AutoSave();
e0fc0305 971 // reset tree
88cb7938 972 fLoader->TreeD()->Reset();
e0fc0305 973
2aea926d 974}
975//______________________________________________________________________
976void AliITS::Hits2Digits(){
977 // Standard Hits to Digits function.
4a5bebc2 978 // Inputs:
979 // none.
980 // Outputs:
981 // none.
2aea926d 982
85a5290f 983 fLoader->LoadHits("read");
984 fLoader->LoadDigits("recreate");
985 AliRunLoader* rl = fLoader->GetRunLoader();
986
987 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
aacedc3e 988 // Do the Hits to Digits operation. Use Standard input values.
989 // Event number from file, no background hit merging , use size from
990 // AliITSgeom class, option="All", input from this file only.
991 rl->GetEvent(iEvent);
992 if (!fLoader->TreeD()) fLoader->MakeTree("D");
993 MakeBranch("D");
994 SetTreeAddress();
995 HitsToDigits(iEvent,0,-1," ",fOpt," ");
996 } // end for iEvent
85a5290f 997
998 fLoader->UnloadHits();
999 fLoader->UnloadDigits();
2aea926d 1000}
1001//______________________________________________________________________
2aea926d 1002void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
aacedc3e 1003 Option_t *option,Option_t *opt,
1004 const char *filename){
4a5bebc2 1005 // Keep galice.root for signal and name differently the file for
2aea926d 1006 // background when add! otherwise the track info for signal will be lost !
1007 // the condition below will disappear when the geom class will be
4a5bebc2 1008 // initialized for all versions - for the moment it is only for v5 !
1009 // 7 is the SDD beam test version.
1010 // Inputs:
1011 // Int_t evnt Event to be processed.
1012 // Int_t bgrev Background Hit tree number.
1013 // Int_t nmodules Not used.
1014 // Option_t *option String indicating if merging hits or not. To
1015 // merge hits set equal to "Add". Otherwise no
1016 // background hits are considered.
1017 // Test_t *filename File name containing the background hits..
1018 // Outputs:
1019 // none.
1020 // Return:
1021 // none.
2aea926d 1022
1023 if(!GetITSgeom()) return; // need transformations to do digitization.
1024 AliITSgeom *geom = GetITSgeom();
1025
1026 const char *all = strstr(opt,"All");
1027 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
88cb7938 1028 strstr(opt,"SSD")};
2aea926d 1029 static Bool_t setDef=kTRUE;
1030 if (setDef) SetDefaultSimulation();
1031 setDef=kFALSE;
1032
1033 Int_t nmodules;
1034 InitModules(size,nmodules);
1035 FillModules(evNumber,bgrev,nmodules,option,filename);
1036
1037 AliITSsimulation *sim = 0;
1038 AliITSDetType *iDetType = 0;
1039 AliITSmodule *mod = 0;
1040 Int_t id,module;
1041 for(module=0;module<geom->GetIndexMax();module++){
88cb7938 1042 id = geom->GetModuleType(module);
2aea926d 1043 if (!all && !det[id]) continue;
88cb7938 1044 iDetType = DetType(id);
1045 sim = (AliITSsimulation*)iDetType->GetSimulationModel();
1046 if (!sim) {
e80bf2b3 1047 Error("HitsToSDigits","The simulation class was not "
1048 "instanciated for module %d type %s!",module,
1049 geom->GetModuleTypeName(module));
88cb7938 1050 exit(1);
1051 } // end if !sim
1052 mod = (AliITSmodule *)fITSmodules->At(module);
1053 sim->SDigitiseModule(mod,module,evNumber);
1054 // fills all branches - wasted disk space
1055 fLoader->TreeS()->Fill();
1056 ResetSDigits();
2aea926d 1057 } // end for module
1058
1059 ClearModules();
1060
88cb7938 1061 fLoader->TreeS()->GetEntries();
1062 fLoader->TreeS()->AutoSave();
1063 fLoader->WriteSDigits("OVERWRITE");
2aea926d 1064 // reset tree
88cb7938 1065 fLoader->TreeS()->Reset();
2aea926d 1066}
1067//______________________________________________________________________
1068void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
aacedc3e 1069 Option_t *option,Option_t *opt,
1070 const char *filename){
4a5bebc2 1071 // Keep galice.root for signal and name differently the file for
2aea926d 1072 // background when add! otherwise the track info for signal will be lost !
1073 // the condition below will disappear when the geom class will be
4a5bebc2 1074 // initialized for all versions - for the moment it is only for v5 !
1075 // 7 is the SDD beam test version.
1076 // Inputs:
1077 // Int_t evnt Event to be processed.
1078 // Int_t bgrev Background Hit tree number.
1079 // Int_t nmodules Not used.
1080 // Option_t *option String indicating if merging hits or not. To
1081 // merge hits set equal to "Add". Otherwise no
1082 // background hits are considered.
1083 // Test_t *filename File name containing the background hits..
1084 // Outputs:
1085 // none.
1086 // Return:
1087 // none.
1088
2aea926d 1089 if(!GetITSgeom()) return; // need transformations to do digitization.
1090 AliITSgeom *geom = GetITSgeom();
1091
1092 const char *all = strstr(opt,"All");
1093 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
88cb7938 1094 strstr(opt,"SSD")};
2aea926d 1095 static Bool_t setDef=kTRUE;
1096 if (setDef) SetDefaultSimulation();
1097 setDef=kFALSE;
1098
1099 Int_t nmodules;
1100 InitModules(size,nmodules);
1101 FillModules(evNumber,bgrev,nmodules,option,filename);
1102
1103 AliITSsimulation *sim = 0;
1104 AliITSDetType *iDetType = 0;
1105 AliITSmodule *mod = 0;
1106 Int_t id,module;
1107 for(module=0;module<geom->GetIndexMax();module++){
88cb7938 1108 id = geom->GetModuleType(module);
2aea926d 1109 if (!all && !det[id]) continue;
88cb7938 1110 iDetType = DetType(id);
1111 sim = (AliITSsimulation*)iDetType->GetSimulationModel();
1112 if (!sim) {
e80bf2b3 1113 Error("HitsToDigits","The simulation class was not "
1114 "instanciated for module %d type %s!",module,
1115 geom->GetModuleTypeName(module));
88cb7938 1116 exit(1);
1117 } // end if !sim
1118 mod = (AliITSmodule *)fITSmodules->At(module);
1119 sim->DigitiseModule(mod,module,evNumber);
1120 // fills all branches - wasted disk space
1121 fLoader->TreeD()->Fill();
1122 ResetDigits();
2aea926d 1123 } // end for module
4a5bebc2 1124
2aea926d 1125 ClearModules();
3bd79107 1126
88cb7938 1127 fLoader->TreeD()->GetEntries();
1128 fLoader->TreeD()->AutoSave();
2aea926d 1129 // reset tree
88cb7938 1130 fLoader->TreeD()->Reset();
2aea926d 1131}
1132//______________________________________________________________________
2aea926d 1133void AliITS::ResetDigits(){
4a5bebc2 1134 // Reset number of digits and the digits array for the ITS detector.
1135 // Inputs:
1136 // none.
1137 // Outputs:
1138 // none.
3bd79107 1139
2aea926d 1140 if (!fDtype) return;
3bd79107 1141
2aea926d 1142 Int_t i;
1143 for (i=0;i<kNTYPES;i++ ) {
aacedc3e 1144 ResetDigits(i);
2aea926d 1145 } // end for i
1146}
1147//______________________________________________________________________
1148void AliITS::ResetDigits(Int_t i){
4a5bebc2 1149 // Reset number of digits and the digits array for this branch.
1150 // Inputs:
1151 // none.
1152 // Outputs:
1153 // none.
828e06c7 1154
aacedc3e 1155 if (fDtype->At(i)) ((TClonesArray*)fDtype->At(i))->Clear();
1156 if (fNdtype) fNdtype[i]=0;
2aea926d 1157}
1158//______________________________________________________________________
1159void AliITS::AddSumDigit(AliITSpListItem &sdig){
4a5bebc2 1160 // Adds the a module full of summable digits to the summable digits tree.
1161 // Inputs:
1162 // AliITSpListItem &sdig SDigit to be added to SDigits tree.
1163 // Outputs:
1164 // none.
1165 // Return:
1166 // none.
828e06c7 1167
2aea926d 1168 TClonesArray &lsdig = *fSDigits;
1169 new(lsdig[fNSDigits++]) AliITSpListItem(sdig);
828e06c7 1170}
2aea926d 1171//______________________________________________________________________
1172void AliITS::AddRealDigit(Int_t id, Int_t *digits){
4a5bebc2 1173 // Add a real digit - as coming from data.
1174 // Inputs:
1175 // Int_t id Detector type number.
1176 // Int_t *digits Integer array containing the digits info. See
1177 // AliITSdigit.h
1178 // Outputs:
1179 // none.
1180 // Return:
1181 // none.
9c74c52b 1182
2aea926d 1183 TClonesArray &ldigits = *((TClonesArray*)fDtype->At(id));
1184 new(ldigits[fNdtype[id]++]) AliITSdigit(digits);
1185}
1186//______________________________________________________________________
1187void AliITS::AddSimDigit(Int_t id, AliITSdigit *d){
4a5bebc2 1188 // Add a simulated digit.
1189 // Inputs:
1190 // Int_t id Detector type number.
1191 // AliITSdigit *d Digit to be added to the Digits Tree. See
1192 // AliITSdigit.h
1193 // Outputs:
1194 // none.
1195 // Return:
1196 // none.
2aea926d 1197
1198 TClonesArray &ldigits = *((TClonesArray*)fDtype->At(id));
1199
1200 switch(id){
1201 case 0:
88cb7938 1202 new(ldigits[fNdtype[id]++]) AliITSdigitSPD(*((AliITSdigitSPD*)d));
1203 break;
2aea926d 1204 case 1:
88cb7938 1205 new(ldigits[fNdtype[id]++]) AliITSdigitSDD(*((AliITSdigitSDD*)d));
1206 break;
2aea926d 1207 case 2:
88cb7938 1208 new(ldigits[fNdtype[id]++]) AliITSdigitSSD(*((AliITSdigitSSD*)d));
1209 break;
2aea926d 1210 } // end switch id
1211}
1212//______________________________________________________________________
1213void AliITS::AddSimDigit(Int_t id,Float_t phys,Int_t *digits,Int_t *tracks,
88cb7938 1214 Int_t *hits,Float_t *charges){
7f1a504b 1215 // Add a simulated digit to the list.
1216 // Inputs:
1217 // Int_t id Detector type number.
1218 // Float_t phys Physics indicator. See AliITSdigits.h
1219 // Int_t *digits Integer array containing the digits info. See
1220 // AliITSdigit.h
1221 // Int_t *tracks Integer array [AliITSdigitS?D::GetNTracks()]
1222 // containing the track numbers that contributed to
1223 // this digit.
1224 // Int_t *hits Integer array [AliITSdigitS?D::GetNTracks()]
1225 // containing the hit numbers, from AliITSmodule, that
1226 // contributed to this digit.
1227 // Float_t *charge Floating point array of the signals contributed
1228 // to this digit by each track.
1229 // Outputs:
1230 // none.
1231 // Return:
1232 // none.
2aea926d 1233
7f1a504b 1234 TClonesArray &ldigits = *((TClonesArray*)fDtype->At(id));
1235 AliITSresponseSDD *resp = 0;
1236 switch(id){
1237 case 0:
aacedc3e 1238 new(ldigits[fNdtype[id]++]) AliITSdigitSPD(digits,tracks,hits);
1239 break;
7f1a504b 1240 case 1:
aacedc3e 1241 resp = (AliITSresponseSDD*)DetType(1)->GetResponseModel();
1242 new(ldigits[fNdtype[id]++]) AliITSdigitSDD(phys,digits,tracks,
1243 hits,charges,resp);
1244 break;
7f1a504b 1245 case 2:
aacedc3e 1246 new(ldigits[fNdtype[id]++]) AliITSdigitSSD(digits,tracks,hits);
1247 break;
7f1a504b 1248 } // end switch id
2aea926d 1249}
0421c3d1 1250//______________________________________________________________________
aacedc3e 1251void AliITS::Digits2Raw(){
1252 // convert digits of the current event to raw data
0421c3d1 1253
1254 fLoader->LoadDigits();
1255 TTree* digits = fLoader->TreeD();
1256 if (!digits) {
aacedc3e 1257 Error("Digits2Raw", "no digits tree");
1258 return;
0421c3d1 1259 }
1260 SetTreeAddressD(digits);
1261
1262 AliITSDDLRawData rawWriter;
1263 //Verbose level
1264 // 0: Silent
1265 // 1: cout messages
1266 // 2: txt files with digits
1267 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
1268 //it is highly suggested to use this mode only for debugging digits files
1269 //reasonably small, because otherwise the size of the txt files can reach
1270 //quickly several MB wasting time and disk space.
1271 rawWriter.SetVerbose(0);
1272
1273 //SILICON PIXEL DETECTOR
1274 Info("Digits2Raw", "Formatting raw data for SPD");
1275 rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"));
1276
1277 //SILICON DRIFT DETECTOR
1278 Info("Digits2Raw", "Formatting raw data for SDD");
1279 rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"));
1280
1281 //SILICON STRIP DETECTOR
1282 Info("Digits2Raw", "Formatting raw data for SSD");
1283 rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
1284
1285 fLoader->UnloadDigits();
1286}
1287
2aea926d 1288//______________________________________________________________________
1289void AliITS::MakeTreeC(Option_t *option){
88cb7938 1290 // Create a separate tree to store the clusters.
1291 // Inputs:
1292 // Option_t *option string which must contain "C" otherwise
1293 // no Cluster Tree is created.
1294 // Outputs:
1295 // none.
1296 // Return:
1297 // none.
1298
1299 AliITSLoader *pITSLoader = (AliITSLoader*)fLoader;
1300
1301 if (pITSLoader == 0x0) {
aacedc3e 1302 Error("MakeTreeC","fLoader == 0x0 option=%s",option);
1303 return;
88cb7938 1304 }
1305 if (pITSLoader->TreeC() == 0x0) pITSLoader->MakeTree("C");
1306 MakeBranchC();
1307}
aacedc3e 1308//----------------------------------------------------------------------
1309void AliITS::MakeBranchC(){
1310 //Makes barnches in treeC
1311 AliITSLoader *pITSLoader = (AliITSLoader*)fLoader;
1312 if (pITSLoader == 0x0) {
1313 Error("MakeTreeC","fLoader == 0x0");
1314 return;
1315 }
1316 TTree * lTC = pITSLoader->TreeC();
1317 if (lTC == 0x0){
1318 Error("MakeTreeC","Can not get TreeC from Loader");
1319 return;
1320 }
828e06c7 1321
aacedc3e 1322 Int_t buffersize = 4000;
1323 char branchname[30];
1324 const char *det[3] = {"SPD","SDD","SSD"};
1325 char digclass[40];
1326 char clclass[40];
1327
2aea926d 1328 // one branch for Clusters per type of detector
aacedc3e 1329 Int_t i;
1330 for (i=0; i<kNTYPES ;i++) {
2aea926d 1331 AliITSDetType *iDetType=DetType(i);
1332 iDetType->GetClassNames(digclass,clclass);
88cb7938 1333 // clusters
1334 if (fCtype == 0x0) fCtype = new TObjArray(fNDetTypes);
aacedc3e 1335 if(!ClustersAddress(i)){
1336 fCtype->AddAt(new TClonesArray(clclass,1000),i);
1337 }
2aea926d 1338 if (kNTYPES==3) sprintf(branchname,"%sClusters%s",GetName(),det[i]);
88cb7938 1339 else sprintf(branchname,"%sClusters%d",GetName(),i+1);
aacedc3e 1340 if (fCtype && lTC) {
1341 if (lTC->GetBranch(branchname)){
1342 Warning("MakeBranchC","Branch %s alread exists in TreeC",
1343 branchname);
1344 }else{
1345 Info("MakeBranchC","Creating branch %s in TreeC",branchname);
1346 lTC->Branch(branchname,&((*fCtype)[i]), buffersize);
88cb7938 1347 }
aacedc3e 1348 } // end if fCtype && lTC
1349 } // end for i
2aea926d 1350}
1351//______________________________________________________________________
1352void AliITS::GetTreeC(Int_t event){
aacedc3e 1353 // Get the clusters tree for this event and set the branch address.
1354 // Inputs:
1355 // Int_t event Event number for the cluster tree.
1356 // Outputs:
1357 // none.
1358 // Return:
1359 // none.
1360 char branchname[30];
1361 const char *det[3] = {"SPD","SDD","SSD"};
3bd79107 1362
aacedc3e 1363 AliITSLoader *pITSLoader = (AliITSLoader*)fLoader;
1364 TTree * lTC = pITSLoader->TreeC();
2aea926d 1365
aacedc3e 1366 ResetClusters();
1367 if (lTC) {
1368 pITSLoader->CleanRawClusters();
1369 } // end if TreeC()
88cb7938 1370
aacedc3e 1371 TBranch *branch;
88cb7938 1372
aacedc3e 1373 if (lTC) {
1374 Int_t i;
88cb7938 1375 char digclass[40];
1376 char clclass[40];
1377 for (i=0; i<kNTYPES; i++) {
aacedc3e 1378 AliITSDetType *iDetType=DetType(i);
1379 iDetType->GetClassNames(digclass,clclass);
1380 // clusters
1381 if (fCtype == 0x0) fCtype = new TObjArray(fNDetTypes);
1382 if(!fCtype->At(i)) fCtype->AddAt(new TClonesArray(clclass,1000),i);
1383 if(kNTYPES==3) sprintf(branchname,"%sClusters%s",GetName(),det[i]);
1384 else sprintf(branchname,"%sClusters%d",GetName(),i+1);
1385 if (fCtype) {
93f82b23 1386 branch = lTC->GetBranch(branchname);
aacedc3e 1387 if (branch) branch->SetAddress(&((*fCtype)[i]));
1388 } // end if fCtype
88cb7938 1389 } // end for i
aacedc3e 1390 } else {
88cb7938 1391 Error("GetTreeC","cannot find Clusters Tree for event:%d",event);
aacedc3e 1392 } // end if lTC
2aea926d 1393}
1394//______________________________________________________________________
1395void AliITS::AddCluster(Int_t id, AliITSRawCluster *c){
4a5bebc2 1396 // Add a cluster to the list.
1397 // Inputs:
1398 // Int_t id Detector type number.
1399 // AliITSRawCluster *c Cluster class to be added to the tree of
1400 // clusters.
1401 // Outputs:
1402 // none.
1403 // Return:
1404 // none.
2aea926d 1405
1406 TClonesArray &lc = *((TClonesArray*)fCtype->At(id));
1407
1408 switch(id){
1409 case 0:
88cb7938 1410 new(lc[fNctype[id]++]) AliITSRawClusterSPD(*((AliITSRawClusterSPD*)c));
1411 break;
2aea926d 1412 case 1:
88cb7938 1413 new(lc[fNctype[id]++]) AliITSRawClusterSDD(*((AliITSRawClusterSDD*)c));
1414 break;
2aea926d 1415 case 2:
88cb7938 1416 new(lc[fNctype[id]++]) AliITSRawClusterSSD(*((AliITSRawClusterSSD*)c));
1417 break;
2aea926d 1418 } // end switch id
1419}
1420//______________________________________________________________________
2aea926d 1421void AliITS::ResetClusters(Int_t i){
4a5bebc2 1422 // Reset number of clusters and the clusters array for this branch.
1423 // Inputs:
1424 // Int_t i Detector type number.
1425 // Outputs:
1426 // none.
1427 // Return:
1428 // none.
3bd79107 1429
2aea926d 1430 if (fCtype->At(i)) ((TClonesArray*)fCtype->At(i))->Clear();
1431 if (fNctype) fNctype[i]=0;
1432}
1433//______________________________________________________________________
ff0e455e 1434void AliITS::MakeBranchR(const char *file, Option_t *opt){
2aea926d 1435 // Creates Tree branches for the ITS Reconstructed points.
4a5bebc2 1436 // Inputs:
1437 // cont char *file File name where RecPoints branch is to be written
1438 // to. If blank it write the SDigits to the same
1439 // file in which the Hits were found.
1440 // Outputs:
1441 // none.
1442 // Return:
1443 // none.
1444 Int_t buffsz = 4000;
2aea926d 1445 char branchname[30];
3bd79107 1446
2aea926d 1447 // only one branch for rec points for all detector types
ff0e455e 1448 Bool_t oFast= (strstr(opt,"Fast")!=0);
1449 if(oFast){
aacedc3e 1450 sprintf(branchname,"%sRecPointsF",GetName());
ff0e455e 1451 } else {
aacedc3e 1452 sprintf(branchname,"%sRecPoints",GetName());
ff0e455e 1453 }
aacedc3e 1454
8a92b3ef 1455 if(!fRecPoints)fRecPoints = new TClonesArray("AliITSRecPoint",1000);
1456 if (fLoader->TreeR()) {
aacedc3e 1457 if(fRecPoints==0x0) fRecPoints = new TClonesArray("AliITSRecPoint",
1458 1000);
88cb7938 1459 MakeBranchInTree(fLoader->TreeR(),branchname,&fRecPoints,buffsz,file);
2aea926d 1460 } // end if
1461}
1462//______________________________________________________________________
1463void AliITS::SetTreeAddressR(TTree *treeR){
1464 // Set branch address for the Reconstructed points Trees.
4a5bebc2 1465 // Inputs:
1466 // TTree *treeR Tree containing the RecPoints.
1467 // Outputs:
1468 // none.
1469 // Return:
1470 // none.
2aea926d 1471 char branchname[30];
3bd79107 1472
2aea926d 1473 if(!treeR) return;
aacedc3e 1474 if(fRecPoints==0x0) fRecPoints = new TClonesArray("AliITSRecPoint",1000);
2aea926d 1475 TBranch *branch;
2aea926d 1476 sprintf(branchname,"%sRecPoints",GetName());
1477 branch = treeR->GetBranch(branchname);
ff0e455e 1478 if (branch) {
ff0e455e 1479 branch->SetAddress(&fRecPoints);
aacedc3e 1480 }else {
1481 sprintf(branchname,"%sRecPointsF",GetName());
1482 branch = treeR->GetBranch(branchname);
1483 if (branch) {
1484 branch->SetAddress(&fRecPoints);
1485 }
ff0e455e 1486 }
2aea926d 1487}
1488//______________________________________________________________________
1489void AliITS::AddRecPoint(const AliITSRecPoint &r){
1490 // Add a reconstructed space point to the list
4a5bebc2 1491 // Inputs:
1492 // const AliITSRecPoint &r RecPoint class to be added to the tree
1493 // of reconstructed points TreeR.
1494 // Outputs:
1495 // none.
1496 // Return:
1497 // none.
3bd79107 1498
2aea926d 1499 TClonesArray &lrecp = *fRecPoints;
1500 new(lrecp[fNRecPoints++]) AliITSRecPoint(r);
3bd79107 1501}
2aea926d 1502//______________________________________________________________________
e8189707 1503void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
aacedc3e 1504 Option_t *opt0,Option_t *opt1,
1505 const char *flnm){
3bd79107 1506 // keep galice.root for signal and name differently the file for
1507 // background when add! otherwise the track info for signal will be lost !
2aea926d 1508 // the condition below will disappear when the geom class will be
4a5bebc2 1509 // initialized for all versions - for the moment it is only for v5 !
1510 // Inputs:
1511 // Int_t evnt Event to be processed.
1512 // Int_t bgrev Background Hit tree number.
1513 // Int_t size Size used by InitModules. See InitModules.
1514 // Option_t *opt0 Option passed to FillModules. See FillModules.
1515 // Option_t *opt1 String indicating if merging hits or not. To
1516 // merge hits set equal to "Add". Otherwise no
1517 // background hits are considered.
1518 // Test_t *flnm File name containing the background hits..
1519 // Outputs:
1520 // none.
1521 // Return:
1522 // none.
1523
2aea926d 1524 if(!GetITSgeom()) return;
8a92b3ef 1525 AliITSLoader *pITSloader = (AliITSLoader*)fLoader;
2aea926d 1526 AliITSgeom *geom = GetITSgeom();
1527
1528 const char *all = strstr(opt1,"All");
1529 const char *det[3] ={strstr(opt1,"SPD"),strstr(opt1,"SDD"),
88cb7938 1530 strstr(opt1,"SSD")};
2aea926d 1531 Int_t nmodules;
1532 InitModules(size,nmodules);
1533 FillModules(evNumber,bgrev,nmodules,opt0,flnm);
1534
1535 AliITSsimulation *sim = 0;
1536 AliITSDetType *iDetType = 0;
1537 AliITSmodule *mod = 0;
1538 Int_t id,module;
e3b819ce 1539
1540 //m.b. : this change is nothing but a nice way to make sure
1541 //the CPU goes up !
88cb7938 1542
aacedc3e 1543 if(GetDebug()) cout<<"HitsToFastRecPoints: N mod = "<<
1544 geom->GetIndexMax()<<endl;
e80bf2b3 1545 for(module=0;module<geom->GetIndexMax();module++){
88cb7938 1546 id = geom->GetModuleType(module);
2aea926d 1547 if (!all && !det[id]) continue;
88cb7938 1548 iDetType = DetType(id);
1549 sim = (AliITSsimulation*)iDetType->GetSimulationModel();
aacedc3e 1550 if (!sim) {
1551 Error("HitsToFastPoints","The simulation class was not "
1552 "instanciated for module %d type %x!",module,
1553 geom->GetModuleTypeName(module));
1554 exit(1);
1555 } // end if !sim
88cb7938 1556 mod = (AliITSmodule *)fITSmodules->At(module);
1557 sim->CreateFastRecPoints(mod,module,gRandom);
1558 cout<<module<<"\r";fflush(0);
8a92b3ef 1559 //gAlice->TreeR()->Fill();
aacedc3e 1560 TTree *lTR = pITSloader->TreeR();
93f82b23 1561 TBranch *br=lTR->GetBranch("ITSRecPointsF");
88cb7938 1562 br->Fill();
1563 ResetRecPoints();
2aea926d 1564 } // end for module
4a5bebc2 1565
2aea926d 1566 ClearModules();
88cb7938 1567 fLoader->WriteRecPoints("OVERWRITE");
2aea926d 1568}
1569//______________________________________________________________________
2aea926d 1570void AliITS::DigitsToRecPoints(Int_t evNumber,Int_t lastentry,Option_t *opt){
88cb7938 1571 // cluster finding and reconstruction of space points
1572 // the condition below will disappear when the geom class will be
1573 // initialized for all versions - for the moment it is only for v5 !
1574 // 7 is the SDD beam test version
1575 // Inputs:
1576 // Int_t evNumber Event number to be processed.
1577 // Int_t lastentry Offset for module when not all of the modules
1578 // are processed.
1579 // Option_t *opt String indicating which ITS sub-detectors should
1580 // be processed. If ="All" then all of the ITS
1581 // sub detectors are processed.
1582 // Outputs:
1583 // none.
1584 // Return:
1585 // none.
1586
1587 if(!GetITSgeom()) return;
1588 AliITSgeom *geom = GetITSgeom();
2aea926d 1589
88cb7938 1590 const char *all = strstr(opt,"All");
1591 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
1592 strstr(opt,"SSD")};
1593 static Bool_t setRec=kTRUE;
1594 if (setRec) SetDefaultClusterFinders();
1595 setRec=kFALSE;
1596
1597 AliITSLoader *pITSloader = (AliITSLoader*)fLoader;
1598 TTree *treeC=pITSloader->TreeC();
1599 AliITSClusterFinder *rec = 0;
1600 AliITSDetType *iDetType = 0;
1601 Int_t id,module,first=0;
1602 for(module=0;module<geom->GetIndexMax();module++){
ac74f489 1603 id = geom->GetModuleType(module);
1604 if (!all && !det[id]) continue;
1605 if(det[id]) first = geom->GetStartDet(id);
1606 iDetType = DetType(id);
1607 rec = (AliITSClusterFinder*)iDetType->GetReconstructionModel();
1608 TClonesArray *itsDigits = this->DigitsAddress(id);
1609 if (!rec) {
aacedc3e 1610 Error("DigitsToRecPoints",
1611 "The reconstruction class was not instanciated! event=%d",
1612 evNumber);
1613 exit(1);
ac74f489 1614 } // end if !rec
1615 this->ResetDigits();
93f82b23 1616 TTree *lTD = pITSloader->TreeD();
ac74f489 1617 if (all) {
aacedc3e 1618 lTD->GetEvent(lastentry+module);
ac74f489 1619 }else {
aacedc3e 1620 lTD->GetEvent(lastentry+(module-first));
ac74f489 1621 }
1622 Int_t ndigits = itsDigits->GetEntriesFast();
aacedc3e 1623 if(ndigits>0){
1624 rec->SetDigits(DigitsAddress(id));
1625 rec->SetClusters(ClustersAddress(id));
1626 rec->FindRawClusters(module);
1627 } // end if
ac74f489 1628 pITSloader->TreeR()->Fill();
1629 ResetRecPoints();
1630 treeC->Fill();
1631 ResetClusters();
88cb7938 1632 } // end for module
828e06c7 1633
88cb7938 1634 pITSloader->WriteRecPoints("OVERWRITE");
1635 pITSloader->WriteRawClusters("OVERWRITE");
fe4da5cc 1636}
2aea926d 1637//______________________________________________________________________
aacedc3e 1638AliLoader* AliITS::MakeLoader(const char* topfoldername){
1639 //builds ITSgetter (AliLoader type)
1640 //if detector wants to use castomized getter, it must overload this method
1641
1642 Info("MakeLoader","Creating AliITSLoader. Top folder is %s.",
1643 topfoldername);
1644 fLoader = new AliITSLoader(GetName(),topfoldername);
1645 return fLoader;
2aea926d 1646}