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 **************************************************************************/
18 //____________________________________________________________________
20 // This is a class that constructs ReconstParticles (reconstructed
21 // particles) out 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).
28 // From the cached values it then calculates the number of particles
29 // that hit a region of the FMDs, as specified by the user.
31 // The reconstruction can be done in two ways: Either via counting the
32 // number of empty strips (Poisson method), or by converting the ADC
33 // signal to an energy deposition, and then dividing by the typical
34 // energy loss of a particle.
36 // Currently, this class only reads the digits from a TClonesArray,
37 // and the Poission method for reconstruction.
40 //-- Authors: Evgeny Karpechev(INR) and Alla Maevsksia
41 // Latest changes by Christian Holm Christensen <cholm@nbi.dk>
44 //____________________________________________________________________
46 #include <AliLog.h> // ALILOG_H
47 #include <AliRun.h> // ALIRUN_H
48 #include <AliRunLoader.h> // ALIRUNLOADER_H
49 #include <AliLoader.h> // ALILOADER_H
50 #include <AliHeader.h> // ALIHEADER_H
51 #include <AliRawReader.h> // ALIRAWREADER_H
52 #include <AliGenEventHeader.h> // ALIGENEVENTHEADER_H
53 #include "AliFMD.h" // ALIFMD_H
54 #include "AliFMDDigit.h" // ALIFMDDIGIT_H
55 #include "AliFMDReconstructor.h" // ALIFMDRECONSTRUCTOR_H
56 #include "AliFMDRawStream.h" // ALIFMDRAWSTREAM_H
57 #include "AliFMDRawReader.h" // ALIFMDRAWREADER_H
58 #include "AliFMDMultAlgorithm.h" // ALIFMDMULTALGORITHM_H
59 #include "AliFMDMultPoisson.h" // ALIFMDMULTPOISSON_H
60 #include "AliFMDMultNaiive.h" // ALIFMDMULTNAIIVE_H
62 //____________________________________________________________________
63 ClassImp(AliFMDReconstructor);
65 //____________________________________________________________________
66 AliFMDReconstructor::AliFMDReconstructor()
72 // Make a new FMD reconstructor object - default CTOR.
78 fAlgorithms.Add(new AliFMDMultNaiive);
79 fAlgorithms.Add(new AliFMDMultPoisson);
83 //____________________________________________________________________
84 AliFMDReconstructor::AliFMDReconstructor(const AliFMDReconstructor& other)
91 SetPedestal(other.fPedestal, other.fPedestalWidth, other.fPedestalFactor);
93 fFMDLoader = other.fFMDLoader;
94 fRunLoader = other.fRunLoader;
98 TIter next(&(other.fAlgorithms));
99 AliFMDMultAlgorithm* algorithm = 0;
100 while ((algorithm = static_cast<AliFMDMultAlgorithm*>(next())))
101 fAlgorithms.Add(algorithm);
102 fAlgorithms.SetOwner(kFALSE);
106 //____________________________________________________________________
108 AliFMDReconstructor::operator=(const AliFMDReconstructor& other)
110 // Assignment operator
111 SetPedestal(other.fPedestal, other.fPedestalWidth, other.fPedestalFactor);
113 fFMDLoader = other.fFMDLoader;
114 fRunLoader = other.fRunLoader;
117 fAlgorithms.Delete();
118 TIter next(&(other.fAlgorithms));
119 AliFMDMultAlgorithm* algorithm = 0;
120 while ((algorithm = static_cast<AliFMDMultAlgorithm*>(next())))
121 fAlgorithms.Add(algorithm);
122 fAlgorithms.SetOwner(kFALSE);
127 //____________________________________________________________________
128 AliFMDReconstructor::~AliFMDReconstructor()
131 fAlgorithms.Delete();
134 //____________________________________________________________________
136 AliFMDReconstructor::SetPedestal(Float_t mean, Float_t width, Float_t factor)
138 // Set the pedestal, and pedestal width
140 fPedestalWidth = width;
141 fPedestalFactor = factor;
144 //____________________________________________________________________
146 AliFMDReconstructor::Reconstruct(AliRunLoader* runLoader,
147 AliRawReader* rawReader) const
149 // Collects all digits in the same active volume into number of
152 // Reconstruct number of particles in given group of pads for given
153 // FMDvolume determined by numberOfVolume,
154 // numberOfMinSector, numberOfMaxSector, numberOfMinRing,
157 // The reconstruction method is choosen based on the number of empty
160 Error("Exec","Run Loader loader is NULL - Session not opened");
163 fRunLoader = runLoader;
164 fFMDLoader = runLoader->GetLoader("FMDLoader");
166 Fatal("AliFMDReconstructor","Can not find FMD (loader) "
167 "in specified event");
169 // Get the AliRun object
170 if (!fRunLoader->GetAliRun()) fRunLoader->LoadgAlice();
172 // Get the AliFMD object
173 fFMD = static_cast<AliFMD*>(fRunLoader->GetAliRun()->GetDetector("FMD"));
175 AliError("Can not get FMD from gAlice");
178 fFMDLoader->LoadRecPoints("RECREATE");
180 if (!fRunLoader->TreeE()) fRunLoader->LoadHeader();
182 TIter next(&fAlgorithms);
183 AliFMDMultAlgorithm* algorithm = 0;
184 while ((algorithm = static_cast<AliFMDMultAlgorithm*>(next())))
185 algorithm->PreRun(fFMD);
189 while (rawReader->NextEvent()) {
190 ProcessEvent(event, rawReader);
195 Int_t nEvents= Int_t(fRunLoader->TreeE()->GetEntries());
196 for(Int_t event = 0; event < nEvents; event++)
197 ProcessEvent(event, 0);
202 while ((algorithm = static_cast<AliFMDMultAlgorithm*>(next())))
203 algorithm->PostRun();
205 fFMDLoader->UnloadRecPoints();
211 //____________________________________________________________________
213 AliFMDReconstructor::Reconstruct(AliRunLoader* runLoader) const
215 // Collects all digits in the same active volume into number of
218 // Reconstruct number of particles in given group of pads for given
219 // FMDvolume determined by numberOfVolume,
220 // numberOfMinSector, numberOfMaxSector, numberOfMinRing,
223 // The reconstruction method is choosen based on the number of empty
225 Reconstruct(runLoader, 0);
229 //____________________________________________________________________
231 AliFMDReconstructor::ProcessEvent(Int_t event,
232 AliRawReader* reader) const
234 // Process one event read from either a clones array or from a a raw
236 fRunLoader->GetEvent(event) ;
237 //event z-vertex for correction eta-rad dependence
238 AliHeader *header = fRunLoader->GetHeader();
239 if (!header) Warning("ProcessEvent", "no AliHeader found!");
240 AliGenEventHeader* genHeader = (header ? header->GenEventHeader() : 0);
242 // Get the Z--coordinate from the event header
244 if (genHeader) genHeader->PrimaryVertex(o);
245 else Warning("ProcessEvent", "No GenEventHeader Found");
246 fCurrentVertex = o.At(2);
248 // If the recontruction tree isn't loaded, load it
249 if(fFMDLoader->TreeR()==0) fFMDLoader->MakeTree("R");
251 // Load or recreate the digits
252 if (fFMDLoader->LoadDigits((reader ? "UPDATE" : "READ"))) {
254 Error("Exec","Error occured while loading digits. Exiting.");
258 // Get the digits tree
259 TTree* digitTree = fFMDLoader->TreeD();
262 Error("Exec","Can not get Tree with Digits. "
263 "Nothing to reconstruct - Exiting");
266 fFMDLoader->MakeTree("D");
267 digitTree = fFMDLoader->TreeD();
270 // Get the FMD branch holding the digits.
271 TBranch *digitBranch = digitTree->GetBranch("FMD");
272 TClonesArray* digits = fFMD->Digits();
275 Error("Exec", "No digit branch for the FMD found");
278 fFMD->MakeBranchInTree(digitTree, fFMD->GetName(), &(digits), 4000, 0);
280 if (!reader) digitBranch->SetAddress(&digits);
283 AliFMDRawReader rawRead(fFMD, reader);
284 // rawRead->SetSampleRate(fSampleRate);
288 // Read the ADC values from a clones array.
289 AliDebug(10, "Reading ADCs from Digits array");
290 // read Digits, and reconstruct the particles
291 if (!fFMDLoader->TreeD()->GetEvent(0)) return;
294 TIter next(&fAlgorithms);
295 AliFMDMultAlgorithm* algorithm = 0;
296 while ((algorithm = static_cast<AliFMDMultAlgorithm*>(next())))
297 algorithm->PreEvent(fFMDLoader->TreeR(), fCurrentVertex);
299 ProcessDigits(digits);
303 while ((algorithm = static_cast<AliFMDMultAlgorithm*>(next())))
304 algorithm->PostEvent();
308 fFMDLoader->WriteDigits("OVERWRITE");
310 fFMDLoader->UnloadDigits();
311 fFMDLoader->TreeR()->Reset();
312 fFMDLoader->TreeR()->Fill();
313 fFMDLoader->WriteRecPoints("OVERWRITE");
316 //____________________________________________________________________
318 AliFMDReconstructor::SubtractPedestal(AliFMDDigit* digit) const
320 // Member function to subtract the pedestal from a digit
321 // This implementation does nothing, but a derived class could over
322 // load this to subtract a pedestal that was given in a database or
323 // something like that.
326 Float_t ped = fPedestal * fPedestalFactor * fPedestalWidth;
327 if (digit->Count3() >= 0) counts = digit->Count3();
328 else if (digit->Count2() >= 0) counts = digit->Count2();
329 else counts = digit->Count2();
330 counts = TMath::Max(Int_t(counts - ped), 0);
331 return UShort_t(counts);
334 //____________________________________________________________________
336 AliFMDReconstructor::ProcessDigits(TClonesArray* digits) const
338 Int_t nDigits = digits->GetEntries();
339 for (Int_t i = 0; i < nDigits; i++) {
340 AliFMDDigit* digit = static_cast<AliFMDDigit*>(digits->At(i));
341 AliFMDSubDetector* subDetector = 0;
342 switch (digit->Detector()) {
343 case 1: subDetector = fFMD->GetFMD1(); break;
344 case 2: subDetector = fFMD->GetFMD2(); break;
345 case 3: subDetector = fFMD->GetFMD3(); break;
348 Warning("ProcessDigits", "Unknown detector: FMD%d" , digit->Detector());
352 AliFMDRing* ring = 0;
354 switch(digit->Ring()) {
357 ring = subDetector->GetInner();
358 ringZ = subDetector->GetInnerZ();
362 ring = subDetector->GetOuter();
363 ringZ = subDetector->GetOuterZ();
367 Warning("ProcessDigits", "Unknown ring: FMD%d%c", digit->Detector(),
372 Float_t realZ = fCurrentVertex + ringZ;
373 Float_t stripR = ((ring->GetHighR() - ring->GetLowR())
374 / ring->GetNStrips() * (digit->Strip() + .5)
376 Float_t theta = TMath::ATan2(stripR, realZ);
377 Float_t phi = (2 * TMath::Pi() / ring->GetNSectors()
378 * (digit->Sector() + .5));
379 Float_t eta = -TMath::Log(TMath::Tan(theta / 2));
380 UShort_t counts = SubtractPedestal(digit);
382 TIter next(&fAlgorithms);
383 AliFMDMultAlgorithm* algorithm = 0;
384 while ((algorithm = static_cast<AliFMDMultAlgorithm*>(next())))
385 algorithm->ProcessDigit(digit, eta, phi, counts);
390 //____________________________________________________________________
392 AliFMDReconstructor::FillESD(AliRunLoader* /*fRunLoader*/,
393 AliESD* /*esd*/) const
395 // nothing to be done
399 //____________________________________________________________________