Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:25

0001 #include <vector>
0002 #include <fstream>
0003 #include <iostream>
0004 #include <algorithm>
0005 #include "TFile.h"
0006 #include "TTree.h"
0007 
0008 
0009 using namespace std;
0010 
0011 struct DATA
0012 {
0013     long d;
0014     int f;
0015 };
0016 
0017 void Counting(vector<DATA>* data,long x)
0018 {
0019     
0020     
0021     for(unsigned int i=0;i<data->size();i++)
0022     {
0023 
0024         if( (data->at(i).d)==x)
0025         {
0026             data->at(i).f++;
0027             return; 
0028         }
0029     }
0030 
0031     DATA d = {x,1};
0032     data->push_back(d);
0033 return; 
0034 }
0035 
0036 void CosmicRateTool_MakeIdList(const char* fileName)
0037 {
0038    TString InputFile= Form("%s",fileName); 
0039    TFile *file = new TFile(InputFile);
0040 
0041    bool IsFileExist;
0042    IsFileExist = file->IsZombie();
0043    if(IsFileExist)
0044    {   
0045       cout<<endl<<"====================================================================================================="<<endl;
0046       cout<<fileName << " is not found. Check the file!"<<endl;
0047       cout<<"====================================================================================================="<<endl<<endl;
0048       exit (EXIT_FAILURE);
0049    } 
0050 
0051    TTree *tree;
0052    tree = (TTree*)file->Get("cosmicRateAnalyzer/Cluster");
0053 
0054    ofstream output("IdList.txt");
0055    UInt_t Id;
0056    long x;
0057    tree->SetBranchAddress("DetID",&Id);
0058 
0059    vector<DATA>* dataIn = new vector<DATA>();
0060    
0061    long int nentries = (int)tree->GetEntries();
0062    cout<<"entries : "<<nentries<<endl;
0063    for(long int i=0; i < nentries; i++)
0064    {
0065     tree->GetEntry(i);
0066     x=Id;
0067     Counting(dataIn,x);
0068    
0069     if(i%10000==0)cout<<"At : "<<i<<endl;
0070 //      if (i==10000) break;
0071    }    
0072 
0073    for(unsigned int j=0;j<dataIn->size();)
0074    {
0075     output<<(dataIn->at(j).d)<<" "<<(dataIn->at(j).f)<<endl;
0076     j++;
0077    }
0078    output.close();
0079 }