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 **************************************************************************/
15 /* $Id: AliFMDHitDigitizer.cxx 28055 2008-08-18 00:33:20Z cholm $ */
16 /** @file AliFMDHitDigitizer.cxx
17 @author Christian Holm Christensen <cholm@nbi.dk>
18 @date Mon Mar 27 12:38:26 2006
19 @brief FMD Digitizers implementation
22 //////////////////////////////////////////////////////////////////////////////
24 // This class contains the procedures simulation ADC signal for the
25 // Forward Multiplicity detector : Hits->Digits
32 // - ADC count in this channel
34 // As the Digits and SDigits have so much in common, the classes
35 // AliFMDHitDigitizer and AliFMDSDigitizer are implemented via a base
36 // class AliFMDBaseDigitizer.
38 // +---------------------+
39 // | AliFMDBaseDigitizer |
40 // +---------------------+
43 // +----------+---------+
45 // +-----------------+ +------------------+
46 // | AliFMDHitDigitizer | | AliFMDSDigitizer |
47 // +-----------------+ +------------------+
49 // These classes has several paramters:
53 // (Only AliFMDHitDigitizer)
54 // Mean and width of the pedestal. The pedestal is simulated
55 // by a Guassian, but derived classes my override MakePedestal
56 // to simulate it differently (or pick it up from a database).
59 // The dymamic MIP range of the VA1_ALICE pre-amplifier chip
62 // The largest number plus one that can be stored in one
63 // channel in one time step in the ALTRO ADC chip.
66 // How many times the ALTRO ADC chip samples the VA1_ALICE
67 // pre-amplifier signal. The VA1_ALICE chip is read-out at
68 // 10MHz, while it's possible to drive the ALTRO chip at
69 // 25MHz. That means, that the ALTRO chip can have time to
70 // sample each VA1_ALICE signal up to 2 times. Although it's
71 // not certain this feature will be used in the production,
72 // we'd like have the option, and so it should be reflected in
75 // These parameters are fetched from OCDB via the mananger AliFMDParameters.
77 // The shaping function of the VA1_ALICE is generally given by
79 // f(x) = A(1 - exp(-Bx))
81 // where A is the total charge collected in the pre-amp., and B is a
82 // paramter that depends on the shaping time of the VA1_ALICE circut.
84 // When simulating the shaping function of the VA1_ALICe
85 // pre-amp. chip, we have to take into account, that the shaping
86 // function depends on the previous value of read from the pre-amp.
88 // That results in the following algorithm:
91 // FOR charge IN pre-amp. charge train DO
92 // IF last < charge THEN
93 // f(t) = (charge - last) * (1 - exp(-B * t)) + last
95 // f(t) = (last - charge) * exp(-B * t) + charge)
97 // FOR i IN # samples DO
98 // adc_i = f(i / (# samples))
105 // pre-amp. charge train
106 // is a series of 128 charges read from the VA1_ALICE chip
109 // is the number of times the ALTRO ADC samples each of the 128
110 // charges from the pre-amp.
112 // Where Q is the total charge collected by the VA1_ALICE
113 // pre-amplifier. Q is then given by
119 // where E is the total energy deposited in a silicon strip, R is the
120 // dynamic range of the VA1_ALICE pre-amp (fVA1MipRange), e is the
121 // energy deposited by a single MIP, and S ALTRO channel size in each
122 // time step (fAltroChannelSize).
124 // The energy deposited per MIP is given by
128 // where M is the universal number 1.664, rho is the density of
129 // silicon, and w is the depth of the silicon sensor.
131 // The final ADC count is given by
135 // where P is the (randomized) pedestal (see MakePedestal)
137 // This class uses the class template AliFMDMap<Type> to make an
138 // internal cache of the energy deposted of the hits. The class
139 // template is instantasized as
141 // typedef AliFMDMap<std::pair<Float_t, UShort_t> > AliFMDEdepMap;
143 // The first member of the values is the summed energy deposition in a
144 // given strip, while the second member of the values is the number of
145 // hits in a given strip. Using the second member, it's possible to
146 // do some checks on just how many times a strip got hit, and what
147 // kind of error we get in our reconstructed hits. Note, that this
148 // information is currently not written to the digits tree. I think a
149 // QA (Quality Assurance) digit tree is better suited for that task.
150 // However, the information is there to be used in the future.
153 // Latest changes by Christian Holm Christensen
155 //////////////////////////////////////////////////////////////////////////////
158 // | A(-1 + B + exp(-B))
159 // | f(x) dx = ------------------- = 1
163 // and B is the a parameter defined by the shaping time (fShapingTime).
165 // Solving the above equation, for A gives
168 // A = ----------------
171 // So, if we define the function g: [0,1] -> [0:1] by
174 // | Bu + exp(-Bu) - Bv - exp(-Bv)
175 // g(u,v) = | f(x) dx = -A -----------------------------
179 // we can evaluate the ALTRO sample of the VA1_ALICE pre-amp between
180 // any two times (u, v), by
183 // B Bu + exp(-Bu) - Bv - exp(-Bv)
184 // C = Q g(u,v) = - Q ---------------- -----------------------------
185 // -1 + B + exp(-B) B
187 // Bu + exp(-Bu) - Bv - exp(-Bv)
188 // = - Q -----------------------------
192 #include <TTree.h> // ROOT_TTree
193 #include "AliFMDDebug.h" // Better debug macros
194 #include "AliFMDHitDigitizer.h" // ALIFMDDIGITIZER_H
195 #include "AliFMD.h" // ALIFMD_H
196 #include "AliFMDDigit.h" // ALIFMDDIGIT_H
197 #include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
198 #include <AliRun.h> // ALIRUN_H
199 #include <AliLoader.h> // ALILOADER_H
200 #include <AliRunLoader.h> // ALIRUNLOADER_H
201 #include <AliFMDHit.h>
202 #include <AliStack.h>
204 #include <TParticle.h>
206 //====================================================================
207 ClassImp(AliFMDHitDigitizer)
212 //____________________________________________________________________
213 AliFMDHitDigitizer::AliFMDHitDigitizer(AliFMD* fmd, Output_t output)
214 : AliFMDBaseDigitizer("FMD", (output == kDigits ?
215 "FMD Hit->Digit digitizer" :
216 "FMD Hit->SDigit digitizer")),
224 //____________________________________________________________________
226 AliFMDHitDigitizer::operator=(const AliFMDHitDigitizer& o)
229 * Assignment operator
231 * @param o Object to assign from
232 * @return Reference to this
234 AliFMDBaseDigitizer::operator=(o);
235 fHoldTime = o.fHoldTime;
241 //____________________________________________________________________
243 AliFMDHitDigitizer::Exec(Option_t* /*option*/)
245 // Run this digitizer
246 // Get an inititialize parameter manager
247 AliFMDParameters::Instance()->Init();
248 if (AliLog::GetDebugLevel("FMD","") >= 10)
249 AliFMDParameters::Instance()->Print("ALL");
251 // Get loader, and ask it to read in the hits
252 AliLoader* loader = fFMD->GetLoader();
254 AliError("Failed to get loader from detector object");
257 loader->LoadHits("READ");
259 // Get the run loader
260 AliRunLoader* runLoader = loader->GetRunLoader();
262 AliError("Failed to get run loader from loader");
266 // Now loop over events
267 Int_t nEvents = runLoader->GetNumberOfEvents();
268 for (Int_t event = 0; event < nEvents; event++) {
269 // Get the current event folder.
270 TFolder* folder = loader->GetEventFolder();
272 AliError("Failed to get event folder from loader");
276 // Get the run-loader of this event.
277 const char* loaderName = AliRunLoader::GetRunLoaderName();
278 AliRunLoader* thisLoader =
279 static_cast<AliRunLoader*>(folder->FindObject(loaderName));
281 AliError(Form("Failed to get loader '%s' from event folder", loaderName));
286 AliFMDDebug(1, ("Now digitizing (Hits->%s) event # %d",
287 (fOutput == kDigits ? "digits" : "sdigits"), event));
288 thisLoader->GetEvent(event);
290 // Load kinematics to get primary information for SDigits
292 if (fOutput == kSDigits) {
293 if (thisLoader->LoadKinematics("READ")) {
294 AliError("Failed to get kinematics from event loader");
297 AliFMDDebug(5, ("Loading stack of kinematics"));
298 fStack = thisLoader->Stack();
301 // Check that we have the hits
302 if (!loader->TreeH() && loader->LoadHits()) {
303 AliError("Failed to load hits");
306 TTree* hitsTree = loader->TreeH();
307 TBranch* hitsBranch = hitsTree->GetBranch(fFMD->GetName());
309 AliError("Failed to get hits branch in tree");
312 // Check that we can make the output digits - This must come
313 // before AliFMD::SetBranchAddress
314 TTree* outTree = MakeOutputTree(loader);
316 AliError("Failed to get output tree");
319 AliFMDDebug(5, ("Output tree name for %s is '%s'",
320 (fOutput == kDigits ? "digits" : "sdigits"),
321 outTree->GetName()));
322 if (AliLog::GetDebugLevel("FMD","") >= 5) {
323 TFile* file = outTree->GetCurrentFile();
325 AliWarning("Output tree has no file!");
328 AliFMDDebug(5, ("Output tree file %s content:", file->GetName()));
333 // Set-up the branch addresses
334 fFMD->SetTreeAddress();
336 // Now sum all contributions in cache
337 SumContributions(hitsBranch);
338 loader->UnloadHits();
340 // And now digitize the hits
343 // Write digits to tree
344 Int_t write = outTree->Fill();
345 AliFMDDebug(5, ("Wrote %d bytes to digit tree", write));
353 //____________________________________________________________________
355 AliFMDHitDigitizer::MakeOutputTree(AliLoader* loader)
358 * Make the output tree using the passed loader
361 * @return The generated tree.
363 if (fOutput == kDigits)
364 return AliFMDBaseDigitizer::MakeOutputTree(loader);
366 AliFMDDebug(5, ("Making sdigits tree"));
367 loader->LoadSDigits("UPDATE"); // RECREATE");
368 TTree* out = loader->TreeS();
369 if (!out) loader->MakeTree("S");
370 out = loader->TreeS();
373 fFMD->MakeBranch("S");
379 //____________________________________________________________________
381 AliFMDHitDigitizer::SumContributions(TBranch* hitsBranch)
383 // Sum energy deposited contributions from each hit in a cache
386 // Clear array of deposited energies
389 // Get a list of hits from the FMD manager
390 AliFMDDebug(5, ("Get array of FMD hits"));
391 TClonesArray *fmdHits = fFMD->Hits();
394 // Get number of entries in the tree
395 AliFMDDebug(5, ("Get # of tracks"));
396 Int_t ntracks = Int_t(hitsBranch->GetEntries());
397 AliFMDDebug(5, ("We got %d tracks", ntracks));
400 // Loop over the tracks in the
401 for (Int_t track = 0; track < ntracks; track++) {
402 // Read in entry number `track'
403 read += hitsBranch->GetEntry(track);
405 // Get the number of hits
406 Int_t nhits = fmdHits->GetEntries ();
407 for (Int_t hit = 0; hit < nhits; hit++) {
408 // Get the hit number `hit'
410 static_cast<AliFMDHit*>(fmdHits->UncheckedAt(hit));
412 // Ignore hits that arrive too late
413 if (fmdHit->Time() > fHoldTime) continue;
416 // Check if this is a primary particle
417 Bool_t isPrimary = kTRUE;
420 trackno = fmdHit->Track();
421 AliFMDDebug(10, ("Will get track # %d/%d from entry # %d",
422 trackno, fStack->GetNtrack(), track));
423 if (fStack->GetNtrack() < trackno) {
424 AliError(Form("Track number %d/%d out of bounds",
425 trackno, fStack->GetNtrack()));
429 isPrimary = fStack->IsPhysicalPrimary(trackno);
430 #else // This is our hand-crafted code. We use the ALICE definition
431 TParticle* part = fStack->Particle(trackno);
432 isPrimary = part->IsPrimary();
434 // Extended testing of mother status - this is for Pythia6.
435 Int_t mother1 = part->GetFirstMother();
436 TParticle* mother = fStack->Particle(mother1);
437 if (!mother || mother->GetStatusCode() > 1)
440 ("Track %d secondary, mother: %d - %s - status %d: %s",
442 (mother ? "found" : "not found"),
443 (mother ? mother->GetStatusCode() : -1),
444 (isPrimary ? "primary" : "secondary")));
449 // Extract parameters
450 AliFMDDebug(15,("Adding contribution %7.5f for FMD%d%c[%2d,%3d] "
451 " for trackno %6d (%s)",
458 (isPrimary ? "primary" : "secondary")));
459 AddContribution(fmdHit->Detector(),
469 AliFMDDebug(5, ("Size of cache: %d bytes, read %d bytes",
470 int(sizeof(fEdep)), read));
474 //____________________________________________________________________
476 AliFMDHitDigitizer::MakePedestal(UShort_t detector,
479 UShort_t strip) const
482 if (fOutput == kSDigits) return 0;
483 return AliFMDBaseDigitizer::MakePedestal(detector, ring, sector, strip);
488 //____________________________________________________________________
490 AliFMDHitDigitizer::AddDigit(UShort_t detector,
501 const TArrayI& refs) const
503 // Add a digit or summable digit
504 if (fOutput == kDigits) {
505 AliFMDDebug(15,("Adding digit for FMD%d%c[%2d,%3d] = (%x,%x,%x,%x)",
506 detector, ring, sector, strip,
507 count1, count2, count3, count4));
508 AliFMDBaseDigitizer::AddDigit(detector, ring, sector, strip, 0,
509 count1, count2, count3, count4,
510 ntotal, nprim, refs);
514 AliFMDDebug(15, ("Digit edep = %f <= 0 for FMD%d%c[%2d,%3d]",
515 edep, detector, ring, sector, strip));
518 if (count1 == 0 && count2 <= 0 && count3 <= 0 && count4 <= 0) {
519 AliFMDDebug(15, ("Digit counts = (%x,%x,%x,%x) <= 0 for FMD%d%c[%2d,%3d]",
520 count1, count2, count3, count4,
521 detector, ring, sector, strip));
524 AliFMDDebug(15, ("Adding sdigit for FMD%d%c[%2d,%3d] = "
525 "(%x,%x,%x,%x) [%d/%d] %d",
526 detector, ring, sector, strip,
527 count1, count2, count3, count4, nprim, ntotal, refs.fN));
528 fFMD->AddSDigitByFields(detector, ring, sector, strip, edep,
529 count1, count2, count3, count4,
530 ntotal, nprim, fStoreTrackRefs ? refs.fArray : 0);
531 if (fStoreTrackRefs && nprim > 3) fIgnoredLabels += nprim - 3;
534 //____________________________________________________________________
536 AliFMDHitDigitizer::CheckDigit(AliFMDDigit* digit,
538 const TArrayI& counts)
540 // Check that digit is consistent
541 AliFMDParameters* param = AliFMDParameters::Instance();
542 UShort_t det = digit->Detector();
543 Char_t ring = digit->Ring();
544 UShort_t sec = digit->Sector();
545 UShort_t str = digit->Strip();
546 Float_t mean = param->GetPedestal(det,ring,sec,str);
547 Float_t width = param->GetPedestalWidth(det,ring,sec,str);
548 UShort_t range = param->GetVA1MipRange();
549 UShort_t size = param->GetAltroChannelSize();
550 Int_t integral = counts[0];
551 if (counts[1] >= 0) integral += counts[1];
552 if (counts[2] >= 0) integral += counts[2];
553 if (counts[3] >= 0) integral += counts[3];
554 integral -= Int_t(mean + 2 * width);
555 if (integral < 0) integral = 0;
557 Float_t convF = Float_t(range) / size;
558 Float_t mips = integral * convF;
559 if (mips > Float_t(nhits) + .5 || mips < Float_t(nhits) - .5)
560 Warning("CheckDigit", "Digit -> %4.2f MIPS != %d +/- .5 hits",
564 //____________________________________________________________________
566 AliFMDHitDigitizer::StoreDigits(const AliLoader* loader)
569 * Store the data using the loader
571 * @param loader The loader
573 if (fOutput == kDigits) {
574 AliFMDBaseDigitizer::StoreDigits(loader);
577 AliFMDDebug(5, ("Storing %d sdigits", fFMD->SDigits()->GetEntries()));
578 // Write the digits to disk
579 loader->WriteSDigits("OVERWRITE");
580 loader->UnloadSDigits();
581 // Reset the digits in the AliFMD object
582 fFMD->ResetSDigits();
586 //____________________________________________________________________