]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FEMTOSCOPY/AliFemto/AliFemtoLikeSignAnalysis.cxx
More coding rule conformance
[u/mrichter/AliRoot.git] / PWG2 / FEMTOSCOPY / AliFemto / AliFemtoLikeSignAnalysis.cxx
1 ///////////////////////////////////////////////////////////////////////////
2 //                                                                       //
3 // This is an analysis which calculated the background from like sign    //
4 // pairs in the same event                                               //
5 //                                                                       //
6 ///////////////////////////////////////////////////////////////////////////
7
8 #include "AliFemtoLikeSignAnalysis.h"
9 #include "AliFemtoParticleCollection.h"
10 #include "AliFemtoPicoEventCollectionVector.h"
11 #include "AliFemtoPicoEventCollectionVectorHideAway.h"
12
13 #ifdef __ROOT__ 
14 ClassImp(AliFemtoLikeSignAnalysis)
15 #endif
16
17 // this little function used to apply ParticleCuts (TrackCuts or V0Cuts) and fill ParticleCollections of picoEvent
18 //  it is called from AliFemtoAnalysis::ProcessEvent()
19
20
21 extern void FillHbtParticleCollection(AliFemtoParticleCut*         partCut,
22                                      AliFemtoEvent*               hbtEvent,
23                                      AliFemtoParticleCollection*  partCollection);
24
25  
26 //____________________________
27 AliFemtoLikeSignAnalysis::AliFemtoLikeSignAnalysis(unsigned int bins, double min, double max) : 
28   AliFemtoAnalysis(),
29   fVertexBins(0),
30   fOverFlow(0),  
31   fUnderFlow(0)  
32 {
33   // standard constructor
34   fVertexBins = bins;
35   fVertexZ[0] = min;
36   fVertexZ[1] = max;
37   fUnderFlow = 0; 
38   fOverFlow = 0; 
39   if (fMixingBuffer) delete fMixingBuffer;
40   fPicoEventCollectionVectorHideAway = new AliFemtoPicoEventCollectionVectorHideAway(fVertexBins,fVertexZ[0],fVertexZ[1]);
41     /* no-op */
42 }
43 //____________________________
44 AliFemtoLikeSignAnalysis::AliFemtoLikeSignAnalysis(const AliFemtoLikeSignAnalysis& a) : 
45   AliFemtoAnalysis(a) ,
46   fVertexBins(0),
47   fOverFlow(0),  
48   fUnderFlow(0)  
49 {
50   // copy constructor
51   fVertexBins = a.fVertexBins; 
52   fVertexZ[0] = a.fVertexZ[0]; 
53   fVertexZ[1] = a.fVertexZ[1];
54   fUnderFlow = 0; 
55   fOverFlow = 0; 
56   if (fMixingBuffer) delete fMixingBuffer;
57   fPicoEventCollectionVectorHideAway = new AliFemtoPicoEventCollectionVectorHideAway(fVertexBins,fVertexZ[0],fVertexZ[1]);
58  }
59 //____________________________ 
60 AliFemtoLikeSignAnalysis::~AliFemtoLikeSignAnalysis(){
61   // destructor
62   delete fPicoEventCollectionVectorHideAway; fPicoEventCollectionVectorHideAway=0;
63 }
64 //____________________________
65 AliFemtoString AliFemtoLikeSignAnalysis::Report()
66 {  
67   // prepare report
68   char tCtemp[200];
69   cout << "AliFemtoLikeSignAnalysis - constructing Report..."<<endl;
70   AliFemtoString temp = "-----------\nHbt Analysis Report:\n";
71   sprintf(tCtemp,"Events are mixed in %d bins in the range %E cm to %E cm.\n",fVertexBins,fVertexZ[0],fVertexZ[1]);
72   temp += tCtemp;
73   sprintf(tCtemp,"Events underflowing: %d\n",fUnderFlow);
74   temp += tCtemp;
75   sprintf(tCtemp,"Events overflowing: %d\n",fOverFlow);
76   temp += tCtemp;
77   sprintf(tCtemp,"Now adding AliFemtoAnalysis(base) Report\n");
78   temp += tCtemp; 
79   temp += "Adding AliFemtoAnalysis(base) Report now:\n";
80   temp += AliFemtoAnalysis::Report();
81   temp += "-------------\n";
82   AliFemtoString returnThis=temp;
83   return returnThis;
84 }
85 //_________________________
86 void AliFemtoLikeSignAnalysis::ProcessEvent(const AliFemtoEvent* hbtEvent) {
87   // perform all the analysis tasks for a single event
88   // get right mixing buffer
89   double vertexZ = hbtEvent->PrimVertPos().z();
90   fMixingBuffer = fPicoEventCollectionVectorHideAway->PicoEventCollection(vertexZ); 
91   if (!fMixingBuffer) {
92     if ( vertexZ < fVertexZ[0] ) fUnderFlow++;
93     if ( vertexZ > fVertexZ[1] ) fOverFlow++;
94     return;
95   }
96
97   // startup for EbyE 
98   EventBegin(hbtEvent);  
99   // event cut and event cut monitor
100   bool tmpPassEvent = fEventCut->Pass(hbtEvent);
101   fEventCut->FillCutMonitor(hbtEvent, tmpPassEvent);
102   if (tmpPassEvent) {
103       fNeventsProcessed++;
104       cout << "AliFemtoLikeSignAnalysis::ProcessEvent() - " << hbtEvent->TrackCollection()->size();
105       cout << " #track=" << hbtEvent->TrackCollection()->size();
106       // OK, analysis likes the event-- build a pico event from it, using tracks the analysis likes...
107       AliFemtoPicoEvent* picoEvent = new AliFemtoPicoEvent;       // this is what we will make pairs from and put in Mixing Buffer
108       FillHbtParticleCollection(fFirstParticleCut,(AliFemtoEvent*)hbtEvent,picoEvent->FirstParticleCollection());
109       if ( !(AnalyzeIdenticalParticles()) )
110         FillHbtParticleCollection(fSecondParticleCut,(AliFemtoEvent*)hbtEvent,picoEvent->SecondParticleCollection());
111       cout <<"   #particles in First, Second Collections: " <<
112         picoEvent->FirstParticleCollection()->size() << " " <<
113         picoEvent->SecondParticleCollection()->size() << endl;
114       
115       if (picoEvent->SecondParticleCollection()->size()*picoEvent->FirstParticleCollection()->size()==0) {
116         delete picoEvent;
117         cout << "AliFemtoLikeSignAnalysis - picoEvent deleted due to empty collection " <<endl; 
118         return;
119       }
120       // OK, pico event is built
121       // make real pairs...
122       
123       // Fabrice points out that we do not need to keep creating/deleting pairs all the time
124       // We only ever need ONE pair, and we can just keep changing internal pointers
125       // this should help speed things up
126       AliFemtoPair* tThePair = new AliFemtoPair;
127       
128       AliFemtoParticleIterator tPartIter1;
129       AliFemtoParticleIterator tPartIter2;
130       AliFemtoCorrFctnIterator tCorrFctnIter;
131       AliFemtoParticleIterator tStartOuterLoop = picoEvent->FirstParticleCollection()->begin();  // always
132       AliFemtoParticleIterator tEndOuterLoop   = picoEvent->FirstParticleCollection()->end();    // will be one less if identical
133       AliFemtoParticleIterator tStartInnerLoop;
134       AliFemtoParticleIterator tEndInnerLoop;
135       if (AnalyzeIdenticalParticles()) {             // only use First collection
136         tEndOuterLoop--;                                               // outer loop goes to next-to-last particle in First collection
137         tEndInnerLoop = picoEvent->FirstParticleCollection()->end() ;  // inner loop goes to last particle in First collection
138       }
139       else {                                                          // nonidentical - loop over First and Second collections
140         tStartInnerLoop = picoEvent->SecondParticleCollection()->begin(); // inner loop starts at first particle in Second collection
141         tEndInnerLoop   = picoEvent->SecondParticleCollection()->end() ;  // inner loop goes to last particle in Second collection
142       }
143       // real pairs
144       for (tPartIter1=tStartOuterLoop;tPartIter1!=tEndOuterLoop;tPartIter1++){
145         if (AnalyzeIdenticalParticles()){
146           tStartInnerLoop = tPartIter1;
147           tStartInnerLoop++;
148         }
149         tThePair->SetTrack1(*tPartIter1);
150         for (tPartIter2 = tStartInnerLoop; tPartIter2!=tEndInnerLoop;tPartIter2++){
151           tThePair->SetTrack2(*tPartIter2);
152           // The following lines have to be uncommented if you want pairCutMonitors
153           // they are not in for speed reasons
154           // bool tmpPassPair = mPairCut->Pass(tThePair);
155           // mPairCut->FillCutMonitor(tThePair, tmpPassPair);
156           // if ( tmpPassPair ) {
157           if (fPairCut->Pass(tThePair)){
158             for (tCorrFctnIter=fCorrFctnCollection->begin();
159                  tCorrFctnIter!=fCorrFctnCollection->end();tCorrFctnIter++){
160               AliFemtoLikeSignCorrFctn* tCorrFctn = dynamic_cast<AliFemtoLikeSignCorrFctn*>(*tCorrFctnIter);
161               if (tCorrFctn) tCorrFctn->AddRealPair(tThePair);
162             }
163           }  // if passed pair cut
164         }    // loop over second particle
165       }      // loop over first particle
166 #ifdef STHBTDEBUG
167       cout << "AliFemtoLikeSignAnalysis::ProcessEvent() - reals done" << endl;
168 #endif
169
170       AliFemtoParticleIterator nextIter;
171       AliFemtoParticleIterator prevIter;
172
173       // like sign first partilce collection pairs
174       prevIter = tEndOuterLoop;
175       prevIter--;
176       for (tPartIter1=tStartOuterLoop;tPartIter1!=prevIter;tPartIter1++){
177         tThePair->SetTrack1(*tPartIter1);
178         nextIter = tPartIter1;
179         nextIter++;
180         for (tPartIter2 = nextIter; tPartIter2!=tEndOuterLoop;tPartIter2++){
181           tThePair->SetTrack2(*tPartIter2);
182           // The following lines have to be uncommented if you want pairCutMonitors
183           // they are not in for speed reasons
184           // bool tmpPassPair = mPairCut->Pass(tThePair);
185           // mPairCut->FillCutMonitor(tThePair, tmpPassPair);
186           // if ( tmpPassPair ) {
187           if (fPairCut->Pass(tThePair)){
188             for (tCorrFctnIter=fCorrFctnCollection->begin();
189                  tCorrFctnIter!=fCorrFctnCollection->end();tCorrFctnIter++){
190               AliFemtoLikeSignCorrFctn* CorrFctn = dynamic_cast<AliFemtoLikeSignCorrFctn*>(*tCorrFctnIter);
191               if (CorrFctn) CorrFctn->AddLikeSignPositivePair(tThePair);
192             }
193           }  // if passed pair cut
194         }    // loop over second particle
195       }      // loop over first particle
196 #ifdef STHBTDEBUG
197       cout << "AliFemtoLikeSignAnalysis::ProcessEvent() - like sign first collection done" << endl;
198 #endif
199       // like sign second partilce collection pairs
200       prevIter = tEndInnerLoop;
201       prevIter--;
202       for (tPartIter1=tStartInnerLoop;tPartIter1!=prevIter;tPartIter1++){
203         tThePair->SetTrack1(*tPartIter1);
204         nextIter = tPartIter1;
205         nextIter++;
206         for (tPartIter2 = nextIter; tPartIter2!=tEndInnerLoop;tPartIter2++){
207           tThePair->SetTrack2(*tPartIter2);
208           // The following lines have to be uncommented if you want pairCutMonitors
209           // they are not in for speed reasons
210           // bool tmpPassPair = mPairCut->Pass(tThePair);
211           // mPairCut->FillCutMonitor(tThePair, tmpPassPair);
212           // if ( tmpPassPair ) {
213           if (fPairCut->Pass(tThePair)){
214             for (tCorrFctnIter=fCorrFctnCollection->begin();
215                  tCorrFctnIter!=fCorrFctnCollection->end();tCorrFctnIter++){
216               AliFemtoLikeSignCorrFctn* tCorrFctn = dynamic_cast<AliFemtoLikeSignCorrFctn*>(*tCorrFctnIter);
217               if (tCorrFctn) tCorrFctn->AddLikeSignNegativePair(tThePair);
218             }
219           }  // if passed pair cut
220         }    // loop over second particle
221       }      // loop over first particle
222 #ifdef STHBTDEBUG
223       cout << "AliFemtoLikeSignAnalysis::ProcessEvent() - like sign second collection done" << endl;
224 #endif
225       
226       if (MixingBufferFull()){
227 #ifdef STHBTDEBUG
228         cout << "Mixing Buffer is full - lets rock and roll" << endl;
229 #endif
230       }
231       else {
232         cout << "Mixing Buffer not full -gotta wait " << MixingBuffer()->size() << endl;
233       }
234       if (MixingBufferFull()){
235         tStartOuterLoop = picoEvent->FirstParticleCollection()->begin();
236         tEndOuterLoop   = picoEvent->FirstParticleCollection()->end();
237         AliFemtoPicoEvent* storedEvent;
238         AliFemtoPicoEventIterator picoEventIter;
239         for (picoEventIter=MixingBuffer()->begin();picoEventIter!=MixingBuffer()->end();picoEventIter++){
240           storedEvent = *picoEventIter;
241           if (AnalyzeIdenticalParticles()){
242             tStartInnerLoop = storedEvent->FirstParticleCollection()->begin();
243             tEndInnerLoop = storedEvent->FirstParticleCollection()->end();
244           }
245           else{
246             tStartInnerLoop = storedEvent->SecondParticleCollection()->begin();
247             tEndInnerLoop = storedEvent->SecondParticleCollection()->end();
248           }
249           for (tPartIter1=tStartOuterLoop;tPartIter1!=tEndOuterLoop;tPartIter1++){
250             tThePair->SetTrack1(*tPartIter1);
251             for (tPartIter2=tStartInnerLoop;tPartIter2!=tEndInnerLoop;tPartIter2++){
252               tThePair->SetTrack2(*tPartIter2);
253               // testing...           cout << "tThePair defined... going to pair cut... ";
254               if (fPairCut->Pass(tThePair)){
255                 // testing...           cout << " tThePair passed PairCut... ";
256                 for (tCorrFctnIter=fCorrFctnCollection->begin();
257                      tCorrFctnIter!=fCorrFctnCollection->end();tCorrFctnIter++){
258                   AliFemtoLikeSignCorrFctn* tCorrFctn = dynamic_cast<AliFemtoLikeSignCorrFctn*>(*tCorrFctnIter);
259                   if (tCorrFctn) { 
260                     tCorrFctn->AddMixedPair(tThePair);
261                     //cout << " tThePair has been added to MixedPair method " << endl;
262                   }
263                 }
264               }  // if passed pair cut
265             }    // loop over second particle
266           }      // loop over first particle
267         }        // loop over pico-events stored in Mixing buffer
268         // Now get rid of oldest stored pico-event in buffer.
269         // This means (1) delete the event from memory, (2) "pop" the pointer to it from the MixingBuffer
270         delete MixingBuffer()->back();
271         MixingBuffer()->pop_back();
272       }  // if mixing buffer is full
273       delete tThePair;
274       MixingBuffer()->push_front(picoEvent);  // store the current pico-event in buffer
275     }   // if currentEvent is accepted by currentAnalysis
276     EventEnd(hbtEvent);  // cleanup for EbyE 
277     //    cout << "AliFemtoLikeSignAnalysis::ProcessEvent() - return to caller ... " << endl;
278 }
279
280
281