|
| 1 | +#include "CalibTimeSlewingParamTOF.h" |
| 2 | +#include "AliTOFCalibFineSlewing.h" |
| 3 | +#include "TFile.h" |
| 4 | +#include "TROOT.h" |
| 5 | +#include "AliCDBEntry.h" |
| 6 | +#include "TCanvas.h" |
| 7 | +#include "TGraph.h" |
| 8 | +#include "TTree.h" |
| 9 | +#include "TMath.h" |
| 10 | +#include "AliTOFChannelOffline.h" |
| 11 | +#include "TH1C.h" |
| 12 | + |
| 13 | +// macro to be run in *** AliRoot *** to convert the TOF OCDB entries in CCDB entries |
| 14 | +// How to run (see below for futher instructions): |
| 15 | +// gROOT->LoadMacro("CalibTimeSlewingParamTOF.cxx+") |
| 16 | +// .x ConvertRun2CalibrationToO2.C+ |
| 17 | + |
| 18 | +class MyFineTimeSlewing : public AliTOFCalibFineSlewing |
| 19 | +{ |
| 20 | + |
| 21 | +public: |
| 22 | + |
| 23 | + // class needed to access some data members of the AliTOFCalibFineSlewing class that are protected |
| 24 | + |
| 25 | + Int_t GetSize() {return fSize;} |
| 26 | + void GetChannelArrays(Int_t ich, Float_t* x, Float_t* y, Int_t& n) { |
| 27 | + n = fStart[ich+1] - fStart[ich]; |
| 28 | + if (ich == 157247) n = fSize - fStart[ich]; |
| 29 | + for (Int_t i = 0; i < n; i++){ |
| 30 | + x[i] = fX[fStart[ich] + i] * 0.001; // in the OCDB, we saves the tot in ps |
| 31 | + y[i] = fY[fStart[ich] + i] * 1.; // make it float |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + ClassDef(MyFineTimeSlewing, 1); |
| 36 | + |
| 37 | +}; |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +void ConvertRun2CalibrationToO2() { |
| 42 | + |
| 43 | + gROOT->LoadMacro("CalibTimeSlewingParamTOF.cxx+"); // actually you need to call this outside the macro, or it won't work |
| 44 | + // so you should first: |
| 45 | + // - copy |
| 46 | + // - DataFormats/Detectors/TOF/src/CalibTimeSlewingParamTOF.cxx |
| 47 | + // and |
| 48 | + // - DataFormats/Detectors/TOF/include/DataFormatsTOF/CalibTimeSlewingParamTOF.h |
| 49 | + // in the local working directory, substituting: |
| 50 | + // - #include "DataFormatsTOF/CalibTimeSlewingParamTOF.h" |
| 51 | + // with |
| 52 | + // - #include "CalibTimeSlewingParamTOF.h" |
| 53 | + // - then call: |
| 54 | + // - gROOT->LoadMacro("CalibTimeSlewingParamTOF.cxx+") |
| 55 | + // from the prompt |
| 56 | + |
| 57 | + o2::dataformats::CalibTimeSlewingParamTOF* mTimeSlewingObj = new o2::dataformats::CalibTimeSlewingParamTOF(); |
| 58 | + |
| 59 | + TFile* ffineSlewing = new TFile("TOF/Calib/FineSlewing/Run0_999999999_v2_s0.root"); |
| 60 | + AliCDBEntry* efineSlewing = (AliCDBEntry*)ffineSlewing->Get("AliCDBEntry"); |
| 61 | + AliTOFCalibFineSlewing* fs = (AliTOFCalibFineSlewing*)efineSlewing->GetObject(); |
| 62 | + TFile* foffset = new TFile("TOF/Calib/ParOffline/Run297624_999999999_v4_s0.root"); |
| 63 | + AliCDBEntry* eoffset = (AliCDBEntry*)foffset->Get("AliCDBEntry"); |
| 64 | + TObjArray* foff = (TObjArray*)eoffset->GetObject(); |
| 65 | + TFile *fproblematic = new TFile("TOF/Calib/Problematic/Run296631_999999999_v3_s0.root"); |
| 66 | + AliCDBEntry* eproblematic = (AliCDBEntry*)fproblematic->Get("AliCDBEntry"); |
| 67 | + TH1C* hProb = (TH1C*)eproblematic->GetObject(); |
| 68 | + |
| 69 | + MyFineTimeSlewing* mfs = (MyFineTimeSlewing*)fs; |
| 70 | + Printf("size = %d", mfs->GetSize()); |
| 71 | + |
| 72 | + |
| 73 | + Float_t x[10000]; |
| 74 | + Float_t y[10000]; |
| 75 | + |
| 76 | + Int_t n; |
| 77 | + |
| 78 | + for (Int_t i = 0; i < 157248; i++) { |
| 79 | + mfs->GetChannelArrays(i, x, y, n); |
| 80 | + //Printf("channel %d has %d entries", i, n); |
| 81 | + AliTOFChannelOffline* parOffline = (AliTOFChannelOffline*)foff->At(i); |
| 82 | + //Printf("channel %d has offset = %f", parOffline->GetSlewPar(0)); |
| 83 | + for (Int_t j = 0; j < n; j++) { |
| 84 | + Float_t corr = 0; |
| 85 | + for (Int_t islew = 0; islew < 6; islew++) |
| 86 | + corr += parOffline->GetSlewPar(islew) * TMath::Power(x[j], islew) * 1.e3; |
| 87 | + if(j==0 && x[j] > 0.03) mTimeSlewingObj->addTimeSlewingInfo(i, 0.025, y[j]+parOffline->GetSlewPar(0)); // force to have an entry for ToT=0 |
| 88 | + mTimeSlewingObj->addTimeSlewingInfo(i, x[j], y[j]+corr); |
| 89 | + } |
| 90 | + if(n==0) // force to have at least one entry |
| 91 | + mTimeSlewingObj->addTimeSlewingInfo(i, 0.025, parOffline->GetSlewPar(0)); |
| 92 | + |
| 93 | + // set problematics |
| 94 | + int sector = i/8736; |
| 95 | + int localchannel = i%8736; |
| 96 | + float fraction = float(hProb->GetBinContent(i)==0) - 0.01; // negative means problematic |
| 97 | + mTimeSlewingObj->setFractionUnderPeak(sector, localchannel, fraction); |
| 98 | + mTimeSlewingObj->setSigmaPeak(sector, localchannel, 100.); |
| 99 | + } |
| 100 | + |
| 101 | + TGraph* g = new TGraph(n, x, y); |
| 102 | + |
| 103 | + new TCanvas(); |
| 104 | + g->Draw("A*"); |
| 105 | + |
| 106 | + Printf("time slewing object has size = %d", mTimeSlewingObj->size()); |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | + TFile *fout = new TFile("outputCCDBfromOCDB.root","RECREATE"); |
| 111 | + TTree *t = new TTree("tree","tree"); |
| 112 | + t->Branch("CalibTimeSlewingParamTOF",&mTimeSlewingObj); |
| 113 | + t->Fill(); |
| 114 | + t->Write(); |
| 115 | + fout->Close(); |
| 116 | +} |
| 117 | + |
0 commit comments