Esempio n. 1
0
void testEcalDetId::testEEDetId(){

  std::vector<unsigned int> detIds(EEDetId::kSizeForDenseIndexing,0);
  
  
  for (int ix=EEDetId::IX_MIN;ix<=EEDetId::IX_MAX;ix++)
    for (int iy=EEDetId::IY_MIN;iy<=EEDetId::IY_MAX;iy++)
      try
	{
	  //EEDetId Zside 1 
	  if ( EEDetId::validDetId(ix,iy,1) ) {
	    EEDetId aPositiveId(ix,iy,1);
	    CPPUNIT_ASSERT(aPositiveId.ix()==ix);
	    CPPUNIT_ASSERT(aPositiveId.iy()==iy);
	    CPPUNIT_ASSERT(aPositiveId.zside()==1);
	    CPPUNIT_ASSERT(EEDetId::validHashIndex(aPositiveId.hashedIndex()));
	    CPPUNIT_ASSERT(EEDetId::unhashIndex(aPositiveId.hashedIndex())==aPositiveId);
	    detIds.at(aPositiveId.hashedIndex()) = aPositiveId;
	  }
	  //EEDetId Zside -1 
	  if ( EEDetId::validDetId(ix,iy,-1) ) {
	    EEDetId aNegativeId(ix,iy,-1);
	    CPPUNIT_ASSERT(aNegativeId.ix()==ix);
	    CPPUNIT_ASSERT(aNegativeId.iy()==iy);
	    CPPUNIT_ASSERT(aNegativeId.zside()==-1);
	    CPPUNIT_ASSERT(EEDetId::validHashIndex(aNegativeId.hashedIndex()));
	    CPPUNIT_ASSERT(EEDetId::unhashIndex(aNegativeId.hashedIndex())==aNegativeId);
	    detIds.at(aNegativeId.hashedIndex()) = aNegativeId;
	  }
	}
      catch ( cms::Exception &e ) 
	{ 
	  bool cmsExceptionCought=false;
	  CPPUNIT_ASSERT(cmsExceptionCought);
	}
      catch ( std::exception &e ) 
	{ 
	  bool stdExceptionCought=false;
	  CPPUNIT_ASSERT(stdExceptionCought);
	}

  int holes=0;
  for (int i=0;i!=EEDetId::kSizeForDenseIndexing;++i) {
    // CPPUNIT_ASSERT(detIds[i]!=0);
    if (detIds[i]==0) { holes++; continue; }// there are holes...
    CPPUNIT_ASSERT(EEDetId(detIds[i]).hashedIndex()==i);
    CPPUNIT_ASSERT(EEDetId::unhashIndex(i)==detIds[i]);
  }
  CPPUNIT_ASSERT(holes==0);
  //FIXME hope a better test...
  //CPPUNIT_ASSERT(holes>EEDetId::kSizeForDenseIndexing/100);
  //CPPUNIT_ASSERT(holes<EEDetId::kSizeForDenseIndexing/10);
}
Esempio n. 2
0
int main(int argc, char *argv[]) {
  FILE *ofile = fopen("ee_numbering.dat", "w");
  FILE *ofile_2 = fopen("ee_next_to_boundary.dat", "w");
  int hi = -1;
  try {
    for (int iz = -1; iz < 2; iz += 2) {
      for (int ix = EEDetId::IX_MIN; ix <= EEDetId::IX_MAX; ix++) {
        for (int iy = nBegin[ix - 1]; iy <= 100 - nBegin[ix - 1] + 1; iy++) {
          hi = -1;
          if (EEDetId::validDetId(ix, iy, iz)) {
            EEDetId id = EEDetId(ix, iy, iz);
            hi = id.hashedIndex();
            assert(EEDetId::unhashIndex(hi) == id);
            //std::cout << id << " " << hi << " " << EEDetId::unhashIndex( hi ) << std::endl;
            fprintf(ofile, "%d %d %d %d %d\n", ix, iy, iz, hi, 1);
            if (EEDetId::isNextToBoundary(id)) {
              fprintf(ofile_2, "%d %d %d %d %d\n", ix, iy, iz, hi, 1);
            } else {
              fprintf(ofile_2, "%d %d %d %d %d\n", ix, iy, iz, hi, 0);
            }
          } else {
            fprintf(ofile, "%d %d %d %d %d\n", ix, iy, iz, hi, 0);
            //std::cout << "Invalid detId " << ix << " " << iy << " " << iz << std::endl;
          }
        }
      }
    }
    for (int i = 0; i < 15480; i++) {
      EEDetId id = EEDetId::unhashIndex(hi);
      assert(EEDetId::validDetId(id.ix(), id.iy(), id.zside()));
    }
  } catch (std::exception &e) {
    std::cerr << e.what();
  }
  fclose(ofile);
  fclose(ofile_2);
}
Esempio n. 3
0
int main (int argc, char* argv[]) 
{
  std::cout << "parsing cfg file: " << argv[1] << std::endl ;
  trivialParser configParams (static_cast<std::string> (argv[1])) ;
  
  int IMAEEradStart = static_cast<int> (configParams.getVal ("IMAEEradStart")) ;
  int IMAEEradEnd = static_cast<int> (configParams.getVal ("IMAEEradEnd")) ;
  int IMAEEradWidth = static_cast<int> (configParams.getVal ("IMAEEradWidth")) ;
  int IMAEEphiStart = static_cast<int> (configParams.getVal ("IMAEEphiStart")) ;
  int IMAEEphiEnd = static_cast<int> (configParams.getVal ("IMAEEphiEnd")) ;

//  std::cerr << "[PG] IMAEEradStart = " << IMAEEradStart << std::endl ;
//  std::cerr << "[PG] IMAEEradEnd = " << IMAEEradEnd << std::endl ;
//  std::cerr << "[PG] IMAEEradWidth = " << IMAEEradWidth << std::endl ;
//  std::cerr << "[PG] IMAEEphiStart = " << IMAEEphiStart << std::endl ;
//  std::cerr << "[PG] IMAEEphiEnd = " << IMAEEphiEnd << std::endl ;
//  std::cerr << "[PG] IMAEEphiWidth = " << IMAEEphiWidth << std::endl ;

  std::string coeffFolder = argv[2] ;

  std::map<int, EcalIntercalibConstantMap> recalibrators ; 
  //PG FIXME  c'e' il copy ctor della CaloMiscalibMapEcal?
 
  //PG loop on EB rad indexes
  for (int radIndex = IMAEEradStart ; 
       radIndex < IMAEEradEnd ; 
       radIndex += IMAEEradWidth)
    {
      int currentIndex = radIndex ;
      int nextIndex = radIndex + IMAEEradWidth ;

      //PG compute the values of the limits
      //PG FIXME questo forse non e' sufficiente, bisogna anche considerare il caso
      //PG FIXME in cui currentIndex e' positivo e effradIndex start no 
      //PG FIXME lo stesso vale per l'end e il nexindex
      //PG FIXME lo stesso vale per gli script perl
//      int effradIndexStart = currentIndex - IMAEEradWidth ;
//      if (effradIndexStart < 0) { effradIndexStart = 0 ; }
//      int effradIndexEnd = nextIndex + IMAEEradWidth ;
//      if (effradIndexEnd > 50) { effradIndexEnd = 50 ; }
    
      //PG build the filename
      std::stringstream nomeFile ;
      nomeFile << coeffFolder << "/EEcalibCoeff_" << currentIndex 
               << "-" << nextIndex << ".xml" ;
      std::string fileName = nomeFile.str () ;      
//      std::cerr << "PG nomefile: " << fileName << std::endl ;

      //PG open the XML file
      CaloMiscalibMapEcal map ;
      map.prefillMap () ;
      MiscalibReaderFromXMLEcalEndcap endcapreader (map) ;
      if (!fileName.empty ()) endcapreader.parseXMLMiscalibFile (fileName) ;
      EcalIntercalibConstants* constants = 
             new EcalIntercalibConstants (map.get ()) ;
      recalibrators[currentIndex] = constants->getMap () ;  
    } //PG loop on EB rad indexes

  //PG prepare the XML to be saved
  
  //PG this command outputs an XML file with a fixed name
  calibXMLwriter endcapWriter (EcalEndcap) ;
  //PG loop on EB rad slices
  for (std::map<int, EcalIntercalibConstantMap>::const_iterator itMap = 
          recalibrators.begin () ;
       itMap != recalibrators.end () ;
       ++itMap)
    {
      //PG compute the values of the limits
      //PG FIXME questo forse non e' sufficiente, bisogna anche considerare il caso
      //PG FIXME in cui currentIndex e' positivo e effradIndex start no 
      //PG FIXME lo stesso vale per l'end e il nexindex
      //PG FIXME lo stesso vale per gli script perl

      //PG non so scegliere da dove partire, questo e' un disastro
      //PG il problema e' dei bordi
      //PG forse la cosa migliore e' salvare i xml file con un nome che dica dei coeff buoni,
      //PG non di quelli calcolati - direi che e' la cosa giusta

      //PG loop over x
      for (int ix = 0 ; ix < 100 ; ++ix)
      //PG loop over y
      for (int iy = 0 ; iy < 100 ; ++iy)
        {
          //PG select the subregion of interest
          if (EEregionCheck (ix,iy,
                             itMap->first,itMap->first+IMAEEradWidth,
                             IMAEEphiStart,IMAEEphiEnd) ) continue ;
          //PG check whether the detid is buildable
          if (!EEDetId::validDetId (ix,iy,1))
            {
              std::cerr << "[WARN] elemento " << ix << " " << iy
                        << " 1" 
                        << " scartato" << std::endl ;
              continue ;
            }
          EEDetId det = EEDetId (ix,iy,1,EEDetId::XYMODE) ;
          std::cerr << "[INFO] writing " << ix << " " << iy << " 1" 
                    << " " << *(itMap->second.find (det.rawId ()))
                    << std::endl ;
          endcapWriter.writeLine (det,*(itMap->second.find (det.rawId ())));

        } //PG loop over x, loop over y
    }

  /* TODOS
   - inizio con EB
  
   - leggi l'intervallo di validita'
   - cerca i XML file in funzione di quello che sta scritto nel parser
     (qui bisogna conoscere gia' la cartella e costruire i nomi allo stesso
      modo, questo e' un punto debole)
   - apri un XML interface per ciascun file XML e leggine sono quello
     che serve
   - riversalo nel XML finale  
   - check the includes
  */
  
  

  
}
Esempio n. 4
0
int main (int argc, char* argv[]) 
{
   
    int EEradStart = 15 ;
    int EEradEnd = 50 ;
    int EEphiStart = 0 ;
    int EEphiEnd = 360 ;

    std::string filename = "coeffcompareEE.root" ;
     
//     std::string NameDBOracle1 = "oracle://cms_orcoff_int2r/CMS_COND_ECAL";
//     std::string TagDBOracle1 = "EcalIntercalibConstants_startup_csa08_mc";  
//     
//     std::string NameDBOracle2 = "oracle://cms_orcoff_int2r/CMS_COND_ECAL";
//     std::string TagDBOracle2 = "EcalIntercalibConstants_inv_startup_csa08_mc";  

    std::string NameDBOracle1 = "oracle://cms_orcoff_prod/CMS_COND_20X_ECAL";
    std::string TagDBOracle1 = "EcalIntercalibConstants_phi_Zee_csa08_s156_mc";  
    
    std::string NameDBOracle2 = "oracle://cms_orcoff_prod/CMS_COND_20X_ECAL";
    std::string TagDBOracle2 = "EcalIntercalibConstants_startup_csa08_mc";  
    
    
    
    //---- location of the xml file ----
    std::string calibFile = "/afs/cern.ch/user/a/amassiro/scratch0/CMSSW_2_1_2/src/CalibCalorimetry/CaloMiscalibTools/data/miscalib_endcap_startup_csa08.xml";
 
    
    
    
    if (argc == 1) {
        std::cout << "Help:"<<std::endl;
        std::cout << " 0-> Help"<< std::endl;
        std::cout << " 1-> Name of 1st Database. e.g. oracle://cms_orcoff_int2r/CMS_COND_ECAL"<< std::endl;
        std::cout << " 2-> Name of 1st Database Tag. e.g. EcalIntercalibConstants_startup_csa08_mc"<< std::endl;
        std::cout << " 3-> Location of the xml file, e.g. /afs/cern.ch/user/.../CMSSW_2_1_2/src/CalibCalorimetry/CaloMiscalibTools/data/miscalib_endcap_startup_csa08.xml. Make sure it is on your afs."<< std::endl;
        std::cout << " 4-> Name of 2nd Database. e.g. oracle://cms_orcoff_int2r/CMS_COND_ECAL"<< std::endl;
        std::cout << " 5-> Name of 2nd Database Tag. e.g. EcalIntercalibConstants_startup_csa08_mc"<< std::endl;
        std::cout << " 6-> EEradStart"<< std::endl;
        std::cout << " 7-> EEradEnd"<< std::endl;
        std::cout << " 8-> EEphiStart"<< std::endl;
        std::cout << " 9-> EEphiEnd"<< std::endl;
        std::cout << " 10-> filename output"<< std::endl;
        
        std::cout << std::endl << std::endl << "Now working with default values" << std::endl;
    }
      
    if (argc == 2) {
        //---- Help option ----
        std::string testName = "--help";
        std::string testNameLoad = argv[1];
        if (argv[1] == testName){
        std::cout << "Help:"<<std::endl;
        std::cout << " 0-> Help. --help option"<< std::endl;
        std::cout << " 1-> Name of 1st Database. e.g. oracle://cms_orcoff_int2r/CMS_COND_ECAL"<< std::endl;
        std::cout << " 2-> Name of 1st Database Tag. e.g. EcalIntercalibConstants_startup_csa08_mc"<< std::endl;
        std::cout << " 3-> Location of the xml file, e.g. /afs/cern.ch/user/.../CMSSW_2_1_2/src/CalibCalorimetry/CaloMiscalibTools/data/miscalib_endcap_startup_csa08.xml. Make sure it is on your afs."<< std::endl;
        std::cout << " 4-> Name of 2nd Database. e.g. oracle://cms_orcoff_int2r/CMS_COND_ECAL"<< std::endl;
        std::cout << " 5-> Name of 2nd Database Tag. e.g. EcalIntercalibConstants_startup_csa08_mc"<< std::endl;
        std::cout << " 6-> EEradStart"<< std::endl;
        std::cout << " 7-> EEradEnd"<< std::endl;
        std::cout << " 8-> EEphiStart"<< std::endl;
        std::cout << " 9-> EEphiEnd"<< std::endl;
        std::cout << " 10-> filename output"<< std::endl;
        exit (1);
        }
    }
    if (argc > 1){
        NameDBOracle1 = argv[1];
        TagDBOracle1 = argv[2];
        std::cout << "NameDBOracle1 = " << NameDBOracle1 << std::endl;
        std::cout << "TagDBOracle1 = " << TagDBOracle1 << std::endl;
        if (argc > 3){
            calibFile = argv[3];
            std::cout << "calibFile = " << calibFile << std::endl;
            if (argc > 4){
                NameDBOracle2 = argv[4];
                TagDBOracle2 = argv[5];
                std::cout << "NameDBOracle2 = " << NameDBOracle2 << std::endl;
                std::cout << "TagDBOracle2 = " << TagDBOracle2 << std::endl;
            }
        }
    }
  
    
    if (argc > 6)
    {
        if (argc < 10)
        {
            std::cerr << "Too few (or too many) arguments passed" << std::endl ;
            exit (1) ;
        }
        EEradStart = atoi (argv[6]) ;
        EEradEnd = atoi (argv[7]) ;
        EEphiStart = atoi (argv[8]) ;
        EEphiEnd = atoi (argv[9]) ;
    }
    if (argc == 11) filename = argv[10] ;

    
    
    
    //---- export of the DB from oracle to sqlite db ----
  
    
    std::string Command2LineStr1 = "cmscond_export_iov -s " + NameDBOracle1 + " -d sqlite_file:Uno.db -D CondFormatsEcalObjects -t " + TagDBOracle1 + " -P /afs/cern.ch/cms/DB/conddb/";
   
    std::string Command2LineStr2 = "cmscond_export_iov -s " + NameDBOracle2 + " -d sqlite_file:Due.db -D CondFormatsEcalObjects -t " + TagDBOracle2 + " -P /afs/cern.ch/cms/DB/conddb/";
            

    gSystem->Exec(Command2LineStr1.c_str());

    //---- now the second set analysed through xml file ----
        gSystem->Exec(Command2LineStr2.c_str());
   
    
    
   
  
  std::string NameDB;
  std::string FileData;

  //----------------------------------
  //---- First Database Analyzed -----
  //----------------------------------

  NameDB = "sqlite_file:Uno.db";
  FileData = TagDBOracle1;
  CondIter<EcalIntercalibConstants> Iterator1;
  Iterator1.create(NameDB,FileData);
  
  
  
  //-----------------------------------
  //---- Second Database Analyzed -----
  //-----------------------------------
  
  NameDB = "sqlite_file:Due.db";
  FileData = TagDBOracle2;
  CondIter<EcalIntercalibConstants> Iterator2;
  Iterator2.create(NameDB,FileData);

  //---------------------------------------------------------------------
  
  
      
  
  
  //-------------------------------------------------
  //---- Ottengo Mappe da entrambi gli Iterators ----
  //-------------------------------------------------
  
  const EcalIntercalibConstants* EEconstants1;
  EEconstants1 = Iterator1.next();
  EcalIntercalibConstantMap iEEcalibMap = EEconstants1->getMap () ;
 
  
  
  const EcalIntercalibConstants* EEconstants2;
  EEconstants2 = Iterator2.next();
  EcalIntercalibConstantMap iEEscalibMap = EEconstants2->getMap () ;

  
  
  
  
  
  
  
  
  
  //---- load form xml file ----
  //---- name of the xml file defined at the beginning ----
  
//   CaloMiscalibMapEcal EEscalibMap ;
//   EEscalibMap.prefillMap () ;
//   MiscalibReaderFromXMLEcalEndcap endcapreader (EEscalibMap) ;
//   if (!calibFile.empty ()) endcapreader.parseXMLMiscalibFile (calibFile) ;
//   EcalIntercalibConstants* EEconstants = new EcalIntercalibConstants (EEscalibMap.get ()) ;
//   EcalIntercalibConstantMap iEEscalibMap = EEconstants->getMap () ;  //MF prende i vecchi coeff
    
  
  
  
  
  
  
  //---- Xml way ----  

  
  
//   CaloMiscalibMapEcal EEscalibMap ;
//   EEscalibMap.prefillMap () ;
//   MiscalibReaderFromXMLEcalEndcap endcapreader (EEscalibMap) ;
//   if (!endcapfile.empty ()) endcapreader.parseXMLMiscalibFile (endcapfile) ;
//   EcalIntercalibConstants* EEconstants = 
//           new EcalIntercalibConstants (EEscalibMap.get ()) ;
//   EcalIntercalibConstantMap iEEscalibMap = EEconstants->getMap () ;  //MF prende i vecchi coeff
// 
//   //PG get the recalibration files for EB and EE
//   //PG -----------------------------------------
// 
//   CaloMiscalibMapEcal EEcalibMap ;
//   EEcalibMap.prefillMap () ;
//   MiscalibReaderFromXMLEcalEndcap calibEndcapreader (EEcalibMap) ;
//   if (!calibEndcapfile.empty ()) calibEndcapreader.parseXMLMiscalibFile (calibEndcapfile) ;
//   EcalIntercalibConstants* EECconstants = 
//           new EcalIntercalibConstants (EEcalibMap.get ()) ;
//   EcalIntercalibConstantMap iEEcalibMap = EECconstants->getMap () ;  //MF prende i vecchi coeff
  
  
  
  
  
  
  
  
  //PG fill the histograms
  //PG -------------------
  
  TH1F EEPCompareCoeffDistr ("EEPCompareCoeffDistr","EEPCompareCoeffDistr",5000,0,2) ;
  TH2F EEPCompareCoeffMap ("EEPCompareCoeffMap","EEPCompareCoeffMap",101,0,101,101,0,101) ;
  TH2F EEPCompareCoeffEtaTrend ("EEPCompareCoeffEtaTrend",
                                "EEPCompareCoeffEtaTrend",
                                51,0,50,500,0,2) ;
  TProfile EEPCompareCoeffEtaProfile ("EEPCompareCoeffEtaProfile",
                                      "EEPCompareCoeffEtaProfile",
                                      51,0,50,0,2) ;
   
  TH1F EEPCompareCoeffDistr_R1 ("EEPCompareCoeff_R1","EEPCompareCoeff_R1",1000,0,2) ;
  TH1F EEPCompareCoeffDistr_R2 ("EEPCompareCoeff_R2","EEPCompareCoeff_R2",1000,0,2) ;
  TH1F EEPCompareCoeffDistr_R3 ("EEPCompareCoeff_R3","EEPCompareCoeff_R3",1000,0,2) ;
  TH1F EEPCompareCoeffDistr_R4 ("EEPCompareCoeff_R4","EEPCompareCoeff_R4",1000,0,2) ;
  TH1F EEPCompareCoeffDistr_R5 ("EEPCompareCoeff_R5","EEPCompareCoeff_R5",1000,0,2) ;

  // ECAL endcap +
  for (int ix = 1 ; ix <= 100 ; ++ix)
      for (int iy = 1 ; iy <= 100 ; ++iy)
  {
      int rad = static_cast<int> (sqrt ((ix - 50) * (ix - 50) +
              (iy - 50) * (iy - 50))) ;
      if (rad < EEradStart || rad > EEradEnd) continue ;
      double phiTemp = atan2 (iy - 50, ix - 50) ;
      if (phiTemp < 0) phiTemp += 2 * PI_GRECO ;
      int phi = static_cast<int> ( phiTemp * 180 / PI_GRECO) ;
      if (phi < EEphiStart || phi > EEphiEnd) continue ;
      if (!EEDetId::validDetId (ix,iy,1)) continue ;
      EEDetId det = EEDetId (ix, iy, 1, EEDetId::XYMODE) ;
      double factor = *(iEEcalibMap.find (det.rawId ())) / 
                  *(iEEscalibMap.find (det.rawId ())) ;
      
//       std::cout << " iEEcalibMap rad = " << rad << " --> " << *(iEEcalibMap.find (det.rawId ()));
//       std::cout << " iEEscalibMap --> " << *(iEEscalibMap.find (det.rawId ())) << std::endl;  
      
      EEPCompareCoeffDistr.Fill (factor) ;
      EEPCompareCoeffMap.Fill (ix,iy,factor) ;
      EEPCompareCoeffEtaTrend.Fill (rad,factor) ;
      EEPCompareCoeffEtaProfile.Fill (rad,factor) ;
      if (abs(rad) < 22) continue ;
      else if (abs(rad) < 27) EEPCompareCoeffDistr_R1.Fill (factor) ;
      else if (abs(rad) < 32) EEPCompareCoeffDistr_R2.Fill (factor) ;
      else if (abs(rad) < 37) EEPCompareCoeffDistr_R3.Fill (factor) ;
      else if (abs(rad) < 42) EEPCompareCoeffDistr_R4.Fill (factor) ;
      else EEPCompareCoeffDistr_R5.Fill (factor) ;

  } // ECAL endcap +

  // ECAL endcap-
  TH1F EEMCompareCoeffDistr ("EEMCompareCoeffDistr","EEMCompareCoeffDistr",200,0,2) ;
  TH2F EEMCompareCoeffMap ("EEMCompareCoeffMap","EEMCompareCoeffMap",100,0,100,100,0,100) ;
  TH2F EEMCompareCoeffEtaTrend ("EEMCompareCoeffEtaTrend",
                                "EEMCompareCoeffEtaTrend",
                                51,0,50,500,0,2) ;
  TProfile EEMCompareCoeffEtaProfile ("EEMCompareCoeffEtaProfile",
                                      "EEMCompareCoeffEtaProfile",
                                      51,0,50,0,2) ;
   
  // ECAL endcap -
  for (int ix = 1 ; ix <= 100 ; ++ix)
      for (int iy = 1 ; iy <= 100 ; ++iy)
  {
      int rad = static_cast<int> (sqrt ((ix - 50) * (ix - 50) +
              (iy - 50) * (iy - 50))) ;
      if (rad < EEradStart || rad > EEradEnd) continue ;
      double phiTemp = atan2 (iy - 50, ix - 50) ;
      if (phiTemp < 0) phiTemp += 2 * PI_GRECO ;
      if (!EEDetId::validDetId (ix,iy,-1)) continue ;
      EEDetId det = EEDetId (ix, iy, -1, EEDetId::XYMODE) ;
      double factor = *(iEEcalibMap.find (det.rawId ())) *
                  *(iEEscalibMap.find (det.rawId ())) ;
      EEMCompareCoeffDistr.Fill (factor) ;
      EEMCompareCoeffMap.Fill (ix,iy,factor) ;
      EEMCompareCoeffEtaTrend.Fill (rad,factor) ;
      EEMCompareCoeffEtaProfile.Fill (rad,factor) ;
  } // ECAL endcap -
    
  TFile out (filename.c_str (),"recreate") ;
  EEMCompareCoeffMap.Write() ;
  EEMCompareCoeffDistr.Write() ;
  EEMCompareCoeffEtaTrend.Write () ;
  EEMCompareCoeffEtaProfile.Write () ;
  EEPCompareCoeffMap.Write() ;
  EEPCompareCoeffDistr.Write() ;
  EEPCompareCoeffEtaTrend.Write () ;
  EEPCompareCoeffEtaProfile.Write () ;
  EEPCompareCoeffDistr_R1.Write () ;
  EEPCompareCoeffDistr_R2.Write () ;
  EEPCompareCoeffDistr_R3.Write () ;
  EEPCompareCoeffDistr_R4.Write () ;
  EEPCompareCoeffDistr_R5.Write () ;
  out.Close() ;
  
  
  
  
  
  
  
  
  //---- remove local database ----
  
  gSystem->Exec("rm Uno.db");
  gSystem->Exec("rm Due.db");

  
   
}
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");
}
Esempio n. 6
0
int main (int argc, char* argv[]) 
{

  int EEradStart = 15 ;
  int EEradEnd = 50 ;
  int EEphiStart = 15 ;
  int EEphiEnd = 45 ;

  std::string endcapfile = argv[1] ; 
  std::string calibEndcapfile = argv[2] ; 
  std::string filename = "coeffcompareEE.root" ;

  if (argc > 3)
    {
      if (argc < 7)
        {
          std::cerr << "Too few (or too many) arguments passed" << std::endl ;
          exit (1) ;
        }
      EEradStart = atoi (argv[3]) ;
      EEradEnd = atoi (argv[4]) ;
      EEphiStart = atoi (argv[5]) ;
      EEphiEnd = atoi (argv[6]) ;
    }

  if (argc == 8) filename = argv[7] ;

//  std::string endcapfile = "/afs/cern.ch/user/g/govoni/scratch1/CMSSW/CALIB/CMSSW_1_6_0/src/CalibCalorimetry/CaloMiscalibTools/data/ecal_endcap_startup.xml" ;
//  std::string calibEndcapfile = "/afs/cern.ch/user/g/govoni/scratch1/CMSSW/CALIB/CMSSW_1_6_0/src/CalibCalorimetry/CaloMiscalibTools/data/inv_ecal_endcap_startup.xml" ;
  
  //PG get the miscalibration files for EB and EE
  //PG ------------------------------------------

  CaloMiscalibMapEcal EEscalibMap ;
  EEscalibMap.prefillMap () ;
  MiscalibReaderFromXMLEcalEndcap endcapreader (EEscalibMap) ;
  if (!endcapfile.empty ()) endcapreader.parseXMLMiscalibFile (endcapfile) ;
  EcalIntercalibConstants* EEconstants = 
         new EcalIntercalibConstants (EEscalibMap.get ()) ;
  EcalIntercalibConstants::EcalIntercalibConstantMap iEEscalibMap = EEconstants->getMap () ;  //MF prende i vecchi coeff

  //PG get the recalibration files for EB and EE
  //PG -----------------------------------------

  CaloMiscalibMapEcal EEcalibMap ;
  EEcalibMap.prefillMap () ;
  MiscalibReaderFromXMLEcalEndcap calibEndcapreader (EEcalibMap) ;
  if (!calibEndcapfile.empty ()) calibEndcapreader.parseXMLMiscalibFile (calibEndcapfile) ;
  EcalIntercalibConstants* EECconstants = 
         new EcalIntercalibConstants (EEcalibMap.get ()) ;
  EcalIntercalibConstants::EcalIntercalibConstantMap iEEcalibMap = EECconstants->getMap () ;  //MF prende i vecchi coeff
  
  //PG fill the histograms
  //PG -------------------
  
  TH1F EEPCompareCoeffDistr ("EEPCompareCoeffDistr","EEPCompareCoeffDistr",5000,0,2) ;
  TH2F EEPCompareCoeffMap ("EEPCompareCoeffMap","EEPCompareCoeffMap",101,0,101,101,0,101) ;
  TH2F EEPCompareCoeffEtaTrend ("EEPCompareCoeffEtaTrend",
                               "EEPCompareCoeffEtaTrend",
                               51,0,50,500,0,2) ;
  TProfile EEPCompareCoeffEtaProfile ("EEPCompareCoeffEtaProfile",
                                      "EEPCompareCoeffEtaProfile",
                                      51,0,50,0,2) ;
   
  TH1F EEPCompareCoeffDistr_R1 ("EEPCompareCoeff_R1","EEPCompareCoeff_R1",1000,0,2) ;
  TH1F EEPCompareCoeffDistr_R2 ("EEPCompareCoeff_R2","EEPCompareCoeff_R2",1000,0,2) ;
  TH1F EEPCompareCoeffDistr_R3 ("EEPCompareCoeff_R3","EEPCompareCoeff_R3",1000,0,2) ;
  TH1F EEPCompareCoeffDistr_R4 ("EEPCompareCoeff_R4","EEPCompareCoeff_R4",1000,0,2) ;
  TH1F EEPCompareCoeffDistr_R5 ("EEPCompareCoeff_R5","EEPCompareCoeff_R5",1000,0,2) ;

  // ECAL endcap +
  for (int ix = 1 ; ix <= 100 ; ++ix)
   for (int iy = 1 ; iy <= 100 ; ++iy)
    {
      int rad = static_cast<int> (sqrt ((ix - 50) * (ix - 50) +
                                        (iy - 50) * (iy - 50))) ;
      if (rad < EEradStart || rad > EEradEnd) continue ;
      double phiTemp = atan2 (iy - 50, ix - 50) ;
      if (phiTemp < 0) phiTemp += 2 * PI_GRECO ;
      int phi = static_cast<int> ( phiTemp * 180 / PI_GRECO) ;
      if (phi < EEphiStart || phi > EEphiEnd) continue ;
      if (!EEDetId::validDetId (ix,iy,1)) continue ;
      EEDetId det = EEDetId (ix, iy, 1, EEDetId::XYMODE) ;
      double factor = (iEEcalibMap.find (det.rawId ()))->second * 
                      (iEEscalibMap.find (det.rawId ()))->second ;
      EEPCompareCoeffDistr.Fill (factor) ;
      EEPCompareCoeffMap.Fill (ix,iy,factor) ;
      EEPCompareCoeffEtaTrend.Fill (rad,factor) ;
      EEPCompareCoeffEtaProfile.Fill (rad,factor) ;
      if (abs(rad) < 22) continue ;
      else if (abs(rad) < 27) EEPCompareCoeffDistr_R1.Fill (factor) ;
      else if (abs(rad) < 32) EEPCompareCoeffDistr_R2.Fill (factor) ;
      else if (abs(rad) < 37) EEPCompareCoeffDistr_R3.Fill (factor) ;
      else if (abs(rad) < 42) EEPCompareCoeffDistr_R4.Fill (factor) ;
      else EEPCompareCoeffDistr_R5.Fill (factor) ;

    } // ECAL endcap +

  // ECAL endcap-
  TH1F EEMCompareCoeffDistr ("EEMCompareCoeffDistr","EEMCompareCoeffDistr",200,0,2) ;
  TH2F EEMCompareCoeffMap ("EEMCompareCoeffMap","EEMCompareCoeffMap",100,0,100,100,0,100) ;
  TH2F EEMCompareCoeffEtaTrend ("EEMCompareCoeffEtaTrend",
                               "EEMCompareCoeffEtaTrend",
                               51,0,50,500,0,2) ;
  TProfile EEMCompareCoeffEtaProfile ("EEMCompareCoeffEtaProfile",
                                     "EEMCompareCoeffEtaProfile",
                                     51,0,50,0,2) ;
   
  // ECAL endcap -
  for (int ix = 1 ; ix <= 100 ; ++ix)
   for (int iy = 1 ; iy <= 100 ; ++iy)
    {
      int rad = static_cast<int> (sqrt ((ix - 50) * (ix - 50) +
                                        (iy - 50) * (iy - 50))) ;
      if (rad < EEradStart || rad > EEradEnd) continue ;
      double phiTemp = atan2 (iy - 50, ix - 50) ;
      if (phiTemp < 0) phiTemp += 2 * PI_GRECO ;
      int phi = static_cast<int> ( phiTemp * 180 / PI_GRECO) ;
      if (!EEDetId::validDetId (ix,iy,-1)) continue ;
      EEDetId det = EEDetId (ix, iy, -1, EEDetId::XYMODE) ;
      double factor = (iEEcalibMap.find (det.rawId ()))->second * 
                      (iEEscalibMap.find (det.rawId ()))->second ;
      EEMCompareCoeffDistr.Fill (factor) ;
      EEMCompareCoeffMap.Fill (ix,iy,factor) ;
      EEMCompareCoeffEtaTrend.Fill (rad,factor) ;
      EEMCompareCoeffEtaProfile.Fill (rad,factor) ;
    } // ECAL endcap -
    
  TFile out (filename.c_str (),"recreate") ;
  EEMCompareCoeffMap.Write() ;
  EEMCompareCoeffDistr.Write() ;
  EEMCompareCoeffEtaTrend.Write () ;
  EEMCompareCoeffEtaProfile.Write () ;
  EEPCompareCoeffMap.Write() ;
  EEPCompareCoeffDistr.Write() ;
  EEPCompareCoeffEtaTrend.Write () ;
  EEPCompareCoeffEtaProfile.Write () ;
  EEPCompareCoeffDistr_R1.Write () ;
  EEPCompareCoeffDistr_R2.Write () ;
  EEPCompareCoeffDistr_R3.Write () ;
  EEPCompareCoeffDistr_R4.Write () ;
  EEPCompareCoeffDistr_R5.Write () ;
  out.Close() ;
  
}