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