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