1 /**************************************************************************
2 * Copyright(c) 1998-2000, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 Class for creating of the sumable digits and digits from MC data
21 The input : ideal signals (Hits->Diffusion->Attachment -Ideal signal)
22 The output: raw digits
25 1. Pad by pad gain map
27 3. The dead channels identified - zerro noise for corresponding pads
28 In this case the outpu equal zerro
37 #include <TObjArray.h>
39 #include <TDirectory.h>
40 #include <Riostream.h>
42 #include "AliTPCDigitizer.h"
45 #include "AliTPCParam.h"
46 #include "AliTPCParamSR.h"
49 #include "AliRunDigitizer.h"
50 #include "AliSimDigits.h"
53 #include "AliTPCcalibDB.h"
54 #include "AliTPCCalPad.h"
55 #include "AliTPCCalROC.h"
57 ClassImp(AliTPCDigitizer)
59 //___________________________________________
60 AliTPCDigitizer::AliTPCDigitizer() :AliDigitizer(),fDebug(0)
63 // Default ctor - don't use it
68 //___________________________________________
69 AliTPCDigitizer::AliTPCDigitizer(AliRunDigitizer* manager)
70 :AliDigitizer(manager),fDebug(0)
73 // ctor which should be used
75 AliDebug(2,"(AliRunDigitizer* manager) was processed");
78 //------------------------------------------------------------------------
79 AliTPCDigitizer::~AliTPCDigitizer()
86 //------------------------------------------------------------------------
87 Bool_t AliTPCDigitizer::Init()
95 //------------------------------------------------------------------------
96 void AliTPCDigitizer::Exec(Option_t* option)
100 //------------------------------------------------------------------------
101 void AliTPCDigitizer::ExecFast(Option_t* option)
104 // merge input tree's with summable digits
105 //output stored in TreeTPCD
108 TString optionString = option;
109 if (!strcmp(optionString.Data(),"deb")) {
110 cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl;
113 //get detector and geometry
116 AliRunLoader *rl, *orl;
117 AliLoader *gime, *ogime;
121 Warning("ExecFast","gAlice is NULL. Loading from input 0");
122 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
125 Error("ExecFast","Can not find Run Loader for input 0. Can not proceed.");
131 AliTPC *pTPC = (AliTPC *) gAlice->GetModule("TPC");
132 AliTPCParam * param = pTPC->GetParam();
134 sprintf(s,param->GetTitle());
135 sprintf(ss,"75x40_100x60");
137 printf("2 pad-length geom hits with 3 pad-lenght geom digits...\n");
139 param=new AliTPCParamSR();
142 sprintf(ss,"75x40_100x60_150x60");
143 if(strcmp(s,ss)!=0) {
144 printf("No TPC parameters found...\n");
149 pTPC->GenerNoise(500000); //create teble with noise
151 Int_t nInputs = fManager->GetNinputs();
152 Int_t * masks = new Int_t[nInputs];
153 for (Int_t i=0; i<nInputs;i++)
154 masks[i]= fManager->GetMask(i);
155 Short_t **pdig= new Short_t*[nInputs]; //pointers to the expanded digits array
156 Int_t **ptr= new Int_t*[nInputs]; //pointers to teh expanded tracks array
157 Bool_t *active= new Bool_t[nInputs]; //flag for active input segments
160 //create digits array for given sectors
163 AliSimDigits ** digarr = new AliSimDigits*[nInputs];
164 for (Int_t i1=0;i1<nInputs; i1++)
168 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i1));
169 gime = rl->GetLoader("TPCLoader");
170 gime->LoadSDigits("read");
171 TTree * treear = gime->TreeS();
175 cerr<<"AliTPCDigitizer: Input tree with SDigits not found in"
176 <<" input "<< i1<<endl;
180 if (treear->GetIndex()==0)
181 treear->BuildIndex("fSegmentID","fSegmentID");
182 treear->GetBranch("Segment")->SetAddress(&digarr[i1]);
186 //create branch's in TPC treeD
187 AliSimDigits * digrow = new AliSimDigits;
189 orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
190 ogime = orl->GetLoader("TPCLoader");
192 TTree * tree = ogime->TreeD();
195 ogime->MakeTree("D");
196 tree = ogime->TreeD();
198 tree->Branch("Segment","AliSimDigits",&digrow);
201 param->SetZeroSup(2);
203 Int_t zerosup = param->GetZeroSup();
204 AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetDedxGainFactor();
205 AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
207 //Loop over segments of the TPC
209 for (Int_t segmentID=0; segmentID<param->GetNRowsTotal(); segmentID++)
212 if (!param->AdjustSectorRow(segmentID,sec,row))
214 cerr<<"AliTPC warning: invalid segment ID ! "<<segmentID<<endl;
217 AliTPCCalROC * gainROC = gainTPC->GetCalROC(sec); // pad gains per given sector
218 AliTPCCalROC * noiseROC = noiseTPC->GetCalROC(sec); // noise per given sector
219 digrow->SetID(segmentID);
224 Bool_t digitize = kFALSE;
225 for (Int_t i=0;i<nInputs; i++)
228 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i));
229 gime = rl->GetLoader("TPCLoader");
231 if (gime->TreeS()->GetEntryWithIndex(segmentID,segmentID) >= 0) {
232 digarr[i]->ExpandBuffer();
233 digarr[i]->ExpandTrackBuffer();
234 nrows = digarr[i]->GetNRows();
235 ncols = digarr[i]->GetNCols();
237 if (!fRegionOfInterest || (i == 0)) digitize = kTRUE;
241 if (fRegionOfInterest && !digitize) break;
243 if (!digitize) continue;
245 digrow->Allocate(nrows,ncols);
246 digrow->AllocateTrack(3);
249 Int_t label[1000]; //stack for 300 events
252 Int_t nElems = nrows*ncols;
254 for (Int_t i=0;i<nInputs; i++)
256 pdig[i] = digarr[i]->GetDigits();
257 ptr[i] = digarr[i]->GetTracks();
260 Short_t *pdig1= digrow->GetDigits();
261 Int_t *ptr1= digrow->GetTracks() ;
265 for (Int_t elem=0;elem<nElems; elem++)
271 for (Int_t i=0;i<nInputs; i++) if (active[i])
273 // q += digarr[i]->GetDigitFast(rows,col);
276 for (Int_t tr=0;tr<3;tr++)
278 // Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
279 Int_t lab = ptr[i][tr*nElems];
280 if ( (lab > 1) && *(pdig[i])>zerosup)
282 label[labptr]=lab+masks[i];
289 q/=16.; //conversion factor
290 Float_t gain = gainROC->GetValue(row,elem/nrows); // get gain for given - pad-row pad
292 //printf("problem\n");
295 Float_t noisePad = noiseROC->GetValue(row,elem/nrows);
296 // Float_t noise = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac());
297 Float_t noise = pTPC->GetNoise();
302 if(q >= param->GetADCSat()) q = (Short_t)(param->GetADCSat() - 1);
303 //digrow->SetDigitFast((Short_t)q,rows,col);
305 for (Int_t tr=0;tr<3;tr++)
308 ptr1[tr*nElems] = label[tr];
317 digrow->GlitchFilter();
319 digrow->CompresBuffer(1,zerosup);
320 digrow->CompresTrackBuffer(1);
322 if (fDebug>0) cerr<<sec<<"\t"<<row<<"\n";
323 } //for (Int_t n=0; n<param->GetNRowsTotal(); n++)
326 orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
327 ogime = orl->GetLoader("TPCLoader");
328 ogime->WriteDigits("OVERWRITE");
330 //fManager->GetTreeDTPC()->Write(0,TObject::kOverwrite);
333 for (Int_t i1=0;i1<nInputs; i1++) delete digarr[i1];
343 //------------------------------------------------------------------------
344 void AliTPCDigitizer::ExecSave(Option_t* option)
347 // merge input tree's with summable digits
348 //output stored in TreeTPCD
350 TString optionString = option;
351 if (!strcmp(optionString.Data(),"deb")) {
352 cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl;
355 //get detector and geometry
356 AliRunLoader *rl, *orl;
357 AliLoader *gime, *ogime;
360 orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
361 ogime = orl->GetLoader("TPCLoader");
363 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
364 gime = rl->GetLoader("TPCLoader");
367 AliRun* alirun = rl->GetAliRun();
369 AliTPC *pTPC = (AliTPC *) alirun->GetModule("TPC");
370 AliTPCParam * param = pTPC->GetParam();
371 pTPC->GenerNoise(500000); //create teble with noise
372 printf("noise %f \n", param->GetNoise()*param->GetNoiseNormFac());
374 Int_t nInputs = fManager->GetNinputs();
375 Int_t * masks = new Int_t[nInputs];
376 for (Int_t i=0; i<nInputs;i++)
377 masks[i]= fManager->GetMask(i);
379 AliSimDigits ** digarr = new AliSimDigits*[nInputs];
380 for (Int_t i1=0;i1<nInputs; i1++)
384 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i1));
385 gime = rl->GetLoader("TPCLoader");
387 TTree * treear = gime->TreeS();
388 TBranch * br = treear->GetBranch("fSegmentID");
389 if (br) br->GetFile()->cd();
391 cerr<<" TPC - not existing input = \n"<<i1<<" ";
393 treear->GetBranch("Segment")->SetAddress(&digarr[i1]);
396 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
397 gime = rl->GetLoader("TPCLoader");
398 Stat_t nentries = gime->TreeS()->GetEntries();
401 //create branch's in TPC treeD
402 AliSimDigits * digrow = new AliSimDigits;
403 TTree * tree = ogime->TreeD();
405 tree->Branch("Segment","AliSimDigits",&digrow);
406 param->SetZeroSup(2);
408 Int_t zerosup = param->GetZeroSup();
409 //Loop over segments of the TPC
411 AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetDedxGainFactor();
412 AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
413 for (Int_t n=0; n<nentries; n++) {
414 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
415 gime = rl->GetLoader("TPCLoader");
416 gime->TreeS()->GetEvent(n);
418 digarr[0]->ExpandBuffer();
419 digarr[0]->ExpandTrackBuffer();
422 for (Int_t i=1;i<nInputs; i++){
423 // fManager->GetInputTreeTPCS(i)->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());
424 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i));
425 gime = rl->GetLoader("TPCLoader");
426 gime->TreeS()->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());
427 digarr[i]->ExpandBuffer();
428 digarr[i]->ExpandTrackBuffer();
429 if ((digarr[0]->GetID()-digarr[i]->GetID())>0)
435 if (!param->AdjustSectorRow(digarr[0]->GetID(),sec,row)) {
436 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr[0]->GetID()<<endl;
440 AliTPCCalROC * gainROC = gainTPC->GetCalROC(sec); // pad gains per given sector
441 AliTPCCalROC * noiseROC = noiseTPC->GetCalROC(sec); // noise per given sector
442 digrow->SetID(digarr[0]->GetID());
444 Int_t nrows = digarr[0]->GetNRows();
445 Int_t ncols = digarr[0]->GetNCols();
446 digrow->Allocate(nrows,ncols);
447 digrow->AllocateTrack(3);
450 Int_t label[1000]; //stack for 300 events
455 for (Int_t rows=0;rows<nrows; rows++){
456 for (Int_t col=0;col<ncols; col++){
461 for (Int_t i=0;i<nInputs; i++){
462 q += digarr[i]->GetDigitFast(rows,col);
465 for (Int_t tr=0;tr<3;tr++) {
466 Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
467 //Int_t lab = ptr[i][tr*nElems];
469 label[labptr]=lab+masks[i];
477 q/=16.; //conversion factor
478 // Float_t noise = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac());
479 Float_t gain = gainROC->GetValue(row,col);
481 Float_t noisePad = noiseROC->GetValue(row, col);
483 Float_t noise = pTPC->GetNoise();
489 if(q >= param->GetADCSat()) q = (Short_t)(param->GetADCSat() - 1);
490 digrow->SetDigitFast((Short_t)q,rows,col);
491 // *pdig1 =Short_t(q);
492 for (Int_t tr=0;tr<3;tr++){
494 ((AliSimDigits*)digrow)->SetTrackIDFast(label[tr],rows,col,tr);
495 //ptr1[tr*nElems] = label[tr];
497 // ((AliSimDigits*)digrow)->SetTrackIDFast(-1,rows,col,tr);
498 // ptr1[tr*nElems] = 1;
506 digrow->CompresBuffer(1,zerosup);
507 digrow->CompresTrackBuffer(1);
509 if (fDebug>0) cerr<<sec<<"\t"<<row<<"\n";
511 // printf("end TPC merging - end -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
512 //fManager->GetTreeDTPC()->Write(0,TObject::kOverwrite);
513 ogime->WriteDigits("OVERWRITE");
515 for (Int_t i=1;i<nInputs; i++)
517 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i));
518 gime = rl->GetLoader("TPCLoader");
519 gime->UnloadSDigits();
521 ogime->UnloadDigits();
524 for (Int_t i1=0;i1<nInputs; i1++) delete digarr[i1];