3 #include "AliHighMultiplicitySelector.h"
11 #include <TParticle.h>
14 #include <TGeoManager.h>
22 #include <AliRunLoader.h>
25 #include <AliITSgeom.h>
26 #include <AliITSLoader.h>
27 #include <AliITSdigitSPD.h>
28 #include <AliITSRecPoint.h>
30 #include "AliPWG0Helper.h"
35 ClassImp(AliHighMultiplicitySelector)
37 AliHighMultiplicitySelector::AliHighMultiplicitySelector() :
54 // Constructor. Initialization of pointers
58 AliHighMultiplicitySelector::~AliHighMultiplicitySelector()
64 // histograms are in the output list and deleted when the output
65 // list is deleted by the TSelector dtor
68 void AliHighMultiplicitySelector::SlaveBegin(TTree *tree)
70 AliSelectorRL::SlaveBegin(tree);
72 fChipsFired = new TH2F("fChipsFired", ";Module;Chip;Count", 240, -0.5, 239.5, 5, -0.5, 4.5);
74 fPrimaryL1 = new TNtuple("fPrimaryL1", "", "multiplicity:firedChips:chipsByPrimaries:clusters");
75 fPrimaryL2 = new TNtuple("fPrimaryL2", "", "multiplicity:firedChips:chipsByPrimaries:clusters");
77 fClusterZL1 = new TH1F("fClusterZL1", ";z", 400, -20, 20);
78 fClusterZL2 = new TH1F("fClusterZL2", ";z", 400, -20, 20);
81 void AliHighMultiplicitySelector::Init(TTree* tree)
83 // read the user objects
85 AliSelectorRL::Init(tree);
87 // enable only the needed branches
90 tree->SetBranchStatus("*", 0);
91 tree->SetBranchStatus("fTriggerMask", 1);
93 /*if (fTree->GetCurrentFile())
95 TString fileName(fTree->GetCurrentFile()->GetName());
96 fileName.ReplaceAll("AliESDs", "geometry");
99 TGeoManager::Import(fileName);
104 Bool_t AliHighMultiplicitySelector::Process(Long64_t entry)
110 if (AliSelectorRL::Process(entry) == kFALSE)
113 // Check prerequisites
116 AliDebug(AliLog::kError, "ESD branch not available");
120 Bool_t eventTriggered = AliPWG0Helper::IsEventTriggered(fESD, AliPWG0Helper::kMB1);
124 AliDebug(AliLog::kDebug, "Event not triggered. Skipping.");
128 AliStack* stack = GetStack();
131 AliDebug(AliLog::kError, "Stack not available");
135 Int_t nPrim = stack->GetNprimary();
136 Int_t multiplicity21 = 0;
137 Int_t multiplicity16 = 0;
139 for (Int_t iMc = 0; iMc < nPrim; ++iMc)
141 AliDebug(AliLog::kDebug+1, Form("MC Loop: Processing particle %d.", iMc));
143 TParticle* particle = stack->Particle(iMc);
147 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (mc loop).", iMc));
151 if (AliPWG0Helper::IsPrimaryCharged(particle, nPrim) == kFALSE)
156 if (TMath::Abs(particle->Eta()) < 1.05)
158 if (TMath::Abs(particle->Eta()) < 0.8)
163 if (TMath::Abs(particle->Eta()) < 2.1)
165 if (TMath::Abs(particle->Eta()) < 1.6)
168 }// end of mc particle
170 AliRunLoader* runLoader = GetRunLoader();
173 AliDebug(AliLog::kError, "runloader not available");
177 // TDirectory::TContext restores the current directory is restored when the scope ends.
178 // This helps around ROOT bug #26025 and is good behaviour anyway
179 TDirectory::TContext context(0);
180 AliITSLoader* loader = (AliITSLoader*) runLoader->GetLoader( "ITSLoader" );
181 loader->LoadDigits("READ");
182 TTree* treeD = loader->TreeD();
185 AliDebug(AliLog::kError, "Could not retrieve TreeD of ITS");
189 treeD->SetBranchStatus("*", 0);
190 treeD->SetBranchStatus("ITSDigitsSPD.fTracks*", 1);
191 treeD->SetBranchStatus("ITSDigitsSPD.fCoord1", 1);
193 TClonesArray* digits = 0;
194 treeD->SetBranchAddress("ITSDigitsSPD", &digits);
198 // each value for both layers
199 Int_t totalNumberOfFO[2];
200 Int_t chipsHitByPrimaries[2];
201 //Int_t chipsHitBySecondaries[2];
203 for (Int_t i=0; i<2; ++i)
205 totalNumberOfFO[i] = 0;
206 chipsHitByPrimaries[i] = 0;
207 //chipsHitBySecondaries[i] = 0;
210 Int_t startSPD = 0; //geom->GetStartSPD();
211 Int_t lastSPD = 239; //geom->GetLastSPD();
213 //printf("%d %d\n", startSPD, lastSPD);
214 // for (Int_t l=0; l<240; ++l) { AliITSgeomTGeo::GetModuleId(l, i, j, k); printf("%d --> %d\n", l, i); }
216 // loop over modules (ladders)
217 for (Int_t moduleIndex=startSPD; moduleIndex<lastSPD+1; moduleIndex++)
221 if ((moduleIndex % 4) == 0 || (moduleIndex % 4) == 3)
225 Int_t currentLayer = 0;
226 if (moduleIndex >= 80)
229 treeD->GetEvent(moduleIndex);
231 // get number of digits in this module
232 Int_t ndigitsInModule = digits->GetEntriesFast();
234 // get number of digits in each chip of the module
235 Int_t ndigitsInChip[5];
236 Bool_t hitByPrimary[5];
237 for( Int_t iChip=0; iChip<5; iChip++)
239 ndigitsInChip[iChip]=0;
240 hitByPrimary[iChip] = kFALSE;
243 // loop over digits in this module
244 for (Int_t iDig=0; iDig<ndigitsInModule; iDig++)
246 AliITSdigitSPD* dp = (AliITSdigitSPD*) digits->At(iDig);
247 Int_t column = dp->GetCoord1();
248 Int_t isChip = column / 32;
250 //printf("Digit %d has column %d which translates to chip %d\n", iDig, column, isChip);
252 fChipsFired->Fill(moduleIndex, isChip);
254 ndigitsInChip[isChip]++;
256 Bool_t debug = kFALSE;
258 // find out which particle caused this chip to fire
259 // if we find at least one primary we consider this chip being fired by a primary
260 for (Int_t track=0; track<10; ++track)
262 Int_t label = dp->GetTrack(track);
268 printf("track %d contains label %d\n", track, label);
270 TParticle* particle = stack->Particle(label);
274 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (digit loop).", label));
281 printf("statuscode = %d, p = %f, m = %d\n", particle->GetStatusCode(), particle->P(), particle->GetFirstMother());
284 // TODO delta electrons should be traced back to their mother. this is e.g. solved in AliITSClusterFinderV2::CheckLabels2
285 while (particle->P() < 0.02 && particle->GetStatusCode() == 0 && particle->GetFirstMother() >= 0)
287 label = particle->GetFirstMother();
288 particle = stack->Particle(label);
296 printf("statuscode = %d, p = %f, m = %d\n", particle->GetStatusCode(), particle->P(), particle->GetFirstMother());
303 AliDebug(AliLog::kError, Form("UNEXPECTED: particle with label %d not found in stack (digit loop, finding delta electrons).", label));
310 if (AliPWG0Helper::IsPrimaryCharged(particle, nPrim) == kFALSE)
314 printf("This was a primary (or delta-electron of a primary)!\n");
316 hitByPrimary[isChip] = kTRUE;
320 // get number of FOs in the module
321 for (Int_t ifChip=0; ifChip<5; ifChip++)
322 if( ndigitsInChip[ifChip] >= 1 )
324 totalNumberOfFO[currentLayer]++;
325 if (hitByPrimary[ifChip])
327 chipsHitByPrimaries[currentLayer]++;
330 // chipsHitBySecondaries[currentLayer]++;
334 //printf("Fired chips: %d %d\n", totalNumberOfFOLayer1, totalNumberOfFOLayer2);
337 Int_t clustersLayer[2];
338 clustersLayer[0] = 0;
339 clustersLayer[1] = 0;
341 loader->LoadRecPoints("READ");
342 TTree* treeR = loader->TreeR();
345 AliDebug(AliLog::kError, "Could not retrieve TreeR of ITS");
350 //treeR->SetBranchStatus("*", 0);
352 TClonesArray* itsClusters = 0;
353 treeR->SetBranchAddress("ITSRecPoints", &itsClusters);
355 Int_t nTreeEntries = treeR->GetEntries();
356 for (Int_t iEntry = 0; iEntry < nTreeEntries; ++iEntry)
358 if (!treeR->GetEvent(iEntry))
361 Int_t nClusters = itsClusters->GetEntriesFast();
365 AliITSRecPoint* cluster = (AliITSRecPoint*) itsClusters->UncheckedAt(nClusters);
367 if (cluster->GetLayer() == 0)
370 fClusterZL1->Fill(cluster->GetZ());
372 else if (cluster->GetLayer() == 1)
375 fClusterZL2->Fill(cluster->GetZ());
380 fPrimaryL1->Fill(multiplicity21, totalNumberOfFO[0], chipsHitByPrimaries[0], clustersLayer[0]);
381 fPrimaryL2->Fill(multiplicity16, totalNumberOfFO[1], chipsHitByPrimaries[1], clustersLayer[1]);
386 Bool_t AliHighMultiplicitySelector::Notify()
388 AliRunLoader* runLoader = GetRunLoader();
392 AliITSLoader* loader = (AliITSLoader* )runLoader->GetLoader( "ITSLoader" );
395 loader->UnloadDigits();
396 loader->UnloadRecPoints();
400 return AliSelectorRL::Notify();
403 void AliHighMultiplicitySelector::SlaveTerminate()
405 // The SlaveTerminate() function is called after all entries or objects
406 // have been processed. When running with PROOF SlaveTerminate() is called
407 // on each slave server.
409 AliSelectorRL::SlaveTerminate();
411 // Add the histograms to the output on each slave server
414 AliDebug(AliLog::kError, "ERROR: Output list not initialized.");
418 fOutput->Add(fChipsFired);
419 fOutput->Add(fPrimaryL1);
420 fOutput->Add(fPrimaryL2);
421 fOutput->Add(fClusterZL1);
422 fOutput->Add(fClusterZL2);
425 void AliHighMultiplicitySelector::Terminate()
427 // The Terminate() function is the last function to be called during
428 // a query. It always runs on the client, it can be used to present
429 // the results graphically or save the results to file.
431 AliSelectorRL::Terminate();
433 fChipsFired = dynamic_cast<TH2F*> (fOutput->FindObject("fChipsFired"));
434 fPrimaryL1 = dynamic_cast<TNtuple*> (fOutput->FindObject("fPrimaryL1"));
435 fPrimaryL2 = dynamic_cast<TNtuple*> (fOutput->FindObject("fPrimaryL2"));
436 fClusterZL1 = dynamic_cast<TH1F*> (fOutput->FindObject("fClusterZL1"));
437 fClusterZL2 = dynamic_cast<TH1F*> (fOutput->FindObject("fClusterZL2"));
439 if (!fClusterZL1 || !fClusterZL2 || !fChipsFired || !fPrimaryL1 || !fPrimaryL2)
441 AliError("Histograms not available");
448 void AliHighMultiplicitySelector::WriteHistograms(const char* filename)
450 TFile* file = TFile::Open(filename, "RECREATE");
452 fChipsFired->Write();
455 fClusterZL1->Write();
456 fClusterZL2->Write();
461 void AliHighMultiplicitySelector::ReadHistograms(const char* filename)
463 TFile* file = TFile::Open(filename);
468 fPrimaryL1 = dynamic_cast<TNtuple*> (file->Get("fPrimaryL1"));
469 fPrimaryL2 = dynamic_cast<TNtuple*> (file->Get("fPrimaryL2"));
470 fChipsFired = dynamic_cast<TH2F*> (file->Get("fChipsFired"));
471 fClusterZL1 = dynamic_cast<TH1F*> (file->Get("fClusterZL1"));
472 fClusterZL2 = dynamic_cast<TH1F*> (file->Get("fClusterZL2"));
474 #define MULT 1001, -0.5, 1000.5
475 #define BINNING_LAYER1 401, -0.5, 400.5
476 #define BINNING_LAYER2 801, -0.5, 800.5
478 fChipsLayer1 = new TH1F("fChipsLayer1", "Layer 1;Fired Chips;Count", BINNING_LAYER1);
479 fChipsLayer2 = new TH1F("fChipsLayer2", "Layer 2;Fired Chips;Count", BINNING_LAYER2);
481 fL1vsL2 = new TH2F("fL1vsL2", ";Fired Chips Layer 1;Fired Chips Layer 2", BINNING_LAYER1, BINNING_LAYER2);
482 fMvsL1 = new TH2F("fMvsL1", ";true multiplicity;fired chips layer1", MULT, BINNING_LAYER1);
483 fMvsL2 = new TH2F("fMvsL2", ";true multiplicity;fired chips layer2", MULT, BINNING_LAYER2);
485 fClvsL1 = new TH2F("fClvsL1", ";clusters layer1;fired chips layer1", MULT, BINNING_LAYER1);
486 fClvsL2 = new TH2F("fClvsL2", ";clusters layer2;fired chips layer2", MULT, BINNING_LAYER2);
488 for (Int_t i = 0; i < fPrimaryL1->GetEntries(); i++)
490 fPrimaryL1->GetEvent(i);
491 fPrimaryL2->GetEvent(i);
493 Int_t multiplicity21 = (Int_t) fPrimaryL1->GetArgs()[0];
494 Int_t multiplicity16 = (Int_t) fPrimaryL2->GetArgs()[0];
496 Int_t totalNumberOfFO[2];
497 totalNumberOfFO[0] = (Int_t) fPrimaryL1->GetArgs()[1];
498 totalNumberOfFO[1] = (Int_t) fPrimaryL2->GetArgs()[1];
500 Int_t chipsHitByPrimaries[2];
501 chipsHitByPrimaries[0] = (Int_t) fPrimaryL1->GetArgs()[2];
502 chipsHitByPrimaries[1] = (Int_t) fPrimaryL2->GetArgs()[2];
504 Int_t clustersLayer[2];
505 clustersLayer[0] = (Int_t) fPrimaryL1->GetArgs()[3];
506 clustersLayer[1] = (Int_t) fPrimaryL2->GetArgs()[3];
508 fChipsLayer1->Fill(totalNumberOfFO[0]);
509 fChipsLayer2->Fill(totalNumberOfFO[1]);
511 fL1vsL2->Fill(totalNumberOfFO[0], totalNumberOfFO[1]);
513 fMvsL1->Fill(multiplicity21, totalNumberOfFO[0]);
514 fMvsL2->Fill(multiplicity16, totalNumberOfFO[1]);
516 fClvsL1->Fill(clustersLayer[0], totalNumberOfFO[0]);
517 fClvsL2->Fill(clustersLayer[1], totalNumberOfFO[1]);
521 TH1* AliHighMultiplicitySelector::GetTriggerEfficiency(TH2* multVsLayer, Int_t cut)
524 // returns the trigger efficiency as function of multiplicity with a given cut
527 //cut and multiply with x-section
528 TH1* allEvents = multVsLayer->ProjectionX("fMvsL_x_total", 1, 1001);
529 //allEvents->Sumw2();
531 //cut and multiply with x-section
532 TH1* proj = multVsLayer->ProjectionX(Form("%s_x", multVsLayer->GetName()), cut, 1001);
535 //new TCanvas; allEvents->DrawCopy(); gPad->SetLogy();
536 //new TCanvas; proj->DrawCopy(); gPad->SetLogy();
538 // make probability distribution out of it
539 // TODO binomial errors do not work??? weird...
540 proj->Divide(proj, allEvents, 1, 1, "B");
545 TH1* AliHighMultiplicitySelector::GetXSectionCut(TH1* xSection, TH2* multVsLayer, Int_t cut)
547 // returns the rel. cross section of the true spectrum that is measured when a cut at <cut> is performed
549 TH1* proj = GetTriggerEfficiency(multVsLayer, cut);
551 //new TCanvas; proj->DrawCopy(); gPad->SetLogy();
553 for (Int_t i=1; i<=proj->GetNbinsX(); i++)
555 if (i <= xSection->GetNbinsX())
557 Double_t value = proj->GetBinContent(i) * xSection->GetBinContent(i);
561 error = value * (proj->GetBinError(i) / proj->GetBinContent(i) + xSection->GetBinError(i) / xSection->GetBinContent(i));
563 proj->SetBinContent(i, value);
564 proj->SetBinError(i, error);
568 proj->SetBinContent(i, 0);
569 proj->SetBinError(i, 0);
573 //new TCanvas; proj->DrawCopy(); gPad->SetLogy();
578 void AliHighMultiplicitySelector::MakeGraphs2(const char* title, TH1* xSection, TH2* fMvsL)
580 TGraph* effGraph = new TGraph;
581 effGraph->SetTitle(Form("%s;Cut on fired chips;mult. where eff. >50%%", title));
582 TGraph* ratioGraph = new TGraph;
583 ratioGraph->SetTitle(Form("%s;Cut on fired chips;x-section_(>=eff. limit) / x-section_(total)", title));
584 TGraph* totalGraph = new TGraph;
585 totalGraph->SetTitle(Form("%s;Cut on fired chips;rel x-section_(>=eff. limit)", title));
587 for (Int_t cut = 0; cut <= 300; cut+=50)
589 TH1* proj = (TH1*) GetTriggerEfficiency(fMvsL, cut)->Clone("clone");
592 //proj->Scale(1.0 / 3);
594 new TCanvas; proj->DrawCopy();
596 Int_t limitBin = proj->GetNbinsX()+1;
597 while (limitBin > 1 && proj->GetBinContent(limitBin-1) > 0.5)
600 Float_t limit = proj->GetXaxis()->GetBinCenter(limitBin);
602 effGraph->SetPoint(effGraph->GetN(), cut, limit);
604 proj = GetXSectionCut(xSection, fMvsL, cut);
608 if (proj->Integral(1, 1001) > 0)
610 ratio = proj->Integral(proj->FindBin(limit), 1001) / proj->Integral(1, 1001);
611 total = proj->Integral(proj->FindBin(limit), 1001);
614 ratioGraph->SetPoint(ratioGraph->GetN(), cut, ratio);
615 totalGraph->SetPoint(totalGraph->GetN(), cut, total);
617 Printf("Cut at %d --> trigger eff. is > 0.5 for mult. >= %.2f. That is the case for %f of the triggered, %e of all events", cut, limit, ratio, total);
620 TCanvas* canvas = new TCanvas(Form("%s_Efficiency", title), Form("%s_Efficiency", title), 1200, 800);
621 canvas->Divide(2, 2);
624 effGraph->Draw("A*");
626 for (Int_t i=8; i<=10; ++i)
628 TLine* line = new TLine(0, xSection->GetMean() * i, 300, xSection->GetMean() * i);
632 canvas->cd(2); ratioGraph->Draw("A*");
633 canvas->cd(3); gPad->SetLogy(); totalGraph->Draw("A*");
635 canvas->SaveAs(Form("%s.gif", canvas->GetName()));
638 void AliHighMultiplicitySelector::MakeGraphs(const char* title, TH1* xSection, TH2* fMvsL, Int_t limit)
640 // relative x-section, once we have a collision
641 xSection->Scale(1.0 / xSection->Integral());
643 TGraph* ratioGraph = new TGraph;
644 ratioGraph->SetTitle(Form("%s;Cut on fired chips;x-section_(>=%d) / x-section_(total)", title, limit));
645 TGraph* totalGraph = new TGraph;
646 totalGraph->SetTitle(Form("%s;Cut on fired chips;rel x-section_(>=%d)", title, limit));
650 Double_t bestRatio = -1;
651 Double_t bestTotal = -1;
653 Double_t fullRatio = -1;
654 Double_t fullTotal = -1;
658 for (Int_t cut = 50; cut <= 300; cut+=2)
660 TH1* proj = GetXSectionCut(xSection, fMvsL, cut);
664 if (proj->Integral(1, 1000) > 0)
666 ratio = proj->Integral(limit, 1000) / proj->Integral(1, 1000);
667 total = proj->Integral(limit, 1000);
670 max = TMath::Max(max, total);
672 //printf("Cut at %d: rel. x-section_(>=%d) = %e; x-section_(>=%d) / x-section_(total) = %f\n", cut, limit, total, limit, ratio);
674 if (total < max * 0.9 && bestCut == -1)
681 if (ratio == 1 && fullCut == -1)
688 ratioGraph->SetPoint(ratioGraph->GetN(), cut, ratio);
689 totalGraph->SetPoint(totalGraph->GetN(), cut, total);
693 printf("Best cut at %d: rel. x-section_(>=%d) = %e %%; x-section_(>=%d) / x-section_(total) = %f %%\n", bestCut, limit, bestTotal, limit, bestRatio);
695 printf("100%% cut at %d: rel. x-section_(>=%d) = %e %%; x-section_(>=%d) / x-section_(total) = %f %%\n", fullCut, limit, fullTotal, limit, fullRatio);
697 TCanvas* canvas = new TCanvas(Form("%s_RatioXSection_%d", title, limit), Form("%s_RatioXSection_%d", title, limit), 600, 400);
698 ratioGraph->Draw("A*");
699 canvas->SaveAs(Form("%s.gif", canvas->GetName()));
701 canvas = new TCanvas(Form("%s_TotalXSection_%d", title, limit), Form("%s_TotalXSection_%d", title, limit), 600, 400);
702 totalGraph->Draw("A*");
703 canvas->SaveAs(Form("%s.gif", canvas->GetName()));
706 void AliHighMultiplicitySelector::JPRPlots()
710 gSystem->Load("libPWG0base");
711 .L AliHighMultiplicitySelector.cxx+
712 x = new AliHighMultiplicitySelector();
713 x->ReadHistograms("highmult_hijing100k.root");
719 TFile* file = TFile::Open("crosssectionEx.root");
724 xSections[0] = dynamic_cast<TH1*> (gFile->Get("xSection2Ex"));
725 xSections[1] = dynamic_cast<TH1*> (gFile->Get("xSection15Ex"));
727 for (Int_t i=0; i<2; ++i)
732 TH1* xSection = xSections[i];
733 TH2* fMvsL = (i == 0) ? fMvsL1: fMvsL2;
734 //Int_t cut = (i == 0) ? 164 : 150; // 8 times the mean
735 //Int_t cut = (i == 0) ? 178 : 166; // 9 times the mean
736 Int_t cut = (i == 0) ? 190 : 182; // 10 times the mean
738 // limit is N times the mean
739 Int_t limit = (Int_t) (xSection->GetMean() * 10);
741 // 10^28 lum --> 1.2 kHz
742 // 10^31 lum --> 1200 kHz
743 Float_t rate = 1200e3;
746 Float_t lengthRun = 1e6;
748 xSection->SetStats(kFALSE);
749 xSection->SetTitle(""); //(i == 0) ? "SPD Layer 1" : "SPD Layer 2");
750 xSection->GetXaxis()->SetTitle(Form("true multiplicity in |#eta| < %.1f", (i == 0) ? 2.0 : 1.5));
751 xSection->GetXaxis()->SetRangeUser(0, (i == 0) ? 400 : 350);
752 //xSection->GetYaxis()->SetTitle("relative cross section");
753 xSection->GetYaxis()->SetTitleOffset(1.2);
755 // relative x-section, once we have a collision
756 xSection->Scale(1.0 / xSection->Integral());
758 TH1* proj = GetXSectionCut(xSection, fMvsL, cut);
762 if (proj->Integral(1, 1000) > 0)
764 ratio = proj->Integral(limit, 1000) / proj->Integral(1, 1000);
765 total = proj->Integral(limit, 1000);
768 printf("Cut at %d: rel. x-section_(>=%d) = %e; x-section_(>=%d) / x-section_(total) = %f\n", cut, limit, total, limit, ratio);
770 TCanvas* canvas = new TCanvas(Form("HMPlots_%d", i), Form("HMPlots_%d", i), 800, 600);
772 xSection->DrawCopy();
773 proj->SetLineColor(2);
774 proj->SetStats(kFALSE);
775 proj->DrawCopy("SAME");
777 TLegend* legend = new TLegend(0.15, 0.15, 0.45, 0.3);
778 legend->SetFillColor(0);
779 legend->AddEntry(xSection, "no trigger");
780 legend->AddEntry(proj, Form("FO trigger > %d chips", cut));
783 TLine* line = new TLine(limit, xSection->GetMinimum() * 0.5, limit, xSection->GetMaximum() * 2);
784 line->SetLineWidth(2);
787 canvas->SaveAs(Form("%s.gif", canvas->GetName()));
789 TCanvas* canvas2 = new TCanvas(Form("HMPlots_%d_Random", i), Form("HMPlots_%d_Random", i), 800, 600);
790 //canvas2->SetTopMargin(0.05);
791 //canvas2->SetRightMargin(0.05);
793 xSection->DrawCopy("HIST");
795 TLegend* legend2 = new TLegend(0.15, 0.15, 0.6, 0.3);
796 legend2->SetFillColor(0);
797 legend2->AddEntry(xSection, "no trigger");
799 TH1* proj2 = (TH1*) proj->Clone("random");
801 // MB lengthRun s 100 Hz
802 Int_t nTrigger = (Int_t) (100 * lengthRun * proj->Integral(1, 1000));
803 proj2->FillRandom(proj, nTrigger);
805 TH1* proj3 = (TH1*) proj2->Clone("random_clone");
807 proj3->Fit("pol0", "0", "");
808 proj2->Scale(1.0 / proj3->GetFunction("pol0")->GetParameter(0));
811 proj2->DrawCopy("SAME");
812 legend2->AddEntry(proj2, Form("%d evts, FO > %d chips (%d evts)", nTrigger, cut, (Int_t) (nTrigger * ratio)));
815 proj2 = (TH1*) proj->Clone("random2");
817 // 10^31 lum --> 1200 kHz; lengthRun s
818 nTrigger = (Int_t) (rate * proj->Integral(1, 1000) * lengthRun);
819 proj2->FillRandom(proj, nTrigger);
821 proj3 = (TH1*) proj2->Clone("random_clone2");
823 proj3->Fit("pol0", "0", "");
824 proj2->Scale(1.0 / proj3->GetFunction("pol0")->GetParameter(0));
826 proj2->SetLineColor(4);
827 proj2->SetMarkerStyle(7);
828 proj2->SetMarkerColor(4);
829 proj2->DrawCopy("SAME P");
830 //legend2->AddEntry(proj2, Form("%d evts, FO > %d chips (%d evts)", nTrigger, cut, (Int_t) (nTrigger * ratio)));
831 legend2->AddEntry(proj2, Form("FO trigger > %d chips", cut));
836 canvas2->SaveAs(Form("%s.gif", canvas2->GetName()));
837 canvas2->SaveAs(Form("%s.eps", canvas2->GetName()));
841 void AliHighMultiplicitySelector::Ntrigger()
844 // produces a spectrum created with N triggers
845 // number of triggers and thresholds for the moment fixed
850 gSystem->Load("libPWG0base");
851 .L AliHighMultiplicitySelector.cxx+g
852 x = new AliHighMultiplicitySelector();
853 x->ReadHistograms("highmult_hijing100k.root");
859 TFile* file = TFile::Open("crosssectionEx.root");
864 xSections[0] = dynamic_cast<TH1*> (gFile->Get("xSection2Ex"));
865 xSections[1] = dynamic_cast<TH1*> (gFile->Get("xSection15Ex"));
867 // 10^28 lum --> 1.2 kHz
868 // 10^31 lum --> 1200 kHz
869 //Float_t rate = 1200e3;
870 Float_t rate = 1200e3;
873 Float_t lengthRun = 1e6;
875 Int_t colors[] = { 2, 3, 4, 6, 7, 8 };
876 Int_t markers[] = { 7, 2, 4, 5, 6, 27 };
878 // put to 2 for second layer
879 for (Int_t i=0; i<1; ++i)
884 TH1* xSection = xSections[i];
885 TH2* fMvsL = (i == 0) ? fMvsL1: fMvsL2;
888 Int_t cuts[] = { 0, 164, 178, 190, 204, 216 };
890 //Int_t cuts[] = { 0, 164, 190, 216 };
891 // desired trigger rate in Hz
892 Float_t ratePerTrigger[] = { 100, 1, 1, 1, 1, 1 };
894 xSection->SetStats(kFALSE);
895 xSection->SetTitle(""); //(i == 0) ? "SPD Layer 1" : "SPD Layer 2");
896 xSection->GetXaxis()->SetTitle(Form("true multiplicity in |#eta| < %.1f", (i == 0) ? 2.0 : 1.5));
897 xSection->GetXaxis()->SetRangeUser(0, (i == 0) ? 450 : 350);
898 //xSection->GetYaxis()->SetTitle("relative cross section");
899 xSection->GetYaxis()->SetTitleOffset(1.2);
901 // relative x-section, once we have a collision
902 xSection->Scale(1.0 / xSection->Integral());
904 TCanvas* canvas2 = new TCanvas(Form("HMPlots2_%d_Random", i), Form("HMPlots2_%d_Random", i), 800, 600);
905 canvas2->SetTopMargin(0.05);
906 canvas2->SetRightMargin(0.05);
908 xSection->DrawCopy("HIST");
910 TLegend* legend2 = new TLegend(0.15, 0.15, 0.6, 0.4);
911 legend2->SetFillColor(0);
912 legend2->AddEntry(xSection, "cross-section");
914 for (Int_t currentCut = 0; currentCut<nCuts; ++currentCut)
916 Int_t cut = cuts[currentCut];
918 TH1* proj = GetXSectionCut(xSection, fMvsL, cut);
921 if (proj->Integral(1, 1000) > 0)
922 total = proj->Integral(1, 1000);
924 printf("Cut at %d: rel. x-section = %e\n", cut, total);
926 TH1* proj2 = (TH1*) proj->Clone("random2");
929 // calculate downscale factor
930 Float_t normalRate = rate * proj->Integral(1, 1000);
931 Float_t downScale = normalRate / ratePerTrigger[currentCut];
934 Long64_t nTrigger = (Long64_t) (normalRate / downScale * lengthRun);
936 Printf("Normal rate is %f, downscale: %f, Simulating %lld triggers", normalRate, downScale, nTrigger);
937 proj2->FillRandom(proj, nTrigger);
940 for (Int_t bin=1; bin<proj2->GetNbinsX(); ++bin)
941 if (proj2->GetBinContent(bin) < 5)
943 removed += (Int_t) proj2->GetBinContent(bin);
944 proj2->SetBinContent(bin, 0);
947 Printf("Removed %d events", removed);
949 proj2->Scale(1.0 / nTrigger * proj->Integral(1, 1000));
951 proj2->SetLineColor(colors[currentCut]);
952 proj2->SetMarkerStyle(markers[currentCut]);
953 proj2->SetMarkerColor(colors[currentCut]);
954 proj2->DrawCopy("SAME P");
955 legend2->AddEntry(proj2, Form("%lld evts, FO > %d chips", nTrigger, cut));
960 canvas2->SaveAs(Form("%s.gif", canvas2->GetName()));
961 canvas2->SaveAs(Form("%s.eps", canvas2->GetName()));
965 void AliHighMultiplicitySelector::DrawHistograms()
969 gSystem->Load("libPWG0base");
970 .L AliHighMultiplicitySelector.cxx+
971 x = new AliHighMultiplicitySelector();
972 x->ReadHistograms("highmult_pythia.root");
976 gSystem->Load("libPWG0base");
977 .L AliHighMultiplicitySelector.cxx+
978 x = new AliHighMultiplicitySelector();
979 x->ReadHistograms("highmult_hijing.root");
982 gSystem->Load("libPWG0base");
983 .L AliHighMultiplicitySelector.cxx+
984 x = new AliHighMultiplicitySelector();
985 x->ReadHistograms("highmult_central.root");
988 gSystem->Load("libPWG0base");
989 .L AliHighMultiplicitySelector.cxx+
990 x = new AliHighMultiplicitySelector();
991 x->ReadHistograms("highmult_hijing100k.root");
996 /*TCanvas* canvas = new TCanvas("chips", "chips", 600, 400);
998 fChipsLayer2->SetLineColor(2);
999 fChipsLayer2->SetStats(kFALSE);
1000 fChipsLayer1->SetStats(kFALSE);
1001 fChipsLayer2->SetTitle("");
1002 fChipsLayer2->DrawCopy();
1003 fChipsLayer1->DrawCopy("SAME");
1004 canvas->SaveAs("chips.gif");
1006 canvas = new TCanvas("L1vsL2", "L1vsL2", 600, 400);
1007 fL1vsL2->SetStats(kFALSE);
1008 fL1vsL2->DrawCopy("COLZ");
1010 canvas->SaveAs("L1vsL2.gif");*/
1012 TCanvas *canvas = new TCanvas("L1", "L1", 800, 600);
1013 canvas->SetTopMargin(0.05);
1014 canvas->SetRightMargin(0.12);
1015 fMvsL1->SetStats(kFALSE);
1016 fMvsL1->DrawCopy("COLZ");
1019 canvas->SaveAs("L1NoCurve.gif");
1020 canvas->SaveAs("L1NoCurve.eps");
1022 // draw corresponding theoretical curve
1023 TF1* func = new TF1("func", "[0]*(1-(1-1/[0])**x)", 1, 1000);
1024 func->SetParameter(0, 400-5*2);
1025 func->DrawCopy("SAME");
1027 canvas->SaveAs("L1.gif");
1029 canvas = new TCanvas("L2", "L2", 600, 400);
1030 //fMvsL2->GetYaxis()->SetRangeUser(0, 150);
1031 fMvsL2->SetStats(kFALSE);
1032 fMvsL2->DrawCopy("COLZ");
1034 func->SetParameter(0, 800-5*4);
1035 func->DrawCopy("SAME");
1036 canvas->SaveAs("L2.gif");
1039 TFile* file = TFile::Open("crosssectionEx.root");
1042 TH1* xSection2 = dynamic_cast<TH1*> (gFile->Get("xSection2Ex"));
1043 TH1* xSection15 = dynamic_cast<TH1*> (gFile->Get("xSection15Ex"));
1045 MakeGraphs2("Layer1", xSection2, fMvsL1);
1049 //MakeGraphs("Layer1", xSection2, fMvsL1, (Int_t) (xSection2->GetMean() * 5)); //75 * 2 * 2);
1050 //MakeGraphs("Layer2", xSection15, fMvsL2, (Int_t) (xSection15->GetMean() * 5)); //(Int_t) (75 * 1.5 * 2));
1052 MakeGraphs("Layer1", xSection2, fMvsL1, (Int_t) (xSection2->GetMean() * 8));
1053 MakeGraphs("Layer2", xSection15, fMvsL2, (Int_t) (xSection15->GetMean() * 8));
1054 MakeGraphs("Layer1", xSection2, fMvsL1, (Int_t) (xSection2->GetMean() * 9));
1055 MakeGraphs("Layer2", xSection15, fMvsL2, (Int_t) (xSection15->GetMean() * 9));
1056 MakeGraphs("Layer1", xSection2, fMvsL1, (Int_t) (xSection2->GetMean() * 10));
1057 MakeGraphs("Layer2", xSection15, fMvsL2, (Int_t) (xSection15->GetMean() * 10));
1062 // make spread hists
1063 TGraph* spread = new TGraph;
1064 spread->SetTitle("Spread L1;true multiplicity;RMS");
1066 for (Int_t i=1; i<=fMvsL1->GetNbinsX(); ++i)
1068 TH1* proj = fMvsL1->ProjectionY("proj", i, i);
1069 spread->SetPoint(spread->GetN(), i, proj->GetRMS());
1072 canvas = new TCanvas("SpreadL1", "SpreadL1", 600, 400);
1074 canvas->SaveAs(Form("%s.gif", canvas->GetName()));
1076 TF1* log = new TF1("log", "[0]*log([1]*x)", 1, 150);
1077 log->SetParLimits(0, 0, 10);
1078 log->SetParLimits(1, 1e-5, 10);
1080 spread->Fit(log, "", "", 1, 150);
1081 log->DrawCopy("SAME");
1083 TGraph* spread2 = new TGraph;
1084 spread2->SetTitle("Spread L2;true multiplicity;RMS");
1086 for (Int_t i=1; i<=fMvsL1->GetNbinsX(); ++i)
1088 TH1* proj = fMvsL2->ProjectionY("proj", i, i);
1089 spread2->SetPoint(spread2->GetN(), i, proj->GetRMS());
1092 canvas = new TCanvas("SpreadL2", "SpreadL2", 600, 400);
1093 spread2->Draw("A*");
1094 canvas->SaveAs(Form("%s.gif", canvas->GetName()));
1096 spread2->Fit(log, "", "", 1, 150);
1097 log->DrawCopy("SAME");
1099 canvas = new TCanvas("Clusters_L1", "Clusters_L1", 600, 400);
1100 fClvsL1->SetStats(kFALSE);
1101 fClvsL1->DrawCopy("COLZ");
1104 func->SetParameter(0, 400-5*2);
1105 func->DrawCopy("SAME");
1107 canvas->SaveAs("Clusters_L1.gif");
1109 canvas = new TCanvas("Clusters_L2", "Clusters_L2", 600, 400);
1110 fClvsL2->SetStats(kFALSE);
1111 fClvsL2->DrawCopy("COLZ");
1113 func->SetParameter(0, 800-5*4);
1114 func->DrawCopy("SAME");
1115 canvas->SaveAs("Clusters_L2.gif");
1117 canvas = new TCanvas("ChipsFired", "ChipsFired", 600, 400);
1118 //fChipsFired->GetYaxis()->SetRangeUser(0, 150);
1119 fChipsFired->SetStats(kFALSE);
1120 fChipsFired->DrawCopy("COLZ");
1121 canvas->SaveAs("ChipsFired.gif");
1123 /*TH1F* tresholdHistL1 = new TH1F("tresholdHistL1", ";chip treshold;<n>", BINNING_LAYER1);
1124 TH1F* tresholdHistL2 = new TH1F("tresholdHistL2", ";chip treshold;<n>", BINNING_LAYER2);
1126 for (Int_t treshold = 0; treshold < 800; treshold++)
1128 if (fPrimaryL1->Draw("multiplicity>>mult", Form("firedChips>%d", treshold), "goff") > 0)
1130 TH1F* mult = dynamic_cast<TH1F*> (fPrimaryL1->GetHistogram());
1132 tresholdHistL1->Fill(treshold, mult->GetMean());
1134 if (fPrimaryL2->Draw("multiplicity>>mult", Form("firedChips>%d", treshold), "goff") > 0)
1136 TH1F* mult = dynamic_cast<TH1F*> (fPrimaryL2->GetHistogram());
1138 tresholdHistL2->Fill(treshold, mult->GetMean());
1142 canvas = new TCanvas("TresholdL1", "TresholdL1", 600, 400);
1143 tresholdHistL1->Draw();
1144 canvas->SaveAs(Form("%s.gif", canvas->GetName()));
1146 canvas = new TCanvas("TresholdL2", "TresholdL2", 600, 400);
1147 tresholdHistL2->Draw();
1148 canvas->SaveAs(Form("%s.gif", canvas->GetName()));*/
1150 fPrimaryL1->Draw("(chipsByPrimaries/firedChips):multiplicity>>eff1", "", "prof goff");
1151 fPrimaryL2->Draw("(chipsByPrimaries/firedChips):multiplicity>>eff2", "", "prof goff");
1153 canvas = new TCanvas("Efficiency", "Efficiency", 600, 400);
1154 fPrimaryL1->GetHistogram()->SetStats(kFALSE);
1155 fPrimaryL1->GetHistogram()->Draw();
1156 fPrimaryL2->GetHistogram()->SetLineColor(2);
1157 fPrimaryL2->GetHistogram()->SetStats(kFALSE);
1158 fPrimaryL2->GetHistogram()->Draw("SAME");
1159 canvas->SaveAs(Form("%s.gif", canvas->GetName()));
1161 canvas = new TCanvas("ClustersZL1", "ClustersZL1", 600, 400);
1162 fClusterZL1->Rebin(2);
1163 fClusterZL1->Draw();
1164 canvas->SaveAs(Form("%s.gif", canvas->GetName()));
1166 canvas = new TCanvas("ClustersZL2", "ClustersZL2", 600, 400);
1167 fClusterZL2->Draw();
1168 fClusterZL2->Rebin(2);
1169 canvas->SaveAs(Form("%s.gif", canvas->GetName()));