]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TRD/AliHLTTRDCalibrationComponent.cxx
HLT TRD update and cleanup, changes according to offline TRD (Theodor)
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDCalibrationComponent.cxx
1 // $Id$
2
3 /**************************************************************************
4  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5  *                                                                        *
6  * Authors: Matthias Richter <Matthias.Richter@ift.uib.no>                *
7  *          Timm Steinbeck <timm@kip.uni-heidelberg.de>                   *
8  *          for The ALICE Off-line Project.                               *
9  *                                                                        *
10  * Permission to use, copy, modify and distribute this software and its   *
11  * documentation strictly for non-commercial purposes is hereby granted   *
12  * without fee, provided that the above copyright notice appears in all   *
13  * copies and that both the copyright notice and this permission notice   *
14  * appear in the supporting documentation. The authors make no claims     *
15  * about the suitability of this software for any purpose. It is          *
16  * provided "as is" without express or implied warranty.                  *
17  **************************************************************************/
18
19 /** @file   AliHLTTRDCalibrationComponent.cxx
20     @author Timm Steinbeck, Matthias Richter
21     @date
22     @brief  A TRDCalibration processing component for the HLT. */
23
24 #if __GNUC__ >= 3
25 using namespace std;
26 #endif
27
28 #include "TTree.h"
29 #include "TFile.h"
30 #include "TBranch.h"
31
32 #include "AliHLTTRDCalibrationComponent.h"
33 #include "AliHLTTRDDefinitions.h"
34 #include "AliHLTTRDUtils.h"
35
36 #include "AliCDBManager.h"
37 #include "AliCDBStorage.h"
38 #include "AliRawReaderMemory.h"
39 #include "AliTRDCalibraFillHisto.h"
40 #include "AliTRDtrackV1.h"
41
42 #include <cstdlib>
43 #include <cerrno>
44 #include <string>
45
46 ClassImp(AliHLTTRDCalibrationComponent);
47
48 AliHLTTRDCalibrationComponent::AliHLTTRDCalibrationComponent()
49 : AliHLTCalibrationProcessor(),
50   fTRDCalibraFillHisto(NULL),
51   fOutputSize(50000),
52   fTracksArray(NULL),
53   fOutArray(NULL),
54   fNevent(0),
55   feveryNevent(20),
56   fRecievedTimeBins(kFALSE)
57 {
58   // Default constructor
59 }
60
61 AliHLTTRDCalibrationComponent::~AliHLTTRDCalibrationComponent()
62 {
63   // Destructor
64 }
65
66 const char* AliHLTTRDCalibrationComponent::GetComponentID()
67 {
68   // Return the component ID const char *
69   return "TRDCalibration"; // The ID of this component
70 }
71
72 void AliHLTTRDCalibrationComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
73 {
74   // Get the list of input data
75   list.clear(); // We do not have any requirements for our input data type(s).
76   list.push_back(AliHLTTRDDefinitions::fgkTRDSATracksDataType);
77 }
78
79 AliHLTComponentDataType AliHLTTRDCalibrationComponent::GetOutputDataType()
80 {
81   // Get the output data type
82   return AliHLTTRDDefinitions::fgkCalibrationDataType;
83 }
84
85 void AliHLTTRDCalibrationComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
86 {
87   // Get the output data size
88   constBase = fOutputSize;
89   inputMultiplier = 0;
90 }
91
92 AliHLTComponent* AliHLTTRDCalibrationComponent::Spawn()
93 {
94   // Spawn function, return new instance of this class
95   return new AliHLTTRDCalibrationComponent;
96 };
97
98 Int_t AliHLTTRDCalibrationComponent::ScanArgument( int argc, const char** argv )
99 {
100   // perform initialization. We check whether our relative output size is specified in the arguments.
101   int i = 0;
102   char* cpErr;
103   while ( i < argc )
104     {
105       HLTDebug("argv[%d] == %s", i, argv[i] );
106       if ( !strcmp( argv[i], "output_size" ) )
107         {
108           if ( i+1>=argc )
109             {
110               HLTError("Missing output_size parameter");
111               return ENOTSUP;
112             }
113           HLTDebug("argv[%d+1] == %s", i, argv[i+1] );
114           fOutputSize = strtoul( argv[i+1], &cpErr, 0 );
115           if ( *cpErr )
116             {
117               HLTError("Cannot convert output_size parameter '%s'", argv[i+1] );
118               return EINVAL;
119             }
120           HLTInfo("Output size set to %lu %%", fOutputSize );
121           i += 2;
122           continue;
123         }
124       if ( !strcmp( argv[i], "-everyNevent" ) )
125         {
126           if ( i+1>=argc )
127             {
128               HLTError("Missing everyNevent parameter");
129               return ENOTSUP;
130             }
131           HLTDebug("argv[%d+1] == %s", i, argv[i+1] );
132           fOutputSize = strtoul( argv[i+1], &cpErr, 0 );
133           if ( *cpErr )
134             {
135               HLTError("Cannot convert everyNevent parameter '%s'", argv[i+1] );
136               return EINVAL;
137             }
138           HLTInfo("Pushing back every %d event", feveryNevent);
139           i += 2;
140           continue;
141         }
142
143       else {
144         HLTError("Unknown option '%s'", argv[i] );
145         return EINVAL;
146       }
147     }
148   return 0;
149 }
150
151 Int_t AliHLTTRDCalibrationComponent::InitCalibration()
152 {
153   if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
154     HLTError("DefaultStorage is not set in CDBManager");
155     return -EINVAL;
156   }
157   if(AliCDBManager::Instance()->GetRun()<0){
158     HLTError("Run Number is not set in CDBManager");
159     return -EINVAL;
160   }
161   HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
162
163   fTRDCalibraFillHisto = AliTRDCalibraFillHisto::Instance();
164   fTRDCalibraFillHisto->SetHisto2d(); // choose to use histograms
165   fTRDCalibraFillHisto->SetCH2dOn();  // choose to calibrate the gain
166   fTRDCalibraFillHisto->SetPH2dOn();  // choose to calibrate the drift velocity
167   fTRDCalibraFillHisto->SetPRF2dOn(); // choose to look at the PRF
168   fTRDCalibraFillHisto->SetIsHLT(); // per detector
169   //fTRDCalibraFillHisto->SetDebugLevel(1);// debug
170   fTRDCalibraFillHisto->SetFillWithZero(kTRUE);
171
172   fTracksArray = new TClonesArray("AliTRDtrackV1");
173   fOutArray = new TObjArray(3);
174
175   return 0;
176 }
177
178 Int_t AliHLTTRDCalibrationComponent::DeinitCalibration()
179 {
180   
181   // Deinitialization of the component
182   
183   HLTDebug("DeinitCalibration");
184   fTracksArray->Delete();
185   delete fTracksArray;
186   fTRDCalibraFillHisto->Destroy();
187   //fOutArray->Delete();
188   delete fOutArray;
189
190   return 0;
191 }
192
193 Int_t AliHLTTRDCalibrationComponent::ProcessCalibration(const AliHLTComponent_EventData& evtData,
194                                                         const AliHLTComponent_BlockData* blocks,
195                                                         AliHLTComponent_TriggerData& /*trigData*/,
196                                                         AliHLTUInt8_t* /*outputPtr*/,
197                                                         AliHLTUInt32_t& /*size*/,
198                                                         vector<AliHLTComponent_BlockData>& /*outputBlocks*/)
199 {
200   HLTDebug("NofBlocks %lu", evtData.fBlockCnt );
201   // Process an event
202
203   // Loop over all input blocks in the event
204   vector<AliHLTComponent_DataType> expectedDataTypes;
205   GetInputDataTypes(expectedDataTypes);
206   for ( unsigned long iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
207     {
208       const AliHLTComponentBlockData &block = blocks[iBlock];
209       AliHLTComponentDataType inputDataType = block.fDataType;
210       Bool_t correctDataType = kFALSE;
211
212       for(UInt_t i = 0; i < expectedDataTypes.size(); i++)
213         if( expectedDataTypes.at(i) == inputDataType)
214           correctDataType = kTRUE;
215       if (!correctDataType) {
216         HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - Skipping",
217                   iBlock, evtData.fBlockCnt,
218                   evtData.fEventID, evtData.fEventID,
219                   DataType2Text(inputDataType).c_str());
220         continue;
221       }
222       else {
223         HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s; Block Size: %i",
224                  iBlock, evtData.fBlockCnt-1,
225                  evtData.fEventID, evtData.fEventID,
226                  DataType2Text(inputDataType).c_str(),
227                  block.fSize);
228       }
229
230       Int_t nTimeBins;
231       AliHLTTRDUtils::ReadTracks(fTracksArray, block.fPtr, block.fSize, &nTimeBins);
232       
233       if(!fRecievedTimeBins){
234         HLTDebug("Reading number of time bins from input block. Value is: %d", nTimeBins);
235         fTRDCalibraFillHisto->Init2Dhistos(); // initialise the histos
236         fTRDCalibraFillHisto->SetNumberClusters(0); // At least 1 clusters
237         fTRDCalibraFillHisto->SetNumberClustersf(nTimeBins); // Not more than %d  clusters
238         fRecievedTimeBins=kTRUE;
239       }
240
241       Int_t nbEntries = fTracksArray->GetEntries();
242       HLTDebug(" %i TRDtracks in tracksArray", nbEntries);
243       AliTRDtrackV1* trdTrack = 0x0;
244       for (Int_t i = 0; i < nbEntries; i++){
245         HLTDebug("%i/%i: ", i+1, nbEntries);
246         trdTrack = (AliTRDtrackV1*)fTracksArray->At(i);
247         trdTrack->Print();
248         fTRDCalibraFillHisto->UpdateHistogramsV1(trdTrack);
249       }
250       
251       if(!fOutArray->At(0))FormOutput();
252       if (fNevent%feveryNevent==0 && fOutArray) {
253         PushBack(fOutArray, AliHLTTRDDefinitions::fgkCalibrationDataType);
254       }
255
256       fTracksArray->Delete();
257       fNevent++;
258
259     }
260   return 0;
261
262 }
263
264 /**
265  * Form output array of histrograms
266  */
267 //============================================================================
268 void AliHLTTRDCalibrationComponent::FormOutput()
269 {
270   // gain histo
271   TH2I *hCH2d = fTRDCalibraFillHisto->GetCH2d();
272   fOutArray->Add(hCH2d);
273
274   // drift velocity histo
275   TProfile2D *hPH2d = fTRDCalibraFillHisto->GetPH2d();
276   fOutArray->Add(hPH2d);
277
278   // PRF histo
279   TProfile2D *hPRF2d = fTRDCalibraFillHisto->GetPRF2d();
280   fOutArray->Add(hPRF2d);
281
282   HLTDebug("GetCH2d = 0x%x; NEntries = %i; size = %i", hCH2d, hCH2d->GetEntries(), sizeof(hCH2d));
283   hCH2d->Print();
284   HLTDebug("GetPH2d = 0x%x; NEntries = %i; size = %i", hPH2d, hPH2d->GetEntries(), sizeof(hPH2d));
285   hPH2d->Print();
286   HLTDebug("GetPRF2d = 0x%x; NEntries = %i; size = %i", hPRF2d, hPRF2d->GetEntries(), sizeof(hPRF2d));
287   hPRF2d->Print();
288   HLTDebug("output Array: pointer = 0x%x; NEntries = %i; size = %i", fOutArray, fOutArray->GetEntries(), sizeof(fOutArray));
289 }
290
291 Int_t AliHLTTRDCalibrationComponent::ShipDataToFXS(const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/)
292 {
293   //fTRDCalibraFillHisto->DestroyDebugStreamer();
294   PushToFXS((TObject*)fOutArray, "TRD", "GAINDRIFTPRF");
295 }