]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPCDigitizer.cxx
removing AnalisysManager warning
[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));
394 gime = rl->GetLoader("TPCLoader");
395
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();
405 Int_t * masks = new Int_t[nInputs];
406 for (Int_t i=0; i<nInputs;i++)
407 masks[i]= fManager->GetMask(i);
f648982e 408
712976a6 409 //AliSimDigits ** digarr = new AliSimDigits*[nInputs];
410 AliSimDigits ** digarr =0x0;
411 digarr = new AliSimDigits*[nInputs];
88cb7938 412 for (Int_t i1=0;i1<nInputs; i1++)
413 {
f648982e 414 digarr[i1]=0;
415 // intree[i1]
88cb7938 416 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i1));
417 gime = rl->GetLoader("TPCLoader");
418
419 TTree * treear = gime->TreeS();
f648982e 420 TBranch * br = treear->GetBranch("fSegmentID");
421 if (br) br->GetFile()->cd();
f648982e 422 if (!treear) {
423 cerr<<" TPC - not existing input = \n"<<i1<<" ";
424 }
f648982e 425 treear->GetBranch("Segment")->SetAddress(&digarr[i1]);
f648982e 426 }
88cb7938 427
428 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
429 gime = rl->GetLoader("TPCLoader");
430 Stat_t nentries = gime->TreeS()->GetEntries();
f648982e 431
432
433 //create branch's in TPC treeD
434 AliSimDigits * digrow = new AliSimDigits;
88cb7938 435 TTree * tree = ogime->TreeD();
436
f648982e 437 tree->Branch("Segment","AliSimDigits",&digrow);
f648982e 438 param->SetZeroSup(2);
439
440 Int_t zerosup = param->GetZeroSup();
441 //Loop over segments of the TPC
442
5033a39a 443 AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetDedxGainFactor();
1ac191a6 444 AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
f648982e 445 for (Int_t n=0; n<nentries; n++) {
88cb7938 446 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
447 gime = rl->GetLoader("TPCLoader");
448 gime->TreeS()->GetEvent(n);
449
f648982e 450 digarr[0]->ExpandBuffer();
451 digarr[0]->ExpandTrackBuffer();
13116aec 452
453
f648982e 454 for (Int_t i=1;i<nInputs; i++){
88cb7938 455// fManager->GetInputTreeTPCS(i)->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());
456 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i));
457 gime = rl->GetLoader("TPCLoader");
458 gime->TreeS()->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());
f648982e 459 digarr[i]->ExpandBuffer();
460 digarr[i]->ExpandTrackBuffer();
461 if ((digarr[0]->GetID()-digarr[i]->GetID())>0)
88cb7938 462 printf("problem\n");
f648982e 463
464 }
465
466 Int_t sec, row;
467 if (!param->AdjustSectorRow(digarr[0]->GetID(),sec,row)) {
468 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr[0]->GetID()<<endl;
469 continue;
470 }
471
13116aec 472 AliTPCCalROC * gainROC = gainTPC->GetCalROC(sec); // pad gains per given sector
1ac191a6 473 AliTPCCalROC * noiseROC = noiseTPC->GetCalROC(sec); // noise per given sector
f648982e 474 digrow->SetID(digarr[0]->GetID());
475
476 Int_t nrows = digarr[0]->GetNRows();
477 Int_t ncols = digarr[0]->GetNCols();
478 digrow->Allocate(nrows,ncols);
479 digrow->AllocateTrack(3);
480
481 Float_t q=0;
482 Int_t label[1000]; //stack for 300 events
483 Int_t labptr = 0;
484
485
486
487 for (Int_t rows=0;rows<nrows; rows++){
488 for (Int_t col=0;col<ncols; col++){
489
88cb7938 490 q=0;
491 labptr=0;
492 // looop over digits
f648982e 493 for (Int_t i=0;i<nInputs; i++){
88cb7938 494 q += digarr[i]->GetDigitFast(rows,col);
f648982e 495 //q += *(pdig[i]);
88cb7938 496
f648982e 497 for (Int_t tr=0;tr<3;tr++) {
88cb7938 498 Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
499 //Int_t lab = ptr[i][tr*nElems];
f648982e 500 if ( (lab > 1) ) {
501 label[labptr]=lab+masks[i];
502 labptr++;
88cb7938 503 }
f648982e 504 }
88cb7938 505 // pdig[i]++;
506 //ptr[i]++;
507
f648982e 508 }
88cb7938 509 q/=16.; //conversion factor
510 // Float_t noise = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac());
13116aec 511 Float_t gain = gainROC->GetValue(row,col);
512 q*= gain;
1ac191a6 513 Float_t noisePad = noiseROC->GetValue(row, col);
514
88cb7938 515 Float_t noise = pTPC->GetNoise();
1ac191a6 516 q+=noise*noisePad;
633fa37f 517
f648982e 518 q=TMath::Nint(q);
519 if (q > zerosup){
88cb7938 520
e93a083a 521 if(q >= param->GetADCSat()) q = (Short_t)(param->GetADCSat() - 1);
88cb7938 522 digrow->SetDigitFast((Short_t)q,rows,col);
523 // *pdig1 =Short_t(q);
524 for (Int_t tr=0;tr<3;tr++){
525 if (tr<labptr)
526 ((AliSimDigits*)digrow)->SetTrackIDFast(label[tr],rows,col,tr);
527 //ptr1[tr*nElems] = label[tr];
528 //else
529 // ((AliSimDigits*)digrow)->SetTrackIDFast(-1,rows,col,tr);
530 // ptr1[tr*nElems] = 1;
531 }
532 }
533 //pdig1++;
534 //ptr1++;
f648982e 535 }
536 }
537
538 digrow->CompresBuffer(1,zerosup);
539 digrow->CompresTrackBuffer(1);
540 tree->Fill();
541 if (fDebug>0) cerr<<sec<<"\t"<<row<<"\n";
542 }
88cb7938 543// printf("end TPC merging - end -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
544 //fManager->GetTreeDTPC()->Write(0,TObject::kOverwrite);
545 ogime->WriteDigits("OVERWRITE");
546
547 for (Int_t i=1;i<nInputs; i++)
548 {
549 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i));
550 gime = rl->GetLoader("TPCLoader");
551 gime->UnloadSDigits();
552 }
553 ogime->UnloadDigits();
554
f648982e 555 delete digrow;
556 for (Int_t i1=0;i1<nInputs; i1++) delete digarr[i1];
4ce766eb 557 delete [] masks;
558 delete [] digarr;
f648982e 559}