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