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
51 AliDebug(2,"(AliRunDigitizer* manager) was processed");
54 //------------------------------------------------------------------------
55 AliTPCDigitizer::~AliTPCDigitizer()
62 //------------------------------------------------------------------------
63 Bool_t AliTPCDigitizer::Init()
71 //------------------------------------------------------------------------
72 void AliTPCDigitizer::Exec(Option_t* option)
76 //------------------------------------------------------------------------
77 void AliTPCDigitizer::ExecFast(Option_t* option)
80 // merge input tree's with summable digits
81 //output stored in TreeTPCD
84 TString optionString = option;
85 if (optionString.Data() == "deb") {
86 cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl;
89 //get detector and geometry
92 AliRunLoader *rl, *orl;
93 AliLoader *gime, *ogime;
97 Warning("ExecFast","gAlice is NULL. Loading from input 0");
98 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
101 Error("ExecFast","Can not find Run Loader for input 0. Can not proceed.");
107 AliTPC *pTPC = (AliTPC *) gAlice->GetModule("TPC");
108 AliTPCParam * param = pTPC->GetParam();
110 sprintf(s,param->GetTitle());
111 sprintf(ss,"75x40_100x60");
113 printf("2 pad-length geom hits with 3 pad-lenght geom digits...\n");
115 param=new AliTPCParamSR();
118 sprintf(ss,"75x40_100x60_150x60");
119 if(strcmp(s,ss)!=0) {
120 printf("No TPC parameters found...\n");
125 pTPC->GenerNoise(500000); //create teble with noise
127 Int_t nInputs = fManager->GetNinputs();
128 Int_t * masks = new Int_t[nInputs];
129 for (Int_t i=0; i<nInputs;i++)
130 masks[i]= fManager->GetMask(i);
131 Short_t **pdig= new Short_t*[nInputs]; //pointers to the expanded digits array
132 Int_t **ptr= new Int_t*[nInputs]; //pointers to teh expanded tracks array
133 Bool_t *active= new Bool_t[nInputs]; //flag for active input segments
136 //create digits array for given sectors
139 AliSimDigits ** digarr = new AliSimDigits*[nInputs];
140 for (Int_t i1=0;i1<nInputs; i1++)
144 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i1));
145 gime = rl->GetLoader("TPCLoader");
146 gime->LoadSDigits("read");
147 TTree * treear = gime->TreeS();
151 cerr<<"AliTPCDigitizer: Input tree with SDigits not found in"
152 <<" input "<< i1<<endl;
156 if (treear->GetIndex()==0)
157 treear->BuildIndex("fSegmentID","fSegmentID");
158 treear->GetBranch("Segment")->SetAddress(&digarr[i1]);
162 //create branch's in TPC treeD
163 AliSimDigits * digrow = new AliSimDigits;
165 orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
166 ogime = orl->GetLoader("TPCLoader");
168 TTree * tree = ogime->TreeD();
171 ogime->MakeTree("D");
172 tree = ogime->TreeD();
174 tree->Branch("Segment","AliSimDigits",&digrow);
177 param->SetZeroSup(2);
179 Int_t zerosup = param->GetZeroSup();
181 //Loop over segments of the TPC
183 for (Int_t segmentID=0; segmentID<param->GetNRowsTotal(); segmentID++)
186 if (!param->AdjustSectorRow(segmentID,sec,row))
188 cerr<<"AliTPC warning: invalid segment ID ! "<<segmentID<<endl;
192 digrow->SetID(segmentID);
197 Bool_t digitize = kFALSE;
198 for (Int_t i=0;i<nInputs; i++)
201 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i));
202 gime = rl->GetLoader("TPCLoader");
204 if (gime->TreeS()->GetEntryWithIndex(segmentID,segmentID) >= 0) {
205 digarr[i]->ExpandBuffer();
206 digarr[i]->ExpandTrackBuffer();
207 nrows = digarr[i]->GetNRows();
208 ncols = digarr[i]->GetNCols();
210 if (!fRegionOfInterest || (i == 0)) digitize = kTRUE;
214 if (fRegionOfInterest && !digitize) break;
216 if (!digitize) continue;
218 digrow->Allocate(nrows,ncols);
219 digrow->AllocateTrack(3);
222 Int_t label[1000]; //stack for 300 events
225 Int_t nElems = nrows*ncols;
227 for (Int_t i=0;i<nInputs; i++)
229 pdig[i] = digarr[i]->GetDigits();
230 ptr[i] = digarr[i]->GetTracks();
233 Short_t *pdig1= digrow->GetDigits();
234 Int_t *ptr1= digrow->GetTracks() ;
238 for (Int_t elem=0;elem<nElems; elem++)
244 for (Int_t i=0;i<nInputs; i++) if (active[i])
246 // q += digarr[i]->GetDigitFast(rows,col);
249 for (Int_t tr=0;tr<3;tr++)
251 // Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
252 Int_t lab = ptr[i][tr*nElems];
253 if ( (lab > 1) && *(pdig[i])>zerosup)
255 label[labptr]=lab+masks[i];
262 q/=16.; //conversion factor
263 // Float_t noise = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac());
264 Float_t noise = pTPC->GetNoise();
269 if(q > param->GetADCSat()) q = (Short_t)(param->GetADCSat());
270 //digrow->SetDigitFast((Short_t)q,rows,col);
272 for (Int_t tr=0;tr<3;tr++)
275 ptr1[tr*nElems] = label[tr];
282 digrow->CompresBuffer(1,zerosup);
283 digrow->CompresTrackBuffer(1);
285 if (fDebug>0) cerr<<sec<<"\t"<<row<<"\n";
286 } //for (Int_t n=0; n<param->GetNRowsTotal(); n++)
289 orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
290 ogime = orl->GetLoader("TPCLoader");
291 ogime->WriteDigits("OVERWRITE");
293 //fManager->GetTreeDTPC()->Write(0,TObject::kOverwrite);
296 for (Int_t i1=0;i1<nInputs; i1++) delete digarr[i1];
306 //------------------------------------------------------------------------
307 void AliTPCDigitizer::ExecSave(Option_t* option)
310 // merge input tree's with summable digits
311 //output stored in TreeTPCD
313 TString optionString = option;
314 if (optionString.Data() == "deb") {
315 cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl;
318 //get detector and geometry
319 AliRunLoader *rl, *orl;
320 AliLoader *gime, *ogime;
323 orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
324 ogime = orl->GetLoader("TPCLoader");
326 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
327 gime = rl->GetLoader("TPCLoader");
330 AliRun* alirun = rl->GetAliRun();
332 AliTPC *pTPC = (AliTPC *) alirun->GetModule("TPC");
333 AliTPCParam * param = pTPC->GetParam();
334 pTPC->GenerNoise(500000); //create teble with noise
335 printf("noise %f \n", param->GetNoise()*param->GetNoiseNormFac());
337 Int_t nInputs = fManager->GetNinputs();
338 Int_t * masks = new Int_t[nInputs];
339 for (Int_t i=0; i<nInputs;i++)
340 masks[i]= fManager->GetMask(i);
342 AliSimDigits ** digarr = new AliSimDigits*[nInputs];
343 for (Int_t i1=0;i1<nInputs; i1++)
347 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i1));
348 gime = rl->GetLoader("TPCLoader");
350 TTree * treear = gime->TreeS();
351 TBranch * br = treear->GetBranch("fSegmentID");
352 if (br) br->GetFile()->cd();
354 cerr<<" TPC - not existing input = \n"<<i1<<" ";
356 treear->GetBranch("Segment")->SetAddress(&digarr[i1]);
359 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
360 gime = rl->GetLoader("TPCLoader");
361 Stat_t nentries = gime->TreeS()->GetEntries();
364 //create branch's in TPC treeD
365 AliSimDigits * digrow = new AliSimDigits;
366 TTree * tree = ogime->TreeD();
368 tree->Branch("Segment","AliSimDigits",&digrow);
369 param->SetZeroSup(2);
371 Int_t zerosup = param->GetZeroSup();
372 //Loop over segments of the TPC
374 for (Int_t n=0; n<nentries; n++) {
375 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
376 gime = rl->GetLoader("TPCLoader");
377 gime->TreeS()->GetEvent(n);
379 digarr[0]->ExpandBuffer();
380 digarr[0]->ExpandTrackBuffer();
382 for (Int_t i=1;i<nInputs; i++){
383 // fManager->GetInputTreeTPCS(i)->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());
384 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i));
385 gime = rl->GetLoader("TPCLoader");
386 gime->TreeS()->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());
387 digarr[i]->ExpandBuffer();
388 digarr[i]->ExpandTrackBuffer();
389 if ((digarr[0]->GetID()-digarr[i]->GetID())>0)
395 if (!param->AdjustSectorRow(digarr[0]->GetID(),sec,row)) {
396 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr[0]->GetID()<<endl;
400 digrow->SetID(digarr[0]->GetID());
402 Int_t nrows = digarr[0]->GetNRows();
403 Int_t ncols = digarr[0]->GetNCols();
404 digrow->Allocate(nrows,ncols);
405 digrow->AllocateTrack(3);
408 Int_t label[1000]; //stack for 300 events
413 for (Int_t rows=0;rows<nrows; rows++){
414 for (Int_t col=0;col<ncols; col++){
419 for (Int_t i=0;i<nInputs; i++){
420 q += digarr[i]->GetDigitFast(rows,col);
423 for (Int_t tr=0;tr<3;tr++) {
424 Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
425 //Int_t lab = ptr[i][tr*nElems];
427 label[labptr]=lab+masks[i];
435 q/=16.; //conversion factor
436 // Float_t noise = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac());
437 Float_t noise = pTPC->GetNoise();
442 if(q > param->GetADCSat()) q = (Short_t)(param->GetADCSat());
443 digrow->SetDigitFast((Short_t)q,rows,col);
444 // *pdig1 =Short_t(q);
445 for (Int_t tr=0;tr<3;tr++){
447 ((AliSimDigits*)digrow)->SetTrackIDFast(label[tr],rows,col,tr);
448 //ptr1[tr*nElems] = label[tr];
450 // ((AliSimDigits*)digrow)->SetTrackIDFast(-1,rows,col,tr);
451 // ptr1[tr*nElems] = 1;
459 digrow->CompresBuffer(1,zerosup);
460 digrow->CompresTrackBuffer(1);
462 if (fDebug>0) cerr<<sec<<"\t"<<row<<"\n";
464 // printf("end TPC merging - end -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
465 //fManager->GetTreeDTPC()->Write(0,TObject::kOverwrite);
466 ogime->WriteDigits("OVERWRITE");
468 for (Int_t i=1;i<nInputs; i++)
470 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i));
471 gime = rl->GetLoader("TPCLoader");
472 gime->UnloadSDigits();
474 ogime->UnloadDigits();
477 for (Int_t i1=0;i1<nInputs; i1++) delete digarr[i1];