]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTrackerCalibratedDataMaker.cxx
- Implementing the possibility to histogram the raw adc values when reading
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackerCalibratedDataMaker.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$
17
18 #include "AliMUONTrackerCalibratedDataMaker.h"
19
20 #include "AliMUON2DMap.h"
21 #include "AliMUONCalibParamND.h"
22 #include "AliMUONCalibrationData.h"
23 #include "AliMUONDigitCalibrator.h"
24 #include "AliMUONDigitMaker.h"
25 #include "AliMUONDigitStoreV2R.h"
26 #include "AliMUONTrackerData.h"
27 #include "AliMUONVDigit.h"
28 #include "AliMUONVDigitStore.h"
29 #include "AliMpDDLStore.h"
30 #include "AliCodeTimer.h"
31 #include "AliCDBManager.h"
32 #include "AliCDBStorage.h"
33 #include "AliRawEventHeaderBase.h"
34 #include "AliRawReader.h"
35 #include "AliLog.h"
36 #include <Riostream.h>
37
38 ///\class AliMUONTrackerCalibratedDataMaker
39 ///
40 /// Creator of AliMUONVTrackerData from AliRawReader
41 /// 
42 ///\author Laurent Aphecetche, Subatech
43
44 ///\cond CLASSIMP
45 ClassImp(AliMUONTrackerCalibratedDataMaker)
46 ///\endcond
47
48 Int_t AliMUONTrackerCalibratedDataMaker::fgkCounter(0);
49
50 //_____________________________________________________________________________
51 AliMUONTrackerCalibratedDataMaker::AliMUONTrackerCalibratedDataMaker(AliRawReader* reader,
52                                                        const char* cdbpath)
53 : AliMUONVTrackerDataMaker(),
54   fRawReader(reader),
55   fAccumulatedData(0x0),
56   fOneEventData(new AliMUON2DMap(true)),
57   fIsOwner(kTRUE),
58   fSource("unspecified"),
59   fIsRunning(kFALSE),
60   fDigitMaker(0x0),
61   fDigitCalibrator(0x0),
62   fCalibrationData(0x0),
63   fDigitStore(0x0), 
64   fCDBPath(cdbpath),
65   fNumberOfEvents(0)
66 {
67   /// Ctor
68   reader->NextEvent(); // to be sure to get run number available
69   
70   Int_t runNumber = reader->GetRunNumber();
71   
72   ++fgkCounter;
73   
74   Bool_t calibrate = ( fCDBPath.Length() > 0 );
75   
76   TString name;
77   
78   if (!runNumber)
79   {
80     name = Form("%s(%d)",(calibrate ? "CAL" : "RAW"),fgkCounter);
81   }
82   else
83   {
84     name = Form("%s%d",(calibrate ? "CAL" : "RAW"),runNumber);
85   }
86   
87   fAccumulatedData = new AliMUONTrackerData(name.Data(),"charge values",1);
88   fAccumulatedData->SetDimensionName(0,(calibrate ? "Calibrated charge" : "Raw charge"));
89   
90   reader->RewindEvents();
91
92   fDigitMaker = new AliMUONDigitMaker;
93   fDigitMaker->SetMakeTriggerDigits(kFALSE);
94   fDigitStore = new AliMUONDigitStoreV2R;
95
96   if ( calibrate ) 
97   {
98     fCalibrationData = new AliMUONCalibrationData(runNumber);
99     
100     // force the reading of calibration NOW
101     // FIXME: not really elegant and error prone (as we have the list of calib data twice, 
102     // once here and once in the digitcalibrator class, hence the change of them getting
103     // out of sync)
104     // But with the current CDBManager implementation, I don't know how to solve
105     // this better (e.g. to avoid clearing cache messages and so on).
106     
107     AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
108     
109     if ( storage->GetURI() != fCDBPath.Data() ) 
110     {
111       AliCDBManager::Instance()->SetDefaultStorage(fCDBPath.Data());
112     }
113     
114     fCalibrationData->Pedestals();
115     fCalibrationData->Gains();
116     fCalibrationData->Neighbours();
117     fCalibrationData->HV();
118     fCalibrationData->Capacitances();
119     
120     if ( storage->GetURI() != fCDBPath.Data() ) 
121     {
122       AliCDBManager::Instance()->SetDefaultStorage(storage);
123     }
124     
125     fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData);
126   }
127 }
128
129 //_____________________________________________________________________________
130 AliMUONTrackerCalibratedDataMaker::~AliMUONTrackerCalibratedDataMaker()
131 {
132   /// dtor
133   delete fOneEventData;
134   if ( fIsOwner ) delete fAccumulatedData;
135   delete fRawReader;
136   delete fDigitStore;
137   delete fCalibrationData;
138   delete fDigitMaker;
139   delete fDigitCalibrator;
140 }
141
142 //_____________________________________________________________________________
143 Bool_t 
144 AliMUONTrackerCalibratedDataMaker::NextEvent()
145 {
146   /// Read next event
147  
148   AliCodeTimerAuto("");
149   
150   static Int_t nphysics(0);
151   static Int_t ngood(0);
152
153   if ( !IsRunning() ) return kTRUE;
154   
155   Bool_t ok = fRawReader->NextEvent();
156
157   if (!ok) 
158   {
159     fDigitMaker->Print();
160     return kFALSE;
161   }
162   
163   Int_t eventType = fRawReader->GetType();
164
165   ++fNumberOfEvents;
166   
167   if (eventType != AliRawEventHeaderBase::kPhysicsEvent ) 
168   {
169     return kTRUE; // for the moment
170   }
171
172   ++nphysics;
173
174   Int_t rv = fDigitMaker->Raw2Digits(fRawReader,fDigitStore);
175   
176   if ( ( rv & AliMUONDigitMaker::kTrackerBAD ) != 0 ) return kTRUE;
177
178   if ( fDigitCalibrator ) 
179   {
180     fDigitCalibrator->Calibrate(*fDigitStore);
181   }
182   
183   Bool_t dok = ConvertDigits();
184   
185   if ( dok )
186     {
187       ++ngood;
188       fAccumulatedData->Add(*fOneEventData);
189     }
190
191   AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,nphysics,ngood));
192
193   return kTRUE;
194 }
195
196 //_____________________________________________________________________________
197 Bool_t 
198 AliMUONTrackerCalibratedDataMaker::ConvertDigits()
199 {
200   /// Convert digitstore into fOneEventData
201   
202   AliCodeTimerAuto("");
203   
204   TIter next(fDigitStore->CreateIterator());
205   AliMUONVDigit* digit;
206
207   fOneEventData->Clear();
208   
209   while ( ( digit = static_cast<AliMUONVDigit*>(next())) )
210   {
211     Double_t value = ( digit->IsCalibrated() ? digit->Charge() : digit->ADC() );
212
213     if ( value > 0 ) 
214     {
215       Int_t detElemId = digit->DetElemId();
216       Int_t manuId = digit->ManuId();
217     
218       AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fOneEventData->FindObject(detElemId,manuId));
219       if (!param)
220       {
221         param = new AliMUONCalibParamND(1,64,detElemId,manuId,
222                                       AliMUONVCalibParam::InvalidFloatValue());
223         fOneEventData->Add(param);
224       }
225     
226       param->SetValueAsDouble(digit->ManuChannel(),0,value);
227     }
228   }
229
230   return kTRUE;
231 }
232
233 //_____________________________________________________________________________
234 void
235 AliMUONTrackerCalibratedDataMaker::Print(Option_t*) const
236 {
237   /// Printout
238   
239   cout << "Source=" << Source() << " Running=" << ( IsRunning() ? "YES" : "NO")
240   << endl;
241   
242 }
243
244 //_____________________________________________________________________________
245 void 
246 AliMUONTrackerCalibratedDataMaker::Rewind()
247 {
248   /// Rewind events
249   fRawReader->RewindEvents();
250   fNumberOfEvents=0;
251 }