1 /***************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
20 /////////////////////////////////////////////////////////////////////
21 // Base simulation functions for ITS //
24 /////////////////////////////////////////////////////////////////////
26 #include "TClonesArray.h"
27 #include "TObjArray.h"
31 #include "AliITSdigit.h"
32 #include "AliITSdigitSPD.h"
33 #include "AliITSdigitSDD.h"
34 #include "AliITSdigitSSD.h"
35 #include "AliITSDetTypeSim.h"
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"
50 const Int_t AliITSDetTypeSim::fgkNdettypes = 3;
52 ClassImp(AliITSDetTypeSim)
54 //----------------------------------------------------------------------
55 AliITSDetTypeSim::AliITSDetTypeSim():
58 fSimulation(), // [NDet]
59 fSegmentation(), // [NDet]
60 fResponse(), // [NMod]
61 fPreProcess(), // [] e.g. Fill fHitModule with hits
62 fPostProcess(), // [] e.g. Wright Raw data
63 fNSDigits(0), //! number of SDigits
64 fSDigits(), //! [NMod][NSDigits]
65 fNDigits(0), //! number of Digits
66 fDigits(), //! [NMod][NDigits]
67 fHitClassName(), // String with Hit class name.
68 fSDigClassName(),// String with SDigit class name.
69 fDigClassName(){ // String with digit class name.
70 // Default Constructor
76 // A properly zero-ed AliITSDetTypeSim class.
78 fSimulation = new TObjArray(fgkNdettypes);
79 fSegmentation = new TObjArray(fgkNdettypes);
84 fSDigits = new TClonesArray("AliITSpListItem",1000);
85 fDigits = new TObjArray(fgkNdettypes);
86 fNDigits = new Int_t[fgkNdettypes];
89 //----------------------------------------------------------------------
90 AliITSDetTypeSim::~AliITSDetTypeSim(){
99 if(fGeom) delete fGeom;
101 fSimulation->Delete();
107 fSegmentation->Delete();
108 delete fSegmentation;
119 fPreProcess->Delete();
125 fPostProcess->Delete();
132 fLoader->GetModulesFolder()->Remove(this);
148 //----------------------------------------------------------------------
149 AliITSDetTypeSim::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");
158 //----------------------------------------------------------------------
159 AliITSDetTypeSim& AliITSDetTypeSim::operator=(const AliITSDetTypeSim &source){
160 // The = operator for object AliITSDetTypeSim
162 if(&source==this) return *this;
163 Error("operator=","You are not allowed to make a copy of the AliITSDetTypeSIm");
169 //______________________________________________________________________
170 void AliITSDetTypeSim::SetSimulationModel(Int_t dettype,AliITSsimulation *sim){
172 //Set simulation model for detector type
174 if(fSimulation==0) fSimulation = new TObjArray(fgkNdettypes);
175 fSimulation->AddAt(sim,dettype);
177 //______________________________________________________________________
178 AliITSsimulation* AliITSDetTypeSim::GetSimulationModel(Int_t dettype){
180 //Get simulation model for detector type
182 Warning("GetSimulationModel","fSimulation is 0!");
185 return (AliITSsimulation*)(fSimulation->At(dettype));
187 //______________________________________________________________________
188 AliITSsimulation* AliITSDetTypeSim::GetSimulationModelByModule(Int_t module){
190 //Get simulation model by module number
192 Warning("GetSimulationModelByModule","fGeom is 0!");
196 return GetSimulationModel(fGeom->GetModuleType(module));
198 //______________________________________________________________________
199 void AliITSDetTypeSim::SetSegmentationModel(Int_t dettype,AliITSsegmentation *seg){
201 //Set segmentation model for detector type
202 if(fSegmentation==0x0) fSegmentation = new TObjArray(fgkNdettypes);
203 fSegmentation->AddAt(seg,dettype);
206 //______________________________________________________________________
207 AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModel(Int_t dettype){
209 //Get segmentation model for detector type
211 if(fSegmentation==0) {
212 Warning("GetSegmentationModel","fSegmentation is 0!");
215 return (AliITSsegmentation*)(fSegmentation->At(dettype));
218 //_______________________________________________________________________
219 AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModelByModule(Int_t module){
221 //Get segmentation model by module number
223 Warning("GetSegmentationModelByModule","fGeom is 0!");
226 return GetSegmentationModel(fGeom->GetModuleType(module));
229 //_______________________________________________________________________
230 void AliITSDetTypeSim::SetResponseModel(Int_t module,AliITSresponse *resp){
233 //Set segmentation model for module number
234 if(fResponse==0) fResponse = new TObjArray(fGeom->GetIndexMax());
235 fResponse->AddAt(resp,module);
237 //______________________________________________________________________
238 void AliITSDetTypeSim::ResetResponse(){
240 //resets response array
242 for(Int_t i=0;i<fResponse->GetEntries();i++){
243 if(fResponse->At(i)) delete (AliITSresponse*)fResponse->At(i);
247 //______________________________________________________________________
248 void AliITSDetTypeSim::ResetSegmentation(){
250 //Resets segmentation array
252 for(Int_t i=0;i<fgkNdettypes;i++){
253 if(fSegmentation->At(i)) delete (AliITSsegmentation*)fSegmentation->At(i);
258 //_______________________________________________________________________
259 AliITSresponse* AliITSDetTypeSim::GetResponseModel(Int_t module){
261 //Get segmentation model for module number
264 Warning("GetResponseModel","fResponse is 0!");
267 return (AliITSresponse*)(fResponse->At(module));
269 //_______________________________________________________________________
270 void AliITSDetTypeSim::SetDefaults(){
272 //Set defaults for segmentation and response
276 Warning("SetDefaults","fGeom is 0!");
280 if(!fResponse) fResponse = new TObjArray(fGeom->GetIndexMax());
282 AliITSsegmentation* seg;
287 for(Int_t imod=0;imod<fGeom->GetIndexMax();imod++){
288 Int_t dettype = fGeom->GetModuleType(imod);
291 if(!GetSegmentationModel(dettype)){
292 seg = new AliITSsegmentationSPD(fGeom);
293 SetSegmentationModel(dettype,seg);
295 if(!GetResponseModel(imod)){
296 res = new AliITSresponseSPD();
297 SetResponseModel(imod,res);
299 const char *kData0=(GetResponseModel(imod))->DataType();
300 if (strstr(kData0,"real")) {
301 SetDigitClassName(dettype,"AliITSdigit");
302 } else SetDigitClassName(dettype,"AliITSdigitSPD");
306 if(!GetResponseModel(imod)){
307 SetResponseModel(imod,new AliITSresponseSDD("simulated"));
309 if(!GetSegmentationModel(dettype)){
310 res = GetResponseModel(imod);
311 seg = new AliITSsegmentationSDD(fGeom,res);
312 SetSegmentationModel(dettype,seg);
314 const char *kopt = GetResponseModel(imod)->ZeroSuppOption();
315 if((!strstr(kopt,"2D"))&&(!strstr(kopt,"1D"))) SetDigitClassName(dettype,"AliITSdigit");
316 else SetDigitClassName(dettype,"AliITSdigitSDD");
320 if(!GetSegmentationModel(dettype)){
321 seg = new AliITSsegmentationSSD(fGeom);
322 SetSegmentationModel(dettype,seg);
324 if(!GetResponseModel(imod)){
325 SetResponseModel(imod,new AliITSresponseSSD("simulated"));
327 const char *kData2 = (GetResponseModel(imod))->DataType();
328 if (strstr(kData2,"real")) {
329 SetDigitClassName(dettype,"AliITSdigit");
330 } else SetDigitClassName(dettype,"AliITSdigitSSD");
338 //_______________________________________________________________________
339 void AliITSDetTypeSim::SetDefaultSimulation(){
341 //Set default simulation for detector type
345 Warning("SetDefaults","fGeom is 0!");
349 if(!fResponse) fResponse = new TObjArray(fGeom->GetIndexMax());
351 AliITSsegmentation* seg;
353 AliITSsimulation* sim;
355 for(Int_t idet=0;idet<fgkNdettypes;idet++){
358 sim = GetSimulationModel(idet);
360 seg = (AliITSsegmentationSPD*)GetSegmentationModel(idet);
361 res = (AliITSresponseSPD*)GetResponseModel(fGeom->GetStartSPD());
362 sim = new AliITSsimulationSPD(seg,res);
363 SetSimulationModel(idet,sim);
365 sim->SetResponseModel(GetResponseModel(fGeom->GetStartSPD()));
366 sim->SetSegmentationModel((AliITSsegmentationSPD*)GetSegmentationModel(idet));
372 sim = GetSimulationModel(idet);
374 seg = (AliITSsegmentationSDD*)GetSegmentationModel(idet);
375 res = (AliITSresponseSDD*)GetResponseModel(fGeom->GetStartSDD());
376 sim = new AliITSsimulationSDD(seg,res);
377 SetSimulationModel(idet,sim);
379 sim->SetResponseModel((AliITSresponseSDD*)GetResponseModel(fGeom->GetStartSDD()));
380 sim->SetSegmentationModel((AliITSsegmentationSDD*)GetSegmentationModel(idet));
387 sim = GetSimulationModel(idet);
389 seg = (AliITSsegmentationSSD*)GetSegmentationModel(idet);
390 res = (AliITSresponseSSD*)GetResponseModel(fGeom->GetStartSSD());
391 sim = new AliITSsimulationSSD(seg,res);
392 SetSimulationModel(idet,sim);
394 sim->SetResponseModel((AliITSresponseSSD*)GetResponseModel(fGeom->GetStartSSD()));
395 sim->SetSegmentationModel((AliITSsegmentationSSD*)GetSegmentationModel(idet));
404 //___________________________________________________________________
405 void AliITSDetTypeSim::SetTreeAddressS(TTree* treeS, Char_t* name){
406 // Set branch address for the ITS summable digits Trees.
413 if (fSDigits == 0x0){
414 fSDigits = new TClonesArray("AliITSpListItem",1000);
417 sprintf(branchname,"%s",name);
418 branch = treeS->GetBranch(branchname);
419 if (branch) branch->SetAddress(&fSDigits);
422 //___________________________________________________________________
423 void AliITSDetTypeSim::SetTreeAddressD(TTree* treeD, Char_t* name){
424 // Set branch address for the digit Trees.
426 const char *det[3] = {"SPD","SDD","SSD"};
435 fDigits = new TObjArray(fgkNdettypes);
437 for(Int_t i=0;i<fgkNdettypes;i++){
438 Char_t* digclass = GetDigitClassName(i);
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);
445 TString classn = digclass;
446 if(!(fDigits->At(i))){
447 fDigits->AddAt(new TClonesArray(classn.Data(),1000),i);
452 if(fgkNdettypes==3) sprintf(branchname,"%sDigits%s",name,det[i]);
453 else sprintf(branchname,"%sDigits%d",name,i+1);
455 branch = treeD->GetBranch(branchname);
456 if(branch) branch->SetAddress(&((*fDigits)[i]));
461 //___________________________________________________________________
462 void AliITSDetTypeSim::ResetDigits(){
463 // Reset number of digits and the digits array for the ITS detector.
467 Error("ResetDigits","fDigits is null!");
470 for(Int_t i=0;i<fgkNdettypes;i++){
474 //___________________________________________________________________
475 void AliITSDetTypeSim::ResetDigits(Int_t branch){
476 // Reset number of digits and the digits array for this branch.
478 if(fDigits->At(branch)){
479 ((TClonesArray*)fDigits->At(branch))->Clear();
481 if(fNDigits) fNDigits[branch]=0;
487 //_______________________________________________________________________
488 void AliITSDetTypeSim::SDigitsToDigits(Option_t* opt, Char_t* name){
489 // Standard Summable digits to Digits function.
491 Warning("SDigitsToDigits","fGeom is null!!");
495 const char *all = strstr(opt,"All");
496 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
498 if( !det[0] && !det[1] && !det[2] ) all = "All";
500 static Bool_t setDef = kTRUE;
501 if(setDef) SetDefaultSimulation();
504 AliITSsimulation *sim =0;
505 TTree* trees = fLoader->TreeS();
506 if( !(trees && GetSDigits()) ){
507 Error("SDigits2Digits","Error: No trees or SDigits. Returning.");
510 sprintf(name,"%s",name);
511 TBranch* brchSDigits = trees->GetBranch(name);
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);
519 Error("SDigit2Digits","The simulation class was not "
520 "instanciated for module %d type %s!",module,
521 fGeom->GetModuleTypeName(module));
524 sim->InitSimulationModule(module,gAlice->GetEvNumber());
527 brchSDigits->GetEvent(module);
528 sim->AddSDigitsToModule(fSDigits,0);
529 sim->FinishSDigitiseModule();
530 fLoader->TreeD()->Fill();
533 fLoader->TreeD()->GetEntries();
534 fLoader->TreeD()->AutoSave();
535 fLoader->TreeD()->Reset();
540 //_________________________________________________________
541 void AliITSDetTypeSim::AddSumDigit(AliITSpListItem &sdig){
543 //Adds the module full of summable digits to the summable digits tree.
544 TClonesArray &lsdig = *fSDigits;
545 new(lsdig[fNSDigits++]) AliITSpListItem(sdig);
547 //__________________________________________________________
548 void 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);
553 //__________________________________________________________
554 void AliITSDetTypeSim::AddSimDigit(Int_t branch, AliITSdigit* d){
556 // Add a simulated digit.
557 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
560 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(*((AliITSdigitSPD*)d));
563 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(*((AliITSdigitSDD*)d));
566 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(*((AliITSdigitSSD*)d));
573 //______________________________________________________________________
574 void 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.
578 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
579 AliITSresponseSDD *resp = 0;
582 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(digits,tracks,hits);
585 resp = (AliITSresponseSDD*)GetResponseModel(fGeom->GetStartSDD());
586 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(phys,digits,tracks,
590 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(digits,tracks,hits);