]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AD/AliADReconstructor.cxx
Added SPD outlier trigger bit
[u/mrichter/AliRoot.git] / AD / AliADReconstructor.cxx
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  **************************************************************************/
15
16 /* $Id: AliADReconstructor.cxx 20956 2007-09-26 14:22:18Z mrodrigu $ */
17 //////////////////////////////////////////////////////////////////////////////
18 //                                                                          //
19 //  Class for AD reconstruction                                         //
20 //////////////////////////////////////////////////////////////////////////////
21 #include <TParameter.h>
22
23 #include "AliRawReader.h"
24 #include "AliGRPObject.h"
25 #include "AliCDBManager.h"
26 #include "AliCDBStorage.h"
27 #include "AliCDBEntry.h"
28 #include "AliESDEvent.h"
29
30 #include "AliADReconstructor.h"
31 #include "AliADdigit.h"
32 #include "AliESDAD.h"
33 #include "AliADConst.h"
34 #include "AliADCalibData.h"
35 #include "AliADRawStream.h"
36
37 ClassImp(AliADReconstructor)
38 //_____________________________________________________________________________
39 AliADReconstructor:: AliADReconstructor():
40   AliReconstructor(),
41   fESDAD(0x0),
42   fCalibData(NULL),
43   fDigitsArray(0)
44
45 {
46   fCalibData = GetCalibData();
47   // Default constructor  
48   // Get calibration data
49
50 }
51
52 //_____________________________________________________________________________
53 AliADReconstructor& AliADReconstructor::operator = 
54   (const AliADReconstructor& /*reconstructor*/)
55 {
56 // assignment operator
57
58   Fatal("operator =", "assignment operator not implemented");
59   return *this;
60 }
61
62 //_____________________________________________________________________________
63 AliADReconstructor::~AliADReconstructor()
64 {
65 // destructor
66   delete fESDAD;
67   delete fDigitsArray;
68 }
69
70 //_____________________________________________________________________________
71 void AliADReconstructor::Init()
72 {
73 // initializer
74     fESDAD  = new AliESDAD;
75 }
76
77 //_____________________________________________________________________________
78 void AliADReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
79 {
80 // converts RAW to digits 
81
82   if (!digitsTree) {
83     AliError("No digits tree!");
84     return;
85   }
86
87   if (!fDigitsArray){
88     fDigitsArray = new TClonesArray("AliADdigit", 16);
89     digitsTree->Branch("ADDigit", &fDigitsArray);
90     }
91
92   rawReader->Reset();
93   AliADRawStream rawStream(rawReader);
94   if (rawStream.Next()) { 
95
96     for(Int_t iChannel=0; iChannel < 16; ++iChannel) {
97       Int_t offlineCh = rawStream.GetOfflineChannel(iChannel);
98       // ADC charge samples
99       Short_t chargeADC[kNClocks];
100       for(Int_t iClock=0; iClock < kNClocks; ++iClock) {
101         chargeADC[iClock] = rawStream.GetPedestal(iChannel,iClock);
102       }
103       // Integrator flag
104       Bool_t integrator = rawStream.GetIntegratorFlag(iChannel,kNClocks/2);
105       Bool_t BBflag = rawStream.GetBBFlag(iChannel,kNClocks/2); 
106       Bool_t BGflag = rawStream.GetBGFlag(iChannel,kNClocks/2);
107    
108       // HPTDC data (leading time and width)
109       Int_t board = AliADCalibData::GetBoardNumber(offlineCh);
110       Float_t time = rawStream.GetTime(iChannel)*fCalibData->GetTimeResolution(board);
111       Float_t width = rawStream.GetWidth(iChannel)*fCalibData->GetWidthResolution(board);
112       // Add a digit
113       if(!fCalibData->IsChannelDead(iChannel)){
114           new ((*fDigitsArray)[fDigitsArray->GetEntriesFast()]) AliADdigit(offlineCh, time, width,integrator, chargeADC, BBflag, BGflag);
115       }
116     }
117
118     digitsTree->Fill();
119   }
120
121   fDigitsArray->Clear();
122
123 }
124
125 //_____________________________________________________________________________
126 void AliADReconstructor::FillESD(TTree* digitsTree, TTree* /*clustersTree*/,AliESDEvent* esd) const
127 {
128
129   printf("Running AD Reconstruction \n");
130
131   // fills ESD with AD Digits
132
133   if (!digitsTree)
134     {
135       AliError("No digits tree!");
136       return;
137     }
138
139   TBranch* digitBranch = digitsTree->GetBranch("ADdigit");
140   if (!digitBranch) {
141     AliError("No AD digits branch found!");
142     return;
143   }
144   digitBranch->SetAddress(&fDigitsArray);
145
146   digitsTree->GetEvent(0);
147
148   Bool_t ADHits[16];
149   for(Int_t i = 0; i < 16; i++) { ADHits[i] = kFALSE; }
150
151   Int_t nDigits = fDigitsArray->GetEntriesFast();
152     
153   for (Int_t d=0; d<nDigits; d++) {    
154     AliADdigit* digit = (AliADdigit*) fDigitsArray->At(d);
155     Int_t module = digit->PMNumber();
156  //   printf("AD Module: %d\n",module);
157     ADHits[module] = kTRUE;
158   }  
159   if (!esd) {
160         AliError("NO AD ESD branch found!");
161         return;
162 }
163   fESDAD->SetADBitCell(ADHits);
164
165   if (esd)
166     {
167       AliDebug(1, Form("Writing AD data to ESD Tree"));
168       esd->SetADData(fESDAD);
169     }
170
171   fDigitsArray->Clear();
172 }
173
174 //_____________________________________________________________________________
175 AliADCalibData* AliADReconstructor::GetCalibData() const
176 {
177   AliCDBManager *man = AliCDBManager::Instance();
178
179   AliCDBEntry *entry=0;
180
181   //entry = man->Get("AD/Calib/Data");
182   //if(!entry){
183     //AliWarning("Load of calibration data from default storage failed!");
184     //AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");
185         
186     man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
187     man->SetRun(1);
188     entry = man->Get("AD/Calib/Data");
189   //}
190   // Retrieval of data in directory AD/Calib/Data:
191
192   AliADCalibData *calibdata = 0;
193
194   if (entry) calibdata = (AliADCalibData*) entry->GetObject();
195   if (!calibdata)  AliFatal("No calibration data from calibration database !");
196
197   return calibdata;
198 }
199
200