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 **************************************************************************/
20 #include <TObjArray.h>
22 #include <TDirectory.h>
23 #include <Riostream.h>
25 #include "AliTPCDigitizer.h"
28 #include "AliTPCParam.h"
29 #include "AliTPCParamSR.h"
32 #include "AliRunDigitizer.h"
33 #include "AliSimDigits.h"
36 ClassImp(AliTPCDigitizer)
38 //___________________________________________
39 AliTPCDigitizer::AliTPCDigitizer() :AliDigitizer()
41 // Default ctor - don't use it
45 //___________________________________________
46 AliTPCDigitizer::AliTPCDigitizer(AliRunDigitizer* manager)
47 :AliDigitizer(manager)
49 // ctor which should be used
52 cerr<<"AliTPCDigitizer::AliTPCDigitizer"
53 <<"(AliRunDigitizer* manager) was processed"<<endl;
56 //------------------------------------------------------------------------
57 AliTPCDigitizer::~AliTPCDigitizer()
64 //------------------------------------------------------------------------
65 Bool_t AliTPCDigitizer::Init()
73 //------------------------------------------------------------------------
74 void AliTPCDigitizer::Exec(Option_t* option)
78 //------------------------------------------------------------------------
79 void AliTPCDigitizer::ExecFast(Option_t* option)
82 // merge input tree's with summable digits
83 //output stored in TreeTPCD
86 TString optionString = option;
87 if (optionString.Data() == "deb") {
88 cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl;
91 //get detector and geometry
94 AliRunLoader *rl, *orl;
95 AliLoader *gime, *ogime;
99 Warning("ExecFast","gAlice is NULL. Loading from input 0");
100 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
103 Error("ExecFast","Can not find Run Loader for input 0. Can not proceed.");
109 AliTPC *pTPC = (AliTPC *) gAlice->GetModule("TPC");
110 AliTPCParam * param = pTPC->GetParam();
112 sprintf(s,param->GetTitle());
113 sprintf(ss,"75x40_100x60");
115 printf("2 pad-length geom hits with 3 pad-lenght geom digits...\n");
117 param=new AliTPCParamSR();
120 sprintf(ss,"75x40_100x60_150x60");
121 if(strcmp(s,ss)!=0) {
122 printf("No TPC parameters found...\n");
127 pTPC->GenerNoise(500000); //create teble with noise
129 Int_t nInputs = fManager->GetNinputs();
130 Int_t * masks = new Int_t[nInputs];
131 for (Int_t i=0; i<nInputs;i++)
132 masks[i]= fManager->GetMask(i);
133 Short_t **pdig= new Short_t*[nInputs]; //pointers to the expanded digits array
134 Int_t **ptr= new Int_t*[nInputs]; //pointers to teh expanded tracks array
137 //create digits array for given sectors
139 Stat_t nentries = 0;//number of entries in TreeS
141 AliSimDigits ** digarr = new AliSimDigits*[nInputs];
142 for (Int_t i1=0;i1<nInputs; i1++)
146 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i1));
147 gime = rl->GetLoader("TPCLoader");
148 gime->LoadSDigits("read");
149 TTree * treear = gime->TreeS();
153 cerr<<"AliTPCDigitizer: Input tree with SDigits not found in"
154 <<" input "<< i1<<endl;
157 if (i1 == 0) nentries=treear->GetEntries();
159 if (treear->GetIndex()==0)
160 treear->BuildIndex("fSegmentID","fSegmentID");
161 treear->GetBranch("Segment")->SetAddress(&digarr[i1]);
165 //create branch's in TPC treeD
166 AliSimDigits * digrow = new AliSimDigits;
168 orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
169 ogime = orl->GetLoader("TPCLoader");
171 TTree * tree = ogime->TreeD();
174 ogime->MakeTree("D");
175 tree = ogime->TreeD();
177 tree->Branch("Segment","AliSimDigits",&digrow);
180 param->SetZeroSup(2);
182 Int_t zerosup = param->GetZeroSup();
184 //Loop over segments of the TPC
186 for (Int_t n=0; n<nentries; n++)
188 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
189 gime = rl->GetLoader("TPCLoader");
190 gime->TreeS()->GetEvent(n);
191 digarr[0]->ExpandBuffer();
192 digarr[0]->ExpandTrackBuffer();
194 for (Int_t i=1;i<nInputs; i++)
197 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i));
198 gime = rl->GetLoader("TPCLoader");
200 gime->TreeS()->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());
201 if ((digarr[0]->GetID()-digarr[i]->GetID())>0)
202 printf("problem - not corresponding segment in background event\n");
204 digarr[i]->ExpandBuffer();
205 digarr[i]->ExpandTrackBuffer();
209 if (!param->AdjustSectorRow(digarr[0]->GetID(),sec,row))
211 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr[0]->GetID()<<endl;
215 digrow->SetID(digarr[0]->GetID());
217 Int_t nrows = digarr[0]->GetNRows();
218 Int_t ncols = digarr[0]->GetNCols();
219 digrow->Allocate(nrows,ncols);
220 digrow->AllocateTrack(3);
223 Int_t label[1000]; //stack for 300 events
226 Int_t nElems = nrows*ncols;
228 for (Int_t i=0;i<nInputs; i++)
230 pdig[i] = digarr[i]->GetDigits();
231 ptr[i] = digarr[i]->GetTracks();
234 Short_t *pdig1= digrow->GetDigits();
235 Int_t *ptr1= digrow->GetTracks() ;
239 for (Int_t elem=0;elem<nElems; elem++)
245 for (Int_t i=0;i<nInputs; i++)
247 // q += digarr[i]->GetDigitFast(rows,col);
250 for (Int_t tr=0;tr<3;tr++)
252 // Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
253 Int_t lab = ptr[i][tr*nElems];
254 if ( (lab > 1) && *(pdig[i])>zerosup)
256 label[labptr]=lab+masks[i];
263 q/=16.; //conversion factor
264 // Float_t noise = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac());
265 Float_t noise = pTPC->GetNoise();
270 if(q > param->GetADCSat()) q = (Short_t)(param->GetADCSat());
271 //digrow->SetDigitFast((Short_t)q,rows,col);
273 for (Int_t tr=0;tr<3;tr++)
276 ptr1[tr*nElems] = label[tr];
283 digrow->CompresBuffer(1,zerosup);
284 digrow->CompresTrackBuffer(1);
286 if (fDebug>0) cerr<<sec<<"\t"<<row<<"\n";
287 } //for (Int_t n=0; n<nentries; n++)
290 orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
291 ogime = orl->GetLoader("TPCLoader");
292 ogime->WriteDigits("OVERWRITE");
294 //fManager->GetTreeDTPC()->Write(0,TObject::kOverwrite);
297 for (Int_t i1=0;i1<nInputs; i1++) delete digarr[i1];
304 //------------------------------------------------------------------------
305 void AliTPCDigitizer::ExecSave(Option_t* option)
308 // merge input tree's with summable digits
309 //output stored in TreeTPCD
311 TString optionString = option;
312 if (optionString.Data() == "deb") {
313 cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl;
316 //get detector and geometry
317 AliRunLoader *rl, *orl;
318 AliLoader *gime, *ogime;
321 orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
322 ogime = orl->GetLoader("TPCLoader");
324 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
325 gime = rl->GetLoader("TPCLoader");
328 AliRun* alirun = rl->GetAliRun();
330 AliTPC *pTPC = (AliTPC *) alirun->GetModule("TPC");
331 AliTPCParam * param = pTPC->GetParam();
332 pTPC->GenerNoise(500000); //create teble with noise
333 printf("noise %f \n", param->GetNoise()*param->GetNoiseNormFac());
335 Int_t nInputs = fManager->GetNinputs();
336 Int_t * masks = new Int_t[nInputs];
337 for (Int_t i=0; i<nInputs;i++)
338 masks[i]= fManager->GetMask(i);
340 AliSimDigits ** digarr = new AliSimDigits*[nInputs];
341 for (Int_t i1=0;i1<nInputs; i1++)
345 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i1));
346 gime = rl->GetLoader("TPCLoader");
348 TTree * treear = gime->TreeS();
349 TBranch * br = treear->GetBranch("fSegmentID");
350 if (br) br->GetFile()->cd();
352 cerr<<" TPC - not existing input = \n"<<i1<<" ";
354 treear->GetBranch("Segment")->SetAddress(&digarr[i1]);
357 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
358 gime = rl->GetLoader("TPCLoader");
359 Stat_t nentries = gime->TreeS()->GetEntries();
362 //create branch's in TPC treeD
363 AliSimDigits * digrow = new AliSimDigits;
364 TTree * tree = ogime->TreeD();
366 tree->Branch("Segment","AliSimDigits",&digrow);
367 param->SetZeroSup(2);
369 Int_t zerosup = param->GetZeroSup();
370 //Loop over segments of the TPC
372 for (Int_t n=0; n<nentries; n++) {
373 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
374 gime = rl->GetLoader("TPCLoader");
375 gime->TreeS()->GetEvent(n);
377 digarr[0]->ExpandBuffer();
378 digarr[0]->ExpandTrackBuffer();
380 for (Int_t i=1;i<nInputs; i++){
381 // fManager->GetInputTreeTPCS(i)->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());
382 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i));
383 gime = rl->GetLoader("TPCLoader");
384 gime->TreeS()->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());
385 digarr[i]->ExpandBuffer();
386 digarr[i]->ExpandTrackBuffer();
387 if ((digarr[0]->GetID()-digarr[i]->GetID())>0)
393 if (!param->AdjustSectorRow(digarr[0]->GetID(),sec,row)) {
394 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr[0]->GetID()<<endl;
398 digrow->SetID(digarr[0]->GetID());
400 Int_t nrows = digarr[0]->GetNRows();
401 Int_t ncols = digarr[0]->GetNCols();
402 digrow->Allocate(nrows,ncols);
403 digrow->AllocateTrack(3);
406 Int_t label[1000]; //stack for 300 events
411 for (Int_t rows=0;rows<nrows; rows++){
412 for (Int_t col=0;col<ncols; col++){
417 for (Int_t i=0;i<nInputs; i++){
418 q += digarr[i]->GetDigitFast(rows,col);
421 for (Int_t tr=0;tr<3;tr++) {
422 Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
423 //Int_t lab = ptr[i][tr*nElems];
425 label[labptr]=lab+masks[i];
433 q/=16.; //conversion factor
434 // Float_t noise = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac());
435 Float_t noise = pTPC->GetNoise();
440 if(q > param->GetADCSat()) q = (Short_t)(param->GetADCSat());
441 digrow->SetDigitFast((Short_t)q,rows,col);
442 // *pdig1 =Short_t(q);
443 for (Int_t tr=0;tr<3;tr++){
445 ((AliSimDigits*)digrow)->SetTrackIDFast(label[tr],rows,col,tr);
446 //ptr1[tr*nElems] = label[tr];
448 // ((AliSimDigits*)digrow)->SetTrackIDFast(-1,rows,col,tr);
449 // ptr1[tr*nElems] = 1;
457 digrow->CompresBuffer(1,zerosup);
458 digrow->CompresTrackBuffer(1);
460 if (fDebug>0) cerr<<sec<<"\t"<<row<<"\n";
462 // printf("end TPC merging - end -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
463 //fManager->GetTreeDTPC()->Write(0,TObject::kOverwrite);
464 ogime->WriteDigits("OVERWRITE");
466 for (Int_t i=1;i<nInputs; i++)
468 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i));
469 gime = rl->GetLoader("TPCLoader");
470 gime->UnloadSDigits();
472 ogime->UnloadDigits();
475 for (Int_t i1=0;i1<nInputs; i1++) delete digarr[i1];