]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPCDigitizer.cxx
code defects fix
[u/mrichter/AliRoot.git] / TPC / AliTPCDigitizer.cxx
CommitLineData
3c038d07 1/**************************************************************************
2 * Copyright(c) 1998-2000, 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
88cb7938 16/* $Id$ */
d37f8c34 17
f94f8f87 18/*
19 Class for creating of the sumable digits and digits from MC data
20 //
21 The input : ideal signals (Hits->Diffusion->Attachment -Ideal signal)
22 The output: raw digits
23
24 Effect implemented:
25 1. Pad by pad gain map
26 2. Noise map
27 3. The dead channels identified - zerro noise for corresponding pads
28 In this case the outpu equal zerro
29
30*/
31
32
33
34
d37f8c34 35#include <stdlib.h>
3c038d07 36#include <TTree.h>
37#include <TObjArray.h>
38#include <TFile.h>
39#include <TDirectory.h>
19364939 40#include <Riostream.h>
f546a4b4 41#include <TParameter.h>
3c038d07 42
43#include "AliTPCDigitizer.h"
44
45#include "AliTPC.h"
46#include "AliTPCParam.h"
7a09f434 47#include "AliTPCParamSR.h"
3c038d07 48#include "AliRun.h"
49#include "AliPDG.h"
50#include "AliRunDigitizer.h"
51#include "AliSimDigits.h"
f77f13c8 52#include "AliLog.h"
3c038d07 53
13116aec 54#include "AliTPCcalibDB.h"
55#include "AliTPCCalPad.h"
56#include "AliTPCCalROC.h"
57
3c038d07 58ClassImp(AliTPCDigitizer)
59
60//___________________________________________
179c6296 61 AliTPCDigitizer::AliTPCDigitizer() :AliDigitizer(),fDebug(0)
3c038d07 62{
179c6296 63 //
3c038d07 64// Default ctor - don't use it
179c6296 65//
66
3c038d07 67}
68
69//___________________________________________
70AliTPCDigitizer::AliTPCDigitizer(AliRunDigitizer* manager)
179c6296 71 :AliDigitizer(manager),fDebug(0)
3c038d07 72{
179c6296 73 //
3c038d07 74// ctor which should be used
179c6296 75//
f77f13c8 76 AliDebug(2,"(AliRunDigitizer* manager) was processed");
3c038d07 77}
78
79//------------------------------------------------------------------------
80AliTPCDigitizer::~AliTPCDigitizer()
81{
82// Destructor
83}
84
85
86
87//------------------------------------------------------------------------
88Bool_t AliTPCDigitizer::Init()
89{
90// Initialization
91
92 return kTRUE;
93}
94
95
96//------------------------------------------------------------------------
97void AliTPCDigitizer::Exec(Option_t* option)
f648982e 98{
99 ExecFast(option);
100}
101//------------------------------------------------------------------------
102void AliTPCDigitizer::ExecFast(Option_t* option)
3c038d07 103{
104
105 // merge input tree's with summable digits
106 //output stored in TreeTPCD
7a09f434 107 char s[100];
108 char ss[100];
3c038d07 109 TString optionString = option;
94bf739c 110 if (!strcmp(optionString.Data(),"deb")) {
3c038d07 111 cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl;
112 fDebug = 3;
113 }
114 //get detector and geometry
88cb7938 115
116
117 AliRunLoader *rl, *orl;
118 AliLoader *gime, *ogime;
119
120 if (gAlice == 0x0)
121 {
122 Warning("ExecFast","gAlice is NULL. Loading from input 0");
123 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
124 if (rl == 0x0)
125 {
126 Error("ExecFast","Can not find Run Loader for input 0. Can not proceed.");
127 return;
128 }
129 rl->LoadgAlice();
130 rl->GetAliRun();
131 }
3c038d07 132 AliTPC *pTPC = (AliTPC *) gAlice->GetModule("TPC");
133 AliTPCParam * param = pTPC->GetParam();
7a09f434 134
135 sprintf(s,param->GetTitle());
136 sprintf(ss,"75x40_100x60");
137 if(strcmp(s,ss)==0){
138 printf("2 pad-length geom hits with 3 pad-lenght geom digits...\n");
139 delete param;
140 param=new AliTPCParamSR();
141 }
142 else{
143 sprintf(ss,"75x40_100x60_150x60");
144 if(strcmp(s,ss)!=0) {
145 printf("No TPC parameters found...\n");
146 exit(2);
147 }
148 }
149
f546a4b4 150 pTPC->GenerNoise(500000); //create table with noise
407ff276 151 //
152 Int_t nInputs = fManager->GetNinputs();
153 Int_t * masks = new Int_t[nInputs];
154 for (Int_t i=0; i<nInputs;i++)
155 masks[i]= fManager->GetMask(i);
156 Short_t **pdig= new Short_t*[nInputs]; //pointers to the expanded digits array
f546a4b4 157 Int_t **ptr= new Int_t*[nInputs]; //pointers to the expanded tracks array
4df28b43 158 Bool_t *active= new Bool_t[nInputs]; //flag for active input segments
f546a4b4 159 Char_t phname[100];
88cb7938 160
3c038d07 161 //create digits array for given sectors
f648982e 162 // make indexes
f546a4b4 163 //
164 //create branch's in TPC treeD
165 orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
166 ogime = orl->GetLoader("TPCLoader");
167 TTree * tree = ogime->TreeD();
168 AliSimDigits * digrow = new AliSimDigits;
169
170 if (tree == 0x0)
171 {
172 ogime->MakeTree("D");
173 tree = ogime->TreeD();
174 }
175 tree->Branch("Segment","AliSimDigits",&digrow);
176 //
407ff276 177 AliSimDigits ** digarr = new AliSimDigits*[nInputs];
88cb7938 178 for (Int_t i1=0;i1<nInputs; i1++)
179 {
180 digarr[i1]=0;
181 // intree[i1]
182 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i1));
183 gime = rl->GetLoader("TPCLoader");
184 gime->LoadSDigits("read");
185 TTree * treear = gime->TreeS();
186
187 if (!treear)
188 {
189 cerr<<"AliTPCDigitizer: Input tree with SDigits not found in"
190 <<" input "<< i1<<endl;
712976a6 191 for (Int_t i2=0;i2<i1+1; i2++){
192
193 if(digarr[i2]) delete digarr[i2];
194 }
195 delete [] digarr;
196 delete [] active;
197 delete []masks;
198 delete []pdig;
199 delete []ptr;
88cb7938 200 return;
201 }
f546a4b4 202
203 sprintf(phname,"lhcphase%d",i1);
204 TParameter<float> *ph = (TParameter<float>*)treear->GetUserInfo()
205 ->FindObject("lhcphase0");
206 if(!ph){
207 cerr<<"AliTPCDigitizer: LHC phase not found in"
208 <<" input "<< i1<<endl;
712976a6 209 for (Int_t i2=0;i2<i1+1; i2++){
210 if(digarr[i2]) delete digarr[i2];
211 }
212 delete [] digarr;
213 delete [] active;
214 delete []masks;
215 delete []pdig;
216 delete []ptr;
f546a4b4 217 return;
218 }
219 tree->GetUserInfo()->Add(new TParameter<float>(phname,ph->GetVal()));
220 //
88cb7938 221 if (treear->GetIndex()==0)
222 treear->BuildIndex("fSegmentID","fSegmentID");
223 treear->GetBranch("Segment")->SetAddress(&digarr[i1]);
12d8d654 224 }
88cb7938 225
3c038d07 226
88cb7938 227
f546a4b4 228
3c038d07 229 //
230
407ff276 231 param->SetZeroSup(2);
232
f648982e 233 Int_t zerosup = param->GetZeroSup();
5033a39a 234 AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetDedxGainFactor();
1ac191a6 235 AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
f648982e 236 //
3c038d07 237 //Loop over segments of the TPC
238
4df28b43 239 for (Int_t segmentID=0; segmentID<param->GetNRowsTotal(); segmentID++)
88cb7938 240 {
4df28b43 241 Int_t sec, row;
242 if (!param->AdjustSectorRow(segmentID,sec,row))
243 {
244 cerr<<"AliTPC warning: invalid segment ID ! "<<segmentID<<endl;
245 continue;
246 }
13116aec 247 AliTPCCalROC * gainROC = gainTPC->GetCalROC(sec); // pad gains per given sector
1ac191a6 248 AliTPCCalROC * noiseROC = noiseTPC->GetCalROC(sec); // noise per given sector
4df28b43 249 digrow->SetID(segmentID);
250
251 Int_t nrows = 0;
252 Int_t ncols = 0;
253
254 Bool_t digitize = kFALSE;
255 for (Int_t i=0;i<nInputs; i++)
88cb7938 256 {
257
258 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i));
259 gime = rl->GetLoader("TPCLoader");
260
4df28b43 261 if (gime->TreeS()->GetEntryWithIndex(segmentID,segmentID) >= 0) {
262 digarr[i]->ExpandBuffer();
263 digarr[i]->ExpandTrackBuffer();
264 nrows = digarr[i]->GetNRows();
265 ncols = digarr[i]->GetNCols();
266 active[i] = kTRUE;
267 if (!fRegionOfInterest || (i == 0)) digitize = kTRUE;
268 } else {
269 active[i] = kFALSE;
270 }
271 if (fRegionOfInterest && !digitize) break;
88cb7938 272 }
4df28b43 273 if (!digitize) continue;
3c038d07 274
3c038d07 275 digrow->Allocate(nrows,ncols);
276 digrow->AllocateTrack(3);
277
407ff276 278 Float_t q=0;
279 Int_t label[1000]; //stack for 300 events
280 Int_t labptr = 0;
281
f648982e 282 Int_t nElems = nrows*ncols;
283
88cb7938 284 for (Int_t i=0;i<nInputs; i++)
4df28b43 285 if (active[i]) {
88cb7938 286 pdig[i] = digarr[i]->GetDigits();
287 ptr[i] = digarr[i]->GetTracks();
4df28b43 288 }
88cb7938 289
407ff276 290 Short_t *pdig1= digrow->GetDigits();
291 Int_t *ptr1= digrow->GetTracks() ;
292
f648982e 293
407ff276 294
88cb7938 295 for (Int_t elem=0;elem<nElems; elem++)
296 {
297
298 q=0;
299 labptr=0;
300 // looop over digits
4df28b43 301 for (Int_t i=0;i<nInputs; i++) if (active[i])
88cb7938 302 {
303 // q += digarr[i]->GetDigitFast(rows,col);
304 q += *(pdig[i]);
305
306 for (Int_t tr=0;tr<3;tr++)
307 {
308 // Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
309 Int_t lab = ptr[i][tr*nElems];
310 if ( (lab > 1) && *(pdig[i])>zerosup)
311 {
312 label[labptr]=lab+masks[i];
313 labptr++;
314 }
315 }
316 pdig[i]++;
317 ptr[i]++;
318 }
319 q/=16.; //conversion factor
13116aec 320 Float_t gain = gainROC->GetValue(row,elem/nrows); // get gain for given - pad-row pad
ebf9a79e 321 //if (gain<0.5){
322 //printf("problem\n");
323 //}
13116aec 324 q*= gain;
1ac191a6 325 Float_t noisePad = noiseROC->GetValue(row,elem/nrows);
88cb7938 326 // Float_t noise = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac());
327 Float_t noise = pTPC->GetNoise();
1ac191a6 328 q+=noise*noisePad;
3c038d07 329 q=TMath::Nint(q);
88cb7938 330 if (q > zerosup)
331 {
e93a083a 332 if(q >= param->GetADCSat()) q = (Short_t)(param->GetADCSat() - 1);
88cb7938 333 //digrow->SetDigitFast((Short_t)q,rows,col);
334 *pdig1 =Short_t(q);
335 for (Int_t tr=0;tr<3;tr++)
336 {
337 if (tr<labptr)
338 ptr1[tr*nElems] = label[tr];
339 }
340 }
341 pdig1++;
342 ptr1++;
343 }
58c45a5e 344 //
345 // glitch filter
346 //
347 digrow->GlitchFilter();
348 //
3c038d07 349 digrow->CompresBuffer(1,zerosup);
350 digrow->CompresTrackBuffer(1);
351 tree->Fill();
352 if (fDebug>0) cerr<<sec<<"\t"<<row<<"\n";
4df28b43 353 } //for (Int_t n=0; n<param->GetNRowsTotal(); n++)
88cb7938 354
355
356 orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
357 ogime = orl->GetLoader("TPCLoader");
358 ogime->WriteDigits("OVERWRITE");
359
360 //fManager->GetTreeDTPC()->Write(0,TObject::kOverwrite);
361
3c038d07 362 delete digrow;
407ff276 363 for (Int_t i1=0;i1<nInputs; i1++) delete digarr[i1];
364 delete []masks;
4df28b43 365 delete []pdig;
366 delete []ptr;
367 delete []active;
368 delete []digarr;
3c038d07 369}
370
f648982e 371
372
373//------------------------------------------------------------------------
374void AliTPCDigitizer::ExecSave(Option_t* option)
375{
376
377 // merge input tree's with summable digits
378 //output stored in TreeTPCD
379
380 TString optionString = option;
94bf739c 381 if (!strcmp(optionString.Data(),"deb")) {
f648982e 382 cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl;
383 fDebug = 3;
384 }
385 //get detector and geometry
88cb7938 386 AliRunLoader *rl, *orl;
387 AliLoader *gime, *ogime;
388
389
390 orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
391 ogime = orl->GetLoader("TPCLoader");
392
393 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
097d753a 394 //gime = rl->GetLoader("TPCLoader");
395 rl->GetLoader("TPCLoader");
88cb7938 396 rl->LoadgAlice();
397 AliRun* alirun = rl->GetAliRun();
398
399 AliTPC *pTPC = (AliTPC *) alirun->GetModule("TPC");
f648982e 400 AliTPCParam * param = pTPC->GetParam();
401 pTPC->GenerNoise(500000); //create teble with noise
402 printf("noise %f \n", param->GetNoise()*param->GetNoiseNormFac());
403 //
404 Int_t nInputs = fManager->GetNinputs();
097d753a 405 // stupid protection...
406 if (nInputs <= 0) return;
407 //
f648982e 408 Int_t * masks = new Int_t[nInputs];
409 for (Int_t i=0; i<nInputs;i++)
410 masks[i]= fManager->GetMask(i);
f648982e 411
606d6545 412 AliSimDigits ** digarr = new AliSimDigits*[nInputs];
413 for(Int_t ii=0;ii<nInputs;ii++) digarr[ii]=0;
414
88cb7938 415 for (Int_t i1=0;i1<nInputs; i1++)
416 {
606d6545 417 //digarr[i1]=0;
f648982e 418 // intree[i1]
88cb7938 419 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i1));
420 gime = rl->GetLoader("TPCLoader");
421
422 TTree * treear = gime->TreeS();
de0e19ab 423 //
f648982e 424 if (!treear) {
de0e19ab 425 cerr<<" TPC - not existing input = \n"<<i1<<" ";
426 delete [] masks;
427 for(Int_t i=0; i<nInputs; i++) delete digarr[i];
428 delete [] digarr;
429 return;
f648982e 430 }
de0e19ab 431 //
432 TBranch * br = treear->GetBranch("fSegmentID");
433 if (br) br->GetFile()->cd();
f648982e 434 treear->GetBranch("Segment")->SetAddress(&digarr[i1]);
de0e19ab 435 }
88cb7938 436
437 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
438 gime = rl->GetLoader("TPCLoader");
439 Stat_t nentries = gime->TreeS()->GetEntries();
f648982e 440
441
442 //create branch's in TPC treeD
443 AliSimDigits * digrow = new AliSimDigits;
88cb7938 444 TTree * tree = ogime->TreeD();
445
f648982e 446 tree->Branch("Segment","AliSimDigits",&digrow);
f648982e 447 param->SetZeroSup(2);
448
449 Int_t zerosup = param->GetZeroSup();
450 //Loop over segments of the TPC
451
5033a39a 452 AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetDedxGainFactor();
1ac191a6 453 AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
f648982e 454 for (Int_t n=0; n<nentries; n++) {
88cb7938 455 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
456 gime = rl->GetLoader("TPCLoader");
457 gime->TreeS()->GetEvent(n);
458
f648982e 459 digarr[0]->ExpandBuffer();
460 digarr[0]->ExpandTrackBuffer();
13116aec 461
462
f648982e 463 for (Int_t i=1;i<nInputs; i++){
88cb7938 464// fManager->GetInputTreeTPCS(i)->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());
465 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i));
466 gime = rl->GetLoader("TPCLoader");
467 gime->TreeS()->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());
f648982e 468 digarr[i]->ExpandBuffer();
469 digarr[i]->ExpandTrackBuffer();
470 if ((digarr[0]->GetID()-digarr[i]->GetID())>0)
88cb7938 471 printf("problem\n");
f648982e 472
473 }
474
475 Int_t sec, row;
476 if (!param->AdjustSectorRow(digarr[0]->GetID(),sec,row)) {
477 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr[0]->GetID()<<endl;
478 continue;
479 }
480
13116aec 481 AliTPCCalROC * gainROC = gainTPC->GetCalROC(sec); // pad gains per given sector
1ac191a6 482 AliTPCCalROC * noiseROC = noiseTPC->GetCalROC(sec); // noise per given sector
f648982e 483 digrow->SetID(digarr[0]->GetID());
484
485 Int_t nrows = digarr[0]->GetNRows();
486 Int_t ncols = digarr[0]->GetNCols();
487 digrow->Allocate(nrows,ncols);
488 digrow->AllocateTrack(3);
489
490 Float_t q=0;
491 Int_t label[1000]; //stack for 300 events
492 Int_t labptr = 0;
493
494
495
496 for (Int_t rows=0;rows<nrows; rows++){
497 for (Int_t col=0;col<ncols; col++){
498
88cb7938 499 q=0;
500 labptr=0;
501 // looop over digits
f648982e 502 for (Int_t i=0;i<nInputs; i++){
88cb7938 503 q += digarr[i]->GetDigitFast(rows,col);
f648982e 504 //q += *(pdig[i]);
88cb7938 505
f648982e 506 for (Int_t tr=0;tr<3;tr++) {
88cb7938 507 Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
508 //Int_t lab = ptr[i][tr*nElems];
f648982e 509 if ( (lab > 1) ) {
510 label[labptr]=lab+masks[i];
511 labptr++;
88cb7938 512 }
f648982e 513 }
88cb7938 514 // pdig[i]++;
515 //ptr[i]++;
516
f648982e 517 }
88cb7938 518 q/=16.; //conversion factor
519 // Float_t noise = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac());
13116aec 520 Float_t gain = gainROC->GetValue(row,col);
521 q*= gain;
1ac191a6 522 Float_t noisePad = noiseROC->GetValue(row, col);
523
88cb7938 524 Float_t noise = pTPC->GetNoise();
1ac191a6 525 q+=noise*noisePad;
633fa37f 526
f648982e 527 q=TMath::Nint(q);
528 if (q > zerosup){
88cb7938 529
e93a083a 530 if(q >= param->GetADCSat()) q = (Short_t)(param->GetADCSat() - 1);
88cb7938 531 digrow->SetDigitFast((Short_t)q,rows,col);
532 // *pdig1 =Short_t(q);
533 for (Int_t tr=0;tr<3;tr++){
534 if (tr<labptr)
535 ((AliSimDigits*)digrow)->SetTrackIDFast(label[tr],rows,col,tr);
536 //ptr1[tr*nElems] = label[tr];
537 //else
538 // ((AliSimDigits*)digrow)->SetTrackIDFast(-1,rows,col,tr);
539 // ptr1[tr*nElems] = 1;
540 }
541 }
542 //pdig1++;
543 //ptr1++;
f648982e 544 }
545 }
546
547 digrow->CompresBuffer(1,zerosup);
548 digrow->CompresTrackBuffer(1);
549 tree->Fill();
550 if (fDebug>0) cerr<<sec<<"\t"<<row<<"\n";
551 }
88cb7938 552// printf("end TPC merging - end -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
553 //fManager->GetTreeDTPC()->Write(0,TObject::kOverwrite);
554 ogime->WriteDigits("OVERWRITE");
555
556 for (Int_t i=1;i<nInputs; i++)
557 {
558 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i));
559 gime = rl->GetLoader("TPCLoader");
560 gime->UnloadSDigits();
561 }
562 ogime->UnloadDigits();
563
f648982e 564 delete digrow;
565 for (Int_t i1=0;i1<nInputs; i1++) delete digarr[i1];
4ce766eb 566 delete [] masks;
567 delete [] digarr;
f648982e 568}