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