3 #include "AliGenTriggerMapSelector.h"
11 #include <TParticle.h>
14 #include <TGeoManager.h>
22 #include <AliRunLoader.h>
24 #include <AliGenEventHeader.h>
25 #include <AliHeader.h>
27 #include <AliITSgeom.h>
28 #include <AliITSLoader.h>
29 #include <AliITSdigitSPD.h>
30 #include <AliITSRecPoint.h>
32 #include "AliPWG0Helper.h"
37 ClassImp(AliGenTriggerMapSelector)
39 AliGenTriggerMapSelector::AliGenTriggerMapSelector() :
45 // Constructor. Initialization of pointers
49 AliGenTriggerMapSelector::~AliGenTriggerMapSelector()
55 // histograms are in the output list and deleted when the output
56 // list is deleted by the TSelector dtor
59 void AliGenTriggerMapSelector::SlaveBegin(TTree *tree)
61 AliSelectorRL::SlaveBegin(tree);
63 fChipsFired = new TH2F("fChipsFired", ";Module;Chip;Count", 240, -0.5, 239.5, 5, -0.5, 4.5);
64 fTracklets = new TNtuple("fTracklets", "", "vertex:chip1:chip2:dirty");
67 void AliGenTriggerMapSelector::Init(TTree* tree)
69 // read the user objects
71 AliSelectorRL::Init(tree);
73 // enable only the needed branches
76 tree->SetBranchStatus("*", 0);
77 tree->SetBranchStatus("fTriggerMask", 1);
78 tree->SetBranchStatus("fSPDVertex*", 1);
79 tree->SetBranchStatus("fSPDMult*", 1);
83 Bool_t AliGenTriggerMapSelector::Process(Long64_t entry)
89 if (AliSelectorRL::Process(entry) == kFALSE)
92 // Check prerequisites
95 AliDebug(AliLog::kError, "ESD branch not available");
99 Bool_t eventTriggered = AliPWG0Helper::IsEventTriggered(fESD, AliPWG0Helper::kMB1);
103 AliDebug(AliLog::kDebug, "Event not triggered. Skipping.");
107 AliHeader* header = GetHeader();
110 AliDebug(AliLog::kError, "Header not available");
115 AliGenEventHeader* genHeader = header->GenEventHeader();
117 genHeader->PrimaryVertex(vtxMC);
118 Float_t zVertex = vtxMC[2];
120 AliStack* stack = GetStack();
123 AliDebug(AliLog::kError, "Stack not available");
126 Int_t nPrim = stack->GetNprimary();
128 AliRunLoader* runLoader = GetRunLoader();
131 AliDebug(AliLog::kError, "runloader not available");
135 // TDirectory::TContext restores the current directory is restored when the scope ends.
136 // This helps around ROOT bug #26025 and is good behaviour anyway
137 TDirectory::TContext context(0);
138 AliITSLoader* loader = (AliITSLoader*) runLoader->GetLoader( "ITSLoader" );
139 loader->LoadDigits("READ");
140 TTree* treeD = loader->TreeD();
143 AliDebug(AliLog::kError, "Could not retrieve TreeD of ITS");
147 treeD->SetBranchStatus("*", 0);
148 treeD->SetBranchStatus("ITSDigitsSPD.fTracks*", 1);
149 treeD->SetBranchStatus("ITSDigitsSPD.fCoord1", 1);
151 TClonesArray* digits = 0;
152 treeD->SetBranchAddress("ITSDigitsSPD", &digits);
156 const Int_t startSPD = 0; //geom->GetStartSPD();
157 const Int_t lastSPD = 239; //geom->GetLastSPD();
159 const AliMultiplicity* mult = fESD->GetMultiplicity();
162 AliDebug(AliLog::kError, "AliMultiplicity not available");
166 // loop over tracklets
167 for (Int_t i=0; i<mult->GetNumberOfTracklets(); ++i)
169 Float_t theta = mult->GetTheta(i);
170 Float_t eta = -TMath::Log(TMath::Tan(theta/2.));
172 Int_t label = mult->GetLabel(i);
175 AliDebug(AliLog::kDebug, Form("Skipping particle %d because it is not a primary (label %d)", i, label));
180 AliDebug(AliLog::kDebug, Form("Skipping particle %d because its label is negative (label %d)", i, label));
187 for (Int_t j=0; j<2; ++j)
193 // now find clusters that belong to this label
194 // loop over modules (ladders)
195 for (Int_t moduleIndex=startSPD; moduleIndex<lastSPD+1; moduleIndex++)
197 Int_t currentLayer = 0;
198 if (moduleIndex >= 80)
201 treeD->GetEvent(moduleIndex);
203 // get number of digits in this module
204 Int_t ndigitsInModule = digits->GetEntriesFast();
206 // loop over digits in this module
207 for (Int_t iDig=0; iDig<ndigitsInModule; iDig++)
209 AliITSdigitSPD* dp = (AliITSdigitSPD*) digits->At(iDig);
211 // check if digit belongs to this tracklet
212 Bool_t belongs = kFALSE;
213 for (Int_t iTrack = 0; iTrack < dp->GetNTracks(); ++iTrack)
215 //Printf("%d %d %d %d: %d =? %d", i, moduleIndex, iDig, iTrack, label, dp->GetTrack(iTrack));
216 if (dp->GetTrack(iTrack) == label)
223 Int_t column = dp->GetCoord1();
224 Int_t isChip = column / 32;
226 //printf("Digit %d has column %d which translates to chip %d\n", iDig, column, isChip);
228 fChipsFired->Fill(moduleIndex, isChip);
230 if (chip[currentLayer] == -1)
232 chip[currentLayer] = moduleIndex * 5 + isChip;
233 //Printf("%d --> %d %d", label, moduleIndex, isChip);
234 nClusters[currentLayer]++;
238 if (chip[currentLayer] != moduleIndex * 5 + isChip)
239 nClusters[currentLayer]++;
244 AliDebug(AliLog::kDebug, Form("Tracklet %d fired by chip %d and %d", i, chip[0], chip[1]));
246 Bool_t dirty = kFALSE;
247 if (nClusters[0] == 0 || nClusters[1] == 0)
249 AliDebug(AliLog::kDebug, Form("Not enough clusters found for tracklet %d", i));
252 if (nClusters[0] > 1 || nClusters[1] > 1)
254 AliDebug(AliLog::kDebug, Form("Too many clusters found for tracklet %d; L1: %d; L2: %d", i, nClusters[0], nClusters[1]));
257 fTracklets->Fill(zVertex, chip[0], chip[1], dirty);
263 Bool_t AliGenTriggerMapSelector::Notify()
265 AliRunLoader* runLoader = GetRunLoader();
269 AliITSLoader* loader = (AliITSLoader* )runLoader->GetLoader( "ITSLoader" );
272 loader->UnloadDigits();
273 loader->UnloadRecPoints();
277 return AliSelectorRL::Notify();
280 void AliGenTriggerMapSelector::SlaveTerminate()
282 // The SlaveTerminate() function is called after all entries or objects
283 // have been processed. When running with PROOF SlaveTerminate() is called
284 // on each slave server.
286 AliSelectorRL::SlaveTerminate();
288 // Add the histograms to the output on each slave server
291 AliDebug(AliLog::kError, "ERROR: Output list not initialized.");
295 fOutput->Add(fChipsFired);
296 fOutput->Add(fTracklets);
299 void AliGenTriggerMapSelector::Terminate()
301 // The Terminate() function is the last function to be called during
302 // a query. It always runs on the client, it can be used to present
303 // the results graphically or save the results to file.
305 AliSelectorRL::Terminate();
307 fChipsFired = dynamic_cast<TH2F*> (fOutput->FindObject("fChipsFired"));
308 fTracklets = dynamic_cast<TNtuple*> (fOutput->FindObject("fTracklets"));
310 if (!fTracklets || !fChipsFired)
312 AliError("Histograms not available");
319 void AliGenTriggerMapSelector::WriteHistograms(const char* filename)
321 TFile* file = TFile::Open(filename, "RECREATE");
323 fChipsFired->Write();
329 void AliGenTriggerMapSelector::ReadHistograms(const char* filename)
331 TFile* file = TFile::Open(filename);
336 fTracklets = dynamic_cast<TNtuple*> (file->Get("fTracklets"));
337 fChipsFired = dynamic_cast<TH2F*> (file->Get("fChipsFired"));
340 void AliGenTriggerMapSelector::GenerateTriggerMap(Bool_t clean)
342 Int_t nEntries = fTracklets->GetEntries();
345 TH2F* hist = new TH2F("hist", ";layer1;layer2", 400, -0.5, 399.5, 800, 399.5, 1199.5);
347 Long64_t nSkipped = 0;
348 for (Int_t i = 0; i < nEntries; ++i)
350 fTracklets->GetEntry(i);
351 Float_t* vars = fTracklets->GetArgs();
353 if (clean && (Bool_t) vars[3] != kFALSE)
359 hist->Fill(vars[1], vars[2]);
362 Printf("Skipped %lld dirty entries", nSkipped);
366 for (Int_t i = 1; i <= hist->GetNbinsX(); ++i)
367 for (Int_t j = 1; j <= hist->GetNbinsY(); ++j)
368 if (hist->GetBinContent(i, j) > 0)
369 Printf("(%d,%d) ", TMath::Nint(hist->GetXaxis()->GetBinCenter(i)), TMath::Nint(hist->GetYaxis()->GetBinCenter(j)));