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