#include "TList.h" #include "TIterator.h" #include #include #include #include #include typedef std::vector MyObjectInfo; //////////////////////////////////////////////////////////////////////////////// TString sub_detector(MyObjectInfo& info) { return info[0]; } //////////////////////////////////////////////////////////////////////////////// TString side(MyObjectInfo& info) { if( info[2].Contains("noSide") ) return "side unknown"; else if (info[2].Contains("negative") ) return "negative side"; else if (info[2].Contains("positive") ) return "positive side"; return ""; } //////////////////////////////////////////////////////////////////////////////// TString structure(MyObjectInfo& info) { TString out = TString( info[1](5,info[2].Length()-5) ); //TString out = TString( info[1](6,info[2].Length()-6) ); if( info[1].Contains("layer") ) { out.Prepend("Layer "); } if( info[1].Contains("wheel") ) { out.Prepend("Wheel "); } return out; } //////////////////////////////////////////////////////////////////////////////// TString frame(MyObjectInfo& info) { if ( info[3].CompareTo("frame1")==0 ) return "w pararrel to R, v parallel to Z"; if ( info[3].CompareTo("frame2")==0 ) return "w pararrel to R, v anti-parallel to Z"; if ( info[3].CompareTo("frame3")==0 ) return "w anti-pararrel to R, v parallel to Z"; if ( info[3].CompareTo("frame4")==0 ) return "w anti-pararrel to R, v anti-parallel to Z"; return ""; } //////////////////////////////////////////////////////////////////////////////// template bool sort_TObject_by_name(T* obj1, T* obj2) { return ( std::string(obj1->GetName()) < std::string(obj2->GetName()) ); } //////////////////////////////////////////////////////////////////////////////// template void set_style(std::vector& histos, int line_color, int fill_color, int marker_style, int marker_color) { for(unsigned int i=0 ;iSetLineColor(line_color); histos[i]->SetFillColor(fill_color); //histos[i]->SetMarkerStyle(marker_style); histos[i]->SetMarkerColor(marker_color); } } //////////////////////////////////////////////////////////////////////////////// template void fill_histogram_vector(std::vector& v, const char* name) { TIter it( gDirectory->GetListOfKeys() ); TKey *key; while ((key=(TKey*)it())) { // Check we gather only TH2 TClass *cl = gROOT->GetClass(key->GetClassName()); if (!cl->InheritsFrom(name)) continue; v.push_back( (T*)gDirectory->Get( key->GetName() ) ); } } //////////////////////////////////////////////////////////////////////////////// template void gather_info(T* object, MyObjectInfo& infos) { TString name( object->GetName() ); TObjArray *info = name.Tokenize("_"); info->Print(); for (int i = 0; i < info->GetEntries(); i++) { infos.push_back( ((TObjString *)(info->At(i)))->String() ); } } //////////////////////////////////////////////////////////////////////////////// void create_profile_x(std::vector v, std::vector& profiles) { for(unsigned int i=0; iProfileX() ); } } //////////////////////////////////////////////////////////////////////////////// template< typename T> std::vector< std::vector > arrange(std::vector&v) { cout<<" v : "< taken(v.size(), false); std::vector< std::vector > out; for (unsigned int i=0; i tmp; tmp.push_back( obj1 ); MyObjectInfo info1; gather_info(obj1,info1); TString obj1_str = structure(info1); TString obj1_sde = side(info1); for (unsigned int j=i+1; j tmp; MyObjectInfo info2; gather_info(obj2,info2); TString obj2_str = structure(info2); TString obj2_sde = side(info2); if ( obj1_str.CompareTo(obj2_str)==0 && obj1_sde.CompareTo(obj2_sde)==0 ) { taken[j] = true; tmp.push_back( obj2 ); } } std::sort(tmp.begin(),tmp.end(),sort_TObject_by_name); out.push_back( tmp ); } cout<<"out size "< std::vector > difference(std::vector< std::vector > pool1, std::vector< std::vector > pool2) { std::vector< std::vector > out; for (unsigned int i=0; i subset_1 = pool1.at(i); std::vector subset_2 = pool2.at(i); std::vector subset_out; for (unsigned int j=0; jClone(); el->Add(h2,-1.); subset_out.push_back( el ); } out.push_back( subset_out ); } return out; } //////////////////////////////////////////////////////////////////////////////// void plot(TProfile* p) { TLatex text; p->Draw(); p->GetXaxis()->SetTitle("tan(#theta)"); p->GetYaxis()->SetTitle("shift "); MyObjectInfo info; gather_info(p,info); TString p_sdt = sub_detector(info); TString p_str = structure(info); TString p_frm = frame(info); Int_t font=42; // Helvetica Double_t tsize=0.05; p->GetXaxis()->SetLabelFont(font); p->GetXaxis()->SetTitleFont(font); p->GetYaxis()->SetLabelFont(font); p->GetYaxis()->SetTitleFont(font); p->GetXaxis()->SetLabelSize(tsize); p->GetXaxis()->SetTitleSize(0.06); p->GetYaxis()->SetLabelSize(tsize); p->GetYaxis()->SetTitleSize(0.06); text.DrawLatexNDC(.16,.955, TString::Format("#scale[1.2]{%s, %s}",p_sdt.Data(),p_str.Data()).Data()); text.DrawLatexNDC(.19,.905, TString::Format("%s",p_frm.Data())); text.DrawLatexNDC(.19,.855, TString::Format("deco and peak runs : ")); TPaveStats* p_stat = (TPaveStats*) p->FindObject("stats"); p_stat->SetLineColor( p->GetLineColor() ); p_stat->SetTextColor( p->GetLineColor() ); p_stat->SetX1NDC(.85); p_stat->SetX2NDC(.95); p_stat->SetY1NDC(0.91); p_stat->SetY2NDC(0.99); gPad->Update(); } //////////////////////////////////////////////////////////////////////////////// void backplane_corrections(const char* dir, const char* peak_file, const char* deco_file) { // Histograms for peak data taking std::vector listOfPeak; std::vector profilePeak; // Histograms for Deco data taking std::vector listOfDeco; std::vector profileDeco; // open Peak / Deco data taking analysis and arranging histogram to be displayed TFile *file_peak = new TFile( peak_file ); file_peak->cd( TString::Format("prod/%s",dir).Data() ); fill_histogram_vector(listOfPeak,"TH2"); create_profile_x(listOfPeak,profilePeak); set_style(profilePeak,1,1,20,1); TFile *file_deco = new TFile( deco_file ); file_deco->cd( TString::Format("prod/%s",dir).Data() ); fill_histogram_vector(listOfDeco,"TH2"); create_profile_x(listOfDeco,profileDeco); set_style(profileDeco,4,4,20,4); std::vector< std::vector > histo_set_peak = arrange(profilePeak); std::vector< std::vector > histo_set_deco = arrange(profileDeco); std::vector< std::vector > result = histo_set_deco; //difference(histo_set_peak,histo_set_deco); cout<<" # of deco profile : "<< profileDeco.size()<< " # peak profile : "<SetOptTitle(0); gStyle->SetOptStat(10); TCanvas* c1 = new TCanvas(); c1->Print("TEC_deco_clusterSize.pdf["); for (unsigned int i=0; i result_frames = result.at(i); for (unsigned int j=0; jDivide(1,2); c2->cd(1); plot(p1); c2->cd(2); plot(p2); c2->Print("TEC_deco_clusterSize.pdf"); delete c2; } } } c1->Print("TEC_deco_clusterSize.pdf]"); } //////////////////////////////////////////////////////////////////////////////// void lorentz_analysis() { gStyle->SetOptFit(1111); gStyle->SetPaperSize(20,26); gStyle->SetPadTopMargin(0.05); gStyle->SetPadRightMargin(0.05); gStyle->SetPadBottomMargin(0.16); gStyle->SetPadLeftMargin(0.16); gStyle->SetTitleXOffset(1.1); gStyle->SetTitleYOffset(1.2); gStyle->SetMarkerStyle(20); gStyle->SetMarkerSize(0.8); gStyle->SetStatX(0.9); gStyle->SetStatY(0.9); gStyle->SetStatFontSize(0.16); gStyle->SetStatFont(61); gStyle->SetStatW(0.2); gStyle->SetPadTickX(1); gStyle->SetPadTickY(1); backplane_corrections("TEC","decos_OT_2017.root","peaks_OT_2017.root"); }