]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/UPGRADE/AliITSDetTypeSimUpg.cxx
Decoupled ITS/UPGRADE cmake stuff from ITS
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSDetTypeSimUpg.cxx
CommitLineData
a84c4b15 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: AliITSDetTypeSimUpg.cxx 56993 2012-06-08 08:24:17Z fca $
18*/
19
20
21/////////////////////////////////////////////////////////////////////
22// Base simulation functions for ITS upgrade //
23// //
24// //
25/////////////////////////////////////////////////////////////////////
26#include "TBranch.h"
27#include "TClonesArray.h"
28#include "TObjArray.h"
29#include "TTree.h"
30
31#include "AliRun.h"
32
33#include "AliCDBManager.h"
34#include "AliCDBId.h"
35#include "AliCDBStorage.h"
36#include "AliCDBEntry.h"
37#include "AliCDBMetaData.h"
38#include "AliITSdigit.h"
39#include "AliITSdigitPixUpg.h"
40#include "AliITSgeom.h"
41#include "AliITSDetTypeSimUpg.h"
42#include "AliITSpListItem.h"
43#include "AliITSCalibration.h"
44#include "AliITSsimulation.h"
45#include "AliITSTriggerConditions.h"
46#include "AliITSsegmentation.h"
47#include "AliITSsegmentationPixUpg.h"
48#include "AliBaseLoader.h"
49
50using std::endl;
51using std::cout;
52ClassImp(AliITSDetTypeSimUpg)
53
54const char* AliITSDetTypeSimUpg::fgkDetTypeName[AliITSDetTypeSimUpg::kNDetTypes] = {"PixUpg"};
55
56
57//----------------------------------------------------------------------
58AliITSDetTypeSimUpg::AliITSDetTypeSimUpg():
59TObject(),
60fSimulation(), // [NDet]
61fSegmentation(), // [NDet]
62fCalibration(), // [NMod]
63fNSDigits(0), //! number of SDigits
64fSDigits("AliITSpListItem",1000),
65fNDigits(0), //! number of Digits
66fRunNumber(0), //! Run number (to access DB)
67fDigits(), //! [NMod][NDigits]
68fSimuPar(0),
69fkDigClassName(), // String with digit class name.
70fLoader(0), // local pointer to loader
71fFirstcall(kTRUE),
72fTriggerConditions(NULL)
73{
74 // Default Constructor
75 // Inputs:
76 // none.
77 // Outputs:
78 // none.
79 // Return:
80 // A properly zero-ed AliITSDetTypeSimUpg class.
81 for (int i=kNDetTypes;i--;) fDetNModules[i] = 0;
82 fSimulation = new TObjArray(kNDetTypes);
83 fSegmentation = new TObjArray(kNDetTypes);
84 fSegmentation->SetOwner(kTRUE);
85 fDigits = new TObjArray(kNDetTypes);
86 fNDigits = new Int_t[kNDetTypes];
87 fSimuPar= new AliITSSimuParam();
88 SetRunNumber();
89}
90
91//----------------------------------------------------------------------
92AliITSDetTypeSimUpg::~AliITSDetTypeSimUpg()
93{
94 // Destructor
95 // Inputs:
96 // none.
97 // Outputs:
98 // none.
99 // Return:
100 // Nothing.
101
102 if(fSimulation){
103 fSimulation->Delete();
104 delete fSimulation;
105 }
106 //
107 if(fSegmentation){
108 fSegmentation->Delete();
109 delete fSegmentation;
110 }
111 //
112 if(fCalibration && fRunNumber<0){
113 fCalibration->Delete();
114 delete fCalibration;
115 }
116 //
117 delete fSimuPar;
118 delete[] fNDigits;
119 //
120 if (fLoader)fLoader->GetModulesFolder()->Remove(this); // Not deleting it.
121 fSDigits.Delete();
122 if (fDigits) {
123 fDigits->Delete();
124 delete fDigits;
125 }
126 //
127}
128
129//______________________________________________________________________
130void AliITSDetTypeSimUpg::SetITSgeom(AliITSgeom *geom)
131{
132 // Sets/replaces the existing AliITSgeom object kept in AliITSLoader
133 //
134 // Inputs:
135 // AliITSgoem *geom The AliITSgeom object to be used.
136 // Output:
137 // none.
138 // Return:
139 // none.
140 if(!fLoader){
141 Error("SetITSgeom","No pointer to loader - nothing done");
142 return;
143 }
144 else {
145 fLoader->SetITSgeom(geom); // protections in AliITSLoader::SetITSgeom
146 }
147
148}
149
150//______________________________________________________________________
151void AliITSDetTypeSimUpg::SetLoader(AliITSLoader *loader)
152{
153 // Sets the local copy of the AliITSLoader, and passes on the
154 // AliITSgeom object as needed.
155 // Inputs
156 // AliITSLoader *loader pointer to AliITSLoader for local use
157 // Outputs:
158 // none.
159 // Return:
160 // none.
161
162 if(fLoader==loader) return; // Same do nothing
163 if(fLoader){ // alread have an existing loader
164 Error("SetLoader","Already have an exisiting loader ptr=%p Nothing done",fLoader);
165 } // end if
166 fLoader = loader;
167}
168
169//______________________________________________________________________
170void AliITSDetTypeSimUpg::SetSimulationModel(Int_t dettype,AliITSsimulation *sim)
171{
172 //Set simulation model for detector type
173 if(fSimulation==0) fSimulation = new TObjArray(kNDetTypes);
174 fSimulation->AddAt(sim,dettype);
175}
176
177//______________________________________________________________________
178AliITSsimulation* AliITSDetTypeSimUpg::GetSimulationModel(Int_t dettype) const
179{
180 //Get simulation model for detector type
181 if(fSimulation==0) {
182 Warning("GetSimulationModel","fSimulation is 0!");
183 return 0;
184 }
185 return (AliITSsimulation*)(fSimulation->At(dettype));
186}
187
188//______________________________________________________________________
189AliITSsimulation* AliITSDetTypeSimUpg::GetSimulationModelByModule(Int_t module) const
190{
191 //Get simulation model by module number
192 if(GetITSgeom()==0) {
193 Warning("GetSimulationModelByModule","GetITSgeom() is 0!");
194 return 0;
195 }
196
197 return GetSimulationModel(GetITSgeom()->GetModuleType(module));
198}
199
200//_______________________________________________________________________
201void AliITSDetTypeSimUpg::SetDefaultSegmentation(Int_t idet)
202{
203 // Set default segmentation model objects
204 AliITSsegmentation *seg;
205 //
206 if(fSegmentation==0x0){
207 fSegmentation = new TObjArray(kNDetTypes);
208 fSegmentation->SetOwner(kTRUE);
209 }
210 if (GetSegmentationModel(idet)) delete (AliITSsegmentation*)fSegmentation->RemoveAt(idet);
211 //
212 switch (idet)
213 {
214 case kDetPixUpg: seg = new AliITSsegmentationPixUpg(); break;
215 default : AliFatal(Form("Uknown detector type %d",idet));
216 };
217 SetSegmentationModel(idet,seg);
218 //
219}
220
221//______________________________________________________________________
222void AliITSDetTypeSimUpg::SetSegmentationModel(Int_t dettype, AliITSsegmentation *seg)
223{
224 // Set segmentation model for detector type
225 if(fSegmentation==0x0){
226 fSegmentation = new TObjArray(kNDetTypes);
227 fSegmentation->SetOwner(kTRUE);
228 }
229 fSegmentation->AddAt(seg,dettype);
230}
231
232//______________________________________________________________________
233AliITSsegmentation* AliITSDetTypeSimUpg::GetSegmentationModel(Int_t dettype) const
234{
235 //Get segmentation model for detector type
236
237 if(fSegmentation==0) {
238 Warning("GetSegmentationModel","fSegmentation is 0!");
239 return 0;
240 }
241 return (AliITSsegmentation*)(fSegmentation->At(dettype));
242}
243
244//_______________________________________________________________________
245AliITSsegmentation* AliITSDetTypeSimUpg::GetSegmentationModelByModule(Int_t module) const
246{
247 //Get segmentation model by module number
248 if(GetITSgeom()==0) {
249 Warning("GetSegmentationModelByModule","GetITSgeom() is 0!");
250 return 0;
251 }
252 return GetSegmentationModel(GetITSgeom()->GetModuleType(module));
253 //
254}
255
256//_______________________________________________________________________
257void AliITSDetTypeSimUpg::CreateCalibrationArray()
258{
259 //Create the container of calibration functions with correct size
260 if (fCalibration) {
261 Warning("CreateCalibration","pointer to calibration object exists\n");
262 fCalibration->Delete();
263 delete fCalibration;
264 }
265 //
266 Int_t nModTot = GetITSgeom()->GetIndexMax();
267 fCalibration = new TObjArray(nModTot);
268 fCalibration->SetOwner(kTRUE);
269 fCalibration->Clear();
270}
271
272//_______________________________________________________________________
273void AliITSDetTypeSimUpg::SetCalibrationModel(Int_t iMod, AliITSCalibration *resp)
274{
275 //Set response model for modules
276
277 if (fCalibration==0) CreateCalibrationArray();
278
279 if (fCalibration->At(iMod)!=0) delete (AliITSCalibration*) fCalibration->At(iMod);
280 fCalibration->AddAt(resp, iMod);
281}
282
283//______________________________________________________________________
284void AliITSDetTypeSimUpg::ResetCalibrationArray()
285{
286 //resets response array
287 fCalibration->Clear();
288}
289
290//______________________________________________________________________
291void AliITSDetTypeSimUpg::ResetSegmentation()
292{
293 //Resets segmentation array
294 if(fSegmentation) fSegmentation->Clear();
295}
296
297//_______________________________________________________________________
298AliITSCalibration* AliITSDetTypeSimUpg::GetCalibrationModel(Int_t iMod) const
299{
300 //Get response model for module number iMod
301 //
302 if(fCalibration==0) {
303 AliError("fCalibration is 0!");
304 return 0;
305 }
306 return (AliITSCalibration*)fCalibration->At(iMod);
307}
308
309//_______________________________________________________________________
310void AliITSDetTypeSimUpg::SetDefaults()
311{
312 //Set defaults for segmentation and response
313
314 if(GetITSgeom()==0){
315 Warning("SetDefaults","GetITSgeom() is 0!");
316 return;
317 } // end if
318 if (fCalibration==0) {
319 CreateCalibrationArray();
320 } // end if
321
322 ResetSegmentation();
323 if(!GetCalibration()){AliFatal("Exit"); exit(0);}
324
325 SetDigitClassName(0,"AliITSdigitPixUpg");
326 //
327 for(Int_t idet=0;idet<kNDetTypes;idet++){
328 if(!GetSegmentationModel(idet)) SetDefaultSegmentation(idet);
329 }
330 //
331}
332
333//______________________________________________________________________
334Bool_t AliITSDetTypeSimUpg::GetCalibration() {
335 // Get Default calibration if a storage is not defined.
336
337 if(!fFirstcall){
338 AliITSCalibration* cal = GetCalibrationModel(0);
339 if(cal)return kTRUE;
340 }
341 else {
342 fFirstcall = kFALSE;
343 }
344
345 SetRunNumber((Int_t)AliCDBManager::Instance()->GetRun());
346 Int_t run=GetRunNumber();
347
348 Bool_t isCacheActive = kTRUE;
349 if (run) {
350 isCacheActive=kFALSE;
351 fCalibration->SetOwner(kTRUE);
352 }
353 else{
354 fCalibration->SetOwner(kFALSE);
355 }
356
357 AliCDBManager::Instance()->SetCacheFlag(isCacheActive);
358 //
359 // TO DO, RS
360 return kTRUE;
361}
362
363//_______________________________________________________________________
364void AliITSDetTypeSimUpg::SetDefaultSimulation()
365{
366 //Set default simulation for detector type
367 //
368 if (GetITSgeom()==0) {
369 Warning("SetDefaultSimulation","GetITSgeom() is 0!");
370 return;
371 }
372 if (fCalibration==0) {
373 Warning("SetDefaultSimulation","fCalibration is 0!");
374 return;
375 }
376 if (fSegmentation==0) {
377 Warning("SetDefaultSimulation","fSegmentation is 0!");
378 for (Int_t i=0;i<kNDetTypes;i++) SetDefaultSegmentation(i);
379 } else for(Int_t i=0;i<kNDetTypes;i++) if(!GetSegmentationModel(i)){
380 Warning("SetDefaultSimulation",
381 "Segmentation not defined for det %d - Default taken\n!",i);
382 SetDefaultSegmentation(i);
383 }
384 //
385 AliITSsimulation* sim;
386 //
387 for (Int_t idet=0;idet<kNDetTypes;idet++) {
388 //OixUpg
389 if(idet==0){
390 sim = GetSimulationModel(idet);
391 if(!sim){
392 sim = new AliITSsimulationPixUpg(this);
393 SetSimulationModel(idet,sim);
394 }
395 }
396 }
397}
398
399//___________________________________________________________________
400void AliITSDetTypeSimUpg::SetTreeAddressS(TTree* treeS, const Char_t* name)
401{
402 // Set branch address for the ITS summable digits Trees.
403
404 if(!treeS) return;
405 TBranch *branch;
406 branch = treeS->GetBranch(name);
407 TClonesArray *sdigi = &fSDigits;
408 if (branch) branch->SetAddress(&sdigi);
409
410}
411
412//___________________________________________________________________
413void AliITSDetTypeSimUpg::SetTreeAddressD(TTree* treeD, const Char_t* name)
414{
415 // Set branch address for the digit Trees.
416 TBranch *branch;
417 TString branchname;
418 //
419 if(!treeD) return;
420 //
421 if(!fDigits) fDigits = new TObjArray(kNDetTypes);
422 //
423 for(Int_t i=0;i<kNDetTypes;i++){
424 const Char_t* digclass = GetDigitClassName(i);
425 if(digclass==0x0){
426 if(i==0) SetDigitClassName(i,Form("AliITSdigit%s",fgkDetTypeName[i]));
427 digclass = GetDigitClassName(i);
428 }
429 TString classn = digclass;
430 if(!(fDigits->At(i))){
431 fDigits->AddAt(new TClonesArray(classn.Data(),1000),i);
432 }else{
433 ResetDigits(i);
434 }
435 //
436 if(kNDetTypes==3) branchname.Form("%sDigits%s",name,fgkDetTypeName[i]);
437 branch = treeD->GetBranch(branchname.Data());
438 if(branch) branch->SetAddress(&((*fDigits)[i]));
439 }
440}
441
442//___________________________________________________________________
443void AliITSDetTypeSimUpg::ResetDigits()
444{
445 // Reset number of digits and the digits array for the ITS detector.
446 //
447 if(!fDigits){
448 Error("ResetDigits","fDigits is null!");
449 return;
450 }
451 for(Int_t i=0;i<kNDetTypes;i++) ResetDigits(i);
452 //
453}
454
455//___________________________________________________________________
456void AliITSDetTypeSimUpg::ResetDigits(Int_t branch)
457{
458 // Reset number of digits and the digits array for this branch.
459 //
460 if (fDigits->At(branch)) ((TClonesArray*)fDigits->At(branch))->Clear();
461 if(fNDigits) fNDigits[branch]=0;
462}
463
464//_______________________________________________________________________
465void AliITSDetTypeSimUpg::SDigitsToDigits(Option_t* opt, Char_t* name)
466{
467 // Standard Summable digits to Digits function.
468 if(!GetITSgeom()){
469 Warning("SDigitsToDigits","GetITSgeom() is null!!");
470 return;
471 }
472 //
473 static Bool_t setDef = kTRUE;
474 if(setDef) SetDefaultSimulation();
475 setDef = kFALSE;
476 //
477 AliITSsimulation *sim =0;
478 TTree* trees = fLoader->TreeS();
479 if( !(trees && GetSDigits()) ){
480 Error("SDigits2Digits","Error: No trees or SDigits. Returning.");
481 return;
482 }
483 //
484 TBranch* brchSDigits = trees->GetBranch(name);
485 //
486 Int_t id;
487 for(Int_t module=0;module<GetITSgeom()->GetIndexMax();module++) {
488 //
489 id = GetITSgeom()->GetModuleType(module);
490 sim = (AliITSsimulation*)GetSimulationModel(id);
491 if(!sim){
492 AliFatal(Form("The simulation class was not instanciated for module %d type %s!",
493 module,GetITSgeom()->GetModuleTypeName(module)));
494 }
495 sim->InitSimulationModule(module,gAlice->GetEvNumber());
496 //
497 fSDigits.Clear();
498 brchSDigits->GetEvent(module);
499 sim->AddSDigitsToModule(&fSDigits,0);
500 sim->FinishSDigitiseModule();
501 fLoader->TreeD()->Fill();
502 ResetDigits();
503 }
504 //
505 // WriteFOSignals();
506 fLoader->TreeD()->GetEntries();
507 fLoader->TreeD()->AutoSave();
508 fLoader->TreeD()->Reset();
509}
510
511//_________________________________________________________
512void AliITSDetTypeSimUpg::AddSumDigit(AliITSpListItem &sdig)
513{
514 //Adds the module full of summable digits to the summable digits tree.
515 new(fSDigits[fNSDigits++]) AliITSpListItem(sdig);
516}
517
518//__________________________________________________________
519void AliITSDetTypeSimUpg::AddSimDigit(Int_t branch, const AliITSdigit* d)
520{
521 // Add a simulated digit.
522 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
523 switch(branch){
524 case kDetPixUpg:
525 new(ldigits[fNDigits[branch]++]) AliITSdigitPixUpg(*((AliITSdigitPixUpg*)d));
526 break;
527 default:
528 AliFatal(Form("Digit for unknown detector type %d",branch));
529 }
530}
531
532//______________________________________________________________________
533void AliITSDetTypeSimUpg::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,
534 Int_t *tracks,Int_t *hits,Float_t *charges,
535 Int_t sigexpanded)
536{
537 // Add a simulated digit to the list.
538
539 TClonesArray &ldigits = *((TClonesArray*)fDigits->At(branch));
540 switch(branch){
541 case kDetPixUpg:
542 new(ldigits[fNDigits[branch]++]) AliITSdigitPixUpg(digits,tracks,hits);
543 break;
544 default:
545 AliFatal(Form("Digit for unknown detector type %d",branch));
546 }
547}
548
549//_______________________________________________________________________
550AliITSTriggerConditions* AliITSDetTypeSimUpg::GetTriggerConditions()
551{
552 // Get Pixel Trigger Conditions (separate method since it is used only when simulating trigger)
553 if (fTriggerConditions==NULL) { // read from db
554 fRunNumber = ((Int_t)AliCDBManager::Instance()->GetRun());
555 Bool_t origCacheStatus = AliCDBManager::Instance()->GetCacheFlag();
556 Bool_t isCacheActive;
557 if (fRunNumber<0) isCacheActive=kFALSE;
558 else isCacheActive=kTRUE;
559 AliCDBManager::Instance()->SetCacheFlag(isCacheActive);
560 AliCDBEntry *pitCond = AliCDBManager::Instance()->Get("TRIGGER/SPD/PITConditions", fRunNumber);
561 if (!pitCond) {
562 AliError("Trigger conditions retrieval failed! ");
563 return NULL;
564 }
565 fTriggerConditions = (AliITSTriggerConditions*) pitCond->GetObject();
566 if (!isCacheActive) pitCond->SetObject(NULL);
567 pitCond->SetOwner(kTRUE);
568 if (!isCacheActive) {
569 delete pitCond;
570 }
571 AliCDBManager::Instance()->SetCacheFlag(origCacheStatus);
572 if (fTriggerConditions==NULL) {
573 AliWarning("fTriggerConditions is NULL!");
574 }
575 }
576 return fTriggerConditions;
577}
578