Adding function to make calibration tree (Marian)
[u/mrichter/AliRoot.git] / FMD / AliFMDBaseDA.cxx
CommitLineData
a0180e76 1/**************************************************************************
2 * Copyright(c) 2004, 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/** @file AliFMDBaseDA.cxx
17 @author Hans Hjersing Dalsgaard <canute@nbi.dk>
18 @date Wed Mar 26 11:30:45 2008
19 @brief Base class for detector algorithms.
20*/
21//
e9c06036 22// This is the implementation of the (virtual) base class for the FMD
23// detector algorithms(DA). It implements the creation of the relevant
24// containers and handles the loop over the raw data. The derived
25// classes can control the parameters and action to be taken making
26// this the base class for the Pedestal, Gain and Physics DA.
a0180e76 27//
28
29#include "AliFMDBaseDA.h"
30#include "iostream"
31
32#include "AliFMDRawReader.h"
1656783c 33#include "AliFMDCalibSampleRate.h"
a0180e76 34#include "AliLog.h"
35//_____________________________________________________________________
36ClassImp(AliFMDBaseDA)
e9c06036 37#if 0
38; // Do not delete - to let Emacs for mat the code
39#endif
40
41//_____________________________________________________________________
42const char*
43AliFMDBaseDA::GetStripPath(UShort_t det,
44 Char_t ring,
45 UShort_t sec,
46 UShort_t str,
47 Bool_t full) const
48{
49 return Form("%s%sFMD%d%c[%02d,%03d]",
50 (full ? GetSectorPath(det, ring, sec, full) : ""),
51 (full ? "/" : ""), det, ring, sec, str);
52}
53//_____________________________________________________________________
54const char*
55AliFMDBaseDA::GetSectorPath(UShort_t det,
56 Char_t ring,
57 UShort_t sec,
58 Bool_t full) const
59{
60 return Form("%s%sFMD%d%c[%02d]",
61 (full ? GetRingPath(det, ring, full) : ""),
62 (full ? "/" : ""), det, ring, sec);
63}
64//_____________________________________________________________________
65const char*
66AliFMDBaseDA::GetRingPath(UShort_t det,
67 Char_t ring,
68 Bool_t full) const
69{
70 return Form("%s%sFMD%d%c",
71 (full ? GetDetectorPath(det, full) : ""),
72 (full ? "/" : ""), det, ring);
73}
74//_____________________________________________________________________
75const char*
76AliFMDBaseDA::GetDetectorPath(UShort_t det,
77 Bool_t full) const
78{
79 return Form("%s%sFMD%d",
80 (full ? fDiagnosticsFilename.Data() : ""),
81 (full ? ":/" : ""), det);
82}
a0180e76 83
84//_____________________________________________________________________
85AliFMDBaseDA::AliFMDBaseDA() : TNamed(),
86 fDiagnosticsFilename("diagnosticsHistograms.root"),
87 fOutputFile(),
ce5a8b1a 88 fConditionsFile(),
a0180e76 89 fSaveHistograms(kFALSE),
90 fDetectorArray(),
91 fRequiredEvents(0),
92 fCurrentEvent(0)
93{
94 fDetectorArray.SetOwner();
ce5a8b1a 95 fConditionsFile.open("conditions.csv");
a0180e76 96}
97//_____________________________________________________________________
98AliFMDBaseDA::AliFMDBaseDA(const AliFMDBaseDA & baseDA) :
99 TNamed(baseDA),
a7e41e8d 100 fDiagnosticsFilename(baseDA.fDiagnosticsFilename.Data()),
a0180e76 101 fOutputFile(),
ce5a8b1a 102 fConditionsFile(),
a0180e76 103 fSaveHistograms(baseDA.fSaveHistograms),
104 fDetectorArray(baseDA.fDetectorArray),
105 fRequiredEvents(baseDA.fRequiredEvents),
106 fCurrentEvent(baseDA.fCurrentEvent)
107{
108 fDetectorArray.SetOwner();
109
110}
111
82d71828 112
a0180e76 113//_____________________________________________________________________
e9c06036 114AliFMDBaseDA::~AliFMDBaseDA()
115{
a0180e76 116 //destructor
a0180e76 117}
118
119//_____________________________________________________________________
e9c06036 120void AliFMDBaseDA::Run(AliRawReader* reader)
121{
122 TFile* diagFile = 0;
123 if (fSaveHistograms)
124 diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
a0180e76 125
e9c06036 126 InitContainer(diagFile);
a0180e76 127 Init();
128
e9c06036 129
a0180e76 130 reader->Reset();
ce5a8b1a 131
e9c06036 132 AliFMDRawReader* fmdReader = new AliFMDRawReader(reader,0);
133 TClonesArray* digitArray = new TClonesArray("AliFMDDigit",0);
a0180e76 134
ce5a8b1a 135 WriteConditionsData();
136
e9c06036 137 reader->NextEvent(); // Read Start-of-Run event
138 reader->NextEvent(); // Read Start-of-Files event
1656783c 139 int lastProgress = 0;
a0180e76 140
e9c06036 141 for(Int_t n =1;n <= GetRequiredEvents(); n++) {
142 if(!reader->NextEvent()) continue;
143
144 SetCurrentEvent(*(reader->GetEventId()));
145
146 digitArray->Clear();
147 fmdReader->ReadAdcs(digitArray);
148
149 AliDebug(5, Form("In event # %d with %d entries",
150 *(reader->GetEventId()), digitArray->GetEntriesFast()));
151
152 for(Int_t i = 0; i<digitArray->GetEntriesFast();i++) {
153 AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i));
154 FillChannels(digit);
a0180e76 155 }
e9c06036 156
157 FinishEvent();
158 int progress = int((n *100)/ GetRequiredEvents()) ;
159 if (progress <= lastProgress) continue;
160 lastProgress = progress;
161 std::cout << "Progress: " << lastProgress << " / 100 " << std::endl;
162 }
163
a0180e76 164 AliInfo(Form("Looped over %d events",GetCurrentEvent()));
165 WriteHeaderToFile();
166
167 for(UShort_t det=1;det<=3;det++) {
e9c06036 168 std::cout << "FMD" << det << std::endl;
a0180e76 169 UShort_t FirstRing = (det == 1 ? 1 : 0);
170 for (UShort_t ir = FirstRing; ir < 2; ir++) {
171 Char_t ring = (ir == 0 ? 'O' : 'I');
172 UShort_t nsec = (ir == 0 ? 40 : 20);
173 UShort_t nstr = (ir == 0 ? 256 : 512);
e9c06036 174 std::cout << " Ring " << ring << ": " << std::flush;
a0180e76 175 for(UShort_t sec =0; sec < nsec; sec++) {
176 for(UShort_t strip = 0; strip < nstr; strip++) {
177 Analyse(det,ring,sec,strip);
a0180e76 178 }
e9c06036 179 std::cout << '.' << std::flush;
a0180e76 180 }
e9c06036 181 diagFile->Flush();
182 std::cout << "done" << std::endl;
a0180e76 183 }
184 }
ce5a8b1a 185
a0180e76 186 if(fOutputFile.is_open()) {
a0180e76 187 fOutputFile.write("# EOF\n",6);
188 fOutputFile.close();
a0180e76 189 }
190
191 if(fSaveHistograms ) {
e9c06036 192 AliInfo("Closing diagnostics file - please wait ...");
193 // diagFile->Write();
ce5a8b1a 194 diagFile->Close();
e9c06036 195 AliInfo("done");
a0180e76 196 }
197}
198//_____________________________________________________________________
199
e9c06036 200void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
201{
a0180e76 202 TObjArray* detArray;
203 TObjArray* ringArray;
204 TObjArray* sectorArray;
205
e9c06036 206 TDirectory* savDir = gDirectory;
207
a0180e76 208 for(UShort_t det=1;det<=3;det++) {
209 detArray = new TObjArray();
210 detArray->SetOwner();
211 fDetectorArray.AddAtAndExpand(detArray,det);
e9c06036 212
213 TDirectory* detDir = 0;
214 if (diagFile) {
215 diagFile->cd();
216 detDir = diagFile->mkdir(GetDetectorPath(det, kFALSE));
217 }
218
a0180e76 219 UShort_t FirstRing = (det == 1 ? 1 : 0);
220 for (UShort_t ir = FirstRing; ir < 2; ir++) {
221 Char_t ring = (ir == 0 ? 'O' : 'I');
222 UShort_t nsec = (ir == 0 ? 40 : 20);
223 UShort_t nstr = (ir == 0 ? 256 : 512);
224 ringArray = new TObjArray();
225 ringArray->SetOwner();
226 detArray->AddAtAndExpand(ringArray,ir);
e9c06036 227
228
229 TDirectory* ringDir = 0;
230 if (detDir) {
231 detDir->cd();
232 ringDir = detDir->mkdir(GetRingPath(det,ring, kFALSE));
233 }
234
235
a0180e76 236 for(UShort_t sec =0; sec < nsec; sec++) {
237 sectorArray = new TObjArray();
238 sectorArray->SetOwner();
239 ringArray->AddAtAndExpand(sectorArray,sec);
e9c06036 240
241
242 TDirectory* secDir = 0;
243 if (ringDir) {
244 ringDir->cd();
245 secDir = ringDir->mkdir(GetSectorPath(det, ring, sec, kFALSE));
246 }
247
a0180e76 248 for(UShort_t strip = 0; strip < nstr; strip++) {
e9c06036 249 if (secDir) {
250 secDir->cd();
251 secDir->mkdir(GetStripPath(det, ring, sec, strip, kFALSE));
252 }
a0180e76 253 AddChannelContainer(sectorArray, det, ring, sec, strip);
254 }
255 }
256 }
257 }
e9c06036 258 savDir->cd();
a0180e76 259}
ce5a8b1a 260
261//_____________________________________________________________________
e9c06036 262void AliFMDBaseDA::WriteConditionsData()
263{
ce5a8b1a 264 AliFMDParameters* pars = AliFMDParameters::Instance();
265 fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
266 fConditionsFile.write("# Sample Rate, timebins \n",25);
267
1656783c 268 UInt_t defSampleRate = 4;
ce5a8b1a 269 UInt_t timebins = 544;
1656783c 270 AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
271 for(UShort_t det=1;det<=3;det++) {
272 UShort_t FirstRing = (det == 1 ? 1 : 0);
273 for (UShort_t ir = FirstRing; ir < 2; ir++) {
274 Char_t ring = (ir == 0 ? 'O' : 'I');
275 UShort_t nsec = (ir == 0 ? 40 : 20);
276 UShort_t nstr = (ir == 0 ? 256 : 512);
277 for(UShort_t sec =0; sec < nsec; sec++) {
278 for(UShort_t strip = 0; strip < nstr; strip++) {
279 sampleRate->Set(det,ring,sec,strip,defSampleRate);
280 }
281 }
282 }
283 }
284
285 pars->SetSampleRate(sampleRate);
286
287
288 fConditionsFile << defSampleRate << ','
ce5a8b1a 289 << timebins <<"\n";
1656783c 290
291 if(fConditionsFile.is_open()) {
ce5a8b1a 292
1656783c 293 // fConditionsFile.write("# EOF\n",6);
294 fConditionsFile.close();
295
296 }
ce5a8b1a 297
298}
299
a0180e76 300//_____________________________________________________________________
301//
302// EOF
303//