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 **************************************************************************/
18 Revision 1.3.6.1 2002/06/10 15:26:11 hristov
21 Revision 1.6 2002/04/06 14:41:04 kowal2
22 Added #include<stdlib.h> and log
31 #include <TObjArray.h>
33 #include <TDirectory.h>
36 #include "AliTPCDigitizer.h"
39 #include "AliTPCParam.h"
40 #include "AliTPCParamSR.h"
43 #include "AliRunDigitizer.h"
44 #include "AliSimDigits.h"
47 ClassImp(AliTPCDigitizer)
49 //___________________________________________
50 AliTPCDigitizer::AliTPCDigitizer() :AliDigitizer()
52 // Default ctor - don't use it
56 //___________________________________________
57 AliTPCDigitizer::AliTPCDigitizer(AliRunDigitizer* manager)
58 :AliDigitizer(manager)
60 // ctor which should be used
63 cerr<<"AliTPCDigitizer::AliTPCDigitizer"
64 <<"(AliRunDigitizer* manager) was processed"<<endl;
67 //------------------------------------------------------------------------
68 AliTPCDigitizer::~AliTPCDigitizer()
75 //------------------------------------------------------------------------
76 Bool_t AliTPCDigitizer::Init()
84 //------------------------------------------------------------------------
85 void AliTPCDigitizer::Exec(Option_t* option)
89 //------------------------------------------------------------------------
90 void AliTPCDigitizer::ExecFast(Option_t* option)
93 // merge input tree's with summable digits
94 //output stored in TreeTPCD
97 TString optionString = option;
98 if (optionString.Data() == "deb") {
99 cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl;
102 //get detector and geometry
103 AliTPC *pTPC = (AliTPC *) gAlice->GetModule("TPC");
104 AliTPCParam * param = pTPC->GetParam();
106 sprintf(s,param->GetTitle());
107 sprintf(ss,"75x40_100x60");
109 printf("2 pad-length geom hits with 3 pad-lenght geom digits...\n");
111 param=new AliTPCParamSR();
114 sprintf(ss,"75x40_100x60_150x60");
115 if(strcmp(s,ss)!=0) {
116 printf("No TPC parameters found...\n");
121 pTPC->GenerNoise(500000); //create teble with noise
123 Int_t nInputs = fManager->GetNinputs();
124 Int_t * masks = new Int_t[nInputs];
125 for (Int_t i=0; i<nInputs;i++)
126 masks[i]= fManager->GetMask(i);
127 Short_t **pdig= new Short_t*[nInputs]; //pointers to the expanded digits array
128 Int_t **ptr= new Int_t*[nInputs]; //pointers to teh expanded tracks array
130 //create digits array for given sectors
132 AliSimDigits ** digarr = new AliSimDigits*[nInputs];
133 for (Int_t i1=0;i1<nInputs; i1++){
136 TTree * treear = fManager->GetInputTreeTPCS(i1);
138 cerr<<"AliTPCDigitizer: Input tree with SDigits not found in"
139 <<" input "<< i1<<endl;
142 if (treear->GetIndex()==0)
143 treear->BuildIndex("fSegmentID","fSegmentID");
145 cerr<<" TPC - not existing input = \n"<<i1<<" ";
147 treear->GetBranch("Segment")->SetAddress(&digarr[i1]);
149 Stat_t nentries = fManager->GetInputTreeTPCS(0)->GetEntries();
152 //create branch's in TPC treeD
153 AliSimDigits * digrow = new AliSimDigits;
154 TTree * tree = fManager->GetTreeDTPC();
155 tree->Branch("Segment","AliSimDigits",&digrow);
158 param->SetZeroSup(2);
160 Int_t zerosup = param->GetZeroSup();
162 //Loop over segments of the TPC
164 for (Int_t n=0; n<nentries; n++) {
165 // for (Int_t n=0; n<300; n++) {
166 fManager->GetInputTreeTPCS(0)->GetEvent(n);
167 digarr[0]->ExpandBuffer();
168 digarr[0]->ExpandTrackBuffer();
170 for (Int_t i=1;i<nInputs; i++){
171 fManager->GetInputTreeTPCS(i)->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());
172 if ((digarr[0]->GetID()-digarr[i]->GetID())>0)
173 printf("problem - not corresponding segment in background event\n");
175 digarr[i]->ExpandBuffer();
176 digarr[i]->ExpandTrackBuffer();
179 if (!param->AdjustSectorRow(digarr[0]->GetID(),sec,row)) {
180 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr[0]->GetID()<<endl;
184 digrow->SetID(digarr[0]->GetID());
186 Int_t nrows = digarr[0]->GetNRows();
187 Int_t ncols = digarr[0]->GetNCols();
188 digrow->Allocate(nrows,ncols);
189 digrow->AllocateTrack(3);
192 Int_t label[1000]; //stack for 300 events
195 Int_t nElems = nrows*ncols;
197 for (Int_t i=0;i<nInputs; i++){
198 pdig[i] = digarr[i]->GetDigits();
199 ptr[i] = digarr[i]->GetTracks();
201 Short_t *pdig1= digrow->GetDigits();
202 Int_t *ptr1= digrow->GetTracks() ;
206 // for (Int_t rows=0;rows<nrows; rows++){
207 // for (Int_t col=0;col<ncols; col++){
208 for (Int_t elem=0;elem<nElems; elem++){
209 //for (Int_t elem=nElems;elem<nElems; elem++){
214 for (Int_t i=0;i<nInputs; i++){
215 // q += digarr[i]->GetDigitFast(rows,col);
218 for (Int_t tr=0;tr<3;tr++) {
219 // Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
220 Int_t lab = ptr[i][tr*nElems];
221 if ( (lab > 1) && *(pdig[i])>zerosup) {
222 label[labptr]=lab+masks[i];
230 q/=16.; //conversion factor
231 // Float_t noise = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac());
232 Float_t noise = pTPC->GetNoise();
237 if(q > param->GetADCSat()) q = (Short_t)(param->GetADCSat());
238 //digrow->SetDigitFast((Short_t)q,rows,col);
240 for (Int_t tr=0;tr<3;tr++){
242 // ((AliSimDigits*)digrow)->SetTrackIDFast(label[tr],rows,col,tr);
243 ptr1[tr*nElems] = label[tr];
245 // ((AliSimDigits*)digrow)->SetTrackIDFast(-1,rows,col,tr);
246 // ptr1[tr*nElems] = 1;
253 digrow->CompresBuffer(1,zerosup);
254 digrow->CompresTrackBuffer(1);
256 if (fDebug>0) cerr<<sec<<"\t"<<row<<"\n";
258 fManager->GetTreeDTPC()->Write(0,TObject::kOverwrite);
260 for (Int_t i1=0;i1<nInputs; i1++) delete digarr[i1];
267 //------------------------------------------------------------------------
268 void AliTPCDigitizer::ExecSave(Option_t* option)
271 // merge input tree's with summable digits
272 //output stored in TreeTPCD
274 TString optionString = option;
275 if (optionString.Data() == "deb") {
276 cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl;
279 //get detector and geometry
280 printf("TPC merging -1 -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
281 AliTPC *pTPC = (AliTPC *) gAlice->GetModule("TPC");
282 AliTPCParam * param = pTPC->GetParam();
283 pTPC->GenerNoise(500000); //create teble with noise
284 printf("noise %f \n", param->GetNoise()*param->GetNoiseNormFac());
286 Int_t nInputs = fManager->GetNinputs();
287 Int_t * masks = new Int_t[nInputs];
288 for (Int_t i=0; i<nInputs;i++)
289 masks[i]= fManager->GetMask(i);
290 // Short_t **pdig= new Short_t*[nInputs]; //pointers to the expanded digits array
291 //Int_t **ptr= new Int_t*[nInputs]; //pointers to teh expanded tracks array
293 //create digits array for given sectors
295 printf("TPC merging -2 -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
296 AliSimDigits ** digarr = new AliSimDigits*[nInputs];
297 for (Int_t i1=0;i1<nInputs; i1++){
300 TTree * treear = fManager->GetInputTreeTPCS(i1);
301 printf("TPC merging -2.7 -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
302 TBranch * br = treear->GetBranch("fSegmentID");
303 if (br) br->GetFile()->cd();
304 printf("TPC merging -2.75 -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
305 //treear->BuildIndex("fSegmentID","fSegmentID");
307 cerr<<" TPC - not existing input = \n"<<i1<<" ";
309 printf("TPC merging -2.8 -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
310 treear->GetBranch("Segment")->SetAddress(&digarr[i1]);
311 printf("TPC merging -2.9 -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
313 Stat_t nentries = fManager->GetInputTreeTPCS(0)->GetEntries();
316 //create branch's in TPC treeD
317 AliSimDigits * digrow = new AliSimDigits;
318 TTree * tree = fManager->GetTreeDTPC();
319 //if (tree->GetBranch("Segment") ) tree->GetBranch("Segment")->SetAddress(&digrow);
321 tree->Branch("Segment","AliSimDigits",&digrow);
323 printf("TPC merging -3 -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
324 param->SetZeroSup(2);
326 Int_t zerosup = param->GetZeroSup();
327 //Loop over segments of the TPC
329 for (Int_t n=0; n<nentries; n++) {
330 // for (Int_t n=0; n<300; n++) {
331 fManager->GetInputTreeTPCS(0)->GetEvent(n);
332 digarr[0]->ExpandBuffer();
333 digarr[0]->ExpandTrackBuffer();
335 for (Int_t i=1;i<nInputs; i++){
336 fManager->GetInputTreeTPCS(i)->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());
337 //fManager->GetInputTreeTPCS(i)->GetEntryWithIndex(digarr[0]->GetID(),1);
338 digarr[i]->ExpandBuffer();
339 digarr[i]->ExpandTrackBuffer();
340 if ((digarr[0]->GetID()-digarr[i]->GetID())>0)
346 if (!param->AdjustSectorRow(digarr[0]->GetID(),sec,row)) {
347 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr[0]->GetID()<<endl;
351 digrow->SetID(digarr[0]->GetID());
353 Int_t nrows = digarr[0]->GetNRows();
354 Int_t ncols = digarr[0]->GetNCols();
355 digrow->Allocate(nrows,ncols);
356 digrow->AllocateTrack(3);
359 Int_t label[1000]; //stack for 300 events
364 for (Int_t rows=0;rows<nrows; rows++){
365 for (Int_t col=0;col<ncols; col++){
370 for (Int_t i=0;i<nInputs; i++){
371 q += digarr[i]->GetDigitFast(rows,col);
374 for (Int_t tr=0;tr<3;tr++) {
375 Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
376 //Int_t lab = ptr[i][tr*nElems];
378 label[labptr]=lab+masks[i];
386 q/=16.; //conversion factor
387 // Float_t noise = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac());
388 Float_t noise = pTPC->GetNoise();
393 if(q > param->GetADCSat()) q = (Short_t)(param->GetADCSat());
394 digrow->SetDigitFast((Short_t)q,rows,col);
395 // *pdig1 =Short_t(q);
396 for (Int_t tr=0;tr<3;tr++){
398 ((AliSimDigits*)digrow)->SetTrackIDFast(label[tr],rows,col,tr);
399 //ptr1[tr*nElems] = label[tr];
401 // ((AliSimDigits*)digrow)->SetTrackIDFast(-1,rows,col,tr);
402 // ptr1[tr*nElems] = 1;
410 digrow->CompresBuffer(1,zerosup);
411 digrow->CompresTrackBuffer(1);
413 if (fDebug>0) cerr<<sec<<"\t"<<row<<"\n";
415 printf("end TPC merging - end -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
416 fManager->GetTreeDTPC()->Write(0,TObject::kOverwrite);
418 for (Int_t i1=0;i1<nInputs; i1++) delete digarr[i1];