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