]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSDetTypeSim.cxx
Replacing array of objects by array of pointers
[u/mrichter/AliRoot.git] / ITS / AliITSDetTypeSim.cxx
CommitLineData
3b9df642 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 $Id$
18*/
19
7d62fb64 20/////////////////////////////////////////////////////////////////////
21// Base simulation functions for ITS //
22// //
23// //
24/////////////////////////////////////////////////////////////////////
25#include "TBranch.h"
26#include "TClonesArray.h"
27#include "TObjArray.h"
28#include "TTree.h"
29
30#include "AliRun.h"
31#include "AliITSdigit.h"
32#include "AliITSdigitSPD.h"
33#include "AliITSdigitSDD.h"
34#include "AliITSdigitSSD.h"
3b9df642 35#include "AliITSDetTypeSim.h"
7d62fb64 36#include "AliITSgeom.h"
37#include "AliITSpListItem.h"
38#include "AliITSresponseSPD.h"
39#include "AliITSresponseSDD.h"
40#include "AliITSresponseSSD.h"
41#include "AliITSsegmentationSPD.h"
42#include "AliITSsegmentationSDD.h"
43#include "AliITSsegmentationSSD.h"
44#include "AliITSsimulation.h"
45#include "AliITSsimulationSPD.h"
46#include "AliITSsimulationSDD.h"
47#include "AliITSsimulationSSD.h"
48
49
50const Int_t AliITSDetTypeSim::fgkNdettypes = 3;
3b9df642 51
52ClassImp(AliITSDetTypeSim)
53
54//----------------------------------------------------------------------
55AliITSDetTypeSim::AliITSDetTypeSim():
56TObject(),
57fGeom(), //
58fSimulation(), // [NDet]
59fSegmentation(), // [NDet]
60fResponse(), // [NMod]
61fPreProcess(), // [] e.g. Fill fHitModule with hits
62fPostProcess(), // [] e.g. Wright Raw data
3b9df642 63fNSDigits(0), //! number of SDigits
64fSDigits(), //! [NMod][NSDigits]
65fNDigits(0), //! number of Digits
66fDigits(), //! [NMod][NDigits]
67fHitClassName(), // String with Hit class name.
68fSDigClassName(),// String with SDigit class name.
69fDigClassName(){ // String with digit class name.
70 // Default Constructor
71 // Inputs:
72 // none.
73 // Outputs:
74 // none.
75 // Return:
76 // A properly zero-ed AliITSDetTypeSim class.
7d62fb64 77 fGeom = 0;
78 fSimulation = new TObjArray(fgkNdettypes);
79 fSegmentation = new TObjArray(fgkNdettypes);
80 fResponse = 0;
81 fPreProcess = 0;
82 fPostProcess = 0;
83 fNSDigits = 0;
84 fSDigits = new TClonesArray("AliITSpListItem",1000);
85 fDigits = new TObjArray(fgkNdettypes);
86 fNDigits = new Int_t[fgkNdettypes];
87 fLoader = 0;
3b9df642 88}
89//----------------------------------------------------------------------
90AliITSDetTypeSim::~AliITSDetTypeSim(){
91 // Destructor
92 // Inputs:
93 // none.
94 // Outputs:
95 // none.
96 // Return:
97 // Nothing.
7d62fb64 98
99 if(fGeom) delete fGeom;
100 if(fSimulation){
101 fSimulation->Delete();
102 delete fSimulation;
103 fSimulation = 0;
104 }
105
106 if(fSegmentation){
107 fSegmentation->Delete();
108 delete fSegmentation;
109 fSegmentation = 0;
110 }
111
112 if(fResponse){
113 fResponse->Delete();
114 delete fResponse;
115 fResponse = 0;
116 }
117
118 if(fPreProcess){
119 fPreProcess->Delete();
120 delete fPreProcess;
121 fPreProcess = 0;
122 }
123
124 if(fPostProcess){
125 fPostProcess->Delete();
126 delete fPostProcess;
127 fPostProcess = 0;
128 }
129
130 if (fLoader)
131 {
132 fLoader->GetModulesFolder()->Remove(this);
133 }
134
135
136 if (fSDigits) {
137 fSDigits->Delete();
138 delete fSDigits;
139 fSDigits=0;
140 }
141 if (fDigits) {
142 fDigits->Delete();
143 delete fDigits;
144 fDigits=0;
145 }
146
3b9df642 147}
148//----------------------------------------------------------------------
7d62fb64 149AliITSDetTypeSim::AliITSDetTypeSim(const AliITSDetTypeSim &source) : TObject(source){
150 // Copy Constructor for object AliITSDetTypeSim not allowed
151 if(this==&source) return;
152 Error("Copy constructor",
153 "You are not allowed to make a copy of the AliITSDetTypeSim");
154 exit(1);
3b9df642 155
7d62fb64 156
3b9df642 157}
158//----------------------------------------------------------------------
7d62fb64 159AliITSDetTypeSim& AliITSDetTypeSim::operator=(const AliITSDetTypeSim &source){
3b9df642 160 // The = operator for object AliITSDetTypeSim
7d62fb64 161
162 if(&source==this) return *this;
163 Error("operator=","You are not allowed to make a copy of the AliITSDetTypeSIm");
164 exit(1);
3b9df642 165 return *this;
166}
7d62fb64 167
168
3b9df642 169//______________________________________________________________________
7d62fb64 170void AliITSDetTypeSim::SetSimulationModel(Int_t dettype,AliITSsimulation *sim){
171
172 //Set simulation model for detector type
173
174 if(fSimulation==0) fSimulation = new TObjArray(fgkNdettypes);
175 fSimulation->AddAt(sim,dettype);
176}
177//______________________________________________________________________
178AliITSsimulation* AliITSDetTypeSim::GetSimulationModel(Int_t dettype){
179
180 //Get simulation model for detector type
181 if(fSimulation==0) {
182 Warning("GetSimulationModel","fSimulation is 0!");
183 return 0;
184 }
185 return (AliITSsimulation*)(fSimulation->At(dettype));
186}
187//______________________________________________________________________
188AliITSsimulation* AliITSDetTypeSim::GetSimulationModelByModule(Int_t module){
189
190 //Get simulation model by module number
191 if(fGeom==0) {
192 Warning("GetSimulationModelByModule","fGeom is 0!");
193 return 0;
194 }
195
196 return GetSimulationModel(fGeom->GetModuleType(module));
197}
198//______________________________________________________________________
199void AliITSDetTypeSim::SetSegmentationModel(Int_t dettype,AliITSsegmentation *seg){
200
201 //Set segmentation model for detector type
202 if(fSegmentation==0x0) fSegmentation = new TObjArray(fgkNdettypes);
203 fSegmentation->AddAt(seg,dettype);
204
205}
206//______________________________________________________________________
207AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModel(Int_t dettype){
208
209 //Get segmentation model for detector type
210
211 if(fSegmentation==0) {
212 Warning("GetSegmentationModel","fSegmentation is 0!");
213 return 0;
214 }
215 return (AliITSsegmentation*)(fSegmentation->At(dettype));
216
217}
218//_______________________________________________________________________
219AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModelByModule(Int_t module){
220
221 //Get segmentation model by module number
222 if(fGeom==0){
223 Warning("GetSegmentationModelByModule","fGeom is 0!");
224 return 0;
225 }
226 return GetSegmentationModel(fGeom->GetModuleType(module));
227
228}
229//_______________________________________________________________________
230void AliITSDetTypeSim::SetResponseModel(Int_t module,AliITSresponse *resp){
231
232
233 //Set segmentation model for module number
234 if(fResponse==0) fResponse = new TObjArray(fGeom->GetIndexMax());
235 fResponse->AddAt(resp,module);
236}
237//______________________________________________________________________
238void AliITSDetTypeSim::ResetResponse(){
239
240 //resets response array
241 if(fResponse){
242 for(Int_t i=0;i<fResponse->GetEntries();i++){
243 if(fResponse->At(i)) delete (AliITSresponse*)fResponse->At(i);
244 }
245 }
246}
247//______________________________________________________________________
248void AliITSDetTypeSim::ResetSegmentation(){
249
250 //Resets segmentation array
251 if(fSegmentation){
252 for(Int_t i=0;i<fgkNdettypes;i++){
253 if(fSegmentation->At(i)) delete (AliITSsegmentation*)fSegmentation->At(i);
254 }
255 }
256}
257
258//_______________________________________________________________________
259AliITSresponse* AliITSDetTypeSim::GetResponseModel(Int_t module){
260
261 //Get segmentation model for module number
262
263 if(fResponse==0) {
264 Warning("GetResponseModel","fResponse is 0!");
265 return 0;
266 }
267 return (AliITSresponse*)(fResponse->At(module));
268}
269//_______________________________________________________________________
270void AliITSDetTypeSim::SetDefaults(){
271
272 //Set defaults for segmentation and response
273
274
275 if(fGeom==0){
276 Warning("SetDefaults","fGeom is 0!");
277 return;
278 }
279
280 if(!fResponse) fResponse = new TObjArray(fGeom->GetIndexMax());
281
282 AliITSsegmentation* seg;
283 AliITSresponse* res;
284 ResetResponse();
285 ResetSegmentation();
286
287 for(Int_t imod=0;imod<fGeom->GetIndexMax();imod++){
288 Int_t dettype = fGeom->GetModuleType(imod);
289 //SPD
290 if(dettype==0){
291 if(!GetSegmentationModel(dettype)){
292 seg = new AliITSsegmentationSPD(fGeom);
293 SetSegmentationModel(dettype,seg);
294 }
295 if(!GetResponseModel(imod)){
296 res = new AliITSresponseSPD();
297 SetResponseModel(imod,res);
298 }
299 const char *kData0=(GetResponseModel(imod))->DataType();
300 if (strstr(kData0,"real")) {
301 SetDigitClassName(dettype,"AliITSdigit");
302 } else SetDigitClassName(dettype,"AliITSdigitSPD");
303 }
304 //SDD
305 if(dettype==1){
306 if(!GetResponseModel(imod)){
307 SetResponseModel(imod,new AliITSresponseSDD("simulated"));
308 }
309 if(!GetSegmentationModel(dettype)){
310 res = GetResponseModel(imod);
311 seg = new AliITSsegmentationSDD(fGeom,res);
312 SetSegmentationModel(dettype,seg);
313 }
314 const char *kopt = GetResponseModel(imod)->ZeroSuppOption();
315 if((!strstr(kopt,"2D"))&&(!strstr(kopt,"1D"))) SetDigitClassName(dettype,"AliITSdigit");
316 else SetDigitClassName(dettype,"AliITSdigitSDD");
317 }
318 //SSD
319 if(dettype==2){
320 if(!GetSegmentationModel(dettype)){
321 seg = new AliITSsegmentationSSD(fGeom);
322 SetSegmentationModel(dettype,seg);
323 }
324 if(!GetResponseModel(imod)){
325 SetResponseModel(imod,new AliITSresponseSSD("simulated"));
326 }
327 const char *kData2 = (GetResponseModel(imod))->DataType();
328 if (strstr(kData2,"real")) {
329 SetDigitClassName(dettype,"AliITSdigit");
330 } else SetDigitClassName(dettype,"AliITSdigitSSD");
331
332 }
333
334 }
335
336}
337
338//_______________________________________________________________________
339void AliITSDetTypeSim::SetDefaultSimulation(){
340
341 //Set default simulation for detector type
342
343
344 if(fGeom==0){
345 Warning("SetDefaults","fGeom is 0!");
346 return;
347 }
348
349 if(!fResponse) fResponse = new TObjArray(fGeom->GetIndexMax());
350
351 AliITSsegmentation* seg;
352 AliITSresponse* res;
353 AliITSsimulation* sim;
354
355 for(Int_t idet=0;idet<fgkNdettypes;idet++){
356 //SPD
357 if(idet==0){
358 sim = GetSimulationModel(idet);
359 if(!sim){
360 seg = (AliITSsegmentationSPD*)GetSegmentationModel(idet);
361 res = (AliITSresponseSPD*)GetResponseModel(fGeom->GetStartSPD());
362 sim = new AliITSsimulationSPD(seg,res);
363 SetSimulationModel(idet,sim);
364 } else{
365 sim->SetResponseModel(GetResponseModel(fGeom->GetStartSPD()));
366 sim->SetSegmentationModel((AliITSsegmentationSPD*)GetSegmentationModel(idet));
367 sim->Init();
368 }
369 }
370 //SDD
371 if(idet==1){
372 sim = GetSimulationModel(idet);
373 if(!sim){
374 seg = (AliITSsegmentationSDD*)GetSegmentationModel(idet);
375 res = (AliITSresponseSDD*)GetResponseModel(fGeom->GetStartSDD());
376 sim = new AliITSsimulationSDD(seg,res);
377 SetSimulationModel(idet,sim);
378 } else {
379 sim->SetResponseModel((AliITSresponseSDD*)GetResponseModel(fGeom->GetStartSDD()));
380 sim->SetSegmentationModel((AliITSsegmentationSDD*)GetSegmentationModel(idet));
381 sim->Init();
382 }
383
384 }
385 //SSD
386 if(idet==2){
387 sim = GetSimulationModel(idet);
388 if(!sim){
389 seg = (AliITSsegmentationSSD*)GetSegmentationModel(idet);
390 res = (AliITSresponseSSD*)GetResponseModel(fGeom->GetStartSSD());
391 sim = new AliITSsimulationSSD(seg,res);
392 SetSimulationModel(idet,sim);
393 } else{
394 sim->SetResponseModel((AliITSresponseSSD*)GetResponseModel(fGeom->GetStartSSD()));
395 sim->SetSegmentationModel((AliITSsegmentationSSD*)GetSegmentationModel(idet));
396 sim->Init();
397 }
398
399 }
400
401 }
402}
403
404//___________________________________________________________________
405void AliITSDetTypeSim::SetTreeAddressS(TTree* treeS, Char_t* name){
406 // Set branch address for the ITS summable digits Trees.
407
408 char branchname[30];
409
410 if(!treeS){
411 return;
412 }
413 if (fSDigits == 0x0){
414 fSDigits = new TClonesArray("AliITSpListItem",1000);
415 }
416 TBranch *branch;
417 sprintf(branchname,"%s",name);
418 branch = treeS->GetBranch(branchname);
419 if (branch) branch->SetAddress(&fSDigits);
420
421}
422//___________________________________________________________________
423void AliITSDetTypeSim::SetTreeAddressD(TTree* treeD, Char_t* name){
424 // Set branch address for the digit Trees.
425
426 const char *det[3] = {"SPD","SDD","SSD"};
427 TBranch *branch;
428
429 char branchname[30];
430
431 if(!treeD){
432 return;
433 }
434 if(!fDigits){
435 fDigits = new TObjArray(fgkNdettypes);
436 }
437 for(Int_t i=0;i<fgkNdettypes;i++){
438 Char_t* digclass = GetDigitClassName(i);
439 if(digclass==0x0){
440 if(i==0) SetDigitClassName(i,"AliITSdigitSPD");
441 if(i==1) SetDigitClassName(i,"AliITSdigitSDD");
442 if(i==2) SetDigitClassName(i,"AliITSdigitSSD");
443 digclass = GetDigitClassName(i);
444 }
445 TString classn = digclass;
446 if(!(fDigits->At(i))){
447 fDigits->AddAt(new TClonesArray(classn.Data(),1000),i);
3b9df642 448 }else{
7d62fb64 449 ResetDigits(i);
450 }
451
452 if(fgkNdettypes==3) sprintf(branchname,"%sDigits%s",name,det[i]);
453 else sprintf(branchname,"%sDigits%d",name,i+1);
454 if(fDigits){
455 branch = treeD->GetBranch(branchname);
456 if(branch) branch->SetAddress(&((*fDigits)[i]));
457 }
458 }
3b9df642 459
3b9df642 460}
7d62fb64 461//___________________________________________________________________
462void AliITSDetTypeSim::ResetDigits(){
463 // Reset number of digits and the digits array for the ITS detector.
464
465
466 if(!fDigits){
467 Error("ResetDigits","fDigits is null!");
468 return;
469 }
470 for(Int_t i=0;i<fgkNdettypes;i++){
471 ResetDigits(i);
472 }
473}
474//___________________________________________________________________
475void AliITSDetTypeSim::ResetDigits(Int_t branch){
476 // Reset number of digits and the digits array for this branch.
477
478 if(fDigits->At(branch)){
479 ((TClonesArray*)fDigits->At(branch))->Clear();
480 }
481 if(fNDigits) fNDigits[branch]=0;
482
483}
484
485
486
487//_______________________________________________________________________
488void AliITSDetTypeSim::SDigitsToDigits(Option_t* opt, Char_t* name){
489 // Standard Summable digits to Digits function.
490 if(!fGeom){
491 Warning("SDigitsToDigits","fGeom is null!!");
492 return;
493 }
494
495 const char *all = strstr(opt,"All");
496 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
497 strstr(opt,"SSD")};
498 if( !det[0] && !det[1] && !det[2] ) all = "All";
499 else all = 0;
500 static Bool_t setDef = kTRUE;
501 if(setDef) SetDefaultSimulation();
502 setDef = kFALSE;
503
504 AliITSsimulation *sim =0;
505 TTree* trees = fLoader->TreeS();
506 if( !(trees && GetSDigits()) ){
507 Error("SDigits2Digits","Error: No trees or SDigits. Returning.");
508 return;
509 }
510 sprintf(name,"%s",name);
511 TBranch* brchSDigits = trees->GetBranch(name);
512
513 Int_t id;
514 for(Int_t module=0;module<fGeom->GetIndexMax();module++){
515 id = fGeom->GetModuleType(module);
516 if (!all && !det[id]) continue;
517 sim = (AliITSsimulation*)GetSimulationModel(id);
518 if(!sim){
519 Error("SDigit2Digits","The simulation class was not "
520 "instanciated for module %d type %s!",module,
521 fGeom->GetModuleTypeName(module));
522 exit(1);
523 }
524 sim->InitSimulationModule(module,gAlice->GetEvNumber());
525
526 fSDigits->Clear();
527 brchSDigits->GetEvent(module);
528 sim->AddSDigitsToModule(fSDigits,0);
529 sim->FinishSDigitiseModule();
530 fLoader->TreeD()->Fill();
531 ResetDigits();
532 }
533 fLoader->TreeD()->GetEntries();
534 fLoader->TreeD()->AutoSave();
535 fLoader->TreeD()->Reset();
536}
537
538
539
540//_________________________________________________________
541void AliITSDetTypeSim::AddSumDigit(AliITSpListItem &sdig){
542
543 //Adds the module full of summable digits to the summable digits tree.
544 TClonesArray &lsdig = *fSDigits;
545 new(lsdig[fNSDigits++]) AliITSpListItem(sdig);
546}
547//__________________________________________________________
548void AliITSDetTypeSim::AddRealDigit(Int_t branch, Int_t *digits){
549 // Add a real digit - as coming from data.
550 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
551 new(ldigits[fNDigits[branch]++]) AliITSdigit(digits);
552}
553//__________________________________________________________
554void AliITSDetTypeSim::AddSimDigit(Int_t branch, AliITSdigit* d){
555
556 // Add a simulated digit.
557 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
558 switch(branch){
559 case 0:
560 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(*((AliITSdigitSPD*)d));
561 break;
562 case 1:
563 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(*((AliITSdigitSDD*)d));
564 break;
565 case 2:
566 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(*((AliITSdigitSSD*)d));
567 break;
568 }
569
570
571}
572
3b9df642 573//______________________________________________________________________
7d62fb64 574void AliITSDetTypeSim::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,
575 Int_t *tracks,Int_t *hits,Float_t *charges){
576 // Add a simulated digit to the list.
577
578 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
579 AliITSresponseSDD *resp = 0;
580 switch(branch){
581 case 0:
582 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(digits,tracks,hits);
583 break;
584 case 1:
585 resp = (AliITSresponseSDD*)GetResponseModel(fGeom->GetStartSDD());
586 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(phys,digits,tracks,
587 hits,charges,resp);
588 break;
589 case 2:
590 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(digits,tracks,hits);
591 break;
592 }
3b9df642 593}