void anaMeritSvacNtuple(const char* ra, const char* rb, TNtuple* tuple, TH1F** h) { // Author: Chen, Xin (xchen@slac.stanford.edu) // Additions and comments by anders :-) // Input Root file (SVAC ntuple): TFile f(ra); // 'Output' is the name of the Root tree in the SVAC ntuple. TTree* t1 = (TTree*) f.Get("Output"); // Get the Merit tree: TFile fMerit(rb); TTree* t2 = (TTree*) fMerit.Get("MeritTuple"); // // Declare variables to hold data read from the tree. // Note some variables in the SVAC ntuple are arrays, so it is neccessary // to have an array to hold the data loaded from the SVAC ntuple file. // Check the description of the SVAC ntuple on the Instrument Analysis // web page to determine size and dimension of the array int nStrips[16][18][2]; int nTkrNumDigis; float dir[3]; // ALL MERIT VARIABLES ARE 'double'! double nbrTracks; // // Load the branches we want. The branch name is the same as the // variable name in the SVAC ntuple. You can find a complete list // of SVAC variables in the description available from the main // Instrument Analysis Page. // // i.e. here we load the SVAC variable 'TkrNumStrips'. TBranch* brTkrNumStrips = t1->GetBranch("TkrNumStrips"); brTkrNumStrips->SetAddress(&nStrips); TBranch* brTkrNumDigis = t1->GetBranch("TkrNumDigis"); brTkrNumDigis->SetAddress(&nTkrNumDigis); TBranch* brVtxXDir = t1->GetBranch("VtxXDir"); brVtxXDir->SetAddress(&dir[0]); TBranch* brVtxYDir = t1->GetBranch("VtxYDir"); brVtxYDir->SetAddress(&dir[1]); TBranch* brVtxZDir = t1->GetBranch("VtxZDir"); brVtxZDir->SetAddress(&dir[2]); // Load the Merit variable 'TkrNumTracks': TBranch* brTkrNumTracks = t2->GetBranch("TkrNumTracks"); brTkrNumTracks->SetAddress(&nbrTracks); // Get the total number of events: //int nEvt = (int) t1->GetEntries(); int nEvt = (int) t2->GetEntries(); // For testing: //nEvt = 100; // Some output ..... cout << "nEvent = " << nEvt << endl; // Loop over all events: for(int i = 0; i != nEvt; ++i) { // Get the events: t1->GetEntry(i); t2->GetEntry(i); // Fill output ntuple with SVAC and Merit variables: tuple->Fill(nTkrNumDigis, nbrTracks, dir[0], dir[1], dir[2]); // Cut: We only want to look at the events with less than 6 digis! if(nTkrNumDigis >= 6) continue; // Loop over tracker bilayers and views: for(int biLayer = 0; biLayer != 18; ++biLayer) { for(int view = 0; view != 2; ++view) { // Hits in this plane? if(nStrips[0][biLayer][view] > 0) { // Fill histogram with planes that are hit: h[0]->Fill(getPlane(biLayer, view)); } } } } } // // Given the biLayer number and the view, return the // corresponding plane number. Plane 0 is at the bottom. // int getPlane(int biLayer, int view) { static int map[18][2]; static bool first = true; if(first) { map[0][1] = 0; map[0][0] = 1; map[1][0] = 2; map[1][1] = 3; map[2][1] = 4; map[2][0] = 5; map[3][0] = 6; map[3][1] = 7; map[4][1] = 8; map[4][0] = 9; map[5][0] = 10; map[5][1] = 11; map[6][1] = 12; map[6][0] = 13; map[7][0] = 14; map[7][1] = 15; map[8][1] = 16; map[8][0] = 17; map[9][0] = 18; map[9][1] = 19; map[10][1] = 20; map[10][0] = 21; map[11][0] = 22; map[11][1] = 23; map[12][1] = 24; map[12][0] = 25; map[13][0] = 26; map[13][1] = 27; map[14][1] = 28; map[14][0] = 29; map[15][0] = 30; map[15][1] = 31; map[16][1] = 32; map[16][0] = 33; map[17][0] = 34; map[17][1] = 35; first = false; } return map[biLayer][view]; }