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