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