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 option = 9999,
35 Int_t maxPileUp = 9999) {
37 if (option==kMergePileUpClusters_pp) {
39 Int_t runs_pp[fNRunsPileUp_pp] = {0};
41 while (nFiles_pp<TMath::Min(fNRunsPileUp_pp,maxPileUp)) {
42 Int_t run = gRandom->Integer(fNRunsPileUpAvailable[k_pp]);
43 fileInPileUp = new TFile(Form("%s/run_%d/MFT.RecPoints.MCShifted.root",fPileUpDir[k_pp],run));
44 if (!fileInPileUp->IsOpen() || !fileInPileUp->cd("Event0")) {
48 Bool_t runAlreadyLoaded=kFALSE;
49 for (Int_t iAddedRun=0; iAddedRun<nFiles_pp; iAddedRun++) {
50 if (run==runs_pp[iAddedRun]) {
51 runAlreadyLoaded=kTRUE;
55 if (!runAlreadyLoaded) runs_pp[nFiles_pp++] = run;
58 MergePileUpClusters(runs_pp, TMath::Min(fNRunsPileUp_pp,maxPileUp), fPileUpDir[k_pp], nEvents);
61 else if (option==kMergePileUpClusters_PbPb) {
62 Int_t runs_PbPb[fNRunsPileUp_PbPb] = {0};
63 Int_t nFiles_PbPb = 0;
64 while (nFiles_PbPb<TMath::Min(fNRunsPileUp_PbPb,maxPileUp)) {
65 Int_t run = gRandom->Integer(fNRunsPileUpAvailable[k_PbPb]);
66 fileInPileUp = new TFile(Form("%s/run_%d/MFT.RecPoints.MCShifted.root",fPileUpDir[k_PbPb],run));
67 if (!fileInPileUp->IsOpen() || !fileInPileUp->cd("Event0")) {
71 Bool_t runAlreadyLoaded=kFALSE;
72 for (Int_t iAddedRun=0; iAddedRun<nFiles_PbPb; iAddedRun++) {
73 if (run==runs_PbPb[iAddedRun]) {
74 runAlreadyLoaded=kTRUE;
78 if (!runAlreadyLoaded) runs_PbPb[nFiles_PbPb++] = run;
81 MergePileUpClusters(runs_PbPb, TMath::Min(fNRunsPileUp_PbPb,maxPileUp), fPileUpDir[k_PbPb], nEvents);
84 if (option>=kMergeAllClusters_pp) MergeAllClusters();
88 //====================================================================================================================================================
90 void MergePileUpClusters(Int_t *runs, Int_t nRunsPileUp, const Char_t *pileUpDir, Int_t nEvents) {
92 fileOutPileUp = new TFile("./MFT.RecPoints.PileUp.root", "recreate");
94 Bool_t eventExist = kTRUE;
97 while (eventExist && iEv<nEvents) {
99 for (Int_t iPlane=0; iPlane<AliMFTConstants::fNMaxPlanes; iPlane++) {
100 fRecPointsPerPlaneOut[iPlane] = new TClonesArray("AliMFTCluster");
103 if (iEv) fileOutPileUp = new TFile("./MFT.RecPoints.PileUp.root", "update");
105 printf("Merging Event %d\n",iEv);
107 fileOutPileUp-> cd();
108 TTree *treeOutPileUp = new TTree("TreeR_OutPileUp", "Reconstructed Points Container");
110 Int_t nFilesAdded = 0;
111 while (nFilesAdded<nRunsPileUp) {
112 fileInPileUp = new TFile(Form("%s/run_%d/MFT.RecPoints.MCShifted.root",pileUpDir,runs[nFilesAdded++]));
113 printf("Merging file %s\n", fileInPileUp->GetName());
114 if (!fileInPileUp->cd(Form("Event%d",iEv))) {
118 for (Int_t iPlane=0; iPlane<AliMFTConstants::fNMaxPlanes; iPlane++) {
119 fRecPointsPerPlaneIn[iPlane] = new TClonesArray("AliMFTCluster");
121 TTree *treeInPileUp = (TTree*) gDirectory->Get("TreeR");
122 treeInPileUp -> SetName("TreeR_InPileUp");
124 while (treeInPileUp->GetBranch(Form("Plane_%02d",iPlane))) {
125 // printf("Plane %02d\n",iPlane);
126 treeInPileUp ->SetBranchAddress(Form("Plane_%02d",iPlane), &(fRecPointsPerPlaneIn[iPlane]));
127 TBranch *branch = treeOutPileUp->GetBranch(Form("Plane_%02d",iPlane));
128 if (!branch) treeOutPileUp->Branch(Form("Plane_%02d",iPlane), &(fRecPointsPerPlaneOut[iPlane]));
132 treeInPileUp -> GetEntry(0);
133 while (treeInPileUp->GetBranch(Form("Plane_%02d",iPlane))) {
134 Int_t nClusters = fRecPointsPerPlaneIn[iPlane]->GetEntries();
135 for (Int_t iCluster=0; iCluster<nClusters; iCluster++) {
136 // printf("Cluster %4d\n",iCluster);
137 AliMFTCluster *newCluster = (AliMFTCluster*) fRecPointsPerPlaneIn[iPlane]->At(iCluster);
138 new ((*fRecPointsPerPlaneOut[iPlane])[fRecPointsPerPlaneOut[iPlane]->GetEntries()]) AliMFTCluster(*newCluster);
142 for (Int_t jPlane=0; jPlane<AliMFTConstants::fNMaxPlanes; jPlane++) {
143 delete fRecPointsPerPlaneIn[jPlane];
146 fileInPileUp -> Close();
150 treeOutPileUp -> Fill();
151 fileOutPileUp -> mkdir(Form("Event%d",iEv));
152 fileOutPileUp -> cd(Form("Event%d",iEv));
153 treeOutPileUp -> SetName("TreeR");
154 treeOutPileUp -> Write();
155 delete treeOutPileUp;
156 fileOutPileUp -> Close();
157 delete fileOutPileUp;
158 for (Int_t iPlane=0; iPlane<AliMFTConstants::fNMaxPlanes; iPlane++) {
159 delete fRecPointsPerPlaneOut[iPlane];
167 //====================================================================================================================================================
169 void MergeAllClusters() {
171 fileOutTotal = new TFile("./MFT.RecPoints.root", "recreate");
173 Bool_t eventExist = kTRUE;
178 for (Int_t iPlane=0; iPlane<AliMFTConstants::fNMaxPlanes; iPlane++) {
179 fRecPointsPerPlaneOut[iPlane] = new TClonesArray("AliMFTCluster");
182 if (iEv) fileOutTotal = new TFile("./MFT.RecPoints.root", "update");
184 printf("Merging Event %d\n",iEv);
187 TTree *treeOutTotal = new TTree("TreeR_Out", "Reconstructed Points Container");
189 // Adding Pile-Up Clusters
191 fileInPileUp = new TFile("./MFT.RecPoints.PileUp.root");
192 printf("Merging file %s\n", fileInPileUp->GetName());
193 if (!fileInPileUp->cd(Form("Event%d",iEv))) {
197 for (Int_t jPlane=0; jPlane<AliMFTConstants::fNMaxPlanes; jPlane++) {
198 fRecPointsPerPlaneIn[jPlane] = new TClonesArray("AliMFTCluster");
200 TTree *treeInPileUp = (TTree*) gDirectory->Get("TreeR");
201 treeInPileUp -> SetName("TreeR_InPileUp");
203 while (treeInPileUp->GetBranch(Form("Plane_%02d",iPlane))) {
204 // printf("Plane %02d\n",iPlane);
205 treeInPileUp ->SetBranchAddress(Form("Plane_%02d",iPlane), &(fRecPointsPerPlaneIn[iPlane]));
206 TBranch *branch = treeOutTotal->GetBranch(Form("Plane_%02d",iPlane));
207 if (!branch) treeOutTotal->Branch(Form("Plane_%02d",iPlane), &(fRecPointsPerPlaneOut[iPlane]));
211 treeInPileUp -> GetEntry(0);
212 while (treeInPileUp->GetBranch(Form("Plane_%02d",iPlane))) {
213 Int_t nClusters = fRecPointsPerPlaneIn[iPlane]->GetEntries();
214 for (Int_t iCluster=0; iCluster<nClusters; iCluster++) {
215 // printf("Cluster %4d\n",iCluster);
216 AliMFTCluster *newCluster = (AliMFTCluster*) fRecPointsPerPlaneIn[iPlane]->At(iCluster);
217 new ((*fRecPointsPerPlaneOut[iPlane])[fRecPointsPerPlaneOut[iPlane]->GetEntries()]) AliMFTCluster(*newCluster);
221 for (Int_t jPlane=0; jPlane<AliMFTConstants::fNMaxPlanes; jPlane++) {
222 delete fRecPointsPerPlaneIn[jPlane];
225 fileInPileUp -> Close();
228 // Adding Underlying Event Clusters
230 fileInUnderlying = new TFile("./MFT.RecPoints.Underlying.root");
231 printf("Merging file %s\n", fileInUnderlying->GetName());
232 if (!fileInUnderlying->cd(Form("Event%d",iEv))) {
236 for (Int_t jPlane=0; jPlane<AliMFTConstants::fNMaxPlanes; jPlane++) {
237 fRecPointsPerPlaneIn[jPlane] = new TClonesArray("AliMFTCluster");
239 TTree *treeInUnderlying = (TTree*) gDirectory->Get("TreeR");
240 treeInUnderlying -> SetName("TreeR_InUnderlying");
242 while (treeInUnderlying->GetBranch(Form("Plane_%02d",iPlane))) {
243 // printf("Plane %02d\n",iPlane);
244 treeInUnderlying ->SetBranchAddress(Form("Plane_%02d",iPlane), &(fRecPointsPerPlaneIn[iPlane]));
245 TBranch *branch = treeOutTotal->GetBranch(Form("Plane_%02d",iPlane));
246 if (!branch) treeOutTotal->Branch(Form("Plane_%02d",iPlane), &(fRecPointsPerPlaneOut[iPlane]));
250 treeInUnderlying -> GetEntry(0);
251 while (treeInUnderlying->GetBranch(Form("Plane_%02d",iPlane))) {
252 Int_t nClusters = fRecPointsPerPlaneIn[iPlane]->GetEntries();
253 for (Int_t iCluster=0; iCluster<nClusters; iCluster++) {
254 // printf("Cluster %4d\n",iCluster);
255 AliMFTCluster *newCluster = (AliMFTCluster*) fRecPointsPerPlaneIn[iPlane]->At(iCluster);
256 new ((*fRecPointsPerPlaneOut[iPlane])[fRecPointsPerPlaneOut[iPlane]->GetEntries()]) AliMFTCluster(*newCluster);
260 for (Int_t jPlane=0; jPlane<AliMFTConstants::fNMaxPlanes; jPlane++) {
261 delete fRecPointsPerPlaneIn[jPlane];
263 delete treeInUnderlying;
264 fileInUnderlying -> Close();
265 delete fileInUnderlying;
267 // Adding Signal Clusters
269 fileInSignal = new TFile("./MFT.RecPoints.Signal.root");
270 printf("Merging file %s\n", fileInSignal->GetName());
271 if (!fileInSignal->cd(Form("Event%d",iEv))) {
275 for (Int_t jPlane=0; jPlane<AliMFTConstants::fNMaxPlanes; jPlane++) {
276 fRecPointsPerPlaneIn[jPlane] = new TClonesArray("AliMFTCluster");
278 TTree *treeInSignal = (TTree*) gDirectory->Get("TreeR");
279 treeInSignal -> SetName("TreeR_InSignal");
281 while (treeInSignal->GetBranch(Form("Plane_%02d",iPlane))) {
282 // printf("Plane %02d\n",iPlane);
283 treeInSignal ->SetBranchAddress(Form("Plane_%02d",iPlane), &(fRecPointsPerPlaneIn[iPlane]));
284 TBranch *branch = treeOutTotal->GetBranch(Form("Plane_%02d",iPlane));
285 if (!branch) treeOutTotal->Branch(Form("Plane_%02d",iPlane), &(fRecPointsPerPlaneOut[iPlane]));
289 treeInSignal -> GetEntry(0);
290 while (treeInSignal->GetBranch(Form("Plane_%02d",iPlane))) {
291 Int_t nClusters = fRecPointsPerPlaneIn[iPlane]->GetEntries();
292 for (Int_t iCluster=0; iCluster<nClusters; iCluster++) {
293 // printf("Cluster %4d\n",iCluster);
294 AliMFTCluster *newCluster = (AliMFTCluster*) fRecPointsPerPlaneIn[iPlane]->At(iCluster);
295 new ((*fRecPointsPerPlaneOut[iPlane])[fRecPointsPerPlaneOut[iPlane]->GetEntries()]) AliMFTCluster(*newCluster);
299 for (Int_t jPlane=0; jPlane<AliMFTConstants::fNMaxPlanes; jPlane++) {
300 delete fRecPointsPerPlaneIn[jPlane];
303 fileInSignal -> Close();
307 treeOutTotal -> Fill();
308 fileOutTotal -> mkdir(Form("Event%d",iEv));
309 fileOutTotal -> cd(Form("Event%d",iEv));
310 treeOutTotal -> SetName("TreeR");
311 treeOutTotal -> Write();
313 fileOutTotal -> Close();
315 for (Int_t jPlane=0; jPlane<AliMFTConstants::fNMaxPlanes; jPlane++) {
316 delete fRecPointsPerPlaneOut[jPlane];
325 //====================================================================================================================================================
327 // LocalWords: nFiles