1 #include "AliMFTCluster.h"
3 #include "AliMFTCluster.h"
5 #include "TClonesArray.h"
7 #include "AliMFTConstants.h"
12 TFile *fileInPileUp=0, *fileInSignal, *fileInUnderlying, *fileOutPileUp=0, *fileOutTotal;
14 enum {kMergePileUpClusters_pp, kMergePileUpClusters_PbPb, kMergeAllClusters_pp, kMergeAllClusters_PbPb};
17 const Char_t *fPileUpDir[2] = {"$UnderlyingDirPP/spreadVtx", // local directory with pile-up event p-p
18 "$UnderlyingDirPbPb/spreadVtx"}; // local directory with pile-up event Pb-Pb
20 const Int_t fNRunsPileUp_pp = 100;
21 const Int_t fNRunsPileUp_PbPb = 3;
23 const Int_t fNRunsPileUpAvailable[2] = {500, 500}; // pp, PbPb
25 TClonesArray *fRecPointsPerPlaneIn[AliMFTConstants::fNMaxPlanes] = {0};
26 TClonesArray *fRecPointsPerPlaneOut[AliMFTConstants::fNMaxPlanes] = {0};
28 void MergePileUpClusters(Int_t *runs, Int_t nRunsPileUp, const Char_t *pileUpDir, Int_t nEvents);
29 void MergeAllClusters();
31 //====================================================================================================================================================
33 void MergeClustersMFT(Int_t seed = 12345,
36 Int_t maxPileUp = 9999) {
38 gRandom->SetSeed(seed);
40 if (option==kMergePileUpClusters_pp) {
42 Int_t runs_pp[fNRunsPileUp_pp] = {0};
44 while (nFiles_pp<TMath::Min(fNRunsPileUp_pp,maxPileUp)) {
45 Int_t run = gRandom->Integer(fNRunsPileUpAvailable[k_pp]);
46 fileInPileUp = new TFile(Form("%s/run_%d/MFT.RecPoints.MCShifted.root",fPileUpDir[k_pp],run));
47 if (!fileInPileUp->IsOpen() || !fileInPileUp->cd("Event0")) {
51 Bool_t runAlreadyLoaded=kFALSE;
52 for (Int_t iAddedRun=0; iAddedRun<nFiles_pp; iAddedRun++) {
53 if (run==runs_pp[iAddedRun]) {
54 runAlreadyLoaded=kTRUE;
58 if (!runAlreadyLoaded) runs_pp[nFiles_pp++] = run;
61 MergePileUpClusters(runs_pp, TMath::Min(fNRunsPileUp_pp,maxPileUp), fPileUpDir[k_pp], nEvents);
64 else if (option==kMergePileUpClusters_PbPb) {
65 Int_t runs_PbPb[fNRunsPileUp_PbPb] = {0};
66 Int_t nFiles_PbPb = 0;
67 while (nFiles_PbPb<TMath::Min(fNRunsPileUp_PbPb,maxPileUp)) {
68 Int_t run = gRandom->Integer(fNRunsPileUpAvailable[k_PbPb]);
69 fileInPileUp = new TFile(Form("%s/run_%d/MFT.RecPoints.MCShifted.root",fPileUpDir[k_PbPb],run));
70 if (!fileInPileUp->IsOpen() || !fileInPileUp->cd("Event0")) {
74 Bool_t runAlreadyLoaded=kFALSE;
75 for (Int_t iAddedRun=0; iAddedRun<nFiles_PbPb; iAddedRun++) {
76 if (run==runs_PbPb[iAddedRun]) {
77 runAlreadyLoaded=kTRUE;
81 if (!runAlreadyLoaded) runs_PbPb[nFiles_PbPb++] = run;
84 MergePileUpClusters(runs_PbPb, TMath::Min(fNRunsPileUp_PbPb,maxPileUp), fPileUpDir[k_PbPb], nEvents);
87 if (option>=kMergeAllClusters_pp) MergeAllClusters();
91 //====================================================================================================================================================
93 void MergePileUpClusters(Int_t *runs, Int_t nRunsPileUp, const Char_t *pileUpDir, Int_t nEvents) {
95 fileOutPileUp = new TFile("./MFT.RecPoints.PileUp.root", "recreate");
97 Bool_t eventExist = kTRUE;
100 while (eventExist && iEv<nEvents) {
102 for (Int_t iPlane=0; iPlane<AliMFTConstants::fNMaxPlanes; iPlane++) {
103 fRecPointsPerPlaneOut[iPlane] = new TClonesArray("AliMFTCluster");
106 if (iEv) fileOutPileUp = new TFile("./MFT.RecPoints.PileUp.root", "update");
108 printf("Merging Event %d\n",iEv);
110 fileOutPileUp-> cd();
111 TTree *treeOutPileUp = new TTree("TreeR_OutPileUp", "Reconstructed Points Container");
113 Int_t nFilesAdded = 0;
114 while (nFilesAdded<nRunsPileUp) {
115 fileInPileUp = new TFile(Form("%s/run_%d/MFT.RecPoints.MCShifted.root",pileUpDir,runs[nFilesAdded++]));
116 printf("Merging file %s\n", fileInPileUp->GetName());
117 if (!fileInPileUp->cd(Form("Event%d",iEv))) {
121 for (Int_t iPlane=0; iPlane<AliMFTConstants::fNMaxPlanes; iPlane++) {
122 fRecPointsPerPlaneIn[iPlane] = new TClonesArray("AliMFTCluster");
124 TTree *treeInPileUp = (TTree*) gDirectory->Get("TreeR");
125 treeInPileUp -> SetName("TreeR_InPileUp");
127 while (treeInPileUp->GetBranch(Form("Plane_%02d",iPlane))) {
128 // printf("Plane %02d\n",iPlane);
129 treeInPileUp ->SetBranchAddress(Form("Plane_%02d",iPlane), &(fRecPointsPerPlaneIn[iPlane]));
130 TBranch *branch = treeOutPileUp->GetBranch(Form("Plane_%02d",iPlane));
131 if (!branch) treeOutPileUp->Branch(Form("Plane_%02d",iPlane), &(fRecPointsPerPlaneOut[iPlane]));
135 treeInPileUp -> GetEntry(0);
136 while (treeInPileUp->GetBranch(Form("Plane_%02d",iPlane))) {
137 Int_t nClusters = fRecPointsPerPlaneIn[iPlane]->GetEntries();
138 for (Int_t iCluster=0; iCluster<nClusters; iCluster++) {
139 // printf("Cluster %4d\n",iCluster);
140 AliMFTCluster *newCluster = (AliMFTCluster*) fRecPointsPerPlaneIn[iPlane]->At(iCluster);
141 new ((*fRecPointsPerPlaneOut[iPlane])[fRecPointsPerPlaneOut[iPlane]->GetEntries()]) AliMFTCluster(*newCluster);
145 for (Int_t jPlane=0; jPlane<AliMFTConstants::fNMaxPlanes; jPlane++) {
146 delete fRecPointsPerPlaneIn[jPlane];
149 fileInPileUp -> Close();
153 treeOutPileUp -> Fill();
154 fileOutPileUp -> mkdir(Form("Event%d",iEv));
155 fileOutPileUp -> cd(Form("Event%d",iEv));
156 treeOutPileUp -> SetName("TreeR");
157 treeOutPileUp -> Write();
158 delete treeOutPileUp;
159 fileOutPileUp -> Close();
160 delete fileOutPileUp;
161 for (Int_t iPlane=0; iPlane<AliMFTConstants::fNMaxPlanes; iPlane++) {
162 delete fRecPointsPerPlaneOut[iPlane];
170 //====================================================================================================================================================
172 void MergeAllClusters() {
174 fileOutTotal = new TFile("./MFT.RecPoints.root", "recreate");
176 Bool_t eventExist = kTRUE;
181 for (Int_t iPlane=0; iPlane<AliMFTConstants::fNMaxPlanes; iPlane++) {
182 fRecPointsPerPlaneOut[iPlane] = new TClonesArray("AliMFTCluster");
185 if (iEv) fileOutTotal = new TFile("./MFT.RecPoints.root", "update");
187 printf("Merging Event %d\n",iEv);
190 TTree *treeOutTotal = new TTree("TreeR_Out", "Reconstructed Points Container");
192 // Adding Pile-Up Clusters
194 fileInPileUp = new TFile("./MFT.RecPoints.PileUp.root");
195 printf("Merging file %s\n", fileInPileUp->GetName());
196 if (!fileInPileUp->cd(Form("Event%d",iEv))) {
200 for (Int_t jPlane=0; jPlane<AliMFTConstants::fNMaxPlanes; jPlane++) {
201 fRecPointsPerPlaneIn[jPlane] = new TClonesArray("AliMFTCluster");
203 TTree *treeInPileUp = (TTree*) gDirectory->Get("TreeR");
204 treeInPileUp -> SetName("TreeR_InPileUp");
206 while (treeInPileUp->GetBranch(Form("Plane_%02d",iPlane))) {
207 // printf("Plane %02d\n",iPlane);
208 treeInPileUp ->SetBranchAddress(Form("Plane_%02d",iPlane), &(fRecPointsPerPlaneIn[iPlane]));
209 TBranch *branch = treeOutTotal->GetBranch(Form("Plane_%02d",iPlane));
210 if (!branch) treeOutTotal->Branch(Form("Plane_%02d",iPlane), &(fRecPointsPerPlaneOut[iPlane]));
214 treeInPileUp -> GetEntry(0);
215 while (treeInPileUp->GetBranch(Form("Plane_%02d",iPlane))) {
216 Int_t nClusters = fRecPointsPerPlaneIn[iPlane]->GetEntries();
217 for (Int_t iCluster=0; iCluster<nClusters; iCluster++) {
218 // printf("Cluster %4d\n",iCluster);
219 AliMFTCluster *newCluster = (AliMFTCluster*) fRecPointsPerPlaneIn[iPlane]->At(iCluster);
220 new ((*fRecPointsPerPlaneOut[iPlane])[fRecPointsPerPlaneOut[iPlane]->GetEntries()]) AliMFTCluster(*newCluster);
224 for (Int_t jPlane=0; jPlane<AliMFTConstants::fNMaxPlanes; jPlane++) {
225 delete fRecPointsPerPlaneIn[jPlane];
228 fileInPileUp -> Close();
231 // Adding Underlying Event Clusters
233 fileInUnderlying = new TFile("./MFT.RecPoints.Underlying.root");
234 printf("Merging file %s\n", fileInUnderlying->GetName());
235 if (!fileInUnderlying->cd(Form("Event%d",iEv))) {
239 for (Int_t jPlane=0; jPlane<AliMFTConstants::fNMaxPlanes; jPlane++) {
240 fRecPointsPerPlaneIn[jPlane] = new TClonesArray("AliMFTCluster");
242 TTree *treeInUnderlying = (TTree*) gDirectory->Get("TreeR");
243 treeInUnderlying -> SetName("TreeR_InUnderlying");
245 while (treeInUnderlying->GetBranch(Form("Plane_%02d",iPlane))) {
246 // printf("Plane %02d\n",iPlane);
247 treeInUnderlying ->SetBranchAddress(Form("Plane_%02d",iPlane), &(fRecPointsPerPlaneIn[iPlane]));
248 TBranch *branch = treeOutTotal->GetBranch(Form("Plane_%02d",iPlane));
249 if (!branch) treeOutTotal->Branch(Form("Plane_%02d",iPlane), &(fRecPointsPerPlaneOut[iPlane]));
253 treeInUnderlying -> GetEntry(0);
254 while (treeInUnderlying->GetBranch(Form("Plane_%02d",iPlane))) {
255 Int_t nClusters = fRecPointsPerPlaneIn[iPlane]->GetEntries();
256 for (Int_t iCluster=0; iCluster<nClusters; iCluster++) {
257 // printf("Cluster %4d\n",iCluster);
258 AliMFTCluster *newCluster = (AliMFTCluster*) fRecPointsPerPlaneIn[iPlane]->At(iCluster);
259 new ((*fRecPointsPerPlaneOut[iPlane])[fRecPointsPerPlaneOut[iPlane]->GetEntries()]) AliMFTCluster(*newCluster);
263 for (Int_t jPlane=0; jPlane<AliMFTConstants::fNMaxPlanes; jPlane++) {
264 delete fRecPointsPerPlaneIn[jPlane];
266 delete treeInUnderlying;
267 fileInUnderlying -> Close();
268 delete fileInUnderlying;
270 // Adding Signal Clusters
272 fileInSignal = new TFile("./MFT.RecPoints.Signal.root");
273 printf("Merging file %s\n", fileInSignal->GetName());
274 if (!fileInSignal->cd(Form("Event%d",iEv))) {
278 for (Int_t jPlane=0; jPlane<AliMFTConstants::fNMaxPlanes; jPlane++) {
279 fRecPointsPerPlaneIn[jPlane] = new TClonesArray("AliMFTCluster");
281 TTree *treeInSignal = (TTree*) gDirectory->Get("TreeR");
282 treeInSignal -> SetName("TreeR_InSignal");
284 while (treeInSignal->GetBranch(Form("Plane_%02d",iPlane))) {
285 // printf("Plane %02d\n",iPlane);
286 treeInSignal ->SetBranchAddress(Form("Plane_%02d",iPlane), &(fRecPointsPerPlaneIn[iPlane]));
287 TBranch *branch = treeOutTotal->GetBranch(Form("Plane_%02d",iPlane));
288 if (!branch) treeOutTotal->Branch(Form("Plane_%02d",iPlane), &(fRecPointsPerPlaneOut[iPlane]));
292 treeInSignal -> GetEntry(0);
293 while (treeInSignal->GetBranch(Form("Plane_%02d",iPlane))) {
294 Int_t nClusters = fRecPointsPerPlaneIn[iPlane]->GetEntries();
295 for (Int_t iCluster=0; iCluster<nClusters; iCluster++) {
296 // printf("Cluster %4d\n",iCluster);
297 AliMFTCluster *newCluster = (AliMFTCluster*) fRecPointsPerPlaneIn[iPlane]->At(iCluster);
298 new ((*fRecPointsPerPlaneOut[iPlane])[fRecPointsPerPlaneOut[iPlane]->GetEntries()]) AliMFTCluster(*newCluster);
302 for (Int_t jPlane=0; jPlane<AliMFTConstants::fNMaxPlanes; jPlane++) {
303 delete fRecPointsPerPlaneIn[jPlane];
306 fileInSignal -> Close();
310 treeOutTotal -> Fill();
311 fileOutTotal -> mkdir(Form("Event%d",iEv));
312 fileOutTotal -> cd(Form("Event%d",iEv));
313 treeOutTotal -> SetName("TreeR");
314 treeOutTotal -> Write();
316 fileOutTotal -> Close();
318 for (Int_t jPlane=0; jPlane<AliMFTConstants::fNMaxPlanes; jPlane++) {
319 delete fRecPointsPerPlaneOut[jPlane];
328 //====================================================================================================================================================
330 // LocalWords: nFiles