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 **************************************************************************/
25 #include <TObjArray.h>
27 #include <TDirectory.h>
30 #include "AliTPCDigitizer.h"
33 #include "AliTPCParam.h"
34 #include "AliTPCParamSR.h"
37 #include "AliRunDigitizer.h"
38 #include "AliSimDigits.h"
41 ClassImp(AliTPCDigitizer)
43 //___________________________________________
44 AliTPCDigitizer::AliTPCDigitizer() :AliDigitizer()
46 // Default ctor - don't use it
50 //___________________________________________
51 AliTPCDigitizer::AliTPCDigitizer(AliRunDigitizer* manager)
52 :AliDigitizer(manager)
54 // ctor which should be used
57 cerr<<"AliTPCDigitizer::AliTPCDigitizer"
58 <<"(AliRunDigitizer* manager) was processed"<<endl;
61 //------------------------------------------------------------------------
62 AliTPCDigitizer::~AliTPCDigitizer()
69 //------------------------------------------------------------------------
70 Bool_t AliTPCDigitizer::Init()
78 //------------------------------------------------------------------------
79 void AliTPCDigitizer::Exec(Option_t* option)
83 //------------------------------------------------------------------------
84 void AliTPCDigitizer::ExecFast(Option_t* option)
87 // merge input tree's with summable digits
88 //output stored in TreeTPCD
91 TString optionString = option;
92 if (optionString.Data() == "deb") {
93 cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl;
96 //get detector and geometry
97 AliTPC *pTPC = (AliTPC *) gAlice->GetModule("TPC");
98 AliTPCParam * param = pTPC->GetParam();
100 sprintf(s,param->GetTitle());
101 sprintf(ss,"75x40_100x60");
103 printf("2 pad-length geom hits with 3 pad-lenght geom digits...\n");
105 param=new AliTPCParamSR();
108 sprintf(ss,"75x40_100x60_150x60");
109 if(strcmp(s,ss)!=0) {
110 printf("No TPC parameters found...\n");
115 pTPC->GenerNoise(500000); //create teble with noise
117 Int_t nInputs = fManager->GetNinputs();
118 Int_t * masks = new Int_t[nInputs];
119 for (Int_t i=0; i<nInputs;i++)
120 masks[i]= fManager->GetMask(i);
121 Short_t **pdig= new Short_t*[nInputs]; //pointers to the expanded digits array
122 Int_t **ptr= new Int_t*[nInputs]; //pointers to teh expanded tracks array
124 //create digits array for given sectors
126 AliSimDigits ** digarr = new AliSimDigits*[nInputs];
127 for (Int_t i1=0;i1<nInputs; i1++){
130 TTree * treear = fManager->GetInputTreeTPCS(i1);
132 cerr<<"AliTPCDigitizer: Input tree with SDigits not found in"
133 <<" input "<< i1<<endl;
136 if (treear->GetIndex()==0)
137 treear->BuildIndex("fSegmentID","fSegmentID");
139 cerr<<" TPC - not existing input = \n"<<i1<<" ";
141 treear->GetBranch("Segment")->SetAddress(&digarr[i1]);
143 Stat_t nentries = fManager->GetInputTreeTPCS(0)->GetEntries();
146 //create branch's in TPC treeD
147 AliSimDigits * digrow = new AliSimDigits;
148 TTree * tree = fManager->GetTreeDTPC();
149 tree->Branch("Segment","AliSimDigits",&digrow);
152 param->SetZeroSup(2);
154 Int_t zerosup = param->GetZeroSup();
156 //Loop over segments of the TPC
158 for (Int_t n=0; n<nentries; n++) {
159 // for (Int_t n=0; n<300; n++) {
160 fManager->GetInputTreeTPCS(0)->GetEvent(n);
161 digarr[0]->ExpandBuffer();
162 digarr[0]->ExpandTrackBuffer();
164 for (Int_t i=1;i<nInputs; i++){
165 fManager->GetInputTreeTPCS(i)->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());
166 if ((digarr[0]->GetID()-digarr[i]->GetID())>0)
167 printf("problem - not corresponding segment in background event\n");
169 digarr[i]->ExpandBuffer();
170 digarr[i]->ExpandTrackBuffer();
173 if (!param->AdjustSectorRow(digarr[0]->GetID(),sec,row)) {
174 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr[0]->GetID()<<endl;
178 digrow->SetID(digarr[0]->GetID());
180 Int_t nrows = digarr[0]->GetNRows();
181 Int_t ncols = digarr[0]->GetNCols();
182 digrow->Allocate(nrows,ncols);
183 digrow->AllocateTrack(3);
186 Int_t label[1000]; //stack for 300 events
189 Int_t nElems = nrows*ncols;
191 for (Int_t i=0;i<nInputs; i++){
192 pdig[i] = digarr[i]->GetDigits();
193 ptr[i] = digarr[i]->GetTracks();
195 Short_t *pdig1= digrow->GetDigits();
196 Int_t *ptr1= digrow->GetTracks() ;
200 // for (Int_t rows=0;rows<nrows; rows++){
201 // for (Int_t col=0;col<ncols; col++){
202 for (Int_t elem=0;elem<nElems; elem++){
203 //for (Int_t elem=nElems;elem<nElems; elem++){
208 for (Int_t i=0;i<nInputs; i++){
209 // q += digarr[i]->GetDigitFast(rows,col);
212 for (Int_t tr=0;tr<3;tr++) {
213 // Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
214 Int_t lab = ptr[i][tr*nElems];
215 if ( (lab > 1) && *(pdig[i])>zerosup) {
216 label[labptr]=lab+masks[i];
224 q/=16.; //conversion factor
225 // Float_t noise = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac());
226 Float_t noise = pTPC->GetNoise();
231 if(q > param->GetADCSat()) q = (Short_t)(param->GetADCSat());
232 //digrow->SetDigitFast((Short_t)q,rows,col);
234 for (Int_t tr=0;tr<3;tr++){
236 // ((AliSimDigits*)digrow)->SetTrackIDFast(label[tr],rows,col,tr);
237 ptr1[tr*nElems] = label[tr];
239 // ((AliSimDigits*)digrow)->SetTrackIDFast(-1,rows,col,tr);
240 // ptr1[tr*nElems] = 1;
247 digrow->CompresBuffer(1,zerosup);
248 digrow->CompresTrackBuffer(1);
250 if (fDebug>0) cerr<<sec<<"\t"<<row<<"\n";
252 fManager->GetTreeDTPC()->Write(0,TObject::kOverwrite);
254 for (Int_t i1=0;i1<nInputs; i1++) delete digarr[i1];
261 //------------------------------------------------------------------------
262 void AliTPCDigitizer::ExecSave(Option_t* option)
265 // merge input tree's with summable digits
266 //output stored in TreeTPCD
268 TString optionString = option;
269 if (optionString.Data() == "deb") {
270 cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl;
273 //get detector and geometry
274 printf("TPC merging -1 -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
275 AliTPC *pTPC = (AliTPC *) gAlice->GetModule("TPC");
276 AliTPCParam * param = pTPC->GetParam();
277 pTPC->GenerNoise(500000); //create teble with noise
278 printf("noise %f \n", param->GetNoise()*param->GetNoiseNormFac());
280 Int_t nInputs = fManager->GetNinputs();
281 Int_t * masks = new Int_t[nInputs];
282 for (Int_t i=0; i<nInputs;i++)
283 masks[i]= fManager->GetMask(i);
284 // Short_t **pdig= new Short_t*[nInputs]; //pointers to the expanded digits array
285 //Int_t **ptr= new Int_t*[nInputs]; //pointers to teh expanded tracks array
287 //create digits array for given sectors
289 printf("TPC merging -2 -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
290 AliSimDigits ** digarr = new AliSimDigits*[nInputs];
291 for (Int_t i1=0;i1<nInputs; i1++){
294 TTree * treear = fManager->GetInputTreeTPCS(i1);
295 printf("TPC merging -2.7 -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
296 TBranch * br = treear->GetBranch("fSegmentID");
297 if (br) br->GetFile()->cd();
298 printf("TPC merging -2.75 -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
299 //treear->BuildIndex("fSegmentID","fSegmentID");
301 cerr<<" TPC - not existing input = \n"<<i1<<" ";
303 printf("TPC merging -2.8 -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
304 treear->GetBranch("Segment")->SetAddress(&digarr[i1]);
305 printf("TPC merging -2.9 -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
307 Stat_t nentries = fManager->GetInputTreeTPCS(0)->GetEntries();
310 //create branch's in TPC treeD
311 AliSimDigits * digrow = new AliSimDigits;
312 TTree * tree = fManager->GetTreeDTPC();
313 //if (tree->GetBranch("Segment") ) tree->GetBranch("Segment")->SetAddress(&digrow);
315 tree->Branch("Segment","AliSimDigits",&digrow);
317 printf("TPC merging -3 -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
318 param->SetZeroSup(2);
320 Int_t zerosup = param->GetZeroSup();
321 //Loop over segments of the TPC
323 for (Int_t n=0; n<nentries; n++) {
324 // for (Int_t n=0; n<300; n++) {
325 fManager->GetInputTreeTPCS(0)->GetEvent(n);
326 digarr[0]->ExpandBuffer();
327 digarr[0]->ExpandTrackBuffer();
329 for (Int_t i=1;i<nInputs; i++){
330 fManager->GetInputTreeTPCS(i)->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());
331 //fManager->GetInputTreeTPCS(i)->GetEntryWithIndex(digarr[0]->GetID(),1);
332 digarr[i]->ExpandBuffer();
333 digarr[i]->ExpandTrackBuffer();
334 if ((digarr[0]->GetID()-digarr[i]->GetID())>0)
340 if (!param->AdjustSectorRow(digarr[0]->GetID(),sec,row)) {
341 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr[0]->GetID()<<endl;
345 digrow->SetID(digarr[0]->GetID());
347 Int_t nrows = digarr[0]->GetNRows();
348 Int_t ncols = digarr[0]->GetNCols();
349 digrow->Allocate(nrows,ncols);
350 digrow->AllocateTrack(3);
353 Int_t label[1000]; //stack for 300 events
358 for (Int_t rows=0;rows<nrows; rows++){
359 for (Int_t col=0;col<ncols; col++){
364 for (Int_t i=0;i<nInputs; i++){
365 q += digarr[i]->GetDigitFast(rows,col);
368 for (Int_t tr=0;tr<3;tr++) {
369 Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
370 //Int_t lab = ptr[i][tr*nElems];
372 label[labptr]=lab+masks[i];
380 q/=16.; //conversion factor
381 // Float_t noise = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac());
382 Float_t noise = pTPC->GetNoise();
387 if(q > param->GetADCSat()) q = (Short_t)(param->GetADCSat());
388 digrow->SetDigitFast((Short_t)q,rows,col);
389 // *pdig1 =Short_t(q);
390 for (Int_t tr=0;tr<3;tr++){
392 ((AliSimDigits*)digrow)->SetTrackIDFast(label[tr],rows,col,tr);
393 //ptr1[tr*nElems] = label[tr];
395 // ((AliSimDigits*)digrow)->SetTrackIDFast(-1,rows,col,tr);
396 // ptr1[tr*nElems] = 1;
404 digrow->CompresBuffer(1,zerosup);
405 digrow->CompresTrackBuffer(1);
407 if (fDebug>0) cerr<<sec<<"\t"<<row<<"\n";
409 printf("end TPC merging - end -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
410 fManager->GetTreeDTPC()->Write(0,TObject::kOverwrite);
412 for (Int_t i1=0;i1<nInputs; i1++) delete digarr[i1];