Exemple #1
0
 void setBranchAddresses(TTree* t) override { setBranchAddresses(t, ""); }
Exemple #2
0
 void setBranchAddresses(TTree* t, std::string) override { setBranchAddresses(t); }
Exemple #3
0
//! main program
int main (int argc, char** argv)
{

  std::string outputRootName = "matchDistance.root" ;
  std::string fileName (argv[1]) ;
  boost::shared_ptr<edm::ProcessDesc> processDesc = edm::readConfigFile (fileName) ;
  boost::shared_ptr<edm::ParameterSet> parameterSet = processDesc->getProcessPSet () ;
  std::cout << parameterSet->dump () << std::endl ; //PG for testing
  
  edm::ParameterSet subPSetSelections =  parameterSet->getParameter<edm::ParameterSet> ("selections") ;
  //cuts on SC Energy
  double EnergyMaxSC = subPSetSelections.getParameter<double> ("EnergyMaxSC") ;
  double EnergyMinSC = subPSetSelections.getParameter<double> ("EnergyMinSC") ;
  
  //cuts on Angle Muon / SCdirection
  double angleMAX = subPSetSelections.getParameter<double> ("angleMAX") ;
  double angleMIN = subPSetSelections.getParameter<double> ("angleMIN") ;
 
  //cuts on Xtal Energy
  double XtalMaxEnergyMin = subPSetSelections.getParameter<double> ("XtalMaxEnergyMin") ;
  double XtalMaxEnergyMax = subPSetSelections.getParameter<double> ("XtalMaxEnergyMax") ;
  double XtalMinEnergy = subPSetSelections.getParameter<double> ("XtalMinEnergy") ;
  
  //cuts on Windows
  double phiWINDOW    = subPSetSelections.getParameter<double> ("phiWINDOW") ;
  double ietaMAX    = subPSetSelections.getUntrackedParameter<int> ("ietaMAX",85) ;

  edm::ParameterSet subPSetInput =  
    parameterSet->getParameter<edm::ParameterSet> ("inputNtuples") ;
  std::vector<std::string> inputFiles = 
   subPSetInput.getParameter<std::vector<std::string> > ("inputFiles") ;
  std::cout << "reading : " ;

  TChain *chain = new TChain ("EcalCosmicsAnalysis") ;
  EcalCosmicsTreeContent treeVars ; 
  setBranchAddresses (chain, treeVars) ;

  for (std::vector<std::string>::const_iterator listIt = inputFiles.begin () ;
       listIt != inputFiles.end () ;
       ++listIt)
    {   
      std::cout << *listIt << " " << std::endl ;
      chain->Add (listIt->c_str ()) ;
    }

  TProfile2D aveEoxMap ("aveEoxMap","aveEoxMap",360,1.,361.,172,-86.,86.); 

  int nEntries = chain->GetEntries () ;
  std::cout << "FOUND " << nEntries << " ENTRIES\n" ;    

  //PG loop over entries
  for (int entry = 0 ; entry < nEntries ; ++entry)
    {
      chain->GetEntry (entry) ;
      if (entry % 100000 == 0) std::cout << "reading entry " << entry << std::endl ;


      std::vector<ect::association> associations ;
      ect::fillAssocVector (associations, treeVars) ;
      ect::selectOnDR (associations, treeVars, 0.3) ;

      //PG loop on associations vector
      for (unsigned int i = 0 ; 
           i < associations.size () ; 
           ++i)
        {
          int MUindex = associations.at (i).first  ;
          int SCindex = associations.at (i).second ;

          TVector3 SC0_pos (treeVars.superClusterX[SCindex], 
                            treeVars.superClusterY[SCindex], 
                            treeVars.superClusterZ[SCindex]) ; 
	       
          TVector3 MuonDir (treeVars.muonPx[MUindex], 
                            treeVars.muonPy[MUindex], 
                            treeVars.muonPz[MUindex]) ;

          float dummyEmax = 0.;
          float dummyLmax = 0.;
          int numCrystalEMax = -1;
          int numCrystalLMax = -1;
          bool SclOk = false;
          double dummyLength = 0;
       
          for (int XTLindex = treeVars.xtalIndexInSuperCluster[SCindex] ;
               XTLindex < treeVars.xtalIndexInSuperCluster[SCindex] +
                          treeVars.nXtalsInSuperCluster[SCindex] ; 
               ++XTLindex)
            {
              if(treeVars.xtalTkLength[XTLindex] == -1) continue;
          
              dummyLength+= treeVars.xtalTkLength[XTLindex];
          
              //---- check the link Xtal with max energy  == Xtal with max length ----
              if (treeVars.xtalEnergy[XTLindex] > dummyEmax) numCrystalEMax = XTLindex;
              if(treeVars.xtalTkLength[XTLindex] > dummyLmax) numCrystalLMax = XTLindex;
            }
       
          //   if( abs(treeVars.muonTkLengthInEcalDetail[associations.at(i).first] - dummyLength) > 0.5) continue;
       
          if ( (numCrystalEMax != numCrystalLMax) && 
               (numCrystalEMax != -1) && 
               (numCrystalLMax != -1)) 
          {
            if ( 3.*treeVars.xtalEnergy[numCrystalLMax] < 
                 treeVars.xtalTkLength[numCrystalLMax] * 0.0125) SclOk = false;
          }
          else SclOk = true;
          if ((numCrystalEMax == -1) || (numCrystalLMax == -1)) SclOk = false;
          if(SclOk == false) continue;

          double SCphi = fabs(SC0_pos.Phi()) / 3.1415 * 180. ;
          if ( (SCphi < 90. - phiWINDOW/2) || (SCphi > 90. + phiWINDOW/2) ) continue;

          double SCieta = SC0_pos.Eta () / 0.0175 ;
          if (fabs (SCieta) > ietaMAX) continue ;
        
          double angle = MuonDir.Angle ( SC0_pos ) ;
          if( angle > 3.1415/2. ) angle = 3.1415 - angle; // angle belongs to [0:90]

          if ((angle < angleMIN) || (angle >= angleMAX)) continue ;

          if ((treeVars.superClusterRawEnergy[SCindex] >= EnergyMaxSC) || 
              (treeVars.superClusterRawEnergy[SCindex] < EnergyMinSC)) continue ; 

          std::pair <int,int> maxima = findMaxXtalsInSC (treeVars, SCindex) ;
          double XtalEnergyMax = treeVars.xtalEnergy[maxima.first] ;

          if ((XtalEnergyMax < XtalMaxEnergyMin) || 
              (XtalEnergyMax >= XtalMaxEnergyMax)) continue ;
          
          //loop su cristalli di Supercluster Associato
          for (int XTLindex = treeVars.xtalIndexInSuperCluster[SCindex] ;
                   XTLindex < treeVars.xtalIndexInSuperCluster[SCindex] +
                              treeVars.nXtalsInSuperCluster[SCindex] ;
                   ++XTLindex)
            {
              if (treeVars.xtalEnergy[XTLindex] < XtalMinEnergy) continue ;               
              if (treeVars.xtalTkLength[XTLindex] <= 0.) continue ;
              double eox = treeVars.xtalEnergy[XTLindex] / 
                           treeVars.xtalTkLength[XTLindex] ;
              EBDetId dummy = EBDetId::unhashIndex (treeVars.xtalHashedIndex[XTLindex]) ;
              aveEoxMap.Fill (dummy.iphi (), dummy.ieta (), eox) ;
            }
        }
    } //PG loop over entries

  TH1F aveEoxDistr ("aveEoxDistr","aveEoxDistr",500,0,0.5) ;
  for (int phiIndex = 1 ; phiIndex < 361 ; ++phiIndex)
    for (int etaIndex = 1 ; etaIndex < 173 ; ++etaIndex)
      aveEoxDistr.Fill (aveEoxMap.GetBinContent (phiIndex,etaIndex)) ;

  TFile saving ("singleXtalEox.root","recreate") ;
  saving.cd () ;  
  aveEoxMap.Write () ;
  aveEoxDistr.Write () ;
  saving.Close () ;

  return 0 ;
}
int main(int argc,  char * argv[])
{
  // Binary to view the hits per crystal maps of a TTree
  // Also prints out information on run range of the TTree and number of: hits, entries, and consecutive duplicate hits with amplitude above 26 (47) in EB (EE) and |t| < 5 (7) ns
  // Duplicate hits require the same time, amplitude, time error and in the barrel also the same swiss cross noise. Some duplicates are expected by random chance when enough hits are present in the input tree
  // To view for instance the occupancy EB map produced by this binary, open root and type .x occupancyEB.C
  // Jared Turkewitz
  // Usage: MakeEcalTimingTreePlots <TTree input file>

  char* infile = argv[1];
  if(!infile)
  {
    std::cout << "Missing input file." << std::endl;
    return -1;
  }

  EcalTimeTreeContent treeVars_;

  TFile* myFile = new TFile(infile);
  TTree *myInputTree_ = (TTree*)myFile->Get("EcalTimeAnalysis");

  float lastCryTimesEB[EBDetId::kSizeForDenseIndexing];
  for(int i=0; i<EBDetId::kSizeForDenseIndexing;++i)
    lastCryTimesEB[i] = 0;
  float lastCryAmpsEB[EBDetId::kSizeForDenseIndexing];
  for(int i=0; i<EBDetId::kSizeForDenseIndexing;++i)
    lastCryAmpsEB[i] = 0;
  float lastCrySwissCrossEB[EBDetId::kSizeForDenseIndexing];
  for(int i=0; i<EBDetId::kSizeForDenseIndexing;++i)
    lastCrySwissCrossEB[i] = 0;
  float lastCryTimeErrorEB[EBDetId::kSizeForDenseIndexing];
  for(int i=0; i<EBDetId::kSizeForDenseIndexing;++i)
    lastCryTimeErrorEB[i] = 0;

  float lastCryTimesEE[EEDetId::kSizeForDenseIndexing];
  for(int i=0; i<EEDetId::kSizeForDenseIndexing;++i)
    lastCryTimesEE[i] = 0;
  float lastCryAmpsEE[EEDetId::kSizeForDenseIndexing];
  for(int i=0; i<EEDetId::kSizeForDenseIndexing;++i)
    lastCryAmpsEE[i] = 0;
  float lastCryTimeErrorEE[EEDetId::kSizeForDenseIndexing];
  for(int i=0; i<EEDetId::kSizeForDenseIndexing;++i)
    lastCryTimeErrorEE[i] = 0;

  float hitCounterPerCrystalEB[EBDetId::kSizeForDenseIndexing];
  for(int i=0; i<EBDetId::kSizeForDenseIndexing;++i)
    hitCounterPerCrystalEB[i] = 0;
  float hitCounterPerCrystalEE[EEDetId::kSizeForDenseIndexing];
  for(int i=0; i<EEDetId::kSizeForDenseIndexing;++i)
    hitCounterPerCrystalEE[i] = 0;
  
  int runFirst = 999999;
  int runLast = 0;
  
  TCanvas* canvas = new TCanvas();
  TH2F* occupancyEB = new TH2F("hitsPerCryMapEB","Hits used in each crystal;i#phi;i#eta",360,1.,361.,171,-85,86);
  TH2F* occupancyEBNoDuplicates = new TH2F("occupancyEBNoDuplicates","occupancyEBNoDuplicates",360,1,361,171,-85,86); 
  TH2F* duplicatesEB = new TH2F("duplicatesEB","duplicatesEB",360,1,361,171,-85,86);
  TH2F* occupancyEEM = new TH2F("hitsPerCryMapEEM","Hits per cry EEM;ix;iy",100,1,101,100,1,101);
  TH2F* occupancyEEP = new TH2F("hitsPerCryMapEEP","Hits per cry EEP;ix;iy",100,1,101,100,1,101);

  setBranchAddresses(myInputTree_,treeVars_);
  int hitCounterEBAll = 0;
  int duplicateCounterEBAll = 0;
  int hitCounterEEAll = 0;
  int duplicateCounterEEAll = 0;
  int nEntries = myInputTree_->GetEntries();
  for(int entry = 0; entry < nEntries; ++entry)
  {
    myInputTree_->GetEntry(entry);
    // Loop over the clusters in the event
    for(int bCluster=0; bCluster < treeVars_.nClusters; bCluster++)
    {
      for(int cryInBC=0; cryInBC < treeVars_.nXtalsInCluster[bCluster]; cryInBC++)
      {
        int hashedIndex = treeVars_.xtalInBCHashedIndex[bCluster][cryInBC];
        float cryTime = treeVars_.xtalInBCTime[bCluster][cryInBC];
        float cryTimeError = treeVars_.xtalInBCTimeErr[bCluster][cryInBC];
        float cryAmp = treeVars_.xtalInBCAmplitudeADC[bCluster][cryInBC];
        float crySwissCrossNoise = treeVars_.xtalInBCSwissCross[bCluster][cryInBC];

	int runNumber = treeVars_.runId;
	if (runNumber < runFirst)
	{
	  runFirst = runNumber;
	}
	if (runNumber > runLast)
	{
	  runLast = runNumber;
	}
	
        if(treeVars_.xtalInBCIEta[bCluster][0] != -999999)
        {
	  EBDetId det = EBDetId::unhashIndex(hashedIndex);
          if(det==EBDetId()) // make sure DetId is valid
	  {
            continue;
          }
          int ieta = det.ieta();
          int iphi = det.iphi();

          // RecHit cuts
          bool keepHit = cryAmp >= 26
            && crySwissCrossNoise < 0.95
	    && cryTime >= -5
	    && cryTime <= 5;
          if(!keepHit)
            continue;
	  hitCounterEBAll++;
          hitCounterPerCrystalEB[hashedIndex]++;

          if(cryTime==lastCryTimesEB[hashedIndex] && cryAmp==lastCryAmpsEB[hashedIndex] && crySwissCrossNoise == lastCrySwissCrossEB[hashedIndex] && cryTimeError==lastCryTimeErrorEB[hashedIndex])
          {
            duplicateCounterEBAll++;
          }
          occupancyEB->Fill(iphi,ieta);
          if(cryTime!=lastCryTimesEB[hashedIndex])
            occupancyEBNoDuplicates->Fill(iphi,ieta);

          if(cryTime==lastCryTimesEB[hashedIndex])
	  {
	     duplicatesEB->Fill(iphi,ieta);
	  }
          //Store information on previous hit for duplicate checking
          lastCryTimesEB[hashedIndex] = cryTime;
	  lastCryAmpsEB[hashedIndex] = cryAmp;
	  lastCrySwissCrossEB[hashedIndex] = crySwissCrossNoise;
	  lastCryTimeErrorEB[hashedIndex] = cryTimeError;
        }
	else
       	{

	  EEDetId det = EEDetId::unhashIndex(hashedIndex);
	  if(det==EEDetId()) // make sure DetId is valid
	    continue; 

	  int ix = det.ix();
	  int iy = det.iy();
	  int zside = det.zside();

          bool keepHit = cryAmp >= 47 
	    && cryTime >= -7
	    && cryTime <= 7;
          if(!keepHit)
            continue;
          hitCounterPerCrystalEE[hashedIndex]++;
	  hitCounterEEAll++;
          if(cryTime==lastCryTimesEE[hashedIndex] && cryAmp==lastCryAmpsEE[hashedIndex] && cryTimeError==lastCryTimeErrorEE[hashedIndex])
          {
            duplicateCounterEEAll++;
          }
	  if(zside == -1)
            occupancyEEM->Fill(ix,iy);
	  if(zside == 1)
            occupancyEEP->Fill(ix,iy);

          //Store information on previous hit for duplicate checking
          lastCryTimesEE[hashedIndex] = cryTime;
	  lastCryAmpsEE[hashedIndex] = cryAmp;
	  lastCryTimeErrorEE[hashedIndex] = cryTimeError;
        }
      }
    }
  }
  if(runFirst > runLast)
  {
    std::cout << "No runs in the tree!" << std::endl;
  }
  std::cout << "Run Range: " << runFirst << "-" << runLast << std::endl;
  std::cout << "nEntries: " << nEntries << std::endl;  
  std::cout << "hitCounterEBAll: " << hitCounterEBAll << " duplicateCounterEBAll: " << duplicateCounterEBAll << std::endl;
  std::cout << "hitCounterEEAll: " << hitCounterEEAll << " duplicateCounterEEAll: " << duplicateCounterEEAll << std::endl;
  int nXtalsUnder10HitsEB = 0;
  for(int i=0; i<EBDetId::kSizeForDenseIndexing;++i)
    if(hitCounterPerCrystalEB[i] <= 10)
    {
      nXtalsUnder10HitsEB++; 
    } 
  int nXtalsUnder10HitsEE = 0;
  for(int i=0; i<EEDetId::kSizeForDenseIndexing;++i)
    if(hitCounterPerCrystalEE[i] <= 10)
    {
      nXtalsUnder10HitsEE++; 
    } 

  int nXtalsWithZeroHitsEB = 0;
  for(int i=0; i<EBDetId::kSizeForDenseIndexing;++i)
    if(hitCounterPerCrystalEB[i] == 0)
    {
      nXtalsWithZeroHitsEB++; 
    } 
  int nXtalsWithZeroHitsEE = 0;
  for(int i=0; i<EEDetId::kSizeForDenseIndexing;++i)
    if(hitCounterPerCrystalEE[i] == 0)
    {
      nXtalsWithZeroHitsEE++; 
    } 

  std::cout << "nXtalsWithZeroHitsEB: " << nXtalsWithZeroHitsEB << std::endl;
  std::cout << "nXtalsUnder10HitsEB: " << nXtalsUnder10HitsEB << std::endl;
  std::cout << "nXtalsWithZeroHitsEE: " << nXtalsWithZeroHitsEE << std::endl;
  std::cout << "nXtalsUnder10HitsEE: " << nXtalsUnder10HitsEE << std::endl;
  
  canvas->cd();
  occupancyEB->Draw("colz");
  canvas->Print("occupancyEB.C");

  occupancyEEM->Draw("colz");
  canvas->Print("occupancyEEM.C");

  occupancyEEP->Draw("colz");
  canvas->Print("occupancyEEP.C");

  occupancyEBNoDuplicates->Draw("colz");
  canvas->Print("occupancyEBNoDuplicates.C");
  
  duplicatesEB->Draw("colz");
  canvas->Print("duplicatesEB.C");
}
Exemple #5
0
int main (int argc, char** argv)
{

  if (argc < 3) {
    printHelp() ;
    exit (1) ;
  }

  std::string inputfiles, inputdir ;
  std::string outputRootName = "histoTPG.root" ;
  int verbose = 0 ;
  int occupancyCut = 0 ;
  std::string l1algo ; 

  bool ok(false) ;
  for (int i=0 ; i<argc ; i++) {
    if (argv[i] == std::string("-h") ) {
      printHelp() ;
      exit(1);
    }
    if (argv[i] == std::string("-i") && argc>i+1) {
      ok = true ;
      inputfiles = argv[i+1] ;
    }
    if (argv[i] == std::string("-d") && argc>i+1) inputdir = argv[i+1] ;
    if (argv[i] == std::string("-o") && argc>i+1) outputRootName = argv[i+1] ;
    if (argv[i] == std::string("-v") && argc>i+1) verbose = atoi(argv[i+1]) ;
    if (argv[i] == std::string("-l1") && argc>i+1) l1algo =  std::string(argv[i+1]) ;
    if (argv[i] == std::string("--cutTPOccup") && argc>i+1) occupancyCut = atoi(argv[i+1]) ;
  }
  if (!ok) {
    std::cout<<"No input files have been given: nothing to do!"<<std::endl ;
    printHelp() ;
    exit(1);
  }
  
  std::vector<int> algobits ;
  std::vector<std::string> algos = split(l1algo,",") ;
  for (unsigned int i=0 ; i<algos.size() ; i++) algobits.push_back(atoi(algos[i].c_str())) ;


  unsigned int ref = 2 ;



  ///////////////////////
  // book the histograms
  ///////////////////////

  TH2F * occupancyTP = new TH2F("occupancyTP", "Occupancy TP data", 72, 1, 73, 38, -19, 19) ;
  occupancyTP->GetYaxis()->SetTitle("eta index") ;
  occupancyTP->GetXaxis()->SetTitle("phi index") ;
  TH2F * occupancyTPEmul = new TH2F("occupancyTPEmul", "Occupancy TP emulator", 72, 1, 73, 38, -19, 19) ;
  occupancyTPEmul->GetYaxis()->SetTitle("eta index") ;
  occupancyTPEmul->GetXaxis()->SetTitle("phi index") ;

  TH1F * TP = new TH1F("TP", "TP", 256, 0., 256.) ;
  TP->GetXaxis()->SetTitle("TP (ADC)") ;
  TH1F * TPEmul = new TH1F("TPEmul", "TP Emulator", 256, 0., 256.) ;
  TPEmul->GetXaxis()->SetTitle("TP (ADC)") ;
  TH1F * TPEmulMax = new TH1F("TPEmulMax", "TP Emulator max", 256, 0., 256.) ;
  TPEmulMax->GetXaxis()->SetTitle("TP (ADC)") ;
  TH3F * TPspectrumMap3D = new TH3F("TPspectrumMap3D", "TP data spectrum map", 72, 1, 73, 38, -19, 19, 256, 0., 256.) ;
  TPspectrumMap3D->GetYaxis()->SetTitle("eta index") ;
  TPspectrumMap3D->GetXaxis()->SetTitle("phi index") ;

  TH1F * TPMatchEmul = new TH1F("TPMatchEmul", "TP data matching Emulator", 7, -1., 6.) ;
  TH1F * TPEmulMaxIndex = new TH1F("TPEmulMaxIndex", "Index of the max TP from Emulator", 7, -1., 6.) ;
  TH3I * TPMatchEmul3D = new TH3I("TPMatchEmul3D", "TP data matching Emulator", 72, 1, 73, 38, -19, 19, 7, -1, 6) ;
  TPMatchEmul3D->GetYaxis()->SetTitle("eta index") ;
  TPMatchEmul3D->GetXaxis()->SetTitle("phi index") ;

  TH2I * ttfMismatch = new TH2I("ttfMismatch", "TTF mismatch map",  72, 1, 73, 38, -19, 19) ;
  ttfMismatch->GetYaxis()->SetTitle("eta index") ;
  ttfMismatch->GetXaxis()->SetTitle("phi index") ;

  ///////////////////////
  // Chain the trees:
  ///////////////////////

  TChain * chain = new TChain ("EcalTPGAnalysis") ;
  std::vector<std::string> files ;
  if (inputfiles.find(std::string(",")) != std::string::npos) files = split(inputfiles,",") ;
  if (inputfiles.find(std::string(":")) != std::string::npos) {
    std::vector<std::string> filesbase = split(inputfiles,":") ;
    if (filesbase.size() == 4) {
      int first = atoi(filesbase[1].c_str()) ;
      int last = atoi(filesbase[2].c_str()) ;
      for (int i=first ; i<=last ; i++) {
	std::stringstream name ;
	name<<filesbase[0]<<i<<filesbase[3] ;
	files.push_back(name.str()) ;
      }
    }
  }
  for (unsigned int i=0 ; i<files.size() ; i++) {
    files[i] = inputdir+"/"+files[i] ;
    std::cout<<"Input file: "<<files[i]<<std::endl ;
    chain->Add (files[i].c_str()) ;
  }

  EcalTPGVariables treeVars ;
  setBranchAddresses (chain, treeVars) ;

  int nEntries = chain->GetEntries () ;
  std::cout << "Number of entries: " << nEntries <<std::endl ;    



  ///////////////////////
  // Main loop over entries
  ///////////////////////

  for (int entry = 0 ; entry < nEntries ; ++entry) {
    chain->GetEntry (entry) ;
    if (entry%1000==0) std::cout <<"------> "<< entry+1 <<" entries processed" << " <------\n" ; 
    if (verbose>0) std::cout<<"Run="<<treeVars.runNb<<" Evt="<<treeVars.runNb<<std::endl ;

    // trigger selection if any
    bool keep(false) ;
    if (!algobits.size()) keep = true ; // keep all events when no trigger selection
    for (unsigned int algo = 0 ; algo<algobits.size() ; algo++)
      for (unsigned int ntrig = 0 ; ntrig < treeVars.nbOfActiveTriggers ; ntrig++)
	if (algobits[algo] == treeVars.activeTriggers[ntrig]) keep = true ;
    if (!keep) continue ;
    
             
    // loop on towers
    for (unsigned int tower = 0 ; tower < treeVars.nbOfTowers ; tower++) {

      int tp = getEt(treeVars.rawTPData[tower]) ;
      int emul[5] = {getEt(treeVars.rawTPEmul1[tower]),
		     getEt(treeVars.rawTPEmul2[tower]),
		     getEt(treeVars.rawTPEmul3[tower]),
		     getEt(treeVars.rawTPEmul4[tower]),
		     getEt(treeVars.rawTPEmul5[tower])} ;
      int maxOfTPEmul = 0 ;
      int indexOfTPEmulMax = -1 ;
      for (int i=0 ; i<5 ; i++) if (emul[i]>maxOfTPEmul) {
	maxOfTPEmul = emul[i] ; 
	indexOfTPEmulMax = i ;
      }
      int ieta = treeVars.ieta[tower] ;
      int iphi = treeVars.iphi[tower] ;
      int nbXtals = treeVars.nbOfXtals[tower] ;
      int ttf = getTtf(treeVars.rawTPData[tower]) ;


      if (verbose>9 && (tp>0 || maxOfTPEmul>0)) {
	std::cout<<"(phi,eta, Nbxtals)="<<std::dec<<iphi<<" "<<ieta<<" "<<nbXtals<<std::endl ;
	std::cout<<"Data Et, TTF: "<<tp<<" "<<ttf<<std::endl ;
	std::cout<<"Emulator: " ;
	for (int i=0 ; i<5 ; i++) std::cout<<emul[i]<<" " ;
	std::cout<<std::endl ;
      }


      // Fill TP spctrum
      TP->Fill(tp) ;
      TPEmul->Fill(emul[ref]) ;
      TPEmulMax->Fill(maxOfTPEmul) ;
      TPspectrumMap3D->Fill(iphi, ieta, tp) ;


      // Fill TP occupancy
      if (tp>occupancyCut) occupancyTP->Fill(iphi, ieta) ;
      if (emul[ref]>occupancyCut) occupancyTPEmul->Fill(iphi, ieta) ;


      // Fill TP-Emulator matching
      // comparison is meaningful when:
      if (tp>0 && nbXtals == 25) {
	bool match(false) ;
	for (int i=0 ; i<5 ; i++) {
	  if (tp == emul[i]) {
	    TPMatchEmul->Fill(i+1) ;
	    TPMatchEmul3D->Fill(iphi, ieta, i+1) ;
	    match = true ;
	  }
	}
	if (!match) {
	  TPMatchEmul->Fill(-1) ;
	  TPMatchEmul3D->Fill(iphi, ieta, -1) ;
	  if (verbose>5) {
	    std::cout<<"MISMATCH"<<std::endl ;
	    std::cout<<"(phi,eta, Nbxtals)="<<std::dec<<iphi<<" "<<ieta<<" "<<nbXtals<<std::endl ;
	    std::cout<<"Data Et, TTF: "<<tp<<" "<<ttf<<std::endl ;
	    std::cout<<"Emulator: " ;
	    for (int i=0 ; i<5 ; i++) std::cout<<emul[i]<<" " ;
	    std::cout<<std::endl ;
	  }
	}
      }
      if (maxOfTPEmul>0) TPEmulMaxIndex->Fill(indexOfTPEmulMax+1) ;


      // Fill TTF mismatch
      if ((ttf==1 || ttf==3) && nbXtals != 25) ttfMismatch->Fill(iphi, ieta) ;


    } // end loop towers


  } // endloop entries

  

  ///////////////////////
  // Format & write histos
  ///////////////////////


  // 1. TP Spectrum  
  TProfile2D * TPspectrumMap = TPspectrumMap3D->Project3DProfile("yx") ;
  TPspectrumMap->SetName("TPspectrumMap") ;

  // 2. TP Timing
  TH2F * TPMatchEmul2D = new TH2F("TPMatchEmul2D", "TP data matching Emulator", 72, 1, 73, 38, -19, 19) ;
  TH2F * TPMatchFraction2D = new TH2F("TPMatchFraction2D", "TP data: fraction of non-single timing", 72, 1, 73, 38, -19, 19) ;
  TPMatchEmul2D->GetYaxis()->SetTitle("eta index") ; 
  TPMatchEmul2D->GetXaxis()->SetTitle("phi index") ;
  TPMatchEmul2D->GetZaxis()->SetRangeUser(-1,6) ;
  TPMatchFraction2D->GetYaxis()->SetTitle("eta index") ; 
  TPMatchFraction2D->GetXaxis()->SetTitle("phi index") ;
  for (int binx=1 ; binx<=72 ; binx++)    
    for (int biny=1 ; biny<=38 ; biny++) {
      int maxBinz = 5 ;
      double maxCell = TPMatchEmul3D->GetBinContent(binx, biny, maxBinz) ;
      double totalCell(0) ;
      for (int binz=1; binz<=7 ; binz++) {
	double content = TPMatchEmul3D->GetBinContent(binx, biny, binz) ;
	if (content>maxCell) {
	  maxCell = content ;
	  maxBinz = binz ;
	}
	totalCell += content ;
      }
      if (maxCell <=0) maxBinz = 2 ; // empty cell
      TPMatchEmul2D->SetBinContent(binx, biny, float(maxBinz)-2.) ; //z must be in [-1,5] 
      double fraction = 0 ;
      if (totalCell>0) fraction = 1.- maxCell/totalCell ;
      TPMatchFraction2D->SetBinContent(binx, biny, fraction) ;
      if (totalCell > maxCell && verbose>9) {
	std::cout<<"--->"<<std::endl ;	
	for (int binz=1; binz<=7 ; binz++) {	  
	  std::cout<< "(phi,eta, z): (" 
		   << TPMatchEmul3D->GetXaxis()->GetBinLowEdge(binx) 
		   << ", " << TPMatchEmul3D->GetYaxis()->GetBinLowEdge(biny) 
		   << ", " << TPMatchEmul3D->GetZaxis()->GetBinLowEdge(binz)		   
		   << ") Content="<<TPMatchEmul3D->GetBinContent(binx, biny, binz)		   
		   << ", erro="<<TPMatchEmul3D->GetBinContent(binx, biny, binz)	   
		   << std::endl ;	
	}
      }
    }



  TFile saving (outputRootName.c_str (),"recreate") ;
  saving.cd () ;
  
  occupancyTP->Write() ;
  occupancyTPEmul->Write() ;
  
  TP->Write() ;
  TPEmul->Write() ;
  TPEmulMax->Write() ;
  TPspectrumMap->Write() ;

  TPMatchEmul->Write() ; 
  TPMatchEmul3D->Write() ; 
  TPEmulMaxIndex->Write() ;
  TPMatchEmul2D->Write() ; 
  TPMatchFraction2D->Write() ; 

  ttfMismatch->Write() ; 

     
  saving.Close () ;
  delete chain ;

  return 0 ;
}
Exemple #6
0
int main (int argc, char** argv)
{
  std::string fileName (argv[1]) ;
  boost::shared_ptr<edm::ProcessDesc> processDesc = edm::readConfigFile (fileName) ;
  boost::shared_ptr<edm::ParameterSet> parameterSet = processDesc->getProcessPSet () ;
  std::cout << parameterSet->dump () << std::endl ; //PG for testing
  
  // edm::ParameterSet subPSetSelections =  parameterSet->getParameter<edm::ParameterSet> ("Selections") ;
  edm::ParameterSet subPSetInput = parameterSet->getParameter<edm::ParameterSet> ("inputNtuples") ;
  std::vector<std::string> inputFiles = subPSetInput.getParameter<std::vector<std::string> > ("inputFiles") ;

  TChain *chain = new TChain ("EcalCosmicsAnalysis") ;
  EcalCosmicsTreeContent treeVars ; 
  setBranchAddresses (chain, treeVars) ;


  // input files
  for (std::vector<std::string>::const_iterator listIt = inputFiles.begin () ;
       listIt != inputFiles.end () ; ++listIt)
  {
    std::cout << *listIt << " " << std::endl ;
    chain->Add (listIt->c_str ()) ;
  }

  int nEntries = chain->GetEntries () ;
  std::cout << "FOUND " << nEntries << " ENTRIES\n" ;    
  // input files


  // output file
  std::string outputRootName = "CRAFT_SCdistr.root" ;
  // output file  



  // output distributions
  TH2F SCoccupancy ("SCoccupancy", "SCoccupancy", PHI_BIN, PHI_MIN, PHI_MAX, ETA_BIN, ETA_MIN, ETA_MAX) ;
  
  TH1F SCenergy ("SCenergy", "SCenergy", E_BIN, E_MIN, E_MAX) ;
  TProfile2D SCenergy_ETAvsPHI ("SCenergy_ETAvsPHI", "SCenergy_ETAvsPHI", PHI_BIN, PHI_MIN, PHI_MAX, ETA_BIN, ETA_MIN, ETA_MAX) ;
  // output distributions



  // loop over entries
  for (int entry = 0; entry < nEntries; ++entry)
  {
    chain->GetEntry (entry) ;

    for (int SCindex = 0; SCindex < treeVars.nSuperClusters; ++SCindex)
    {
      SCoccupancy.Fill (treeVars.superClusterPhi[SCindex], treeVars.superClusterEta[SCindex]) ;
      
      SCenergy.Fill (treeVars.superClusterRawEnergy[SCindex]) ;
      SCenergy_ETAvsPHI.Fill (treeVars.superClusterPhi[SCindex], treeVars.superClusterEta[SCindex], treeVars.superClusterRawEnergy[SCindex]) ;
    }
  
  
  } //PG loop over entries

  TFile saving (outputRootName.c_str (),"recreate") ;
  saving.cd () ;  
  
  SCoccupancy.Write () ;
  SCenergy.Write () ;
  SCenergy_ETAvsPHI.Write () ;
  
  saving.Close () ;
  
  return 0 ;
}
int main (int argc, char** argv)
{
  std::string fileName (argv[1]) ;
  boost::shared_ptr<edm::ProcessDesc> processDesc = edm::readConfigFile (fileName) ;
  boost::shared_ptr<edm::ParameterSet> parameterSet = processDesc->getProcessPSet () ;
  
  edm::ParameterSet subPSetSelections =  parameterSet->getParameter<edm::ParameterSet> ("selections") ;
  
  edm::ParameterSet subPSetInput = parameterSet->getParameter<edm::ParameterSet> ("inputNtuples") ;
  std::vector<std::string> inputFiles = subPSetInput.getParameter<std::vector<std::string> > ("inputFiles") ;
  
  
  
  // load ntuple
  TChain *chain = new TChain ("EcalCosmicsAnalysis") ;
  EcalCosmicsTreeContent treeVars ; 
  setBranchAddresses (chain, treeVars) ;
  
  
  
  // input files
  for (std::vector<std::string>::const_iterator listIt = inputFiles.begin () ;
       listIt != inputFiles.end () ; ++listIt)
  {
    std::cout << *listIt << " " << std::endl ;
    chain->Add (listIt->c_str ()) ;
  }
  
  int nEntries = chain->GetEntries () ;
  std::cout << "FOUND " << nEntries << " ENTRIES\n" ;
  
  
  
  // Output file
  std::string outputRootName = "CRAFT_MATCHdistr.root" ;
  TFile outputRootFile (outputRootName.c_str (), "recreate") ;
  outputRootFile.cd () ;
  
  
  
  // output distributions
  TH2F looseAssoc_DETAvsDPHI ("looseAssoc_DETAvsDPHI", "looseAssoc_DETAvsDPHI", PHI_BIN, PHI_MIN, PHI_MAX, 2*ETA_BIN, 2*ETA_MIN, 2*ETA_MAX) ;
  TH1F looseAssoc_DR ("looseAssoc_DR", "looseAssoc_DR", 2*PHI_BIN, 0., 2*PHI_MAX) ;
  
  TH1F EoverP_loose ("EoverP_loose", "EoverP_loose", 1000, 0., 5.) ;
  
  
  TH2F tightAssoc_DETAvsDPHI ("tightAssoc_DETAvsDPHI", "tightAssoc_DETAvsDPHI", PHI_BIN, -0.5, 0.5, ETA_BIN, -0.5, 0.5) ;
  TH1F tightAssoc_DR ("tightAssoc_DR", "tightAssoc_DR", 2*PHI_BIN, 0., 2*PHI_MAX) ;
  
  TH1F EoverP_tight ("EoverP_tight", "EoverP_tight", 1000, 0., 5.) ;
  TProfile EoverPvsETA_tight ("EoverPvsETA_tight", "EoverPvsETA_tight", ETA_BIN, ETA_MIN, ETA_MAX) ;
  TProfile EoverPvsPHI_tight ("EoverPvsPHI_tight", "EoverPvsPHI_tight", PHI_BIN, PHI_MIN, PHI_MAX) ;
  TProfile EoverPvsPT_tight ("EoverPvsPT_tight", "EoverPvsPT_tight", P_BIN, P_MIN, P_MAX) ;
  
  TProfile dEvsdX_tight ("dEvsdX_tight", "dEvsdX_tight", 200, 0., 100.) ;
  
  
  // loop over entries
  for (int entry = 0; entry < nEntries; ++entry)
  {
    if ((entry % 100000) == 0)
      std::cout << "Reading entry " << entry << std::endl;
    chain->GetEntry (entry) ;
    // if (entry == 100000) break ;
    
    // association MU-SC
    std::vector<ect::association> looseAssoc ;
    ect::fillAssocVector (looseAssoc, treeVars) ;
    ect::selectOnDR (looseAssoc, treeVars, 1000000.) ;
    
    std::vector<ect::association> tightAssoc ;
    ect::fillAssocVector (tightAssoc, treeVars) ;
    ect::selectOnDR (tightAssoc, treeVars, 0.1) ;
    
    
    
    //loop on associations vector
    for (unsigned int i = 0 ; i < looseAssoc.size () ; ++i)
    {
      int MUindex = looseAssoc.at (i).first  ;
      int SCindex = looseAssoc.at (i).second ;
      
      
      
      int muonLeg = treeVars.muonLeg[MUindex];
      float muonP = 0.;
      float muonPt = 0.;
      float muond0 = treeVars.muond0[MUindex];
      float muondz = treeVars.muondz[MUindex];
      float muonPhi = 0.;
      float muonEta = 0.;
      float muonTkLengthInEcal = treeVars.muonTkLengthInEcalDetail[MUindex];
      float muonTkLengthInEcalCurved = treeVars.muonTkLengthInEcalDetailCurved[MUindex];
      float superClusterRawEnergy = treeVars.superClusterRawEnergy[SCindex]; 
      GlobalPoint muonTkInternalPointInEcal (treeVars.muonTkInternalPointInEcalX[MUindex],
                                             treeVars.muonTkInternalPointInEcalY[MUindex],
                                             treeVars.muonTkInternalPointInEcalZ[MUindex]) ;
      float Dphi = treeVars.superClusterPhi[SCindex] - muonTkInternalPointInEcal.phi () ;
      float Deta = treeVars.superClusterEta[SCindex] - muonTkInternalPointInEcal.eta () ;
      
      if (muonLeg == 1)
      {
        muonP = treeVars.muonInnTkInnerHitP[MUindex];
        muonPt = treeVars.muonInnTkInnerHitPt[MUindex];
        muonPhi = treeVars.muonInnTkInnerHitPhi[MUindex];
        muonEta = treeVars.muonInnTkInnerHitEta[MUindex];
      }
      
      else if (muonLeg == -1)
      {
        muonP = treeVars.muonInnTkOuterHitP[MUindex];
        muonPt = treeVars.muonInnTkOuterHitPt[MUindex];
        muonPhi = treeVars.muonInnTkOuterHitPhi[MUindex];
        muonEta = treeVars.muonInnTkOuterHitEta[MUindex];
      }
      
      
      
      looseAssoc_DETAvsDPHI.Fill (Dphi, Deta) ;
      looseAssoc_DR.Fill (sqrt (Dphi*Dphi + Deta*Deta)) ;
      
      if (muonLeg == -1)
      {
        EoverP_loose.Fill (superClusterRawEnergy/muonP) ;
      }
    }
    
    
    
    for (unsigned int i = 0 ; i < tightAssoc.size () ; ++i)
    {
      int MUindex = tightAssoc.at (i).first  ;
      int SCindex = tightAssoc.at (i).second ;
      
      
      
      int muonLeg = treeVars.muonLeg[MUindex];
      float muonP = 0.;
      float muonPt = 0.;
      float muond0 = treeVars.muond0[MUindex];
      float muondz = treeVars.muondz[MUindex];
      float muonPhi = 0.;
      float muonEta = 0.;
      float muonTkLengthInEcal = treeVars.muonTkLengthInEcalDetail[MUindex];
      float muonTkLengthInEcalCurved = treeVars.muonTkLengthInEcalDetailCurved[MUindex];
      float superClusterRawEnergy = treeVars.superClusterRawEnergy[SCindex]/4*0.9 ;
      GlobalPoint muonTkInternalPointInEcal (treeVars.muonTkInternalPointInEcalX[MUindex],
                                             treeVars.muonTkInternalPointInEcalY[MUindex],
                                             treeVars.muonTkInternalPointInEcalZ[MUindex]) ;
      float Dphi = treeVars.superClusterPhi[SCindex] - muonTkInternalPointInEcal.phi () ;
      float Deta = treeVars.superClusterEta[SCindex] - muonTkInternalPointInEcal.eta () ;
      
      if (muonLeg == 1)
      {
        muonP = treeVars.muonInnTkInnerHitP[MUindex];
        muonPt = treeVars.muonInnTkInnerHitPt[MUindex];
        muonPhi = treeVars.muonInnTkInnerHitPhi[MUindex];
        muonEta = treeVars.muonInnTkInnerHitEta[MUindex];
      }
      
      else if (muonLeg == -1)
      {
        muonP = treeVars.muonInnTkOuterHitP[MUindex];
        muonPt = treeVars.muonInnTkOuterHitPt[MUindex];
        muonPhi = treeVars.muonInnTkOuterHitPhi[MUindex];
        muonEta = treeVars.muonInnTkOuterHitEta[MUindex];
      }
      
      
      
      tightAssoc_DETAvsDPHI.Fill (Dphi, Deta) ;
      tightAssoc_DR.Fill (sqrt (Dphi*Dphi + Deta*Deta)) ;
      
      if (muonLeg == -1)
      {
        EoverP_tight.Fill (superClusterRawEnergy/muonP) ;
        EoverPvsETA_tight.Fill (muonEta, superClusterRawEnergy/muonP) ;
        EoverPvsPHI_tight.Fill (muonPhi, superClusterRawEnergy/muonP) ;
        EoverPvsPT_tight.Fill (muonPt, superClusterRawEnergy/muonP) ;
        
        if(muonTkLengthInEcal > 0.)
        {
          dEvsdX_tight.Fill (muonTkLengthInEcal, superClusterRawEnergy) ;
        }
      }
    }
  
  } //PG loop over entries
  
  
  
  // Save histograms
  looseAssoc_DETAvsDPHI.Write () ;
  looseAssoc_DR.Write () ;
  
  EoverP_loose.Write () ;
  
  
  tightAssoc_DETAvsDPHI.Write () ;
  tightAssoc_DR.Write () ;
  
  EoverP_tight.Write () ;
  EoverPvsETA_tight.Write () ;
  EoverPvsPHI_tight.Write () ;
  EoverPvsPT_tight.Write () ;
  
  dEvsdX_tight.Write () ;
  
  
  outputRootFile.Close () ;
  
  return 0 ;
}