1 /**************************************************************************
2 * Copyright(c) 1998-1999, 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 **************************************************************************/
16 /** @file AliFMDReconstructor.cxx
17 @author Christian Holm Christensen <cholm@nbi.dk>
18 @date Mon Mar 27 12:47:09 2006
19 @brief FMD reconstruction
21 //____________________________________________________________________
23 // This is a class that constructs AliFMDRecPoint objects from of Digits
24 // This class reads either digits from a TClonesArray or raw data from
25 // a DDL file (or similar), and stores the read ADC counts in an
26 // internal cache (fAdcs). The rec-points are made via the naiive
29 //-- Authors: Evgeny Karpechev(INR) and Alla Maevsksia
30 // Latest changes by Christian Holm Christensen <cholm@nbi.dk>
33 //____________________________________________________________________
35 #include <AliLog.h> // ALILOG_H
36 // #include <AliRun.h> // ALIRUN_H
37 #include <AliRunLoader.h> // ALIRUNLOADER_H
38 #include <AliHeader.h> // ALIHEADER_H
39 #include <AliGenEventHeader.h> // ALIGENEVENTHEADER_H
40 #include "AliFMDGeometry.h" // ALIFMDGEOMETRY_H
41 #include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
42 #include "AliFMDDigit.h" // ALIFMDDIGIT_H
43 #include "AliFMDReconstructor.h" // ALIFMDRECONSTRUCTOR_H
44 #include "AliFMDRawReader.h" // ALIFMDRAWREADER_H
45 #include "AliFMDRecPoint.h" // ALIFMDMULTNAIIVE_H
46 #include "AliESD.h" // ALIESD_H
47 #include <AliESDFMD.h> // ALIESDFMD_H
50 //____________________________________________________________________
51 ClassImp(AliFMDReconstructor)
53 ; // This is here to keep Emacs for indenting the next line
56 //____________________________________________________________________
57 AliFMDReconstructor::AliFMDReconstructor()
66 // Make a new FMD reconstructor object - default CTOR.
72 //____________________________________________________________________
73 AliFMDReconstructor::AliFMDReconstructor(const AliFMDReconstructor& other)
78 fCurrentVertex(other.fCurrentVertex),
79 fESDObj(other.fESDObj),
81 fNoiseFactor(other.fNoiseFactor),
82 fAngleCorrect(other.fAngleCorrect)
88 //____________________________________________________________________
90 AliFMDReconstructor::operator=(const AliFMDReconstructor& other)
92 // Assignment operator
94 fNMult = other.fNMult;
95 fTreeR = other.fTreeR;
96 fCurrentVertex = other.fCurrentVertex;
97 fESDObj = other.fESDObj;
99 fNoiseFactor = other.fNoiseFactor;
100 fAngleCorrect = other.fAngleCorrect;
105 //____________________________________________________________________
106 AliFMDReconstructor::~AliFMDReconstructor()
109 if (fMult) fMult->Delete();
110 if (fMult) delete fMult;
111 if (fESDObj) delete fESDObj;
114 //____________________________________________________________________
116 AliFMDReconstructor::Init(AliRunLoader* runLoader)
118 // Initialize the reconstructor
119 AliDebug(1, Form("Init called with runloader 0x%x", runLoader));
120 // Initialize the geometry
121 AliFMDGeometry* geom = AliFMDGeometry::Instance();
123 geom->InitTransformations();
125 // Initialize the parameters
126 AliFMDParameters* param = AliFMDParameters::Instance();
129 // Current vertex position
131 // Create array of reconstructed strip multiplicities
132 fMult = new TClonesArray("AliFMDRecPoint", 51200);
133 // Create ESD output object
134 fESDObj = new AliESDFMD;
136 // Check that we have a run loader
138 Warning("Init", "No run loader");
142 // Check if we can get the header tree
143 AliHeader* header = runLoader->GetHeader();
145 Warning("Init", "No header");
149 // Check if we can get a simulation header
150 AliGenEventHeader* eventHeader = header->GenEventHeader();
153 eventHeader->PrimaryVertex(vtx);
154 fCurrentVertex = vtx[2];
155 AliDebug(1, Form("Primary vertex Z coordinate for event # %d/%d is %f",
156 header->GetRun(), header->GetEvent(), fCurrentVertex));
157 Warning("Init", "no generator event header");
160 Warning("Init", "No generator event header - "
161 "perhaps we get the vertex from ESD?");
165 //____________________________________________________________________
167 AliFMDReconstructor::ConvertDigits(AliRawReader* reader,
168 TTree* digitsTree) const
170 // Convert Raw digits to AliFMDDigit's in a tree
171 AliDebug(1, "Reading raw data into digits tree");
172 AliFMDRawReader rawRead(reader, digitsTree);
173 // rawRead.SetSampleRate(fFMD->GetSampleRate());
177 //____________________________________________________________________
179 AliFMDReconstructor::Reconstruct(TTree* digitsTree,
180 TTree* clusterTree) const
182 // Reconstruct event from digits in tree
183 // Get the FMD branch holding the digits.
184 // FIXME: The vertex may not be known yet, so we may have to move
185 // some of this to FillESD.
186 AliDebug(1, "Reconstructing from digits in a tree");
189 const AliESDVertex* vertex = fESD->GetVertex();
191 AliDebug(1, Form("Got vertex from ESD: %f", vertex->GetZv()));
192 fCurrentVertex = vertex->GetZv();
196 TBranch *digitBranch = digitsTree->GetBranch("FMD");
198 Error("Exec", "No digit branch for the FMD found");
201 TClonesArray* digits = new TClonesArray("AliFMDDigit");
202 digitBranch->SetAddress(&digits);
204 if (fMult) fMult->Clear();
205 if (fESDObj) fESDObj->Clear();
208 fTreeR = clusterTree;
209 fTreeR->Branch("FMD", &fMult);
211 AliDebug(5, "Getting entry 0 from digit branch");
212 digitBranch->GetEntry(0);
214 AliDebug(5, "Processing digits");
215 ProcessDigits(digits);
217 Int_t written = clusterTree->Fill();
218 AliDebug(10, Form("Filled %d bytes into cluster tree", written));
224 //____________________________________________________________________
226 AliFMDReconstructor::ProcessDigits(TClonesArray* digits) const
228 // For each digit, find the pseudo rapdity, azimuthal angle, and
229 // number of corrected ADC counts, and pass it on to the algorithms
231 Int_t nDigits = digits->GetEntries();
232 AliDebug(1, Form("Got %d digits", nDigits));
233 fESDObj->SetNoiseFactor(fNoiseFactor);
234 fESDObj->SetAngleCorrected(fAngleCorrect);
235 for (Int_t i = 0; i < nDigits; i++) {
236 AliFMDDigit* digit = static_cast<AliFMDDigit*>(digits->At(i));
237 AliFMDParameters* param = AliFMDParameters::Instance();
238 // Check that the strip is not marked as dead
239 if (param->IsDead(digit->Detector(), digit->Ring(),
240 digit->Sector(), digit->Strip())) {
241 AliDebug(10, Form("FMD%d%c[%2d,%3d] is dead", digit->Detector(),
242 digit->Ring(), digit->Sector(), digit->Strip()));
249 PhysicalCoordinates(digit, eta, phi);
251 // Substract pedestal.
252 UShort_t counts = SubtractPedestal(digit);
254 // Gain match digits.
255 Double_t edep = Adc2Energy(digit, eta, counts);
257 // Make rough multiplicity
258 Double_t mult = Energy2Multiplicity(digit, edep);
260 AliDebug(10, Form("FMD%d%c[%2d,%3d]: "
261 "ADC: %d, Counts: %d, Energy: %f, Mult: %f",
262 digit->Detector(), digit->Ring(), digit->Sector(),
263 digit->Strip(), digit->Counts(), counts, edep, mult));
265 // Create a `RecPoint' on the output branch.
267 new ((*fMult)[fNMult]) AliFMDRecPoint(digit->Detector(),
273 (void)m; // Suppress warnings about unused variables.
276 fESDObj->SetMultiplicity(digit->Detector(), digit->Ring(),
277 digit->Sector(), digit->Strip(), mult);
278 fESDObj->SetEta(digit->Detector(), digit->Ring(),
279 digit->Sector(), digit->Strip(), eta);
283 //____________________________________________________________________
285 AliFMDReconstructor::SubtractPedestal(AliFMDDigit* digit) const
287 // Member function to subtract the pedestal from a digit
288 // This implementation does nothing, but a derived class could over
289 // load this to subtract a pedestal that was given in a database or
290 // something like that.
293 AliFMDParameters* param = AliFMDParameters::Instance();
294 Float_t ped = param->GetPedestal(digit->Detector(),
298 Float_t noise = param->GetPedestalWidth(digit->Detector(),
302 AliDebug(15, Form("Subtracting pedestal %f from signal %d",
303 ped, digit->Counts()));
304 if (digit->Count3() > 0) counts = digit->Count3();
305 else if (digit->Count2() > 0) counts = digit->Count2();
306 else counts = digit->Count1();
307 counts = TMath::Max(Int_t(counts - ped), 0);
308 if (counts < noise * fNoiseFactor) counts = 0;
309 if (counts > 0) AliDebug(15, "Got a hit strip");
311 return UShort_t(counts);
314 //____________________________________________________________________
316 AliFMDReconstructor::Adc2Energy(AliFMDDigit* digit,
318 UShort_t count) const
320 // Converts number of ADC counts to energy deposited.
321 // Note, that this member function can be overloaded by derived
322 // classes to do strip-specific look-ups in databases or the like,
323 // to find the proper gain for a strip.
325 // In this simple version, we calculate the energy deposited as
327 // EnergyDeposited = cos(theta) * gain * count
332 // gain = ----------------- * Energy_deposited_per_MIP
335 // is constant and the same for all strips.
337 if (count <= 0) return 0;
338 AliFMDParameters* param = AliFMDParameters::Instance();
339 Float_t gain = param->GetPulseGain(digit->Detector(),
343 AliDebug(15, Form("Converting counts %d to energy via factor %f",
346 Double_t edep = count * gain;
348 Double_t theta = 2 * TMath::ATan(TMath::Exp(-eta));
349 edep *= TMath::Abs(TMath::Cos(theta));
354 //____________________________________________________________________
356 AliFMDReconstructor::Energy2Multiplicity(AliFMDDigit* /* digit */,
359 // Converts an energy signal to number of particles.
360 // Note, that this member function can be overloaded by derived
361 // classes to do strip-specific look-ups in databases or the like,
362 // to find the proper gain for a strip.
364 // In this simple version, we calculate the multiplicity as
366 // multiplicity = Energy_deposited / Energy_deposited_per_MIP
370 // Energy_deposited_per_MIP = 1.664 * SI_density * SI_thickness
372 // is constant and the same for all strips
373 AliFMDParameters* param = AliFMDParameters::Instance();
374 Double_t edepMIP = param->GetEdepMip();
375 Float_t mult = edep / edepMIP;
377 AliDebug(15, Form("Translating energy %f to multiplicity via "
378 "divider %f->%f", edep, edepMIP, mult));
382 //____________________________________________________________________
384 AliFMDReconstructor::PhysicalCoordinates(AliFMDDigit* digit,
388 // Get the eta and phi of a digit
391 AliFMDGeometry* geom = AliFMDGeometry::Instance();
392 Double_t x, y, z, r, theta;
393 geom->Detector2XYZ(digit->Detector(), digit->Ring(), digit->Sector(),
394 digit->Strip(), x, y, z);
395 // Correct for vertex offset.
397 phi = TMath::ATan2(y, x);
398 r = TMath::Sqrt(y * y + x * x);
399 theta = TMath::ATan2(r, z);
400 eta = -TMath::Log(TMath::Tan(theta / 2));
405 //____________________________________________________________________
407 AliFMDReconstructor::FillESD(TTree* /* digitsTree */,
408 TTree* /* clusterTree */,
411 // nothing to be done
412 // FIXME: The vertex may not be known when Reconstruct is executed,
413 // so we may have to move some of that member function here.
414 AliDebug(1, Form("Calling FillESD with two trees and one ESD"));
418 AliDebug(1, Form("Writing FMD data to ESD tree"));
419 esd->SetFMDData(fESDObj);
424 //____________________________________________________________________
426 AliFMDReconstructor::Reconstruct(AliRawReader*,TTree*) const
428 // Cannot be used. See member function with same name but with 2
429 // TTree arguments. Make sure you do local reconstrucion
430 AliDebug(1, Form("Calling FillESD with loader and tree"));
431 AliError("MayNotUse");
433 //____________________________________________________________________
435 AliFMDReconstructor::Reconstruct(AliRunLoader*) const
437 // Cannot be used. See member function with same name but with 2
438 // TTree arguments. Make sure you do local reconstrucion
439 AliDebug(1, Form("Calling FillESD with loader"));
440 AliError("MayNotUse");
442 //____________________________________________________________________
444 AliFMDReconstructor::Reconstruct(AliRunLoader*, AliRawReader*) const
446 // Cannot be used. See member function with same name but with 2
447 // TTree arguments. Make sure you do local reconstrucion
448 AliDebug(1, Form("Calling FillESD with loader and raw reader"));
449 AliError("MayNotUse");
451 //____________________________________________________________________
453 AliFMDReconstructor::FillESD(AliRawReader*,TTree*,AliESD*) const
455 // Cannot be used. See member function with same name but with 2
456 // TTree arguments. Make sure you do local reconstrucion
457 AliDebug(1, Form("Calling FillESD with raw reader, tree, and ESD"));
458 AliError("MayNotUse");
460 //____________________________________________________________________
462 AliFMDReconstructor::FillESD(AliRunLoader*,AliESD*) const
464 // Cannot be used. See member function with same name but with 2
465 // TTree arguments. Make sure you do local reconstrucion
466 AliDebug(1, Form("Calling FillESD with loader and ESD"));
467 AliError("MayNotUse");
469 //____________________________________________________________________
471 AliFMDReconstructor::FillESD(AliRunLoader*,AliRawReader*,AliESD*) const
473 // Cannot be used. See member function with same name but with 2
474 // TTree arguments. Make sure you do local reconstrucion
475 AliDebug(1, Form("Calling FillESD with loader, raw reader, and ESD"));
476 AliError("MayNotUse");
479 //____________________________________________________________________