Setting the branch address to permit correct reading
[u/mrichter/AliRoot.git] / TPC / AliTPCDigitizer.cxx
CommitLineData
3c038d07 1/**************************************************************************
2 * Copyright(c) 1998-2000, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
d37f8c34 16/*
17$Log$
170bf274 18Revision 1.8 2002/10/23 07:17:33 alibrary
19Introducing Riostream.h
20
19364939 21Revision 1.7 2002/10/14 14:57:42 hristov
22Merging the VirtualMC branch to the main development branch (HEAD)
23
b9d0a01d 24Revision 1.3.6.1 2002/06/10 15:26:11 hristov
25Merged with v3-08-02
26
27Revision 1.6 2002/04/06 14:41:04 kowal2
28Added #include<stdlib.h> and log
29
d37f8c34 30*/
407ff276 31
3c038d07 32
d37f8c34 33
34
35#include <stdlib.h>
3c038d07 36#include <TTree.h>
37#include <TObjArray.h>
38#include <TFile.h>
39#include <TDirectory.h>
19364939 40#include <Riostream.h>
3c038d07 41
42#include "AliTPCDigitizer.h"
43
44#include "AliTPC.h"
45#include "AliTPCParam.h"
7a09f434 46#include "AliTPCParamSR.h"
3c038d07 47#include "AliRun.h"
48#include "AliPDG.h"
49#include "AliRunDigitizer.h"
50#include "AliSimDigits.h"
51
52
53ClassImp(AliTPCDigitizer)
54
55//___________________________________________
56AliTPCDigitizer::AliTPCDigitizer() :AliDigitizer()
57{
58// Default ctor - don't use it
f648982e 59 fDebug =0;
3c038d07 60}
61
62//___________________________________________
63AliTPCDigitizer::AliTPCDigitizer(AliRunDigitizer* manager)
64 :AliDigitizer(manager)
65{
66// ctor which should be used
f648982e 67 fDebug =0;
3c038d07 68 if (GetDebug()>2)
69 cerr<<"AliTPCDigitizer::AliTPCDigitizer"
70 <<"(AliRunDigitizer* manager) was processed"<<endl;
71}
72
73//------------------------------------------------------------------------
74AliTPCDigitizer::~AliTPCDigitizer()
75{
76// Destructor
77}
78
79
80
81//------------------------------------------------------------------------
82Bool_t AliTPCDigitizer::Init()
83{
84// Initialization
85
86 return kTRUE;
87}
88
89
90//------------------------------------------------------------------------
91void AliTPCDigitizer::Exec(Option_t* option)
f648982e 92{
93 ExecFast(option);
94}
95//------------------------------------------------------------------------
96void AliTPCDigitizer::ExecFast(Option_t* option)
3c038d07 97{
98
99 // merge input tree's with summable digits
100 //output stored in TreeTPCD
7a09f434 101 char s[100];
102 char ss[100];
3c038d07 103 TString optionString = option;
104 if (optionString.Data() == "deb") {
105 cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl;
106 fDebug = 3;
107 }
108 //get detector and geometry
109 AliTPC *pTPC = (AliTPC *) gAlice->GetModule("TPC");
110 AliTPCParam * param = pTPC->GetParam();
7a09f434 111
112 sprintf(s,param->GetTitle());
113 sprintf(ss,"75x40_100x60");
114 if(strcmp(s,ss)==0){
115 printf("2 pad-length geom hits with 3 pad-lenght geom digits...\n");
116 delete param;
117 param=new AliTPCParamSR();
118 }
119 else{
120 sprintf(ss,"75x40_100x60_150x60");
121 if(strcmp(s,ss)!=0) {
122 printf("No TPC parameters found...\n");
123 exit(2);
124 }
125 }
126
407ff276 127 pTPC->GenerNoise(500000); //create teble with noise
407ff276 128 //
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
135
3c038d07 136 //create digits array for given sectors
f648982e 137 // make indexes
407ff276 138 AliSimDigits ** digarr = new AliSimDigits*[nInputs];
139 for (Int_t i1=0;i1<nInputs; i1++){
3c038d07 140 digarr[i1]=0;
141 // intree[i1]
142 TTree * treear = fManager->GetInputTreeTPCS(i1);
12d8d654 143 if (!treear) {
144 cerr<<"AliTPCDigitizer: Input tree with SDigits not found in"
145 <<" input "<< i1<<endl;
146 return;
147 }
170bf274 148 treear->GetBranch("Segment")->SetAddress(&digarr[i1]);
f648982e 149 if (treear->GetIndex()==0)
150 treear->BuildIndex("fSegmentID","fSegmentID");
3c038d07 151 }
152 Stat_t nentries = fManager->GetInputTreeTPCS(0)->GetEntries();
153
154
155 //create branch's in TPC treeD
156 AliSimDigits * digrow = new AliSimDigits;
157 TTree * tree = fManager->GetTreeDTPC();
407ff276 158 tree->Branch("Segment","AliSimDigits",&digrow);
3c038d07 159 //
160
407ff276 161 param->SetZeroSup(2);
162
f648982e 163 Int_t zerosup = param->GetZeroSup();
164 //
3c038d07 165 //Loop over segments of the TPC
166
167 for (Int_t n=0; n<nentries; n++) {
407ff276 168 // for (Int_t n=0; n<300; n++) {
f648982e 169 fManager->GetInputTreeTPCS(0)->GetEvent(n);
170 digarr[0]->ExpandBuffer();
171 digarr[0]->ExpandTrackBuffer();
407ff276 172
f648982e 173 for (Int_t i=1;i<nInputs; i++){
174 fManager->GetInputTreeTPCS(i)->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());
175 if ((digarr[0]->GetID()-digarr[i]->GetID())>0)
176 printf("problem - not corresponding segment in background event\n");
177
3c038d07 178 digarr[i]->ExpandBuffer();
179 digarr[i]->ExpandTrackBuffer();
180 }
3c038d07 181 Int_t sec, row;
182 if (!param->AdjustSectorRow(digarr[0]->GetID(),sec,row)) {
183 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr[0]->GetID()<<endl;
184 continue;
185 }
186
187 digrow->SetID(digarr[0]->GetID());
188
189 Int_t nrows = digarr[0]->GetNRows();
190 Int_t ncols = digarr[0]->GetNCols();
191 digrow->Allocate(nrows,ncols);
192 digrow->AllocateTrack(3);
193
407ff276 194 Float_t q=0;
195 Int_t label[1000]; //stack for 300 events
196 Int_t labptr = 0;
197
f648982e 198 Int_t nElems = nrows*ncols;
199
407ff276 200 for (Int_t i=0;i<nInputs; i++){
201 pdig[i] = digarr[i]->GetDigits();
202 ptr[i] = digarr[i]->GetTracks();
203 }
204 Short_t *pdig1= digrow->GetDigits();
205 Int_t *ptr1= digrow->GetTracks() ;
206
f648982e 207
407ff276 208
209 // for (Int_t rows=0;rows<nrows; rows++){
210 // for (Int_t col=0;col<ncols; col++){
f648982e 211 for (Int_t elem=0;elem<nElems; elem++){
212 //for (Int_t elem=nElems;elem<nElems; elem++){
407ff276 213
214 q=0;
215 labptr=0;
216 // looop over digits
217 for (Int_t i=0;i<nInputs; i++){
218 // q += digarr[i]->GetDigitFast(rows,col);
219 q += *(pdig[i]);
220
3c038d07 221 for (Int_t tr=0;tr<3;tr++) {
407ff276 222 // Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
223 Int_t lab = ptr[i][tr*nElems];
f648982e 224 if ( (lab > 1) && *(pdig[i])>zerosup) {
407ff276 225 label[labptr]=lab+masks[i];
3c038d07 226 labptr++;
407ff276 227 }
3c038d07 228 }
407ff276 229 pdig[i]++;
230 ptr[i]++;
231
3c038d07 232 }
3c038d07 233 q/=16.; //conversion factor
407ff276 234 // Float_t noise = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac());
235 Float_t noise = pTPC->GetNoise();
3c038d07 236 q+=noise;
237 q=TMath::Nint(q);
407ff276 238 if (q > zerosup){
3c038d07 239
407ff276 240 if(q > param->GetADCSat()) q = (Short_t)(param->GetADCSat());
241 //digrow->SetDigitFast((Short_t)q,rows,col);
242 *pdig1 =Short_t(q);
243 for (Int_t tr=0;tr<3;tr++){
244 if (tr<labptr)
f648982e 245 // ((AliSimDigits*)digrow)->SetTrackIDFast(label[tr],rows,col,tr);
407ff276 246 ptr1[tr*nElems] = label[tr];
247 //else
248 // ((AliSimDigits*)digrow)->SetTrackIDFast(-1,rows,col,tr);
249 // ptr1[tr*nElems] = 1;
250 }
251 }
252 pdig1++;
253 ptr1++;
3c038d07 254 }
407ff276 255
3c038d07 256 digrow->CompresBuffer(1,zerosup);
257 digrow->CompresTrackBuffer(1);
258 tree->Fill();
259 if (fDebug>0) cerr<<sec<<"\t"<<row<<"\n";
f648982e 260 }
407ff276 261 fManager->GetTreeDTPC()->Write(0,TObject::kOverwrite);
3c038d07 262 delete digrow;
407ff276 263 for (Int_t i1=0;i1<nInputs; i1++) delete digarr[i1];
264 delete []masks;
3c038d07 265 delete digarr;
266}
267
f648982e 268
269
270//------------------------------------------------------------------------
271void AliTPCDigitizer::ExecSave(Option_t* option)
272{
273
274 // merge input tree's with summable digits
275 //output stored in TreeTPCD
276
277 TString optionString = option;
278 if (optionString.Data() == "deb") {
279 cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl;
280 fDebug = 3;
281 }
282 //get detector and geometry
283 printf("TPC merging -1 -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
284 AliTPC *pTPC = (AliTPC *) gAlice->GetModule("TPC");
285 AliTPCParam * param = pTPC->GetParam();
286 pTPC->GenerNoise(500000); //create teble with noise
287 printf("noise %f \n", param->GetNoise()*param->GetNoiseNormFac());
288 //
289 Int_t nInputs = fManager->GetNinputs();
290 Int_t * masks = new Int_t[nInputs];
291 for (Int_t i=0; i<nInputs;i++)
292 masks[i]= fManager->GetMask(i);
293 // Short_t **pdig= new Short_t*[nInputs]; //pointers to the expanded digits array
294 //Int_t **ptr= new Int_t*[nInputs]; //pointers to teh expanded tracks array
295
296 //create digits array for given sectors
297 // make indexes
298 printf("TPC merging -2 -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
299 AliSimDigits ** digarr = new AliSimDigits*[nInputs];
300 for (Int_t i1=0;i1<nInputs; i1++){
301 digarr[i1]=0;
302 // intree[i1]
303 TTree * treear = fManager->GetInputTreeTPCS(i1);
304 printf("TPC merging -2.7 -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
305 TBranch * br = treear->GetBranch("fSegmentID");
306 if (br) br->GetFile()->cd();
307 printf("TPC merging -2.75 -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
308 //treear->BuildIndex("fSegmentID","fSegmentID");
309 if (!treear) {
310 cerr<<" TPC - not existing input = \n"<<i1<<" ";
311 }
312 printf("TPC merging -2.8 -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
313 treear->GetBranch("Segment")->SetAddress(&digarr[i1]);
314 printf("TPC merging -2.9 -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
315 }
316 Stat_t nentries = fManager->GetInputTreeTPCS(0)->GetEntries();
317
318
319 //create branch's in TPC treeD
320 AliSimDigits * digrow = new AliSimDigits;
321 TTree * tree = fManager->GetTreeDTPC();
322 //if (tree->GetBranch("Segment") ) tree->GetBranch("Segment")->SetAddress(&digrow);
323 //else
324 tree->Branch("Segment","AliSimDigits",&digrow);
325 //
326 printf("TPC merging -3 -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
327 param->SetZeroSup(2);
328
329 Int_t zerosup = param->GetZeroSup();
330 //Loop over segments of the TPC
331
332 for (Int_t n=0; n<nentries; n++) {
333 // for (Int_t n=0; n<300; n++) {
334 fManager->GetInputTreeTPCS(0)->GetEvent(n);
335 digarr[0]->ExpandBuffer();
336 digarr[0]->ExpandTrackBuffer();
337
338 for (Int_t i=1;i<nInputs; i++){
339 fManager->GetInputTreeTPCS(i)->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());
340 //fManager->GetInputTreeTPCS(i)->GetEntryWithIndex(digarr[0]->GetID(),1);
341 digarr[i]->ExpandBuffer();
342 digarr[i]->ExpandTrackBuffer();
343 if ((digarr[0]->GetID()-digarr[i]->GetID())>0)
344 printf("problem\n");
345
346 }
347
348 Int_t sec, row;
349 if (!param->AdjustSectorRow(digarr[0]->GetID(),sec,row)) {
350 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr[0]->GetID()<<endl;
351 continue;
352 }
353
354 digrow->SetID(digarr[0]->GetID());
355
356 Int_t nrows = digarr[0]->GetNRows();
357 Int_t ncols = digarr[0]->GetNCols();
358 digrow->Allocate(nrows,ncols);
359 digrow->AllocateTrack(3);
360
361 Float_t q=0;
362 Int_t label[1000]; //stack for 300 events
363 Int_t labptr = 0;
364
365
366
367 for (Int_t rows=0;rows<nrows; rows++){
368 for (Int_t col=0;col<ncols; col++){
369
370 q=0;
371 labptr=0;
372 // looop over digits
373 for (Int_t i=0;i<nInputs; i++){
374 q += digarr[i]->GetDigitFast(rows,col);
375 //q += *(pdig[i]);
376
377 for (Int_t tr=0;tr<3;tr++) {
378 Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
379 //Int_t lab = ptr[i][tr*nElems];
380 if ( (lab > 1) ) {
381 label[labptr]=lab+masks[i];
382 labptr++;
383 }
384 }
385 // pdig[i]++;
386 //ptr[i]++;
387
388 }
389 q/=16.; //conversion factor
390 // Float_t noise = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac());
391 Float_t noise = pTPC->GetNoise();
392 q+=noise;
393 q=TMath::Nint(q);
394 if (q > zerosup){
395
396 if(q > param->GetADCSat()) q = (Short_t)(param->GetADCSat());
397 digrow->SetDigitFast((Short_t)q,rows,col);
398 // *pdig1 =Short_t(q);
399 for (Int_t tr=0;tr<3;tr++){
400 if (tr<labptr)
401 ((AliSimDigits*)digrow)->SetTrackIDFast(label[tr],rows,col,tr);
402 //ptr1[tr*nElems] = label[tr];
403 //else
404 // ((AliSimDigits*)digrow)->SetTrackIDFast(-1,rows,col,tr);
405 // ptr1[tr*nElems] = 1;
406 }
407 }
408 //pdig1++;
409 //ptr1++;
410 }
411 }
412
413 digrow->CompresBuffer(1,zerosup);
414 digrow->CompresTrackBuffer(1);
415 tree->Fill();
416 if (fDebug>0) cerr<<sec<<"\t"<<row<<"\n";
417 }
418 printf("end TPC merging - end -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
419 fManager->GetTreeDTPC()->Write(0,TObject::kOverwrite);
420 delete digrow;
421 for (Int_t i1=0;i1<nInputs; i1++) delete digarr[i1];
422 delete []masks;
423 delete digarr;
424}