]>
Commit | Line | Data |
---|---|---|
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 | ||
88cb7938 | 16 | /* $Id$ */ |
d37f8c34 | 17 | |
18 | #include <stdlib.h> | |
3c038d07 | 19 | #include <TTree.h> |
20 | #include <TObjArray.h> | |
21 | #include <TFile.h> | |
22 | #include <TDirectory.h> | |
19364939 | 23 | #include <Riostream.h> |
3c038d07 | 24 | |
25 | #include "AliTPCDigitizer.h" | |
26 | ||
27 | #include "AliTPC.h" | |
28 | #include "AliTPCParam.h" | |
7a09f434 | 29 | #include "AliTPCParamSR.h" |
3c038d07 | 30 | #include "AliRun.h" |
31 | #include "AliPDG.h" | |
32 | #include "AliRunDigitizer.h" | |
33 | #include "AliSimDigits.h" | |
f77f13c8 | 34 | #include "AliLog.h" |
3c038d07 | 35 | |
13116aec | 36 | #include "AliTPCcalibDB.h" |
37 | #include "AliTPCCalPad.h" | |
38 | #include "AliTPCCalROC.h" | |
39 | ||
3c038d07 | 40 | ClassImp(AliTPCDigitizer) |
41 | ||
42 | //___________________________________________ | |
43 | AliTPCDigitizer::AliTPCDigitizer() :AliDigitizer() | |
44 | { | |
45 | // Default ctor - don't use it | |
f648982e | 46 | fDebug =0; |
3c038d07 | 47 | } |
48 | ||
49 | //___________________________________________ | |
50 | AliTPCDigitizer::AliTPCDigitizer(AliRunDigitizer* manager) | |
51 | :AliDigitizer(manager) | |
52 | { | |
53 | // ctor which should be used | |
f648982e | 54 | fDebug =0; |
f77f13c8 | 55 | AliDebug(2,"(AliRunDigitizer* manager) was processed"); |
3c038d07 | 56 | } |
57 | ||
58 | //------------------------------------------------------------------------ | |
59 | AliTPCDigitizer::~AliTPCDigitizer() | |
60 | { | |
61 | // Destructor | |
62 | } | |
63 | ||
64 | ||
65 | ||
66 | //------------------------------------------------------------------------ | |
67 | Bool_t AliTPCDigitizer::Init() | |
68 | { | |
69 | // Initialization | |
70 | ||
71 | return kTRUE; | |
72 | } | |
73 | ||
74 | ||
75 | //------------------------------------------------------------------------ | |
76 | void AliTPCDigitizer::Exec(Option_t* option) | |
f648982e | 77 | { |
78 | ExecFast(option); | |
79 | } | |
80 | //------------------------------------------------------------------------ | |
81 | void AliTPCDigitizer::ExecFast(Option_t* option) | |
3c038d07 | 82 | { |
83 | ||
84 | // merge input tree's with summable digits | |
85 | //output stored in TreeTPCD | |
7a09f434 | 86 | char s[100]; |
87 | char ss[100]; | |
3c038d07 | 88 | TString optionString = option; |
89 | if (optionString.Data() == "deb") { | |
90 | cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl; | |
91 | fDebug = 3; | |
92 | } | |
93 | //get detector and geometry | |
88cb7938 | 94 | |
95 | ||
96 | AliRunLoader *rl, *orl; | |
97 | AliLoader *gime, *ogime; | |
98 | ||
99 | if (gAlice == 0x0) | |
100 | { | |
101 | Warning("ExecFast","gAlice is NULL. Loading from input 0"); | |
102 | rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0)); | |
103 | if (rl == 0x0) | |
104 | { | |
105 | Error("ExecFast","Can not find Run Loader for input 0. Can not proceed."); | |
106 | return; | |
107 | } | |
108 | rl->LoadgAlice(); | |
109 | rl->GetAliRun(); | |
110 | } | |
3c038d07 | 111 | AliTPC *pTPC = (AliTPC *) gAlice->GetModule("TPC"); |
112 | AliTPCParam * param = pTPC->GetParam(); | |
7a09f434 | 113 | |
114 | sprintf(s,param->GetTitle()); | |
115 | sprintf(ss,"75x40_100x60"); | |
116 | if(strcmp(s,ss)==0){ | |
117 | printf("2 pad-length geom hits with 3 pad-lenght geom digits...\n"); | |
118 | delete param; | |
119 | param=new AliTPCParamSR(); | |
120 | } | |
121 | else{ | |
122 | sprintf(ss,"75x40_100x60_150x60"); | |
123 | if(strcmp(s,ss)!=0) { | |
124 | printf("No TPC parameters found...\n"); | |
125 | exit(2); | |
126 | } | |
127 | } | |
128 | ||
407ff276 | 129 | pTPC->GenerNoise(500000); //create teble with noise |
407ff276 | 130 | // |
131 | Int_t nInputs = fManager->GetNinputs(); | |
132 | Int_t * masks = new Int_t[nInputs]; | |
133 | for (Int_t i=0; i<nInputs;i++) | |
134 | masks[i]= fManager->GetMask(i); | |
135 | Short_t **pdig= new Short_t*[nInputs]; //pointers to the expanded digits array | |
136 | Int_t **ptr= new Int_t*[nInputs]; //pointers to teh expanded tracks array | |
4df28b43 | 137 | Bool_t *active= new Bool_t[nInputs]; //flag for active input segments |
407ff276 | 138 | |
88cb7938 | 139 | |
3c038d07 | 140 | //create digits array for given sectors |
f648982e | 141 | // make indexes |
88cb7938 | 142 | |
407ff276 | 143 | AliSimDigits ** digarr = new AliSimDigits*[nInputs]; |
88cb7938 | 144 | for (Int_t i1=0;i1<nInputs; i1++) |
145 | { | |
146 | digarr[i1]=0; | |
147 | // intree[i1] | |
148 | rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i1)); | |
149 | gime = rl->GetLoader("TPCLoader"); | |
150 | gime->LoadSDigits("read"); | |
151 | TTree * treear = gime->TreeS(); | |
152 | ||
153 | if (!treear) | |
154 | { | |
155 | cerr<<"AliTPCDigitizer: Input tree with SDigits not found in" | |
156 | <<" input "<< i1<<endl; | |
157 | return; | |
158 | } | |
88cb7938 | 159 | |
160 | if (treear->GetIndex()==0) | |
161 | treear->BuildIndex("fSegmentID","fSegmentID"); | |
162 | treear->GetBranch("Segment")->SetAddress(&digarr[i1]); | |
12d8d654 | 163 | } |
88cb7938 | 164 | |
3c038d07 | 165 | |
166 | //create branch's in TPC treeD | |
167 | AliSimDigits * digrow = new AliSimDigits; | |
88cb7938 | 168 | |
169 | orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName()); | |
170 | ogime = orl->GetLoader("TPCLoader"); | |
171 | ||
172 | TTree * tree = ogime->TreeD(); | |
173 | if (tree == 0x0) | |
174 | { | |
175 | ogime->MakeTree("D"); | |
176 | tree = ogime->TreeD(); | |
177 | } | |
170950c3 | 178 | tree->Branch("Segment","AliSimDigits",&digrow); |
3c038d07 | 179 | // |
180 | ||
407ff276 | 181 | param->SetZeroSup(2); |
182 | ||
f648982e | 183 | Int_t zerosup = param->GetZeroSup(); |
13116aec | 184 | AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetPadGainFactor(); |
f648982e | 185 | // |
3c038d07 | 186 | //Loop over segments of the TPC |
187 | ||
4df28b43 | 188 | for (Int_t segmentID=0; segmentID<param->GetNRowsTotal(); segmentID++) |
88cb7938 | 189 | { |
4df28b43 | 190 | Int_t sec, row; |
191 | if (!param->AdjustSectorRow(segmentID,sec,row)) | |
192 | { | |
193 | cerr<<"AliTPC warning: invalid segment ID ! "<<segmentID<<endl; | |
194 | continue; | |
195 | } | |
13116aec | 196 | AliTPCCalROC * gainROC = gainTPC->GetCalROC(sec); // pad gains per given sector |
4df28b43 | 197 | digrow->SetID(segmentID); |
198 | ||
199 | Int_t nrows = 0; | |
200 | Int_t ncols = 0; | |
201 | ||
202 | Bool_t digitize = kFALSE; | |
203 | for (Int_t i=0;i<nInputs; i++) | |
88cb7938 | 204 | { |
205 | ||
206 | rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i)); | |
207 | gime = rl->GetLoader("TPCLoader"); | |
208 | ||
4df28b43 | 209 | if (gime->TreeS()->GetEntryWithIndex(segmentID,segmentID) >= 0) { |
210 | digarr[i]->ExpandBuffer(); | |
211 | digarr[i]->ExpandTrackBuffer(); | |
212 | nrows = digarr[i]->GetNRows(); | |
213 | ncols = digarr[i]->GetNCols(); | |
214 | active[i] = kTRUE; | |
215 | if (!fRegionOfInterest || (i == 0)) digitize = kTRUE; | |
216 | } else { | |
217 | active[i] = kFALSE; | |
218 | } | |
219 | if (fRegionOfInterest && !digitize) break; | |
88cb7938 | 220 | } |
4df28b43 | 221 | if (!digitize) continue; |
3c038d07 | 222 | |
3c038d07 | 223 | digrow->Allocate(nrows,ncols); |
224 | digrow->AllocateTrack(3); | |
225 | ||
407ff276 | 226 | Float_t q=0; |
227 | Int_t label[1000]; //stack for 300 events | |
228 | Int_t labptr = 0; | |
229 | ||
f648982e | 230 | Int_t nElems = nrows*ncols; |
231 | ||
88cb7938 | 232 | for (Int_t i=0;i<nInputs; i++) |
4df28b43 | 233 | if (active[i]) { |
88cb7938 | 234 | pdig[i] = digarr[i]->GetDigits(); |
235 | ptr[i] = digarr[i]->GetTracks(); | |
4df28b43 | 236 | } |
88cb7938 | 237 | |
407ff276 | 238 | Short_t *pdig1= digrow->GetDigits(); |
239 | Int_t *ptr1= digrow->GetTracks() ; | |
240 | ||
f648982e | 241 | |
407ff276 | 242 | |
88cb7938 | 243 | for (Int_t elem=0;elem<nElems; elem++) |
244 | { | |
245 | ||
246 | q=0; | |
247 | labptr=0; | |
248 | // looop over digits | |
4df28b43 | 249 | for (Int_t i=0;i<nInputs; i++) if (active[i]) |
88cb7938 | 250 | { |
251 | // q += digarr[i]->GetDigitFast(rows,col); | |
252 | q += *(pdig[i]); | |
253 | ||
254 | for (Int_t tr=0;tr<3;tr++) | |
255 | { | |
256 | // Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr); | |
257 | Int_t lab = ptr[i][tr*nElems]; | |
258 | if ( (lab > 1) && *(pdig[i])>zerosup) | |
259 | { | |
260 | label[labptr]=lab+masks[i]; | |
261 | labptr++; | |
262 | } | |
263 | } | |
264 | pdig[i]++; | |
265 | ptr[i]++; | |
266 | } | |
267 | q/=16.; //conversion factor | |
13116aec | 268 | Float_t gain = gainROC->GetValue(row,elem/nrows); // get gain for given - pad-row pad |
269 | if (gain<0.5){ | |
270 | printf("problem\n"); | |
271 | } | |
272 | q*= gain; | |
88cb7938 | 273 | // Float_t noise = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac()); |
274 | Float_t noise = pTPC->GetNoise(); | |
275 | q+=noise; | |
3c038d07 | 276 | q=TMath::Nint(q); |
88cb7938 | 277 | if (q > zerosup) |
278 | { | |
e93a083a | 279 | if(q >= param->GetADCSat()) q = (Short_t)(param->GetADCSat() - 1); |
88cb7938 | 280 | //digrow->SetDigitFast((Short_t)q,rows,col); |
281 | *pdig1 =Short_t(q); | |
282 | for (Int_t tr=0;tr<3;tr++) | |
283 | { | |
284 | if (tr<labptr) | |
285 | ptr1[tr*nElems] = label[tr]; | |
286 | } | |
287 | } | |
288 | pdig1++; | |
289 | ptr1++; | |
290 | } | |
407ff276 | 291 | |
3c038d07 | 292 | digrow->CompresBuffer(1,zerosup); |
293 | digrow->CompresTrackBuffer(1); | |
294 | tree->Fill(); | |
295 | if (fDebug>0) cerr<<sec<<"\t"<<row<<"\n"; | |
4df28b43 | 296 | } //for (Int_t n=0; n<param->GetNRowsTotal(); n++) |
88cb7938 | 297 | |
298 | ||
299 | orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName()); | |
300 | ogime = orl->GetLoader("TPCLoader"); | |
301 | ogime->WriteDigits("OVERWRITE"); | |
302 | ||
303 | //fManager->GetTreeDTPC()->Write(0,TObject::kOverwrite); | |
304 | ||
3c038d07 | 305 | delete digrow; |
407ff276 | 306 | for (Int_t i1=0;i1<nInputs; i1++) delete digarr[i1]; |
307 | delete []masks; | |
4df28b43 | 308 | delete []pdig; |
309 | delete []ptr; | |
310 | delete []active; | |
311 | delete []digarr; | |
3c038d07 | 312 | } |
313 | ||
f648982e | 314 | |
315 | ||
316 | //------------------------------------------------------------------------ | |
317 | void AliTPCDigitizer::ExecSave(Option_t* option) | |
318 | { | |
319 | ||
320 | // merge input tree's with summable digits | |
321 | //output stored in TreeTPCD | |
322 | ||
323 | TString optionString = option; | |
324 | if (optionString.Data() == "deb") { | |
325 | cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl; | |
326 | fDebug = 3; | |
327 | } | |
328 | //get detector and geometry | |
88cb7938 | 329 | AliRunLoader *rl, *orl; |
330 | AliLoader *gime, *ogime; | |
331 | ||
332 | ||
333 | orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName()); | |
334 | ogime = orl->GetLoader("TPCLoader"); | |
335 | ||
336 | rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0)); | |
337 | gime = rl->GetLoader("TPCLoader"); | |
338 | ||
339 | rl->LoadgAlice(); | |
340 | AliRun* alirun = rl->GetAliRun(); | |
341 | ||
342 | AliTPC *pTPC = (AliTPC *) alirun->GetModule("TPC"); | |
f648982e | 343 | AliTPCParam * param = pTPC->GetParam(); |
344 | pTPC->GenerNoise(500000); //create teble with noise | |
345 | printf("noise %f \n", param->GetNoise()*param->GetNoiseNormFac()); | |
346 | // | |
347 | Int_t nInputs = fManager->GetNinputs(); | |
348 | Int_t * masks = new Int_t[nInputs]; | |
349 | for (Int_t i=0; i<nInputs;i++) | |
350 | masks[i]= fManager->GetMask(i); | |
f648982e | 351 | |
f648982e | 352 | AliSimDigits ** digarr = new AliSimDigits*[nInputs]; |
88cb7938 | 353 | for (Int_t i1=0;i1<nInputs; i1++) |
354 | { | |
f648982e | 355 | digarr[i1]=0; |
356 | // intree[i1] | |
88cb7938 | 357 | rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i1)); |
358 | gime = rl->GetLoader("TPCLoader"); | |
359 | ||
360 | TTree * treear = gime->TreeS(); | |
f648982e | 361 | TBranch * br = treear->GetBranch("fSegmentID"); |
362 | if (br) br->GetFile()->cd(); | |
f648982e | 363 | if (!treear) { |
364 | cerr<<" TPC - not existing input = \n"<<i1<<" "; | |
365 | } | |
f648982e | 366 | treear->GetBranch("Segment")->SetAddress(&digarr[i1]); |
f648982e | 367 | } |
88cb7938 | 368 | |
369 | rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0)); | |
370 | gime = rl->GetLoader("TPCLoader"); | |
371 | Stat_t nentries = gime->TreeS()->GetEntries(); | |
f648982e | 372 | |
373 | ||
374 | //create branch's in TPC treeD | |
375 | AliSimDigits * digrow = new AliSimDigits; | |
88cb7938 | 376 | TTree * tree = ogime->TreeD(); |
377 | ||
f648982e | 378 | tree->Branch("Segment","AliSimDigits",&digrow); |
f648982e | 379 | param->SetZeroSup(2); |
380 | ||
381 | Int_t zerosup = param->GetZeroSup(); | |
382 | //Loop over segments of the TPC | |
383 | ||
13116aec | 384 | AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetPadGainFactor(); |
f648982e | 385 | for (Int_t n=0; n<nentries; n++) { |
88cb7938 | 386 | rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0)); |
387 | gime = rl->GetLoader("TPCLoader"); | |
388 | gime->TreeS()->GetEvent(n); | |
389 | ||
f648982e | 390 | digarr[0]->ExpandBuffer(); |
391 | digarr[0]->ExpandTrackBuffer(); | |
13116aec | 392 | |
393 | ||
f648982e | 394 | for (Int_t i=1;i<nInputs; i++){ |
88cb7938 | 395 | // fManager->GetInputTreeTPCS(i)->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID()); |
396 | rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i)); | |
397 | gime = rl->GetLoader("TPCLoader"); | |
398 | gime->TreeS()->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID()); | |
f648982e | 399 | digarr[i]->ExpandBuffer(); |
400 | digarr[i]->ExpandTrackBuffer(); | |
401 | if ((digarr[0]->GetID()-digarr[i]->GetID())>0) | |
88cb7938 | 402 | printf("problem\n"); |
f648982e | 403 | |
404 | } | |
405 | ||
406 | Int_t sec, row; | |
407 | if (!param->AdjustSectorRow(digarr[0]->GetID(),sec,row)) { | |
408 | cerr<<"AliTPC warning: invalid segment ID ! "<<digarr[0]->GetID()<<endl; | |
409 | continue; | |
410 | } | |
411 | ||
13116aec | 412 | AliTPCCalROC * gainROC = gainTPC->GetCalROC(sec); // pad gains per given sector |
f648982e | 413 | digrow->SetID(digarr[0]->GetID()); |
414 | ||
415 | Int_t nrows = digarr[0]->GetNRows(); | |
416 | Int_t ncols = digarr[0]->GetNCols(); | |
417 | digrow->Allocate(nrows,ncols); | |
418 | digrow->AllocateTrack(3); | |
419 | ||
420 | Float_t q=0; | |
421 | Int_t label[1000]; //stack for 300 events | |
422 | Int_t labptr = 0; | |
423 | ||
424 | ||
425 | ||
426 | for (Int_t rows=0;rows<nrows; rows++){ | |
427 | for (Int_t col=0;col<ncols; col++){ | |
428 | ||
88cb7938 | 429 | q=0; |
430 | labptr=0; | |
431 | // looop over digits | |
f648982e | 432 | for (Int_t i=0;i<nInputs; i++){ |
88cb7938 | 433 | q += digarr[i]->GetDigitFast(rows,col); |
f648982e | 434 | //q += *(pdig[i]); |
88cb7938 | 435 | |
f648982e | 436 | for (Int_t tr=0;tr<3;tr++) { |
88cb7938 | 437 | Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr); |
438 | //Int_t lab = ptr[i][tr*nElems]; | |
f648982e | 439 | if ( (lab > 1) ) { |
440 | label[labptr]=lab+masks[i]; | |
441 | labptr++; | |
88cb7938 | 442 | } |
f648982e | 443 | } |
88cb7938 | 444 | // pdig[i]++; |
445 | //ptr[i]++; | |
446 | ||
f648982e | 447 | } |
88cb7938 | 448 | q/=16.; //conversion factor |
449 | // Float_t noise = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac()); | |
13116aec | 450 | Float_t gain = gainROC->GetValue(row,col); |
451 | q*= gain; | |
88cb7938 | 452 | Float_t noise = pTPC->GetNoise(); |
453 | q+=noise; | |
f648982e | 454 | q=TMath::Nint(q); |
455 | if (q > zerosup){ | |
88cb7938 | 456 | |
e93a083a | 457 | if(q >= param->GetADCSat()) q = (Short_t)(param->GetADCSat() - 1); |
88cb7938 | 458 | digrow->SetDigitFast((Short_t)q,rows,col); |
459 | // *pdig1 =Short_t(q); | |
460 | for (Int_t tr=0;tr<3;tr++){ | |
461 | if (tr<labptr) | |
462 | ((AliSimDigits*)digrow)->SetTrackIDFast(label[tr],rows,col,tr); | |
463 | //ptr1[tr*nElems] = label[tr]; | |
464 | //else | |
465 | // ((AliSimDigits*)digrow)->SetTrackIDFast(-1,rows,col,tr); | |
466 | // ptr1[tr*nElems] = 1; | |
467 | } | |
468 | } | |
469 | //pdig1++; | |
470 | //ptr1++; | |
f648982e | 471 | } |
472 | } | |
473 | ||
474 | digrow->CompresBuffer(1,zerosup); | |
475 | digrow->CompresTrackBuffer(1); | |
476 | tree->Fill(); | |
477 | if (fDebug>0) cerr<<sec<<"\t"<<row<<"\n"; | |
478 | } | |
88cb7938 | 479 | // printf("end TPC merging - end -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3)); |
480 | //fManager->GetTreeDTPC()->Write(0,TObject::kOverwrite); | |
481 | ogime->WriteDigits("OVERWRITE"); | |
482 | ||
483 | for (Int_t i=1;i<nInputs; i++) | |
484 | { | |
485 | rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i)); | |
486 | gime = rl->GetLoader("TPCLoader"); | |
487 | gime->UnloadSDigits(); | |
488 | } | |
489 | ogime->UnloadDigits(); | |
490 | ||
f648982e | 491 | delete digrow; |
492 | for (Int_t i1=0;i1<nInputs; i1++) delete digarr[i1]; | |
493 | delete []masks; | |
494 | delete digarr; | |
495 | } |