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