18 #if !defined(__CINT__) || defined(__MAKECINT__) 20 #include "Riostream.h" 55 TString outputCDB =
"",
73 if ( outputCDB.IsNull() ){
87 AliMUONCDB::WriteToCDB(effMap,
"MUON/Calib/TriggerEfficiency", firstRun, lastRun,
"Measured efficiencies");
91 void ShowOCDBmap(Int_t
runNumber = 0, TString specificCDB=
"", TString ocdbPath =
"local://$ALICE_ROOT/OCDB", TString runType=
"Full")
99 if ( ocdbPath.BeginsWith(
"alien://") || ocdbPath.BeginsWith(
"raw://"))
100 TGrid::Connect(
"alien://");
102 if (!ocdbPath.CompareTo(
"MC"))
107 if ( !specificCDB.IsNull() )
121 for ( Int_t ibin=1; ibin<=histo->GetXaxis()->GetNbins(); ++ibin ) {
122 Double_t binCenter = histo->GetXaxis()->GetBinCenter(ibin);
123 for ( Int_t ievent=0; ievent<nevents; ++ievent ) {
124 histo->Fill(binCenter);
130 void BuildDefaultMap(TString outFilename=
"/tmp/defTrigChEff.root", Double_t globalValue = 1., Int_t nevents = 100000)
135 enum { kBendingEff, kNonBendingEff, kBothPlanesEff, kAllTracks, kNcounts};
136 TString countTypeName[kNcounts] = {
"bendPlane",
"nonBendPlane",
"bothPlanes",
"allTracks"};
138 const Char_t* yAxisTitle =
"counts";
140 const Int_t kNboards = 234;
141 const Int_t kFirstTrigCh = 11;
142 const Int_t kNchambers = 4;
143 const Int_t kNslats = 18;
145 Int_t chamberBins = kNchambers;
146 Float_t chamberLow = kFirstTrigCh-0.5, chamberHigh = kFirstTrigCh+kNchambers-0.5;
147 const Char_t* chamberName =
"chamber";
149 Int_t slatBins = kNslats;
150 Float_t slatLow = 0-0.5, slatHigh = kNslats-0.5;
151 const Char_t* slatName =
"slat";
153 Int_t boardBins = kNboards;
154 Float_t boardLow = 1-0.5, boardHigh = kNboards+1.-0.5;
155 const Char_t* boardName =
"board";
157 TString baseName, histoName, histoTitle;
158 TList* histoList =
new TList();
159 histoList->SetOwner();
163 for(Int_t icount=0; icount<kNcounts; icount++){
164 histoName = Form(
"%sCountChamber", countTypeName[icount].Data());
165 histo =
new TH1F(histoName, histoName,
166 chamberBins, chamberLow, chamberHigh);
167 histo->GetXaxis()->SetTitle(chamberName);
168 histo->GetYaxis()->SetTitle(yAxisTitle);
169 Double_t nfills = ( icount == kAllTracks ) ? nevents : globalValue * (Double_t)nevents;
171 histoList->AddLast(histo);
174 for(Int_t icount=0; icount<kNcounts; icount++){
175 for(Int_t ch=0; ch<kNchambers; ch++){
176 histoName = Form(
"%sCountSlatCh%i", countTypeName[icount].Data(), kFirstTrigCh+ch);
177 histo =
new TH1F(histoName, histoName,
178 slatBins, slatLow, slatHigh);
179 histo->GetXaxis()->SetTitle(slatName);
180 histo->GetYaxis()->SetTitle(yAxisTitle);
181 Double_t nfills = ( icount == kAllTracks ) ? nevents : globalValue * (Double_t)nevents;
183 histoList->AddLast(histo);
187 for(Int_t icount=0; icount<kNcounts; icount++){
188 for(Int_t ch=0; ch<kNchambers; ch++){
189 histoName = Form(
"%sCountBoardCh%i", countTypeName[icount].Data(), kFirstTrigCh+ch);
190 histo =
new TH1F(histoName, histoName,
191 boardBins, boardLow, boardHigh);
192 histo->GetXaxis()->SetTitle(boardName);
193 histo->GetYaxis()->SetTitle(yAxisTitle);
194 Double_t nfills = ( icount == kAllTracks ) ? nevents : globalValue * (Double_t)nevents;
196 histoList->AddLast(histo);
200 TFile* outFile =
TFile::Open(outFilename,
"create");
201 histoList->Write(
"triggerChamberEff",TObject::kSingleKey);
207 void BuildSystematicMap ( TString runList, Double_t globalSyst = -0.02, TString outputCDB =
"local://CDB", TString inputCDB =
"raw://", TString systematicPerBoard =
"" )
216 TArrayI runListArray(1000);
218 if ( gSystem->AccessPathName(runList.Data()) ) {
219 runList.ReplaceAll(
",",
" ");
221 TObjString* objStr = 0x0;
223 while ( (objStr = static_cast<TObjString*>(nextRun())) ) {
224 if ( objStr->String().IsDigit() ) runListArray[nruns++] = objStr->String().Atoi();
229 ifstream inRunList(runList.Data());
230 TString currLine =
"";
231 while ( ! inRunList.eof() ) {
232 currLine.ReadLine(inRunList);
233 currLine.ReplaceAll(
",",
" ");
235 TObjString* objStr = 0x0;
237 while ( (objStr = static_cast<TObjString*>(nextRun())) ) {
238 if ( objStr->String().IsDigit() ) runListArray[nruns++] = objStr->String().Atoi();
244 runListArray.Set(nruns);
251 for ( Int_t irun=0; irun<runListArray.GetSize(); irun++ ) {
252 mgr->
SetRun(runListArray[irun]);
255 if ( prevId && cdbId.
IsEqual(prevId) )
continue;
257 prevId =
static_cast<AliCDBId*
>(cdbId.Clone());
260 effMapsList.Add(
new TObjString(Form(
"%i_%i",cdbId.
GetFirstRun(),cdbId.
GetLastRun())),effMap->Clone());
266 Int_t nPoints = 234*4*3;
267 TArrayD systDiff(nPoints);
268 systDiff.Reset(globalSyst);
269 if ( ! systematicPerBoard.IsNull() && gSystem->AccessPathName(systematicPerBoard.Data()) == 0 ) {
271 TString currLine =
"";
272 ifstream inFile(systematicPerBoard.Data());
273 while ( ! inFile.eof() ) {
274 currLine.ReadLine(inFile);
276 if ( arr->GetEntries() >= 4 &&
static_cast<TObjString*
>(arr->UncheckedAt(0))->String().IsDigit() ) {
277 Int_t ich =
static_cast<TObjString*
>(arr->UncheckedAt(0))->String().Atoi()%11;
278 Int_t iboard =
static_cast<TObjString*
>(arr->UncheckedAt(1))->String().Atoi()-1;
279 Int_t icount =
static_cast<TObjString*
>(arr->UncheckedAt(2))->String().Atoi();
280 Double_t systErr =
static_cast<TObjString*
>(arr->UncheckedAt(3))->String().Atof();
281 Int_t idx = ich*234*3+iboard*3+icount;
282 if ( idx < nPoints ) systDiff[idx] = systErr;
290 for ( Int_t ich=0; ich<4; ich++ ) {
291 for ( Int_t iboard=0; iboard<234; iboard++ ) {
292 Int_t idx = ich*234*3+iboard*3;
293 Double_t diffBend = systDiff[idx];
294 Double_t diffNonBend = systDiff[idx+1];
295 systDiff[idx+2] = ( TMath::Abs(diffBend) > TMath::Abs(diffNonBend) ) ? diffBend : diffNonBend;
302 enum { kBendingEff, kNonBendingEff, kBothPlanesEff};
303 TString countTypeName[3] = {
"bendPlane",
"nonBendPlane",
"bothPlanes"};
305 TIter next(&effMapsList);
307 while ( ( key = next() ) ) {
308 TString runRange = key->GetName();
310 for ( Int_t ich=0; ich<4; ich++ ) {
311 TString histoName = Form(
"allTracksCountBoardCh%i", 11+ich);
312 TH1* auxHisto =
static_cast<TH1*
>(effMap->
GetHistoList()->FindObject(histoName));
313 for ( Int_t icount=0; icount<3; icount++ ) {
314 histoName = Form(
"%sCountBoardCh%i", countTypeName[icount].Data(), 11+ich);
315 TH1* histo =
static_cast<TH1*
>(effMap->
GetHistoList()->FindObject(histoName));
316 for ( Int_t iboard=0; iboard<234; iboard++ ) {
317 Int_t idx = ich*234*3+iboard*3+icount;
318 Int_t ibin = iboard+1;
319 Double_t countAll = auxHisto->GetBinContent(ibin);
320 Double_t countDiff = TMath::Nint(systDiff[idx] * countAll);
321 Double_t countOrig = histo->GetBinContent(ibin);
322 Double_t newCount = countOrig+countDiff;
323 if ( newCount < 0 || newCount > countAll ) {
324 printf(
"WARNING: ch %i board %i cath %i systDiff %g newEff %g / %g\n",11+ich,ibin,icount,systDiff[idx],newCount,countAll);
325 if ( newCount < 0 ) newCount = 0;
326 else newCount = countAll;
327 printf(
" => setting numerator to %g\n",newCount);
329 histo->SetBinContent(ibin,newCount);
330 if ( histo->GetSumw2N() > 0 ) histo->SetBinError(ibin,TMath::Sqrt(newCount));
335 Int_t firstRun =
static_cast<TObjString*
>(arr->UncheckedAt(0))->String().Atoi();
336 Int_t lastRun =
static_cast<TObjString*
>(arr->UncheckedAt(1))->String().Atoi();
337 AliMUONCDB::WriteToCDB(effMap,
"MUON/Calib/TriggerEfficiency", firstRun, lastRun,
"Measured efficiencies");
349 TList* histoList[2] = {0x0, 0x0};
350 TString filenames[2] = {effFileWithHoles, effFileCompatible};
351 for ( Int_t ifile=0; ifile<2; ifile++ ) {
352 TFile* file =
TFile::Open(filenames[ifile].Data());
354 printf(
"Fatal: cannot find %s\n", filenames[ifile].Data());
357 histoList[ifile] =
static_cast<TList*
> (file->FindObjectAny(
"triggerChamberEff"));
358 if ( ! histoList[ifile] ) {
359 printf(
"Cannot find histo list in file %s\n", filenames[ifile].Data());
364 TString detElemName[2] = {
"Slat",
"Board"};
365 enum { kBendingEff, kNonBendingEff, kBothPlanesEff, kAllTracks, kNcounts};
366 TString countTypeName[kNcounts] = {
"bendPlane",
"nonBendPlane",
"bothPlanes",
"allTracks"};
368 Bool_t isChanged = kFALSE;
369 TString histoName =
"";
370 for ( Int_t idet=0; idet<2; idet++ ) {
371 for ( Int_t ich=11; ich<=14; ich++ ) {
372 histoName = Form(
"%sCount%sCh%i", countTypeName[kAllTracks].Data(), detElemName[idet].Data(), ich);
373 TH1* allTracksHisto =
static_cast<TH1*
> (histoList[0]->FindObject(histoName.Data()));
374 for ( Int_t ibin=1; ibin<=allTracksHisto->GetXaxis()->GetNbins(); ibin++ ) {
375 if ( allTracksHisto->GetBinContent(ibin) > 0. )
continue;
377 printf(
"Modifying info for Ch %i %s %3i\n", ich, detElemName[idet].Data(), (Int_t)allTracksHisto->GetXaxis()->GetBinCenter(ibin));
382 Double_t nTracks = 0;
383 for ( Int_t jch=11; jch<=14; jch++ ) {
384 histoName = Form(
"%sCount%sCh%i", countTypeName[kAllTracks].Data(), detElemName[idet].Data(), jch);
385 TH1* allTracksOtherCh =
static_cast<TH1*
> (histoList[0]->FindObject(histoName.Data()));
386 nTracks = allTracksOtherCh->GetBinContent(ibin);
387 if ( nTracks > 0. ) {
393 histoName = Form(
"%sCount%sCh%i", countTypeName[kAllTracks].Data(), detElemName[idet].Data(), ich);
394 TH1* allTracksHistoAux =
static_cast<TH1*
> (histoList[1]->FindObject(histoName.Data()));
395 Double_t nTracksNew = allTracksHistoAux->GetBinContent(ibin);
396 if ( nTracksNew == 0.) {
397 printf(
"Warning: new histogram has no entries for Ch %i %s %3i\n", ich, detElemName[idet].Data(), (Int_t)allTracksHisto->GetXaxis()->GetBinCenter(ibin));
400 Double_t scaleFactor = TMath::Min(nTracksNew, nTracks) / nTracksNew;
403 for ( Int_t icount=0; icount<kNcounts; icount++ ) {
404 histoName = Form(
"%sCount%sCh%i", countTypeName[icount].Data(), detElemName[idet].Data(), ich);
405 TH1* auxHisto =
static_cast<TH1*
> (histoList[1]->FindObject(histoName.Data()));
406 TH1* histo =
static_cast<TH1*
> (histoList[0]->FindObject(histoName.Data()));
407 histo->SetBinContent(ibin, auxHisto->GetBinContent(ibin) * scaleFactor);
408 if ( histo->GetSumw2N() > 0 ) histo->SetBinError(ibin, auxHisto->GetBinError(ibin)*scaleFactor);
415 printf(
"Input histograms not modified\n");
418 TFile* outFile =
TFile::Open(outFilename,
"create");
419 histoList[0]->Write(
"triggerChamberEff",TObject::kSingleKey);
void ShowOCDBmap(Int_t runNumber=0, TString specificCDB="", TString ocdbPath="local://$ALICE_ROOT/OCDB", TString runType="Full")
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
TFile * Open(const char *filename, Long64_t &nevents)
void FillHisto(TH1 *histo, Int_t nevents)
TList * GetHistoList()
Get list of histograms.
Store and give access to the trigger chamber efficiency.
AliCDBEntry * Get(const AliCDBId &query, Bool_t forceCaching=kFALSE)
void SetSpecificStorage(const char *calibType, const char *dbString, Int_t version=-1, Int_t subVersion=-1)
virtual Bool_t IsEqual(const TObject *obj) const
void MUONTriggerChamberEfficiency(TString inputFile="./MUON.TriggerEfficiencyMap.root", TString outputCDB="", Int_t firstRun=0, Int_t lastRun=AliCDBRunRange::Infinity())
void CompleteEfficiency(TString effFileWithHoles, TString effFileCompatible, TString outFilename)
AliMUONTriggerEfficiencyCells * TriggerEfficiency() const
Get the trigger efficiency map.
void SetDefaultStorage(const char *dbString)
void DisplayEfficiency(Bool_t perSlat=kFALSE, Bool_t show2Dhisto=kTRUE)
void WriteToCDB(const char *calibpath, TObject *object, Int_t startRun, Int_t endRun, const char *filename)
Single entry point to access MUON calibration data.
void BuildDefaultMap(TString outFilename="/tmp/defTrigChEff.root", Double_t globalValue=1., Int_t nevents=100000)
Calculate, apply and possibly draw trigger chamber efficiency.
static AliCDBManager * Instance(TMap *entryCache=NULL, Int_t run=-1)
void BuildSystematicMap(TString runList, Double_t globalSyst=-0.02, TString outputCDB="local://CDB", TString inputCDB="raw://", TString systematicPerBoard="")
Int_t GetFirstRun() const