]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/AliFMDReconstructor.cxx
-maxdepth option is not portable, reverting the changes
[u/mrichter/AliRoot.git] / FMD / AliFMDReconstructor.cxx
CommitLineData
37c55dc0 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 **************************************************************************/
0d0e6995 15/* $Id$ */
c2fc1258 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
20*/
4347b38f 21//____________________________________________________________________
42403906 22//
02a27b50 23// This is a class that constructs AliFMDRecPoint objects from of Digits
6169f936 24// This class reads either digits from a TClonesArray or raw data from
4347b38f 25// a DDL file (or similar), and stores the read ADC counts in an
6169f936 26// internal cache (fAdcs). The rec-points are made via the naiive
27// method.
4347b38f 28//
37c55dc0 29//-- Authors: Evgeny Karpechev(INR) and Alla Maevsksia
4347b38f 30// Latest changes by Christian Holm Christensen <cholm@nbi.dk>
31//
32//
33//____________________________________________________________________
37c55dc0 34
56b1929b 35#include <AliLog.h> // ALILOG_H
6169f936 36// #include <AliRun.h> // ALIRUN_H
56b1929b 37#include <AliRunLoader.h> // ALIRUNLOADER_H
56b1929b 38#include <AliHeader.h> // ALIHEADER_H
56b1929b 39#include <AliGenEventHeader.h> // ALIGENEVENTHEADER_H
1a1fdef7 40#include "AliFMDGeometry.h" // ALIFMDGEOMETRY_H
41#include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
56b1929b 42#include "AliFMDDigit.h" // ALIFMDDIGIT_H
43#include "AliFMDReconstructor.h" // ALIFMDRECONSTRUCTOR_H
56b1929b 44#include "AliFMDRawReader.h" // ALIFMDRAWREADER_H
bf000c32 45#include "AliFMDRecPoint.h" // ALIFMDMULTNAIIVE_H
a3537838 46#include "AliESD.h" // ALIESD_H
8f6ee336 47#include <AliESDFMD.h> // ALIESDFMD_H
02a27b50 48class AliRawReader;
4347b38f 49
50//____________________________________________________________________
925e6570 51ClassImp(AliFMDReconstructor)
1a1fdef7 52#if 0
53 ; // This is here to keep Emacs for indenting the next line
54#endif
37c55dc0 55
4347b38f 56//____________________________________________________________________
57AliFMDReconstructor::AliFMDReconstructor()
58 : AliReconstructor(),
e9fd1e20 59 fMult(0x0),
60 fNMult(0),
61 fTreeR(0x0),
62 fCurrentVertex(0),
63 fESDObj(0x0),
64 fESD(0x0)
4347b38f 65{
8f6ee336 66 // Make a new FMD reconstructor object - default CTOR.
a9579262 67 SetNoiseFactor();
68 SetAngleCorrect();
4347b38f 69}
70
42403906 71
72//____________________________________________________________________
73AliFMDReconstructor::AliFMDReconstructor(const AliFMDReconstructor& other)
8f6ee336 74 : AliReconstructor(),
75 fMult(other.fMult),
e9fd1e20 76 fNMult(other.fNMult),
77 fTreeR(other.fTreeR),
78 fCurrentVertex(other.fCurrentVertex),
79 fESDObj(other.fESDObj),
a9579262 80 fESD(other.fESD),
81 fNoiseFactor(other.fNoiseFactor),
82 fAngleCorrect(other.fAngleCorrect)
42403906 83{
56b1929b 84 // Copy constructor
42403906 85}
86
87
88//____________________________________________________________________
89AliFMDReconstructor&
90AliFMDReconstructor::operator=(const AliFMDReconstructor& other)
91{
56b1929b 92 // Assignment operator
a9579262 93 fMult = other.fMult;
94 fNMult = other.fNMult;
95 fTreeR = other.fTreeR;
e9fd1e20 96 fCurrentVertex = other.fCurrentVertex;
a9579262 97 fESDObj = other.fESDObj;
98 fESD = other.fESD;
99 fNoiseFactor = other.fNoiseFactor;
100 fAngleCorrect = other.fAngleCorrect;
101
42403906 102 return *this;
103}
56b1929b 104
105//____________________________________________________________________
106AliFMDReconstructor::~AliFMDReconstructor()
107{
108 // Destructor
8f6ee336 109 if (fMult) fMult->Delete();
110 if (fMult) delete fMult;
111 if (fESDObj) delete fESDObj;
56b1929b 112}
4347b38f 113
114//____________________________________________________________________
115void
1a1fdef7 116AliFMDReconstructor::Init(AliRunLoader* runLoader)
117{
118 // Initialize the reconstructor
119 AliDebug(1, Form("Init called with runloader 0x%x", runLoader));
bf000c32 120 // Initialize the geometry
9b48326f 121 AliFMDGeometry* geom = AliFMDGeometry::Instance();
122 geom->Init();
123 geom->InitTransformations();
124
125 // Initialize the parameters
126 AliFMDParameters* param = AliFMDParameters::Instance();
127 param->Init();
bf000c32 128
8f6ee336 129 // Current vertex position
1a1fdef7 130 fCurrentVertex = 0;
8f6ee336 131 // Create array of reconstructed strip multiplicities
bf000c32 132 fMult = new TClonesArray("AliFMDRecPoint", 51200);
8f6ee336 133 // Create ESD output object
134 fESDObj = new AliESDFMD;
135
136 // Check that we have a run loader
1a1fdef7 137 if (!runLoader) {
138 Warning("Init", "No run loader");
4347b38f 139 return;
140 }
8f6ee336 141
142 // Check if we can get the header tree
1a1fdef7 143 AliHeader* header = runLoader->GetHeader();
144 if (!header) {
145 Warning("Init", "No header");
4347b38f 146 return;
147 }
8f6ee336 148
149 // Check if we can get a simulation header
1a1fdef7 150 AliGenEventHeader* eventHeader = header->GenEventHeader();
a3537838 151 if (eventHeader) {
152 TArrayF vtx;
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");
158 }
159 else {
160 Warning("Init", "No generator event header - "
161 "perhaps we get the vertex from ESD?");
4347b38f 162 }
4347b38f 163}
dc8af42e 164
4347b38f 165//____________________________________________________________________
166void
1a1fdef7 167AliFMDReconstructor::ConvertDigits(AliRawReader* reader,
168 TTree* digitsTree) const
169{
170 // Convert Raw digits to AliFMDDigit's in a tree
8f6ee336 171 AliDebug(1, "Reading raw data into digits tree");
1a1fdef7 172 AliFMDRawReader rawRead(reader, digitsTree);
173 // rawRead.SetSampleRate(fFMD->GetSampleRate());
174 rawRead.Exec();
4347b38f 175}
176
4347b38f 177//____________________________________________________________________
178void
1a1fdef7 179AliFMDReconstructor::Reconstruct(TTree* digitsTree,
180 TTree* clusterTree) const
4347b38f 181{
1a1fdef7 182 // Reconstruct event from digits in tree
4347b38f 183 // Get the FMD branch holding the digits.
69b696b9 184 // FIXME: The vertex may not be known yet, so we may have to move
185 // some of this to FillESD.
1a1fdef7 186 AliDebug(1, "Reconstructing from digits in a tree");
1e8f773e 187#if 1
a3537838 188 if (fESD) {
8f6ee336 189 const AliESDVertex* vertex = fESD->GetVertex();
190 if (vertex) {
191 AliDebug(1, Form("Got vertex from ESD: %f", vertex->GetZv()));
192 fCurrentVertex = vertex->GetZv();
193 }
a3537838 194 }
54e415a8 195#endif
1a1fdef7 196 TBranch *digitBranch = digitsTree->GetBranch("FMD");
4347b38f 197 if (!digitBranch) {
1a1fdef7 198 Error("Exec", "No digit branch for the FMD found");
199 return;
4347b38f 200 }
0abe7182 201 TClonesArray* digits = new TClonesArray("AliFMDDigit");
1a1fdef7 202 digitBranch->SetAddress(&digits);
4347b38f 203
8f6ee336 204 if (fMult) fMult->Clear();
205 if (fESDObj) fESDObj->Clear();
206
207 fNMult = 0;
208 fTreeR = clusterTree;
209 fTreeR->Branch("FMD", &fMult);
210
211 AliDebug(5, "Getting entry 0 from digit branch");
1a1fdef7 212 digitBranch->GetEntry(0);
213
8f6ee336 214 AliDebug(5, "Processing digits");
e802be3e 215 ProcessDigits(digits);
216
8f6ee336 217 Int_t written = clusterTree->Fill();
218 AliDebug(10, Form("Filled %d bytes into cluster tree", written));
0abe7182 219 digits->Delete();
220 delete digits;
4347b38f 221}
1a1fdef7 222
8f6ee336 223
4347b38f 224//____________________________________________________________________
e802be3e 225void
226AliFMDReconstructor::ProcessDigits(TClonesArray* digits) const
4347b38f 227{
69b696b9 228 // For each digit, find the pseudo rapdity, azimuthal angle, and
229 // number of corrected ADC counts, and pass it on to the algorithms
230 // used.
e802be3e 231 Int_t nDigits = digits->GetEntries();
1a1fdef7 232 AliDebug(1, Form("Got %d digits", nDigits));
a9579262 233 fESDObj->SetNoiseFactor(fNoiseFactor);
234 fESDObj->SetAngleCorrected(fAngleCorrect);
e802be3e 235 for (Int_t i = 0; i < nDigits; i++) {
236 AliFMDDigit* digit = static_cast<AliFMDDigit*>(digits->At(i));
8f6ee336 237 AliFMDParameters* param = AliFMDParameters::Instance();
238 // Check that the strip is not marked as dead
239 if (param->IsDead(digit->Detector(), digit->Ring(),
15b17c89 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()));
243 continue;
244 }
8f6ee336 245
246 // digit->Print();
247 // Get eta and phi
248 Float_t eta, phi;
249 PhysicalCoordinates(digit, eta, phi);
4347b38f 250
8f6ee336 251 // Substract pedestal.
e802be3e 252 UShort_t counts = SubtractPedestal(digit);
4347b38f 253
8f6ee336 254 // Gain match digits.
255 Double_t edep = Adc2Energy(digit, eta, counts);
256
257 // Make rough multiplicity
258 Double_t mult = Energy2Multiplicity(digit, edep);
259
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));
264
265 // Create a `RecPoint' on the output branch.
bf000c32 266 AliFMDRecPoint* m =
267 new ((*fMult)[fNMult]) AliFMDRecPoint(digit->Detector(),
268 digit->Ring(),
269 digit->Sector(),
270 digit->Strip(),
271 eta, phi,
272 edep, mult);
8f6ee336 273 (void)m; // Suppress warnings about unused variables.
274 fNMult++;
275
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);
4347b38f 280 }
4347b38f 281}
8f6ee336 282
1a1fdef7 283//____________________________________________________________________
284UShort_t
285AliFMDReconstructor::SubtractPedestal(AliFMDDigit* digit) const
286{
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.
291
8f6ee336 292 Int_t counts = 0;
293 AliFMDParameters* param = AliFMDParameters::Instance();
a9579262 294 Float_t ped = param->GetPedestal(digit->Detector(),
8f6ee336 295 digit->Ring(),
296 digit->Sector(),
297 digit->Strip());
a9579262 298 Float_t noise = param->GetPedestalWidth(digit->Detector(),
299 digit->Ring(),
300 digit->Sector(),
301 digit->Strip());
15b17c89 302 AliDebug(15, Form("Subtracting pedestal %f from signal %d",
a9579262 303 ped, digit->Counts()));
1a1fdef7 304 if (digit->Count3() > 0) counts = digit->Count3();
305 else if (digit->Count2() > 0) counts = digit->Count2();
306 else counts = digit->Count1();
a9579262 307 counts = TMath::Max(Int_t(counts - ped), 0);
308 if (counts < noise * fNoiseFactor) counts = 0;
15b17c89 309 if (counts > 0) AliDebug(15, "Got a hit strip");
8f6ee336 310
1a1fdef7 311 return UShort_t(counts);
312}
313
8f6ee336 314//____________________________________________________________________
315Float_t
316AliFMDReconstructor::Adc2Energy(AliFMDDigit* digit,
a9579262 317 Float_t eta,
8f6ee336 318 UShort_t count) const
319{
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.
324 //
325 // In this simple version, we calculate the energy deposited as
326 //
327 // EnergyDeposited = cos(theta) * gain * count
328 //
329 // where
330 //
331 // Pre_amp_MIP_Range
332 // gain = ----------------- * Energy_deposited_per_MIP
333 // ADC_channel_size
334 //
335 // is constant and the same for all strips.
336
a9579262 337 if (count <= 0) return 0;
8f6ee336 338 AliFMDParameters* param = AliFMDParameters::Instance();
339 Float_t gain = param->GetPulseGain(digit->Detector(),
340 digit->Ring(),
341 digit->Sector(),
342 digit->Strip());
15b17c89 343 AliDebug(15, Form("Converting counts %d to energy via factor %f",
8f6ee336 344 count, gain));
a9579262 345
346 Double_t edep = count * gain;
347 if (fAngleCorrect) {
348 Double_t theta = 2 * TMath::ATan(TMath::Exp(-eta));
349 edep *= TMath::Abs(TMath::Cos(theta));
350 }
8f6ee336 351 return edep;
352}
353
354//____________________________________________________________________
355Float_t
356AliFMDReconstructor::Energy2Multiplicity(AliFMDDigit* /* digit */,
357 Float_t edep) const
358{
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.
363 //
364 // In this simple version, we calculate the multiplicity as
365 //
366 // multiplicity = Energy_deposited / Energy_deposited_per_MIP
367 //
368 // where
369 //
370 // Energy_deposited_per_MIP = 1.664 * SI_density * SI_thickness
371 //
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;
376 if (edep > 0)
15b17c89 377 AliDebug(15, Form("Translating energy %f to multiplicity via "
8f6ee336 378 "divider %f->%f", edep, edepMIP, mult));
379 return mult;
380}
381
382//____________________________________________________________________
383void
384AliFMDReconstructor::PhysicalCoordinates(AliFMDDigit* digit,
385 Float_t& eta,
386 Float_t& phi) const
387{
388 // Get the eta and phi of a digit
389 //
390 // Get geometry.
9b48326f 391 AliFMDGeometry* geom = AliFMDGeometry::Instance();
bf000c32 392 Double_t x, y, z, r, theta;
9b48326f 393 geom->Detector2XYZ(digit->Detector(), digit->Ring(), digit->Sector(),
bf000c32 394 digit->Strip(), x, y, z);
395 // Correct for vertex offset.
396 z += fCurrentVertex;
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));
8f6ee336 401}
402
403
404
4347b38f 405//____________________________________________________________________
406void
1a1fdef7 407AliFMDReconstructor::FillESD(TTree* /* digitsTree */,
408 TTree* /* clusterTree */,
8f6ee336 409 AliESD* esd) const
121a60bd 410{
42403906 411 // nothing to be done
69b696b9 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.
8f6ee336 414 AliDebug(1, Form("Calling FillESD with two trees and one ESD"));
415 // fESDObj->Print();
416
417 if (esd) {
418 AliDebug(1, Form("Writing FMD data to ESD tree"));
419 esd->SetFMDData(fESDObj);
a3537838 420 }
121a60bd 421}
422
54e415a8 423
424//____________________________________________________________________
425void
426AliFMDReconstructor::Reconstruct(AliRawReader*,TTree*) const
427{
428 // Cannot be used. See member function with same name but with 2
429 // TTree arguments. Make sure you do local reconstrucion
8f6ee336 430 AliDebug(1, Form("Calling FillESD with loader and tree"));
54e415a8 431 AliError("MayNotUse");
432}
433//____________________________________________________________________
434void
435AliFMDReconstructor::Reconstruct(AliRunLoader*) const
436{
437 // Cannot be used. See member function with same name but with 2
438 // TTree arguments. Make sure you do local reconstrucion
8f6ee336 439 AliDebug(1, Form("Calling FillESD with loader"));
54e415a8 440 AliError("MayNotUse");
441}
442//____________________________________________________________________
443void
444AliFMDReconstructor::Reconstruct(AliRunLoader*, AliRawReader*) const
445{
446 // Cannot be used. See member function with same name but with 2
447 // TTree arguments. Make sure you do local reconstrucion
8f6ee336 448 AliDebug(1, Form("Calling FillESD with loader and raw reader"));
54e415a8 449 AliError("MayNotUse");
450}
451//____________________________________________________________________
452void
453AliFMDReconstructor::FillESD(AliRawReader*,TTree*,AliESD*) const
454{
455 // Cannot be used. See member function with same name but with 2
456 // TTree arguments. Make sure you do local reconstrucion
8f6ee336 457 AliDebug(1, Form("Calling FillESD with raw reader, tree, and ESD"));
54e415a8 458 AliError("MayNotUse");
459}
460//____________________________________________________________________
461void
462AliFMDReconstructor::FillESD(AliRunLoader*,AliESD*) const
463{
464 // Cannot be used. See member function with same name but with 2
465 // TTree arguments. Make sure you do local reconstrucion
8f6ee336 466 AliDebug(1, Form("Calling FillESD with loader and ESD"));
54e415a8 467 AliError("MayNotUse");
468}
469//____________________________________________________________________
470void
471AliFMDReconstructor::FillESD(AliRunLoader*,AliRawReader*,AliESD*) const
472{
473 // Cannot be used. See member function with same name but with 2
474 // TTree arguments. Make sure you do local reconstrucion
8f6ee336 475 AliDebug(1, Form("Calling FillESD with loader, raw reader, and ESD"));
54e415a8 476 AliError("MayNotUse");
477}
478
42403906 479//____________________________________________________________________
480//
481// EOF
482//