Drift velocity calibration document
[u/mrichter/AliRoot.git] / MUON / MUONOfflineShift.C
CommitLineData
10eb3d17 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$ */
17
18/// \ingroup macros
19/// \file MUONOfflineShift.C
20/// \brief Macro to be used to check raw data during MUON offline shifts.
21///
22/// Basic usage is :
23///
24/// MUONOfflineShift("path_to_raw_file","basename of output file")
25///
26/// This will read the raw data and process it several times, varying what's done :
27/// only decoding, decoding + zero-suppression, etc... (TBE)
28///
29/// Two outputs files will be created :
30///
31/// - basename.root, containing AliMUONVTrackerData objects that can then
32/// be displayed using the mchview program (using mchview --use basename.root)
33///
34/// - basename.log, containing (for the moment) the occupancy numbers of the various detection elements
35///
36/// \author Laurent Aphecetche
37
38#if !defined(__CINT__) || defined(__MAKECINT__)
39
40#include "AliCDBManager.h"
41#include "AliCodeTimer.h"
42#include "AliMUONPainterRegistry.h"
43#include "AliMUONTrackerCalibratedDataMaker.h"
44#include "AliMUONTrackerRawDataMaker.h"
45#include "AliMUONVTrackerData.h"
46#include "AliMpCDB.h"
47#include "AliMpConstants.h"
48#include "AliMpDEIterator.h"
49#include "AliRawReader.h"
50#include "AliRawReaderDate.h"
51#include "AliRawReaderRoot.h"
52#include <Riostream.h>
53#include <TFile.h>
54#include <TGrid.h>
55#include <TStopwatch.h>
56#include <TString.h>
57#include <TSystem.h>
58
59#endif
60
61//______________________________________________________________________________
62Int_t DataMakerReading(AliRawReader* rawReader,
63 TStopwatch& timer,
64 const char* cdbPath="",
65 const char* calibMode="",
66 Bool_t histogram=kFALSE,
67 Double_t xmin = 0.0,
68 Double_t xmax = 4096.0)
69{
70 /// Run over the data and calibrate it if so required (if cdbPath != "")
71 /// calibMode can be :
72 /// - NOGAIN : only zero-suppression will be done
73 /// - GAINCONSTANTCAPA : zero-suppression + gain, but with a single capa value for all channels
74 /// - GAIN : zero-suppression + gain w/ individual capacitance per channel.
75
76 rawReader->RewindEvents();
77
78 AliMUONVTrackerDataMaker* dm(0x0);
79
80 if ( strlen(cdbPath) > 0 )
81 {
82 dm = new AliMUONTrackerCalibratedDataMaker(rawReader,cdbPath,calibMode,histogram,xmin,xmax);
83 }
84 else
85 {
86 dm = new AliMUONTrackerRawDataMaker(rawReader,kTRUE);
87 }
88
89 AliMUONPainterRegistry::Instance()->Register(dm);
90
91 timer.Start(kTRUE);
92 Int_t n(0);
93
94 dm->SetRunning(kTRUE);
95
96 while (dm->NextEvent())
97 {
98 ++n;
99 }
100
101 timer.Stop();
102
103 delete dm;
104
105 return n;
106}
107
108//______________________________________________________________________________
109void Print(const char* method, TStopwatch& timer, Int_t n)
110{
111 /// Get the timing for a given method
112
113 cout << Form("%20s %10d events. Total CPU time %7.2f seconds.",
114 method,n,timer.CpuTime());
115
116 Double_t cpu = timer.CpuTime()/n;
117 Double_t real = timer.RealTime()/n;
118
119 cout << Form(" ms real/event = %7.2f ms CPU/event = %7.2f",real*1E3,cpu*1E3)
120 << endl;
121}
122
123//______________________________________________________________________________
124void Occupancy(ostream& outfile)
125{
126 /// Write occupancy numbers to output text file
127
128 outfile << "-----------------------------------------------------" << endl;
129 outfile << "Occupancy numbers" << endl;
130 outfile << "-----------------------------------------------------" << endl;
131
132 const Int_t occIndex = 2;
133
134 AliMUONPainterRegistry* reg = AliMUONPainterRegistry::Instance();
135
136 Int_t nofDataSources = reg->NumberOfDataSources();
137
138 outfile << Form("%11s|"," ");
139
140 for ( Int_t ids = 0; ids < nofDataSources; ++ ids )
141 {
142 AliMUONVTrackerData* data = reg->DataSource(ids);
143 outfile << Form(" %13s |",data->GetName());
144 }
145
146 outfile << endl;
147
148 for ( Int_t chamberId = 0; chamberId < AliMpConstants::NofTrackingChambers(); ++chamberId )
149 {
150 Bool_t nonZero(kFALSE);
151 for ( Int_t ids = 0; ids < nofDataSources && nonZero == kFALSE; ++ ids )
152 {
153 if ( reg->DataSource(ids)->Chamber(chamberId,occIndex) ) nonZero = kTRUE;
154 }
155
156 if ( !nonZero ) continue;
157
158 outfile << Form("Chamber %2d |",chamberId);
159 for ( Int_t ids = 0; ids < nofDataSources; ++ ids )
160 {
161 AliMUONVTrackerData* data = reg->DataSource(ids);
162 outfile << Form(" %7.2f %% |",100.0*data->Chamber(chamberId,occIndex));
163 }
164 outfile << endl;
165
166 AliMpDEIterator it;
167 it.First(chamberId);
168 while (!it.IsDone())
169 {
170 Int_t detElemId = it.CurrentDEId();
171 Bool_t nonZero(kFALSE);
172 for ( Int_t ids = 0; ids < nofDataSources && nonZero == kFALSE; ++ ids )
173 {
174 AliMUONVTrackerData* data = reg->DataSource(ids);
175 if ( data->DetectionElement(detElemId,occIndex) > 0 )
176 {
177 nonZero = kTRUE;
178 }
179 }
180
181 if ( nonZero )
182 {
183 outfile << Form(" DE %04d |",detElemId);
184 for ( Int_t ids = 0; ids < nofDataSources; ++ ids )
185 {
186 AliMUONVTrackerData* data = reg->DataSource(ids);
187 outfile << Form(" %7.2f %% |",100.0*data->DetectionElement(detElemId,occIndex));
188 }
189 outfile << endl;
190 }
191 it.Next();
192 }
193 }
194}
195
196//______________________________________________________________________________
197void MUONOfflineShift(const char* input, const char* outputBase,
198 const char* ocdbPath="alien://folder=/alice/data/2008/LHC08a/OCDB")
199{
200 /// Entry point of the macro.
201 /// Example of syntax for an input file (from alien)
202 ///
203 /// alien::///alice/data/2007/LHC07w/000014493/raw/07000014493001.10.root
204 ///
205 /// and for an OCDB path :
206 ///
207 /// alien://folder=/alice/data/2007/LHC07w/OCDB
208 ///
209
210 TGrid::Connect("alien://");
211
212 AliCodeTimer::Instance()->Reset();
213
214 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
215 AliCDBManager::Instance()->SetRun(0);
216 AliMpCDB::LoadDDLStore();
217
218 TString fileName(gSystem->ExpandPathName(input));
219
220 AliRawReader* rawReader(0x0);
221
222 // check extention to choose the rawdata file format
223 if (fileName.EndsWith(".root"))
224 {
225 rawReader = new AliRawReaderRoot(fileName);
226 }
227 else if (!fileName.IsNull())
228 {
229 rawReader = new AliRawReaderDate(fileName); // DATE file
230 }
231
232 if (!rawReader) return;
233
234 TStopwatch timer2;
235 TStopwatch timer3;
236
237 Int_t n2 = DataMakerReading(rawReader,timer2);
238
239 Int_t n3 = DataMakerReading(rawReader,timer3,ocdbPath);
240
241 Print("DataMakerReading(RAW)",timer2,n2);
242
243 Print("DataMakerReading(CAL)",timer3,n3);
244
245 AliMUONPainterRegistry* reg = AliMUONPainterRegistry::Instance();
246
247 TFile f(gSystem->ExpandPathName(Form("%s.root",outputBase)),"RECREATE");
248 ofstream out(gSystem->ExpandPathName(Form("%s.log",outputBase)));
249
250 Occupancy(out);
251
252 for ( Int_t i = 0; i < reg->NumberOfDataSources(); ++i )
253 {
254 AliMUONVTrackerData* data = reg->DataSource(i);
255 data->Write();
256 }
257
258 f.Close();
259
260}