]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AD/AliADReconstructor.cxx
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[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     Int_t aBBflagsADA = 0;
97     Int_t aBBflagsADC = 0;
98     Int_t aBGflagsADA = 0;
99     Int_t aBGflagsADC = 0;
100
101     for(Int_t iChannel=0; iChannel < 16; ++iChannel) {
102       Int_t offlineCh = rawStream.GetOfflineChannel(iChannel);
103       // ADC charge samples
104       Short_t chargeADC[kNClocks];
105       for(Int_t iClock=0; iClock < kNClocks; ++iClock) {
106         chargeADC[iClock] = rawStream.GetPedestal(iChannel,iClock);
107       }
108       // Integrator flag
109       Bool_t integrator = rawStream.GetIntegratorFlag(iChannel,kNClocks/2);
110       // Beam-beam and beam-gas flags
111       if(offlineCh<8) {
112         if (rawStream.GetBBFlag(iChannel,kNClocks/2)) aBBflagsADC |= (1 << offlineCh);
113         if (rawStream.GetBGFlag(iChannel,kNClocks/2)) aBGflagsADC |= (1 << offlineCh);
114       } else {
115         if (rawStream.GetBBFlag(iChannel,kNClocks/2)) aBBflagsADA |= (1 << (offlineCh-32));
116         if (rawStream.GetBGFlag(iChannel,kNClocks/2)) aBGflagsADA |= (1 << (offlineCh-32));
117       }
118       // HPTDC data (leading time and width)
119       Int_t board = AliADCalibData::GetBoardNumber(offlineCh);
120       Float_t time = rawStream.GetTime(iChannel)*fCalibData->GetTimeResolution(board);
121       Float_t width = rawStream.GetWidth(iChannel)*fCalibData->GetWidthResolution(board);
122       // Add a digit
123       if(!fCalibData->IsChannelDead(iChannel)){
124           new ((*fDigitsArray)[fDigitsArray->GetEntriesFast()]) AliADdigit(offlineCh, time, width,integrator, chargeADC);
125       }
126     }
127     // Store the BB and BG flags in the digits tree (user info)
128     digitsTree->GetUserInfo()->Add(new TParameter<int>("BBflagsADA",aBBflagsADA));
129     digitsTree->GetUserInfo()->Add(new TParameter<int>("BBflagsADC",aBBflagsADC));
130     digitsTree->GetUserInfo()->Add(new TParameter<int>("BGflagsADA",aBGflagsADA));
131     digitsTree->GetUserInfo()->Add(new TParameter<int>("BGflagsADC",aBGflagsADC));
132
133
134     digitsTree->Fill();
135   }
136
137   fDigitsArray->Clear();
138
139 }
140
141 //_____________________________________________________________________________
142 void AliADReconstructor::FillESD(TTree* digitsTree, TTree* /*clustersTree*/,AliESDEvent* esd) const
143 {
144
145   printf("Running AD Reconstruction \n");
146
147   // fills ESD with AD Digits
148
149   if (!digitsTree)
150     {
151       AliError("No digits tree!");
152       return;
153     }
154
155   TBranch* digitBranch = digitsTree->GetBranch("ADdigit");
156   if (!digitBranch) {
157     AliError("No AD digits branch found!");
158     return;
159   }
160   digitBranch->SetAddress(&fDigitsArray);
161
162   digitsTree->GetEvent(0);
163
164   Bool_t ADHits[16];
165   for(Int_t i = 0; i < 16; i++) { ADHits[i] = kFALSE; }
166
167   Int_t nDigits = fDigitsArray->GetEntriesFast();
168     
169   for (Int_t d=0; d<nDigits; d++) {    
170     AliADdigit* digit = (AliADdigit*) fDigitsArray->At(d);
171     Int_t module = digit->PMNumber();
172  //   printf("AD Module: %d\n",module);
173     ADHits[module] = kTRUE;
174   }  
175   if (!esd) {
176         AliError("NO AD ESD branch found!");
177         return;
178 }
179   fESDAD->SetADBitCell(ADHits);
180
181   if (esd)
182     {
183       AliDebug(1, Form("Writing AD data to ESD Tree"));
184       esd->SetADData(fESDAD);
185     }
186
187   fDigitsArray->Clear();
188 }
189
190 //_____________________________________________________________________________
191 AliADCalibData* AliADReconstructor::GetCalibData() const
192 {
193   AliCDBManager *man = AliCDBManager::Instance();
194
195   AliCDBEntry *entry=0;
196
197   //entry = man->Get("AD/Calib/Data");
198   //if(!entry){
199     //AliWarning("Load of calibration data from default storage failed!");
200     //AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");
201         
202     man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
203     man->SetRun(1);
204     entry = man->Get("AD/Calib/Data");
205   //}
206   // Retrieval of data in directory AD/Calib/Data:
207
208   AliADCalibData *calibdata = 0;
209
210   if (entry) calibdata = (AliADCalibData*) entry->GetObject();
211   if (!calibdata)  AliFatal("No calibration data from calibration database !");
212
213   return calibdata;
214 }
215
216