9 #include <TClonesArray.h>
10 #include <TPolyLine3D.h>
11 #include <TPolyMarker3D.h>
15 #include <AliTrackPointArray.h>
17 #include "AliToyMCDrawer.h"
18 #include "AliToyMCEvent.h"
19 #include "AliToyMCTrack.h"
20 #include <AliCDBManager.h>
21 #include <AliTPCParam.h>
22 #include <AliGeomManager.h>
23 #include <TGeoGlobalMagField.h>
24 #include <AliTPCcalibDB.h>
25 #include <AliTPCROC.h>
28 ClassImp(AliToyMCDrawer);
30 AliToyMCDrawer::AliToyMCDrawer()
42 fEventArray = new TClonesArray("AliToyMCEvent");
44 fTPCParam = AliTPCcalibDB::Instance()->GetParameters();
45 fTPCParam->ReadGeoMatrices();
46 fDriftVel = fTPCParam->GetDriftV();///1000000;
47 fMaxZ0=fTPCParam->GetZLength();
48 fTimeRange = 2*fMaxZ0/fDriftVel;
52 fRoc = AliTPCROC::Instance();
53 fPoints = new TClonesArray("TPolyMarker3D");
54 fDistPoints = new TClonesArray("TPolyMarker3D");
57 //________________________________________________________________
58 AliToyMCDrawer::AliToyMCDrawer(const AliToyMCDrawer &drawer)
60 ,fInputTree(drawer.fInputTree)
61 ,inFile(drawer.inFile)
62 ,fFileName(drawer.fFileName)
63 ,fEvent(drawer.fEvent)
64 ,fEventArray(drawer.fEventArray)
65 ,fDispHist(drawer.fDispHist)
66 , fCenterTime(drawer.fCenterTime)
67 ,fDriftVel(drawer.fDriftVel)
68 ,fTPCParam(drawer.fTPCParam)
69 ,fMaxZ0(drawer.fMaxZ0)
70 ,fOFCRadius(drawer.fOFCRadius)
71 ,fIFCRadius(drawer.fIFCRadius)
72 ,fTimeRange(drawer.fTimeRange)
74 ,fPoints(drawer.fPoints)
75 ,fDistPoints(drawer.fDistPoints)
79 //_____________________________________________________
80 AliToyMCDrawer& AliToyMCDrawer::operator = (const AliToyMCDrawer &drawer)
83 if (&drawer == this) return *this;
84 new (this) AliToyMCDrawer(drawer);
89 //________________________________________________________________
90 AliToyMCDrawer::~AliToyMCDrawer()
99 //________________________________________________________________
100 Int_t AliToyMCDrawer::FillEventArray(Double_t snapShotTime)
103 std::cout << "no input file provided, using default (toyMC.root)" << std::endl;
104 fFileName = "toyMC.root";
107 inFile = new TFile(fFileName,"read");
108 fInputTree = dynamic_cast<TTree*> (inFile->Get("toyMCtree"));
109 fInputTree->SetBranchAddress("event",&fEvent);
110 fEventArray->Clear();
111 fCenterTime = snapShotTime;
112 Int_t leftSearchIndex = Int_t(snapShotTime/2e-5);
113 if(leftSearchIndex>fInputTree->GetEntries()) leftSearchIndex = fInputTree->GetEntries()-1;
114 if(leftSearchIndex<0) leftSearchIndex = 0;
116 fInputTree->GetEvent(leftSearchIndex);
117 Double_t leftTime = fEvent ->GetT0();
118 Int_t firstEventIndex;
119 //if fEvent exactly at snapShotTime, check if there are more events at the same time but with lower indices
120 if( TMath::Abs(leftTime - snapShotTime)<5e-9)
122 // printf("close from start, lefttime = %2.2f\n",leftTime);
123 firstEventIndex = leftSearchIndex+1;
124 while( TMath::Abs(leftTime- snapShotTime) < 5e-9){
126 // printf("close from start, lefttime = %2.2f\n",leftTime);
127 if(fInputTree->GetEvent(firstEventIndex-1))
129 leftTime=fEvent->GetT0();
130 // printf("close from start, lefttime = %2.2f\n",leftTime);
139 Int_t rightSearchIndex = leftSearchIndex;
142 Int_t direction = 1; //go right
143 if(leftTime > snapShotTime) {
146 rightSearchIndex+= direction;
147 fInputTree->GetEvent(rightSearchIndex);
148 rightTime = fEvent->GetT0();
149 //std::cout << "bef search " << leftTime << " " << rightTime<< " " << " " << snapShotTime << " "<< (leftTime-snapShotTime)*(rightTime-snapShotTime) << std::endl;
150 while ( (leftTime-snapShotTime)*(rightTime-snapShotTime)>0 ){
151 // printf("searching, leftime %f, righttim %f\n",leftTime,rightTime);
152 rightSearchIndex += direction;
153 leftSearchIndex +=direction;
154 fInputTree->GetEvent(leftSearchIndex);
155 leftTime = fEvent->GetT0();
156 fInputTree->GetEvent(rightSearchIndex);
157 rightTime = fEvent->GetT0();
158 // printf("searching, leftime %f, righttim %f\n",leftTime,rightTime);
160 if (direction==-1) rightSearchIndex = leftSearchIndex;
161 firstEventIndex = rightSearchIndex;
164 fInputTree->GetEvent(firstEventIndex);
165 //std::cout <<"first event after sn time: " << fEvent->GetT0() << std::endl;
166 return FillEventArray(firstEventIndex);
169 //________________________________________________________________
170 Int_t AliToyMCDrawer::FillEventArray(Int_t middleEventNbr)
173 std::cout << "no input file provided, using default (toyMC.root)" << std::endl;
174 fFileName = "toyMC.root";
176 if(!inFile) inFile = new TFile(fFileName,"read");
179 fInputTree = dynamic_cast<TTree*> (inFile->Get("toyMCtree"));
180 // fInputTree->Add(fileName);
181 fInputTree->SetBranchAddress("event",&fEvent);
182 if(fInputTree->GetEvent(middleEventNbr)) fCenterTime = fEvent->GetT0();
184 Double_t centerEventTime;
185 if(fInputTree->GetEvent(middleEventNbr))
187 centerEventTime = fEvent->GetT0();
191 fEventArray->Clear();
192 if(fInputTree->GetEvent(middleEventNbr)){
193 new((*fEventArray)[fEventArray->GetEntriesFast()]) AliToyMCEvent(*fEvent);
195 //add events after middle event
196 Int_t eventIndex = middleEventNbr + 1;
197 Double_t currentTime = centerEventTime;
198 if(fInputTree->GetEvent(eventIndex)) {
199 currentTime = fEvent->GetT0();
200 while(currentTime - centerEventTime < fTimeRange/2) {
201 new((*fEventArray)[fEventArray->GetEntriesFast()]) AliToyMCEvent(*fEvent);
203 if(!fInputTree->GetEvent(eventIndex)) break;
204 currentTime = fEvent->GetT0();
207 //add events before middle event
208 eventIndex = middleEventNbr - 1;
209 if(fInputTree->GetEvent(eventIndex)){
210 currentTime = fEvent->GetT0();
211 while(centerEventTime-currentTime < fTimeRange/2) {
213 new((*fEventArray)[fEventArray->GetEntriesFast()]) AliToyMCEvent(*fEvent);
215 if(!fInputTree->GetEvent(eventIndex)) break;
216 currentTime = fEvent->GetT0();
222 printf("Selected event number (%d) out of range!\n",middleEventNbr);
225 //return fEventArray;
228 //________________________________________________________________
229 void AliToyMCDrawer::DrawEvents(Bool_t both, Bool_t before)
233 fDistPoints->Clear();
237 Double_t phiCut = 1.;
238 TLegend *leg = new TLegend(0.1,0.75,0.6,1,Form("Snapshot of TPC at %f micros after sim start, freq. = , bunchcr.rate = .",1000000*fCenterTime));
239 leg->AddEntry((TObject*)0,Form("%2.2f<#phi<#pi-%2.2f && #pi+%2.2f<#phi<2#pi-%2.2f",phiCut,phiCut,phiCut,phiCut),"");
244 for(Int_t iEvent = 0; iEvent<fEventArray->GetEntriesFast(); iEvent++){
247 AliToyMCEvent *currentEvent = static_cast<AliToyMCEvent*> (fEventArray->At(iEvent));
248 Double_t currentEventTime = currentEvent->GetT0();
250 if((1000000*currentEventTime)>((1000000*fCenterTime)+0.05 )) {
251 printf("larger iEvent: %d, current %f, center %f\n",iEvent, currentEventTime,fCenterTime);
253 if ( !(both || !before)) continue;
256 if( currentEventTime<=fCenterTime)// && !(currentEventTime==fCenterTime &&both ))
258 printf("smaller iEvent: %d, current %f, center %f\n",iEvent, currentEventTime,fCenterTime);
260 if ( !(both || before)) continue;
263 //std:: cout << "iev " << iEvent << " " << color << std::endl;
264 Double_t currentEventTimeRelToCentral = fCenterTime - currentEventTime;
266 Int_t color = ((currentEvent->GetEventNumber())%10);
267 if(color == 0||color ==1) {
268 color==0?color=2:color=3;
269 // if(iEvent==0) color = 8;
270 // if(iEvent==1) color = 9;
274 char bef[] = "before snapshot time";
275 char aft[] = "after snapshot time";
278 if( 1000000*(currentEventTime-fCenterTime) > 0.5) {when = aft;
282 TGraph *temp = new TGraph();
283 temp->SetName(Form("temp%d",currentEvent->GetEventNumber()));
284 temp->SetLineColor(color);
285 temp->SetLineWidth(10);
287 leg->AddEntry(temp,Form(" %2.2f microseconds %s (global time %2.2f) at z_vertex = %2.2f, centr = ., eventNr: %d", 1000000*sign*currentEventTimeRelToCentral, when, 1000000*currentEvent->GetT0(), currentEvent->GetZ() ,currentEvent->GetEventNumber() ),"l");
290 DrawEvent(currentEvent, fCenterTime, color);
300 //________________________________________________________________
302 void AliToyMCDrawer::DrawEvent(AliToyMCEvent *currentEvent, Double_t centerTime, Int_t color){
303 if(!fDispHist) DrawGeometry();
305 for(Int_t iTrack = 0; iTrack < currentEvent->GetNumberOfTracks(); iTrack++){
307 //Double_t alpha = TMath::ATan2(currentEvent->GetTrack(iTrack)->GetSpacePoint(0)->GetY(),currentEvent->GetTrack(iTrack)->GetSpacePoint(0)->GetX());
308 // if( ( ( !(abs(alpha)>phiCut && abs(alpha) < TMath::Pi() - phiCut) ) ) )continue;
314 //if(currentEvent->GetTrack(iTrack)->GetSpacePoint(0)->GetY()<0) alpha +=TMath::Pi();
315 //if( ( (alpha>phiCut && alpha < TMath::Pi() - phiCut) || ( alpha>TMath::Pi() + phiCut && alpha < TMath::TwoPi() - phiCut)) )continue;
317 // if(alpha > 0) continue;
319 //std::cout << TMath::ASin(tempTrack->GetParameter()[2]) << std::endl;
320 // Double_t x = currentEvent->GetX();
321 // Double_t y = currentEvent->GetY();
322 // Double_t hlxpar[6];
323 // currentEvent->GetTrack(iTrack)->GetHelixParameters(hlxpar,0);
324 // Double_t trackPhi = hlxpar[2];
325 // Double_t phiCut = 1.47;
326 // std::cout << "bef phi cut "<< trackPhi<< std::endl;
328 // std::cout << "aft phi cut " << std::endl;
329 // Double_t trackEta = currentEvent->GetTrack(iTrack)->GetEta();
330 // Double_t z = currentEvent->GetZ();
336 const AliToyMCTrack *tempTrack = currentEvent->GetTrack(iTrack);
337 //AliToyMCTrack *tempTrack = new AliToyMCTrack(*currentEvent->GetTrack(iTrack));
338 DrawTrack(tempTrack, centerTime, currentEvent->GetT0(),color);
356 //________________________________________________________________
357 void AliToyMCDrawer::DrawTrack(const AliToyMCTrack *track, Double_t centerTime, Double_t currentEventTime, Int_t color){
358 if(!fDispHist) DrawGeometry();
360 TPolyMarker3D *disttrackpoints = new((*fDistPoints)[fDistPoints->GetEntriesFast()]) TPolyMarker3D();
361 TPolyMarker3D *trackpoints = new((*fPoints)[fPoints->GetEntriesFast()]) TPolyMarker3D();
363 Double_t currentEventTimeRelToCentral = centerTime - currentEventTime;
364 Int_t nDistPoints = track->GetNumberOfDistSpacePoints();
365 Int_t nPoints = track->GetNumberOfSpacePoints();
367 for(Int_t iPoint = 0; iPoint< (nDistPoints<nPoints?nPoints:nDistPoints);iPoint++){
371 Double_t xp = track->GetSpacePoint(iPoint)->GetX();
372 Double_t yp = track->GetSpacePoint(iPoint)->GetY();
373 Double_t zp = track->GetSpacePoint(iPoint)->GetZ();
374 Double_t zDrifted = zp+(zp/TMath::Abs(zp))*currentEventTimeRelToCentral * fDriftVel;
375 //Double_t zDrifted = (zp/TMath::Abs(zp))*fMaxZ0 -(zp/TMath::Abs(zp))* fDriftVel*(track->GetSpacePoint(iPoint)->GetTimeBin() -centerTime );
376 Float_t xyzp[3] = {xp,yp,zp};
379 Float_t tempcov[6] = {0};
381 Int_t sec = track->GetSpacePoint(iPoint)->GetDetector();
382 Double_t angle=((sec%18)*20.+10.)/TMath::RadToDeg();
383 AliTrackPoint prot = p.Rotate(-angle);
389 if(track->GetSpacePoint(iPoint)->GetRow()!=255) {
390 if(TMath::Abs(zDrifted)<fMaxZ0 && zDrifted*zp >=0 /*&&TMath::Sqrt(xp*xp + yp*yp)<fIFCRadius*/) trackpoints->SetNextPoint(zDrifted,xp,yp);
393 else std::cout << "row == " << track->GetSpacePoint(iPoint)->GetRow() << std::endl;
396 if(iPoint<nDistPoints) {
397 Double_t xpdist = track->GetDistortedSpacePoint(iPoint)->GetX();
398 Double_t ypdist = track->GetDistortedSpacePoint(iPoint)->GetY();
399 Double_t zpdist = track->GetDistortedSpacePoint(iPoint)->GetZ();
400 //std::cout << zpdist << std::endl;
402 Float_t xyzpdist[3] = {xpdist,ypdist,zpdist};
404 pdist.SetXYZ(xyzpdist);
405 Float_t tempcovdist[6] = {0};
406 pdist.SetCov(tempcovdist);
407 Int_t secdist = track->GetDistortedSpacePoint(iPoint)->GetDetector();
408 Double_t angledist=((secdist%18)*20.+10.)/TMath::RadToDeg();
409 AliTrackPoint protdist = pdist.Rotate(-angledist);
410 xpdist = protdist.GetX();
411 ypdist = protdist.GetY();
414 UInt_t sector = track->GetDistortedSpacePoint(iPoint)->GetDetector();
415 UInt_t row = track->GetDistortedSpacePoint(iPoint)->GetRow();
416 UInt_t pad = track->GetDistortedSpacePoint(iPoint)->GetPad();
418 Int_t nPads = fTPCParam->GetNPads(sector,row);
419 Int_t intPad = TMath::Nint(Float_t(pad+nPads/2));
422 //std::cout <<"sector: " << sector << " row: " << row << " pad: " <<pad<< std::endl;
423 fRoc->GetPositionGlobal(sector,row,intPad,xyz);
425 Double_t zDrifteddist = (zpdist/TMath::Abs(zpdist))*fMaxZ0 -(zpdist/TMath::Abs(zpdist))* fDriftVel*(track->GetDistortedSpacePoint(iPoint)->GetTimeBin() -centerTime );
428 if(TMath::Abs(zDrifteddist)<fMaxZ0 && zDrifteddist*zpdist>=0 /*&&TMath::Sqrt(xpdist*xpdist + ypdist*ypdist)<fIFCRadius*/) {
430 disttrackpoints->SetNextPoint(zDrifteddist,xpdist,ypdist);
431 //if(TMath::Sqrt(xpdist*xpdist + ypdist*ypdist)<fIFCRadius) std::cout << "fMaxZ0 " << fMaxZ0 <<" inside " << xpdist << " " << "zpdist " << zpdist << " " << "zDrifteddist "<< zDrifteddist << " " << zDrifteddist*zpdist << std::endl;
434 else std::cout << "row == " << row << std::endl;
435 //Double_t zDrifteddist =(zpdist/TMath::Abs(zpdist))*fMaxZ0 -(zpdist/TMath::Abs(zpdist))*(currentEvent->GetTrack(iTrack)->GetDistortedSpacePoint(iPoint)->GetTimeBin()- currentEvent->GetT0() )* fDriftVel;
439 // if( ( (trackPhi>phiCut && trackPhi < TMath::Pi() - phiCut) || ( trackPhi>TMath::Pi() + phiCut && trackPhi < TMath::TwoPi() - phiCut)) ) {
447 if(trackpoints && trackpoints->GetN()>0) {
448 // trackpoints->SetMarkerColor(1+currentEvent->GetEventNumber()%9);
449 //trackpoints->SetMarkerStyle(7);
450 trackpoints->Draw("same");
452 if(disttrackpoints && disttrackpoints->GetN()>0) {
455 disttrackpoints->SetMarkerColor(color);
458 disttrackpoints->Draw("same");
469 //________________________________________________________________
470 void AliToyMCDrawer::DrawGeometry() {
474 //fDispGraph = new TGraph2D();
477 fDispHist = new TH3F("fDispHist","",100,-fMaxZ0, fMaxZ0, 100,-(fOFCRadius +10), fOFCRadius +10,100,-(fOFCRadius +10), fOFCRadius +10);
478 //if(!fDispGraph) fDispGraph = new TGraph();
480 //fDispGraph->Clear();
481 fDispHist->SetStats(0);
482 fDispHist->GetXaxis()->SetTitle("z [cm]");
483 fDispHist->GetYaxis()->SetTitle("x [cm]");
484 fDispHist->GetZaxis()->SetTitle("y [cm]");
488 TPolyLine3D *endCap1 = new TPolyLine3D();
489 TPolyLine3D *endCap2 = new TPolyLine3D();
490 TPolyLine3D *cage[16] ={0x0};
491 TPolyLine3D *innerCage[16] ={0x0};
492 TPolyLine3D *innerEndCap1 = new TPolyLine3D();
493 TPolyLine3D *innerEndCap2 = new TPolyLine3D();
494 for(Int_t i = 0; i<16; i++){
496 cage[i] = new TPolyLine3D();
497 cage[i]->SetPoint(0,-fMaxZ0,fOFCRadius*TMath::Cos(i*TMath::TwoPi()/16) ,fOFCRadius*TMath::Sin(i*TMath::TwoPi()/16)) ;
498 cage[i]->SetPoint(1,fMaxZ0,fOFCRadius*TMath::Cos(i*TMath::TwoPi()/16) ,fOFCRadius*TMath::Sin(i*TMath::TwoPi()/16)) ;
499 innerCage[i] = new TPolyLine3D();
500 innerCage[i]->SetPoint(0,-fMaxZ0,fIFCRadius*TMath::Cos(i*TMath::TwoPi()/16) ,fIFCRadius*TMath::Sin(i*TMath::TwoPi()/16)) ;
501 innerCage[i]->SetPoint(1,fMaxZ0,fIFCRadius*TMath::Cos(i*TMath::TwoPi()/16) ,fIFCRadius*TMath::Sin(i*TMath::TwoPi()/16)) ;
503 endCap1->SetPoint(i,fMaxZ0,fOFCRadius*TMath::Cos(i*TMath::TwoPi()/16) ,fOFCRadius*TMath::Sin(i*TMath::TwoPi()/16)) ;
504 endCap2->SetPoint(i,-fMaxZ0,fOFCRadius*TMath::Cos(i*TMath::TwoPi()/16) ,fOFCRadius*TMath::Sin(i*TMath::TwoPi()/16)) ;
506 innerEndCap1->SetPoint(i,fMaxZ0,fIFCRadius*TMath::Cos(i*TMath::TwoPi()/16) ,fIFCRadius*TMath::Sin(i*TMath::TwoPi()/16)) ;
507 innerEndCap2->SetPoint(i,-fMaxZ0,fIFCRadius*TMath::Cos(i*TMath::TwoPi()/16) ,fIFCRadius*TMath::Sin(i*TMath::TwoPi()/16)) ;
508 innerCage[i]->Draw("same");
509 if(!(i%2)) cage[i]->Draw("same");
512 endCap1->SetPoint(16,fMaxZ0,fOFCRadius*TMath::Cos(16*TMath::TwoPi()/16) ,fOFCRadius*TMath::Sin(16*TMath::TwoPi()/16)) ;
513 endCap2->SetPoint(16,-fMaxZ0,fOFCRadius*TMath::Cos(16*TMath::TwoPi()/16) ,fOFCRadius*TMath::Sin(16*TMath::TwoPi()/16)) ;
515 innerEndCap1->SetPoint(16,fMaxZ0,fIFCRadius*TMath::Cos(16*TMath::TwoPi()/16) ,fIFCRadius*TMath::Sin(16*TMath::TwoPi()/16)) ;
516 innerEndCap2->SetPoint(16,-fMaxZ0,fIFCRadius*TMath::Cos(16*TMath::TwoPi()/16) ,fIFCRadius*TMath::Sin(16*TMath::TwoPi()/16)) ;
519 //fDispGraph->SetTitle("ToyMC display");
521 endCap1->Draw("same");
522 endCap2->Draw("same");
524 innerEndCap2->Draw("same");
525 innerEndCap1->Draw("same");