7  #include <TStopwatch.h> 
   10  #include <TGeoManager.h> 
   11  #include <TClonesArray.h> 
   18  #include <TStopwatch.h> 
   21  #include <TProfile2D.h> 
   44   gROOT->LoadMacro(
"../run/Tools.C");
 
   67   std::string 
inFile = 
"../../geometry/pndcave.geo";
 
   68   std::string inFile = 
"../../geometry/pipebeamtarget.geo";
 
   69   std::string inFile = 
"../../geometry/gem_3Stations_realistic_v1.root";
 
   72   TFile* 
f = 
new TFile(MCFile.Data()); 
 
   73   TTree* 
t =(TTree *) f->Get(
"pndsim") ;
 
   74   TFile* 
par = TFile::Open(parFile.Data());
 
   76   cout << 
"file name = " << f->GetName() << 
", tree = " << t->GetName() << endl;
 
   78   TClonesArray* 
mc_array=
new TClonesArray(
"PndMCTrack");
 
   79   t->SetBranchAddress(
"MCTrack",&mc_array );
 
   81   TClonesArray* rad_array=
new TClonesArray(
"FairRadLenPoint");
 
   82   t->SetBranchAddress(
"RadLen",&rad_array);
 
   85   TGeoManager *
geoMan = (TGeoManager*) gDirectory->Get(
"FairGeoParSet");
 
   90   int res = 1000; 
int angres = 180;
 
   91   TH1D* hRadLenDistMat = 
new TH1D(
"radldm",
"Material thicknesses",100,0,15);
 
   92   TH1D* hRadLenDistEff = 
new TH1D(
"radlde",
"Effective Radiation length values per volume",100,0,0.2);
 
   93   TH2D* 
hisxy = 
new TH2D(
"hisxy",
"MC Points, xy view",res,-85.,85.,res,-85.,85.);
 
   94   TH2D* 
hisrz = 
new TH2D(
"hisrz",
"MC Points, rz view",res,-90.,210.,res,-85.,85.);
 
   96   TClonesArray* arrhisxy = 
new TClonesArray(
"TH2D");
 
   97   TClonesArray* arrhisrz = 
new TClonesArray(
"TH2D");
 
   98   TClonesArray* arrprothe = 
new TClonesArray(
"TProfile");
 
   99   TClonesArray* arrprophi = 
new TClonesArray(
"TProfile");
 
  100   TClonesArray* arrprothephi = 
new TClonesArray(
"TProfile2D");
 
  102   std::vector<std::string> namesList;
 
  111   namesList.push_back(
"Seg");
 
  120   double radlList[100];
 
  124   int maxnames=namesList.size();
 
  125   cout << 
"before maxnames loop" << endl;
 
  127   for(
int i=0;
i<maxnames;
i++){
 
  134      name += 
i;   name2 += 
i;   name3 += 
i;   name4 += 
i;    name5 += 
i;
 
  136      new ((*arrhisxy)[
i]) TH2D(name.Data(),(namesList[
i]).c_str(),2*
res,-85.,85.,2*
res,-85.,85.);
 
  137      new ((*arrhisrz)[
i]) TH2D(name2.Data(),(namesList[
i]).c_str(),2*
res,-100.,225.,2*
res,-85.,85.);
 
  138      new ((*arrprothe)[
i]) TProfile(name3.Data(),(namesList[
i]).c_str(),angres,0.,180.);
 
  139      new ((*arrprophi)[
i]) TProfile(name4.Data(),(namesList[
i]).c_str(),angres,-180.,180.);
 
  140      new ((*arrprothephi)[
i]) TProfile2D(name5.Data(),(namesList[
i]).c_str(),angres,0.,180.,angres,-180.,180.);
 
  145   cout << 
"after maxnames loop " << endl;
 
  147   new ((*arrhisxy)[maxnames]) TH2D(
"hisxy-rest",
"Gemrest",2*res,-85.,85.,2*res,-85.,85.);
 
  148   new ((*arrhisrz)[maxnames]) TH2D(
"hisrz-rest",
"Gemrest",2*res,100.,225.,2*res,-85.,85.);
 
  149   new ((*arrprothe)[maxnames]) TProfile(
"hthe-rest",
"Gemrest",angres,0.,180.);
 
  150   new ((*arrprophi)[maxnames]) TProfile(
"hphi-rest",
"Gemrest",angres,-180.,180.);
 
  151   new ((*arrprothephi)[maxnames]) TProfile2D(
"hthephi-rest",
"Gemrest",angres,0.,180.,angres,-180.,180.);
 
  152   radlList[maxnames]=0.;
 
  154   TProfile* thetaprofile = 
new TProfile(
"thetaprof",
"(a)Radiation length vs #theta;#theta[degree];X/X_{0}",angres,0.,180.);
 
  155   TProfile* phiprofile = 
new TProfile(
"phiprof",
"(b)Radiation length vs #phi;#phi[degree];X/X_{0}",angres,-180.,180.);
 
  158   TProfile2D* histhephi = 
new TProfile2D(
"hThePhi",
"",angres,0.0,180.0,angres,-180.,180.);
 
  159   histhephi->SetTitle(
"(c)Radiation length map vs #theta & #phi;#theta[degree];#phi[degree];X/X_{0}");
 
  161   TH1D* hisx = 
new TH1D(
"hX",
"X",100,-80.,80.);
 
  162   TH1D* hisy = 
new TH1D(
"hY",
"Y",100,-80.,80.);
 
  163   TH1D* hisz = 
new TH1D(
"hZ",
"Z",100,0.,210.);
 
  166   double radlen=0.,effradl=0.,effradlsum=0.,
theta=0.,
phi=0.;
 
  170   cout << 
"before event lop" << endl;
 
  171   for (Int_t event=0; 
event<
nEvents && 
event<t->GetEntriesFast(); 
event++)
 
  174     if(
verbose) cout<<
"Event No "<<
event<<endl;
 
  175     else if (!(event%100)) cout <<
"Event No "<<
event<<endl;
 
  180        for (Int_t trackno=0; trackno<mc_array->GetEntriesFast();trackno++){
 
  185       mapMCIndex[trackno] = trackno;
 
  192       theta = mom.Theta()*TMath::RadToDeg(); 
phi = mom.Phi()*TMath::RadToDeg();
 
  196       effradl=0.;      effradlsum=0.;
 
  197       for(
int i=0; 
i<100; 
i++) radlList[
i]=0.;
 
  201       for (Int_t k=0; k<rad_array->GetEntriesFast(); k++){
 
  202         FairRadLenPoint* radpoint = (FairRadLenPoint*)rad_array->At(k);
 
  203         if (radpoint->GetTrackID() != trackno) 
continue;
 
  207         radlen = radpoint->GetRadLength();
 
  208         in = radpoint->GetPosition();
 
  209         out = radpoint->GetPositionOut();
 
  212         point.SetXYZ(0.5*(in.x()+in.x()),0.5*(in.y()+in.y()),0.5*(in.z()+in.z()));
 
  216         if(in.Mag() < 0.02) 
continue; 
 
  218         effradl = dist.Mag()/radlen;
 
  220         effradlsum += effradl;
 
  226         if ( !geoMan)   cout << 
"have no manager" << endl;
 
  229         TGeoNode* node = 
gGeoManager->FindNode(point.x(),point.y(),point.z());
 
  232           std::cout<<
"Warning: There is a node not defined properly!"<<std::endl;
 
  233           cout<<
"\tEvent No "<<
event<<
" \t RadLenPoint No."<< k <<endl;
 
  240         volname = node->GetVolume()->GetName();
 
  246            if(
"cave" == volname && point.Mag() > 20. ) {
 
  253           cout<<
"---> "<<volname.Data()<<endl;
 
  256         hRadLenDistMat->Fill(dist.Mag());
 
  257         hRadLenDistEff->Fill(effradl);
 
  259         hisx->Fill(in.X(),effradl);
 
  260         hisy->Fill(in.Y(),effradl);
 
  261         hisz->Fill(in.Z(),effradl);
 
  263         hisxy->Fill(in.X(),in.Y());
 
  264         if(in.Y()>0.) hisrz->Fill(in.Z(),in.Perp());
 
  265         else hisrz->Fill(in.Z(),-1.*in.Perp());
 
  269         int selected = maxnames;
 
  270         for(
int i=0; 
i<namesList.size(); 
i++){
 
  271           if (volname.Contains( (namesList[
i]).c_str())){
 
  277         radlList[selected]+=effradl;
 
  279         ((TH2D*)arrhisxy->At(selected))->
Fill(point.X(),point.Y(),effradl);
 
  280         if(point.Y()>0.) ((TH2D*)arrhisrz->At(selected))->
Fill(point.Z(),point.Perp(),effradl); 
 
  281         else ((TH2D*)(arrhisrz->At(selected)))->Fill(point.Z(),-1.*point.Perp(),effradl);
 
  284       thetaprofile->Fill(
theta,effradlsum);
 
  285       phiprofile->Fill(
phi,effradlsum);
 
  286       histhephi->Fill(
theta,
phi,effradlsum);
 
  291       for(
int i=0;
i<=maxnames;
i++){
 
  297         ((TProfile*)arrprothe->At(
i))->
Fill(
theta,effradl);
 
  298         ((TProfile*)arrprophi->At(
i))->
Fill(
phi,effradl);
 
  305   cout << 
"finished the loop" << endl;
 
  311 TCanvas* 
can1 = 
new TCanvas(
"can1",
"MCHit view in GEM",0,0,a*resol,
b*resol);
 
  315 hisxy->SetStats(
false);
 
  316 hisxy->DrawCopy(
"colz");
 
  317  cout << 
"doing 2" << endl;
 
  320  hisrz->SetStats(
false);
 
  321  hisrz->DrawCopy(
"colz");
 
  322   cout << 
"doing 3" << endl;
 
  326    cout << gPad->GetName() << endl;
 
  330    if ( !gPad ) cout << 
"have no damn pad" << endl;
 
  332    cout << gPad->GetName()<< endl;
 
  333   gPad->Divide(200,200);
 
  337   hisx->SetFillColor(38);
 
  343   hisy->SetFillColor(45);
 
  349   hisz->SetFillColor(60);
 
  354   cout << 
"doing 4" << endl;
 
  356    THStack* hs = 
new THStack(
"hs",
"test stacked histograms");
 
  370   TLegend* legend = 
new TLegend(0.8, 0.55, 0.98, 0.98);
 
  371   legend->AddEntry(hisx,
"",
"F");
 
  372   legend->AddEntry(hisy,
"",
"F");
 
  378 hRadLenDistMat->SetFillColor(38);
 
  379 hRadLenDistMat->DrawCopy();
 
  383 hRadLenDistEff->SetFillColor(38);
 
  384 hRadLenDistEff->DrawCopy();
 
  387    cout << gPad->GetName() << endl;
 
  391    if ( !gPad ) cout << 
"have no damn pad" << endl;
 
  393    cout << gPad->GetName()<< endl;
 
  394   gPad->Divide(200,200);
 
  398   hisx->SetFillColor(38);
 
  404   hisy->SetFillColor(45);
 
  410   hisz->SetFillColor(60);
 
  415   cout << 
"doing 4" << endl;
 
  417    THStack* hs = 
new THStack(
"hs",
"test stacked histograms");
 
  425   TLegend* legend = 
new TLegend(0.8, 0.55, 0.98, 0.98);
 
  428   legend->AddEntry(hisz,
"",
"F");
 
  433 thetaprofile->SetFillColor(60);
 
  434 thetaprofile->SetLineColor(60);
 
  435 thetaprofile->Draw(
"hist");
 
  439 phiprofile->SetFillColor(45);
 
  440 phiprofile->SetLineColor(45);
 
  441 phiprofile->Draw(
"hist");
 
  444  histhephi->SetStats(
false);
 
  445  histhephi->DrawCopy(
"colz");
 
  453 TCanvas* 
can2 = 
new TCanvas(
"can2",
"MCHit view in GEM",50,50,a*2*resol,
b*2*resol);
 
  459 TCanvas* can4 = 
new TCanvas(
"can4",
"MCHit view in GEM",100,100,a*resol,
b*resol);
 
  466 int colors[5] = {60,45,15,30,80};
 
  469 THStack* thetastack = 
new THStack(
"thetastack",
"");
 
  470 thetastack->SetTitle(
"(a)Radiation length vs #theta;#theta[degree];X/X_{0}    ");
 
  471 THStack* phistack = 
new THStack(
"phistack",
"");
 
  472 phistack->SetTitle(
"(b)Radiation length vs #phi;#phi[degree];X/X_{0}    ");
 
  476 TLegend* legMat=
new TLegend(0.6, 0.75, 0.8, 0.98);
 
  478 for(
int i=maxnames;
i>=0;
i--){
 
  479   aprof=(TProfile*)arrprothe->At(
i);
 
  480   ahist=aprof->ProjectionX();
 
  481   ahist->SetFillColor(colors[
i] + coloff);
 
  482   ahist->SetLineColor(colors[
i] + coloff);
 
  483   legMat->AddEntry(ahist,
"",
"F");
 
  486   ahist->DrawCopy(
"hist");
 
  487   thetastack->Add(ahist);
 
  489   aprof=(TProfile*)arrprophi->At(
i);
 
  490   ahist=aprof->ProjectionX();
 
  491   ahist->SetFillColor(colors[
i] + coloff);
 
  492   ahist->SetLineColor(colors[
i] + coloff);
 
  493   phistack->Add(ahist);
 
  497  thetastack->SetMaximum(2.0);
 
  500  thetastack->Draw(
"hist,nostack");
 
  505  phistack->SetMaximum(1.8);
 
  508  phistack->Draw(
"hist,nostack");
 
  517  TCanvas* can5 = 
new TCanvas(
"can5",
"RadMap",50,50,a*2*resol,
b*2*resol);
 
  520  TProfile2D* thephimap = 
new TProfile2D(
"thephimap",
"",angres,0.,180.,angres,-180.,180.);
 
  521  thephimap->SetTitle(
"Radiation length map vs #theta & #phi;#theta[degree];#phi[degree];X/X_{0}");
 
  524  TLegend* legMat=
new TLegend(0.6, 0.75, 0.8, 0.98);
 
  526  for(
int i=maxnames;
i>=0;
i--){
 
  527    bprof=(TProfile2D*)arrprothephi->At(
i);
 
  528    legMat->AddEntry(bprof,
"",
"F");
 
  530    thephimap->SetStats(
false);
 
  531    bprof->DrawCopy(
"colz");
 
  542 if(a>4) resol = int(1200/a);
 
  543 TCanvas* 
can3 = 
new TCanvas(
"can3",
"MCHit view in GEM",150,150,a*resol,b*resol);
 
  546 for(
int i=0; 
i<
a ;
i++){
 
  548   ((TH2D*)arrhisxy->At(
i))->
DrawCopy(
"colz");
 
  550   ((TH2D*)arrhisrz->At(
i))->
DrawCopy(
"colz");
 
  551   gStyle->SetOptStat();
 
  555 can1->Print(
"outAnaGemSim1.ps");
 
  560   cout << endl << endl;
 
  561   cout << 
"Macro finished succesfully." << endl;
 
  564   cout << 
"Real time " << rtime << 
" s, CPU time " << ctime << 
" s" << endl;
 
TVector3 GetMomentum() const 
TGeoManager * gGeoManager
int gem_material_ana1(int nEvents=1000000, bool verbose=false)
h1 Fill(hit_theta-point_theta)
Int_t GetMotherID() const