]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG/muondep/AliAnalysisTriggerScalers.cxx
- AddTask macro for fast embedding: making jet embedding possible with the lego train...
[u/mrichter/AliRoot.git] / PWG / muondep / AliAnalysisTriggerScalers.cxx
CommitLineData
2f331ac9 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 "AliAnalysisTriggerScalers.h"
19#include "AliCDBEntry.h"
20#include "AliCDBManager.h"
21#include "AliGRPObject.h"
22#include "AliLog.h"
23#include "AliTimeStamp.h"
24#include "AliTriggerBCMask.h"
25#include "AliTriggerClass.h"
26#include "AliTriggerCluster.h"
27#include "AliTriggerConfiguration.h"
28#include "AliTriggerDescriptor.h"
29#include "AliTriggerInput.h"
30#include "AliTriggerRunScalers.h"
31#include "AliTriggerScalers.h"
32#include "AliTriggerScalersESD.h"
33#include "AliTriggerScalersRecord.h"
34#include "Riostream.h"
35#include "TDatime.h"
36#include "TError.h"
37#include "TGraph.h"
acbe06d5 38#include "TGraphErrors.h"
c665b011 39#include "TH2.h"
2f331ac9 40#include "TObjArray.h"
41#include "TObjString.h"
42#include <set>
43#include <map>
44#include "TStyle.h"
45#include "AliLHCData.h"
46#include "TMath.h"
47#include "TAxis.h"
48#include "TCanvas.h"
49
50ClassImp(AliAnalysisTriggerScalers)
51
52namespace {
53
54 //______________________________________________________________________________
55 UChar_t GetIndex(ULong64_t mask)
56 {
57 for ( Int_t i = 0; i < 64; ++i )
58 {
59 if ( mask & ( 1ull << i ) ) return i+1;
60 }
61 return 0;
62 }
63
64
65 //______________________________________________________________________________
66 Double_t Mu(Double_t L0B, Double_t Nb)
67 {
68 /// L0B = trigger rate before any veto
69 /// Nb = number of crossing bunches
70
71 Double_t p0 = 1-L0B/(Nb*11245.0); // proba to get *no* collision per bunch crossing
72
73 return -TMath::Log(p0);
74 }
75
76 //______________________________________________________________________________
77 TCanvas* NewCanvas(const char* name)
78 {
79 TCanvas* c = new TCanvas(name,name);
80 c->SetLeftMargin(0.15);
81 return c;
82 }
83
84 //______________________________________________________________________________
85 void TimeAxis(TGraph* g)
86 {
87// g->GetXaxis()->SetTimeDisplay(1);
88// g->GetXaxis()->SetTimeFormat("%d/%m %H:%M%F2010-12-31 24:00:00");
89// g->GetXaxis()->SetNdivisions(505);
90 g->GetYaxis()->SetTitleOffset(1.5);
91
92 g->GetXaxis()->SetTimeDisplay(1);
93 // g->GetXaxis()->SetTimeFormat("%d/%m %H:%M%F2010-12-31 24:00:00");
94 g->GetXaxis()->SetTimeFormat("%d/%m %H:%M");
95 g->GetXaxis()->SetTimeOffset(0,"gmt");
96 g->GetXaxis()->SetNdivisions(505);
97
98 }
99
100}
101
102//_____________________________________________________________________________
103AliAnalysisTriggerScalers::AliAnalysisTriggerScalers(Int_t runNumber, const char* ocdbPath) : fRunList(), fVerbose(0), fOCDBPath(ocdbPath)
104{
105 // ctor using a single run number
106 SetRunList(runNumber);
107}
108
109//_____________________________________________________________________________
110AliAnalysisTriggerScalers::AliAnalysisTriggerScalers(const char* runlist, const char* ocdbPath) : fRunList(), fVerbose(0), fOCDBPath(ocdbPath)
111{
112 // ctor from a run list (txt file)
113 SetRunList(runlist);
114}
115
116//_____________________________________________________________________________
117AliAnalysisTriggerScalers::~AliAnalysisTriggerScalers()
118{
119}
120
c665b011 121//______________________________________________________________________________
122Int_t AliAnalysisTriggerScalers::GetFillNumberFromRunNumber(Int_t runNumber)
123{
124 /// Get the fill number of a run
125
126 AliLHCData* lhcData = static_cast<AliLHCData*>(GetOCDBObject("GRP/GRP/LHCData",runNumber));
127 if (lhcData)
128 {
129 Int_t fillNumber = lhcData->GetFillNumber();
130 if ( fillNumber == 0 && runNumber == 189694)
131 {
132 // manual hack because GRP info incorrect for this run ?
133 fillNumber = 3135;
134 }
135
136 return fillNumber;
137 }
138 return -1;
139}
140
2f331ac9 141//______________________________________________________________________________
142TObject* AliAnalysisTriggerScalers::GetOCDBObject(const char* path, Int_t runNumber)
143{
144 if ( !AliCDBManager::Instance()->IsDefaultStorageSet() )
145 {
146 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
147 }
148
149 AliCDBManager::Instance()->SetRun(runNumber);
150
151 gErrorIgnoreLevel=kWarning; // to avoid all the TAlienFile::Open messages...
152
153 AliCDBEntry* e = AliCDBManager::Instance()->Get(path);
154 return e ? e->GetObject() : 0x0;
155}
156
157
158//______________________________________________________________________________
159Int_t AliAnalysisTriggerScalers::GetTriggerInput(Int_t runNumber, const char* inputname)
160{
161 AliTriggerConfiguration* tc = static_cast<AliTriggerConfiguration*>(GetOCDBObject("GRP/CTP/Config",runNumber));
162 if (!tc) return -1;
163
164 const TObjArray& inputs = tc->GetInputs();
165
166 AliTriggerInput* ti = static_cast<AliTriggerInput*>(inputs.FindObject(inputname));
167
168 if (!ti) return -1;
169
170 return ti->GetSignature();
171}
172
173//______________________________________________________________________________
174AliAnalysisTriggerScalerItem*
175AliAnalysisTriggerScalers::GetTriggerScaler(Int_t runNumber, const char* level, const char* triggerClassName)
176{
177 // Get the scaler for a given trigger class and a given trigger level.
178 // Returned object must be deleted by the user.
179
180 AliTriggerConfiguration* tc = static_cast<AliTriggerConfiguration*>(GetOCDBObject("GRP/CTP/Config",runNumber));
181 AliTriggerRunScalers* trs = static_cast<AliTriggerRunScalers*>(GetOCDBObject("GRP/CTP/Scalers",runNumber));
182 AliGRPObject* grp = static_cast<AliGRPObject*>(GetOCDBObject("GRP/GRP/Data",runNumber));
183
184 TString diCurrent(Form("L3:%5.0f;DIP:%5.0f [L3:%d;DIP:%d]",
185 grp->GetL3Current((AliGRPObject::Stats)0),
186 grp->GetDipoleCurrent((AliGRPObject::Stats)0),
187 grp->GetL3Polarity(),
188 grp->GetDipolePolarity()));
189
190 if (!tc || !trs || !grp) return 0x0;
191
192 time_t duration = grp->GetTimeEnd() - grp->GetTimeStart();
193
194 const TObjArray& trClasses = tc->GetClasses();
195
196 const TObjArray* scalers = trs->GetScalersRecords();
197 const AliTriggerScalersRecord* begin = (AliTriggerScalersRecord*)(scalers->First());
198 const AliTriggerScalersRecord* end = (AliTriggerScalersRecord*)(scalers->Last());
199
200 AliTriggerClass* triggerClass = static_cast<AliTriggerClass*>(trClasses.FindObject(triggerClassName));
201 if (!triggerClass)
202 {
203 return 0x0;
204 }
205 UChar_t index = GetIndex(triggerClass->GetMask());
206
207 ULong64_t value(0);
208
209 const AliTriggerScalers* sbegin = begin->GetTriggerScalersForClass(index);
210 const AliTriggerScalers* send = end->GetTriggerScalersForClass(index);
211
212 TString swhat(level);
213 swhat.ToUpper();
214
215 if ( swhat.BeginsWith("L0A") )
216 {
217 value = send->GetLOCA() - sbegin->GetLOCA();
218 }
219 else if ( swhat.BeginsWith("L0B") )
220 {
221 value = send->GetLOCB() - sbegin->GetLOCB();
222 }
223 else if ( swhat.BeginsWith("L1A") )
224 {
225 value = send->GetL1CA() - sbegin->GetL1CA();
226 }
227 else if ( swhat.BeginsWith("L1B") )
228 {
229 value = send->GetL1CB() - sbegin->GetL1CB();
230 }
231 else if ( swhat.BeginsWith("L2A") )
232 {
233 value = send->GetL2CA() - sbegin->GetL2CA();
234 }
235 else if ( swhat.BeginsWith("L2B") )
236 {
237 value = send->GetL2CB() - sbegin->GetL2CB();
238 }
239
240 Int_t ds(1);
241
242 // FIXME: get the downscaling factor here for all cases (only BC1 supported here so far)
243 if ( TString(triggerClassName).Contains("_B1") )
244 {
245 ds = GetTriggerInput(runNumber,"BC1");
246 if (!ds) ds=1;
247 }
248
249 swhat.ReplaceAll("RATE","");
250
251 return new AliAnalysisTriggerScalerItem(runNumber,swhat.Data(),diCurrent.Data(),triggerClass->GetName(),value,triggerClass->GetBCMask(),ds,duration);
252}
253
254//______________________________________________________________________________
c665b011 255void AliAnalysisTriggerScalers::IntegratedLuminosity(const char* triggerList,
256 const char* lumiTrigger,
257 Double_t lumiCrossSection,
258 const char* csvOutputFile,
259 const char sep)
2f331ac9 260{
c665b011 261 // Compute the luminosity for a set of triggers
262
263 // for T0 based lumi (end of pp 2012), use lumiTrigger = C0TVX-S-NOPF-ALLNOTRD and lumiCrossSection = 28 mb
264 // for V0 base lumi (pp) use lumiTrigger = CVBAND-S-NOPF-ALLNOTRD and lumiCrossSection = 55 mb
265 //
2f331ac9 266
267 double intLumi(0);
268
c665b011 269 std::map<std::string,float> lumiPerTrigger;
270 std::map<int, std::map<std::string,float> > lumiPerFillPerTrigger;
271
272 std::map<std::string,time_t> durationPerTrigger;
273
274 TString sTriggerList(triggerList);
275
276 if ( sTriggerList.Length()==0 )
277 {
278 sTriggerList = "CMUL8-S-NOPF-ALLNOTRD,CMUL7-S-NOPF-ALLNOTRD,CMUL8-S-NOPF-MUON,CMUL7-S-NOPF-MUON";
2f331ac9 279
c665b011 280 // for C0MUL-SC-NOPF-MUON must use C0TVX-SC as lumiTrigger (with same cross-section as C0TVX=28mb)
281 }
282
283 TObjArray* triggerArray = sTriggerList.Tokenize(",");
284 triggerArray->SetOwner(kTRUE);
285
286 std::ofstream* out(0x0);
287
288 if ( TString(csvOutputFile).Length() > 0 )
289 {
290 out = new std::ofstream(gSystem->ExpandPathName(csvOutputFile));
291 if (!out || out->bad())
292 {
293 delete out;
294 out = 0x0;
295 }
296 }
2f331ac9 297
c665b011 298 TIter nextTrigger(triggerArray);
299 TObjString* trigger;
2f331ac9 300
c665b011 301 if (out)
302 {
303 (*out) << "Fill number" << sep;
304
305 nextTrigger.Reset();
306
307 std::map<std::string,float>::const_iterator it;
308
309 while ( ( trigger = static_cast<TObjString*>(nextTrigger())))
2f331ac9 310 {
c665b011 311 lumiPerTrigger[trigger->String().Data()] = 0;
312 }
313
314 for ( it = lumiPerTrigger.begin(); it != lumiPerTrigger.end(); ++it )
315 {
316 (*out) << "lumi from " << it->first.c_str() << sep;
317 }
2f331ac9 318
c665b011 319 (*out) << "comments" << sep;
320
321 for ( it = lumiPerTrigger.begin(); it != lumiPerTrigger.end(); ++it )
322 {
323 (*out) << "recorded " << it->first.c_str() << " (integrated)" << sep;
324 }
2f331ac9 325
c665b011 326 (*out) << "LHC delivered (nb^-1) per fill " << sep << "LHC delivered (nb^-1 integrated)" << sep;
327 (*out) << "lumi tot muon" << sep << "eff (%)" << sep;
328 (*out) << std::endl;
329
330 nextTrigger.Reset();
331 }
332
333 Int_t currentFillNumber(-1);
334 Int_t fillNumber(0);
335
336 for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
337 {
338 Int_t runNumber = fRunList[i];
339 Bool_t atLeastOneTriggerFound(kFALSE);
340
341 // find out which trigger classes to use
342
343 AliTriggerConfiguration* tc = static_cast<AliTriggerConfiguration*>(GetOCDBObject("GRP/CTP/Config",runNumber));
344 const TObjArray& trClasses = tc->GetClasses();
345
346 if (out)
347 {
348 fillNumber = GetFillNumberFromRunNumber(runNumber);
349 if ( fillNumber == 0 )
350 {
351 AliError(Form("Got fillNumber = 0 for run %09d !",runNumber));
352 }
2f331ac9 353
c665b011 354 if ( fillNumber != currentFillNumber )
2f331ac9 355 {
c665b011 356 std::map<std::string,float>::const_iterator it;
2f331ac9 357
c665b011 358 for ( it = lumiPerTrigger.begin(); it != lumiPerTrigger.end(); ++it )
2f331ac9 359 {
c665b011 360 lumiPerFillPerTrigger[fillNumber][it->first.c_str()] = 0;
2f331ac9 361 }
c665b011 362 currentFillNumber = fillNumber;
363 }
364 }
2f331ac9 365
c665b011 366 AliGRPObject* grp = static_cast<AliGRPObject*>(GetOCDBObject("GRP/GRP/Data",runNumber));
367 time_t duration = grp->GetTimeEnd() - grp->GetTimeStart();
368
369 nextTrigger.Reset();
2f331ac9 370
c665b011 371 while ( ( trigger = static_cast<TObjString*>(nextTrigger()) ) )
372 {
373 TString lumiTriggerClassName(lumiTrigger);
374 TString muTriggerClassName(trigger->String());
375 Int_t n(0);
376 float lumiSigma = lumiCrossSection*1E6; //nb
377
378 if ( !trClasses.FindObject(muTriggerClassName.Data() ) )
379 {
380 continue;
381 }
382
383 if ( muTriggerClassName.Contains("CMUL8") ) ++n;
384 if ( muTriggerClassName.Contains("CMUL7") ) ++n;
385
386 if ( n>1 )
387 {
388 AliError(Form("More than 1 relevant trigger class found for run %09d ! Check that !",runNumber));
389 trClasses.Print();
390 continue;
391 }
392
393 AliAnalysisTriggerScalerItem* lumiB = GetTriggerScaler(runNumber,"L0B",lumiTriggerClassName.Data());
394 AliAnalysisTriggerScalerItem* muonA = GetTriggerScaler(runNumber,"L0A",muTriggerClassName.Data());
395 AliAnalysisTriggerScalerItem* muonB = GetTriggerScaler(runNumber,"L0B",muTriggerClassName.Data());
396
397 if (!lumiB)
398 {
399 AliError(Form("Did not find lumiTrigger %s for run %09d",lumiTriggerClassName.Data(),runNumber));
400 continue;
401 }
402
403 if (!lumiB || !muonA || !muonB) continue;
404
405 atLeastOneTriggerFound = kTRUE;
406
407 Float_t ratio(0);
408
409 if ( muonB->ValueCorrectedForDownscale() > 0 )
410 {
411 ratio = muonA->ValueCorrectedForDownscale()/muonB->ValueCorrectedForDownscale();
412 }
413
414 ratio *= lumiB->ValueCorrectedForDownscale()/lumiSigma;
415
416 if ( muTriggerClassName.BeginsWith("CMUL"))
417 {
418 intLumi += ratio;
2f331ac9 419 }
c665b011 420
421 lumiPerTrigger[muTriggerClassName.Data()] += ratio;
422 durationPerTrigger[muTriggerClassName.Data()] += duration;
423 lumiPerFillPerTrigger[currentFillNumber][muTriggerClassName.Data()] += ratio;
424
425 }
426
427 if (!atLeastOneTriggerFound && sTriggerList.Contains("CMUL") )
428 {
429 AliError(Form("Found no relevant trigger for run %09d",runNumber));
2f331ac9 430 }
c665b011 431 }
432
433 AliInfo(Form("Integrated lumi %7.4f nb^-1",intLumi));
434
435 std::map<std::string,float>::const_iterator it;
436
437 for ( it = lumiPerTrigger.begin(); it != lumiPerTrigger.end(); ++it )
438 {
439 AliInfo(Form("Trigger %30s Lumi %10.4f nb^-1 duration %10ld s",it->first.c_str(),it->second,durationPerTrigger[it->first]));
440 }
2f331ac9 441
c665b011 442 if (out)
443 {
444 std::map<int, std::map<std::string, float> >::const_iterator fit;
2f331ac9 445
c665b011 446 lumiPerTrigger.clear();
2f331ac9 447
c665b011 448 for ( fit = lumiPerFillPerTrigger.begin(); fit != lumiPerFillPerTrigger.end(); ++fit )
2f331ac9 449 {
c665b011 450 int fill = fit->first;
451 std::map<std::string,float>::const_iterator tit;
452 (*out) << fill << sep;
453
454 for ( tit = fit->second.begin(); tit != fit->second.end(); ++tit )
455 {
456 (*out) << Form("%e",tit->second) << sep;
457 }
458
459 (*out) << sep; // comment (empty)
460
461 for ( tit = fit->second.begin(); tit != fit->second.end(); ++tit )
462 {
463 lumiPerTrigger[tit->first] += tit->second;
464
465 (*out) << Form("%e",lumiPerTrigger[tit->first]) << sep;
466 }
467 (*out) << sep << "0" << sep << "0" << sep << "0" << sep << "0" << sep << std::endl; // LHC per fill, LHC integrated, lumi tot muon , efficiency
2f331ac9 468 }
c665b011 469 }
09d5920f 470 //
471 delete triggerArray;
2f331ac9 472}
473
474//______________________________________________________________________________
475TGraph* AliAnalysisTriggerScalers::PlotTriggerEvolution(const char* triggerClassName,
476 const char* what,
477 bool draw,
478 double* mean)
479{
480 /// Make a graph of "what" for a given trigger class.
481 ///
482 /// What can be :
483 ///
484 /// - L0B (level 0 before any veto applied)
485 /// - L0A (level 0 after all vetoes)
486 /// - L0AOVERB (L0A/L0B)
487 /// - mu ( = -TMath::Log( 1 - P(0) ) where P(0) is the proba to have zero collisions in a bunch crossing)
488 /// - pileupfactor = mu/(1-exp(-mu)) : the factor to apply to correct the cint1b count rate
489 /// - vsnb = L0B/(NumberOfInteractingBunches*11245)
490
c665b011 491 TString swhat(what);
492 swhat.ToUpper();
493
494 if ( swhat.Contains(";"))
495 {
496 swhat.ReplaceAll(";",",");
497 AliWarningClass("; is not a valid separator, replaced it with ,");
498 }
499
500 int color(1);
501 int marker(20);
502
503 TObjArray* a = swhat.Tokenize(",");
504 if (a->GetEntries()>1)
505 {
506 TObjArray graphs;
507 TIter next(a);
508 TObjString* str(0x0);
509 Double_t ymin(TMath::Limits<Double_t>::Max());
510 Double_t ymax(0);
511 Double_t xmin(TMath::Limits<Double_t>::Max());
512 Double_t xmax(0);
513 TGraph* g(0x0);
514
515 while ( ( str = static_cast<TObjString*>(next())) )
516 {
517 g = PlotTriggerEvolution(triggerClassName,str->String().Data(),false);
518 graphs.Add(g);
519 for ( Int_t i = 0; i < g->GetN(); ++i )
520 {
521 ymin = TMath::Min(ymin,g->GetY()[i]);
522 ymax = TMath::Max(ymax,g->GetY()[i]);
523 }
524 xmin = TMath::Min(xmin,g->GetX()[0]);
525 xmax = TMath::Max(xmax,g->GetX()[g->GetN()-1]);
526 }
527
528 gStyle->SetOptTitle(0);
529
530 AliInfoClass(Form("x %e ; %e y %e ; %e",xmin,xmax,ymin,ymax));
531 TH2* h = new TH2F("h",triggerClassName,100,xmin,xmax,100,ymin,ymax);
532 h->SetStats(kFALSE);
533 h->GetXaxis()->SetTimeDisplay(1);
534 h->GetXaxis()->SetTimeFormat("%d/%m %H:%M");
535 h->GetXaxis()->SetTimeOffset(0,"gmt");
536 h->GetXaxis()->SetNdivisions(505);
537 h->Draw();
538
539 TIter nextGraph(&graphs);
540
541 while ( ( g = static_cast<TGraph*>(nextGraph())) )
542 {
543 AliInfoClass(g->GetTitle());
544 g->Draw("lp");
545 g->SetLineColor(color);
546 g->SetMarkerColor(color);
547 g->SetMarkerStyle(marker);
548 ++color;
549 ++marker;
550 }
09d5920f 551 delete a;
c665b011 552 return 0x0;
553 }
09d5920f 554 delete a;
555
2f331ac9 556 std::vector<int> vx;
557 std::vector<int> vex;
558 std::vector<double> vy;
559 std::vector<double> vey;
560
2f331ac9 561
562 if (mean) *mean=0;
563 double nvalues(0);
564
565
566 for ( std::vector<int>::size_type iRun = 0; iRun < fRunList.size(); ++iRun )
567 {
568 Int_t runNumber = fRunList[iRun];
569
570 AliTriggerConfiguration* tc = static_cast<AliTriggerConfiguration*>(GetOCDBObject("GRP/CTP/Config",runNumber));
571 AliTriggerRunScalers* trs = static_cast<AliTriggerRunScalers*>(GetOCDBObject("GRP/CTP/Scalers",runNumber));
572
573 AliLHCData* lhc = static_cast<AliLHCData*>(GetOCDBObject("GRP/GRP/LHCData",runNumber));
574
575 Int_t NumberOfInteractingBunches(0);
576 Int_t NumberOfInteractingBunchesMeasured(0);
577 Int_t NIBM2(0);
578
579 int beam1(0);
580 int beam2(1);
581
582 AliLHCDipValI* val = lhc->GetBunchConfigDeclared(beam1,0);
583
584 for ( Int_t i = 0; i < val->GetSizeTotal(); ++i )
585 {
586 if ( val->GetValue(i) < 0 ) ++NumberOfInteractingBunches;
587 }
588
589 AliLHCDipValI* valm = lhc->GetBunchConfigMeasured(beam1,0);
590
591 for ( Int_t i = 0; i < valm->GetSizeTotal(); ++i )
592 {
593 if ( valm->GetValue(i) < 0 ) ++NumberOfInteractingBunchesMeasured;
594 }
595
596 valm = lhc->GetBunchConfigMeasured(beam2,0);
597
598 for ( Int_t i = 0; i < valm->GetSizeTotal(); ++i )
599 {
600 if ( valm->GetValue(i) <= 0 ) ++NIBM2;
601 }
602
603 AliInfo(Form("RUN %09d NumberOfInteractingBunches=%3d NumberOfInteractingBunchesMeasured=%3d NIBM2=%3d",
604 runNumber,NumberOfInteractingBunches,NumberOfInteractingBunchesMeasured,NIBM2));
605
606// if ( NumberOfInteractingBunches <= 0 )
607// {
608// AliInfo(Form("RUN %09d NumberOfInteractingBunches=%3d !!!!",runNumber,NumberOfInteractingBunches));
609// return 0x0;
610// }
611
612 const TObjArray* scalers = trs->GetScalersRecords();
613
614 const TObjArray& trClasses = tc->GetClasses();
615 TIter next(&trClasses);
616 AliTriggerClass* triggerClass;
617
618 while ( ( triggerClass = static_cast<AliTriggerClass*>(next()) ) )
619 {
620 UChar_t index = GetIndex(triggerClass->GetMask());
621
622 if ( !TString(triggerClass->GetName()).Contains(triggerClassName) ) continue;
623
624 TIter nextScaler(scalers);
625 AliTriggerScalersRecord* record;
626 UInt_t reft(0);
627 UInt_t refl0b(0);
628 UInt_t refl1b(0);
629 UInt_t refl2b(0);
630 UInt_t refl0a(0);
631 UInt_t refl1a(0);
632 UInt_t refl2a(0);
633 Bool_t first(kTRUE);
634
635 while ( ( record = static_cast<AliTriggerScalersRecord*>(nextScaler()) ) )
636 {
637 const AliTriggerScalers* scaler = record->GetTriggerScalersForClass(index);
638
639 const AliTimeStamp* ats = record->GetTimeStamp();
640
641 UInt_t seconds = ats->GetSeconds();// - TTimeStamp::GetZoneOffset();
642
643 TTimeStamp ts(seconds,ats->GetMicroSecs());
644
645 UInt_t l0b = scaler->GetLOCB() - refl0b;
646 UInt_t l0a = scaler->GetLOCA() - refl0a;
647 UInt_t l1b = scaler->GetL1CB() - refl1b;
648 UInt_t l1a = scaler->GetL1CA() - refl1a;
649 UInt_t l2b = scaler->GetL2CB() - refl2b;
650 UInt_t l2a = scaler->GetL2CA() - refl2a;
651 UInt_t timelapse = seconds - reft;
652
653 if ( l0b <= 2 || ( l0a <= 2 && l0a != 0 ) || timelapse <= 9 ) continue;
654
655 reft = seconds;
656 refl0b = scaler->GetLOCB();
657 refl0a = scaler->GetLOCA();
658 refl1b = scaler->GetL1CB();
659 refl1a = scaler->GetL1CA();
660 refl2b = scaler->GetL2CB();
661 refl2a = scaler->GetL2CA();
662
663 if ( first )
664 {
665 first = kFALSE;
666 continue;
667 }
668
669 double value(1.0);
670
671 if (swhat.Contains("L0AOVERB") )
672 {
673 value = l0a*1.0/l0b;
674 }
675 else if ( swhat.Contains("L0B") )
676 {
677 value = l0b;
678 }
679 else if (swhat.Contains("L0A") )
680 {
681 value = l0a;
682 }
683 else if ( swhat.Contains("L1B") )
684 {
685 value = l1b;
686 }
687 else if (swhat.Contains("L1A") )
688 {
689 value = l1a;
690 }
691 else if ( swhat.Contains("L2B") )
692 {
693 value = l2b;
694 }
695 else if (swhat.Contains("L2A") )
696 {
697 value = l2a;
698 }
699 else if ( swhat.Contains("MU") )
700 {
701 value = Mu(l0b/timelapse,NumberOfInteractingBunches);
702 }
703 else if ( swhat.Contains("PILEUPFACTOR") )
704 {
705 Double_t mu = Mu(l0b/timelapse,NumberOfInteractingBunches);
706 value = mu/(1-TMath::Exp(-mu));
707 }
708 else if ( swhat.Contains("VSNB") )
709 {
710 value = l0b/(11245.0*NumberOfInteractingBunches);
711 }
712 else
713 {
714 value = timelapse;
715 AliInfo(Form("Unknown what %s",what));
716 }
717
718 if ( ! swhat.Contains("OVER") && ! swhat.Contains("RATIO") &&
c665b011 719 ! swhat.Contains("MU") && ! swhat.Contains("PILEUPFACTOR") &&
720 ! swhat.Contains("RAW") )
2f331ac9 721 {
722 value /= timelapse;
723 }
724
725 if ( !TMath::Finite(value) ) continue;
726
727 if (mean)
728 {
729 (*mean) += value;
730 ++nvalues;
731 }
732
733 vx.push_back(seconds);
734 vex.push_back(1);
735
736 vy.push_back(value);
737
738 vey.push_back(1);
739
740 }
741 }
742
743 if (mean && nvalues)
744 {
745 (*mean) /= nvalues;
746 }
747
2f331ac9 748 }
c665b011 749
750 if ( vx.empty() ) return 0;
2f331ac9 751
752 TGraph* g = MakeGraph(vx,vex,vy,vey);
753 TString title(Form("TriggerEvolution%s-%s",triggerClassName,swhat.Data()));
754
755 g->SetName(title.Data());
756 g->SetTitle(title.Data());
757
758 g->GetYaxis()->SetTitle(title.Data());
759
760 if (draw)
761 {
762 NewCanvas(g->GetName());
c665b011 763 g->SetLineColor(color);
764 g->SetMarkerColor(color);
765 g->SetMarkerStyle(marker);
766 g->Draw("ALP");
2f331ac9 767 g->SaveAs(Form("%s.pdf",title.Data()));
768 }
769
770
771 return g;
772}
773
774//______________________________________________________________________________
775TGraph* AliAnalysisTriggerScalers::MakeGraph(const std::vector<int>& vx,
776 const std::vector<int>& vex,
777 const std::vector<double>& vy,
778 const std::vector<double>& vey)
779{
780 if ( ! ( vx.size() == vex.size() && vx.size() == vy.size() && vx.size() == vey.size() ) )
781 {
782 std::cerr << "incompatible sizes" << std::endl;
783 return 0x0;
784 }
785
786 double* x = new double[vx.size()];
787 double* ex = new double[vx.size()];
788 double* y = new double[vx.size()];
789 double* ey = new double[vx.size()];
790
791 for ( size_t i = 0; i < vx.size(); ++i )
792 {
793 x[i] = vx[i];
794 ex[i] = vex[i];
795 y[i] = vy[i];
796 ey[i] = vey[i];
797 }
798
acbe06d5 799 TGraph* g = new TGraphErrors(vx.size(),x,y,ex,ey);
2f331ac9 800
801 TimeAxis(g);
802
acbe06d5 803 delete[] x;
804 delete[] y;
805 delete[] ex;
806 delete[] ey;
807
2f331ac9 808 return g;
809}
810
811//______________________________________________________________________________
812TGraph* AliAnalysisTriggerScalers::PlotTrigger(const char* triggerClassName,
813 const char* what)
814{
815 std::vector<Float_t> x;
816 std::vector<Float_t> y;
817
818 double integral(0);
819 double mean(0);
820
821 for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
822 {
823 Int_t runNumber = fRunList[i];
824
825 AliAnalysisTriggerScalerItem* s = GetTriggerScaler(runNumber,what,triggerClassName);
826
827 if (!s) continue;
828
829 x.push_back(runNumber);
830
831 Double_t value = s->ValueCorrectedForDownscale();
832
833 if ( TString(what).Contains("RATE") )
834 {
835 value = s->Rate();
836 }
837
838 integral += value;
839
840 y.push_back(value);
841 }
842
843 if ( fRunList.size() ) {
844 mean /= fRunList.size();
845 }
846
847 AliInfo(Form("Integral %e mean %e",integral,mean));
848
849 return new TGraph(x.size(),&x[0],&y[0]);
850}
851
852//______________________________________________________________________________
853TGraph* AliAnalysisTriggerScalers::PlotTriggerRatio(const char* triggerClassName1,
854 const char* what1,
855 const char* triggerClassName2,
856 const char* what2)
857{
858 std::vector<Float_t> x;
859 std::vector<Float_t> y;
860
861 for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
862 {
863 Int_t runNumber = fRunList[i];
864
865 AliAnalysisTriggerScalerItem* s1 = GetTriggerScaler(runNumber,what1,triggerClassName1);
866 AliAnalysisTriggerScalerItem* s2 = GetTriggerScaler(runNumber,what2,triggerClassName2);
867
868 if (!s1 || !s2) continue;
869
870 x.push_back(runNumber);
871
872 Float_t ratio(0);
873
874 if ( s2->ValueCorrectedForDownscale() > 0 )
875 {
876 ratio = s1->ValueCorrectedForDownscale()/s2->ValueCorrectedForDownscale();
877 }
878
879 y.push_back(ratio);
880
881 if ( fVerbose )
882 {
883 AliInfo(Form("RUN %09d %20s (%s) %12llu (%5d) %20s (%s) %12llu (%5d) R %7.2f",
884 runNumber,
885 triggerClassName1,what1,
886 s1->Value(),s1->DownscalingFactor(),
887 triggerClassName2,what2,
888 s2->Value(),s2->DownscalingFactor(),
889 ratio));
890 }
891 }
892
893 return new TGraph(x.size(),&x[0],&y[0]);
894}
895
896//______________________________________________________________________________
c665b011 897void AliAnalysisTriggerScalers::Print(Option_t* /* opt */) const
898{
899 /// print our runlist
900 AliAnalysisTriggerScalers::PrintIntegers(fRunList,',');
901}
902
903//______________________________________________________________________________
904void AliAnalysisTriggerScalers::PrintIntegers(const std::vector<int>& integers,
2f331ac9 905 const char sep,
906 std::ostream& out)
907{
908 /// print a list of integers
909 for ( std::vector<int>::size_type i = 0; i < integers.size(); ++i )
910 {
911 out << integers[i] << sep;
912 }
913 out << std::endl;
914}
915
916//______________________________________________________________________________
917void AliAnalysisTriggerScalers::ReadIntegers(const char* filename,
918 std::vector<int>& integers,
919 Bool_t resetVector)
920{
921 /// Read integers from filename, where integers are either
922 /// separated by "," or by return carriage
923 std::ifstream in(gSystem->ExpandPathName(filename));
924 int i;
925
926 std::set<int> runset;
927
928 if (!resetVector)
929 {
930 for ( std::vector<int>::size_type j = 0; j < integers.size(); ++ j )
931 {
932 runset.insert(integers[j]);
933 }
934 }
935
936 char line[10000];
937
938 in.getline(line,10000,'\n');
939
940 TString sline(line);
941
942 if (sline.Contains(","))
943 {
944 TObjArray* a = sline.Tokenize(",");
945 TIter next(a);
946 TObjString* s;
947 while ( ( s = static_cast<TObjString*>(next()) ) )
948 {
949 runset.insert(s->String().Atoi());
950 }
951 delete a;
952 }
953 else
954 {
955 runset.insert(sline.Atoi());
956
957 while ( in >> i )
958 {
959 runset.insert(i);
960 }
961 }
962
963 integers.clear();
964
965 for ( std::set<int>::const_iterator it = runset.begin(); it != runset.end(); ++it )
966 {
967 integers.push_back((*it));
968 }
969
970 std::sort(integers.begin(),integers.end());
971}
972
973
974//______________________________________________________________________________
975void AliAnalysisTriggerScalers::SetRunList(Int_t runNumber)
976{
977 // Make the runlist be a single run
978 fRunList.clear();
979 fRunList.push_back(runNumber);
980}
981
982//______________________________________________________________________________
983void AliAnalysisTriggerScalers::SetRunList(const char* runlist)
984{
985 // Read the runlist from an ASCII file or a comma separated list
986 // or a space separated list
987
988 fRunList.clear();
989
990 if ( TString(runlist).Contains(",") || TString(runlist).Contains(" ") )
991 {
992 TObjArray* runs = 0x0;
993 if ( TString(runlist).Contains(",") )
994 {
995 runs = TString(runlist).Tokenize(",");
996 }
997 else
998 {
999 runs = TString(runlist).Tokenize(" ");
1000 }
1001 TIter next(runs);
1002 TObjString* s;
1003 std::set<int> runset;
1004
1005 while ( ( s = static_cast<TObjString*>(next()) ) )
1006 {
1007 runset.insert(s->String().Atoi());
1008 }
1009
1010 for ( std::set<int>::const_iterator it = runset.begin(); it != runset.end(); ++it )
1011 {
1012 fRunList.push_back((*it));
1013 }
1014
1015 std::sort(fRunList.begin(),fRunList.end());
1016
1017 delete runs;
1018 }
1019 else
1020 {
1021 ReadIntegers(runlist,fRunList);
1022 }
1023}
1024
1025//______________________________________________________________________________
1026//______________________________________________________________________________
1027//______________________________________________________________________________
1028//______________________________________________________________________________
1029//______________________________________________________________________________
1030//______________________________________________________________________________
1031//______________________________________________________________________________
1032
1033ClassImp(AliAnalysisTriggerScalerItem)
1034
1035//______________________________________________________________________________
1036const char*
1037AliAnalysisTriggerScalerItem::BCMaskName() const
1038{
1039 if ( BCMask() ) return BCMask()->GetName(); else return "";
1040}
1041
1042//______________________________________________________________________________
1043Int_t AliAnalysisTriggerScalerItem::Compare(const TObject* obj) const
1044{
1045 const AliAnalysisTriggerScalerItem* s = static_cast<const AliAnalysisTriggerScalerItem*>(obj);
1046
1047 if ( s->RunNumber() < RunNumber() )
1048 {
1049 return -1;
1050 }
1051 else if ( s->RunNumber() > RunNumber() )
1052 {
1053 return 1;
1054 }
1055 return 0;
1056}
1057
1058//______________________________________________________________________________
1059void AliAnalysisTriggerScalerItem::Print(Option_t* opt) const
1060{
1061 TString sopt(opt);
1062
1063 if ( RunNumber() > 0 )
1064 {
1065 sopt.ToUpper();
1066
1067 if ( sopt.Contains("FULL") )
1068 {
1069 }
1070 else
1071 {
1072 std::cout << Form("RUN %6d CLASS %24s (%5s %4d BCs) SCALER %s %12llu DS %6d DURATION %ld",
1073 RunNumber(),TriggerClassName(),
1074 BCMaskName(),
1075 BCMask() ? BCMask()->GetNUnmaskedBCs() : 0,
1076 Level(),
1077 Value(),DownscalingFactor(),Duration()) << std::endl;
1078 }
1079 }
1080 else
1081 {
1082 std::cout << Form("CLASS %24s SCALER %20llu NRUNS %d",
1083 TriggerClassName(),Value(),NofRuns()) << std::endl;
1084 }
1085}