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