]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSDetTypeSim.cxx
Initialization of AliITSgeom from TGeo for the reconstruction pass. AliITSLoader...
[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
fcf95fc7 20
7d62fb64 21/////////////////////////////////////////////////////////////////////
22// Base simulation functions for ITS //
23// //
24// //
25/////////////////////////////////////////////////////////////////////
26#include "TBranch.h"
27#include "TClonesArray.h"
28#include "TObjArray.h"
29#include "TTree.h"
30
31#include "AliRun.h"
8ba39da9 32
33#include "AliCDBManager.h"
34#include "AliCDBId.h"
35#include "AliCDBStorage.h"
36#include "AliCDBEntry.h"
37#include "AliCDBMetaData.h"
38
7d62fb64 39#include "AliITSdigit.h"
40#include "AliITSdigitSPD.h"
41#include "AliITSdigitSDD.h"
42#include "AliITSdigitSSD.h"
3b9df642 43#include "AliITSDetTypeSim.h"
7d62fb64 44#include "AliITSpListItem.h"
fcf95fc7 45#include "AliITSresponseSDD.h"
46#include "AliITSCalibrationSDD.h"
47#include "AliITSCalibrationSSD.h"
7d62fb64 48#include "AliITSsegmentationSPD.h"
49#include "AliITSsegmentationSDD.h"
50#include "AliITSsegmentationSSD.h"
51#include "AliITSsimulation.h"
52#include "AliITSsimulationSPD.h"
53#include "AliITSsimulationSDD.h"
54#include "AliITSsimulationSSD.h"
55
56
57const Int_t AliITSDetTypeSim::fgkNdettypes = 3;
8ba39da9 58const Int_t AliITSDetTypeSim::fgkDefaultNModulesSPD = 240;
59const Int_t AliITSDetTypeSim::fgkDefaultNModulesSDD = 260;
60const Int_t AliITSDetTypeSim::fgkDefaultNModulesSSD = 1698;
3b9df642 61
62ClassImp(AliITSDetTypeSim)
63
64//----------------------------------------------------------------------
65AliITSDetTypeSim::AliITSDetTypeSim():
66TObject(),
3b9df642 67fSimulation(), // [NDet]
68fSegmentation(), // [NDet]
fcf95fc7 69fCalibration(), // [NMod]
3b9df642 70fPreProcess(), // [] e.g. Fill fHitModule with hits
71fPostProcess(), // [] e.g. Wright Raw data
3b9df642 72fNSDigits(0), //! number of SDigits
73fSDigits(), //! [NMod][NSDigits]
74fNDigits(0), //! number of Digits
023ae34b 75fRunNumber(0), //! Run number (to access DB)
3b9df642 76fDigits(), //! [NMod][NDigits]
77fHitClassName(), // String with Hit class name.
78fSDigClassName(),// String with SDigit class name.
023ae34b 79fDigClassName(), // String with digit class name.
80fLoader(0), // local pointer to loader
81fFirstcall(kTRUE){ // flag
3b9df642 82 // Default Constructor
83 // Inputs:
84 // none.
85 // Outputs:
86 // none.
87 // Return:
88 // A properly zero-ed AliITSDetTypeSim class.
023ae34b 89
7d62fb64 90 fSimulation = new TObjArray(fgkNdettypes);
91 fSegmentation = new TObjArray(fgkNdettypes);
1964ae5f 92 fSegmentation->SetOwner(kTRUE);
7d62fb64 93 fSDigits = new TClonesArray("AliITSpListItem",1000);
94 fDigits = new TObjArray(fgkNdettypes);
95 fNDigits = new Int_t[fgkNdettypes];
8ba39da9 96 fNMod[0] = fgkDefaultNModulesSPD;
97 fNMod[1] = fgkDefaultNModulesSDD;
98 fNMod[2] = fgkDefaultNModulesSSD;
99 SetRunNumber();
3b9df642 100}
101//----------------------------------------------------------------------
102AliITSDetTypeSim::~AliITSDetTypeSim(){
103 // Destructor
104 // Inputs:
105 // none.
106 // Outputs:
107 // none.
108 // Return:
109 // Nothing.
023ae34b 110
7d62fb64 111 if(fSimulation){
023ae34b 112 fSimulation->Delete();
113 delete fSimulation;
7d62fb64 114 }
023ae34b 115 fSimulation = 0;
7d62fb64 116 if(fSegmentation){
023ae34b 117 fSegmentation->Delete();
118 delete fSegmentation;
7d62fb64 119 }
023ae34b 120 fSegmentation = 0;
b17dae48 121 if(fCalibration && fRunNumber<0){
023ae34b 122 AliITSresponse* rspd = ((AliITSCalibration*)fCalibration->At(
123 GetITSgeom()->GetStartSPD()))->GetResponse();
124 AliITSresponse* rsdd = ((AliITSCalibration*)fCalibration->At(
125 GetITSgeom()->GetStartSDD()))->GetResponse();
126 AliITSresponse* rssd = ((AliITSCalibration*)fCalibration->At(
127 GetITSgeom()->GetStartSSD()))->GetResponse();
128 if(rspd) delete rspd;
129 if(rsdd) delete rsdd;
130 if(rssd) delete rssd;
131 fCalibration->Delete();
132 delete fCalibration;
7d62fb64 133 }
023ae34b 134 fCalibration = 0;
7d62fb64 135 if(fPreProcess){
023ae34b 136 fPreProcess->Delete();
137 delete fPreProcess;
7d62fb64 138 }
023ae34b 139 fPreProcess = 0;
7d62fb64 140 if(fPostProcess){
023ae34b 141 fPostProcess->Delete();
142 delete fPostProcess;
7d62fb64 143 }
023ae34b 144 fPostProcess = 0;
2a476797 145 if(fNDigits) delete [] fNDigits;
023ae34b 146 fNDigits = 0;
147 if (fLoader)fLoader->GetModulesFolder()->Remove(this);
148 fLoader = 0; // Not deleting it.
7d62fb64 149 if (fSDigits) {
023ae34b 150 fSDigits->Delete();
151 delete fSDigits;
7d62fb64 152 }
023ae34b 153 fSDigits=0;
7d62fb64 154 if (fDigits) {
155 fDigits->Delete();
156 delete fDigits;
7d62fb64 157 }
023ae34b 158 fDigits=0;
3b9df642 159}
160//----------------------------------------------------------------------
7d62fb64 161AliITSDetTypeSim::AliITSDetTypeSim(const AliITSDetTypeSim &source) : TObject(source){
162 // Copy Constructor for object AliITSDetTypeSim not allowed
3b9df642 163
023ae34b 164 if(this==&source) return;
165 Error("Copy constructor",
166 "You are not allowed to make a copy of the AliITSDetTypeSim");
167 exit(1);
3b9df642 168}
169//----------------------------------------------------------------------
7d62fb64 170AliITSDetTypeSim& AliITSDetTypeSim::operator=(const AliITSDetTypeSim &source){
3b9df642 171 // The = operator for object AliITSDetTypeSim
7d62fb64 172
173 if(&source==this) return *this;
023ae34b 174 Error("operator=",
175 "You are not allowed to make a copy of the AliITSDetTypeSIm");
7d62fb64 176 exit(1);
3b9df642 177 return *this;
178}
7d62fb64 179
023ae34b 180//______________________________________________________________________
181void AliITSDetTypeSim::SetITSgeom(AliITSgeom *geom){
182 // Sets/replaces the existing AliITSgeom object kept in AliITSLoader
183 //
184 // Inputs:
185 // AliITSgoem *geom The AliITSgeom object to be used.
186 // Output:
187 // none.
188 // Return:
189 // none.
190 if(!fLoader){
191 Error("SetITSgeom","No pointer to loader - nothing done");
192 return;
193 }
194 else {
195 fLoader->SetITSgeom(geom); // protections in AliITSLoader::SetITSgeom
196 }
197
198}
199//______________________________________________________________________
200void AliITSDetTypeSim::SetLoader(AliITSLoader *loader){
201 // Sets the local copy of the AliITSLoader, and passes on the
202 // AliITSgeom object as needed.
203 // Inputs
204 // AliITSLoader *loader pointer to AliITSLoader for local use
205 // Outputs:
206 // none.
207 // Return:
208 // none.
209
210 if(fLoader==loader) return; // Same do nothing
211 if(fLoader){ // alread have an existing loader
212 Error("SetLoader",
213 "Already have an exisiting loader ptr=%p Nothing done",
214 fLoader);
215 } // end if
216 fLoader = loader;
217}
3b9df642 218//______________________________________________________________________
7d62fb64 219void AliITSDetTypeSim::SetSimulationModel(Int_t dettype,AliITSsimulation *sim){
220
221 //Set simulation model for detector type
222
223 if(fSimulation==0) fSimulation = new TObjArray(fgkNdettypes);
224 fSimulation->AddAt(sim,dettype);
225}
226//______________________________________________________________________
227AliITSsimulation* AliITSDetTypeSim::GetSimulationModel(Int_t dettype){
228
229 //Get simulation model for detector type
230 if(fSimulation==0) {
231 Warning("GetSimulationModel","fSimulation is 0!");
232 return 0;
233 }
234 return (AliITSsimulation*)(fSimulation->At(dettype));
235}
236//______________________________________________________________________
237AliITSsimulation* AliITSDetTypeSim::GetSimulationModelByModule(Int_t module){
238
239 //Get simulation model by module number
023ae34b 240 if(GetITSgeom()==0) {
241 Warning("GetSimulationModelByModule","GetITSgeom() is 0!");
7d62fb64 242 return 0;
243 }
244
023ae34b 245 return GetSimulationModel(GetITSgeom()->GetModuleType(module));
7d62fb64 246}
fcf95fc7 247//_______________________________________________________________________
1964ae5f 248void AliITSDetTypeSim::SetDefaultSegmentation(Int_t idet){
023ae34b 249 // Set default segmentation model objects
250 AliITSsegmentation *seg;
1964ae5f 251
023ae34b 252 if(fSegmentation==0x0){
253 fSegmentation = new TObjArray(fgkNdettypes);
254 fSegmentation->SetOwner(kTRUE);
255 }
256 if(GetSegmentationModel(idet))
257 delete (AliITSsegmentation*)fSegmentation->At(idet);
258 if(idet==0){
259 seg = new AliITSsegmentationSPD(GetITSgeom());
260 }else if(idet==1){
261 AliITSCalibration* res=GetCalibrationModel(
262 GetITSgeom()->GetStartSDD());
263 seg = new AliITSsegmentationSDD(GetITSgeom(),res);
264 }else {
265 seg = new AliITSsegmentationSSD(GetITSgeom());
266 }
267 SetSegmentationModel(idet,seg);
268}
7d62fb64 269//______________________________________________________________________
023ae34b 270void AliITSDetTypeSim::SetSegmentationModel(Int_t dettype,
271 AliITSsegmentation *seg){
7d62fb64 272
273 //Set segmentation model for detector type
fcf95fc7 274 if(fSegmentation==0x0){
1964ae5f 275 fSegmentation = new TObjArray(fgkNdettypes);
276 fSegmentation->SetOwner(kTRUE);
277 }
7d62fb64 278 fSegmentation->AddAt(seg,dettype);
7d62fb64 279}
280//______________________________________________________________________
281AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModel(Int_t dettype){
7d62fb64 282 //Get segmentation model for detector type
283
284 if(fSegmentation==0) {
023ae34b 285 Warning("GetSegmentationModel","fSegmentation is 0!");
286 return 0;
7d62fb64 287 }
288 return (AliITSsegmentation*)(fSegmentation->At(dettype));
7d62fb64 289}
290//_______________________________________________________________________
291AliITSsegmentation* AliITSDetTypeSim::GetSegmentationModelByModule(Int_t module){
023ae34b 292 //Get segmentation model by module number
293 if(GetITSgeom()==0){
294 Warning("GetSegmentationModelByModule","GetITSgeom() is 0!");
295 return 0;
296 }
297 return GetSegmentationModel(GetITSgeom()->GetModuleType(module));
7d62fb64 298}
299//_______________________________________________________________________
fcf95fc7 300void AliITSDetTypeSim::CreateCalibrationArray() {
023ae34b 301 //Create the container of calibration functions with correct size
302 if (fCalibration) {
303 Warning("CreateCalibration","pointer to calibration object exists\n");
304 fCalibration->Delete();
305 delete fCalibration;
306 }
8ba39da9 307
023ae34b 308 Int_t nModTot = GetITSgeom()->GetIndexMax();
309 fCalibration = new TObjArray(nModTot);
310 fCalibration->SetOwner(kTRUE);
311 fCalibration->Clear();
8ba39da9 312}
313//_______________________________________________________________________
fcf95fc7 314void AliITSDetTypeSim::SetCalibrationModel(Int_t iMod, AliITSCalibration *resp){
023ae34b 315 //Set response model for modules
8ba39da9 316
023ae34b 317 if (fCalibration==0) CreateCalibrationArray();
8ba39da9 318
023ae34b 319 if (fCalibration->At(iMod)!=0)
320 delete (AliITSCalibration*) fCalibration->At(iMod);
321 fCalibration->AddAt(resp, iMod);
8ba39da9 322}
7d62fb64 323//______________________________________________________________________
fcf95fc7 324void AliITSDetTypeSim::ResetCalibrationArray(){
023ae34b 325 //resets response array
326 if(fCalibration && fRunNumber<0){ // if fRunNumber<0 fCalibration is owner
327 AliITSresponse* rspd = ((AliITSCalibration*)fCalibration->At(
328 GetITSgeom()->GetStartSPD()))->GetResponse();
329 AliITSresponse* rsdd = ((AliITSCalibration*)fCalibration->At(
330 GetITSgeom()->GetStartSDD()))->GetResponse();
331 AliITSresponse* rssd = ((AliITSCalibration*)fCalibration->At(
332 GetITSgeom()->GetStartSSD()))->GetResponse();
333 if(rspd) delete rspd;
334 if(rsdd) delete rsdd;
335 if(rssd) delete rssd;
336 fCalibration->Clear();
337 }else if (fCalibration && fRunNumber>=0){
338 fCalibration->Clear();
339 }
7d62fb64 340}
341//______________________________________________________________________
342void AliITSDetTypeSim::ResetSegmentation(){
023ae34b 343 //Resets segmentation array
344 if(fSegmentation) fSegmentation->Clear();
7d62fb64 345}
7d62fb64 346//_______________________________________________________________________
fcf95fc7 347AliITSCalibration* AliITSDetTypeSim::GetCalibrationModel(Int_t iMod){
023ae34b 348 //Get response model for module number iMod
8ba39da9 349
023ae34b 350 if(fCalibration==0) {
351 AliError("fCalibration is 0!");
352 return 0;
353 }
fcf95fc7 354 return (AliITSCalibration*)(fCalibration->At(iMod));
7d62fb64 355}
356//_______________________________________________________________________
357void AliITSDetTypeSim::SetDefaults(){
023ae34b 358 //Set defaults for segmentation and response
359
360 if(GetITSgeom()==0){
361 Warning("SetDefaults","GetITSgeom() is 0!");
362 return;
363 } // end if
364 if (fCalibration==0) {
365 CreateCalibrationArray();
366 } // end if
367
368 ResetSegmentation();
369 if(!GetCalibration()){AliFatal("Exit"); exit(0);}
370
371 for(Int_t idet=0;idet<fgkNdettypes;idet++){
372 //SPD
373 if(idet==0){
374 if(!GetSegmentationModel(idet)) SetDefaultSegmentation(idet);
375 const char *kData0=(GetCalibrationModel(GetITSgeom()->GetStartSPD()))->DataType();
376 if (strstr(kData0,"real")) {
377 SetDigitClassName(idet,"AliITSdigit");
378 }else {
379 SetDigitClassName(idet,"AliITSdigitSPD");
380 } // end if
381 } // end if idet==0
382 //SDD
383 if(idet==1){
384 if(!GetSegmentationModel(idet)) SetDefaultSegmentation(idet);
385 AliITSCalibrationSDD* rsp =
386 (AliITSCalibrationSDD*)GetCalibrationModel(
387 GetITSgeom()->GetStartSDD());
388 const char *kopt = ((AliITSresponseSDD*)rsp->GetResponse())->
389 ZeroSuppOption();
390 if((!strstr(kopt,"2D"))&&(!strstr(kopt,"1D"))) {
391 SetDigitClassName(idet,"AliITSdigit");
392 }else {
393 SetDigitClassName(idet,"AliITSdigitSDD");
394 } // end if
395 } // end if idet==1
396 //SSD
397 if(idet==2){
398 if(!GetSegmentationModel(idet))SetDefaultSegmentation(idet);
399 const char *kData2 = (GetCalibrationModel(
400 GetITSgeom()->GetStartSSD())->DataType());
401 if (strstr(kData2,"real")) {
402 SetDigitClassName(idet,"AliITSdigit");
403 }else {
404 SetDigitClassName(idet,"AliITSdigitSSD");
405 } // end if
406 } // end if idet==2
407 }// end for idet
8ba39da9 408}
8ba39da9 409//______________________________________________________________________
410Bool_t AliITSDetTypeSim::GetCalibration() {
411 // Get Default calibration if a storage is not defined.
7d62fb64 412
b17dae48 413 if(!fFirstcall){
414 AliITSCalibration* cal = GetCalibrationModel(0);
415 if(cal)return kTRUE;
416 }
417 else {
418 fFirstcall = kFALSE;
419 }
420
421 SetRunNumber((Int_t)AliCDBManager::Instance()->GetRun());
422 Int_t run=GetRunNumber();
423 if(run<0)run=0; // if the run number is not yet set, use fake run # 0
424
425 Bool_t origCacheStatus = AliCDBManager::Instance()->GetCacheFlag();
426 Bool_t isCacheActive = kTRUE;
427 if(GetRunNumber()<0){
428 isCacheActive=kFALSE;
429 fCalibration->SetOwner(kTRUE);
430 }
431 else{
432 fCalibration->SetOwner(kFALSE);
433 }
434
435 AliCDBManager::Instance()->SetCacheFlag(isCacheActive);
436
437 AliCDBEntry *entrySPD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSPD", run);
438 AliCDBEntry *entrySDD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSDD", run);
439 AliCDBEntry *entrySSD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSSD", run);
440 AliCDBEntry *entry2SPD = AliCDBManager::Instance()->Get("ITS/Calib/RespSPD", run);
441 AliCDBEntry *entry2SDD = AliCDBManager::Instance()->Get("ITS/Calib/RespSDD", run);
442 AliCDBEntry *entry2SSD = AliCDBManager::Instance()->Get("ITS/Calib/RespSSD", run);
06232459 443
fcf95fc7 444 if(!entrySPD || !entrySDD || !entrySSD || !entry2SPD || !entry2SDD || !entry2SSD){
445 AliWarning("Calibration object retrieval failed! Dummy calibration will be used.");
446 AliCDBStorage *origStorage = AliCDBManager::Instance()->GetDefaultStorage();
447 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
06232459 448
b17dae48 449 entrySPD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSPD", run);
450 entrySDD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSDD", run);
451 entrySSD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSSD", run);
452 entry2SPD = AliCDBManager::Instance()->Get("ITS/Calib/RespSPD", run);
453 entry2SDD = AliCDBManager::Instance()->Get("ITS/Calib/RespSDD", run);
454 entry2SSD = AliCDBManager::Instance()->Get("ITS/Calib/RespSSD", run);
06232459 455
fcf95fc7 456 AliCDBManager::Instance()->SetDefaultStorage(origStorage);
8ba39da9 457 }
8ba39da9 458
06232459 459
b17dae48 460 TObjArray *calSPD = (TObjArray *)entrySPD->GetObject();
461 if(!isCacheActive)entrySPD->SetObject(NULL);
8ba39da9 462 entrySPD->SetOwner(kTRUE);
06232459 463
fcf95fc7 464 AliITSresponseSPD *pSPD = (AliITSresponseSPD*)entry2SPD->GetObject();
b17dae48 465 if(!isCacheActive)entry2SPD->SetObject(NULL);
fcf95fc7 466 entry2SPD->SetOwner(kTRUE);
467
b17dae48 468 TObjArray *calSDD = (TObjArray *)entrySDD->GetObject();
469 if(!isCacheActive)entrySDD->SetObject(NULL);
8ba39da9 470 entrySDD->SetOwner(kTRUE);
06232459 471
fcf95fc7 472 AliITSresponseSDD *pSDD = (AliITSresponseSDD*)entry2SDD->GetObject();
b17dae48 473 if(!isCacheActive)entry2SDD->SetObject(NULL);
fcf95fc7 474 entry2SDD->SetOwner(kTRUE);
475
b17dae48 476 TObjArray *calSSD = (TObjArray *)entrySSD->GetObject();
477 if(!isCacheActive)entrySSD->SetObject(NULL);
8ba39da9 478 entrySSD->SetOwner(kTRUE);
06232459 479
fcf95fc7 480 AliITSresponseSSD *pSSD = (AliITSresponseSSD*)entry2SSD->GetObject();
b17dae48 481 if(!isCacheActive)entry2SSD->SetObject(NULL);
fcf95fc7 482 entry2SSD->SetOwner(kTRUE);
483
b17dae48 484 // DB entries are deleted. In this way metadeta objects are deleted as well
485 if(!isCacheActive){
486 delete entrySPD;
487 delete entrySDD;
488 delete entrySSD;
489 delete entry2SPD;
490 delete entry2SDD;
491 delete entry2SSD;
492 }
fcf95fc7 493
b17dae48 494 AliCDBManager::Instance()->SetCacheFlag(origCacheStatus);
495
fcf95fc7 496 if ((!pSPD)||(!pSDD)||(!pSSD)) {
497 AliWarning("Can not get calibration from calibration database !");
498 return kFALSE;
499 }
b17dae48 500 if ((! calSPD)||(! calSDD)||(! calSSD)) {
8ba39da9 501 AliWarning("Can not get calibration from calibration database !");
502 return kFALSE;
503 }
b17dae48 504 fNMod[0] = calSPD->GetEntries();
505 fNMod[1] = calSDD->GetEntries();
506 fNMod[2] = calSSD->GetEntries();
8ba39da9 507 AliInfo(Form("%i SPD, %i SDD and %i SSD in calibration database",
508 fNMod[0], fNMod[1], fNMod[2]));
b17dae48 509 AliITSCalibration* cal;
8ba39da9 510 for (Int_t i=0; i<fNMod[0]; i++) {
b17dae48 511 cal = (AliITSCalibration*) calSPD->At(i);
512 cal->SetResponse(pSPD);
513 SetCalibrationModel(i, cal);
8ba39da9 514 }
515 for (Int_t i=0; i<fNMod[1]; i++) {
b17dae48 516 cal = (AliITSCalibration*) calSDD->At(i);
517 cal->SetResponse(pSDD);
8ba39da9 518 Int_t iMod = i + fNMod[0];
b17dae48 519 SetCalibrationModel(iMod, cal);
8ba39da9 520 }
521 for (Int_t i=0; i<fNMod[2]; i++) {
b17dae48 522 cal = (AliITSCalibration*) calSSD->At(i);
523 cal->SetResponse(pSSD);
8ba39da9 524 Int_t iMod = i + fNMod[0] + fNMod[1];
b17dae48 525 SetCalibrationModel(iMod, cal);
8ba39da9 526 }
8ba39da9 527 return kTRUE;
7d62fb64 528}
7d62fb64 529//_______________________________________________________________________
530void AliITSDetTypeSim::SetDefaultSimulation(){
7d62fb64 531 //Set default simulation for detector type
532
023ae34b 533 if(GetITSgeom()==0){
534 Warning("SetDefaultSimulation","GetITSgeom() is 0!");
8ba39da9 535 return;
536 }
fcf95fc7 537 if(fCalibration==0){
538 Warning("SetDefaultSimulation","fCalibration is 0!");
7d62fb64 539 return;
540 }
fcf95fc7 541 if(fSegmentation==0){
542 Warning("SetDefaultSimulation","fSegmentation is 0!");
543 for(Int_t i=0;i<fgkNdettypes;i++) SetDefaultSegmentation(i);
023ae34b 544 }else for(Int_t i=0;i<fgkNdettypes;i++) if(!GetSegmentationModel(i)){
545 Warning("SetDefaultSimulation",
546 "Segmentation not defined for det %d - Default taken\n!",i);
547 SetDefaultSegmentation(i);
1964ae5f 548 }
7d62fb64 549 AliITSsimulation* sim;
550
551 for(Int_t idet=0;idet<fgkNdettypes;idet++){
552 //SPD
553 if(idet==0){
023ae34b 554 sim = GetSimulationModel(idet);
7d62fb64 555 if(!sim){
8ba39da9 556 sim = new AliITSsimulationSPD(this);
7d62fb64 557 SetSimulationModel(idet,sim);
7d62fb64 558 }
559 }
560 //SDD
561 if(idet==1){
562 sim = GetSimulationModel(idet);
563 if(!sim){
8ba39da9 564 sim = new AliITSsimulationSDD(this);
7d62fb64 565 SetSimulationModel(idet,sim);
023ae34b 566 }
7d62fb64 567 }
568 //SSD
569 if(idet==2){
570 sim = GetSimulationModel(idet);
571 if(!sim){
8ba39da9 572 sim = new AliITSsimulationSSD(this);
7d62fb64 573 SetSimulationModel(idet,sim);
7d62fb64 574 }
7d62fb64 575 }
576
577 }
578}
7d62fb64 579//___________________________________________________________________
580void AliITSDetTypeSim::SetTreeAddressS(TTree* treeS, Char_t* name){
023ae34b 581 // Set branch address for the ITS summable digits Trees.
7d62fb64 582 char branchname[30];
583
584 if(!treeS){
585 return;
586 }
b17dae48 587 if (fSDigits == 0x0){
7d62fb64 588 fSDigits = new TClonesArray("AliITSpListItem",1000);
589 }
590 TBranch *branch;
591 sprintf(branchname,"%s",name);
592 branch = treeS->GetBranch(branchname);
593 if (branch) branch->SetAddress(&fSDigits);
594
595}
596//___________________________________________________________________
597void AliITSDetTypeSim::SetTreeAddressD(TTree* treeD, Char_t* name){
598 // Set branch address for the digit Trees.
599
600 const char *det[3] = {"SPD","SDD","SSD"};
601 TBranch *branch;
602
603 char branchname[30];
604
605 if(!treeD){
606 return;
607 }
608 if(!fDigits){
609 fDigits = new TObjArray(fgkNdettypes);
610 }
611 for(Int_t i=0;i<fgkNdettypes;i++){
612 Char_t* digclass = GetDigitClassName(i);
613 if(digclass==0x0){
614 if(i==0) SetDigitClassName(i,"AliITSdigitSPD");
615 if(i==1) SetDigitClassName(i,"AliITSdigitSDD");
616 if(i==2) SetDigitClassName(i,"AliITSdigitSSD");
617 digclass = GetDigitClassName(i);
618 }
619 TString classn = digclass;
620 if(!(fDigits->At(i))){
621 fDigits->AddAt(new TClonesArray(classn.Data(),1000),i);
3b9df642 622 }else{
7d62fb64 623 ResetDigits(i);
624 }
625
626 if(fgkNdettypes==3) sprintf(branchname,"%sDigits%s",name,det[i]);
627 else sprintf(branchname,"%sDigits%d",name,i+1);
628 if(fDigits){
629 branch = treeD->GetBranch(branchname);
630 if(branch) branch->SetAddress(&((*fDigits)[i]));
631 }
632 }
3b9df642 633
3b9df642 634}
7d62fb64 635//___________________________________________________________________
636void AliITSDetTypeSim::ResetDigits(){
023ae34b 637 // Reset number of digits and the digits array for the ITS detector.
7d62fb64 638
639 if(!fDigits){
640 Error("ResetDigits","fDigits is null!");
641 return;
642 }
643 for(Int_t i=0;i<fgkNdettypes;i++){
644 ResetDigits(i);
645 }
646}
647//___________________________________________________________________
648void AliITSDetTypeSim::ResetDigits(Int_t branch){
649 // Reset number of digits and the digits array for this branch.
650
651 if(fDigits->At(branch)){
652 ((TClonesArray*)fDigits->At(branch))->Clear();
653 }
654 if(fNDigits) fNDigits[branch]=0;
655
656}
657
658
659
660//_______________________________________________________________________
661void AliITSDetTypeSim::SDigitsToDigits(Option_t* opt, Char_t* name){
662 // Standard Summable digits to Digits function.
023ae34b 663 if(!GetITSgeom()){
664 Warning("SDigitsToDigits","GetITSgeom() is null!!");
7d62fb64 665 return;
666 }
667
668 const char *all = strstr(opt,"All");
669 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
670 strstr(opt,"SSD")};
671 if( !det[0] && !det[1] && !det[2] ) all = "All";
672 else all = 0;
673 static Bool_t setDef = kTRUE;
674 if(setDef) SetDefaultSimulation();
675 setDef = kFALSE;
676
677 AliITSsimulation *sim =0;
678 TTree* trees = fLoader->TreeS();
679 if( !(trees && GetSDigits()) ){
680 Error("SDigits2Digits","Error: No trees or SDigits. Returning.");
681 return;
682 }
683 sprintf(name,"%s",name);
684 TBranch* brchSDigits = trees->GetBranch(name);
685
686 Int_t id;
023ae34b 687 for(Int_t module=0;module<GetITSgeom()->GetIndexMax();module++){
688 id = GetITSgeom()->GetModuleType(module);
7d62fb64 689 if (!all && !det[id]) continue;
690 sim = (AliITSsimulation*)GetSimulationModel(id);
691 if(!sim){
692 Error("SDigit2Digits","The simulation class was not "
693 "instanciated for module %d type %s!",module,
023ae34b 694 GetITSgeom()->GetModuleTypeName(module));
7d62fb64 695 exit(1);
696 }
697 sim->InitSimulationModule(module,gAlice->GetEvNumber());
698
699 fSDigits->Clear();
700 brchSDigits->GetEvent(module);
701 sim->AddSDigitsToModule(fSDigits,0);
702 sim->FinishSDigitiseModule();
703 fLoader->TreeD()->Fill();
704 ResetDigits();
705 }
706 fLoader->TreeD()->GetEntries();
707 fLoader->TreeD()->AutoSave();
708 fLoader->TreeD()->Reset();
709}
7d62fb64 710//_________________________________________________________
023ae34b 711void AliITSDetTypeSim::AddSumDigit(AliITSpListItem &sdig){
7d62fb64 712 //Adds the module full of summable digits to the summable digits tree.
023ae34b 713
7d62fb64 714 TClonesArray &lsdig = *fSDigits;
715 new(lsdig[fNSDigits++]) AliITSpListItem(sdig);
716}
717//__________________________________________________________
718void AliITSDetTypeSim::AddRealDigit(Int_t branch, Int_t *digits){
719 // Add a real digit - as coming from data.
023ae34b 720
7d62fb64 721 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
722 new(ldigits[fNDigits[branch]++]) AliITSdigit(digits);
723}
724//__________________________________________________________
023ae34b 725void AliITSDetTypeSim::AddSimDigit(Int_t branch, AliITSdigit* d){
7d62fb64 726 // Add a simulated digit.
023ae34b 727
7d62fb64 728 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
729 switch(branch){
730 case 0:
731 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(*((AliITSdigitSPD*)d));
732 break;
733 case 1:
734 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(*((AliITSdigitSDD*)d));
735 break;
736 case 2:
737 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(*((AliITSdigitSSD*)d));
738 break;
023ae34b 739 }
7d62fb64 740}
3b9df642 741//______________________________________________________________________
7d62fb64 742void AliITSDetTypeSim::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,
743 Int_t *tracks,Int_t *hits,Float_t *charges){
744 // Add a simulated digit to the list.
745
746 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
fcf95fc7 747 AliITSCalibrationSDD *resp = 0;
7d62fb64 748 switch(branch){
749 case 0:
750 new(ldigits[fNDigits[branch]++]) AliITSdigitSPD(digits,tracks,hits);
751 break;
752 case 1:
023ae34b 753 resp = (AliITSCalibrationSDD*)GetCalibrationModel(
754 GetITSgeom()->GetStartSDD());
7d62fb64 755 new(ldigits[fNDigits[branch]++]) AliITSdigitSDD(phys,digits,tracks,
756 hits,charges,resp);
757 break;
758 case 2:
759 new(ldigits[fNDigits[branch]++]) AliITSdigitSSD(digits,tracks,hits);
760 break;
761 }
3b9df642 762}
8ba39da9 763//______________________________________________________________________
023ae34b 764void AliITSDetTypeSim::StoreCalibration(Int_t firstRun, Int_t lastRun,
765 AliCDBMetaData &md) {
8ba39da9 766 // Store calibration in the calibration database
8ba39da9 767 // The database must be created in an external piece of code (i.e.
768 // a configuration macro )
769
770 if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
06232459 771 AliWarning("No storage set! Will use dummy one");
8ba39da9 772 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
8ba39da9 773 }
774
fcf95fc7 775 if (!fCalibration) {
776 AliError("AliITSCalibration classes are not defined - nothing done");
8ba39da9 777 return;
778 }
fcf95fc7 779 AliCDBId idRespSPD("ITS/Calib/CalibSPD",firstRun, lastRun);
780 AliCDBId idRespSDD("ITS/Calib/CalibSDD",firstRun, lastRun);
781 AliCDBId idRespSSD("ITS/Calib/CalibSSD",firstRun, lastRun);
8ba39da9 782
783 TObjArray respSPD(fNMod[0]);
784 TObjArray respSDD(fNMod[1]-fNMod[0]);
785 TObjArray respSSD(fNMod[2]-fNMod[1]);
786 respSPD.SetOwner(kFALSE);
787 respSSD.SetOwner(kFALSE);
788 respSSD.SetOwner(kFALSE);
789
790 Int_t index[fgkNdettypes];
791 for (Int_t i = 0; i<fgkNdettypes; i++ ) {
792 index[i] = 0;
793 for (Int_t j = 0; j<=i; j++ )
794 index[i]+=fNMod[j];
795 }
796
797 for (Int_t i = 0; i<index[0]; i++ )
fcf95fc7 798 respSPD.Add(fCalibration->At(i));
8ba39da9 799
800 for (Int_t i = index[0]; i<index[1]; i++ )
fcf95fc7 801 respSDD.Add(fCalibration->At(i));
8ba39da9 802
803 for (Int_t i = index[1]; i<index[2]; i++ )
fcf95fc7 804 respSSD.Add(fCalibration->At(i));
8ba39da9 805
06232459 806 AliCDBManager::Instance()->Put(&respSPD, idRespSPD, &md);
807 AliCDBManager::Instance()->Put(&respSDD, idRespSDD, &md);
808 AliCDBManager::Instance()->Put(&respSSD, idRespSSD, &md);
8ba39da9 809}
810
811