]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFSDigitizer.cxx
SetTrackIsExiting, SetTrackIsEntering, SetTrackIsInside added.
[u/mrichter/AliRoot.git] / TOF / AliTOFSDigitizer.cxx
CommitLineData
517b7f8f 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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
16//_________________________________________________________________________
17// This is a TTask that constructs SDigits out of Hits
ea7a588a 18// A Summable Digits is the "sum" of all hits in a pad
19// Detector response has been simulated via the method
20// SimulateDetectorResponse
517b7f8f 21//
ea7a588a 22//-- Authors: F. Pierella, A. De Caro
23// Use case: see AliTOFhits2sdigits.C macro in the CVS
517b7f8f 24//////////////////////////////////////////////////////////////////////////////
25
ea7a588a 26#include "TBenchmark.h"
517b7f8f 27#include "TTask.h"
28#include "TTree.h"
29#include "TSystem.h"
ea7a588a 30#include "TParticle.h"
31#include "TH1.h"
bfec09a6 32#include "TFile.h"
33#include "TROOT.h"
34#include "TFolder.h"
35#include <TF1.h>
36#include <stdlib.h>
f8014e68 37#include <Riostream.h>
38#include <Riostream.h>
517b7f8f 39
5919c40c 40#include "AliTOFHitMap.h"
41#include "AliTOFSDigit.h"
f73548c4 42#include "AliTOFConstants.h"
517b7f8f 43#include "AliTOFhit.h"
016e1f91 44#include "AliTOFhitT0.h"
517b7f8f 45#include "AliTOF.h"
46#include "AliTOFv1.h"
47#include "AliTOFv2.h"
48#include "AliTOFv3.h"
49#include "AliTOFv4.h"
50#include "AliTOFSDigitizer.h"
51#include "AliRun.h"
52#include "AliDetector.h"
517b7f8f 53
517b7f8f 54
55ClassImp(AliTOFSDigitizer)
56
57//____________________________________________________________________________
58 AliTOFSDigitizer::AliTOFSDigitizer():TTask("AliTOFSDigitizer","")
59{
60 // ctor
ea7a588a 61 fEvent1=0;
62 fEvent2=0;
f73548c4 63 ftail = 0;
55991c8b 64 fSelectedSector=0;
65 fSelectedPlate =0;
517b7f8f 66}
67
68//____________________________________________________________________________
bfec09a6 69 AliTOFSDigitizer::AliTOFSDigitizer(char* HeaderFile, Int_t evNumber1, Int_t nEvents):TTask("AliTOFSDigitizer","")
517b7f8f 70{
ea7a588a 71 fEvent1=evNumber1;
72 fEvent2=fEvent1+nEvents;
f73548c4 73 ftail = 0;
55991c8b 74 fSelectedSector=0; // by default we sdigitize all sectors
75 fSelectedPlate =0; // by default we sdigitize all plates in all sectors
f73548c4 76
ea7a588a 77 fHeadersFile = HeaderFile ; // input filename (with hits)
ea7a588a 78 TFile * file = (TFile*) gROOT->GetFile(fHeadersFile.Data() ) ;
79
80 //File was not opened yet
81 // open file and get alirun object
82 if(file == 0){
83 file = TFile::Open(fHeadersFile.Data(),"update") ;
84 gAlice = (AliRun *) file->Get("gAlice") ;
85 }
86
f73548c4 87 // init parameters for sdigitization
88 InitParameters();
89
517b7f8f 90 // add Task to //root/Tasks folder
91 TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ;
92 roottasks->Add(this) ;
93}
94
95//____________________________________________________________________________
96 AliTOFSDigitizer::~AliTOFSDigitizer()
97{
98 // dtor
f73548c4 99}
100
101//____________________________________________________________________________
102void AliTOFSDigitizer::InitParameters()
103{
104 // set parameters for detector simulation
105
106 fTimeResolution =0.120;
107 fpadefficiency =0.99 ;
108 fEdgeEffect = 2 ;
109 fEdgeTails = 0 ;
110 fHparameter = 0.4 ;
111 fH2parameter = 0.15;
112 fKparameter = 0.5 ;
113 fK2parameter = 0.35;
114 fEffCenter = fpadefficiency;
115 fEffBoundary = 0.65;
116 fEff2Boundary = 0.90;
117 fEff3Boundary = 0.08;
118 fResCenter = 50. ;
119 fResBoundary = 70. ;
120 fResSlope = 40. ;
121 fTimeWalkCenter = 0. ;
122 fTimeWalkBoundary=0. ;
123 fTimeWalkSlope = 0. ;
124 fTimeDelayFlag = 1 ;
125 fPulseHeightSlope=2.0 ;
126 fTimeDelaySlope =0.060;
127 // was fMinimumCharge = TMath::Exp(fPulseHeightSlope*fKparameter/2.);
128 fMinimumCharge = TMath::Exp(-fPulseHeightSlope*fHparameter);
129 fChargeSmearing=0.0 ;
130 fLogChargeSmearing=0.13;
131 fTimeSmearing =0.022;
132 fAverageTimeFlag=0 ;
ea7a588a 133 fTdcBin = 50.; // 1 TDC bin = 50 ps
134 fAdcBin = 0.25; // 1 ADC bin = 0.25 pC (or 0.03 pC)
135 fAdcMean = 50.; // ADC distribution mpv value for Landau (in bins)
136 // it corresponds to a mean value of ~100 bins
137 fAdcRms = 25.; // ADC distribution rms value (in bins)
138 // it corresponds to distribution rms ~50 bins
f73548c4 139}
140
141//__________________________________________________________________
ea7a588a 142Double_t TimeWithTail(Double_t* x, Double_t* par)
f73548c4 143{
144 // sigma - par[0], alpha - par[1], part - par[2]
145 // at x<part*sigma - gauss
146 // at x>part*sigma - TMath::Exp(-x/alpha)
147 Float_t xx =x[0];
148 Double_t f;
149 if(xx<par[0]*par[2]) {
150 f = TMath::Exp(-xx*xx/(2*par[0]*par[0]));
151 } else {
152 f = TMath::Exp(-(xx-par[0]*par[2])/par[1]-0.5*par[2]*par[2]);
153 }
154 return f;
517b7f8f 155}
156
f73548c4 157
517b7f8f 158//____________________________________________________________________________
ea7a588a 159void AliTOFSDigitizer::Exec(Option_t *verboseOption, Option_t *allEvents) {
517b7f8f 160
ea7a588a 161 if(strstr(verboseOption,"tim") || strstr(verboseOption,"all"))
162 gBenchmark->Start("TOFSDigitizer");
517b7f8f 163
517b7f8f 164 AliTOF *TOF = (AliTOF *) gAlice->GetDetector ("TOF");
165
5919c40c 166 if (!TOF) {
167 Error("AliTOFSDigitizer","TOF not found");
168 return;
169 }
170
55991c8b 171 // is pointer to fSDigits non zero after changes?
172 cout<<"TOF fSDigits pointer:"<<TOF->SDigits()<<endl;
173
174 // recreate TClonesArray fSDigits - for backward compatibility
175 if (TOF->SDigits() == 0) {
176 TOF->CreateSDigitsArray();
177 } else {
178 TOF->RecreateSDigitsArray();
179 }
180
016e1f91 181 Int_t version=TOF->IsVersion();
55991c8b 182
ea7a588a 183 if (fEdgeTails) ftail = new TF1("tail",TimeWithTail,-2,2,3);
184
185 Int_t nselectedHits=0;
186 Int_t ntotalsdigits=0;
187 Int_t ntotalupdates=0;
188 Int_t nnoisesdigits=0;
189 Int_t nsignalsdigits=0;
190 Int_t nHitsFromPrim=0;
191 Int_t nHitsFromSec=0;
192 Int_t nlargeTofDiff=0;
f73548c4 193
ea7a588a 194 if (strstr(allEvents,"all")){
195 fEvent1=0;
196 fEvent2= (Int_t) gAlice->TreeE()->GetEntries();
197 }
198
55991c8b 199 Bool_t thereIsNotASelection=(fSelectedSector==0) && (fSelectedPlate==0);
200
ea7a588a 201 for (Int_t ievent = fEvent1; ievent < fEvent2; ievent++) {
202 cout << "------------------- "<< GetName() << " -------------" << endl ;
203 cout << "Sdigitizing event " << ievent << endl;
204
205 Int_t nselectedHitsinEv=0;
206 Int_t ntotalsdigitsinEv=0;
207 Int_t ntotalupdatesinEv=0;
208 Int_t nnoisesdigitsinEv=0;
209 Int_t nsignalsdigitsinEv=0;
517b7f8f 210
5919c40c 211 gAlice->GetEvent(ievent);
212 TTree *TH = gAlice->TreeH ();
213 if (!TH)
214 return;
215 if (gAlice->TreeS () == 0)
216 gAlice->MakeTree ("S");
517b7f8f 217
218
5919c40c 219 //Make branches
220 char branchname[20];
221 sprintf (branchname, "%s", TOF->GetName ());
222 //Make branch for digits
223 TOF->MakeBranch ("S");
517b7f8f 224
5919c40c 225 //Now made SDigits from hits
226
016e1f91 227
5919c40c 228 TParticle *particle;
016e1f91 229 //AliTOFhit *tofHit;
5919c40c 230 TClonesArray *TOFhits = TOF->Hits();
231
f73548c4 232 // create hit map
5919c40c 233 AliTOFHitMap *hitMap = new AliTOFHitMap(TOF->SDigits());
234
55991c8b 235 // increase performances in terms of CPU time
d7ccea72 236 //PH TH->SetBranchStatus("*",0); // switch off all branches
237 //PH TH->SetBranchStatus("TOF*",1); // switch on only TOF
238
239 TBranch * tofHitsBranch = TH->GetBranch("TOF");
bfec09a6 240
5919c40c 241 Int_t ntracks = static_cast<Int_t>(TH->GetEntries());
242 for (Int_t track = 0; track < ntracks; track++)
243 {
244 gAlice->ResetHits();
d7ccea72 245 //PH TH->GetEvent(track);
246 tofHitsBranch->GetEvent(track);
5919c40c 247 particle = gAlice->Particle(track);
248 Int_t nhits = TOFhits->GetEntriesFast();
f73548c4 249 // cleaning all hits of the same track in the same pad volume
250 // it is a rare event, however it happens
251
252 Int_t previousTrack =0;
253 Int_t previousSector=0;
254 Int_t previousPlate =0;
255 Int_t previousStrip =0;
256 Int_t previousPadX =0;
257 Int_t previousPadZ =0;
5919c40c 258
259 for (Int_t hit = 0; hit < nhits; hit++)
260 {
016e1f91 261 Int_t vol[5]; // location for a digit
262 Float_t digit[2]; // TOF digit variables
263 Int_t tracknum;
264 Float_t Xpad;
265 Float_t Zpad;
266 Float_t geantTime;
267
268 // fp: really sorry for this, it is a temporary trick to have
269 // track length too
270 if(version!=6){
271 AliTOFhit *tofHit = (AliTOFhit *) TOFhits->UncheckedAt(hit);
272 tracknum = tofHit->GetTrack();
273 vol[0] = tofHit->GetSector();
274 vol[1] = tofHit->GetPlate();
275 vol[2] = tofHit->GetStrip();
276 vol[3] = tofHit->GetPadx();
277 vol[4] = tofHit->GetPadz();
278 Xpad = tofHit->GetDx();
279 Zpad = tofHit->GetDz();
280 geantTime = tofHit->GetTof(); // unit [s]
281 } else {
282 AliTOFhitT0 *tofHit = (AliTOFhitT0 *) TOFhits->UncheckedAt(hit);
283 tracknum = tofHit->GetTrack();
284 vol[0] = tofHit->GetSector();
285 vol[1] = tofHit->GetPlate();
55991c8b 286 vol[2] = tofHit->GetStrip();
287 vol[3] = tofHit->GetPadx();
288 vol[4] = tofHit->GetPadz();
016e1f91 289 Xpad = tofHit->GetDx();
290 Zpad = tofHit->GetDz();
291 geantTime = tofHit->GetTof(); // unit [s]
292 }
293
294 geantTime *= 1.e+09; // conversion from [s] to [ns]
295
296 // selection case for sdigitizing only hits in a given plate of a given sector
297 if(thereIsNotASelection || (vol[0]==fSelectedSector && vol[1]==fSelectedPlate)){
55991c8b 298
299 Bool_t dummy=((tracknum==previousTrack) && (vol[0]==previousSector) && (vol[1]==previousPlate) && (vol[2]==previousStrip));
300
301 Bool_t isCloneOfThePrevious=dummy && ((vol[3]==previousPadX) && (vol[4]==previousPadZ));
302
b213b8bd 303 Bool_t isNeighOfThePrevious=dummy && ((((vol[3]==previousPadX-1) || (vol[3]==previousPadX+1)) && (vol[4]==previousPadZ)) || ((vol[3]==previousPadX) && ((vol[4]==previousPadZ+1) || (vol[4]==previousPadZ-1))));
55991c8b 304
b213b8bd 305 if(!isCloneOfThePrevious && !isNeighOfThePrevious){
55991c8b 306 // update "previous" values
307 // in fact, we are yet in the future, so the present is past
308 previousTrack=tracknum;
309 previousSector=vol[0];
310 previousPlate=vol[1];
311 previousStrip=vol[2];
312 previousPadX=vol[3];
313 previousPadZ=vol[4];
314
315 nselectedHits++;
316 nselectedHitsinEv++;
317 if (particle->GetFirstMother() < 0){
318 nHitsFromPrim++;
319 } // counts hits due to primary particles
320
55991c8b 321 Float_t xStrip=AliTOFConstants::fgkXPad*(vol[3]-0.5-0.5*AliTOFConstants::fgkNpadX)+Xpad;
322 Float_t zStrip=AliTOFConstants::fgkZPad*(vol[4]-0.5-0.5*AliTOFConstants::fgkNpadZ)+Zpad;
016e1f91 323
55991c8b 324 //cout << "geantTime " << geantTime << " [ns]" << endl;
325 Int_t nActivatedPads = 0, nFiredPads = 0;
326 Bool_t isFired[4] = {kFALSE, kFALSE, kFALSE, kFALSE};
327 Float_t tofAfterSimul[4] = {0., 0., 0., 0.};
328 Float_t qInduced[4] = {0.,0.,0.,0.};
329 Int_t nPlace[4] = {0, 0, 0, 0};
330 Float_t averageTime = 0.;
331 SimulateDetectorResponse(zStrip,xStrip,geantTime,nActivatedPads,nFiredPads,isFired,nPlace,qInduced,tofAfterSimul,averageTime);
332 if(nFiredPads) {
333 for(Int_t indexOfPad=0; indexOfPad<nActivatedPads; indexOfPad++) {
334 if(isFired[indexOfPad]){ // the pad has fired
335 Float_t timediff=geantTime-tofAfterSimul[indexOfPad];
336
337 if(timediff>=0.2) nlargeTofDiff++;
338
b213b8bd 339 digit[0] = (Int_t) ((tofAfterSimul[indexOfPad]*1.e+03)/fTdcBin); // TDC bin number (each bin -> 50. ps)
55991c8b 340
341 Float_t landauFactor = gRandom->Landau(fAdcMean, fAdcRms);
342 digit[1] = (Int_t) (qInduced[indexOfPad] * landauFactor); // ADC bins (each bin -> 0.25 (or 0.03) pC)
343
344 // recalculate the volume only for neighbouring pads
ea7a588a 345 if(indexOfPad){
55991c8b 346 (nPlace[indexOfPad]<=AliTOFConstants::fgkNpadX) ? vol[4] = 1 : vol[4] = 2;
347 (nPlace[indexOfPad]<=AliTOFConstants::fgkNpadX) ? vol[3] = nPlace[indexOfPad] : vol[3] = nPlace[indexOfPad] - AliTOFConstants::fgkNpadX;
ea7a588a 348 }
55991c8b 349
350 // check if two sdigit are on the same pad; in that case we sum
351 // the two or more sdigits
352 if (hitMap->TestHit(vol) != kEmpty) {
353 AliTOFSDigit *sdig = static_cast<AliTOFSDigit*>(hitMap->GetHit(vol));
354 Int_t tdctime = (Int_t) digit[0];
355 Int_t adccharge = (Int_t) digit[1];
b213b8bd 356 sdig->Update(fTdcBin,tdctime,adccharge,tracknum);
55991c8b 357 ntotalupdatesinEv++;
358 ntotalupdates++;
359 } else {
360
361 TOF->AddSDigit(tracknum, vol, digit);
362
363 if(indexOfPad){
364 nnoisesdigits++;
365 nnoisesdigitsinEv++;
366 } else {
367 nsignalsdigits++;
368 nsignalsdigitsinEv++;
369 }
370 ntotalsdigitsinEv++;
371 ntotalsdigits++;
372 hitMap->SetHit(vol);
373 } // if (hitMap->TestHit(vol) != kEmpty)
374 } // if(isFired[indexOfPad])
375 } // end loop on nActivatedPads
376 } // if(nFiredPads) i.e. if some pads has fired
377 } // close if(!isCloneOfThePrevious)
378 } // close the selection on sector and plate
5919c40c 379 } // end loop on hits for the current track
380 } // end loop on ntracks
55991c8b 381
5919c40c 382 delete hitMap;
517b7f8f 383
5919c40c 384 gAlice->TreeS()->Reset();
385 gAlice->TreeS()->Fill();
ea7a588a 386 //gAlice->TreeS()->Write(0,TObject::kOverwrite) ;
387 gAlice->TreeS()->AutoSave();
388
389 if(strstr(verboseOption,"all")){
390 cout << "----------------------------------------" << endl;
391 cout << " <AliTOFSDigitizer> " << endl;
392 cout << "After sdigitizing " << nselectedHitsinEv << " hits" << " in event " << ievent << endl;
393 //" (" << nHitsFromPrim << " from primaries and " << nHitsFromSec << " from secondaries) TOF hits, "
394 cout << ntotalsdigitsinEv << " digits have been created " << endl;
395 cout << "(" << nsignalsdigitsinEv << " due to signals and " << nnoisesdigitsinEv << " due to border effect)" << endl;
396 cout << ntotalupdatesinEv << " total updates of the hit map have been performed in current event" << endl;
397 cout << "----------------------------------------" << endl;
398 }
399
400 } //event loop on events
401
402 // free used memory
403 if (ftail){
404 delete ftail;
405 ftail = 0;
406 }
407
408 nHitsFromSec=nselectedHits-nHitsFromPrim;
409 if(strstr(verboseOption,"all")){
410 cout << "----------------------------------------" << endl;
411 cout << "----------------------------------------" << endl;
412 cout << "-----------SDigitization Summary--------" << endl;
413 cout << " <AliTOFSDigitizer> " << endl;
414 cout << "After sdigitizing " << nselectedHits << " hits" << endl;
415 cout << "in " << (fEvent2-fEvent1) << " events" << endl;
416//" (" << nHitsFromPrim << " from primaries and " << nHitsFromSec << " from secondaries) TOF hits, "
417 cout << ntotalsdigits << " sdigits have been created " << endl;
418 cout << "(" << nsignalsdigits << " due to signals and " << nnoisesdigits << " due to border effect)" << endl;
419 cout << ntotalupdates << " total updates of the hit map have been performed" << endl;
420 cout << "in " << nlargeTofDiff << " cases the time of flight difference is greater than 200 ps" << endl;
421 }
422
517b7f8f 423
ea7a588a 424 if(strstr(verboseOption,"tim") || strstr(verboseOption,"all")){
425 gBenchmark->Stop("TOFSDigitizer");
426 cout << "AliTOFSDigitizer:" << endl ;
427 cout << " took " << gBenchmark->GetCpuTime("TOFSDigitizer") << " seconds in order to make sdigits "
428 << gBenchmark->GetCpuTime("TOFSDigitizer")/(fEvent2-fEvent1) << " seconds per event " << endl ;
429 cout << endl ;
430 }
517b7f8f 431
ea7a588a 432 Print("");
517b7f8f 433}
ea7a588a 434
517b7f8f 435//__________________________________________________________________
ea7a588a 436void AliTOFSDigitizer::Print(Option_t* opt)const
517b7f8f 437{
438 cout << "------------------- "<< GetName() << " -------------" << endl ;
bfec09a6 439
517b7f8f 440}
f73548c4 441
55991c8b 442//__________________________________________________________________
443void AliTOFSDigitizer::SelectSectorAndPlate(Int_t sector, Int_t plate)
444{
445 Bool_t isaWrongSelection=(sector < 1) || (sector > AliTOFConstants::fgkNSectors) || (plate < 1) || (plate > AliTOFConstants::fgkNPlates);
446 if(isaWrongSelection){
447 cout << "You have selected an invalid value for sector or plate " << endl;
448 cout << "The correct range for sector is [1,"<< AliTOFConstants::fgkNSectors <<"]" << endl;
449 cout << "The correct range for plate is [1,"<< AliTOFConstants::fgkNPlates <<"]" << endl;
450 cout << "By default we continue sdigitizing all hits in all plates of all sectors" << endl;
451 } else {
452 fSelectedSector=sector;
453 fSelectedPlate =plate;
454 cout << "SDigitizing only hits in plate " << fSelectedPlate << " of the sector " << fSelectedSector << endl;
455 }
456}
457
f73548c4 458//__________________________________________________________________
459void AliTOFSDigitizer::SimulateDetectorResponse(Float_t z0, Float_t x0, Float_t geantTime, Int_t& nActivatedPads, Int_t& nFiredPads, Bool_t* isFired, Int_t* nPlace, Float_t* qInduced, Float_t* tofTime, Float_t& averageTime)
460{
461 // Description:
462 // Input: z0, x0 - hit position in the strip system (0,0 - center of the strip), cm
463 // geantTime - time generated by Geant, ns
464 // Output: nActivatedPads - the number of pads activated by the hit (1 || 2 || 4)
465 // nFiredPads - the number of pads fired (really activated) by the hit (nFiredPads <= nActivatedPads)
466 // qInduced[iPad]- charge induced on pad, arb. units
467 // this array is initialized at zero by the caller
468 // tofAfterSimul[iPad] - time calculated with edge effect algorithm, ns
469 // this array is initialized at zero by the caller
470 // averageTime - time given by pad hited by the Geant track taking into account the times (weighted) given by the pads fired for edge effect also.
471 // The weight is given by the qInduced[iPad]/qCenterPad
472 // this variable is initialized at zero by the caller
473 // nPlace[iPad] - the number of the pad place, iPad = 0, 1, 2, 3
474 // this variable is initialized at zero by the caller
475 //
476 // Description of used variables:
477 // eff[iPad] - efficiency of the pad
478 // res[iPad] - resolution of the pad, ns
479 // timeWalk[iPad] - time walk of the pad, ns
480 // timeDelay[iPad] - time delay for neighbouring pad to hited pad, ns
481 // PadId[iPad] - Pad Identifier
482 // E | F --> PadId[iPad] = 5 | 6
483 // A | B --> PadId[iPad] = 1 | 2
484 // C | D --> PadId[iPad] = 3 | 4
485 // nTail[iPad] - the tail number, = 1 for tailA, = 2 for tailB
486 // qCenterPad - charge extimated for each pad, arb. units
487 // weightsSum - sum of weights extimated for each pad fired, arb. units
488
489 const Float_t kSigmaForTail[2] = {AliTOFConstants::fgkSigmaForTail1,AliTOFConstants::fgkSigmaForTail2}; //for tail
490 Int_t iz = 0, ix = 0;
491 Float_t dX = 0., dZ = 0., x = 0., z = 0.;
492 Float_t h = fHparameter, h2 = fH2parameter, k = fKparameter, k2 = fK2parameter;
493 Float_t effX = 0., effZ = 0., resX = 0., resZ = 0., timeWalkX = 0., timeWalkZ = 0.;
494 Float_t logOfqInd = 0.;
495 Float_t weightsSum = 0.;
496 Int_t nTail[4] = {0,0,0,0};
497 Int_t padId[4] = {0,0,0,0};
498 Float_t eff[4] = {0.,0.,0.,0.};
499 Float_t res[4] = {0.,0.,0.,0.};
500 // Float_t qCenterPad = fMinimumCharge * fMinimumCharge;
501 Float_t qCenterPad = 1.;
502 Float_t timeWalk[4] = {0.,0.,0.,0.};
503 Float_t timeDelay[4] = {0.,0.,0.,0.};
504
505 nActivatedPads = 0;
506 nFiredPads = 0;
507
508 (z0 <= 0) ? iz = 0 : iz = 1;
509 dZ = z0 + (0.5 * AliTOFConstants::fgkNpadZ - iz - 0.5) * AliTOFConstants::fgkZPad; // hit position in the pad frame, (0,0) - center of the pad
510 z = 0.5 * AliTOFConstants::fgkZPad - TMath::Abs(dZ); // variable for eff., res. and timeWalk. functions
511 iz++; // z row: 1, ..., AliTOFConstants::fgkNpadZ = 2
512 ix = (Int_t)((x0 + 0.5 * AliTOFConstants::fgkNpadX * AliTOFConstants::fgkXPad) / AliTOFConstants::fgkXPad);
513 dX = x0 + (0.5 * AliTOFConstants::fgkNpadX - ix - 0.5) * AliTOFConstants::fgkXPad; // hit position in the pad frame, (0,0) - center of the pad
514 x = 0.5 * AliTOFConstants::fgkXPad - TMath::Abs(dX); // variable for eff., res. and timeWalk. functions;
515 ix++; // x row: 1, ..., AliTOFConstants::fgkNpadX = 48
516
517 ////// Pad A:
518 nActivatedPads++;
519 nPlace[nActivatedPads-1] = (iz - 1) * AliTOFConstants::fgkNpadX + ix;
520 qInduced[nActivatedPads-1] = qCenterPad;
521 padId[nActivatedPads-1] = 1;
522
523 if (fEdgeEffect == 0) {
524 eff[nActivatedPads-1] = fEffCenter;
525 if (gRandom->Rndm() < eff[nActivatedPads-1]) {
526 nFiredPads = 1;
527 res[nActivatedPads-1] = 0.001 * TMath::Sqrt(10400 + fResCenter * fResCenter); // 10400=30^2+20^2+40^2+50^2+50^2+50^2 ns;
528 isFired[nActivatedPads-1] = kTRUE;
529 tofTime[nActivatedPads-1] = gRandom->Gaus(geantTime + fTimeWalkCenter, res[0]);
530 averageTime = tofTime[nActivatedPads-1];
531 }
532 } else {
533
534 if(z < h) {
535 if(z < h2) {
536 effZ = fEffBoundary + (fEff2Boundary - fEffBoundary) * z / h2;
537 } else {
538 effZ = fEff2Boundary + (fEffCenter - fEff2Boundary) * (z - h2) / (h - h2);
539 }
540 resZ = fResBoundary + (fResCenter - fResBoundary) * z / h;
541 timeWalkZ = fTimeWalkBoundary + (fTimeWalkCenter - fTimeWalkBoundary) * z / h;
542 nTail[nActivatedPads-1] = 1;
543 } else {
544 effZ = fEffCenter;
545 resZ = fResCenter;
546 timeWalkZ = fTimeWalkCenter;
547 }
548
549 if(x < h) {
550 if(x < h2) {
551 effX = fEffBoundary + (fEff2Boundary - fEffBoundary) * x / h2;
552 } else {
553 effX = fEff2Boundary + (fEffCenter - fEff2Boundary) * (x - h2) / (h - h2);
554 }
555 resX = fResBoundary + (fResCenter - fResBoundary) * x / h;
556 timeWalkX = fTimeWalkBoundary + (fTimeWalkCenter - fTimeWalkBoundary) * x / h;
557 nTail[nActivatedPads-1] = 1;
558 } else {
559 effX = fEffCenter;
560 resX = fResCenter;
561 timeWalkX = fTimeWalkCenter;
562 }
563
564 (effZ<effX) ? eff[nActivatedPads-1] = effZ : eff[nActivatedPads-1] = effX;
565 (resZ<resX) ? res[nActivatedPads-1] = 0.001 * TMath::Sqrt(10400 + resX * resX) : res[nActivatedPads-1] = 0.001 * TMath::Sqrt(10400 + resZ * resZ); // 10400=30^2+20^2+40^2+50^2+50^2+50^2 ns
566 (timeWalkZ<timeWalkX) ? timeWalk[nActivatedPads-1] = 0.001 * timeWalkZ : timeWalk[nActivatedPads-1] = 0.001 * timeWalkX; // ns
567
568
569 ////// Pad B:
570 if(z < k2) {
571 effZ = fEffBoundary - (fEffBoundary - fEff3Boundary) * (z / k2);
572 } else {
573 effZ = fEff3Boundary * (k - z) / (k - k2);
574 }
575 resZ = fResBoundary + fResSlope * z / k;
576 timeWalkZ = fTimeWalkBoundary + fTimeWalkSlope * z / k;
577
578 if(z < k && z > 0) {
579 if( (iz == 1 && dZ > 0) || (iz == 2 && dZ < 0) ) {
580 nActivatedPads++;
581 nPlace[nActivatedPads-1] = nPlace[0] + (3 - 2 * iz) * AliTOFConstants::fgkNpadX;
582 eff[nActivatedPads-1] = effZ;
583 res[nActivatedPads-1] = 0.001 * TMath::Sqrt(10400 + resZ * resZ); // 10400=30^2+20^2+40^2+50^2+50^2+50^2 ns
584 timeWalk[nActivatedPads-1] = 0.001 * timeWalkZ; // ns
585 nTail[nActivatedPads-1] = 2;
586 if (fTimeDelayFlag) {
587 // qInduced[0] = fMinimumCharge * TMath::Exp(fPulseHeightSlope * z / 2.);
588 // qInduced[nActivatedPads-1] = fMinimumCharge * TMath::Exp(-fPulseHeightSlope * z / 2.);
589 qInduced[nActivatedPads-1] = TMath::Exp(-fPulseHeightSlope * z);
590 logOfqInd = gRandom->Gaus(-fPulseHeightSlope * z, fLogChargeSmearing);
591 timeDelay[nActivatedPads-1] = gRandom->Gaus(-fTimeDelaySlope * logOfqInd, fTimeSmearing);
592 } else {
593 timeDelay[nActivatedPads-1] = 0.;
594 }
595 padId[nActivatedPads-1] = 2;
596 }
597 }
598
599
600 ////// Pad C, D, E, F:
601 if(x < k2) {
602 effX = fEffBoundary - (fEffBoundary - fEff3Boundary) * (x / k2);
603 } else {
604 effX = fEff3Boundary * (k - x) / (k - k2);
605 }
606 resX = fResBoundary + fResSlope*x/k;
607 timeWalkX = fTimeWalkBoundary + fTimeWalkSlope*x/k;
608
609 if(x < k && x > 0) {
610 // C:
611 if(ix > 1 && dX < 0) {
612 nActivatedPads++;
613 nPlace[nActivatedPads-1] = nPlace[0] - 1;
614 eff[nActivatedPads-1] = effX;
615 res[nActivatedPads-1] = 0.001 * TMath::Sqrt(10400 + resX * resX); // 10400=30^2+20^2+40^2+50^2+50^2+50^2 ns
616 timeWalk[nActivatedPads-1] = 0.001 * timeWalkX; // ns
617 nTail[nActivatedPads-1] = 2;
618 if (fTimeDelayFlag) {
619 // qInduced[0] = fMinimumCharge * TMath::Exp(fPulseHeightSlope * x / 2.);
620 // qInduced[nActivatedPads-1] = fMinimumCharge * TMath::Exp(-fPulseHeightSlope * x / 2.);
621 qInduced[nActivatedPads-1] = TMath::Exp(-fPulseHeightSlope * x);
622 logOfqInd = gRandom->Gaus(-fPulseHeightSlope * x, fLogChargeSmearing);
623 timeDelay[nActivatedPads-1] = gRandom->Gaus(-fTimeDelaySlope * logOfqInd, fTimeSmearing);
624 } else {
625 timeDelay[nActivatedPads-1] = 0.;
626 }
627 padId[nActivatedPads-1] = 3;
628
629 // D:
630 if(z < k && z > 0) {
631 if( (iz == 1 && dZ > 0) || (iz == 2 && dZ < 0) ) {
632 nActivatedPads++;
633 nPlace[nActivatedPads-1] = nPlace[0] + (3 - 2 * iz) * AliTOFConstants::fgkNpadX - 1;
634 eff[nActivatedPads-1] = effX * effZ;
635 (resZ<resX) ? res[nActivatedPads-1] = 0.001 * TMath::Sqrt(10400 + resX * resX) : res[nActivatedPads-1] = 0.001 * TMath::Sqrt(10400 + resZ * resZ); // 10400=30^2+20^2+40^2+50^2+50^2+50^2 ns
636 (timeWalkZ<timeWalkX) ? timeWalk[nActivatedPads-1] = 0.001 * timeWalkZ : timeWalk[nActivatedPads-1] = 0.001 * timeWalkX; // ns
637
638 nTail[nActivatedPads-1] = 2;
639 if (fTimeDelayFlag) {
640 if (TMath::Abs(x) < TMath::Abs(z)) {
641 // qInduced[0] = fMinimumCharge * TMath::Exp(fPulseHeightSlope * z / 2.);
642 // qInduced[nActivatedPads-1] = fMinimumCharge * TMath::Exp(-fPulseHeightSlope * z / 2.);
643 qInduced[nActivatedPads-1] = TMath::Exp(-fPulseHeightSlope * z);
644 logOfqInd = gRandom->Gaus(-fPulseHeightSlope * z, fLogChargeSmearing);
645 } else {
646 // qInduced[0] = fMinimumCharge * TMath::Exp(fPulseHeightSlope * x / 2.);
647 // qInduced[nActivatedPads-1] = fMinimumCharge * TMath::Exp(-fPulseHeightSlope * x / 2.);
648 qInduced[nActivatedPads-1] = TMath::Exp(-fPulseHeightSlope * x);
649 logOfqInd = gRandom->Gaus(-fPulseHeightSlope * x, fLogChargeSmearing);
650 }
651 timeDelay[nActivatedPads-1] = gRandom->Gaus(-fTimeDelaySlope * logOfqInd, fTimeSmearing);
652 } else {
653 timeDelay[nActivatedPads-1] = 0.;
654 }
655 padId[nActivatedPads-1] = 4;
656 }
657 } // end D
658 } // end C
659
660 // E:
661 if(ix < AliTOFConstants::fgkNpadX && dX > 0) {
662 nActivatedPads++;
663 nPlace[nActivatedPads-1] = nPlace[0] + 1;
664 eff[nActivatedPads-1] = effX;
665 res[nActivatedPads-1] = 0.001 * (TMath::Sqrt(10400 + resX * resX)); // ns
666 timeWalk[nActivatedPads-1] = 0.001 * timeWalkX; // ns
667 nTail[nActivatedPads-1] = 2;
668 if (fTimeDelayFlag) {
669 // qInduced[0] = fMinimumCharge * TMath::Exp(fPulseHeightSlope * x / 2.);
670 // qInduced[nActivatedPads-1] = fMinimumCharge * TMath::Exp(-fPulseHeightSlope * x / 2.);
671 qInduced[nActivatedPads-1] = TMath::Exp(-fPulseHeightSlope * x);
672 logOfqInd = gRandom->Gaus(-fPulseHeightSlope * x, fLogChargeSmearing);
673 timeDelay[nActivatedPads-1] = gRandom->Gaus(-fTimeDelaySlope * logOfqInd, fTimeSmearing);
674 } else {
675 timeDelay[nActivatedPads-1] = 0.;
676 }
677 padId[nActivatedPads-1] = 5;
678
679
680 // F:
681 if(z < k && z > 0) {
682 if( (iz == 1 && dZ > 0) || (iz == 2 && dZ < 0) ) {
683 nActivatedPads++;
684 nPlace[nActivatedPads - 1] = nPlace[0] + (3 - 2 * iz) * AliTOFConstants::fgkNpadX + 1;
685 eff[nActivatedPads - 1] = effX * effZ;
686 (resZ<resX) ? res[nActivatedPads-1] = 0.001 * TMath::Sqrt(10400 + resX * resX) : res[nActivatedPads-1] = 0.001 * TMath::Sqrt(10400 + resZ * resZ); // 10400=30^2+20^2+40^2+50^2+50^2+50^2 ns
687 (timeWalkZ<timeWalkX) ? timeWalk[nActivatedPads-1] = 0.001 * timeWalkZ : timeWalk[nActivatedPads-1] = 0.001*timeWalkX; // ns
688 nTail[nActivatedPads-1] = 2;
689 if (fTimeDelayFlag) {
690 if (TMath::Abs(x) < TMath::Abs(z)) {
691 // qInduced[0] = fMinimumCharge * TMath::Exp(fPulseHeightSlope * z / 2.);
692 // qInduced[nActivatedPads-1] = fMinimumCharge * TMath::Exp(-fPulseHeightSlope * z / 2.);
693 qInduced[nActivatedPads-1] = TMath::Exp(-fPulseHeightSlope * z);
694 logOfqInd = gRandom->Gaus(-fPulseHeightSlope * z, fLogChargeSmearing);
695 } else {
696 // qInduced[0] = fMinimumCharge * TMath::Exp(fPulseHeightSlope * x / 2.);
697 // qInduced[nActivatedPads-1] = fMinimumCharge * TMath::Exp(-fPulseHeightSlope * x / 2.);
698 qInduced[nActivatedPads-1] = TMath::Exp(-fPulseHeightSlope * x);
699 logOfqInd = gRandom->Gaus(-fPulseHeightSlope * x, fLogChargeSmearing);
700 }
701 timeDelay[nActivatedPads-1] = gRandom->Gaus(-fTimeDelaySlope * logOfqInd, fTimeSmearing);
702 } else {
703 timeDelay[nActivatedPads-1] = 0.;
704 }
705 padId[nActivatedPads-1] = 6;
706 }
707 } // end F
708 } // end E
709 } // end if(x < k)
710
711
712 for (Int_t iPad = 0; iPad < nActivatedPads; iPad++) {
713 if (res[iPad] < fTimeResolution) res[iPad] = fTimeResolution;
714 if(gRandom->Rndm() < eff[iPad]) {
715 isFired[iPad] = kTRUE;
716 nFiredPads++;
717 if(fEdgeTails) {
718 if(nTail[iPad] == 0) {
719 tofTime[iPad] = gRandom->Gaus(geantTime + timeWalk[iPad] + timeDelay[iPad], res[iPad]);
720 } else {
721 ftail->SetParameters(res[iPad], 2. * res[iPad], kSigmaForTail[nTail[iPad]-1]);
722 Double_t timeAB = ftail->GetRandom();
723 tofTime[iPad] = geantTime + timeWalk[iPad] + timeDelay[iPad] + timeAB;
724 }
725 } else {
726 tofTime[iPad] = gRandom->Gaus(geantTime + timeWalk[iPad] + timeDelay[iPad], res[iPad]);
727 }
728 if (fAverageTimeFlag) {
729 averageTime += tofTime[iPad] * qInduced[iPad];
730 weightsSum += qInduced[iPad];
731 } else {
732 averageTime += tofTime[iPad];
733 weightsSum += 1.;
734 }
735 }
736 }
737 if (weightsSum!=0) averageTime /= weightsSum;
738 } // end else (fEdgeEffect != 0)
739}
740
741//__________________________________________________________________
742void AliTOFSDigitizer::PrintParameters()const
743{
744 //
745 // Print parameters used for sdigitization
746 //
747 cout << " ------------------- "<< GetName() << " -------------" << endl ;
748 cout << " Parameters used for TOF SDigitization " << endl ;
749 // Printing the parameters
750
ea7a588a 751 cout << " Number of events: " << (fEvent2-fEvent1) << endl;
752 cout << " from event " << fEvent1 << " to event " << (fEvent2-1) << endl;
f73548c4 753 cout << " Time Resolution (ns) "<< fTimeResolution <<" Pad Efficiency: "<< fpadefficiency << endl;
754 cout << " Edge Effect option: "<< fEdgeEffect<< endl;
755
756 cout << " Boundary Effect Simulation Parameters " << endl;
757 cout << " Hparameter: "<< fHparameter<<" H2parameter:"<< fH2parameter <<" Kparameter:"<< fKparameter<<" K2parameter: "<< fK2parameter << endl;
758 cout << " Efficiency in the central region of the pad: "<< fEffCenter << endl;
759 cout << " Efficiency at the boundary region of the pad: "<< fEffBoundary << endl;
760 cout << " Efficiency value at H2parameter "<< fEff2Boundary << endl;
761 cout << " Efficiency value at K2parameter "<< fEff3Boundary << endl;
762 cout << " Resolution (ps) in the central region of the pad: "<< fResCenter << endl;
763 cout << " Resolution (ps) at the boundary of the pad : "<< fResBoundary << endl;
764 cout << " Slope (ps/K) for neighbouring pad : "<< fResSlope <<endl;
765 cout << " Time walk (ps) in the central region of the pad : "<< fTimeWalkCenter << endl;
766 cout << " Time walk (ps) at the boundary of the pad : "<< fTimeWalkBoundary<< endl;
767 cout << " Slope (ps/K) for neighbouring pad : "<< fTimeWalkSlope<<endl;
768 cout << " Pulse Heigth Simulation Parameters " << endl;
769 cout << " Flag for delay due to the PulseHeightEffect: "<< fTimeDelayFlag <<endl;
770 cout << " Pulse Height Slope : "<< fPulseHeightSlope<<endl;
771 cout << " Time Delay Slope : "<< fTimeDelaySlope<<endl;
772 cout << " Minimum charge amount which could be induced : "<< fMinimumCharge<<endl;
773 cout << " Smearing in charge in (q1/q2) vs x plot : "<< fChargeSmearing<<endl;
774 cout << " Smearing in log of charge ratio : "<< fLogChargeSmearing<<endl;
775 cout << " Smearing in time in time vs log(q1/q2) plot : "<< fTimeSmearing<<endl;
776 cout << " Flag for average time : "<< fAverageTimeFlag<<endl;
777 cout << " Edge tails option : "<< fEdgeTails << endl;
778
779}