1 /**************************************************************************
2 * Copyright(c) 2004, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //////////////////////////////////////////////////////////////////////////////
20 // This class contains the procedures simulation ADC signal for the
21 // Forward Multiplicity detector : Hits->Digits and Hits->SDigits
28 // - ADC count in this channel
35 // - Total energy deposited in the strip
36 // - ADC count in this channel
38 // As the Digits and SDigits have so much in common, the classes
39 // AliFMDDigitizer and AliFMDSDigitizer are implemented via a base
40 // class AliFMDBaseDigitizer.
42 // +---------------------+
43 // | AliFMDBaseDigitizer |
44 // +---------------------+
47 // +----------+---------+
49 // +-----------------+ +------------------+
50 // | AliFMDDigitizer | | AliFMDSDigitizer |
51 // +-----------------+ +------------------+
53 // These classes has several paramters:
57 // (Only AliFMDDigitizer)
58 // Mean and width of the pedestal. The pedestal is simulated
59 // by a Guassian, but derived classes my override MakePedestal
60 // to simulate it differently (or pick it up from a database).
63 // The dymamic MIP range of the VA1_ALICE pre-amplifier chip
66 // The largest number plus one that can be stored in one
67 // channel in one time step in the ALTRO ADC chip.
70 // How many times the ALTRO ADC chip samples the VA1_ALICE
71 // pre-amplifier signal. The VA1_ALICE chip is read-out at
72 // 10MHz, while it's possible to drive the ALTRO chip at
73 // 25MHz. That means, that the ALTRO chip can have time to
74 // sample each VA1_ALICE signal up to 2 times. Although it's
75 // not certain this feature will be used in the production,
76 // we'd like have the option, and so it should be reflected in
80 // The shaping function of the VA1_ALICE is generally given by
82 // f(x) = A(1 - exp(-Bx))
84 // where A is the total charge collected in the pre-amp., and B is a
85 // paramter that depends on the shaping time of the VA1_ALICE circut.
87 // When simulating the shaping function of the VA1_ALICe
88 // pre-amp. chip, we have to take into account, that the shaping
89 // function depends on the previous value of read from the pre-amp.
91 // That results in the following algorithm:
94 // FOR charge IN pre-amp. charge train DO
95 // IF last < charge THEN
96 // f(t) = (charge - last) * (1 - exp(-B * t)) + last
98 // f(t) = (last - charge) * exp(-B * t) + charge)
100 // FOR i IN # samples DO
101 // adc_i = f(i / (# samples))
108 // pre-amp. charge train
109 // is a series of 128 charges read from the VA1_ALICE chip
112 // is the number of times the ALTRO ADC samples each of the 128
113 // charges from the pre-amp.
115 // Where Q is the total charge collected by the VA1_ALICE
116 // pre-amplifier. Q is then given by
122 // where E is the total energy deposited in a silicon strip, R is the
123 // dynamic range of the VA1_ALICE pre-amp (fVA1MipRange), e is the
124 // energy deposited by a single MIP, and S ALTRO channel size in each
125 // time step (fAltroChannelSize).
127 // The energy deposited per MIP is given by
131 // where M is the universal number 1.664, rho is the density of
132 // silicon, and w is the depth of the silicon sensor.
134 // The final ADC count is given by
138 // where P is the (randomized) pedestal (see MakePedestal)
140 // This class uses the class template AliFMDMap<Type> to make an
141 // internal cache of the energy deposted of the hits. The class
142 // template is instantasized as
144 // typedef AliFMDMap<std::pair<Float_t, UShort_t> > AliFMDEdepMap;
146 // The first member of the values is the summed energy deposition in a
147 // given strip, while the second member of the values is the number of
148 // hits in a given strip. Using the second member, it's possible to
149 // do some checks on just how many times a strip got hit, and what
150 // kind of error we get in our reconstructed hits. Note, that this
151 // information is currently not written to the digits tree. I think a
152 // QA (Quality Assurance) digit tree is better suited for that task.
153 // However, the information is there to be used in the future.
156 // Latest changes by Christian Holm Christensen
158 //////////////////////////////////////////////////////////////////////////////
161 // | A(-1 + B + exp(-B))
162 // | f(x) dx = ------------------- = 1
166 // and B is the a parameter defined by the shaping time (fShapingTime).
168 // Solving the above equation, for A gives
171 // A = ----------------
174 // So, if we define the function g: [0,1] -> [0:1] by
177 // | Bu + exp(-Bu) - Bv - exp(-Bv)
178 // g(u,v) = | f(x) dx = -A -----------------------------
182 // we can evaluate the ALTRO sample of the VA1_ALICE pre-amp between
183 // any two times (u, v), by
186 // B Bu + exp(-Bu) - Bv - exp(-Bv)
187 // C = Q g(u,v) = - Q ---------------- -----------------------------
188 // -1 + B + exp(-B) B
190 // Bu + exp(-Bu) - Bv - exp(-Bv)
191 // = - Q -----------------------------
195 #include "TTree.h" // ROOT_TTree
196 #include "TRandom.h" // ROOT_TRandom
197 #include "AliLog.h" // ALILOG_H
198 #include "AliFMDDigitizer.h" // ALIFMDDIGITIZER_H
199 #include "AliFMD.h" // ALIFMD_H
200 #include "AliFMDHit.h" // ALIFMDHIT_H
201 #include "AliFMDDigit.h" // ALIFMDDIGIT_H
202 #include "AliRunDigitizer.h" // ALIRUNDIGITIZER_H
203 #include "AliRun.h" // ALIRUN_H
204 #include "AliLoader.h" // ALILOADER_H
205 #include "AliRunLoader.h" // ALIRUNLOADER_H
207 //____________________________________________________________________
208 ClassImp(AliFMDEdepMap);
210 //====================================================================
211 ClassImp(AliFMDBaseDigitizer);
213 //____________________________________________________________________
214 AliFMDBaseDigitizer::AliFMDBaseDigitizer()
217 // Default ctor - don't use it
220 //____________________________________________________________________
221 AliFMDBaseDigitizer::AliFMDBaseDigitizer(AliRunDigitizer* manager)
222 : AliDigitizer(manager, "AliFMDBaseDigitizer", "FMD Digitizer base class"),
224 fEdep(AliFMDMap::kMaxDetectors,
225 AliFMDMap::kMaxRings,
226 AliFMDMap::kMaxSectors,
227 AliFMDMap::kMaxStrips)
230 AliDebug(1," processed");
232 SetAltroChannelSize();
237 //____________________________________________________________________
238 AliFMDBaseDigitizer::AliFMDBaseDigitizer(const Char_t* name,
240 : AliDigitizer(name, title),
242 fEdep(AliFMDMap::kMaxDetectors,
243 AliFMDMap::kMaxRings,
244 AliFMDMap::kMaxSectors,
245 AliFMDMap::kMaxStrips)
248 AliDebug(1," processed");
250 SetAltroChannelSize();
255 //____________________________________________________________________
256 AliFMDBaseDigitizer::~AliFMDBaseDigitizer()
261 //____________________________________________________________________
263 AliFMDBaseDigitizer::Init()
270 //____________________________________________________________________
272 AliFMDBaseDigitizer::SumContributions(AliFMD* fmd)
274 // Sum energy deposited contributions from each hit in a cache
277 Fatal("SumContributions", "no run loader");
279 // Clear array of deposited energies
282 // Get the FMD loader
283 AliLoader* inFMD = fRunLoader->GetLoader("FMDLoader");
285 inFMD->LoadHits("READ");
287 // Get the tree of hits
288 TTree* hitsTree = inFMD->TreeH();
291 inFMD->LoadHits("READ");
292 hitsTree = inFMD->TreeH();
295 // Get the FMD branch
296 TBranch* hitsBranch = hitsTree->GetBranch("FMD");
297 if (hitsBranch) fmd->SetHitsAddressBranch(hitsBranch);
298 else AliFatal("Branch FMD hit not found");
300 // Get a list of hits from the FMD manager
301 TClonesArray *fmdHits = fmd->Hits();
303 // Get number of entries in the tree
304 Int_t ntracks = Int_t(hitsTree->GetEntries());
306 // Loop over the tracks in the
307 for (Int_t track = 0; track < ntracks; track++) {
308 // Read in entry number `track'
309 hitsBranch->GetEntry(track);
311 // Get the number of hits
312 Int_t nhits = fmdHits->GetEntries ();
313 for (Int_t hit = 0; hit < nhits; hit++) {
314 // Get the hit number `hit'
316 static_cast<AliFMDHit*>(fmdHits->UncheckedAt(hit));
318 // Extract parameters
319 UShort_t detector = fmdHit->Detector();
320 Char_t ring = fmdHit->Ring();
321 UShort_t sector = fmdHit->Sector();
322 UShort_t strip = fmdHit->Strip();
323 Float_t edep = fmdHit->Edep();
324 if (fEdep(detector, ring, sector, strip).fEdep != 0)
325 AliDebug(1, Form("Double hit in %d%c(%d,%d)",
326 detector, ring, sector, strip));
328 fEdep(detector, ring, sector, strip).fEdep += edep;
329 fEdep(detector, ring, sector, strip).fN += 1;
330 // Add this to the energy deposited for this strip
335 //____________________________________________________________________
337 AliFMDBaseDigitizer::DigitizeHits(AliFMD* fmd) const
339 // For the stored energy contributions in the cache (fEdep), convert
340 // the energy signal to ADC counts, and store the created digit in
341 // the digits array (AliFMD::fDigits)
344 for (UShort_t detector=1; detector <= 3; detector++) {
345 // Get pointer to subdetector
346 AliFMDSubDetector* det = 0;
348 case 1: det = fmd->GetFMD1(); break;
349 case 2: det = fmd->GetFMD2(); break;
350 case 3: det = fmd->GetFMD3(); break;
353 for (UShort_t ringi = 0; ringi <= 1; ringi++) {
354 // Get pointer to Ring
357 case 0: if (det->GetInner()) r = det->GetInner(); break;
358 case 1: if (det->GetOuter()) r = det->GetOuter(); break;
362 // Get number of sectors
363 UShort_t nSectors = UShort_t(360. / r->GetTheta());
364 // Loop over the number of sectors
365 for (UShort_t sector = 0; sector < nSectors; sector++) {
366 // Get number of strips
367 UShort_t nStrips = r->GetNStrips();
368 // Loop over the stips
370 for (UShort_t strip = 0; strip < nStrips; strip++) {
371 // Reset the counter array to the invalid value -1
373 // Reset the last `ADC' value when we've get to the end of a
374 // VA1_ALICE channel.
375 if (strip % 128 == 0) last = 0;
377 Float_t edep = fEdep(detector, r->GetId(), sector, strip).fEdep;
378 ConvertToCount(edep, last, r->GetSiThickness(), fmd->GetSiDensity(),
381 AddDigit(fmd, detector, r->GetId(), sector, strip,
382 edep, UShort_t(counts[0]),
383 Short_t(counts[1]), Short_t(counts[2]));
385 // This checks if the digit created will give the `right'
386 // number of particles when reconstructed, using a naiive
387 // approach. It's here only as a quality check - nothing
389 CheckDigit(fEdep(detector, r->GetId(), sector, strip).fEdep,
390 fEdep(detector, r->GetId(), sector, strip).fN,
399 //____________________________________________________________________
401 AliFMDBaseDigitizer::ConvertToCount(Float_t edep,
405 TArrayI& counts) const
407 // Convert the total energy deposited to a (set of) ADC count(s).
411 // Energy_Deposited ALTRO_Channel_Size
412 // ADC = -------------------------- ------------------- + pedestal
413 // Energy_Deposition_Of_1_MIP VA1_ALICE_MIP_Range
415 // Energy_Deposited fAltroChannelSize
416 // = --------------------------------- ----------------- + pedestal
417 // 1.664 * Si_Thickness * Si_Density fVA1MipRange
420 // = Energy_Deposited * ConversionFactor + pedestal
422 // However, this is modified by the response function of the
423 // VA1_ALICE pre-amp. chip in case we are doing oversampling of the
426 // In that case, we get N=fSampleRate values of the ADC, and the
427 // `EnergyDeposited' is a function of which sample where are
428 // calculating the ADC for
430 // ADC_i = f(EnergyDeposited, i/N, Last) * ConversionFactor + pedestal
432 // where Last is the Energy deposited in the previous strip.
434 // Here, f is the shaping function of the VA1_ALICE. This is given
437 // | (E - l) * (1 - exp(-B * t) + l if E > l
439 // | (l - E) * exp(-B * t) + E otherwise
442 // = E + (l - E) * ext(-B * t)
444 const Float_t mipEnergy = 1.664 * siThickness * siDensity;
445 const Float_t convf = (1 / mipEnergy * Float_t(fAltroChannelSize)
447 UShort_t ped = MakePedestal();
449 // In case we don't oversample, just return the end value.
450 if (fSampleRate == 1) {
451 counts[0] = UShort_t(TMath::Min(edep * convf + ped,
452 Float_t(fAltroChannelSize)));
457 Int_t n = fSampleRate;
458 Float_t B = fShapingTime;
459 for (Ssiz_t i = 0; i < n; i++) {
460 Float_t t = Float_t(i) / n;
461 Float_t s = edep + (last - edep) * TMath::Exp(-B * t);
462 counts[i] = UShort_t(TMath::Min(s * convf + ped,
463 Float_t(fAltroChannelSize)));
468 //====================================================================
469 ClassImp(AliFMDDigitizer);
471 //____________________________________________________________________
472 AliFMDDigitizer::AliFMDDigitizer()
473 : AliFMDBaseDigitizer()
475 // Default ctor - don't use it
478 //____________________________________________________________________
479 AliFMDDigitizer::AliFMDDigitizer(AliRunDigitizer* manager)
480 : AliFMDBaseDigitizer(manager)
483 AliDebug(1," processed");
487 //____________________________________________________________________
489 AliFMDDigitizer::Exec(Option_t*)
491 // Get the output manager
492 TString outFolder(fManager->GetOutputFolderName());
494 AliRunLoader::GetRunLoader(outFolder.Data());
495 // Get the FMD output manager
496 AliLoader* outFMD = out->GetLoader("FMDLoader");
498 // Get the input loader
499 TString inFolder(fManager->GetInputFolderName(0));
501 AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
503 AliError("Can not find Run Loader for input stream 0");
506 // Get the AliRun object
507 if (!fRunLoader->GetAliRun()) fRunLoader->LoadgAlice();
509 // Get the AliFMD object
510 AliFMD* fmd = static_cast<AliFMD*>(fRunLoader->GetAliRun()->GetDetector("FMD"));
512 AliError("Can not get FMD from gAlice");
516 Int_t nFiles= fManager->GetNinputs();
517 for (Int_t inputFile = 0; inputFile < nFiles; inputFile++) {
518 AliDebug(1,Form(" Digitizing event number %d",
519 fManager->GetOutputEventNr()));
520 // Get the current loader
522 AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
523 if (!fRunLoader) Fatal("Exec", "no run loader");
524 // Cache contriutions
525 SumContributions(fmd);
527 // Digitize the event
530 // Load digits from the tree
531 outFMD->LoadDigits("update");
532 // Get the tree of digits
533 TTree* digitTree = outFMD->TreeD();
535 outFMD->MakeTree("D");
536 digitTree = outFMD->TreeD();
539 // Make a branch in the tree
540 TClonesArray* digits = fmd->Digits();
541 fmd->MakeBranchInTree(digitTree, fmd->GetName(), &(digits), 4000, 0);
542 // TBranch* digitBranch = digitTree->GetBranch(fmd->GetName());
546 // Write the digits to disk
547 outFMD->WriteDigits("OVERWRITE");
548 outFMD->UnloadHits();
549 outFMD->UnloadDigits();
551 // Reset the digits in the AliFMD object
556 //____________________________________________________________________
558 AliFMDDigitizer::MakePedestal() const
560 return UShort_t(TMath::Max(gRandom->Gaus(fPedestal, fPedestalWidth), 0.));
563 //____________________________________________________________________
565 AliFMDDigitizer::AddDigit(AliFMD* fmd,
573 Short_t count3) const
575 fmd->AddDigit(detector, ring, sector, strip, count1, count2, count3);
578 //____________________________________________________________________
580 AliFMDDigitizer::CheckDigit(Float_t /* edep */,
582 const TArrayI& counts)
584 Int_t integral = counts[0];
585 if (counts[1] >= 0) integral += counts[1];
586 if (counts[2] >= 0) integral += counts[2];
587 integral -= Int_t(fPedestal + 2 * fPedestalWidth);
588 if (integral < 0) integral = 0;
590 Float_t convf = Float_t(fVA1MipRange) / fAltroChannelSize;
591 Float_t mips = integral * convf;
592 if (mips > Float_t(nhits) + .5 || mips < Float_t(nhits) - .5)
593 Warning("CheckDigit", "Digit -> %4.2f MIPS != %d +/- .5 hits",
597 //====================================================================
598 ClassImp(AliFMDSDigitizer);
600 //____________________________________________________________________
601 AliFMDSDigitizer::AliFMDSDigitizer()
603 // Default ctor - don't use it
606 //____________________________________________________________________
607 AliFMDSDigitizer::AliFMDSDigitizer(const Char_t* headerFile,
608 const Char_t* /* sdigfile */)
609 : AliFMDBaseDigitizer("FMDSDigitizer", "FMD SDigitizer")
612 AliDebug(1," processed");
614 fRunLoader = AliRunLoader::GetRunLoader(); // Open(headerFile);
616 Fatal("AliFMDSDigitizer", "cannot open session, header file '%s'",
618 AliLoader* loader = fRunLoader->GetLoader("FMDLoader");
620 Fatal("AliFMDSDigitizer", "cannot find FMD loader in specified event");
622 // Add task to tasks folder
623 loader->PostSDigitizer(this);
627 //____________________________________________________________________
628 AliFMDSDigitizer::~AliFMDSDigitizer()
630 AliLoader* loader = fRunLoader->GetLoader("FMDLoader");
631 loader->CleanSDigitizer();
634 //____________________________________________________________________
636 AliFMDSDigitizer::Exec(Option_t*)
638 // Get the output manager
640 Error("Exec", "Run loader is not set");
643 if (!fRunLoader->GetAliRun()) fRunLoader->LoadgAlice();
644 if (!fRunLoader->TreeE()) fRunLoader->LoadHeader();
646 AliLoader* fmdLoader = fRunLoader->GetLoader("FMDLoader");
647 if (!fmdLoader) Fatal("Exec", "no FMD loader");
649 // Get the AliFMD object
651 static_cast<AliFMD*>(fRunLoader->GetAliRun()->GetDetector("FMD"));
653 AliError("Can not get FMD from gAlice");
657 Int_t nEvents = Int_t(fRunLoader->TreeE()->GetEntries());
658 for (Int_t event = 0; event < nEvents; event++) {
659 AliDebug(1,Form(" Digitizing event number %d", event));
660 // Get the current loader
661 fRunLoader->GetEvent(event);
663 if (!fmdLoader->TreeS()) fmdLoader->MakeTree("S");
665 fmd->MakeBranch("S");
667 // Cache contriutions
668 SumContributions(fmd);
670 // Digitize the event
673 fmdLoader->TreeS()->Reset();
674 fmdLoader->TreeS()->Fill();
675 fmdLoader->WriteSDigits("OVERWRITE");
679 //____________________________________________________________________
681 AliFMDSDigitizer::AddDigit(AliFMD* fmd,
689 Short_t count3) const
691 fmd->AddSDigit(detector, ring, sector, strip, edep, count1, count2, count3);
696 //____________________________________________________________________