1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ////////////////////////////////////////////////////////////////////////////
20 // This class is a first implementation for the TRD. //
21 // It takes data from HLT and computes the parameters //
22 // and stores both reference data and online calibration //
23 // parameters in the CDB //
24 // It alsotakes DCS data, does spline fits //
25 // and stores both reference data and spline fits results //
29 // R. Bailhache (R.Bailhache@gsi.de) //
30 // W. Monange (w.monange@gsi.de) //
32 ////////////////////////////////////////////////////////////////////////////
34 #include "AliTRDPreprocessor.h"
37 #include <TProfile2D.h>
38 #include <TStopwatch.h>
39 #include <TObjString.h>
42 #include <TCollection.h>
44 #include "AliCDBMetaData.h"
47 #include "AliTRDSensorArray.h"
48 #include "AliTRDCalibraFit.h"
49 #include "AliTRDCalibraMode.h"
50 #include "AliTRDCalibPadStatus.h"
51 #include "Cal/AliTRDCalDet.h"
52 #include "Cal/AliTRDCalPadStatus.h"
54 ClassImp(AliTRDPreprocessor)
56 //______________________________________________________________________________________________
57 AliTRDPreprocessor::AliTRDPreprocessor(AliShuttleInterface *shuttle)
58 :AliPreprocessor("TRD", shuttle)
66 //______________________________________________________________________________________________
67 AliTRDPreprocessor::~AliTRDPreprocessor()
75 //______________________________________________________________________________________________
76 void AliTRDPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
79 // Initialization routine for the TRD preprocessor
82 AliPreprocessor::Initialize(run,startTime,endTime);
86 //______________________________________________________________________________________________
87 UInt_t AliTRDPreprocessor::Process(TMap* dcsAliasMap)
90 // Process DCS and calibration part for HLT
99 AliCDBMetaData metaData;
100 metaData.SetBeamPeriod(0);
101 metaData.SetResponsible("Wilfried Monange/Raphaelle Bailhache");
102 metaData.SetComment("TRD calib test");
105 Log ("****** DCS ******\n");
107 TObjArray * list = AliTRDSensorArray::GetList ();
110 Log ("Error during AliTRDSensorArray::GetList");
111 Log ("DCS will not be processing");
114 Int_t nEntries = list->GetEntries ();
115 Log (Form ("%d alias loaded", nEntries));
117 Bool_t * results = new Bool_t [nEntries];
118 Int_t * nGraph = new Int_t [nEntries];
120 for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
122 AliTRDSensorArray * oneTRDDCS = (AliTRDSensorArray *)list->At (iAlias);
124 oneTRDDCS->SetStartTime (TTimeStamp (fStartTime));
125 oneTRDDCS->SetEndTime (TTimeStamp (fEndTime));
127 Log (Form("Processing DCS : \"%s\"",
128 oneTRDDCS->GetStoreName ().Data ()));
130 TMap * map = oneTRDDCS->ExtractDCS (dcsAliasMap);
132 nGraph [iAlias] = map->GetEntries ();
134 if (nGraph [iAlias] == 0) {
135 Log("No TGraph for this dcsDatapointAlias : not stored");
136 results [iAlias] = kFALSE;
137 result |= kEStoreRefDCS;
141 oneTRDDCS->SetGraph (map);
143 results [iAlias] = Store("Calib",
144 oneTRDDCS->GetStoreName ().Data (),
151 results [iAlias] = StoreReferenceData("Calib",
152 oneTRDDCS->GetStoreName ().Data (),
156 if (!results [iAlias]) {
157 AliError("Problem during StoreRef DCS");
158 result |= kEStoreRefDCS;
165 oneTRDDCS->SetDiffCut2 (0.1);
166 map = oneTRDDCS->ExtractDCS (dcsAliasMap);
167 oneTRDDCS->SetGraph (map);
169 StoreReferenceData("Calib",
170 (oneTRDDCS->GetStoreName ()+"Cut").Data(),
171 oneTRDDCS, &metaData);
177 Log (" Summury of DCS :\n");
178 Log (Form("%30s %10s %10s", "dcsDatapointAlias", "Stored ?", "# graph"));
179 for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
180 AliTRDSensorArray * oneTRDDCS = (AliTRDSensorArray *)list->At (iAlias);
181 Log (Form ("%30s %10s %4d",
182 oneTRDDCS->GetStoreName ().Data (),
183 results[iAlias] ? "ok" : "X",
186 Log ("*********** End of DCS **********");
193 // Process the calibration data for the HLT part
196 // Objects for HLT and DAQ zusammen
197 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
198 Bool_t hltVdrifthisto = kFALSE;
199 // Store the infos for the detector
200 AliCDBMetaData *md1= new AliCDBMetaData();
201 md1->SetObjectClassName("AliTRDCalDet");
202 md1->SetResponsible("Raphaelle Bailhache");
203 md1->SetBeamPeriod(0);
204 md1->SetComment("TRD calib test");
205 // Store the infos for the pads
206 AliCDBMetaData *md2= new AliCDBMetaData();
207 md2->SetObjectClassName("AliTRDCalPad");
208 md2->SetResponsible("Raphaelle Bailhache");
209 md2->SetBeamPeriod(0);
210 md2->SetComment("TRD calib test");
213 // Process the calibration data for the HLT part
216 // How long does it take for the HLT part?
221 TString runType = GetRunType();
222 Log(Form("Run type for run %d: %s", fRun, runType.Data()));
223 if (strcmp(runType, "PHYSICS") != 0){
224 Log("Nothing to do for HLT!");
227 // note that the parameters are returned as character strings!
228 const char* nEvents = GetRunParameter("totalEvents");
230 Log(Form("Number of events for run %d: %s",fRun, nEvents));
232 Log(Form("Number of events not put in logbook!"));
235 // Take the file from the HLT file exchange server
236 TList *filesourceshlt = GetFileSources(kHLT,"GAINDRIFTPRF");
237 if (!filesourceshlt) {
238 Log(Form("No sources found for GAINDRIFTPRF for run %d !",fRun));
239 result |= kEListFileHLT;
242 if (filesourceshlt->GetSize() != 1) {
243 Log(Form("More than one source found for GAINDRIFTPRF for run %d!",fRun));
244 filesourceshlt->Print();
245 result |= kEListFileHLT;
250 //calibra->SetDebugLevel(2); //Debug
252 // Loop over the files taken from the HLT
253 TIter iter(filesourceshlt);
254 TObjString *sourcehlt;
255 while ((sourcehlt = dynamic_cast<TObjString *> (iter.Next()))) {
257 TString filenamehlt = GetFile(kHLT,"GAINDRIFTPRF",sourcehlt->GetName());
258 if (filenamehlt.Length() == 0) {
259 Log(Form("Error retrieving file from source %d failed!", sourcehlt->GetName()));
260 result |= kEOpenFileHLT;
265 TH2I *histogain = 0x0; // Histogram taken from HLT for gain factor
266 TProfile2D *histodriftvelocity = 0x0; // Profile taken from HLT for drift velocity and time0
267 TProfile2D *histoprf = 0x0; // Profile taken from HLT for prf
271 TFile *filehlt = TFile::Open(filenamehlt);
272 histogain = (TH2I *) filehlt->Get("CH2d");
273 histogain->SetDirectory(0);
275 Log("Error retrieving 2D histos for gain failed!");
276 result |= kETakeHistoHLT;
278 histodriftvelocity = (TProfile2D *) filehlt->Get("PH2d");
279 histodriftvelocity->SetDirectory(0);
280 if (!histodriftvelocity) {
281 Log("Error retrieving 2D Profile for average pulse height failed!");
282 result |= kETakeHistoHLT;
284 histoprf = (TProfile2D *) filehlt->Get("PRF2d");
285 histoprf->SetDirectory(0);
287 Log("Error retrieving 2D Profile for Pad Response Function failed!");
288 result |= kETakeHistoHLT;
292 // try to fit them and store
294 if(!StoreReferenceData("HLTData","Gain",(TObject *) histogain,&metaData)){
295 Log("Error storing 2D histos for gain as reference data");
296 result |= kEStoreHistoHLT;
298 Log("Take the CH reference data. Now we will try to fit\n");
299 calibra->SetMinEntries(100); // If there is less than 100 entries in the histo: no fit
300 calibra->AnalyseCH(histogain);
301 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
302 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
303 Int_t nbfit = calibra->GetNumberFit();
304 Int_t nbE = calibra->GetNumberEnt();
306 (nbfit >= 0.95*nbE)) {
307 TObjArray object = calibra->GetVectorFit();
308 AliTRDCalDet *objgaindet = calibra->CreateDetObjectGain(&object,calibra->GetScaleFitFactor(),kTRUE);
309 TObject *objgainpad = calibra->CreatePadObjectGain();
310 if(!Store("Calib","ChamberGainFactor",(TObject *) objgaindet ,md1,0,kTRUE)){
311 Log("Error storing the calibration object for the chamber gain");
312 result |= kEStoreCalHLT;
314 if(!Store("Calib","LocalGainFactor" ,(TObject *) objgainpad ,md2,0,kTRUE)){
315 Log("Error storing the calibration object for the local gain factor");
316 result |= kEStoreCalHLT;
320 Log("Not enough statistics for the gain");
321 result |= kEFitHistoHLT;
323 calibra->ResetVectorFit();
326 if (histodriftvelocity) {
327 if(!StoreReferenceData("HLTData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
328 Log("Error storing 2D Profile for average pulse height as reference data");
329 result |= kEStoreHistoHLT;
331 Log("Take the PH reference data. Now we will try to fit\n");
332 calibra->SetMinEntries(100*20); // If there is less than 2000
333 calibra->AnalysePH(histodriftvelocity);
334 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
335 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
336 Int_t nbfit = calibra->GetNumberFit();
337 Int_t nbE = calibra->GetNumberEnt();
339 (nbfit >= 0.95*nbE)) {
340 TObjArray object = calibra->GetVectorFit();
341 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
342 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
343 object = calibra->GetVectorFit2();
344 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
345 TObject *objtime0pad = calibra->CreatePadObjectT0();
346 if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,md1,0,kTRUE)){
347 Log("Error storing the calibration object for the chamber vdrift");
348 result |= kEStoreCalHLT;
350 if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,md1,0,kTRUE)){
351 Log("Error storing the calibration object for the chamber t0");
352 result |= kEStoreCalHLT;
354 if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,md2,0,kTRUE)){
355 Log("Error storing the calibration object for the local drift velocity");
356 result |= kEStoreCalHLT;
358 if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,md2,0,kTRUE)){
359 Log("Error storing the calibration object for the local time0");
360 result |= kEStoreCalHLT;
362 hltVdrifthisto = kTRUE;
365 Log("Not enough statistics for the average pulse height");
366 result |= kEFitHistoHLT;
368 calibra->ResetVectorFit();
372 if(!StoreReferenceData("HLTData","PRF",(TObject *) histoprf,&metaData)){
373 Log("Error storing the 2D Profile for Pad Response Function as reference data");
374 result |= kEStoreHistoHLT;
376 Log("Take the PRF reference data. Now we will try to fit\n");
377 calibra->SetMinEntries(100*20); // If there is less than 2000
378 calibra->AnalysePRFMarianFit(histoprf);
379 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
380 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
381 Int_t nbfit = calibra->GetNumberFit();
382 Int_t nbE = calibra->GetNumberEnt();
384 (nbfit >= 0.95*nbE)) {
385 TObjArray object = calibra->GetVectorFit();
386 TObject *objPRFpad = calibra->CreatePadObjectPRF(&object);
387 if(!Store("Calib","PRFWidth" ,(TObject *) objPRFpad ,md2,0,kTRUE)){
388 Log("Error storing the calibration object for the Pad Response Function");
389 result |= kEStoreCalHLT;
393 Log("Not enough statistics for the Pad Response Function");
394 result |= kEFitHistoHLT;
396 calibra->ResetVectorFit();
400 } // if HLT size of tlist
402 delete filesourceshlt;
403 } //if run type physics
409 // Process the calibration data for the DAQ part
412 // How long does it take for the DAQ part?
416 // Take the file from the DAQ file exchange server
417 TList *filesourcesdaq = GetFileSources(kDAQ,"PADSTATUSVDRIFT");
418 if (!filesourcesdaq) {
419 Log(Form("No sources found for GAINDRIFTPRF for run %d !",fRun));
420 result |= kEListFileDAQ;
423 if (filesourcesdaq->GetSize() != 1) {
424 Log(Form("More than one source found for PADSTATUSVDRIFT for run %d!",fRun));
425 filesourcesdaq->Print();
426 result |= kEListFileDAQ;
429 // Loop over the files taken from the DAQ
430 TIter iter(filesourcesdaq);
431 TObjString *sourcedaq;
432 while ((sourcedaq = dynamic_cast<TObjString *> (iter.Next()))) {
434 TString filenamedaq = GetFile(kDAQ,"PADSTATUSVDRIFT",sourcedaq->GetName());
435 if (filenamedaq.Length() == 0) {
436 Log(Form("Error retrieving file from source %d failed!", sourcedaq->GetName()));
437 result |= kEOpenFileDAQ;
442 TProfile2D *histodriftvelocity = 0x0; // Profile taken from DAQ for drift velocity and time0
443 AliTRDCalibPadStatus *calibpadstatus = 0x0; // AliTRDCalibPadStatus from DAQ for pad status
446 Bool_t something = kFALSE;
447 TFile *filedaq = TFile::Open(filenamedaq);
448 calibpadstatus = (AliTRDCalibPadStatus *) filedaq->Get("calibpadstatus");
449 if (!calibpadstatus) {
450 Log("No pedetral run!");
452 else something = kTRUE;
453 histodriftvelocity = (TProfile2D *) filedaq->Get("PH2d");
454 if (!histodriftvelocity) {
455 Log("No Vdrift TProfile2D!");
458 histodriftvelocity->SetDirectory(0);
460 if(histodriftvelocity) something = kTRUE;
462 Log("Error DAQ, nothing in the file!");
463 result |= kETakeObjectDAQ;
466 // try to fit and store reference data
468 calibpadstatus->AnalyseHisto();
469 if(!StoreReferenceData("DAQData","PadStatus",(TObject *) calibpadstatus,&metaData)){
470 Log("Error storing AliTRDCalibPadStatus object as reference data");
471 result |= kEStoreRefDAQ;
473 AliTRDCalPadStatus *calPadStatus = calibpadstatus->CreateCalPadStatus();
474 AliCDBMetaData *md3= new AliCDBMetaData();
475 md3->SetObjectClassName("AliTRDCalPadStatus");
476 md3->SetResponsible("Raphaelle Bailhache");
477 md3->SetBeamPeriod(1);
478 md3->SetComment("TRD calib test");
479 if(!Store("Calib","PadStatus" ,(TObject *)calPadStatus, md3, 0, kTRUE)){
480 Log("Error storing the calibration object for the chamber vdrift");
481 result |= kEStoreCalDAQ;
484 if (histodriftvelocity) {
485 if(!StoreReferenceData("DAQData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
486 Log("Error storing 2D Profile for average pulse height as reference data");
487 result |= kEStoreRefDAQ;
490 Log("Take the PH reference data. Now we will try to fit\n");
491 calibra->SetMinEntries(100*20); // If there is less than 2000
492 calibra->AnalysePH(histodriftvelocity);
493 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
494 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
495 Int_t nbfit = calibra->GetNumberFit();
496 Int_t nbE = calibra->GetNumberEnt();
498 (nbfit >= 0.95*nbE)) {
499 TObjArray object = calibra->GetVectorFit();
500 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
501 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
502 object = calibra->GetVectorFit2();
503 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
504 TObject *objtime0pad = calibra->CreatePadObjectT0();
505 calibra->ResetVectorFit();
506 if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,md1,0,kTRUE)){
507 Log("Error storing the calibration object for the chamber vdrift");
508 result |= kEStoreCalDAQ;
510 if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,md1,0,kTRUE)){
511 Log("Error storing the calibration object for the chamber t0");
512 result |= kEStoreCalDAQ;
514 if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,md2,0,kTRUE)){
515 Log("Error storing the calibration object for the local drift velocity");
516 result |= kEStoreCalDAQ;
518 if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,md2,0,kTRUE)){
519 Log("Error storing the calibration object for the local time0");
520 result |= kEStoreCalDAQ;
524 Log("Not enough statistics for the average pulse height");
525 result |= kEFitObjectDAQ;
531 } // while iter DAQ list
534 delete filesourcesdaq;