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